List of usage examples for android.app FragmentTransaction replace
public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);
From source file:co.taqat.call.CallActivity.java
private void replaceFragmentAudioByVideo() { // Hiding controls to let displayVideoCallControlsIfHidden add them plus the callback videoCallFragment = new CallVideoFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.fragmentContainer, videoCallFragment); try {// w ww. jav a 2s .co m transaction.commitAllowingStateLoss(); } catch (Exception e) { } }
From source file:com.android.calendar.AllInOneActivity.java
private void initFragments(long timeMillis, int viewType, Bundle icicle) { if (DEBUG) {/*from w w w . j a va 2 s .c o m*/ Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType); } FragmentTransaction ft = getFragmentManager().beginTransaction(); if (mShowCalendarControls) { Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true); ft.replace(R.id.mini_month, miniMonthFrag); mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag); Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment(); ft.replace(R.id.calendar_list, selectCalendarsFrag); mController.registerEventHandler(R.id.calendar_list, (EventHandler) selectCalendarsFrag); } if (!mShowCalendarControls || viewType == ViewType.EDIT) { mMiniMonth.setVisibility(View.GONE); mCalendarsList.setVisibility(View.GONE); } EventInfo info = null; if (viewType == ViewType.EDIT) { mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW); long eventId = -1; Intent intent = getIntent(); Uri data = intent.getData(); if (data != null) { try { eventId = Long.parseLong(data.getLastPathSegment()); } catch (NumberFormatException e) { if (DEBUG) { Log.d(TAG, "Create new event"); } } } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) { eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID); } long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1); long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1); info = new EventInfo(); if (end != -1) { info.endTime = new Time(); info.endTime.set(end); } if (begin != -1) { info.startTime = new Time(); info.startTime.set(begin); } info.id = eventId; // We set the viewtype so if the user presses back when they are // done editing the controller knows we were in the Edit Event // screen. Likewise for eventId mController.setViewType(viewType); mController.setEventId(eventId); } else { mPreviousView = viewType; } setMainPane(ft, R.id.main_pane, viewType, timeMillis, true); ft.commit(); // this needs to be after setMainPane() Time t = new Time(mTimeZone); t.set(timeMillis); if (viewType == ViewType.AGENDA && icicle != null) { mController.sendEvent(this, EventType.GO_TO, t, null, icicle.getLong(BUNDLE_KEY_EVENT_ID, -1), viewType); } else if (viewType != ViewType.EDIT) { mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType); } }
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 . ja va 2 s . c o m 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(); // } } }
From source file:itcr.gitsnes.MainActivity.java
/** * OnCreate methods do that things://from w ww . ja v a 2 s . c o m * - Inflate Login formulary frame (hide action bar) * - Init Accelerometer intent (onShake) * - Create login method (auth with FB) * - Handle exceptions of previously methods */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* -- Shows action bar and inflate main Listview from JSON (see BackendHandler) --- */ getActionBar().hide(); setContentView(R.layout.activity_main); FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); /* Add transaction and login FB intent to mainActivity*/ Login login = new Login(); transaction.add(R.id.placeholder, login).commit(); /* Init shake sensor and create event to get random game from DB (Backend on app-engine)*/ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(); mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() { @Override public void onShake(int count) { /* Inflate random-game detail */ Toast.makeText(getApplicationContext(), "Buscando juego aleatorio!!", Toast.LENGTH_SHORT).show(); MasterGames new_fragment = new MasterGames(json_arr); new_fragment.setRandomgame("random"); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.placeholder, new_fragment); transaction.addToBackStack(null); transaction.commit(); } }); mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI); /*Initialize FB API helper methods and listen callback from fb_loginbutton*/ uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); authButton = (LoginButton) findViewById(R.id.authButton); authButton.setOnErrorListener(new LoginButton.OnErrorListener() { @Override public void onError(FacebookException error) { Log.i(TAG, "Error " + error.getMessage()); } }); /*Obtaining data from successfully FB API callback using GraphUser*/ authButton.setReadPermissions(Arrays.asList("email")); authButton.setSessionStatusCallback(new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { Log.i(TAG, "Accesssss Token"); if (session.isOpened()) { Log.i(TAG, "Access Token" + session.getAccessToken()); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { Log.i(TAG, "User ID " + user.getId()); Log.i(TAG, "Email " + user.asMap().get("email")); /* Inflate main-Listview from JSON (see BackendHandler) and saving current user*/ back_stage(); getActionBar().show(); KS.setCurrent_user(user.asMap().get("email").toString()); Toast.makeText(getApplicationContext(), "Welcome!! " + KS.getCurrent_user(), Toast.LENGTH_SHORT).show(); new BackendHandler().sendUser(KS.getCurrent_user(), user.asMap().get("email").toString()); //lblEmail.setText(user.asMap().get("email").toString()); } } }); } else Log.i(TAG, "Nopes Token"); } }); }
From source file:de.sourcestream.movieDB.controller.SearchList.java
public void onSuggestionClick(int id, String mediaType, String title) { FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); boolean result; Bundle args;/*from w ww .j a v a 2 s .com*/ switch (mediaType) { case "movie": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (movieDetails != null && lastVisitedId == id && movieDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash movieDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", id); Bundle save = movieDetails.getSave(); movieDetails = new MovieDetails(); movieDetails.setTimeOut(0); movieDetails.setSave(save); movieDetails.setArguments(bundle); } else movieDetails = new MovieDetails(); args = new Bundle(); args.putInt("id", id); movieDetails.setArguments(args); movieDetails.setTitle(title); transaction.replace(R.id.frame_container, movieDetails); result = true; break; case "person": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (castDetails != null && lastVisitedId == id && castDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash castDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", id); Bundle save = castDetails.getSave(); castDetails = new CastDetails(); castDetails.setTimeOut(0); castDetails.setSave(save); castDetails.setArguments(bundle); } else castDetails = new CastDetails(); args = new Bundle(); args.putInt("id", id); castDetails.setArguments(args); castDetails.setTitle(title); transaction.replace(R.id.frame_container, castDetails); result = true; break; case "tv": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (tvDetails != null && lastVisitedId == id && tvDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash tvDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", id); Bundle save = tvDetails.getSave(); tvDetails = new TVDetails(); tvDetails.setTimeOut(0); tvDetails.setSave(save); tvDetails.setArguments(bundle); } else tvDetails = new TVDetails(); args = new Bundle(); args.putInt("id", id); tvDetails.setArguments(args); tvDetails.setTitle(title); transaction.replace(R.id.frame_container, tvDetails); result = true; break; default: result = false; break; } lastVisitedId = id; if (result) { // add the current transaction to the back stack: transaction.addToBackStack("movieList"); transaction.commit(); // collapse the search View ((MainActivity) getActivity()).collapseSearchView(); } }
From source file:com.concentricsky.android.khanacademy.app.VideoDetailActivity.java
private void createAndAttachCaptionFragment(int containerId) { FragmentTransaction tx = getFragmentManager().beginTransaction(); if (captionFragment != null) { tx.remove(captionFragment);//from w w w . j av a 2 s . c o m } captionFragment = new CaptionFragment(); Bundle args = new Bundle(); if (video != null) { args.putString(Constants.PARAM_VIDEO_ID, video.getId()); if (videoFragment != null) { args.putInt(PARAM_VIDEO_POSITION, videoFragment.getVideoPosition()); } } // Set args even if empty to avoid possible NPE inside CaptionFragment. captionFragment.setArguments(args); captionFragment.registerCallbacks(this); tx.replace(containerId, captionFragment); tx.commit(); // Force execute, so we can populateHeader afterward. getFragmentManager().executePendingTransactions(); }
From source file:com.hijacker.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.reset: stop(PROCESS_AIRODUMP);//from w w w . jav a2s. c o m Tile.clear(); Tile.onCountsChanged(); Airodump.startClean(); return true; case R.id.stop_run: if (Airodump.isRunning()) stop(PROCESS_AIRODUMP); else Airodump.start(); return true; case R.id.stop_aireplay: stop(PROCESS_AIREPLAY); return true; case R.id.filter: new FiltersDialog().show(mFragmentManager, "FiltersDialog"); return true; case R.id.settings: if (currentFragment != FRAGMENT_SETTINGS) { FragmentTransaction ft = mFragmentManager.beginTransaction(); ft.replace(R.id.fragment1, new SettingsFragment()); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.addToBackStack(null); ft.commitAllowingStateLoss(); } return true; case R.id.export: new ExportDialog().show(mFragmentManager, "ExportDialog"); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
public void swapToFragmentView(ScreenList newFragment) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newFragment.toString()); FragmentManager mgr = getFragmentManager(); Fragment f;/* www . jav a2 s . c o m*/ if (newFragment == ScreenList.MAIN_SCREEN) { throw new IllegalStateException("unexpected reference to generic main screen"); } else if (newFragment == ScreenList.CUSTOM_VIEW) { WebLogger.getLogger(getAppName()).w(t, "swapToFragmentView: changing navigation to move to WebKit (was custom view)"); f = mgr.findFragmentById(WebViewFragment.ID); if (f == null) { f = new WebViewFragment(); } newFragment = ScreenList.WEBKIT; } else if (newFragment == ScreenList.FORM_CHOOSER) { f = mgr.findFragmentById(FormChooserListFragment.ID); if (f == null) { f = new FormChooserListFragment(); } } else if (newFragment == ScreenList.INITIALIZATION_DIALOG) { if (currentFragment == ScreenList.INITIALIZATION_DIALOG) { WebLogger.getLogger(getAppName()).e(t, "Unexpected: currentFragment == INITIALIZATION_DIALOG"); return; } else { f = mgr.findFragmentById(InitializationFragment.ID); if (f == null) { f = new InitializationFragment(); } ((InitializationFragment) f).setFragmentToShowNext( (currentFragment == null) ? ScreenList.FORM_CHOOSER.name() : currentFragment.name()); } } else if (newFragment == ScreenList.FORM_DELETER) { f = mgr.findFragmentById(FormDeleteListFragment.ID); if (f == null) { f = new FormDeleteListFragment(); } } else if (newFragment == ScreenList.FORM_DOWNLOADER) { f = mgr.findFragmentById(FormDownloadListFragment.ID); if (f == null) { f = new FormDownloadListFragment(); } } else if (newFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER) { f = mgr.findFragmentById(InstanceUploaderTableChooserListFragment.ID); if (f == null) { f = new InstanceUploaderTableChooserListFragment(); } } else if (newFragment == ScreenList.INSTANCE_UPLOADER) { f = mgr.findFragmentById(InstanceUploaderListFragment.ID); if (f == null) { f = new InstanceUploaderListFragment(); } ((InstanceUploaderListFragment) f).changeUploadTableId(); } else if (newFragment == ScreenList.WEBKIT) { f = mgr.findFragmentById(WebViewFragment.ID); if (f == null) { f = new WebViewFragment(); } } else if (newFragment == ScreenList.ABOUT_MENU) { f = mgr.findFragmentById(AboutMenuFragment.ID); if (f == null) { f = new AboutMenuFragment(); } } else { throw new IllegalStateException("Unrecognized ScreenList type"); } FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content); View frags = findViewById(R.id.main_content); View wkt = findViewById(R.id.webkit_view); shadow.setVisibility(View.GONE); shadow.removeAllViews(); if (newFragment == ScreenList.WEBKIT) { frags.setVisibility(View.GONE); wkt.setVisibility(View.VISIBLE); wkt.invalidate(); } else { wkt.setVisibility(View.GONE); frags.setVisibility(View.VISIBLE); } currentFragment = newFragment; BackStackEntry entry = null; for (int i = 0; i < mgr.getBackStackEntryCount(); ++i) { BackStackEntry e = mgr.getBackStackEntryAt(i); if (e.getName().equals(currentFragment.name())) { entry = e; break; } } if (entry != null) { // flush backward, including the screen want to go back to mgr.popBackStackImmediate(currentFragment.name(), FragmentManager.POP_BACK_STACK_INCLUSIVE); } // add transaction to show the screen we want FragmentTransaction trans = mgr.beginTransaction(); trans.replace(R.id.main_content, f); trans.addToBackStack(currentFragment.name()); trans.commit(); // and see if we should re-initialize... if ((currentFragment != ScreenList.INITIALIZATION_DIALOG) && Survey.getInstance().shouldRunInitializationTask(getAppName())) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView -- calling clearRunInitializationTask"); // and immediately clear the should-run flag... Survey.getInstance().clearRunInitializationTask(getAppName()); // OK we should swap to the InitializationFragment view swapToFragmentView(ScreenList.INITIALIZATION_DIALOG); } else { levelSafeInvalidateOptionsMenu(); } }
From source file:finalproject.ece558.edu.pdx.ece.brailleblackjack.PlayBlackJackGameFragment.java
/** * Set-up button listeners. Restore the state of the fragment if the state was saved. If no * state to restore then go set-up the game. Finally inflate the layout of the fragment * @param inflater LayoutInflater object * @param container ViewGroup object/*from w w w. ja v a 2s. c om*/ * @param savedInstanceState Bundle object of saved instances * @return View to inflate the layout on the screen */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v = inflater.inflate(R.layout.fragment_play_black_jack_game, container, false); // Bind views group = (ViewGroup) v.findViewById(R.id.playFragment); // Set up the card slots dealer_left_slot = (ImageView) v.findViewById(R.id.img_view_dealer_left_card); dealer_right_slot = (ImageView) v.findViewById(R.id.img_view_dealer_right_card); player_left_slot = (ImageView) v.findViewById(R.id.img_view_player_left_card); player_right_slot = (ImageView) v.findViewById(R.id.img_view_player_right_card); // Set up the total slots dealer_top_total_slot = (ImageView) v.findViewById(R.id.img_view_dealer_top_total); dealer_bot_total_slot = (ImageView) v.findViewById(R.id.img_view_dealer_bot_total); player_top_total_slot = (ImageView) v.findViewById(R.id.img_view_player_top_total); player_bot_total_slot = (ImageView) v.findViewById(R.id.img_view_player_bot_total); /* Hit button Listener */ button_hit = (Button) v.findViewById(R.id.button_hit); button_hit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { playerHits(); } }); /* Stand button Listener */ button_stand = (Button) v.findViewById(R.id.button_stand); button_stand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { playerStands(); } }); /* Start Over buttonListener */ button_start_over = (Button) v.findViewById(R.id.button_start_over); button_start_over.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentTransaction fm = getFragmentManager().beginTransaction(); fm.replace(R.id.fragment_container, new PlayBlackJackGameFragment()); fm.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); fm.commit(); } }); /* Hint button Listener */ button_hint = (Button) v.findViewById(R.id.button_hint); button_hint.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hintDialog(); } }); // If activity recreated (such as from screen rotate), restore // the previous article selection set by onSaveInstanceState(). // This is primarily necessary when in the two-pane layout. if (savedInstanceState != null) { /* Restore Variables and Flags */ dealer_had_ace = savedInstanceState.getBoolean("DEALER_HAD_ACE"); player_had_ace = savedInstanceState.getBoolean("PLAYER_HAD_ACE"); dealer_turn = savedInstanceState.getBoolean("DEALER_TURN"); player_turn = savedInstanceState.getBoolean("PLAYER_TURN"); first_draw_spoken = savedInstanceState.getBoolean("IS_FIRST_DRAW_SPOKEN"); dealer_top_total_value = savedInstanceState.getInt("DEALER_TOP_TOTAL_VALUE"); dealer_bot_total_value = savedInstanceState.getInt("DEALER_BOT_TOTAL_VALUE"); player_top_total_value = savedInstanceState.getInt("PLAYER_TOP_TOTAL_VALUE"); dealer_bot_total_value = savedInstanceState.getInt("PLAYER_BOT_TOTAL_VALUE"); button_hit_state = savedInstanceState.getBoolean("BUTTON_HIT_STATE"); button_stand_state = savedInstanceState.getBoolean("BUTTON_STAND_STATE"); button_hint_state = savedInstanceState.getBoolean("BUTTON_HINT_STATE"); /* Set button Visibility */ changeAllButtonStates(button_hit_state, button_stand_state, button_hint_state, true); /* Restore Cards */ curDeck = new Deck(context); String d_left, d_right, p_left, p_right; boolean dealer_left_exists = savedInstanceState.getBoolean("DEALER_LEFT_EXISTS"); d_right = savedInstanceState.getString("DEALER_RIGHT_CARD"); p_left = savedInstanceState.getString("PLAYER_LEFT_CARD"); p_right = savedInstanceState.getString("PLAYER_RIGHT_CARD"); dealer_right_card = curDeck.getCard(d_right); player_left_card = curDeck.getCard(p_left); player_right_card = curDeck.getCard(p_right); /* Restore Views and Totals and Description for TalkBack */ dealer_left_slot.setContentDescription("Dealer left card is hidden until you stand"); dealer_right_slot .setContentDescription("Dealer right card is " + dealer_right_card.getCardDescription()); player_left_slot.setContentDescription("Your left card is " + player_left_card.getCardDescription()); player_right_slot.setContentDescription("Your right card is " + player_right_card.getCardDescription()); dealer_right_slot.setImageResource(dealer_right_card.getCardDrawable()); player_left_slot.setImageResource(player_left_card.getCardDrawable()); player_right_slot.setImageResource(player_right_card.getCardDrawable()); if (dealer_left_exists) { d_left = savedInstanceState.getString("DEALER_LEFT_CARD"); dealer_left_card = curDeck.getCard(d_left); dealer_left_slot.setImageResource(dealer_left_card.getCardDrawable()); dealer_left_slot .setContentDescription("Dealer left card is " + dealer_left_card.getCardDescription()); } dealer_top_total_slot.setImageResource(giveTotalDrawable(dealer_top_total_value)); dealer_top_total_slot .setContentDescription("Dealer has a total of" + String.valueOf(dealer_top_total_value)); player_top_total_slot.setImageResource(giveTotalDrawable(player_top_total_value)); player_top_total_slot .setContentDescription("You have a total of " + String.valueOf(player_top_total_value)); if (player_bot_total_value > 0) { player_bot_total_slot.setImageResource(giveTotalDrawable(player_bot_total_value)); player_bot_total_slot.setVisibility(v.VISIBLE); player_bot_total_slot.setContentDescription("Because of an ace you have an alternative total of" + String.valueOf(player_bot_total_value)); } else { player_bot_total_slot.setVisibility(v.INVISIBLE); player_bot_total_slot.setContentDescription(""); } if (dealer_bot_total_value > 0) { dealer_bot_total_slot.setImageResource(giveTotalDrawable(dealer_bot_total_value)); dealer_bot_total_slot.setVisibility(v.VISIBLE); dealer_top_total_slot.setContentDescription("Because of an ace dealer has an alternative total of" + String.valueOf(dealer_bot_total_value)); } else { dealer_bot_total_slot.setVisibility(v.INVISIBLE); dealer_top_total_slot.setContentDescription(""); } } else { // Start Android Wear App if its connected sendMessage(START_WEAR); gameSetup(); } // Inflate the layout for this fragment return v; }
From source file:android.support.v17.leanback.app.BrowseFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getChildFragmentManager().findFragmentById(R.id.scale_frame) == null) { mHeadersFragment = new HeadersFragment(); createMainFragment(mAdapter, mSelectedPosition); FragmentTransaction ft = getChildFragmentManager().beginTransaction().replace(R.id.browse_headers_dock, mHeadersFragment);// w ww .jav a 2s. c om if (mMainFragment != null) { ft.replace(R.id.scale_frame, mMainFragment); } else { // Empty adapter used to guard against lazy adapter loading. When this // fragment is instantiated, mAdapter might not have the data or might not // have been set. In either of those cases mFragmentAdapter will be null. // This way we can maintain the invariant that mMainFragmentAdapter is never // null and it avoids doing null checks all over the code. mMainFragmentAdapter = new MainFragmentAdapter(null); mMainFragmentAdapter.setFragmentHost(new FragmentHostImpl()); } ft.commit(); } else { mHeadersFragment = (HeadersFragment) getChildFragmentManager() .findFragmentById(R.id.browse_headers_dock); mMainFragment = getChildFragmentManager().findFragmentById(R.id.scale_frame); mMainFragmentAdapter = ((MainFragmentAdapterProvider) mMainFragment).getMainFragmentAdapter(); mMainFragmentAdapter.setFragmentHost(new FragmentHostImpl()); mIsPageRow = savedInstanceState != null ? savedInstanceState.getBoolean(IS_PAGE_ROW, false) : false; mSelectedPosition = savedInstanceState != null ? savedInstanceState.getInt(CURRENT_SELECTED_POSITION, 0) : 0; if (!mIsPageRow) { if (mMainFragment instanceof MainFragmentRowsAdapterProvider) { mMainFragmentRowsAdapter = ((MainFragmentRowsAdapterProvider) mMainFragment) .getMainFragmentRowsAdapter(); } else { mMainFragmentRowsAdapter = null; } } else { mMainFragmentRowsAdapter = null; } } mHeadersFragment.setHeadersGone(!mCanShowHeaders); if (mHeaderPresenterSelector != null) { mHeadersFragment.setPresenterSelector(mHeaderPresenterSelector); } mHeadersFragment.setAdapter(mAdapter); mHeadersFragment.setOnHeaderViewSelectedListener(mHeaderViewSelectedListener); mHeadersFragment.setOnHeaderClickedListener(mHeaderClickedListener); View root = inflater.inflate(R.layout.lb_browse_fragment, container, false); getProgressBarManager().setRootView((ViewGroup) root); mBrowseFrame = (BrowseFrameLayout) root.findViewById(R.id.browse_frame); mBrowseFrame.setOnChildFocusListener(mOnChildFocusListener); mBrowseFrame.setOnFocusSearchListener(mOnFocusSearchListener); installTitleView(inflater, mBrowseFrame, savedInstanceState); mScaleFrameLayout = (ScaleFrameLayout) root.findViewById(R.id.scale_frame); mScaleFrameLayout.setPivotX(0); mScaleFrameLayout.setPivotY(mContainerListAlignTop); setupMainFragment(); if (mBrandColorSet) { mHeadersFragment.setBackgroundColor(mBrandColor); } mSceneWithHeaders = TransitionHelper.createScene(mBrowseFrame, new Runnable() { @Override public void run() { showHeaders(true); } }); mSceneWithoutHeaders = TransitionHelper.createScene(mBrowseFrame, new Runnable() { @Override public void run() { showHeaders(false); } }); mSceneAfterEntranceTransition = TransitionHelper.createScene(mBrowseFrame, new Runnable() { @Override public void run() { setEntranceTransitionEndState(); } }); return root; }