List of usage examples for android.app ActionBar setHomeButtonEnabled
public void setHomeButtonEnabled(boolean enabled)
From source file:blackman.matt.infinitebrowser.NavigationDrawerFragment.java
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. *///from ww w .ja v a2 s. c om public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */ ) { /** * Handles the drawer being closed. * * @param drawerView The drawer being closed. */ @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } /** * Handles the drawer being opened. * * @param drawerView The drawer being opened. */ @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } setUpListAdapter(); getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String boardRoot = "/tech/"; if (view instanceof TextView) { boardRoot = ((TextView) view).getText().toString(); } FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Board newBoard = Board.newInstance(boardRoot); fragmentTransaction.replace(R.id.container, newBoard, boardRoot); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); closeDrawer(); } }); // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
From source file:co.edu.uniajc.vtf.content.SwipeContentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_swipe_content); //get the pager this.coAppSectionsPagerAdapter = new AppSectionsPagerAdapter(this.getSupportFragmentManager(), this); this.coViewPager = (ViewPager) findViewById(R.id.pagPagerContainer); this.coViewPager.setAdapter(coAppSectionsPagerAdapter); //get the action bar final ActionBar actionBar = this.getActionBar(); coViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/*from w ww. j a v a 2 s. co m*/ public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.list48)); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.map48)); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.ra48)); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.options48)); //get the google api client this.coApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_PROFILE).build(); }
From source file:com.cachirulop.moneybox.activity.MainActivity.java
/** * Initialize the application action bar *//*from w w w.j av a 2 s. c o m*/ private void createActionBar() { final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); }
From source file:com.example.android.listentgt.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); PACKAGE_NAME = getApplicationContext().getPackageName(); // 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.//from w ww . j a v a2s . c om actionBar.setHomeButtonEnabled(false); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); 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.addTab(actionBar.newTab().setText(pages[i]).setTabListener(this)); } //Initalize fragments fragment1 = new FragmentPlayList(); fragment2 = new DeviceListFragment(); fragment3 = new FragmentSettingsPage(); //wifiP2pManagerActivity intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); }
From source file:org.catrobat.catroid.ui.MainMenuActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!Utils.checkForExternalStorageAvailableAndDisplayErrorIfNot(this)) { return;/*w w w. ja va 2s . co m*/ } initializeFacebookSdk(); PreferenceManager.setDefaultValues(this, R.xml.preferences, true); UtilUi.updateScreenWidthAndHeight(this); if (STANDALONE_MODE) { /*requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);*/ getActionBar().hide(); setContentView(R.layout.activity_main_menu_splashscreen); unzipProgram(); } else { setContentView(R.layout.activity_main_menu); final ActionBar actionBar = getActionBar(); actionBar.setDisplayUseLogoEnabled(true); actionBar.setHomeButtonEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setTitle(R.string.app_name); findViewById(R.id.main_menu_button_continue).setEnabled(false); // Load external project from URL or local file system. Uri loadExternalProjectUri = getIntent().getData(); getIntent().setData(null); if (loadExternalProjectUri != null) { loadProgramFromExternalSource(loadExternalProjectUri); } } }
From source file:us.cboyd.android.dicom.DcmBrowser.java
/** Called when the activity is first created. */ @Override/* ww w . j a v a 2 s .co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dcm_browser); FragmentManager fragManager = getFragmentManager(); if (savedInstanceState != null) { mListFragment = (DcmListFragment) fragManager.getFragment(savedInstanceState, DcmVar.FRAGLIST); mInfoFragment = (DcmInfoFragment) fragManager.getFragment(savedInstanceState, DcmVar.FRAGINFO); // Remove existing fragments from associated views. fragManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); fragManager.beginTransaction().remove(mListFragment).commit(); fragManager.beginTransaction().remove(mInfoFragment).commit(); fragManager.executePendingTransactions(); } // Restore the retained fragments, if this is a configuration change. if (mListFragment == null) { mListFragment = new DcmListFragment(); } if (mInfoFragment == null) { mInfoFragment = new DcmInfoFragment(); } // Specify that the Home/Up button should not be enabled, // since there is no hierarchical parent yet. ActionBar actionBar = getActionBar(); // enable ActionBar app icon to behave as action to toggle nav drawer actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setHomeButtonEnabled(false); // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first fragment if (findViewById(R.id.fragment_container) != null) { Log.i("cpb", "mListFrag: One-pane"); mFragmented = true; // Add the fragment to the 'fragment_container' FrameLayout fragManager.beginTransaction().add(R.id.fragment_container, mListFragment).commit(); generateDrawer(); } else { Log.i("cpb", "mListFrag: Two-pane"); mFragmented = false; // Add the fragments to the respective FrameLayouts fragManager.beginTransaction().add(R.id.fragment_left, mListFragment).commit(); fragManager.beginTransaction().add(R.id.fragment_right, mInfoFragment).commit(); } }
From source file:it.durip_app.GraphActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_graph); data = new DataSource(); // Get the message from the intent Intent intent = getIntent();//from w w w. j a v a2s. c o m String paramUrl = intent.getStringExtra(MainActivity.PARAM_URL); int paramT = intent.getIntExtra(MainActivity.PARAM_T, 200); int paramI = intent.getIntExtra(MainActivity.PARAM_I, 5); int paramPort = intent.getIntExtra(MainActivity.PARAM_PORT, 4000); int paramVerbose = intent.getIntExtra(MainActivity.PARAM_VERBOSE, 1); data.setUrl(paramUrl); data.setT(paramT); data.setI(paramI); data.setPort(paramPort); data.setVerbose(paramVerbose); // kick off the data generating thread: mySource = new Thread(data); mySource.start(); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // 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); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); 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.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } // Show the Up button in the action bar. }
From source file:com.techsoc.cultureconnect.navigation.NavigationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.nav_main_activity); mTitle = mDrawerTitle = "";//getTitle(); mOptions = getResources().getStringArray(R.array.options); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerListLeft = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerListLeft.setAdapter(new ArrayAdapter<String>(this, R.layout.nav_drawer_list_item, mOptions)); mDrawerListLeft.setOnItemClickListener(new DrawerItemClickListener()); ActionBar actionBar = getActionBar(); actionBar.setIcon(R.drawable.culture_connect_white); actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.CultureConnect))); actionBar.setTitle(null);// w w w. ja v a2s . co m // enable ActionBar app icon to behave as action to toggle nav drawer actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggleLeft = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggleLeft); if (savedInstanceState == null) { selectItem(0); } }
From source file:it.durip_app.TCPActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_graph); data = new TCPSource(); // Get the message from the intent isIperfRunning = isIperfRunning();/* w ww .j a va 2s . c o m*/ Intent intent = getIntent(); paramUrl = intent.getStringExtra(MainActivity.PARAM_URL); paramT = intent.getIntExtra(MainActivity.PARAM_T, 200); paramI = intent.getIntExtra(MainActivity.PARAM_I, 5); paramPort = intent.getIntExtra(MainActivity.PARAM_PORT, 4000); paramSleep = intent.getIntExtra(MainActivity.PARAM_SLEEP, 500); paramVerbose = intent.getIntExtra(MainActivity.PARAM_VERBOSE, 1); // frequency = paramPort/1000; data.setUrl(paramUrl); data.setT(paramT); data.setI(paramI); data.setPort(paramPort); data.setSleep(paramSleep); data.setVerbose(paramVerbose); data.startTCP(); // kick off the data generating thread: /* mySource = new Thread(data); mySource.start(); */ // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // 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); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); 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.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } // Show the Up button in the action bar. }
From source file:com.idevity.card.read.ReadMain.java
/** * Method onCreate.//from ww w . j a v a 2 s . c o m * * @param savedInstanceState * Bundle */ @TargetApi(19) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_main); /* * We will take over the NFC Interface while in the foreground so there * is no additional read attempt. * * If on KitKat, we will set a filter and ignore any callbacks. */ /****************** Initialize NFC ******************/ if (debug) { Log.d(TAG, "Getting Adaptor..."); } NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); /* * Platform version specific handling: KitKat */ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { if (debug) { Log.d(TAG, "Setting Adaptor up for KitKat"); } ReaderCallback listener = new ReaderCallback() { public void onTagDiscovered(Tag tag) { /* * Discard the tags here */ tag = null; } }; int flags = NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS; adapter.enableReaderMode(this, listener, flags, null); } // Get preferences / settings that have been saved // get the show log this.sharedPref = PreferenceManager.getDefaultSharedPreferences(this); boolean showLog = this.sharedPref.getBoolean(g.getShowLog(), false); // Create the adapter that will return a fragment for each of the three // primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager(), this.sharedPref); // 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(true); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener // for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select // the corresponding tab. // We can also use ActionBar.Tab#select() to do this if // we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); /* * Use the following to determine content to show in the tabs. First, * check to see if there is an active intent Also, check to see if there * is an active saved instance state If, active intent - use active * intent; if active intent = null, and saved instance state !null, use * saved instance state; else return user to "main" instructions */ boolean hasIntent = false; boolean hasSavedData = false; try { if (getIntent().getExtras().getByteArray(g.getCardData()) != null) { hasIntent = true; } } catch (Throwable e) { Log.e(TAG, "Error: intent " + e.getMessage()); } try { if (g.getCard() != null) { hasSavedData = true; } } catch (Throwable e) { Log.e(TAG, "Error: saved instance state " + e.getMessage()); } // if intent, populate the variables with the intent values // else if saved instance, populate the same variables with the saved // instance state // else return user to read800-73 activity to read a new card if (hasIntent) { logStringBuffer = getIntent().getExtras().getString(g.getReaderLog()); byte[] _data = getIntent().getExtras().getByteArray(g.getCardData()); this.carddata = new CardData80073(_data); if (debug) { Log.d(TAG, "Using new card data"); } g.putCard(carddata.toByteArray()); g.putLogData(logStringBuffer); } else if (hasSavedData) { logStringBuffer = g.getLogData(); byte[] _data = g.getCard(); this.carddata = new CardData80073(_data); Log.e(TAG, "Using saved card data"); } else { Intent returnuser = new Intent(this, Read80073.class); startActivity(returnuser); Log.e(TAG, "No card data found; returning user to read a new card."); } /* * For each of the sections in the app, add a tab to the action bar. */ Tab tabA = actionBar.newTab(); tabA.setText(getString(R.string.TabRead_Title)); tabA.setTabListener(this); actionBar.addTab(tabA); // this one will become the CAK tab Tab tabB = actionBar.newTab(); tabB.setText(getString(R.string.TabCert_Title)); tabB.setTabListener(this); actionBar.addTab(tabB); // this one will become the CHUID tab Tab tabC = actionBar.newTab(); tabC.setText(getString(R.string.TabChuid_Title)); tabC.setTabListener(this); actionBar.addTab(tabC); // this one will become the APDU log tab // only set up the tab is the preferences for Show Log = True if (showLog) { Tab tabD = actionBar.newTab(); tabD.setText(getString(R.string.TabLog_Title)); tabD.setTabListener(this); actionBar.addTab(tabD); } }