Example usage for android.support.v4.app Fragment getActivity

List of usage examples for android.support.v4.app Fragment getActivity

Introduction

In this page you can find the example usage for android.support.v4.app Fragment getActivity.

Prototype

public Activity getActivity() 

Source Link

Usage

From source file:org.xbmc.kore.utils.MediaPlayerUtils.java

/**
 * Clears current playlist and starts playing item
 * @param fragment Fragment instance from which this method is called
 * @param item PlaylistType.Item that needs to be played
 *//*from  ww  w  .  j  ava 2 s  .co  m*/
public static void play(final Fragment fragment, final PlaylistType.Item item) {
    HostManager hostManager = HostManager.getInstance(fragment.getActivity());

    final Handler callbackHandler = new Handler();

    final Context context = fragment.getActivity();

    Player.Open action = new Player.Open(item);
    action.execute(hostManager.getConnection(), new ApiCallback<String>() {
        @Override
        public void onSuccess(String result) {
            if (!fragment.isAdded())
                return;
            boolean switchToRemote = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
                    Settings.KEY_PREF_SWITCH_TO_REMOTE_AFTER_MEDIA_START,
                    Settings.DEFAULT_PREF_SWITCH_TO_REMOTE_AFTER_MEDIA_START);
            if (switchToRemote) {
                Intent launchIntent = new Intent(context, RemoteActivity.class);
                context.startActivity(launchIntent);
            } else {
                Toast.makeText(context, R.string.now_playing, 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_play_media_file, description);
            Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show();
        }
    }, callbackHandler);
}

From source file:com.brq.wallet.activity.AddAccountActivity.java

public static void callMe(Fragment fragment, int requestCode) {
    Intent intent = new Intent(fragment.getActivity(), AddAccountActivity.class);
    fragment.startActivityForResult(intent, requestCode);
}

From source file:com.vuze.android.remote.VuzeEasyTracker.java

public static IVuzeEasyTracker getInstance(Fragment fragment) {
    synchronized (VuzeEasyTracker.class) {
        if (vuzeEasyTracker == null) {
            return getInstance(fragment.getActivity());
        }//from   w w  w .  j a v  a  2 s  .c  o m
    }
    return vuzeEasyTracker;
}

From source file:com.github.michalbednarski.intentslab.valueeditors.framework.ChildFragmentWorkaround.java

/**
 * Start an activity for result on fragment
 *
 * Use this instead of standard startActivityForResult on child fragments
 */// ww  w  .j  a v a 2s .  c o  m
public static void startActivityForResultFromFragment(Fragment fragment, Intent intent, int requestCode) {

    FragmentActivity activity = fragment.getActivity();
    FragmentManager topFragmentManager = activity.getSupportFragmentManager();
    FragmentManager fragmentManager = fragment.getFragmentManager();

    // No workaround needed?
    if (topFragmentManager == fragmentManager) {
        fragment.startActivityForResult(intent, requestCode);
        return;
    }

    DeliverResultInfo deliverInfo = new DeliverResultInfo(fragment, requestCode);

    // Create instance
    ChildFragmentWorkaround instance = (ChildFragmentWorkaround) topFragmentManager.findFragmentByTag(TAG_F);
    if (instance == null) {
        instance = new ChildFragmentWorkaround();
        instance.mNextSendIntent = intent;
        instance.mNextSendDeliverInfo = deliverInfo;
        topFragmentManager.beginTransaction().add(instance, TAG_F).commit();
    } else {
        instance.doStartActivity(intent, deliverInfo);
    }

}

From source file:com.lvbo.template.common.Utils.PermissionUtils.java

/**
 * ??/*from  ww w .j a  v a2s.c  o m*/
 *
 * @param cxt
 * @param req
 * @return
 */
@TargetApi(23)
public static boolean checkSettingAlertPermission(Object cxt, int req) {
    if (cxt instanceof Activity) {
        Activity activity = (Activity) cxt;
        if (!Settings.canDrawOverlays(activity.getBaseContext())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + activity.getPackageName()));
            activity.startActivityForResult(intent, req);
            return false;
        }
    } else if (cxt instanceof Fragment) {
        Fragment fragment = (Fragment) cxt;
        if (!Settings.canDrawOverlays(fragment.getActivity())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + fragment.getActivity().getPackageName()));
            fragment.startActivityForResult(intent, req);
            Context c;
            return false;
        }
    } else {
        throw new RuntimeException("cxt is net a activity or fragment");
    }

    return true;
}

From source file:com.activiti.android.platform.intent.IntentUtils.java

