Move hard-coded dimens to dimens.xml.
This is an initial change to allow the values to be overridden by Android Auto. Change-Id: Iaa611b6ff2ce0aa00d93776e775905c786802ef2
This commit is contained in:
@@ -77,7 +77,7 @@
|
||||
</FrameLayout>
|
||||
<View
|
||||
android:id="@+id/wifi_signal_spacer"
|
||||
android:layout_width="4dp"
|
||||
android:layout_width="@dimen/status_bar_wifi_signal_spacer_width"
|
||||
android:layout_height="4dp"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
@@ -112,7 +112,7 @@
|
||||
</FrameLayout>
|
||||
<View
|
||||
android:id="@+id/wifi_airplane_spacer"
|
||||
android:layout_width="4dp"
|
||||
android:layout_width="@dimen/status_bar_airplane_spacer_width"
|
||||
android:layout_height="4dp"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
@@ -70,7 +70,8 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:singleLine="true"
|
||||
android:paddingStart="7dp"
|
||||
android:paddingStart="@dimen/status_bar_clock_starting_padding"
|
||||
android:paddingEnd="@dimen/status_bar_clock_end_padding"
|
||||
android:gravity="center_vertical|start"
|
||||
/>
|
||||
</com.android.keyguard.AlphaOptimizedLinearLayout>
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
android:id="@+id/signal_cluster"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2.5dp"/>
|
||||
android:layout_marginStart="@dimen/signal_cluster_margin_start"/>
|
||||
|
||||
<!-- battery must be padded below to match assets -->
|
||||
<com.android.systemui.BatteryMeterView android:id="@+id/battery"
|
||||
android:layout_height="14.5dp"
|
||||
android:layout_width="9.5dp"
|
||||
android:layout_height="@dimen/status_bar_battery_icon_height"
|
||||
android:layout_width="@dimen/status_bar_battery_icon_width"
|
||||
android:layout_marginBottom="@dimen/battery_margin_bottom"/>
|
||||
</LinearLayout>
|
||||
@@ -33,9 +33,30 @@
|
||||
<!-- Height of notification icons in the status bar -->
|
||||
<dimen name="status_bar_icon_size">@*android:dimen/status_bar_icon_size</dimen>
|
||||
|
||||
<!-- The font size for the clock -->
|
||||
<!-- Height of the battery icon in the status bar. -->
|
||||
<dimen name="status_bar_battery_icon_height">14.5dp</dimen>
|
||||
|
||||
<!-- Width of the battery icon in the status bar. -->
|
||||
<dimen name="status_bar_battery_icon_width">9.5dp</dimen>
|
||||
|
||||
<!-- The font size for the clock in the status bar. -->
|
||||
<dimen name="status_bar_clock_size">14sp</dimen>
|
||||
|
||||
<!-- The starting padding for the clock in the status bar. -->
|
||||
<dimen name="status_bar_clock_starting_padding">7dp</dimen>
|
||||
|
||||
<!-- The end padding for the clock in the status bar. -->
|
||||
<dimen name="status_bar_clock_end_padding">0dp</dimen>
|
||||
|
||||
<!-- Spacing after the wifi signals that is present if there are any icons following it. -->
|
||||
<dimen name="status_bar_wifi_signal_spacer_width">4dp</dimen>
|
||||
|
||||
<!-- Spacing before the airplane mode icon if there are any icons preceding it. -->
|
||||
<dimen name="status_bar_airplane_spacer_width">4dp</dimen>
|
||||
|
||||
<!-- The amount to scale each of the status bar icons by. A value of 1 means no scaling. -->
|
||||
<item name="status_bar_icon_scale_factor" format="float" type="dimen">1.0</item>
|
||||
|
||||
<!-- Height of a small notification in the status bar-->
|
||||
<dimen name="notification_min_height">84dp</dimen>
|
||||
|
||||
@@ -518,6 +539,9 @@
|
||||
|
||||
<dimen name="fake_shadow_size">8dp</dimen>
|
||||
|
||||
<!-- Starting margin before the signal cluster -->
|
||||
<dimen name="signal_cluster_margin_start">2.5dp</dimen>
|
||||
|
||||
<!-- Padding between signal cluster and battery icon -->
|
||||
<dimen name="signal_cluster_battery_padding">7dp</dimen>
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.statusbar;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.DrawableWrapper;
|
||||
|
||||
/**
|
||||
* An extension of {@link DrawableWrapper} that will take a given Drawable and scale it by
|
||||
* the given factor.
|
||||
*/
|
||||
class ScalingDrawableWrapper extends DrawableWrapper {
|
||||
private float mScaleFactor;
|
||||
|
||||
public ScalingDrawableWrapper(Drawable drawable, float scaleFactor) {
|
||||
super(drawable);
|
||||
mScaleFactor = scaleFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return (int) (super.getIntrinsicWidth() * mScaleFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return (int) (super.getIntrinsicHeight() * mScaleFactor);
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,18 @@
|
||||
|
||||
package com.android.systemui.statusbar;
|
||||
|
||||
import android.annotation.DrawableRes;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.util.ArraySet;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -86,10 +88,11 @@ public class SignalClusterView
|
||||
View mWifiSignalSpacer;
|
||||
LinearLayout mMobileSignalGroup;
|
||||
|
||||
private int mWideTypeIconStartPadding;
|
||||
private int mSecondaryTelephonyPadding;
|
||||
private int mEndPadding;
|
||||
private int mEndPaddingNothingVisible;
|
||||
private final int mWideTypeIconStartPadding;
|
||||
private final int mSecondaryTelephonyPadding;
|
||||
private final int mEndPadding;
|
||||
private final int mEndPaddingNothingVisible;
|
||||
private final float mIconScaleFactor;
|
||||
|
||||
private boolean mBlockAirplane;
|
||||
private boolean mBlockMobile;
|
||||
@@ -106,6 +109,17 @@ public class SignalClusterView
|
||||
|
||||
public SignalClusterView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
Resources res = getResources();
|
||||
mWideTypeIconStartPadding = res.getDimensionPixelSize(R.dimen.wide_type_icon_start_padding);
|
||||
mSecondaryTelephonyPadding = res.getDimensionPixelSize(R.dimen.secondary_telephony_padding);
|
||||
mEndPadding = res.getDimensionPixelSize(R.dimen.signal_cluster_battery_padding);
|
||||
mEndPaddingNothingVisible = res.getDimensionPixelSize(
|
||||
R.dimen.no_signal_cluster_battery_padding);
|
||||
|
||||
TypedValue typedValue = new TypedValue();
|
||||
res.getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true);
|
||||
mIconScaleFactor = typedValue.getFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,19 +160,6 @@ public class SignalClusterView
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mWideTypeIconStartPadding = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.wide_type_icon_start_padding);
|
||||
mSecondaryTelephonyPadding = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.secondary_telephony_padding);
|
||||
mEndPadding = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.signal_cluster_battery_padding);
|
||||
mEndPaddingNothingVisible = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.no_signal_cluster_battery_padding);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
mVpn = (ImageView) findViewById(R.id.vpn);
|
||||
mEthernetGroup = (ViewGroup) findViewById(R.id.ethernet_combo);
|
||||
@@ -174,6 +175,32 @@ public class SignalClusterView
|
||||
mWifiAirplaneSpacer = findViewById(R.id.wifi_airplane_spacer);
|
||||
mWifiSignalSpacer = findViewById(R.id.wifi_signal_spacer);
|
||||
mMobileSignalGroup = (LinearLayout) findViewById(R.id.mobile_signal_group);
|
||||
|
||||
maybeScaleVpnAndNoSimsIcons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the icon off of the VPN and no sims views and maybe scale them by
|
||||
* {@link #mIconScaleFactor}. Note that the other icons are not scaled here because they are
|
||||
* dynamic. As such, they need to be scaled each time the icon changes in {@link #apply()}.
|
||||
*/
|
||||
private void maybeScaleVpnAndNoSimsIcons() {
|
||||
if (mIconScaleFactor == 1.f) {
|
||||
return;
|
||||
}
|
||||
|
||||
mVpn.setImageDrawable(new ScalingDrawableWrapper(mVpn.getDrawable(), mIconScaleFactor));
|
||||
|
||||
mNoSims.setImageDrawable(
|
||||
new ScalingDrawableWrapper(mNoSims.getDrawable(), mIconScaleFactor));
|
||||
mNoSimsDark.setImageDrawable(
|
||||
new ScalingDrawableWrapper(mNoSimsDark.getDrawable(), mIconScaleFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
for (PhoneState state : mPhoneStates) {
|
||||
mMobileSignalGroup.addView(state.mMobileGroup);
|
||||
}
|
||||
@@ -185,14 +212,7 @@ public class SignalClusterView
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
mVpn = null;
|
||||
mEthernetGroup = null;
|
||||
mEthernet = null;
|
||||
mWifiGroup = null;
|
||||
mWifi = null;
|
||||
mAirplane = null;
|
||||
mMobileSignalGroup.removeAllViews();
|
||||
mMobileSignalGroup = null;
|
||||
TunerService.get(mContext).removeTunable(this);
|
||||
|
||||
super.onDetachedFromWindow();
|
||||
@@ -380,8 +400,8 @@ public class SignalClusterView
|
||||
|
||||
if (mEthernetVisible) {
|
||||
if (mLastEthernetIconId != mEthernetIconId) {
|
||||
mEthernet.setImageResource(mEthernetIconId);
|
||||
mEthernetDark.setImageResource(mEthernetIconId);
|
||||
setIconForView(mEthernet, mEthernetIconId);
|
||||
setIconForView(mEthernetDark, mEthernetIconId);
|
||||
mLastEthernetIconId = mEthernetIconId;
|
||||
}
|
||||
mEthernetGroup.setContentDescription(mEthernetDescription);
|
||||
@@ -394,11 +414,10 @@ public class SignalClusterView
|
||||
String.format("ethernet: %s",
|
||||
(mEthernetVisible ? "VISIBLE" : "GONE")));
|
||||
|
||||
|
||||
if (mWifiVisible) {
|
||||
if (mWifiStrengthId != mLastWifiStrengthId) {
|
||||
mWifi.setImageResource(mWifiStrengthId);
|
||||
mWifiDark.setImageResource(mWifiStrengthId);
|
||||
setIconForView(mWifi, mWifiStrengthId);
|
||||
setIconForView(mWifiDark, mWifiStrengthId);
|
||||
mLastWifiStrengthId = mWifiStrengthId;
|
||||
}
|
||||
mWifiGroup.setContentDescription(mWifiDescription);
|
||||
@@ -425,7 +444,7 @@ public class SignalClusterView
|
||||
|
||||
if (mIsAirplaneMode) {
|
||||
if (mLastAirplaneIconId != mAirplaneIconId) {
|
||||
mAirplane.setImageResource(mAirplaneIconId);
|
||||
setIconForView(mAirplane, mAirplaneIconId);
|
||||
mLastAirplaneIconId = mAirplaneIconId;
|
||||
}
|
||||
mAirplane.setContentDescription(mAirplaneContentDescription);
|
||||
@@ -453,6 +472,21 @@ public class SignalClusterView
|
||||
setPaddingRelative(0, 0, anythingVisible ? mEndPadding : mEndPaddingNothingVisible, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given drawable id on the view. This method will also scale the icon by
|
||||
* {@link #mIconScaleFactor} if appropriate.
|
||||
*/
|
||||
private void setIconForView(ImageView imageView, @DrawableRes int iconId) {
|
||||
// Using the imageView's context to retrieve the Drawable so that theme is preserved.
|
||||
Drawable icon = imageView.getContext().getDrawable(iconId);
|
||||
|
||||
if (mIconScaleFactor == 1.f) {
|
||||
imageView.setImageDrawable(icon);
|
||||
} else {
|
||||
imageView.setImageDrawable(new ScalingDrawableWrapper(icon, mIconScaleFactor));
|
||||
}
|
||||
}
|
||||
|
||||
public void setIconTint(int tint, float darkIntensity) {
|
||||
boolean changed = tint != mIconTint || darkIntensity != mDarkIntensity;
|
||||
mIconTint = tint;
|
||||
|
||||
@@ -24,10 +24,13 @@ import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.graphics.drawable.ScaleDrawable;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewDebug;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import com.android.internal.statusbar.StatusBarIcon;
|
||||
@@ -189,12 +192,24 @@ public class StatusBarIconView extends AnimatedImageView {
|
||||
* @return Drawable for this item, or null if the package or item could not
|
||||
* be found
|
||||
*/
|
||||
public static Drawable getIcon(Context context, StatusBarIcon icon) {
|
||||
int userId = icon.user.getIdentifier();
|
||||
public static Drawable getIcon(Context context, StatusBarIcon statusBarIcon) {
|
||||
int userId = statusBarIcon.user.getIdentifier();
|
||||
if (userId == UserHandle.USER_ALL) {
|
||||
userId = UserHandle.USER_SYSTEM;
|
||||
}
|
||||
return icon.icon.loadDrawableAsUser(context, userId);
|
||||
|
||||
Drawable icon = statusBarIcon.icon.loadDrawableAsUser(context, userId);
|
||||
|
||||
TypedValue typedValue = new TypedValue();
|
||||
context.getResources().getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true);
|
||||
float scaleFactor = typedValue.getFloat();
|
||||
|
||||
// No need to scale the icon, so return it as is.
|
||||
if (scaleFactor == 1.f) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
return new ScalingDrawableWrapper(icon, scaleFactor);
|
||||
}
|
||||
|
||||
public StatusBarIcon getStatusBarIcon() {
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.animation.ArgbEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
@@ -28,6 +29,7 @@ import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AnimationUtils;
|
||||
@@ -122,7 +124,10 @@ public class StatusBarIconController extends StatusBarIconList implements Tunabl
|
||||
notificationIconArea.addView(mNotificationIconAreaInner);
|
||||
|
||||
mStatusIconsKeyguard = (LinearLayout) keyguardStatusBar.findViewById(R.id.statusIcons);
|
||||
|
||||
mBatteryMeterView = (BatteryMeterView) statusBar.findViewById(R.id.battery);
|
||||
maybeScaleBatteryMeterView(context);
|
||||
|
||||
mClock = (TextView) statusBar.findViewById(R.id.clock);
|
||||
mLinearOutSlowIn = AnimationUtils.loadInterpolator(mContext,
|
||||
android.R.interpolator.linear_out_slow_in);
|
||||
@@ -136,6 +141,30 @@ public class StatusBarIconController extends StatusBarIconList implements Tunabl
|
||||
TunerService.get(mContext).addTunable(this, ICON_BLACKLIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the scale factor for status bar icons and scales the battery view by that amount
|
||||
* if appropriate.
|
||||
*/
|
||||
private void maybeScaleBatteryMeterView(Context context) {
|
||||
Resources res = context.getResources();
|
||||
TypedValue typedValue = new TypedValue();
|
||||
|
||||
res.getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true);
|
||||
float iconScaleFactor = typedValue.getFloat();
|
||||
|
||||
if (iconScaleFactor == 1.f) {
|
||||
return;
|
||||
}
|
||||
|
||||
float batteryHeight = res.getDimension(R.dimen.status_bar_battery_icon_height);
|
||||
float batteryWidth = res.getDimension(R.dimen.status_bar_battery_icon_width);
|
||||
|
||||
LinearLayout.LayoutParams scaledLayoutParams = new LinearLayout.LayoutParams(
|
||||
(int) (batteryWidth * iconScaleFactor), (int) (batteryHeight * iconScaleFactor));
|
||||
|
||||
mBatteryMeterView.setLayoutParams(scaledLayoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTuningChanged(String key, String newValue) {
|
||||
if (!ICON_BLACKLIST.equals(key)) {
|
||||
@@ -174,8 +203,12 @@ public class StatusBarIconController extends StatusBarIconList implements Tunabl
|
||||
boolean blocked = mIconBlacklist.contains(slot);
|
||||
StatusBarIconView view = new StatusBarIconView(mContext, slot, null, blocked);
|
||||
view.set(icon);
|
||||
mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize));
|
||||
|
||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize);
|
||||
lp.setMargins(mIconHPadding, 0, mIconHPadding, 0);
|
||||
mStatusIcons.addView(view, viewIndex, lp);
|
||||
|
||||
view = new StatusBarIconView(mContext, slot, null, blocked);
|
||||
view.set(icon);
|
||||
mStatusIconsKeyguard.addView(view, viewIndex, new LinearLayout.LayoutParams(
|
||||
|
||||
Reference in New Issue
Block a user