mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-19 19:58:26 +00:00
single contact selection
This commit is contained in:
parent
9438973eac
commit
9b41675f8f
@ -134,6 +134,10 @@
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".SingleContactSelectionActivity"
|
||||
android:label="@string/AndroidManifest__select_contact"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".PushContactSelectionActivity"
|
||||
android:label="@string/AndroidManifest__select_contacts"
|
||||
|
8
res/drawable/thin_border.xml
Normal file
8
res/drawable/thin_border.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#00ffffff" />
|
||||
<stroke android:width="1px" android:color="#22000000" />
|
||||
<corners android:radius="4dp"/>
|
||||
<padding android:left="4dp" android:top="4dp" android:right="4dp" android:bottom="4dp" />
|
||||
</shape>
|
@ -17,15 +17,16 @@
|
||||
android:layout_height="106dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="18dp"
|
||||
android:paddingLeft="14dp"
|
||||
android:paddingRight="18dp"
|
||||
android:paddingTop="18dp">
|
||||
android:paddingTop="14dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:background="@drawable/thin_border"
|
||||
android:src="@drawable/icon"/>
|
||||
|
||||
<EditText
|
||||
@ -33,7 +34,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:hint="Group name"
|
||||
android:hint="@string/GroupCreateActivity_group_name_hint"
|
||||
android:layout_gravity="center_vertical" />
|
||||
</LinearLayout>
|
||||
|
||||
@ -68,8 +69,9 @@
|
||||
<RelativeLayout
|
||||
android:id="@+id/push_disabled"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="106dp"
|
||||
android:background="#dd555555"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="106dp"
|
||||
android:background="#aa000000"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:padding="15dp"
|
||||
android:visibility="gone">
|
||||
@ -78,11 +80,11 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="#ff444444"
|
||||
android:background="#dd222222"
|
||||
android:textColor="#ffeeeeee"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:padding="8dp"
|
||||
android:textSize="16dp"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/GroupCreateActivity_contacts_dont_support_push" />
|
||||
|
||||
</RelativeLayout>
|
||||
@ -91,7 +93,9 @@
|
||||
<org.thoughtcrime.securesms.components.PushRecipientsPanel
|
||||
android:id="@+id/recipients"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/selected_contacts_list"
|
||||
|
16
res/layout/single_contact_selection_activity.xml
Normal file
16
res/layout/single_contact_selection_activity.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout android:layout_gravity="center"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="vertical"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<fragment
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/contact_selection_list_fragment"
|
||||
android:name="org.thoughtcrime.securesms.SingleContactSelectionListFragment">
|
||||
</fragment>
|
||||
|
||||
</LinearLayout>
|
29
res/layout/single_contact_selection_list_activity.xml
Normal file
29
res/layout/single_contact_selection_list_activity.xml
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText android:id="@+id/filter"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Type a name to filter..."
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginBottom="7dp" />
|
||||
|
||||
<ListView android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fastScrollEnabled="true" />
|
||||
|
||||
<TextView android:id="@android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center|center_vertical"
|
||||
android:layout_marginTop="15dp"
|
||||
android:text="@string/contact_selection_group_activity__no_contacts"
|
||||
android:textSize="20sp" />
|
||||
|
||||
</LinearLayout>
|
53
res/layout/single_contact_selection_list_item.xml
Normal file
53
res/layout/single_contact_selection_list_item.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:paddingRight="25dip">
|
||||
|
||||
<TextView android:id="@+id/label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginBottom="8dip"
|
||||
android:layout_marginTop="-8dip"
|
||||
android:layout_marginLeft="14dip"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textStyle="bold"
|
||||
android:visibility = "gone"
|
||||
/>
|
||||
|
||||
<TextView android:id="@+id/number"
|
||||
android:visibility = "visible"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dip"
|
||||
android:layout_marginTop="-8dip"
|
||||
android:layout_marginLeft="14dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:fontFamily="sans-serif-light"
|
||||
/>
|
||||
|
||||
<TextView android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/number"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginBottom="1dip"
|
||||
android:layout_marginLeft="14dip"
|
||||
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:gravity="center_vertical|left"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
@ -118,10 +118,9 @@
|
||||
|
||||
<!-- GroupCreateActivity -->
|
||||
<string name="GroupCreateActivity_actionbar_title">New Group</string>
|
||||
<string name="GroupCreateActivity_group_name_hint">Group Name</string>
|
||||
<string name="GroupCreateActivity_actionbar_mms_title">New MMS Group</string>
|
||||
<string name="GroupCreateActivity_contacts_dont_support_push">You have selected contacts that
|
||||
don\'t support TextSecure groups, so this will be an unencrypted MMS group.
|
||||
</string>
|
||||
<string name="GroupCreateActivity_contacts_dont_support_push">You have selected a contact that doesn\'t support TextSecure groups, so this group will be MMS.</string>
|
||||
|
||||
<!-- ImportFragment -->
|
||||
<string name="ImportFragment_import_system_sms_database">Import System SMS Database?</string>
|
||||
@ -377,7 +376,10 @@
|
||||
<!-- contact_selection_group_activity -->
|
||||
<!-- contact_selection_list_activity -->
|
||||
<string name="contact_selection_group_activity__no_contacts">No contacts.</string>
|
||||
<string name="contact_selection_group_activity__finding_contacts">Finding contacts...</string>
|
||||
<string name="contact_selection_group_activity__finding_contacts">Finding contacts…</string>
|
||||
|
||||
<!-- single_contact_selection_activity -->
|
||||
<string name="single_contact_selection_group_activity__filter">Type a name to filter…</string>
|
||||
|
||||
<!-- ContactSelectionListFragment-->
|
||||
<string name="ContactSelectionlistFragment_select_for">Select for</string>
|
||||
@ -569,6 +571,7 @@
|
||||
<string name="AndroidManifest__create_passphrase">Create Passphrase</string>
|
||||
<string name="AndroidManifest__enter_passphrase">Enter Passphrase</string>
|
||||
<string name="AndroidManifest__select_contacts">Select Contacts</string>
|
||||
<string name="AndroidManifest__select_contact">Select Contact</string>
|
||||
<string name="AndroidManifest__textsecure_detected">TextSecure Detected</string>
|
||||
<string name="AndroidManifest__public_identity_key">Public Identity Key</string>
|
||||
<string name="AndroidManifest__change_passphrase">Change Passphrase</string>
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -167,13 +166,13 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (!isExistingConversation())
|
||||
initializeRecipientsInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
if (recipients == null || recipients.isEmpty())
|
||||
initializeRecipientsInput();
|
||||
|
||||
super.onResume();
|
||||
dynamicTheme.onResume(this);
|
||||
dynamicLanguage.onResume(this);
|
||||
@ -207,28 +206,30 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
Log.w("ComposeMessageActivity", "onActivityResult called: " + resultCode + " , " + data);
|
||||
super.onActivityResult(reqCode, resultCode, data);
|
||||
|
||||
if (data == null || resultCode != Activity.RESULT_OK)
|
||||
return;
|
||||
|
||||
switch (reqCode) {
|
||||
case PICK_CONTACT:
|
||||
List<ContactData> contacts = data.getParcelableArrayListExtra("contacts");
|
||||
|
||||
if (contacts != null)
|
||||
recipientsPanel.addContacts(contacts);
|
||||
|
||||
if (resultCode == RESULT_OK) {
|
||||
List<ContactData> contacts = data.getParcelableArrayListExtra("contacts");
|
||||
if (contacts != null) {
|
||||
recipientsPanel.addContacts(contacts);
|
||||
this.recipients = getRecipients();
|
||||
}
|
||||
} else {
|
||||
Log.w("ConversationActivity", "gonna have a bad time.");
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
case PICK_IMAGE:
|
||||
addAttachmentImage(data.getData());
|
||||
if (data != null && resultCode == RESULT_OK) addAttachmentImage(data.getData());
|
||||
break;
|
||||
case PICK_VIDEO:
|
||||
addAttachmentVideo(data.getData());
|
||||
if (data != null && resultCode == RESULT_OK) addAttachmentVideo(data.getData());
|
||||
break;
|
||||
case PICK_AUDIO:
|
||||
addAttachmentAudio(data.getData());
|
||||
if (data != null && resultCode == RESULT_OK) addAttachmentAudio(data.getData());
|
||||
break;
|
||||
case PICK_CONTACT_INFO:
|
||||
addContactInfo(data.getData());
|
||||
if (data != null && resultCode == RESULT_OK) addContactInfo(data.getData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -649,16 +650,9 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
}
|
||||
|
||||
private void initializeRecipientsInput() {
|
||||
recipientsPanel.setVisibility(View.VISIBLE);
|
||||
|
||||
if (this.recipients != null) {
|
||||
recipientsPanel.addRecipients(this.recipients);
|
||||
} else {
|
||||
InputMethodManager input = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
input.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
|
||||
}
|
||||
Intent intent = new Intent(ConversationActivity.this, SingleContactSelectionActivity.class);
|
||||
startActivityForResult(intent, PICK_CONTACT);
|
||||
}
|
||||
|
||||
private void initializeReceivers() {
|
||||
securityUpdateReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@ -846,7 +840,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
if (isExistingConversation()) return this.recipients;
|
||||
else return recipientsPanel.getRecipients();
|
||||
} catch (RecipientFormattingException rfe) {
|
||||
Log.w("ConversationActivity", rfe);
|
||||
Log.d("ConversationActivity", "Empty list of recipients retrieved from RecipientsPanel.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (editable.length() > 0)
|
||||
getSupportActionBar().setTitle(editable);
|
||||
getSupportActionBar().setTitle(getString(R.string.GroupCreateActivity_actionbar_title) + ": " + editable.toString());
|
||||
else
|
||||
getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_title);
|
||||
}
|
||||
|
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Filter;
|
||||
import android.widget.FilterQueryProvider;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.util.ActionBarUtil;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
|
||||
/**
|
||||
* Activity container for selecting a list of contacts. Provides a tab frame for
|
||||
* contact, group, and "recent contact" activity tabs. Used by ComposeMessageActivity
|
||||
* when selecting a list of contacts to address a message to.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
public class SingleContactSelectionActivity extends PassphraseRequiredSherlockFragmentActivity {
|
||||
private final String TAG = "SingleContactSelectionActivity";
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
dynamicTheme.onCreate(this);
|
||||
super.onCreate(icicle);
|
||||
|
||||
final ActionBar actionBar = this.getSupportActionBar();
|
||||
ActionBarUtil.initializeDefaultActionBar(this, actionBar);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
setContentView(R.layout.single_contact_selection_activity);
|
||||
final SingleContactSelectionListFragment listFragment = (SingleContactSelectionListFragment)getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
|
||||
listFragment.setOnContactSelectedListener(new SingleContactSelectionListFragment.OnContactSelectedListener() {
|
||||
@Override
|
||||
public void onContactSelected(ContactData contactData) {
|
||||
Intent resultIntent = getIntent();
|
||||
ArrayList<ContactData> contactList = new ArrayList<ContactData>();
|
||||
contactList.add(contactData);
|
||||
resultIntent.putParcelableArrayListExtra("contacts", contactList);
|
||||
setResult(RESULT_OK, resultIntent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
EditText filter = (EditText)findViewById(R.id.filter);
|
||||
filter.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
final CursorAdapter adapter = (CursorAdapter)listFragment.getListView().getAdapter();
|
||||
Log.i(TAG, "new text change: " + editable);
|
||||
Filter filter = adapter.getFilter();
|
||||
|
||||
if (filter != null) { filter.filter(editable.toString()); adapter.notifyDataSetChanged(); }
|
||||
else { Log.w(TAG, "filter was null, bad time."); }
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
dynamicTheme.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,298 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.database.Cursor;
|
||||
import android.database.MergeCursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.FilterQueryProvider;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Activity for selecting a list of contacts. Displayed inside
|
||||
* a PushContactSelectionActivity tab frame, and ultimately called by
|
||||
* ComposeMessageActivity for selecting a list of destination contacts.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
|
||||
public class SingleContactSelectionListFragment extends SherlockListFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>
|
||||
{
|
||||
private final String TAG = "SingleContactSelectionListFragment";
|
||||
private final HashMap<Long, ContactData> selectedContacts = new HashMap<Long, ContactData>();
|
||||
private static LayoutInflater li;
|
||||
private OnContactSelectedListener onContactSelectedListener;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
initializeResources();
|
||||
initializeCursor();
|
||||
}
|
||||
|
||||
public void setOnContactSelectedListener(OnContactSelectedListener onContactSelectedListener) {
|
||||
this.onContactSelectedListener = onContactSelectedListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.single_contact_selection_list_activity, container, false);
|
||||
}
|
||||
|
||||
private void addSingleNumberContact(ContactData contactData) {
|
||||
if (onContactSelectedListener != null) {
|
||||
onContactSelectedListener.onContactSelected(contactData);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMultipleNumberContact(ContactData contactData, TextView textView) {
|
||||
String[] options = new String[contactData.numbers.size()];
|
||||
int i = 0;
|
||||
|
||||
for (NumberData option : contactData.numbers) {
|
||||
options[i++] = option.type + " " + option.number;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.ContactSelectionlistFragment_select_for + " " + contactData.name);
|
||||
builder.setMultiChoiceItems(options, null, new DiscriminatorClickedListener(contactData));
|
||||
builder.setPositiveButton(android.R.string.ok, new DiscriminatorFinishedListener(contactData, textView));
|
||||
builder.setOnCancelListener(new DiscriminatorFinishedListener(contactData, textView));
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void initializeCursor() {
|
||||
final ContactSelectionListAdapter listAdapter = new ContactSelectionListAdapter(getActivity(), null);
|
||||
listAdapter.setFilterQueryProvider(new FilterQueryProvider() {
|
||||
@Override
|
||||
public Cursor runQuery(CharSequence charSequence) {
|
||||
final Uri uri = ContactsContract.Contacts.CONTENT_URI;
|
||||
final String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1" +
|
||||
" AND " + ContactsContract.Contacts.DISPLAY_NAME + " like ?";
|
||||
|
||||
final Cursor filteredCursor = getActivity().getContentResolver().query(uri, null, selection, new String[]{"%"+charSequence.toString()+"%"},
|
||||
ContactsContract.Contacts.DISPLAY_NAME + " ASC");
|
||||
return filteredCursor;
|
||||
}
|
||||
});
|
||||
setListAdapter(listAdapter);
|
||||
this.getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.getListView().setFocusable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
((ContactItemView)v).selected();
|
||||
}
|
||||
|
||||
private class ContactSelectionListAdapter extends CursorAdapter {
|
||||
|
||||
public ContactSelectionListAdapter(Context context, Cursor c) {
|
||||
super(context, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
ContactItemView view = new ContactItemView(context);
|
||||
bindView(view, context, cursor);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
boolean isPushUser;
|
||||
try {
|
||||
isPushUser = (cursor.getInt(cursor.getColumnIndexOrThrow(ContactAccessor.PUSH_COLUMN)) > 0);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
isPushUser = false;
|
||||
}
|
||||
ContactData contactData = ContactAccessor.getInstance().getContactData(context, cursor);
|
||||
PushContactData pushContactData = new PushContactData(contactData, isPushUser);
|
||||
((ContactItemView)view).set(pushContactData);
|
||||
}
|
||||
}
|
||||
|
||||
private class PushContactData {
|
||||
private final ContactData contactData;
|
||||
private final boolean pushSupport;
|
||||
public PushContactData(ContactData contactData, boolean pushSupport) {
|
||||
this.contactData = contactData;
|
||||
this.pushSupport = pushSupport;
|
||||
}
|
||||
}
|
||||
|
||||
private class ContactItemView extends RelativeLayout {
|
||||
private ContactData contactData;
|
||||
private boolean pushSupport;
|
||||
private TextView name;
|
||||
private TextView number;
|
||||
private TextView label;
|
||||
private View pushLabel;
|
||||
|
||||
public ContactItemView(Context context) {
|
||||
super(context);
|
||||
|
||||
li.inflate(R.layout.single_contact_selection_list_item, this, true);
|
||||
|
||||
this.name = (TextView) findViewById(R.id.name);
|
||||
this.number = (TextView) findViewById(R.id.number);
|
||||
this.label = (TextView) findViewById(R.id.label);
|
||||
this.pushLabel = findViewById(R.id.push_support_label);
|
||||
}
|
||||
|
||||
public void selected() {
|
||||
if (contactData.numbers.size() == 1) addSingleNumberContact(contactData);
|
||||
else addMultipleNumberContact(contactData, name);
|
||||
}
|
||||
|
||||
public void set(PushContactData pushContactData) {
|
||||
this.contactData = pushContactData.contactData;
|
||||
this.pushSupport = pushContactData.pushSupport;
|
||||
|
||||
/*if (!pushSupport) {
|
||||
this.name.setTextColor(0xa0000000);
|
||||
this.number.setTextColor(0xa0000000);
|
||||
this.pushLabel.setBackgroundColor(0x99000000);
|
||||
} else {
|
||||
this.name.setTextColor(0xff000000);
|
||||
this.number.setTextColor(0xff000000);
|
||||
this.pushLabel.setBackgroundColor(0xff64a926);
|
||||
}*/
|
||||
|
||||
this.name.setText(contactData.name);
|
||||
|
||||
if (contactData.numbers.isEmpty()) {
|
||||
this.name.setEnabled(false);
|
||||
this.number.setText("");
|
||||
this.label.setText("");
|
||||
} else {
|
||||
this.number.setText(contactData.numbers.get(0).number);
|
||||
this.label.setText(contactData.numbers.get(0).type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DiscriminatorFinishedListener implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
|
||||
private final ContactData contactData;
|
||||
private final TextView textView;
|
||||
|
||||
public DiscriminatorFinishedListener(ContactData contactData, TextView textView) {
|
||||
this.contactData = contactData;
|
||||
this.textView = textView;
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ContactData selected = selectedContacts.get(contactData.id);
|
||||
|
||||
if (selected.numbers.size() == 0) {
|
||||
selectedContacts.remove(selected.id);
|
||||
}
|
||||
|
||||
if (textView == null)
|
||||
((CursorAdapter) getListView().getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
onClick(dialog, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private class DiscriminatorClickedListener implements DialogInterface.OnMultiChoiceClickListener {
|
||||
private final ContactData contactData;
|
||||
|
||||
public DiscriminatorClickedListener(ContactData contactData) {
|
||||
this.contactData = contactData;
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
Log.w(TAG, "Got checked: " + isChecked);
|
||||
|
||||
ContactData existing = selectedContacts.get(contactData.id);
|
||||
|
||||
if (existing == null) {
|
||||
Log.w(TAG, "No existing contact data, creating...");
|
||||
|
||||
if (!isChecked)
|
||||
throw new AssertionError("We shouldn't be unchecking data that doesn't exist.");
|
||||
|
||||
existing = new ContactData(contactData.id, contactData.name);
|
||||
selectedContacts.put(existing.id, existing);
|
||||
}
|
||||
|
||||
NumberData selectedData = contactData.numbers.get(which);
|
||||
|
||||
if (!isChecked) existing.numbers.remove(selectedData);
|
||||
else existing.numbers.add(selectedData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return ContactAccessor.getInstance().getCursorLoaderForContactsWithNumbers(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
((CursorAdapter) getListAdapter()).changeCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> arg0) {
|
||||
((CursorAdapter) getListAdapter()).changeCursor(null);
|
||||
}
|
||||
|
||||
public interface OnContactSelectedListener {
|
||||
public void onContactSelected(ContactData contactData);
|
||||
}
|
||||
}
|
@ -79,14 +79,6 @@ public class PushRecipientsPanel extends RelativeLayout {
|
||||
else recipientsText.append(number + ", ");
|
||||
}
|
||||
|
||||
public void addContacts(List<ContactAccessor.ContactData> contacts) {
|
||||
for (ContactAccessor.ContactData contact : contacts) {
|
||||
for (ContactAccessor.NumberData number : contact.numbers) {
|
||||
addRecipient(contact.name, number.number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addRecipients(Recipients recipients) {
|
||||
List<Recipient> recipientList = recipients.getRecipientsList();
|
||||
Iterator<Recipient> iterator = recipientList.iterator();
|
||||
@ -130,8 +122,8 @@ public class PushRecipientsPanel extends RelativeLayout {
|
||||
}
|
||||
|
||||
private void initRecipientsEditor() {
|
||||
Recipients recipients = null;
|
||||
recipientsText = (RecipientsEditor)findViewById(R.id.recipients_text);
|
||||
Recipients recipients;
|
||||
recipientsText = (RecipientsEditor)findViewById(R.id.recipients_text);
|
||||
|
||||
try {
|
||||
recipients = getRecipients();
|
||||
|
@ -102,6 +102,7 @@ public class ContactAccessor {
|
||||
try {
|
||||
if (lookupCursor != null && lookupCursor.moveToFirst()) {
|
||||
cursor.addRow(new Object[]{lookupCursor.getLong(0), lookupCursor.getString(1), 1});
|
||||
Log.w("poop", "Adding matrix row for " + lookupCursor.getLong(0) + " : " + lookupCursor.getString(1));
|
||||
}
|
||||
} finally {
|
||||
if (lookupCursor != null)
|
||||
|
@ -111,7 +111,7 @@ public class MmsCommunication {
|
||||
Log.w("MmsCommunication", sqe);
|
||||
return getLocalMmsConnectionParameters(context);
|
||||
} catch (SecurityException se) {
|
||||
Log.w("MmsCommunication", se);
|
||||
Log.i("MmsCommunication", "Couldn't write APN settings, expected. msg: " + se.getMessage());
|
||||
return getLocalMmsConnectionParameters(context);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
Log.w("MmsCommunication", iae);
|
||||
|
Loading…
x
Reference in New Issue
Block a user