Merge "Fix support for rendering status icons" into pi-dev

am: fad31024f8

Change-Id: I31e8f917a78c1abcb175513360b90ff7427940c1
This commit is contained in:
Brad Stenning
2018-04-06 12:22:24 -07:00
committed by android-build-merger
4 changed files with 68 additions and 35 deletions

View File

@@ -19,6 +19,8 @@
<declare-styleable name="CarFacetButton">
<!-- icon to be rendered (drawable) -->
<attr name="icon" format="reference"/>
<!-- icon to be rendered when in selected state -->
<attr name="selectedIcon" format="reference"/>
<!-- intent to start when button is click -->
<attr name="intent" format="string"/>
<!-- intent to start when a long press has happened -->
@@ -45,6 +47,12 @@
<attr name="longIntent" format="string"/>
<!-- start the intent as a broad cast instead of an activity if true-->
<attr name="broadcast" format="boolean"/>
<!-- 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 -->
<attr name="unselectedAlpha" format="float" />
<!-- icon to be rendered when in selected state -->
<attr name="selectedIcon" format="reference"/>
</declare-styleable>
<!-- Custom attributes to configure hvac values -->

View File

@@ -42,6 +42,11 @@ public class CarFacetButton extends LinearLayout {
/** App packages that are allowed to be used with this widget */
private String[] mFacetPackages;
private int mIconResourceId;
/**
* If defined in the xml this will be the icon that's rendered when the button is marked as
* selected
*/
private int mSelectedIconResourceId;
private boolean mUseMoreIcon = true;
private float mSelectedAlpha = 1f;
private float mUnselectedAlpha = 1f;
@@ -112,10 +117,9 @@ public class CarFacetButton extends LinearLayout {
mIcon.setClickable(false);
mIcon.setAlpha(mUnselectedAlpha);
mIconResourceId = styledAttributes.getResourceId(R.styleable.CarFacetButton_icon, 0);
if (mIconResourceId == 0) {
throw new RuntimeException("specified icon resource was not found and is required");
}
mIcon.setImageResource(mIconResourceId);
mSelectedIconResourceId = styledAttributes.getResourceId(
R.styleable.CarFacetButton_selectedIcon, mIconResourceId);
mMoreIcon = findViewById(R.id.car_nav_button_more_icon);
mMoreIcon.setClickable(false);
@@ -161,22 +165,10 @@ public class CarFacetButton extends LinearLayout {
*/
public void setSelected(boolean selected, boolean showMoreIcon) {
mSelected = selected;
if (selected) {
if (mUseMoreIcon) {
mMoreIcon.setVisibility(showMoreIcon ? VISIBLE : GONE);
}
mIcon.setAlpha(mSelectedAlpha);
} else {
mMoreIcon.setVisibility(GONE);
mIcon.setAlpha(mUnselectedAlpha);
}
}
public void setIcon(Drawable d) {
if (d != null) {
mIcon.setImageDrawable(d);
} else {
mIcon.setImageResource(mIconResourceId);
mIcon.setAlpha(mSelected ? mSelectedAlpha : mUnselectedAlpha);
mIcon.setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId);
if (mUseMoreIcon) {
mMoreIcon.setVisibility(showMoreIcon ? VISIBLE : GONE);
}
}
}

View File

@@ -25,7 +25,9 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.keyguard.AlphaOptimizedImageButton;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.StatusBarIconController;
/**
* A custom navigation bar for the automotive use case.
@@ -52,6 +54,17 @@ class CarNavigationBarView extends LinearLayout {
if (mNotificationsButton != null) {
mNotificationsButton.setOnClickListener(this::onNotificationsClick);
}
View mStatusIcons = findViewById(R.id.statusIcons);
if (mStatusIcons != null) {
// Attach the controllers for Status icons such as wifi and bluetooth if the standard
// container is in the view.
StatusBarIconController.DarkIconManager mDarkIconManager =
new StatusBarIconController.DarkIconManager(
mStatusIcons.findViewById(R.id.statusIcons));
mDarkIconManager.setShouldLog(true);
Dependency.get(StatusBarIconController.class).addIconGroup(mDarkIconManager);
}
}
void setStatusBar(CarStatusBar carStatusBar) {

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
import com.android.systemui.R;
@@ -17,23 +18,34 @@ import java.net.URISyntaxException;
*/
public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImageButton {
private static final float SELECTED_ALPHA = 1;
private static final float UNSELECTED_ALPHA = 0.7f;
private static final String TAG = "CarNavigationButton";
private Context mContext;
private String mIntent = null;
private String mLongIntent = null;
private boolean mBroadcastIntent = false;
private String mIntent;
private String mLongIntent;
private boolean mBroadcastIntent;
private boolean mSelected = false;
private float mSelectedAlpha;
private float mUnselectedAlpha;
private int mSelectedIconResourceId;
private int mIconResourceId;
public CarNavigationButton(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CarNavigationButton);
TypedArray typedArray = context.obtainStyledAttributes(
attrs, R.styleable.CarNavigationButton);
mIntent = typedArray.getString(R.styleable.CarNavigationButton_intent);
mLongIntent = typedArray.getString(R.styleable.CarNavigationButton_longIntent);
mBroadcastIntent = typedArray.getBoolean(R.styleable.CarNavigationButton_broadcast, false);
mSelectedAlpha = typedArray.getFloat(
R.styleable.CarNavigationButton_selectedAlpha, mSelectedAlpha);
mUnselectedAlpha = typedArray.getFloat(
R.styleable.CarNavigationButton_unselectedAlpha, mUnselectedAlpha);
mIconResourceId = typedArray.getResourceId(
com.android.internal.R.styleable.ImageView_src, 0);
mSelectedIconResourceId = typedArray.getResourceId(
R.styleable.CarNavigationButton_selectedIcon, mIconResourceId);
}
@@ -45,17 +57,20 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
public void onFinishInflate() {
super.onFinishInflate();
setScaleType(ImageView.ScaleType.CENTER);
setAlpha(UNSELECTED_ALPHA);
setAlpha(mUnselectedAlpha);
try {
if (mIntent != null) {
final Intent intent = Intent.parseUri(mIntent, Intent.URI_INTENT_SCHEME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
setOnClickListener(v -> {
if (mBroadcastIntent) {
mContext.sendBroadcast(intent);
return;
try {
if (mBroadcastIntent) {
mContext.sendBroadcast(intent);
return;
}
mContext.startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Failed to launch intent", e);
}
mContext.startActivity(intent);
});
}
} catch (URISyntaxException e) {
@@ -65,9 +80,13 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
try {
if (mLongIntent != null) {
final Intent intent = Intent.parseUri(mLongIntent, Intent.URI_INTENT_SCHEME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
setOnLongClickListener(v -> {
mContext.startActivity(intent);
try {
mContext.startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Failed to launch intent", e);
}
// consume event either way
return true;
});
}
@@ -82,6 +101,7 @@ public class CarNavigationButton extends com.android.keyguard.AlphaOptimizedImag
public void setSelected(boolean selected) {
super.setSelected(selected);
mSelected = selected;
setAlpha(mSelected ? SELECTED_ALPHA : UNSELECTED_ALPHA);
setAlpha(mSelected ? mSelectedAlpha : mUnselectedAlpha);
setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId);
}
}