public static boolean actionSendFeedbackEmail(Fragment fr) {
    try {/*w ww . ja va 2 s .  c  o  m*/
        ShareCompat.IntentBuilder iBuilder = ShareCompat.IntentBuilder.from(fr.getActivity());
        Context context = fr.getContext();
        // Email
        iBuilder.addEmailTo(context.getResources().getStringArray(R.array.bugreport_email));

        // Prepare Subject
        String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
        int versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;

        String subject = "Alfresco Activiti Android Feedback";
        iBuilder.setSubject(subject);

        // Content
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        String densityBucket = getDensityString(dm);

        Map<String, String> info = new LinkedHashMap<>();
        info.put("Version", versionName);
        info.put("Version code", Integer.toString(versionCode));
        info.put("Make", Build.MANUFACTURER);
        info.put("Model", Build.MODEL);
        info.put("Resolution", dm.heightPixels + "x" + dm.widthPixels);
        info.put("Density", dm.densityDpi + "dpi (" + densityBucket + ")");
        info.put("Release", Build.VERSION.RELEASE);
        info.put("API", String.valueOf(Build.VERSION.SDK_INT));
        info.put("Language", context.getResources().getConfiguration().locale.getDisplayLanguage());

        StringBuilder builder = new StringBuilder();
        builder.append("\n\n\n\n");
        builder.append("Alfresco Activiti Mobile and device details\n");
        builder.append("-------------------\n").toString();
        for (Map.Entry entry : info.entrySet()) {
            builder.append(entry.getKey()).append(": ").append(entry.getValue()).append('\n');
        }

        builder.append("-------------------\n\n").toString();
        iBuilder.setType("message/rfc822");
        iBuilder.setText(builder.toString());
        iBuilder.setChooserTitle(fr.getString(R.string.settings_feedback_email)).startChooser();

        return true;
    } catch (Exception e) {
        Log.d("Action Send Feedback", Log.getStackTraceString(e));
    }

    return false;
}

From source file:com.domowe.apki.lista2.Utils.java

public static void setFragmentFile(Fragment fragment, String name) {
    if (fragment instanceof NoteFragment)
        ((NoteFragment) fragment).setFile(getFileFromName(fragment.getActivity(), name));
    if (fragment instanceof PrivateListFragment)
        ((PrivateListFragment) fragment).setFile(getFileFromName(fragment.getActivity(), name));
}

From source file:com.yek.keyboard.ui.settings.MainSettingsActivity.java

/**
 * Will set the title in the hosting Activity's title.
 * Will only set the title if the fragment is hosted by the Activity's manager, and not inner one.
 *///from www . j a  va 2 s. c  om
public static void setActivityTitle(Fragment fragment, CharSequence title) {
    FragmentActivity activity = fragment.getActivity();
    if (activity.getSupportFragmentManager() == fragment.getFragmentManager()) {
        activity.setTitle(title);
    }
}

From source file:fr.shywim.antoinedaniel.utils.FragmentUtils.java

/**
 * @param frag The Fragment whose parent is to be found
 * @param callbackInterface The interface class that the parent should implement
 *
 * @return The parent of frag that implements the callbackInterface or null
 * if no such parent can be found//w  w  w.  j a v a 2 s  .  c om
 */
public static <T> T getParent(Fragment frag, Class<T> callbackInterface) {
    Fragment parentFragment = frag.getParentFragment();
    if (parentFragment != null && callbackInterface.isInstance(parentFragment)) {
        return (T) parentFragment;
    } else {
        Activity activity = frag.getActivity();
        if (activity != null && callbackInterface.isInstance(activity)) {
            return (T) activity;
        }
    }
    return null;
}

From source file:com.laevatein.internal.ui.helper.SelectedGridViewHelper.java

public static void setUpGridView(Fragment fragment, ItemViewResources resources,
        SelectedUriCollection collection) {
    GridView gridView = (GridView) fragment.getView().findViewById(R.id.l_grid_photo);
    SelectedPhotoAdapter adapter = new SelectedPhotoAdapter(fragment.getActivity(), resources, collection);
    adapter.registerCheckStateListener((SelectedPhotoAdapter.CheckStateListener) fragment);
    gridView.setAdapter(adapter);/*from   w w  w .  j a  v  a2  s .  c o  m*/

    TextView emptyMessage = (TextView) fragment.getView().findViewById(R.id.l_label_empty);
    emptyMessage.setText(R.string.l_empty_selection);
    gridView.setEmptyView(emptyMessage);
}