List of usage examples for android.support.v4.app Fragment getActivity
public Activity getActivity()
From source file:gstb.fd.eofficial.oa.eofficial.activity.runtimepermissions.PermissionsManager.java
/** * This method should be used to execute a {@link PermissionsResultAction} for the array * of permissions passed to this method. This method will request the permissions if * they need to be requested (i.e. we don't have permission yet) and will add the * PermissionsResultAction to the queue to be notified of permissions being granted or * denied. In the case of pre-Android Marshmallow, permissions will be granted immediately. * The Fragment variable is used, but if {@link Fragment#getActivity()} returns null, this method * will fail to work as the activity reference is necessary to check for permissions. * * @param fragment the fragment necessary to request the permissions. * @param permissions the list of permissions to request for the {@link PermissionsResultAction}. * @param action the PermissionsResultAction to notify when the permissions are granted or denied. *///from w ww. j a v a2 s.c o m @SuppressWarnings("unused") public synchronized void requestPermissionsIfNecessaryForResult(@NonNull Fragment fragment, @NonNull String[] permissions, @Nullable PermissionsResultAction action) { Activity activity = fragment.getActivity(); if (activity == null) { return; } addPendingAction(permissions, action); List<String> permList = getPermissionsListToRequest(activity, permissions, action); if (permList.isEmpty()) { //if there is no permission to request, there is no reason to keep the action int the list removePendingAction(action); } else { String[] permsToRequest = permList.toArray(new String[permList.size()]); mPendingRequests.addAll(permList); fragment.requestPermissions(permsToRequest, 1); } }
From source file:com.vuze.android.remote.adapter.TorrentPagerAdapter.java
private void updateFragmentArgs(Fragment fragment, int position) { if (fragment == null) { return;/* w w w .ja v a 2 s. com*/ } if (fragment instanceof PagerPosition) { PagerPosition pagerPosition = (PagerPosition) fragment; pagerPosition.setPagerPosition(position); } if (fragment.getActivity() != null) { if (fragment instanceof SetTorrentIdListener) { ((SetTorrentIdListener) fragment).setTorrentID(torrentID); } if (position == viewPager.getCurrentItem()) { // Special case for first item, which never gets an onPageSelected event // Send pageActivated event. if (fragment instanceof FragmentPagerListener) { FragmentPagerListener l = (FragmentPagerListener) fragment; l.pageActivated(); } } } else { Bundle arguments = fragment.getArguments(); if (arguments == null) { arguments = new Bundle(); } arguments.putLong("torrentID", torrentID); arguments.putInt("pagerPosition", position); // Fragment will have to handle pageActivated call when it's view is // attached :( arguments.putBoolean("isActive", position == viewPager.getCurrentItem()); fragment.setArguments(arguments); } }
From source file:cn.moon.superwechat.runtimepermissions.PermissionsManager.java
/** * This method should be used to execute a {@link PermissionsResultAction} for the array * of permissions passed to this method. This method will request the permissions if * they need to be requested (i.e. we don't have permission yet) and will add the * PermissionsResultAction to the queue to be notified of permissions being granted or * denied. In the case of pre-Android Marshmallow, permissions will be granted immediately. * The Fragment variable is used, but if {@link Fragment#getActivity()} returns null, this method * will fail to work as the activity reference is necessary to check for permissions. * * @param fragment the fragment necessary to request the permissions. * @param permissions the list of permissions to request for the {@link PermissionsResultAction}. * @param action the PermissionsResultAction to notify when the permissions are granted or denied. *//*from w w w . j av a2 s. c o m*/ @SuppressWarnings("unused") public synchronized void requestPermissionsIfNecessaryForResult(@NonNull Fragment fragment, @NonNull String[] permissions, @Nullable PermissionsResultAction action) { Activity activity = fragment.getActivity(); if (activity == null) { return; } addPendingAction(permissions, action); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { doPermissionWorkBeforeAndroidM(activity, permissions, action); } else { List<String> permList = getPermissionsListToRequest(activity, permissions, action); if (permList.isEmpty()) { //if there is no permission to request, there is no reason to keep the action int the list removePendingAction(action); } else { String[] permsToRequest = permList.toArray(new String[permList.size()]); mPendingRequests.addAll(permList); fragment.requestPermissions(permsToRequest, 1); } } }
From source file:com.e2g.ecocicle.barcode.IntentIntegrator.java
/** * @param fragment {@link android.app.Fragment} invoking the integration. * {@link #startActivityForResult(android.content.Intent, int)} will be called on the {@link android.app.Fragment} instead * of an {@link android.app.Activity}/*from w w w.j av a 2s . c om*/ */ public IntentIntegrator(Fragment fragment) { this.activity = fragment.getActivity(); this.fragment = fragment; initializeConfiguration(); }
From source file:com.google.zxing.integration.android.ScannerIntegrator.java
/** * @param fragment {@link Fragment} invoking the integration. * {@link #startActivityForResult(Intent, int)} will be called on the {@link Fragment} instead * of an {@link Activity}/* w w w .j av a 2 s.c o m*/ */ public ScannerIntegrator(Fragment fragment) { this.activity = fragment.getActivity(); this.fragment = fragment; initializeConfiguration(); }
From source file:com.wanderfar.expander.Settings.SettingsActivity.java
private void requestSystemAlertPermission(Activity context, Fragment fragment, int requestCode) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { setFloatingUIEnabledorDisabled(); } else {/*w w w .j av a2 s. c om*/ final String packageName = context == null ? fragment.getActivity().getPackageName() : context.getPackageName(); final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName)); if (fragment != null) fragment.startActivityForResult(intent, requestCode); else context.startActivityForResult(intent, requestCode); } }
From source file:com.normalexception.app.rx8club.TimeoutFactory.java
public boolean checkTimeout(final Fragment src) { // Only update pong when the login activity was called if (!(src instanceof LoginFragment)) { pingTime = System.currentTimeMillis() / 1000l; diffTime = pingTime - pongTime;/*from www . j a va 2s . co m*/ Log.d(TAG, String.format("Ping Time: %d", pingTime)); Log.d(TAG, String.format("Difference Time: %d", diffTime)); if (diffTime > PING_EXPIRE) { src.getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(src.getActivity(), R.string.timeout, Toast.LENGTH_SHORT).show(); } }); Log.d(TAG, "## PING TIME EXPIRED ##"); FragmentUtils.returnToLoginPage(src.getActivity(), FragmentUtils.LogoutReason.TIMEOUT); return false; } } return true; }
From source file:com.hiqes.andele.RequestOwnerSupportFragment.java
@TargetApi(23) @Override//from www .ja va2 s .co m public int checkSelfPermission(String permission) { int ret = PackageManager.PERMISSION_GRANTED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Fragment frag = getFragment(); if (frag == null) { // The Fragment has been garbage collected, should NOT // happen but fail gracefully with a log Log.e(TAG, "checkSelfPermission: Fragment no long valid, assume DENIED"); ret = PackageManager.PERMISSION_DENIED; } else { ret = frag.getActivity().checkSelfPermission(permission); } } return ret; }
From source file:io.nuclei.cyto.share.ShareIntent.java
/** * Start the sharing activity//ww w. ja v a 2 s . com * * @param info The activity info * @param requestCode The request code to receive back from the started activity * @param permissionRequestCode The permission request code in case we need access to external storage */ public Intent startActivityForResult(Fragment fragment, ResolveInfo info, int requestCode, int permissionRequestCode) { String authority; String facebookId = null; try { ApplicationInfo applicationInfo = fragment.getActivity().getPackageManager() .getApplicationInfo(fragment.getActivity().getPackageName(), PackageManager.GET_META_DATA); authority = applicationInfo.metaData.getString(SHARING_AUTHORITY); if (PackageTargetManager.FACEBOOK.equals(info.activityInfo.packageName)) facebookId = applicationInfo.metaData.getString("com.facebook.sdk.ApplicationId"); } catch (Exception err) { throw new RuntimeException(err); } if (TextUtils.isEmpty(authority)) Log.w(TAG, MISSING_CONFIG); PackageTargetManager manager = mTargetListeners == null ? null : mTargetListeners.get(info.activityInfo.packageName); if (manager == null) { if (mDefaultTargetManager == null) manager = new DefaultPackageTargetManager(); else manager = mDefaultTargetManager; } manager.initialize(mText, mUri, mUrl, mEmail, mSubject, mFile); manager.mFacebookId = facebookId; Intent intent = manager.onCreateIntent(fragment.getActivity(), authority, info, permissionRequestCode); if (intent != null) manager.onShare(fragment, intent, requestCode); return intent; }
From source file:com.todoroo.astrid.notes.EditNoteActivity.java
public EditNoteActivity(ActFmCameraModule actFmCameraModule, Preferences preferences, MetadataDao metadataDao, UserActivityDao userActivityDao, TaskService taskService, Fragment fragment, View parent, long t) { super(fragment.getActivity()); this.actFmCameraModule = actFmCameraModule; this.preferences = preferences; this.metadataDao = metadataDao; this.userActivityDao = userActivityDao; this.taskService = taskService; this.fragment = fragment; this.activity = (AstridActivity) fragment.getActivity(); cameraButton = getDefaultCameraButton(); setOrientation(VERTICAL);/*from ww w .j av a2s . c o m*/ commentsBar = parent.findViewById(R.id.updatesFooter); loadViewForTaskID(t); }