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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/settings/DialerSettingsActivity.java | 83 |
1 files changed, 83 insertions, 0 deletions
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; + } + } } |