Example usage for android.app Activity getFragmentManager

List of usage examples for android.app Activity getFragmentManager

Introduction

In this page you can find the example usage for android.app Activity getFragmentManager.

Prototype

@Deprecated
public FragmentManager getFragmentManager() 

Source Link

Document

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

Usage

From source file:com.jlabs.peepaid.searchviewlay.SearchViewLayout.java

/***
 * Set the fragment which would be shown in the expanded state
 * @param activity to get fragment manager
 * @param contentFragment fragment which needs to be shown.
 * @throws RuntimeException if support version of content fragment already set
 *//*from  w  w w.  j  av  a  2  s  .c o m*/

public void setExpandedContentFragment(Activity activity, android.app.Fragment contentFragment) {
    mExpandedContentFragment = contentFragment;
    mFragmentManager = activity.getFragmentManager();
    mExpandedHeight = Utils.getSizeOfScreen(activity).y;
}

From source file:com.aizen.manga.util.ImageWorker.java

/**
 * Adds an {@link ImageCache} to this {@link ImageWorker} to handle disk and memory bitmap
 * caching./*from   w w  w . j ava2  s  .c  om*/
 * @param activity
 * @param diskCacheDirectoryName See
 * {@link ImageCache.ImageCacheParams#ImageCacheParams(android.content.Context, String)}.
 */
public void addImageCache(Activity activity, String diskCacheDirectoryName) {
    mImageCacheParams = new ImageCache.ImageCacheParams(activity, diskCacheDirectoryName);
    mImageCache = ImageCache.getInstance(activity.getFragmentManager(), mImageCacheParams);
    new CacheAsyncTask().execute(MESSAGE_INIT_DISK_CACHE);
}

From source file:com.embeddedlog.LightUpDroid.LightUpPiSync.java

/**
 * Public constructor. Saves the class context to be able to check the network connectivity
 * and display a progress dialog./*from   www.j av  a 2  s . c o  m*/
 *
 * @param activityContext Context of the activity (no application context) requesting the sync.
 */
public LightUpPiSync(Context activityContext, String alarmFragmentTag) {
    this.mActivityContext = activityContext;
    Activity activity = (Activity) this.mActivityContext;
    this.mAlarmFragment = (AlarmClockFragment) activity.getFragmentManager()
            .findFragmentByTag(alarmFragmentTag);
}

From source file:android.support.v17.leanback.app.BackgroundManager.java

private void createFragment(Activity activity) {
    // Use a fragment to ensure the background manager gets detached properly.
    BackgroundFragment fragment = (BackgroundFragment) activity.getFragmentManager()
            .findFragmentByTag(FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new BackgroundFragment();
        activity.getFragmentManager().beginTransaction().add(fragment, FRAGMENT_TAG).commit();
    } else {// ww  w . ja va 2  s .co  m
        if (fragment.getBackgroundManager() != null) {
            throw new IllegalStateException("Created duplicated BackgroundManager for same "
                    + "activity, please use getInstance() instead");
        }
    }
    fragment.setBackgroundManager(this);
    mFragmentState = fragment;
}

From source file:com.example.android.camera2basic.Camera2VideoFragment.java

private void setUpMediaRecorder() throws IOException {
    final Activity activity = getActivity();
    if (null == activity) {
        return;/*from   w  w  w .j a  va 2  s .  c  o  m*/
    }
    mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
        @Override
        public void onInfo(MediaRecorder mr, int what, int extra) {
            if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
                Toast.makeText(getActivity(), "Video saved: " + mFile, Toast.LENGTH_SHORT).show();
                CameraActivity activity = (CameraActivity) getActivity();
                activity.setTake(true);
                activity.setOnListenAcc(true);
                Camera2BasicFragment fragment = activity.getCamerafragment();
                activity.getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
            }
        }
    });

    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    //10 seconds
    mMediaRecorder.setMaxDuration(10000);
    mMediaRecorder.setOutputFile(getVideoFile(activity).getAbsolutePath());
    mMediaRecorder.setVideoEncodingBitRate(10000000);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int orientation = ORIENTATIONS.get(rotation);
    mMediaRecorder.setOrientationHint(orientation);
    mMediaRecorder.prepare();
}

From source file:com.facebook.react.modules.timepicker.TimePickerDialogModule.java

