1575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell/*
2575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * Copyright (C) 2012 The Android Open Source Project
3575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell *
4575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
5575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * you may not use this file except in compliance with the License.
6575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * You may obtain a copy of the License at
7575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell *
8575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
9575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell *
10575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * Unless required by applicable law or agreed to in writing, software
11575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
12575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * See the License for the specific language governing permissions and
14575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * limitations under the License.
15575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell */
16575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell
17575e098da5bc16ff8b95ca080284253fd206fe12Adam Powellpackage android.support.v4.content;
18575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell
19575e098da5bc16ff8b95ca080284253fd206fe12Adam Powellimport android.app.Activity;
20575e098da5bc16ff8b95ca080284253fd206fe12Adam Powellimport android.content.Context;
21575e098da5bc16ff8b95ca080284253fd206fe12Adam Powellimport android.content.Intent;
22575e098da5bc16ff8b95ca080284253fd206fe12Adam Powellimport android.os.Build;
23575e098da5bc16ff8b95ca080284253fd206fe12Adam Powellimport android.os.Bundle;
24575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell
25575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell/**
26575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * Helper for accessing features in {@link android.content.Context}
27575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell * introduced after API level 4 in a backwards compatible fashion.
28575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell */
29575e098da5bc16ff8b95ca080284253fd206fe12Adam Powellpublic class ContextCompat {
30575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell
31575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell    /**
32575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * Start a set of activities as a synthesized task stack, if able.
33575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
34575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * <p>In API level 11 (Android 3.0/Honeycomb) the recommended conventions for
35575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * app navigation using the back key changed. The back key's behavior is local
36575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * to the current task and does not capture navigation across different tasks.
37575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * Navigating across tasks and easily reaching the previous task is accomplished
38575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * through the "recents" UI, accessible through the software-provided Recents key
39575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * on the navigation or system bar. On devices with the older hardware button configuration
40575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * the recents UI can be accessed with a long press on the Home key.</p>
41575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
42575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * <p>When crossing from one task stack to another post-Android 3.0,
43575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * the application should synthesize a back stack/history for the new task so that
44575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * the user may navigate out of the new task and back to the Launcher by repeated
45575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * presses of the back key. Back key presses should not navigate across task stacks.</p>
46575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
47575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * <p>startActivities provides a mechanism for constructing a synthetic task stack of
48575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * multiple activities. If the underlying API is not available on the system this method
49575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * will return false.</p>
50575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
51575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * @param context Start activities using this activity as the starting context
52575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * @param intents Array of intents defining the activities that will be started. The element
53575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *                length-1 will correspond to the top activity on the resulting task stack.
54575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * @return true if the underlying API was available and the call was successful, false otherwise
55575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     */
56575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell    public static boolean startActivities(Context context, Intent[] intents) {
57575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell        return startActivities(context, intents, null);
58575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell    }
59575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell
60575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell    /**
61575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * Start a set of activities as a synthesized task stack, if able.
62575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
63575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * <p>In API level 11 (Android 3.0/Honeycomb) the recommended conventions for
64575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * app navigation using the back key changed. The back key's behavior is local
65575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * to the current task and does not capture navigation across different tasks.
66575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * Navigating across tasks and easily reaching the previous task is accomplished
67575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * through the "recents" UI, accessible through the software-provided Recents key
68575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * on the navigation or system bar. On devices with the older hardware button configuration
69575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * the recents UI can be accessed with a long press on the Home key.</p>
70575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
71575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * <p>When crossing from one task stack to another post-Android 3.0,
72575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * the application should synthesize a back stack/history for the new task so that
73575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * the user may navigate out of the new task and back to the Launcher by repeated
74575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * presses of the back key. Back key presses should not navigate across task stacks.</p>
75575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
76575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * <p>startActivities provides a mechanism for constructing a synthetic task stack of
77575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * multiple activities. If the underlying API is not available on the system this method
78575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * will return false.</p>
79575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *
80575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * @param context Start activities using this activity as the starting context
81575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * @param intents Array of intents defining the activities that will be started. The element
82575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     *                length-1 will correspond to the top activity on the resulting task stack.
83575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * @param options Additional options for how the Activity should be started.
84575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * See {@link android.content.Context#startActivity(Intent, Bundle)
85575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     * @return true if the underlying API was available and the call was successful, false otherwise
86575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell     */
87575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell    public static boolean startActivities(Context context, Intent[] intents,
88575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell            Bundle options) {
89575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell        final int version = Build.VERSION.SDK_INT;
90575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell        if (version >= 16) {
91575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell            ContextCompatJellybean.startActivities(context, intents, options);
92575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell            return true;
93575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell        } else if (version >= 11) {
94575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell            ContextCompatHoneycomb.startActivities(context, intents);
95575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell            return true;
96575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell        }
97575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell        return false;
98575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell    }
99575e098da5bc16ff8b95ca080284253fd206fe12Adam Powell}
100