Java Code Examples for android.support.v4.app.Fragment#getContext()

The following examples show how to use android.support.v4.app.Fragment#getContext() . 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
Source File: GetContactsFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
public static void show(Fragment parent, ContactSourceType sourceType, boolean singleNumberMode) {
    Context context = parent.getContext();

    // check permission
    final String permission = ContactsAccessHelper.getPermission(sourceType);
    if (permission == null || Permissions.notifyIfNotGranted(context, permission)) {
        return;
    }

    // create fragment's args
    Bundle arguments = new Bundle();
    arguments.putSerializable(SOURCE_TYPE, sourceType);
    arguments.putBoolean(SINGLE_NUMBER_MODE, singleNumberMode);

    // open the dialog activity with the fragment
    CustomFragmentActivity.show(context, parent,
            getTitleId(context, sourceType),
            GetContactsFragment.class, arguments, 0);
}
 
Example 2
Source File: SecurityCodeActivity.java    From px-android with MIT License 5 votes vote down vote up
public static void startForRecovery(@NonNull final Fragment fragment, @NonNull final PaymentRecovery recovery,
    final int reqCode) {
    final Context context = fragment.getContext();
    if (context != null) {
        final Card card = recovery.getCard();
        final Intent intent = card != null ? createIntent(context, card) : createIntent(context, recovery);
        intent.putExtra(EXTRA_PAYMENT_RECOVERY, recovery);
        intent.putExtra(EXTRA_REASON, Reason.from(recovery).name());
        fragment.startActivityForResult(intent, reqCode);
    }
}
 
Example 3
Source File: MultiImageSelector.java    From MultiImageSelector with MIT License 5 votes vote down vote up
public void start(Fragment fragment, int requestCode){
    final Context context = fragment.getContext();
    if(hasPermission(context)) {
        fragment.startActivityForResult(createIntent(context), requestCode);
    }else{
        Toast.makeText(context, R.string.mis_error_no_permission, Toast.LENGTH_SHORT).show();
    }
}
 
Example 4
Source File: PrayerTimePresenter.java    From Muslim-Athkar-Islamic-Reminders with MIT License 5 votes vote down vote up
public PrayerTimePresenter(Fragment fragment) {
    mContext = fragment.getContext();
    this.MVPView = (net.a6te.lazycoder.muslim_pro_islamicremainders.MVP.MVPView.PrayerTimeView) fragment;
    prayerTimes = new ArrayList<>();
    savedData = new SavedData(fragment.getContext());
    calculationMethodId = savedData.getCalculationMethodId();
    juristicMethodId = savedData.getJuristicMethodId();
    city = savedData.getUserCity();
    latitude = savedData.getLat();
    longitude = savedData.getLong();
}
 
Example 5
Source File: PermissionHelper.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
public Context getContext() {
    Activity activity = getActivity();
    Fragment fragment = getFragment();
    if (activity == null && fragment == null) {
        return null;
    }
    if (activity == null) {
        return fragment.getContext();
    }
    if (fragment == null) {
        return activity;
    }
    return null;
}
 
Example 6
Source File: PostListAdapter.java    From zhizhihu with Apache License 2.0 4 votes vote down vote up
public PostListAdapter(Fragment fragment, List<Post> postList) {
    this.mContext = fragment.getContext();
    this.mPostList = postList;
}
 
Example 7
Source File: RxDialogChooseImage.java    From RxTools-master with Apache License 2.0 4 votes vote down vote up
public RxDialogChooseImage(Fragment fragment, float alpha, int gravity, LayoutType layoutType) {
    super(fragment.getContext(), alpha, gravity);
    mLayoutType = layoutType;
    initView(fragment);
}
 
Example 8
Source File: SearchActivity.java    From droidkaigi2016 with Apache License 2.0 4 votes vote down vote up
static void start(@NonNull Fragment fragment, int requestCode) {
    Intent intent = new Intent(fragment.getContext(), SearchActivity.class);
    fragment.startActivityForResult(intent, requestCode);
    fragment.getActivity().overridePendingTransition(0, R.anim.activity_fade_exit);
}
 
Example 9
Source File: RxDialogChooseImage.java    From RxTools-master with Apache License 2.0 4 votes vote down vote up
public RxDialogChooseImage(Fragment fragment, int themeResId) {
    super(fragment.getContext(), themeResId);
    initView(fragment);
}
 
Example 10
Source File: RxDialogChooseImage.java    From RxTools-master with Apache License 2.0 4 votes vote down vote up
public RxDialogChooseImage(Fragment fragment) {
    super(fragment.getContext());
    initView(fragment);
}
 
Example 11
Source File: NoInternetDialog.java    From NoInternetDialog with Apache License 2.0 4 votes vote down vote up
public Builder(Fragment fragment) {
    this.context = fragment.getContext();
}
 
Example 12
Source File: PreviewControllerView.java    From YImagePicker with Apache License 2.0 4 votes vote down vote up
/**
 * 获取预览的fragment里的布局
 *
 * @param fragment 当前加载的fragment,可以使用以下方式来绑定生命周期
 * <p>
 *         fragment.getLifecycle().addObserver(new ILifeCycleCallBack() {
 *             public void onResume() {}
 *             public void onPause() {}
 *             public void onDestroy() {}
 *         });
 *</p>
 *
 * @param imageItem  当前加载imageitem
 * @param presenter presenter
 * @return 预览的布局
 */
