Java Code Examples for androidx.fragment.app.Fragment#getContext()
The following examples show how to use
androidx.fragment.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: AdapterAttachment.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterAttachment(Fragment parentFragment, boolean readonly) { this.parentFragment = parentFragment; this.readonly = readonly; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); this.debug = prefs.getBoolean("debug", false); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterAttachment.this + " parent destroyed"); AdapterAttachment.this.parentFragment = null; } }); }
Example 2
Source File: PermissionHelper.java From openScale with GNU General Public License v3.0 | 6 votes |
public static boolean requestLocationServicePermission(final Fragment fragment) { LocationManager locationManager = (LocationManager) fragment.getActivity().getSystemService(LOCATION_SERVICE); if (!(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))) { AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getContext()); builder.setTitle(R.string.permission_bluetooth_info_title); builder.setIcon(R.drawable.ic_preferences_about); builder.setMessage(R.string.permission_location_service_info); builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges the alert dialog Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); fragment.getActivity().startActivity(intent); } }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); return false; } return true; }
Example 3
Source File: AdapterContact.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterContact(Fragment parentFragment) { this.parentFragment = parentFragment; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(context); this.contacts = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS); this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent); this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterContact.this + " parent destroyed"); AdapterContact.this.parentFragment = null; } }); }
Example 4
Source File: AdapterLog.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterLog(Fragment parentFragment) { this.parentFragment = parentFragment; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(parentFragment.getContext()); this.TF = Helper.getTimeInstance(context); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterLog.this + " parent destroyed"); AdapterLog.this.parentFragment = null; } }); }
Example 5
Source File: AccountImporter.java From Android-SingleSignOn with GNU General Public License v3.0 | 6 votes |
private static void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, Activity activity, Fragment fragment) { Context context = (activity != null) ? activity : fragment.getContext(); switch (requestCode) { case REQUEST_GET_ACCOUNTS_PERMISSION: if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Permissions have been granted.. start pick account dialog try { if (activity != null) { pickNewAccount(activity); } else { pickNewAccount(fragment); } } catch (NextcloudFilesAppNotInstalledException | AndroidGetAccountsPermissionNotGranted e) { UiExceptionManager.showDialogForException(context, e); } } else { // user declined the permission request.. UiExceptionManager.showDialogForException(context, new AndroidGetAccountsPermissionNotGranted()); } break; default: break; } }
Example 6
Source File: AdapterIdentity.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterIdentity(Fragment parentFragment) { this.parentFragment = parentFragment; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(context); this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterIdentity.this + " parent destroyed"); AdapterIdentity.this.parentFragment = null; } }); }
Example 7
Source File: AdapterAccount.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterAccount(final Fragment parentFragment, boolean settings) { this.parentFragment = parentFragment; this.settings = settings; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean highlight_unread = prefs.getBoolean("highlight_unread", true); this.colorUnread = Helper.resolveColor(context, highlight_unread ? R.attr.colorUnreadHighlight : android.R.attr.textColorPrimary); this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary); this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterAccount.this + " parent destroyed"); AdapterAccount.this.parentFragment = null; } }); }
Example 8
Source File: AdapterOperation.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterOperation(Fragment parentFragment) { this.parentFragment = parentFragment; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(context); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterOperation.this + " parent destroyed"); AdapterOperation.this.parentFragment = null; } }); }
Example 9
Source File: AdapterOrder.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterOrder(Fragment parentFragment) { this.parentFragment = parentFragment; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(context); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterOrder.this + " parent destroyed"); AdapterOrder.this.parentFragment = null; } }); }
Example 10
Source File: AdapterImage.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterImage(Fragment parentFragment) { this.parentFragment = parentFragment; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(context); setHasStableIds(true); owner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterImage.this + " parent destroyed"); AdapterImage.this.parentFragment = null; } }); }
Example 11
Source File: ComposeActivity.java From lttrs-android with Apache License 2.0 | 5 votes |
private static void launch(final Fragment fragment, final Long account, final String emailId, final ComposeAction action) { final Intent intent = new Intent(fragment.getContext(), ComposeActivity.class); intent.putExtra(ACCOUNT_EXTRA, account); intent.putExtra(COMPOSE_ACTION_EXTRA, action.toString()); intent.putExtra(EMAIL_ID_EXTRA, emailId); fragment.startActivityForResult(intent, REQUEST_EDIT_DRAFT); }
Example 12
Source File: AdapterCertificate.java From FairEmail with GNU General Public License v3.0 | 5 votes |
AdapterCertificate(Fragment parentFragment) { this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(parentFragment.getContext()); this.TF = Helper.getDateTimeInstance(context, SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); setHasStableIds(true); }
Example 13
Source File: FileSelectorAdapter.java From HaoReader with GNU General Public License v3.0 | 5 votes |
public FileSelectorAdapter(Fragment fragment, boolean singleChoice, boolean checkBookAdded, boolean isImage) { this.fragment = new WeakReference<>(fragment); this.singleChoice = singleChoice; this.checkBookAdded = checkBookAdded; this.isImage = isImage; this.context = fragment.getContext(); this.inflater = LayoutInflater.from(context); placeholder = fragment.getResources().getDrawable(R.drawable.ic_image_placeholder); AppCompat.setTint(placeholder, fragment.getResources().getColor(R.color.colorTextSecondary)); files = new ArrayList<>(); }
Example 14
Source File: CustomPreviewControllerView.java From YImagePicker with Apache License 2.0 | 5 votes |
@Override public View getItemView(Fragment fragment, ImageItem imageItem, IPickerPresenter presenter) { if (imageItem.isVideo()) { TextView view = new TextView(fragment.getContext()); view.setText("这是视频"); view.setTextColor(Color.WHITE); view.setGravity(Gravity.CENTER); view.setBackgroundColor(Color.RED); return view; } return super.getItemView(fragment, imageItem, presenter); }
Example 15
Source File: PhotoSelectActivity.java From NewFastFrame with Apache License 2.0 | 5 votes |
public static void start(Fragment fragment, String from, boolean isOne, boolean isCrop, ArrayList<SystemUtil.ImageItem> selectedImageItemList) { Intent intent = new Intent(fragment.getContext(), PhotoSelectActivity.class); intent.putExtra(ConstantUtil.DATA, selectedImageItemList); intent.putExtra(ConstantUtil.IS_ONE, isOne); intent.putExtra(ConstantUtil.IS_CROP, isCrop); intent.putExtra(ConstantUtil.FROM, from); if (isOne) { fragment.startActivityForResult(intent, com.example.commonlibrary.utils.SystemUtil.REQUEST_CODE_ONE_PHOTO); } else { fragment.startActivity(intent); } }
Example 16
Source File: FastMainTabDelegate.java From FastLib with Apache License 2.0 | 5 votes |
public FastMainTabDelegate(View rootView, Fragment activity, IFastMainView iFastMainView) { if (iFastMainView == null || rootView == null || activity == null) { return; } this.mContext = activity.getContext(); this.mObject = activity; this.mIFastMainView = iFastMainView; mFragmentManager = activity.getChildFragmentManager(); mSavedInstanceState = iFastMainView.getSavedInstanceState(); getTabLayout(rootView); getViewPager(rootView); initTabLayout(); }
Example 17
Source File: AdapterFolder.java From FairEmail with GNU General Public License v3.0 | 4 votes |
AdapterFolder(Fragment parentFragment, long account, boolean primary, boolean show_compact, boolean show_hidden, boolean show_flagged, IFolderSelectedListener listener) { this(parentFragment.getContext(), parentFragment.getViewLifecycleOwner(), account, primary, show_compact, show_hidden, show_flagged, listener); this.parentFragment = parentFragment; }
Example 18
Source File: PreviewControllerView.java From YImagePicker with Apache License 2.0 | 4 votes |
/** * 获取预览的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 View.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); Uri uri = imageItem.getUri(); if (uri == null) { uri = PickerFileProvider.getUriForFile((Activity) getContext(), new File(imageItem.path)); } intent.setDataAndType(uri, "video/*"); getContext().startActivity(intent); return; } singleTap(); } }); DetailImageLoadHelper.displayDetailImage(false, imageView, presenter, imageItem); return layout; }
Example 19
Source File: NoteEditActivity.java From CrazyDaily with Apache License 2.0 | 4 votes |
public static void start(Fragment fragment, NoteEntity note) { Intent intent = new Intent(fragment.getContext(), NoteEditActivity.class); intent.putExtra(ActivityConstant.DATA, note); fragment.startActivityForResult(intent, REQUEST_CODE); }
Example 20
Source File: AppSettingsDialog.java From easypermissions with Apache License 2.0 | 2 votes |
/** * 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(); }