Loading res/layout/contact_detail_add_connection_entry_view.xml 0 → 100644 +54 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* * Copyright 2012, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="@dimen/detail_item_side_margin" android:paddingRight="@dimen/detail_item_side_margin"> <LinearLayout android:id="@+id/primary_action_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="@dimen/detail_item_vertical_margin" android:paddingBottom="@dimen/detail_item_vertical_margin" android:focusable="true" android:background="?android:attr/selectableItemBackground" android:minHeight="@dimen/detail_min_line_item_height" android:orientation="horizontal" android:gravity="center_vertical"> <ImageView android:id="@+id/add_connection_icon" android:layout_width="@dimen/detail_network_icon_size" android:layout_height="@dimen/detail_network_icon_size" android:layout_marginLeft="@dimen/detail_item_icon_margin" android:layout_marginRight="@dimen/detail_item_icon_margin" android:layout_gravity="center_vertical" android:scaleType="centerInside" /> <TextView android:id="@+id/add_connection_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textAppearance="?android:attr/textAppearanceMedium"/> </LinearLayout> </FrameLayout> res/layout/contact_detail_network_title_entry_view.xml +2 −1 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="?android:attr/textColorSecondary" /> </LinearLayout> </FrameLayout> src/com/android/contacts/detail/ContactDetailFragment.java +89 −28 Original line number Diff line number Diff line Loading @@ -811,7 +811,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen for (AccountType accountType : mOtherEntriesMap.keySet()) { // Add a title for each third party app mAllEntries.add(NetworkTitleViewEntry.fromAccountType(mContext, accountType)); mAllEntries.add(new NetworkTitleViewEntry(mContext, accountType)); for (DetailViewEntry detailEntry : mOtherEntriesMap.get(accountType)) { // Add indented separator Loading Loading @@ -867,7 +867,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen }; // Finally create the entry. mAllEntries.add(NetworkTitleViewEntry.forMoreNetworks(mContext, onClickListener)); mAllEntries.add(new AddConnectionViewEntry(mContext, onClickListener)); } /** Loading Loading @@ -1124,35 +1124,43 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } /** * A title for a section of contact details from a single 3rd party network. It's also * used for the "More networks" entry, which has the same layout. * A title for a section of contact details from a single 3rd party network. */ private static class NetworkTitleViewEntry extends ViewEntry { private final Drawable mIcon; private final CharSequence mLabel; private final View.OnClickListener mOnClickListener; private NetworkTitleViewEntry(Drawable icon, CharSequence label, View.OnClickListener onClickListener) { public NetworkTitleViewEntry(Context context, AccountType type) { super(ViewAdapter.VIEW_TYPE_NETWORK_TITLE_ENTRY); this.mIcon = icon; this.mLabel = label; this.mOnClickListener = onClickListener; this.mIcon = type.getDisplayIcon(context); this.mLabel = type.getDisplayLabel(context); this.isEnabled = false; } public static NetworkTitleViewEntry fromAccountType(Context context, AccountType type) { return new NetworkTitleViewEntry( type.getDisplayIcon(context), type.getDisplayLabel(context), null); public Drawable getIcon() { return mIcon; } public static NetworkTitleViewEntry forMoreNetworks(Context context, View.OnClickListener onClickListener) { // TODO Icon is temporary. Need proper one. return new NetworkTitleViewEntry( context.getResources().getDrawable(R.drawable.ic_menu_add_field_holo_light), context.getString(R.string.add_connection_button), onClickListener); public CharSequence getLabel() { return mLabel; } } /** * This is used for the "Add Connections" entry. */ private static class AddConnectionViewEntry extends ViewEntry { private final Drawable mIcon; private final CharSequence mLabel; private final View.OnClickListener mOnClickListener; private AddConnectionViewEntry(Context context, View.OnClickListener onClickListener) { super(ViewAdapter.VIEW_TYPE_ADD_CONNECTION_ENTRY); this.mIcon = context.getResources().getDrawable( R.drawable.ic_menu_add_field_holo_light); this.mLabel = context.getString(R.string.add_connection_button); this.mOnClickListener = onClickListener; this.isEnabled = true; } @Override Loading Loading @@ -1349,6 +1357,14 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } } private static class KindTitleViewCache { public final TextView titleView; public KindTitleViewCache(View view) { titleView = (TextView)view.findViewById(R.id.title); } } /** * Cache of the children views for a view that displays a {@link NetworkTitleViewEntry} */ Loading @@ -1362,6 +1378,21 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } } /** * Cache of the children views for a view that displays a {@link AddConnectionViewEntry} */ private static class AddConnectionViewCache { public final TextView name; public final ImageView icon; public final View primaryActionView; public AddConnectionViewCache(View view) { name = (TextView) view.findViewById(R.id.add_connection_label); icon = (ImageView) view.findViewById(R.id.add_connection_icon); primaryActionView = view.findViewById(R.id.primary_action_view); } } /** * Cache of the children views of a contact detail entry represented by a * {@link DetailViewEntry} Loading Loading @@ -1406,8 +1437,9 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen public static final int VIEW_TYPE_HEADER_ENTRY = 1; public static final int VIEW_TYPE_KIND_TITLE_ENTRY = 2; public static final int VIEW_TYPE_NETWORK_TITLE_ENTRY = 3; public static final int VIEW_TYPE_SEPARATOR_ENTRY = 4; private static final int VIEW_TYPE_COUNT = 5; public static final int VIEW_TYPE_ADD_CONNECTION_ENTRY = 4; public static final int VIEW_TYPE_SEPARATOR_ENTRY = 5; private static final int VIEW_TYPE_COUNT = 6; @Override public View getView(int position, View convertView, ViewGroup parent) { Loading @@ -1422,6 +1454,8 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen return getDetailEntryView(position, convertView, parent); case VIEW_TYPE_NETWORK_TITLE_ENTRY: return getNetworkTitleEntryView(position, convertView, parent); case VIEW_TYPE_ADD_CONNECTION_ENTRY: return getAddConnectionEntryView(position, convertView, parent); default: throw new IllegalStateException("Invalid view type ID " + getItemViewType(position)); Loading Loading @@ -1519,11 +1553,19 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen private View getKindTitleEntryView(int position, View convertView, ViewGroup parent) { final KindTitleViewEntry entry = (KindTitleViewEntry) getItem(position); final View result; final KindTitleViewCache viewCache; final View result = (convertView != null) ? convertView : mInflater.inflate(R.layout.list_separator, parent, false); final TextView titleTextView = (TextView) result.findViewById(R.id.title); titleTextView.setText(entry.getTitle()); if (convertView != null) { result = convertView; viewCache = (KindTitleViewCache)result.getTag(); } else { result = mInflater.inflate(R.layout.list_separator, parent, false); viewCache = new KindTitleViewCache(result); result.setTag(viewCache); } viewCache.titleView.setText(entry.getTitle()); return result; } Loading @@ -1541,8 +1583,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen parent, false); viewCache = new NetworkTitleViewCache(result); result.setTag(viewCache); result.findViewById(R.id.primary_action_view).setOnClickListener( entry.mOnClickListener); } viewCache.name.setText(entry.getLabel()); Loading @@ -1551,6 +1591,27 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen return result; } private View getAddConnectionEntryView(int position, View convertView, ViewGroup parent) { final AddConnectionViewEntry entry = (AddConnectionViewEntry) getItem(position); final View result; final AddConnectionViewCache viewCache; if (convertView != null) { result = convertView; viewCache = (AddConnectionViewCache) result.getTag(); } else { result = mInflater.inflate(R.layout.contact_detail_add_connection_entry_view, parent, false); viewCache = new AddConnectionViewCache(result); result.setTag(viewCache); } viewCache.name.setText(entry.getLabel()); viewCache.icon.setImageDrawable(entry.getIcon()); viewCache.primaryActionView.setOnClickListener(entry.mOnClickListener); return result; } private View getDetailEntryView(int position, View convertView, ViewGroup parent) { final DetailViewEntry entry = (DetailViewEntry) getItem(position); final View v; Loading Loading
res/layout/contact_detail_add_connection_entry_view.xml 0 → 100644 +54 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* * Copyright 2012, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="@dimen/detail_item_side_margin" android:paddingRight="@dimen/detail_item_side_margin"> <LinearLayout android:id="@+id/primary_action_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="@dimen/detail_item_vertical_margin" android:paddingBottom="@dimen/detail_item_vertical_margin" android:focusable="true" android:background="?android:attr/selectableItemBackground" android:minHeight="@dimen/detail_min_line_item_height" android:orientation="horizontal" android:gravity="center_vertical"> <ImageView android:id="@+id/add_connection_icon" android:layout_width="@dimen/detail_network_icon_size" android:layout_height="@dimen/detail_network_icon_size" android:layout_marginLeft="@dimen/detail_item_icon_margin" android:layout_marginRight="@dimen/detail_item_icon_margin" android:layout_gravity="center_vertical" android:scaleType="centerInside" /> <TextView android:id="@+id/add_connection_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textAppearance="?android:attr/textAppearanceMedium"/> </LinearLayout> </FrameLayout>
res/layout/contact_detail_network_title_entry_view.xml +2 −1 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="?android:attr/textColorSecondary" /> </LinearLayout> </FrameLayout>
src/com/android/contacts/detail/ContactDetailFragment.java +89 −28 Original line number Diff line number Diff line Loading @@ -811,7 +811,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen for (AccountType accountType : mOtherEntriesMap.keySet()) { // Add a title for each third party app mAllEntries.add(NetworkTitleViewEntry.fromAccountType(mContext, accountType)); mAllEntries.add(new NetworkTitleViewEntry(mContext, accountType)); for (DetailViewEntry detailEntry : mOtherEntriesMap.get(accountType)) { // Add indented separator Loading Loading @@ -867,7 +867,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen }; // Finally create the entry. mAllEntries.add(NetworkTitleViewEntry.forMoreNetworks(mContext, onClickListener)); mAllEntries.add(new AddConnectionViewEntry(mContext, onClickListener)); } /** Loading Loading @@ -1124,35 +1124,43 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } /** * A title for a section of contact details from a single 3rd party network. It's also * used for the "More networks" entry, which has the same layout. * A title for a section of contact details from a single 3rd party network. */ private static class NetworkTitleViewEntry extends ViewEntry { private final Drawable mIcon; private final CharSequence mLabel; private final View.OnClickListener mOnClickListener; private NetworkTitleViewEntry(Drawable icon, CharSequence label, View.OnClickListener onClickListener) { public NetworkTitleViewEntry(Context context, AccountType type) { super(ViewAdapter.VIEW_TYPE_NETWORK_TITLE_ENTRY); this.mIcon = icon; this.mLabel = label; this.mOnClickListener = onClickListener; this.mIcon = type.getDisplayIcon(context); this.mLabel = type.getDisplayLabel(context); this.isEnabled = false; } public static NetworkTitleViewEntry fromAccountType(Context context, AccountType type) { return new NetworkTitleViewEntry( type.getDisplayIcon(context), type.getDisplayLabel(context), null); public Drawable getIcon() { return mIcon; } public static NetworkTitleViewEntry forMoreNetworks(Context context, View.OnClickListener onClickListener) { // TODO Icon is temporary. Need proper one. return new NetworkTitleViewEntry( context.getResources().getDrawable(R.drawable.ic_menu_add_field_holo_light), context.getString(R.string.add_connection_button), onClickListener); public CharSequence getLabel() { return mLabel; } } /** * This is used for the "Add Connections" entry. */ private static class AddConnectionViewEntry extends ViewEntry { private final Drawable mIcon; private final CharSequence mLabel; private final View.OnClickListener mOnClickListener; private AddConnectionViewEntry(Context context, View.OnClickListener onClickListener) { super(ViewAdapter.VIEW_TYPE_ADD_CONNECTION_ENTRY); this.mIcon = context.getResources().getDrawable( R.drawable.ic_menu_add_field_holo_light); this.mLabel = context.getString(R.string.add_connection_button); this.mOnClickListener = onClickListener; this.isEnabled = true; } @Override Loading Loading @@ -1349,6 +1357,14 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } } private static class KindTitleViewCache { public final TextView titleView; public KindTitleViewCache(View view) { titleView = (TextView)view.findViewById(R.id.title); } } /** * Cache of the children views for a view that displays a {@link NetworkTitleViewEntry} */ Loading @@ -1362,6 +1378,21 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } } /** * Cache of the children views for a view that displays a {@link AddConnectionViewEntry} */ private static class AddConnectionViewCache { public final TextView name; public final ImageView icon; public final View primaryActionView; public AddConnectionViewCache(View view) { name = (TextView) view.findViewById(R.id.add_connection_label); icon = (ImageView) view.findViewById(R.id.add_connection_icon); primaryActionView = view.findViewById(R.id.primary_action_view); } } /** * Cache of the children views of a contact detail entry represented by a * {@link DetailViewEntry} Loading Loading @@ -1406,8 +1437,9 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen public static final int VIEW_TYPE_HEADER_ENTRY = 1; public static final int VIEW_TYPE_KIND_TITLE_ENTRY = 2; public static final int VIEW_TYPE_NETWORK_TITLE_ENTRY = 3; public static final int VIEW_TYPE_SEPARATOR_ENTRY = 4; private static final int VIEW_TYPE_COUNT = 5; public static final int VIEW_TYPE_ADD_CONNECTION_ENTRY = 4; public static final int VIEW_TYPE_SEPARATOR_ENTRY = 5; private static final int VIEW_TYPE_COUNT = 6; @Override public View getView(int position, View convertView, ViewGroup parent) { Loading @@ -1422,6 +1454,8 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen return getDetailEntryView(position, convertView, parent); case VIEW_TYPE_NETWORK_TITLE_ENTRY: return getNetworkTitleEntryView(position, convertView, parent); case VIEW_TYPE_ADD_CONNECTION_ENTRY: return getAddConnectionEntryView(position, convertView, parent); default: throw new IllegalStateException("Invalid view type ID " + getItemViewType(position)); Loading Loading @@ -1519,11 +1553,19 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen private View getKindTitleEntryView(int position, View convertView, ViewGroup parent) { final KindTitleViewEntry entry = (KindTitleViewEntry) getItem(position); final View result; final KindTitleViewCache viewCache; final View result = (convertView != null) ? convertView : mInflater.inflate(R.layout.list_separator, parent, false); final TextView titleTextView = (TextView) result.findViewById(R.id.title); titleTextView.setText(entry.getTitle()); if (convertView != null) { result = convertView; viewCache = (KindTitleViewCache)result.getTag(); } else { result = mInflater.inflate(R.layout.list_separator, parent, false); viewCache = new KindTitleViewCache(result); result.setTag(viewCache); } viewCache.titleView.setText(entry.getTitle()); return result; } Loading @@ -1541,8 +1583,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen parent, false); viewCache = new NetworkTitleViewCache(result); result.setTag(viewCache); result.findViewById(R.id.primary_action_view).setOnClickListener( entry.mOnClickListener); } viewCache.name.setText(entry.getLabel()); Loading @@ -1551,6 +1591,27 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen return result; } private View getAddConnectionEntryView(int position, View convertView, ViewGroup parent) { final AddConnectionViewEntry entry = (AddConnectionViewEntry) getItem(position); final View result; final AddConnectionViewCache viewCache; if (convertView != null) { result = convertView; viewCache = (AddConnectionViewCache) result.getTag(); } else { result = mInflater.inflate(R.layout.contact_detail_add_connection_entry_view, parent, false); viewCache = new AddConnectionViewCache(result); result.setTag(viewCache); } viewCache.name.setText(entry.getLabel()); viewCache.icon.setImageDrawable(entry.getIcon()); viewCache.primaryActionView.setOnClickListener(entry.mOnClickListener); return result; } private View getDetailEntryView(int position, View convertView, ViewGroup parent) { final DetailViewEntry entry = (DetailViewEntry) getItem(position); final View v; Loading