diff --git a/mobile/android/base/toolbar/BrowserToolbar.java b/mobile/android/base/toolbar/BrowserToolbar.java index 8105c8c42e3c..ea2c60a1374e 100644 --- a/mobile/android/base/toolbar/BrowserToolbar.java +++ b/mobile/android/base/toolbar/BrowserToolbar.java @@ -20,7 +20,6 @@ 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; @@ -118,52 +117,49 @@ public class BrowserToolbar extends ThemedRelativeLayout 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 mFocusOrder; + private ToolbarProgressView progressBar; + private TabCounter tabsCounter; + private ThemedImageButton menuButton; + private ThemedImageView menuIcon; + private LinearLayout actionItemBar; + private MenuPopup menuPopup; + private List 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 mActivity; - private boolean mHasSoftMenuButton; + final private BrowserApp activity; + private boolean hasSoftMenuButton; - private UIMode mUIMode; - private boolean mAnimatingEntry; + private UIMode uiMode; + private boolean isAnimatingEntry; - private int mUrlBarViewOffset; - private int mDefaultForwardMargin; + private int urlBarViewOffset; + private int defaultForwardMargin; - 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); @@ -171,31 +167,29 @@ public class BrowserToolbar extends ThemedRelativeLayout 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(); - 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); + 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); - 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; @@ -206,36 +200,36 @@ public class BrowserToolbar extends ThemedRelativeLayout 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(); + focusOrder = new ArrayList(); 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); @@ -248,8 +242,8 @@ public class BrowserToolbar extends ThemedRelativeLayout setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { - if (mActivateListener != null) { - mActivateListener.onActivate(); + if (activateListener != null) { + activateListener.onActivate(); } } }); @@ -265,7 +259,7 @@ public class BrowserToolbar extends ThemedRelativeLayout // 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(); @@ -298,7 +292,7 @@ public class BrowserToolbar extends ThemedRelativeLayout } }); - mUrlDisplayLayout.setOnStopListener(new OnStopListener() { + urlDisplayLayout.setOnStopListener(new OnStopListener() { @Override public Tab onStop() { final Tab tab = Tabs.getInstance().getSelectedTab(); @@ -311,14 +305,14 @@ public class BrowserToolbar extends ThemedRelativeLayout } }); - 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 @@ -327,44 +321,44 @@ public class BrowserToolbar extends ThemedRelativeLayout } }); - 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(); @@ -378,25 +372,25 @@ public class BrowserToolbar extends ThemedRelativeLayout } }); - 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() { @@ -405,7 +399,7 @@ public class BrowserToolbar extends ThemedRelativeLayout return true; } - return mUrlDisplayLayout.dismissSiteIdentityPopup(); + return urlDisplayLayout.dismissSiteIdentityPopup(); } public boolean onKey(int keyCode, KeyEvent event) { @@ -433,7 +427,7 @@ public class BrowserToolbar extends ThemedRelativeLayout keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { return false; } else if (isEditing()) { - return mUrlEditLayout.onKey(keyCode, event); + return urlEditLayout.onKey(keyCode, event); } return false; @@ -460,7 +454,7 @@ public class BrowserToolbar extends ThemedRelativeLayout post(new Runnable() { @Override public void run() { - mActivity.refreshToolbarHeight(); + activity.refreshToolbarHeight(); } }); } @@ -484,9 +478,9 @@ public class BrowserToolbar extends ThemedRelativeLayout case RESTORED: // TabCount fixup after OOM case SELECTED: - mUrlDisplayLayout.dismissSiteIdentityPopup(); + urlDisplayLayout.dismissSiteIdentityPopup(); updateTabCount(tabs.getDisplayCount()); - mSwitchingTabs = true; + isSwitchingTabs = true; break; } @@ -504,8 +498,8 @@ public class BrowserToolbar extends ThemedRelativeLayout 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; @@ -567,7 +561,7 @@ public class BrowserToolbar extends ThemedRelativeLayout case SELECTED: case LOAD_ERROR: case LOCATION_CHANGE: - mSwitchingTabs = false; + isSwitchingTabs = false; } } @@ -578,10 +572,10 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } } @@ -592,22 +586,22 @@ public class BrowserToolbar extends ThemedRelativeLayout @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) { @@ -619,25 +613,25 @@ public class BrowserToolbar extends ThemedRelativeLayout } 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(); } } } @@ -654,11 +648,11 @@ public class BrowserToolbar extends ThemedRelativeLayout // 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)); } } @@ -672,28 +666,28 @@ public class BrowserToolbar extends ThemedRelativeLayout } // 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 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()); } } @@ -709,7 +703,7 @@ public class BrowserToolbar extends ThemedRelativeLayout // 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; @@ -717,10 +711,10 @@ public class BrowserToolbar extends ThemedRelativeLayout 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()); @@ -746,24 +740,24 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } @@ -773,10 +767,10 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } } @@ -787,12 +781,12 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } @@ -801,34 +795,31 @@ public class BrowserToolbar extends ThemedRelativeLayout } 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() { @@ -848,10 +839,10 @@ public class BrowserToolbar extends ThemedRelativeLayout } 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); @@ -914,24 +905,24 @@ public class BrowserToolbar extends ThemedRelativeLayout 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 @@ -945,8 +936,8 @@ public class BrowserToolbar extends ThemedRelativeLayout } private void setUIMode(final UIMode uiMode) { - mUIMode = uiMode; - mUrlEditLayout.setEnabled(uiMode == UIMode.EDIT); + this.uiMode = uiMode; + urlEditLayout.setEnabled(uiMode == UIMode.EDIT); } /** @@ -954,7 +945,7 @@ public class BrowserToolbar extends ThemedRelativeLayout * 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) { @@ -962,15 +953,15 @@ public class BrowserToolbar extends ThemedRelativeLayout 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(); @@ -980,7 +971,7 @@ public class BrowserToolbar extends ThemedRelativeLayout if (urlBarTranslatingEdge != null) { urlBarTranslatingEdge.setVisibility(View.VISIBLE); if (shouldShrinkURLBar) { - mUrlBarEntry.setLayoutParams(urlBarEntryShrunkenLayoutParams); + urlBarEntry.setLayoutParams(urlBarEntryShrunkenLayoutParams); } } @@ -1002,25 +993,25 @@ public class BrowserToolbar extends ThemedRelativeLayout 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) { @@ -1029,22 +1020,22 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } @@ -1058,11 +1049,11 @@ public class BrowserToolbar extends ThemedRelativeLayout @Override public void onPropertyAnimationEnd() { - mAnimatingEntry = false; + isAnimatingEntry = false; } }); - mAnimatingEntry = true; + isAnimatingEntry = true; } /** @@ -1088,7 +1079,7 @@ public class BrowserToolbar extends ThemedRelativeLayout } private String stopEditing() { - final String url = mUrlEditLayout.getText(); + final String url = urlEditLayout.getText(); if (!isEditing()) { return url; } @@ -1096,8 +1087,8 @@ public class BrowserToolbar extends ThemedRelativeLayout updateChildrenForEditing(); - if (mStopEditingListener != null) { - mStopEditingListener.onStopEditing(); + if (stopEditingListener != null) { + stopEditingListener.onStopEditing(); } updateProgressVisibility(); @@ -1123,17 +1114,17 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } } @@ -1148,22 +1139,22 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } @@ -1180,15 +1171,15 @@ public class BrowserToolbar extends ThemedRelativeLayout 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. @@ -1196,7 +1187,7 @@ public class BrowserToolbar extends ThemedRelativeLayout } }); - mAnimatingEntry = true; + isAnimatingEntry = true; contentAnimator.start(); } @@ -1212,13 +1203,13 @@ public class BrowserToolbar extends ThemedRelativeLayout } 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; } @@ -1226,16 +1217,16 @@ public class BrowserToolbar extends ThemedRelativeLayout // 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 @@ -1244,11 +1235,11 @@ public class BrowserToolbar extends ThemedRelativeLayout // 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(); @@ -1262,18 +1253,18 @@ public class BrowserToolbar extends ThemedRelativeLayout 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(); } @@ -1285,63 +1276,63 @@ public class BrowserToolbar extends ThemedRelativeLayout 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); } } @@ -1354,7 +1345,7 @@ public class BrowserToolbar extends ThemedRelativeLayout } public View getDoorHangerAnchor() { - return mUrlDisplayLayout.getDoorHangerAnchor(); + return urlDisplayLayout.getDoorHangerAnchor(); } public void onDestroy() { @@ -1365,36 +1356,40 @@ public class BrowserToolbar extends ThemedRelativeLayout } 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; } @@ -1425,7 +1420,7 @@ public class BrowserToolbar extends ThemedRelativeLayout @Override public void onLightweightThemeChanged() { - Drawable drawable = mTheme.getDrawable(this); + Drawable drawable = theme.getDrawable(this); if (drawable == null) return;