Example usage for android.app ActionBar DISPLAY_SHOW_CUSTOM

List of usage examples for android.app ActionBar DISPLAY_SHOW_CUSTOM

Introduction

In this page you can find the example usage for android.app ActionBar DISPLAY_SHOW_CUSTOM.

Prototype

int DISPLAY_SHOW_CUSTOM

To view the source code for android.app ActionBar DISPLAY_SHOW_CUSTOM.

Click Source Link

Document

Show the custom view if one has been set.

Usage

From source file:io.oceanos.shaderbox.ShaderEditorActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final LayoutInflater inflater = getLayoutInflater();
    final View customActionBarView = inflater.inflate(R.layout.actionbar_view_save, null);
    final View shaderActionView = customActionBarView.findViewById(R.id.actionbar_view);
    final View shaderActionSave = customActionBarView.findViewById(R.id.actionbar_save);
    shaderActionView.setOnClickListener(new View.OnClickListener() {
        @Override/*from   ww  w  .  j av  a 2s  .c  om*/
        public void onClick(View v) {
            if (result.isSuccess())
                onView(shader);
            else {
                Toast errorMsg = Toast.makeText(getBaseContext(), result.getError(), Toast.LENGTH_LONG);
                errorMsg.getView().setBackgroundColor(getResources().getColor(R.color.editor_color_error));
                errorMsg.show();
            }
        }
    });
    shaderActionSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSave(shader);
        }
    });

    fps = (TextView) customActionBarView.findViewById(R.id.text_fps);
    viewError = (TextView) shaderActionView.findViewById(R.id.viewError);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    setContentView(R.layout.activity_editor);

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    ShaderDatabase database = new ShaderDatabase(getBaseContext());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
            long id = database.newShader();
            Cursor cursor = database.findById(id);
            if (cursor.moveToFirst())
                shader = Shader.getValues(cursor);
            cursor.close();
            if (sharedText != null)
                shader.setText(sharedText);
            else
                shader.setText("");
        }
    } else {
        long id = intent.getLongExtra("ID", 0);
        Cursor cursor = database.findById(id);
        if (cursor.moveToFirst())
            shader = Shader.getValues(cursor);
        cursor.close();
    }
    database.close();

    setSymbolListener(R.id.action_tab, '\t');
    setSymbolListener(R.id.action_rpo, '(');
    setSymbolListener(R.id.action_rpc, ')');
    setSymbolListener(R.id.action_cpo, '{');
    setSymbolListener(R.id.action_cpc, '}');
    setSymbolListener(R.id.action_dotcoma, ';');
    setSymbolListener(R.id.action_coma, ',');
    setSymbolListener(R.id.action_dot, '.');
    setSymbolListener(R.id.action_plus, '+');
    setSymbolListener(R.id.action_minus, '-');
    setSymbolListener(R.id.action_times, '*');
    setSymbolListener(R.id.action_div, '/');
    setSymbolListener(R.id.action_equal, '=');
    setSymbolListener(R.id.action_spo, '[');
    setSymbolListener(R.id.action_spc, ']');
    setSymbolListener(R.id.action_and, '&');
    setSymbolListener(R.id.action_or, '|');
    setSymbolListener(R.id.action_greater, '>');
    setSymbolListener(R.id.action_lesser, '<');
    setSymbolListener(R.id.action_cardinal, '#');

    final Handler uiHandler = new Handler(this);
    renderer = new ShaderRenderer(shader, uiHandler);

    shaderView = (ShaderGLView) findViewById(R.id.shader_view);
    shaderView.setRenderer(renderer);
    shaderView.setVRModeEnabled(false);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int textSize = Integer.parseInt(prefs.getString("pref_editor_text_size", "14"));
    int opacity = Integer.parseInt(prefs.getString("pref_editor_opacity", "127"));
    editor = (ShaderEditor) findViewById(R.id.editor);
    editor.setTextSize(textSize);
    editor.setBackgroundColor(opacity << 24);
    editor.setHorizontallyScrolling(true);
    editor.setHorizontalScrollBarEnabled(true);

    editor.setText(shader.getText());

    ScrollView scroll = (ScrollView) findViewById(R.id.scroll);
    editor.setScrollView(scroll);

    compileRT = prefs.getBoolean("pref_compile_rt", true);
}

