Example usage for android.support.v4.app FragmentActivity getSupportFragmentManager

List of usage examples for android.support.v4.app FragmentActivity getSupportFragmentManager

Introduction

In this page you can find the example usage for android.support.v4.app FragmentActivity getSupportFragmentManager.

Prototype

public FragmentManager getSupportFragmentManager() 

Source Link

Document

Return the FragmentManager for interacting with fragments associated with this activity.

Usage

From source file:com.facebook.login.WebViewLoginMethodHandler.java

@Override
boolean tryAuthorize(final LoginClient.Request request) {
    Bundle parameters = new Bundle();
    if (!Utility.isNullOrEmpty(request.getPermissions())) {
        String scope = TextUtils.join(",", request.getPermissions());
        parameters.putString(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
        addLoggingExtra(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
    }//  ww w . j  a v  a  2 s . c o m

    DefaultAudience audience = request.getDefaultAudience();
    parameters.putString(ServerProtocol.DIALOG_PARAM_DEFAULT_AUDIENCE, audience.getNativeProtocolAudience());

    AccessToken previousToken = AccessToken.getCurrentAccessToken();
    String previousTokenString = previousToken != null ? previousToken.getToken() : null;
    if (previousTokenString != null && (previousTokenString.equals(loadCookieToken()))) {
        parameters.putString(ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, previousTokenString);
        // Don't log the actual access token, just its presence or absence.
        addLoggingExtra(ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, AppEventsConstants.EVENT_PARAM_VALUE_YES);
    } else {
        // The call to clear cookies will create the first instance of CookieSyncManager if
        // necessary
        Utility.clearFacebookCookies(loginClient.getActivity());
        addLoggingExtra(ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, AppEventsConstants.EVENT_PARAM_VALUE_NO);
    }

    WebDialog.OnCompleteListener listener = new WebDialog.OnCompleteListener() {
        @Override
        public void onComplete(Bundle values, FacebookException error) {
            onWebDialogComplete(request, values, error);
        }
    };

    e2e = LoginClient.getE2E();
    addLoggingExtra(ServerProtocol.DIALOG_PARAM_E2E, e2e);

    FragmentActivity fragmentActivity = loginClient.getActivity();
    WebDialog.Builder builder = new AuthDialogBuilder(fragmentActivity, request.getApplicationId(), parameters)
            .setE2E(e2e).setIsRerequest(request.isRerequest()).setOnCompleteListener(listener)
            .setTheme(FacebookSdk.getWebDialogTheme());
    loginDialog = builder.build();

    FacebookDialogFragment dialogFragment = new FacebookDialogFragment();
    dialogFragment.setRetainInstance(true);
    dialogFragment.setDialog(loginDialog);
    dialogFragment.show(fragmentActivity.getSupportFragmentManager(), FacebookDialogFragment.TAG);

    return true;
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog telling the user what to do before the QR code scanner is
 * displayed, and starts the QR code activity.
 * //from ww w.j  a v  a 2  s.c o  m
 * @param activity
 *            the caller activity
 */
public static void pairInboundInstructions(final FragmentActivity activity) {
    DialogFragment dialog = new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            View layout = View.inflate(getContext(), R.layout.pair_inbound_instructions, null);
            builder.setView(layout);
            ((TextView) layout.findViewById(R.id.instructions))
                    .setText(getResources().getString(R.string.new_inbound_instructions));
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                    intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
                    getActivity().startActivityForResult(intent, MainActivity.QR_CODE_SCANNED);
                }
            });
            return builder.create();
        }
    };
    dialog.show(activity.getSupportFragmentManager(), "instruction");
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static FragmentTransaction transactionFragment(final Fragment fragment, final View container,
        final FragmentActivity activity) {
    FragmentManager manager = activity.getSupportFragmentManager();
    Fragment tabFragment = manager.findFragmentById(android.R.id.tabcontent);
    // check if is opened inside an actionbar tab, which is
    // another fragment
    if (tabFragment != null) {
        manager = tabFragment.getChildFragmentManager();
    }//from ww w  .java 2  s.co m
    FragmentTransaction transaction = null;
    transaction = manager.beginTransaction();
    transaction.add(container.getId(), fragment);
    transaction.commit();
    return transaction;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static FragmentTransaction removeFragment(final Fragment fragment, final View container,
        final FragmentActivity activity) {
    FragmentManager manager = activity.getSupportFragmentManager();
    Fragment tabFragment = manager.findFragmentById(android.R.id.tabcontent);
    // check if is opened inside an actionbar tab, which is
    // another fragment
    if (tabFragment != null) {
        manager = tabFragment.getChildFragmentManager();
    }//from w w  w.  j a v a 2 s .  c  o  m
    FragmentTransaction transaction = null;
    transaction = manager.beginTransaction();
    transaction.remove(fragment);
    transaction.commitAllowingStateLoss();
    return transaction;
}

From source file:de.avpptr.umweltzone.map.MapFragment.java

private void setUpMapIfNeeded() {
    if (mMap == null) {
        FragmentActivity activity = getActivity();
        Context context = activity.getApplicationContext();
        int connectionResult = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        if (connectionResult != ConnectionResult.SUCCESS) {
            final String connectionResultString = ConnectionResultHelper
                    .connectionResultToString(connectionResult);
            mTracking.trackError(TrackingPoint.GooglePlayServicesNotAvailableError, connectionResultString);
            showGooglePlayServicesErrorDialog(activity, connectionResult);
        } else {// www  .j ava  2s.c o m
            FragmentManager fragmentManager = activity.getSupportFragmentManager();
            SupportMapFragment mapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.map);
            mMap = mapFragment.getMap();
            if (mMap != null) {
                onMapIsSetUp(activity);
            }
        }
    }
}

