List of usage examples for android.app FragmentTransaction commit
public abstract int commit();
From source file:com.example.search.car.pools.welcome.java
private void selectItem(int position) { setTitle(mPlanetTitles[position]);// www . j a v a2s .c o m // update the main content by replacing fragments Fragment fragment = null; if (mPlanetTitles[position].equals("Cities")) { layout = "Cities"; fragment = new Cities(); frag_tag = "Cities"; // } else if (mPlanetTitles[position].equals("Promote Carpooling")) // { // layout = "Promote Carpooling"; // fragment = new Promote_Carpooling(); // frag_tag = "Promote Carpooling"; // } else if (mPlanetTitles[position].equals("Create Listing")) { // layout = "Create Listing"; // fragment = new Create_Listing(); // frag_id = 3; // frag_tag = "Create Listing"; // } else if (mPlanetTitles[position].equals("About Us")) { // layout = "About Us"; // fragment = new About_Us(); // // } else if (mPlanetTitles[position].equals("Blog")) { // layout = "Blog"; // fragment = new blog(); } else if (mPlanetTitles[position].equals("Dashboard")) { layout = "Dashboard"; fragment = new dashboard(); frag_tag = "Dashboard"; // getActionBar().setTitle("My Profile"); } else { layout = "Search"; frag_tag = "Search"; fragment = new Search(); } FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment, frag_tag); fragmentTransaction.commit(); /* * Bundle args = new Bundle(); * args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); * fragment.setArguments(args); * * FragmentManager fragmentManager = getFragmentManager(); * fragmentManager.beginTransaction().replace(R.id.content_frame, * fragment).commit(); */ // update selected item and title, then close the drawer // mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.android.dialer.DialtactsActivity.java
@Override public void onAttachFragment(Fragment fragment) { if (fragment instanceof DialpadFragment) { mDialpadFragment = (DialpadFragment) fragment; if (!mIsDialpadShown && !mShowDialpadOnResume) { final FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.hide(mDialpadFragment); transaction.commit(); }//from w w w.j a v a2 s . c om } else if (fragment instanceof SmartDialSearchFragment) { mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this); if (!TextUtils.isEmpty(mDialpadQuery)) { mSmartDialSearchFragment.setAddToContactNumber(mDialpadQuery); } } else if (fragment instanceof SearchFragment) { mRegularSearchFragment = (RegularSearchFragment) fragment; mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this); } else if (fragment instanceof ListsFragment) { mListsFragment = (ListsFragment) fragment; mListsFragment.addOnPageChangeListener(this); } }
From source file:com.geecko.QuickLyric.MainActivity.java
public void updateLyricsFragment(int outAnim, String... params) { // Should only be called from SearchFragment or IdDecoder String artist = params[0];/* ww w .java2 s .c o m*/ String song = params[1]; String url = null; if (params.length > 2) url = params[2]; LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager() .findFragmentByTag(LYRICS_FRAGMENT_TAG); if (lyricsViewFragment != null) lyricsViewFragment.fetchLyrics(artist, song, url); else { Lyrics lyrics = new Lyrics(Lyrics.SEARCH_ITEM); lyrics.setArtist(artist); lyrics.setTitle(song); lyrics.setURL(url); Bundle lyricsBundle = new Bundle(); try { if (artist != null && song != null) lyricsBundle.putByteArray("lyrics", lyrics.toBytes()); } catch (IOException e) { e.printStackTrace(); } lyricsViewFragment = new LyricsViewFragment(); lyricsViewFragment.setArguments(lyricsBundle); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, outAnim, R.animator.slide_in_start, outAnim); Fragment activeFragment = getDisplayedFragment(getActiveFragments()); if (activeFragment != null) { prepareAnimations(activeFragment); fragmentTransaction.hide(activeFragment); } fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG); lyricsViewFragment.isActiveFragment = true; fragmentTransaction.commit(); } if (drawer instanceof DrawerLayout && !mDrawerToggle.isDrawerIndicatorEnabled()) { mDrawerToggle.setDrawerIndicatorEnabled(true); ((DrawerLayout) drawer).setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); } }
From source file:com.cloudbees.gasp.activity.PlacesDetailActivity.java
private void addGaspFragments() { FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mGaspDatabaseFragment = new GaspDatabaseFragment(); mGaspRestaurantFragment = new GaspRestaurantFragment() { @Override/*from w w w .ja v a2 s .c om*/ public void onSuccess(String location) { Log.d(TAG, "Gasp! restaurant added: " + location); mGaspRestaurantId = Integer.valueOf(location.substring(location.lastIndexOf("/") + 1)); mGaspRestaurant = true; setButtons(); } @Override public void onFailure() { Log.e(TAG, "Error adding Gasp! review"); } }; mGaspReviewFragment = new GaspReviewFragment() { @Override public void onSuccess(String location) { Log.d(TAG, "Gasp! review added: " + location); } @Override public void onFailure() { Log.e(TAG, "Error adding Gasp! review"); } }; ft.add(mGaspDatabaseFragment, getString(R.string.fragment_gasp_database)); ft.add(mGaspRestaurantFragment, getString(R.string.fragment_gasp_restaurant)); ft.add(mGaspReviewFragment, getString(R.string.fragment_gasp_review)); ft.commit(); }
From source file:com.example.office.ui.Office365DemoActivity.java
/** * Choose one of the available screens to display (via appropriate Fragment). * * @param newScreen Screen to be shown.//from w ww. j a v a2 s . c o m */ private void switchScreen(UI.Screen newScreen) { try { ActionBar actionBar = getActionBar(); mDrawerList.setItemChecked(newScreen.ordinal(), true); setTitle(newScreen.getName(this)); actionBar.setLogo(newScreen.getIcon(this)); if (newScreen.in(ScreenGroup.MAIL)) { Screen currentScreen = Screen.getByTag(mCurrentFragmentTag, this); if (!currentScreen.in(ScreenGroup.MAIL)) { Fragment newFragment; FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); switch (newScreen) { case CONTACTS: newFragment = new ContactsFragment(); break; case MAILBOX: newFragment = new DraftsFragment(); break; case CALENDAR: { newFragment = new CalendarFragment(); break; } default: { newFragment = new DraftsFragment(); break; } } fragmentTransaction.add(R.id.content_pane, newFragment, newScreen.getName(this)); fragmentTransaction.commit(); } actionBar.selectTab(actionBar.getTabAt(newScreen.ordinal())); mCurrentFragmentTag = newScreen.getName(this); } mDrawerLayout.closeDrawer(mDrawerList); } catch (Exception e) { Logger.logApplicationException(e, getClass().getSimpleName() + ".switchBox(): Error."); } }
From source file:com.mainpanel.LifeApp_Map.java
private void initiateFragments() { Log.d("datastore", "initiateFragments"); FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); // Check to see if we have retained the fragment which handles // asynchronous backend calls mProcessingFragment = (CloudBackendFragment) mFragmentManager.findFragmentByTag(PROCESSING_FRAGMENT_TAG); // If not retained (or first time running), create a new one if (mProcessingFragment == null) { mProcessingFragment = new CloudBackendFragment(); mProcessingFragment.setRetainInstance(true); fragmentTransaction.add(mProcessingFragment, PROCESSING_FRAGMENT_TAG); }/* w w w . j a v a2 s . c o m*/ fragmentTransaction.commit(); }
From source file:com.geecko.QuickLyric.MainActivity.java
private void selectItem(int position) { FragmentManager fragmentManager = getFragmentManager(); Fragment newFragment;// w w w.ja va 2s . co m String tag; switch (position) { default: // Lyrics tag = LYRICS_FRAGMENT_TAG; newFragment = fragmentManager.findFragmentByTag(tag); if (newFragment == null || !(newFragment instanceof LyricsViewFragment)) newFragment = new LyricsViewFragment(); ((LyricsViewFragment) newFragment).showTransitionAnim = true; break; case 1: // Saved Lyrics tag = LOCAL_LYRICS_FRAGMENT_TAG; newFragment = fragmentManager.findFragmentByTag(tag); if (newFragment == null || !(newFragment instanceof LocalLyricsFragment)) newFragment = new LocalLyricsFragment(); ((LocalLyricsFragment) newFragment).showTransitionAnim = true; break; case 2: // Separator return; case 3: // Settings if (drawer instanceof DrawerLayout) ((DrawerLayout) drawer).closeDrawer(drawerView); drawer.postDelayed(new Runnable() { @Override public void run() { Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(settingsIntent, 77); } }, 250); return; case 4: // Feedback return; case 5: // About Dialog if (drawer instanceof DrawerLayout) ((DrawerLayout) drawer).closeDrawer(drawerView); drawer.postDelayed(new Runnable() { @Override public void run() { Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class); startActivityForResult(aboutIntent, 77); } }, 250); return; } final Fragment activeFragment = getDisplayedFragment(getActiveFragments()); prepareAnimations(activeFragment); // Insert the fragment by replacing any existing fragment if (newFragment != activeFragment) { if (mActionMode != null) mActionMode.finish(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, R.animator.slide_out_start, R.animator.slide_in_start, R.animator.slide_out_start); fragmentTransaction.hide(activeFragment); if (newFragment.isAdded()) fragmentTransaction.show(newFragment); else fragmentTransaction.add(id.main_fragment_container, newFragment, tag); ((CollapsingToolbarLayout) findViewById(R.id.toolbar_layout)).setCollapsedTitleTextColor(Color.WHITE); fragmentTransaction.commit(); if (activeFragment instanceof LyricsViewFragment || newFragment instanceof LyricsViewFragment) { final Fragment newFragmentCopy = newFragment; activeFragment.getView().postDelayed(new Runnable() { @Override public void run() { if (activeFragment instanceof LyricsViewFragment) { expandToolbar(false); showRefreshFab(false); } else if (newFragmentCopy instanceof LyricsViewFragment) { expandToolbar(true); showRefreshFab(true); } } }, getResources().getInteger(android.R.integer.config_longAnimTime)); } } if (drawer instanceof DrawerLayout && (newFragment == activeFragment)) ((DrawerLayout) drawer).closeDrawer(drawerView); }
From source file:com.android.dialer.DialtactsActivity.java
/** * Hides the search fragment//from ww w .ja v a2 s. c o m */ private void exitSearchUi() { // See related bug in enterSearchUI(); if (getFragmentManager().isDestroyed() || mStateSaved) { return; } mSearchView.setText(null); if (mDialpadFragment != null) { mDialpadFragment.clearDialpad(); } setNotInSearchUi(); // Restore the FAB for the lists fragment. if (getFabAlignment() != FloatingActionButtonController.ALIGN_END) { mFloatingActionButtonController.setVisible(false); } mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); onPageScrolled(mListsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */); onPageSelected(mListsFragment.getCurrentTabIndex()); final FragmentTransaction transaction = getFragmentManager().beginTransaction(); if (mSmartDialSearchFragment != null) { transaction.remove(mSmartDialSearchFragment); } if (mRegularSearchFragment != null) { transaction.remove(mRegularSearchFragment); } transaction.commit(); mListsFragment.getView().animate().alpha(1).withLayer(); if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { // If the dialpad fragment wasn't previously visible, then send a screen view because // we are exiting regular search. Otherwise, the screen view will be sent by // {@link #hideDialpadFragment}. mListsFragment.sendScreenViewForCurrentPosition(); mListsFragment.setUserVisibleHint(true); } mActionBarController.onSearchUiExited(); }
From source file:com.google.samples.apps.iosched.ui.BaseActivity.java
/** * Adds a {@link com.google.samples.apps.iosched.framework.PresenterFragmentImpl} to the * Activity if required, and sets it up with the {@code model}, {@code queries}, * {@code actions} and the {@link com.google.samples.apps.iosched.framework.UpdatableView} * corresponding to the {@code updatableViewResId}. * * @return the {@link com.google.samples.apps.iosched.framework.PresenterFragmentImpl}, *//* www .j a v a 2s . com*/ public PresenterFragmentImpl addPresenterFragment(int updatableViewResId, Model model, QueryEnum[] queries, UserActionEnum[] actions) { FragmentManager fragmentManager = getFragmentManager(); //Check if the presenter fragment is already present (ie if the activity is recreated due // to orientation change). PresenterFragmentImpl presenter = (PresenterFragmentImpl) fragmentManager.findFragmentByTag(PRESENTER_TAG); if (presenter == null) { //Create, set up and add the presenter. presenter = new PresenterFragmentImpl(); setUpPresenter(presenter, fragmentManager, updatableViewResId, model, queries, actions); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(presenter, PRESENTER_TAG); fragmentTransaction.commit(); } else { //Set up the presenter. setUpPresenter(presenter, fragmentManager, updatableViewResId, model, queries, actions); } return presenter; }
From source file:com.example.search.car.pools.welcome.java
@Override public void onClick(View v) { // TODO Auto-generated method stub Fragment fragment = null;//w w w . java 2 s . com if ((v.equals(l_1) || (v.equals(sp_city)))) { String[] city = { "Delhi/NCR", "Bengaluru", "Kolkata", "Mumbai", "Pune", "Ahmedabad" }; dialog("City", city, sp_city); } else if ((v.equals(l_2) || (v.equals(sp_category)))) { String[] category = { "All", "Carpool", "Cab", "Rideshare" }; dialog("Category", category, sp_category); } else if ((v.equals(l_3) || (v.equals(sp_search_for)))) { String[] search_for = { "Seeker", "Provider", "Both" }; dialog(" Search For", search_for, sp_search_for); } else if (v.equals(close)) { promptsView.dismiss(); } else if (v.equals(rlCities)) { layout = "Cities"; fragment = new Cities(); frag_tag = "Cities"; set_fragment(fragment); mDrawerLayout.closeDrawer(mDrawerList); // getActionBar().setTitle("Cities"); svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city1); iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); rlCities.setBackgroundColor(Color.parseColor("#00ca98")); l_cities.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard); iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50")); l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue)); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#2C3E50")); l_search.setBackground(getResources().getDrawable(R.drawable.search_blue)); } else if (v.equals(rlDashboard)) { if (task.getString("user_id", null) != null) { // layout = "Dashboard"; // fragment = new dashboard(); // frag_tag = "Dashboard"; // // getActionBar().setTitle("My Profile"); // set_fragment(fragment); // mDrawerLayout.closeDrawer(mDrawerList); // svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard1); // iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); // rlDashboard.setBackgroundColor(Color.parseColor("#00ca98")); // l_dashboard.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); // // svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city); // iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); // rlCities.setBackgroundColor(Color.parseColor("#2C3E50")); // l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue)); // svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search); // iv_search.setImageDrawable(svg_search.createPictureDrawable()); // rlSearch.setBackgroundColor(Color.parseColor("#2C3E50")); // l_search.setBackground(getResources().getDrawable(R.drawable.search_blue)); Intent i = new Intent(welcome.this, dashboard_main.class); i.putExtra("edit", "1"); startActivity(i); mDrawerLayout.closeDrawer(mDrawerList); } else { Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show(); mDrawerLayout.closeDrawer(mDrawerList); } } else if (v.equals(rlSearch)) { layout = "Search"; frag_tag = "Search"; fragment = new Search(); set_fragment(fragment); mDrawerLayout.closeDrawer(mDrawerList); // getActionBar().setTitle("Search"); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard); iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50")); l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue)); svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city); iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); rlCities.setBackgroundColor(Color.parseColor("#2C3E50")); l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue)); } else if (v.equals(rlProfile_login) || v.equals(profile_login)) { if (task.getString("user_id", null) == null) { Intent i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } mDrawerLayout.closeDrawer(mDrawerList); } // else if (v.equals(rlEditProfile)) { // if (task.getString("user_id", null) != null) { // Intent i = new Intent(welcome.this, dashboard_main.class); // i.putExtra("edit", "3"); // startActivity(i); // } else { // Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show(); // } // mDrawerLayout.closeDrawer(mDrawerList); // } else if (v.equals(login) || v.equals(rlLogin)) { if (task.getString("user_id", null) != null && login.getText().toString().contentEquals("Logout")) { SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit(); editor.clear(); editor.commit(); login.setText("Login"); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) { // highlight search menu on slider during on resume // change fragment to search FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, new Search()); fragmentTransaction.commit(); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); } iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); if (frag_id == 6) { Intent i_user = new Intent(getBaseContext(), user_login.class); i_user.putExtra("frag_id", frag_id); startActivity(i_user); } } else { Intent i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } mDrawerLayout.closeDrawer(mDrawerList); } else if (v.equals(b_search)) { if (sp_city.getText().toString().toUpperCase().equals("SELECT CITY")) { Toast.makeText(welcome.this, "First Select the City", Toast.LENGTH_LONG).show(); } else { Intent i = new Intent(welcome.this, search_result.class); i.putExtra("city", sp_city.getText().toString()); i.putExtra("category", sp_category.getText().toString()); i.putExtra("search_for", sp_search_for.getText().toString()); i.putExtra("from", et_from.getText().toString()); i.putExtra("to", et_to.getText().toString()); i.putExtra("frag_id", 1); i.putExtra("company_id", 0); startActivity(i); promptsView.dismiss(); } } else if (v.equals(l_nav_search) || v.equals(ib_search)) { final int DELAY = 200; // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_nav_search.setBackground(a); a.start(); showSearchDialog(); } else if (v.equals(l_handle) || v.equals(ib_handle)) { final int DELAY = 200; // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_handle.setBackground(a); a.start(); if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } } else if (v.equals(l_menu) || v.equals(ib_menu)) { final int DELAY = 200; // for light background // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_menu.setBackground(a); a.start(); final PopupMenu popup = new PopupMenu(welcome.this, v); popup.getMenuInflater().inflate(R.menu.main, popup.getMenu()); bedMenuItem = popup.getMenu().findItem(R.id.menu_login); final SharedPreferences task = getSharedPreferences("user", MODE_PRIVATE); popup.getMenu().findItem(R.id.menu_add_new_list).setVisible(!(task.getString("user_id", null) == null)); popup.getMenu().findItem(R.id.menu_dashboard).setVisible(!(task.getString("user_id", null) == null)); if (task.getString("user_id", null) != null) { bedMenuItem.setTitle("Logout"); login.setText("Logout"); iv_login.setImageDrawable(svg_logout.createPictureDrawable()); rlProfile.setVisibility(View.VISIBLE); rlProfile_login.setVisibility(View.GONE); rlDashboard.setVisibility(View.VISIBLE); // rlEditProfile.setVisibility(View.VISIBLE); set_data(); } else { bedMenuItem.setTitle("Login/Register"); login.setText("Login"); iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); } if (task.getString("user_id", null) != null) { popup.getMenu().findItem(R.id.menu_login).setTitle("Logout"); } else { popup.getMenu().findItem(R.id.menu_login).setTitle("Login/Register"); } popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // TODO Auto-generated method stub int id = item.getItemId(); Intent i; switch (id) { case R.id.menu_add_new_list: if (task.getString("user_id", null) != null) { i = new Intent(welcome.this, create_activity.class); startActivity(i); } else { Toast.makeText(welcome.this, "Login first", Toast.LENGTH_SHORT).show(); } return true; case R.id.menu_dashboard: if (task.getString("user_id", null) != null) { i = new Intent(welcome.this, dashboard_main.class); i.putExtra("edit", "12344"); startActivity(i); } else { Toast.makeText(welcome.this, "Please Login first", Toast.LENGTH_LONG).show(); } return true; case R.id.menu_login: if (bedMenuItem.getTitle().equals("Logout")) { SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit(); editor.clear(); editor.commit(); // bedMenuItem.setTitle("Login/Register"); login.setText("Login"); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) { // highlight search menu on slider during on // resume // change fragment to search FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, new Search()); fragmentTransaction.commit(); SVG svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground( getResources().getDrawable(R.drawable.white_circle_side_menu)); } iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); if (frag_id == 6) { Intent i_user = new Intent(getBaseContext(), user_login.class); i_user.putExtra("frag_id", frag_id); startActivity(i_user); } } else { i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } return true; } return false; } }); popup.show(); // } else { // openOptionsMenu(); // } } }