Skip to content

Commit

Permalink
Bug 771380 - Use animation to show/hide lock icon in toolbar (r=srira…
Browse files Browse the repository at this point in the history
…m, a=akeybl)
  • Loading branch information
lucasr committed Aug 23, 2012
1 parent 1d79de8 commit 2ffcb0d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 8 deletions.
78 changes: 76 additions & 2 deletions mobile/android/base/BrowserToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.view.ContextMenu;
Expand Down Expand Up @@ -53,12 +56,14 @@

public class BrowserToolbar implements ViewSwitcher.ViewFactory,
Tabs.OnTabsChangedListener,
GeckoMenu.ActionItemBarPresenter {
GeckoMenu.ActionItemBarPresenter,
Animation.AnimationListener {
private static final String LOGTAG = "GeckoToolbar";
private LinearLayout mLayout;
private Button mAwesomeBar;
private TextView mTitle;
private int mTitlePadding;
private boolean mSiteSecurityVisible;
private ImageButton mTabs;
private ImageView mBack;
private ImageView mForward;
Expand Down Expand Up @@ -90,6 +95,10 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
private TranslateAnimation mSlideDownIn;
private TranslateAnimation mSlideDownOut;

private AlphaAnimation mLockFadeIn;
private TranslateAnimation mTitleSlideLeft;
private TranslateAnimation mTitleSlideRight;

private int mCount;

private static final int TABS_CONTRACTED = 1;
Expand Down Expand Up @@ -189,6 +198,7 @@ public void onClick(View view) {

mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security);
mSiteSecurity.setOnClickListener(faviconListener);
mSiteSecurityVisible = (mSiteSecurity.getVisibility() == View.VISIBLE);

mProgressSpinner = (AnimationDrawable) mContext.getResources().getDrawable(R.drawable.progress_spinner);

Expand Down Expand Up @@ -224,6 +234,26 @@ public void onClick(View view) {
mSlideDownIn.setDuration(mDuration);
mSlideDownOut.setDuration(mDuration);

float slideWidth = mContext.getResources().getDimension(R.dimen.browser_toolbar_lock_width);

LinearLayout.LayoutParams siteSecParams = (LinearLayout.LayoutParams) mSiteSecurity.getLayoutParams();
final float scale = mContext.getResources().getDisplayMetrics().density;
slideWidth += (siteSecParams.leftMargin + siteSecParams.rightMargin) * scale + 0.5f;

mLockFadeIn = new AlphaAnimation(0.0f, 1.0f);
mLockFadeIn.setAnimationListener(this);

mTitleSlideLeft = new TranslateAnimation(slideWidth, 0, 0, 0);
mTitleSlideLeft.setAnimationListener(this);

mTitleSlideRight = new TranslateAnimation(-slideWidth, 0, 0, 0);
mTitleSlideRight.setAnimationListener(this);

final int lockAnimDuration = 300;
mLockFadeIn.setDuration(lockAnimDuration);
mTitleSlideLeft.setDuration(lockAnimDuration);
mTitleSlideRight.setDuration(lockAnimDuration);

mMenu = (ImageButton) mLayout.findViewById(R.id.menu);
mActionItemBar = (LinearLayout) mLayout.findViewById(R.id.menu_items);
mHasSoftMenuButton = !GeckoApp.mAppContext.hasPermanentMenuKey();
Expand Down Expand Up @@ -322,6 +352,27 @@ public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
}
}

@Override
public void onAnimationStart(Animation animation) {
if (animation.equals(mLockFadeIn)) {
if (mSiteSecurityVisible)
mSiteSecurity.setVisibility(View.VISIBLE);
}
}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
if (animation.equals(mTitleSlideLeft)) {
mSiteSecurity.setVisibility(View.GONE);
} else if (animation.equals(mTitleSlideRight)) {
mSiteSecurity.startAnimation(mLockFadeIn);
}
}

