List of usage examples for android.support.v4.app Fragment getActivity
public Activity getActivity()
From source file:com.mycelium.wallet.activity.send.SendMainActivity.java
public static void callMe(Fragment currentFragment, UUID account, Long amountToSend, Address receivingAddress, boolean isColdStorage) { Intent intent = new Intent(currentFragment.getActivity(), SendMainActivity.class); intent.putExtra("account", account); intent.putExtra("amountToSend", amountToSend); intent.putExtra("receivingAddress", receivingAddress); intent.putExtra("isColdStorage", isColdStorage); currentFragment.startActivity(intent); }
From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java
public static AddContentRelatedRepresentation prepareLink(Fragment fr, Uri uri) { Cursor cursor = null;//from w w w .j a va 2 s . c o m String name = null, source, sourceId, mimetype; String nodeId, type, alfAccountId; try { // Retrieve Document information cursor = fr.getActivity().getApplicationContext().getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { type = cursor.getString(cursor.getColumnIndex("alf_type")); alfAccountId = cursor.getString(cursor.getColumnIndex("alf_account_id")); name = cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME)); mimetype = cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)); } else { throw new Exception("Cursor is empty"); } ActivitiAccount acc = ActivitiAccountManager.getInstance(fr.getActivity()).getCurrentAccount(); Integration integration = IntegrationManager.getInstance(fr.getActivity()) .getByAlfrescoId(Long.parseLong(alfAccountId), acc.getId()); // Retrieve NodeId String pathSegment = uri.getLastPathSegment(); nodeId = pathSegment.split("&")[1].substring(3); // nodeId = // NodeRefUtils.getCleanIdentifier(uri.getLastPathSegment().split("&")[1].substring(3)); // Be aware this is an hack ! // Ideally we should populate with site Id. // In this case all link are absolute from root. sourceId = nodeId.concat("@A"); source = "alfresco-" + integration.getId(); return new AddContentRelatedRepresentation(name, true, source, sourceId, mimetype); } catch (Exception e) { return null; } finally { CursorUtils.closeCursor(cursor); } }
From source file:com.zhangwx.dynamicpermissionsrequest.permission.EasyPermissions.java
/** * Request a set of permissions, showing rationale if the system requests it. * * @param fragment {@link android.app.Fragment} requesting permissions. Should override {@link * android.app.Fragment#onRequestPermissionsResult(int, String[], int[])}. * @see #requestPermissions(Activity, int, String, String, int, int, int, String...) *///ww w . j a v a2s. c om @SuppressLint("NewApi") @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) public static void requestPermissions(@NonNull android.app.Fragment fragment, @DrawableRes int icon, String title, @NonNull String rationale, @StringRes int positiveButton, @StringRes int negativeButton, int requestCode, @NonNull String... perms) { if (hasPermissions(fragment.getActivity(), perms)) { notifyAlreadyHasPermissions(fragment, requestCode, perms); return; } if (shouldShowRationale(fragment, perms)) { showRationaleDialogFragment(fragment.getChildFragmentManager(), icon, title, rationale, positiveButton, negativeButton, requestCode, perms); } else { fragment.requestPermissions(perms, requestCode); } }
From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java
@TargetApi(11) private static int createStandardRow(Fragment fragment, TableLayout tableLayout, List<Stock> stocks, SparseArray<View> tiles, int height, int margin, int index, int row) { Stock stock1 = stocks.get(index);//from w ww . j a v a 2s . c o m Stock stock2 = (index + 1 < stocks.size()) ? stocks.get(index + 1) : null; if (shouldUpdateTableRow(tableLayout, row, stock1, stock2)) { TableRow tableRow = new TableRow(fragment.getActivity()); boolean shouldSpanFirstTile = row % 2 != 0; boolean shouldSpanSecondTile = !shouldSpanFirstTile; if (stock2 != null) { View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile); tiles.put(index, tile1); tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin) : getNotSpannedLayoutParams(row, height, margin)); View tile2 = createTile(fragment, stock2, index + 1, shouldSpanSecondTile); tiles.put(index + 1, tile2); tableRow.addView(tile2, shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin) : getLastNotSpannedLayoutParams(row, height, margin)); } else { View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile); tiles.put(index, tile1); tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin) : getNotSpannedLayoutParams(row, height, margin)); View tile2 = createTileForAddingNewStock(fragment); tiles.put(index + 1, tile2); tableRow.addView(tile2, shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin) : getLastNotSpannedLayoutParams(row, height, margin)); } if (row < tableLayout.getChildCount()) { tableLayout.removeViewAt(row); } tableLayout.addView(tableRow, row); } return index + 2; }
From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java
public static void fullscreen(android.support.v4.app.Fragment fragment, JSONParcelable imageData, PopupWindow popupWindow, View mainView) { popupWindow.setBackgroundDrawable(new ColorDrawable(0x80000000)); popupWindow.setFocusable(true);/* www .ja va 2 s .com*/ popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); final ZoomableImageView zoomableImageView = new ZoomableImageView(fragment.getActivity()); popupWindow.setContentView(zoomableImageView); popupWindow.showAtLocation(mainView, Gravity.TOP, 0, 0); LoadImageAsync loadImageAsync = new LoadImageAsync(zoomableImageView, imageData); loadImageAsync.execute(); }
From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java
public static void requestUpload(Fragment fr, Uri uri, String objectId, int type, String mimetyp) { Cursor cursor = null;// w w w . j a v a 2 s. co m String name = null, source, sourceId, mimetype = mimetyp; try { Bundle settingsBundle = new Bundle(); // Retrieve other info cursor = fr.getActivity().getContentResolver().query(uri, null, null, null, null); if (cursor == null && uri != null) { // Is it a file ? File file = new File(uri.getPath()); if (file.exists()) { // It's a file name = file.getName(); settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_CONTENT_PATH, file.getPath()); if (mimetype == null) { MimeType mime = MimeTypeManager.getInstance(fr.getActivity()).getMimetype(file.getName()); mimetype = (mime != null) ? mime.getMimeType() : mimetyp; } } } else if (cursor != null && cursor.moveToFirst()) { name = cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME)); mimetype = cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)); settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_CONTENT_URI, uri.toString()); } else { throw new Exception("Cursor is empty"); } settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); settingsBundle.putInt(ContentTransferSyncAdapter.ARGUMENT_MODE, ContentTransferSyncAdapter.MODE_SAF_UPLOAD); settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_FILE_PATH, name); if (type == TYPE_TASK_ID) { settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_TASK_ID, objectId); } else if (type == TYPE_PROCESS_ID) { settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_PROCESS_ID, objectId); } else if (type == TYPE_PROFILE_ID) { settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_PROFILE_ID, objectId); } settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_MIMETYPE, mimetype); ContentResolver.requestSync( ActivitiAccountManager.getInstance(fr.getActivity()).getCurrentAndroidAccount(), ContentTransferProvider.AUTHORITY, settingsBundle); } catch (Exception e) { Log.w("COntent Transfer", Log.getStackTraceString(e)); } finally { CursorUtils.closeCursor(cursor); } }
From source file:Main.java
public static void start(Activity activity, Fragment fragment, Class<?> cls, Bundle extras, int req_code, int enterAnim, int exitAnim) { if (null != activity) { Intent intent = new Intent(activity, cls); if (null != extras) { intent.putExtras(extras);//from ww w .ja v a 2s . c om } if (REQUEST_CODE_INVALID == req_code) { activity.startActivity(intent); } else { activity.startActivityForResult(intent, req_code); } if (0 != enterAnim || 0 != exitAnim) { activity.overridePendingTransition(enterAnim, exitAnim); } } else if (null != fragment) { activity = fragment.getActivity(); if (null != activity) { Intent intent = new Intent(activity, cls); if (null != extras) { intent.putExtras(extras); } if (REQUEST_CODE_INVALID == req_code) { fragment.startActivity(intent); } else { fragment.startActivityForResult(intent, req_code); } if (0 != enterAnim || 0 != exitAnim) { activity.overridePendingTransition(enterAnim, exitAnim); } } } }
From source file:Main.java
public static void startActivityForResult(Fragment fragment, Intent intent, int requestCode, Bundle options) { if (Build.VERSION.SDK_INT >= 19) { if ((requestCode & 0xffff0000) != 0) { throw new IllegalArgumentException("Can only use lower 16 bits" + " for requestCode"); }//w ww .ja v a2 s . c o m if (requestCode != -1) { try { Field mIndex = Fragment.class.getDeclaredField("mIndex"); mIndex.setAccessible(true); requestCode = ((mIndex.getInt(fragment) + 1) << 16) + (requestCode & 0xffff); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } } ActivityCompat.startActivityForResult(fragment.getActivity(), intent, requestCode, options); } else { fragment.getActivity().startActivityFromFragment(fragment, intent, requestCode); } }
From source file:com.waz.zclient.utils.ViewUtils.java
public static long getNextAnimationDuration(Fragment fragment) { try {/*w w w . jav a2 s . c o m*/ // Attempt to get the resource ID of the next animation that // will be applied to the given fragment. Field nextAnimField = Fragment.class.getDeclaredField("mNextAnim"); nextAnimField.setAccessible(true); int nextAnimResource = nextAnimField.getInt(fragment); Animation nextAnim = AnimationUtils.loadAnimation(fragment.getActivity(), nextAnimResource); // ...and if it can be loaded, return that animation's duration return (nextAnim == null) ? DEFAULT_CHILD_ANIMATION_DURATION : nextAnim.getDuration(); } catch (NoSuchFieldException | IllegalAccessException | Resources.NotFoundException ex) { return DEFAULT_CHILD_ANIMATION_DURATION; } }
From source file:com.just.agentweb.AgentWeb.java
public static AgentBuilder with(@NonNull Fragment fragment) { Activity mActivity = null;// ww w. j a va2 s. c o m if ((mActivity = fragment.getActivity()) == null) { throw new NullPointerException("activity can not be null ."); } return new AgentBuilder(mActivity, fragment); }