From source file:com.sbstrm.appirater.Appirater.java

private void showRateDialog(FragmentActivity activity) {
    RateDialog rateDialog = new RateDialog();
    Bundle args = new Bundle();
    String appName = mContext.getString(R.string.appirator_app_title);
    args.putString("title", String.format(mContext.getString(R.string.appirator_rate_title), appName));
    args.putString("message", String.format(mContext.getString(R.string.appirator_message), appName));
    args.putString("yes", String.format(mContext.getString(R.string.appirator_button_rate), appName));
    args.putString("later", mContext.getString(R.string.appirator_button_rate_later));
    args.putString("no", mContext.getString(R.string.appirator_button_rate_cancel));
    rateDialog.setArguments(args);/* w  ww  .  j a  va  2  s . c  o m*/
    rateDialog.show(activity.getSupportFragmentManager(), "appirater");
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog that informs the user of the result of a pairing action,
 * and saves the newly paired outbound device if the operation was
 * successful./* w  ww.j av  a  2  s .c om*/
 * 
 * <p>
 * Once the user taps on the OK button,
 * {@link Activity#startActivity(Intent)} is called to get back to the
 * {@link MainActivity}.
 * 
 * @param device
 *            the outbound device to be paired
 * @param activity
 *            the caller activity
 */
public static void onPairingOutbound(final PairedDevice device, final FragmentActivity activity) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            try {
                builder.setMessage(getString(R.string.failed_pairing));
                if (device != null) {
                    PairOutboundActivity.savePairing(device, activity);
                    builder.setMessage(getResources().getString(R.string.successful_pairing, device.type));
                }
            } catch (IOException e) {
                // TODO let user know
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // back to main screen
                    startActivity(new Intent(activity, MainActivity.class));
                }
            });
            return builder.create();
        }
    }.show(activity.getSupportFragmentManager(), "code");
}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

/**
 * ??/*from   ww w . j a v  a  2s .c  om*/
 * @param fragmentTag fragmenttag
 * @return Fragment??
 */
@Override
public boolean isFragmentTop(String fragmentTag) {
    int size = mActivities.size();
    if (size > 0) {
        WeakReference<BaseActivity> ref = mActivities.get(size - 1);
        BaseActivity item = ref.get();
        if (item != null && item == this) {
            FragmentActivity activity = item;
            FragmentManager manager = activity.getSupportFragmentManager();
            if (manager != null) {
                int count = manager.getBackStackEntryCount();
                if (count >= 1) {
                    FragmentManager.BackStackEntry entry = manager.getBackStackEntryAt(count - 1);
                    if (entry.getName().equalsIgnoreCase(fragmentTag)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

From source file:com.dat255.ht13.grupp23.view.MapView.java

/**
 * Initiating the GoogleMap and all necessary items for the configuration
 * //  www .j a  v  a  2  s. co m
 * @param fragmentActivity
 */
private void initiateMap(FragmentActivity fragmentActivity) {
    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(fragmentActivity.getBaseContext());

    // Showing status
    if (status != ConnectionResult.SUCCESS) { // Google Play Services are
        // not available

        int requestCode = 10;
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, fragmentActivity, requestCode);
        dialog.show();

    } else { // Google Play Services are available

        // Getting reference to the SupportMapFragment of activity_main.xml
        SupportMapFragment fm = (SupportMapFragment) fragmentActivity.getSupportFragmentManager()
                .findFragmentById(R.id.map);

        // Getting GoogleMap object from the fragment
        googleMap = fm.getMap();

        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);

        // Getting LocationManager object from System Service
        // LOCATION_SERVICE
        LocationManager locationManager = (LocationManager) fragmentActivity
                .getSystemService(Context.LOCATION_SERVICE);

        // Creating a criteria object to retrieve provider
        Criteria criteria = new Criteria();

        // Getting the name of the best provider
        String provider = locationManager.getBestProvider(criteria, true);

        // Getting Current Location
        Location location = locationManager.getLastKnownLocation(provider);

        if (location != null) {
            onLocationChanged(location);
            locationManager.requestLocationUpdates(provider, 20000, 0, this);
        }
    }

}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows the about screen./*from   w w w.  j  a v a  2 s . co m*/
 * 
 * @param activity
 *            the caller activity
 */
public static void showAbout(final FragmentActivity activity) {
    DialogFragment dialog = new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            View layout = View.inflate(getContext(), R.layout.about, null);
            String version = "alpha";
            try {
                version = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
            ((TextView) layout.findViewById(R.id.title))
                    .setText(activity.getResources().getString(R.string.title_about_dialog, version));
            ((TextView) layout.findViewById(R.id.build_date)).setText(
                    activity.getResources().getString(R.string.build_date_about, getBuildDate(activity)));
            // make links clickable
            ((TextView) layout.findViewById(R.id.description))
                    .setMovementMethod(LinkMovementMethod.getInstance());
            builder.setView(layout);
            return builder.create();
        }
    };
    dialog.show(activity.getSupportFragmentManager(), "about");
}