public static boolean handleMenuClick(@NonNull FragmentActivity activity, @NonNull ArrayList<Song> songs, int menuItemId) { switch (menuItemId) { case R.id.action_play_next: MusicPlayerRemote.playNext(songs); return true; case R.id.action_add_to_current_playing: MusicPlayerRemote.enqueue(songs); return true; case R.id.action_add_to_playlist: AddToPlaylistDialog.create(songs).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST"); return true; case R.id.action_delete_from_device: DeleteSongsDialog.create(songs).show(activity.getSupportFragmentManager(), "DELETE_SONGS"); return true; } return false; }
private static void handleActivity(Activity activity) { if (activity instanceof DaggerInjectable) { AndroidInjection.inject(activity); } if (activity instanceof FragmentActivity) { ((FragmentActivity) activity).getSupportFragmentManager() .registerFragmentLifecycleCallbacks( new FragmentManager.FragmentLifecycleCallbacks() { @Override public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) { if (f instanceof DaggerInjectable) { AndroidSupportInjection.inject(f); } } }, true); } }
@Before public void initComponents() { view = new MvpView() { }; presenter = Mockito.mock(MvpPresenter.class); callback = Mockito.mock(PartialViewGroupMvpDelegateCallbackImpl.class); Mockito.doCallRealMethod().when(callback).setPresenter(presenter); Mockito.doCallRealMethod().when(callback).getPresenter(); activity = Mockito.mock(FragmentActivity.class); application = Mockito.mock(Application.class); androidView = Mockito.mock(View.class); Mockito.when(callback.getMvpView()).thenReturn(view); Mockito.when(callback.getContext()).thenReturn(activity); Mockito.when(activity.getApplication()).thenReturn(application); Mockito.when(androidView.isInEditMode()).thenReturn(false); delegate = new ViewGroupMvpDelegateImpl<>(androidView, callback, true); }
private void showTracksChooserDialog() throws TransientNetworkDisconnectionException, NoConnectionException { if(!(getContext() instanceof FragmentActivity)) throw new IllegalStateException("Activity needs to be FragmentActivity"); FragmentTransaction transaction = ((FragmentActivity)getContext()).getSupportFragmentManager().beginTransaction(); Fragment prev = ((FragmentActivity)getContext()).getSupportFragmentManager().findFragmentByTag(DIALOG_TAG); if (prev != null) { transaction.remove(prev); } transaction.addToBackStack(null); // Create and show the dialog. /* <--archos changes> */ ArchosTracksChooserDialog dialogFragment = ArchosTracksChooserDialog .newInstance(ArchosVideoCastManager.getInstance().getMediaInfo()); /* <!--archos changes> */ dialogFragment.show(transaction, DIALOG_TAG); }
/** * 关联ViewPager,用于连适配器都不想自己实例化的情况 */ public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments) { if (vp == null) { throw new IllegalStateException("ViewPager can not be NULL !"); } if (titles == null || titles.length == 0) { throw new IllegalStateException("Titles can not be EMPTY !"); } this.mViewPager = vp; this.mViewPager.setAdapter(new InnerPagerAdapter(fa.getSupportFragmentManager(), fragments, titles)); // this.mViewPager.removeOnPageChangeListener(this); this.mViewPager.setOnPageChangeListener(this); notifyDataSetChanged(); }
/** 关联ViewPager,用于连适配器都不想自己实例化的情况 */ public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments) { if (vp == null) { throw new IllegalStateException("ViewPager can not be NULL !"); } if (titles == null || titles.length == 0) { throw new IllegalStateException("Titles can not be EMPTY !"); } this.mViewPager = vp; this.mViewPager.setAdapter(new InnerPagerAdapter(fa.getSupportFragmentManager(), fragments, titles)); this.mViewPager.removeOnPageChangeListener(this); this.mViewPager.addOnPageChangeListener(this); notifyDataSetChanged(); }
/** * To set the lifecycle of all Fragments settings for each Activity, the Activity can be accessed through {@link IActivity # useFragment ()} * Set whether to use the monitor, if the Activity returns false, then the activities of all the following Fragment will not be able to use {@link FragmentDelegate} * * @param activity: Activity */ private void registerFragmentCallbacks(Activity activity) { boolean useFragment = !(activity instanceof IActivity) || ((IActivity) activity).useFragment(); if (activity instanceof FragmentActivity && useFragment) { if (mFragmentLifecycle == null) { mFragmentLifecycle = new FragmentLifecycle(); } ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(mFragmentLifecycle, true); if (mFragmentLifecycles == null && mExtras.containsKey(ConfigLifecycle.class.getName())) { mFragmentLifecycles = new ArrayList<>(); List<ConfigLifecycle> lifecycles = (List<ConfigLifecycle>) mExtras.get(ConfigLifecycle.class.getName()); for (ConfigLifecycle lifecycle : lifecycles) { lifecycle.injectFragmentLifecycle(mApplication, mFragmentLifecycles); } mExtras.remove(ConfigLifecycle.class.getName()); } for (FragmentManager.FragmentLifecycleCallbacks fragmentLifecycle : mFragmentLifecycles) { ((FragmentActivity) activity).getSupportFragmentManager() .registerFragmentLifecycleCallbacks(fragmentLifecycle, true); } } }
private static void handleActivity(Activity activity) { if (activity instanceof HasSupportFragmentInjector || activity instanceof Injectable) { AndroidInjection.inject(activity); } if (activity instanceof FragmentActivity) { ((FragmentActivity) activity).getSupportFragmentManager() .registerFragmentLifecycleCallbacks( new FragmentManager.FragmentLifecycleCallbacks() { @Override public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) { if (f instanceof Injectable) { AndroidSupportInjection.inject(f); } } }, true); } }
@Override public void configGoogleSigin() { // Configure Google Sign In GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getContext().getString(R.string.default_google_web_client_id)) .requestEmail() .build(); //GoogleApiClient -> GOOGLE googleApiClient = new GoogleApiClient.Builder(getContext().getApplicationContext()) .enableAutoManage(((FragmentActivity) view), new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { showLog("GOOGLE SIGN_IN ERROR: " + connectionResult); // view.showToast(getContext().getString(R.string.something_was_wrong)); } }) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); }
public void onShareTencent() { if (this.mShareFrom == 3) { letvTencentShare.getInstance(this.mContext).gotoSharePage((FragmentActivity) this.mContext, this.playLiveController.getShareProgramName(), ShareUtils.getAnalysisLiveShareUrl(getShareMode(), this.mLiveType, this.mLiveId, 6, 0), this.mLiveImgUrl, getShareMode(), this.secondShareDesc, PageIdConstant.halpPlayPage, "s10"); StatisticsUtils.staticticsInfoPost(this.mContext, "4", "h223", "5005", 5, null, PageIdConstant.halpPlayPage, this.cid, this.pid, this.vid, NetworkUtils.DELIMITER_LINE, NetworkUtils.DELIMITER_LINE); } else if (this.mShareFrom == 4) { letvTencentShare.getInstance(this.mContext).gotoSharePage((FragmentActivity) this.mContext, this.album, this.mVideoShotShareInfoBean, this.album.order, this.album.Share_vid, 4, this.mVideoShotShareInfoBean.mRandText, PageIdConstant.pictureSharePage, "sh21"); StatisticsUtils.staticticsInfoPost(this.mContext, "4", "sh20", "5005", 5, null, PageIdConstant.pictureSharePage, this.cid, this.pid, this.vid, NetworkUtils.DELIMITER_LINE, NetworkUtils.DELIMITER_LINE); } else if (this.mShareFrom == 5) { letvTencentShare.getInstance(this.mContext).gotoSharePage((FragmentActivity) this.mContext, this.album, null, this.album.order, this.album.Share_vid, 5, getCommentDesc(4), PageIdConstant.halpPlayPage, "sh23"); StatisticsUtils.staticticsInfoPost(this.mContext, "4", "sh22", "5005", 5, null, PageIdConstant.halpPlayPage, this.cid, this.pid, this.vid, NetworkUtils.DELIMITER_LINE, NetworkUtils.DELIMITER_LINE); } else if (this.mShareFrom == 1) { letvTencentShare.getInstance(this.mContext).gotoSharePage((FragmentActivity) this.mContext, this.album, null, this.album.order, this.album.Share_vid, 1, this.secondShareDesc, PageIdConstant.halpPlayPage, "s10"); StatisticsUtils.staticticsInfoPost(this.mContext, "4", "h223", "5005", 5, null, PageIdConstant.halpPlayPage, this.cid, this.pid, this.vid, NetworkUtils.DELIMITER_LINE, NetworkUtils.DELIMITER_LINE); } else if (this.mShareFrom == 11) { LogInfo.log("fornia", "share-SHARE_FROM_RED_PACKET_SPRING shareQ"); letvTencentShare.getInstance(this.mContext).gotoSharePage((FragmentActivity) this.mContext, this.mActivityTitle, this.mActivityUrl, this.mPhotoUrl, this.mAwardUrl, 22, this.mGiftContent, PageIdConstant.halpPlayPage, "s10"); StatisticsUtils.staticticsInfoPost(this.mContext, "4", "h223", "5005", 5, null, PageIdConstant.halpPlayPage, this.cid, this.pid, this.vid, NetworkUtils.DELIMITER_LINE, NetworkUtils.DELIMITER_LINE); } else { letvTencentShare.getInstance(this.mContext).gotoSharePage((FragmentActivity) this.mContext, this.album, null, this.album.order, this.album.Share_vid, 1, this.secondShareDesc, PageIdConstant.halpPlayPage, "s10"); StatisticsUtils.staticticsInfoPost(this.mContext, "4", "h223", "5005", 5, null, PageIdConstant.halpPlayPage, this.cid, this.pid, this.vid, NetworkUtils.DELIMITER_LINE, NetworkUtils.DELIMITER_LINE); } }
private Drawable getDrawable(String condition) { final FragmentActivity activity = getActivity(); if (activity != null) { switch (condition) { case "Cloudy": return ContextCompat.getDrawable(activity, R.drawable.ic_cloudy); case "Fine": return ContextCompat.getDrawable(activity, R.drawable.ic_fine); case "Mostly Cloudy": return ContextCompat.getDrawable(activity, R.drawable.ic_mostly_cloudy); case "Partly Cloudy": return ContextCompat.getDrawable(activity, R.drawable.ic_partly_cloudy); case "Showers": return ContextCompat.getDrawable(activity, R.drawable.ic_showers); case "Snow": return ContextCompat.getDrawable(activity, R.drawable.ic_snow); default: return ContextCompat.getDrawable(activity, R.drawable.ic_help_black_48dp); } } else { return null; } }
public static GoogleApiClient createGoogleApiClient(FragmentActivity fragmentActivity) { GoogleApiClient.OnConnectionFailedListener failedListener; if (fragmentActivity instanceof GoogleApiClient.OnConnectionFailedListener) { failedListener = (GoogleApiClient.OnConnectionFailedListener) fragmentActivity; } else { throw new IllegalArgumentException(fragmentActivity.getClass().getSimpleName() + " should implement OnConnectionFailedListener"); } GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(fragmentActivity.getResources().getString(R.string.google_web_client_id)) .requestEmail() .build(); return new GoogleApiClient.Builder(fragmentActivity) .enableAutoManage(fragmentActivity, failedListener) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); }
public static View.OnClickListener getPickImageClickListener(final FragmentActivity activity,final Fragment fragment, final int requestCode){ return new View.OnClickListener() { @Override public void onClick(View v) { pickIntent(); } private void pickIntent(){ Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); activity.startActivityFromFragment(fragment, Intent.createChooser(intent, "Complete action using"), requestCode); } }; }
public void attachToActivity(FragmentActivity activity) { mActivity = activity; TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{ android.R.attr.windowBackground }); int background = a.getResourceId(0, 0); a.recycle(); ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); decorChild.setBackgroundResource(background); decor.removeView(decorChild); addView(decorChild); setContentView(decorChild); decor.addView(this); }
public void load() { FragmentActivity activity = mAppChooser.getActivity(); if (activity == null) { return; } Fragment fragment = mAppChooser.getFragment(); if (fragment != null) { mActionConfig.fromActivity = false; ViewFragment.newInstance(mActionConfig).show(fragment.getFragmentManager(), FRAGMENT_TAG); } else { mActionConfig.fromActivity = true; ViewFragment.newInstance(mActionConfig).show(activity.getSupportFragmentManager(), FRAGMENT_TAG); } }
/** * Return the callbacks for a fragment or throw an exception. * <p/> * Inspired by: https://gist.github.com/keyboardr/5455206 */ @SuppressWarnings("unchecked") public static <T> T getCallbacksOrThrow(Fragment frag, Class<T> callbacks) { Fragment parent = frag.getParentFragment(); if (parent != null && callbacks.isInstance(parent)) { return (T) parent; } else { FragmentActivity activity = frag.getActivity(); if (activity != null && callbacks.isInstance(activity)) { return (T) activity; } } // We haven't actually failed a class cast thanks to the checks above, but that's the // idiomatic approach for this pattern with fragments. throw new ClassCastException("This fragment's activity or parent fragment must implement " + callbacks.getCanonicalName()); }
/** * 给每个 Activity 的所有 Fragment 设置监听其生命周期, Activity 可以通过 {@link IActivity#useFragment()} * 设置是否使用监听,如果这个 Activity 返回 false 的话,这个 Activity 下面的所有 Fragment 将不能使用 {@link FragmentDelegate} * 意味着 {@link BaseFragment} 也不能使用 * * @param activity */ private void registerFragmentCallbacks(Activity activity) { boolean useFragment = activity instanceof IActivity ? ((IActivity) activity).useFragment() : true; if (activity instanceof FragmentActivity && useFragment) { if (mFragmentLifecycle == null) { mFragmentLifecycle = new FragmentLifecycle(); } ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(mFragmentLifecycle, true); if (mFragmentLifecycles == null && mExtras.containsKey(ConfigModule.class.getName())) { mFragmentLifecycles = new ArrayList<>(); List<ConfigModule> modules = (List<ConfigModule>) mExtras.get(ConfigModule.class.getName()); for (ConfigModule module : modules) { module.injectFragmentLifecycle(mApplication, mFragmentLifecycles); } mExtras.remove(ConfigModule.class.getName()); } for (FragmentManager.FragmentLifecycleCallbacks fragmentLifecycle : mFragmentLifecycles) { ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(fragmentLifecycle, true); } } }
@Override public void onAttach(Activity activity) { super.onAttach(activity); this.activity = (FragmentActivity) activity; }
/** * Disables progress bar animations for the views of the given activity rule * * @param activityTestRule The activity rule whose views will be checked */ public static void disableProgressBarAnimations( ActivityTestRule<? extends FragmentActivity> activityTestRule) { activityTestRule.getActivity().getSupportFragmentManager() .registerFragmentLifecycleCallbacks( new FragmentManager.FragmentLifecycleCallbacks() { @Override public void onFragmentViewCreated(FragmentManager fm, Fragment f, View v, Bundle savedInstanceState) { // traverse all views, if any is a progress bar, replace its animation traverseViews(v); } }, true); }
@Override public void onActivityCreated(Bundle savedInstanceState) { if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, savedInstanceState); super.onActivityCreated(savedInstanceState); /* Delay to avoid brief displaying of no-repos view. */ new android.os.Handler().postDelayed(() -> { FragmentActivity activity = getActivity(); if (activity != null) { activity.getSupportLoaderManager() .initLoader(Loaders.REPOS_FRAGMENT, null, ReposFragment.this); } }, 100); }
public RequestManager get(FragmentActivity activity) { if (Util.isOnBackgroundThread()) { return get(activity.getApplicationContext()); } else { assertNotDestroyed(activity); FragmentManager fm = activity.getSupportFragmentManager(); return supportFragmentGet(activity, fm, null /*parentHint*/); } }
@Test public void testSupportCanGetRequestManagerFromFragment() { FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).create().start().resume().get(); Fragment fragment = new Fragment(); activity.getSupportFragmentManager().beginTransaction().add(fragment, PARENT_TAG).commit(); activity.getSupportFragmentManager().executePendingTransactions(); RequestManager manager = retriever.get(fragment); assertEquals(manager, retriever.get(fragment)); }
public ReactActivityDelegate( FragmentActivity fragmentActivity, @Nullable String mainComponentName) { mFragmentActivity = fragmentActivity; mMainComponentName = mainComponentName; mActivity = null; }
@Override public void onDestroyView() { super.onDestroyView(); placeApiClient.stopAutoManage((FragmentActivity) getActivity()); placeApiClient.disconnect(); }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); printFragmentLife("onViewCreated"); Bundle argsBundle = getArguments(); if (savedInstanceState != null) { mConfiguration = savedInstanceState.getParcelable(EXTRA_CONFIGURATION); } if (mConfiguration == null && argsBundle != null) { mConfiguration = argsBundle.getParcelable(EXTRA_CONFIGURATION); } if (mConfiguration != null) { if (argsBundle == null) { argsBundle = savedInstanceState; } onViewCreatedOk(view, argsBundle); setTheme(); } else { FragmentActivity activity = getActivity(); if (activity != null && !activity.isFinishing()) { activity.finish(); } } }
protected ProgressDialog showWaitDialog(int resid) { FragmentActivity activity = getActivity(); if (activity instanceof DialogControl) { return ((DialogControl) activity).showWaitDialog(resid); } return null; }
/** * Disables progress bar animations for the views of the given activity rule * * @param activityTestRule The activity rule whose views will be checked */ public static void disableAnimations( ActivityTestRule<? extends FragmentActivity> activityTestRule) { activityTestRule.getActivity().getSupportFragmentManager() .registerFragmentLifecycleCallbacks( new FragmentManager.FragmentLifecycleCallbacks() { @Override public void onFragmentViewCreated(FragmentManager fm, Fragment f, View v, Bundle savedInstanceState) { // traverse all views, if any is a progress bar, replace its animation traverseViews(v); } }, true); }
/** * 拆红包方法 * * @param activity FragmentActivity(由于使用了DialogFragment,这个参数类型必须为FragmentActivity) * @param chatType 聊天类型 * @param redPacketId 红包id * @param redPacketType 红包类型 * @param receiverId 接收者id * @param messageDirect 消息的方向 */ public static void openRedPacket(final FragmentActivity activity, final int chatType, String redPacketId, String redPacketType, String receiverId, String messageDirect) { final ProgressDialog progressDialog = new ProgressDialog(activity); progressDialog.setCanceledOnTouchOutside(false); RedPacketInfo redPacketInfo = new RedPacketInfo(); redPacketInfo.redPacketId = redPacketId; redPacketInfo.messageDirect = messageDirect; redPacketInfo.chatType = chatType; RPRedPacketUtil.getInstance().openRedPacket(redPacketInfo, activity, new RPRedPacketUtil.RPOpenPacketCallback() { @Override public void onSuccess(String senderId, String senderNickname, String myAmount) { //领取红包成功 发送回执消息到聊天窗口 Toast.makeText(activity, "拆红包成功,红包金额" + myAmount + "元", Toast.LENGTH_LONG).show(); } @Override public void showLoading() { progressDialog.show(); } @Override public void hideLoading() { progressDialog.dismiss(); } @Override public void onError(String code, String message) { Toast.makeText(activity, message, Toast.LENGTH_SHORT).show(); } }); }
/** * Updates the status on the action bar. * * @param resId a string resource ID */ private void setStatus(int resId) { FragmentActivity activity = getActivity(); if (null == activity) { return; } final ActionBar actionBar = activity.getActionBar(); if (null == actionBar) { return; } actionBar.setSubtitle(resId); }
public static void signOut(FragmentActivity fragmentActivity, final SignOutDelegate delegate) { AuthUI.getInstance() .signOut(fragmentActivity) .addOnCompleteListener(new OnCompleteListener<Void>() { public void onComplete(@NonNull Task<Void> task) { delegate.onSignOut(); } }); }
/** * Updates the status on the action bar. * * @param subTitle status */ private void setStatus(CharSequence subTitle) { FragmentActivity activity = getActivity(); if (null == activity) { return; } final ActionBar actionBar = activity.getActionBar(); if (null == actionBar) { return; } actionBar.setSubtitle(subTitle); }
public FriendsListRecycler(FragmentActivity context) { this.mContext = context; // remove self and display all others TreeMap<String, User> tempHashMap = new TreeMap<>(UserHelper.getInstance().getAllContacts()); tempHashMap.remove(UserHelper.getInstance().getOwnerProfile().username); mUserList = new ArrayList<>(tempHashMap.values()); }
public FeedsRecycler(FragmentActivity context) { this.mContext = context; this.mGoalFeedList = GoalHelper.getInstance().getFeeds(); this.mProgressDialog = new DelayedProgressDialog(); if (mHasVoted == null) mHasVoted = new HashSet<>(); if (mCachedImages == null) mCachedImages = new HashMap<>(); }
@Override public MainPresenter mainPresenter(FragmentActivity activity) { if (mainPresenter == null) { mainPresenter = new MainPresenter(getLoggedUser(), getFeedItem(), getFeedItems(), likePhoto()); } return mainPresenter; }
public static void show(FragmentActivity context, String imageUrl) { SaveImageDialogFragment fragment = new SaveImageDialogFragment(); fragment.context = context; Bundle bundle = new Bundle(); bundle.putString("data", imageUrl); fragment.setArguments(bundle); fragment.show(fragment.context.getSupportFragmentManager(), "dialog"); }
@Before public void initComponents() { view = new MvpView() { }; viewState = Mockito.mock(ViewState.class); presenter = Mockito.mock(MvpPresenter.class); callback = Mockito.spy(PartialMvpViewStateDelegateCallbackImpl.class); Mockito.doCallRealMethod().when(callback).setPresenter(presenter); Mockito.doCallRealMethod().when(callback).getPresenter(); Mockito.doCallRealMethod().when(callback).setViewState(viewState); Mockito.doCallRealMethod().when(callback).getViewState(); fragment = PowerMockito.mock(Fragment.class); activity = Mockito.mock(FragmentActivity.class); application = Mockito.mock(Application.class); Mockito.when(callback.getMvpView()).thenReturn(view); Mockito.when(fragment.getActivity()).thenReturn(activity); Mockito.when(activity.getApplication()).thenReturn(application); Mockito.when(callback.createPresenter()).thenReturn(presenter); Mockito.when(callback.createViewState()).thenReturn(viewState); delegate = new FragmentMvpViewStateDelegateImpl<>(fragment, callback, true, true); }
public static void editItem(FragmentActivity activity, int id, String inputText, int color) { Uri uri = TaskItemsContract.TaskItemsColumns.CONTENT_URI; ContentValues contentValues = new ContentValues(); contentValues.put(TaskItemsContract.TaskItemsColumns.COLUMN_NAME_COLOR, color); contentValues.put(TaskItemsContract.TaskItemsColumns.COLUMN_NAME_DESCRIPTION, inputText); uri = uri.buildUpon().appendPath(String.valueOf(id)).build(); activity.getContentResolver().update(uri, contentValues, null, null); }
private void initViewModels() { try { locationViewModel = ViewModelProviders.of((FragmentActivity) getContext()).get(LocationViewModel.class); routeViewModel = ViewModelProviders.of((FragmentActivity) getContext()).get(RouteViewModel.class); navigationViewModel = ViewModelProviders.of((FragmentActivity) getContext()).get(NavigationViewModel.class); } catch (ClassCastException exception) { throw new ClassCastException("Please ensure that the provided Context is a valid FragmentActivity"); } }
public static boolean canLoadImage(Fragment fragment) { if (fragment == null) { return true; } FragmentActivity activity = fragment.getActivity(); return canLoadImage(activity); }