From source file:com.xenon.greenup.MainActivity.java

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical parent.
    actionBar.setHomeButtonEnabled(false);

    //Set the stacked background otherwise we get the gross dark gray color under the icon
    BitmapDrawable background = (BitmapDrawable) getResources().getDrawable(R.drawable.bottom_menu);
    background.setTileModeXY(TileMode.REPEAT, TileMode.MIRROR);
    actionBar.setStackedBackgroundDrawable(background);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setIcon(R.drawable.bottom_menu);

    _ViewPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabsAdapter(this, _ViewPager);

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < 3; i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.

        ActionBar.Tab tabToAdd = actionBar.newTab();
        if (i == 0)
            //Set the home page as active since we'll start there:
            tabToAdd.setIcon(getActiveIcon(i));
        else//  www.j a v  a  2  s  . c o  m
            tabToAdd.setIcon(getRegularIcon(i));
        mTabsAdapter.addTab(tabToAdd);

    }

    //Setting the display to custom will push the action bar to the top
    //which gives us more real estate
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.show();
    Log.i("visible", "" + _ViewPager.VISIBLE);

}

From source file:fr.cph.stock.android.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "MainActivity onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from  w ww . j  a  va2s .c om*/

    Bundle b = getIntent().getExtras();
    portfolio = b.getParcelable("portfolio");

    ada = new MainListAdapter(this, portfolio);
    listView = (ListView) findViewById(R.id.mainList);
    listView.setAdapter(ada);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            Intent intent;
            switch (position) {
            case 0:
                intent = new Intent(getBaseContext(), AccountActivity.class);
                intent.putExtra("portfolio", portfolio);
                startActivityForResult(intent, MainActivity.ACCOUNT_REQUEST);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                break;
            case 1:
                intent = new Intent(getBaseContext(), EquityActivity.class);
                intent.putExtra("portfolio", portfolio);
                startActivityForResult(intent, MainActivity.EQUITY_REQUEST);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                break;
            case 2:
                intent = new Intent(getBaseContext(), OverallActivity.class);
                intent.putExtra("portfolio", portfolio);
                startActivityForResult(intent, MainActivity.OVERALL_REQUEST);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                break;
            }
        }

    });

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);

    errorView = (TextView) findViewById(R.id.errorMessage);
    errorView.setOnClickListener(new ErrorMainOnClickListener(listView, errorView));
    EasyTracker.getInstance().setContext(this);

    // Set context
    EasyTracker.getInstance().setContext(getApplicationContext());
    // Instantiate the Tracker
    tracker = EasyTracker.getTracker();
}

From source file:com.klinker.android.twitter.settings.configure_pages.ConfigurePagerActivity.java

public void setUpDoneDiscard() {
    LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_done_discard, null);
    TextView doneButton = (TextView) customActionBarView.findViewById(R.id.done);
    doneButton.setText(getResources().getString(R.string.done_label));
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override/* w ww. j  a  v a 2s. c om*/
        public void onClick(View v) {
            int currentAccount = sharedPrefs.getInt("current_account", 1);

            SharedPreferences.Editor editor = sharedPrefs.edit();

            editor.putInt("account_" + currentAccount + "_page_1", PageOneFragment.type);
            editor.putInt("account_" + currentAccount + "_page_2", PageTwoFragment.type);

            editor.putLong("account_" + currentAccount + "_list_1_long", PageOneFragment.listId);
            editor.putLong("account_" + currentAccount + "_list_2_long", PageTwoFragment.listId);

            editor.putString("account_" + currentAccount + "_name_1", PageOneFragment.listName);
            editor.putString("account_" + currentAccount + "_name_2", PageTwoFragment.listName);

            editor.commit();

            onBackPressed();
        }
    });
    customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
}

