Skip to content
This repository was archived by the owner on Apr 21, 2021. It is now read-only.

Commit 4294140

Browse files
author
AndroidDeveloperLB
committed
bugfix: updated demo (for those who don't wish to use the read-contacts permission) , so that clicking on a chip will not cause a crash, but instead will allow you to delete the chip.
1 parent dc02ee7 commit 4294140

6 files changed

Lines changed: 140 additions & 32 deletions

File tree

‎ChipsLibrary/src/com/android/ex/chips/RecipientAlternatesAdapter.java‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ public RecipientAlternatesAdapter(final Context context,final long contactId,fin
277277
this(context,contactId,currentId,QUERY_TYPE_EMAIL,listener);
278278
}
279279

280-
public RecipientAlternatesAdapter(final Context context,final long contactId,final long currentId,final int queryMode,final OnCheckedItemChangedListener listener)
280+
public RecipientAlternatesAdapter(final Context context,final long contactId,final long currentId,//
281+
final int queryMode,final OnCheckedItemChangedListener listener)
281282
{
282283
super(context,getCursorForConstruction(context,contactId,queryMode),0);
283284
mLayoutInflater=LayoutInflater.from(context);
@@ -294,7 +295,24 @@ else if(queryMode==QUERY_TYPE_PHONE)
294295
}
295296
}
296297

297-
private static Cursor getCursorForConstruction(final Context context,final long contactId,final int queryType)
298+
public RecipientAlternatesAdapter(final Context context,final Cursor c,final long currentId,final int queryMode,final OnCheckedItemChangedListener listener)
299+
{
300+
super(context,c,0);
301+
mLayoutInflater=LayoutInflater.from(context);
302+
mCurrentId=currentId;
303+
mCheckedItemChangedListener=listener;
304+
if(queryMode==QUERY_TYPE_EMAIL)
305+
mQuery=Queries.EMAIL;
306+
else if(queryMode==QUERY_TYPE_PHONE)
307+
mQuery=Queries.PHONE;
308+
else
309+
{
310+
mQuery=Queries.EMAIL;
311+
Log.e(TAG,"Unsupported query type: "+queryMode);
312+
}
313+
}
314+
315+
protected static Cursor getCursorForConstruction(final Context context,final long contactId,final int queryType)
298316
{
299317
final Cursor cursor;
300318
if(queryType==QUERY_TYPE_EMAIL)

‎ChipsLibrary/src/com/android/ex/chips/RecipientEditTextView.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ protected void onPostExecute(final ListAdapter result)
14871487
}.execute((Void[])null);
14881488
}
14891489

1490-
private ListAdapter createAlternatesAdapter(final DrawableRecipientChip chip)
1490+
protected ListAdapter createAlternatesAdapter(final DrawableRecipientChip chip)
14911491
{
14921492
return new RecipientAlternatesAdapter(getContext(),chip.getContactId(),chip.getDataId(),getAdapter().getQueryType(),this);
14931493
}

‎ChipsSample/AndroidManifest.xml‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.android.ex.chips.sample"
4-
android:versionCode="1"
5-
android:versionName="1.0" >
3+
package="com.android.ex.chips.sample"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
66

7-
<uses-sdk
8-
android:minSdkVersion="11"
9-
android:targetSdkVersion="19" />
7+
<uses-sdk
8+
android:minSdkVersion="11"
9+
android:targetSdkVersion="19" />
1010

11-
<uses-permission android:name="android.permission.READ_CONTACTS" />
11+
<uses-permission android:name="android.permission.READ_CONTACTS" />
1212

13-
<application
14-
android:allowBackup="true"
15-
android:icon="@drawable/ic_launcher"
16-
android:label="@string/app_name"
17-
android:theme="@android:style/Theme.Holo.Light" >
18-
<activity
19-
android:name="com.android.ex.chips.sample.MainActivity"
20-
android:label="@string/app_name">
21-
<intent-filter>
22-
<action android:name="android.intent.action.MAIN" />
13+
<application
14+
android:allowBackup="true"
15+
android:icon="@drawable/ic_launcher"
16+
android:label="@string/app_name"
17+
android:theme="@android:style/Theme.Holo.Light" >
18+
<activity
19+
android:name="com.android.ex.chips.sample.MainActivity"
20+
android:label="@string/app_name" >
21+
<intent-filter>
22+
<action android:name="android.intent.action.MAIN" />
2323

24-
<category android:name="android.intent.category.LAUNCHER" />
25-
</intent-filter>
26-
</activity>
27-
</application>
24+
<category android:name="android.intent.category.LAUNCHER" />
25+
</intent-filter>
26+
</activity>
27+
</application>
2828

2929
</manifest>

