author | Michael Comella <michael.l.comella@gmail.com> |
Thu, 17 Apr 2014 13:34:12 -0700 | |
changeset 179089 | d46231f4d4ae9e73a5c41c637ca4ac8e1a9eab0d |
parent 179088 | 9a5586190013a870fcf0b2b2eb64039fdcd24db4 |
child 179090 | 62a5caa65d45503838a232d70a2de7fc3effd789 |
push id | 26606 |
push user | ryanvm@gmail.com |
push date | Fri, 18 Apr 2014 02:20:00 +0000 |
treeherder | mozilla-central@ec728bfdbb79 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | lucasr |
bugs | 965548 |
milestone | 31.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/mobile/android/base/toolbar/BrowserToolbar.java +++ b/mobile/android/base/toolbar/BrowserToolbar.java @@ -15,17 +15,16 @@ import org.mozilla.gecko.BrowserApp; import org.mozilla.gecko.GeckoAppShell; import org.mozilla.gecko.GeckoApplication; import org.mozilla.gecko.GeckoProfile; import org.mozilla.gecko.LightweightTheme; import org.mozilla.gecko.R; import org.mozilla.gecko.Tab; import org.mozilla.gecko.Tabs; import org.mozilla.gecko.animation.PropertyAnimator; -import org.mozilla.gecko.animation.PropertyAnimator.Property; import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener; import org.mozilla.gecko.animation.ViewHelper; import org.mozilla.gecko.menu.GeckoMenu; import org.mozilla.gecko.menu.MenuPopup; import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnStopListener; import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnTitleChangeListener; import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.UpdateFlags; import org.mozilla.gecko.util.Clipboard; @@ -113,164 +112,159 @@ public class BrowserToolbar extends Them DISPLAY } enum ForwardButtonAnimation { SHOW, HIDE } - private ToolbarDisplayLayout mUrlDisplayLayout; - private ToolbarEditLayout mUrlEditLayout; - private View mUrlBarEntry; + private ToolbarDisplayLayout urlDisplayLayout; + private ToolbarEditLayout urlEditLayout; + private View urlBarEntry; private RelativeLayout.LayoutParams urlBarEntryDefaultLayoutParams; private RelativeLayout.LayoutParams urlBarEntryShrunkenLayoutParams; private ImageView urlBarTranslatingEdge; - private boolean mSwitchingTabs; - private ShapedButton mTabs; - private ImageButton mBack; - private ImageButton mForward; + private boolean isSwitchingTabs; + private ShapedButton tabsButton; + private ImageButton backButton; + private ImageButton forwardButton; - private ToolbarProgressView mProgressBar; - private TabCounter mTabsCounter; - private ThemedImageButton mMenu; - private ThemedImageView mMenuIcon; - private LinearLayout mActionItemBar; - private MenuPopup mMenuPopup; - private List<View> mFocusOrder; + private ToolbarProgressView progressBar; + private TabCounter tabsCounter; + private ThemedImageButton menuButton; + private ThemedImageView menuIcon; + private LinearLayout actionItemBar; + private MenuPopup menuPopup; + private List<View> focusOrder; private final ThemedView editSeparator; private final View editCancel; private boolean shouldShrinkURLBar = false; - private OnActivateListener mActivateListener; - private OnCommitListener mCommitListener; - private OnDismissListener mDismissListener; - private OnFilterListener mFilterListener; - private OnFocusChangeListener mFocusChangeListener; - private OnStartEditingListener mStartEditingListener; - private OnStopEditingListener mStopEditingListener; + private OnActivateListener activateListener; + private OnFocusChangeListener focusChangeListener; + private OnStartEditingListener startEditingListener; + private OnStopEditingListener stopEditingListener; + + final private BrowserApp activity; + private boolean hasSoftMenuButton; - final private BrowserApp mActivity; - private boolean mHasSoftMenuButton; + private UIMode uiMode; + private boolean isAnimatingEntry; - private UIMode mUIMode; - private boolean mAnimatingEntry; + private int urlBarViewOffset; + private int defaultForwardMargin; - private int mUrlBarViewOffset; - private int mDefaultForwardMargin; - - private static final Interpolator sButtonsInterpolator = new AccelerateInterpolator(); + private static final Interpolator buttonsInterpolator = new AccelerateInterpolator(); private static final int FORWARD_ANIMATION_DURATION = 450; - private final LightweightTheme mTheme; + private final LightweightTheme theme; public BrowserToolbar(Context context) { this(context, null); } public BrowserToolbar(Context context, AttributeSet attrs) { super(context, attrs); - mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme(); + theme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme(); // BrowserToolbar is attached to BrowserApp only. - mActivity = (BrowserApp) context; + activity = (BrowserApp) context; // Inflate the content. LayoutInflater.from(context).inflate(R.layout.browser_toolbar, this); Tabs.registerOnTabsChangedListener(this); - mSwitchingTabs = true; - mAnimatingEntry = false; + isSwitchingTabs = true; + isAnimatingEntry = false; registerEventListener("Reader:Click"); registerEventListener("Reader:LongClick"); - mAnimatingEntry = false; + final Resources res = getResources(); + urlBarViewOffset = res.getDimensionPixelSize(R.dimen.url_bar_offset_left); + defaultForwardMargin = res.getDimensionPixelSize(R.dimen.forward_default_offset); + urlDisplayLayout = (ToolbarDisplayLayout) findViewById(R.id.display_layout); + urlBarEntry = findViewById(R.id.url_bar_entry); + urlEditLayout = (ToolbarEditLayout) findViewById(R.id.edit_layout); - final Resources res = getResources(); - mUrlBarViewOffset = res.getDimensionPixelSize(R.dimen.url_bar_offset_left); - mDefaultForwardMargin = res.getDimensionPixelSize(R.dimen.forward_default_offset); - mUrlDisplayLayout = (ToolbarDisplayLayout) findViewById(R.id.display_layout); - mUrlBarEntry = findViewById(R.id.url_bar_entry); - mUrlEditLayout = (ToolbarEditLayout) findViewById(R.id.edit_layout); - - urlBarEntryDefaultLayoutParams = (RelativeLayout.LayoutParams) mUrlBarEntry.getLayoutParams(); + urlBarEntryDefaultLayoutParams = (RelativeLayout.LayoutParams) urlBarEntry.getLayoutParams(); urlBarEntryShrunkenLayoutParams = new RelativeLayout.LayoutParams(urlBarEntryDefaultLayoutParams); urlBarEntryShrunkenLayoutParams.addRule(RelativeLayout.ALIGN_RIGHT, R.id.edit_layout); urlBarEntryShrunkenLayoutParams.rightMargin = 0; // This will clip the translating edge's image at 60% of its width urlBarTranslatingEdge = (ImageView) findViewById(R.id.url_bar_translating_edge); if (urlBarTranslatingEdge != null) { urlBarTranslatingEdge.getDrawable().setLevel(6000); } - mTabs = (ShapedButton) findViewById(R.id.tabs); - mTabsCounter = (TabCounter) findViewById(R.id.tabs_counter); + tabsButton = (ShapedButton) findViewById(R.id.tabs); + tabsCounter = (TabCounter) findViewById(R.id.tabs_counter); if (Build.VERSION.SDK_INT >= 11) { - mTabsCounter.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + tabsCounter.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } - mBack = (ImageButton) findViewById(R.id.back); - setButtonEnabled(mBack, false); - mForward = (ImageButton) findViewById(R.id.forward); - setButtonEnabled(mForward, false); + backButton = (ImageButton) findViewById(R.id.back); + setButtonEnabled(backButton, false); + forwardButton = (ImageButton) findViewById(R.id.forward); + setButtonEnabled(forwardButton, false); - mMenu = (ThemedImageButton) findViewById(R.id.menu); - mMenuIcon = (ThemedImageView) findViewById(R.id.menu_icon); - mActionItemBar = (LinearLayout) findViewById(R.id.menu_items); - mHasSoftMenuButton = !HardwareUtils.hasMenuButton(); + menuButton = (ThemedImageButton) findViewById(R.id.menu); + menuIcon = (ThemedImageView) findViewById(R.id.menu_icon); + actionItemBar = (LinearLayout) findViewById(R.id.menu_items); + hasSoftMenuButton = !HardwareUtils.hasMenuButton(); editSeparator = (ThemedView) findViewById(R.id.edit_separator); editCancel = findViewById(R.id.edit_cancel); // We use different layouts on phones and tablets, so adjust the focus // order appropriately. - mFocusOrder = new ArrayList<View>(); + focusOrder = new ArrayList<View>(); if (HardwareUtils.isTablet()) { - mFocusOrder.addAll(Arrays.asList(mTabs, mBack, mForward, this)); - mFocusOrder.addAll(mUrlDisplayLayout.getFocusOrder()); - mFocusOrder.addAll(Arrays.asList(mActionItemBar, mMenu)); + focusOrder.addAll(Arrays.asList(tabsButton, backButton, forwardButton, this)); + focusOrder.addAll(urlDisplayLayout.getFocusOrder()); + focusOrder.addAll(Arrays.asList(actionItemBar, menuButton)); } else { - mFocusOrder.add(this); - mFocusOrder.addAll(mUrlDisplayLayout.getFocusOrder()); - mFocusOrder.addAll(Arrays.asList(mTabs, mMenu)); + focusOrder.add(this); + focusOrder.addAll(urlDisplayLayout.getFocusOrder()); + focusOrder.addAll(Arrays.asList(tabsButton, menuButton)); } setUIMode(UIMode.DISPLAY); } @Override public void onAttachedToWindow() { super.onAttachedToWindow(); setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { - if (mActivateListener != null) { - mActivateListener.onActivate(); + if (activateListener != null) { + activateListener.onActivate(); } } }); setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { // We don't the context menu while editing if (isEditing()) { return; } // NOTE: Use MenuUtils.safeSetVisible because some actions might // be on the Page menu - MenuInflater inflater = mActivity.getMenuInflater(); + MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.titlebar_contextmenu, menu); String clipboard = Clipboard.getText(); if (TextUtils.isEmpty(clipboard)) { menu.findItem(R.id.pasteandgo).setVisible(false); menu.findItem(R.id.paste).setVisible(false); } @@ -293,124 +287,124 @@ public class BrowserToolbar extends Them MenuUtils.safeSetVisible(menu, R.id.subscribe, false); MenuUtils.safeSetVisible(menu, R.id.add_search_engine, false); } MenuUtils.safeSetVisible(menu, R.id.share, !GeckoProfile.get(getContext()).inGuestMode()); } }); - mUrlDisplayLayout.setOnStopListener(new OnStopListener() { + urlDisplayLayout.setOnStopListener(new OnStopListener() { @Override public Tab onStop() { final Tab tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { tab.doStop(); return tab; } return null; } }); - mUrlDisplayLayout.setOnTitleChangeListener(new OnTitleChangeListener() { + urlDisplayLayout.setOnTitleChangeListener(new OnTitleChangeListener() { @Override public void onTitleChange(CharSequence title) { final String contentDescription; if (title != null) { contentDescription = title.toString(); } else { - contentDescription = mActivity.getString(R.string.url_bar_default_text); + contentDescription = activity.getString(R.string.url_bar_default_text); } // The title and content description should // always be sync. setContentDescription(contentDescription); } }); - mUrlEditLayout.setOnFocusChangeListener(new View.OnFocusChangeListener() { + urlEditLayout.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { setSelected(hasFocus); - if (mFocusChangeListener != null) { - mFocusChangeListener.onFocusChange(v, hasFocus); + if (focusChangeListener != null) { + focusChangeListener.onFocusChange(v, hasFocus); } } }); - mTabs.setOnClickListener(new Button.OnClickListener() { + tabsButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { toggleTabs(); } }); - mTabs.setImageLevel(0); + tabsButton.setImageLevel(0); - mBack.setOnClickListener(new Button.OnClickListener() { + backButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { Tabs.getInstance().getSelectedTab().doBack(); } }); - mBack.setOnLongClickListener(new Button.OnLongClickListener() { + backButton.setOnLongClickListener(new Button.OnLongClickListener() { @Override public boolean onLongClick(View view) { return Tabs.getInstance().getSelectedTab().showBackHistory(); } }); - mForward.setOnClickListener(new Button.OnClickListener() { + forwardButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { Tabs.getInstance().getSelectedTab().doForward(); } }); - mForward.setOnLongClickListener(new Button.OnLongClickListener() { + forwardButton.setOnLongClickListener(new Button.OnLongClickListener() { @Override public boolean onLongClick(View view) { return Tabs.getInstance().getSelectedTab().showForwardHistory(); } }); editCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { cancelEdit(); } }); - if (mHasSoftMenuButton) { - mMenu.setVisibility(View.VISIBLE); - mMenuIcon.setVisibility(View.VISIBLE); + if (hasSoftMenuButton) { + menuButton.setVisibility(View.VISIBLE); + menuIcon.setVisibility(View.VISIBLE); - mMenu.setOnClickListener(new Button.OnClickListener() { + menuButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { - mActivity.openOptionsMenu(); + activity.openOptionsMenu(); } }); } } public void setProgressBar(ToolbarProgressView progressBar) { - mProgressBar = progressBar; + this.progressBar = progressBar; } public void refresh() { - mUrlDisplayLayout.dismissSiteIdentityPopup(); + urlDisplayLayout.dismissSiteIdentityPopup(); } public boolean onBackPressed() { if (isEditing()) { stopEditing(); return true; } - return mUrlDisplayLayout.dismissSiteIdentityPopup(); + return urlDisplayLayout.dismissSiteIdentityPopup(); } public boolean onKey(int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) { return false; } // Galaxy Note sends key events for the stylus that are outside of the @@ -428,17 +422,17 @@ public class BrowserToolbar extends Them keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { return false; } else if (isEditing()) { - return mUrlEditLayout.onKey(keyCode, event); + return urlEditLayout.onKey(keyCode, event); } return false; } @Override public boolean onTouchEvent(MotionEvent event) { // If the motion event has occured below the toolbar (due to the scroll @@ -455,17 +449,17 @@ public class BrowserToolbar extends Them super.onSizeChanged(w, h, oldw, oldh); if (h != oldh) { // Post this to happen outside of onSizeChanged, as this may cause // a layout change and relayouts within a layout change don't work. post(new Runnable() { @Override public void run() { - mActivity.refreshToolbarHeight(); + activity.refreshToolbarHeight(); } }); } } @Override public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) { Log.d(LOGTAG, "onTabChanged: " + msg); @@ -479,19 +473,19 @@ public class BrowserToolbar extends Them switch (msg) { case ADDED: case CLOSED: updateTabCount(tabs.getDisplayCount()); break; case RESTORED: // TabCount fixup after OOM case SELECTED: - mUrlDisplayLayout.dismissSiteIdentityPopup(); + urlDisplayLayout.dismissSiteIdentityPopup(); updateTabCount(tabs.getDisplayCount()); - mSwitchingTabs = true; + isSwitchingTabs = true; break; } if (tabs.isSelectedTab(tab)) { final EnumSet<UpdateFlags> flags = EnumSet.noneOf(UpdateFlags.class); // Progress-related handling switch (msg) { @@ -499,18 +493,18 @@ public class BrowserToolbar extends Them updateProgressVisibility(tab, Tab.LOAD_PROGRESS_INIT); // Fall through. case ADDED: case LOCATION_CHANGE: case LOAD_ERROR: case LOADED: case STOP: flags.add(UpdateFlags.PROGRESS); - if (mProgressBar.getVisibility() == View.VISIBLE) { - mProgressBar.animateProgress(tab.getLoadProgress()); + if (progressBar.getVisibility() == View.VISIBLE) { + progressBar.animateProgress(tab.getLoadProgress()); } break; case SELECTED: flags.add(UpdateFlags.PROGRESS); updateProgressVisibility(); break; } @@ -562,170 +556,170 @@ public class BrowserToolbar extends Them updateDisplayLayout(tab, flags); } } switch (msg) { case SELECTED: case LOAD_ERROR: case LOCATION_CHANGE: - mSwitchingTabs = false; + isSwitchingTabs = false; } } private void updateProgressVisibility() { final Tab selectedTab = Tabs.getInstance().getSelectedTab(); updateProgressVisibility(selectedTab, selectedTab.getLoadProgress()); } private void updateProgressVisibility(Tab selectedTab, int progress) { if (!isEditing() && selectedTab.getState() == Tab.STATE_LOADING) { - mProgressBar.setProgress(progress); - mProgressBar.setVisibility(View.VISIBLE); + progressBar.setProgress(progress); + progressBar.setVisibility(View.VISIBLE); } else { - mProgressBar.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); } } public boolean isVisible() { return ViewHelper.getTranslationY(this) == 0; } @Override public void setNextFocusDownId(int nextId) { super.setNextFocusDownId(nextId); - mTabs.setNextFocusDownId(nextId); - mBack.setNextFocusDownId(nextId); - mForward.setNextFocusDownId(nextId); - mUrlDisplayLayout.setNextFocusDownId(nextId); - mMenu.setNextFocusDownId(nextId); + tabsButton.setNextFocusDownId(nextId); + backButton.setNextFocusDownId(nextId); + forwardButton.setNextFocusDownId(nextId); + urlDisplayLayout.setNextFocusDownId(nextId); + menuButton.setNextFocusDownId(nextId); } private int getUrlBarEntryTranslation() { // We would ideally use the right-most point of the edit layout instead of the // edit separator and its margin, but it is not inflated when this code initially runs. final LayoutParams lp = (LayoutParams) editSeparator.getLayoutParams(); - return editSeparator.getLeft() - lp.leftMargin - mUrlBarEntry.getRight(); + return editSeparator.getLeft() - lp.leftMargin - urlBarEntry.getRight(); } private int getUrlBarCurveTranslation() { - return getWidth() - mTabs.getLeft(); + return getWidth() - tabsButton.getLeft(); } private boolean canDoBack(Tab tab) { return (tab.canDoBack() && !isEditing()); } private boolean canDoForward(Tab tab) { return (tab.canDoForward() && !isEditing()); } private void addTab() { - mActivity.addTab(); + activity.addTab(); } private void toggleTabs() { - if (mActivity.areTabsShown()) { - if (mActivity.hasTabsSideBar()) - mActivity.hideTabs(); + if (activity.areTabsShown()) { + if (activity.hasTabsSideBar()) + activity.hideTabs(); } else { // hide the virtual keyboard InputMethodManager imm = - (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(mTabs.getWindowToken(), 0); + (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(tabsButton.getWindowToken(), 0); Tab tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { if (!tab.isPrivate()) - mActivity.showNormalTabs(); + activity.showNormalTabs(); else - mActivity.showPrivateTabs(); + activity.showPrivateTabs(); } } } private void updateTabCountAndAnimate(int count) { // Don't animate if the toolbar is hidden. if (!isVisible()) { updateTabCount(count); return; } // If toolbar is in edit mode on a phone, this means the entry is expanded // and the tabs button is translated offscreen. Don't trigger tabs counter // updates until the tabs button is back on screen. // See stopEditing() if (!isEditing() || HardwareUtils.isTablet()) { - mTabsCounter.setCount(count); + tabsCounter.setCount(count); - mTabs.setContentDescription((count > 1) ? - mActivity.getString(R.string.num_tabs, count) : - mActivity.getString(R.string.one_tab)); + tabsButton.setContentDescription((count > 1) ? + activity.getString(R.string.num_tabs, count) : + activity.getString(R.string.one_tab)); } } private void updateTabCount(int count) { // If toolbar is in edit mode on a phone, this means the entry is expanded // and the tabs button is translated offscreen. Don't trigger tabs counter // updates until the tabs button is back on screen. // See stopEditing() if (isEditing() && !HardwareUtils.isTablet()) { return; } // Set TabCounter based on visibility - if (isVisible() && ViewHelper.getAlpha(mTabsCounter) != 0 && !isEditing()) { - mTabsCounter.setCountWithAnimation(count); + if (isVisible() && ViewHelper.getAlpha(tabsCounter) != 0 && !isEditing()) { + tabsCounter.setCountWithAnimation(count); } else { - mTabsCounter.setCount(count); + tabsCounter.setCount(count); } // Update A11y information - mTabs.setContentDescription((count > 1) ? - mActivity.getString(R.string.num_tabs, count) : - mActivity.getString(R.string.one_tab)); + tabsButton.setContentDescription((count > 1) ? + activity.getString(R.string.num_tabs, count) : + activity.getString(R.string.one_tab)); } private void updateDisplayLayout(Tab tab, EnumSet<UpdateFlags> flags) { - if (mSwitchingTabs) { + if (isSwitchingTabs) { flags.add(UpdateFlags.DISABLE_ANIMATIONS); } - mUrlDisplayLayout.updateFromTab(tab, flags); + urlDisplayLayout.updateFromTab(tab, flags); if (flags.contains(UpdateFlags.TITLE)) { if (!isEditing()) { - mUrlEditLayout.setText(tab.getURL()); + urlEditLayout.setText(tab.getURL()); } } if (flags.contains(UpdateFlags.PROGRESS)) { updateFocusOrder(); } } private void updateFocusOrder() { View prevView = null; // If the element that has focus becomes disabled or invisible, focus // is given to the URL bar. boolean needsNewFocus = false; - for (View view : mFocusOrder) { + for (View view : focusOrder) { if (view.getVisibility() != View.VISIBLE || !view.isEnabled()) { if (view.hasFocus()) { needsNewFocus = true; } continue; } - if (view == mActionItemBar) { - final int childCount = mActionItemBar.getChildCount(); + if (view == actionItemBar) { + final int childCount = actionItemBar.getChildCount(); for (int child = 0; child < childCount; child++) { - View childView = mActionItemBar.getChildAt(child); + View childView = actionItemBar.getChildAt(child); if (prevView != null) { childView.setNextFocusLeftId(prevView.getId()); prevView.setNextFocusRightId(childView.getId()); } prevView = childView; } } else { if (prevView != null) { @@ -741,99 +735,96 @@ public class BrowserToolbar extends Them } } public void onEditSuggestion(String suggestion) { if (!isEditing()) { return; } - mUrlEditLayout.onEditSuggestion(suggestion); + urlEditLayout.onEditSuggestion(suggestion); } public void setTitle(CharSequence title) { - mUrlDisplayLayout.setTitle(title); + urlDisplayLayout.setTitle(title); } public void prepareTabsAnimation(PropertyAnimator animator, boolean tabsAreShown) { if (!tabsAreShown) { PropertyAnimator buttonsAnimator = - new PropertyAnimator(animator.getDuration(), sButtonsInterpolator); + new PropertyAnimator(animator.getDuration(), buttonsInterpolator); - buttonsAnimator.attach(mTabsCounter, + buttonsAnimator.attach(tabsCounter, PropertyAnimator.Property.ALPHA, 1.0f); - if (mHasSoftMenuButton && !HardwareUtils.isTablet()) { - buttonsAnimator.attach(mMenuIcon, + if (hasSoftMenuButton && !HardwareUtils.isTablet()) { + buttonsAnimator.attach(menuIcon, PropertyAnimator.Property.ALPHA, 1.0f); } buttonsAnimator.start(); return; } - ViewHelper.setAlpha(mTabsCounter, 0.0f); + ViewHelper.setAlpha(tabsCounter, 0.0f); - if (mHasSoftMenuButton && !HardwareUtils.isTablet()) { - ViewHelper.setAlpha(mMenuIcon, 0.0f); + if (hasSoftMenuButton && !HardwareUtils.isTablet()) { + ViewHelper.setAlpha(menuIcon, 0.0f); } } public void finishTabsAnimation(boolean tabsAreShown) { if (tabsAreShown) { return; } PropertyAnimator animator = new PropertyAnimator(150); - animator.attach(mTabsCounter, + animator.attach(tabsCounter, PropertyAnimator.Property.ALPHA, 1.0f); - if (mHasSoftMenuButton && !HardwareUtils.isTablet()) { - animator.attach(mMenuIcon, + if (hasSoftMenuButton && !HardwareUtils.isTablet()) { + animator.attach(menuIcon, PropertyAnimator.Property.ALPHA, 1.0f); } animator.start(); } public void setOnActivateListener(OnActivateListener listener) { - mActivateListener = listener; + activateListener = listener; } public void setOnCommitListener(OnCommitListener listener) { - mCommitListener = listener; - mUrlEditLayout.setOnCommitListener(listener); + urlEditLayout.setOnCommitListener(listener); } public void setOnDismissListener(OnDismissListener listener) { - mDismissListener = listener; - mUrlEditLayout.setOnDismissListener(listener); + urlEditLayout.setOnDismissListener(listener); } public void setOnFilterListener(OnFilterListener listener) { - mFilterListener = listener; - mUrlEditLayout.setOnFilterListener(listener); + urlEditLayout.setOnFilterListener(listener); } public void setOnFocusChangeListener(OnFocusChangeListener listener) { - mFocusChangeListener = listener; + focusChangeListener = listener; } public void setOnStartEditingListener(OnStartEditingListener listener) { - mStartEditingListener = listener; + startEditingListener = listener; } public void setOnStopEditingListener(OnStopEditingListener listener) { - mStopEditingListener = listener; + stopEditingListener = listener; } private void showUrlEditLayout() { setUrlEditLayoutVisibility(true, null); } private void showUrlEditLayout(PropertyAnimator animator) { setUrlEditLayoutVisibility(true, animator); @@ -843,20 +834,20 @@ public class BrowserToolbar extends Them setUrlEditLayoutVisibility(false, null); } private void hideUrlEditLayout(PropertyAnimator animator) { setUrlEditLayoutVisibility(false, animator); } private void setUrlEditLayoutVisibility(final boolean showEditLayout, PropertyAnimator animator) { - mUrlEditLayout.prepareAnimation(showEditLayout, animator); + urlEditLayout.prepareAnimation(showEditLayout, animator); - final View viewToShow = (showEditLayout ? mUrlEditLayout : mUrlDisplayLayout); - final View viewToHide = (showEditLayout ? mUrlDisplayLayout : mUrlEditLayout); + final View viewToShow = (showEditLayout ? urlEditLayout : urlDisplayLayout); + final View viewToHide = (showEditLayout ? urlDisplayLayout : urlEditLayout); if (animator == null) { viewToHide.setVisibility(View.GONE); viewToShow.setVisibility(View.VISIBLE); final int cancelVisibility = (showEditLayout ? View.VISIBLE : View.INVISIBLE); setCancelVisibility(cancelVisibility); return; @@ -909,83 +900,83 @@ public class BrowserToolbar extends Them // Disable toolbar elemens while in editing mode final boolean enabled = !isEditing(); // This alpha value has to be in sync with the one used // in setButtonEnabled(). final float alpha = (enabled ? 1.0f : 0.24f); if (!enabled) { - mTabsCounter.onEnterEditingMode(); + tabsCounter.onEnterEditingMode(); } - mTabs.setEnabled(enabled); - ViewHelper.setAlpha(mTabsCounter, alpha); - mMenu.setEnabled(enabled); - ViewHelper.setAlpha(mMenuIcon, alpha); + tabsButton.setEnabled(enabled); + ViewHelper.setAlpha(tabsCounter, alpha); + menuButton.setEnabled(enabled); + ViewHelper.setAlpha(menuIcon, alpha); - final int actionItemsCount = mActionItemBar.getChildCount(); + final int actionItemsCount = actionItemBar.getChildCount(); for (int i = 0; i < actionItemsCount; i++) { - mActionItemBar.getChildAt(i).setEnabled(enabled); + actionItemBar.getChildAt(i).setEnabled(enabled); } - ViewHelper.setAlpha(mActionItemBar, alpha); + ViewHelper.setAlpha(actionItemBar, alpha); final Tab tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { - setButtonEnabled(mBack, canDoBack(tab)); - setButtonEnabled(mForward, canDoForward(tab)); + setButtonEnabled(backButton, canDoBack(tab)); + setButtonEnabled(forwardButton, canDoForward(tab)); // Once the editing mode is finished, we have to ensure that the // forward button slides away if necessary. This is because we might // have only disabled it (without hiding it) when the toolbar entered // editing mode. if (!isEditing()) { animateForwardButton(canDoForward(tab) ? ForwardButtonAnimation.SHOW : ForwardButtonAnimation.HIDE); } } } private void setUIMode(final UIMode uiMode) { - mUIMode = uiMode; - mUrlEditLayout.setEnabled(uiMode == UIMode.EDIT); + this.uiMode = uiMode; + urlEditLayout.setEnabled(uiMode == UIMode.EDIT); } /** * Returns whether or not the URL bar is in editing mode (url bar is expanded, hiding the new * tab button). Note that selection state is independent of editing mode. */ public boolean isEditing() { - return (mUIMode == UIMode.EDIT); + return (uiMode == UIMode.EDIT); } public void startEditing(String url, PropertyAnimator animator) { if (isEditing()) { return; } - mUrlEditLayout.setText(url != null ? url : ""); + urlEditLayout.setText(url != null ? url : ""); setUIMode(UIMode.EDIT); updateChildrenForEditing(); updateProgressVisibility(); - if (mStartEditingListener != null) { - mStartEditingListener.onStartEditing(); + if (startEditingListener != null) { + startEditingListener.onStartEditing(); } final int curveTranslation = getUrlBarCurveTranslation(); final int entryTranslation = getUrlBarEntryTranslation(); shouldShrinkURLBar = (entryTranslation < 0); if (urlBarTranslatingEdge != null) { urlBarTranslatingEdge.setVisibility(View.VISIBLE); if (shouldShrinkURLBar) { - mUrlBarEntry.setLayoutParams(urlBarEntryShrunkenLayoutParams); + urlBarEntry.setLayoutParams(urlBarEntryShrunkenLayoutParams); } } if (Build.VERSION.SDK_INT < 11) { showEditingWithoutAnimation(entryTranslation, curveTranslation); } else if (HardwareUtils.isTablet()) { // No animation. showUrlEditLayout(); @@ -997,77 +988,77 @@ public class BrowserToolbar extends Them private void showEditingWithoutAnimation(final int entryTranslation, final int curveTranslation) { showUrlEditLayout(); if (urlBarTranslatingEdge != null) { ViewHelper.setTranslationX(urlBarTranslatingEdge, entryTranslation); } - ViewHelper.setTranslationX(mTabs, curveTranslation); - ViewHelper.setTranslationX(mTabsCounter, curveTranslation); - ViewHelper.setTranslationX(mActionItemBar, curveTranslation); + ViewHelper.setTranslationX(tabsButton, curveTranslation); + ViewHelper.setTranslationX(tabsCounter, curveTranslation); + ViewHelper.setTranslationX(actionItemBar, curveTranslation); - if (mHasSoftMenuButton) { - ViewHelper.setTranslationX(mMenu, curveTranslation); - ViewHelper.setTranslationX(mMenuIcon, curveTranslation); + if (hasSoftMenuButton) { + ViewHelper.setTranslationX(menuButton, curveTranslation); + ViewHelper.setTranslationX(menuIcon, curveTranslation); } } private void showEditingWithPhoneAnimation(final PropertyAnimator animator, final int entryTranslation, final int curveTranslation) { - if (mAnimatingEntry) + if (isAnimatingEntry) return; // Highlight the toolbar from the start of the animation. setSelected(true); - mUrlDisplayLayout.prepareStartEditingAnimation(); + urlDisplayLayout.prepareStartEditingAnimation(); // Slide toolbar elements. if (urlBarTranslatingEdge != null) { animator.attach(urlBarTranslatingEdge, PropertyAnimator.Property.TRANSLATION_X, entryTranslation); } - animator.attach(mTabs, + animator.attach(tabsButton, PropertyAnimator.Property.TRANSLATION_X, curveTranslation); - animator.attach(mTabsCounter, + animator.attach(tabsCounter, PropertyAnimator.Property.TRANSLATION_X, curveTranslation); - animator.attach(mActionItemBar, + animator.attach(actionItemBar, PropertyAnimator.Property.TRANSLATION_X, curveTranslation); - if (mHasSoftMenuButton) { - animator.attach(mMenu, + if (hasSoftMenuButton) { + animator.attach(menuButton, PropertyAnimator.Property.TRANSLATION_X, curveTranslation); - animator.attach(mMenuIcon, + animator.attach(menuIcon, PropertyAnimator.Property.TRANSLATION_X, curveTranslation); } showUrlEditLayout(animator); animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { @Override public void onPropertyAnimationStart() { } @Override public void onPropertyAnimationEnd() { - mAnimatingEntry = false; + isAnimatingEntry = false; } }); - mAnimatingEntry = true; + isAnimatingEntry = true; } /** * Exits edit mode without updating the toolbar title. * * @return the url that was entered */ public String cancelEdit() { @@ -1083,26 +1074,26 @@ public class BrowserToolbar extends Them final String url = stopEditing(); if (!TextUtils.isEmpty(url)) { setTitle(url); } return url; } private String stopEditing() { - final String url = mUrlEditLayout.getText(); + final String url = urlEditLayout.getText(); if (!isEditing()) { return url; } setUIMode(UIMode.DISPLAY); updateChildrenForEditing(); - if (mStopEditingListener != null) { - mStopEditingListener.onStopEditing(); + if (stopEditingListener != null) { + stopEditingListener.onStopEditing(); } updateProgressVisibility(); if (Build.VERSION.SDK_INT < 11) { stopEditingWithoutAnimation(); } else if (HardwareUtils.isTablet()) { // No animation. @@ -1118,288 +1109,292 @@ public class BrowserToolbar extends Them hideUrlEditLayout(); updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount()); if (urlBarTranslatingEdge != null) { urlBarTranslatingEdge.setVisibility(View.INVISIBLE); ViewHelper.setTranslationX(urlBarTranslatingEdge, 0); if (shouldShrinkURLBar) { - mUrlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams); + urlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams); } } - ViewHelper.setTranslationX(mTabs, 0); - ViewHelper.setTranslationX(mTabsCounter, 0); - ViewHelper.setTranslationX(mActionItemBar, 0); + ViewHelper.setTranslationX(tabsButton, 0); + ViewHelper.setTranslationX(tabsCounter, 0); + ViewHelper.setTranslationX(actionItemBar, 0); - if (mHasSoftMenuButton) { - ViewHelper.setTranslationX(mMenu, 0); - ViewHelper.setTranslationX(mMenuIcon, 0); + if (hasSoftMenuButton) { + ViewHelper.setTranslationX(menuButton, 0); + ViewHelper.setTranslationX(menuIcon, 0); } } private void stopEditingWithPhoneAnimation() { final PropertyAnimator contentAnimator = new PropertyAnimator(250); contentAnimator.setUseHardwareLayer(false); // Slide the toolbar back to its original size. if (urlBarTranslatingEdge != null) { contentAnimator.attach(urlBarTranslatingEdge, PropertyAnimator.Property.TRANSLATION_X, 0); } - contentAnimator.attach(mTabs, + contentAnimator.attach(tabsButton, PropertyAnimator.Property.TRANSLATION_X, 0); - contentAnimator.attach(mTabsCounter, + contentAnimator.attach(tabsCounter, PropertyAnimator.Property.TRANSLATION_X, 0); - contentAnimator.attach(mActionItemBar, + contentAnimator.attach(actionItemBar, PropertyAnimator.Property.TRANSLATION_X, 0); - if (mHasSoftMenuButton) { - contentAnimator.attach(mMenu, + if (hasSoftMenuButton) { + contentAnimator.attach(menuButton, PropertyAnimator.Property.TRANSLATION_X, 0); - contentAnimator.attach(mMenuIcon, + contentAnimator.attach(menuIcon, PropertyAnimator.Property.TRANSLATION_X, 0); } hideUrlEditLayout(contentAnimator); contentAnimator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { @Override public void onPropertyAnimationStart() { } @Override public void onPropertyAnimationEnd() { if (urlBarTranslatingEdge != null) { urlBarTranslatingEdge.setVisibility(View.INVISIBLE); if (shouldShrinkURLBar) { - mUrlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams); + urlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams); } } PropertyAnimator buttonsAnimator = new PropertyAnimator(300); - mUrlDisplayLayout.prepareStopEditingAnimation(buttonsAnimator); + urlDisplayLayout.prepareStopEditingAnimation(buttonsAnimator); buttonsAnimator.start(); - mAnimatingEntry = false; + isAnimatingEntry = false; // Trigger animation to update the tabs counter once the // tabs button is back on screen. updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount()); } }); - mAnimatingEntry = true; + isAnimatingEntry = true; contentAnimator.start(); } public void setButtonEnabled(ImageButton button, boolean enabled) { final Drawable drawable = button.getDrawable(); if (drawable != null) { // This alpha value has to be in sync with the one used // in updateChildrenForEditing(). drawable.setAlpha(enabled ? 255 : 61); } button.setEnabled(enabled); } public void updateBackButton(Tab tab) { - setButtonEnabled(mBack, canDoBack(tab)); + setButtonEnabled(backButton, canDoBack(tab)); } private void animateForwardButton(final ForwardButtonAnimation animation) { // If the forward button is not visible, we must be // in the phone UI. - if (mForward.getVisibility() != View.VISIBLE) { + if (forwardButton.getVisibility() != View.VISIBLE) { return; } final boolean showing = (animation == ForwardButtonAnimation.SHOW); // if the forward button's margin is non-zero, this means it has already // been animated to be visible¸ and vice-versa. - MarginLayoutParams fwdParams = (MarginLayoutParams) mForward.getLayoutParams(); - if ((fwdParams.leftMargin > mDefaultForwardMargin && showing) || - (fwdParams.leftMargin == mDefaultForwardMargin && !showing)) { + MarginLayoutParams fwdParams = (MarginLayoutParams) forwardButton.getLayoutParams(); + if ((fwdParams.leftMargin > defaultForwardMargin && showing) || + (fwdParams.leftMargin == defaultForwardMargin && !showing)) { return; } // We want the forward button to show immediately when switching tabs final PropertyAnimator forwardAnim = - new PropertyAnimator(mSwitchingTabs ? 10 : FORWARD_ANIMATION_DURATION); - final int width = mForward.getWidth() / 2; + new PropertyAnimator(isSwitchingTabs ? 10 : FORWARD_ANIMATION_DURATION); + final int width = forwardButton.getWidth() / 2; forwardAnim.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { @Override public void onPropertyAnimationStart() { if (!showing) { // Set the margin before the transition when hiding the forward button. We // have to do this so that the favicon isn't clipped during the transition MarginLayoutParams layoutParams = - (MarginLayoutParams) mUrlDisplayLayout.getLayoutParams(); + (MarginLayoutParams) urlDisplayLayout.getLayoutParams(); layoutParams.leftMargin = 0; // Do the same on the URL edit container - layoutParams = (MarginLayoutParams) mUrlEditLayout.getLayoutParams(); + layoutParams = (MarginLayoutParams) urlEditLayout.getLayoutParams(); layoutParams.leftMargin = 0; requestLayout(); // Note, we already translated the favicon, site security, and text field // in prepareForwardAnimation, so they should appear to have not moved at // all at this point. } } @Override public void onPropertyAnimationEnd() { if (showing) { MarginLayoutParams layoutParams = - (MarginLayoutParams) mUrlDisplayLayout.getLayoutParams(); - layoutParams.leftMargin = mUrlBarViewOffset; + (MarginLayoutParams) urlDisplayLayout.getLayoutParams(); + layoutParams.leftMargin = urlBarViewOffset; - layoutParams = (MarginLayoutParams) mUrlEditLayout.getLayoutParams(); - layoutParams.leftMargin = mUrlBarViewOffset; + layoutParams = (MarginLayoutParams) urlEditLayout.getLayoutParams(); + layoutParams.leftMargin = urlBarViewOffset; } - mUrlDisplayLayout.finishForwardAnimation(); + urlDisplayLayout.finishForwardAnimation(); - MarginLayoutParams layoutParams = (MarginLayoutParams) mForward.getLayoutParams(); - layoutParams.leftMargin = mDefaultForwardMargin + (showing ? width : 0); - ViewHelper.setTranslationX(mForward, 0); + MarginLayoutParams layoutParams = (MarginLayoutParams) forwardButton.getLayoutParams(); + layoutParams.leftMargin = defaultForwardMargin + (showing ? width : 0); + ViewHelper.setTranslationX(forwardButton, 0); requestLayout(); } }); prepareForwardAnimation(forwardAnim, animation, width); forwardAnim.start(); } public void updateForwardButton(Tab tab) { final boolean enabled = canDoForward(tab); - if (mForward.isEnabled() == enabled) + if (forwardButton.isEnabled() == enabled) return; // Save the state on the forward button so that we can skip animations // when there's nothing to change - setButtonEnabled(mForward, enabled); + setButtonEnabled(forwardButton, enabled); animateForwardButton(enabled ? ForwardButtonAnimation.SHOW : ForwardButtonAnimation.HIDE); } private void prepareForwardAnimation(PropertyAnimator anim, ForwardButtonAnimation animation, int width) { if (animation == ForwardButtonAnimation.HIDE) { - anim.attach(mForward, + anim.attach(forwardButton, PropertyAnimator.Property.TRANSLATION_X, -width); - anim.attach(mForward, + anim.attach(forwardButton, PropertyAnimator.Property.ALPHA, 0); } else { - anim.attach(mForward, + anim.attach(forwardButton, PropertyAnimator.Property.TRANSLATION_X, width); - anim.attach(mForward, + anim.attach(forwardButton, PropertyAnimator.Property.ALPHA, 1); } - mUrlDisplayLayout.prepareForwardAnimation(anim, animation, width); + urlDisplayLayout.prepareForwardAnimation(anim, animation, width); } @Override public boolean addActionItem(View actionItem) { - mActionItemBar.addView(actionItem); + actionItemBar.addView(actionItem); return true; } @Override public void removeActionItem(View actionItem) { - mActionItemBar.removeView(actionItem); + actionItemBar.removeView(actionItem); } @Override public void setPrivateMode(boolean isPrivate) { super.setPrivateMode(isPrivate); - mTabs.setPrivateMode(isPrivate); - mMenu.setPrivateMode(isPrivate); - mMenuIcon.setPrivateMode(isPrivate); - mUrlEditLayout.setPrivateMode(isPrivate); + tabsButton.setPrivateMode(isPrivate); + menuButton.setPrivateMode(isPrivate); + menuIcon.setPrivateMode(isPrivate); + urlEditLayout.setPrivateMode(isPrivate); editSeparator.setPrivateMode(isPrivate); - if (mBack instanceof BackButton) { - ((BackButton) mBack).setPrivateMode(isPrivate); + if (backButton instanceof BackButton) { + ((BackButton) backButton).setPrivateMode(isPrivate); } - if (mForward instanceof ForwardButton) { - ((ForwardButton) mForward).setPrivateMode(isPrivate); + if (forwardButton instanceof ForwardButton) { + ((ForwardButton) forwardButton).setPrivateMode(isPrivate); } } public void show() { setVisibility(View.VISIBLE); } public void hide() { setVisibility(View.GONE); } public View getDoorHangerAnchor() { - return mUrlDisplayLayout.getDoorHangerAnchor(); + return urlDisplayLayout.getDoorHangerAnchor(); } public void onDestroy() { Tabs.unregisterOnTabsChangedListener(this); unregisterEventListener("Reader:Click"); unregisterEventListener("Reader:LongClick"); } public boolean openOptionsMenu() { - if (!mHasSoftMenuButton) + if (!hasSoftMenuButton) { return false; + } // Initialize the popup. - if (mMenuPopup == null) { - View panel = mActivity.getMenuPanel(); - mMenuPopup = new MenuPopup(mActivity); - mMenuPopup.setPanelView(panel); + if (menuPopup == null) { + View panel = activity.getMenuPanel(); + menuPopup = new MenuPopup(activity); + menuPopup.setPanelView(panel); - mMenuPopup.setOnDismissListener(new PopupWindow.OnDismissListener() { + menuPopup.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { - mActivity.onOptionsMenuClosed(null); + activity.onOptionsMenuClosed(null); } }); } GeckoAppShell.getGeckoInterface().invalidateOptionsMenu(); - if (!mMenuPopup.isShowing()) - mMenuPopup.showAsDropDown(mMenu); + if (!menuPopup.isShowing()) { + menuPopup.showAsDropDown(menuButton); + } return true; } public boolean closeOptionsMenu() { - if (!mHasSoftMenuButton) + if (!hasSoftMenuButton) { return false; + } - if (mMenuPopup != null && mMenuPopup.isShowing()) - mMenuPopup.dismiss(); + if (menuPopup != null && menuPopup.isShowing()) { + menuPopup.dismiss(); + } return true; } private void registerEventListener(String event) { GeckoAppShell.getEventDispatcher().registerEventListener(event, this); } @@ -1420,17 +1415,17 @@ public class BrowserToolbar extends Them if (tab != null) { tab.addToReadingList(); } } } @Override public void onLightweightThemeChanged() { - Drawable drawable = mTheme.getDrawable(this); + Drawable drawable = theme.getDrawable(this); if (drawable == null) return; StateListDrawable stateList = new StateListDrawable(); stateList.addState(PRIVATE_STATE_SET, getColorDrawable(R.color.background_private)); stateList.addState(EMPTY_STATE_SET, drawable); setBackgroundDrawable(stateList);