Address book list
This commit is contained in:
@ -29,6 +29,9 @@
|
||||
<activity
|
||||
android:name="i2p.bote.android.NewEmailActivity"
|
||||
android:parentActivityName="i2p.bote.android.EmailListActivity" />
|
||||
<activity
|
||||
android:name="i2p.bote.android.addressbook.AddressBookActivity"
|
||||
android:parentActivityName="i2p.bote.android.EmailListActivity" />
|
||||
<activity
|
||||
android:name="i2p.bote.android.config.SettingsActivity"
|
||||
android:parentActivityName="i2p.bote.android.EmailListActivity" />
|
||||
|
BIN
res/drawable-hdpi/ic_social_add_person.png
Normal file
BIN
res/drawable-hdpi/ic_social_add_person.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
res/drawable-mdpi/ic_social_add_person.png
Normal file
BIN
res/drawable-mdpi/ic_social_add_person.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
res/drawable-xhdpi/ic_social_add_person.png
Normal file
BIN
res/drawable-xhdpi/ic_social_add_person.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
24
res/layout/listitem_contact.xml
Normal file
24
res/layout/listitem_contact.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_picture"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contact_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/contact_picture"
|
||||
android:layout_marginTop="13dp"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_toRightOf="@+id/contact_picture"
|
||||
android:text="Contact name"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</RelativeLayout>
|
11
res/menu/address_book_list.xml
Normal file
11
res/menu/address_book_list.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_new_contact"
|
||||
android:icon="@drawable/ic_social_add_person.png"
|
||||
android:title="@string/action_new_contact"
|
||||
i2pandroid:showAsAction="ifRoom"/>
|
||||
|
||||
</menu>
|
@ -1,6 +1,12 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_address_book"
|
||||
android:orderInCategory="50"
|
||||
android:title="@string/action_address_book"
|
||||
i2pandroid:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
|
@ -4,6 +4,7 @@
|
||||
<string name="app_name">I2P-Bote</string>
|
||||
<string name="action_new_email">New email</string>
|
||||
<string name="action_send_email">Send email</string>
|
||||
<string name="action_address_book">Address book</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
|
||||
<string name="items_selected">%s selected</string>
|
||||
@ -39,6 +40,9 @@
|
||||
<string name="compose_email">Compose email</string>
|
||||
<string name="email_queued_for_sending">Email queued for sending</string>
|
||||
|
||||
<string name="address_book_empty">Address book is empty</string>
|
||||
<string name="action_new_contact">New contact</string>
|
||||
|
||||
<string name="pref_title_general">General</string>
|
||||
<string name="pref_summ_general">General settings and default identity settings</string>
|
||||
<string name="pref_title_autoMail">Auto-check mail</string>
|
||||
|
@ -2,6 +2,7 @@ package i2p.bote.android;
|
||||
|
||||
import net.i2p.client.I2PClient;
|
||||
import i2p.bote.I2PBote;
|
||||
import i2p.bote.android.addressbook.AddressBookActivity;
|
||||
import i2p.bote.android.config.SettingsActivity;
|
||||
import i2p.bote.android.util.MoveToDialogFragment;
|
||||
import i2p.bote.folder.EmailFolder;
|
||||
@ -163,6 +164,11 @@ public class EmailListActivity extends ActionBarActivity implements
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_address_book:
|
||||
Intent ai = new Intent(this, AddressBookActivity.class);
|
||||
startActivity(ai);
|
||||
return true;
|
||||
|
||||
case R.id.action_settings:
|
||||
Intent si = new Intent(this, SettingsActivity.class);
|
||||
startActivity(si);
|
||||
|
27
src/i2p/bote/android/addressbook/AddressBookActivity.java
Normal file
27
src/i2p/bote/android/addressbook/AddressBookActivity.java
Normal file
@ -0,0 +1,27 @@
|
||||
package i2p.bote.android.addressbook;
|
||||
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
public class AddressBookActivity extends ActionBarActivity implements
|
||||
AddressBookFragment.OnContactSelectedListener {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Enable ActionBar app icon to behave as action to go back
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
AddressBookFragment f = new AddressBookFragment();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(android.R.id.content, f).commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContactSelected(Contact contact) {
|
||||
// TODO
|
||||
}
|
||||
}
|
139
src/i2p/bote/android/addressbook/AddressBookFragment.java
Normal file
139
src/i2p/bote/android/addressbook/AddressBookFragment.java
Normal file
@ -0,0 +1,139 @@
|
||||
package i2p.bote.android.addressbook;
|
||||
|
||||
import i2p.bote.I2PBote;
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.util.BetterAsyncTaskLoader;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class AddressBookFragment extends ListFragment implements
|
||||
LoaderManager.LoaderCallbacks<SortedSet<Contact>> {
|
||||
OnContactSelectedListener mCallback;
|
||||
private ContactAdapter mAdapter;
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnContactSelectedListener {
|
||||
public void onContactSelected(Contact contact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
// This makes sure that the container activity has implemented
|
||||
// the callback interface. If not, it throws an exception
|
||||
try {
|
||||
mCallback = (OnContactSelectedListener) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(activity.toString()
|
||||
+ " must implement OnContactSelectedListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mAdapter = new ContactAdapter(getActivity());
|
||||
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
setListShown(false);
|
||||
setEmptyText(getResources().getString(
|
||||
R.string.address_book_empty));
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.address_book_list, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_new_contact:
|
||||
// TODO
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView parent, View view, int pos, long id) {
|
||||
mCallback.onContactSelected(mAdapter.getItem(pos));
|
||||
}
|
||||
|
||||
// LoaderManager.LoaderCallbacks<SortedSet<Contact>>
|
||||
|
||||
public Loader<SortedSet<Contact>> onCreateLoader(int id, Bundle args) {
|
||||
return new AddressBookLoader(getActivity());
|
||||
}
|
||||
|
||||
private static class AddressBookLoader extends BetterAsyncTaskLoader<SortedSet<Contact>> {
|
||||
public AddressBookLoader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Contact> loadInBackground() {
|
||||
SortedSet<Contact> contacts = null;
|
||||
try {
|
||||
contacts = I2PBote.getInstance().getAddressBook().getAll();
|
||||
} catch (PasswordException e) {
|
||||
// TODO handle, but should not get here
|
||||
e.printStackTrace();
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartMonitoring() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopMonitoring() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void releaseResources(SortedSet<Contact> data) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<SortedSet<Contact>> loader,
|
||||
SortedSet<Contact> data) {
|
||||
mAdapter.setData(data);
|
||||
|
||||
if (isResumed()) {
|
||||
setListShown(true);
|
||||
} else {
|
||||
setListShownNoAnimation(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<SortedSet<Contact>> loader) {
|
||||
mAdapter.setData(null);
|
||||
}
|
||||
}
|
50
src/i2p/bote/android/addressbook/ContactAdapter.java
Normal file
50
src/i2p/bote/android/addressbook/ContactAdapter.java
Normal file
@ -0,0 +1,50 @@
|
||||
package i2p.bote.android.addressbook;
|
||||
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.util.BoteHelper;
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ContactAdapter extends ArrayAdapter<Contact> {
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public ContactAdapter(Context context) {
|
||||
super(context, android.R.layout.simple_list_item_2);
|
||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
public void setData(SortedSet<Contact> contacts) {
|
||||
clear();
|
||||
if (contacts != null) {
|
||||
for (Contact contact : contacts) {
|
||||
add(contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = mInflater.inflate(R.layout.listitem_contact, parent, false);
|
||||
Contact contact = getItem(position);
|
||||
|
||||
ImageView picture = (ImageView) v.findViewById(R.id.contact_picture);
|
||||
TextView name = (TextView) v.findViewById(R.id.contact_name);
|
||||
|
||||
String pic = contact.getPictureBase64();
|
||||
if (pic != null)
|
||||
picture.setImageBitmap(BoteHelper.decodePicture(pic));
|
||||
|
||||
name.setText(contact.getName());
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
@ -91,8 +91,7 @@ public class BoteHelper extends GeneralHelper {
|
||||
// Address is in address book
|
||||
String pic = c.getPictureBase64();
|
||||
if (pic != null) {
|
||||
byte[] decodedPic = Base64.decode(pic, Base64.DEFAULT);
|
||||
return BitmapFactory.decodeByteArray(decodedPic, 0, decodedPic.length);
|
||||
return decodePicture(pic);
|
||||
}
|
||||
} else {
|
||||
// Address is an identity
|
||||
@ -100,8 +99,7 @@ public class BoteHelper extends GeneralHelper {
|
||||
if (i != null) {
|
||||
String pic = i.getPictureBase64();
|
||||
if (pic != null) {
|
||||
byte[] decodedPic = Base64.decode(pic, Base64.DEFAULT);
|
||||
return BitmapFactory.decodeByteArray(decodedPic, 0, decodedPic.length);
|
||||
return decodePicture(pic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,4 +108,9 @@ public class BoteHelper extends GeneralHelper {
|
||||
// Address not found anywhere, or found and has no picture
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Bitmap decodePicture(String picB64) {
|
||||
byte[] decodedPic = Base64.decode(picB64, Base64.DEFAULT);
|
||||
return BitmapFactory.decodeByteArray(decodedPic, 0, decodedPic.length);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user