android.app.Fragment

Here are the examples of the java api android.app.Fragment taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

451 Examples 7

19 Source : FragmentTransitionLauncher.java
with Apache License 2.0
from zixpo

public void prepare(Fragment toFragment) {
    final Bundle transitionBundle = TransitionBundleFactory.createTransitionBundle(context, fromView, bitmap);
    if (Build.VERSION.SDK_INT >= 21) {
        toFragment.setSharedElementEnterTransition(new ChangeBounds());
        toFragment.setSharedElementReturnTransition(new ChangeBounds());
    }
    toFragment.setArguments(transitionBundle);
}

19 Source : FragmentTransition.java
with Apache License 2.0
from zixpo

public clreplaced FragmentTransition {

    private static TimeInterpolator interpolator;

    private int duration = 1000;

    private View toView;

    private androidx.fragment.app.Fragment supportFragment;

    private Fragment fragment;

    private FragmentTransition(Fragment fragment) {
        this.fragment = fragment;
    }

    private FragmentTransition(androidx.fragment.app.Fragment fragment) {
        this.supportFragment = fragment;
    }

    public static FragmentTransition with(Fragment fragment) {
        return new FragmentTransition(fragment);
    }

    public static FragmentTransition with(androidx.fragment.app.Fragment fragment) {
        return new FragmentTransition(fragment);
    }

    public FragmentTransition to(View toView) {
        this.toView = toView;
        return this;
    }

    public FragmentTransition duration(int duration) {
        this.duration = duration;
        return this;
    }

    public FragmentTransition interpolator(TimeInterpolator interpolator) {
        FragmentTransition.interpolator = interpolator;
        return this;
    }

    public ExitFragmentTransition start(Bundle savedInstanceState) {
        if (interpolator == null) {
            interpolator = new DecelerateInterpolator();
        }
        final Context context = toView.getContext();
        final Bundle bundle;
        if (fragment == null) {
            bundle = supportFragment.getArguments();
        } else {
            bundle = fragment.getArguments();
        }
        final MoveData moveData = TransitionAnimation.startAnimation(context, toView, bundle, savedInstanceState, duration, interpolator);
        if (fragment == null) {
            return new ExitFragmentTransition(supportFragment, moveData);
        }
        return new ExitFragmentTransition(fragment, moveData);
    }
}

19 Source : FragmentTransition.java
with Apache License 2.0
from zixpo

public static FragmentTransition with(Fragment fragment) {
    return new FragmentTransition(fragment);
}

19 Source : ExitFragmentTransition.java
with Apache License 2.0
from zixpo

public clreplaced ExitFragmentTransition {

    private final MoveData moveData;

    private Fragment fragment;

    private androidx.fragment.app.Fragment supportFragment;

    private TimeInterpolator interpolator;

    public ExitFragmentTransition(Fragment fragment, MoveData moveData) {
        this.fragment = fragment;
        this.moveData = moveData;
    }

    public ExitFragmentTransition(final androidx.fragment.app.Fragment fragment, MoveData moveData) {
        this.supportFragment = fragment;
        this.moveData = moveData;
    }

    public ExitFragmentTransition interpolator(TimeInterpolator interpolator) {
        this.interpolator = interpolator;
        return this;
    }

    public void startExitListening() {
        startExitListening(null);
    }

    public void startExitListening(final Runnable popBackStackRunnable) {
        if (interpolator == null) {
            interpolator = new DecelerateInterpolator();
        }
        final View toView = moveData.toView;
        toView.setFocusableInTouchMode(true);
        toView.requestFocus();
        toView.setOnKeyListener(new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    if (event.getAction() != KeyEvent.ACTION_UP) {
                        return true;
                    }
                    TransitionAnimation.startExitAnimation(moveData, interpolator, new Runnable() {

                        @Override
                        public void run() {
                            if (popBackStackRunnable != null) {
                                popBackStackRunnable.run();
                                return;
                            }
                            if (fragment == null) {
                                if (!supportFragment.isResumed()) {
                                    return;
                                }
                                final FragmentManager fragmentManager = supportFragment.getFragmentManager();
                                if (fragmentManager != null) {
                                    fragmentManager.popBackStack();
                                }
                            } else {
                                if (!fragment.isResumed()) {
                                    return;
                                }
                                final android.app.FragmentManager fragmentManager = fragment.getFragmentManager();
                                if (fragmentManager != null) {
                                    fragmentManager.popBackStack();
                                }
                            }
                        }
                    });
                    return true;
                }
                return false;
            }
        });
    }
}

19 Source : DrawerActivity.java
with MIT License
from ZafraniTechLLC

private void itemsSelected() {
    if (this.contentLayout == null) {
        return;
    }
    final Fragment fragment = getFragmentManager().findFragmentByTag(ItemFragment.TAG);
    if (fragment == null) {
        showFragment(new ItemFragment(), ItemFragment.TAG);
    } else {
        showFragment(fragment, ItemFragment.TAG);
    }
}

19 Source : DrawerActivity.java
with MIT License
from ZafraniTechLLC

private void newsSelected() {
    if (this.contentLayout == null) {
        return;
    }
    final Fragment fragment = getFragmentManager().findFragmentByTag(NewsFragment.TAG);
    if (fragment == null) {
        showFragment(new NewsFragment(), NewsFragment.TAG);
    } else {
        showFragment(fragment, NewsFragment.TAG);
    }
}

19 Source : DrawerActivity.java
with MIT License
from ZafraniTechLLC

