List of usage examples for android.app Fragment getActivity
final public Activity getActivity()
From source file:com.xtremelabs.imageutils.ImageLoader.java
public static ImageLoader buildImageLoaderForSupportFragment(android.support.v4.app.Fragment fragment) { return new ImageLoader(fragment, fragment.getActivity()); }
From source file:com.poloure.simplerss.Utilities.java
private static void switchToFragment(Fragment fragment, boolean addToBackStack) { if (fragment.isHidden()) { Fragment[] fragments = { s_fragmentFavourites, s_fragmentManage, s_fragmentFeeds, s_fragmentSettings }; FragmentTransaction transaction = s_fragmentManager.beginTransaction(); for (Fragment frag : fragments) { if (frag.isVisible()) { transaction.hide(frag);/*from ww w . jav a 2s. c o m*/ } } transaction.show(fragment); if (addToBackStack) { transaction.addToBackStack(null); // Set the default transition for adding to the stack. transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); } transaction.commit(); s_fragmentManager.executePendingTransactions(); fragment.getActivity().invalidateOptionsMenu(); } }
From source file:org.alfresco.mobile.android.application.manager.ActionManager.java
public static boolean actionSendMailWithAttachment(Fragment fr, String subject, String content, Uri attachment, int requestCode) { try {/*from ww w . j a v a2 s . c o m*/ Intent i = new Intent(Intent.ACTION_SEND); i.putExtra(Intent.EXTRA_SUBJECT, subject); i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(content)); i.putExtra(Intent.EXTRA_STREAM, attachment); i.setType("text/plain"); fr.startActivityForResult(Intent.createChooser(i, fr.getString(R.string.send_email)), requestCode); return true; } catch (Exception e) { MessengerManager.showToast(fr.getActivity(), R.string.decryption_failed); Log.d(TAG, Log.getStackTraceString(e)); } return false; }
From source file:org.alfresco.mobile.android.application.manager.ActionManager.java
public static void actionSendDocuments(Fragment fr, List<File> files) { if (files.size() == 1) { actionSendDocument(fr, files.get(0)); return;//from w ww . j a v a2 s.co m } try { Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE); ArrayList<Uri> uris = new ArrayList<Uri>(); // convert from paths to Android friendly Parcelable Uri's for (File file : files) { Uri u = Uri.fromFile(file); uris.add(u); } i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); i.setType(MimeTypeManager.getMIMEType(fr.getActivity(), "text/plain")); fr.getActivity() .startActivity(Intent.createChooser(i, fr.getActivity().getText(R.string.share_content))); } catch (ActivityNotFoundException e) { MessengerManager.showToast(fr.getActivity(), R.string.error_unable_share_content); } }
From source file:com.commonslibrary.commons.net.BaseRemoteModel.java
public BaseRemoteModel(Object object) { if (object instanceof android.app.Fragment) { android.app.Fragment fragment = (android.app.Fragment) object; mContext = fragment.getActivity(); } else if (object instanceof android.support.v4.app.Fragment) { android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) object; mContext = fragment.getActivity(); } else if (object instanceof Activity) { mContext = (Activity) object;// ww w . j a va 2 s. c o m } else if (object instanceof Application) { mContext = ((Application) object).getApplicationContext(); } }
From source file:prism.framework.DependencyInjector.java
/** * Run Dagger injections for a Fragment. * * Runs Dagger's application object graph on the class as well as static * injections./*from w ww . jav a2 s.com*/ * * @param target The fragment to inject services into */ public void inject(android.app.Fragment target) { Activity parentActivity = target.getActivity(); this.inject(target, parentActivity); }
From source file:com.commonslibrary.commons.net.BaseRxJavaRemoteModel.java
public BaseRxJavaRemoteModel(Object object) { if (object instanceof android.app.Fragment) { android.app.Fragment fragment = (android.app.Fragment) object; mContext = fragment.getActivity(); } else if (object instanceof android.support.v4.app.Fragment) { android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) object; mContext = fragment.getActivity(); } else if (object instanceof Activity) { mContext = (Activity) object;/*from w ww . j a v a2s. co m*/ } else if (object instanceof Application) { mContext = ((Application) object).getApplicationContext(); } }
From source file:com.nick.scalpel.core.request.RequestPermissionWirer.java
@Override public void wire(Object obj) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;//from w w w .java2s . co m Activity activity = null; if (obj instanceof Activity) { activity = (Activity) obj; } if (obj instanceof Fragment) { Fragment fragment = (Fragment) obj; activity = fragment.getActivity(); } if (obj instanceof android.support.v4.app.Fragment) { android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj; activity = fragment.getActivity(); } Preconditions.checkNotNull(activity, "Only Activity or Fragment(app/v4) is supported for this annotation."); RequirePermission autoRequirePermission = activity.getClass().getAnnotation(RequirePermission.class); int code = autoRequirePermission.requestCode(); String[] scope = autoRequirePermission.permissions(); String[] required; if (scope.length == 0) { scope = getPkgInfo(activity).requestedPermissions; required = extractUnGranted(activity, scope); } else { required = extractUnGranted(activity, scope); } if (required == null || required.length == 0) { int[] codes = new int[0]; if (required != null) { codes = new int[scope.length]; for (int i = 0; i < codes.length; i++) { codes[i] = PackageManager.PERMISSION_GRANTED; } } activity.onRequestPermissionsResult(code, scope, codes); } else { activity.requestPermissions(required, code); } }
From source file:dev.nick.accessories.injection.processors.PermissionProcessor.java
@Override public boolean process(@NonNull Object obj, @NonNull Type type) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false; in();//from w w w . j a va2 s . com Activity activity = null; if (obj instanceof Activity) { activity = (Activity) obj; } if (obj instanceof Fragment) { Fragment fragment = (Fragment) obj; activity = fragment.getActivity(); } if (obj instanceof android.support.v4.app.Fragment) { android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj; activity = fragment.getActivity(); } Preconditions.checkNotNull(activity, "Only Activity or Fragment is supported for this annotation."); RequestPermissions autoRequirePermission = activity.getClass().getAnnotation(RequestPermissions.class); int code = autoRequirePermission.requestCode(); String[] scope = autoRequirePermission.permissions(); String[] required; if (scope.length == 0) { scope = getPkgInfo(activity).requestedPermissions; required = extractUnGranted(activity, scope); } else { required = extractUnGranted(activity, scope); } if (required == null || required.length == 0) { int[] codes = new int[0]; if (required != null) { codes = new int[scope.length]; for (int i = 0; i < codes.length; i++) { codes[i] = PackageManager.PERMISSION_GRANTED; } } activity.onRequestPermissionsResult(code, scope, codes); } else { activity.requestPermissions(required, code); } return true; }
From source file:io.nuclei.box.intent.AbstractBinding.java
@TargetApi(11) public T toModel(android.app.Fragment fragment) { if (fragment == null) return null; Bundle bundle = fragment.getArguments(); if (bundle == null && fragment.getActivity() != null) { Activity activity = fragment.getActivity(); if (activity.getIntent() != null) bundle = activity.getIntent().getExtras(); }/* w ww . j ava 2s . c o m*/ return toModel(bundle); }