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:com.openatk.planting.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    dbHelper = new DatabaseHelper(this);

    FragmentManager fm = getSupportFragmentManager();
    fragMap = (SupportMapFragment) fm.findFragmentById(R.id.map);

    fragmentEditField = (FragmentEditJobPopup) fm.findFragmentByTag("edit_job");

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        fragMap.setRetainInstance(true);
    } else {/*w w  w  .  j ava2 s .co  m*/
        // Reincarnated activity. The obtained map is the same map instance
        // in the previous
        // activity life cycle. There is no need to reinitialize it.
        map = fragMap.getMap();
    }
    checkGPS();

    actionBar = getActionBar();
    // Specify that a dropdown list should be displayed in the action bar.
    // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Hide the title
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
    View view;
    LayoutInflater inflater = (LayoutInflater) this.getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.action_bar, null);
    RelativeLayout item = (RelativeLayout) view.findViewById(R.id.action_bar_layout);
    spinnerMenu = (Spinner) view.findViewById(R.id.action_bar_operation_spinner);
    actionBarSearch = (EditText) view.findViewById(R.id.action_bar_search_box);
    actionBar.setCustomView(item, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.LEFT));

    actionBarSearch.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == false) {
                InputMethodManager imm = (InputMethodManager) v.getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    });
    actionBarSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (fragmentListView != null)
                fragmentListView.search(s.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

    Fragment fragment = fm.findFragmentById(R.id.list_view);
    FragmentTransaction ft = fm.beginTransaction();
    ft.hide(fragment);
    ft.commit();

    //Trello
    trelloController = new TrelloController(getApplicationContext());
    syncController = new SyncController(getApplicationContext(), trelloController, this);
    trelloController.setSyncController(syncController);

    // Get last selected operation
    if (savedInstanceState != null) {
        // Find current field
        currentField = FindFieldById(savedInstanceState.getInt("currentField"));

        // Find current job
        currentJob = FindJobById(savedInstanceState.getInt("currentJob"));

        // Find current operation
        currentOperationId = savedInstanceState.getInt("currentOperationId");

        editIsShowing = savedInstanceState.getInt("editIsShowing");
        addIsShowing = savedInstanceState.getInt("addIsShowing");

        this.addingBoundary = savedInstanceState.getString("drawingBoundary", "");

        // Switch to correct state
        setState(savedInstanceState.getInt("mCurrentState"), false);
    }

    // Load operations from database
    loadOperations();

    // Specify a SpinnerAdapter to populate the dropdown list.
    spinnerMenuAdapter = new ArrayAdapter<Operation>(this, R.layout.operation_list_item, operationsList);
    spinnerMenu.setAdapter(spinnerMenuAdapter);
    // Load current from preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    currentOperationId = prefs.getInt("currentOperationId", 0);
    this.showingHazards = prefs.getBoolean("showingHazards", false);
    selectCurrentOperationInSpinner();
    spinnerMenu.setOnItemSelectedListener(this);

    setUpMapIfNeeded();

    Intent intent = this.getIntent();
    String todo = intent.getStringExtra("todo");
    if (todo != null) {
        if (todo.contentEquals("sync")) {
            trelloController.sync();
        }
    }
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.dnielfe.manager.Browser.java

private void initActionBar() {
    mActionBar = this.getActionBar();
    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM
            | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_HOME_AS_UP);

    // set custom ActionBar layout
    final View mActionView = getLayoutInflater().inflate(R.layout.activity_browser_actionbar, null);
    mActionBar.setCustomView(mActionView);
    mActionBar.show();/*www. j  a v a2  s. c om*/
}

From source file:com.openatk.field_work.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    dbHelper = new DatabaseHelper(this);
    syncHelper = new TrelloSyncHelper();

    //Get fragments
    FragmentManager fm = getSupportFragmentManager();
    atkMapFragment = (ATKSupportMapFragment) fm.findFragmentById(R.id.map);
    fragmentJob = (FragmentJob) fm.findFragmentByTag("edit_job");
    fragmentAddField = (FragmentAddField) fm.findFragmentByTag("add_field");

    //Show and hide listview really fast. TODO is there a better way to do this
    //I would like this to retain if possible...
    fragmentListView = (FragmentListView) fm.findFragmentById(R.id.list_view);
    FragmentTransaction ft = fm.beginTransaction();
    ft.hide(fragmentListView); //TODO check state, are we in list view state? if so don't hide
    ft.commit();/*from w  ww .  j  ava  2 s  . c  om*/

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        atkMapFragment.setRetainInstance(true);
        fragmentListView.setRetainInstance(true);
        if (fragmentJob != null)
            fragmentJob.setRetainInstance(true);
        if (fragmentAddField != null)
            fragmentAddField.setRetainInstance(true);

        fragmentJob = null;
        fragmentAddField = null;
    } else {
        // Reincarnated activity. The obtained map is the same map instance
        // in the previous
        // activity life cycle. There is no need to reinitialize it.
        map = atkMapFragment.getAtkMap();
    }

    actionBar = getActionBar();
    // Specify that a dropdown list should be displayed in the action bar.
    // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Hide the title
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);

    LayoutInflater inflater = (LayoutInflater) this.getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.action_bar, null);

    RelativeLayout item = (RelativeLayout) view.findViewById(R.id.action_bar_layout);

    spinnerMenu = (Spinner) view.findViewById(R.id.action_bar_operation_spinner);
    actionBarSearch = (EditText) view.findViewById(R.id.action_bar_search_box);
    actionBar.setCustomView(item, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.LEFT));

    actionBarSearch.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == false) {
                closeKeyboard();
            }
        }
    });
    actionBarSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (fragmentListView != null)
                fragmentListView.search(s.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    // Get last selected items on rotate
    this.savedInstanceState = savedInstanceState;

    // Specify a SpinnerAdapter to populate the dropdown list.
    spinnerMenuAdapter = new ArrayAdapter<Operation>(this, R.layout.operation_list_item, operationsList);
    spinnerMenu.setAdapter(spinnerMenuAdapter);

    RelativeLayoutKeyboardDetect layout = (RelativeLayoutKeyboardDetect) this.findViewById(R.id.mainActivity);
    layout.setListener(this);

    setUpMapIfNeeded();
    if (this.savedInstanceState != null) {
        int viewState = savedInstanceState.getInt("currentViewState", STATE_DEFAULT);
        setState(viewState);
    }
}

