FileDocCategorySizeDatePackage
SetupWizardNavBar.javaAPI DocAndroid 5.1 API7410Thu Mar 12 22:22:54 GMT 2015com.android.setupwizard.navigationbar

SetupWizardNavBar

public class SetupWizardNavBar extends android.app.Fragment implements android.view.View.OnClickListener, android.view.ViewTreeObserver.OnPreDrawListener
Fragment class for controlling the custom navigation bar shown during setup wizard. Apps in the 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.

Fields Summary
private static final String
TAG
private static final int
IMMERSIVE_FLAGS
private int
mSystemUiFlags
private android.view.ViewGroup
mNavigationBarView
private android.widget.Button
mNextButton
private android.widget.Button
mBackButton
private NavigationBarListener
mCallback
Constructors Summary
public SetupWizardNavBar()


       
           
          
          
    

      
        // no-arg constructor for fragments
    
Methods Summary
public android.widget.ButtongetBackButton()

        return mBackButton;
    
private intgetNavbarTheme()

        // 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,
                        android.R.attr.colorForeground,
                        android.R.attr.colorBackground });
        int theme = attributes.getResourceId(0, 0);
        if (theme == 0) {
            // 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);
            Color.colorToHSV(attributes.getColor(2, 0), backgroundHsv);
            boolean isDarkBg = foregroundHsv[2] > backgroundHsv[2];
            theme = isDarkBg ? R.style.setup_wizard_navbar_theme_dark :
                    R.style.setup_wizard_navbar_theme_light;
        }
        attributes.recycle();
        return theme;
    
public android.widget.ButtongetNextButton()

        return mNextButton;
    
public voidonAttach(android.app.Activity activity)

        super.onAttach(activity);
        mCallback = (NavigationBarListener) activity;
    
public voidonClick(android.view.View v)

        if (v == mBackButton) {
            mCallback.onNavigateBack();
        } else if (v == mNextButton) {
            mCallback.onNavigateNext();
        }
    
public android.view.ViewonCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)

        Context context = new ContextThemeWrapper(getActivity(), getNavbarTheme());
        inflater = LayoutInflater.from(context);
        mNavigationBarView = (ViewGroup) inflater.inflate(R.layout.setup_wizard_navbar_layout,
                container, false);
        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;
    
public booleanonPreDraw()

        // View.setSystemUiVisibility checks if the visibility changes before applying them
        // so the performance impact is contained
        mNavigationBarView.setSystemUiVisibility(mSystemUiFlags);
        return true;
    
public voidonViewCreated(android.view.View view, android.os.Bundle savedInstanceState)

        super.onViewCreated(view, savedInstanceState);
        mCallback.onNavigationBarCreated(this);
        mNavigationBarView.setSystemUiVisibility(mSystemUiFlags);

        // Set the UI flags before draw because the visibility might change in unexpected /
        // undetectable times, like transitioning from a finishing activity that had a keyboard
        ViewTreeObserver viewTreeObserver = mNavigationBarView.getViewTreeObserver();
        viewTreeObserver.addOnPreDrawListener(this);
    
public voidsetUseImmersiveMode(boolean useImmersiveMode)
Sets whether system navigation bar should be hidden.

param
useImmersiveMode True to activate immersive mode and hide the system navigation bar

        // By default, enable layoutHideNavigation if immersive mode is used
        setUseImmersiveMode(useImmersiveMode, useImmersiveMode);
    
public voidsetUseImmersiveMode(boolean useImmersiveMode, boolean layoutHideNavigation)

        if (useImmersiveMode) {
            mSystemUiFlags |= IMMERSIVE_FLAGS;
            if (layoutHideNavigation) {
                mSystemUiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
            }
        } else {
            mSystemUiFlags &= ~(IMMERSIVE_FLAGS | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
        }
        mNavigationBarView.setSystemUiVisibility(mSystemUiFlags);