Java Code Examples for android.app.Activity#getFragmentManager()

The following examples show how to use android.app.Activity#getFragmentManager() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private String getFragmentForActivity(Activity activity) {
    StringBuilder builder = new StringBuilder();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        android.app.FragmentManager manager = activity.getFragmentManager();
        List<android.app.Fragment> list = manager.getFragments();
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                android.app.Fragment fragment = list.get(i);
                if (fragment != null && fragment.isVisible()) {
                    builder.append(fragment.getClass().getSimpleName() + "#" + fragment.getId());
                    if (i < list.size() - 1) {
                        builder.append(";");
                    }
                }
            }
        }
    }
    return builder.toString();
}
 
Example 2
/**
 * Performs video playback of passed videoId in fragment video container.
 * Video container is attached to img container of an row item.
 *
 * @param activity activity context in which adapter is set
 * @param img      img container to which video container is going to be attached
 * @param videoId  yt video id which is going to be played
 * @param position list item position of img container
 */
public static void onClick(Activity activity, View img, String videoId, int position) {
    if (activity != null) {
        FragmentManager fragmentManager = activity.getFragmentManager();
        YoutubeOverlayFragment yt = (YoutubeOverlayFragment) fragmentManager.findFragmentByTag(YoutubeOverlayFragment.class.getName());
        if (yt != null) {
            yt.onClick(img, videoId, position);
        }
    }
}
 
Example 3
private static void showDialog(Activity activity, Class clazz, String tag) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(tag);
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    try {
        ((DialogFragment) clazz.newInstance()).show(ft, tag);
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source Project: webrtc_android   File: Permissions.java    License: MIT License 5 votes vote down vote up
@RequiresApi(M)
public static void request2(Activity activity, String permission, Consumer<Integer> callback) {
    final FragmentManager fm = activity.getFragmentManager();
    if (!has(activity, permission)) {
        fm.beginTransaction().add(new PermissionRequestFragment(new String[]{permission}, callback), null).commitAllowingStateLoss();
    } else {
        callback.accept(PERMISSION_GRANTED);
    }
}
 
Example 5
public ListPagerAdapter(Activity activity) {
        super(activity.getFragmentManager());
        actionBar = activity.getActionBar();

        mFragments.add(FIRST_TAB, new QuestionsListFragment());
//        fragment.add(FIRST_TAB, new QuestionsGridFragment());
        mFragments.add(SECOND_TAB, new StaredListFragment());
    }
 
Example 6
private static Object createFragment(boolean isSupport, Activity activity,
                                     Instrumentation instrumentation, int color)
        throws InterruptedException {
    final Object fragment;
    if (isSupport) {
        fragment = SupportTestFragment.getInstance(color);
        final android.support.v4.app.FragmentManager supportFragmentManager = ((FragmentActivity) activity).getSupportFragmentManager();
        supportFragmentManager
                .beginTransaction()
                .replace(R.id.content, (android.support.v4.app.Fragment) fragment, FRAGMENT_TAG)
                .commit();
        instrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                supportFragmentManager.executePendingTransactions();
            }
        });
    } else {
        fragment = TestFragment.getInstance(color);
        final FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager
                .beginTransaction()
                .replace(R.id.content, (Fragment) fragment, FRAGMENT_TAG)
                .commit();
        instrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                fragmentManager.executePendingTransactions();
            }
        });
    }
    Thread.sleep(WAIT_INIT);
    return fragment;
}
 
Example 7
private PermissionHandler genHandler(@NonNull Activity activity) {
    android.app.FragmentManager fragmentManager = activity.getFragmentManager();
    android.app.Fragment fragment = fragmentManager.findFragmentByTag(DefaultPermissionHandler.FRAGMENT_TAG);
    if (!(fragment instanceof DefaultPermissionHandler)) {
        fragment = new DefaultPermissionHandler();
        fragmentManager.beginTransaction()
                .add(fragment, DefaultPermissionHandler.FRAGMENT_TAG)
                .commitAllowingStateLoss();
    }

    return (PermissionHandler) fragment;
}
 