@ReactMethod
public void open(@Nullable final ReadableMap options, Promise promise) {

    Activity activity = getCurrentActivity();
    if (activity == null) {
        promise.reject(ERROR_NO_ACTIVITY,
                "Tried to open a TimePicker dialog while not attached to an Activity");
        return;/*from  w w  w .  j a v a2  s  .c  o m*/
    }
    // We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
    // (for apps that use it for legacy reasons). This unfortunately leads to some code duplication.
    if (activity instanceof android.support.v4.app.FragmentActivity) {
        android.support.v4.app.FragmentManager fragmentManager = ((android.support.v4.app.FragmentActivity) activity)
                .getSupportFragmentManager();
        android.support.v4.app.DialogFragment oldFragment = (android.support.v4.app.DialogFragment) fragmentManager
                .findFragmentByTag(FRAGMENT_TAG);
        if (oldFragment != null) {
            oldFragment.dismiss();
        }
        SupportTimePickerDialogFragment fragment = new SupportTimePickerDialogFragment();
        if (options != null) {
            Bundle args = createFragmentArguments(options);
            fragment.setArguments(args);
        }
        TimePickerDialogListener listener = new TimePickerDialogListener(promise);
        fragment.setOnDismissListener(listener);
        fragment.setOnTimeSetListener(listener);
        fragment.show(fragmentManager, FRAGMENT_TAG);
    } else {
        FragmentManager fragmentManager = activity.getFragmentManager();
        DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
        if (oldFragment != null) {
            oldFragment.dismiss();
        }
        TimePickerDialogFragment fragment = new TimePickerDialogFragment();
        if (options != null) {
            final Bundle args = createFragmentArguments(options);
            fragment.setArguments(args);
        }
        TimePickerDialogListener listener = new TimePickerDialogListener(promise);
        fragment.setOnDismissListener(listener);
        fragment.setOnTimeSetListener(listener);
        fragment.show(fragmentManager, FRAGMENT_TAG);
    }
}

From source file:com.facebook.react.modules.datepicker.DatePickerDialogModule.java

/**
 * Show a date picker dialog.//from   w  w  w. jav a2 s .  co m
 *
 * @param options a map containing options. Available keys are:
 *
 * <ul>
 *   <li>{@code date} (timestamp in milliseconds) the date to show by default</li>
 *   <li>
 *     {@code minDate} (timestamp in milliseconds) the minimum date the user should be allowed
 *     to select
 *   </li>
 *   <li>
 *     {@code maxDate} (timestamp in milliseconds) the maximum date the user should be allowed
 *     to select
 *    </li>
 * </ul>
 *
 * @param promise This will be invoked with parameters action, year,
 *                month (0-11), day, where action is {@code dateSetAction} or
 *                {@code dismissedAction}, depending on what the user did. If the action is
 *                dismiss, year, month and date are undefined.
 */
@ReactMethod
public void open(@Nullable final ReadableMap options, Promise promise) {
    Activity activity = getCurrentActivity();
    if (activity == null) {
        promise.reject(ERROR_NO_ACTIVITY,
                "Tried to open a DatePicker dialog while not attached to an Activity");
        return;
    }
    // We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
    // (for apps that use it for legacy reasons). This unfortunately leads to some code duplication.
    if (activity instanceof android.support.v4.app.FragmentActivity) {
        android.support.v4.app.FragmentManager fragmentManager = ((android.support.v4.app.FragmentActivity) activity)
                .getSupportFragmentManager();
        android.support.v4.app.DialogFragment oldFragment = (android.support.v4.app.DialogFragment) fragmentManager
                .findFragmentByTag(FRAGMENT_TAG);
        if (oldFragment != null) {
            oldFragment.dismiss();
        }
        SupportDatePickerDialogFragment fragment = new SupportDatePickerDialogFragment();
        if (options != null) {
            final Bundle args = createFragmentArguments(options);
            fragment.setArguments(args);
        }
        final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
        fragment.setOnDismissListener(listener);
        fragment.setOnDateSetListener(listener);
        fragment.show(fragmentManager, FRAGMENT_TAG);
    } else {
        FragmentManager fragmentManager = activity.getFragmentManager();
        DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
        if (oldFragment != null) {
            oldFragment.dismiss();
        }
        DatePickerDialogFragment fragment = new DatePickerDialogFragment();
        if (options != null) {
            final Bundle args = createFragmentArguments(options);
            fragment.setArguments(args);
        }
        final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
        fragment.setOnDismissListener(listener);
        fragment.setOnDateSetListener(listener);
        fragment.show(fragmentManager, FRAGMENT_TAG);
    }
}

