package com.android.systemui.statusbar.stack;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.android.systemui.R;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.ExpandableView;
import java.util.List;
import java.util.WeakHashMap;
public class StackScrollState {
private static final String CHILD_NOT_FOUND_TAG = "StackScrollStateNoSuchChild";
private final ViewGroup mHostView;
private WeakHashMap<ExpandableView, ExpandableViewState> mStateMap;
public StackScrollState(ViewGroup hostView) {
mHostView = hostView;
mStateMap = new WeakHashMap<>();
}
public ViewGroup getHostView() {
return mHostView;
}
public void resetViewStates() {
int numChildren = mHostView.getChildCount();
for (int i = 0; i < numChildren; i++) {
ExpandableView child = (ExpandableView) mHostView.getChildAt(i);
resetViewState(child);
if (child instanceof ExpandableNotificationRow) {
ExpandableNotificationRow row = (ExpandableNotificationRow) child;
List<ExpandableNotificationRow> children =
row.getNotificationChildren();
if (row.isSummaryWithChildren() && children != null) {
for (ExpandableNotificationRow childRow : children) {
resetViewState(childRow);
}
}
}
}
}
private void resetViewState(ExpandableView view) {
ExpandableViewState viewState = mStateMap.get(view);
if (viewState == null) {
viewState = view.createNewViewState(this);
mStateMap.put(view, viewState);
}
viewState.height = view.getIntrinsicHeight();
viewState.gone = view.getVisibility() == View.GONE;
viewState.alpha = 1f;
viewState.shadowAlpha = 1f;
viewState.notGoneIndex = -1;
viewState.xTranslation = view.getTranslationX();
viewState.hidden = false;
viewState.scaleX = view.getScaleX();
viewState.scaleY = view.getScaleY();
viewState.inShelf = false;
viewState.headsUpIsVisible = false;
}
public ExpandableViewState getViewStateForView(View requestedView) {
return mStateMap.get(requestedView);
}
public void removeViewStateForView(View child) {
mStateMap.remove(child);
}
public void apply() {
int numChildren = mHostView.getChildCount();
for (int i = 0; i < numChildren; i++) {
ExpandableView child = (ExpandableView) mHostView.getChildAt(i);
ExpandableViewState state = mStateMap.get(child);
if (state == null) {
Log.wtf(CHILD_NOT_FOUND_TAG, "No child state was found when applying this state " +
"to the hostView");
continue;
}
if (state.gone) {
continue;
}
state.applyToView(child);
}
}
}