Java Code Examples for android.app.ActionBar#setDisplayOptions()

The following examples show how to use android.app.ActionBar#setDisplayOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppUtils.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static void initActionBar(final Activity activity) {
    if (activity == null) {
        return;
    }

    ActionBar bar = activity.getActionBar();
    if (bar == null) {
        return;
    }

    if (activity instanceof MainActivity) {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM
                | ActionBar.DISPLAY_SHOW_HOME);
    } else {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP
                | ActionBar.DISPLAY_SHOW_CUSTOM);
    }
}
 
Example 2
Source File: DConnectServiceListActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_service_list);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
        actionBar.setTitle(R.string.activity_service_list_title);
    }

    mManualActivity = getSettingManualActivityClass();

    bindMessageService();
}
 
Example 3
Source File: FragmentNestingPagerSupport.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Simple"),
            CountingFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("List"),
            FragmentPagerSupport.ArrayListFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Cursor"),
            CursorFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Tabs"),
            FragmentTabsFragment.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}
 
Example 4
Source File: ActionBarTabsPager.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Simple"),
            CountingFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("List"),
            FragmentPagerSupport.ArrayListFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Cursor"),
            CursorFragment.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}
 
Example 5
Source File: ViewPagerTransformerActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int selectedPage = 0;
    if (savedInstanceState != null) {
        mSelectedItem = savedInstanceState.getInt(KEY_SELECTED_CLASS);
        selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
    }

    final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<>(getApplicationContext(),
            android.R.layout.simple_list_item_1, android.R.id.text1, TRANSFORM_CLASSES);

    final ActionBar actionBar = getActionBar();
    actionBar.setListNavigationCallbacks(actionBarAdapter, this);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);

    setContentView(R.layout.viewpager_transform_activity);

    mAdapter = new PageAdapter(getFragmentManager());

    mPager = (ViewPager) findViewById(R.id.container);
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(selectedPage);

    actionBar.setSelectedNavigationItem(mSelectedItem);
}
 
Example 6
Source File: ActionBarTabs.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onToggleTabs(View v) {
    final ActionBar bar = getActionBar();

    if (bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS) {
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    } else {
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    }
}
 
Example 7
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	ActionBar actionBar = getActionBar();
	Bitmap b = BitmapFactory.decodeResource(getResources(),
			R.drawable.ic_launcher);

	actionBar.
		setBackgroundDrawable(new BitmapDrawable(getResources(), b));

	// add the custom view to the action bar

	actionBar.setCustomView(R.layout.actionbar_view);

	EditText search = (EditText) actionBar.getCustomView().findViewById(
			R.id.searchfield);
	search.setOnEditorActionListener(new OnEditorActionListener() {
		@Override
		public boolean onEditorAction(TextView v, int actionId,
				KeyEvent event) {
			Toast.makeText(MainActivity.this, "Search triggered",
					Toast.LENGTH_LONG).show();
			return false;
		}
	});
	actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
			| ActionBar.DISPLAY_SHOW_HOME);
}
 
Example 8
Source File: ActivityListPublish.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
private void renderLayout(ArrayList<DeliveryRequest> list) {

		ActionBar actionBar = getActionBar();
		actionBar.setCustomView(R.layout.actionbar_top); // load your layout
		actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
			| ActionBar.DISPLAY_SHOW_CUSTOM); // show it

		actionBar.setDisplayHomeAsUpEnabled(true);

		numVS = (TextView) actionBar.getCustomView().findViewById(R.id.num_vs);
		numVS.setText("0");
		listAdapter.clear();
		listAdapter.notifyDataSetChanged();

		for (DeliveryRequest dr : list) {

			new AsyncTask<DeliveryRequest, Void, PublishRow>() {
				@Override
				protected PublishRow doInBackground(DeliveryRequest... params) {
					Calendar cal = Calendar.getInstance();
					cal.setTimeInMillis(params[0].getLastTime());
					String info = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH).format(cal.getTime());
					return new PublishRow(params[0].getId(), params[0].getUrl(), params[0].getClientID(),params[0].getClientSecret(), params[0].isActive(), "Last connection: " + info, params[0].getVsname());
				}

				@Override
				protected void onPostExecute(PublishRow result) {
					listAdapter.add(result);
					listAdapter.notifyDataSetChanged();
					numVS.setText(listAdapter.getCount() + "");
				}
			}.execute(dr);

		}
		TextView lastUpdate = (TextView) actionBar.getCustomView().findViewById(
			R.id.lastUpdate);
		lastUpdate.setText("Last update:\n" + (new Date()).toString());
	}
 