From source file:com.zte.permissioncontrol.ui.PermissionControlPageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.permission_control_pages);
    mEmptyView = (FrameLayout) findViewById(R.id.empty_view);
    mSavedInstanceState = savedInstanceState;
    // add the switch on Action bar
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSwitch = (Switch) inflater.inflate(R.layout.imageswitch_layout, null);
    final int padding = getResources().getDimensionPixelSize(R.dimen.action_bar_switch_padding);
    mSwitch.setPadding(0, 0, padding, 0);
    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
    getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    mSwitch.setOnCheckedChangeListener(this);

    // hide fragment firstly , then update it in onResume() according to switch status
    final FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    mPermissionsFragment = (PermissionsFragment) fragmentManager.findFragmentByTag(mPermissionsTag);
    mAppsFragment = (AppsFragment) fragmentManager.findFragmentByTag(mAppsTag);

    if (mPermissionsFragment == null) {
        mPermissionsFragment = new PermissionsFragment();
        mAppsFragment = new AppsFragment();
        transaction.add(R.id.tab_pager, mPermissionsFragment, mPermissionsTag);
        transaction.add(R.id.tab_pager, mAppsFragment, mAppsTag);
    }/*from w  ww  .  j a v  a  2s .  c  o m*/

    transaction.hide(mPermissionsFragment);
    transaction.hide(mAppsFragment);
    transaction.commit();
    fragmentManager.executePendingTransactions();

    // set page adapter
    mTabPager = (ViewPager) findViewById(R.id.tab_pager);
    mTabPagerAdapter = new TabPagerAdapter();
    mTabPager.setAdapter(mTabPagerAdapter);
    mTabPager.setOnPageChangeListener(mTabPagerListener);

    // Configure action bar
    mActionBarAdapter = new ActionBarAdapter(this, this, getActionBar());

    boolean isShow = PermControlUtils.isPermControlOn(this);
    Log.d(TAG, "oncreate(), isShow " + isShow);

}

From source file:com.dnielfe.manager.Browser.java

private void setupDrawer() {
    final TypedArray array = obtainStyledAttributes(new int[] { R.attr.themeId });
    final int themeId = array.getInteger(0, SimpleExplorer.THEME_ID_LIGHT);
    array.recycle();//  w ww .  jav a  2  s. co m

    mDrawer = (LinearLayout) findViewById(R.id.left_drawer);

    // Set shadow of navigation drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    int icon = themeId == SimpleExplorer.THEME_ID_LIGHT ? R.drawable.holo_light_ic_drawer
            : R.drawable.holo_dark_ic_drawer;

    // Add Navigation Drawer to ActionBar
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, icon, R.string.drawer_open,
            R.string.drawer_close) {

        @Override
        public void onDrawerOpened(View view) {
            super.onDrawerOpened(view);
            mActionBar.setDisplayOptions(
                    ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
            mActionBar.setTitle(R.string.app_name);
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            mActionBar.setDisplayOptions(
                    ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);
            invalidateOptionsMenu();
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:com.geotrackin.gpslogger.GpsMainActivity.java

public void SetUpActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(),
            R.array.gps_main_views, android.R.layout.simple_spinner_dropdown_item);

    actionBar.setListNavigationCallbacks(spinnerAdapter, this);

    //Reload the user's previously selected view f73
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    actionBar.setSelectedNavigationItem(prefs.getInt("dropdownview", 0));

    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle("");
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME
            | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.actionbar);

    ImageButton helpButton = (ImageButton) actionBar.getCustomView().findViewById(R.id.imgHelp);
    helpButton.setOnClickListener(new View.OnClickListener() {
        @Override//from w  w w .  jav  a 2 s . c  om
        public void onClick(View view) {
            Intent faqtivity = new Intent(getApplicationContext(), Faqtivity.class);
            startActivity(faqtivity);
        }
    });

}

