android.support.v4.content.IntentCompat Java Examples

The following examples show how to use android.support.v4.content.IntentCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskStackBuilder.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <p>On devices that do not support API level 11 or higher the topmost activity
 * will be started as a new task. On devices that do support API level 11 or higher
 * the new task stack will be created in its entirety.</p>
 *
 * @param options Additional options for how the Activity should be started.
 * See {@link android.content.Context#startActivity(Intent, Bundle)
 */
public void startActivities(Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException(
                "No intents added to TaskStackBuilder; cannot startActivities");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    if (!ContextCompat.startActivities(mSourceContext, intents, options)) {
        Intent topIntent = new Intent(intents[intents.length - 1]);
        topIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSourceContext.startActivity(topIntent);
    }
}
 
Example #2
Source File: NavUtils.java    From guideshow with MIT License 6 votes vote down vote up
@Override
public Intent getParentActivityIntent(Activity activity) {
    String parentName = NavUtils.getParentActivityName(activity);
    if (parentName == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(activity, parentName);
    try {
        final String grandparent = NavUtils.getParentActivityName(activity, target);
        final Intent parentIntent = grandparent == null
                ? IntentCompat.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
 
Example #3
Source File: TaskStackBuilder.java    From guideshow with MIT License 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <p>On devices that do not support API level 11 or higher the topmost activity
 * will be started as a new task. On devices that do support API level 11 or higher
 * the new task stack will be created in its entirety.</p>
 *
 * @param options Additional options for how the Activity should be started.
 * See {@link android.content.Context#startActivity(Intent, Bundle)
 */
public void startActivities(Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException(
                "No intents added to TaskStackBuilder; cannot startActivities");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    if (!ContextCompat.startActivities(mSourceContext, intents, options)) {
        Intent topIntent = new Intent(intents[intents.length - 1]);
        topIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSourceContext.startActivity(topIntent);
    }
}
 
Example #4
Source File: SettingsFragment.java    From secrecy with Apache License 2.0 6 votes vote down vote up
private void confirm_stealth(String password) {
    final View dialogView = View.inflate(context, R.layout.dialog_confirm_stealth, null);
    ((TextView) dialogView
            .findViewById(R.id.stealth_keycode))
            .append(password);
    new AlertDialog.Builder(context)
            .setInverseBackgroundForced(true)
            .setView(dialogView)
            .setMessage(R.string.Settings__try_once_before_hide)
            .setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    SharedPreferences.Editor editor
                            = PreferenceManager.getDefaultSharedPreferences(context).edit();
                    editor.putBoolean(Config.SHOW_STEALTH_MODE_TUTORIAL, true);
                    editor.apply();
                    Intent dial = new Intent();
                    dial.setAction("android.intent.action.DIAL");
                    dial.setData(Uri.parse("tel:"));
                    dial.setFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(dial);
                    getActivity().finish();
                }
            })
            .show();
}
 
Example #5
Source File: NavUtils.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public static Intent getParentActivityIntent(Context context, ComponentName componentname)
{
    String s = getParentActivityName(context, componentname);
    if (s == null)
    {
        return null;
    }
    ComponentName componentname1 = new ComponentName(componentname.getPackageName(), s);
    if (getParentActivityName(context, componentname1) == null)
    {
        return IntentCompat.makeMainActivity(componentname1);
    } else
    {
        return (new Intent()).setComponent(componentname1);
    }
}
 
Example #6
Source File: NavUtils.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public static Intent getParentActivityIntent(Context context, Class class1)
{
    String s = getParentActivityName(context, new ComponentName(context, class1));
    if (s == null)
    {
        return null;
    }
    ComponentName componentname = new ComponentName(context, s);
    if (getParentActivityName(context, componentname) == null)
    {
        return IntentCompat.makeMainActivity(componentname);
    } else
    {
        return (new Intent()).setComponent(componentname);
    }
}
 
Example #7
Source File: TaskStackBuilder.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <p>On devices that do not support API level 11 or higher the topmost activity
 * will be started as a new task. On devices that do support API level 11 or higher
 * the new task stack will be created in its entirety.</p>
 *
 * @param options Additional options for how the Activity should be started.
 * See {@link android.content.Context#startActivity(Intent, Bundle)
 */
public void startActivities(Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException(
                "No intents added to TaskStackBuilder; cannot startActivities");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    if (!ContextCompat.startActivities(mSourceContext, intents, options)) {
        Intent topIntent = new Intent(intents[intents.length - 1]);
        topIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSourceContext.startActivity(topIntent);
    }
}
 
Example #8
Source File: NavUtils.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
public Intent getParentActivityIntent(Activity activity) {
    String parentName = NavUtils.getParentActivityName(activity);
    if (parentName == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(activity, parentName);
    try {
        final String grandparent = NavUtils.getParentActivityName(activity, target);
        final Intent parentIntent = grandparent == null
                ? IntentCompat.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
 
Example #9
Source File: TaskStackBuilder.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <p>On devices that do not support API level 11 or higher the topmost activity
 * will be started as a new task. On devices that do support API level 11 or higher
 * the new task stack will be created in its entirety.</p>
 *
 * @param options Additional options for how the Activity should be started.
 * See {@link android.content.Context#startActivity(Intent, Bundle)
 */
public void startActivities(Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException(
                "No intents added to TaskStackBuilder; cannot startActivities");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    if (!ContextCompat.startActivities(mSourceContext, intents, options)) {
        Intent topIntent = new Intent(intents[intents.length - 1]);
        topIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSourceContext.startActivity(topIntent);
    }
}
 
Example #10
Source File: NavUtils.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Intent getParentActivityIntent(Activity activity) {
    String parentName = NavUtils.getParentActivityName(activity);
    if (parentName == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(activity, parentName);
    try {
        final String grandparent = NavUtils.getParentActivityName(activity, target);
        final Intent parentIntent = grandparent == null
                ? IntentCompat.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
 
Example #11
Source File: TaskStackBuilder.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <p>On devices that do not support API level 11 or higher the topmost activity
 * will be started as a new task. On devices that do support API level 11 or higher
 * the new task stack will be created in its entirety.</p>
 *
 * @param options Additional options for how the Activity should be started.
 * See {@link android.content.Context#startActivity(Intent, Bundle)
 */
public void startActivities(Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException(
                "No intents added to TaskStackBuilder; cannot startActivities");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    if (!ContextCompat.startActivities(mSourceContext, intents, options)) {
        Intent topIntent = new Intent(intents[intents.length - 1]);
        topIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSourceContext.startActivity(topIntent);
    }
}
 
Example #12
Source File: NavUtils.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public Intent getParentActivityIntent(Activity activity) {
    String parentName = NavUtils.getParentActivityName(activity);
    if (parentName == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(activity, parentName);
    try {
        final String grandparent = NavUtils.getParentActivityName(activity, target);
        final Intent parentIntent = grandparent == null
                ? IntentCompat.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
 
Example #13
Source File: NavUtils.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
@Override
public Intent getParentActivityIntent(Activity activity) {
    String parentName = NavUtils.getParentActivityName(activity);
    if (parentName == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(activity, parentName);
    try {
        final String grandparent = NavUtils.getParentActivityName(activity, target);
        final Intent parentIntent = grandparent == null
                ? IntentCompat.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
 
Example #14
Source File: OutgoingCallReceiver.java    From secrecy with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {

    // Gets the intent, check if it matches our secret code
    if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction()) &&
            intent.getExtras() != null) {
        Intent launcher = new Intent(context, MainActivity.class);
        //These flags are added to make the new mainActivity in the home stack.
        //i.e. back button returns to home not dialer.
        launcher.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
        String phoneNumber = intent.getExtras().getString(android.content.Intent.EXTRA_PHONE_NUMBER);
        String openPin = PreferenceManager.getDefaultSharedPreferences(context)
                .getString(Config.STEALTH_MODE_PASSWORD, "");
        if (!openPin.equals("")) {
            if (("*#" + openPin).equals(phoneNumber)) {
                // Launch the main app!!
                launchActivity(context, launcher);
            }
        }
    }
}
 
Example #15
Source File: TaskStackBuilder.java    From guideshow with MIT License 5 votes vote down vote up
/**
 * Return an array containing the intents added to this builder. The intent at the
 * root of the task stack will appear as the first item in the array and the
 * intent at the top of the stack will appear as the last item.
 *
 * @return An array containing the intents added to this builder.
 */
public Intent[] getIntents() {
    Intent[] intents = new Intent[mIntents.size()];
    if (intents.length == 0) return intents;

    intents[0] = new Intent(mIntents.get(0)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    for (int i = 1; i < intents.length; i++) {
        intents[i] = new Intent(mIntents.get(i));
    }
    return intents;
}
 
Example #16
Source File: NavUtils.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
/**
 * Obtain an {@link Intent} that will launch an explicit target activity
 * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element in the application's manifest.
 *
 * @param context Context for looking up the activity component for the source activity
 * @param componentName ComponentName for the source Activity
 * @return a new Intent targeting the defined parent activity of sourceActivity
 * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid
 */
public static Intent getParentActivityIntent(Context context, ComponentName componentName)
        throws NameNotFoundException {
    String parentActivity = getParentActivityName(context, componentName);
    if (parentActivity == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(
            componentName.getPackageName(), parentActivity);
    final String grandparent = getParentActivityName(context, target);
    final Intent parentIntent = grandparent == null
            ? IntentCompat.makeMainActivity(target)
            : new Intent().setComponent(target);
    return parentIntent;
}
 
Example #17
Source File: LoaderCustomSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public PackageIntentReceiver(AppListLoader loader) {
    mLoader = loader;
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    mLoader.getContext().registerReceiver(this, filter);
    // Register for events related to sdcard installation.
    IntentFilter sdFilter = new IntentFilter();
    sdFilter.addAction(IntentCompat.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter.addAction(IntentCompat.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mLoader.getContext().registerReceiver(this, sdFilter);
}
 
Example #18
Source File: ShareCompat.java    From guideshow with MIT License 5 votes vote down vote up
/**
 * Get the styled HTML text shared with the target activity.
 * If no HTML text was supplied but {@link Intent#EXTRA_TEXT} contained
 * styled text, it will be converted to HTML if possible and returned.
 * If the text provided by {@link Intent#EXTRA_TEXT} was not styled text,
 * it will be escaped by {@link android.text.Html#escapeHtml(CharSequence)}
 * and returned. If no text was provided at all, this method will return null.
 *
 * @return Styled text provided by the sender as HTML.
 */
public String getHtmlText() {
    String result = mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result == null) {
        CharSequence text = getText();
        if (text instanceof Spanned) {
            result = Html.toHtml((Spanned) text);
        } else if (text != null) {
            result = IMPL.escapeHtml(text);
        }
    }
    return result;
}
 
Example #19
Source File: TaskStackBuilder.java    From guideshow with MIT License 5 votes vote down vote up
public PendingIntent getPendingIntent(Context context, Intent[] intents, int requestCode,
        int flags, Bundle options) {
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    return TaskStackBuilderHoneycomb.getActivitiesPendingIntent(context, requestCode,
            intents, flags);
}
 
Example #20
Source File: TaskStackBuilder.java    From guideshow with MIT License 5 votes vote down vote up
public PendingIntent getPendingIntent(Context context, Intent[] intents, int requestCode,
        int flags, Bundle options) {
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    return TaskStackBuilderJellybean.getActivitiesPendingIntent(context, requestCode,
            intents, flags, options);
}
 
Example #21
Source File: NavUtils.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
/**
 * Obtain an {@link Intent} that will launch an explicit target activity
 * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element in the application's manifest.
 *
 * @param context Context for looking up the activity component for sourceActivityClass
 * @param sourceActivityClass {@link java.lang.Class} object for an Activity class
 * @return a new Intent targeting the defined parent activity of sourceActivity
 * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid
 */
public static Intent getParentActivityIntent(Context context, Class<?> sourceActivityClass)
        throws NameNotFoundException {
    String parentActivity = getParentActivityName(context,
            new ComponentName(context, sourceActivityClass));
    if (parentActivity == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(context, parentActivity);
    final String grandparent = getParentActivityName(context, target);
    final Intent parentIntent = grandparent == null
            ? IntentCompat.makeMainActivity(target)
            : new Intent().setComponent(target);
    return parentIntent;
}
 
Example #22
Source File: TaskStackBuilder.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public PendingIntent getPendingIntent(Context context, Intent[] intents, int requestCode,
        int flags, Bundle options) {
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    return TaskStackBuilderHoneycomb.getActivitiesPendingIntent(context, requestCode,
            intents, flags);
}
 
Example #23
Source File: NavUtils.java    From guideshow with MIT License 5 votes vote down vote up
/**
 * Obtain an {@link Intent} that will launch an explicit target activity
 * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element in the application's manifest.
 *
 * @param context Context for looking up the activity component for sourceActivityClass
 * @param sourceActivityClass {@link java.lang.Class} object for an Activity class
 * @return a new Intent targeting the defined parent activity of sourceActivity
 * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid
 */
public static Intent getParentActivityIntent(Context context, Class<?> sourceActivityClass)
        throws NameNotFoundException {
    String parentActivity = getParentActivityName(context,
            new ComponentName(context, sourceActivityClass));
    if (parentActivity == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(context, parentActivity);
    final String grandparent = getParentActivityName(context, target);
    final Intent parentIntent = grandparent == null
            ? IntentCompat.makeMainActivity(target)
            : new Intent().setComponent(target);
    return parentIntent;
}
 
Example #24
Source File: ShareCompat.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
/**
 * Get the styled HTML text shared with the target activity.
 * If no HTML text was supplied but {@link Intent#EXTRA_TEXT} contained
 * styled text, it will be converted to HTML if possible and returned.
 * If the text provided by {@link Intent#EXTRA_TEXT} was not styled text,
 * it will be escaped by {@link android.text.Html#escapeHtml(CharSequence)}
 * and returned. If no text was provided at all, this method will return null.
 *
 * @return Styled text provided by the sender as HTML.
 */
public String getHtmlText() {
    String result = mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result == null) {
        CharSequence text = getText();
        if (text instanceof Spanned) {
            result = Html.toHtml((Spanned) text);
        } else if (text != null) {
            result = IMPL.escapeHtml(text);
        }
    }
    return result;
}
 
Example #25
Source File: NavUtils.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain an {@link Intent} that will launch an explicit target activity
 * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element in the application's manifest.
 *
 * @param context Context for looking up the activity component for the source activity
 * @param componentName ComponentName for the source Activity
 * @return a new Intent targeting the defined parent activity of sourceActivity
 * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid
 */
public static Intent getParentActivityIntent(Context context, ComponentName componentName)
        throws NameNotFoundException {
    String parentActivity = getParentActivityName(context, componentName);
    if (parentActivity == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(
            componentName.getPackageName(), parentActivity);
    final String grandparent = getParentActivityName(context, target);
    final Intent parentIntent = grandparent == null
            ? IntentCompat.makeMainActivity(target)
            : new Intent().setComponent(target);
    return parentIntent;
}
 
Example #26
Source File: NavUtils.java    From guideshow with MIT License 5 votes vote down vote up
/**
 * Obtain an {@link Intent} that will launch an explicit target activity
 * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element in the application's manifest.
 *
 * @param context Context for looking up the activity component for the source activity
 * @param componentName ComponentName for the source Activity
 * @return a new Intent targeting the defined parent activity of sourceActivity
 * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid
 */
public static Intent getParentActivityIntent(Context context, ComponentName componentName)
        throws NameNotFoundException {
    String parentActivity = getParentActivityName(context, componentName);
    if (parentActivity == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(
            componentName.getPackageName(), parentActivity);
    final String grandparent = getParentActivityName(context, target);
    final Intent parentIntent = grandparent == null
            ? IntentCompat.makeMainActivity(target)
            : new Intent().setComponent(target);
    return parentIntent;
}
 
Example #27
Source File: NavUtils.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain an {@link Intent} that will launch an explicit target activity
 * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element in the application's manifest.
 *
 * @param context Context for looking up the activity component for sourceActivityClass
 * @param sourceActivityClass {@link java.lang.Class} object for an Activity class
 * @return a new Intent targeting the defined parent activity of sourceActivity
 * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid
 */
public static Intent getParentActivityIntent(Context context, Class<?> sourceActivityClass)
        throws NameNotFoundException {
    String parentActivity = getParentActivityName(context,
            new ComponentName(context, sourceActivityClass));
    if (parentActivity == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(context, parentActivity);
    final String grandparent = getParentActivityName(context, target);
    final Intent parentIntent = grandparent == null
            ? IntentCompat.makeMainActivity(target)
            : new Intent().setComponent(target);
    return parentIntent;
}
 
Example #28
Source File: TaskStackBuilder.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
/**
 * Return an array containing the intents added to this builder. The intent at the
 * root of the task stack will appear as the first item in the array and the
 * intent at the top of the stack will appear as the last item.
 *
 * @return An array containing the intents added to this builder.
 */
public Intent[] getIntents() {
    Intent[] intents = new Intent[mIntents.size()];
    if (intents.length == 0) return intents;

    intents[0] = new Intent(mIntents.get(0)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    for (int i = 1; i < intents.length; i++) {
        intents[i] = new Intent(mIntents.get(i));
    }
    return intents;
}
 
Example #29
Source File: TaskStackBuilder.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a {@link PendingIntent} for launching the task constructed by this builder so far.
 *
 * @param requestCode Private request code for the sender
 * @param flags May be {@link PendingIntent#FLAG_ONE_SHOT},
 *              {@link PendingIntent#FLAG_NO_CREATE}, {@link PendingIntent#FLAG_CANCEL_CURRENT},
 *              {@link PendingIntent#FLAG_UPDATE_CURRENT}, or any of the flags supported by
 *              {@link Intent#fillIn(Intent, int)} to control which unspecified parts of the
 *              intent that can be supplied when the actual send happens.
 * @param options Additional options for how the Activity should be started.
 * See {@link android.content.Context#startActivity(Intent, Bundle)
 * @return The obtained PendingIntent
 */
public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException(
                "No intents added to TaskStackBuilder; cannot getPendingIntent");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            IntentCompat.FLAG_ACTIVITY_CLEAR_TASK |
            IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    // Appropriate flags will be added by the call below.
    return IMPL.getPendingIntent(mSourceContext, intents, requestCode, flags, options);
}
 
Example #30
Source File: ShareCompat.java    From letv with Apache License 2.0 5 votes vote down vote up
public String getHtmlText() {
    String result = this.mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result != null) {
        return result;
    }
    CharSequence text = getText();
    if (text instanceof Spanned) {
        return Html.toHtml((Spanned) text);
    }
    if (text != null) {
        return ShareCompat.IMPL.escapeHtml(text);
    }
    return result;
}