<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 -->
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;
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 */
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()));
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;
});
}
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
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;
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;
*/
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) {
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;
}
}
+ 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();
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;
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);
}
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);
}