// endregion
// region methods
private void mapSelected() {
    if (this.contentLayout == null) {
        return;
    }
    final Fragment fragment = getFragmentManager().findFragmentByTag(PUBGMapFragment.TAG);
    if (fragment == null) {
        showFragment(new PUBGMapFragment(), PUBGMapFragment.TAG);
    } else {
        showFragment(fragment, PUBGMapFragment.TAG);
    }
}

19 Source : BaseActivity.java
with MIT License
from ZafraniTechLLC

public void showFragment(@NonNull final Fragment fragment, @IdRes final int contentView, @NonNull final String tag) {
    final FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
    final Fragment topFragment = getTopFragment();
    if (topFragment == null) {
        fragTransaction.add(contentView, fragment, tag);
    } else {
        fragTransaction.replace(contentView, fragment, tag);
    }
    fragTransaction.commit();
    getFragmentManager().executePendingTransactions();
}

19 Source : BaseActivity.java
with MIT License
from ZafraniTechLLC

protected void showFragment(@NonNull final Fragment fragment, @NonNull final String tag) {
    showFragment(fragment, getContentView(), tag);
}

19 Source : SoftKeyboardHelper.java
with Apache License 2.0
from yuanhoujun

public static void hideKeyboardDelayed(@NonNull final Fragment fragment, int delayMillis) {
    Message message = mMainHandler.obtainMessage(MESSAGE_WHAT_HIDE_KEYBOARD, fragment);
    mMainHandler.sendMessageDelayed(message, delayMillis);
}

19 Source : SoftKeyboardHelper.java
with Apache License 2.0
from yuanhoujun

public static boolean hideKeyboard(@NonNull Fragment fragment) {
    if (fragment.isDetached() || fragment.isRemoving() || null == fragment.getActivity())
        return true;
    InputMethodManager inputMethodManager = (InputMethodManager) fragment.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    View rootView = fragment.getView();
    if (rootView instanceof ViewGroup) {
        View focusedChild = ((ViewGroup) rootView).getFocusedChild();
        if (null != focusedChild) {
            return inputMethodManager.hideSoftInputFromWindow(focusedChild.getWindowToken(), 0);
        }
    }
    return true;
}

19 Source : PluginActivityLauncher.java
with Apache License 2.0
from yjfnypeu

@Override
public void open(Fragment fragment) {
    if (TextUtils.isEmpty(alias())) {
        super.open(fragment);
    } else {
        open(fragment.getActivity());
    }
}

19 Source : PreferenceActivity.java
with GNU General Public License v2.0
from yeriomin

@Override
public void onAttachFragment(Fragment fragment) {
    super.onAttachFragment(fragment);
    if (fragment instanceof PreferenceFragment) {
        this.fragment = (PreferenceFragment) fragment;
    }
}

19 Source : FragmentSource.java
with Apache License 2.0
from yanzhenjie

/**
 * <p>android.app.Fragment Wrapper.</p>
 * Created by Zhenjie Yan on 2017/5/1.
 */
public clreplaced FragmentSource extends Source {

    private Fragment mFragment;

    public FragmentSource(Fragment fragment) {
        this.mFragment = fragment;
    }

    @Override
    public Context getContext() {
        return mFragment.getActivity();
    }

    @Override
    public void startActivity(Intent intent) {
        mFragment.startActivity(intent);
    }

    @Override
    public void startActivityForResult(Intent intent, int requestCode) {
        mFragment.startActivityForResult(intent, requestCode);
    }

    @Override
    public boolean isShowRationalePermission(String permission) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
            return false;
        return mFragment.shouldShowRequestPermissionRationale(permission);
    }
}

19 Source : Album.java
with Apache License 2.0
from yanzhenjie

/**
 * Preview Album.
 */
public static BasicGalleryWrapper<GalleryAlbumWrapper, AlbumFile, String, AlbumFile> galleryAlbum(Fragment fragment) {
    return new GalleryAlbumWrapper(fragment.getActivity());
}

19 Source : Album.java
with Apache License 2.0
from yanzhenjie

/**
 * Select videos.
 */
public static Choice<VideoMultipleWrapper, VideoSingleWrapper> video(Fragment fragment) {
    return new VideoChoice(fragment.getActivity());
}

19 Source : Album.java
with Apache License 2.0
from yanzhenjie

/**
 * Select images.
 */
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(Fragment fragment) {
    return new ImageChoice(fragment.getActivity());
}

19 Source : Album.java
with Apache License 2.0
from yanzhenjie

/**
 * Open the camera from the activity.
 */
public static Camera<ImageCameraWrapper, VideoCameraWrapper> camera(Fragment fragment) {
    return new AlbumCamera(fragment.getActivity());
}

19 Source : Album.java
with Apache License 2.0
from yanzhenjie

/**
 * Select images and videos.
 */
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(Fragment fragment) {
    return new AlbumChoice(fragment.getActivity());
}

19 Source : Album.java
with Apache License 2.0
from yanzhenjie

/**
 * Preview picture.
 */
public static BasicGalleryWrapper<GalleryWrapper, String, String, String> gallery(Fragment fragment) {
    return new GalleryWrapper(fragment.getActivity());
}

19 Source : RxLifecycle.java
with Apache License 2.0
from xuexiangjys

// ===========================获得生命周期绑定管理者,进行生命周期的绑定==============================//
/**
 * 获得生命周期绑定管理者,进行生命周期的绑定
 *
 * @param activity
 * @return
 */