Example 8
public static void showAbout(Activity activity) {
  FragmentManager fm = activity.getFragmentManager();
  FragmentTransaction ft = fm.beginTransaction();
  Fragment prev = fm.findFragmentByTag(ABOUT_DIALOG_TAG);
  if (prev != null) {
    ft.remove(prev);
  }
  ft.addToBackStack(null);

  new AboutDialog().show(ft, "about_dialog");
}
 
Example 9
Source Project: memoir   File: RTProxyImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
/* @inheritDoc */
   public void openDialogFragment(String fragmentTag, DialogFragment fragment) {
       Activity activity = getActivity();
       if (activity != null) {
           FragmentManager fragmentMgr = activity.getFragmentManager();
           FragmentTransaction ft = fragmentMgr.beginTransaction();
           DialogFragment oldFragment = (DialogFragment) fragmentMgr
                   .findFragmentByTag(fragmentTag);
           if (oldFragment == null) {
               fragment.show(ft, fragmentTag);
           }
       }
   }
 
Example 10
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
        throws JSONException {

    if (action.equals("new")) {
        // TODO: Make default title translatable
        String title = "Please sign below";
        String htmlFile = null;
        String save = "Save";
        String clear = "Clear";

        if (args.length() >= 4) {
            htmlFile = args.getString(3);
        }

        if (args.length() >= 3) {
            clear = args.getString(2);
        }

        if (args.length() >= 2) {
            save = args.getString(1);
        }

        if (args.length() >= 1) {
            title = args.getString(0);
        }

        Activity act = this.cordova.getActivity();
        FragmentManager fragmentManager = act.getFragmentManager();
        SignatureDialogFragment signatureDialogFragment = new SignatureDialogFragment(title, save, clear, htmlFile, callbackContext);
        signatureDialogFragment.show(fragmentManager, "dialog");

        return true;
    } else {
        callbackContext.error("Unknown action: " + action);

        return false;
    }
}
 
Example 11
Source Project: react-native-GPay   File: DialogModule.java    License: MIT License 5 votes vote down vote up
/**
 * Creates a new helper to work with either the FragmentManager or the legacy support
 * FragmentManager transparently. Returns null if we're not attached to an Activity.
 *
 * DO NOT HOLD LONG-LIVED REFERENCES TO THE OBJECT RETURNED BY THIS METHOD, AS THIS WILL CAUSE
 * MEMORY LEAKS.
 */
private @Nullable FragmentManagerHelper getFragmentManagerHelper() {
  Activity activity = getCurrentActivity();
  if (activity == null) {
    return null;
  }
  if (activity instanceof FragmentActivity) {
    return new FragmentManagerHelper(((FragmentActivity) activity).getSupportFragmentManager());
  } else {
    return new FragmentManagerHelper(activity.getFragmentManager());
  }
}
 
Example 12
Source Project: SugarTask   File: SugarTask.java    License: Apache License 2.0 5 votes vote down vote up
private void unregisterHookToContext(@NonNull Activity activity) {
    FragmentManager manager = activity.getFragmentManager();

    HookFragment hookFragment = (HookFragment) manager.findFragmentByTag(TAG_HOOK);
    if (hookFragment != null) {
        hookFragment.postEnable = false;
        manager.beginTransaction().remove(hookFragment).commitAllowingStateLoss();
    }
}
 
Example 13
public BuffersPagerAdapter(Activity activity, long connectionId, BuffersToDisplay display) {
    super(activity.getFragmentManager());
    TapchatApp.get().inject(this);

    mConnectionId = connectionId;
    mDisplay = display;
}
 
