Example usage for android.app ActionBar setCustomView

List of usage examples for android.app ActionBar setCustomView

Introduction

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

Prototype

public abstract void setCustomView(@LayoutRes int resId);

Source Link

Document

Set the action bar into custom navigation mode, supplying a view for custom navigation.

Usage

From source file:com.inha.stickyonpage.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (getSupportFragmentManager().findFragmentByTag("BrowsingWebView") != null) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT) || mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
                mDrawerLayout.closeDrawer(Gravity.LEFT);
                return false;
            } else {
                WebView mWebView = (WebView) findViewById(R.id.webView1);
                if (mWebView.canGoBack()) {
                    mWebView.goBack();//w  w w  . j a  va2  s.c  o  m
                } else {
                    ActionBar mActionBar = getActionBar();
                    mActionBar.setCustomView(null);
                    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);
                    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    RecentStickyView stickyFragment = new RecentStickyView();
                    ft.replace(R.id.drawer_main, stickyFragment, "RecentStickyView");
                    ft.commit();
                }
                return false;
            }
        } else if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
            if (!mFlag) {
                Toast.makeText(this, "''?  ?  ?.",
                        Toast.LENGTH_SHORT).show();
                mFlag = true;
                mHandler.sendEmptyMessageDelayed(0, 2000);
                return false;
            } else {
                finish();
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.noorganization.shoppinglist.view.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    m_presenter = ShoppingListPresenter.getInstance(this);
    if (m_presenter.needsToCreateAList()) {
        m_presenter.createList("Test List");
    }// www . j  a  v a2 s  .co m

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

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

    m_listSelector = new Spinner(this);
    m_listSelector.setAdapter(new ListSpinnerAdapter(m_presenter.getLists()));
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(m_listSelector);

    updateListDropDown();

    m_listSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> _parent, View _view, int _position, long _selectedId) {
            m_presenter.selectList((int) _selectedId);
            // TODO refresh listfragments
        }

        @Override
        public void onNothingSelected(AdapterView<?> _parent) {
        }
    });

}

From source file:com.aboveware.actionbar.honeycomb.ActionBarHelperHoneycomb.java

@Override
public void setCustomView(View view) {
    ActionBar bar = mActivity.getActionBar();
    bar.setCustomView(view);
}

From source file:com.example.android.donebar.DoneButtonActivity.java

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

    // BEGIN_INCLUDE (inflate_set_custom_view)
    // Inflate a "Done" custom action bar view to serve as the "Up" affordance.
    final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done, null);
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w w .  j a  v a  2 s. com*/
        public void onClick(View v) {
            // "Done"
            finish();
        }
    });

    // 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);
    // END_INCLUDE (inflate_set_custom_view)

    AsyncHttpClient client = new AsyncHttpClient();

    client.get("http://192.168.0.101:8080/AndroidRESTful2/webresources/com.erikchenmelbourne.entities.caller",
            new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, org.apache.http.Header[] headers,
                        org.json.JSONArray response) {
                    if (response != null) {
                        String string = response.toString();
                        try {
                            JSONArray jsonarray = new JSONArray(string);
                            Caller.jsonarraylist.clear();
                            populateArrayList(jsonarray, Caller.jsonarraylist);
                            /*for (int i = 0; i < Caller.jsonarraylist.size(); i++) {
                            Toast.makeText(getApplicationContext(), Caller.jsonarraylist.get(i).toString(), Toast.LENGTH_LONG).show();
                            }*/
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    } else {
                        Toast.makeText(getApplicationContext(),
                                "Status Code: " + statusCode + " Data has been posted.", Toast.LENGTH_LONG)
                                .show();
                    }
                }

                @Override
                public void onFailure(int statusCode, org.apache.http.Header[] headers,
                        java.lang.Throwable throwable, org.json.JSONArray errorResponse) {
                    if (statusCode == 404) {
                        Toast.makeText(getApplicationContext(), "Requested resource not found.",
                                Toast.LENGTH_LONG).show();
                    } else if (statusCode == 500) {
                        Toast.makeText(getApplicationContext(), "Something went wrong at server end.",
                                Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(getApplicationContext(),
                                "Unexpected Error occurred. [Most common Error: Device might not be connected to Internet or remote server is not up and running]",
                                Toast.LENGTH_LONG).show();
                    }
                }
            });

    setContentView(R.layout.activity_done_button);
}

From source file:com.emman.tame.MainActivity.java

public void restoreActionBar() {
    ActionBar actionBar = getActionBar();

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.action_bar);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(mTitle);/*from   w w  w . j  ava 2  s  .  co m*/
}

