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:de.azapps.mirakel.helper.TaskDialogHelpers.java

@SuppressWarnings("boxing")
public static void handleRecurrence(final FragmentActivity activity, final Task task, final boolean isDue,
        final ExecInterface callback) {
    final FragmentManager fm = activity.getSupportFragmentManager();
    Optional<Recurring> recurringOptional = isDue ? task.getRecurrence() : task.getRecurringReminder();
    boolean isExact = false;
    if (recurringOptional.isPresent()) {
        Recurring recurring = recurringOptional.get();
        isExact = recurring.isExact();//from   w w  w .  j a  v  a 2  s. c  o m
        Log.d(TAG, "exact: " + isExact);
        if (recurring.getDerivedFrom().isPresent()) {
            final Optional<Recurring> master = Recurring.get(recurring.getDerivedFrom().get());
            if (master.isPresent()) {
                recurring = master.get();
            }
        }
    }
    final RecurrencePickerDialog rp = RecurrencePickerDialog.newInstance(new OnRecurrenceSetListener() {
        @Override
        public void onCustomRecurrenceSetInterval(final boolean isDue, final int intervalYears,
                final int intervalMonths, final int intervalDays, final int intervalHours,
                final int intervalMinutes, @NonNull final Optional<Calendar> startDate,
                @NonNull final Optional<Calendar> endDate, final boolean isExact) {
            final Recurring r = Recurring.newRecurring("", intervalMinutes, intervalHours, intervalDays,
                    intervalMonths, intervalYears, isDue, startDate, endDate, true, isExact,
                    new SparseBooleanArray());
            setRecurence(task, isDue, r.getId(), callback);
        }

        @Override
        public void onCustomRecurrenceSetWeekdays(final boolean isDue, @NonNull final List<Integer> weekdays,
                @NonNull final Optional<Calendar> startDate, @NonNull final Optional<Calendar> endDate,
                final boolean isExact) {
            final SparseBooleanArray weekdaysArray = new SparseBooleanArray();
            for (final int day : weekdays) {
                weekdaysArray.put(day, true);
            }
            final Recurring r = Recurring.newRecurring("", 0, 0, 0, 0, 0, isDue, startDate, endDate, true,
                    isExact, weekdaysArray);
            setRecurence(task, isDue, r.getId(), callback);
        }

        @Override
        public void onNoRecurrenceSet() {
            setRecurence(task, isDue, -1, callback);
        }

        @Override
        public void onRecurrenceSet(final Recurring r) {
            setRecurence(task, isDue, r.getId(), callback);
        }
    }, recurringOptional, isDue, MirakelCommonPreferences.isDark(), isExact);
    rp.show(fm, "reccurence");
}

From source file:gr.scify.newsum.ui.PlusClientFragment.java

/**
 * Attach a {@link PlusClient} managing fragment to you activity.
 *
 * @param activity The activity to attach the fragment to.
 * @param visibleActivities An array of visible activities to request.
 * @return The fragment managing a {@link PlusClient}.
 */// w w w  . j  av a 2  s .co  m