Example 14
Source Project: YummyTextSwitcher   File: NumberAnimDialog.java    License: MIT License 5 votes vote down vote up
public static void showDialog(Activity activity){
    FragmentManager fragmentManager = activity.getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    Fragment prev = fragmentManager.findFragmentByTag("NumberAnimDialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    NumberAnimDialog dialogFragment =  new NumberAnimDialog();
    dialogFragment.show(ft, "NumberAnimDialog");
}
 
Example 15
/**
 * Handles exiting from yt full screen videoContainer
 *
 * @param activity activity in which on backpressed is handled
 * @return returns if action was handled
 */
public static boolean onBackPressed(Activity activity) {
    if (activity != null) {
        FragmentManager fragmentManager = activity.getFragmentManager();
        YoutubeOverlayFragment yt = (YoutubeOverlayFragment) fragmentManager.findFragmentByTag(YoutubeOverlayFragment.class.getName());
        if (yt != null) {
            yt.onBackPressed();
        }
    }
    return false;
}
 
Example 16
Source Project: memento   File: Memento.java    License: Apache License 2.0 5 votes vote down vote up
private static void retainNative(Activity activity, String fragmentTag) {
    log("Entering native fragments mode");
    android.app.FragmentManager fragmentManager = activity.getFragmentManager();
    MementoMethods memento = (MementoMethods) fragmentManager.findFragmentByTag(fragmentTag);

    if (memento == null) {
        memento = buildMemento(activity);
        fragmentManager.beginTransaction().add((android.app.Fragment) memento, fragmentTag).commit();
    } else {
        restoreMemento(activity, memento);
    }
}
 
Example 17
Source Project: weex   File: FragmentCompatFramework.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public FragmentManager getFragmentManager(Activity activity) {
  return activity.getFragmentManager();
}
 
Example 18
Source Project: mirror   File: ArtikOAuthManager.java    License: Apache License 2.0 4 votes vote down vote up
public static ArtikOAuthManager newInstance(Activity activity, String clientId) {
    // create the ClientParametersAuthentication object
    final ClientParametersAuthentication client = new ClientParametersAuthentication(clientId, null);

    // create JsonFactory
    final JsonFactory jsonFactory = new JacksonFactory();

    // setup credential store
    final SharedPreferencesCredentialStore credentialStore =
            new SharedPreferencesCredentialStore(activity, CREDENTIALS_STORE_PREF_FILE, jsonFactory);

    // setup authorization flow
    AuthorizationFlow flow = new AuthorizationFlow.Builder(
            BearerToken.authorizationHeaderAccessMethod(),
            AndroidHttp.newCompatibleTransport(),
            jsonFactory,
            new GenericUrl(TOKEN_URL),
            client,
            client.getClientId(),
            AUTHORIZATION_URL)
            //.setScopes(scopes)
            .setCredentialStore(credentialStore)
            .build();

    // setup authorization UI controller
    AuthorizationDialogController controller =
            new DialogFragmentController(activity.getFragmentManager()) {
                @Override
                public String getRedirectUri() throws IOException {
                    return REDIRECT_URL;
                }

                @Override
                public boolean isJavascriptEnabledForWebView() {
                    return true;
                }

                @Override
                public boolean disableWebViewCache() {
                    return false;
                }

                @Override
                public boolean removePreviousCookie() {
                    return false;
                }
            };
    return new ArtikOAuthManager(flow, controller);
}
 
Example 19
/**
 * @param activity 父activity
 * @param uri      地址
 */
public FragmentTransactionUriRequest(@NonNull Activity activity, String uri) {
    super(activity, uri);
    mFragmentManager = activity.getFragmentManager();
}
 
Example 20
Source Project: Flora   File: LifeAttachManager.java    License: MIT License 2 votes vote down vote up
/**
 * 找到指定的Activity绑定的空白Fragment,如果没有则会自动绑定一个
 *
 * @param activity
 * @return
 */
public LifeListenFragment getLifeListenerFragment(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    return findFragment(fm);
}