List of usage examples for android.app ActionBar setNavigationMode
@Deprecated public abstract void setNavigationMode(@NavigationMode int mode);
From source file:com.juick.android.ThreadActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { JuickAdvancedApplication.maybeEnableAcceleration(this); JuickAdvancedApplication.setupTheme(this); //requestWindowFeature(Window.FEATURE_NO_TITLE); //getSherlock().requestFeature(Window.FEATURE_NO_TITLE); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); super.onCreate(savedInstanceState); handler = new Handler(); Intent i = getIntent();// w w w .j a v a 2 s.c o m mid = (MessageID) i.getSerializableExtra("mid"); if (mid == null) { finish(); } messagesSource = (MessagesSource) i.getSerializableExtra("messagesSource"); if (sp.getBoolean("fullScreenThread", false)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } setContentView(R.layout.thread); /* findViewById(R.id.gotoMain).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(ThreadActivity.this, MainActivity.class)); } }); */ final View buttons = findViewById(R.id.buttons); bSend = (ImageButton) findViewById(R.id.buttonSend); bSend.setOnClickListener(this); bAttach = (ImageButton) findViewById(R.id.buttonAttachment); bAttach.setOnClickListener(this); etMessage = (EditText) findViewById(R.id.editMessage); if (sp.getBoolean("helvNueFonts", false)) { etMessage.setTypeface(JuickAdvancedApplication.helvNue); /* TextView oldTitle = (TextView)findViewById(R.id.old_title); oldTitle.setTypeface(JuickAdvancedApplication.helvNue); */ } Button cancel = (Button) findViewById(R.id.buttonCancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { doCancel(); } }); tvReplyTo = (TextView) findViewById(R.id.textReplyTo); replyToContainer = (RelativeLayout) findViewById(R.id.replyToContainer); setHeight(replyToContainer, 0); showThread = (Button) findViewById(R.id.showThread); draftsButton = (Button) findViewById(R.id.drafts); etMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { etMessage.setHint(""); setHeight(buttons, ActionBar.LayoutParams.WRAP_CONTENT); InputMethodManager inputMgr = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); } else { etMessage.setHint(R.string.ClickToReply); setHeight(buttons, 0); } //To change body of implemented methods use File | Settings | File Templates. } }); draftsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { class Item { String label; long ts; int index; Item(String label, long ts, int index) { this.label = label; this.ts = ts; this.index = index; } } final ArrayList<Item> items = new ArrayList<Item>(); final SharedPreferences drafts = getSharedPreferences("drafts", MODE_PRIVATE); for (int q = 0; q < 1000; q++) { String msg = drafts.getString("message" + q, null); if (msg != null) { if (msg.length() > 50) msg = msg.substring(0, 50); items.add(new Item(msg, drafts.getLong("timestamp" + q, 0), q)); } } Collections.sort(items, new Comparator<Item>() { @Override public int compare(Item item, Item item2) { final long l = item2.ts - item.ts; return l == 0 ? 0 : l > 0 ? 1 : -1; } }); CharSequence[] arr = new CharSequence[items.size()]; for (int i1 = 0; i1 < items.size(); i1++) { Item item = items.get(i1); arr[i1] = item.label; } new AlertDialog.Builder(ThreadActivity.this).setItems(arr, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { final Runnable doPull = new Runnable() { @Override public void run() { pullDraft(null, drafts, items.get(which).index); updateDraftsButton(); } }; if (pulledDraft != null && pulledDraft.trim().equals(etMessage.getText().toString().trim())) { // no need to ask, user just looks at the drafts saveDraft(pulledDraftRid, pulledDraftMid, pulledDraftTs, pulledDraft); doPull.run(); } else { if (etMessage.getText().toString().length() > 0) { new AlertDialog.Builder(ThreadActivity.this) .setTitle(getString(R.string.ReplacingText)) .setMessage(getString(R.string.YourTextWillBeReplaced)) .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { doPull.run(); } }) .setNeutralButton( getString(pulledDraft != null ? R.string.SaveChangedDraft : R.string.SaveDraft), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (pulledDraft != null) { saveDraft(pulledDraftRid, pulledDraftMid, System.currentTimeMillis(), etMessage.getText().toString()); } else { saveDraft(rid, mid.toString(), System.currentTimeMillis(), etMessage.getText().toString()); } doPull.run(); } }) .setPositiveButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }) .show(); } else { doPull.run(); } } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).show(); } }); enableDrafts = (sp.getBoolean("enableDrafts", false)); if (sp.getBoolean("capitalizeReplies", false)) { etMessage.setInputType(etMessage.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES); } FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); tf = new ThreadFragment(); tf.init(getLastCustomNonConfigurationInstance(), this); Bundle args = new Bundle(); args.putSerializable("mid", mid); args.putSerializable("messagesSource", messagesSource); args.putSerializable("prefetched", i.getSerializableExtra("prefetched")); args.putSerializable("originalMessage", i.getSerializableExtra("originalMessage")); args.putBoolean("scrollToBottom", i.getBooleanExtra("scrollToBottom", false)); tf.setArguments(args); ft.add(R.id.threadfragment, tf); ft.commit(); MainActivity.restyleChildrenOrWidget(getWindow().getDecorView()); detector = new GestureDetector(this, new GestureDetector.OnGestureListener() { @Override public boolean onDown(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (velocityX > 0 && Math.abs(velocityX) > 4 * Math.abs(velocityY) && Math.abs(velocityX) > 400) { if (etMessage.getText().toString().trim().length() == 0) { System.out.println("velocityX=" + velocityX + " velocityY" + velocityY); if (sp.getBoolean("swipeToClose", true)) { onBackPressed(); } } } return false; } }); com.actionbarsherlock.app.ActionBar actionBar = getSherlock().getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setHomeButtonEnabled(true); actionBar.setLogo(R.drawable.back_button); }
From source file:com.core.vmfiveadnetwork.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(), this); // Set up the action bar. final ActionBar actionBar = getActionBar(); if (actionBar != null) { // 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); }//from ww w. j av a 2 s. co m // 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. if (actionBar != null) 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. if (actionBar != null) actionBar.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } // check permissions for M, if some permission denied, it would shut down activity checkRequiredPermissions(); // need to enable app scan in backend, and prompt this dialog to notice user //ADN.showAppScanDialog(this, "???App?"); }
From source file:com.tweetlanes.android.core.view.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { AccountDescriptor account = getApp().getCurrentAccount(); Bundle extras = getIntent().getExtras(); if (extras != null) { // Notifications String accountKey = extras.getString("account_key"); String notificationType = extras.getString("notification_type"); long notificationPostId = extras.getLong("notification_post_id"); String laneName = extras.getString("lane"); final String urlToLoad = extras.getString("urlToLoad"); if (accountKey != null) { getIntent().removeExtra("account_key"); getIntent().removeExtra("notification_type"); AccountDescriptor notificationAccount = getApp().getAccountByKey(accountKey); Notifier.saveLastNotificationActioned(this, accountKey, notificationType, notificationPostId); Constant.LaneType notificationLaneType = notificationType.equals( SharedPreferencesConstants.NOTIFICATION_TYPE_MENTION) ? Constant.LaneType.USER_MENTIONS : Constant.LaneType.DIRECT_MESSAGES; if (notificationAccount != null) { long notificationAccountId = notificationAccount.getId(); long currentAccountId = account.getId(); if (notificationAccountId == currentAccountId) { int index = account.getCurrentLaneIndex(notificationLaneType); if (index > -1) { mDefaultLaneOverride = index; }// ww w . j a v a 2 s . co m } else { showAccount(notificationAccount, notificationLaneType); } } } else if (laneName != null) { getIntent().removeExtra("lane"); int index = account.getCurrentLaneIndex(Constant.LaneType.valueOf(laneName.trim().toUpperCase())); if (index > -1) { mDefaultLaneOverride = index; } } else if (urlToLoad != null) { getIntent().removeExtra("urlToLoad"); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage(getString(R.string.unknown_intent)); alertDialogBuilder.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(urlToLoad.trim())); startActivity(viewIntent); } }); alertDialogBuilder.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); alertDialogBuilder.create().show(); } } super.onCreate(savedInstanceState); // Attempt at fixing a crash found in HomeActivity if (account == null) { Toast.makeText(getApplicationContext(), "No cached account found, restarting", Constant.DEFAULT_TOAST_DISPLAY_TIME).show(); restartApp(); return; } ActionBar actionBar = getActionBar(); actionBar.setDisplayUseLogoEnabled(true); actionBar.setTitle(null); actionBar.setDisplayShowTitleEnabled(false); mSpinnerAdapter = new AccountAdapter(this, getApp().getAccounts()); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener); actionBar.setSelectedNavigationItem(0); onCreateNavigationListener(); configureListNavigation(); mViewSwitcher = (ViewSwitcher) findViewById(R.id.rootViewSwitcher); updateViewVisibility(); onCreateHandleIntents(); account.setDisplayedLaneDefinitionsDirty(false); Notifier.setNotificationAlarm(this); clearTempFolder(); cacheFollowers(); //Launch change log dialog final WhatsNewDialog whatsNewDialog = new WhatsNewDialog(this); whatsNewDialog.show(); }
From source file:com.google.samples.apps.iosched.ui.SessionLivestreamActivity.java
/** * Load the list of currently live sessions or upcoming live sessions. This * populates the Action Bar (either the title or as list navigation. */// w ww .ja v a 2 s. c o m private void loadSessionsList(Cursor data) { mLivestreamAdapter.swapCursor(data); if (data != null && data.getCount() > 0) { mSessionsFound = true; final ActionBar actionBar = getActionBar(); if (data.getCount() == 1) { // Just one session on, display title in Action Bar if (data.moveToFirst()) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayShowTitleEnabled(true); actionBar.setTitle(data.getString(SessionsQuery.TITLE)); } } else if (data.getCount() > 1) { // 2+ sessions found, set Action Bar to list navigation (spinner) actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(mLivestreamAdapter, this); actionBar.setDisplayShowTitleEnabled(false); getActionBar().setSelectedNavigationItem(locateSelectedItem(data)); } } else if (mSessionsFound) { // Sessions were previously found but no sessions are currently live, // adjust query to see if there are any future sessions at all mSessionsFound = false; final Bundle bundle = new Bundle(); bundle.putBoolean(LOADER_SESSIONS_ARG, true); getLoaderManager().restartLoader(SessionsQuery._TOKEN, bundle, this); } else { // No sessions live right now and no sessions coming up, get out finish(); } }
From source file:org.dmfs.webcal.fragments.PagerFragment.java
/** * Configures the tabs on the action bar. */// ww w .j a v a2 s.c o m private void setupActionBarTabs() { ActionBar actionBar = getActivity().getActionBar(); int tabCount = actionBar.getTabCount(); int pageCount = mAdapter.getCount(); // replace titles and listeners of existing tabs int i = 0; for (; i < tabCount && i < pageCount; ++i) { final Tab tab = actionBar.getTabAt(i); tab.setText(mAdapter.getPageTitle(i)); tab.setTabListener(this); } // add missing tabs for (; i < pageCount; ++i) { actionBar.addTab(actionBar.newTab().setText(mAdapter.getPageTitle(i)).setTabListener(this)); } // remove remaining tabs for (; i < tabCount; --tabCount) { actionBar.removeTabAt(i); } if (pageCount > 1) { int selection = mSelectedTab; // changing the navigation mode might trigger a call to onTabSelected overriding mSelectedTab with a wrong value, so save it actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mSelectedTab = selection; if (selection < pageCount) { mViewPager.setCurrentItem(selection, false); } } else { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } }
From source file:com.inc.playground.playgroundApp.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); globalVariables = ((GlobalVariables) getApplication()); // Set up the action bar. final ActionBar actionBar = getActionBar(); setPlayGroundActionBar();//from www .j a va 2s .co m //set actionBar color actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor))); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. //actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowHomeEnabled(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().setTabListener(this)); } actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view); actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view); //NavigationDrawer handling (e.g the list from leftside): mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); getActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActionBar().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.closeDrawers(); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // all linear layout from slider menu /*Home button */ LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home); ll_Home.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); /*Login button */ LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login); ll_Login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes LinearLayout ll_Login = (LinearLayout) v; TextView loginTxt = (TextView) findViewById(R.id.login_txt); if (loginTxt.getText().equals("Login")) { Intent iv = new Intent(MainActivity.this, Login.class); startActivity(iv); finish(); } else if (loginTxt.getText().equals("Logout")) { final Dialog alertDialog = new Dialog(MainActivity.this); alertDialog.setContentView(R.layout.logout_dilaog); alertDialog.setTitle("Logout"); alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); editor.commit(); ImageView loginImg = (ImageView) findViewById(R.id.login_img); TextView loginTxt = (TextView) findViewById(R.id.login_txt); loginTxt.setText("Login"); loginImg.setImageResource(R.drawable.pg_action_lock_open); globalVariables = ((GlobalVariables) getApplication()); globalVariables.SetCurrentUser(null); globalVariables.SetUserPictureBitMap(null); globalVariables.SetUsersList(null); globalVariables.SetUsersImagesMap(null); Util.clearCookies(getApplicationContext()); Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.show(); //<-- See This! } } }); // // /*Setting button*/ // LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings); // ll_Setting.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // // TODO Auto-generated method stub // // new changes // Intent iv = new Intent(MainActivity.this, // com.inc.playground.playgroundApp.upLeft3StripesButton. // SettingsActivity.class); // startActivity(iv); // finish(); // } // }); /*My profile button*/ LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile); ll_my_profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // new changes globalVariables = ((GlobalVariables) getApplication()); User currentUser = globalVariables.GetCurrentUser(); if ((currentUser == null) || (currentUser != null && currentUser.GetUserId() == null)) { Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show(); } else { Intent iv = new Intent(MainActivity.this, com.inc.playground.playgroundApp.upLeft3StripesButton.MyProfile.class); //for my profile iv.putExtra("name", currentUser.getName()); iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents()); //pass events iv.putExtra("events", currentUser.getEvents()); iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval()); iv.putExtra("events_decline", currentUser.getEvents_decline()); iv.putExtra("photoUrl", currentUser.getPhotoUrl()); startActivity(iv); // } } }); LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about); ll_aboutUs.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, AboutUs.class); startActivity(iv); finish(); } }); }
From source file:com.inc.playground.playground.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); globalVariables = ((GlobalVariables) getApplication()); // Set up the action bar. final ActionBar actionBar = getActionBar(); setPlayGroundActionBar();/*ww w.j a v a2s. c o m*/ //set actionBar color actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor))); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. //actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowHomeEnabled(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().setTabListener(this)); } actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view); actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view); actionBar.getTabAt(2).setIcon(R.drawable.pg_calendar_view); //NavigationDrawer handling (e.g the list from leftside): mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); getActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActionBar().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.closeDrawers(); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // all linear layout from slider menu /*Home button */ LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home); ll_Home.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); /*Login button */ LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login); ll_Login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes LinearLayout ll_Login = (LinearLayout) v; TextView loginTxt = (TextView) findViewById(R.id.login_txt); if (loginTxt.getText().equals("Login")) { Intent iv = new Intent(MainActivity.this, Login.class); startActivity(iv); finish(); } else if (loginTxt.getText().equals("Logout")) { final Dialog alertDialog = new Dialog(MainActivity.this); alertDialog.setContentView(R.layout.logout_dilaog); alertDialog.setTitle("Logout"); alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); editor.commit(); ImageView loginImg = (ImageView) findViewById(R.id.login_img); TextView loginTxt = (TextView) findViewById(R.id.login_txt); loginTxt.setText("Login"); loginImg.setImageResource(R.drawable.pg_action_lock_open); globalVariables = ((GlobalVariables) getApplication()); globalVariables.SetCurrentUser(null); globalVariables.SetUserPictureBitMap(null); globalVariables.SetUsersList(null); globalVariables.SetUsersImagesMap(null); Util.clearCookies(getApplicationContext()); Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.show(); //<-- See This! } } }); /*Setting button*/ LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings); ll_Setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, com.inc.playground.playground.upLeft3StripesButton.SettingsActivity.class); startActivity(iv); finish(); } }); /*My profile button*/ LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile); ll_my_profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // new changes globalVariables = ((GlobalVariables) getApplication()); User currentUser = globalVariables.GetCurrentUser(); if (currentUser == null) { Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show(); } else { Intent iv = new Intent(MainActivity.this, com.inc.playground.playground.upLeft3StripesButton.MyProfile.class); //for my profile iv.putExtra("name", currentUser.getName()); iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents()); //pass events iv.putExtra("events", currentUser.getEvents()); iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval()); iv.putExtra("events_decline", currentUser.getEvents_decline()); iv.putExtra("photoUrl", currentUser.getPhotoUrl()); startActivity(iv); // } } }); LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about); ll_aboutUs.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, AboutUs.class); startActivity(iv); finish(); } }); }
From source file:es.farfuteam.vncpp.controller.ActivityTabs.java
/** * @param savedInstanceState//from ww w . j a v a 2s . c o m * @brief This is the onCreate method * @details The onCreate method adds an actionBar to the activity with two tabs (recent and favorites). * It also load the preferences file into the prefs attribute and sets the rememeberExit attribute. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab_host); final ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME); final String recents = getString(R.string.recents); final String favorites = getString(R.string.favoritesTab); // add tabs Tab tab1 = actionBar.newTab().setText(recents) .setTabListener(new TabListener<ListFragmentTab>(this, "tab1", ListFragmentTab.class)); actionBar.addTab(tab1); Tab tab2 = actionBar.newTab().setText(favorites) .setTabListener(new TabListener<ListFragmentTabFav>(this, "tab2", ListFragmentTabFav.class)); actionBar.addTab(tab2); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //accedemos a fichero preferencias (Configuration.getInstance()).setPrefs(getSharedPreferences("PreferencesFile", Context.MODE_PRIVATE)); (Configuration.getInstance()).readPrefs(); // Orientation Change Occurred if (savedInstanceState != null) { int currentTabIndex = savedInstanceState.getInt("tab_index"); actionBar.setSelectedNavigationItem(currentTabIndex); } //nombre en la activity bar final String title = getString(R.string.connections); setTitle(title); }
From source file:com.nononsenseapps.notepad.MainActivity.java
private void leftOrTabletCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { // currentListId = savedInstanceState.getLong(CURRENT_LIST_ID); listIdToSelect = savedInstanceState.getLong(CURRENT_LIST_ID); // currentListPos = savedInstanceState.getInt(CURRENT_LIST_POS); }//w ww .ja va 2 s. c om // Set up dropdown navigation final ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); // Will set cursor in Loader // mSpinnerAdapter = new ExtrasCursorAdapter(this, // R.layout.actionbar_dropdown_item, null, // new String[] { NotePad.Lists.COLUMN_NAME_TITLE }, // new int[] { android.R.id.text1 }, new int[] { -9, -8 }, // new int[] { R.string.show_from_all_lists, R.string.error_title }); mSpinnerAdapter = new SimpleCursorAdapter(this, R.layout.actionbar_dropdown_item, null, new String[] { NotePad.Lists.COLUMN_NAME_TITLE }, new int[] { android.R.id.text1 }, 0); mSpinnerAdapter.setDropDownViewResource(R.layout.actionbar_dropdown_item); // This will listen for navigation callbacks actionBar.setListNavigationCallbacks(mSpinnerAdapter, this); // setContentView(R.layout.fragment_layout); // setUpList(); mSectionAdapter = new SimpleCursorAdapter(this, R.layout.actionbar_dropdown_item, null, new String[] { NotePad.Lists.COLUMN_NAME_TITLE }, new int[] { android.R.id.text1 }, 0); mSectionsPagerAdapter = new ListPagerAdapter(this, getFragmentManager(), mSectionAdapter); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.leftFragment); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int pos) { currentListId = mSectionsPagerAdapter.getItemId(pos); currentListPos = pos; actionBar.setSelectedNavigationItem(pos); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); // Set up navigation list // Set a default list to open if one is set if (listIdToSelect < 0) { listIdToSelect = getAList(this, -1); // Select the first note in that list to open also noteIdToSelect = getANote(this, listIdToSelect); } // Handle the intent first, so we know what to possibly select once // the // loader is finished beforeBoot = true; if (!resuming) { onNewIntent(getIntent()); } getLoaderManager().initLoader(0, null, this); }
From source file:fm.krui.kruifm.StreamContainer.java
/** * Styles the ActionBar appropriately based on the fragment to be loaded * @param fragmentId Integer identifier of fragment *//*from w ww. j a v a 2 s. c o m*/ private void applyActionBarParameters(int fragmentId) { // Default params ActionBar actionBar = getActionBar(); String title = ""; String subTitle = ""; int navigationMode = ActionBar.NAVIGATION_MODE_STANDARD; // Set params based on opening tab switch (fragmentId) { case STREAM_TAB: //navigationMode = ActionBar.NAVIGATION_MODE_LIST; break; case PLAYLIST_TAB: title = getString(R.string.extended_playlist_title); subTitle = getString(R.string.extended_playlist_subtitle); break; case DJ_TAB: title = getString(R.string.dj_info_tab); break; case FAVORITE_TRACKS_TAB: title = getString(R.string.favorite_tracks_title); subTitle = getString(R.string.favorite_tracks_subtitle); break; case MUSIC_ARTICLES_TAB: title = getString(R.string.music_content_sidebar); break; case NEWS_ARTICLES_TAB: title = getString(R.string.news_content_sidebar); break; case SPORTS_ARTICLES_TAB: title = getString(R.string.sports_content_sidebar); break; } // Apply parameters actionBar.setNavigationMode(navigationMode); actionBar.setTitle(title); actionBar.setSubtitle(subTitle); }