List of usage examples for android.app ActionBar setDisplayHomeAsUpEnabled
public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
From source file:com.metaphyze.hackernewsfrontpage.HackerNewsFrontPageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hacker_news_front_page); bookFileName = getFilesDir() + File.separator + "bookmarked_posts.js"; drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.drawer); location = (TextView) findViewById(R.id.location); webView = (WebView) findViewById(R.id.content_frame); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setAppCacheEnabled(true); loadingView = findViewById(R.id.loading); ProgressBar progressBar = ((ProgressBar) findViewById(R.id.progress_bar)); progressBar.setIndeterminate(true);//from w w w. j av a2 s . c o m drawerList.setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this, R.layout.post_item, new ArrayList<HackerNewsPost>(), true)); getActionBar().setTitle("Hacker News Front Page (Loading Live Stream...)"); drawerList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { HackerNewsPost post = (HackerNewsPost) parent.getItemAtPosition(position); webView.loadUrl(post.getUrl()); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); loadingView.setVisibility(View.VISIBLE); location.setText("LOADING......" + url); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); loadingView.setVisibility(View.INVISIBLE); location.setText(url); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { loadingView.setVisibility(View.INVISIBLE); location.setText("ERROR LOADING PAGE"); view.loadUrl("file:///android_asset/failed_to_load_page.html"); } }); drawerLayout.closeDrawer(drawerList); } }); drawerList.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final HackerNewsPost clonedPost = ((HackerNewsPost) parent.getItemAtPosition(position)).clone(); clonedPost.setPostedAgo(new Date().toString()); AlertDialog.Builder builder = new AlertDialog.Builder(HackerNewsFrontPageActivity.this); if (((HackerNewsAdapter) parent.getAdapter()).isLive()) { builder.setTitle("Bookmark?"); builder.setMessage("Do you want to bookmark the post\n" + clonedPost.getTitle()); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { HackerNewsFrontPageContents contents = readContentsFromBookmarksFile(); if (contents == null) { showError("ERROR", "Failed to read bookmark file"); dialog.dismiss(); return; } if (!contents.addPost(clonedPost)) { showError("Already Exists", "Not added becasue bookmark already exists"); dialog.dismiss(); return; } if (!saveContentsToBookmarksFile(contents)) { showError("ERROR", "Failed to save bookmark"); dialog.dismiss(); } } catch (Exception ex) { ex.printStackTrace(); showError("ERROR", "Internal error: " + ex); } } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); } else { builder.setTitle("Delete?"); builder.setMessage("Do you want to delete the bookmarked post:\n" + clonedPost.getTitle()); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { HackerNewsFrontPageContents contents = readContentsFromBookmarksFile(); if (contents == null) { showError("ERROR", "Unable to find or generate bookmarks file"); dialog.dismiss(); return; } if (!contents.removePost(clonedPost)) { showError("Not Removed", "Does not exist? How's that possible?"); dialog.dismiss(); return; } if (saveContentsToBookmarksFile(contents)) { if (contents.getItems().size() > 0) { drawerList .setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this, R.layout.post_item, contents.getItems(), false)); } else { showError("No more bookmarks", "Reverting to live stream"); loadLiveStream(); } } else { showError("ERROR", "Failed to save bookmark deletion"); } dialog.dismiss(); } catch (Exception ex) { ex.printStackTrace(); showError("ERROR", "Internal Error: " + ex); } } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); } builder.setCancelable(true); builder.create().show(); return false; } }); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.drawer_icon, 0, 0); drawerLayout.setDrawerListener(drawerToggle); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); // actionBar.setHomeButtonEnabled(true); requestQueue = Volley.newRequestQueue(this); loadLiveStream(); }
From source file:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final TypedArray styledAttributes = getTheme() .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); mActionBarSize = (int) styledAttributes.getDimension(0, 0); styledAttributes.recycle();//ww w. ja va2 s. c om ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } invalidateOptionsMenu(); if (profileId != 0 && savedInstanceState == null) { getSupportLoaderManager().initLoader(LOAD_PROFILE, null, this); } }
From source file:us.cboyd.android.dicom.DcmBrowser.java
/** Called when the activity is first created. */ @Override//w w w.j a v a2 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:au.com.wallaceit.reddinator.ViewRedditActivity.java
/** * (non-Javadoc)//from w w w.j av a 2 s . c o m * * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) */ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); global = ((GlobalObjects) ViewRedditActivity.this.getApplicationContext()); prefs = PreferenceManager.getDefaultSharedPreferences(ViewRedditActivity.this); global.loadSavedAccn(prefs); // set window flags getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); // request loading bar first getWindow().requestFeature(Window.FEATURE_PROGRESS); // get actionbar and set home button, pad the icon ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } ImageView view = (ImageView) findViewById(android.R.id.home); if (view != null) { view.setPadding(5, 0, 5, 0); } // set content view setContentView(R.layout.viewreddit); // Setup TabHost initialiseTabHost(savedInstanceState); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state } redditItemId = getIntent().getStringExtra(WidgetProvider.ITEM_ID); widgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0); feedposition = getIntent().getIntExtra("itemposition", 0); // Get selected item from feed and user vote preference JSONObject currentFeedItem = global.getFeedObject(prefs, widgetId, feedposition, redditItemId); try { userLikes = currentFeedItem.getString("likes"); } catch (JSONException e) { e.printStackTrace(); } System.out.println("User likes post: " + userLikes); }
From source file:com.android.ex.photo.PhotoViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ActivityManager mgr = (ActivityManager) getApplicationContext() .getSystemService(Activity.ACTIVITY_SERVICE); sMemoryClass = mgr.getMemoryClass(); Intent mIntent = getIntent();/*from w w w. j a va 2 s .c o m*/ int currentItem = -1; if (savedInstanceState != null) { currentItem = savedInstanceState.getInt(STATE_ITEM_KEY, -1); mFullScreen = savedInstanceState.getBoolean(STATE_FULLSCREEN_KEY, false); } // uri of the photos to view; optional if (mIntent.hasExtra(Intents.EXTRA_PHOTOS_URI)) { mPhotosUri = mIntent.getStringExtra(Intents.EXTRA_PHOTOS_URI); } // projection for the query; optional // I.f not set, the default projection is used. // This projection must include the columns from the default projection. if (mIntent.hasExtra(Intents.EXTRA_PROJECTION)) { mProjection = mIntent.getStringArrayExtra(Intents.EXTRA_PROJECTION); } else { mProjection = null; } // Set the current item from the intent if wasn't in the saved instance if (mIntent.hasExtra(Intents.EXTRA_PHOTO_INDEX) && currentItem < 0) { currentItem = mIntent.getIntExtra(Intents.EXTRA_PHOTO_INDEX, -1); } mPhotoIndex = currentItem; setContentView(R.layout.photo_activity_view); // Create the adapter and add the view pager mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null); mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager); mViewPager.setAdapter(mAdapter); mViewPager.setOnPageChangeListener(this); mViewPager.setOnInterceptTouchListener(this); // Kick off the loader getLoaderManager().initLoader(LOADER_PHOTO_LIST, null, this); final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); mActionBarHideDelayTime = getResources().getInteger(R.integer.action_bar_delay_time_in_millis); actionBar.addOnMenuVisibilityListener(this); actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); }
From source file:org.leopub.mat.controller.PersonalInfoActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_personal_info); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); }/*from w ww. java 2 s. c o m*/ mUserManager = UserManager.getInstance(); mUser = mUserManager.getCurrentUser(); mEditButtonListener = new EditButtonListener(); mHelpButtonListener = new HelpButtonListener(); mPersonalInfoList = new ArrayList<>(); mPersonalInfoArrayAdapter = null; mUnderlingList = mUser.getUnderling(); mChosenPerson = mUser.getContact(mUserManager.getCurrentUser().getUserId()); updateCategoryData(); //updateView(); }
From source file:com.android.mms.ui.MailBoxMessageContent.java
private void initUi() { setProgressBarIndeterminateVisibility(true); mScaleDetector = new ScaleGestureDetector(this, new MyScaleListener()); Cursor cursor = moveCursorToCurrentMsg(mCursor, mMsgId); if (cursor != null) { mPagerAdapter = new MessageDetailAdapter(this, cursor); mPagerAdapter.setScaleTextList(mSlidePaperItemTextViews); mContentPager = (ViewPager) findViewById(R.id.details_view_pager); mContentPager.setAdapter(mPagerAdapter); mContentPager.setCurrentItem(cursor.getPosition()); }/* w w w . jav a 2s .c o m*/ ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); }
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. j av a 2 s.c o 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:com.tweetlanes.android.core.view.TweetSpotlightActivity.java
void onGetStatus(TwitterStatus status) { mStatus = new TwitterStatus(status); updateViewVisibility();/*from w ww .j a va 2s. co m*/ ActionBar actionBar = getActionBar(); actionBar.setDisplayUseLogoEnabled(true); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); invalidateOptionsMenu(); setComposeDefault(); }
From source file:name.gumartinm.weather.information.activity.MainTabsActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.weather_main_tabs); this.mPager = (ViewPager) this.findViewById(R.id.pager); this.mPager.setAdapter(new TabsAdapter(this.getSupportFragmentManager())); this.mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/*from www . ja v a 2 s .c o m*/ public void onPageSelected(final int position) { MainTabsActivity.this.getActionBar().setSelectedNavigationItem(position); } }); final ActionBar actionBar = this.getActionBar(); PreferenceManager.setDefaultValues(this, R.xml.weather_preferences, false); // Specify that tabs should be displayed in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayHomeAsUpEnabled(true); // Create a tab listener that is called when the user changes tabs. final ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(final Tab tab, final FragmentTransaction ft) { MainTabsActivity.this.mPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(final Tab tab, final FragmentTransaction ft) { } @Override public void onTabReselected(final Tab tab, final FragmentTransaction ft) { } }; actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_currently)) .setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_five_days_forecast)) .setTabListener(tabListener)); }