Skip to content
Snippets Groups Projects
Commit 656c53cf authored by akwizgran's avatar akwizgran
Browse files

Converted the home screen into a grid view.

parent 06d32814
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">Briar</string> <string name="app_name">Briar</string>
<string name="notification_title">Syncing messages</string> <string name="notification_title">Briar is running</string>
<string name="notification_text">Touch to quit.</string> <string name="notification_text">Touch to quit.</string>
<string name="contact_list_button">Contacts</string> <string name="contact_list_button">Contacts</string>
<string name="messages_button">Messages</string>
<string name="settings_button">Settings</string>
<string name="quit_button">Quit</string> <string name="quit_button">Quit</string>
<string name="contact_list_title">Contacts</string> <string name="contact_list_title">Contacts</string>
<string name="contact_connected">Connected</string> <string name="contact_connected">Connected</string>
......
...@@ -2,11 +2,10 @@ package net.sf.briar.android; ...@@ -2,11 +2,10 @@ package net.sf.briar.android;
import static android.view.Gravity.CENTER; import static android.view.Gravity.CENTER;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.R; import net.sf.briar.R;
...@@ -18,62 +17,121 @@ import android.os.Bundle; ...@@ -18,62 +17,121 @@ import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
public class HomeScreenActivity extends BriarActivity public class HomeScreenActivity extends BriarActivity {
implements OnClickListener {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(HomeScreenActivity.class.getName()); Logger.getLogger(HomeScreenActivity.class.getName());
private final BriarServiceConnection serviceConnection = private final BriarServiceConnection serviceConnection =
new BriarServiceConnection(); new BriarServiceConnection();
private final List<Button> buttons = new ArrayList<Button>();
Button contactListButton = null, quitButton = null; public HomeScreenActivity() {
super();
}
@Override @Override
public void onCreate(Bundle state) { public void onCreate(Bundle state) {
super.onCreate(null); super.onCreate(null);
if(LOG.isLoggable(INFO)) LOG.info("Created"); if(LOG.isLoggable(INFO)) LOG.info("Created");
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
layout.setOrientation(VERTICAL);
layout.setGravity(CENTER);
// If this activity was launched from the notification bar, quit // If this activity was launched from the notification bar, quit
if(getIntent().getBooleanExtra("net.sf.briar.QUIT", false)) { if(getIntent().getBooleanExtra("net.sf.briar.QUIT", false)) {
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT,
MATCH_PARENT));
layout.setGravity(CENTER);
ProgressBar spinner = new ProgressBar(this); ProgressBar spinner = new ProgressBar(this);
spinner.setIndeterminate(true); spinner.setIndeterminate(true);
layout.addView(spinner); layout.addView(spinner);
setContentView(layout);
quit(); quit();
} else { } else {
LinearLayout innerLayout = new LinearLayout(this); ListView.LayoutParams matchParent = new ListView.LayoutParams(
innerLayout.setOrientation(HORIZONTAL); MATCH_PARENT, MATCH_PARENT);
innerLayout.setGravity(CENTER);
contactListButton = new Button(this); Button contactListButton = new Button(this);
LayoutParams lp = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT); contactListButton.setLayoutParams(matchParent);
contactListButton.setLayoutParams(lp); contactListButton.setCompoundDrawablesWithIntrinsicBounds(0,
R.drawable.social_person, 0, 0);
contactListButton.setText(R.string.contact_list_button); contactListButton.setText(R.string.contact_list_button);
contactListButton.setCompoundDrawablesWithIntrinsicBounds( contactListButton.setOnClickListener(new OnClickListener() {
R.drawable.social_person, 0, 0, 0); public void onClick(View view) {
contactListButton.setOnClickListener(this); startActivity(new Intent(HomeScreenActivity.this,
innerLayout.addView(contactListButton); ContactListActivity.class));
}
});
buttons.add(contactListButton);
Button messagesButton = new Button(this);
messagesButton.setLayoutParams(matchParent);
messagesButton.setCompoundDrawablesWithIntrinsicBounds(0,
R.drawable.content_email, 0, 0);
messagesButton.setText(R.string.messages_button);
messagesButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
// FIXME: Hook this button up to an activity
}
});
buttons.add(messagesButton);
Button settingsButton = new Button(this);
settingsButton.setLayoutParams(matchParent);
settingsButton.setCompoundDrawablesWithIntrinsicBounds(0,
R.drawable.action_settings, 0, 0);
settingsButton.setText(R.string.settings_button);
settingsButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
// FIXME: Hook this button up to an activity
}
});
buttons.add(settingsButton);
quitButton = new Button(this); Button quitButton = new Button(this);
quitButton.setLayoutParams(lp); quitButton.setLayoutParams(matchParent);
quitButton.setCompoundDrawablesWithIntrinsicBounds(0,
R.drawable.navigation_cancel, 0, 0);
quitButton.setText(R.string.quit_button); quitButton.setText(R.string.quit_button);
quitButton.setCompoundDrawablesWithIntrinsicBounds( quitButton.setOnClickListener(new OnClickListener() {
R.drawable.navigation_cancel, 0, 0, 0); public void onClick(View view) {
quitButton.setOnClickListener(this); quit();
innerLayout.addView(quitButton); }
layout.addView(innerLayout); });
} buttons.add(quitButton);
GridView grid = new GridView(this);
grid.setLayoutParams(matchParent);
grid.setGravity(CENTER);
grid.setNumColumns(2);
grid.setAdapter(new BaseAdapter() {
setContentView(layout); public int getCount() {
return buttons.size();
}
public Object getItem(int position) {
return buttons.get(position);
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView,
ViewGroup parent) {
return buttons.get(position);
}
});
setContentView(grid);
}
// Start the service and bind to it // Start the service and bind to it
startService(new Intent(BriarService.class.getName())); startService(new Intent(BriarService.class.getName()));
...@@ -87,12 +145,6 @@ implements OnClickListener { ...@@ -87,12 +145,6 @@ implements OnClickListener {
unbindService(serviceConnection); unbindService(serviceConnection);
} }
public void onClick(View view) {
if(view == contactListButton)
startActivity(new Intent(this, ContactListActivity.class));
else if(view == quitButton) quit();
}
private void quit() { private void quit() {
new Thread() { new Thread() {
@Override @Override
......
...@@ -67,6 +67,7 @@ implements OnClickListener, DatabaseListener, ConnectionListener { ...@@ -67,6 +67,7 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
adapter = new ContactListAdapter(this); adapter = new ContactListAdapter(this);
ListView listView = new ListView(this); ListView listView = new ListView(this);
// Give me all the width and all the unused height
listView.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT, listView.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT,
1f)); 1f));
listView.setAdapter(adapter); listView.setAdapter(adapter);
......
...@@ -18,9 +18,9 @@ import android.widget.LinearLayout; ...@@ -18,9 +18,9 @@ import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
public class ContactListAdapter extends ArrayAdapter<ContactListItem> { class ContactListAdapter extends ArrayAdapter<ContactListItem> {
public ContactListAdapter(Context context) { ContactListAdapter(Context context) {
super(context, android.R.layout.simple_expandable_list_item_1, super(context, android.R.layout.simple_expandable_list_item_1,
new ArrayList<ContactListItem>()); new ArrayList<ContactListItem>());
} }
...@@ -36,10 +36,11 @@ public class ContactListAdapter extends ArrayAdapter<ContactListItem> { ...@@ -36,10 +36,11 @@ public class ContactListAdapter extends ArrayAdapter<ContactListItem> {
ImageView bulb = new ImageView(ctx); ImageView bulb = new ImageView(ctx);
if(item.getConnected()) bulb.setImageResource(R.drawable.green_bulb); if(item.getConnected()) bulb.setImageResource(R.drawable.green_bulb);
else bulb.setImageResource(R.drawable.grey_bulb); else bulb.setImageResource(R.drawable.grey_bulb);
bulb.setPadding(5, 0, 5, 0); bulb.setPadding(5, 5, 5, 5);
layout.addView(bulb); layout.addView(bulb);
TextView name = new TextView(ctx); TextView name = new TextView(ctx);
// Give me all the unused width
name.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1f)); name.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1f));
name.setTextSize(18); name.setTextSize(18);
name.setText(item.getName()); name.setText(item.getName());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment