List of usage examples for android.app FragmentTransaction add
public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment);
From source file:Main.java
public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment); transaction.commit();/*from w w w .ja v a 2 s. c o m*/ }
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}. * *///w w w .jav 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:Main.java
public static void showDialogFragment(final DialogFragment dialog, final String tag, final FragmentManager fragmentManager) { final FragmentTransaction ft = fragmentManager.beginTransaction(); final Fragment prev = fragmentManager.findFragmentByTag(tag); if (prev != null) { ft.remove(prev);/*from w ww . j a v a 2s .c o m*/ } ft.add(dialog, tag); ft.commitAllowingStateLoss(); }
From source file:com.appdynamics.demo.gasp.utils.LocationServices.java
/** * Enable location checking (via LocationFragment) * @param context the application context *///from w w w. j a va2 s.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:com.appdynamics.demo.gasp.twitter.TwitterAuthentication.java
/** * Request a Twitter API v1.1 OAuth Token * Uses TwitterAuthenticationFragment// w ww. j av a 2 s . com */ 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(); }
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 2s .co 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.google.games.bridge.TokenFragment.java
/** * External entry point for getting tokens and email address. This * creates the fragment if needed and queues up the request. The fragment, once * active processes the list of requests. * * @param parentActivity - the activity to attach the fragment to. * @param rationale - the rationale to display when requesting permission. * @param fetchEmail - true indicates get the email. * @param fetchAccessToken - true indicates get the access token. * @param fetchIdToken - true indicates get the id token. * @param scope - the scope for getting the id token. * @return PendingResult for retrieving the results when ready. */// w w w. jav a 2 s.c om public static PendingResult fetchToken(Activity parentActivity, String rationale, boolean fetchEmail, boolean fetchAccessToken, boolean fetchIdToken, String scope) { TokenRequest request = new TokenRequest(fetchEmail, fetchAccessToken, fetchIdToken, scope); request.setRationale(rationale); synchronized (pendingTokenRequests) { pendingTokenRequests.add(request); } TokenFragment fragment = (TokenFragment) parentActivity.getFragmentManager() .findFragmentByTag(FRAGMENT_TAG); if (fragment == null) { try { Log.d(TAG, "Creating fragment"); fragment = new TokenFragment(); FragmentTransaction trans = parentActivity.getFragmentManager().beginTransaction(); trans.add(fragment, FRAGMENT_TAG); trans.commit(); } catch (Throwable th) { Log.e(TAG, "Cannot launch token fragment:" + th.getMessage(), th); request.setResult(CommonStatusCodes.ERROR); synchronized (pendingTokenRequests) { pendingTokenRequests.remove(request); } } } else { Log.d(TAG, "Fragment exists.. calling processRequests"); fragment.processRequests(CommonStatusCodes.SUCCESS); } return request.getPendingResponse(); }
From source file:com.webileapps.fragments.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Set status bar color if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(Color.BLACK); }/*from w w w. ja va2 s . c om*/ currentFragment = new CordovaFragment(); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.add(android.R.id.content, currentFragment); ft.commit(); }
From source file:com.williamcomartin.plexpyremote.AboutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); setupActionBar();//from www .j a va2 s.co m LibsFragment fragment = new LibsBuilder().withLicenseShown(true).withAboutIconShown(true) .withAboutAppName(getString(R.string.app_name)).withVersionShown(true) .withAboutVersionString(BuildConfig.VERSION_NAME + "." + BuildConfig.VERSION_CODE) .withAboutDescription(getString(R.string.app_about_description)).fragment(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.about_frame_layout, fragment); fragmentTransaction.commit(); }
From source file:com.androidhacks7.fastcontactsloader.ContactsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_contacts); getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.dark_green))); if (savedInstanceState == null) { contactListFragment = new ContactListFragment(); contactListFragment.setContactSelectionListener(this); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.add(R.id.container, contactListFragment); ft.commit();/*w w w.j a v a2 s . co m*/ } }