summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2014-06-24 17:30:28 -0700
committerMaurice Lam <yukl@google.com>2014-06-24 17:51:32 -0700
commit6c4d5786ec0ce22429a68c5b9e92f3dab9863f2d (patch)
tree879f24a579265c48ae7cc561d5b39fafe6d7bdaf
parent4f35a014222af63c5f931f1cd010d594ee09ed5f (diff)
downloadandroid_frameworks_opt_setupwizard-6c4d5786ec0ce22429a68c5b9e92f3dab9863f2d.tar.gz
android_frameworks_opt_setupwizard-6c4d5786ec0ce22429a68c5b9e92f3dab9863f2d.tar.bz2
android_frameworks_opt_setupwizard-6c4d5786ec0ce22429a68c5b9e92f3dab9863f2d.zip
Navigation bar code cleanup
Bug: 15863755 Change-Id: I00876935be5cd374a9454ea053d0f899bfd8745c
-rw-r--r--navigationbar/src/com/android/setupwizard/navigationbar/SetupWizardNavBar.java47
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() {