List of usage examples for android.app ActionBar setHomeButtonEnabled
public void setHomeButtonEnabled(boolean enabled)
From source file:lth.pontus.getResults.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = getApplicationContext();/*from w w w. j a v a2 s. c o m*/ // 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(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayUseLogoEnabled(false); // 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); exercisel = new ExerciseProvider(); DateHelper = new DateProvider(); openDB(); // 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. Tab a = actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageICon(i)); a.setTabListener(this); actionBar.addTab(a); } }
From source file:com.mediatek.galleryfeature.stereo.segment.background.StereoBackgroundActivity.java
private void setActionBarDisplayOptions(ActionBar actionBar, boolean displayHomeAsUp, boolean showTitle) { if (actionBar == null) { return;// ww w . j av a 2 s.c o m } int options = 0; if (displayHomeAsUp) { options |= ActionBar.DISPLAY_HOME_AS_UP; } if (showTitle) { options |= ActionBar.DISPLAY_SHOW_TITLE; } actionBar.setDisplayOptions(options, ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setHomeButtonEnabled(displayHomeAsUp); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setTitle(R.string.m_save); }
From source file:com.frostwire.android.gui.activities.MainActivity.java
private void setupActionBar() { ActionBar bar = getActionBar(); if (bar != null) { bar.setCustomView(R.layout.view_custom_actionbar); bar.setDisplayShowCustomEnabled(true); bar.setDisplayHomeAsUpEnabled(true); bar.setHomeButtonEnabled(true); }/* w ww . j a va2s . c om*/ }
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();//from w ww.j a v a 2s. co 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:org.nypl.simplified.app.MainSettingsAccountActivity.java
@Override protected void onCreate(final @Nullable Bundle state) { super.onCreate(state); final Bundle extras = getIntent().getExtras(); if (extras != null) { this.account = new AccountsRegistry(this).getAccount(extras.getInt("selected_account")); } else {/* w w w . j a v a2s . co m*/ this.account = Simplified.getCurrentAccount(); } final ActionBar bar = this.getActionBar(); if (android.os.Build.VERSION.SDK_INT < 21) { bar.setDisplayHomeAsUpEnabled(false); bar.setHomeButtonEnabled(true); bar.setIcon(R.drawable.ic_arrow_back); } else { bar.setHomeAsUpIndicator(R.drawable.ic_arrow_back); bar.setDisplayHomeAsUpEnabled(true); bar.setHomeButtonEnabled(false); } final DocumentStoreType docs = Simplified.getDocumentStore(this.account, getResources()); final LayoutInflater inflater = NullCheck.notNull(this.getLayoutInflater()); final FrameLayout content_area = this.getContentFrame(); final ViewGroup layout = NullCheck .notNull((ViewGroup) inflater.inflate(R.layout.settings_account, content_area, false)); content_area.addView(layout); content_area.requestLayout(); final TextView in_barcode_label = NullCheck.notNull(this.findViewById(R.id.settings_barcode_label)); final TextView in_barcode_text = NullCheck.notNull(this.findViewById(R.id.settings_barcode_text)); final TextView in_pin_label = NullCheck.notNull(this.findViewById(R.id.settings_pin_label)); final ImageView in_barcode_image = NullCheck.notNull(this.findViewById(R.id.settings_barcode_image)); final TextView in_barcode_image_toggle = NullCheck .notNull(this.findViewById(R.id.settings_barcode_toggle_barcode)); final TextView in_pin_text = NullCheck.notNull(this.findViewById(R.id.settings_pin_text)); final CheckBox in_pin_reveal = NullCheck.notNull(this.findViewById(R.id.settings_reveal_password)); if (!this.account.pinRequired()) { in_pin_label.setVisibility(View.INVISIBLE); in_pin_text.setVisibility(View.INVISIBLE); in_pin_reveal.setVisibility(View.INVISIBLE); } final Button in_login = NullCheck.notNull(this.findViewById(R.id.settings_login)); final Button in_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup)); this.sync_switch = findViewById(R.id.sync_switch); this.sync_table_row = findViewById(R.id.sync_table_row); this.sync_table_row.setVisibility(View.GONE); this.advanced_table_row = findViewById(R.id.link_advanced); this.advanced_table_row.setVisibility(View.GONE); this.advanced_table_row.setOnClickListener(view -> { final FragmentManager mgr = getFragmentManager(); final FragmentTransaction transaction = mgr.beginTransaction(); final SettingsAccountAdvancedFragment fragment = new SettingsAccountAdvancedFragment(); transaction.add(R.id.settings_account_container, fragment).addToBackStack("advanced").commit(); }); final TableRow in_privacy = findViewById(R.id.link_privacy); final TableRow in_license = findViewById(R.id.link_license); final TextView account_name = NullCheck.notNull(this.findViewById(android.R.id.text1)); final TextView account_subtitle = NullCheck.notNull(this.findViewById(android.R.id.text2)); final ImageView in_account_icon = NullCheck.notNull(this.findViewById(R.id.account_icon)); in_pin_text.setTransformationMethod(PasswordTransformationMethod.getInstance()); if (android.os.Build.VERSION.SDK_INT >= 21) { this.handle_pin_reveal(in_pin_text, in_pin_reveal); } else { in_pin_reveal.setVisibility(View.GONE); } final TableRow in_report_issue = findViewById(R.id.report_issue); if (this.account.getSupportEmail() == null) { in_report_issue.setVisibility(View.GONE); } else { in_report_issue.setVisibility(View.VISIBLE); in_report_issue.setOnClickListener(view -> { final Intent intent = new Intent(this, ReportIssueActivity.class); final Bundle b = new Bundle(); b.putInt("selected_account", this.account.getId()); intent.putExtras(b); startActivity(intent); }); } final TableRow in_support_center = findViewById(R.id.support_center); if (this.account.supportsHelpCenter()) { in_support_center.setVisibility(View.VISIBLE); in_support_center.setOnClickListener(view -> { final HSHelpStack stack = HSHelpStack.getInstance(this); final HSDeskGear gear = new HSDeskGear("https://nypl.desk.com/", "4GBRmMv8ZKG8fGehhA", null); stack.setGear(gear); stack.showHelp(this); }); } else { in_support_center.setVisibility(View.GONE); } //Get labels from the current authentication document. final AuthenticationDocumentType auth_doc = docs.getAuthenticationDocument(); in_barcode_label.setText(auth_doc.getLabelLoginUserID()); in_pin_label.setText(auth_doc.getLabelLoginPassword()); final TableLayout in_table_with_code = NullCheck .notNull(this.findViewById(R.id.settings_login_table_with_code)); in_table_with_code.setVisibility(View.GONE); final TableLayout in_table_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup_table)); // boolean locationpermission = false; // if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { // locationpermission = true; // } // else // { // ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1); // } if (this.account.supportsCardCreator() || this.account.getCardCreatorUrl() != null) { in_table_signup.setVisibility(View.VISIBLE); } else { in_table_signup.setVisibility(View.GONE); } in_login.setOnClickListener(v -> this.onLoginWithBarcode()); final CheckBox in_age13_checkbox = NullCheck.notNull(this.findViewById(R.id.age13_checkbox)); if (Simplified.getSharedPrefs().contains("age13")) { in_age13_checkbox.setChecked(Simplified.getSharedPrefs().getBoolean("age13")); } else if (account.getId() == 2) { showAgeGateOptionsDialog(in_age13_checkbox); } in_age13_checkbox.setOnCheckedChangeListener(this::showAgeChangeConfirmation); if (this.account.needsAuth()) { in_login.setVisibility(View.VISIBLE); in_age13_checkbox.setVisibility(View.GONE); } else { in_login.setVisibility(View.GONE); in_age13_checkbox.setVisibility(View.VISIBLE); } if (this.account.supportsCardCreator()) { in_signup.setOnClickListener(v -> { final Intent cardcreator = new Intent(this, CardCreatorActivity.class); startActivity(cardcreator); }); in_signup.setText(R.string.need_card_button); } else if (this.account.getCardCreatorUrl() != null) { in_signup.setOnClickListener(v -> { final Intent e_card = new Intent(Intent.ACTION_VIEW); e_card.setData(Uri.parse(this.account.getCardCreatorUrl())); startActivity(e_card); }); in_signup.setText(R.string.need_card_button); } final boolean permission = Simplified.getSharedPrefs().getBoolean("syncPermissionGranted", this.account.getId()); this.sync_switch.setChecked(permission); /* If switching on, disable user interaction until server has responded. If switching off, disable applicable network requests by updating shared prefs flags. */ this.sync_switch.setOnCheckedChangeListener((buttonView, isChecked) -> { if (isChecked) { buttonView.setEnabled(false); annotationsManager.updateServerSyncPermissionStatus(true, (success) -> { if (success) { Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), true); this.sync_switch.setChecked(true); } else { Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), false); this.sync_switch.setChecked(false); } this.sync_switch.setEnabled(true); return kotlin.Unit.INSTANCE; }); } else { Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), false); this.sync_switch.setChecked(false); } }); if (this.account.getPrivacyPolicy() != null) { in_privacy.setVisibility(View.VISIBLE); } else { in_privacy.setVisibility(View.GONE); } if (this.account.getContentLicense() != null) { in_license.setVisibility(View.VISIBLE); } else { in_license.setVisibility(View.GONE); } in_license.setOnClickListener(view -> { final Intent intent = new Intent(this, WebViewActivity.class); final Bundle b = new Bundle(); WebViewActivity.setActivityArguments(b, this.account.getContentLicense(), "Content Licenses", SimplifiedPart.PART_SETTINGS); intent.putExtras(b); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); }); in_privacy.setOnClickListener(view -> { final Intent intent = new Intent(this, WebViewActivity.class); final Bundle b = new Bundle(); WebViewActivity.setActivityArguments(b, this.account.getPrivacyPolicy(), "Privacy Policy", SimplifiedPart.PART_SETTINGS); intent.putExtras(b); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); }); this.navigationDrawerSetActionBarTitle(); this.account_name_text = account_name; this.account_subtitle_text = account_subtitle; this.account_icon = in_account_icon; this.barcode_text = in_barcode_text; this.pin_text = in_pin_text; this.barcode_image_toggle = in_barcode_image_toggle; this.barcode_image = in_barcode_image; this.login = in_login; this.table_with_code = in_table_with_code; this.table_signup = in_table_signup; final CheckBox in_eula_checkbox = NullCheck.notNull(this.findViewById(R.id.eula_checkbox)); final OptionType<EULAType> eula_opt = docs.getEULA(); if (eula_opt.isSome()) { final Some<EULAType> some_eula = (Some<EULAType>) eula_opt; final EULAType eula = some_eula.get(); in_eula_checkbox.setChecked(eula.eulaHasAgreed()); in_eula_checkbox.setEnabled(true); in_eula_checkbox.setOnCheckedChangeListener((button, checked) -> eula.eulaSetHasAgreed(checked)); if (eula.eulaHasAgreed()) { LOG.debug("EULA: agreed"); } else { LOG.debug("EULA: not agreed"); } } else { LOG.debug("EULA: unavailable"); } this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); }
From source file:org.floens.chan.ui.activity.BoardActivity.java
private void updateActionBarStateCallback() { final ActionBar actionBar = getActionBar(); if (threadPane.isSlideable()) { if (threadPane.isOpen()) { int index = getBoardIndexNavigator(boardLoadable.board); if (index >= 0) { // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); setActionBarListMode();//from ww w . j a va 2 s.c o m actionBar.setTitle(""); } else { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); String niceTitle = ChanApplication.getBoardManager().getBoardKey(boardLoadable.board); if (niceTitle == null) { actionBar.setTitle("/" + boardLoadable.board + "/"); } else { actionBar.setTitle(niceTitle); } } actionBar.setHomeButtonEnabled(true); pinDrawerListener.setDrawerIndicatorEnabled(true); if (boardLoadable.isBoardMode()) setShareUrl(ChanUrls.getBoardUrlDesktop(boardLoadable.board)); } else { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setTitle(threadLoadable.title); pinDrawerListener.setDrawerIndicatorEnabled(false); if (threadLoadable.isThreadMode()) setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no)); } actionBar.setDisplayHomeAsUpEnabled(true); } else { setActionBarListMode(); // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); pinDrawerListener.setDrawerIndicatorEnabled(true); actionBar.setTitle(threadLoadable.title); actionBar.setDisplayHomeAsUpEnabled(true); if (threadLoadable.isThreadMode()) setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no)); } actionBar.setDisplayShowTitleEnabled(true); invalidateOptionsMenu(); }
From source file:se.dxapps.generic.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ActionBar actionBar = getActionBar(); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); mTitle = mDrawerTitle = getTitle();/*from www . j a va2s . co m*/ mPlanetTitles = getResources().getStringArray(R.array.planets_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (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 mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // 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 mDrawerToggle = 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(mDrawerToggle); // if (savedInstanceState == null) { // selectItem(0); // } //ViewPager stuff. // 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)); } }
From source file:com.fitme.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Init db scheme DbHelper dbh = new DbHelper(this); dbh.createDataBase();// w w w . j a v a2s . c o m ActiveProgramDAO apd = new ActiveProgramDAO(this); activeProgram = apd.getActiveProgramName(); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(this); // Refresh trainings section data TrainingsSectionFragment tsf = (TrainingsSectionFragment) mAppSectionsPagerAdapter .getItem(AppSectionsPagerAdapter.SECTION_TRAININGS); tsf.onNewProgramSelected(); // Set up the action bar. final ActionBar actionBar = getActionBar(); // 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); } }); 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); // 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)); } actionBar.getTabAt(WorkoutsSectionFragment.WORKOUTS_SECTION_ID).setIcon(R.drawable.ic_section_workouts); actionBar.getTabAt(TrainingsSectionFragment.TRAININGS_SECTION_ID) .setIcon(R.drawable.ic_section_trainings); actionBar.getTabAt(DummySectionFragment.DUMMY_SECTION_ID).setIcon(R.drawable.ic_section_charts); // Additional fake tab for the future development actionBar.getTabAt(DummySectionFragment.DUMMY_SECTION_ID + 1).setIcon(R.drawable.ic_section_photo); } }
From source file:me.albertonicoletti.latex.activities.EditorActivity.java
/** * Initializes the navigation drawer./* w w w . ja v a 2 s.c o m*/ */ private void initDrawer() { mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); /* Recycler View containing the open documents */ RecyclerView mDrawerList = (RecyclerView) findViewById(R.id.left_drawer); mDrawerList.setHasFixedSize(true); // Sets the layout manager /* Recycler View layout manager */ RecyclerView.LayoutManager documentsLayoutManager = new LinearLayoutManager(this); mDrawerList.setLayoutManager(documentsLayoutManager); documentsAdapter = new DocumentsAdapter(documentsToFiles(), new DocumentClickListener(this), DocumentsAdapter.DRAWER); mDrawerList.setAdapter(documentsAdapter); mDrawerLayout.openDrawer(GravityCompat.START); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ 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); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setTitle(document.getName()); } } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setTitle("Choose File"); } } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
private void handleIntent() { if (!m_app.isAuthenticated()) { Log.v(TAG, "handleIntent: not authenticated"); startLogin();/*from w w w.j a va 2s . c o m*/ return; } if (!m_app.initialSyncDone()) { m_sync_dialog = new ProgressDialog(this, m_app.getActiveTheme()); m_sync_dialog.setIndeterminate(true); m_sync_dialog.setMessage("Initial Dropbox sync in progress, please wait...."); m_sync_dialog.setCancelable(false); m_sync_dialog.show(); } else if (m_sync_dialog != null) { m_sync_dialog.cancel(); } mFilter = new ActiveFilter(); m_leftDrawerList = (ListView) findViewById(R.id.left_drawer); m_rightDrawerList = (ListView) findViewById(R.id.right_drawer_list); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Set the list's click listener m_leftDrawerList.setOnItemClickListener(new DrawerItemClickListener()); if (m_drawerLayout != null) { m_drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ m_drawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ R.string.changelist, /* "open drawer" description */ R.string.app_label /* "close drawer" description */ ) { /** * Called when a drawer has settled in a completely closed * state. */ public void onDrawerClosed(View view) { // setTitle(R.string.app_label); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { // setTitle(R.string.changelist); } }; // Set the drawer toggle as the DrawerListener m_drawerLayout.setDrawerListener(m_drawerToggle); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } m_drawerToggle.syncState(); } // Show search or filter results Intent intent = getIntent(); if (Constants.INTENT_START_FILTER.equals(intent.getAction())) { mFilter.initFromIntent(intent); Log.v(TAG, "handleIntent: launched with filter" + mFilter); Log.v(TAG, "handleIntent: saving filter in prefs"); mFilter.saveInPrefs(TodoApplication.getPrefs()); } else { // Set previous filters and sort Log.v(TAG, "handleIntent: from m_prefs state"); mFilter.initFromPrefs(TodoApplication.getPrefs()); } // Initialize Adapter if (m_adapter == null) { m_adapter = new TaskAdapter(getLayoutInflater()); } m_adapter.setFilteredTasks(); getListView().setAdapter(this.m_adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(new ActionBarListener()); lv.setClickable(true); lv.setOnItemClickListener(this); // If we were started with a selected task, // select it now and clear it from the intent String selectedTask = intent.getStringExtra(Constants.INTENT_SELECTED_TASK); if (!Strings.isEmptyOrNull(selectedTask)) { String[] parts = selectedTask.split(":", 2); setSelectedTask(Integer.valueOf(parts[0]), parts[1]); intent.removeExtra(Constants.INTENT_SELECTED_TASK); setIntent(intent); } else { // Set the adapter for the list view updateDrawers(); } if (m_savedInstanceState != null) { ArrayList<String> selection = m_savedInstanceState.getStringArrayList("selection"); int position = m_savedInstanceState.getInt("position"); if (selection != null) { for (String selected : selection) { String[] parts = selected.split(":", 2); setSelectedTask(Integer.valueOf(parts[0]), parts[1]); } } lv.setSelectionFromTop(position, 0); } }