Example 9
Source File: DoneButtonActivity.java    From android-DoneBar with Apache License 2.0 5 votes vote down vote up
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
                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)

    setContentView(R.layout.activity_done_button);
}
 
Example 10
Source File: MainActivity.java    From androidtestdebug with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(savedInstanceState != null && savedInstanceState.getInt("theme", -1) != -1) {
        mThemeId = savedInstanceState.getInt("theme");
        this.setTheme(mThemeId);
    }
            
    setContentView(R.layout.main);

    Directory.initializeDirectory(new OnDirectoryChanged());
    
    ActionBar bar = getActionBar();

    int i;
    for (i = 0; i < Directory.getCategoryCount(); i++) {
        bar.addTab(bar.newTab().setText(Directory.getCategory(i).getName())
                .setTabListener(this));
    }

    mActionBarView = getLayoutInflater().inflate(
            R.layout.action_bar_custom, null);

    bar.setCustomView(mActionBarView);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowHomeEnabled(true);

    // If category is not saved to the savedInstanceState,
    // 0 is returned by default.
    if(savedInstanceState != null) {
        int category = savedInstanceState.getInt("category");
        bar.selectTab(bar.getTabAt(category));
    }
}
 
Example 11
Source File: CameraActivity.java    From dbclf with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void onResume() {
    super.onResume();

    if (!hasPermission(PERMISSION_CAMERA)) {

        if (cameraPermissionRequests++ < 3) {
            requestPermission(PERMISSION_CAMERA);
        } else {
            Toast.makeText(getApplicationContext(), "Camera permission required.", Toast.LENGTH_LONG).show();
        }
    } else {
        setFragment();
    }

    snapShot.set(false);

    handlerThread = new HandlerThread("inference");
    handlerThread.start();
    handler = new Handler(handlerThread.getLooper());

    final ActionBar actionBar = getActionBar();
    if (actionBar != null)
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);

    if (!imageSet) cameraButton.setEnabled(true);
}
 
Example 12
Source File: ViewPagerTransformerActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int selectedPage = 0;
    if (savedInstanceState != null) {
        mSelectedItem = savedInstanceState.getInt(KEY_SELECTED_CLASS);
        selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
    }

    final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<>(getApplicationContext(),
            android.R.layout.simple_list_item_1, android.R.id.text1, TRANSFORM_CLASSES);

    final ActionBar actionBar = getActionBar();
    actionBar.setListNavigationCallbacks(actionBarAdapter, this);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);

    setContentView(R.layout.viewpager_transform_activity);

    mAdapter = new PageAdapter(getFragmentManager());

    mPager = (ViewPager) findViewById(R.id.container);
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(selectedPage);

    actionBar.setSelectedNavigationItem(mSelectedItem);
}
 
Example 13
Source File: MainActivity.java    From android-viewpager-transformers with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int selectedPage = 0;
    if (savedInstanceState != null) {
        mSelectedItem = savedInstanceState.getInt(KEY_SELECTED_CLASS);
        selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
    }

    final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<TransformerItem>(getApplicationContext(),
            android.R.layout.simple_list_item_1, android.R.id.text1, TRANSFORM_CLASSES);

    final ActionBar actionBar = getActionBar();
    actionBar.setListNavigationCallbacks(actionBarAdapter, this);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);

    setContentView(R.layout.activity_main);

    mAdapter = new PageAdapter(getSupportFragmentManager());

    mPager = (ViewPager) findViewById(R.id.container);
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(selectedPage);

    actionBar.setSelectedNavigationItem(mSelectedItem);
}
 
Example 14
Source File: MainActivity.java    From androidtestdebug with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(savedInstanceState != null && savedInstanceState.getInt("theme", -1) != -1) {
        mThemeId = savedInstanceState.getInt("theme");
        this.setTheme(mThemeId);
    }
            
    setContentView(R.layout.main);

    Directory.initializeDirectory(new OnDirectoryChanged());
    
    ActionBar bar = getActionBar();

    int i;
    for (i = 0; i < Directory.getCategoryCount(); i++) {
        bar.addTab(bar.newTab().setText(Directory.getCategory(i).getName())
                .setTabListener(this));
    }

    mActionBarView = getLayoutInflater().inflate(
            R.layout.action_bar_custom, null);

    bar.setCustomView(mActionBarView);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowHomeEnabled(true);

    // If category is not saved to the savedInstanceState,
    // 0 is returned by default.
    if(savedInstanceState != null) {
        int category = savedInstanceState.getInt("category");
        bar.selectTab(bar.getTabAt(category));
    }
}
 