From source file:com.se.cronus.AbstractCActivity.java

protected void setUpActionBar() {
    ImageView icon = new ImageView(this);
    icon.setBackgroundResource(com.se.cronus.R.drawable.temp_cronos_logo);
    act = this.getActionBar();
    act.setBackgroundDrawable(new ColorDrawable(CUtils.CRONUS_GREEN_DARK));
    act.setIcon(com.se.cronus.R.drawable.temp_cronos_logo);
    act.setCustomView(com.se.cronus.R.layout.action_bar);
    act.setDisplayHomeAsUpEnabled(true);
    act.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
    ((ViewGroup) act.getCustomView().getParent()).addView(icon);
    // extra icons
    search = (ImageView) findViewById(com.se.cronus.R.id.action_search_b);
    refresh = (ImageView) findViewById(com.se.cronus.R.id.action_refresh);
    searchTextE = (EditText) findViewById(com.se.cronus.R.id.action_search_et);
    searchTextV = (TextView) findViewById(com.se.cronus.R.id.action_search_tv);
    item = (ImageView) findViewById(com.se.cronus.R.id.action_item);

    searchTextE.setTextColor(Color.WHITE);
    searchTextE.setTextSize(15);//from  ww  w  . jav  a2s  .com
    searchTextE.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

    searchTextV.setTextColor(Color.WHITE);
    searchTextV.setTextSize(15);

    ImageView logo = (ImageView) findViewById(com.se.cronus.R.id.temp_cronos_logo);
    logo.setLayoutParams(new RelativeLayout.LayoutParams(act.getHeight(), act.getHeight()));

}

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

@Override
public void setDisplayOptions(int newOpts) {
    final int oldOpts = mDisplayOpts;
    final int changed = oldOpts ^ newOpts;
    mDisplayOpts = newOpts;/*from  w ww .ja  v a 2 s . c  om*/
    if (changed != 0) {
        if ((changed & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
            if ((newOpts & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
                updateHomeAccessibility();
            }
            updateNavigationIcon();
        }

        if ((changed & AFFECTS_LOGO_MASK) != 0) {
            updateToolbarLogo();
        }

        if ((changed & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
            if ((newOpts & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
                mToolbar.setTitle(mTitle);
                mToolbar.setSubtitle(mSubtitle);
            } else {
                mToolbar.setTitle(null);
                mToolbar.setSubtitle(null);
            }
        }

        if ((changed & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomView != null) {
            if ((newOpts & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
                mToolbar.addView(mCustomView);
            } else {
                mToolbar.removeView(mCustomView);
            }
        }
    }
}

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

@Override
public void setDisplayOptions(int newOpts) {
    final int oldOpts = mDisplayOpts;
    final int changed = oldOpts ^ newOpts;
    mDisplayOpts = newOpts;/*from ww  w.  ja va2s.com*/
    if (changed != 0) {
        if ((changed & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
            if ((newOpts & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
                updateNavigationIcon();
                updateHomeAccessibility();
            } else {
                mToolbar.setNavigationIcon(null);
            }
        }

        if ((changed & AFFECTS_LOGO_MASK) != 0) {
            updateToolbarLogo();
        }

        if ((changed & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
            if ((newOpts & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
                mToolbar.setTitle(mTitle);
                mToolbar.setSubtitle(mSubtitle);
            } else {
                mToolbar.setTitle(null);
                mToolbar.setSubtitle(null);
            }
        }

        if ((changed & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomView != null) {
            if ((newOpts & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
                mToolbar.addView(mCustomView);
            } else {
                mToolbar.removeView(mCustomView);
            }
        }
    }
}

From source file:com.roque.rueda.cashflows.fragments.AddMovementFragment.java

/**
 * Show a custom action bar in the activity.
 * @param inflater Inflater used to create the widgets.
 *///from   ww w .java2 s  .  co  m
private void createActionBar(LayoutInflater inflater) {
    final View customActionBarView = inflater.inflate(R.layout.actionbar_done_cancel, null);
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Done.
            //Toast.makeText(getActivity(), R.string.accept, Toast.LENGTH_SHORT).show();

            Movement cashMovement = new Movement();
            cashMovement.setAmount(getInputAmount());
            cashMovement.setDate(new Date(getInputDate()));
            cashMovement.setDescription(getInputNotes());

            if (mIsNegative) {
                cashMovement.setSing("-");
            } else {
                cashMovement.setSing("+");
            }

            cashMovement.setIdAccount(mAccountsSpinner.getSelectedItemId());

            mCashState.saveCashMovement(cashMovement);
            Toast.makeText(getActivity(), R.string.movement_save_message, Toast.LENGTH_SHORT).show();

            Intent intent = new Intent();
            // Indicate to parent activity that the information was store.
            intent.putExtra(MainActivity.ADD_MOVEMENT_RESULT, true);
            getActivity().setResult(MainActivity.REQUEST_CODE, intent);
            getActivity().finish();
        }
    });

    customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Cancel
            getActivity().finish();
        }
    });

    final ActionBar actionBar = getActivity().getActionBar();

    if (actionBar != null) {
        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));
    }
}