From source file:htw.bui.openreskit.discard.InspectionActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mOverlayFramelayout = new FrameLayout(this);

    setContentView(mOverlayFramelayout);
    View view = getLayoutInflater().inflate(R.layout.inspection_fragment, mOverlayFramelayout, false);
    mOverlayFramelayout.addView(view);//w  w  w.ja  v  a 2s  . c  om
    mContext = this;
    mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    mHelpView = getLayoutInflater().inflate(R.layout.help_overlay, mOverlayFramelayout, false);
    mInspFrag = (InspectionFragment) mFragMan.findFragmentById(R.id.inspection_fragment);
    mAddInspectionButton = (Button) mOverlayFramelayout.findViewById(R.id.addInspectionButton);
    mAddInspectionButton.setOnClickListener(mButtonListener);

    if (Utils.isTablet(this)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
        if (findViewById(R.id.inspectionLayoutContainer) != null) {
            // if we are being restored from a previous state, then we dont need to do anything and should
            // return or else we could end up with overlapping fragments.
            if (savedInstanceState != null)
                return;

            // Create an instance of inspectionInfoFragment
            mInspectionInfoFragment = new InspectionInfoFragment();
            // Create an instance of RunningInspectionFragment               
            mRunningInspectionFragment = new RunningInspectionFragment();

            // add fragment to the fragment container layout
            FragmentTransaction ft = mFragMan.beginTransaction();
            ft.add(R.id.inspectionFrameLayout, mInspectionInfoFragment);
            ft.hide(mInspectionInfoFragment).commit();

            FragmentTransaction ft1 = mFragMan.beginTransaction();
            ft1.add(R.id.inspectionFrameLayout, mRunningInspectionFragment);
            ft1.hide(mRunningInspectionFragment).commit();
        }
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }

    ActionBar bar = getActionBar();
    bar.setDisplayOptions(
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
    bar.setDisplayShowHomeEnabled(true);
}

From source file:com.android.settings.profiles.ProfilesSettings.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // We don't call super.onActivityCreated() here, since it assumes we already set up
    // Preference (probably in onCreate()), while ProfilesSettings exceptionally set it up in
    // this method.
    // On/off switch
    Activity activity = getActivity();/* w w  w  .j  av  a 2s  .com*/
    //Switch
    mActionBarSwitch = new Switch(activity);

    if (activity instanceof PreferenceActivity) {
        PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
        if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
            final int padding = activity.getResources()
                    .getDimensionPixelSize(R.dimen.action_bar_switch_padding);
            mActionBarSwitch.setPaddingRelative(0, 0, padding, 0);
            activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                    ActionBar.DISPLAY_SHOW_CUSTOM);
            activity.getActionBar().setCustomView(mActionBarSwitch,
                    new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
        }
    }

    mProfileEnabler = new ProfileEnabler(activity, mActionBarSwitch);

    // After confirming PreferenceScreen is available, we call super.
    super.onActivityCreated(savedInstanceState);
}

From source file:com.ternup.caddisfly.activity.SurveyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setTheme(((MainApp) getApplicationContext()).CurrentTheme);

    setContentView(R.layout.fragment_survey);

    // BEGIN_INCLUDE (inflate_set_custom_view)
    // Inflate a "Done/Cancel" custom action bar view.
    final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done_cancel, null, false);

    final Context context = this;
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override/*from www  .  j a  v a2 s .co  m*/
        public void onClick(View v) {
            long locationId = saveData();
            if (locationId == -1) {
                mViewPager.setCurrentItem(1, true);
                AlertUtils.showMessage(context, R.string.incomplete, R.string.incompleteMessage);
            } else {
                Intent intent = new Intent();
                intent.putExtra(getString(R.string.currentLocationId), locationId);
                setResult(Activity.RESULT_OK, intent);
                //todo: change to finished method
                isCancelled = true;
                finish();
            }
        }
    });
    customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cancelSurvey();
        }
    });

    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    // END_INCLUDE (inflate_set_custom_view)

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    mViewPager.setOffscreenPageLimit(6);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
            case 1:
                //mFormFragment.showKeyboard();
                break;
            case 4:
                mNotesFragment.showKeyboard();
                break;
            default:

                (new Handler()).postDelayed(new Runnable() {

                    public void run() {
                        ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                                .hideSoftInputFromWindow(mViewPager.getWindowToken(), 0);

                    }
                }, 300);
            }

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    // END_INCLUDE (setup_viewpager)

    // BEGIN_INCLUDE (setup_slidingTabLayout)
    // Give the SlidingTabLayout the ViewPager, this must be done AFTER the ViewPager has had
    // it's PagerAdapter set.
    /*
    A custom {@link android.support.v4.view.ViewPager} title strip which looks much like Tabs
    present in Android v4.0 and
    above, but is designed to give continuous feedback to the user when scrolling.
    */
    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    slidingTabLayout.setViewPager(mViewPager);

}

