OSDN Git Service

Show gear for apps that provide general settings intent
authorJason Monk <jmonk@google.com>
Tue, 23 Feb 2016 22:58:30 +0000 (17:58 -0500)
committerJason Monk <jmonk@google.com>
Wed, 24 Feb 2016 15:25:55 +0000 (10:25 -0500)
Bug: 27276982
Change-Id: If598e2901a25f5df2b76a87a95590a5ff831a2dc

res/layout/installed_app_details.xml
src/com/android/settings/applications/InstalledAppDetails.java

index fd98ec3..c84936a 100644 (file)
         android:paddingBottom="10dip"
         android:orientation="vertical">
 
-        <!-- Application snippet label, version and icon -->
-        <include
-            layout="@layout/app_item"
-            android:id="@+id/app_snippet" />
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <FrameLayout
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1">
+                <!-- Application snippet label, version and icon -->
+                <include
+                    layout="@layout/app_item"
+                    android:id="@+id/app_snippet" />
+            </FrameLayout>
+
+            <ImageView
+                android:id="@+id/gear"
+                android:layout_width="48dp"
+                android:layout_height="48dp"
+                android:layout_gravity="center_vertical"
+                android:padding="12dp"
+                android:src="@drawable/ic_settings_24dp"
+                android:tint="?android:attr/colorAccent"
+                android:clickable="true"
+                android:background="?android:attr/selectableItemBackground" />
+
+        </LinearLayout>
 
         <Space
             android:layout_width="match_parent"
index 197da7c..a8f0fd0 100755 (executable)
@@ -63,6 +63,7 @@ import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.Button;
 import android.widget.ImageView;
@@ -390,6 +391,28 @@ public class InstalledAppDetails extends AppInfoBase
         mForceStopButton.setText(R.string.force_stop);
         mUninstallButton = (Button) btnPanel.findViewById(R.id.left_button);
         mForceStopButton.setEnabled(false);
+
+        View gear = mHeader.findViewById(R.id.gear);
+        Intent i = new Intent(Intent.ACTION_APPLICATION_PREFERENCES);
+        i.setPackage(mPackageName);
+        final Intent intent = resolveIntent(i);
+        if (intent != null) {
+            gear.setVisibility(View.VISIBLE);
+            gear.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    startActivity(intent);
+                }
+            });
+        } else {
+            gear.setVisibility(View.GONE);
+        }
+    }
+
+    private Intent resolveIntent(Intent i) {
+        ResolveInfo result = getContext().getPackageManager().resolveActivity(i, 0);
+        return result != null ? new Intent(Intent.ACTION_APPLICATION_PREFERENCES)
+                .setClassName(result.activityInfo.packageName, result.activityInfo.name) : null;
     }
 
     @Override