Merge "Disable ActionBar usage of transitions" into klp-dev
This commit is contained in:
@@ -23,6 +23,7 @@ import android.animation.ValueAnimator;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -41,6 +42,10 @@ public class TextChange extends Transition {
|
||||
private static final String LOG_TAG = "TextChange";
|
||||
|
||||
private static final String PROPNAME_TEXT = "android:textchange:text";
|
||||
private static final String PROPNAME_TEXT_SELECTION_START =
|
||||
"android:textchange:textSelectionStart";
|
||||
private static final String PROPNAME_TEXT_SELECTION_END =
|
||||
"android:textchange:textSelectionEnd";
|
||||
private static final String PROPNAME_TEXT_COLOR = "android:textchange:textColor";
|
||||
|
||||
private int mChangeBehavior = CHANGE_BEHAVIOR_KEEP;
|
||||
@@ -84,7 +89,9 @@ public class TextChange extends Transition {
|
||||
public static final int CHANGE_BEHAVIOR_OUT_IN = 3;
|
||||
|
||||
private static final String[] sTransitionProperties = {
|
||||
PROPNAME_TEXT
|
||||
PROPNAME_TEXT,
|
||||
PROPNAME_TEXT_SELECTION_START,
|
||||
PROPNAME_TEXT_SELECTION_END
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -122,6 +129,12 @@ public class TextChange extends Transition {
|
||||
if (transitionValues.view instanceof TextView) {
|
||||
TextView textview = (TextView) transitionValues.view;
|
||||
transitionValues.values.put(PROPNAME_TEXT, textview.getText());
|
||||
if (textview instanceof EditText) {
|
||||
transitionValues.values.put(PROPNAME_TEXT_SELECTION_START,
|
||||
textview.getSelectionStart());
|
||||
transitionValues.values.put(PROPNAME_TEXT_SELECTION_END,
|
||||
textview.getSelectionEnd());
|
||||
}
|
||||
if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
|
||||
transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
|
||||
}
|
||||
@@ -152,8 +165,24 @@ public class TextChange extends Transition {
|
||||
(CharSequence) startVals.get(PROPNAME_TEXT) : "";
|
||||
final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ?
|
||||
(CharSequence) endVals.get(PROPNAME_TEXT) : "";
|
||||
final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
|
||||
if (view instanceof EditText) {
|
||||
startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ?
|
||||
(Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
|
||||
startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ?
|
||||
(Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart;
|
||||
endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ?
|
||||
(Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
|
||||
endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ?
|
||||
(Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart;
|
||||
} else {
|
||||
startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
|
||||
}
|
||||
if (!startText.equals(endText)) {
|
||||
view.setText(startText);
|
||||
if (view instanceof EditText) {
|
||||
setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
|
||||
}
|
||||
Animator anim;
|
||||
if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
|
||||
anim = ValueAnimator.ofFloat(0, 1);
|
||||
@@ -163,6 +192,9 @@ public class TextChange extends Transition {
|
||||
if (startText.equals(view.getText())) {
|
||||
// Only set if it hasn't been changed since anim started
|
||||
view.setText(endText);
|
||||
if (view instanceof EditText) {
|
||||
setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -188,6 +220,10 @@ public class TextChange extends Transition {
|
||||
if (startText.equals(view.getText())) {
|
||||
// Only set if it hasn't been changed since anim started
|
||||
view.setText(endText);
|
||||
if (view instanceof EditText) {
|
||||
setSelection(((EditText) view), endSelectionStart,
|
||||
endSelectionEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -220,11 +256,17 @@ public class TextChange extends Transition {
|
||||
@Override
|
||||
public void onTransitionPause(Transition transition) {
|
||||
view.setText(endText);
|
||||
if (view instanceof EditText) {
|
||||
setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransitionResume(Transition transition) {
|
||||
view.setText(startText);
|
||||
if (view instanceof EditText) {
|
||||
setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
|
||||
}
|
||||
}
|
||||
};
|
||||
addListener(transitionListener);
|
||||
@@ -235,4 +277,10 @@ public class TextChange extends Transition {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setSelection(EditText editText, int start, int end) {
|
||||
if (start >= 0 && end >= 0) {
|
||||
editText.setSelection(start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1094,7 +1094,11 @@ public abstract class Transition implements Cloneable {
|
||||
}
|
||||
TransitionValues values = new TransitionValues();
|
||||
values.view = view;
|
||||
captureStartValues(values);
|
||||
if (start) {
|
||||
captureStartValues(values);
|
||||
} else {
|
||||
captureEndValues(values);
|
||||
}
|
||||
if (start) {
|
||||
if (!isListViewItem) {
|
||||
mStartValues.viewValues.put(view, values);
|
||||
|
||||
@@ -21,27 +21,38 @@ import android.transition.ChangeBounds;
|
||||
import android.transition.Fade;
|
||||
import android.transition.TextChange;
|
||||
import android.transition.Transition;
|
||||
import android.transition.TransitionManager;
|
||||
import android.transition.TransitionSet;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class ActionBarTransition {
|
||||
|
||||
private static boolean TRANSITIONS_ENABLED = false;
|
||||
|
||||
private static final int TRANSITION_DURATION = 120; // ms
|
||||
|
||||
private static final Transition sTransition;
|
||||
|
||||
static {
|
||||
final TextChange tc = new TextChange();
|
||||
tc.setChangeBehavior(TextChange.CHANGE_BEHAVIOR_OUT_IN);
|
||||
final TransitionSet inner = new TransitionSet();
|
||||
inner.addTransition(tc).addTransition(new ChangeBounds());
|
||||
final TransitionSet tg = new TransitionSet();
|
||||
tg.addTransition(new Fade(Fade.OUT)).addTransition(inner).addTransition(new Fade(Fade.IN));
|
||||
tg.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
|
||||
tg.setDuration(TRANSITION_DURATION);
|
||||
sTransition = tg;
|
||||
if (TRANSITIONS_ENABLED) {
|
||||
final TextChange tc = new TextChange();
|
||||
tc.setChangeBehavior(TextChange.CHANGE_BEHAVIOR_OUT_IN);
|
||||
final TransitionSet inner = new TransitionSet();
|
||||
inner.addTransition(tc).addTransition(new ChangeBounds());
|
||||
final TransitionSet tg = new TransitionSet();
|
||||
tg.addTransition(new Fade(Fade.OUT)).addTransition(inner).
|
||||
addTransition(new Fade(Fade.IN));
|
||||
tg.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
|
||||
tg.setDuration(TRANSITION_DURATION);
|
||||
sTransition = tg;
|
||||
} else {
|
||||
sTransition = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Transition getActionBarTransition() {
|
||||
return sTransition;
|
||||
public static void beginDelayedTransition(ViewGroup sceneRoot) {
|
||||
if (TRANSITIONS_ENABLED) {
|
||||
TransitionManager.beginDelayedTransition(sceneRoot, sTransition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,6 @@ public class ActionMenuPresenter extends BaseMenuPresenter
|
||||
final PopupPresenterCallback mPopupPresenterCallback = new PopupPresenterCallback();
|
||||
int mOpenSubMenuId;
|
||||
|
||||
private static final Transition sTransition = ActionBarTransition.getActionBarTransition();
|
||||
|
||||
public ActionMenuPresenter(Context context) {
|
||||
super(context, com.android.internal.R.layout.action_menu_layout,
|
||||
com.android.internal.R.layout.action_menu_item_layout);
|
||||
@@ -213,7 +211,7 @@ public class ActionMenuPresenter extends BaseMenuPresenter
|
||||
public void updateMenuView(boolean cleared) {
|
||||
final ViewGroup menuViewParent = (ViewGroup) ((View) mMenuView).getParent();
|
||||
if (menuViewParent != null) {
|
||||
TransitionManager.beginDelayedTransition(menuViewParent, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(menuViewParent);
|
||||
}
|
||||
super.updateMenuView(cleared);
|
||||
|
||||
|
||||
@@ -144,8 +144,6 @@ public class ActionBarView extends AbsActionBarView {
|
||||
|
||||
Window.Callback mWindowCallback;
|
||||
|
||||
private final static Transition sTransition = ActionBarTransition.getActionBarTransition();
|
||||
|
||||
private final AdapterView.OnItemSelectedListener mNavItemSelectedListener =
|
||||
new AdapterView.OnItemSelectedListener() {
|
||||
public void onItemSelected(AdapterView parent, View view, int position, long id) {
|
||||
@@ -483,7 +481,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
public void setCustomNavigationView(View view) {
|
||||
final boolean showCustom = (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0;
|
||||
if (showCustom) {
|
||||
TransitionManager.beginDelayedTransition(this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(this);
|
||||
}
|
||||
if (mCustomNavView != null && showCustom) {
|
||||
removeView(mCustomNavView);
|
||||
@@ -522,7 +520,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
}
|
||||
|
||||
private void setTitleImpl(CharSequence title) {
|
||||
TransitionManager.beginDelayedTransition(this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(this);
|
||||
mTitle = title;
|
||||
if (mTitleView != null) {
|
||||
mTitleView.setText(title);
|
||||
@@ -542,7 +540,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
}
|
||||
|
||||
public void setSubtitle(CharSequence subtitle) {
|
||||
TransitionManager.beginDelayedTransition(this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(this);
|
||||
mSubtitle = subtitle;
|
||||
if (mSubtitleView != null) {
|
||||
mSubtitleView.setText(subtitle);
|
||||
@@ -623,7 +621,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
mDisplayOptions = options;
|
||||
|
||||
if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) {
|
||||
TransitionManager.beginDelayedTransition(this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(this);
|
||||
|
||||
if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
|
||||
final boolean setUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0;
|
||||
@@ -737,7 +735,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
public void setNavigationMode(int mode) {
|
||||
final int oldMode = mNavigationMode;
|
||||
if (mode != oldMode) {
|
||||
TransitionManager.beginDelayedTransition(this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(this);
|
||||
switch (oldMode) {
|
||||
case ActionBar.NAVIGATION_MODE_LIST:
|
||||
if (mListNavLayout != null) {
|
||||
@@ -860,7 +858,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
}
|
||||
}
|
||||
|
||||
TransitionManager.beginDelayedTransition(this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(this);
|
||||
mUpGoerFive.addView(mTitleLayout);
|
||||
if (mExpandedActionView != null ||
|
||||
(TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mSubtitle))) {
|
||||
@@ -1639,7 +1637,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
|
||||
@Override
|
||||
public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
|
||||
TransitionManager.beginDelayedTransition(ActionBarView.this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(ActionBarView.this);
|
||||
|
||||
mExpandedActionView = item.getActionView();
|
||||
mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(getResources()));
|
||||
@@ -1668,7 +1666,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
|
||||
@Override
|
||||
public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
|
||||
TransitionManager.beginDelayedTransition(ActionBarView.this, sTransition);
|
||||
ActionBarTransition.beginDelayedTransition(ActionBarView.this);
|
||||
|
||||
// Do this before detaching the actionview from the hierarchy, in case
|
||||
// it needs to dismiss the soft keyboard, etc.
|
||||
|
||||
Reference in New Issue
Block a user