Example usage for android.app Fragment getActivity

List of usage examples for android.app Fragment getActivity

Introduction

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

Prototype

final public Activity getActivity() 

Source Link

Document

Return the Activity this fragment is currently associated with.

Usage

From source file:org.alfresco.mobile.android.platform.intent.BaseActionUtils.java

/**
 * Allow user to share a file with other applications.
 * /*  w ww  .j  a va2s.com*/
 * @param fr
 * @param contentFile
 */
public static void actionShareContent(Fragment fr, File contentFile) {
    try {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_SUBJECT, contentFile.getName());
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(contentFile));
        i.setType(MimeTypeManager.getInstance(fr.getActivity()).getMIMEType(contentFile.getName()));
        fr.startActivity(Intent.createChooser(i, fr.getActivity().getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(),
                R.string.error_unable_share_content);
    }
}

From source file:org.alfresco.mobile.android.platform.intent.BaseActionUtils.java

/**
 * Allow to send a link to other application installed in the device.
 * /*from   www  .j ava 2  s  .  c o m*/
 * @param fr
 * @param url
 */
public static void actionShareLink(Fragment fr, String url) {
    try {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_SUBJECT, R.string.share_url_long);
        i.putExtra(Intent.EXTRA_TEXT, url);
        fr.startActivity(Intent.createChooser(i, fr.getActivity().getText(R.string.share_url)));
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(),
                R.string.error_unable_share_link);
    }
}

From source file:com.miandui.utils.runtimePermission.AndPermission.java

/**
 * Get default setting dialog./*from w w w . ja  v a2s. com*/
 *
 * @param fragment    {@link android.app.Fragment}.
 * @param requestCode requestCode for {@code startActivityForResult(Intent, int)}.
 * @return {@link SettingDialog}.
 */
public static @NonNull SettingDialog defaultSettingDialog(@NonNull android.app.Fragment fragment,
        int requestCode) {
    return new SettingDialog(fragment.getActivity(), new SettingExecutor(fragment, requestCode));
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static void actionSendDocument(Fragment fr, File myFile) {
    actionSend(fr.getActivity(), myFile);
}

From source file:com.miandui.utils.runtimePermission.AndPermission.java

/**
 * Parse the request results./* ww w .  j a va2 s  .  co  m*/
 *
 * @param fragment     {@link android.app.Fragment}.
 * @param requestCode  request code.
 * @param permissions  all permissions.
 * @param grantResults results.
 */
public static void onRequestPermissionsResult(@NonNull android.app.Fragment fragment, int requestCode,
        @NonNull String[] permissions, int[] grantResults) {
    callbackAnnotation(fragment.getActivity(), requestCode, permissions, grantResults);
}

From source file:org.alfresco.mobile.android.platform.intent.BaseActionUtils.java

public static void openIn(Fragment fr, File myFile, String mimeType) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data = Uri.fromFile(myFile);/*from   w  w w. j  ava2  s  .  c o m*/
    intent.setDataAndType(data, mimeType.toLowerCase());

    try {
        fr.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(),
                R.string.error_unable_open_file);
    }
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static void actionOpenIn(Fragment fr, File myFile) {
    try {/*from  w ww .j av a2 s.  c  o  m*/
        String mimeType = MimeTypeManager.getMIMEType(fr.getActivity(), myFile.getName());
        if (DataProtectionManager.getInstance(fr.getActivity()).isEncrypted(myFile.getPath())) {
            WaitingDialogFragment dialog = WaitingDialogFragment.newInstance(R.string.data_protection,
                    R.string.decryption_title, true);
            dialog.show(fr.getActivity().getFragmentManager(), WaitingDialogFragment.TAG);
            DataProtectionManager.getInstance(fr.getActivity()).decrypt(
                    SessionUtils.getAccount(fr.getActivity()), myFile, DataProtectionManager.ACTION_COPY);
        } else {
            actionView(fr.getActivity(), myFile, mimeType, null);
        }
    } catch (Exception e) {
        MessengerManager.showToast(fr.getActivity(), R.string.error_unable_open_file);
    }
}

From source file:cis350.blanket.IntentIntegrator.java

/**
 * @param fragment {@link Fragment} invoking the integration.
 *  {@link #startActivityForResult(Intent, int)} will be called on the {@link Fragment} instead
 *  of an {@link Activity}/*from  w  w  w .ja  v a  2 s .c om*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static IntentIntegrator forFragment(Fragment fragment) {
    IntentIntegrator integrator = new IntentIntegrator(fragment.getActivity());
    integrator.fragment = fragment;
    return integrator;
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static void actionSendDocumentsToAlfresco(Fragment fr, List<File> files) {
    if (files.size() == 1) {
        actionSendDocumentToAlfresco(fr.getActivity(), files.get(0));
        return;/*from   w  w w .j  a  v a 2  s. c  o  m*/
    }

    try {
        Intent i = new Intent(fr.getActivity(), PublicDispatcherActivity.class);
        i.setAction(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(i);
    } catch (ActivityNotFoundException e) {
        MessengerManager.showToast(fr.getActivity(), R.string.error_unable_share_content);
    }
}

From source file:org.alfresco.mobile.android.platform.intent.BaseActionUtils.java

/**
 * Allow to open a file with an associated application installed in the
 * device and saved it backed via a requestcode...
 * /*www . j  a  v a2  s  .  c  om*/
 * @param myFile
 * @param mimeType
 */
public static void openIn(Fragment fr, File myFile, String mimeType, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data = Uri.fromFile(myFile);
    intent.setDataAndType(data, mimeType.toLowerCase());

    try {
        fr.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(),
                R.string.error_unable_open_file);
    }
}