Added app sharing button to contact list activity.

This commit is contained in:
akwizgran
2013-04-19 00:33:21 +01:00
parent a2b3af8718
commit c184458d9b
2 changed files with 24 additions and 2 deletions

View File

@@ -19,6 +19,7 @@
<string name="quit_button">Quit</string>
<string name="new_identity_item">New identity\u2026</string>
<string name="contact_list_title">Contacts</string>
<string name="share_app">Share the Briar App</string>
<string name="contact_connected">Connected</string>
<string name="format_last_connected">Last connected &lt;br /&gt; %1$s</string>
<string name="add_contact_title">Add a Contact</string>

View File

@@ -1,5 +1,7 @@
package net.sf.briar.android.contact;
import static android.content.Intent.ACTION_SEND;
import static android.content.Intent.EXTRA_STREAM;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.widget.LinearLayout.HORIZONTAL;
@@ -10,6 +12,7 @@ import static net.sf.briar.android.widgets.CommonLayoutParams.MATCH_MATCH;
import static net.sf.briar.android.widgets.CommonLayoutParams.MATCH_WRAP;
import static net.sf.briar.android.widgets.CommonLayoutParams.MATCH_WRAP_1;
import java.io.File;
import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
@@ -35,6 +38,7 @@ import net.sf.briar.api.db.event.DatabaseListener;
import net.sf.briar.api.transport.ConnectionListener;
import net.sf.briar.api.transport.ConnectionRegistry;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
@@ -56,6 +60,7 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
@Inject private ConnectionRegistry connectionRegistry;
private ContactListAdapter adapter = null;
private ListView list = null;
private ImageButton addContactButton = null, shareButton = null;
// Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db;
@@ -85,12 +90,19 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
footer.setGravity(CENTER);
footer.addView(new HorizontalSpace(this));
ImageButton addContactButton = new ImageButton(this);
addContactButton = new ImageButton(this);
addContactButton.setBackgroundResource(0);
addContactButton.setImageResource(R.drawable.social_add_person);
addContactButton.setOnClickListener(this);
footer.addView(addContactButton);
footer.addView(new HorizontalSpace(this));
shareButton = new ImageButton(this);
shareButton.setBackgroundResource(0);
shareButton.setImageResource(R.drawable.social_share);
shareButton.setOnClickListener(this);
footer.addView(shareButton);
footer.addView(new HorizontalSpace(this));
layout.addView(footer);
setContentView(layout);
@@ -163,7 +175,16 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
}
public void onClick(View view) {
startActivity(new Intent(this, AddContactActivity.class));
if(view == addContactButton) {
startActivity(new Intent(this, AddContactActivity.class));
} else if(view == shareButton) {
String apkPath = getPackageCodePath();
Intent i = new Intent(ACTION_SEND);
i.setType("application/*");
i.putExtra(EXTRA_STREAM, Uri.fromFile(new File(apkPath)));
String shareApp = getResources().getString(R.string.share_app);
startActivity(Intent.createChooser(i, shareApp));
}
}
public void eventOccurred(DatabaseEvent e) {