From source file:com.numenta.taurus.instance.InstanceListActivity.java

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

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    // Create content from resource
    setContentView(R.layout.activity_instance_list);

    // Get ListFragment
    _listFragment = (InstanceListFragment) getFragmentManager().findFragmentById(R.id.instance_list_fragment);

    // Add Filter menu
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(R.layout.actionbar_filter);
        _favorites = (RadioGroup) actionBar.getCustomView().findViewById(R.id.filter);
        if (_favorites != null) {
            _favorites.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override/*from  www.  ja  va2  s .  com*/
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    if (checkedId == R.id.filter_favorites) {
                        clearNotifications();
                        _listFragment.filterFavorites();
                    } else {
                        _listFragment.clearFilter();
                    }
                    // Write the new viewState to the preferences
                    pref.edit().putInt(TaurusPreferenceConstants.PREF_LAST_VIEW_STATE, checkedId).apply();
                }
            });
            int checkedId = R.id.filter_none;
            try {
                checkedId = pref.getInt(TaurusPreferenceConstants.PREF_LAST_VIEW_STATE, R.id.filter_none);
            } catch (ClassCastException e) {
                // Remove old preference value
                pref.edit().remove(TaurusPreferenceConstants.PREF_LAST_VIEW_STATE).apply();
            }
            RadioButton button = (RadioButton) _favorites.findViewById(checkedId);
            if (button != null) {
                button.setChecked(true);
            }
        }
    }
    // Handle search queries
    if (getIntent() != null) {
        handleIntent(getIntent());
    }
    // Check if we should show the tutorial page
    boolean skipTutorial = pref.getBoolean(PreferencesConstants.PREF_SKIP_TUTORIAL, false);
    if (!skipTutorial) {
        Intent myIntent = new Intent(this, TutorialActivity.class);
        startActivity(myIntent);
        overridePendingTransition(0, R.anim.fadeout_animation);
    }

}

From source file:com.notriddle.budget.EnvelopesActivity.java

private void setupDrawer() {
    mNavDrawer = (ListView) findViewById(R.id.left_drawer);
    mNavAdapter = new NavAdapter(this);
    mNavDrawer.setAdapter(mNavAdapter);//from  ww  w.j a v  a2s  . c  om
    mNavDrawer.setOnItemClickListener(this);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer,
            R.string.drawerOpen_button, R.string.drawerClose_button) {
        @Override
        public void onDrawerClosed(View v) {
            super.onDrawerClosed(v);
            ActionBar ab = getActionBar();
            ab.setTitle(getTitle());
            invalidateOptionsMenu();
            if (mCustomActionBarView != null) {
                ab.setCustomView(mCustomActionBarView);
                ab.setDisplayShowTitleEnabled(false);
                ab.setDisplayShowCustomEnabled(true);
            }
        }

        @Override
        public void onDrawerSlide(View v, float off) {
            super.onDrawerSlide(v, off);
            int allIn = mColor;
            int allOut = 0xFFEEEEEE;
            int result = Color.rgb((int) (Color.red(allIn) * (1 - off) + Color.red(allOut) * off),
                    (int) (Color.green(allIn) * (1 - off) + Color.green(allOut) * off),
                    (int) (Color.blue(allIn) * (1 - off) + Color.blue(allOut) * off));
            mActionBarColor.setColor(result);
        }

        @Override
        public void onDrawerOpened(View v) {
            super.onDrawerOpened(v);
            ActionBar ab = getActionBar();
            ab.setTitle(getString(R.string.app_name));
            invalidateOptionsMenu();
            if (mCustomActionBarView != null) {
                ab.setDisplayShowTitleEnabled(true);
                ab.setDisplayShowCustomEnabled(false);
                ab.setCustomView(null);
            }
        }
    };
    mDrawerLayout.setDrawerListener(mNavToggle);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);
}

From source file:com.android.talkback.tutorial.TutorialLessonFragment.java

@Override
public void onResume() {
    super.onResume();
    Activity activity = getActivity();//w w  w  .  ja v a2  s  .c  o  m
    if (activity != null) {
        ActionBar actionBar = activity.getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setCustomView(R.layout.tutorial_action_bar);
        actionBar.getCustomView().findViewById(R.id.up).setOnClickListener(this);
        TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_title);
        title.setText(getTitle());
        LocalBroadcastManager.getInstance(activity).registerReceiver(mActionMonitor,
                GestureActionMonitor.FILTER);
    }

    TalkBackService service = TalkBackService.getInstance();
    if (service != null) {
        service.addEventListener(mExercise);
    }
}

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");
    }//from  w  w  w. j a v  a  2s.co m

    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:ch.ethz.coss.nervousnet.hub.ui.SensorDisplayActivity.java

@Override
public void updateActionBar() {

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.ab_nn, null);
    ActionBar actionBar;
    Switch mainSwitch;//from  w  ww. j  ava 2  s  .  c  om

    actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setCustomView(v);
    mainSwitch = (Switch) findViewById(R.id.mainSwitch);

    byte state = ((Application) getApplication()).getState();
    NNLog.d("SensorDisplayActivity", "state = " + state);
    mainSwitch.setChecked(state == 0 ? false : true);

    mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            startStopSensorService(isChecked);
        }
    });

}