public static PlusClientFragment getPlusClientFragment(FragmentActivity activity, String[] visibleActivities) {
    if (!(activity instanceof OnSignedInListener)) {
        throw new IllegalArgumentException(
                "The activity must implement OnSignedInListener to receive callbacks.");
    }

    // Check if the fragment is already attached.
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(TAG_PLUS_CLIENT);
    if (fragment instanceof PlusClientFragment) {
        // The fragment is attached.  If it has the right visible activities, return it.
        if (Arrays.equals(visibleActivities, fragment.getArguments().getStringArray(ARG_VISIBLE_ACTIVITIES))) {
            return (PlusClientFragment) fragment;
        }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // If a fragment was already attached, remove it to clean up.
    if (fragment != null) {
        fragmentTransaction.remove(fragment);
    }

    // Create a new fragment and attach it to the fragment manager.
    Bundle arguments = new Bundle();
    arguments.putStringArray(ARG_VISIBLE_ACTIVITIES, visibleActivities);
    PlusClientFragment signInFragment = new PlusClientFragment();
    signInFragment.setArguments(arguments);
    fragmentTransaction.add(signInFragment, TAG_PLUS_CLIENT);
    fragmentTransaction.commit();
    return signInFragment;
}

From source file:org.alfresco.mobile.android.application.fragments.actions.NodeActions.java

public static void download(FragmentActivity activity, Folder parentFolder, Document doc) {
    // Check if File exist
    File folder = AlfrescoStorageManager.getInstance(activity)
            .getDownloadFolder(SessionUtils.getAccount(activity));
    if (folder != null && new File(folder, doc.getName()).exists()) {
        ResolveNamingConflictFragment.newInstance(parentFolder, doc).show(activity.getSupportFragmentManager(),
                ResolveNamingConflictFragment.TAG);
    } else {//from www.ja  v a 2 s  .  co m
        Operator.with(activity).load(new DownloadRequest.Builder(parentFolder, doc, false)
                .setNotificationVisibility(OperationRequest.VISIBILITY_NOTIFICATIONS));
    }
}

From source file:com.sprunck.openit.activity.PlusClientFragment.java

/**
 * Attach a {@link com.google.android.gms.plus.PlusClient} managing fragment to you activity.
 *
 * @param activity The activity to attach the fragment to.
 * @param scopes   The scopes to request permission for.
 * @param actions  An array of actions to request.
 * @return The fragment managing a {@link com.google.android.gms.plus.PlusClient}.
 *///from www.  j av a  2 s  . co m
public static PlusClientFragment getPlusClientFragment(FragmentActivity activity, String[] scopes,
        String[] actions) {
    if (!(activity instanceof OnSignInListener)) {
        throw new IllegalArgumentException(
                "The activity must implement OnSignedInListener to receive callbacks.");
    }

    // Check if the fragment is already attached.
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(TAG_PLUS_CLIENT);
    if (fragment instanceof PlusClientFragment) {
        // The fragment is attached.  If it has the right visible activities, return it.
        if (Arrays.equals(actions, fragment.getArguments().getStringArray(ARG_ACTIONS))) {
            return (PlusClientFragment) fragment;
        }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // If a fragment was already attached, remove it to clean up.
    if (fragment != null) {
        fragmentTransaction.remove(fragment);
    }

    // Create a new fragment and attach it to the fragment manager.
    Bundle arguments = new Bundle();
    arguments.putStringArray(ARG_ACTIONS, actions);
    arguments.putStringArray(ARG_SCOPES, scopes);
    PlusClientFragment signInFragment = new PlusClientFragment();
    signInFragment.setArguments(arguments);
    fragmentTransaction.add(signInFragment, TAG_PLUS_CLIENT);
    fragmentTransaction.commit();
    return signInFragment;
}

From source file:org.alfresco.mobile.android.ui.utils.UIUtils.java

public static void displayTitle(FragmentActivity activity, String title, boolean isUpEnable) {
    if (activity instanceof AppCompatActivity) {
        ActionBar bar = ((AppCompatActivity) activity).getSupportActionBar();

        bar.setDisplayShowTitleEnabled(false);
        bar.setDisplayShowCustomEnabled(true);
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
        bar.setDisplayUseLogoEnabled(false);
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        bar.setHomeButtonEnabled(isUpEnable);

        // If MenuFragment is visible => up is disable.
        Fragment fr = activity.getSupportFragmentManager()
                .findFragmentByTag("org.alfresco.mobile.android.application.fragments.menu.MainMenuFragment");
        if (fr != null && fr.isVisible()) {
            bar.setDisplayHomeAsUpEnabled(false);
            bar.setHomeButtonEnabled(false);
        } else {//from   w w  w  . j a va2  s  .  c  o m
            bar.setDisplayHomeAsUpEnabled(isUpEnable);
        }

        View v = bar.getCustomView();
        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(FragmentActivity.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.app_header_row, null);
        }
        v.setVisibility(View.VISIBLE);

        TextView tv = (TextView) v.findViewById(R.id.toptext);
        if (SessionUtils.getAccount(activity) != null
                && AlfrescoAccountManager.getInstance(activity).hasMultipleAccount()) {
            tv.setText(SessionUtils.getAccount(activity).getTitle());
            tv.setVisibility(View.VISIBLE);
        } else {
            tv.setVisibility(View.GONE);
        }
        tv = (TextView) v.findViewById(R.id.bottomtext);
        tv.setText(title);

        if (bar.getCustomView() == null) {
            bar.setCustomView(v);
        }

        activity.invalidateOptionsMenu();
    }
}

From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java

public static void handleReminder(final FragmentActivity ctx, final Task task,
        final OnTaskChangedListner onSuccess) {
    final Calendar reminder = task.getReminder().or(new GregorianCalendar());
    final FragmentManager fm = ctx.getSupportFragmentManager();
    final SupportDateTimeDialog dtDialog = SupportDateTimeDialog.newInstance(new OnDateTimeSetListener() {
        @Override//from  ww w.ja v  a2 s .c om
        public void onDateTimeSet(final int year, final int month, final int dayOfMonth, final int hourOfDay,
                final int minute) {
            reminder.set(Calendar.YEAR, year);
            reminder.set(Calendar.MONTH, month);
            reminder.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            reminder.set(Calendar.HOUR_OF_DAY, hourOfDay);
            reminder.set(Calendar.MINUTE, minute);
            task.setReminder(of(reminder), true);
            onSuccess.onTaskChanged(task);
        }

        @Override
        public void onNoTimeSet() {
            task.setReminder(Optional.<Calendar>absent());
            onSuccess.onTaskChanged(task);
        }
    }, reminder.get(Calendar.YEAR), reminder.get(Calendar.MONTH), reminder.get(Calendar.DAY_OF_MONTH),
            reminder.get(Calendar.HOUR_OF_DAY), reminder.get(Calendar.MINUTE), true,
            MirakelCommonPreferences.isDark());
    dtDialog.show(fm, "datetimedialog");
}

From source file:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java

/**
 * Convenience routine to show a dialog fragment and start the task
 * //from w ww  .java 2s .c om
 * @param context   Activity of caller
 * @param message   Message to display
 * @param task      Task to run
 */
public static SimpleTaskQueueProgressFragment runTaskWithProgress(final FragmentActivity context, int message,
        FragmentTask task, boolean isIndeterminate, int taskId) {
    SimpleTaskQueueProgressFragment frag = SimpleTaskQueueProgressFragment.newInstance(message, isIndeterminate,
            taskId);
    frag.enqueue(task);
    frag.show(context.getSupportFragmentManager(), (String) null);
    return frag;
}

From source file:com.google.plus.samples.photohunt.PlusClientFragment.java

/**
 * Attach a {@link PlusClient} managing fragment to you activity.
 *
 * @param activity The activity to attach the fragment to.
 * @param scopes The scopes to request permission for.
 * @param visibleActivities An array of visible activities to request.
 * @return The fragment managing a {@link PlusClient}.
 *///  www .  java2 s  .c o m
public static PlusClientFragment getPlusClientFragment(FragmentActivity activity, String[] scopes,
        String[] visibleActivities) {
    if (!(activity instanceof OnSignInListener)) {
        throw new IllegalArgumentException(
                "The activity must implement OnSignedInListener to receive callbacks.");
    }

    // Check if the fragment is already attached.
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(TAG_PLUS_CLIENT);
    if (fragment instanceof PlusClientFragment) {
        // The fragment is attached.  If it has the right visible activities, return it.
        if (Arrays.equals(visibleActivities, fragment.getArguments().getStringArray(ARG_VISIBLE_ACTIVITIES))) {
            return (PlusClientFragment) fragment;
        }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // If a fragment was already attached, remove it to clean up.
    if (fragment != null) {
        fragmentTransaction.remove(fragment);
    }

    // Create a new fragment and attach it to the fragment manager.
    Bundle arguments = new Bundle();
    arguments.putStringArray(ARG_VISIBLE_ACTIVITIES, visibleActivities);
    arguments.putStringArray(ARG_SCOPES, scopes);
    PlusClientFragment signInFragment = new PlusClientFragment();
    signInFragment.setArguments(arguments);
    fragmentTransaction.add(signInFragment, TAG_PLUS_CLIENT);
    fragmentTransaction.commit();
    return signInFragment;
}

From source file:com.gecq.musicwave.cache.ImageCache.java

/**
 * Find and return an existing ImageCache stored in a {@link RetainFragment}
 * , if not found a new one is created using the supplied params and saved
 * to a {@link RetainFragment}/* www  . j a va 2  s.com*/
 *
 * @param activity The calling {@link FragmentActivity}
 * @return An existing retained ImageCache object or a new one if one did
 *         not exist
 */
public static final ImageCache findOrCreateCache(final FragmentActivity activity) {

    // Search for, or create an instance of the non-UI RetainFragment
    final RetainFragment retainFragment = findOrCreateRetainFragment(activity.getSupportFragmentManager());

    // See if we already have an ImageCache stored in RetainFragment
    ImageCache cache = (ImageCache) retainFragment.getObject();

    // No existing ImageCache, create one and store it in RetainFragment
    if (cache == null) {
        cache = getInstance(activity);
        retainFragment.setObject(cache);
    }
    return cache;
}

From source file:com.popdeem.sdk.core.PopdeemSDK.java

/**
* Push the Social Login Flow Fragment to the supplied Activity
*
* @param activity FragmentActivity / AppCompatActivity to show social login flow in
* @param rewards Rewards to add to social login screen
*//*from   www. j  av  a 2  s.  co m*/
private static void pushSocialLoginFragmentToActivity(final FragmentActivity activity,
        ArrayList<PDReward> rewards) {
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    if (rewards != null && rewards.size() > 0) {
        fragmentManager.beginTransaction()
                .add(android.R.id.content, PDUISocialLoginFragment.newInstance(rewards))
                .addToBackStack(PDUISocialLoginFragment.class.getSimpleName()).commit();
    } else {
        fragmentManager.beginTransaction().add(android.R.id.content, PDUISocialLoginFragment.newInstance())
                .addToBackStack(PDUISocialLoginFragment.class.getSimpleName()).commit();
    }
}