diff options
author | lambroslambrou <lambroslambrou@chromium.org> | 2015-11-23 19:14:29 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-24 03:15:20 +0000 |
commit | eaace2b1431b3b411dccc111098e3f49978b87a6 (patch) | |
tree | 7f15184e3af774b65be1a975761c50bfbc2d3330 | |
parent | f310b30f6588cc2683b9d302b312df4efe73bc67 (diff) | |
download | chromium_src-eaace2b1431b3b411dccc111098e3f49978b87a6.zip chromium_src-eaace2b1431b3b411dccc111098e3f49978b87a6.tar.gz chromium_src-eaace2b1431b3b411dccc111098e3f49978b87a6.tar.bz2 |
Android Chromoting: Disable hamburger animation.
This is a little complex, for reasons that are explained in the code
comments. Also, this refactors ChromotingUtil to make it easier to tint
arbitrary Drawables.
Review URL: https://codereview.chromium.org/1461893002
Cr-Commit-Position: refs/heads/master@{#361240}
-rw-r--r-- | remoting/android/java/res/drawable-hdpi/ic_menu.png | bin | 0 -> 94 bytes | |||
-rw-r--r-- | remoting/android/java/res/drawable-mdpi/ic_menu.png | bin | 0 -> 82 bytes | |||
-rw-r--r-- | remoting/android/java/res/drawable-xhdpi/ic_menu.png | bin | 0 -> 99 bytes | |||
-rw-r--r-- | remoting/android/java/res/drawable-xxhdpi/ic_menu.png | bin | 0 -> 111 bytes | |||
-rw-r--r-- | remoting/android/java/res/drawable-xxxhdpi/ic_menu.png | bin | 0 -> 116 bytes | |||
-rw-r--r-- | remoting/android/java/src/org/chromium/chromoting/Chromoting.java | 43 | ||||
-rw-r--r-- | remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java | 42 |
7 files changed, 63 insertions, 22 deletions
diff --git a/remoting/android/java/res/drawable-hdpi/ic_menu.png b/remoting/android/java/res/drawable-hdpi/ic_menu.png Binary files differnew file mode 100644 index 0000000..3f8ebd6 --- /dev/null +++ b/remoting/android/java/res/drawable-hdpi/ic_menu.png diff --git a/remoting/android/java/res/drawable-mdpi/ic_menu.png b/remoting/android/java/res/drawable-mdpi/ic_menu.png Binary files differnew file mode 100644 index 0000000..ef2a48c --- /dev/null +++ b/remoting/android/java/res/drawable-mdpi/ic_menu.png diff --git a/remoting/android/java/res/drawable-xhdpi/ic_menu.png b/remoting/android/java/res/drawable-xhdpi/ic_menu.png Binary files differnew file mode 100644 index 0000000..4e0286b --- /dev/null +++ b/remoting/android/java/res/drawable-xhdpi/ic_menu.png diff --git a/remoting/android/java/res/drawable-xxhdpi/ic_menu.png b/remoting/android/java/res/drawable-xxhdpi/ic_menu.png Binary files differnew file mode 100644 index 0000000..7dae60b --- /dev/null +++ b/remoting/android/java/res/drawable-xxhdpi/ic_menu.png diff --git a/remoting/android/java/res/drawable-xxxhdpi/ic_menu.png b/remoting/android/java/res/drawable-xxxhdpi/ic_menu.png Binary files differnew file mode 100644 index 0000000..5c747ed --- /dev/null +++ b/remoting/android/java/res/drawable-xxxhdpi/ic_menu.png diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java index bf7dd02..5dce18e 100644 --- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java +++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java @@ -11,12 +11,15 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.provider.Settings; +import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -26,6 +29,7 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Toast; +import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.Log; import org.chromium.chromoting.accountswitcher.AccountSwitcher; import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; @@ -185,10 +189,44 @@ public class Chromoting extends AppCompatActivity implements JniInterface.Connec findViewById(R.id.host_setup_link_android).setOnClickListener(this); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, + mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.open_navigation_drawer, R.string.close_navigation_drawer); mDrawerLayout.setDrawerListener(mDrawerToggle); + // Disable the hamburger icon animation. This is more complex than it ought to be. + // The animation can be customized by tweaking some style parameters - see + // http://developer.android.com/reference/android/support/v7/appcompat/R.styleable.html#DrawerArrowToggle . + // But these can't disable the animation completely. + // The icon can only be changed by disabling the drawer indicator, which has side-effects + // that must be worked around. It disables the built-in click listener, so this has to be + // implemented and added. This also requires that the toolbar be passed to the + // ActionBarDrawerToggle ctor above (otherwise the listener is ignored and warnings are + // logged). + // Also, the animation itself is a private implementation detail - it is not possible to + // simply access the first frame of the animation. And the hamburger menu icon doesn't + // exist as a builtin Android resource, so it has to be provided as an application + // resource instead (R.drawable.ic_menu). And, on Lollipop devices and above, it should be + // tinted to match the colorControlNormal theme attribute. + mDrawerToggle.setDrawerIndicatorEnabled(false); + mDrawerToggle.setToolbarNavigationClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mDrawerLayout.isDrawerOpen(Gravity.START)) { + mDrawerLayout.closeDrawer(Gravity.START); + } else { + mDrawerLayout.openDrawer(Gravity.START); + } + } + }); + + // Set the three-line icon instead of the default which is a tinted arrow icon. + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + Drawable menuIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.ic_menu); + DrawableCompat.setTint(menuIcon.mutate(), + ChromotingUtil.getColorAttribute(this, R.attr.colorControlNormal)); + getSupportActionBar().setHomeAsUpIndicator(menuIcon); + ListView navigationMenu = new ListView(this); navigationMenu.setChoiceMode(ListView.CHOICE_MODE_SINGLE); navigationMenu.setLayoutParams(new LinearLayout.LayoutParams( @@ -211,9 +249,6 @@ public class Chromoting extends AppCompatActivity implements JniInterface.Connec } }); - // Make the navigation drawer icon visible in the ActionBar. - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - mAccountSwitcher = AccountSwitcherFactory.getInstance().createAccountSwitcher(this, this); mAccountSwitcher.setNavigation(navigationMenu); LinearLayout navigationDrawer = (LinearLayout) findViewById(R.id.navigation_drawer); diff --git a/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java b/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java index 5224801..64e0008 100644 --- a/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java +++ b/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java @@ -5,13 +5,13 @@ package org.chromium.chromoting; import android.content.Context; +import android.content.res.Resources; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.util.TypedValue; import android.view.Menu; import org.chromium.base.ApiCompatibilityUtils; -import org.chromium.base.Log; /** Utility methods for chromoting code. */ public abstract class ChromotingUtil { @@ -24,32 +24,38 @@ public abstract class ChromotingUtil { * @param menu Menu with icons to be tinted. */ public static void tintMenuIcons(Context context, Menu menu) { + int color = getColorAttribute(context, R.attr.colorControlNormal); + int items = menu.size(); + for (int i = 0; i < items; i++) { + Drawable icon = menu.getItem(i).getIcon(); + if (icon != null) { + icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); + } + } + } + + /** + * Returns a color from a theme attribute. + * @param context Context with resources to look up. + * @param attribute Attribute such as R.attr.colorControlNormal. + * @return Color value. + * @throws Resources.NotFoundException + */ + public static int getColorAttribute(Context context, int attribute) { TypedValue typedValue = new TypedValue(); - if (!context.getTheme().resolveAttribute(R.attr.colorControlNormal, typedValue, true)) { - Log.e(TAG, "Failed to resolve colorControlNormal attribute."); - return; + if (!context.getTheme().resolveAttribute(attribute, typedValue, true)) { + throw new Resources.NotFoundException("Attribute not found."); } - int color; if (typedValue.resourceId != 0) { // Attribute is a resource. - color = ApiCompatibilityUtils.getColor(context.getResources(), typedValue.resourceId); + return ApiCompatibilityUtils.getColor(context.getResources(), typedValue.resourceId); } else if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { // Attribute is a raw color value. - color = typedValue.data; + return typedValue.data; } else { - // The resource compiler should prevent this from happening. - Log.e(TAG, "Invalid colorControlNormal attribute: %s", typedValue); - return; - } - - int items = menu.size(); - for (int i = 0; i < items; i++) { - Drawable icon = menu.getItem(i).getIcon(); - if (icon != null) { - icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); - } + throw new Resources.NotFoundException("Attribute not a color."); } } } |