public static LifecycleManager with(Activity activity) {
    if (activity instanceof FragmentActivity) {
        return with((FragmentActivity) activity);
    }
    FragmentManager fm = activity.getFragmentManager();
    Fragment fragment = fm.findFragmentByTag(FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new LifecycleFragment();
        fm.beginTransaction().add(fragment, FRAGMENT_TAG).commitAllowingStateLoss();
        fm.executePendingTransactions();
    }
    return (LifecycleManager) fragment;
}

19 Source : RxLifecycle.java
with Apache License 2.0
from xuexiangjys

/**
 * 获得生命周期绑定管理者,进行生命周期的绑定
 *
 * @param fragment
 * @return
 */
public static LifecycleManager with(Fragment fragment) {
    return with(fragment.getActivity());
}

19 Source : MainActivity.java
with GNU General Public License v3.0
from XndroidDev

public clreplaced MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

    private Fragment mXndroidFragment;

    private WebViewFragment mXXnetFragment;

    private WebViewFragment mFqrouterFragment;

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            if (ASK_VPN_PERMISSION == requestCode) {
                FqrouterManager.onRequestResult(resultCode, this);
            } else {
                super.onActivityResult(requestCode, resultCode, data);
            }
        } catch (Exception e) {
            LogUtils.e("failed to handle onActivityResult", e);
        }
    }

    private AboutFragment mAboutFragment;

    private ViewGroup mRootView;

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

    @Override
    protected void onPause() {
        super.onPause();
        AppModel.sIsForeground = false;
        AppModel.sUpdateInfoUI = null;
        mXXnetFragment.postPause();
        mFqrouterFragment.postPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        AppModel.sIsForeground = true;
    }

    private void switchFragment(Fragment fragment) {
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.content_main, fragment);
        transaction.commit();
    }

    public void postStop() {
        mXXnetFragment.postStop();
        mFqrouterFragment.postStop();
        this.finish();
        AppModel.sActivity = null;
    }

    private void restart() {
        Intent intent = getIntent();
        finish();
        startActivity(intent);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onDestroy() {
        AppModel.sActivity = null;
        super.onDestroy();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (AppModel.sAppStoped) {
            Log.w("xndroid_log", "Xndroid is exiting, restart the activity.");
            restart();
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return;
        }
        if (AppModel.sContext != null && AppModel.sService == null) {
            AppModel.fatalError("error: App is launched but LaunchService exit");
            return;
        }
        AppModel.sActivity = this;
        if (AppModel.sContext == null) {
            AppModel.appInit(getApplicationContext());
        }
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
            }
        });
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        if (!AppModel.sEnableXXNet) {
            navigationView.getMenu().removeItem(R.id.nav_xxnet);
        // navigationView.getMenu().removeItem(R.id.nav_lightning);
        }
        mRootView = (ViewGroup) findViewById(R.id.content_main);
        if (mXndroidFragment == null)
            mXndroidFragment = new XndroidFragment();
        if (mXXnetFragment == null) {
            mXXnetFragment = new WebViewFragment();
            mXXnetFragment.setURL("http://127.0.0.1:8085");
        }
        if (mFqrouterFragment == null) {
            mFqrouterFragment = new WebViewFragment();
            mFqrouterFragment.setURL("http://127.0.0.1:" + FqrouterManager.getPort());
        }
        if (mAboutFragment == null)
            mAboutFragment = new AboutFragment();
        switchFragment(mXndroidFragment);
        if (getIntent().getBooleanExtra("auto_start", false))
            moveTaskToBack(true);
    }

    public void launchUrl(String url) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        startActivity(intent);
    }

    private void reboot() {
        restart();
        AppModel.appStop();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private void clear_cert_cache() {
        ShellUtils.execBusybox("rm -r " + AppModel.sXndroidFile + "/xxnet/data/gae_proxy/certs");
        AppModel.showToast(getString(R.string.restart_tip));
        new Thread(new Runnable() {

            @Override
            public void run() {
                reboot();
            }
        }).start();
    }

    private void updateXXNet(final boolean rmdata) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                AppModel.showToast(getString(R.string.wait_for));
                if (XXnetManager.updateXXNet(rmdata)) {
                    AppModel.showToast(getString(R.string.restart_tip));
                    reboot();
                }
            }
        }).start();
    }

    private void updateXXNet() {
        new AlertDialog.Builder(AppModel.sActivity).setreplacedle(R.string.xxnet_update_replacedle).setMessage(R.string.xxnet_update_tip).setNegativeButton(R.string.update_remove, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                updateXXNet(true);
            }
        }).setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                updateXXNet(false);
            }
        }).create().show();
    }

    private void selectComponent() {
        LayoutInflater inflater = getLayoutInflater();
        View view = inflater.inflate(R.layout.component_setting, null);
        CheckBox checkXXNet = view.findViewById(R.id.launch_check_xxnet);
        CheckBox checkTeredo = view.findViewById(R.id.launch_check_teredo);
        CheckBox checkFqDNS = view.findViewById(R.id.launch_check_fqdns);
        final CheckBox checkAutoTeredo = view.findViewById(R.id.launch_check_teredo_ipv6);
        final CheckBox checkNotification = view.findViewById(R.id.launch_check_notify);
        CheckBox checkAutoStart = view.findViewById(R.id.launch_check_auto_start);
        Spinner spinnerLaunch = view.findViewById(R.id.launch_mode);
        Spinner spinnerNotify = view.findViewById(R.id.launch_notify_mode);
        boolean enableXXnet = AppModel.sPreferences.getBoolean(AppModel.PRE_ENABLE_XXNET, true);
        boolean enableFqDNS = AppModel.sPreferences.getBoolean(AppModel.PRE_ENABLE_FQDNS, true);
        boolean enableTeredo = AppModel.sPreferences.getBoolean(AppModel.PRE_ENABLE_TEREDO, true);
        boolean autoTeredo = AppModel.sPreferences.getBoolean(AppModel.PRE_AUTO_TEREDO, false);
        boolean enableNotification = AppModel.sPreferences.getBoolean(AppModel.PRE_ENABLE_NOTIFICATION, true);
        boolean autoStart = AppModel.sPreferences.getBoolean(AppModel.PRE_AUTO_START, false);
        spinnerLaunch.setSelection(AppModel.sPreferences.getInt(LaunchService.PER_ROOT_MODE, 0));
        spinnerLaunch.setEnabled(ShellUtils.isRoot());
        spinnerNotify.setSelection(AppModel.sPreferences.getInt(UpdateManager.PER_UPDATE_POLICY, UpdateManager.UPDATE_ALL));
        checkXXNet.setChecked(enableXXnet);
        checkFqDNS.setChecked(enableFqDNS);
        checkTeredo.setChecked(enableTeredo);
        checkAutoTeredo.setChecked(autoTeredo);
        checkAutoTeredo.setEnabled(enableTeredo);
        checkNotification.setChecked(enableNotification);
        checkNotification.setEnabled(enableXXnet);
        checkAutoStart.setChecked(autoStart);
        checkXXNet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                checkNotification.setEnabled(isChecked);
                AppModel.sPreferences.edit().putBoolean(AppModel.PRE_ENABLE_XXNET, isChecked).apply();
            }
        });
        checkFqDNS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                AppModel.sPreferences.edit().putBoolean(AppModel.PRE_ENABLE_FQDNS, isChecked).apply();
            }
        });
        checkTeredo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                checkAutoTeredo.setEnabled(isChecked);
                AppModel.sPreferences.edit().putBoolean(AppModel.PRE_ENABLE_TEREDO, isChecked).apply();
            }
        });
        checkAutoTeredo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                AppModel.sPreferences.edit().putBoolean(AppModel.PRE_AUTO_TEREDO, isChecked).apply();
            }
        });
        checkNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                AppModel.sPreferences.edit().putBoolean(AppModel.PRE_ENABLE_NOTIFICATION, isChecked).apply();
            }
        });
        checkAutoStart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                AppModel.sPreferences.edit().putBoolean(AppModel.PRE_AUTO_START, isChecked).apply();
            }
        });
        spinnerLaunch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                AppModel.sPreferences.edit().putInt(LaunchService.PER_ROOT_MODE, position).apply();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        spinnerNotify.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                AppModel.sPreferences.edit().putInt(UpdateManager.PER_UPDATE_POLICY, position).apply();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        new AlertDialog.Builder(AppModel.sActivity).setreplacedle(R.string.launch_component).setView(view).setPositiveButton(R.string.reboot_app, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        reboot();
                    }
                }).start();
            }
        }).setNegativeButton(R.string.ok, null).create().show();
    }

    private void proxySetting() {
        LayoutInflater inflater = getLayoutInflater();
        View view = inflater.inflate(R.layout.proxy_setting, null);
        final Spinner proxyMode = view.findViewById(R.id.proxy_mode);
        final ListView listView = view.findViewById(R.id.proxy_app_list);
        final ViewGroup group = view.findViewById(R.id.proxy_container);
        final List<String> list = AppModel.loadPackageList();
        int mode = AppModel.sPreferences.getInt(PRE_PROXY_MODE, 0);
        proxyMode.setSelection(mode);
        if (AppModel.PROXY_MODE_ALL == mode || AppModel.PROXY_MODE_NONE == mode) {
            group.removeView(listView);
        }
        proxyMode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                int origin_mode = AppModel.sPreferences.getInt(PRE_PROXY_MODE, 0);
                AppModel.sPreferences.edit().putInt(PRE_PROXY_MODE, position).apply();
                View appList = group.findViewById(R.id.proxy_app_list);
                if (AppModel.PROXY_MODE_ALL == position || AppModel.PROXY_MODE_NONE == position) {
                    if (appList != null) {
                        group.removeView(appList);
                    }
                } else {
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !AppModel.sIsRootMode) {
                        proxyMode.setSelection(origin_mode);
                        AppModel.sPreferences.edit().putInt(PRE_PROXY_MODE, origin_mode).apply();
                        AppModel.showToast(getString(R.string.NO_INDIVIDUAL_SUPPORT));
                        return;
                    }
                    if (appList == null) {
                        group.addView(listView);
                    }
                    String myPkg = getPackageName();
                    if (AppModel.PROXY_MODE_WHITELIST == position) {
                        if (!list.contains(myPkg)) {
                            LogUtils.d("add proxy list:" + myPkg);
                            list.add(myPkg);
                            AppModel.savePackageList(list);
                        }
                    } else if (AppModel.PROXY_MODE_BACKLIST == position) {
                        if (list.contains(myPkg)) {
                            LogUtils.d("remove proxy list:" + myPkg);
                            list.remove(myPkg);
                            AppModel.savePackageList(list);
                        }
                    }
                }
                if ((AppModel.PROXY_MODE_NONE == position || AppModel.PROXY_MODE_WHITELIST == position) && !AppModel.sIsRootMode && ShellUtils.isRoot()) {
                    AppModel.showToast(getString(R.string.VPN_ROOT_GAE_tip));
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        listView.setAdapter(new PackageAdapter(this) {

            @Override
            boolean isPackageChecked(String packageName) {
                return list.contains(packageName);
            }

            @Override
            void onPackageChecked(String packageName, boolean checked) {
                LogUtils.d("select " + packageName + (checked ? " checked" : " not checked"));
                if (checked) {
                    if (!list.contains(packageName)) {
                        list.add(packageName);
                        AppModel.savePackageList(list);
                    }
                } else {
                    if (list.contains(packageName)) {
                        list.remove(packageName);
                        AppModel.savePackageList(list);
                    }
                }
            }
        });
        new AlertDialog.Builder(AppModel.sActivity).setreplacedle(R.string.proxy_setting).setView(view).setPositiveButton(R.string.reboot_app, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        reboot();
                    }
                }).start();
            }
        }).create().show();
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        int[] rootActions = new int[] { R.id.action_import_sys_cert, R.id.action_remove_sys_cert };
        for (int id : rootActions) {
            MenuItem item = menu.findItem(id);
            if (item != null)
                item.setEnabled(ShellUtils.isRoot());
        }
        int[] xxnetActions = new int[] { R.id.action_update_xxnet, R.id.action_import_cert, R.id.action_import_sys_cert, R.id.action_remove_sys_cert, R.id.action_clear_cert };
        if (!AppModel.sEnableXXNet) {
            for (int id : xxnetActions) {
                MenuItem item = menu.findItem(id);
                if (item != null)
                    menu.removeItem(id);
            }
        }
        // menu.findItem(R.id.action_update_xxnet).setEnabled(AppModel.sEnableXXNet);
        return true;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.xndroid_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.gereplacedemId();
        // noinspection SimplifiableIfStatement
        if (id == R.id.action_export_log) {
            AppModel.exportLogs();
        } else if (id == R.id.action_import_cert) {
            XXnetManager.importCert();
        } else if (id == R.id.action_check_update) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    AppModel.showToast(getString(R.string.getting_version));
                    UpdateManager.checkUpdate(true);
                }
            }).start();
        } else if (id == R.id.action_exit) {
            AppModel.appStop();
        } else if (id == R.id.action_clear_cert) {
            clear_cert_cache();
        } else if (id == R.id.action_import_sys_cert) {
            XXnetManager.importSystemCert();
        } else if (id == R.id.action_remove_sys_cert) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    XXnetManager.cleanSystemCert();
                }
            }).start();
        } else if (id == R.id.action_update_xxnet) {
            updateXXNet();
        } else if (id == R.id.action_launch_component) {
            selectComponent();
        } else if (id == R.id.action_proxy_setting) {
            proxySetting();
        } else {
            return super.onOptionsItemSelected(item);
        }
        return true;
    }

    public void showXXnet() {
        switchFragment(mXXnetFragment);
    }

    public void showFqrouter() {
        switchFragment(mFqrouterFragment);
    }

    public void startLightning() {
        Intent intent = new Intent(AppModel.sContext, acr.browser.lightning.MainActivity.clreplaced);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.gereplacedemId();
        if (id == R.id.nav_about) {
            switchFragment(mAboutFragment);
        } else if (id == R.id.nav_xndroid) {
            switchFragment(mXndroidFragment);
        } else if (id == R.id.nav_xxnet) {
            switchFragment(mXXnetFragment);
        } else if (id == R.id.nav_exit) {
            AppModel.appStop();
        } else if (id == R.id.nav_lightning) {
            startLightning();
        } else if (id == R.id.nav_fqrouter) {
            switchFragment(mFqrouterFragment);
        }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

19 Source : SettingsActivity.java
with Apache License 2.0
from xiaojieonly

@Override
public void startWithFragment(String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, @StringRes int replacedleRes, @StringRes int shortreplacedleRes) {
    Intent intent = onBuildStartFragmentIntent(fragmentName, args, replacedleRes, shortreplacedleRes);
    if (resultTo == null) {
        startActivityForResult(intent, REQUEST_CODE_FRAGMENT);
    } else {
        resultTo.startActivityForResult(intent, resultRequestCode);
    }
}

19 Source : OverScrollDemoActivity.java
with BSD 2-Clause "Simplified" License
from XanderWang

private void replaceMainFragment(Fragment fragment, int replacedleResId) {
    getFragmentManager().beginTransaction().setCustomAnimations(R.animator.fade_in_slow, R.animator.fade_out_quick).replace(R.id.fragment_placeholder, fragment).commit();
    getSupportActionBar().setreplacedle(replacedleResId);
}

19 Source : FragmentLauncher.java
with Apache License 2.0
from wurensen

/**
 * Created by LanceWu on 2019/1/31.<br/>
 * 通过fragment启动界面
 */
public clreplaced FragmentLauncher implements Launcher {

    private Fragment mFragment;

    public void setFragment(Fragment fragment) {
        mFragment = fragment;
    }

    @Override
    public void startActivityForResult(Intent intent, int requestCode) {
        if (mFragment == null) {
            return;
        }
        LogUtils.d("startActivityForResult!requestCode=" + requestCode);
        mFragment.startActivityForResult(intent, requestCode);
    }
}

19 Source : FragmentLauncher.java
with Apache License 2.0
from wurensen

public void setFragment(Fragment fragment) {
    mFragment = fragment;
}

19 Source : SettingActivity.java
with MIT License
from WithLei

@Override
protected void initView() {
    initSlidr();
    initToolBar(true, "设置");
    Fragment to = new SettingFragment();
    getFragmentManager().beginTransaction().replace(R.id.container, to).commit();
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

/**
 * fragment管理类
 * Created by xiaoguang on 2017/2/23.
 */
public clreplaced FragmentUtil {

    private static FragmentUtil instance;

    public FragmentActivity act;

    private FragmentManager fm;

    public static FragmentUtil init(FragmentActivity act) {
        if (instance == null || instance.act != act) {
            instance = new FragmentUtil(act);
        }
        return instance;
    }

    public FragmentUtil(FragmentActivity act) {
        this.act = act;
        fm = act.getFragmentManager();
    }

    public void replace(int containerId, Fragment fragment) {
        if (currentFragment == fragment) {
            return;
        }
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(containerId, fragment);
        ft.commitAllowingStateLoss();
        currentFragment = fragment;
    }

    public void replaceHasHistory(int containerId, Fragment fragment) {
        if (currentFragment == fragment) {
            return;
        }
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(containerId, fragment);
        // 添加这个会在按返回键的时候先退出fragment,一些特殊场合可能用到,但效果其实不理想
        ft.addToBackStack(null);
        ft.commitAllowingStateLoss();
        currentFragment = fragment;
    }

    /**
     * 记录已添加的fragment
     */
    private ArrayList<Fragment> fs = new ArrayList<Fragment>();

    /**
     * 记录当前show的fragment
     */
    private Fragment currentFragment;

    /**
     * 添加fragment,这中方式的fragment需要用show来显示
     */
    public void add(int containerId, Fragment fragment) {
        if (!fs.contains(fragment)) {
            fs.add(fragment);
            fm.beginTransaction().add(containerId, fragment).commit();
        }
    }

    /**
     * 添加带tag的fragment
     */
    public void add(int containerId, Fragment fragment, String tag) {
        if (!fs.contains(fragment)) {
            fs.add(fragment);
            fm.beginTransaction().add(containerId, fragment, tag).commit();
        }
    }

    public void addAll(int containerId, List<Fragment> fragments) {
        for (Fragment fragment : fragments) {
            add(containerId, fragment);
        }
    }

    // public void addAll(int containerId, List<Fragment> fragments){
    // fs.addAll(fragments);
    // FragmentTransaction ft = fm.beginTransaction();
    // for (int i = 0; i < fs.size(); i++) {
    // ft.add(i,fs.get(i));
    // }
    // ft.commit();
    // }
    /**
     * 使用本方法前必须先add
     */
    public void show(Fragment fragment) {
        if (currentFragment == fragment) {
            // 如果是当前fragment,则不重新show一遍了,无意义
            return;
        }
        FragmentTransaction ft = fm.beginTransaction();
        for (Fragment f : fs) {
            ft.hide(f);
        }
        ft.show(fragment);
        ft.commit();
        currentFragment = fragment;
    }

    /**
     * 移除add过的fragment
     */
    public void remove(Fragment fragment) {
        if (fs.contains(fragment)) {
            fs.remove(fragment);
            fm.beginTransaction().remove(fragment).commit();
        }
    }

    /**
     * 清空所有fragment
     */
    public void removeAll() {
        FragmentTransaction ft = fm.beginTransaction();
        for (Fragment f : fs) {
            ft.remove(f);
        }
        ft.commitAllowingStateLoss();
    }

    /**
     * 清空所有带此tag的fragment
     */
    public void removeAll(String tag) {
        FragmentTransaction ft = fm.beginTransaction();
        for (Fragment f : fs) {
            if (f.getTag().equals(tag))
                ft.remove(f);
        }
        ft.commitAllowingStateLoss();
    }

    /**
     * 清空所有除了带此tag的fragment
     */
    public void removeAllExcept(String tag) {
        FragmentTransaction ft = fm.beginTransaction();
        for (Fragment f : fs) {
            if (f.getTag() != null && !f.getTag().equals(tag))
                ft.remove(f);
        }
        ft.commitAllowingStateLoss();
    }
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

/**
 * 清空所有除了带此tag的fragment
 */
public void removeAllExcept(String tag) {
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f : fs) {
        if (f.getTag() != null && !f.getTag().equals(tag))
            ft.remove(f);
    }
    ft.commitAllowingStateLoss();
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

/**
 * 移除add过的fragment
 */
public void remove(Fragment fragment) {
    if (fs.contains(fragment)) {
        fs.remove(fragment);
        fm.beginTransaction().remove(fragment).commit();
    }
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

public void replaceHasHistory(int containerId, Fragment fragment) {
    if (currentFragment == fragment) {
        return;
    }
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(containerId, fragment);
    // 添加这个会在按返回键的时候先退出fragment,一些特殊场合可能用到,但效果其实不理想
    ft.addToBackStack(null);
    ft.commitAllowingStateLoss();
    currentFragment = fragment;
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

/**
 * 清空所有fragment
 */
public void removeAll() {
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f : fs) {
        ft.remove(f);
    }
    ft.commitAllowingStateLoss();
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

// public void addAll(int containerId, List<Fragment> fragments){
// fs.addAll(fragments);
// FragmentTransaction ft = fm.beginTransaction();
// for (int i = 0; i < fs.size(); i++) {
// ft.add(i,fs.get(i));
// }
// ft.commit();
// }
/**
 * 使用本方法前必须先add
 */
public void show(Fragment fragment) {
    if (currentFragment == fragment) {
        // 如果是当前fragment,则不重新show一遍了,无意义
        return;
    }
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f : fs) {
        ft.hide(f);
    }
    ft.show(fragment);
    ft.commit();
    currentFragment = fragment;
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

public void addAll(int containerId, List<Fragment> fragments) {
    for (Fragment fragment : fragments) {
        add(containerId, fragment);
    }
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

/**
 * 添加fragment,这中方式的fragment需要用show来显示
 */
public void add(int containerId, Fragment fragment) {
    if (!fs.contains(fragment)) {
        fs.add(fragment);
        fm.beginTransaction().add(containerId, fragment).commit();
    }
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

/**
 * 添加带tag的fragment
 */
public void add(int containerId, Fragment fragment, String tag) {
    if (!fs.contains(fragment)) {
        fs.add(fragment);
        fm.beginTransaction().add(containerId, fragment, tag).commit();
    }
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

public void replace(int containerId, Fragment fragment) {
    if (currentFragment == fragment) {
        return;
    }
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(containerId, fragment);
    ft.commitAllowingStateLoss();
    currentFragment = fragment;
}

19 Source : FragmentUtil.java
with GNU General Public License v3.0
from WeGdufe

/**
 * 清空所有带此tag的fragment
 */
public void removeAll(String tag) {
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f : fs) {
        if (f.getTag().equals(tag))
            ft.remove(f);
    }
    ft.commitAllowingStateLoss();
}

19 Source : MaterialFilePicker.java
with GNU General Public License v2.0
from warren-bank

/**
 * Material File Picker builder
 */
public clreplaced MaterialFilePicker {

    private Activity mActivity;

    private Fragment mFragment;

    private androidx.fragment.app.Fragment mSupportFragment;

    private Clreplaced<? extends FilePickerActivity> mFilePickerClreplaced = FilePickerActivity.clreplaced;

    private Integer mRequestCode;

    private Pattern mFileFilter;

    private Boolean mDirectoriesFilter = false;

    private String mRootPath;

    private String mCurrentPath;

    private Boolean mShowHidden = false;

    private Boolean mCloseable = true;

    private CharSequence mreplacedle;

    public MaterialFilePicker() {
    }

    /**
     * Specifies activity, which will be used to
     * start file picker
     */
    public MaterialFilePicker withActivity(Activity activity) {
        if (mSupportFragment != null || mFragment != null) {
            throw new RuntimeException("You must preplaced either Activity, Fragment or SupportFragment");
        }
        mActivity = activity;
        return this;
    }

    /**
     * Specifies fragment, which will be used to
     * start file picker
     */
    public MaterialFilePicker withFragment(Fragment fragment) {
        if (mSupportFragment != null || mActivity != null) {
            throw new RuntimeException("You must preplaced either Activity, Fragment or SupportFragment");
        }
        mFragment = fragment;
        return this;
    }

    /**
     * Specifies support fragment which will be used to
     * start file picker
     */
    public MaterialFilePicker withSupportFragment(androidx.fragment.app.Fragment fragment) {
        if (mActivity != null || mFragment != null) {
            throw new RuntimeException("You must preplaced either Activity, Fragment or SupportFragment");
        }
        mSupportFragment = fragment;
        return this;
    }

    /**
     * Specifies request code that used in activity result
     *
     * @see <a href="https://developer.android.com/training/basics/intents/result.html">Getting a Result from an Activity</a>
     */
    public MaterialFilePicker withRequestCode(int requestCode) {
        mRequestCode = requestCode;
        return this;
    }

    /**
     * Hides files that matched by specified regular expression.
     * Use {@link MaterialFilePicker#withFilterDirectories withFilterDirectories} method
     * to enable directories filtering
     */
    public MaterialFilePicker withFilter(Pattern pattern) {
        mFileFilter = pattern;
        return this;
    }

    /**
     * If directoriesFilter is true directories will also be affected by filter,
     * the default value of directories filter is false
     *
     * @see MaterialFilePicker#withFilter
     */
    public MaterialFilePicker withFilterDirectories(boolean directoriesFilter) {
        mDirectoriesFilter = directoriesFilter;
        return this;
    }

    /**
     * Specifies root directory for picker,
     * user can't go upper that specified path
     */
    public MaterialFilePicker withRootPath(String rootPath) {
        mRootPath = rootPath;
        return this;
    }

    /**
     * Specifies start directory for picker,
     * which will be shown to user at the beginning
     */
    public MaterialFilePicker withPath(String path) {
        mCurrentPath = path;
        return this;
    }

    /**
     * Show or hide hidden files in picker
     */
    public MaterialFilePicker withHiddenFiles(boolean show) {
        mShowHidden = show;
        return this;
    }

    /**
     * Show or hide close menu in picker
     */
    public MaterialFilePicker withCloseMenu(boolean closeable) {
        mCloseable = closeable;
        return this;
    }

    /**
     * Set replacedle of picker
     */
    public MaterialFilePicker withreplacedle(CharSequence replacedle) {
        mreplacedle = replacedle;
        return this;
    }

    public MaterialFilePicker withCustomActivity(Clreplaced<? extends FilePickerActivity> customActivityClreplaced) {
        mFilePickerClreplaced = customActivityClreplaced;
        return this;
    }

    public CompositeFilter getFilter() {
        ArrayList<FileFilter> filters = new ArrayList<>();
        if (!mShowHidden) {
            filters.add(new HiddenFilter());
        }
        if (mFileFilter != null) {
            filters.add(new PatternFilter(mFileFilter, mDirectoriesFilter));
        }
        return new CompositeFilter(filters);
    }

    /**
     * @return Intent that can be used to start Material File Picker
     */
    public Intent getIntent() {
        CompositeFilter filter = getFilter();
        Activity activity = null;
        if (mActivity != null) {
            activity = mActivity;
        } else if (mFragment != null) {
            activity = mFragment.getActivity();
        } else if (mSupportFragment != null) {
            activity = mSupportFragment.getActivity();
        }
        Intent intent = new Intent(activity, mFilePickerClreplaced);
        intent.putExtra(FilePickerActivity.ARG_FILTER, filter);
        intent.putExtra(FilePickerActivity.ARG_CLOSEABLE, mCloseable);
        if (mRootPath != null) {
            intent.putExtra(FilePickerActivity.ARG_START_PATH, mRootPath);
        }
        if (mCurrentPath != null) {
            intent.putExtra(FilePickerActivity.ARG_CURRENT_PATH, mCurrentPath);
        }
        if (mreplacedle != null) {
            intent.putExtra(FilePickerActivity.ARG_replacedLE, mreplacedle);
        }
        return intent;
    }

    /**
     * Open Material File Picker activity.
     * You should set Activity or Fragment before calling this method
     *
     * @see MaterialFilePicker#withActivity(Activity)
     * @see MaterialFilePicker#withFragment(Fragment)
     * @see MaterialFilePicker#withSupportFragment(androidx.fragment.app.Fragment)
     */
    public void start() {
        if (mActivity == null && mFragment == null && mSupportFragment == null) {
            throw new RuntimeException("You must preplaced Activity/Fragment by calling withActivity/withFragment/withSupportFragment method");
        }
        if (mRequestCode == null) {
            throw new RuntimeException("You must preplaced request code by calling withRequestCode method");
        }
        Intent intent = getIntent();
        if (mActivity != null) {
            mActivity.startActivityForResult(intent, mRequestCode);
        } else if (mFragment != null) {
            mFragment.startActivityForResult(intent, mRequestCode);
        } else {
            mSupportFragment.startActivityForResult(intent, mRequestCode);
        }
    }
}

19 Source : MaterialFilePicker.java
with GNU General Public License v2.0
from warren-bank

/**
 * Specifies fragment, which will be used to
 * start file picker
 */
public MaterialFilePicker withFragment(Fragment fragment) {
    if (mSupportFragment != null || mActivity != null) {
        throw new RuntimeException("You must preplaced either Activity, Fragment or SupportFragment");
    }
    mFragment = fragment;
    return this;
}

19 Source : UiUtils.java
with The Unlicense
from VirgilSecurity

public static void replaceFragment(FragmentManager fm, int containerId, Fragment fragment, String tag) {
    fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(containerId, fragment, tag).addToBackStack(tag).commit();
}

19 Source : UiUtils.java
with The Unlicense
from VirgilSecurity

public static void replaceFragmentNoTag(FragmentManager fm, int containerId, Fragment fragment) {
    fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(containerId, fragment).commit();
}

19 Source : UiUtils.java
with The Unlicense
from VirgilSecurity

public static void showFragment(FragmentManager fm, Fragment fragment) {
    fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).show(fragment).commit();
}

19 Source : UiUtils.java
with The Unlicense
from VirgilSecurity

public static void hideFragment(FragmentManager fm, Fragment fragment) {
    fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).hide(fragment).commit();
}

19 Source : UiUtils.java
with The Unlicense
from VirgilSecurity

public static void replaceFragmentNoBackStack(FragmentManager fm, int containerId, Fragment fragment, String tag) {
    fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(containerId, fragment, tag).commit();
}

19 Source : FragmentUtils.java
with GNU General Public License v2.0
from videgro

public static boolean startReceivingAisFromAntenna(final Fragment fragment, final int reqCode, final int ppm) {
    final String tag = "startReceivingAisFromAntenna (Fragment) - ";
    Log.d(TAG, tag);
    boolean result = false;
    if (fragment != null && fragment.isAdded()) {
        final Intent intent = createOpenDeviceIntent(fragment.getActivity(), createArgumentsToReceiveAis(ppm));
        fragment.startActivityForResult(intent, reqCode);
        result = true;
    } else {
        Log.w(TAG, tag + "Fragment is null or not added to its activity.");
    }
    return result;
}

19 Source : FragmentUtils.java
with GNU General Public License v2.0
from videgro

public static boolean changeRtlSdrPpm(final Fragment fragment, final int reqCode, final int ppm) {
    final String tag = "changeRtlSdrPpm - ";
    Log.d(TAG, tag);
    boolean result = false;
    if (fragment != null && fragment.isAdded()) {
        final Intent intent = createOpenDeviceIntent(fragment.getActivity(), null);
        // Request to change PPM instead of (re)starting RTL-SDR
        intent.putExtra(OpenDeviceActivity.EXTRA_CHANGE_PPM, ppm);
        fragment.startActivityForResult(intent, reqCode);
        result = true;
    } else {
        Log.w(TAG, tag + "Fragment is null or not added to its activity.");
    }
    return result;
}

19 Source : FragmentUtils.java
with GNU General Public License v2.0
from videgro

public static boolean stopReceivingAisFromAntenna(final Fragment fragment, final int reqCode) {
    final String tag = "stopReceivingAisFromAntenna - ";
    Log.d(TAG, tag);
    boolean result = false;
    if (fragment != null && fragment.isAdded()) {
        final Intent intent = createOpenDeviceIntent(fragment.getActivity(), null);
        intent.putExtra(OpenDeviceActivity.EXTRA_DISCONNECT, Boolean.TRUE);
        fragment.startActivityForResult(intent, reqCode);
        result = true;
    } else {
        Log.w(TAG, tag + "Fragment is null or not added to its activity.");
    }
    return result;
}

19 Source : FragmentUtils.java
with GNU General Public License v2.0
from videgro

public static void returnFromFragment(final Fragment fragment) {
    final Activity activity = fragment.getActivity();
    if (activity != null) {
        final FragmentManager fragmentManager = activity.getFragmentManager();
        if (fragmentManager != null) {
            fragmentManager.popBackStack();
        }
    }
}

See More Examples