Example 15
Source File: FaBoServiceListActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_service_list);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
        actionBar.setTitle(R.string.activity_service_list_title);
    }

    bindMessageService();
}
 
Example 16
Source File: FaBoSettingActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fabo_setting);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
        actionBar.setTitle(R.string.activity_setting_arduino_title);
    }
}
 
Example 17
Source File: FaBoArduinoActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fabo_arduino);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
        actionBar.setTitle(R.string.activity_setting_arduino_title);
    }

    Intent a = new Intent();
    a.setClass(this, FaBoArduinoDeviceService.class);
    startService(a);

    boolean finishFlag = true;
    Intent intent = getIntent();
    if (intent != null) {
        String page = intent.getStringExtra("page");
        if ("firmata".equals(page)) {
            showFirmwareFragment();
            return;
        } else if ("connect".equals(page)) {
            finishFlag = false;
        }
    }
    showConnectFragment(finishFlag);
}
 
Example 18
Source File: ActionBarDisplayOptions.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onClick(View v) {
    final ActionBar bar = getActionBar();
    int flags = 0;
    switch (v.getId()) {
        case R.id.toggle_home_as_up:
            flags = ActionBar.DISPLAY_HOME_AS_UP;
            break;
        case R.id.toggle_show_home:
            flags = ActionBar.DISPLAY_SHOW_HOME;
            break;
        case R.id.toggle_use_logo:
            flags = ActionBar.DISPLAY_USE_LOGO;
            break;
        case R.id.toggle_show_title:
            flags = ActionBar.DISPLAY_SHOW_TITLE;
            break;
        case R.id.toggle_show_custom:
            flags = ActionBar.DISPLAY_SHOW_CUSTOM;
            break;

        case R.id.toggle_navigation:
            bar.setNavigationMode(
                    bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD
                            ? ActionBar.NAVIGATION_MODE_TABS
                            : ActionBar.NAVIGATION_MODE_STANDARD);
            return;
        case R.id.cycle_custom_gravity:
            ActionBar.LayoutParams lp = (ActionBar.LayoutParams) mCustomView.getLayoutParams();
            int newGravity = 0;
            switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.LEFT:
                    newGravity = Gravity.CENTER_HORIZONTAL;
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    newGravity = Gravity.RIGHT;
                    break;
                case Gravity.RIGHT:
                    newGravity = Gravity.LEFT;
                    break;
            }
            lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity;
            bar.setCustomView(mCustomView, lp);
            return;
    }

    int change = bar.getDisplayOptions() ^ flags;
    bar.setDisplayOptions(change, flags);
}
 
Example 19
Source File: ActivityListVS.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
private void renderLayout(ArrayList<AbstractVirtualSensor> vsList) {

		ActionBar actionBar = getActionBar();
		actionBar.setCustomView(R.layout.actionbar_top); // load your layout
		actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
			| ActionBar.DISPLAY_SHOW_CUSTOM); // show it

		actionBar.setDisplayHomeAsUpEnabled(true);

		numVS = (TextView) actionBar.getCustomView().findViewById(R.id.num_vs);
		numVS.setText("0");
		vSListAdapter.clear();
		vSListAdapter.notifyDataSetChanged();

		for (AbstractVirtualSensor vs : vsList) {

			new AsyncTask<AbstractVirtualSensor, Void, VSRow>() {
				@Override
				protected VSRow doInBackground(AbstractVirtualSensor... params) {
					StreamElement se = controller.loadLatestData(params[0].getConfig().getName());
					DecimalFormat df = new DecimalFormat("#.##");
					String latest = "";
					if (se != null)
						for (String field : se.getFieldNames()) {
							latest += field + ": " + df.format(se.getData(field)) + "\n";
						}
					return new VSRow(params[0].getConfig().getName(), params[0].getConfig().getRunning(), latest);
				}

				@Override
				protected void onPostExecute(VSRow result) {
					vSListAdapter.add(result);
					vSListAdapter.notifyDataSetChanged();
					numVS.setText(vSListAdapter.getCount() + "");
				}
			}.execute(vs);

		}
		TextView lastUpdate = (TextView) actionBar.getCustomView().findViewById(
			R.id.lastUpdate);
		lastUpdate.setText("Last update:\n" + (new Date()).toString());
	}
 
Example 20
Source File: ApolloUtils.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
/**
 * UP accordance without the icon
 * 
 * @param actionBar
 */
public static void showUpTitleOnly(ActionBar actionBar) {
    actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE,
            ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE
                    | ActionBar.DISPLAY_SHOW_HOME);
}