Allow more flexibility for icon selection
Bug:77906888 Test: Manual Change-Id: Ia011760c4b162d7e6eef2fd716ff2e6015caa919
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
<attr name="categories" format="string"/>
|
||||
<!-- package names that will be added as extras to the fired intents -->
|
||||
<attr name="packages" format="string" />
|
||||
<!-- componentName names that will be used for detecting selected state -->
|
||||
<attr name="componentNames" format="string" />
|
||||
<!-- Alpha value to used when in selected state. Defaults 1f -->
|
||||
<attr name="selectedAlpha" format="float" />
|
||||
<!-- Alpha value to used when in un-selected state. Defaults 0.7f -->
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -37,6 +38,7 @@ public class CarFacetButton extends LinearLayout {
|
||||
private AlphaOptimizedImageButton mIcon;
|
||||
private AlphaOptimizedImageButton mMoreIcon;
|
||||
private boolean mSelected = false;
|
||||
private String[] mComponentNames;
|
||||
/** App categories that are to be used with this widget */
|
||||
private String[] mFacetCategories;
|
||||
/** App packages that are allowed to be used with this widget */
|
||||
@@ -75,6 +77,8 @@ public class CarFacetButton extends LinearLayout {
|
||||
String longPressIntentString = typedArray.getString(R.styleable.CarFacetButton_longIntent);
|
||||
String categoryString = typedArray.getString(R.styleable.CarFacetButton_categories);
|
||||
String packageString = typedArray.getString(R.styleable.CarFacetButton_packages);
|
||||
String componentNameString =
|
||||
typedArray.getString(R.styleable.CarFacetButton_componentNames);
|
||||
try {
|
||||
final Intent intent = Intent.parseUri(intentString, Intent.URI_INTENT_SCHEME);
|
||||
intent.putExtra(EXTRA_FACET_ID, Integer.toString(getId()));
|
||||
@@ -87,17 +91,20 @@ public class CarFacetButton extends LinearLayout {
|
||||
mFacetCategories = categoryString.split(FACET_FILTER_DELIMITER);
|
||||
intent.putExtra(EXTRA_FACET_CATEGORIES, mFacetCategories);
|
||||
}
|
||||
if (componentNameString != null) {
|
||||
mComponentNames = componentNameString.split(FACET_FILTER_DELIMITER);
|
||||
}
|
||||
|
||||
setOnClickListener(v -> {
|
||||
intent.putExtra(EXTRA_FACET_LAUNCH_PICKER, mSelected);
|
||||
mContext.startActivity(intent);
|
||||
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
|
||||
});
|
||||
|
||||
if (longPressIntentString != null) {
|
||||
final Intent longPressIntent = Intent.parseUri(longPressIntentString,
|
||||
Intent.URI_INTENT_SCHEME);
|
||||
setOnLongClickListener(v -> {
|
||||
mContext.startActivity(longPressIntent);
|
||||
mContext.startActivityAsUser(longPressIntent, UserHandle.CURRENT);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -148,6 +155,13 @@ public class CarFacetButton extends LinearLayout {
|
||||
return mFacetPackages;
|
||||
}
|
||||
|
||||
public String[] getComponentName() {
|
||||
if (mComponentNames == null) {
|
||||
return new String[0];
|
||||
}
|
||||
return mComponentNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the alpha of the icons to "selected" and shows the "More icon"
|
||||
* @param selected true if the view must be selected, false otherwise
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.android.systemui.statusbar.car;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -19,6 +21,7 @@ public class CarFacetButtonController {
|
||||
|
||||
protected HashMap<String, CarFacetButton> mButtonsByCategory = new HashMap<>();
|
||||
protected HashMap<String, CarFacetButton> mButtonsByPackage = new HashMap<>();
|
||||
protected HashMap<String, CarFacetButton> mButtonsByComponentName = new HashMap<>();
|
||||
protected CarFacetButton mSelectedFacetButton;
|
||||
protected Context mContext;
|
||||
|
||||
@@ -34,28 +37,32 @@ public class CarFacetButtonController {
|
||||
*/
|
||||
public void addFacetButton(CarFacetButton facetButton) {
|
||||
String[] categories = facetButton.getCategories();
|
||||
for (int j = 0; j < categories.length; j++) {
|
||||
String category = categories[j];
|
||||
mButtonsByCategory.put(category, facetButton);
|
||||
for (int i = 0; i < categories.length; i++) {
|
||||
mButtonsByCategory.put(categories[i], facetButton);
|
||||
}
|
||||
|
||||
String[] facetPackages = facetButton.getFacetPackages();
|
||||
for (int j = 0; j < facetPackages.length; j++) {
|
||||
String facetPackage = facetPackages[j];
|
||||
mButtonsByPackage.put(facetPackage, facetButton);
|
||||
for (int i = 0; i < facetPackages.length; i++) {
|
||||
mButtonsByPackage.put(facetPackages[i], facetButton);
|
||||
}
|
||||
String[] componentNames = facetButton.getComponentName();
|
||||
for (int i = 0; i < componentNames.length; i++) {
|
||||
mButtonsByComponentName.put(componentNames[i], facetButton);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
mButtonsByCategory.clear();
|
||||
mButtonsByPackage.clear();
|
||||
mButtonsByComponentName.clear();
|
||||
mSelectedFacetButton = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will unselect the currently selected CarFacetButton and determine which one should be
|
||||
* selected next. It does this by reading the properties on the CarFacetButton and seeing if
|
||||
* they are a match with the supplied taskino.
|
||||
* they are a match with the supplied taskInfo.
|
||||
* Order of selection detection ComponentName, PackageName, Category
|
||||
* @param taskInfo of the currently running application
|
||||
*/
|
||||
public void taskChanged(ActivityManager.RunningTaskInfo taskInfo) {
|
||||
@@ -69,7 +76,10 @@ public class CarFacetButtonController {
|
||||
if (mSelectedFacetButton != null) {
|
||||
mSelectedFacetButton.setSelected(false);
|
||||
}
|
||||
CarFacetButton facetButton = mButtonsByPackage.get(packageName);
|
||||
CarFacetButton facetButton = findFacetButtongByComponentName(taskInfo.topActivity);
|
||||
if (facetButton == null) {
|
||||
facetButton = mButtonsByPackage.get(packageName);
|
||||
}
|
||||
if (facetButton != null) {
|
||||
facetButton.setSelected(true);
|
||||
mSelectedFacetButton = facetButton;
|
||||
@@ -83,6 +93,12 @@ public class CarFacetButtonController {
|
||||
}
|
||||
}
|
||||
|
||||
private CarFacetButton findFacetButtongByComponentName(ComponentName componentName) {
|
||||
CarFacetButton button = mButtonsByComponentName.get(componentName.flattenToShortString());
|
||||
return (button != null) ? button :
|
||||
mButtonsByComponentName.get(componentName.flattenToString());
|
||||
}
|
||||
|
||||
protected String getPackageCategory(String packageName) {
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
Set<String> supportedCategories = mButtonsByCategory.keySet();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.android.systemui.statusbar.car;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.UserHandle;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
@@ -64,10 +65,10 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
|
||||
setOnClickListener(v -> {
|
||||
try {
|
||||
if (mBroadcastIntent) {
|
||||
mContext.sendBroadcast(intent);
|
||||
mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
|
||||
return;
|
||||
}
|
||||
mContext.startActivity(intent);
|
||||
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to launch intent", e);
|
||||
}
|
||||
@@ -82,7 +83,7 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
|
||||
final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME);
|
||||
setOnLongClickListener(v -> {
|
||||
try {
|
||||
mContext.startActivity(intent);
|
||||
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to launch intent", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user