From source file:com.docd.purefm.ui.activities.SearchActivity.java

private void initActionBar() {
    //noinspection InflateParams
    final View actionBarCustom = this.getLayoutInflater().inflate(R.layout.activity_search_actionbar, null);
    if (actionBarCustom == null) {
        throw new RuntimeException("Inflated View is null");
    }//  w  w w.  j  a  v a  2  s .c  om

    final TextView path = (TextView) actionBarCustom.findViewById(android.R.id.text1);
    path.setText(mStartDirectory.getAbsolutePath());

    final ActionBar bar = this.getActionBar();
    if (bar == null) {
        throw new RuntimeException("ActionBar should not be null");
    }
    bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME
            | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
    bar.setCustomView(actionBarCustom);

    mActionModeController = new ActionModeController(this);
}

From source file:android.support.v7.internal.widget.ToolbarWidgetWrapper.java

public ToolbarWidgetWrapper(Toolbar toolbar, boolean style, int defaultNavigationContentDescription,
        int defaultNavigationIcon) {
    mToolbar = toolbar;//from   www .ja  v  a2  s.com
    mTitle = toolbar.getTitle();
    mSubtitle = toolbar.getSubtitle();
    mTitleSet = mTitle != null;
    mNavIcon = toolbar.getNavigationIcon();

    if (style) {
        final TintTypedArray a = TintTypedArray.obtainStyledAttributes(toolbar.getContext(), null,
                R.styleable.ActionBar, R.attr.actionBarStyle, 0);

        final CharSequence title = a.getText(R.styleable.ActionBar_title);
        if (!TextUtils.isEmpty(title)) {
            setTitle(title);
        }

        final CharSequence subtitle = a.getText(R.styleable.ActionBar_subtitle);
        if (!TextUtils.isEmpty(subtitle)) {
            setSubtitle(subtitle);
        }

        final Drawable logo = a.getDrawable(R.styleable.ActionBar_logo);
        if (logo != null) {
            setLogo(logo);
        }

        final Drawable icon = a.getDrawable(R.styleable.ActionBar_icon);
        if (mNavIcon == null && icon != null) {
            setIcon(icon);
        }

        final Drawable navIcon = a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator);
        if (navIcon != null) {
            setNavigationIcon(navIcon);
        }

        setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, 0));

        final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
        if (customNavId != 0) {
            setCustomView(LayoutInflater.from(mToolbar.getContext()).inflate(customNavId, mToolbar, false));
            setDisplayOptions(mDisplayOpts | ActionBar.DISPLAY_SHOW_CUSTOM);
        }

        final int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
        if (height > 0) {
            final ViewGroup.LayoutParams lp = mToolbar.getLayoutParams();
            lp.height = height;
            mToolbar.setLayoutParams(lp);
        }

        final int contentInsetStart = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetStart, -1);
        final int contentInsetEnd = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetEnd, -1);
        if (contentInsetStart >= 0 || contentInsetEnd >= 0) {
            mToolbar.setContentInsetsRelative(Math.max(contentInsetStart, 0), Math.max(contentInsetEnd, 0));
        }

        final int titleTextStyle = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
        if (titleTextStyle != 0) {
            mToolbar.setTitleTextAppearance(mToolbar.getContext(), titleTextStyle);
        }

        final int subtitleTextStyle = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
        if (subtitleTextStyle != 0) {
            mToolbar.setSubtitleTextAppearance(mToolbar.getContext(), subtitleTextStyle);
        }

        final int popupTheme = a.getResourceId(R.styleable.ActionBar_popupTheme, 0);
        if (popupTheme != 0) {
            mToolbar.setPopupTheme(popupTheme);
        }

        a.recycle();
        // Keep the TintManager in case we need it later
        mTintManager = a.getTintManager();
    } else {
        mDisplayOpts = detectDisplayOptions();
        // Create a TintManager in case we need it later
        mTintManager = new TintManager(toolbar.getContext());
    }

    setDefaultNavigationContentDescription(defaultNavigationContentDescription);
    mHomeDescription = mToolbar.getNavigationContentDescription();

    setDefaultNavigationIcon(mTintManager.getDrawable(defaultNavigationIcon));

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        final ActionMenuItem mNavItem = new ActionMenuItem(mToolbar.getContext(), 0, android.R.id.home, 0, 0,
                mTitle);

        @Override
        public void onClick(View v) {
            if (mWindowCallback != null && mMenuPrepared) {
                mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mNavItem);
            }
        }
    });
}

