diff options
author | Maurice Lam <yukl@google.com> | 2014-06-25 23:43:49 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-06-25 17:34:07 +0000 |
commit | 340d83040b024b8121015db262dfcba2eb5f4433 (patch) | |
tree | f88b134564308401cb85774baed7c7a548b2ce54 | |
parent | 0c8a04354b2af58d3f5c66904f24f5c54894cdff (diff) | |
parent | 6c4d5786ec0ce22429a68c5b9e92f3dab9863f2d (diff) | |
download | android_frameworks_opt_setupwizard-340d83040b024b8121015db262dfcba2eb5f4433.tar.gz android_frameworks_opt_setupwizard-340d83040b024b8121015db262dfcba2eb5f4433.tar.bz2 android_frameworks_opt_setupwizard-340d83040b024b8121015db262dfcba2eb5f4433.zip |
Merge "Navigation bar code cleanup"
-rw-r--r-- | navigationbar/src/com/android/setupwizard/navigationbar/SetupWizardNavBar.java | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/navigationbar/src/com/android/setupwizard/navigationbar/SetupWizardNavBar.java b/navigationbar/src/com/android/setupwizard/navigationbar/SetupWizardNavBar.java index 3d58354..045a256 100644 --- a/navigationbar/src/com/android/setupwizard/navigationbar/SetupWizardNavBar.java +++ b/navigationbar/src/com/android/setupwizard/navigationbar/SetupWizardNavBar.java @@ -23,7 +23,6 @@ import android.content.res.TypedArray; import android.graphics.Color; import android.os.Bundle; import android.util.AttributeSet; -import android.util.Log; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -38,7 +37,7 @@ import android.widget.Button; * Android tree can use this by including the common.mk makefile. Apps outside of the tree can * create a library project out of the source. */ -public class SetupWizardNavBar extends Fragment implements OnPreDrawListener { +public class SetupWizardNavBar extends Fragment implements OnPreDrawListener, OnClickListener { private static final String TAG = "SetupWizardNavBar"; private static final int IMMERSIVE_FLAGS = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; @@ -62,12 +61,7 @@ public class SetupWizardNavBar extends Fragment implements OnPreDrawListener { @Override public void onAttach(Activity activity) { super.onAttach(activity); - try { - mCallback = (NavigationBarListener) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement NavigationBarListener"); - } + mCallback = (NavigationBarListener) activity; } @Override @@ -77,7 +71,10 @@ public class SetupWizardNavBar extends Fragment implements OnPreDrawListener { inflater = LayoutInflater.from(context); mNavigationBarView = (ViewGroup) inflater.inflate(R.layout.setup_wizard_navbar_layout, container, false); - init(); + mNextButton = (Button) mNavigationBarView.findViewById(R.id.setup_wizard_navbar_next); + mBackButton = (Button) mNavigationBarView.findViewById(R.id.setup_wizard_navbar_back); + mNextButton.setOnClickListener(this); + mBackButton.setOnClickListener(this); return mNavigationBarView; } @@ -123,6 +120,9 @@ public class SetupWizardNavBar extends Fragment implements OnPreDrawListener { } private int getNavbarTheme() { + // Normally we can automatically guess the theme by comparing the foreground color against + // the background color. But we also allow specifying explicitly using + // setup_wizard_navbar_theme. TypedArray attributes = getActivity().obtainStyledAttributes( new int[] { R.attr.setup_wizard_navbar_theme, @@ -130,9 +130,8 @@ public class SetupWizardNavBar extends Fragment implements OnPreDrawListener { android.R.attr.colorBackground }); int theme = attributes.getResourceId(0, 0); if (theme == 0) { - // The theme is not set. Fallback to auto mode by comparing the value of the foreground - // against the background color to see if current theme is light-on-dark or - // dark-on-light. + // Compare the value of the foreground against the background color to see if current + // theme is light-on-dark or dark-on-light. float[] foregroundHsv = new float[3]; float[] backgroundHsv = new float[3]; Color.colorToHSV(attributes.getColor(1, 0), foregroundHsv); @@ -140,28 +139,18 @@ public class SetupWizardNavBar extends Fragment implements OnPreDrawListener { boolean isDarkBg = foregroundHsv[2] > backgroundHsv[2]; theme = isDarkBg ? R.style.setup_wizard_navbar_theme_dark : R.style.setup_wizard_navbar_theme_light; - Log.v(TAG, "Theme is not set explicitly, falling back to auto mode"); } - Log.v(TAG, "Using theme " + getResources().getResourceName(theme)); attributes.recycle(); return theme; } - private void init() { - mNextButton = (Button) mNavigationBarView.findViewById(R.id.setup_wizard_navbar_next); - mBackButton = (Button) mNavigationBarView.findViewById(R.id.setup_wizard_navbar_back); - mNextButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - mCallback.onNavigateNext(); - } - }); - mBackButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - mCallback.onNavigateBack(); - } - }); + @Override + public void onClick(View v) { + if (v == mBackButton) { + mCallback.onNavigateBack(); + } else if (v == mNextButton) { + mCallback.onNavigateNext(); + } } public Button getBackButton() { |