From a512b41399eecab9b68d927374ec34940f8644c5 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Wed, 28 Jan 2015 17:13:29 -0800 Subject: [PATCH] Bug 1106935 - Part 2: Remove old tablet branches from BrowserToolbar. --HG-- extra : rebase_source : 23d07e6568c4a4a778f8a4ee926ffbdbbd3f9439 --- .../android/base/toolbar/BrowserToolbar.java | 45 +----------- .../base/toolbar/BrowserToolbarPhoneBase.java | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+), 43 deletions(-) diff --git a/mobile/android/base/toolbar/BrowserToolbar.java b/mobile/android/base/toolbar/BrowserToolbar.java index fced287bf358..d6fe1cdbf786 100644 --- a/mobile/android/base/toolbar/BrowserToolbar.java +++ b/mobile/android/base/toolbar/BrowserToolbar.java @@ -108,8 +108,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout DISPLAY } - private final boolean isNewTablet; - protected final ToolbarDisplayLayout urlDisplayLayout; protected final ToolbarEditLayout urlEditLayout; protected final View urlBarEntry; @@ -123,8 +121,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout private MenuPopup menuPopup; protected final List focusOrder; - protected final ThemedImageView editCancel; - private OnActivateListener activateListener; private OnFocusChangeListener focusChangeListener; private OnStartEditingListener startEditingListener; @@ -177,14 +173,11 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout super(context, attrs); setWillNotDraw(false); - isNewTablet = NewTabletUI.isEnabled(context); - // BrowserToolbar is attached to BrowserApp only. activity = (BrowserApp) context; // Inflate the content. - // TODO: Remove the branch when new tablet becomes old tablet. - if (!isNewTablet) { + if (!HardwareUtils.isTablet()) { LayoutInflater.from(context).inflate(R.layout.browser_toolbar, this); } else { LayoutInflater.from(context).inflate(R.layout.new_tablet_browser_toolbar, this); @@ -207,8 +200,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout menuIcon = (ThemedImageView) findViewById(R.id.menu_icon); hasSoftMenuButton = !HardwareUtils.hasMenuButton(); - editCancel = (ThemedImageView) findViewById(R.id.edit_cancel); - // The focusOrder List should be filled by sub-classes. focusOrder = new ArrayList(); @@ -333,20 +324,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout }); tabsButton.setImageLevel(0); - editCancel.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - // If we exit editing mode during the animation, - // we're put into an inconsistent state (bug 1017276). - if (!isAnimating()) { - Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, - TelemetryContract.Method.ACTIONBAR, - getResources().getResourceEntryName(editCancel.getId())); - cancelEdit(); - } - } - }); - if (hasSoftMenuButton) { menuButton.setVisibility(View.VISIBLE); menuIcon.setVisibility(View.VISIBLE); @@ -745,7 +722,7 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout setUrlEditLayoutVisibility(false, animator); } - private void setUrlEditLayoutVisibility(final boolean showEditLayout, PropertyAnimator animator) { + protected void setUrlEditLayoutVisibility(final boolean showEditLayout, PropertyAnimator animator) { if (showEditLayout) { urlEditLayout.prepareShowAnimation(animator); } @@ -756,9 +733,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout viewToHide.setVisibility(View.GONE); viewToShow.setVisibility(View.VISIBLE); - - final int cancelVisibility = (showEditLayout ? View.VISIBLE : View.INVISIBLE); - setCancelVisibility(cancelVisibility); return; } @@ -768,8 +742,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout if (!showEditLayout) { urlEditLayout.setVisibility(View.GONE); urlDisplayLayout.setVisibility(View.VISIBLE); - - setCancelVisibility(View.INVISIBLE); } } @@ -778,20 +750,11 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout if (showEditLayout) { urlDisplayLayout.setVisibility(View.GONE); urlEditLayout.setVisibility(View.VISIBLE); - - setCancelVisibility(View.VISIBLE); } } }); } - private void setCancelVisibility(final int visibility) { - // TODO: Remove this check (and maybe method) when NewTablet's editing mode is implemented. - if (!isNewTablet) { - editCancel.setVisibility(visibility); - } - } - private void setUIMode(final UIMode uiMode) { this.uiMode = uiMode; urlEditLayout.setEnabled(uiMode == UIMode.EDIT); @@ -870,7 +833,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout tabsButton.setPrivateMode(isPrivate); menuButton.setPrivateMode(isPrivate); menuIcon.setPrivateMode(isPrivate); - editCancel.setPrivateMode(isPrivate); urlEditLayout.setPrivateMode(isPrivate); } @@ -941,14 +903,11 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout stateList.addState(EMPTY_STATE_SET, drawable); setBackgroundDrawable(stateList); - - editCancel.onLightweightThemeChanged(); } @Override public void onLightweightThemeReset() { setBackgroundResource(R.drawable.url_bar_bg); - editCancel.onLightweightThemeReset(); } public static LightweightThemeDrawable getLightweightThemeDrawable(final View view, diff --git a/mobile/android/base/toolbar/BrowserToolbarPhoneBase.java b/mobile/android/base/toolbar/BrowserToolbarPhoneBase.java index b39ad4959c55..fb87d2b98f4e 100644 --- a/mobile/android/base/toolbar/BrowserToolbarPhoneBase.java +++ b/mobile/android/base/toolbar/BrowserToolbarPhoneBase.java @@ -9,6 +9,8 @@ import java.util.Arrays; import org.mozilla.gecko.R; import org.mozilla.gecko.Tab; +import org.mozilla.gecko.Telemetry; +import org.mozilla.gecko.TelemetryContract; import org.mozilla.gecko.animation.PropertyAnimator; import org.mozilla.gecko.animation.ViewHelper; @@ -22,6 +24,7 @@ import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ImageView; +import org.mozilla.gecko.widget.ThemedImageView; /** * A base implementations of the browser toolbar for phones. @@ -30,6 +33,7 @@ import android.widget.ImageView; abstract class BrowserToolbarPhoneBase extends BrowserToolbar { protected final ImageView urlBarTranslatingEdge; + protected final ThemedImageView editCancel; private final Path roundCornerShape; private final Paint roundCornerPaint; @@ -45,6 +49,8 @@ abstract class BrowserToolbarPhoneBase extends BrowserToolbar { // This will clip the translating edge's image at 60% of its width urlBarTranslatingEdge.getDrawable().setLevel(6000); + editCancel = (ThemedImageView) findViewById(R.id.edit_cancel); + focusOrder.add(this); focusOrder.addAll(urlDisplayLayout.getFocusOrder()); focusOrder.addAll(Arrays.asList(tabsButton, menuButton)); @@ -61,6 +67,31 @@ abstract class BrowserToolbarPhoneBase extends BrowserToolbar { roundCornerPaint.setStrokeWidth(0.0f); } + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + + editCancel.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + // If we exit editing mode during the animation, + // we're put into an inconsistent state (bug 1017276). + if (!isAnimating()) { + Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, + TelemetryContract.Method.ACTIONBAR, + getResources().getResourceEntryName(editCancel.getId())); + cancelEdit(); + } + } + }); + } + + @Override + public void setPrivateMode(final boolean isPrivate) { + super.setPrivateMode(isPrivate); + editCancel.setPrivateMode(isPrivate); + } + @Override protected boolean isTabsButtonOffscreen() { return isEditing(); @@ -152,4 +183,42 @@ abstract class BrowserToolbarPhoneBase extends BrowserToolbar { } } + @Override + protected void setUrlEditLayoutVisibility(final boolean showEditLayout, + final PropertyAnimator animator) { + super.setUrlEditLayoutVisibility(showEditLayout, animator); + + if (animator == null) { + editCancel.setVisibility(showEditLayout ? View.VISIBLE : View.INVISIBLE); + return; + } + + animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { + @Override + public void onPropertyAnimationStart() { + if (!showEditLayout) { + editCancel.setVisibility(View.INVISIBLE); + } + } + + @Override + public void onPropertyAnimationEnd() { + if (showEditLayout) { + editCancel.setVisibility(View.VISIBLE); + } + } + }); + } + + @Override + public void onLightweightThemeChanged() { + super.onLightweightThemeChanged(); + editCancel.onLightweightThemeChanged(); + } + + @Override + public void onLightweightThemeReset() { + super.onLightweightThemeReset(); + editCancel.onLightweightThemeReset(); + } }