From source file:lewa.support.v7.internal.widget.ToolbarWidgetWrapper.java

public ToolbarWidgetWrapper(Toolbar toolbar, boolean style, int defaultNavigationContentDescription,
        int defaultNavigationIcon) {
    mToolbar = toolbar;//from   w  ww .  ja v a2  s.co  m
    mTitle = toolbar.getTitle();
    mSubtitle = toolbar.getSubtitle();
    mTitleSet = mTitle != null;

    if (style) {
        final TintTypedArray a = TintTypedArray.obtainStyledAttributes(toolbar.getContext(), null,
                R.styleable.ActionBar, R.attr.actionBarStyle, 0);

        final CharSequence title = a.getText(R.styleable.ActionBar_title);
        if (!TextUtils.isEmpty(title)) {
            setTitle(title);
        }

        final CharSequence subtitle = a.getText(R.styleable.ActionBar_subtitle);
        if (!TextUtils.isEmpty(subtitle)) {
            setSubtitle(subtitle);
        }

        final Drawable logo = a.getDrawable(R.styleable.ActionBar_logo);
        if (logo != null) {
            setLogo(logo);
        }

        final Drawable icon = a.getDrawable(R.styleable.ActionBar_icon);
        if (icon != null) {
            setIcon(icon);
        }

        final Drawable navIcon = a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator);
        if (navIcon != null) {
            setNavigationIcon(navIcon);
        }

        setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, 0));

        final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
        if (customNavId != 0) {
            setCustomView(LayoutInflater.from(mToolbar.getContext()).inflate(customNavId, mToolbar, false));
            setDisplayOptions(mDisplayOpts | ActionBar.DISPLAY_SHOW_CUSTOM);
        }

        final int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
        if (height > 0) {
            final ViewGroup.LayoutParams lp = mToolbar.getLayoutParams();
            lp.height = height;
            mToolbar.setLayoutParams(lp);
        }

        final int contentInsetStart = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetStart, -1);
        final int contentInsetEnd = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetEnd, -1);
        if (contentInsetStart >= 0 || contentInsetEnd >= 0) {
            mToolbar.setContentInsetsRelative(Math.max(contentInsetStart, 0), Math.max(contentInsetEnd, 0));
        }

        final int titleTextStyle = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
        if (titleTextStyle != 0) {
            mToolbar.setTitleTextAppearance(mToolbar.getContext(), titleTextStyle);
        }

        final int subtitleTextStyle = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
        if (subtitleTextStyle != 0) {
            mToolbar.setSubtitleTextAppearance(mToolbar.getContext(), subtitleTextStyle);
        }

        final int popupTheme = a.getResourceId(R.styleable.ActionBar_popupTheme, 0);
        if (popupTheme != 0) {
            mToolbar.setPopupTheme(popupTheme);
        }

        a.recycle();
        // Keep the TintManager in case we need it later
        mTintManager = a.getTintManager();
    } else {
        mDisplayOpts = detectDisplayOptions();
        // Create a TintManager in case we need it later
        mTintManager = new TintManager(toolbar.getContext());
    }

    setDefaultNavigationContentDescription(defaultNavigationContentDescription);
    mHomeDescription = mToolbar.getNavigationContentDescription();

    setDefaultNavigationIcon(mTintManager.getDrawable(defaultNavigationIcon));

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        final ActionMenuItem mNavItem = new ActionMenuItem(mToolbar.getContext(), 0, android.R.id.home, 0, 0,
                mTitle);

        @Override
        public void onClick(View v) {
            if (mWindowCallback != null && mMenuPrepared) {
                mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mNavItem);
            }
        }
    });
}