Rework the list interface

Display the shortcut in the list, and remove the cross button.

Bug: 6026080
Change-Id: I7f594f07a84e4df3ad5b8160129d92d1a4b0fc28
This commit is contained in:
Jean Chalard
2012-05-09 17:47:17 +09:00
parent c4c4b916eb
commit 99e509cc4c
2 changed files with 47 additions and 46 deletions

View File

@@ -17,34 +17,36 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:minHeight="?android:attr/listPreferredItemHeight"
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingLeft="16dip" android:paddingRight="?android:attr/scrollbarSize"
android:minHeight="?android:attr/listPreferredItemHeight"/> android:background="?android:attr/selectableItemBackground" >
<ImageView <RelativeLayout android:layout_width="wrap_content"
android:id="@+id/divider" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_marginLeft="15dip"
android:layout_height="match_parent" android:layout_marginRight="6dip"
android:layout_gravity="center" android:layout_marginTop="6dip"
android:layout_marginLeft="8dip" android:layout_marginBottom="6dip"
android:src="@drawable/nav_divider" android:layout_weight="1">
/>
<ImageView <TextView android:id="@+android:id/text1"
android:id="@+id/delete_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:singleLine="true"
android:padding="8dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:src="@drawable/ic_item_delete" android:ellipsize="marquee"
android:background="?android:attr/selectableItemBackground" android:fadingEdge="horizontal" />
/>
<TextView android:id="@+android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/text1"
android:layout_alignLeft="@android:id/text1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="1" />
</RelativeLayout>
</LinearLayout> </LinearLayout>

View File

@@ -28,6 +28,7 @@ import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.provider.UserDictionary; import android.provider.UserDictionary;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@@ -53,11 +54,11 @@ public class UserDictionarySettings extends ListFragment {
private static final String TAG = "UserDictionarySettings"; private static final String TAG = "UserDictionarySettings";
private static final String[] QUERY_PROJECTION = { private static final String[] QUERY_PROJECTION = {
UserDictionary.Words._ID, UserDictionary.Words.WORD UserDictionary.Words._ID, UserDictionary.Words.WORD, UserDictionary.Words.SHORTCUT
}; };
private static final int INDEX_ID = 0; // The index of the shortcut in the above array.
private static final int INDEX_WORD = 1; private static final int INDEX_SHORTCUT = 2;
// Either the locale is empty (means the word is applicable to all locales) // Either the locale is empty (means the word is applicable to all locales)
// or the word equals our current locale // or the word equals our current locale
@@ -148,8 +149,8 @@ public class UserDictionarySettings extends ListFragment {
private ListAdapter createAdapter() { private ListAdapter createAdapter() {
return new MyAdapter(getActivity(), return new MyAdapter(getActivity(),
R.layout.user_dictionary_item, mCursor, R.layout.user_dictionary_item, mCursor,
new String[] { UserDictionary.Words.WORD, UserDictionary.Words._ID }, new String[] { UserDictionary.Words.WORD, UserDictionary.Words.SHORTCUT },
new int[] { android.R.id.text1, R.id.delete_button }, this); new int[] { android.R.id.text1, android.R.id.text2 }, this);
} }
@Override @Override
@@ -211,18 +212,22 @@ public class UserDictionarySettings extends ListFragment {
UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word }); UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word });
} }
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer, private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
View.OnClickListener {
private AlphabetIndexer mIndexer; private AlphabetIndexer mIndexer;
private UserDictionarySettings mSettings;
private ViewBinder mViewBinder = new ViewBinder() { private ViewBinder mViewBinder = new ViewBinder() {
public boolean setViewValue(View v, Cursor c, int columnIndex) { public boolean setViewValue(View v, Cursor c, int columnIndex) {
if (v instanceof ImageView && columnIndex == INDEX_ID) { if (columnIndex == INDEX_SHORTCUT) {
v.setOnClickListener(MyAdapter.this); final String shortcut = c.getString(INDEX_SHORTCUT);
v.setTag(c.getString(INDEX_WORD)); if (TextUtils.isEmpty(shortcut)) {
v.setVisibility(View.GONE);
} else {
((TextView)v).setText(shortcut);
v.setVisibility(View.VISIBLE);
}
v.invalidate();
return true; return true;
} }
@@ -234,7 +239,6 @@ public class UserDictionarySettings extends ListFragment {
UserDictionarySettings settings) { UserDictionarySettings settings) {
super(context, layout, c, from, to); super(context, layout, c, from, to);
mSettings = settings;
if (null != c) { if (null != c) {
final String alphabet = context.getString( final String alphabet = context.getString(
com.android.internal.R.string.fast_scroll_alphabet); com.android.internal.R.string.fast_scroll_alphabet);
@@ -255,10 +259,5 @@ public class UserDictionarySettings extends ListFragment {
public Object[] getSections() { public Object[] getSections() {
return null == mIndexer ? null : mIndexer.getSections(); return null == mIndexer ? null : mIndexer.getSections();
} }
public void onClick(View v) {
UserDictionarySettings.deleteWord((String) v.getTag(),
mSettings.getActivity().getContentResolver());
}
} }
} }