@Override
public View makeView() {
// This returns a TextView for the TextSwitcher.
Expand Down Expand Up @@ -432,7 +483,7 @@ public void setPageActionVisibility(boolean isLoading) {
mStop.setVisibility(isLoading ? View.VISIBLE : View.GONE);

// Handle the viewing mode page actions
mSiteSecurity.setVisibility(mShowSiteSecurity && !isLoading ? View.VISIBLE : View.GONE);
setSiteSecurityVisibility(mShowSiteSecurity && !isLoading);
mReader.setVisibility(mShowReader && !isLoading ? View.VISIBLE : View.GONE);

// We want title to fill the whole space available for it when there are icons
Expand All @@ -443,6 +494,29 @@ public void setPageActionVisibility(boolean isLoading) {
updateFocusOrder();
}

private void setSiteSecurityVisibility(final boolean visible) {
if (visible == mSiteSecurityVisible)
return;

mSiteSecurityVisible = visible;

mTitle.clearAnimation();
mSiteSecurity.clearAnimation();

// If any of these animations were cancelled as a result of the
// clearAnimation() calls above, we need to reset them.
mLockFadeIn.reset();
mTitleSlideLeft.reset();
mTitleSlideRight.reset();

if (visible)
mSiteSecurity.setVisibility(View.INVISIBLE);
else
mSiteSecurity.setVisibility(View.GONE);

mTitle.startAnimation(visible ? mTitleSlideRight : mTitleSlideLeft);
}

private void updateFocusOrder() {
View prevView = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

<ImageButton android:id="@+id/site_security"
style="@style/AddressBar.ImageButton"
android:layout_width="21.33dip"
android:layout_width="@dimen/browser_toolbar_lock_width"
android:scaleType="fitCenter"
android:layout_marginLeft="-4dip"
android:paddingLeft="1dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

<ImageButton android:id="@+id/site_security"
style="@style/AddressBar.ImageButton"
android:layout_width="21.33dip"
android:layout_width="@dimen/browser_toolbar_lock_width"
android:scaleType="fitCenter"
android:layout_marginLeft="-4dip"
android:paddingLeft="1dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

<ImageButton android:id="@+id/site_security"
style="@style/AddressBar.ImageButton"
android:layout_width="21.33dip"
android:layout_width="@dimen/browser_toolbar_lock_width"
android:scaleType="fitCenter"
android:layout_marginLeft="-4dip"
android:src="@drawable/site_security_level"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

<ImageButton android:id="@+id/site_security"
style="@style/AddressBar.ImageButton"
android:layout_width="21.33dip"
android:layout_width="@dimen/browser_toolbar_lock_width"
android:scaleType="fitCenter"
android:layout_marginLeft="-4dip"
android:src="@drawable/site_security_level"
Expand Down
2 changes: 1 addition & 1 deletion mobile/android/base/resources/layout/browser_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

<ImageButton android:id="@+id/site_security"
style="@style/AddressBar.ImageButton"
android:layout_width="21.33dip"
android:layout_width="@dimen/browser_toolbar_lock_width"
android:scaleType="fitCenter"
android:layout_marginLeft="-4dip"
android:src="@drawable/site_security_level"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

<ImageButton android:id="@+id/site_security"
style="@style/AddressBar.ImageButton"
android:layout_width="21.33dip"
android:layout_width="@dimen/browser_toolbar_lock_width"
android:scaleType="fitCenter"
android:layout_marginLeft="-4dip"
android:src="@drawable/site_security_level"
Expand Down
1 change: 1 addition & 0 deletions mobile/android/base/resources/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<dimen name="awesomebar_tab_transparency_height">38dp</dimen>
<dimen name="browser_toolbar_height">48dp</dimen>
<dimen name="browser_toolbar_icon_width">36dp</dimen>
<dimen name="browser_toolbar_lock_width">21.33dp</dimen>
<dimen name="flow_layout_spacing">6dp</dimen>
<dimen name="local_tab_row_height">108dp</dimen>
<dimen name="remote_tab_child_row_height">54dp</dimen>
Expand Down

0 comments on commit 2ffcb0d

Please sign in to comment.