From source file:com.hijridatepicker.HijriDatePickerAndroidModule.java

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved./*from   w  w  w  .  j  ava2 s.  c  om*/
 * <p>
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 * Show a date picker dialog.
 *
 * @param options a map containing options. Available keys are:
 *                <p>
 *                <ul>
 *                <li>{@code date} (timestamp in milliseconds) the date to show by default</li>
 *                <li>
 *                {@code minDate} (timestamp in milliseconds) the minimum date the user should be allowed
 *                to select
 *                </li>
 *                <li>
 *                {@code maxDate} (timestamp in milliseconds) the maximum date the user should be allowed
 *                to select
 *                </li>
 *                <li>
 *                {@code mode} To set the date picker mode to ' no_arrows/default' ,
 *                currently there's only one mode for HijriDatePicker, so this field works only with mode no_arrows/default
 *                </li>
 *                <li>
 *                {@code weekDayLabels} (array of strings) the day labels that appears on the calendar
 *                </li>
 *                </ul>
 * @param promise This will be invoked with parameters action, year,
 *                month (0-11), day, where action is {@code dateSetAction} or
 *                {@code dismissedAction}, depending on what the user did. If the action is
 *                dismiss, year, month and date are undefined.
 */
@ReactMethod
public void open(@Nullable final ReadableMap options, Promise promise) {
    try {
        Activity activity = getCurrentActivity();
        if (activity == null) {
            promise.reject(ERROR_NO_ACTIVITY,
                    "Tried to open a DatePicker dialog while not attached to an Activity");
            return;
        }
        // We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
        // (for apps that use it for legacy reasons). This unfortunately leads to some code duplication.
        if (activity instanceof android.support.v4.app.FragmentActivity) {
            android.support.v4.app.FragmentManager fragmentManager = ((android.support.v4.app.FragmentActivity) activity)
                    .getSupportFragmentManager();
            android.support.v4.app.DialogFragment oldFragment = (android.support.v4.app.DialogFragment) fragmentManager
                    .findFragmentByTag(FRAGMENT_TAG);
            if (oldFragment != null) {
                oldFragment.dismiss();
            }
            SupportHijriDatePickerDialogFragment fragment = new SupportHijriDatePickerDialogFragment();
            if (options != null) {
                final Bundle args = createFragmentArguments(options, promise);
                if (args == null)
                    return;
                fragment.setArguments(args);
            }
            final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
            fragment.setOnDismissListener(listener);
            fragment.setOnDateSetListener(listener);
            fragment.setOnExceptionListener(listener);
            fragment.show(fragmentManager, FRAGMENT_TAG);
        } else {
            FragmentManager fragmentManager = activity.getFragmentManager();
            DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
            if (oldFragment != null) {
                oldFragment.dismiss();
            }
            HijriDatePickerDialogFragment fragment = new HijriDatePickerDialogFragment();
            if (options != null) {
                final Bundle args = createFragmentArguments(options, promise);
                if (args == null)
                    return;
                fragment.setArguments(args);
            }
            final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
            fragment.setOnDismissListener(listener);
            fragment.setOnDateSetListener(listener);
            fragment.setOnExceptionListener(listener);
            fragment.show(fragmentManager, FRAGMENT_TAG);
        }
    } catch (Exception e) {
        promise.reject(ERROR_OPEN,
                "Exception happened while executing open method, details: " + e.getMessage());
    }
}

From source file:com.breadwallet.BreadWalletApp.java

