From 8b0afc7fb53b90e522b86ba04bb17c0cba2364ab Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Fri, 1 Feb 2013 17:29:15 -0800 Subject: [PATCH] App ops: improve presentation. Change-Id: Ia8702f9421a2cf2e27e8e24bfdc596321ace515a --- res/values/arrays.xml | 30 +++++-- .../settings/applications/AppOpsCategory.java | 17 +++- .../settings/applications/AppOpsDetails.java | 4 +- .../settings/applications/AppOpsState.java | 79 +++++++------------ 4 files changed, 68 insertions(+), 62 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 24d9dd00317..67e426d507b 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -561,10 +561,28 @@ - - Coarse location - Fine location + + coarse location + fine location GPS + vibrate + read contacts + write contacts + read calls + write calls + read calendar + write calendar + wi-fi scan + notification + cell scan + call phone + + + + + Location + Location + Location Vibrate Read contacts Write contacts @@ -572,12 +590,12 @@ Write calls Read calendar Write calendar - Wi-Fi scan + Location Post notification - Cell tower scan + Location Call phone - + diff --git a/src/com/android/settings/applications/AppOpsCategory.java b/src/com/android/settings/applications/AppOpsCategory.java index 7247ad38942..4e426d31c86 100644 --- a/src/com/android/settings/applications/AppOpsCategory.java +++ b/src/com/android/settings/applications/AppOpsCategory.java @@ -29,7 +29,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; import android.preference.PreferenceActivity; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -259,6 +258,17 @@ public class AppOpsCategory extends ListFragment implements } } + @Override + public boolean hasStableIds() { + return true; + } + + @Override + public long getItemId(int position) { + // XXX need to generate real id. + return position; + } + /** * Populate new items in the list. */ @@ -275,8 +285,9 @@ public class AppOpsCategory extends ListFragment implements ((ImageView)view.findViewById(R.id.app_icon)).setImageDrawable( item.getAppEntry().getIcon()); ((TextView)view.findViewById(R.id.app_name)).setText(item.getAppEntry().getLabel()); - ((TextView)view.findViewById(R.id.op_name)).setText(item.getLabelText(mState)); - ((TextView)view.findViewById(R.id.op_time)).setText(item.getTimeText(mResources)); + ((TextView)view.findViewById(R.id.op_name)).setText(item.getSummaryText(mState)); + ((TextView)view.findViewById(R.id.op_time)).setText( + item.getTimeText(mResources, false)); return view; } diff --git a/src/com/android/settings/applications/AppOpsDetails.java b/src/com/android/settings/applications/AppOpsDetails.java index 6bdd3bfebea..1e2ac7d630a 100644 --- a/src/com/android/settings/applications/AppOpsDetails.java +++ b/src/com/android/settings/applications/AppOpsDetails.java @@ -137,9 +137,9 @@ public class AppOpsDetails extends Fragment { } } ((TextView)view.findViewById(R.id.op_name)).setText( - entry.getBriefLabelText(mState)); + entry.getSwitchText(mState)); ((TextView)view.findViewById(R.id.op_time)).setText( - entry.getTimeText(res)); + entry.getTimeText(res, true)); Switch sw = (Switch)view.findViewById(R.id.switchWidget); final int switchOp = AppOpsManager.opToSwitch(firstOp.getOp()); sw.setChecked(mAppOps.checkOp(switchOp, entry.getPackageOps().getUid(), diff --git a/src/com/android/settings/applications/AppOpsState.java b/src/com/android/settings/applications/AppOpsState.java index c49e3176cbc..43fa090cdd7 100644 --- a/src/com/android/settings/applications/AppOpsState.java +++ b/src/com/android/settings/applications/AppOpsState.java @@ -47,7 +47,8 @@ public class AppOpsState { final Context mContext; final AppOpsManager mAppOps; final PackageManager mPm; - final CharSequence[] mOpNames; + final CharSequence[] mOpSummaries; + final CharSequence[] mOpLabels; List mApps; @@ -55,7 +56,8 @@ public class AppOpsState { mContext = context; mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); mPm = context.getPackageManager(); - mOpNames = context.getResources().getTextArray(R.array.app_ops_names); + mOpSummaries = context.getResources().getTextArray(R.array.app_ops_summaries); + mOpLabels = context.getResources().getTextArray(R.array.app_ops_labels); } public static class OpsTemplate implements Parcelable { @@ -226,19 +228,16 @@ public class AppOpsState { private final AppOpsManager.PackageOps mPkgOps; private final ArrayList mOps = new ArrayList(); - private final ArrayList mBriefOps + private final ArrayList mSwitchOps = new ArrayList(); private final AppEntry mApp; - public AppOpEntry(AppOpsManager.PackageOps pkg, AppOpsManager.OpEntry op, AppEntry app, - boolean brief) { + public AppOpEntry(AppOpsManager.PackageOps pkg, AppOpsManager.OpEntry op, AppEntry app) { mPkgOps = pkg; mApp = app; mApp.addOp(this, op); mOps.add(op); - if (brief) { - mBriefOps.add(op); - } + mSwitchOps.add(op); } private static void addOp(ArrayList list, AppOpsManager.OpEntry op) { @@ -259,11 +258,11 @@ public class AppOpsState { list.add(op); } - public void addOp(AppOpsManager.OpEntry op, boolean brief) { + public void addOp(AppOpsManager.OpEntry op) { mApp.addOp(this, op); addOp(mOps, op); - if (brief) { - addOp(mBriefOps, op); + if (mApp.getOpSwitch(AppOpsManager.opToSwitch(op.getOp())) == null) { + addOp(mSwitchOps, op); } } @@ -283,35 +282,35 @@ public class AppOpsState { return mOps.get(pos); } - private CharSequence getLabelText(ArrayList ops, - AppOpsState state) { + private CharSequence getCombinedText(ArrayList ops, + CharSequence[] items) { if (ops.size() == 1) { - return state.mOpNames[ops.get(0).getOp()]; + return items[ops.get(0).getOp()]; } else { StringBuilder builder = new StringBuilder(); for (int i=0; i 0) { builder.append(", "); } - builder.append(state.mOpNames[ops.get(i).getOp()]); + builder.append(items[ops.get(i).getOp()]); } return builder.toString(); } } - public CharSequence getLabelText(AppOpsState state) { - return getLabelText(mOps, state); + public CharSequence getSummaryText(AppOpsState state) { + return getCombinedText(mOps, state.mOpSummaries); } - public CharSequence getBriefLabelText(AppOpsState state) { - if (mBriefOps.size() > 0) { - return getLabelText(mBriefOps, state); + public CharSequence getSwitchText(AppOpsState state) { + if (mSwitchOps.size() > 0) { + return getCombinedText(mSwitchOps, state.mOpLabels); } else { - return getLabelText(mOps, state); + return getCombinedText(mOps, state.mOpLabels); } } - public CharSequence getTimeText(Resources res) { + public CharSequence getTimeText(Resources res, boolean showEmptyText) { if (isRunning()) { return res.getText(R.string.app_ops_running); } @@ -321,7 +320,7 @@ public class AppOpsState { DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); } - return ""; + return showEmptyText ? res.getText(R.string.app_ops_never_used) : ""; } public boolean isRunning() { @@ -358,7 +357,7 @@ public class AppOpsState { }; private void addOp(List entries, AppOpsManager.PackageOps pkgOps, - AppEntry appEntry, AppOpsManager.OpEntry opEntry, boolean brief, boolean allowMerge) { + AppEntry appEntry, AppOpsManager.OpEntry opEntry, boolean allowMerge) { if (allowMerge && entries.size() > 0) { AppOpEntry last = entries.get(entries.size()-1); if (last.getAppEntry() == appEntry) { @@ -367,17 +366,17 @@ public class AppOpsState { if (lastExe == entryExe) { if (DEBUG) Log.d(TAG, "Add op " + opEntry.getOp() + " to package " + pkgOps.getPackageName() + ": append to " + last); - last.addOp(opEntry, brief); + last.addOp(opEntry); return; } } } AppOpEntry entry = appEntry.getOpSwitch(opEntry.getOp()); if (entry != null) { - entry.addOp(opEntry, brief); + entry.addOp(opEntry); return; } - entry = new AppOpEntry(pkgOps, opEntry, appEntry, brief); + entry = new AppOpEntry(pkgOps, opEntry, appEntry); if (DEBUG) Log.d(TAG, "Add op " + opEntry.getOp() + " to package " + pkgOps.getPackageName() + ": making new " + entry); entries.add(entry); @@ -416,9 +415,7 @@ public class AppOpsState { final ArrayList perms = new ArrayList(); final ArrayList permOps = new ArrayList(); - final boolean[] brief = new boolean[AppOpsManager._NUM_OP]; for (int i=0; i 0) { - return DateUtils.getRelativeTimeSpanString(op.getTime(), - System.currentTimeMillis(), - DateUtils.MINUTE_IN_MILLIS, - DateUtils.FORMAT_ABBREV_RELATIVE); - } - return mContext.getResources().getText(R.string.app_ops_never_used); - } - }