List of usage examples for android.app ActionBar setDisplayHomeAsUpEnabled
public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
From source file:com.codebutler.farebot.activity.CardInfoActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card_info); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); mTabsAdapter = new TabPagerAdapter(this, viewPager); final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(R.string.loading); new AsyncTask<Void, Void, Void>() { private Exception mException; public boolean mSpeakBalanceEnabled; @Override/*from ww w . j a v a2s. c om*/ protected Void doInBackground(Void... voids) { try { Uri uri = getIntent().getData(); Cursor cursor = getContentResolver().query(uri, null, null, null, null); startManagingCursor(cursor); cursor.moveToFirst(); String data = cursor.getString(cursor.getColumnIndex(CardsTableColumns.DATA)); mCard = Card.fromXml(FareBotApplication.getInstance().getSerializer(), data); mTransitData = mCard.parseTransitData(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CardInfoActivity.this); mSpeakBalanceEnabled = prefs.getBoolean("pref_key_speak_balance", false); } catch (Exception ex) { mException = ex; } return null; } @Override protected void onPostExecute(Void aVoid) { findViewById(R.id.loading).setVisibility(View.GONE); findViewById(R.id.pager).setVisibility(View.VISIBLE); if (mException != null) { if (mCard == null) { Utils.showErrorAndFinish(CardInfoActivity.this, mException); } else { Log.e("CardInfoActivity", "Error parsing transit data", mException); showAdvancedInfo(mException); finish(); } return; } if (mTransitData == null) { showAdvancedInfo(new UnsupportedCardException()); finish(); return; } String titleSerial = (mTransitData.getSerialNumber() != null) ? mTransitData.getSerialNumber() : Utils.getHexString(mCard.getTagId(), ""); actionBar.setTitle(mTransitData.getCardName() + " " + titleSerial); Bundle args = new Bundle(); args.putString(AdvancedCardInfoActivity.EXTRA_CARD, mCard.toXml(FareBotApplication.getInstance().getSerializer())); args.putParcelable(EXTRA_TRANSIT_DATA, mTransitData); if (mTransitData instanceof UnauthorizedClassicTransitData) { mTabsAdapter.addTab(actionBar.newTab(), UnauthorizedCardFragment.class, args); return; } if (mTransitData.getBalanceString() != null) { mTabsAdapter.addTab(actionBar.newTab().setText(R.string.balance), CardBalanceFragment.class, args); } if (mTransitData.getTrips() != null || mTransitData.getRefills() != null) { mTabsAdapter.addTab(actionBar.newTab().setText(R.string.history), CardTripsFragment.class, args); } if (mTransitData.getSubscriptions() != null) { mTabsAdapter.addTab(actionBar.newTab().setText(R.string.subscriptions), CardSubscriptionsFragment.class, args); } if (mTransitData.getInfo() != null) { mTabsAdapter.addTab(actionBar.newTab().setText(R.string.info), CardInfoFragment.class, args); } if (mTabsAdapter.getCount() > 1) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } if (mTransitData.hasUnknownStations()) { findViewById(R.id.need_stations).setVisibility(View.VISIBLE); } boolean speakBalanceRequested = getIntent().getBooleanExtra(SPEAK_BALANCE_EXTRA, false); if (mSpeakBalanceEnabled && speakBalanceRequested) { mTTS = new TextToSpeech(CardInfoActivity.this, mTTSInitListener); } if (savedInstanceState != null) { viewPager.setCurrentItem(savedInstanceState.getInt(KEY_SELECTED_TAB, 0)); } } }.execute(); }
From source file:com.android.fastinfusion.ui.fragment.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 w ww . j av a 2 s .co m*/ 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, Gravity.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 */) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @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(); } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // 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:com.dhl.android.bitmapfun.ui.ImageDetailActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.image_detail_pager); // Fetch screen height and width, to use as our max size when loading images as this // activity runs full screen final DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); final int height = displaymetrics.heightPixels; final int width = displaymetrics.widthPixels; final int longest = height > width ? height : width; // The ImageWorker takes care of loading images into our ImageView children asynchronously mImageWorker = new ImageFetcher(this, longest); mImageWorker.setAdapter(Images.imageWorkerUrlsAdapter); mImageWorker.setImageCache(ImageCache.findOrCreateCache(this, IMAGE_CACHE_DIR)); mImageWorker.setImageFadeIn(false);/*from w w w. jav a 2s .c om*/ // Set up ViewPager and backing adapter mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), mImageWorker.getAdapter().getSize()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter); mPager.setPageMargin((int) getResources().getDimension(R.dimen.image_detail_pager_margin)); // Set up activity to go full screen getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN); // Enable some additional newer visibility and ActionBar features to create a more immersive // photo viewing experience if (Utils.hasActionBar()) { final ActionBar actionBar = getActionBar(); // Enable "up" navigation on ActionBar icon and hide title text actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); // Start low profile mode and hide ActionBar mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); actionBar.hide(); // Hide and show the ActionBar as the visibility changes mPager.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int vis) { if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) { actionBar.hide(); } else { actionBar.show(); } } }); } // Set the current item based on the extra passed in to this activity final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1); if (extraCurrentItem != -1) { mPager.setCurrentItem(extraCurrentItem); } }
From source file:app.philm.in.BasePhilmActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Crashlytics.start(this); // Request Progress Bar in Action Bar requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(getContentViewLayoutId()); mCardContainer = findViewById(R.id.card_container); mInsetFrameLayout = (InsetFrameLayout) findViewById(R.id.fl_insets); if (mInsetFrameLayout != null) { mInsetFrameLayout.setOnInsetsCallback(this); }/*from w w w. j a v a2s .c om*/ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); if (mDrawerLayout != null) { mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open_content_desc, R.string.drawer_closed_content_desc); mDrawerLayout.setDrawerListener(mDrawerToggle); final ActionBar ab = getActionBar(); if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); ab.setHomeButtonEnabled(true); } } // Let SuperCardToast restore itself SuperCardToast.onRestoreState(savedInstanceState, this); mMainController = PhilmApplication.from(this).getMainController(); mDisplay = new AndroidDisplay(this, mDrawerToggle, mDrawerLayout, mInsetFrameLayout); handleIntent(getIntent(), getDisplay()); }
From source file:co.touchlab.thumbcache.ui.ImageDetailActivity.java
@SuppressLint("NewApi") @Override/*from www . ja v a2s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.image_detail_pager); // Fetch screen height and width, to use as our max size when loading images as this // activity runs full screen final DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); final int height = displaymetrics.heightPixels; final int width = displaymetrics.widthPixels; final int longest = height > width ? height : width; // The ImageWorker takes care of loading images into our ImageView children asynchronously mImageWorker = new ImageFetcher(this, longest); mImageWorker.setAdapter(Images.imageWorkerUrlsAdapter); mImageWorker.setImageCache(ImageCache.findOrCreateCache(this, IMAGE_CACHE_DIR)); mImageWorker.setImageFadeIn(false); // Set up ViewPager and backing adapter mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), mImageWorker.getAdapter().getSize()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter); mPager.setPageMargin((int) getResources().getDimension(R.dimen.image_detail_pager_margin)); // Set up activity to go full screen getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN); // Enable some additional newer visibility and ActionBar features to create a more immersive // photo viewing experience if (Utils.hasActionBar()) { final ActionBar actionBar = getActionBar(); // Enable "up" navigation on ActionBar icon and hide title text actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); // Start low profile mode and hide ActionBar mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); actionBar.hide(); // Hide and show the ActionBar as the visibility changes mPager.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int vis) { if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) { actionBar.hide(); } else { actionBar.show(); } } }); } // Set the current item based on the extra passed in to this activity final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1); if (extraCurrentItem != -1) { mPager.setCurrentItem(extraCurrentItem); } }
From source file:com.mbpro.tweebook.facebook.images.FacebookImageDetailActivity.java
@SuppressLint("NewApi") @Override//from w ww . jav a2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.facebook_album_image_detail_pager); // Fetch screen height and width, to use as our max size when loading images as this // activity runs full screen final DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); final int height = displaymetrics.heightPixels; final int width = displaymetrics.widthPixels; final int longest = height > width ? height : width; // The ImageWorker takes care of loading images into our ImageView children asynchronously mImageWorker = new ImageFetcher(this, longest); mImageWorker.setAdapter(FaceBookAlbumImages.imageWorkerUrlsAdapter); mImageWorker.setImageCache(ImageCache.findOrCreateCache(this, IMAGE_CACHE_DIR)); mImageWorker.setImageFadeIn(false); // Set up ViewPager and backing adapter mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), mImageWorker.getAdapter().getSize()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter); mPager.setPageMargin((int) getResources().getDimension(R.dimen.image_detail_pager_margin)); // Set up activity to go full screen getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN); // Enable some additional newer visibility and ActionBar features to create a more immersive // photo viewing experience if (Utils.hasActionBar()) { final ActionBar actionBar = getActionBar(); // Enable "up" navigation on ActionBar icon and hide title text actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); // Start low profile mode and hide ActionBar mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); actionBar.hide(); // Hide and show the ActionBar as the visibility changes mPager.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int vis) { if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) { actionBar.hide(); } else { actionBar.show(); } } }); } // Set the current item based on the extra passed in to this activity final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1); if (extraCurrentItem != -1) { mPager.setCurrentItem(extraCurrentItem); } }
From source file:com.google.cloud.genomics.android.fragments.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 w w w . j av a2 s.co m 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.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */ ) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @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(); } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // 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:org.site_monitor.activity.PrefSettingsActivity.java
/** * Set up the {@link android.app.ActionBar} *///from w w w . j a v a 2 s.c om private void setupActionBar() { // Show the Up button in the action bar. ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } }
From source file:com.geotrackin.gpslogger.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 w w w . ja v a2s. c om*/ public void setUp(int fragmentId, DrawerLayout drawerLayout) { fragmentContainerView = getActivity().findViewById(fragmentId); this.drawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens this.drawerLayout.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. actionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */ NavigationDrawerFragment.this.drawerLayout, /* 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 */ ) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!userHasSeenDrawer && !fromSavedInstanceState) { this.drawerLayout.openDrawer(fragmentContainerView); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_SEEN_DRAWER, true).apply(); } // Defer code dependent on restoration of previous instance state. this.drawerLayout.post(new Runnable() { @Override public void run() { actionBarDrawerToggle.syncState(); } }); this.drawerLayout.setDrawerListener(actionBarDrawerToggle); }
From source file:de.anderdonau.spacetrader.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. *///ww w.j a v a 2s. c o m public void setUp(int fragmentId, DrawerLayout drawerLayout) { //noinspection ConstantConditions 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 */) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @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(); } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }