List of usage examples for android.support.v4.app Fragment getActivity
public Activity getActivity()
From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java
private static View createTileForAddingNewStock(Fragment fragment) { View view = ((LayoutInflater) fragment.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.stock_tile_add_new_stock, null); Extensions.applyPattern(fragment.getResources(), view.findViewById(R.id.tileLayout), PatternBackgroundColor.BLACK); view.setOnClickListener((OnClickListener) fragment); return view;// ww w. j a v a 2s.c o m }
From source file:io.valuesfeng.picker.Picker.java
public static Picker from(Fragment fragment) { if (hasInitPicker) throw new ExceptionInInitializerError(INITIALIZE_PICKER_ERROR); hasInitPicker = true;//from w ww . j a va2 s . co m return new Picker(fragment.getActivity(), fragment); }
From source file:com.github.piasy.safelyandroid.activity.StartActivityDelegate.java
/** * start activity for result from {@link android.support.v4.app.Fragment} * * @param fragment fragment we start from * @param intent intent to start/*from w w w .jav a 2s . c o m*/ * @param requestCode request code * @param options options used to start activity * @return {@code true} if we start it safely, {@code false} if it's unsafe so we didn't start * it */ public static boolean startActivityForResultSafely(@NonNull android.support.v4.app.Fragment fragment, @NonNull Intent intent, int requestCode, Bundle options) { if (isIntentSafe(fragment.getActivity().getPackageManager(), intent)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { fragment.startActivityForResult(intent, requestCode, options); } else { fragment.startActivityForResult(intent, requestCode); } return true; } return false; }
From source file:org.videolan.vlc.gui.AudioPlayerContainerActivity.java
public static PlaybackServiceClient getPlaybackClient(Fragment fragment) { final Activity activity = fragment.getActivity(); if (activity == null) return null; if (!(activity instanceof AudioPlayerContainerActivity)) throw new IllegalArgumentException("Fragment must be inside AudioPlayerContainerActivity"); return ((AudioPlayerContainerActivity) activity).getPlaybackClient(); }
From source file:de.dala.simplenews.utilities.UIUtils.java
@SuppressWarnings("unchecked") // Casts are checked using runtime methods public static <T> T getParent(Fragment frag, Class<T> callbackInterface) { Fragment parentFragment = frag.getParentFragment(); if (parentFragment != null && callbackInterface.isInstance(parentFragment)) { return (T) parentFragment; } else {// w w w. java 2s. co m FragmentActivity activity = frag.getActivity(); if (activity != null && callbackInterface.isInstance(activity)) { return (T) activity; } } return null; }
From source file:io.valuesfeng.picker.Picker.java
public static Picker from(Fragment fragment, Set<MimeType> mimeType) { if (hasInitPicker) throw new ExceptionInInitializerError(INITIALIZE_PICKER_ERROR); hasInitPicker = true;/*from w w w .ja va2 s. c o m*/ return new Picker(fragment.getActivity(), fragment, mimeType); }
From source file:com.github.kanata3249.ffxieq.android.AtmaSelector.java
static public boolean startActivity(Fragment from, int request, FFXICharacter charInfo, int index, long current) { Intent intent = new Intent(from.getActivity(), AtmaSelector.class); intent.putExtra("Current", current); intent.putExtra("Index", index); intent.putExtra("Filter", (long) -1); from.startActivityForResult(intent, request); return true;/*ww w . j av a 2 s. c om*/ }
From source file:dagger.android.support.AndroidSupportInjection.java
private static HasSupportFragmentInjector findHasFragmentInjector(Fragment fragment) { Fragment parentFragment = fragment;// ww w. ja v a 2s.c o m while ((parentFragment = parentFragment.getParentFragment()) != null) { if (parentFragment instanceof HasSupportFragmentInjector) { return (HasSupportFragmentInjector) parentFragment; } } Activity activity = fragment.getActivity(); if (activity instanceof HasSupportFragmentInjector) { return (HasSupportFragmentInjector) activity; } if (activity.getApplication() instanceof HasSupportFragmentInjector) { return (HasSupportFragmentInjector) activity.getApplication(); } throw new IllegalArgumentException( String.format("No injector was found for %s", fragment.getClass().getCanonicalName())); }
From source file:com.github.kanata3249.ffxieq.android.MagicSelectorActivity.java
static public boolean startActivity(Fragment from, int request, FFXICharacter charInfo, int index, long current, long subId) { Intent intent = new Intent(from.getActivity(), MagicSelectorActivity.class); intent.putExtra("Index", index); intent.putExtra("Current", current); intent.putExtra("SubId", subId); intent.putExtra("Filter", (long) -1); intent.putExtra("FilterByType", ""); from.startActivityForResult(intent, request); return true;/*from w w w .jav a 2 s .co m*/ }
From source file:org.xbmc.kore.utils.MediaPlayerUtils.java
/** * Queues item to current playlist/*from w ww . j a va 2 s.c o m*/ * @param fragment Fragment instance from which this method is called * @param item PlaylistType.Item that needs to be added to the current playlist * @param type {@link org.xbmc.kore.jsonrpc.type.PlaylistType.GetPlaylistsReturnType} */ public static void queue(final Fragment fragment, final PlaylistType.Item item, final String type) { Playlist.GetPlaylists getPlaylists = new Playlist.GetPlaylists(); final Handler callbackHandler = new Handler(); final Context context = fragment.getActivity(); final HostManager hostManager = HostManager.getInstance(fragment.getActivity()); getPlaylists.execute(hostManager.getConnection(), new ApiCallback<ArrayList<PlaylistType.GetPlaylistsReturnType>>() { @Override public void onSuccess(ArrayList<PlaylistType.GetPlaylistsReturnType> result) { if (!fragment.isAdded()) return; // Ok, loop through the playlists, looking for the correct one int playlistId = -1; for (PlaylistType.GetPlaylistsReturnType playlist : result) { if (playlist.type.equals(type)) { playlistId = playlist.playlistid; break; } } // If found, add to playlist if (playlistId != -1) { Playlist.Add action = new Playlist.Add(playlistId, item); action.execute(hostManager.getConnection(), new ApiCallback<String>() { @Override public void onSuccess(String result) { if (!fragment.isAdded()) return; Toast.makeText(context, R.string.item_added_to_playlist, Toast.LENGTH_SHORT) .show(); } @Override public void onError(int errorCode, String description) { if (!fragment.isAdded()) return; // Got an error, show toast String errorMessage = context.getString(R.string.error_queue_media_file, description); Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show(); } }, callbackHandler); } else { Toast.makeText(context, R.string.no_suitable_playlist, Toast.LENGTH_SHORT).show(); } } @Override public void onError(int errorCode, String description) { if (!fragment.isAdded()) return; // Got an error, show toast Toast.makeText(context, R.string.error_getting_playlist, Toast.LENGTH_SHORT).show(); } }, callbackHandler); }