diff options
author | Nancy Chen <nancychen@google.com> | 2014-07-21 15:19:35 -0700 |
---|---|---|
committer | Nancy Chen <nancychen@google.com> | 2014-07-21 15:40:46 -0700 |
commit | bbde565ac6005fec3b0c95fd6cf8feb9723ff02f (patch) | |
tree | 9399fb8fe50df6083d7dba7f52eea2e8ef049c9a | |
parent | ce4126734173687c887652a8914d4e9d13f6249e (diff) |
Update call settings to mocks
Increase padding and modify text spacing. See screenshot here
https://drive.google.com/a/google.com/file/d/0B0hheJjccUOjMHAycHN5Qy01MVk/view?usp=sharing
Bug: 15571286
Change-Id: Ieb3c9e0103bcf2bdfe236ba84d21897b4757faf1
-rw-r--r-- | res/layout/dialer_preferences.xml | 68 | ||||
-rw-r--r-- | res/values/dimens.xml | 7 | ||||
-rw-r--r-- | src/com/android/dialer/settings/DialerSettingsActivity.java | 83 |
3 files changed, 158 insertions, 0 deletions
diff --git a/res/layout/dialer_preferences.xml b/res/layout/dialer_preferences.xml new file mode 100644 index 000000000..bbb79bcb7 --- /dev/null +++ b/res/layout/dialer_preferences.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> + +<!-- Layout of a header item in PreferenceActivity. This is modified from the platform + preference_header_item--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="48dp" + android:background="?android:attr/activatedBackgroundIndicator" + android:gravity="center_vertical" + android:paddingEnd="?android:attr/scrollbarSize"> + + <ImageView + android:id="@+id/icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="6dip" + android:layout_marginEnd="6dip" + android:layout_gravity="center" /> + + <RelativeLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/preference_side_margin" + android:layout_marginEnd="@dimen/preference_side_margin" + android:layout_weight="1" + android:paddingTop="@dimen/preference_padding_top" + android:paddingBottom="@dimen/preference_padding_bottom"> + + <TextView android:id="@+id/title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearance" + android:textSize="16sp" + android:textColor="@color/setting_primary_color" + android:ellipsize="marquee" + android:fadingEdge="horizontal" /> + + <TextView android:id="@+id/summary" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/title" + android:layout_alignStart="@id/title" + android:textAppearance="?android:attr/textAppearanceSmall" + android:textColor="@color/setting_secondary_color" + android:lineSpacingExtra="@dimen/preference_summary_line_spacing_extra" + android:ellipsize="end" + android:maxLines="2" /> + + </RelativeLayout> + +</LinearLayout>
\ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 32cb852d8..1422420cb 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -130,4 +130,11 @@ <dimen name="shadow_length">10dp</dimen> <dimen name="empty_list_message_text_size">16sp</dimen> + + <!-- Dimensions for individual preference cards --> + <dimen name="preference_padding_top">18dp</dimen> + <dimen name="preference_padding_bottom">16dp</dimen> + <dimen name="preference_side_margin">16dp</dimen> + <dimen name="preference_list_top_padding">4dp</dimen> + <dimen name="preference_summary_line_spacing_extra">4dp</dimen> </resources> diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index 904be82b8..6d21db0db 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -1,11 +1,22 @@ package com.android.dialer.settings; +import com.google.common.collect.Lists; + +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; import android.preference.PreferenceActivity.Header; +import android.text.TextUtils; +import android.view.LayoutInflater; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListAdapter; +import android.widget.TextView; import com.android.contacts.common.preference.DisplayOptionsPreferenceFragment; import com.android.dialer.DialtactsActivity; @@ -16,11 +27,15 @@ import java.util.List; public class DialerSettingsActivity extends PreferenceActivity { protected SharedPreferences mPreferences; + private HeaderAdapter mHeaderAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPreferences = PreferenceManager.getDefaultSharedPreferences(this); + final int topPadding = getResources().getDimensionPixelSize( + R.dimen.preference_list_top_padding); + getListView().setPadding(0, topPadding, 0, 0); } @Override @@ -51,4 +66,72 @@ public class DialerSettingsActivity extends PreferenceActivity { protected boolean isValidFragment(String fragmentName) { return true; } + + @Override + public void setListAdapter(ListAdapter adapter) { + if (adapter == null) { + super.setListAdapter(null); + } else { + // We don't have access to the hidden getHeaders() method, so grab the headers from + // the intended adapter and then replace it with our own. + int headerCount = adapter.getCount(); + List<Header> headers = Lists.newArrayList(); + for (int i = 0; i < headerCount; i++) { + headers.add((Header) adapter.getItem(i)); + } + mHeaderAdapter = new HeaderAdapter(this, headers); + super.setListAdapter(mHeaderAdapter); + } + } + + /** + * This custom {@code ArrayAdapter} is mostly identical to the equivalent one in + * {@code PreferenceActivity}, except with a local layout resource. + */ + private static class HeaderAdapter extends ArrayAdapter<Header> { + static class HeaderViewHolder { + ImageView icon; + TextView title; + TextView summary; + } + + private LayoutInflater mInflater; + + public HeaderAdapter(Context context, List<Header> objects) { + super(context, 0, objects); + mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + HeaderViewHolder holder; + View view; + + if (convertView == null) { + view = mInflater.inflate(R.layout.dialer_preferences, parent, false); + holder = new HeaderViewHolder(); + holder.icon = (ImageView) view.findViewById(R.id.icon); + holder.title = (TextView) view.findViewById(R.id.title); + holder.summary = (TextView) view.findViewById(R.id.summary); + view.setTag(holder); + } else { + view = convertView; + holder = (HeaderViewHolder) view.getTag(); + } + + // All view fields must be updated every time, because the view may be recycled + Header header = getItem(position); + holder.icon.setImageResource(header.iconRes); + holder.title.setText(header.getTitle(getContext().getResources())); + CharSequence summary = header.getSummary(getContext().getResources()); + if (!TextUtils.isEmpty(summary)) { + holder.summary.setVisibility(View.VISIBLE); + holder.summary.setText(summary); + } else { + holder.summary.setVisibility(View.GONE); + } + + return view; + } + } } |