Bug 771380 - Use animation to show/hide lock icon in toolbar (r=sriram)

This commit is contained in:
Lucas Rocha 2012-08-23 19:27:11 +01:00
Родитель cddec5a621
Коммит 65bf8a7865
8 изменённых файлов: 83 добавлений и 8 удалений

Просмотреть файл

@ -24,6 +24,9 @@ import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
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.widget.Button;
@ -43,12 +46,14 @@ import java.util.List;
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;
@ -80,6 +85,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;
@ -179,6 +188,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
mFavicon.setOnClickListener(faviconListener);
mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security);
mSiteSecurity.setOnClickListener(faviconListener);
mSiteSecurityVisible = (mSiteSecurity.getVisibility() == View.VISIBLE);
mProgressSpinner = (AnimationDrawable) mActivity.getResources().getDrawable(R.drawable.progress_spinner);
@ -214,6 +224,26 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
mSlideDownIn.setDuration(mDuration);
mSlideDownOut.setDuration(mDuration);
float slideWidth = mActivity.getResources().getDimension(R.dimen.browser_toolbar_lock_width);
LinearLayout.LayoutParams siteSecParams = (LinearLayout.LayoutParams) mSiteSecurity.getLayoutParams();
final float scale = mActivity.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 = !mActivity.hasPermanentMenuKey();
@ -312,6 +342,27 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
}
}
@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.
@ -422,7 +473,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
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
@ -433,6 +484,29 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
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;

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -16,6 +16,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="doorhanger_arrow_width">44dp</dimen>
<dimen name="flow_layout_spacing">6dp</dimen>
<dimen name="local_tab_row_height">108dp</dimen>