public View getItemView(Fragment fragment, final ImageItem imageItem, IPickerPresenter presenter) {
    if (imageItem == null) {
        return new View(fragment.getContext());
    }

    RelativeLayout layout = new RelativeLayout(getContext());
    final CropImageView imageView = new CropImageView(getContext());
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    // 启用图片缩放功能
    imageView.setBounceEnable(true);
    imageView.enable();
    imageView.setShowImageRectLine(false);
    imageView.setCanShowTouchLine(false);
    imageView.setMaxScale(7.0f);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    imageView.setLayoutParams(params);
    layout.setLayoutParams(params);
    layout.addView(imageView);

    ImageView mVideoImg = new ImageView(getContext());
    mVideoImg.setImageDrawable(getResources().getDrawable(R.mipmap.picker_icon_video));
    RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(PViewSizeUtils.dp(getContext(), 80), PViewSizeUtils.dp(getContext(), 80));
    mVideoImg.setLayoutParams(params1);
    params1.addRule(RelativeLayout.CENTER_IN_PARENT);
    layout.addView(mVideoImg, params1);

    if (imageItem.isVideo()) {
        mVideoImg.setVisibility(View.VISIBLE);
    } else {
        mVideoImg.setVisibility(View.GONE);
    }

    imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (imageItem.isVideo()) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setDataAndType(imageItem.getUri(), "video/*");
                getContext().startActivity(intent);
                return;
            }
            singleTap();
        }
    });
    DetailImageLoadHelper.displayDetailImage(false, imageView, presenter, imageItem);
    return layout;
}
 
Example 13
Source File: VMPicker.java    From VMLibrary with Apache License 2.0 4 votes vote down vote up
/**
 * 启动选择器,通过 Fragment 打开
 */
public void startPicker(Fragment fragment) {
    Intent intent = new Intent(fragment.getContext(), VMPickGridActivity.class);
    intent.putParcelableArrayListExtra(VMConstant.VM_KEY_PICK_PICTURES, (ArrayList<? extends Parcelable>) mSelectedPictures);
    fragment.startActivityForResult(intent, VMConstant.VM_PICK_REQUEST_CODE);
}
 
Example 14
Source File: MarkdownDocumentActivity.java    From ncalc with GNU General Public License v3.0 4 votes vote down vote up
public static void open(Fragment fragment, FunctionDocumentItem item) {
    Intent intent = new Intent(fragment.getContext(), MarkdownDocumentActivity.class);
    intent.putExtra(MarkdownDocumentActivity.EXTRA_ASSET_PATH, item.getAssetPath());
    intent.putExtra(MarkdownDocumentActivity.EXTRA_DOCUMENT_NAME, item.getName());
    fragment.startActivityForResult(intent, 0);
}
 
Example 15
Source File: ReadActivity.java    From WanAndroid with GNU General Public License v3.0 4 votes vote down vote up
public static void launch(@Nullable Fragment fragment, BlogPostBean postBean) {
    if (fragment == null) return;
    Intent intent = new Intent(fragment.getContext(), ReadActivity.class);
    intent.putExtra(BlogPostBean.class.getSimpleName(), postBean);
    fragment.startActivityForResult(intent, ACTIVITY_REQUEST_CODE);
}
 
Example 16
Source File: FragmentUriRequest.java    From WMRouter with Apache License 2.0 4 votes vote down vote up
public FragmentUriRequest(@NonNull Fragment fragment, @NonNull String uri) {
    super(fragment.getContext(), uri);
    configStartAction(fragment);
}
 
Example 17
Source File: AppSettingsDialog.java    From AndroidBasicProject with MIT License 4 votes vote down vote up
/**
 * Create a new Builder for an {@link AppSettingsDialog}.
 * @param fragment the Fragment in which to display the dialog.
 * @param rationale text explaining why the user should launch the app settings screen.
 */
public Builder(@NonNull Fragment fragment, @NonNull String rationale) {
    mActivityOrFragment = fragment;
    mContext = fragment.getContext();
    mRationale = rationale;
}
 
Example 18
Source File: MediaUtils.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
public static void startMapForResult(Fragment fragment) {
    Intent intent = new Intent(fragment.getContext(), MapsActivity.class);
    fragment.startActivityForResult(intent, IMAGE_VIDEO_LOCATION_REQUEST_CODE);
}
 
Example 19
Source File: WPSOpenUtils.java    From AndroidDocumentViewer with MIT License 4 votes vote down vote up
public FragmentStartWrapper(Fragment fragment) {
    super(fragment.getContext());
    this.fragment = fragment;
}
 
Example 20
Source File: AppSettingsDialog.java    From BaseProject with MIT License 2 votes vote down vote up
/**
 * Create a new Builder for an {@link AppSettingsDialog}.
 *
 * @param fragment the {@link Fragment} in which to display the dialog.
 */
public Builder(@NonNull Fragment fragment) {
    mActivityOrFragment = fragment;
    mContext = fragment.getContext();
}