In the speedbump view, use hasOverlappingRenderings instead of layers

Bug: 15181880
Change-Id: I49b0dbe1cd0ff9f7804dc68502b73fcfd87c7389
This commit is contained in:
Selim Cinek
2014-05-24 18:02:16 +02:00
parent 5158d82340
commit 9c80964d3f
5 changed files with 69 additions and 28 deletions

View File

@@ -28,7 +28,7 @@
android:layout_height="@dimen/speed_bump_height_collapsed"
android:layout_gravity="top"
android:orientation="horizontal">
<View
<com.android.systemui.statusbar.AlphaOptimizedView
android:id="@+id/speedbump_line_left"
android:layout_width="0dp"
android:layout_height="1dp"
@@ -42,7 +42,7 @@
android:layout_marginEnd="8dp"
android:layout_height="match_parent"
android:layout_weight="0"/>
<View
<com.android.systemui.statusbar.AlphaOptimizedView
android:id="@+id/speedbump_line_right"
android:layout_width="0dp"
android:layout_height="1dp"

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2014 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.content.Context;
import android.util.AttributeSet;
import android.view.View;
/**
* A View which does not have overlapping renderings commands and therefore does not need a
* layer when alpha is changed.
*/
public class AlphaOptimizedView extends View
{
public AlphaOptimizedView(Context context) {
super(context);
}
public AlphaOptimizedView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AlphaOptimizedView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public AlphaOptimizedView(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean hasOverlappingRendering() {
return false;
}
}

View File

@@ -41,6 +41,11 @@ public class SpeedBumpDotView extends View {
canvas.drawCircle(radius, radius, radius, mPaint);
}
@Override
public boolean hasOverlappingRendering() {
return false;
}
public void setColor(int color) {
mPaint.setColor(color);
}

View File

@@ -70,23 +70,12 @@ public class SpeedBumpDotsState {
for (int i = 0; i < childCount; i++) {
View child = mHostView.getChildAt(i);
ViewState viewState = mStateMap.get(child);
float translationX = child.getTranslationX();
float translationY = child.getTranslationY();
float scale = child.getScaleX();
float alpha = child.getAlpha();
if (translationX != viewState.xTranslation) {
child.setTranslationX(viewState.xTranslation);
}
if (translationY != viewState.yTranslation) {
child.setTranslationY(viewState.yTranslation);
}
if (scale != viewState.scale) {
child.setScaleX(viewState.scale);
child.setScaleY(viewState.scale);
}
if (alpha != viewState.alpha) {
child.setAlpha(viewState.alpha);
}
child.setTranslationX(viewState.xTranslation);
child.setTranslationY(viewState.yTranslation);
child.setScaleX(viewState.scale);
child.setScaleY(viewState.scale);
child.setAlpha(viewState.alpha);
}
}
@@ -115,7 +104,7 @@ public class SpeedBumpDotsState {
ViewState viewState = mStateMap.get(child);
child.animate().setInterpolator(mFastOutSlowInInterpolator)
.setStartDelay(startDelay)
.alpha(viewState.alpha).withLayer()
.alpha(viewState.alpha)
.translationX(viewState.xTranslation)
.translationY(viewState.yTranslation)
.scaleX(viewState.scale).scaleY(viewState.scale);

View File

@@ -37,8 +37,8 @@ public class SpeedBumpView extends ExpandableView implements View.OnClickListene
private final int mDotsHeight;
private final int mTextPaddingInset;
private SpeedBumpDotsLayout mDots;
private View mLineLeft;
private View mLineRight;
private AlphaOptimizedView mLineLeft;
private AlphaOptimizedView mLineRight;
private boolean mIsExpanded;
private boolean mDividerVisible = true;
private ValueAnimator mCurrentAnimator;
@@ -89,8 +89,8 @@ public class SpeedBumpView extends ExpandableView implements View.OnClickListene
protected void onFinishInflate() {
super.onFinishInflate();
mDots = (SpeedBumpDotsLayout) findViewById(R.id.speed_bump_dots_layout);
mLineLeft = findViewById(R.id.speedbump_line_left);
mLineRight = findViewById(R.id.speedbump_line_right);
mLineLeft = (AlphaOptimizedView) findViewById(R.id.speedbump_line_left);
mLineRight = (AlphaOptimizedView) findViewById(R.id.speedbump_line_right);
mExplanationText = (TextView) findViewById(R.id.speed_bump_text);
resetExplanationText();
@@ -176,8 +176,7 @@ public class SpeedBumpView extends ExpandableView implements View.OnClickListene
.scaleX(scale)
.scaleY(scale)
.translationY(translationY)
.setListener(needsHideListener ? mHideExplanationListener : null)
.withLayer();
.setListener(needsHideListener ? mHideExplanationListener : null);
mExplanationTextVisible = visible;
}
}
@@ -211,7 +210,6 @@ public class SpeedBumpView extends ExpandableView implements View.OnClickListene
float endTranslationXRight = nowVisible ? 0.0f : mCenterX - mLineRight.getLeft();
mLineLeft.animate()
.alpha(endValue)
.withLayer()
.scaleX(endValue)
.scaleY(endValue)
.translationX(endTranslationXLeft)
@@ -219,7 +217,6 @@ public class SpeedBumpView extends ExpandableView implements View.OnClickListene
.withEndAction(onFinishedRunnable);
mLineRight.animate()
.alpha(endValue)
.withLayer()
.scaleX(endValue)
.scaleY(endValue)
.translationX(endTranslationXRight)