Improved notification transformations

All views are now faded, even if they are not handled specially

Change-Id: I2970548667e0388984098293ac0dfcbdbed12df1
This commit is contained in:
Selim Cinek
2016-01-03 14:42:02 +08:00
parent 0ffbda62e5
commit 646d2054dd
6 changed files with 82 additions and 14 deletions

View File

@@ -54,6 +54,7 @@
<item type="id" name="clip_children_set_tag" />
<item type="id" name="clip_to_padding_tag" />
<item type="id" name="image_icon_tag" />
<item type="id" name="contains_transformed_view" />
<item type="id" name="is_clicked_heads_up_tag" />
</resources>

View File

@@ -19,13 +19,20 @@ package com.android.systemui.statusbar;
import android.os.Handler;
import android.util.ArrayMap;
import android.view.View;
import android.view.ViewGroup;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.TransformState;
import java.util.Stack;
/**
* A view that can be transformed to and from.
*/
public class ViewTransformationHelper implements TransformableView {
private static final int TAG_CONTAINS_TRANSFORMED_VIEW = R.id.contains_transformed_view;
private final Handler mHandler = new Handler();
private ArrayMap<Integer, View> mTransformedViews = new ArrayMap<>();
@@ -105,4 +112,46 @@ public class ViewTransformationHelper implements TransformableView {
}
}
}
/**
* Add the remaining transformation views such that all views are being transformed correctly
* @param viewRoot the root below which all elements need to be transformed
*/
public void addRemainingTransformTypes(View viewRoot) {
// lets now tag the right views
int numValues = mTransformedViews.size();
for (int i = 0; i < numValues; i++) {
View view = mTransformedViews.valueAt(i);
while (view != viewRoot.getParent()) {
view.setTag(TAG_CONTAINS_TRANSFORMED_VIEW, true);
view = (View) view.getParent();
}
}
Stack<View> stack = new Stack<>();
// Add the right views now
stack.push(viewRoot);
while (!stack.isEmpty()) {
View child = stack.pop();
if (child.getVisibility() == View.GONE) {
continue;
}
Boolean containsView = (Boolean) child.getTag(TAG_CONTAINS_TRANSFORMED_VIEW);
if (containsView == null) {
// This one is unhandled, let's add it to our list.
int id = child.getId();
if (id != View.NO_ID) {
// We only fade views with an id
addTransformedView(id, child);
continue;
}
}
child.setTag(TAG_CONTAINS_TRANSFORMED_VIEW, null);
if (child instanceof ViewGroup && !mTransformedViews.containsValue(child)){
ViewGroup group = (ViewGroup) child;
for (int i = 0; i < group.getChildCount(); i++) {
stack.push(group.getChildAt(i));
}
}
}
}
}

View File

@@ -44,7 +44,7 @@ public class ImageTransformState extends TransformState {
@Override
protected boolean sameAs(TransformState otherState) {
if (otherState instanceof ImageTransformState) {
return mIcon.sameAs(((ImageTransformState) otherState).getIcon());
return mIcon != null && mIcon.sameAs(((ImageTransformState) otherState).getIcon());
}
return super.sameAs(otherState);
}

View File

@@ -28,6 +28,7 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
import android.view.NotificationHeaderView;
import android.view.View;
import android.view.ViewGroup;
@@ -41,6 +42,7 @@ import com.android.systemui.statusbar.TransformableView;
import com.android.systemui.statusbar.ViewTransformationHelper;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import java.util.Collection;
import java.util.Stack;
/**
@@ -99,9 +101,19 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
resolveHeaderViews();
updateInvertHelper();
updateTransformedTypes();
addRemainingTransformTypes();
updateCropToPaddingForImageViews();
}
/**
* Adds the remaining TransformTypes to the TransformHelper. This is done to make sure that each
* child is faded automatically and doesn't have to be manually added.
* The keys used for the views are the ids.
*/
private void addRemainingTransformTypes() {
mTransformationHelper.addRemainingTransformTypes(mView);
}
/**
* Since we are deactivating the clipping when transforming the ImageViews don't get clipped
* anymore during these transitions. We can avoid that by using

View File

@@ -60,19 +60,10 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
@Override
public void notifyContentUpdated(StatusBarNotification notification) {
// Reinspect the notification.
// Reinspect the notification. Before the super call, because the super call also updates
// the transformation types and we need to have our values set by then.
resolveTemplateViews(notification);
super.notifyContentUpdated(notification);
addRemainingTransformTypes();
}
/**
* Adds the remaining TransformTypes to the TransformHelper. This is done to make sure that each
* child is faded automatically and doesn't have to be manually added.
* The keys used for the views are the ids.
*/
private void addRemainingTransformTypes() {
}
@Override

View File

@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification;
import android.util.ArraySet;
import android.util.Pools;
import android.view.NotificationHeaderView;
import android.view.View;
import android.view.ViewGroup;
@@ -32,8 +33,9 @@ import com.android.systemui.statusbar.ExpandableNotificationRow;
/**
* A transform state of a view.
*/
public abstract class TransformState {
public class TransformState {
private static Pools.SimplePool<TransformState> sInstancePool = new Pools.SimplePool<>(40);
private static final int CLIP_CLIPPING_SET = R.id.clip_children_set_tag;
private static final int CLIP_CHILDREN_TAG = R.id.clip_children_tag;
private static final int CLIP_TO_PADDING = R.id.clip_to_padding_tag;
@@ -202,11 +204,16 @@ public abstract class TransformState {
result.initFrom(view);
return result;
}
return null;
TransformState result = obtain();
result.initFrom(view);
return result;
}
public void recycle() {
reset();
if (getClass() == TransformState.class) {
sInstancePool.release(this);
}
}
protected void reset() {
@@ -225,4 +232,12 @@ public abstract class TransformState {
public void prepareFadeIn() {
}
public static TransformState obtain() {
TransformState instance = sInstancePool.acquire();
if (instance != null) {
return instance;
}
return new TransformState();
}
}