‎ChipsSample/res/layout/custom_recipient_sample_fragment.xml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
android:layout_height="wrap_content"
1616
android:text="@string/custom_recipients_tutorial" />
1717

18-
<com.android.ex.chips.RecipientEditTextView
18+
<com.android.ex.chips.sample.CustomRecipientEditTextView
1919
android:id="@+id/custom_retv"
2020
android:layout_width="match_parent"
2121
android:layout_height="wrap_content"
22-
android:minHeight="58dp" >
23-
24-
</com.android.ex.chips.RecipientEditTextView>
22+
android:minHeight="58dp" />
2523

2624
<Button
2725
android:id="@+id/addRecipientButton"
@@ -39,8 +37,9 @@
3937

4038
<TextView
4139
android:id="@+id/availableRecipientsTextView"
42-
android:layout_width="wrap_content" android:text="@string/available_recipients_list_"
43-
android:layout_height="wrap_content" />
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
android:text="@string/available_recipients_list_" />
4443
</LinearLayout>
4544

4645
</ScrollView>

‎ChipsSample/res/values/strings.xml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
<string name="all_my_repositories">All my repositories</string>
1212
<string name="all_my_apps">All my apps</string>
1313
<string name="more_info">More info</string>
14-
<string name="device_recipients_tutorial">This demonstrates how to use the device\'s contacts as the list of recipients.</string> <string name="device_recipients_tutorial_unavailable">This demonstrates how to use the device\'s contacts as the list of recipients.
14+
<string name="device_recipients_tutorial">This demonstrates how to use the device\'s contacts as the list of recipients.</string>
15+
<string name="device_recipients_tutorial_unavailable">This demonstrates how to use the device\'s contacts as the list of recipients.
1516
\nIt\'s not supported for the demo versions, as they don\'t allow using the permission to read from contacts
1617
\nIn order to check out the full sample, you need to check out the original code</string>
17-
<string name="custom_recipients_tutorial">This demonstrates how to put your own customized list of recipients</string>
18+
<string name="custom_recipients_tutorial">This demonstrates how to put your own customized list of recipients.
19+
\nIt shows fake contacts, and as opposed to the original sample, clicking a chip will only allow you to remove it, instead of showing alternatives to choose from.
20+
\nOf course, it\'s possible to do it yourself&#8230;</string>
1821
<string name="available_recipients_list_">available recipients list:</string>
1922

2023
</resources>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.android.ex.chips.sample;
2+
import android.content.Context;
3+
import android.database.AbstractCursor;
4+
import android.database.Cursor;
5+
import android.provider.BaseColumns;
6+
import android.util.AttributeSet;
7+
import android.widget.ListAdapter;
8+
import com.android.ex.chips.RecipientAlternatesAdapter;
9+
import com.android.ex.chips.RecipientEditTextView;
10+
import com.android.ex.chips.recipientchip.DrawableRecipientChip;
11+
12+
/** this class is provided just for the demo, which doesn't have read-contacts permission */
13+
public class CustomRecipientEditTextView extends RecipientEditTextView
14+
{
15+
public CustomRecipientEditTextView(final Context context,final AttributeSet attrs)
16+
{
17+
super(context,attrs);
18+
}
19+
20+
protected Cursor getCursorForConstruction(final Context context,final long contactId,final int queryType)
21+
{
22+
return new AbstractCursor()
23+
{
24+
@Override
25+
public boolean isNull(final int column)
26+
{
27+
return false;
28+
}
29+
30+
@Override
31+
public String getString(final int column)
32+
{
33+
return null;
34+
}
35+
36+
@Override
37+
public short getShort(final int column)
38+
{
39+
return 0;
40+
}
41+
42+
@Override
43+
public long getLong(final int column)
44+
{
45+
return 0;
46+
}
47+
48+
@Override
49+
public int getInt(final int column)
50+
{
51+
return 0;
52+
}
53+
54+
@Override
55+
public float getFloat(final int column)
56+
{
57+
return 0;
58+
}
59+
60+
@Override
61+
public double getDouble(final int column)
62+
{
63+
return 0;
64+
}
65+
66+
@Override
67+
public int getCount()
68+
{
69+
return 0;
70+
}
71+
72+
@Override
73+
public String[] getColumnNames()
74+
{
75+
return new String[] {BaseColumns._ID};
76+
}
77+
};
78+
}
79+
80+
@Override
81+
protected ListAdapter createAlternatesAdapter(final DrawableRecipientChip chip)
82+
{
83+
return new RecipientAlternatesAdapter(getContext(),//
84+
getCursorForConstruction(getContext(),chip.getContactId(),getAdapter().getQueryType()),//
85+
chip.getDataId(),getAdapter().getQueryType(),this)
86+
{};
87+
}
88+
}

0 commit comments

Comments
 (0)