List of usage examples for android.app FragmentTransaction commit
public abstract int commit();
From source file:Main.java
public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment);// www. j a va 2 s . c om transaction.commit(); }
From source file:Main.java
public static void addFragmentToLayout(final int containerId, final FragmentManager fragmentManager, final Fragment fragment, final String tag) { final FragmentTransaction ft = fragmentManager.beginTransaction(); ft.add(containerId, fragment, tag);/* w w w.j a v a 2 s .c o m*/ ft.commit(); }
From source file:Main.java
public static void replaceFragment(FragmentManager manager, int parent, Fragment fragment) { FragmentTransaction ft = manager.beginTransaction(); ft.replace(parent, fragment);/*from w w w. j a v a2 s. c om*/ ft.addToBackStack(null); ft.commit(); }
From source file:Main.java
/** * The {@code fragment} is added to the container view with id {@code frameId}. The operation is * performed by the {@code fragmentManager}. * *//*from www. j av a 2 s . c o m*/ public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment); transaction.commit(); }
From source file:com.poloure.simplerss.Constants.java
static void hideFragments(Fragment... fragments) { FragmentTransaction transaction = s_fragmentManager.beginTransaction(); for (Fragment fragment : fragments) { transaction.hide(fragment);/*from ww w . j a v a2 s . com*/ } transaction.commit(); }
From source file:com.poloure.simplerss.Constants.java
static void showFragments(Fragment... fragments) { FragmentTransaction transaction = s_fragmentManager.beginTransaction(); for (Fragment fragment : fragments) { transaction.show(fragment);//from w w w . j ava 2 s . c o m } transaction.commit(); }
From source file:com.appdynamics.demo.gasp.utils.LocationServices.java
/** * Enable location checking (via LocationFragment) * @param context the application context *//*w w w . j ava 2s. c o m*/ public static void enableLocationChecking(FragmentActivity context) { try { if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) { // Check current location Location location = LocationFragment.getLocation(context); if (location != null) { Log.d(TAG, "Location: " + String.format("%.6f", location.getLatitude()) + ", " + String.format("%.6f", location.getLongitude()) + " (via " + location.getProvider() + ")" + '\n'); } // Add LocationFragment to enable location updates FragmentManager fm = context.getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); LocationFragment locationFragment = new LocationFragment(); ft.add(locationFragment, "LocationFragment"); ft.commit(); } else Log.e(TAG, "Google Play Services not available"); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void replaceFragmentToLayout(final int containerId, final FragmentManager fragmentManager, final Fragment fragment, final String tag) { final FragmentTransaction ft = fragmentManager.beginTransaction(); final Fragment previousFragment = fragmentManager.findFragmentByTag(tag); if (previousFragment != null) { ft.remove(previousFragment);/*from w w w. jav a2s.c o m*/ } ft.add(containerId, fragment, tag); ft.commit(); }
From source file:com.androidexperiments.sprayscape.androidutils.PermissionRequester.java
public static void requestPermission(final String permission, final String objectName, final String methodName) { Log.i(TAG, "requestPermission() called for permission: " + permission); final Activity currentActivity = UnityPlayer.currentActivity; boolean granted = ActivityCompat.checkSelfPermission(currentActivity, permission) == PackageManager.PERMISSION_GRANTED; if (granted) { Log.i(TAG, "Permission already granted: " + permission); SendPermissionResult(permission, true, objectName, methodName); return;/*from www . j a va 2 s.c o m*/ } try { // use a fragment here because we wouldn't be able to capture onRequestPermissionsResult() on the main activity unless we sub-classed it... // final values so the fragment inner-class can access them final FragmentManager fragmentManager = currentActivity.getFragmentManager(); final Fragment request = new Fragment() { @Override public void onStart() { super.onStart(); Log.i(TAG, "Permission fragment onStart()"); FragmentCompat.requestPermissions(this, new String[] { permission }, 0); } @SuppressLint("Override") @SuppressWarnings("unused") public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { Log.i(TAG, "onRequestPermissionsResult(" + requestCode + ", " + permissions.toString() + ", " + grantResults.toString() + ")"); if (grantResults.length > 0) { for (int i = 0; i < grantResults.length; i++) { if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "Permission granted: " + permissions[i]); SendPermissionResult(permissions[i], true, objectName, methodName); } else { Log.i(TAG, "Permission denied: " + permissions[i]); SendPermissionResult(permissions[i], false, objectName, methodName); } } } else { Log.i(TAG, "Permission denied: " + permission); SendPermissionResult(permission, false, objectName, methodName); } FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.remove(this); fragmentTransaction.commit(); } }; FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(0, request); fragmentTransaction.commit(); } catch (Exception error) { Log.e(TAG, "Permission request failed: '" + permission + "'", error); SendPermissionResult(permission, false, objectName, methodName); } }
From source file:com.appdynamics.demo.gasp.twitter.TwitterAuthentication.java
/** * Request a Twitter API v1.1 OAuth Token * Uses TwitterAuthenticationFragment/* w w w . j a v a2 s . c o m*/ */ public static void requestTwitterOAuthToken(FragmentActivity activity) { FragmentManager fm = activity.getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); TwitterAuthenticationFragment responder = (TwitterAuthenticationFragment) fm .findFragmentByTag("TwitterAuthentication"); if (responder == null) { responder = new TwitterAuthenticationFragment(); ft.add(responder, "TwitterAuthentication"); } ft.commit(); }