public void promptForAuthentication(Activity context, int mode, PaymentRequestEntity requestEntity,
        String message, String title, PaymentRequestWrapper paymentRequest, boolean forcePasscode) {
    Log.e(TAG, "promptForAuthentication: " + mode);
    if (context == null)
        return;// w  w  w. ja  va2 s.c o  m
    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Activity.KEYGUARD_SERVICE);

    boolean useFingerPrint = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED
            && mFingerprintManager.isHardwareDetected() && mFingerprintManager.hasEnrolledFingerprints();
    if (mode == BRConstants.AUTH_FOR_PAY) {
        long limit = KeyStoreManager.getSpendLimit(context);
        long totalSent = BRWalletManager.getInstance(context).getTotalSent();

        if (requestEntity != null)
            if (limit <= totalSent + requestEntity.amount) {
                useFingerPrint = false;
            }
    }

    if (mode == BRConstants.AUTH_FOR_LIMIT || mode == BRConstants.AUTH_FOR_PHRASE) {
        useFingerPrint = false;
    }

    if (KeyStoreManager.getFailCount(context) != 0) {
        useFingerPrint = false;
    }
    long passTime = KeyStoreManager.getLastPasscodeUsedTime(context);
    if (passTime + TimeUnit.MILLISECONDS.convert(2, TimeUnit.DAYS) <= System.currentTimeMillis()) {
        useFingerPrint = false;
    }
    if (forcePasscode)
        useFingerPrint = false;

    if (keyguardManager.isKeyguardSecure()) {
        if (useFingerPrint) {
            // This happens when no fingerprints are registered.
            FingerprintDialogFragment fingerprintDialogFragment = new FingerprintDialogFragment();
            fingerprintDialogFragment.setMode(mode);
            fingerprintDialogFragment.setPaymentRequestEntity(requestEntity, paymentRequest);
            fingerprintDialogFragment.setMessage(message);
            fingerprintDialogFragment.setTitle(message != null ? "" : title);
            if (!context.isDestroyed())
                fingerprintDialogFragment.show(context.getFragmentManager(),
                        FingerprintDialogFragment.class.getName());
        } else {
            PasswordDialogFragment passwordDialogFragment = new PasswordDialogFragment();
            passwordDialogFragment.setMode(mode);
            passwordDialogFragment.setPaymentRequestEntity(requestEntity, paymentRequest);
            passwordDialogFragment.setVerifyOnlyTrue();
            passwordDialogFragment.setMessage(message);
            if (!context.isDestroyed())
                passwordDialogFragment.show(context.getFragmentManager(),
                        PasswordDialogFragment.class.getName());
        }
    } else {
        showDeviceNotSecuredWarning(context);
    }

}

From source file:com.hijacker.MainActivity.java

static void checkForUpdate(final Activity activity, final boolean showMessages) {
    //Can be called from any thread, blocks until the job is finished
    Runnable runnable = new Runnable() {
        @Override/*from   w  ww .j av a  2 s  .  c  o m*/
        public void run() {
            progress.setIndeterminate(false);
        }
    };
    if (showMessages) {
        runInHandler(new Runnable() {
            @Override
            public void run() {
                progress.setIndeterminate(true);
            }
        });
    }
    Socket socket = connect();
    if (socket == null) {
        if (showMessages) {
            runInHandler(runnable);
            Snackbar.make(rootView, activity.getString(R.string.server_error), Snackbar.LENGTH_SHORT).show();
        }
        return;
    }

    try {
        PrintWriter in = new PrintWriter(socket.getOutputStream());
        BufferedReader out = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        in.print(REQ_VERSION + '\n');
        in.flush();

        int latestCode = Integer.parseInt(out.readLine());
        String latestName = out.readLine();
        String latestLink = out.readLine();

        in.print(REQ_EXIT + '\n');
        in.flush();
        in.close();
        out.close();
        socket.close();

        if (latestCode > versionCode) {
            final UpdateConfirmDialog dialog = new UpdateConfirmDialog();
            dialog.newVersionCode = latestCode;
            dialog.newVersionName = latestName;
            dialog.link = latestLink;
            runInHandler(new Runnable() {
                @Override
                public void run() {
                    dialog.show(activity.getFragmentManager(), "UpdateConfirmDialog");
                }
            });
        } else {
            if (showMessages)
                Snackbar.make(rootView, activity.getString(R.string.already_on_latest), Snackbar.LENGTH_SHORT)
                        .show();
        }
    } catch (IOException | NumberFormatException e) {
        Log.e("HIJACKER/update", e.toString());
        if (showMessages)
            Snackbar.make(rootView, activity.getString(R.string.unknown_error), Snackbar.LENGTH_SHORT).show();
    } finally {
        if (showMessages)
            runInHandler(runnable);
    }
}