The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 19 | import static android.os.Build.VERSION_CODES.O; |
| 20 | |
| 21 | import static java.lang.Character.MIN_VALUE; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 22 | |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 23 | import android.annotation.CallSuper; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 24 | import android.annotation.DrawableRes; |
| 25 | import android.annotation.IdRes; |
| 26 | import android.annotation.IntDef; |
| 27 | import android.annotation.LayoutRes; |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 28 | import android.annotation.MainThread; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 32 | import android.annotation.StyleRes; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 33 | import android.annotation.SystemApi; |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 34 | import android.app.VoiceInteractor.Request; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 35 | import android.app.admin.DevicePolicyManager; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 36 | import android.app.assist.AssistContent; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 37 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.content.ComponentName; |
| 39 | import android.content.ContentResolver; |
| 40 | import android.content.Context; |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 41 | import android.content.CursorLoader; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 42 | import android.content.IIntentSender; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 43 | import android.content.Intent; |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 44 | import android.content.IntentSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.SharedPreferences; |
| 46 | import android.content.pm.ActivityInfo; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 47 | import android.content.pm.ApplicationInfo; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
| 49 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.content.res.Configuration; |
| 51 | import android.content.res.Resources; |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 52 | import android.content.res.TypedArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.database.Cursor; |
| 54 | import android.graphics.Bitmap; |
| 55 | import android.graphics.Canvas; |
Winson | 2d47683 | 2016-02-17 14:53:46 -0800 | [diff] [blame] | 56 | import android.graphics.Color; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 57 | import android.graphics.Rect; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.graphics.drawable.Drawable; |
| 59 | import android.media.AudioManager; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 60 | import android.media.session.MediaController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.net.Uri; |
Adam Powell | d3c63a6 | 2016-06-09 12:36:16 -0700 | [diff] [blame] | 62 | import android.os.BadParcelableException; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 63 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.os.Handler; |
| 66 | import android.os.IBinder; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 67 | import android.os.Looper; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 68 | import android.os.Parcelable; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 69 | import android.os.PersistableBundle; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 70 | import android.os.RemoteException; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 71 | import android.os.ServiceManager.ServiceNotFoundException; |
Brad Fitzpatrick | 7580357 | 2011-01-13 14:21:03 -0800 | [diff] [blame] | 72 | import android.os.StrictMode; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 73 | import android.os.SystemProperties; |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 74 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.text.Selection; |
| 76 | import android.text.SpannableStringBuilder; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 77 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.text.method.TextKeyListener; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 79 | import android.transition.Scene; |
| 80 | import android.transition.TransitionManager; |
| 81 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.util.EventLog; |
| 84 | import android.util.Log; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 85 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 86 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.util.SparseArray; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 88 | import android.util.SuperNotCalledException; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 89 | import android.view.ActionMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.view.ContextMenu; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 91 | import android.view.ContextMenu.ContextMenuInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.view.ContextThemeWrapper; |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 93 | import android.view.DragAndDropPermissions; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 94 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.view.KeyEvent; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 96 | import android.view.KeyboardShortcutGroup; |
| 97 | import android.view.KeyboardShortcutInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.view.LayoutInflater; |
| 99 | import android.view.Menu; |
| 100 | import android.view.MenuInflater; |
| 101 | import android.view.MenuItem; |
| 102 | import android.view.MotionEvent; |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 103 | import android.view.SearchEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.view.View; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 105 | import android.view.View.OnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.ViewGroup; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 107 | import android.view.ViewGroup.LayoutParams; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.ViewManager; |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 109 | import android.view.ViewRootImpl; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 110 | import android.view.ViewRootImpl.ActivityConfigCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import android.view.Window; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 112 | import android.view.Window.WindowControllerCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 114 | import android.view.WindowManagerGlobal; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 115 | import android.view.accessibility.AccessibilityEvent; |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 116 | import android.view.autofill.AutofillManager; |
| 117 | import android.view.autofill.AutofillPopupWindow; |
| 118 | import android.view.autofill.IAutofillWindowPresenter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | import android.widget.AdapterView; |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 120 | import android.widget.Toast; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 121 | import android.widget.Toolbar; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 122 | |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 123 | import com.android.internal.annotations.GuardedBy; |
| 124 | import com.android.internal.app.IVoiceInteractor; |
| 125 | import com.android.internal.app.ToolbarActionBar; |
| 126 | import com.android.internal.app.WindowDecorActionBar; |
| 127 | import com.android.internal.policy.DecorView; |
| 128 | import com.android.internal.policy.PhoneWindow; |
| 129 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 130 | import java.io.FileDescriptor; |
| 131 | import java.io.PrintWriter; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 132 | import java.lang.annotation.Retention; |
| 133 | import java.lang.annotation.RetentionPolicy; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 134 | import java.util.ArrayList; |
| 135 | import java.util.HashMap; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 136 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * An activity is a single, focused thing that the user can do. Almost all |
| 140 | * activities interact with the user, so the Activity class takes care of |
| 141 | * creating a window for you in which you can place your UI with |
| 142 | * {@link #setContentView}. While activities are often presented to the user |
| 143 | * as full-screen windows, they can also be used in other ways: as floating |
| 144 | * windows (via a theme with {@link android.R.attr#windowIsFloating} set) |
| 145 | * or embedded inside of another activity (using {@link ActivityGroup}). |
| 146 | * |
| 147 | * There are two methods almost all subclasses of Activity will implement: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 148 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | * <ul> |
| 150 | * <li> {@link #onCreate} is where you initialize your activity. Most |
| 151 | * importantly, here you will usually call {@link #setContentView(int)} |
| 152 | * with a layout resource defining your UI, and using {@link #findViewById} |
| 153 | * to retrieve the widgets in that UI that you need to interact with |
| 154 | * programmatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 155 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | * <li> {@link #onPause} is where you deal with the user leaving your |
| 157 | * activity. Most importantly, any changes made by the user should at this |
| 158 | * point be committed (usually to the |
| 159 | * {@link android.content.ContentProvider} holding the data). |
| 160 | * </ul> |
| 161 | * |
| 162 | * <p>To be of use with {@link android.content.Context#startActivity Context.startActivity()}, all |
| 163 | * activity classes must have a corresponding |
| 164 | * {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 165 | * declaration in their package's <code>AndroidManifest.xml</code>.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 166 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | * <p>Topics covered here: |
| 168 | * <ol> |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 169 | * <li><a href="#Fragments">Fragments</a> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | * <li><a href="#ActivityLifecycle">Activity Lifecycle</a> |
| 171 | * <li><a href="#ConfigurationChanges">Configuration Changes</a> |
| 172 | * <li><a href="#StartingActivities">Starting Activities and Getting Results</a> |
| 173 | * <li><a href="#SavingPersistentState">Saving Persistent State</a> |
| 174 | * <li><a href="#Permissions">Permissions</a> |
| 175 | * <li><a href="#ProcessLifecycle">Process Lifecycle</a> |
| 176 | * </ol> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 177 | * |
| 178 | * <div class="special reference"> |
| 179 | * <h3>Developer Guides</h3> |
| 180 | * <p>The Activity class is an important part of an application's overall lifecycle, |
| 181 | * and the way activities are launched and put together is a fundamental |
| 182 | * part of the platform's application model. For a detailed perspective on the structure of an |
| 183 | * Android application and how activities behave, please read the |
| 184 | * <a href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a> and |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 185 | * <a href="{@docRoot}guide/components/tasks-and-back-stack.html">Tasks and Back Stack</a> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 186 | * developer guides.</p> |
| 187 | * |
| 188 | * <p>You can also find a detailed discussion about how to create activities in the |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 189 | * <a href="{@docRoot}guide/components/activities.html">Activities</a> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 190 | * developer guide.</p> |
| 191 | * </div> |
| 192 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 193 | * <a name="Fragments"></a> |
| 194 | * <h3>Fragments</h3> |
| 195 | * |
| 196 | * <p>Starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB}, Activity |
| 197 | * implementations can make use of the {@link Fragment} class to better |
| 198 | * modularize their code, build more sophisticated user interfaces for larger |
| 199 | * screens, and help scale their application between small and large screens. |
| 200 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | * <a name="ActivityLifecycle"></a> |
| 202 | * <h3>Activity Lifecycle</h3> |
| 203 | * |
| 204 | * <p>Activities in the system are managed as an <em>activity stack</em>. |
| 205 | * When a new activity is started, it is placed on the top of the stack |
| 206 | * and becomes the running activity -- the previous activity always remains |
| 207 | * below it in the stack, and will not come to the foreground again until |
| 208 | * the new activity exits.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 209 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | * <p>An activity has essentially four states:</p> |
| 211 | * <ul> |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 212 | * <li> If an activity is in the foreground of the screen (at the top of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | * the stack), |
| 214 | * it is <em>active</em> or <em>running</em>. </li> |
| 215 | * <li>If an activity has lost focus but is still visible (that is, a new non-full-sized |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 216 | * or transparent activity has focus on top of your activity), it |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | * is <em>paused</em>. A paused activity is completely alive (it |
| 218 | * maintains all state and member information and remains attached to |
| 219 | * the window manager), but can be killed by the system in extreme |
| 220 | * low memory situations. |
| 221 | * <li>If an activity is completely obscured by another activity, |
| 222 | * it is <em>stopped</em>. It still retains all state and member information, |
| 223 | * however, it is no longer visible to the user so its window is hidden |
| 224 | * and it will often be killed by the system when memory is needed |
| 225 | * elsewhere.</li> |
| 226 | * <li>If an activity is paused or stopped, the system can drop the activity |
| 227 | * from memory by either asking it to finish, or simply killing its |
| 228 | * process. When it is displayed again to the user, it must be |
| 229 | * completely restarted and restored to its previous state.</li> |
| 230 | * </ul> |
| 231 | * |
| 232 | * <p>The following diagram shows the important state paths of an Activity. |
| 233 | * The square rectangles represent callback methods you can implement to |
| 234 | * perform operations when the Activity moves between states. The colored |
| 235 | * ovals are major states the Activity can be in.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 236 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | * <p><img src="../../../images/activity_lifecycle.png" |
| 238 | * alt="State diagram for an Android Activity Lifecycle." border="0" /></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 239 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | * <p>There are three key loops you may be interested in monitoring within your |
| 241 | * activity: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 242 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | * <ul> |
| 244 | * <li>The <b>entire lifetime</b> of an activity happens between the first call |
| 245 | * to {@link android.app.Activity#onCreate} through to a single final call |
| 246 | * to {@link android.app.Activity#onDestroy}. An activity will do all setup |
| 247 | * of "global" state in onCreate(), and release all remaining resources in |
| 248 | * onDestroy(). For example, if it has a thread running in the background |
| 249 | * to download data from the network, it may create that thread in onCreate() |
| 250 | * and then stop the thread in onDestroy(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 251 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | * <li>The <b>visible lifetime</b> of an activity happens between a call to |
| 253 | * {@link android.app.Activity#onStart} until a corresponding call to |
| 254 | * {@link android.app.Activity#onStop}. During this time the user can see the |
| 255 | * activity on-screen, though it may not be in the foreground and interacting |
| 256 | * with the user. Between these two methods you can maintain resources that |
| 257 | * are needed to show the activity to the user. For example, you can register |
| 258 | * a {@link android.content.BroadcastReceiver} in onStart() to monitor for changes |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 259 | * that impact your UI, and unregister it in onStop() when the user no |
| 260 | * longer sees what you are displaying. The onStart() and onStop() methods |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | * can be called multiple times, as the activity becomes visible and hidden |
| 262 | * to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 263 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | * <li>The <b>foreground lifetime</b> of an activity happens between a call to |
| 265 | * {@link android.app.Activity#onResume} until a corresponding call to |
| 266 | * {@link android.app.Activity#onPause}. During this time the activity is |
| 267 | * in front of all other activities and interacting with the user. An activity |
| 268 | * can frequently go between the resumed and paused states -- for example when |
| 269 | * the device goes to sleep, when an activity result is delivered, when a new |
| 270 | * intent is delivered -- so the code in these methods should be fairly |
| 271 | * lightweight. |
| 272 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 273 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | * <p>The entire lifecycle of an activity is defined by the following |
| 275 | * Activity methods. All of these are hooks that you can override |
| 276 | * to do appropriate work when the activity changes state. All |
| 277 | * activities will implement {@link android.app.Activity#onCreate} |
| 278 | * to do their initial setup; many will also implement |
| 279 | * {@link android.app.Activity#onPause} to commit changes to data and |
| 280 | * otherwise prepare to stop interacting with the user. You should always |
| 281 | * call up to your superclass when implementing these methods.</p> |
| 282 | * |
| 283 | * </p> |
| 284 | * <pre class="prettyprint"> |
| 285 | * public class Activity extends ApplicationContext { |
| 286 | * protected void onCreate(Bundle savedInstanceState); |
| 287 | * |
| 288 | * protected void onStart(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 289 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | * protected void onRestart(); |
| 291 | * |
| 292 | * protected void onResume(); |
| 293 | * |
| 294 | * protected void onPause(); |
| 295 | * |
| 296 | * protected void onStop(); |
| 297 | * |
| 298 | * protected void onDestroy(); |
| 299 | * } |
| 300 | * </pre> |
| 301 | * |
| 302 | * <p>In general the movement through an activity's lifecycle looks like |
| 303 | * this:</p> |
| 304 | * |
| 305 | * <table border="2" width="85%" align="center" frame="hsides" rules="rows"> |
| 306 | * <colgroup align="left" span="3" /> |
| 307 | * <colgroup align="left" /> |
| 308 | * <colgroup align="center" /> |
| 309 | * <colgroup align="center" /> |
| 310 | * |
| 311 | * <thead> |
| 312 | * <tr><th colspan="3">Method</th> <th>Description</th> <th>Killable?</th> <th>Next</th></tr> |
| 313 | * </thead> |
| 314 | * |
| 315 | * <tbody> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 316 | * <tr><td colspan="3" align="left" border="0">{@link android.app.Activity#onCreate onCreate()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | * <td>Called when the activity is first created. |
| 318 | * This is where you should do all of your normal static set up: |
| 319 | * create views, bind data to lists, etc. This method also |
| 320 | * provides you with a Bundle containing the activity's previously |
| 321 | * frozen state, if there was one. |
| 322 | * <p>Always followed by <code>onStart()</code>.</td> |
| 323 | * <td align="center">No</td> |
| 324 | * <td align="center"><code>onStart()</code></td> |
| 325 | * </tr> |
| 326 | * |
| 327 | * <tr><td rowspan="5" style="border-left: none; border-right: none;"> </td> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 328 | * <td colspan="2" align="left" border="0">{@link android.app.Activity#onRestart onRestart()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | * <td>Called after your activity has been stopped, prior to it being |
| 330 | * started again. |
| 331 | * <p>Always followed by <code>onStart()</code></td> |
| 332 | * <td align="center">No</td> |
| 333 | * <td align="center"><code>onStart()</code></td> |
| 334 | * </tr> |
| 335 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 336 | * <tr><td colspan="2" align="left" border="0">{@link android.app.Activity#onStart onStart()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | * <td>Called when the activity is becoming visible to the user. |
| 338 | * <p>Followed by <code>onResume()</code> if the activity comes |
| 339 | * to the foreground, or <code>onStop()</code> if it becomes hidden.</td> |
| 340 | * <td align="center">No</td> |
| 341 | * <td align="center"><code>onResume()</code> or <code>onStop()</code></td> |
| 342 | * </tr> |
| 343 | * |
| 344 | * <tr><td rowspan="2" style="border-left: none;"> </td> |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 345 | * <td align="left" border="0">{@link android.app.Activity#onResume onResume()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | * <td>Called when the activity will start |
| 347 | * interacting with the user. At this point your activity is at |
| 348 | * the top of the activity stack, with user input going to it. |
| 349 | * <p>Always followed by <code>onPause()</code>.</td> |
| 350 | * <td align="center">No</td> |
| 351 | * <td align="center"><code>onPause()</code></td> |
| 352 | * </tr> |
| 353 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 354 | * <tr><td align="left" border="0">{@link android.app.Activity#onPause onPause()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | * <td>Called when the system is about to start resuming a previous |
| 356 | * activity. This is typically used to commit unsaved changes to |
| 357 | * persistent data, stop animations and other things that may be consuming |
| 358 | * CPU, etc. Implementations of this method must be very quick because |
| 359 | * the next activity will not be resumed until this method returns. |
| 360 | * <p>Followed by either <code>onResume()</code> if the activity |
| 361 | * returns back to the front, or <code>onStop()</code> if it becomes |
| 362 | * invisible to the user.</td> |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 363 | * <td align="center"><font color="#800000"><strong>Pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB}</strong></font></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | * <td align="center"><code>onResume()</code> or<br> |
| 365 | * <code>onStop()</code></td> |
| 366 | * </tr> |
| 367 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 368 | * <tr><td colspan="2" align="left" border="0">{@link android.app.Activity#onStop onStop()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | * <td>Called when the activity is no longer visible to the user, because |
| 370 | * another activity has been resumed and is covering this one. This |
| 371 | * may happen either because a new activity is being started, an existing |
| 372 | * one is being brought in front of this one, or this one is being |
| 373 | * destroyed. |
| 374 | * <p>Followed by either <code>onRestart()</code> if |
| 375 | * this activity is coming back to interact with the user, or |
| 376 | * <code>onDestroy()</code> if this activity is going away.</td> |
| 377 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 378 | * <td align="center"><code>onRestart()</code> or<br> |
| 379 | * <code>onDestroy()</code></td> |
| 380 | * </tr> |
| 381 | * |
smain@google.com | 10e29b8 | 2016-06-23 12:09:30 -0700 | [diff] [blame] | 382 | * <tr><td colspan="3" align="left" border="0">{@link android.app.Activity#onDestroy onDestroy()}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | * <td>The final call you receive before your |
| 384 | * activity is destroyed. This can happen either because the |
| 385 | * activity is finishing (someone called {@link Activity#finish} on |
| 386 | * it, or because the system is temporarily destroying this |
| 387 | * instance of the activity to save space. You can distinguish |
| 388 | * between these two scenarios with the {@link |
| 389 | * Activity#isFinishing} method.</td> |
| 390 | * <td align="center"><font color="#800000"><strong>Yes</strong></font></td> |
| 391 | * <td align="center"><em>nothing</em></td> |
| 392 | * </tr> |
| 393 | * </tbody> |
| 394 | * </table> |
| 395 | * |
| 396 | * <p>Note the "Killable" column in the above table -- for those methods that |
| 397 | * are marked as being killable, after that method returns the process hosting the |
Kris Giesing | 8b6216d | 2014-12-16 17:23:15 -0800 | [diff] [blame] | 398 | * activity may be killed by the system <em>at any time</em> without another line |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | * of its code being executed. Because of this, you should use the |
| 400 | * {@link #onPause} method to write any persistent data (such as user edits) |
| 401 | * to storage. In addition, the method |
| 402 | * {@link #onSaveInstanceState(Bundle)} is called before placing the activity |
| 403 | * in such a background state, allowing you to save away any dynamic instance |
| 404 | * state in your activity into the given Bundle, to be later received in |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 405 | * {@link #onCreate} if the activity needs to be re-created. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | * See the <a href="#ProcessLifecycle">Process Lifecycle</a> |
| 407 | * section for more information on how the lifecycle of a process is tied |
| 408 | * to the activities it is hosting. Note that it is important to save |
| 409 | * persistent data in {@link #onPause} instead of {@link #onSaveInstanceState} |
Daisuke Miyakawa | 5c40f3f | 2011-02-15 13:24:36 -0800 | [diff] [blame] | 410 | * because the latter is not part of the lifecycle callbacks, so will not |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | * be called in every situation as described in its documentation.</p> |
| 412 | * |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 413 | * <p class="note">Be aware that these semantics will change slightly between |
| 414 | * applications targeting platforms starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 415 | * vs. those targeting prior platforms. Starting with Honeycomb, an application |
| 416 | * is not in the killable state until its {@link #onStop} has returned. This |
| 417 | * impacts when {@link #onSaveInstanceState(Bundle)} may be called (it may be |
| 418 | * safely called after {@link #onPause()} and allows and application to safely |
| 419 | * wait until {@link #onStop()} to save persistent state.</p> |
| 420 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | * <p>For those methods that are not marked as being killable, the activity's |
| 422 | * process will not be killed by the system starting from the time the method |
| 423 | * is called and continuing after it returns. Thus an activity is in the killable |
| 424 | * state, for example, between after <code>onPause()</code> to the start of |
| 425 | * <code>onResume()</code>.</p> |
| 426 | * |
| 427 | * <a name="ConfigurationChanges"></a> |
| 428 | * <h3>Configuration Changes</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 429 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | * <p>If the configuration of the device (as defined by the |
| 431 | * {@link Configuration Resources.Configuration} class) changes, |
| 432 | * then anything displaying a user interface will need to update to match that |
| 433 | * configuration. Because Activity is the primary mechanism for interacting |
| 434 | * with the user, it includes special support for handling configuration |
| 435 | * changes.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 436 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | * <p>Unless you specify otherwise, a configuration change (such as a change |
| 438 | * in screen orientation, language, input devices, etc) will cause your |
| 439 | * current activity to be <em>destroyed</em>, going through the normal activity |
| 440 | * lifecycle process of {@link #onPause}, |
| 441 | * {@link #onStop}, and {@link #onDestroy} as appropriate. If the activity |
| 442 | * had been in the foreground or visible to the user, once {@link #onDestroy} is |
| 443 | * called in that instance then a new instance of the activity will be |
| 444 | * created, with whatever savedInstanceState the previous instance had generated |
| 445 | * from {@link #onSaveInstanceState}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 446 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | * <p>This is done because any application resource, |
| 448 | * including layout files, can change based on any configuration value. Thus |
| 449 | * the only safe way to handle a configuration change is to re-retrieve all |
| 450 | * resources, including layouts, drawables, and strings. Because activities |
| 451 | * must already know how to save their state and re-create themselves from |
| 452 | * that state, this is a convenient way to have an activity restart itself |
| 453 | * with a new configuration.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 454 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | * <p>In some special cases, you may want to bypass restarting of your |
| 456 | * activity based on one or more types of configuration changes. This is |
| 457 | * done with the {@link android.R.attr#configChanges android:configChanges} |
| 458 | * attribute in its manifest. For any types of configuration changes you say |
| 459 | * that you handle there, you will receive a call to your current activity's |
| 460 | * {@link #onConfigurationChanged} method instead of being restarted. If |
| 461 | * a configuration change involves any that you do not handle, however, the |
| 462 | * activity will still be restarted and {@link #onConfigurationChanged} |
| 463 | * will not be called.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 464 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | * <a name="StartingActivities"></a> |
| 466 | * <h3>Starting Activities and Getting Results</h3> |
| 467 | * |
| 468 | * <p>The {@link android.app.Activity#startActivity} |
| 469 | * method is used to start a |
| 470 | * new activity, which will be placed at the top of the activity stack. It |
| 471 | * takes a single argument, an {@link android.content.Intent Intent}, |
| 472 | * which describes the activity |
| 473 | * to be executed.</p> |
| 474 | * |
| 475 | * <p>Sometimes you want to get a result back from an activity when it |
| 476 | * ends. For example, you may start an activity that lets the user pick |
| 477 | * a person in a list of contacts; when it ends, it returns the person |
| 478 | * that was selected. To do this, you call the |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 479 | * {@link android.app.Activity#startActivityForResult(Intent, int)} |
| 480 | * version with a second integer parameter identifying the call. The result |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | * will come back through your {@link android.app.Activity#onActivityResult} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 482 | * method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | * |
| 484 | * <p>When an activity exits, it can call |
| 485 | * {@link android.app.Activity#setResult(int)} |
| 486 | * to return data back to its parent. It must always supply a result code, |
| 487 | * which can be the standard results RESULT_CANCELED, RESULT_OK, or any |
| 488 | * custom values starting at RESULT_FIRST_USER. In addition, it can optionally |
| 489 | * return back an Intent containing any additional data it wants. All of this |
| 490 | * information appears back on the |
| 491 | * parent's <code>Activity.onActivityResult()</code>, along with the integer |
| 492 | * identifier it originally supplied.</p> |
| 493 | * |
| 494 | * <p>If a child activity fails for any reason (such as crashing), the parent |
| 495 | * activity will receive a result with the code RESULT_CANCELED.</p> |
| 496 | * |
| 497 | * <pre class="prettyprint"> |
| 498 | * public class MyActivity extends Activity { |
| 499 | * ... |
| 500 | * |
| 501 | * static final int PICK_CONTACT_REQUEST = 0; |
| 502 | * |
Michael Wright | 5438e4e | 2014-07-25 14:05:42 -0700 | [diff] [blame] | 503 | * public boolean onKeyDown(int keyCode, KeyEvent event) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | * if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 505 | * // When the user center presses, let them pick a contact. |
| 506 | * startActivityForResult( |
| 507 | * new Intent(Intent.ACTION_PICK, |
| 508 | * new Uri("content://contacts")), |
| 509 | * PICK_CONTACT_REQUEST); |
| 510 | * return true; |
| 511 | * } |
| 512 | * return false; |
| 513 | * } |
| 514 | * |
| 515 | * protected void onActivityResult(int requestCode, int resultCode, |
| 516 | * Intent data) { |
| 517 | * if (requestCode == PICK_CONTACT_REQUEST) { |
| 518 | * if (resultCode == RESULT_OK) { |
| 519 | * // A contact was picked. Here we will just display it |
| 520 | * // to the user. |
| 521 | * startActivity(new Intent(Intent.ACTION_VIEW, data)); |
| 522 | * } |
| 523 | * } |
| 524 | * } |
| 525 | * } |
| 526 | * </pre> |
| 527 | * |
| 528 | * <a name="SavingPersistentState"></a> |
| 529 | * <h3>Saving Persistent State</h3> |
| 530 | * |
| 531 | * <p>There are generally two kinds of persistent state than an activity |
| 532 | * will deal with: shared document-like data (typically stored in a SQLite |
| 533 | * database using a {@linkplain android.content.ContentProvider content provider}) |
| 534 | * and internal state such as user preferences.</p> |
| 535 | * |
| 536 | * <p>For content provider data, we suggest that activities use a |
| 537 | * "edit in place" user model. That is, any edits a user makes are effectively |
| 538 | * made immediately without requiring an additional confirmation step. |
| 539 | * Supporting this model is generally a simple matter of following two rules:</p> |
| 540 | * |
| 541 | * <ul> |
| 542 | * <li> <p>When creating a new document, the backing database entry or file for |
| 543 | * it is created immediately. For example, if the user chooses to write |
| 544 | * a new e-mail, a new entry for that e-mail is created as soon as they |
| 545 | * start entering data, so that if they go to any other activity after |
| 546 | * that point this e-mail will now appear in the list of drafts.</p> |
| 547 | * <li> <p>When an activity's <code>onPause()</code> method is called, it should |
| 548 | * commit to the backing content provider or file any changes the user |
| 549 | * has made. This ensures that those changes will be seen by any other |
| 550 | * activity that is about to run. You will probably want to commit |
| 551 | * your data even more aggressively at key times during your |
| 552 | * activity's lifecycle: for example before starting a new |
| 553 | * activity, before finishing your own activity, when the user |
| 554 | * switches between input fields, etc.</p> |
| 555 | * </ul> |
| 556 | * |
| 557 | * <p>This model is designed to prevent data loss when a user is navigating |
| 558 | * between activities, and allows the system to safely kill an activity (because |
| 559 | * system resources are needed somewhere else) at any time after it has been |
| 560 | * paused. Note this implies |
| 561 | * that the user pressing BACK from your activity does <em>not</em> |
| 562 | * mean "cancel" -- it means to leave the activity with its current contents |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 563 | * saved away. Canceling edits in an activity must be provided through |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | * some other mechanism, such as an explicit "revert" or "undo" option.</p> |
| 565 | * |
| 566 | * <p>See the {@linkplain android.content.ContentProvider content package} for |
| 567 | * more information about content providers. These are a key aspect of how |
| 568 | * different activities invoke and propagate data between themselves.</p> |
| 569 | * |
| 570 | * <p>The Activity class also provides an API for managing internal persistent state |
| 571 | * associated with an activity. This can be used, for example, to remember |
| 572 | * the user's preferred initial display in a calendar (day view or week view) |
| 573 | * or the user's default home page in a web browser.</p> |
| 574 | * |
| 575 | * <p>Activity persistent state is managed |
| 576 | * with the method {@link #getPreferences}, |
| 577 | * allowing you to retrieve and |
| 578 | * modify a set of name/value pairs associated with the activity. To use |
| 579 | * preferences that are shared across multiple application components |
| 580 | * (activities, receivers, services, providers), you can use the underlying |
| 581 | * {@link Context#getSharedPreferences Context.getSharedPreferences()} method |
| 582 | * to retrieve a preferences |
| 583 | * object stored under a specific name. |
| 584 | * (Note that it is not possible to share settings data across application |
| 585 | * packages -- for that you will need a content provider.)</p> |
| 586 | * |
| 587 | * <p>Here is an excerpt from a calendar activity that stores the user's |
| 588 | * preferred view mode in its persistent settings:</p> |
| 589 | * |
| 590 | * <pre class="prettyprint"> |
| 591 | * public class CalendarActivity extends Activity { |
| 592 | * ... |
| 593 | * |
| 594 | * static final int DAY_VIEW_MODE = 0; |
| 595 | * static final int WEEK_VIEW_MODE = 1; |
| 596 | * |
| 597 | * private SharedPreferences mPrefs; |
| 598 | * private int mCurViewMode; |
| 599 | * |
| 600 | * protected void onCreate(Bundle savedInstanceState) { |
| 601 | * super.onCreate(savedInstanceState); |
| 602 | * |
| 603 | * SharedPreferences mPrefs = getSharedPreferences(); |
Quddus Chong | 3fa98cb | 2012-04-13 11:17:24 -0700 | [diff] [blame] | 604 | * mCurViewMode = mPrefs.getInt("view_mode", DAY_VIEW_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | * } |
| 606 | * |
| 607 | * protected void onPause() { |
| 608 | * super.onPause(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 609 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | * SharedPreferences.Editor ed = mPrefs.edit(); |
| 611 | * ed.putInt("view_mode", mCurViewMode); |
| 612 | * ed.commit(); |
| 613 | * } |
| 614 | * } |
| 615 | * </pre> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 616 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | * <a name="Permissions"></a> |
| 618 | * <h3>Permissions</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 619 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | * <p>The ability to start a particular Activity can be enforced when it is |
| 621 | * declared in its |
| 622 | * manifest's {@link android.R.styleable#AndroidManifestActivity <activity>} |
| 623 | * tag. By doing so, other applications will need to declare a corresponding |
| 624 | * {@link android.R.styleable#AndroidManifestUsesPermission <uses-permission>} |
| 625 | * element in their own manifest to be able to start that activity. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 626 | * |
| 627 | * <p>When starting an Activity you can set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 628 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 629 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} on the Intent. This will grant the |
| 630 | * Activity access to the specific URIs in the Intent. Access will remain |
| 631 | * until the Activity has finished (it will remain across the hosting |
| 632 | * process being killed and other temporary destruction). As of |
| 633 | * {@link android.os.Build.VERSION_CODES#GINGERBREAD}, if the Activity |
| 634 | * was already created and a new Intent is being delivered to |
| 635 | * {@link #onNewIntent(Intent)}, any newly granted URI permissions will be added |
| 636 | * to the existing ones it holds. |
| 637 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | * <p>See the <a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a> |
| 639 | * document for more information on permissions and security in general. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 640 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | * <a name="ProcessLifecycle"></a> |
| 642 | * <h3>Process Lifecycle</h3> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 643 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | * <p>The Android system attempts to keep application process around for as |
| 645 | * long as possible, but eventually will need to remove old processes when |
| 646 | * memory runs low. As described in <a href="#ActivityLifecycle">Activity |
| 647 | * Lifecycle</a>, the decision about which process to remove is intimately |
| 648 | * tied to the state of the user's interaction with it. In general, there |
| 649 | * are four states a process can be in based on the activities running in it, |
| 650 | * listed here in order of importance. The system will kill less important |
| 651 | * processes (the last ones) before it resorts to killing more important |
| 652 | * processes (the first ones). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 653 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | * <ol> |
| 655 | * <li> <p>The <b>foreground activity</b> (the activity at the top of the screen |
| 656 | * that the user is currently interacting with) is considered the most important. |
| 657 | * Its process will only be killed as a last resort, if it uses more memory |
| 658 | * than is available on the device. Generally at this point the device has |
| 659 | * reached a memory paging state, so this is required in order to keep the user |
| 660 | * interface responsive. |
| 661 | * <li> <p>A <b>visible activity</b> (an activity that is visible to the user |
| 662 | * but not in the foreground, such as one sitting behind a foreground dialog) |
| 663 | * is considered extremely important and will not be killed unless that is |
| 664 | * required to keep the foreground activity running. |
| 665 | * <li> <p>A <b>background activity</b> (an activity that is not visible to |
| 666 | * the user and has been paused) is no longer critical, so the system may |
| 667 | * safely kill its process to reclaim memory for other foreground or |
| 668 | * visible processes. If its process needs to be killed, when the user navigates |
| 669 | * back to the activity (making it visible on the screen again), its |
| 670 | * {@link #onCreate} method will be called with the savedInstanceState it had previously |
| 671 | * supplied in {@link #onSaveInstanceState} so that it can restart itself in the same |
| 672 | * state as the user last left it. |
| 673 | * <li> <p>An <b>empty process</b> is one hosting no activities or other |
| 674 | * application components (such as {@link Service} or |
| 675 | * {@link android.content.BroadcastReceiver} classes). These are killed very |
| 676 | * quickly by the system as memory becomes low. For this reason, any |
| 677 | * background operation you do outside of an activity must be executed in the |
| 678 | * context of an activity BroadcastReceiver or Service to ensure that the system |
| 679 | * knows it needs to keep your process around. |
| 680 | * </ol> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 681 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | * <p>Sometimes an Activity may need to do a long-running operation that exists |
| 683 | * independently of the activity lifecycle itself. An example may be a camera |
| 684 | * application that allows you to upload a picture to a web site. The upload |
| 685 | * may take a long time, and the application should allow the user to leave |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 686 | * the application while it is executing. To accomplish this, your Activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | * should start a {@link Service} in which the upload takes place. This allows |
| 688 | * the system to properly prioritize your process (considering it to be more |
| 689 | * important than other non-visible applications) for the duration of the |
| 690 | * upload, independent of whether the original activity is paused, stopped, |
| 691 | * or finished. |
| 692 | */ |
| 693 | public class Activity extends ContextThemeWrapper |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 694 | implements LayoutInflater.Factory2, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | Window.Callback, KeyEvent.Callback, |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 696 | OnCreateContextMenuListener, ComponentCallbacks2, |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 697 | Window.OnWindowDismissedCallback, WindowControllerCallback, |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 698 | AutofillManager.AutofillClient { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | private static final String TAG = "Activity"; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 700 | private static final boolean DEBUG_LIFECYCLE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | |
| 702 | /** Standard activity result: operation canceled. */ |
| 703 | public static final int RESULT_CANCELED = 0; |
| 704 | /** Standard activity result: operation succeeded. */ |
| 705 | public static final int RESULT_OK = -1; |
| 706 | /** Start of user-defined activity results. */ |
| 707 | public static final int RESULT_FIRST_USER = 1; |
| 708 | |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 709 | /** @hide Task isn't finished when activity is finished */ |
| 710 | public static final int DONT_FINISH_TASK_WITH_ACTIVITY = 0; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 711 | /** |
| 712 | * @hide Task is finished if the finishing activity is the root of the task. To preserve the |
| 713 | * past behavior the task is also removed from recents. |
| 714 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 715 | public static final int FINISH_TASK_WITH_ROOT_ACTIVITY = 1; |
Filip Gruszczynski | c29ecc8 | 2015-10-08 11:08:44 -0700 | [diff] [blame] | 716 | /** |
| 717 | * @hide Task is finished along with the finishing activity, but it is not removed from |
| 718 | * recents. |
| 719 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 720 | public static final int FINISH_TASK_WITH_ACTIVITY = 2; |
| 721 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 722 | static final String FRAGMENTS_TAG = "android:fragments"; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 723 | private static final String LAST_AUTOFILL_ID = "android:lastAutofillId"; |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 724 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 725 | private static final String AUTOFILL_RESET_NEEDED = "@android:autofillResetNeeded"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState"; |
| 727 | private static final String SAVED_DIALOG_IDS_KEY = "android:savedDialogIds"; |
| 728 | private static final String SAVED_DIALOGS_TAG = "android:savedDialogs"; |
| 729 | private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_"; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 730 | private static final String SAVED_DIALOG_ARGS_KEY_PREFIX = "android:dialog_args_"; |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 731 | private static final String HAS_CURENT_PERMISSIONS_REQUEST_KEY = |
| 732 | "android:hasCurrentPermissionsRequest"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 734 | private static final String REQUEST_PERMISSIONS_WHO_PREFIX = "@android:requestPermissions:"; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 735 | private static final String AUTO_FILL_AUTH_WHO_PREFIX = "@android:autoFillAuth:"; |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 736 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 737 | private static final String KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME = "com.android.systemui"; |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 738 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 739 | private static class ManagedDialog { |
| 740 | Dialog mDialog; |
| 741 | Bundle mArgs; |
| 742 | } |
| 743 | private SparseArray<ManagedDialog> mManagedDialogs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | |
| 745 | // set by the thread after the constructor and before onCreate(Bundle savedInstanceState) is called. |
| 746 | private Instrumentation mInstrumentation; |
| 747 | private IBinder mToken; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 748 | private int mIdent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | /*package*/ String mEmbeddedID; |
| 750 | private Application mApplication; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 751 | /*package*/ Intent mIntent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 752 | /*package*/ String mReferrer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | private ComponentName mComponent; |
| 754 | /*package*/ ActivityInfo mActivityInfo; |
| 755 | /*package*/ ActivityThread mMainThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | Activity mParent; |
| 757 | boolean mCalled; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 758 | /*package*/ boolean mResumed; |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 759 | /*package*/ boolean mStopped; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | boolean mFinished; |
| 761 | boolean mStartedActivity; |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 762 | private boolean mDestroyed; |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 763 | private boolean mDoReportFullyDrawn = true; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 764 | /** true if the activity is going through a transient pause */ |
| 765 | /*package*/ boolean mTemporaryPause = false; |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 766 | /** true if the activity is being destroyed in order to recreate it with a new configuration */ |
| 767 | /*package*/ boolean mChangingConfigurations = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | /*package*/ int mConfigChangeFlags; |
| 769 | /*package*/ Configuration mCurrentConfig; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 770 | private SearchManager mSearchManager; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 771 | private MenuInflater mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 773 | /** The autofill manager. Always access via {@link #getAutofillManager()}. */ |
| 774 | @Nullable private AutofillManager mAutofillManager; |
| 775 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 776 | static final class NonConfigurationInstances { |
| 777 | Object activity; |
| 778 | HashMap<String, Object> children; |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 779 | FragmentManagerNonConfig fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 780 | ArrayMap<String, LoaderManager> loaders; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 781 | VoiceInteractor voiceInteractor; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 782 | } |
| 783 | /* package */ NonConfigurationInstances mLastNonConfigurationInstances; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | private Window mWindow; |
| 786 | |
| 787 | private WindowManager mWindowManager; |
| 788 | /*package*/ View mDecor = null; |
| 789 | /*package*/ boolean mWindowAdded = false; |
| 790 | /*package*/ boolean mVisibleFromServer = false; |
| 791 | /*package*/ boolean mVisibleFromClient = true; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 792 | /*package*/ ActionBar mActionBar = null; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 793 | private boolean mEnableDefaultActionBarUp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 795 | private VoiceInteractor mVoiceInteractor; |
| 796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | private CharSequence mTitle; |
| 798 | private int mTitleColor = 0; |
| 799 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 800 | // we must have a handler before the FragmentController is constructed |
| 801 | final Handler mHandler = new Handler(); |
| 802 | final FragmentController mFragments = FragmentController.createController(new HostCallbacks()); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 803 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 804 | // Most recent call to requestVisibleBehind(). |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 805 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 806 | boolean mVisibleBehind; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | private static final class ManagedCursor { |
| 809 | ManagedCursor(Cursor cursor) { |
| 810 | mCursor = cursor; |
| 811 | mReleased = false; |
| 812 | mUpdated = false; |
| 813 | } |
| 814 | |
| 815 | private final Cursor mCursor; |
| 816 | private boolean mReleased; |
| 817 | private boolean mUpdated; |
| 818 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 820 | @GuardedBy("mManagedCursors") |
| 821 | private final ArrayList<ManagedCursor> mManagedCursors = new ArrayList<>(); |
| 822 | |
| 823 | @GuardedBy("this") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | int mResultCode = RESULT_CANCELED; |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 825 | @GuardedBy("this") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | Intent mResultData = null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 827 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 828 | private TranslucentConversionListener mTranslucentCallback; |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 829 | private boolean mChangeCanvasToTranslucent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 831 | private SearchEvent mSearchEvent; |
| 832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | private boolean mTitleReady = false; |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 834 | private int mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | |
| 836 | private int mDefaultKeyMode = DEFAULT_KEYS_DISABLE; |
| 837 | private SpannableStringBuilder mDefaultKeySsb = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 838 | |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 839 | private ActivityManager.TaskDescription mTaskDescription = |
| 840 | new ActivityManager.TaskDescription(); |
| 841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused}; |
| 843 | |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 844 | @SuppressWarnings("unused") |
Jeff Brown | 7e44283 | 2011-06-10 18:00:16 -0700 | [diff] [blame] | 845 | private final Object mInstanceTracker = StrictMode.trackActivity(this); |
| 846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | private Thread mUiThread; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 848 | |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 849 | ActivityTransitionState mActivityTransitionState = new ActivityTransitionState(); |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 850 | SharedElementCallback mEnterTransitionListener = SharedElementCallback.NULL_CALLBACK; |
| 851 | SharedElementCallback mExitTransitionListener = SharedElementCallback.NULL_CALLBACK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 853 | private boolean mHasCurrentPermissionsRequest; |
| 854 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 855 | private boolean mAutoFillResetNeeded; |
| 856 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 857 | /** The last autofill id that was returned from {@link #getNextAutofillId()} */ |
| 858 | private int mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 859 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 860 | private AutofillPopupWindow mAutofillPopupWindow; |
| 861 | |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 862 | private static native String getDlWarning(); |
| 863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | /** Return the intent that started this activity. */ |
| 865 | public Intent getIntent() { |
| 866 | return mIntent; |
| 867 | } |
| 868 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 869 | /** |
| 870 | * Change the intent returned by {@link #getIntent}. This holds a |
| 871 | * reference to the given intent; it does not copy it. Often used in |
| 872 | * conjunction with {@link #onNewIntent}. |
| 873 | * |
| 874 | * @param newIntent The new Intent object to return from getIntent |
| 875 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | * @see #getIntent |
| 877 | * @see #onNewIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 878 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | public void setIntent(Intent newIntent) { |
| 880 | mIntent = newIntent; |
| 881 | } |
| 882 | |
| 883 | /** Return the application that owns this activity. */ |
| 884 | public final Application getApplication() { |
| 885 | return mApplication; |
| 886 | } |
| 887 | |
| 888 | /** Is this activity embedded inside of another activity? */ |
| 889 | public final boolean isChild() { |
| 890 | return mParent != null; |
| 891 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | /** Return the parent activity if this view is an embedded child. */ |
| 894 | public final Activity getParent() { |
| 895 | return mParent; |
| 896 | } |
| 897 | |
| 898 | /** Retrieve the window manager for showing custom windows. */ |
| 899 | public WindowManager getWindowManager() { |
| 900 | return mWindowManager; |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * Retrieve the current {@link android.view.Window} for the activity. |
| 905 | * This can be used to directly access parts of the Window API that |
| 906 | * are not available through Activity/Screen. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 907 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | * @return Window The current window, or null if the activity is not |
| 909 | * visual. |
| 910 | */ |
| 911 | public Window getWindow() { |
| 912 | return mWindow; |
| 913 | } |
| 914 | |
| 915 | /** |
Mark Doliner | 9525f2a | 2014-01-02 11:17:47 -0800 | [diff] [blame] | 916 | * Return the LoaderManager for this activity, creating it if needed. |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 917 | */ |
| 918 | public LoaderManager getLoaderManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 919 | return mFragments.getLoaderManager(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 920 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 921 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 922 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | * Calls {@link android.view.Window#getCurrentFocus} on the |
| 924 | * Window of this Activity to return the currently focused view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 925 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | * @return View The current View with focus or null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 927 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | * @see #getWindow |
| 929 | * @see android.view.Window#getCurrentFocus |
| 930 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 931 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | public View getCurrentFocus() { |
| 933 | return mWindow != null ? mWindow.getCurrentFocus() : null; |
| 934 | } |
| 935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | /** |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 937 | * (Create and) return the autofill manager |
| 938 | * |
| 939 | * @return The autofill manager |
| 940 | */ |
| 941 | @NonNull private AutofillManager getAutofillManager() { |
| 942 | if (mAutofillManager == null) { |
| 943 | mAutofillManager = getSystemService(AutofillManager.class); |
| 944 | } |
| 945 | |
| 946 | return mAutofillManager; |
| 947 | } |
| 948 | |
| 949 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | * Called when the activity is starting. This is where most initialization |
| 951 | * should go: calling {@link #setContentView(int)} to inflate the |
| 952 | * activity's UI, using {@link #findViewById} to programmatically interact |
| 953 | * with widgets in the UI, calling |
| 954 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve |
| 955 | * cursors for data being displayed, etc. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 956 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 957 | * <p>You can call {@link #finish} from within this function, in |
| 958 | * which case onDestroy() will be immediately called without any of the rest |
| 959 | * of the activity lifecycle ({@link #onStart}, {@link #onResume}, |
| 960 | * {@link #onPause}, etc) executing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 961 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | * <p><em>Derived classes must call through to the super class's |
| 963 | * implementation of this method. If they do not, an exception will be |
| 964 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 965 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | * @param savedInstanceState If the activity is being re-initialized after |
| 967 | * previously being shut down then this Bundle contains the data it most |
| 968 | * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 969 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | * @see #onStart |
| 971 | * @see #onSaveInstanceState |
| 972 | * @see #onRestoreInstanceState |
| 973 | * @see #onPostCreate |
| 974 | */ |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 975 | @MainThread |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 976 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 977 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 978 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 979 | |
Bryce Lee | d1ac18c | 2017-05-11 07:59:41 -0700 | [diff] [blame] | 980 | if (getApplicationInfo().targetSdkVersion > O && mActivityInfo.isFixedOrientation()) { |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 981 | final TypedArray ta = obtainStyledAttributes(com.android.internal.R.styleable.Window); |
| 982 | final boolean isTranslucentOrFloating = ActivityInfo.isTranslucentOrFloating(ta); |
| 983 | ta.recycle(); |
| 984 | |
| 985 | if (isTranslucentOrFloating) { |
| 986 | throw new IllegalStateException( |
| 987 | "Only fullscreen opaque activities can request orientation"); |
| 988 | } |
| 989 | } |
| 990 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 991 | if (mLastNonConfigurationInstances != null) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 992 | mFragments.restoreLoaderNonConfig(mLastNonConfigurationInstances.loaders); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 993 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 994 | if (mActivityInfo.parentActivityName != null) { |
| 995 | if (mActionBar == null) { |
| 996 | mEnableDefaultActionBarUp = true; |
| 997 | } else { |
| 998 | mActionBar.setDefaultDisplayHomeAsUpEnabled(true); |
| 999 | } |
| 1000 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1001 | if (savedInstanceState != null) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1002 | mAutoFillResetNeeded = savedInstanceState.getBoolean(AUTOFILL_RESET_NEEDED, false); |
Philip P. Moltmann | e78c771 | 2017-06-19 12:57:13 -0700 | [diff] [blame] | 1003 | mLastAutofillId = savedInstanceState.getInt(LAST_AUTOFILL_ID, |
| 1004 | View.LAST_APP_AUTOFILL_ID); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1005 | |
| 1006 | if (mAutoFillResetNeeded) { |
| 1007 | getAutofillManager().onCreate(savedInstanceState); |
| 1008 | } |
| 1009 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1010 | Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); |
| 1011 | mFragments.restoreAllState(p, mLastNonConfigurationInstances != null |
| 1012 | ? mLastNonConfigurationInstances.fragments : null); |
| 1013 | } |
| 1014 | mFragments.dispatchCreate(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1015 | getApplication().dispatchActivityCreated(this, savedInstanceState); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 1016 | if (mVoiceInteractor != null) { |
| 1017 | mVoiceInteractor.attachActivity(this); |
| 1018 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | mCalled = true; |
| 1020 | } |
| 1021 | |
| 1022 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1023 | * Same as {@link #onCreate(android.os.Bundle)} but called for those activities created with |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1024 | * the attribute {@link android.R.attr#persistableMode} set to |
| 1025 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1026 | * |
| 1027 | * @param savedInstanceState if the activity is being re-initialized after |
| 1028 | * previously being shut down then this Bundle contains the data it most |
| 1029 | * recently supplied in {@link #onSaveInstanceState}. |
| 1030 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1031 | * @param persistentState if the activity is being re-initialized after |
| 1032 | * previously being shut down or powered off then this Bundle contains the data it most |
| 1033 | * recently supplied to outPersistentState in {@link #onSaveInstanceState}. |
| 1034 | * <b><i>Note: Otherwise it is null.</i></b> |
| 1035 | * |
| 1036 | * @see #onCreate(android.os.Bundle) |
| 1037 | * @see #onStart |
| 1038 | * @see #onSaveInstanceState |
| 1039 | * @see #onRestoreInstanceState |
| 1040 | * @see #onPostCreate |
| 1041 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1042 | public void onCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1043 | @Nullable PersistableBundle persistentState) { |
| 1044 | onCreate(savedInstanceState); |
| 1045 | } |
| 1046 | |
| 1047 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1049 | * |
| 1050 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1051 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1052 | * |
| 1053 | * @param savedInstanceState contains the saved state |
| 1054 | */ |
| 1055 | final void performRestoreInstanceState(Bundle savedInstanceState) { |
| 1056 | onRestoreInstanceState(savedInstanceState); |
| 1057 | restoreManagedDialogs(savedInstanceState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1061 | * The hook for {@link ActivityThread} to restore the state of this activity. |
| 1062 | * |
| 1063 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} and |
| 1064 | * {@link #restoreManagedDialogs(android.os.Bundle)}. |
| 1065 | * |
| 1066 | * @param savedInstanceState contains the saved state |
| 1067 | * @param persistentState contains the persistable saved state |
| 1068 | */ |
| 1069 | final void performRestoreInstanceState(Bundle savedInstanceState, |
| 1070 | PersistableBundle persistentState) { |
| 1071 | onRestoreInstanceState(savedInstanceState, persistentState); |
| 1072 | if (savedInstanceState != null) { |
| 1073 | restoreManagedDialogs(savedInstanceState); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | * This method is called after {@link #onStart} when the activity is |
| 1079 | * being re-initialized from a previously saved state, given here in |
Mike LeBeau | 305de9d | 2010-03-11 09:21:08 -0800 | [diff] [blame] | 1080 | * <var>savedInstanceState</var>. Most implementations will simply use {@link #onCreate} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | * to restore their state, but it is sometimes convenient to do it here |
| 1082 | * after all of the initialization has been done or to allow subclasses to |
| 1083 | * decide whether to use your default implementation. The default |
| 1084 | * implementation of this method performs a restore of any view state that |
| 1085 | * had previously been frozen by {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1086 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | * <p>This method is called between {@link #onStart} and |
| 1088 | * {@link #onPostCreate}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1089 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1091 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | * @see #onCreate |
| 1093 | * @see #onPostCreate |
| 1094 | * @see #onResume |
| 1095 | * @see #onSaveInstanceState |
| 1096 | */ |
| 1097 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1098 | if (mWindow != null) { |
| 1099 | Bundle windowState = savedInstanceState.getBundle(WINDOW_HIERARCHY_TAG); |
| 1100 | if (windowState != null) { |
| 1101 | mWindow.restoreHierarchyState(windowState); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1105 | |
| 1106 | /** |
| 1107 | * This is the same as {@link #onRestoreInstanceState(Bundle)} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1108 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1109 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1110 | * came from the restored PersistableBundle first |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1111 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1112 | * |
| 1113 | * <p>This method is called between {@link #onStart} and |
| 1114 | * {@link #onPostCreate}. |
| 1115 | * |
| 1116 | * <p>If this method is called {@link #onRestoreInstanceState(Bundle)} will not be called. |
| 1117 | * |
| 1118 | * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}. |
| 1119 | * @param persistentState the data most recently supplied in {@link #onSaveInstanceState}. |
| 1120 | * |
| 1121 | * @see #onRestoreInstanceState(Bundle) |
| 1122 | * @see #onCreate |
| 1123 | * @see #onPostCreate |
| 1124 | * @see #onResume |
| 1125 | * @see #onSaveInstanceState |
| 1126 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1127 | public void onRestoreInstanceState(Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1128 | PersistableBundle persistentState) { |
| 1129 | if (savedInstanceState != null) { |
| 1130 | onRestoreInstanceState(savedInstanceState); |
| 1131 | } |
| 1132 | } |
| 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | /** |
| 1135 | * Restore the state of any saved managed dialogs. |
| 1136 | * |
| 1137 | * @param savedInstanceState The bundle to restore from. |
| 1138 | */ |
| 1139 | private void restoreManagedDialogs(Bundle savedInstanceState) { |
| 1140 | final Bundle b = savedInstanceState.getBundle(SAVED_DIALOGS_TAG); |
| 1141 | if (b == null) { |
| 1142 | return; |
| 1143 | } |
| 1144 | |
| 1145 | final int[] ids = b.getIntArray(SAVED_DIALOG_IDS_KEY); |
| 1146 | final int numDialogs = ids.length; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1147 | mManagedDialogs = new SparseArray<ManagedDialog>(numDialogs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | for (int i = 0; i < numDialogs; i++) { |
| 1149 | final Integer dialogId = ids[i]; |
| 1150 | Bundle dialogState = b.getBundle(savedDialogKeyFor(dialogId)); |
| 1151 | if (dialogState != null) { |
Romain Guy | e35c235 | 2009-06-19 13:18:12 -0700 | [diff] [blame] | 1152 | // Calling onRestoreInstanceState() below will invoke dispatchOnCreate |
| 1153 | // so tell createDialog() not to do it, otherwise we get an exception |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1154 | final ManagedDialog md = new ManagedDialog(); |
| 1155 | md.mArgs = b.getBundle(savedDialogArgsKeyFor(dialogId)); |
| 1156 | md.mDialog = createDialog(dialogId, dialogState, md.mArgs); |
| 1157 | if (md.mDialog != null) { |
| 1158 | mManagedDialogs.put(dialogId, md); |
| 1159 | onPrepareDialog(dialogId, md.mDialog, md.mArgs); |
| 1160 | md.mDialog.onRestoreInstanceState(dialogState); |
| 1161 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1166 | private Dialog createDialog(Integer dialogId, Bundle state, Bundle args) { |
| 1167 | final Dialog dialog = onCreateDialog(dialogId, args); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1168 | if (dialog == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1169 | return null; |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1170 | } |
Romain Guy | 6de4aed | 2009-07-08 10:54:45 -0700 | [diff] [blame] | 1171 | dialog.dispatchOnCreate(state); |
Romain Guy | 764d533 | 2009-06-17 16:52:22 -0700 | [diff] [blame] | 1172 | return dialog; |
| 1173 | } |
| 1174 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1175 | private static String savedDialogKeyFor(int key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1176 | return SAVED_DIALOG_KEY_PREFIX + key; |
| 1177 | } |
| 1178 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1179 | private static String savedDialogArgsKeyFor(int key) { |
| 1180 | return SAVED_DIALOG_ARGS_KEY_PREFIX + key; |
| 1181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | |
| 1183 | /** |
| 1184 | * Called when activity start-up is complete (after {@link #onStart} |
| 1185 | * and {@link #onRestoreInstanceState} have been called). Applications will |
| 1186 | * generally not implement this method; it is intended for system |
| 1187 | * classes to do final initialization after application code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1188 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | * <p><em>Derived classes must call through to the super class's |
| 1190 | * implementation of this method. If they do not, an exception will be |
| 1191 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1192 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | * @param savedInstanceState If the activity is being re-initialized after |
| 1194 | * previously being shut down then this Bundle contains the data it most |
| 1195 | * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> |
| 1196 | * @see #onCreate |
| 1197 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1198 | @CallSuper |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1199 | protected void onPostCreate(@Nullable Bundle savedInstanceState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | if (!isChild()) { |
| 1201 | mTitleReady = true; |
| 1202 | onTitleChanged(getTitle(), getTitleColor()); |
| 1203 | } |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 1204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | mCalled = true; |
| 1206 | } |
| 1207 | |
| 1208 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1209 | * This is the same as {@link #onPostCreate(Bundle)} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1210 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1211 | * <code>persistAcrossReboots</code>. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1212 | * |
| 1213 | * @param savedInstanceState The data most recently supplied in {@link #onSaveInstanceState} |
| 1214 | * @param persistentState The data caming from the PersistableBundle first |
| 1215 | * saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}. |
| 1216 | * |
| 1217 | * @see #onCreate |
| 1218 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1219 | public void onPostCreate(@Nullable Bundle savedInstanceState, |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1220 | @Nullable PersistableBundle persistentState) { |
| 1221 | onPostCreate(savedInstanceState); |
| 1222 | } |
| 1223 | |
| 1224 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1225 | * Called after {@link #onCreate} — or after {@link #onRestart} when |
| 1226 | * the activity had been stopped, but is now again being displayed to the |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 1227 | * user. It will be followed by {@link #onResume}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | * |
| 1229 | * <p><em>Derived classes must call through to the super class's |
| 1230 | * implementation of this method. If they do not, an exception will be |
| 1231 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1232 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | * @see #onCreate |
| 1234 | * @see #onStop |
| 1235 | * @see #onResume |
| 1236 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1237 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | protected void onStart() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1239 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStart " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | mCalled = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1241 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 1242 | mFragments.doLoaderStart(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1243 | |
| 1244 | getApplication().dispatchActivityStarted(this); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1245 | |
| 1246 | if (mAutoFillResetNeeded) { |
| 1247 | AutofillManager afm = getAutofillManager(); |
| 1248 | if (afm != null) { |
| 1249 | afm.onVisibleForAutofill(); |
| 1250 | } |
| 1251 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | /** |
| 1255 | * Called after {@link #onStop} when the current activity is being |
| 1256 | * re-displayed to the user (the user has navigated back to it). It will |
| 1257 | * be followed by {@link #onStart} and then {@link #onResume}. |
| 1258 | * |
| 1259 | * <p>For activities that are using raw {@link Cursor} objects (instead of |
| 1260 | * creating them through |
| 1261 | * {@link #managedQuery(android.net.Uri , String[], String, String[], String)}, |
| 1262 | * this is usually the place |
| 1263 | * where the cursor should be requeried (because you had deactivated it in |
| 1264 | * {@link #onStop}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1265 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | * <p><em>Derived classes must call through to the super class's |
| 1267 | * implementation of this method. If they do not, an exception will be |
| 1268 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1269 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | * @see #onStop |
| 1271 | * @see #onStart |
| 1272 | * @see #onResume |
| 1273 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1274 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | protected void onRestart() { |
| 1276 | mCalled = true; |
| 1277 | } |
| 1278 | |
| 1279 | /** |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 1280 | * Called when an {@link #onResume} is coming up, prior to other pre-resume callbacks |
| 1281 | * such as {@link #onNewIntent} and {@link #onActivityResult}. This is primarily intended |
| 1282 | * to give the activity a hint that its state is no longer saved -- it will generally |
| 1283 | * be called after {@link #onSaveInstanceState} and prior to the activity being |
| 1284 | * resumed/started again. |
| 1285 | */ |
| 1286 | public void onStateNotSaved() { |
| 1287 | } |
| 1288 | |
| 1289 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | * Called after {@link #onRestoreInstanceState}, {@link #onRestart}, or |
| 1291 | * {@link #onPause}, for your activity to start interacting with the user. |
| 1292 | * This is a good place to begin animations, open exclusive-access devices |
| 1293 | * (such as the camera), etc. |
| 1294 | * |
| 1295 | * <p>Keep in mind that onResume is not the best indicator that your activity |
| 1296 | * is visible to the user; a system window such as the keyguard may be in |
| 1297 | * front. Use {@link #onWindowFocusChanged} to know for certain that your |
| 1298 | * activity is visible to the user (for example, to resume a game). |
| 1299 | * |
| 1300 | * <p><em>Derived classes must call through to the super class's |
| 1301 | * implementation of this method. If they do not, an exception will be |
| 1302 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1303 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | * @see #onRestoreInstanceState |
| 1305 | * @see #onRestart |
| 1306 | * @see #onPostResume |
| 1307 | * @see #onPause |
| 1308 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1309 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | protected void onResume() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1311 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onResume " + this); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1312 | getApplication().dispatchActivityResumed(this); |
George Mount | bdc4d8d | 2016-03-23 13:10:13 -0700 | [diff] [blame] | 1313 | mActivityTransitionState.onResume(this, isTopOfTask()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | mCalled = true; |
| 1315 | } |
| 1316 | |
| 1317 | /** |
| 1318 | * Called when activity resume is complete (after {@link #onResume} has |
| 1319 | * been called). Applications will generally not implement this method; |
| 1320 | * it is intended for system classes to do final setup after application |
| 1321 | * resume code has run. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1322 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | * <p><em>Derived classes must call through to the super class's |
| 1324 | * implementation of this method. If they do not, an exception will be |
| 1325 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1326 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | * @see #onResume |
| 1328 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1329 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | protected void onPostResume() { |
| 1331 | final Window win = getWindow(); |
| 1332 | if (win != null) win.makeActive(); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1333 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | mCalled = true; |
| 1335 | } |
| 1336 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1337 | void setVoiceInteractor(IVoiceInteractor voiceInteractor) { |
Amith Yamasani | eeed06c | 2016-05-03 15:07:03 -0700 | [diff] [blame] | 1338 | if (mVoiceInteractor != null) { |
| 1339 | for (Request activeRequest: mVoiceInteractor.getActiveRequests()) { |
| 1340 | activeRequest.cancel(); |
| 1341 | activeRequest.clear(); |
| 1342 | } |
| 1343 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1344 | if (voiceInteractor == null) { |
| 1345 | mVoiceInteractor = null; |
| 1346 | } else { |
| 1347 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 1348 | Looper.myLooper()); |
| 1349 | } |
| 1350 | } |
| 1351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | /** |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1353 | * Gets the next autofill ID. |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1354 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1355 | * <p>All IDs will be bigger than {@link View#LAST_APP_AUTOFILL_ID}. All IDs returned |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1356 | * will be unique. |
| 1357 | * |
| 1358 | * @return A ID that is unique in the activity |
| 1359 | * |
| 1360 | * {@hide} |
| 1361 | */ |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1362 | public int getNextAutofillId() { |
| 1363 | if (mLastAutofillId == Integer.MAX_VALUE - 1) { |
| 1364 | mLastAutofillId = View.LAST_APP_AUTOFILL_ID; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1367 | mLastAutofillId++; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1368 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1369 | return mLastAutofillId; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1373 | * Check whether this activity is running as part of a voice interaction with the user. |
| 1374 | * If true, it should perform its interaction with the user through the |
| 1375 | * {@link VoiceInteractor} returned by {@link #getVoiceInteractor}. |
| 1376 | */ |
| 1377 | public boolean isVoiceInteraction() { |
| 1378 | return mVoiceInteractor != null; |
| 1379 | } |
| 1380 | |
| 1381 | /** |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1382 | * Like {@link #isVoiceInteraction}, but only returns true if this is also the root |
| 1383 | * of a voice interaction. That is, returns true if this activity was directly |
| 1384 | * started by the voice interaction service as the initiation of a voice interaction. |
| 1385 | * Otherwise, for example if it was started by another activity while under voice |
| 1386 | * interaction, returns false. |
| 1387 | */ |
| 1388 | public boolean isVoiceInteractionRoot() { |
| 1389 | try { |
| 1390 | return mVoiceInteractor != null |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1391 | && ActivityManager.getService().isRootVoiceInteraction(mToken); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1392 | } catch (RemoteException e) { |
| 1393 | } |
| 1394 | return false; |
| 1395 | } |
| 1396 | |
| 1397 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1398 | * Retrieve the active {@link VoiceInteractor} that the user is going through to |
| 1399 | * interact with this activity. |
| 1400 | */ |
| 1401 | public VoiceInteractor getVoiceInteractor() { |
| 1402 | return mVoiceInteractor; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1406 | * Queries whether the currently enabled voice interaction service supports returning |
| 1407 | * a voice interactor for use by the activity. This is valid only for the duration of the |
| 1408 | * activity. |
| 1409 | * |
| 1410 | * @return whether the current voice interaction service supports local voice interaction |
| 1411 | */ |
| 1412 | public boolean isLocalVoiceInteractionSupported() { |
| 1413 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1414 | return ActivityManager.getService().supportsLocalVoiceInteraction(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1415 | } catch (RemoteException re) { |
| 1416 | } |
| 1417 | return false; |
| 1418 | } |
| 1419 | |
| 1420 | /** |
| 1421 | * Starts a local voice interaction session. When ready, |
| 1422 | * {@link #onLocalVoiceInteractionStarted()} is called. You can pass a bundle of private options |
| 1423 | * to the registered voice interaction service. |
| 1424 | * @param privateOptions a Bundle of private arguments to the current voice interaction service |
| 1425 | */ |
| 1426 | public void startLocalVoiceInteraction(Bundle privateOptions) { |
| 1427 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1428 | ActivityManager.getService().startLocalVoiceInteraction(mToken, privateOptions); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1429 | } catch (RemoteException re) { |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | /** |
| 1434 | * Callback to indicate that {@link #startLocalVoiceInteraction(Bundle)} has resulted in a |
| 1435 | * voice interaction session being started. You can now retrieve a voice interactor using |
| 1436 | * {@link #getVoiceInteractor()}. |
| 1437 | */ |
| 1438 | public void onLocalVoiceInteractionStarted() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /** |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1442 | * Callback to indicate that the local voice interaction has stopped either |
| 1443 | * because it was requested through a call to {@link #stopLocalVoiceInteraction()} |
| 1444 | * or because it was canceled by the user. The previously acquired {@link VoiceInteractor} |
| 1445 | * is no longer valid after this. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1446 | */ |
| 1447 | public void onLocalVoiceInteractionStopped() { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | /** |
| 1451 | * Request to terminate the current voice interaction that was previously started |
Amith Yamasani | d8d967e | 2016-04-08 09:57:01 -0700 | [diff] [blame] | 1452 | * using {@link #startLocalVoiceInteraction(Bundle)}. When the interaction is |
| 1453 | * terminated, {@link #onLocalVoiceInteractionStopped()} will be called. |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1454 | */ |
| 1455 | public void stopLocalVoiceInteraction() { |
| 1456 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1457 | ActivityManager.getService().stopLocalVoiceInteraction(mToken); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1458 | } catch (RemoteException re) { |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | * This is called for activities that set launchMode to "singleTop" in |
| 1464 | * their package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} |
| 1465 | * flag when calling {@link #startActivity}. In either case, when the |
| 1466 | * activity is re-launched while at the top of the activity stack instead |
| 1467 | * of a new instance of the activity being started, onNewIntent() will be |
| 1468 | * called on the existing instance with the Intent that was used to |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1469 | * re-launch it. |
| 1470 | * |
| 1471 | * <p>An activity will always be paused before receiving a new intent, so |
| 1472 | * you can count on {@link #onResume} being called after this method. |
| 1473 | * |
| 1474 | * <p>Note that {@link #getIntent} still returns the original Intent. You |
| 1475 | * can use {@link #setIntent} to update it to this new Intent. |
| 1476 | * |
| 1477 | * @param intent The new intent that was started for the activity. |
| 1478 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | * @see #getIntent |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1480 | * @see #setIntent |
| 1481 | * @see #onResume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | */ |
| 1483 | protected void onNewIntent(Intent intent) { |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 1488 | * |
| 1489 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 1490 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 1491 | * |
| 1492 | * @param outState The bundle to save the state to. |
| 1493 | */ |
| 1494 | final void performSaveInstanceState(Bundle outState) { |
| 1495 | onSaveInstanceState(outState); |
| 1496 | saveManagedDialogs(outState); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1497 | mActivityTransitionState.saveState(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 1498 | storeHasCurrentPermissionRequest(outState); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1499 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1503 | * The hook for {@link ActivityThread} to save the state of this activity. |
| 1504 | * |
| 1505 | * Calls {@link #onSaveInstanceState(android.os.Bundle)} |
| 1506 | * and {@link #saveManagedDialogs(android.os.Bundle)}. |
| 1507 | * |
| 1508 | * @param outState The bundle to save the state to. |
| 1509 | * @param outPersistentState The bundle to save persistent state to. |
| 1510 | */ |
| 1511 | final void performSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { |
| 1512 | onSaveInstanceState(outState, outPersistentState); |
| 1513 | saveManagedDialogs(outState); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 1514 | storeHasCurrentPermissionRequest(outState); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1515 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState + |
| 1516 | ", " + outPersistentState); |
| 1517 | } |
| 1518 | |
| 1519 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | * Called to retrieve per-instance state from an activity before being killed |
| 1521 | * so that the state can be restored in {@link #onCreate} or |
| 1522 | * {@link #onRestoreInstanceState} (the {@link Bundle} populated by this method |
| 1523 | * will be passed to both). |
| 1524 | * |
| 1525 | * <p>This method is called before an activity may be killed so that when it |
| 1526 | * comes back some time in the future it can restore its state. For example, |
| 1527 | * if activity B is launched in front of activity A, and at some point activity |
| 1528 | * A is killed to reclaim resources, activity A will have a chance to save the |
| 1529 | * current state of its user interface via this method so that when the user |
| 1530 | * returns to activity A, the state of the user interface can be restored |
| 1531 | * via {@link #onCreate} or {@link #onRestoreInstanceState}. |
| 1532 | * |
| 1533 | * <p>Do not confuse this method with activity lifecycle callbacks such as |
| 1534 | * {@link #onPause}, which is always called when an activity is being placed |
| 1535 | * in the background or on its way to destruction, or {@link #onStop} which |
| 1536 | * is called before destruction. One example of when {@link #onPause} and |
| 1537 | * {@link #onStop} is called and not this method is when a user navigates back |
| 1538 | * from activity B to activity A: there is no need to call {@link #onSaveInstanceState} |
| 1539 | * on B because that particular instance will never be restored, so the |
| 1540 | * system avoids calling it. An example when {@link #onPause} is called and |
| 1541 | * not {@link #onSaveInstanceState} is when activity B is launched in front of activity A: |
| 1542 | * the system may avoid calling {@link #onSaveInstanceState} on activity A if it isn't |
| 1543 | * killed during the lifetime of B since the state of the user interface of |
| 1544 | * A will stay intact. |
| 1545 | * |
| 1546 | * <p>The default implementation takes care of most of the UI per-instance |
| 1547 | * state for you by calling {@link android.view.View#onSaveInstanceState()} on each |
| 1548 | * view in the hierarchy that has an id, and by saving the id of the currently |
| 1549 | * focused view (all of which is restored by the default implementation of |
| 1550 | * {@link #onRestoreInstanceState}). If you override this method to save additional |
| 1551 | * information not captured by each individual view, you will likely want to |
| 1552 | * call through to the default implementation, otherwise be prepared to save |
| 1553 | * all of the state of each view yourself. |
| 1554 | * |
| 1555 | * <p>If called, this method will occur before {@link #onStop}. There are |
| 1556 | * no guarantees about whether it will occur before or after {@link #onPause}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1557 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | * @param outState Bundle in which to place your saved state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1559 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | * @see #onCreate |
| 1561 | * @see #onRestoreInstanceState |
| 1562 | * @see #onPause |
| 1563 | */ |
| 1564 | protected void onSaveInstanceState(Bundle outState) { |
| 1565 | outState.putBundle(WINDOW_HIERARCHY_TAG, mWindow.saveHierarchyState()); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1566 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1567 | outState.putInt(LAST_AUTOFILL_ID, mLastAutofillId); |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1568 | Parcelable p = mFragments.saveAllState(); |
| 1569 | if (p != null) { |
| 1570 | outState.putParcelable(FRAGMENTS_TAG, p); |
| 1571 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1572 | if (mAutoFillResetNeeded) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1573 | outState.putBoolean(AUTOFILL_RESET_NEEDED, true); |
| 1574 | getAutofillManager().onSaveInstanceState(outState); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1575 | } |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1576 | getApplication().dispatchActivitySaveInstanceState(this, outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | /** |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1580 | * This is the same as {@link #onSaveInstanceState} but is called for activities |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 1581 | * created with the attribute {@link android.R.attr#persistableMode} set to |
| 1582 | * <code>persistAcrossReboots</code>. The {@link android.os.PersistableBundle} passed |
| 1583 | * in will be saved and presented in {@link #onCreate(Bundle, PersistableBundle)} |
| 1584 | * the first time that this activity is restarted following the next device reboot. |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1585 | * |
| 1586 | * @param outState Bundle in which to place your saved state. |
| 1587 | * @param outPersistentState State which will be saved across reboots. |
| 1588 | * |
| 1589 | * @see #onSaveInstanceState(Bundle) |
| 1590 | * @see #onCreate |
| 1591 | * @see #onRestoreInstanceState(Bundle, PersistableBundle) |
| 1592 | * @see #onPause |
| 1593 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 1594 | public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1595 | onSaveInstanceState(outState); |
| 1596 | } |
| 1597 | |
| 1598 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | * Save the state of any managed dialogs. |
| 1600 | * |
| 1601 | * @param outState place to store the saved state. |
| 1602 | */ |
| 1603 | private void saveManagedDialogs(Bundle outState) { |
| 1604 | if (mManagedDialogs == null) { |
| 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | final int numDialogs = mManagedDialogs.size(); |
| 1609 | if (numDialogs == 0) { |
| 1610 | return; |
| 1611 | } |
| 1612 | |
| 1613 | Bundle dialogState = new Bundle(); |
| 1614 | |
| 1615 | int[] ids = new int[mManagedDialogs.size()]; |
| 1616 | |
| 1617 | // save each dialog's bundle, gather the ids |
| 1618 | for (int i = 0; i < numDialogs; i++) { |
| 1619 | final int key = mManagedDialogs.keyAt(i); |
| 1620 | ids[i] = key; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1621 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 1622 | dialogState.putBundle(savedDialogKeyFor(key), md.mDialog.onSaveInstanceState()); |
| 1623 | if (md.mArgs != null) { |
| 1624 | dialogState.putBundle(savedDialogArgsKeyFor(key), md.mArgs); |
| 1625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | dialogState.putIntArray(SAVED_DIALOG_IDS_KEY, ids); |
| 1629 | outState.putBundle(SAVED_DIALOGS_TAG, dialogState); |
| 1630 | } |
| 1631 | |
| 1632 | |
| 1633 | /** |
| 1634 | * Called as part of the activity lifecycle when an activity is going into |
| 1635 | * the background, but has not (yet) been killed. The counterpart to |
| 1636 | * {@link #onResume}. |
| 1637 | * |
| 1638 | * <p>When activity B is launched in front of activity A, this callback will |
| 1639 | * be invoked on A. B will not be created until A's {@link #onPause} returns, |
| 1640 | * so be sure to not do anything lengthy here. |
| 1641 | * |
| 1642 | * <p>This callback is mostly used for saving any persistent state the |
| 1643 | * activity is editing, to present a "edit in place" model to the user and |
| 1644 | * making sure nothing is lost if there are not enough resources to start |
| 1645 | * the new activity without first killing this one. This is also a good |
| 1646 | * place to do things like stop animations and other things that consume a |
Pin Ting | 14a9310 | 2012-04-25 11:27:03 +0800 | [diff] [blame] | 1647 | * noticeable amount of CPU in order to make the switch to the next activity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | * as fast as possible, or to close resources that are exclusive access |
| 1649 | * such as the camera. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1650 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | * <p>In situations where the system needs more memory it may kill paused |
| 1652 | * processes to reclaim resources. Because of this, you should be sure |
| 1653 | * that all of your state is saved by the time you return from |
| 1654 | * this function. In general {@link #onSaveInstanceState} is used to save |
| 1655 | * per-instance state in the activity and this method is used to store |
| 1656 | * global persistent data (in content providers, files, etc.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1657 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | * <p>After receiving this call you will usually receive a following call |
| 1659 | * to {@link #onStop} (after the next activity has been resumed and |
| 1660 | * displayed), however in some cases there will be a direct call back to |
| 1661 | * {@link #onResume} without going through the stopped state. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1662 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | * <p><em>Derived classes must call through to the super class's |
| 1664 | * implementation of this method. If they do not, an exception will be |
| 1665 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1666 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | * @see #onResume |
| 1668 | * @see #onSaveInstanceState |
| 1669 | * @see #onStop |
| 1670 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1671 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | protected void onPause() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1673 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onPause " + this); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1674 | getApplication().dispatchActivityPaused(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | mCalled = true; |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * Called as part of the activity lifecycle when an activity is about to go |
| 1680 | * into the background as the result of user choice. For example, when the |
| 1681 | * user presses the Home key, {@link #onUserLeaveHint} will be called, but |
| 1682 | * when an incoming phone call causes the in-call Activity to be automatically |
| 1683 | * brought to the foreground, {@link #onUserLeaveHint} will not be called on |
| 1684 | * the activity being interrupted. In cases when it is invoked, this method |
| 1685 | * is called right before the activity's {@link #onPause} callback. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1686 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | * <p>This callback and {@link #onUserInteraction} are intended to help |
| 1688 | * activities manage status bar notifications intelligently; specifically, |
| 1689 | * for helping activities determine the proper time to cancel a notfication. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1690 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | * @see #onUserInteraction() |
| 1692 | */ |
| 1693 | protected void onUserLeaveHint() { |
| 1694 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1696 | /** |
| 1697 | * Generate a new thumbnail for this activity. This method is called before |
| 1698 | * pausing the activity, and should draw into <var>outBitmap</var> the |
| 1699 | * imagery for the desired thumbnail in the dimensions of that bitmap. It |
| 1700 | * can use the given <var>canvas</var>, which is configured to draw into the |
| 1701 | * bitmap, for rendering if desired. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1702 | * |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1703 | * <p>The default implementation returns fails and does not draw a thumbnail; |
| 1704 | * this will result in the platform creating its own thumbnail if needed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1705 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | * @param outBitmap The bitmap to contain the thumbnail. |
| 1707 | * @param canvas Can be used to render into the bitmap. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1708 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | * @return Return true if you have drawn into the bitmap; otherwise after |
| 1710 | * you return it will be filled with a default thumbnail. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1711 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | * @see #onCreateDescription |
| 1713 | * @see #onSaveInstanceState |
| 1714 | * @see #onPause |
| 1715 | */ |
| 1716 | public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1717 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | /** |
| 1721 | * Generate a new description for this activity. This method is called |
| 1722 | * before pausing the activity and can, if desired, return some textual |
| 1723 | * description of its current state to be displayed to the user. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1724 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | * <p>The default implementation returns null, which will cause you to |
| 1726 | * inherit the description from the previous activity. If all activities |
| 1727 | * return null, generally the label of the top activity will be used as the |
| 1728 | * description. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1729 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | * @return A description of what the user is doing. It should be short and |
| 1731 | * sweet (only a few words). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1732 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | * @see #onCreateThumbnail |
| 1734 | * @see #onSaveInstanceState |
| 1735 | * @see #onPause |
| 1736 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1737 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1738 | public CharSequence onCreateDescription() { |
| 1739 | return null; |
| 1740 | } |
| 1741 | |
| 1742 | /** |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1743 | * This is called when the user is requesting an assist, to build a full |
| 1744 | * {@link Intent#ACTION_ASSIST} Intent with all of the context of the current |
| 1745 | * application. You can override this method to place into the bundle anything |
| 1746 | * you would like to appear in the {@link Intent#EXTRA_ASSIST_CONTEXT} part |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 1747 | * of the assist Intent. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1748 | * |
| 1749 | * <p>This function will be called after any global assist callbacks that had |
Ying Wang | 4e0eb22 | 2013-04-18 20:39:48 -0700 | [diff] [blame] | 1750 | * been registered with {@link Application#registerOnProvideAssistDataListener |
| 1751 | * Application.registerOnProvideAssistDataListener}. |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1752 | */ |
| 1753 | public void onProvideAssistData(Bundle data) { |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | /** |
| 1757 | * This is called when the user is requesting an assist, to provide references |
| 1758 | * to content related to the current activity. Before being called, the |
| 1759 | * {@code outContent} Intent is filled with the base Intent of the activity (the Intent |
| 1760 | * returned by {@link #getIntent()}). The Intent's extras are stripped of any types |
| 1761 | * that are not valid for {@link PersistableBundle} or non-framework Parcelables, and |
| 1762 | * the flags {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION} and |
| 1763 | * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION} are cleared from the Intent. |
| 1764 | * |
| 1765 | * <p>Custom implementation may adjust the content intent to better reflect the top-level |
| 1766 | * context of the activity, and fill in its ClipData with additional content of |
| 1767 | * interest that the user is currently viewing. For example, an image gallery application |
| 1768 | * that has launched in to an activity allowing the user to swipe through pictures should |
| 1769 | * modify the intent to reference the current image they are looking it; such an |
| 1770 | * application when showing a list of pictures should add a ClipData that has |
| 1771 | * references to all of the pictures currently visible on screen.</p> |
| 1772 | * |
| 1773 | * @param outContent The assist content to return. |
| 1774 | */ |
| 1775 | public void onProvideAssistContent(AssistContent outContent) { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1776 | } |
| 1777 | |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1778 | /** |
Clara Bayarri | ab591ba | 2016-05-16 17:48:16 +0100 | [diff] [blame] | 1779 | * Request the Keyboard Shortcuts screen to show up. This will trigger |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1780 | * {@link #onProvideKeyboardShortcuts} to retrieve the shortcuts for the foreground activity. |
| 1781 | */ |
Clara Bayarri | ac6f034 | 2016-05-16 14:15:14 +0100 | [diff] [blame] | 1782 | public final void requestShowKeyboardShortcuts() { |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1783 | Intent intent = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 1784 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
| 1785 | sendBroadcastAsUser(intent, UserHandle.SYSTEM); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * Dismiss the Keyboard Shortcuts screen. |
| 1790 | */ |
| 1791 | public final void dismissKeyboardShortcutsHelper() { |
| 1792 | Intent intent = new Intent(Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS); |
Andrei Stingaceanu | a3d2693 | 2016-07-15 11:12:20 +0100 | [diff] [blame] | 1793 | intent.setPackage(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME); |
| 1794 | sendBroadcastAsUser(intent, UserHandle.SYSTEM); |
Clara Bayarri | eb3c2d3 | 2016-04-01 14:37:32 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1797 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 1798 | public void onProvideKeyboardShortcuts( |
| 1799 | List<KeyboardShortcutGroup> data, Menu menu, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1800 | if (menu == null) { |
| 1801 | return; |
| 1802 | } |
| 1803 | KeyboardShortcutGroup group = null; |
| 1804 | int menuSize = menu.size(); |
| 1805 | for (int i = 0; i < menuSize; ++i) { |
| 1806 | final MenuItem item = menu.getItem(i); |
| 1807 | final CharSequence title = item.getTitle(); |
| 1808 | final char alphaShortcut = item.getAlphabeticShortcut(); |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 1809 | final int alphaModifiers = item.getAlphabeticModifiers(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1810 | if (title != null && alphaShortcut != MIN_VALUE) { |
| 1811 | if (group == null) { |
Clara Bayarri | ada88b3 | 2016-02-02 18:08:01 +0000 | [diff] [blame] | 1812 | final int resource = mApplication.getApplicationInfo().labelRes; |
| 1813 | group = new KeyboardShortcutGroup(resource != 0 ? getString(resource) : null); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1814 | } |
| 1815 | group.addItem(new KeyboardShortcutInfo( |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 1816 | title, alphaShortcut, alphaModifiers)); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | if (group != null) { |
| 1820 | data.add(group); |
| 1821 | } |
| 1822 | } |
| 1823 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1824 | /** |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1825 | * Ask to have the current assistant shown to the user. This only works if the calling |
| 1826 | * activity is the current foreground activity. It is the same as calling |
| 1827 | * {@link android.service.voice.VoiceInteractionService#showSession |
| 1828 | * VoiceInteractionService.showSession} and requesting all of the possible context. |
| 1829 | * The receiver will always see |
| 1830 | * {@link android.service.voice.VoiceInteractionSession#SHOW_SOURCE_APPLICATION} set. |
| 1831 | * @return Returns true if the assistant was successfully invoked, else false. For example |
| 1832 | * false will be returned if the caller is not the current top activity. |
| 1833 | */ |
| 1834 | public boolean showAssist(Bundle args) { |
| 1835 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1836 | return ActivityManager.getService().showAssistFromActivity(mToken, args); |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1837 | } catch (RemoteException e) { |
| 1838 | } |
| 1839 | return false; |
| 1840 | } |
| 1841 | |
| 1842 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | * Called when you are no longer visible to the user. You will next |
| 1844 | * receive either {@link #onRestart}, {@link #onDestroy}, or nothing, |
| 1845 | * depending on later user activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1846 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1847 | * <p><em>Derived classes must call through to the super class's |
| 1848 | * implementation of this method. If they do not, an exception will be |
| 1849 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1850 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | * @see #onRestart |
| 1852 | * @see #onResume |
| 1853 | * @see #onSaveInstanceState |
| 1854 | * @see #onDestroy |
| 1855 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1856 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | protected void onStop() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1858 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStop " + this); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 1859 | if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1860 | mActivityTransitionState.onStop(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1861 | getApplication().dispatchActivityStopped(this); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1862 | mTranslucentCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1863 | mCalled = true; |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 1864 | if (isFinishing() && mAutoFillResetNeeded) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1865 | getAutofillManager().commit(); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | /** |
| 1870 | * Perform any final cleanup before an activity is destroyed. This can |
| 1871 | * happen either because the activity is finishing (someone called |
| 1872 | * {@link #finish} on it, or because the system is temporarily destroying |
| 1873 | * this instance of the activity to save space. You can distinguish |
| 1874 | * between these two scenarios with the {@link #isFinishing} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1875 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | * <p><em>Note: do not count on this method being called as a place for |
| 1877 | * saving data! For example, if an activity is editing data in a content |
| 1878 | * provider, those edits should be committed in either {@link #onPause} or |
| 1879 | * {@link #onSaveInstanceState}, not here.</em> This method is usually implemented to |
| 1880 | * free resources like threads that are associated with an activity, so |
| 1881 | * that a destroyed activity does not leave such things around while the |
| 1882 | * rest of its application is still running. There are situations where |
| 1883 | * the system will simply kill the activity's hosting process without |
| 1884 | * calling this method (or any others) in it, so it should not be used to |
| 1885 | * do things that are intended to remain around after the process goes |
| 1886 | * away. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1887 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | * <p><em>Derived classes must call through to the super class's |
| 1889 | * implementation of this method. If they do not, an exception will be |
| 1890 | * thrown.</em></p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1891 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | * @see #onPause |
| 1893 | * @see #onStop |
| 1894 | * @see #finish |
| 1895 | * @see #isFinishing |
| 1896 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 1897 | @CallSuper |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1898 | protected void onDestroy() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1899 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1900 | mCalled = true; |
| 1901 | |
| 1902 | // dismiss any dialogs we are managing. |
| 1903 | if (mManagedDialogs != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | final int numDialogs = mManagedDialogs.size(); |
| 1905 | for (int i = 0; i < numDialogs; i++) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1906 | final ManagedDialog md = mManagedDialogs.valueAt(i); |
| 1907 | if (md.mDialog.isShowing()) { |
| 1908 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | } |
| 1910 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1911 | mManagedDialogs = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | |
| 1914 | // close any cursors we are managing. |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 1915 | synchronized (mManagedCursors) { |
| 1916 | int numCursors = mManagedCursors.size(); |
| 1917 | for (int i = 0; i < numCursors; i++) { |
| 1918 | ManagedCursor c = mManagedCursors.get(i); |
| 1919 | if (c != null) { |
| 1920 | c.mCursor.close(); |
| 1921 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | } |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 1923 | mManagedCursors.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | } |
Amith Yamasani | 4986044 | 2010-03-17 20:54:10 -0700 | [diff] [blame] | 1925 | |
| 1926 | // Close any open search dialog |
| 1927 | if (mSearchManager != null) { |
| 1928 | mSearchManager.stopSearch(); |
| 1929 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1930 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 1931 | if (mActionBar != null) { |
| 1932 | mActionBar.onDestroy(); |
| 1933 | } |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 1934 | |
| 1935 | getApplication().dispatchActivityDestroyed(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | /** |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 1939 | * Report to the system that your app is now fully drawn, purely for diagnostic |
| 1940 | * purposes (calling it does not impact the visible behavior of the activity). |
| 1941 | * This is only used to help instrument application launch times, so that the |
| 1942 | * app can report when it is fully in a usable state; without this, the only thing |
| 1943 | * the system itself can determine is the point at which the activity's window |
| 1944 | * is <em>first</em> drawn and displayed. To participate in app launch time |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1945 | * measurement, you should always call this method after first launch (when |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 1946 | * {@link #onCreate(android.os.Bundle)} is called), at the point where you have |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1947 | * entirely drawn your UI and populated with all of the significant data. You |
| 1948 | * can safely call this method any time after first launch as well, in which case |
| 1949 | * it will simply be ignored. |
| 1950 | */ |
| 1951 | public void reportFullyDrawn() { |
| 1952 | if (mDoReportFullyDrawn) { |
| 1953 | mDoReportFullyDrawn = false; |
| 1954 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1955 | ActivityManager.getService().reportActivityFullyDrawn(mToken); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1956 | } catch (RemoteException e) { |
| 1957 | } |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | /** |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1962 | * Called by the system when the activity changes from fullscreen mode to multi-window mode and |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1963 | * visa-versa. This method provides the same configuration that will be sent in the following |
| 1964 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 1965 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1966 | * @see android.R.attr#resizeableActivity |
| 1967 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1968 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1969 | * @param newConfig The new configuration of the activity with the state |
| 1970 | * {@param isInMultiWindowMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1971 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1972 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 1973 | // Left deliberately empty. There should be no side effects if a direct |
| 1974 | // subclass of Activity does not call super. |
| 1975 | onMultiWindowModeChanged(isInMultiWindowMode); |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * Called by the system when the activity changes from fullscreen mode to multi-window mode and |
| 1980 | * visa-versa. |
| 1981 | * |
| 1982 | * @see android.R.attr#resizeableActivity |
| 1983 | * |
| 1984 | * @param isInMultiWindowMode True if the activity is in multi-window mode. |
| 1985 | * |
| 1986 | * @deprecated Use {@link #onMultiWindowModeChanged(boolean, Configuration)} instead. |
| 1987 | */ |
| 1988 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1989 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 1990 | // Left deliberately empty. There should be no side effects if a direct |
| 1991 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /** |
| 1995 | * Returns true if the activity is currently in multi-window mode. |
| 1996 | * @see android.R.attr#resizeableActivity |
| 1997 | * |
| 1998 | * @return True if the activity is in multi-window mode. |
| 1999 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2000 | public boolean isInMultiWindowMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2001 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2002 | return ActivityManager.getService().isInMultiWindowMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2003 | } catch (RemoteException e) { |
| 2004 | } |
| 2005 | return false; |
| 2006 | } |
| 2007 | |
| 2008 | /** |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2009 | * Called by the system when the activity changes to and from picture-in-picture mode. This |
| 2010 | * method provides the same configuration that will be sent in the following |
| 2011 | * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode. |
| 2012 | * |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2013 | * @see android.R.attr#supportsPictureInPicture |
| 2014 | * |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2015 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2016 | * @param newConfig The new configuration of the activity with the state |
| 2017 | * {@param isInPictureInPictureMode}. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2018 | */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2019 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 2020 | Configuration newConfig) { |
| 2021 | // Left deliberately empty. There should be no side effects if a direct |
| 2022 | // subclass of Activity does not call super. |
| 2023 | onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 2024 | } |
| 2025 | |
| 2026 | /** |
| 2027 | * Called by the system when the activity changes to and from picture-in-picture mode. |
| 2028 | * |
| 2029 | * @see android.R.attr#supportsPictureInPicture |
| 2030 | * |
| 2031 | * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. |
| 2032 | * |
| 2033 | * @deprecated Use {@link #onPictureInPictureModeChanged(boolean, Configuration)} instead. |
| 2034 | */ |
| 2035 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2036 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2037 | // Left deliberately empty. There should be no side effects if a direct |
| 2038 | // subclass of Activity does not call super. |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * Returns true if the activity is currently in picture-in-picture mode. |
| 2043 | * @see android.R.attr#supportsPictureInPicture |
| 2044 | * |
| 2045 | * @return True if the activity is in picture-in-picture mode. |
| 2046 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2047 | public boolean isInPictureInPictureMode() { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2048 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2049 | return ActivityManager.getService().isInPictureInPictureMode(mToken); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2050 | } catch (RemoteException e) { |
| 2051 | } |
| 2052 | return false; |
| 2053 | } |
| 2054 | |
| 2055 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2056 | * Puts the activity in picture-in-picture mode if possible in the current system state. Any |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2057 | * prior calls to {@link #setPictureInPictureParams(PictureInPictureParams)} will still apply |
| 2058 | * when entering picture-in-picture through this call. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2059 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2060 | * @see #enterPictureInPictureMode(PictureInPictureParams) |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2061 | * @see android.R.attr#supportsPictureInPicture |
| 2062 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2063 | @Deprecated |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2064 | public void enterPictureInPictureMode() { |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2065 | enterPictureInPictureMode(new PictureInPictureParams.Builder().build()); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2066 | } |
| 2067 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2068 | /** @removed */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2069 | @Deprecated |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2070 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2071 | return enterPictureInPictureMode(PictureInPictureArgs.convert(args)); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2075 | * Puts the activity in picture-in-picture mode if possible in the current system state. The |
| 2076 | * set parameters in {@param params} will be combined with the parameters from prior calls to |
| 2077 | * {@link #setPictureInPictureParams(PictureInPictureParams)}. |
| 2078 | * |
| 2079 | * The system may disallow entering picture-in-picture in various cases, including when the |
| 2080 | * activity is not visible, if the screen is locked or if the user has an activity pinned. |
| 2081 | * |
| 2082 | * @see android.R.attr#supportsPictureInPicture |
| 2083 | * @see PictureInPictureParams |
| 2084 | * |
| 2085 | * @param params non-null parameters to be combined with previously set parameters when entering |
| 2086 | * picture-in-picture. |
| 2087 | * |
| 2088 | * @return true if the system puts this activity into picture-in-picture mode or was already |
| 2089 | * in picture-in-picture mode (@see {@link #isInPictureInPictureMode()) |
| 2090 | */ |
| 2091 | public boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params) { |
| 2092 | try { |
| 2093 | if (params == null) { |
| 2094 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
| 2095 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2096 | return ActivityManagerNative.getDefault().enterPictureInPictureMode(mToken, params); |
| 2097 | } catch (RemoteException e) { |
| 2098 | return false; |
| 2099 | } |
| 2100 | } |
| 2101 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2102 | /** @removed */ |
| 2103 | @Deprecated |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2104 | public void setPictureInPictureArgs(@NonNull PictureInPictureArgs args) { |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2105 | setPictureInPictureParams(PictureInPictureArgs.convert(args)); |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | /** |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2109 | * Updates the properties of the picture-in-picture activity, or sets it to be used later when |
| 2110 | * {@link #enterPictureInPictureMode()} is called. |
| 2111 | * |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2112 | * @param params the new parameters for the picture-in-picture. |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2113 | */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2114 | public void setPictureInPictureParams(@NonNull PictureInPictureParams params) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2115 | try { |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2116 | if (params == null) { |
| 2117 | throw new IllegalArgumentException("Expected non-null picture-in-picture params"); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2118 | } |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2119 | ActivityManagerNative.getDefault().setPictureInPictureParams(mToken, params); |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2120 | } catch (RemoteException e) { |
| 2121 | } |
| 2122 | } |
| 2123 | |
Winson Chung | 8802eac | 2017-04-17 14:21:44 -0700 | [diff] [blame] | 2124 | /** |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 2125 | * Return the number of actions that will be displayed in the picture-in-picture UI when the |
| 2126 | * user interacts with the activity currently in picture-in-picture mode. This number may change |
| 2127 | * if the global configuration changes (ie. if the device is plugged into an external display), |
| 2128 | * but will always be larger than three. |
| 2129 | */ |
| 2130 | public int getMaxNumPictureInPictureActions() { |
| 2131 | try { |
| 2132 | return ActivityManagerNative.getDefault().getMaxNumPictureInPictureActions(mToken); |
| 2133 | } catch (RemoteException e) { |
| 2134 | return 0; |
| 2135 | } |
| 2136 | } |
| 2137 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2138 | void dispatchMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2139 | updateDisplay(displayId); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2140 | onMovedToDisplay(displayId, config); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | /** |
| 2144 | * Called by the system when the activity is moved from one display to another without |
| 2145 | * recreation. This means that this activity is declared to handle all changes to configuration |
| 2146 | * that happened when it was switched to another display, so it wasn't destroyed and created |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2147 | * again. |
| 2148 | * |
| 2149 | * <p>This call will be followed by {@link #onConfigurationChanged(Configuration)} if the |
| 2150 | * applied configuration actually changed. It is up to app developer to choose whether to handle |
| 2151 | * the change in this method or in the following {@link #onConfigurationChanged(Configuration)} |
| 2152 | * call. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2153 | * |
| 2154 | * <p>Use this callback to track changes to the displays if some activity functionality relies |
| 2155 | * on an association with some display properties. |
| 2156 | * |
| 2157 | * @param displayId The id of the display to which activity was moved. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2158 | * @param config Configuration of the activity resources on new display after move. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2159 | * |
| 2160 | * @see #onConfigurationChanged(Configuration) |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2161 | * @see View#onMovedToDisplay(int, Configuration) |
Andrii Kulian | cadacce | 2017-04-26 18:09:54 -0700 | [diff] [blame] | 2162 | * @hide |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2163 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 2164 | public void onMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2165 | } |
| 2166 | |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2167 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2168 | * Called by the system when the device configuration changes while your |
| 2169 | * activity is running. Note that this will <em>only</em> be called if |
| 2170 | * you have selected configurations you would like to handle with the |
| 2171 | * {@link android.R.attr#configChanges} attribute in your manifest. If |
| 2172 | * any configuration change occurs that is not selected to be reported |
| 2173 | * by that attribute, then instead of reporting it the system will stop |
| 2174 | * and restart the activity (to have it launched with the new |
| 2175 | * configuration). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2176 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | * <p>At the time that this function has been called, your Resources |
| 2178 | * object will have been updated to return resource values matching the |
| 2179 | * new configuration. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2180 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2181 | * @param newConfig The new device configuration. |
| 2182 | */ |
| 2183 | public void onConfigurationChanged(Configuration newConfig) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2184 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | mCalled = true; |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 2186 | |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 2187 | mFragments.dispatchConfigurationChanged(newConfig); |
| 2188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | if (mWindow != null) { |
| 2190 | // Pass the configuration changed event to the window |
| 2191 | mWindow.onConfigurationChanged(newConfig); |
| 2192 | } |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 2193 | |
| 2194 | if (mActionBar != null) { |
| 2195 | // Do this last; the action bar will need to access |
| 2196 | // view changes from above. |
| 2197 | mActionBar.onConfigurationChanged(newConfig); |
| 2198 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2199 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | /** |
| 2202 | * If this activity is being destroyed because it can not handle a |
| 2203 | * configuration parameter being changed (and thus its |
| 2204 | * {@link #onConfigurationChanged(Configuration)} method is |
| 2205 | * <em>not</em> being called), then you can use this method to discover |
| 2206 | * the set of changes that have occurred while in the process of being |
| 2207 | * destroyed. Note that there is no guarantee that these will be |
| 2208 | * accurate (other changes could have happened at any time), so you should |
| 2209 | * only use this as an optimization hint. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2210 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | * @return Returns a bit field of the configuration parameters that are |
| 2212 | * changing, as defined by the {@link android.content.res.Configuration} |
| 2213 | * class. |
| 2214 | */ |
| 2215 | public int getChangingConfigurations() { |
| 2216 | return mConfigChangeFlags; |
| 2217 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | /** |
| 2220 | * Retrieve the non-configuration instance data that was previously |
| 2221 | * returned by {@link #onRetainNonConfigurationInstance()}. This will |
| 2222 | * be available from the initial {@link #onCreate} and |
| 2223 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2224 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2225 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2226 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2227 | * as an optimization for handling configuration changes. You should always |
| 2228 | * be able to handle getting a null pointer back, and an activity must |
| 2229 | * still be able to restore itself to its previous state (through the |
| 2230 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2231 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2232 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2233 | * <p><strong>Note:</strong> For most cases you should use the {@link Fragment} API |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2234 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2235 | * available on older platforms through the Android support libraries. |
| 2236 | * |
| 2237 | * @return the object previously returned by {@link #onRetainNonConfigurationInstance()} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2239 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2240 | public Object getLastNonConfigurationInstance() { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2241 | return mLastNonConfigurationInstances != null |
| 2242 | ? mLastNonConfigurationInstances.activity : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | /** |
| 2246 | * Called by the system, as part of destroying an |
| 2247 | * activity due to a configuration change, when it is known that a new |
| 2248 | * instance will immediately be created for the new configuration. You |
| 2249 | * can return any object you like here, including the activity instance |
| 2250 | * itself, which can later be retrieved by calling |
| 2251 | * {@link #getLastNonConfigurationInstance()} in the new activity |
| 2252 | * instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2253 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2254 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2255 | * or later, consider instead using a {@link Fragment} with |
| 2256 | * {@link Fragment#setRetainInstance(boolean) |
| 2257 | * Fragment.setRetainInstance(boolean}.</em> |
| 2258 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | * <p>This function is called purely as an optimization, and you must |
| 2260 | * not rely on it being called. When it is called, a number of guarantees |
| 2261 | * will be made to help optimize configuration switching: |
| 2262 | * <ul> |
| 2263 | * <li> The function will be called between {@link #onStop} and |
| 2264 | * {@link #onDestroy}. |
| 2265 | * <li> A new instance of the activity will <em>always</em> be immediately |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2266 | * created after this one's {@link #onDestroy()} is called. In particular, |
| 2267 | * <em>no</em> messages will be dispatched during this time (when the returned |
| 2268 | * object does not have an activity to be associated with). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2269 | * <li> The object you return here will <em>always</em> be available from |
| 2270 | * the {@link #getLastNonConfigurationInstance()} method of the following |
| 2271 | * activity instance as described there. |
| 2272 | * </ul> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2273 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2274 | * <p>These guarantees are designed so that an activity can use this API |
| 2275 | * to propagate extensive state from the old to new activity instance, from |
| 2276 | * loaded bitmaps, to network connections, to evenly actively running |
| 2277 | * threads. Note that you should <em>not</em> propagate any data that |
| 2278 | * may change based on the configuration, including any data loaded from |
| 2279 | * resources such as strings, layouts, or drawables. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2280 | * |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 2281 | * <p>The guarantee of no message handling during the switch to the next |
| 2282 | * activity simplifies use with active objects. For example if your retained |
| 2283 | * state is an {@link android.os.AsyncTask} you are guaranteed that its |
| 2284 | * call back functions (like {@link android.os.AsyncTask#onPostExecute}) will |
| 2285 | * not be called from the call here until you execute the next instance's |
| 2286 | * {@link #onCreate(Bundle)}. (Note however that there is of course no such |
| 2287 | * guarantee for {@link android.os.AsyncTask#doInBackground} since that is |
| 2288 | * running in a separate thread.) |
| 2289 | * |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2290 | * <p><strong>Note:</strong> For most cases you should use the {@link Fragment} API |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2291 | * {@link Fragment#setRetainInstance(boolean)} instead; this is also |
Adam Powell | c4df6bc | 2016-03-09 15:11:37 -0800 | [diff] [blame] | 2292 | * available on older platforms through the Android support libraries. |
| 2293 | * |
| 2294 | * @return any Object holding the desired state to propagate to the |
| 2295 | * next activity instance |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | */ |
| 2297 | public Object onRetainNonConfigurationInstance() { |
| 2298 | return null; |
| 2299 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2301 | /** |
| 2302 | * Retrieve the non-configuration instance data that was previously |
| 2303 | * returned by {@link #onRetainNonConfigurationChildInstances()}. This will |
| 2304 | * be available from the initial {@link #onCreate} and |
| 2305 | * {@link #onStart} calls to the new instance, allowing you to extract |
| 2306 | * any useful dynamic state from the previous instance. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2307 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2308 | * <p>Note that the data you retrieve here should <em>only</em> be used |
| 2309 | * as an optimization for handling configuration changes. You should always |
| 2310 | * be able to handle getting a null pointer back, and an activity must |
| 2311 | * still be able to restore itself to its previous state (through the |
| 2312 | * normal {@link #onSaveInstanceState(Bundle)} mechanism) even if this |
| 2313 | * function returns null. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2314 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | * @return Returns the object previously returned by |
| 2316 | * {@link #onRetainNonConfigurationChildInstances()} |
| 2317 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2318 | @Nullable |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2319 | HashMap<String, Object> getLastNonConfigurationChildInstances() { |
| 2320 | return mLastNonConfigurationInstances != null |
| 2321 | ? mLastNonConfigurationInstances.children : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | /** |
| 2325 | * This method is similar to {@link #onRetainNonConfigurationInstance()} except that |
| 2326 | * it should return either a mapping from child activity id strings to arbitrary objects, |
| 2327 | * or null. This method is intended to be used by Activity framework subclasses that control a |
| 2328 | * set of child activities, such as ActivityGroup. The same guarantees and restrictions apply |
| 2329 | * as for {@link #onRetainNonConfigurationInstance()}. The default implementation returns null. |
| 2330 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2331 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | HashMap<String,Object> onRetainNonConfigurationChildInstances() { |
| 2333 | return null; |
| 2334 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2335 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2336 | NonConfigurationInstances retainNonConfigurationInstances() { |
| 2337 | Object activity = onRetainNonConfigurationInstance(); |
| 2338 | HashMap<String, Object> children = onRetainNonConfigurationChildInstances(); |
Adam Powell | 44ba79e | 2016-02-04 16:20:37 -0800 | [diff] [blame] | 2339 | FragmentManagerNonConfig fragments = mFragments.retainNestedNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2340 | |
| 2341 | // We're already stopped but we've been asked to retain. |
| 2342 | // Our fragments are taken care of but we need to mark the loaders for retention. |
| 2343 | // In order to do this correctly we need to restart the loaders first before |
| 2344 | // handing them off to the next activity. |
| 2345 | mFragments.doLoaderStart(); |
| 2346 | mFragments.doLoaderStop(true); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2347 | ArrayMap<String, LoaderManager> loaders = mFragments.retainLoaderNonConfig(); |
Adam Powell | cbade7f | 2016-04-15 11:14:37 -0700 | [diff] [blame] | 2348 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2349 | if (activity == null && children == null && fragments == null && loaders == null |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 2350 | && mVoiceInteractor == null) { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2351 | return null; |
| 2352 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2353 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2354 | NonConfigurationInstances nci = new NonConfigurationInstances(); |
| 2355 | nci.activity = activity; |
| 2356 | nci.children = children; |
| 2357 | nci.fragments = fragments; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2358 | nci.loaders = loaders; |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 2359 | if (mVoiceInteractor != null) { |
| 2360 | mVoiceInteractor.retainInstance(); |
| 2361 | nci.voiceInteractor = mVoiceInteractor; |
| 2362 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2363 | return nci; |
| 2364 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | public void onLowMemory() { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2367 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onLowMemory " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | mCalled = true; |
Dianne Hackborn | 9d07180 | 2010-12-08 14:49:15 -0800 | [diff] [blame] | 2369 | mFragments.dispatchLowMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2370 | } |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2371 | |
| 2372 | public void onTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2373 | if (DEBUG_LIFECYCLE) Slog.v(TAG, "onTrimMemory " + this + ": " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 2374 | mCalled = true; |
| 2375 | mFragments.dispatchTrimMemory(level); |
| 2376 | } |
| 2377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2378 | /** |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 2379 | * Return the FragmentManager for interacting with fragments associated |
| 2380 | * with this activity. |
| 2381 | */ |
| 2382 | public FragmentManager getFragmentManager() { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 2383 | return mFragments.getFragmentManager(); |
Dianne Hackborn | 9e14e9f3 | 2010-07-14 11:07:38 -0700 | [diff] [blame] | 2384 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2385 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 2386 | /** |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2387 | * Called when a Fragment is being attached to this activity, immediately |
| 2388 | * after the call to its {@link Fragment#onAttach Fragment.onAttach()} |
| 2389 | * method and before {@link Fragment#onCreate Fragment.onCreate()}. |
| 2390 | */ |
| 2391 | public void onAttachFragment(Fragment fragment) { |
| 2392 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2393 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 2394 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | * Wrapper around |
| 2396 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 2397 | * that gives the resulting {@link Cursor} to call |
| 2398 | * {@link #startManagingCursor} so that the activity will manage its |
| 2399 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2400 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2401 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2402 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2403 | * via {@link #getLoaderManager()}.</em> |
| 2404 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2405 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 2406 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 2407 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 2408 | * not</em> automatically close the cursor and, in that case, you must call |
| 2409 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2410 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | * @param uri The URI of the content provider to query. |
| 2412 | * @param projection List of columns to return. |
| 2413 | * @param selection SQL WHERE clause. |
| 2414 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2415 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2417 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 2419 | * @see #startManagingCursor |
| 2420 | * @hide |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2421 | * |
| 2422 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2424 | @Deprecated |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2425 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 2426 | String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | Cursor c = getContentResolver().query(uri, projection, selection, null, sortOrder); |
| 2428 | if (c != null) { |
| 2429 | startManagingCursor(c); |
| 2430 | } |
| 2431 | return c; |
| 2432 | } |
| 2433 | |
| 2434 | /** |
| 2435 | * Wrapper around |
| 2436 | * {@link ContentResolver#query(android.net.Uri , String[], String, String[], String)} |
| 2437 | * that gives the resulting {@link Cursor} to call |
| 2438 | * {@link #startManagingCursor} so that the activity will manage its |
| 2439 | * lifecycle for you. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2440 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2441 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2442 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2443 | * via {@link #getLoaderManager()}.</em> |
| 2444 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2445 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on a cursor obtained using |
| 2446 | * this method, because the activity will do that for you at the appropriate time. However, if |
| 2447 | * you call {@link #stopManagingCursor} on a cursor from a managed query, the system <em>will |
| 2448 | * not</em> automatically close the cursor and, in that case, you must call |
| 2449 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2450 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | * @param uri The URI of the content provider to query. |
| 2452 | * @param projection List of columns to return. |
| 2453 | * @param selection SQL WHERE clause. |
| 2454 | * @param selectionArgs The arguments to selection, if any ?s are pesent |
| 2455 | * @param sortOrder SQL ORDER BY clause. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2456 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | * @return The Cursor that was returned by query(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2458 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | * @see ContentResolver#query(android.net.Uri , String[], String, String[], String) |
| 2460 | * @see #startManagingCursor |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2461 | * |
| 2462 | * @deprecated Use {@link CursorLoader} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2464 | @Deprecated |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2465 | public final Cursor managedQuery(Uri uri, String[] projection, String selection, |
| 2466 | String[] selectionArgs, String sortOrder) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | Cursor c = getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); |
| 2468 | if (c != null) { |
| 2469 | startManagingCursor(c); |
| 2470 | } |
| 2471 | return c; |
| 2472 | } |
| 2473 | |
| 2474 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | * This method allows the activity to take care of managing the given |
| 2476 | * {@link Cursor}'s lifecycle for you based on the activity's lifecycle. |
| 2477 | * That is, when the activity is stopped it will automatically call |
| 2478 | * {@link Cursor#deactivate} on the given Cursor, and when it is later restarted |
| 2479 | * it will call {@link Cursor#requery} for you. When the activity is |
| 2480 | * destroyed, all managed Cursors will be closed automatically. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2481 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 2482 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 2483 | * or later, consider instead using {@link LoaderManager} instead, available |
| 2484 | * via {@link #getLoaderManager()}.</em> |
| 2485 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2486 | * <p><strong>Warning:</strong> Do not call {@link Cursor#close()} on cursor obtained from |
| 2487 | * {@link #managedQuery}, because the activity will do that for you at the appropriate time. |
| 2488 | * However, if you call {@link #stopManagingCursor} on a cursor from a managed query, the system |
| 2489 | * <em>will not</em> automatically close the cursor and, in that case, you must call |
| 2490 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2491 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | * @param c The Cursor to be managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2493 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | * @see #managedQuery(android.net.Uri , String[], String, String[], String) |
| 2495 | * @see #stopManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2496 | * |
| 2497 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 2498 | * {@link LoaderManager} instead; this is also |
| 2499 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2501 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | public void startManagingCursor(Cursor c) { |
| 2503 | synchronized (mManagedCursors) { |
| 2504 | mManagedCursors.add(new ManagedCursor(c)); |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | /** |
| 2509 | * Given a Cursor that was previously given to |
| 2510 | * {@link #startManagingCursor}, stop the activity's management of that |
| 2511 | * cursor. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2512 | * |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2513 | * <p><strong>Warning:</strong> After calling this method on a cursor from a managed query, |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2514 | * the system <em>will not</em> automatically close the cursor and you must call |
Joe Fernandez | 8ef6970 | 2011-09-02 14:32:22 -0700 | [diff] [blame] | 2515 | * {@link Cursor#close()}.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2516 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2517 | * @param c The Cursor that was being managed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2518 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2519 | * @see #startManagingCursor |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 2520 | * |
| 2521 | * @deprecated Use the new {@link android.content.CursorLoader} class with |
| 2522 | * {@link LoaderManager} instead; this is also |
| 2523 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | */ |
Jason parks | 6ed50de | 2010-08-25 10:18:50 -0500 | [diff] [blame] | 2525 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | public void stopManagingCursor(Cursor c) { |
| 2527 | synchronized (mManagedCursors) { |
| 2528 | final int N = mManagedCursors.size(); |
| 2529 | for (int i=0; i<N; i++) { |
| 2530 | ManagedCursor mc = mManagedCursors.get(i); |
| 2531 | if (mc.mCursor == c) { |
| 2532 | mManagedCursors.remove(i); |
| 2533 | break; |
| 2534 | } |
| 2535 | } |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | /** |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 2540 | * @deprecated As of {@link android.os.Build.VERSION_CODES#GINGERBREAD} |
| 2541 | * this is a no-op. |
Dianne Hackborn | 4f3867e | 2010-12-14 22:09:51 -0800 | [diff] [blame] | 2542 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | */ |
Dianne Hackborn | d3efa39 | 2010-09-01 17:34:12 -0700 | [diff] [blame] | 2544 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | public void setPersistent(boolean isPersistent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | /** |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 2549 | * Finds a view that was identified by the {@code android:id} XML attribute |
| 2550 | * that was processed in {@link #onCreate}. |
| 2551 | * <p> |
| 2552 | * <strong>Note:</strong> In most cases -- depending on compiler support -- |
| 2553 | * the resulting view is automatically cast to the target class type. If |
| 2554 | * the target class type is unconstrained, an explicit cast may be |
| 2555 | * necessary. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | * |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 2557 | * @param id the ID to search for |
| 2558 | * @return a view with given ID if found, or {@code null} otherwise |
| 2559 | * @see View#findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2560 | */ |
Scott Kennedy | c051955 | 2015-02-11 15:33:10 -0800 | [diff] [blame] | 2561 | @Nullable |
Alan Viverette | db7423c | 2017-03-31 13:13:58 -0400 | [diff] [blame] | 2562 | public <T extends View> T findViewById(@IdRes int id) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2563 | return getWindow().findViewById(id); |
| 2564 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2565 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2566 | /** |
| 2567 | * Retrieve a reference to this activity's ActionBar. |
Adam Powell | 42c0fe8 | 2010-08-10 16:36:56 -0700 | [diff] [blame] | 2568 | * |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2569 | * @return The Activity's ActionBar, or null if it does not have one. |
| 2570 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2571 | @Nullable |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2572 | public ActionBar getActionBar() { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2573 | initWindowDecorActionBar(); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2574 | return mActionBar; |
| 2575 | } |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2576 | |
| 2577 | /** |
| 2578 | * Set a {@link android.widget.Toolbar Toolbar} to act as the {@link ActionBar} for this |
| 2579 | * Activity window. |
| 2580 | * |
| 2581 | * <p>When set to a non-null value the {@link #getActionBar()} method will return |
| 2582 | * an {@link ActionBar} object that can be used to control the given toolbar as if it were |
| 2583 | * a traditional window decor action bar. The toolbar's menu will be populated with the |
| 2584 | * Activity's options menu and the navigation button will be wired through the standard |
| 2585 | * {@link android.R.id#home home} menu select action.</p> |
| 2586 | * |
| 2587 | * <p>In order to use a Toolbar within the Activity's window content the application |
| 2588 | * must not request the window feature {@link Window#FEATURE_ACTION_BAR FEATURE_ACTION_BAR}.</p> |
| 2589 | * |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 2590 | * @param toolbar Toolbar to set as the Activity's action bar, or {@code null} to clear it |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2591 | */ |
Adam Powell | 3778014 | 2014-06-01 13:31:00 -0700 | [diff] [blame] | 2592 | public void setActionBar(@Nullable Toolbar toolbar) { |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2593 | final ActionBar ab = getActionBar(); |
| 2594 | if (ab instanceof WindowDecorActionBar) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2595 | throw new IllegalStateException("This Activity already has an action bar supplied " + |
| 2596 | "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " + |
| 2597 | "android:windowActionBar to false in your theme to use a Toolbar instead."); |
| 2598 | } |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2599 | |
| 2600 | // If we reach here then we're setting a new action bar |
| 2601 | // First clear out the MenuInflater to make sure that it is valid for the new Action Bar |
Chris Banes | 601bb99 | 2015-06-22 10:05:38 +0100 | [diff] [blame] | 2602 | mMenuInflater = null; |
| 2603 | |
Chris Banes | 21b2577 | 2016-01-04 20:41:59 +0000 | [diff] [blame] | 2604 | // If we have an action bar currently, destroy it |
| 2605 | if (ab != null) { |
| 2606 | ab.onDestroy(); |
| 2607 | } |
| 2608 | |
Chris Banes | c7d6c32 | 2016-01-27 14:09:16 +0000 | [diff] [blame] | 2609 | if (toolbar != null) { |
| 2610 | final ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this); |
| 2611 | mActionBar = tbab; |
| 2612 | mWindow.setCallback(tbab.getWrappedWindowCallback()); |
| 2613 | } else { |
| 2614 | mActionBar = null; |
| 2615 | // Re-set the original window callback since we may have already set a Toolbar wrapper |
| 2616 | mWindow.setCallback(this); |
| 2617 | } |
| 2618 | |
| 2619 | invalidateOptionsMenu(); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2620 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2623 | * Creates a new ActionBar, locates the inflated ActionBarView, |
| 2624 | * initializes the ActionBar with the view, and sets mActionBar. |
| 2625 | */ |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2626 | private void initWindowDecorActionBar() { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 2627 | Window window = getWindow(); |
Adam Powell | a593d98 | 2011-05-13 14:09:54 -0700 | [diff] [blame] | 2628 | |
| 2629 | // Initializing the window decor can change window feature flags. |
| 2630 | // Make sure that we have the correct set before performing the test below. |
| 2631 | window.getDecorView(); |
| 2632 | |
Adam Powell | 9b4c804 | 2010-08-10 15:36:44 -0700 | [diff] [blame] | 2633 | if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) || mActionBar != null) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2634 | return; |
| 2635 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2636 | |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2637 | mActionBar = new WindowDecorActionBar(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 2638 | mActionBar.setDefaultDisplayHomeAsUpEnabled(mEnableDefaultActionBarUp); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2639 | |
| 2640 | mWindow.setDefaultIcon(mActivityInfo.getIconResource()); |
| 2641 | mWindow.setDefaultLogo(mActivityInfo.getLogoResource()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2642 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2643 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2644 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | * Set the activity content from a layout resource. The resource will be |
| 2646 | * inflated, adding all top-level views to the activity. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2647 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | * @param layoutResID Resource ID to be inflated. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2649 | * |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2650 | * @see #setContentView(android.view.View) |
| 2651 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2653 | public void setContentView(@LayoutRes int layoutResID) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | getWindow().setContentView(layoutResID); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2655 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | /** |
| 2659 | * Set the activity content to an explicit view. This view is placed |
| 2660 | * directly into the activity's view hierarchy. It can itself be a complex |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2661 | * view hierarchy. When calling this method, the layout parameters of the |
| 2662 | * specified view are ignored. Both the width and the height of the view are |
| 2663 | * set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use |
| 2664 | * your own layout parameters, invoke |
| 2665 | * {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)} |
| 2666 | * instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2667 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | * @param view The desired content to display. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2669 | * |
| 2670 | * @see #setContentView(int) |
| 2671 | * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | */ |
| 2673 | public void setContentView(View view) { |
| 2674 | getWindow().setContentView(view); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2675 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /** |
| 2679 | * Set the activity content to an explicit view. This view is placed |
| 2680 | * directly into the activity's view hierarchy. It can itself be a complex |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2681 | * view hierarchy. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2682 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | * @param view The desired content to display. |
| 2684 | * @param params Layout parameters for the view. |
Romain Guy | 482b34a6 | 2011-01-20 10:59:28 -0800 | [diff] [blame] | 2685 | * |
| 2686 | * @see #setContentView(android.view.View) |
| 2687 | * @see #setContentView(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | */ |
| 2689 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 2690 | getWindow().setContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2691 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | /** |
| 2695 | * Add an additional content view to the activity. Added after any existing |
| 2696 | * ones in the activity -- existing views are NOT removed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2697 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2698 | * @param view The desired content to display. |
| 2699 | * @param params Layout parameters for the view. |
| 2700 | */ |
| 2701 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 2702 | getWindow().addContentView(view, params); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 2703 | initWindowDecorActionBar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | /** |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2707 | * Retrieve the {@link TransitionManager} responsible for default transitions in this window. |
| 2708 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2709 | * |
| 2710 | * <p>This method will return non-null after content has been initialized (e.g. by using |
| 2711 | * {@link #setContentView}) if {@link Window#FEATURE_CONTENT_TRANSITIONS} has been granted.</p> |
| 2712 | * |
| 2713 | * @return This window's content TransitionManager or null if none is set. |
| 2714 | */ |
| 2715 | public TransitionManager getContentTransitionManager() { |
| 2716 | return getWindow().getTransitionManager(); |
| 2717 | } |
| 2718 | |
| 2719 | /** |
| 2720 | * Set the {@link TransitionManager} to use for default transitions in this window. |
| 2721 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2722 | * |
| 2723 | * @param tm The TransitionManager to use for scene changes. |
| 2724 | */ |
| 2725 | public void setContentTransitionManager(TransitionManager tm) { |
| 2726 | getWindow().setTransitionManager(tm); |
| 2727 | } |
| 2728 | |
| 2729 | /** |
| 2730 | * Retrieve the {@link Scene} representing this window's current content. |
| 2731 | * Requires {@link Window#FEATURE_CONTENT_TRANSITIONS}. |
| 2732 | * |
| 2733 | * <p>This method will return null if the current content is not represented by a Scene.</p> |
| 2734 | * |
| 2735 | * @return Current Scene being shown or null |
| 2736 | */ |
| 2737 | public Scene getContentScene() { |
| 2738 | return getWindow().getContentScene(); |
| 2739 | } |
| 2740 | |
| 2741 | /** |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2742 | * Sets whether this activity is finished when touched outside its window's |
| 2743 | * bounds. |
| 2744 | */ |
| 2745 | public void setFinishOnTouchOutside(boolean finish) { |
| 2746 | mWindow.setCloseOnTouchOutside(finish); |
| 2747 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2748 | |
| 2749 | /** @hide */ |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2750 | @IntDef(prefix = { "DEFAULT_KEYS_" }, value = { |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2751 | DEFAULT_KEYS_DISABLE, |
| 2752 | DEFAULT_KEYS_DIALER, |
| 2753 | DEFAULT_KEYS_SHORTCUT, |
| 2754 | DEFAULT_KEYS_SEARCH_LOCAL, |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2755 | DEFAULT_KEYS_SEARCH_GLOBAL |
| 2756 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2757 | @Retention(RetentionPolicy.SOURCE) |
| 2758 | @interface DefaultKeyMode {} |
| 2759 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2760 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | * Use with {@link #setDefaultKeyMode} to turn off default handling of |
| 2762 | * keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2763 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | * @see #setDefaultKeyMode |
| 2765 | */ |
| 2766 | static public final int DEFAULT_KEYS_DISABLE = 0; |
| 2767 | /** |
| 2768 | * Use with {@link #setDefaultKeyMode} to launch the dialer during default |
| 2769 | * key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2770 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2771 | * @see #setDefaultKeyMode |
| 2772 | */ |
| 2773 | static public final int DEFAULT_KEYS_DIALER = 1; |
| 2774 | /** |
| 2775 | * Use with {@link #setDefaultKeyMode} to execute a menu shortcut in |
| 2776 | * default key handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2777 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2778 | * <p>That is, the user does not need to hold down the menu key to execute menu shortcuts. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2779 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2780 | * @see #setDefaultKeyMode |
| 2781 | */ |
| 2782 | static public final int DEFAULT_KEYS_SHORTCUT = 2; |
| 2783 | /** |
| 2784 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 2785 | * will start an application-defined search. (If the application or activity does not |
| 2786 | * actually define a search, the the keys will be ignored.) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2787 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2788 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2789 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | * @see #setDefaultKeyMode |
| 2791 | */ |
| 2792 | static public final int DEFAULT_KEYS_SEARCH_LOCAL = 3; |
| 2793 | |
| 2794 | /** |
| 2795 | * Use with {@link #setDefaultKeyMode} to specify that unhandled keystrokes |
| 2796 | * will start a global search (typically web search, but some platforms may define alternate |
| 2797 | * methods for global search) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2798 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | * <p>See {@link android.app.SearchManager android.app.SearchManager} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2800 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | * @see #setDefaultKeyMode |
| 2802 | */ |
| 2803 | static public final int DEFAULT_KEYS_SEARCH_GLOBAL = 4; |
| 2804 | |
| 2805 | /** |
| 2806 | * Select the default key handling for this activity. This controls what |
| 2807 | * will happen to key events that are not otherwise handled. The default |
| 2808 | * mode ({@link #DEFAULT_KEYS_DISABLE}) will simply drop them on the |
| 2809 | * floor. Other modes allow you to launch the dialer |
| 2810 | * ({@link #DEFAULT_KEYS_DIALER}), execute a shortcut in your options |
| 2811 | * menu without requiring the menu key be held down |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2812 | * ({@link #DEFAULT_KEYS_SHORTCUT}), or launch a search ({@link #DEFAULT_KEYS_SEARCH_LOCAL} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | * and {@link #DEFAULT_KEYS_SEARCH_GLOBAL}). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2814 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | * <p>Note that the mode selected here does not impact the default |
| 2816 | * handling of system keys, such as the "back" and "menu" keys, and your |
| 2817 | * activity and its views always get a first chance to receive and handle |
| 2818 | * all application keys. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2819 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2820 | * @param mode The desired default key mode constant. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2821 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2822 | * @see #onKeyDown |
| 2823 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2824 | public final void setDefaultKeyMode(@DefaultKeyMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2825 | mDefaultKeyMode = mode; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | // Some modes use a SpannableStringBuilder to track & dispatch input events |
| 2828 | // This list must remain in sync with the switch in onKeyDown() |
| 2829 | switch (mode) { |
| 2830 | case DEFAULT_KEYS_DISABLE: |
| 2831 | case DEFAULT_KEYS_SHORTCUT: |
| 2832 | mDefaultKeySsb = null; // not used in these modes |
| 2833 | break; |
| 2834 | case DEFAULT_KEYS_DIALER: |
| 2835 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 2836 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 2837 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 2838 | Selection.setSelection(mDefaultKeySsb,0); |
| 2839 | break; |
| 2840 | default: |
| 2841 | throw new IllegalArgumentException(); |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | /** |
| 2846 | * Called when a key was pressed down and not handled by any of the views |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2847 | * inside of the activity. So, for example, key presses while the cursor |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 2849 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2850 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | * <p>If the focused view didn't want this event, this method is called. |
| 2852 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2853 | * <p>The default implementation takes care of {@link KeyEvent#KEYCODE_BACK} |
| 2854 | * by calling {@link #onBackPressed()}, though the behavior varies based |
| 2855 | * on the application compatibility mode: for |
| 2856 | * {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications, |
| 2857 | * it will set up the dispatch to call {@link #onKeyUp} where the action |
| 2858 | * will be performed; for earlier applications, it will perform the |
| 2859 | * action immediately in on-down, as those versions of the platform |
| 2860 | * behaved. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2861 | * |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2862 | * <p>Other additional default key handling may be performed |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2863 | * if configured with {@link #setDefaultKeyMode}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2864 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2866 | * further, or <code>false</code> to indicate that you have not handled |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | * this event and it should continue to be propagated. |
| 2868 | * @see #onKeyUp |
| 2869 | * @see android.view.KeyEvent |
| 2870 | */ |
| 2871 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2872 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2873 | if (getApplicationInfo().targetSdkVersion |
| 2874 | >= Build.VERSION_CODES.ECLAIR) { |
| 2875 | event.startTracking(); |
| 2876 | } else { |
| 2877 | onBackPressed(); |
| 2878 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | return true; |
| 2880 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2882 | if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) { |
| 2883 | return false; |
| 2884 | } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 2885 | Window w = getWindow(); |
| 2886 | if (w.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 2887 | w.performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, keyCode, event, |
| 2888 | Menu.FLAG_ALWAYS_PERFORM_CLOSE)) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2889 | return true; |
| 2890 | } |
| 2891 | return false; |
Evan Rosky | c4620378 | 2017-02-17 13:11:53 -0800 | [diff] [blame] | 2892 | } else if (keyCode == KeyEvent.KEYCODE_TAB) { |
| 2893 | // Don't consume TAB here since it's used for navigation. Arrow keys |
| 2894 | // aren't considered "typing keys" so they already won't get consumed. |
| 2895 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | } else { |
| 2897 | // Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_* |
| 2898 | boolean clearSpannable = false; |
| 2899 | boolean handled; |
| 2900 | if ((event.getRepeatCount() != 0) || event.isSystem()) { |
| 2901 | clearSpannable = true; |
| 2902 | handled = false; |
| 2903 | } else { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2904 | handled = TextKeyListener.getInstance().onKeyDown( |
| 2905 | null, mDefaultKeySsb, keyCode, event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | if (handled && mDefaultKeySsb.length() > 0) { |
| 2907 | // something useable has been typed - dispatch it now. |
| 2908 | |
| 2909 | final String str = mDefaultKeySsb.toString(); |
| 2910 | clearSpannable = true; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | switch (mDefaultKeyMode) { |
| 2913 | case DEFAULT_KEYS_DIALER: |
| 2914 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + str)); |
| 2915 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2916 | startActivity(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | break; |
| 2918 | case DEFAULT_KEYS_SEARCH_LOCAL: |
| 2919 | startSearch(str, false, null, false); |
| 2920 | break; |
| 2921 | case DEFAULT_KEYS_SEARCH_GLOBAL: |
| 2922 | startSearch(str, false, null, true); |
| 2923 | break; |
| 2924 | } |
| 2925 | } |
| 2926 | } |
| 2927 | if (clearSpannable) { |
| 2928 | mDefaultKeySsb.clear(); |
| 2929 | mDefaultKeySsb.clearSpans(); |
| 2930 | Selection.setSelection(mDefaultKeySsb,0); |
| 2931 | } |
| 2932 | return handled; |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2937 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 2938 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 2939 | * the event). |
| 2940 | */ |
| 2941 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 2942 | return false; |
| 2943 | } |
| 2944 | |
| 2945 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | * Called when a key was released and not handled by any of the views |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2947 | * inside of the activity. So, for example, key presses while the cursor |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2948 | * is inside a TextView will not trigger the event (unless it is a navigation |
| 2949 | * to another object) because TextView handles its own key presses. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2950 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2951 | * <p>The default implementation handles KEYCODE_BACK to stop the activity |
| 2952 | * and go back. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2953 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | * @return Return <code>true</code> to prevent this event from being propagated |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2955 | * further, or <code>false</code> to indicate that you have not handled |
| 2956 | * this event and it should continue to be propagated. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | * @see #onKeyDown |
| 2958 | * @see KeyEvent |
| 2959 | */ |
| 2960 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2961 | if (getApplicationInfo().targetSdkVersion |
| 2962 | >= Build.VERSION_CODES.ECLAIR) { |
| 2963 | if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() |
| 2964 | && !event.isCanceled()) { |
| 2965 | onBackPressed(); |
| 2966 | return true; |
| 2967 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2968 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | return false; |
| 2970 | } |
| 2971 | |
| 2972 | /** |
| 2973 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 2974 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 2975 | * the event). |
| 2976 | */ |
| 2977 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 2978 | return false; |
| 2979 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2982 | * Called when the activity has detected the user's press of the back |
| 2983 | * key. The default implementation simply finishes the current activity, |
| 2984 | * but you can override this to do whatever you want. |
| 2985 | */ |
| 2986 | public void onBackPressed() { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 2987 | if (mActionBar != null && mActionBar.collapseActionView()) { |
| 2988 | return; |
| 2989 | } |
| 2990 | |
George Mount | 27b0dc0 | 2017-02-21 10:24:09 -0800 | [diff] [blame] | 2991 | FragmentManager fragmentManager = mFragments.getFragmentManager(); |
| 2992 | |
| 2993 | if (fragmentManager.isStateSaved() || !fragmentManager.popBackStackImmediate()) { |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 2994 | finishAfterTransition(); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 2995 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2996 | } |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 2997 | |
| 2998 | /** |
| 2999 | * Called when a key shortcut event is not handled by any of the views in the Activity. |
| 3000 | * Override this method to implement global key shortcuts for the Activity. |
| 3001 | * Key shortcuts can also be implemented by setting the |
| 3002 | * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. |
| 3003 | * |
| 3004 | * @param keyCode The value in event.getKeyCode(). |
| 3005 | * @param event Description of the key event. |
| 3006 | * @return True if the key shortcut was handled. |
| 3007 | */ |
| 3008 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
Abodunrinwa Toki | a04b7ad | 2015-06-30 17:44:04 -0700 | [diff] [blame] | 3009 | // Let the Action Bar have a chance at handling the shortcut. |
| 3010 | ActionBar actionBar = getActionBar(); |
| 3011 | return (actionBar != null && actionBar.onKeyShortcut(keyCode, event)); |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3012 | } |
| 3013 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3014 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | * Called when a touch screen event was not handled by any of the views |
| 3016 | * under it. This is most useful to process touch events that happen |
| 3017 | * outside of your window bounds, where there is no view to receive it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3018 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3019 | * @param event The touch screen event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3020 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3021 | * @return Return true if you have consumed the event, false if you haven't. |
| 3022 | * The default implementation always returns false. |
| 3023 | */ |
| 3024 | public boolean onTouchEvent(MotionEvent event) { |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 3025 | if (mWindow.shouldCloseOnTouch(this, event)) { |
| 3026 | finish(); |
| 3027 | return true; |
| 3028 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | return false; |
| 3031 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | /** |
| 3034 | * Called when the trackball was moved and not handled by any of the |
| 3035 | * views inside of the activity. So, for example, if the trackball moves |
| 3036 | * while focus is on a button, you will receive a call here because |
| 3037 | * buttons do not normally do anything with trackball events. The call |
| 3038 | * here happens <em>before</em> trackball movements are converted to |
| 3039 | * DPAD key events, which then get sent back to the view hierarchy, and |
| 3040 | * will be processed at the point for things like focus navigation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3041 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | * @param event The trackball event being processed. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3043 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3044 | * @return Return true if you have consumed the event, false if you haven't. |
| 3045 | * The default implementation always returns false. |
| 3046 | */ |
| 3047 | public boolean onTrackballEvent(MotionEvent event) { |
| 3048 | return false; |
| 3049 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3050 | |
| 3051 | /** |
| 3052 | * Called when a generic motion event was not handled by any of the |
| 3053 | * views inside of the activity. |
| 3054 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3055 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 3056 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3057 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 3058 | * the class of input that was received. Implementations of this method |
| 3059 | * must examine the bits in the source before processing the event. |
| 3060 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3061 | * </p><p> |
| 3062 | * Generic motion events with source class |
| 3063 | * {@link android.view.InputDevice#SOURCE_CLASS_POINTER} |
| 3064 | * are delivered to the view under the pointer. All other generic motion events are |
| 3065 | * delivered to the focused view. |
| 3066 | * </p><p> |
| 3067 | * See {@link View#onGenericMotionEvent(MotionEvent)} for an example of how to |
| 3068 | * handle this event. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3069 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3070 | * |
| 3071 | * @param event The generic motion event being processed. |
| 3072 | * |
| 3073 | * @return Return true if you have consumed the event, false if you haven't. |
| 3074 | * The default implementation always returns false. |
| 3075 | */ |
| 3076 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 3077 | return false; |
| 3078 | } |
| 3079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | /** |
| 3081 | * Called whenever a key, touch, or trackball event is dispatched to the |
| 3082 | * activity. Implement this method if you wish to know that the user has |
| 3083 | * interacted with the device in some way while your activity is running. |
| 3084 | * This callback and {@link #onUserLeaveHint} are intended to help |
| 3085 | * activities manage status bar notifications intelligently; specifically, |
| 3086 | * for helping activities determine the proper time to cancel a notfication. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3087 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3088 | * <p>All calls to your activity's {@link #onUserLeaveHint} callback will |
| 3089 | * be accompanied by calls to {@link #onUserInteraction}. This |
| 3090 | * ensures that your activity will be told of relevant user activity such |
| 3091 | * as pulling down the notification pane and touching an item there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3092 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3093 | * <p>Note that this callback will be invoked for the touch down action |
| 3094 | * that begins a touch gesture, but may not be invoked for the touch-moved |
| 3095 | * and touch-up actions that follow. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3096 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | * @see #onUserLeaveHint() |
| 3098 | */ |
| 3099 | public void onUserInteraction() { |
| 3100 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3102 | public void onWindowAttributesChanged(WindowManager.LayoutParams params) { |
| 3103 | // Update window manager if: we have a view, that view is |
| 3104 | // attached to its parent (which will be a RootView), and |
| 3105 | // this activity is not embedded. |
| 3106 | if (mParent == null) { |
| 3107 | View decor = mDecor; |
| 3108 | if (decor != null && decor.getParent() != null) { |
| 3109 | getWindowManager().updateViewLayout(decor, params); |
| 3110 | } |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | public void onContentChanged() { |
| 3115 | } |
| 3116 | |
| 3117 | /** |
| 3118 | * Called when the current {@link Window} of the activity gains or loses |
| 3119 | * focus. This is the best indicator of whether this activity is visible |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3120 | * to the user. The default implementation clears the key tracking |
| 3121 | * state, so should always be called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3122 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3123 | * <p>Note that this provides information about global focus state, which |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3124 | * is managed independently of activity lifecycles. As such, while focus |
| 3125 | * changes will generally have some relation to lifecycle changes (an |
| 3126 | * activity that is stopped will not generally get window focus), you |
| 3127 | * should not rely on any particular order between the callbacks here and |
| 3128 | * those in the other lifecycle methods such as {@link #onResume}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3129 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | * <p>As a general rule, however, a resumed activity will have window |
| 3131 | * focus... unless it has displayed other dialogs or popups that take |
| 3132 | * input focus, in which case the activity itself will not have focus |
| 3133 | * when the other windows have it. Likewise, the system may display |
| 3134 | * system-level windows (such as the status bar notification panel or |
| 3135 | * a system alert) which will temporarily take window input focus without |
| 3136 | * pausing the foreground activity. |
| 3137 | * |
| 3138 | * @param hasFocus Whether the window of this activity has focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3139 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | * @see #hasWindowFocus() |
| 3141 | * @see #onResume |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3142 | * @see View#onWindowFocusChanged(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | */ |
| 3144 | public void onWindowFocusChanged(boolean hasFocus) { |
| 3145 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | /** |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3148 | * Called when the main window associated with the activity has been |
| 3149 | * attached to the window manager. |
| 3150 | * See {@link View#onAttachedToWindow() View.onAttachedToWindow()} |
| 3151 | * for more information. |
| 3152 | * @see View#onAttachedToWindow |
| 3153 | */ |
| 3154 | public void onAttachedToWindow() { |
| 3155 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3156 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3157 | /** |
| 3158 | * Called when the main window associated with the activity has been |
| 3159 | * detached from the window manager. |
| 3160 | * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()} |
| 3161 | * for more information. |
| 3162 | * @see View#onDetachedFromWindow |
| 3163 | */ |
| 3164 | public void onDetachedFromWindow() { |
| 3165 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3166 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 3167 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3168 | * Returns true if this activity's <em>main</em> window currently has window focus. |
| 3169 | * Note that this is not the same as the view itself having focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3170 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | * @return True if this activity's main window currently has window focus. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3172 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3173 | * @see #onWindowAttributesChanged(android.view.WindowManager.LayoutParams) |
| 3174 | */ |
| 3175 | public boolean hasWindowFocus() { |
| 3176 | Window w = getWindow(); |
| 3177 | if (w != null) { |
| 3178 | View d = w.getDecorView(); |
| 3179 | if (d != null) { |
| 3180 | return d.hasWindowFocus(); |
| 3181 | } |
| 3182 | } |
| 3183 | return false; |
| 3184 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3185 | |
| 3186 | /** |
| 3187 | * Called when the main window associated with the activity has been dismissed. |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3188 | * @hide |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3189 | */ |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 3190 | @Override |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3191 | public void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition) { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3192 | finish(finishTask ? FINISH_TASK_WITH_ACTIVITY : DONT_FINISH_TASK_WITH_ACTIVITY); |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3193 | if (suppressWindowTransition) { |
| 3194 | overridePendingTransition(0, 0); |
| 3195 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3196 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3197 | |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3198 | |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 3199 | /** |
Filip Gruszczynski | 411c06f | 2016-01-07 09:44:44 -0800 | [diff] [blame] | 3200 | * Moves the activity from |
| 3201 | * {@link android.app.ActivityManager.StackId#FREEFORM_WORKSPACE_STACK_ID} to |
| 3202 | * {@link android.app.ActivityManager.StackId#FULLSCREEN_WORKSPACE_STACK_ID} stack. |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3203 | * |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3204 | * @hide |
| 3205 | */ |
| 3206 | @Override |
Filip Gruszczynski | 411c06f | 2016-01-07 09:44:44 -0800 | [diff] [blame] | 3207 | public void exitFreeformMode() throws RemoteException { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3208 | ActivityManager.getService().exitFreeformMode(mToken); |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | /** Returns the current stack Id for the window. |
| 3212 | * @hide |
| 3213 | */ |
| 3214 | @Override |
| 3215 | public int getWindowStackId() throws RemoteException { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3216 | return ActivityManager.getService().getActivityStackId(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | /** |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3220 | * Puts the activity in picture-in-picture mode if the activity supports. |
| 3221 | * @see android.R.attr#supportsPictureInPicture |
| 3222 | * @hide |
| 3223 | */ |
| 3224 | @Override |
| 3225 | public void enterPictureInPictureModeIfPossible() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 3226 | if (mActivityInfo.supportsPictureInPicture()) { |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 3227 | enterPictureInPictureMode(); |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3232 | * Called to process key events. You can override this to intercept all |
| 3233 | * key events before they are dispatched to the window. Be sure to call |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | * this implementation for key events that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3235 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | * @param event The key event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3237 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | * @return boolean Return true if this event was consumed. |
| 3239 | */ |
| 3240 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 3241 | onUserInteraction(); |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3242 | |
| 3243 | // Let action bars open menus in response to the menu key prioritized over |
| 3244 | // the window handling it |
George Mount | 5beb2617 | 2015-12-15 13:36:01 -0800 | [diff] [blame] | 3245 | final int keyCode = event.getKeyCode(); |
| 3246 | if (keyCode == KeyEvent.KEYCODE_MENU && |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3247 | mActionBar != null && mActionBar.onMenuKeyEvent(event)) { |
| 3248 | return true; |
| 3249 | } |
| 3250 | |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3251 | Window win = getWindow(); |
| 3252 | if (win.superDispatchKeyEvent(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | return true; |
| 3254 | } |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 3255 | View decor = mDecor; |
| 3256 | if (decor == null) decor = win.getDecorView(); |
| 3257 | return event.dispatch(this, decor != null |
| 3258 | ? decor.getKeyDispatcherState() : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 3262 | * Called to process a key shortcut event. |
| 3263 | * You can override this to intercept all key shortcut events before they are |
| 3264 | * dispatched to the window. Be sure to call this implementation for key shortcut |
| 3265 | * events that should be handled normally. |
| 3266 | * |
| 3267 | * @param event The key shortcut event. |
| 3268 | * @return True if this event was consumed. |
| 3269 | */ |
| 3270 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 3271 | onUserInteraction(); |
| 3272 | if (getWindow().superDispatchKeyShortcutEvent(event)) { |
| 3273 | return true; |
| 3274 | } |
| 3275 | return onKeyShortcut(event.getKeyCode(), event); |
| 3276 | } |
| 3277 | |
| 3278 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | * Called to process touch screen events. You can override this to |
| 3280 | * intercept all touch screen events before they are dispatched to the |
| 3281 | * window. Be sure to call this implementation for touch screen events |
| 3282 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3283 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | * @param ev The touch screen event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3285 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | * @return boolean Return true if this event was consumed. |
| 3287 | */ |
| 3288 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 3289 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 3290 | onUserInteraction(); |
| 3291 | } |
| 3292 | if (getWindow().superDispatchTouchEvent(ev)) { |
| 3293 | return true; |
| 3294 | } |
| 3295 | return onTouchEvent(ev); |
| 3296 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | /** |
| 3299 | * Called to process trackball events. You can override this to |
| 3300 | * intercept all trackball events before they are dispatched to the |
| 3301 | * window. Be sure to call this implementation for trackball events |
| 3302 | * that should be handled normally. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3303 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | * @param ev The trackball event. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3305 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | * @return boolean Return true if this event was consumed. |
| 3307 | */ |
| 3308 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 3309 | onUserInteraction(); |
| 3310 | if (getWindow().superDispatchTrackballEvent(ev)) { |
| 3311 | return true; |
| 3312 | } |
| 3313 | return onTrackballEvent(ev); |
| 3314 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3315 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 3316 | /** |
| 3317 | * Called to process generic motion events. You can override this to |
| 3318 | * intercept all generic motion events before they are dispatched to the |
| 3319 | * window. Be sure to call this implementation for generic motion events |
| 3320 | * that should be handled normally. |
| 3321 | * |
| 3322 | * @param ev The generic motion event. |
| 3323 | * |
| 3324 | * @return boolean Return true if this event was consumed. |
| 3325 | */ |
| 3326 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 3327 | onUserInteraction(); |
| 3328 | if (getWindow().superDispatchGenericMotionEvent(ev)) { |
| 3329 | return true; |
| 3330 | } |
| 3331 | return onGenericMotionEvent(ev); |
| 3332 | } |
| 3333 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3334 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 3335 | event.setClassName(getClass().getName()); |
| 3336 | event.setPackageName(getPackageName()); |
| 3337 | |
| 3338 | LayoutParams params = getWindow().getAttributes(); |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 3339 | boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) && |
| 3340 | (params.height == LayoutParams.MATCH_PARENT); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3341 | event.setFullScreen(isFullScreen); |
| 3342 | |
| 3343 | CharSequence title = getTitle(); |
| 3344 | if (!TextUtils.isEmpty(title)) { |
| 3345 | event.getText().add(title); |
| 3346 | } |
| 3347 | |
| 3348 | return true; |
| 3349 | } |
| 3350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3351 | /** |
| 3352 | * Default implementation of |
| 3353 | * {@link android.view.Window.Callback#onCreatePanelView} |
| 3354 | * for activities. This |
| 3355 | * simply returns null so that all panel sub-windows will have the default |
| 3356 | * menu behavior. |
| 3357 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3358 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | public View onCreatePanelView(int featureId) { |
| 3360 | return null; |
| 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * Default implementation of |
| 3365 | * {@link android.view.Window.Callback#onCreatePanelMenu} |
| 3366 | * for activities. This calls through to the new |
| 3367 | * {@link #onCreateOptionsMenu} method for the |
| 3368 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 3369 | * so that subclasses of Activity don't need to deal with feature codes. |
| 3370 | */ |
| 3371 | public boolean onCreatePanelMenu(int featureId, Menu menu) { |
| 3372 | if (featureId == Window.FEATURE_OPTIONS_PANEL) { |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3373 | boolean show = onCreateOptionsMenu(menu); |
| 3374 | show |= mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater()); |
| 3375 | return show; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | } |
| 3377 | return false; |
| 3378 | } |
| 3379 | |
| 3380 | /** |
| 3381 | * Default implementation of |
| 3382 | * {@link android.view.Window.Callback#onPreparePanel} |
| 3383 | * for activities. This |
| 3384 | * calls through to the new {@link #onPrepareOptionsMenu} method for the |
| 3385 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 3386 | * panel, so that subclasses of |
| 3387 | * Activity don't need to deal with feature codes. |
| 3388 | */ |
| 3389 | public boolean onPreparePanel(int featureId, View view, Menu menu) { |
| 3390 | if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) { |
| 3391 | boolean goforit = onPrepareOptionsMenu(menu); |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3392 | goforit |= mFragments.dispatchPrepareOptionsMenu(menu); |
Adam Powell | ef31e7c | 2012-05-08 09:59:40 -0700 | [diff] [blame] | 3393 | return goforit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | } |
| 3395 | return true; |
| 3396 | } |
| 3397 | |
| 3398 | /** |
| 3399 | * {@inheritDoc} |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3400 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | * @return The default implementation returns true. |
| 3402 | */ |
| 3403 | public boolean onMenuOpened(int featureId, Menu menu) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3404 | if (featureId == Window.FEATURE_ACTION_BAR) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3405 | initWindowDecorActionBar(); |
Adam Powell | 049dd3d | 2010-12-02 13:43:59 -0800 | [diff] [blame] | 3406 | if (mActionBar != null) { |
| 3407 | mActionBar.dispatchMenuVisibilityChanged(true); |
| 3408 | } else { |
| 3409 | Log.e(TAG, "Tried to open action bar menu with no action bar"); |
| 3410 | } |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3411 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | return true; |
| 3413 | } |
| 3414 | |
| 3415 | /** |
| 3416 | * Default implementation of |
| 3417 | * {@link android.view.Window.Callback#onMenuItemSelected} |
| 3418 | * for activities. This calls through to the new |
| 3419 | * {@link #onOptionsItemSelected} method for the |
| 3420 | * {@link android.view.Window#FEATURE_OPTIONS_PANEL} |
| 3421 | * panel, so that subclasses of |
| 3422 | * Activity don't need to deal with feature codes. |
| 3423 | */ |
| 3424 | public boolean onMenuItemSelected(int featureId, MenuItem item) { |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 3425 | CharSequence titleCondensed = item.getTitleCondensed(); |
| 3426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3427 | switch (featureId) { |
| 3428 | case Window.FEATURE_OPTIONS_PANEL: |
| 3429 | // Put event logging here so it gets called even if subclass |
| 3430 | // doesn't call through to superclass's implmeentation of each |
| 3431 | // of these methods below |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 3432 | if(titleCondensed != null) { |
| 3433 | EventLog.writeEvent(50000, 0, titleCondensed.toString()); |
| 3434 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3435 | if (onOptionsItemSelected(item)) { |
| 3436 | return true; |
| 3437 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3438 | if (mFragments.dispatchOptionsItemSelected(item)) { |
| 3439 | return true; |
| 3440 | } |
| 3441 | if (item.getItemId() == android.R.id.home && mActionBar != null && |
| 3442 | (mActionBar.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
| 3443 | if (mParent == null) { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 3444 | return onNavigateUp(); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3445 | } else { |
Adam Powell | 07304f529 | 2012-05-07 17:32:44 -0700 | [diff] [blame] | 3446 | return mParent.onNavigateUpFromChild(this); |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3447 | } |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 3448 | } |
| 3449 | return false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | case Window.FEATURE_CONTEXT_MENU: |
zobject | 686a805 | 2012-12-14 21:11:08 +0900 | [diff] [blame] | 3452 | if(titleCondensed != null) { |
| 3453 | EventLog.writeEvent(50000, 1, titleCondensed.toString()); |
| 3454 | } |
Dianne Hackborn | 5ddd127 | 2010-06-12 10:15:28 -0700 | [diff] [blame] | 3455 | if (onContextItemSelected(item)) { |
| 3456 | return true; |
| 3457 | } |
| 3458 | return mFragments.dispatchContextItemSelected(item); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | default: |
| 3461 | return false; |
| 3462 | } |
| 3463 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3465 | /** |
| 3466 | * Default implementation of |
| 3467 | * {@link android.view.Window.Callback#onPanelClosed(int, Menu)} for |
| 3468 | * activities. This calls through to {@link #onOptionsMenuClosed(Menu)} |
| 3469 | * method for the {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel, |
| 3470 | * so that subclasses of Activity don't need to deal with feature codes. |
| 3471 | * For context menus ({@link Window#FEATURE_CONTEXT_MENU}), the |
| 3472 | * {@link #onContextMenuClosed(Menu)} will be called. |
| 3473 | */ |
| 3474 | public void onPanelClosed(int featureId, Menu menu) { |
| 3475 | switch (featureId) { |
| 3476 | case Window.FEATURE_OPTIONS_PANEL: |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3477 | mFragments.dispatchOptionsMenuClosed(menu); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | onOptionsMenuClosed(menu); |
| 3479 | break; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3481 | case Window.FEATURE_CONTEXT_MENU: |
| 3482 | onContextMenuClosed(menu); |
| 3483 | break; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3484 | |
| 3485 | case Window.FEATURE_ACTION_BAR: |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 3486 | initWindowDecorActionBar(); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 3487 | mActionBar.dispatchMenuVisibilityChanged(false); |
| 3488 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | /** |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3493 | * Declare that the options menu has changed, so should be recreated. |
| 3494 | * The {@link #onCreateOptionsMenu(Menu)} method will be called the next |
| 3495 | * time it needs to be displayed. |
| 3496 | */ |
| 3497 | public void invalidateOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3498 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3499 | (mActionBar == null || !mActionBar.invalidateOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3500 | mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL); |
| 3501 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3502 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3503 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3504 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | * Initialize the contents of the Activity's standard options menu. You |
| 3506 | * should place your menu items in to <var>menu</var>. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3507 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | * <p>This is only called once, the first time the options menu is |
| 3509 | * displayed. To update the menu every time it is displayed, see |
| 3510 | * {@link #onPrepareOptionsMenu}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3511 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3512 | * <p>The default implementation populates the menu with standard system |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3513 | * menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that |
| 3514 | * they will be correctly ordered with application-defined menu items. |
| 3515 | * Deriving classes should always call through to the base implementation. |
| 3516 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | * <p>You can safely hold on to <var>menu</var> (and any items created |
| 3518 | * from it), making modifications to it as desired, until the next |
| 3519 | * time onCreateOptionsMenu() is called. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3520 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | * <p>When you add items to the menu, you can implement the Activity's |
| 3522 | * {@link #onOptionsItemSelected} method to handle them there. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3523 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3524 | * @param menu The options menu in which you place your items. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3525 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | * @return You must return true for the menu to be displayed; |
| 3527 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3528 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | * @see #onPrepareOptionsMenu |
| 3530 | * @see #onOptionsItemSelected |
| 3531 | */ |
| 3532 | public boolean onCreateOptionsMenu(Menu menu) { |
| 3533 | if (mParent != null) { |
| 3534 | return mParent.onCreateOptionsMenu(menu); |
| 3535 | } |
| 3536 | return true; |
| 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * Prepare the Screen's standard options menu to be displayed. This is |
| 3541 | * called right before the menu is shown, every time it is shown. You can |
| 3542 | * use this method to efficiently enable/disable items or otherwise |
| 3543 | * dynamically modify the contents. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3544 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | * <p>The default implementation updates the system menu items based on the |
| 3546 | * activity's state. Deriving classes should always call through to the |
| 3547 | * base class implementation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3548 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | * @param menu The options menu as last shown or first initialized by |
| 3550 | * onCreateOptionsMenu(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3551 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3552 | * @return You must return true for the menu to be displayed; |
| 3553 | * if you return false it will not be shown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3554 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3555 | * @see #onCreateOptionsMenu |
| 3556 | */ |
| 3557 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 3558 | if (mParent != null) { |
| 3559 | return mParent.onPrepareOptionsMenu(menu); |
| 3560 | } |
| 3561 | return true; |
| 3562 | } |
| 3563 | |
| 3564 | /** |
| 3565 | * This hook is called whenever an item in your options menu is selected. |
| 3566 | * The default implementation simply returns false to have the normal |
| 3567 | * processing happen (calling the item's Runnable or sending a message to |
| 3568 | * its Handler as appropriate). You can use this method for any items |
| 3569 | * for which you would like to do processing without those other |
| 3570 | * facilities. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3571 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | * <p>Derived classes should call through to the base class for it to |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3573 | * perform the default menu handling.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3574 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3575 | * @param item The menu item that was selected. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3576 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | * @return boolean Return false to allow normal menu processing to |
| 3578 | * proceed, true to consume it here. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3579 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3580 | * @see #onCreateOptionsMenu |
| 3581 | */ |
| 3582 | public boolean onOptionsItemSelected(MenuItem item) { |
| 3583 | if (mParent != null) { |
| 3584 | return mParent.onOptionsItemSelected(item); |
| 3585 | } |
| 3586 | return false; |
| 3587 | } |
| 3588 | |
| 3589 | /** |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3590 | * This method is called whenever the user chooses to navigate Up within your application's |
| 3591 | * activity hierarchy from the action bar. |
| 3592 | * |
| 3593 | * <p>If the attribute {@link android.R.attr#parentActivityName parentActivityName} |
| 3594 | * was specified in the manifest for this activity or an activity-alias to it, |
| 3595 | * default Up navigation will be handled automatically. If any activity |
| 3596 | * along the parent chain requires extra Intent arguments, the Activity subclass |
| 3597 | * should override the method {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)} |
| 3598 | * to supply those arguments.</p> |
| 3599 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 3600 | * <p>See <a href="{@docRoot}guide/components/tasks-and-back-stack.html">Tasks and Back Stack</a> |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3601 | * from the developer guide and <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> |
| 3602 | * from the design guide for more information about navigating within your app.</p> |
| 3603 | * |
| 3604 | * <p>See the {@link TaskStackBuilder} class and the Activity methods |
| 3605 | * {@link #getParentActivityIntent()}, {@link #shouldUpRecreateTask(Intent)}, and |
| 3606 | * {@link #navigateUpTo(Intent)} for help implementing custom Up navigation. |
| 3607 | * The AppNavigation sample application in the Android SDK is also available for reference.</p> |
| 3608 | * |
| 3609 | * @return true if Up navigation completed successfully and this Activity was finished, |
| 3610 | * false otherwise. |
| 3611 | */ |
| 3612 | public boolean onNavigateUp() { |
| 3613 | // Automatically handle hierarchical Up navigation if the proper |
| 3614 | // metadata is available. |
| 3615 | Intent upIntent = getParentActivityIntent(); |
| 3616 | if (upIntent != null) { |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 3617 | if (mActivityInfo.taskAffinity == null) { |
| 3618 | // Activities with a null affinity are special; they really shouldn't |
| 3619 | // specify a parent activity intent in the first place. Just finish |
| 3620 | // the current activity and call it a day. |
| 3621 | finish(); |
| 3622 | } else if (shouldUpRecreateTask(upIntent)) { |
Adam Powell | f78a844 | 2012-05-01 18:09:32 -0700 | [diff] [blame] | 3623 | TaskStackBuilder b = TaskStackBuilder.create(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3624 | onCreateNavigateUpTaskStack(b); |
| 3625 | onPrepareNavigateUpTaskStack(b); |
| 3626 | b.startActivities(); |
Adam Powell | 3d193d9 | 2012-05-15 16:51:55 -0700 | [diff] [blame] | 3627 | |
| 3628 | // We can't finishAffinity if we have a result. |
| 3629 | // Fall back and simply finish the current activity instead. |
| 3630 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 3631 | // Tell the developer what's going on to avoid hair-pulling. |
| 3632 | Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result"); |
| 3633 | finish(); |
| 3634 | } else { |
| 3635 | finishAffinity(); |
| 3636 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3637 | } else { |
| 3638 | navigateUpTo(upIntent); |
| 3639 | } |
| 3640 | return true; |
| 3641 | } |
| 3642 | return false; |
| 3643 | } |
| 3644 | |
| 3645 | /** |
| 3646 | * This is called when a child activity of this one attempts to navigate up. |
| 3647 | * The default implementation simply calls onNavigateUp() on this activity (the parent). |
| 3648 | * |
| 3649 | * @param child The activity making the call. |
| 3650 | */ |
| 3651 | public boolean onNavigateUpFromChild(Activity child) { |
| 3652 | return onNavigateUp(); |
| 3653 | } |
| 3654 | |
| 3655 | /** |
| 3656 | * Define the synthetic task stack that will be generated during Up navigation from |
| 3657 | * a different task. |
| 3658 | * |
| 3659 | * <p>The default implementation of this method adds the parent chain of this activity |
| 3660 | * as specified in the manifest to the supplied {@link TaskStackBuilder}. Applications |
| 3661 | * may choose to override this method to construct the desired task stack in a different |
| 3662 | * way.</p> |
| 3663 | * |
Adam Powell | f019595 | 2012-05-02 21:38:54 -0700 | [diff] [blame] | 3664 | * <p>This method will be invoked by the default implementation of {@link #onNavigateUp()} |
| 3665 | * if {@link #shouldUpRecreateTask(Intent)} returns true when supplied with the intent |
| 3666 | * returned by {@link #getParentActivityIntent()}.</p> |
| 3667 | * |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3668 | * <p>Applications that wish to supply extra Intent parameters to the parent stack defined |
| 3669 | * by the manifest should override {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)}.</p> |
| 3670 | * |
| 3671 | * @param builder An empty TaskStackBuilder - the application should add intents representing |
| 3672 | * the desired task stack |
| 3673 | */ |
| 3674 | public void onCreateNavigateUpTaskStack(TaskStackBuilder builder) { |
| 3675 | builder.addParentStack(this); |
| 3676 | } |
| 3677 | |
| 3678 | /** |
| 3679 | * Prepare the synthetic task stack that will be generated during Up navigation |
| 3680 | * from a different task. |
| 3681 | * |
| 3682 | * <p>This method receives the {@link TaskStackBuilder} with the constructed series of |
| 3683 | * Intents as generated by {@link #onCreateNavigateUpTaskStack(TaskStackBuilder)}. |
| 3684 | * If any extra data should be added to these intents before launching the new task, |
| 3685 | * the application should override this method and add that data here.</p> |
| 3686 | * |
| 3687 | * @param builder A TaskStackBuilder that has been populated with Intents by |
| 3688 | * onCreateNavigateUpTaskStack. |
| 3689 | */ |
| 3690 | public void onPrepareNavigateUpTaskStack(TaskStackBuilder builder) { |
| 3691 | } |
| 3692 | |
| 3693 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | * This hook is called whenever the options menu is being closed (either by the user canceling |
| 3695 | * the menu with the back/menu button, or when an item is selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3696 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | * @param menu The options menu as last shown or first initialized by |
| 3698 | * onCreateOptionsMenu(). |
| 3699 | */ |
| 3700 | public void onOptionsMenuClosed(Menu menu) { |
| 3701 | if (mParent != null) { |
| 3702 | mParent.onOptionsMenuClosed(menu); |
| 3703 | } |
| 3704 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | /** |
| 3707 | * Programmatically opens the options menu. If the options menu is already |
| 3708 | * open, this method does nothing. |
| 3709 | */ |
| 3710 | public void openOptionsMenu() { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3711 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3712 | (mActionBar == null || !mActionBar.openOptionsMenu())) { |
Adam Powell | 07a7454 | 2014-05-30 15:52:44 -0700 | [diff] [blame] | 3713 | mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null); |
| 3714 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | /** |
| 3718 | * Progammatically closes the options menu. If the options menu is already |
| 3719 | * closed, this method does nothing. |
| 3720 | */ |
| 3721 | public void closeOptionsMenu() { |
Evan Rosky | 41823d1 | 2017-03-21 14:42:35 -0700 | [diff] [blame] | 3722 | if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) && |
| 3723 | (mActionBar == null || !mActionBar.closeOptionsMenu())) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 3724 | mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL); |
| 3725 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * Called when a context menu for the {@code view} is about to be shown. |
| 3730 | * Unlike {@link #onCreateOptionsMenu(Menu)}, this will be called every |
| 3731 | * time the context menu is about to be shown and should be populated for |
| 3732 | * the view (or item inside the view for {@link AdapterView} subclasses, |
| 3733 | * this can be found in the {@code menuInfo})). |
| 3734 | * <p> |
| 3735 | * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an |
| 3736 | * item has been selected. |
| 3737 | * <p> |
| 3738 | * It is not safe to hold onto the context menu after this method returns. |
Scott Main | cdf5106 | 2013-01-08 20:03:05 -0800 | [diff] [blame] | 3739 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | */ |
| 3741 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| 3742 | } |
| 3743 | |
| 3744 | /** |
| 3745 | * Registers a context menu to be shown for the given view (multiple views |
| 3746 | * can show the context menu). This method will set the |
| 3747 | * {@link OnCreateContextMenuListener} on the view to this activity, so |
| 3748 | * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be |
| 3749 | * called when it is time to show the context menu. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3750 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | * @see #unregisterForContextMenu(View) |
| 3752 | * @param view The view that should show a context menu. |
| 3753 | */ |
| 3754 | public void registerForContextMenu(View view) { |
| 3755 | view.setOnCreateContextMenuListener(this); |
| 3756 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | /** |
| 3759 | * Prevents a context menu to be shown for the given view. This method will remove the |
| 3760 | * {@link OnCreateContextMenuListener} on the view. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3761 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | * @see #registerForContextMenu(View) |
| 3763 | * @param view The view that should stop showing a context menu. |
| 3764 | */ |
| 3765 | public void unregisterForContextMenu(View view) { |
| 3766 | view.setOnCreateContextMenuListener(null); |
| 3767 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3769 | /** |
| 3770 | * Programmatically opens the context menu for a particular {@code view}. |
| 3771 | * The {@code view} should have been added via |
| 3772 | * {@link #registerForContextMenu(View)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3773 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | * @param view The view to show the context menu for. |
| 3775 | */ |
| 3776 | public void openContextMenu(View view) { |
| 3777 | view.showContextMenu(); |
| 3778 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | /** |
| 3781 | * Programmatically closes the most recently opened context menu, if showing. |
| 3782 | */ |
| 3783 | public void closeContextMenu() { |
Jose Lima | bd769a1 | 2015-01-28 10:43:15 -0800 | [diff] [blame] | 3784 | if (mWindow.hasFeature(Window.FEATURE_CONTEXT_MENU)) { |
| 3785 | mWindow.closePanel(Window.FEATURE_CONTEXT_MENU); |
| 3786 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3789 | /** |
| 3790 | * This hook is called whenever an item in a context menu is selected. The |
| 3791 | * default implementation simply returns false to have the normal processing |
| 3792 | * happen (calling the item's Runnable or sending a message to its Handler |
| 3793 | * as appropriate). You can use this method for any items for which you |
| 3794 | * would like to do processing without those other facilities. |
| 3795 | * <p> |
| 3796 | * Use {@link MenuItem#getMenuInfo()} to get extra information set by the |
| 3797 | * View that added this menu item. |
| 3798 | * <p> |
| 3799 | * Derived classes should call through to the base class for it to perform |
| 3800 | * the default menu handling. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3801 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | * @param item The context menu item that was selected. |
| 3803 | * @return boolean Return false to allow normal context menu processing to |
| 3804 | * proceed, true to consume it here. |
| 3805 | */ |
| 3806 | public boolean onContextItemSelected(MenuItem item) { |
| 3807 | if (mParent != null) { |
| 3808 | return mParent.onContextItemSelected(item); |
| 3809 | } |
| 3810 | return false; |
| 3811 | } |
| 3812 | |
| 3813 | /** |
| 3814 | * This hook is called whenever the context menu is being closed (either by |
| 3815 | * the user canceling the menu with the back/menu button, or when an item is |
| 3816 | * selected). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3817 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | * @param menu The context menu that is being closed. |
| 3819 | */ |
| 3820 | public void onContextMenuClosed(Menu menu) { |
| 3821 | if (mParent != null) { |
| 3822 | mParent.onContextMenuClosed(menu); |
| 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3827 | * @deprecated Old no-arguments version of {@link #onCreateDialog(int, Bundle)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3829 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | protected Dialog onCreateDialog(int id) { |
| 3831 | return null; |
| 3832 | } |
| 3833 | |
| 3834 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3835 | * Callback for creating dialogs that are managed (saved and restored) for you |
| 3836 | * by the activity. The default implementation calls through to |
| 3837 | * {@link #onCreateDialog(int)} for compatibility. |
| 3838 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3839 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3840 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 3841 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3842 | * <p>If you use {@link #showDialog(int)}, the activity will call through to |
| 3843 | * this method the first time, and hang onto it thereafter. Any dialog |
| 3844 | * that is created by this method will automatically be saved and restored |
| 3845 | * for you, including whether it is showing. |
| 3846 | * |
| 3847 | * <p>If you would like the activity to manage saving and restoring dialogs |
| 3848 | * for you, you should override this method and handle any ids that are |
| 3849 | * passed to {@link #showDialog}. |
| 3850 | * |
| 3851 | * <p>If you would like an opportunity to prepare your dialog before it is shown, |
| 3852 | * override {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 3853 | * |
| 3854 | * @param id The id of the dialog. |
| 3855 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 3856 | * @return The dialog. If you return null, the dialog will not be created. |
| 3857 | * |
| 3858 | * @see #onPrepareDialog(int, Dialog, Bundle) |
| 3859 | * @see #showDialog(int, Bundle) |
| 3860 | * @see #dismissDialog(int) |
| 3861 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3862 | * |
| 3863 | * @deprecated Use the new {@link DialogFragment} class with |
| 3864 | * {@link FragmentManager} instead; this is also |
| 3865 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3866 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3867 | @Nullable |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3868 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3869 | protected Dialog onCreateDialog(int id, Bundle args) { |
| 3870 | return onCreateDialog(id); |
| 3871 | } |
| 3872 | |
| 3873 | /** |
| 3874 | * @deprecated Old no-arguments version of |
| 3875 | * {@link #onPrepareDialog(int, Dialog, Bundle)}. |
| 3876 | */ |
| 3877 | @Deprecated |
| 3878 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 3879 | dialog.setOwnerActivity(this); |
| 3880 | } |
| 3881 | |
| 3882 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | * Provides an opportunity to prepare a managed dialog before it is being |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3884 | * shown. The default implementation calls through to |
| 3885 | * {@link #onPrepareDialog(int, Dialog)} for compatibility. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3886 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | * <p> |
| 3888 | * Override this if you need to update a managed dialog based on the state |
| 3889 | * of the application each time it is shown. For example, a time picker |
| 3890 | * dialog might want to be updated with the current time. You should call |
| 3891 | * through to the superclass's implementation. The default implementation |
| 3892 | * will set this Activity as the owner activity on the Dialog. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3893 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | * @param id The id of the managed dialog. |
| 3895 | * @param dialog The dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3896 | * @param args The dialog arguments provided to {@link #showDialog(int, Bundle)}. |
| 3897 | * @see #onCreateDialog(int, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3898 | * @see #showDialog(int) |
| 3899 | * @see #dismissDialog(int) |
| 3900 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3901 | * |
| 3902 | * @deprecated Use the new {@link DialogFragment} class with |
| 3903 | * {@link FragmentManager} instead; this is also |
| 3904 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3906 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3907 | protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { |
| 3908 | onPrepareDialog(id, dialog); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3912 | * Simple version of {@link #showDialog(int, Bundle)} that does not |
| 3913 | * take any arguments. Simply calls {@link #showDialog(int, Bundle)} |
| 3914 | * with null arguments. |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3915 | * |
| 3916 | * @deprecated Use the new {@link DialogFragment} class with |
| 3917 | * {@link FragmentManager} instead; this is also |
| 3918 | * available on older platforms through the Android compatibility package. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3919 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3920 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3921 | public final void showDialog(int id) { |
| 3922 | showDialog(id, null); |
| 3923 | } |
| 3924 | |
| 3925 | /** |
| 3926 | * Show a dialog managed by this activity. A call to {@link #onCreateDialog(int, Bundle)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | * will be made with the same id the first time this is called for a given |
| 3928 | * id. From thereafter, the dialog will be automatically saved and restored. |
| 3929 | * |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 3930 | * <em>If you are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 3931 | * or later, consider instead using a {@link DialogFragment} instead.</em> |
| 3932 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3933 | * <p>Each time a dialog is shown, {@link #onPrepareDialog(int, Dialog, Bundle)} will |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3934 | * be made to provide an opportunity to do any timely preparation. |
| 3935 | * |
| 3936 | * @param id The id of the managed dialog. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3937 | * @param args Arguments to pass through to the dialog. These will be saved |
| 3938 | * and restored for you. Note that if the dialog is already created, |
| 3939 | * {@link #onCreateDialog(int, Bundle)} will not be called with the new |
| 3940 | * arguments but {@link #onPrepareDialog(int, Dialog, Bundle)} will be. |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 3941 | * If you need to rebuild the dialog, call {@link #removeDialog(int)} first. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3942 | * @return Returns true if the Dialog was created; false is returned if |
| 3943 | * it is not created because {@link #onCreateDialog(int, Bundle)} returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3944 | * |
Joe Onorato | 37296dc | 2009-07-31 17:58:55 -0700 | [diff] [blame] | 3945 | * @see Dialog |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3946 | * @see #onCreateDialog(int, Bundle) |
| 3947 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | * @see #dismissDialog(int) |
| 3949 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3950 | * |
| 3951 | * @deprecated Use the new {@link DialogFragment} class with |
| 3952 | * {@link FragmentManager} instead; this is also |
| 3953 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3955 | @Deprecated |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3956 | public final boolean showDialog(int id, Bundle args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | if (mManagedDialogs == null) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3958 | mManagedDialogs = new SparseArray<ManagedDialog>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3960 | ManagedDialog md = mManagedDialogs.get(id); |
| 3961 | if (md == null) { |
| 3962 | md = new ManagedDialog(); |
| 3963 | md.mDialog = createDialog(id, null, args); |
| 3964 | if (md.mDialog == null) { |
| 3965 | return false; |
| 3966 | } |
| 3967 | mManagedDialogs.put(id, md); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3968 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3969 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3970 | md.mArgs = args; |
| 3971 | onPrepareDialog(id, md.mDialog, args); |
| 3972 | md.mDialog.show(); |
| 3973 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | /** |
| 3977 | * Dismiss a dialog that was previously shown via {@link #showDialog(int)}. |
| 3978 | * |
| 3979 | * @param id The id of the managed dialog. |
| 3980 | * |
| 3981 | * @throws IllegalArgumentException if the id was not previously shown via |
| 3982 | * {@link #showDialog(int)}. |
| 3983 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3984 | * @see #onCreateDialog(int, Bundle) |
| 3985 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3986 | * @see #showDialog(int) |
| 3987 | * @see #removeDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 3988 | * |
| 3989 | * @deprecated Use the new {@link DialogFragment} class with |
| 3990 | * {@link FragmentManager} instead; this is also |
| 3991 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 3993 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | public final void dismissDialog(int id) { |
| 3995 | if (mManagedDialogs == null) { |
| 3996 | throw missingDialog(id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3998 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3999 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4000 | if (md == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | throw missingDialog(id); |
| 4002 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4003 | md.mDialog.dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * Creates an exception to throw if a user passed in a dialog id that is |
| 4008 | * unexpected. |
| 4009 | */ |
| 4010 | private IllegalArgumentException missingDialog(int id) { |
| 4011 | return new IllegalArgumentException("no dialog with id " + id + " was ever " |
| 4012 | + "shown via Activity#showDialog"); |
| 4013 | } |
| 4014 | |
| 4015 | /** |
| 4016 | * Removes any internal references to a dialog managed by this Activity. |
| 4017 | * If the dialog is showing, it will dismiss it as part of the clean up. |
| 4018 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4019 | * <p>This can be useful if you know that you will never show a dialog again and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | * want to avoid the overhead of saving and restoring it in the future. |
| 4021 | * |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4022 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, this function |
| 4023 | * will not throw an exception if you try to remove an ID that does not |
| 4024 | * currently have an associated dialog.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4025 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4026 | * @param id The id of the managed dialog. |
| 4027 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4028 | * @see #onCreateDialog(int, Bundle) |
| 4029 | * @see #onPrepareDialog(int, Dialog, Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | * @see #showDialog(int) |
| 4031 | * @see #dismissDialog(int) |
Dianne Hackborn | 271c2fe | 2011-08-09 19:35:13 -0700 | [diff] [blame] | 4032 | * |
| 4033 | * @deprecated Use the new {@link DialogFragment} class with |
| 4034 | * {@link FragmentManager} instead; this is also |
| 4035 | * available on older platforms through the Android compatibility package. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4036 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 4037 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4038 | public final void removeDialog(int id) { |
Dianne Hackborn | d2ce8bbb | 2010-10-06 16:46:05 -0700 | [diff] [blame] | 4039 | if (mManagedDialogs != null) { |
| 4040 | final ManagedDialog md = mManagedDialogs.get(id); |
| 4041 | if (md != null) { |
| 4042 | md.mDialog.dismiss(); |
| 4043 | mManagedDialogs.remove(id); |
| 4044 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4045 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | /** |
| 4049 | * This hook is called when the user signals the desire to start a search. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4050 | * |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4051 | * <p>You can use this function as a simple way to launch the search UI, in response to a |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4052 | * menu item, search button, or other widgets within your activity. Unless overidden, |
Bjorn Bringert | 6266e40 | 2009-09-25 14:25:41 +0100 | [diff] [blame] | 4053 | * calling this function is the same as calling |
| 4054 | * {@link #startSearch startSearch(null, false, null, false)}, which launches |
| 4055 | * search for the current activity as specified in its manifest, see {@link SearchManager}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4056 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | * <p>You can override this function to force global search, e.g. in response to a dedicated |
| 4058 | * search key, or to block search entirely (by simply returning false). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4059 | * |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4060 | * <p>Note: when running in a {@link Configuration#UI_MODE_TYPE_TELEVISION}, the default |
| 4061 | * implementation changes to simply return false and you must supply your own custom |
| 4062 | * implementation if you want to support search.</p> |
| 4063 | * |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4064 | * @param searchEvent The {@link SearchEvent} that signaled this search. |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4065 | * @return Returns {@code true} if search launched, and {@code false} if the activity does |
| 4066 | * not respond to search. The default implementation always returns {@code true}, except |
| 4067 | * when in {@link Configuration#UI_MODE_TYPE_TELEVISION} mode where it returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4068 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4069 | * @see android.app.SearchManager |
| 4070 | */ |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4071 | public boolean onSearchRequested(@Nullable SearchEvent searchEvent) { |
| 4072 | mSearchEvent = searchEvent; |
| 4073 | boolean result = onSearchRequested(); |
| 4074 | mSearchEvent = null; |
| 4075 | return result; |
| 4076 | } |
| 4077 | |
| 4078 | /** |
| 4079 | * @see #onSearchRequested(SearchEvent) |
| 4080 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4081 | public boolean onSearchRequested() { |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 4082 | if ((getResources().getConfiguration().uiMode&Configuration.UI_MODE_TYPE_MASK) |
| 4083 | != Configuration.UI_MODE_TYPE_TELEVISION) { |
| 4084 | startSearch(null, false, null, false); |
| 4085 | return true; |
| 4086 | } else { |
| 4087 | return false; |
| 4088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4091 | /** |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 4092 | * During the onSearchRequested() callbacks, this function will return the |
| 4093 | * {@link SearchEvent} that triggered the callback, if it exists. |
| 4094 | * |
| 4095 | * @return SearchEvent The SearchEvent that triggered the {@link |
| 4096 | * #onSearchRequested} callback. |
| 4097 | */ |
| 4098 | public final SearchEvent getSearchEvent() { |
| 4099 | return mSearchEvent; |
| 4100 | } |
| 4101 | |
| 4102 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4103 | * This hook is called to launch the search UI. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4104 | * |
| 4105 | * <p>It is typically called from onSearchRequested(), either directly from |
| 4106 | * Activity.onSearchRequested() or from an overridden version in any given |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4107 | * Activity. If your goal is simply to activate search, it is preferred to call |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4108 | * onSearchRequested(), which may have been overridden elsewhere in your Activity. If your goal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | * is to inject specific data such as context data, it is preferred to <i>override</i> |
| 4110 | * onSearchRequested(), so that any callers to it will benefit from the override. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4111 | * |
| 4112 | * @param initialQuery Any non-null non-empty string will be inserted as |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | * pre-entered text in the search query box. |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4114 | * @param selectInitialQuery If true, the initial query will be preselected, which means that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | * any further typing will replace it. This is useful for cases where an entire pre-formed |
| 4116 | * query is being inserted. If false, the selection point will be placed at the end of the |
| 4117 | * inserted query. This is useful when the inserted query is text that the user entered, |
| 4118 | * and the user would expect to be able to keep typing. <i>This parameter is only meaningful |
| 4119 | * if initialQuery is a non-empty string.</i> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4120 | * @param appSearchData An application can insert application-specific |
| 4121 | * context here, in order to improve quality or specificity of its own |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4123 | * no extra data is required. |
| 4124 | * @param globalSearch If false, this will only launch the search that has been specifically |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4125 | * defined by the application (which is usually defined as a local search). If no default |
Mike LeBeau | cfa419b | 2009-08-17 10:56:02 -0700 | [diff] [blame] | 4126 | * search is defined in the current application or activity, global search will be launched. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | * If true, this will always launch a platform-global (e.g. web-based) search instead. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4128 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | * @see android.app.SearchManager |
| 4130 | * @see #onSearchRequested |
| 4131 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4132 | public void startSearch(@Nullable String initialQuery, boolean selectInitialQuery, |
| 4133 | @Nullable Bundle appSearchData, boolean globalSearch) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 4134 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 4135 | mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4136 | appSearchData, globalSearch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | /** |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4140 | * Similar to {@link #startSearch}, but actually fires off the search query after invoking |
| 4141 | * the search dialog. Made available for testing purposes. |
| 4142 | * |
| 4143 | * @param query The query to trigger. If empty, the request will be ignored. |
| 4144 | * @param appSearchData An application can insert application-specific |
| 4145 | * context here, in order to improve quality or specificity of its own |
| 4146 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 4147 | * no extra data is required. |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4148 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4149 | public void triggerSearch(String query, @Nullable Bundle appSearchData) { |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4150 | ensureSearchManager(); |
Bjorn Bringert | b782a2f | 2009-10-01 09:57:33 +0100 | [diff] [blame] | 4151 | mSearchManager.triggerSearch(query, getComponentName(), appSearchData); |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | * Request that key events come to this activity. Use this if your |
| 4156 | * activity has no views with focus, but the activity still wants |
| 4157 | * a chance to process key events. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4158 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | * @see android.view.Window#takeKeyEvents |
| 4160 | */ |
| 4161 | public void takeKeyEvents(boolean get) { |
| 4162 | getWindow().takeKeyEvents(get); |
| 4163 | } |
| 4164 | |
| 4165 | /** |
| 4166 | * Enable extended window features. This is a convenience for calling |
| 4167 | * {@link android.view.Window#requestFeature getWindow().requestFeature()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4168 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | * @param featureId The desired feature as defined in |
| 4170 | * {@link android.view.Window}. |
| 4171 | * @return Returns true if the requested feature is supported and now |
| 4172 | * enabled. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4173 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | * @see android.view.Window#requestFeature |
| 4175 | */ |
| 4176 | public final boolean requestWindowFeature(int featureId) { |
| 4177 | return getWindow().requestFeature(featureId); |
| 4178 | } |
| 4179 | |
| 4180 | /** |
| 4181 | * Convenience for calling |
| 4182 | * {@link android.view.Window#setFeatureDrawableResource}. |
| 4183 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4184 | public final void setFeatureDrawableResource(int featureId, @DrawableRes int resId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | getWindow().setFeatureDrawableResource(featureId, resId); |
| 4186 | } |
| 4187 | |
| 4188 | /** |
| 4189 | * Convenience for calling |
| 4190 | * {@link android.view.Window#setFeatureDrawableUri}. |
| 4191 | */ |
| 4192 | public final void setFeatureDrawableUri(int featureId, Uri uri) { |
| 4193 | getWindow().setFeatureDrawableUri(featureId, uri); |
| 4194 | } |
| 4195 | |
| 4196 | /** |
| 4197 | * Convenience for calling |
| 4198 | * {@link android.view.Window#setFeatureDrawable(int, Drawable)}. |
| 4199 | */ |
| 4200 | public final void setFeatureDrawable(int featureId, Drawable drawable) { |
| 4201 | getWindow().setFeatureDrawable(featureId, drawable); |
| 4202 | } |
| 4203 | |
| 4204 | /** |
| 4205 | * Convenience for calling |
| 4206 | * {@link android.view.Window#setFeatureDrawableAlpha}. |
| 4207 | */ |
| 4208 | public final void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 4209 | getWindow().setFeatureDrawableAlpha(featureId, alpha); |
| 4210 | } |
| 4211 | |
| 4212 | /** |
| 4213 | * Convenience for calling |
| 4214 | * {@link android.view.Window#getLayoutInflater}. |
| 4215 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4216 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4217 | public LayoutInflater getLayoutInflater() { |
| 4218 | return getWindow().getLayoutInflater(); |
| 4219 | } |
| 4220 | |
| 4221 | /** |
| 4222 | * Returns a {@link MenuInflater} with this context. |
| 4223 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4224 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | public MenuInflater getMenuInflater() { |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4226 | // Make sure that action views can get an appropriate theme. |
| 4227 | if (mMenuInflater == null) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 4228 | initWindowDecorActionBar(); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4229 | if (mActionBar != null) { |
Dianne Hackborn | 9275197 | 2012-05-18 19:22:14 -0700 | [diff] [blame] | 4230 | mMenuInflater = new MenuInflater(mActionBar.getThemedContext(), this); |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 4231 | } else { |
| 4232 | mMenuInflater = new MenuInflater(this); |
| 4233 | } |
| 4234 | } |
| 4235 | return mMenuInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4236 | } |
| 4237 | |
| 4238 | @Override |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 4239 | public void setTheme(int resid) { |
| 4240 | super.setTheme(resid); |
| 4241 | mWindow.setTheme(resid); |
| 4242 | } |
| 4243 | |
| 4244 | @Override |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 4245 | protected void onApplyThemeResource(Resources.Theme theme, @StyleRes int resid, |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4246 | boolean first) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | if (mParent == null) { |
| 4248 | super.onApplyThemeResource(theme, resid, first); |
| 4249 | } else { |
| 4250 | try { |
| 4251 | theme.setTo(mParent.getTheme()); |
| 4252 | } catch (Exception e) { |
| 4253 | // Empty |
| 4254 | } |
| 4255 | theme.applyStyle(resid, false); |
| 4256 | } |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4257 | |
| 4258 | // Get the primary color and update the TaskDescription for this activity |
| 4259 | TypedArray a = theme.obtainStyledAttributes( |
| 4260 | com.android.internal.R.styleable.ActivityTaskDescription); |
| 4261 | if (mTaskDescription.getPrimaryColor() == 0) { |
| 4262 | int colorPrimary = a.getColor( |
| 4263 | com.android.internal.R.styleable.ActivityTaskDescription_colorPrimary, 0); |
| 4264 | if (colorPrimary != 0 && Color.alpha(colorPrimary) == 0xFF) { |
| 4265 | mTaskDescription.setPrimaryColor(colorPrimary); |
| 4266 | } |
| 4267 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4268 | |
| 4269 | int colorBackground = a.getColor( |
| 4270 | com.android.internal.R.styleable.ActivityTaskDescription_colorBackground, 0); |
| 4271 | if (colorBackground != 0 && Color.alpha(colorBackground) == 0xFF) { |
| 4272 | mTaskDescription.setBackgroundColor(colorBackground); |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4273 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 4274 | |
| 4275 | final int statusBarColor = a.getColor( |
| 4276 | com.android.internal.R.styleable.ActivityTaskDescription_statusBarColor, 0); |
| 4277 | if (statusBarColor != 0) { |
| 4278 | mTaskDescription.setStatusBarColor(statusBarColor); |
| 4279 | } |
| 4280 | |
| 4281 | final int navigationBarColor = a.getColor( |
| 4282 | com.android.internal.R.styleable.ActivityTaskDescription_navigationBarColor, 0); |
| 4283 | if (navigationBarColor != 0) { |
| 4284 | mTaskDescription.setNavigationBarColor(navigationBarColor); |
| 4285 | } |
| 4286 | |
Winson | 073a526 | 2016-02-29 16:04:40 -0800 | [diff] [blame] | 4287 | a.recycle(); |
| 4288 | setTaskDescription(mTaskDescription); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | /** |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4292 | * Requests permissions to be granted to this application. These permissions |
| 4293 | * must be requested in your manifest, they should not be granted to your app, |
| 4294 | * and they should have protection level {@link android.content.pm.PermissionInfo |
| 4295 | * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by |
| 4296 | * the platform or a third-party app. |
| 4297 | * <p> |
| 4298 | * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} |
| 4299 | * are granted at install time if requested in the manifest. Signature permissions |
| 4300 | * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at |
| 4301 | * install time if requested in the manifest and the signature of your app matches |
| 4302 | * the signature of the app declaring the permissions. |
| 4303 | * </p> |
| 4304 | * <p> |
| 4305 | * If your app does not have the requested permissions the user will be presented |
| 4306 | * with UI for accepting them. After the user has accepted or rejected the |
| 4307 | * requested permissions you will receive a callback on {@link |
| 4308 | * #onRequestPermissionsResult(int, String[], int[])} reporting whether the |
| 4309 | * permissions were granted or not. |
| 4310 | * </p> |
| 4311 | * <p> |
| 4312 | * Note that requesting a permission does not guarantee it will be granted and |
| 4313 | * your app should be able to run without having this permission. |
| 4314 | * </p> |
| 4315 | * <p> |
| 4316 | * This method may start an activity allowing the user to choose which permissions |
| 4317 | * to grant and which to reject. Hence, you should be prepared that your activity |
| 4318 | * may be paused and resumed. Further, granting some permissions may require |
| 4319 | * a restart of you application. In such a case, the system will recreate the |
| 4320 | * activity stack before delivering the result to {@link |
| 4321 | * #onRequestPermissionsResult(int, String[], int[])}. |
| 4322 | * </p> |
| 4323 | * <p> |
| 4324 | * When checking whether you have a permission you should use {@link |
| 4325 | * #checkSelfPermission(String)}. |
| 4326 | * </p> |
| 4327 | * <p> |
Svet Ganov | d7ad54e | 2015-08-21 06:18:09 -0700 | [diff] [blame] | 4328 | * Calling this API for permissions already granted to your app would show UI |
| 4329 | * to the user to decide whether the app can still hold these permissions. This |
| 4330 | * can be useful if the way your app uses data guarded by the permissions |
| 4331 | * changes significantly. |
| 4332 | * </p> |
| 4333 | * <p> |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 4334 | * You cannot request a permission if your activity sets {@link |
| 4335 | * android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 4336 | * <code>true</code> because in this case the activity would not receive |
| 4337 | * result callbacks including {@link #onRequestPermissionsResult(int, String[], int[])}. |
| 4338 | * </p> |
| 4339 | * <p> |
Trevor Johns | 682c24e | 2016-04-12 10:13:47 -0700 | [diff] [blame] | 4340 | * The <a href="http://developer.android.com/samples/RuntimePermissions/index.html"> |
| 4341 | * RuntimePermissions</a> sample app demonstrates how to use this method to |
| 4342 | * request permissions at run time. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4343 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4344 | * |
Svet Ganov | f66381c | 2016-02-18 20:02:36 -0800 | [diff] [blame] | 4345 | * @param permissions The requested permissions. Must me non-null and not empty. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4346 | * @param requestCode Application specific request code to match with a result |
| 4347 | * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. |
Svet Ganov | 255aece | 2015-07-03 16:03:53 -0700 | [diff] [blame] | 4348 | * Should be >= 0. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4349 | * |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 4350 | * @throws IllegalArgumentException if requestCode is negative. |
| 4351 | * |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4352 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 4353 | * @see #checkSelfPermission(String) |
Svetoslav | aa048b6 | 2015-06-02 15:08:48 -0700 | [diff] [blame] | 4354 | * @see #shouldShowRequestPermissionRationale(String) |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4355 | */ |
| 4356 | public final void requestPermissions(@NonNull String[] permissions, int requestCode) { |
Paul Miller | 77a0e13 | 2016-02-11 13:46:49 -0800 | [diff] [blame] | 4357 | if (requestCode < 0) { |
| 4358 | throw new IllegalArgumentException("requestCode should be >= 0"); |
| 4359 | } |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4360 | if (mHasCurrentPermissionsRequest) { |
| 4361 | Log.w(TAG, "Can reqeust only one set of permissions at a time"); |
| 4362 | // Dispatch the callback with empty arrays which means a cancellation. |
| 4363 | onRequestPermissionsResult(requestCode, new String[0], new int[0]); |
| 4364 | return; |
| 4365 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4366 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 4367 | startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null); |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 4368 | mHasCurrentPermissionsRequest = true; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | /** |
| 4372 | * Callback for the result from requesting permissions. This method |
| 4373 | * is invoked for every call on {@link #requestPermissions(String[], int)}. |
Svet Ganov | 0f45c7c | 2015-07-16 16:28:51 -0700 | [diff] [blame] | 4374 | * <p> |
| 4375 | * <strong>Note:</strong> It is possible that the permissions request interaction |
| 4376 | * with the user is interrupted. In this case you will receive empty permissions |
| 4377 | * and results arrays which should be treated as a cancellation. |
| 4378 | * </p> |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4379 | * |
| 4380 | * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. |
| 4381 | * @param permissions The requested permissions. Never null. |
| 4382 | * @param grantResults The grant results for the corresponding permissions |
| 4383 | * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} |
| 4384 | * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. |
| 4385 | * |
| 4386 | * @see #requestPermissions(String[], int) |
| 4387 | */ |
| 4388 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, |
| 4389 | @NonNull int[] grantResults) { |
| 4390 | /* callback - no nothing */ |
| 4391 | } |
| 4392 | |
| 4393 | /** |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 4394 | * Gets whether you should show UI with rationale for requesting a permission. |
| 4395 | * You should do this only if you do not have the permission and the context in |
| 4396 | * which the permission is requested does not clearly communicate to the user |
| 4397 | * what would be the benefit from granting this permission. |
| 4398 | * <p> |
| 4399 | * For example, if you write a camera app, requesting the camera permission |
| 4400 | * would be expected by the user and no rationale for why it is requested is |
| 4401 | * needed. If however, the app needs location for tagging photos then a non-tech |
| 4402 | * savvy user may wonder how location is related to taking photos. In this case |
| 4403 | * you may choose to show UI with rationale of requesting this permission. |
| 4404 | * </p> |
| 4405 | * |
| 4406 | * @param permission A permission your app wants to request. |
| 4407 | * @return Whether you can show permission rationale UI. |
| 4408 | * |
| 4409 | * @see #checkSelfPermission(String) |
| 4410 | * @see #requestPermissions(String[], int) |
| 4411 | * @see #onRequestPermissionsResult(int, String[], int[]) |
| 4412 | */ |
Svetoslav | 9ce9a15 | 2015-06-02 17:59:31 -0700 | [diff] [blame] | 4413 | public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 4414 | return getPackageManager().shouldShowRequestPermissionRationale(permission); |
| 4415 | } |
| 4416 | |
| 4417 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4418 | * Same as calling {@link #startActivityForResult(Intent, int, Bundle)} |
| 4419 | * with no options. |
| 4420 | * |
| 4421 | * @param intent The intent to start. |
| 4422 | * @param requestCode If >= 0, this code will be returned in |
| 4423 | * onActivityResult() when the activity exits. |
| 4424 | * |
| 4425 | * @throws android.content.ActivityNotFoundException |
| 4426 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4427 | * @see #startActivity |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4428 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 4429 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 4430 | startActivityForResult(intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4431 | } |
| 4432 | |
| 4433 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4434 | * Launch an activity for which you would like a result when it finished. |
| 4435 | * When this activity exits, your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4436 | * onActivityResult() method will be called with the given requestCode. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4437 | * Using a negative requestCode is the same as calling |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | * {@link #startActivity} (the activity is not launched as a sub-activity). |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4439 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4440 | * <p>Note that this method should only be used with Intent protocols |
| 4441 | * that are defined to return a result. In other protocols (such as |
| 4442 | * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may |
| 4443 | * not get the result when you expect. For example, if the activity you |
Mark Renouf | cca6d05 | 2016-12-02 14:11:18 -0500 | [diff] [blame] | 4444 | * are launching uses {@link Intent#FLAG_ACTIVITY_NEW_TASK}, it will not |
| 4445 | * run in your task and thus you will immediately receive a cancel result. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4446 | * |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4447 | * <p>As a special case, if you call startActivityForResult() with a requestCode |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4449 | * activity, then your window will not be displayed until a result is |
| 4450 | * returned back from the started activity. This is to avoid visible |
| 4451 | * flickering when redirecting to another activity. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4452 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4453 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4454 | * if there was no Activity found to run the given Intent. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4455 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | * @param intent The intent to start. |
| 4457 | * @param requestCode If >= 0, this code will be returned in |
| 4458 | * onActivityResult() when the activity exits. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4459 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4460 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4461 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4462 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4464 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 4465 | * @see #startActivity |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 4467 | public void startActivityForResult(@RequiresPermission Intent intent, int requestCode, |
| 4468 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | if (mParent == null) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4470 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | Instrumentation.ActivityResult ar = |
| 4472 | mInstrumentation.execStartActivity( |
| 4473 | this, mMainThread.getApplicationThread(), mToken, this, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4474 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | if (ar != null) { |
| 4476 | mMainThread.sendActivityResult( |
| 4477 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), |
| 4478 | ar.getResultData()); |
| 4479 | } |
| 4480 | if (requestCode >= 0) { |
| 4481 | // If this start is requesting a result, we can avoid making |
| 4482 | // the activity visible until the result is received. Setting |
| 4483 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4484 | // activity hidden during this time, to avoid flickering. |
| 4485 | // This can only be done when a result is requested because |
| 4486 | // that guarantees we will get information back when the |
| 4487 | // activity is finished, no matter what happens to it. |
| 4488 | mStartedActivity = true; |
| 4489 | } |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 4490 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4491 | cancelInputsAndStartExitTransition(options); |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 4492 | // TODO Consider clearing/flushing other event sources and events for child windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4494 | if (options != null) { |
| 4495 | mParent.startActivityFromChild(this, intent, requestCode, options); |
| 4496 | } else { |
| 4497 | // Note we want to go through this method for compatibility with |
| 4498 | // existing applications that may have overridden it. |
| 4499 | mParent.startActivityFromChild(this, intent, requestCode); |
| 4500 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4501 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | /** |
| 4505 | * Cancels pending inputs and if an Activity Transition is to be run, starts the transition. |
| 4506 | * |
| 4507 | * @param options The ActivityOptions bundle used to start an Activity. |
| 4508 | */ |
| 4509 | private void cancelInputsAndStartExitTransition(Bundle options) { |
| 4510 | final View decor = mWindow != null ? mWindow.peekDecorView() : null; |
| 4511 | if (decor != null) { |
| 4512 | decor.cancelPendingInputEvents(); |
| 4513 | } |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 4514 | if (options != null && !isTopOfTask()) { |
| 4515 | mActivityTransitionState.startExitOutTransition(this, options); |
| 4516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | } |
| 4518 | |
Chet Haase | b64e777f | 2016-12-09 07:17:10 -0800 | [diff] [blame] | 4519 | /** |
| 4520 | * Returns whether there are any activity transitions currently running on this |
| 4521 | * activity. A return value of {@code true} can mean that either an enter or |
| 4522 | * exit transition is running, including whether the background of the activity |
| 4523 | * is animating as a part of that transition. |
| 4524 | * |
| 4525 | * @return true if a transition is currently running on this activity, false otherwise. |
| 4526 | */ |
| 4527 | public boolean isActivityTransitionRunning() { |
| 4528 | return mActivityTransitionState.isTransitionRunning(); |
| 4529 | } |
| 4530 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4531 | private Bundle transferSpringboardActivityOptions(Bundle options) { |
| 4532 | if (options == null && (mWindow != null && !mWindow.isActive())) { |
| 4533 | final ActivityOptions activityOptions = getActivityOptions(); |
George Mount | 9638378 | 2016-06-08 15:13:52 -0700 | [diff] [blame] | 4534 | if (activityOptions != null && |
| 4535 | activityOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4536 | return activityOptions.toBundle(); |
| 4537 | } |
| 4538 | } |
| 4539 | return options; |
| 4540 | } |
| 4541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4542 | /** |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4543 | * @hide Implement to provide correct calling token. |
| 4544 | */ |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4545 | public void startActivityForResultAsUser(Intent intent, int requestCode, UserHandle user) { |
| 4546 | startActivityForResultAsUser(intent, requestCode, null, user); |
| 4547 | } |
| 4548 | |
| 4549 | /** |
| 4550 | * @hide Implement to provide correct calling token. |
| 4551 | */ |
| 4552 | public void startActivityForResultAsUser(Intent intent, int requestCode, |
| 4553 | @Nullable Bundle options, UserHandle user) { |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 4554 | startActivityForResultAsUser(intent, mEmbeddedID, requestCode, options, user); |
| 4555 | } |
| 4556 | |
| 4557 | /** |
| 4558 | * @hide Implement to provide correct calling token. |
| 4559 | */ |
| 4560 | public void startActivityForResultAsUser(Intent intent, String resultWho, int requestCode, |
| 4561 | @Nullable Bundle options, UserHandle user) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4562 | if (mParent != null) { |
| 4563 | throw new RuntimeException("Can't be called from a child"); |
| 4564 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4565 | options = transferSpringboardActivityOptions(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4566 | Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 4567 | this, mMainThread.getApplicationThread(), mToken, resultWho, intent, requestCode, |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4568 | options, user); |
| 4569 | if (ar != null) { |
| 4570 | mMainThread.sendActivityResult( |
| 4571 | mToken, mEmbeddedID, requestCode, ar.getResultCode(), ar.getResultData()); |
| 4572 | } |
| 4573 | if (requestCode >= 0) { |
| 4574 | // If this start is requesting a result, we can avoid making |
| 4575 | // the activity visible until the result is received. Setting |
| 4576 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4577 | // activity hidden during this time, to avoid flickering. |
| 4578 | // This can only be done when a result is requested because |
| 4579 | // that guarantees we will get information back when the |
| 4580 | // activity is finished, no matter what happens to it. |
| 4581 | mStartedActivity = true; |
| 4582 | } |
| 4583 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4584 | cancelInputsAndStartExitTransition(options); |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | /** |
| 4588 | * @hide Implement to provide correct calling token. |
| 4589 | */ |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4590 | public void startActivityAsUser(Intent intent, UserHandle user) { |
| 4591 | startActivityAsUser(intent, null, user); |
| 4592 | } |
| 4593 | |
| 4594 | /** |
| 4595 | * @hide Implement to provide correct calling token. |
| 4596 | */ |
| 4597 | public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { |
| 4598 | if (mParent != null) { |
Alexandra Gherghina | 8323145 | 2014-07-04 12:05:20 +0100 | [diff] [blame] | 4599 | throw new RuntimeException("Can't be called from a child"); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4600 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4601 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4602 | Instrumentation.ActivityResult ar = |
| 4603 | mInstrumentation.execStartActivity( |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 4604 | this, mMainThread.getApplicationThread(), mToken, mEmbeddedID, |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4605 | intent, -1, options, user); |
| 4606 | if (ar != null) { |
| 4607 | mMainThread.sendActivityResult( |
| 4608 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 4609 | ar.getResultData()); |
| 4610 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4611 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | /** |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4615 | * Start a new activity as if it was started by the activity that started our |
| 4616 | * current activity. This is for the resolver and chooser activities, which operate |
| 4617 | * as intermediaries that dispatch their intent to the target the user selects -- to |
| 4618 | * do this, they must perform all security checks including permission grants as if |
| 4619 | * their launch had come from the original activity. |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 4620 | * @param intent The Intent to start. |
| 4621 | * @param options ActivityOptions or null. |
| 4622 | * @param ignoreTargetSecurity If true, the activity manager will not check whether the |
| 4623 | * caller it is doing the start is, is actually allowed to start the target activity. |
| 4624 | * If you set this to true, you must set an explicit component in the Intent and do any |
| 4625 | * appropriate security checks yourself. |
| 4626 | * @param userId The user the new activity should run as. |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4627 | * @hide |
| 4628 | */ |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 4629 | public void startActivityAsCaller(Intent intent, @Nullable Bundle options, |
| 4630 | boolean ignoreTargetSecurity, int userId) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4631 | if (mParent != null) { |
| 4632 | throw new RuntimeException("Can't be called from a child"); |
| 4633 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 4634 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4635 | Instrumentation.ActivityResult ar = |
| 4636 | mInstrumentation.execStartActivityAsCaller( |
| 4637 | this, mMainThread.getApplicationThread(), mToken, this, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 4638 | intent, -1, options, ignoreTargetSecurity, userId); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4639 | if (ar != null) { |
| 4640 | mMainThread.sendActivityResult( |
| 4641 | mToken, mEmbeddedID, -1, ar.getResultCode(), |
| 4642 | ar.getResultData()); |
| 4643 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4644 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4648 | * Same as calling {@link #startIntentSenderForResult(IntentSender, int, |
| 4649 | * Intent, int, int, int, Bundle)} with no options. |
| 4650 | * |
| 4651 | * @param intent The IntentSender to launch. |
| 4652 | * @param requestCode If >= 0, this code will be returned in |
| 4653 | * onActivityResult() when the activity exits. |
| 4654 | * @param fillInIntent If non-null, this will be provided as the |
| 4655 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4656 | * @param flagsMask Intent flags in the original IntentSender that you |
| 4657 | * would like to change. |
| 4658 | * @param flagsValues Desired values for any bits set in |
| 4659 | * <var>flagsMask</var> |
| 4660 | * @param extraFlags Always set to 0. |
| 4661 | */ |
| 4662 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4663 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4664 | throws IntentSender.SendIntentException { |
| 4665 | startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, |
| 4666 | flagsValues, extraFlags, null); |
| 4667 | } |
| 4668 | |
| 4669 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4670 | * Like {@link #startActivityForResult(Intent, int)}, but allowing you |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4671 | * to use a IntentSender to describe the activity to be started. If |
| 4672 | * the IntentSender is for an activity, that activity will be started |
| 4673 | * as if you had called the regular {@link #startActivityForResult(Intent, int)} |
| 4674 | * here; otherwise, its associated action will be executed (such as |
| 4675 | * sending a broadcast) as if you had called |
| 4676 | * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4677 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4678 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4679 | * @param requestCode If >= 0, this code will be returned in |
| 4680 | * onActivityResult() when the activity exits. |
| 4681 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4682 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4683 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4684 | * would like to change. |
| 4685 | * @param flagsValues Desired values for any bits set in |
| 4686 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4687 | * @param extraFlags Always set to 0. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4688 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4689 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4690 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 4691 | * have also been supplied by the IntentSender, options given here will |
| 4692 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4693 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4694 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4695 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4696 | Bundle options) throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4697 | if (mParent == null) { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 4698 | startIntentSenderForResultInner(intent, mEmbeddedID, requestCode, fillInIntent, |
| 4699 | flagsMask, flagsValues, options); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4700 | } else if (options != null) { |
| 4701 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 4702 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4703 | } else { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4704 | // Note we want to go through this call for compatibility with |
| 4705 | // existing applications that may have overridden the method. |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4706 | mParent.startIntentSenderFromChild(this, intent, requestCode, |
| 4707 | fillInIntent, flagsMask, flagsValues, extraFlags); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4708 | } |
| 4709 | } |
| 4710 | |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 4711 | private void startIntentSenderForResultInner(IntentSender intent, String who, int requestCode, |
| 4712 | Intent fillInIntent, int flagsMask, int flagsValues, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4713 | Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4714 | throws IntentSender.SendIntentException { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4715 | try { |
| 4716 | String resolvedType = null; |
| 4717 | if (fillInIntent != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 4718 | fillInIntent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 4719 | fillInIntent.prepareToLeaveProcess(this); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4720 | resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); |
| 4721 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4722 | int result = ActivityManager.getService() |
Dianne Hackborn | 3e6e385 | 2017-05-19 16:12:08 -0700 | [diff] [blame] | 4723 | .startActivityIntentSender(mMainThread.getApplicationThread(), |
| 4724 | intent != null ? intent.getTarget() : null, |
| 4725 | intent != null ? intent.getWhitelistToken() : null, |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 4726 | fillInIntent, resolvedType, mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4727 | requestCode, flagsMask, flagsValues, options); |
| 4728 | if (result == ActivityManager.START_CANCELED) { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4729 | throw new IntentSender.SendIntentException(); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4730 | } |
| 4731 | Instrumentation.checkStartActivityResult(result, null); |
| 4732 | } catch (RemoteException e) { |
| 4733 | } |
| 4734 | if (requestCode >= 0) { |
| 4735 | // If this start is requesting a result, we can avoid making |
| 4736 | // the activity visible until the result is received. Setting |
| 4737 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4738 | // activity hidden during this time, to avoid flickering. |
| 4739 | // This can only be done when a result is requested because |
| 4740 | // that guarantees we will get information back when the |
| 4741 | // activity is finished, no matter what happens to it. |
| 4742 | mStartedActivity = true; |
| 4743 | } |
| 4744 | } |
| 4745 | |
| 4746 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4747 | * Same as {@link #startActivity(Intent, Bundle)} with no options |
| 4748 | * specified. |
| 4749 | * |
| 4750 | * @param intent The intent to start. |
| 4751 | * |
| 4752 | * @throws android.content.ActivityNotFoundException |
| 4753 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4754 | * @see #startActivity(Intent, Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4755 | * @see #startActivityForResult |
| 4756 | */ |
| 4757 | @Override |
| 4758 | public void startActivity(Intent intent) { |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 4759 | this.startActivity(intent, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4763 | * Launch a new activity. You will not receive any information about when |
| 4764 | * the activity exits. This implementation overrides the base version, |
| 4765 | * providing information about |
| 4766 | * the activity performing the launch. Because of this additional |
| 4767 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 4768 | * required; if not specified, the new activity will be added to the |
| 4769 | * task of the caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4770 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4771 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4772 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4773 | * |
| 4774 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4775 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4776 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4777 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4778 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | * @throws android.content.ActivityNotFoundException |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4780 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4781 | * @see #startActivity(Intent) |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4782 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | */ |
| 4784 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4785 | public void startActivity(Intent intent, @Nullable Bundle options) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4786 | if (options != null) { |
| 4787 | startActivityForResult(intent, -1, options); |
| 4788 | } else { |
| 4789 | // Note we want to go through this call for compatibility with |
| 4790 | // applications that may have overridden the method. |
| 4791 | startActivityForResult(intent, -1); |
| 4792 | } |
| 4793 | } |
| 4794 | |
| 4795 | /** |
| 4796 | * Same as {@link #startActivities(Intent[], Bundle)} with no options |
| 4797 | * specified. |
| 4798 | * |
| 4799 | * @param intents The intents to start. |
| 4800 | * |
| 4801 | * @throws android.content.ActivityNotFoundException |
| 4802 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4803 | * @see #startActivities(Intent[], Bundle) |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4804 | * @see #startActivityForResult |
| 4805 | */ |
| 4806 | @Override |
| 4807 | public void startActivities(Intent[] intents) { |
| 4808 | startActivities(intents, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4812 | * Launch a new activity. You will not receive any information about when |
| 4813 | * the activity exits. This implementation overrides the base version, |
| 4814 | * providing information about |
| 4815 | * the activity performing the launch. Because of this additional |
| 4816 | * information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag is not |
| 4817 | * required; if not specified, the new activity will be added to the |
| 4818 | * task of the caller. |
| 4819 | * |
| 4820 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 4821 | * if there was no Activity found to run the given Intent. |
| 4822 | * |
| 4823 | * @param intents The intents to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4824 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4825 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4826 | * Context.startActivity(Intent, Bundle)} for more details. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4827 | * |
| 4828 | * @throws android.content.ActivityNotFoundException |
| 4829 | * |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 4830 | * @see #startActivities(Intent[]) |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4831 | * @see #startActivityForResult |
| 4832 | */ |
| 4833 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4834 | public void startActivities(Intent[] intents, @Nullable Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4835 | mInstrumentation.execStartActivities(this, mMainThread.getApplicationThread(), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4836 | mToken, this, intents, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4840 | * Same as calling {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} |
| 4841 | * with no options. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4842 | * |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4843 | * @param intent The IntentSender to launch. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4844 | * @param fillInIntent If non-null, this will be provided as the |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4845 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4846 | * @param flagsMask Intent flags in the original IntentSender that you |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4847 | * would like to change. |
| 4848 | * @param flagsValues Desired values for any bits set in |
| 4849 | * <var>flagsMask</var> |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4850 | * @param extraFlags Always set to 0. |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4851 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4852 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4853 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 4854 | throws IntentSender.SendIntentException { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4855 | startIntentSender(intent, fillInIntent, flagsMask, flagsValues, |
| 4856 | extraFlags, null); |
| 4857 | } |
| 4858 | |
| 4859 | /** |
| 4860 | * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender |
| 4861 | * to start; see |
| 4862 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle)} |
| 4863 | * for more information. |
| 4864 | * |
| 4865 | * @param intent The IntentSender to launch. |
| 4866 | * @param fillInIntent If non-null, this will be provided as the |
| 4867 | * intent parameter to {@link IntentSender#sendIntent}. |
| 4868 | * @param flagsMask Intent flags in the original IntentSender that you |
| 4869 | * would like to change. |
| 4870 | * @param flagsValues Desired values for any bits set in |
| 4871 | * <var>flagsMask</var> |
| 4872 | * @param extraFlags Always set to 0. |
| 4873 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4874 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4875 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 4876 | * have also been supplied by the IntentSender, options given here will |
| 4877 | * override any that conflict with those given by the IntentSender. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4878 | */ |
| 4879 | public void startIntentSender(IntentSender intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4880 | @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4881 | Bundle options) throws IntentSender.SendIntentException { |
| 4882 | if (options != null) { |
| 4883 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 4884 | flagsValues, extraFlags, options); |
| 4885 | } else { |
| 4886 | // Note we want to go through this call for compatibility with |
| 4887 | // applications that may have overridden the method. |
| 4888 | startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, |
| 4889 | flagsValues, extraFlags); |
| 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | /** |
| 4894 | * Same as calling {@link #startActivityIfNeeded(Intent, int, Bundle)} |
| 4895 | * with no options. |
| 4896 | * |
| 4897 | * @param intent The intent to start. |
| 4898 | * @param requestCode If >= 0, this code will be returned in |
| 4899 | * onActivityResult() when the activity exits, as described in |
| 4900 | * {@link #startActivityForResult}. |
| 4901 | * |
| 4902 | * @return If a new activity was launched then true is returned; otherwise |
| 4903 | * false is returned and you must handle the Intent yourself. |
| 4904 | * |
| 4905 | * @see #startActivity |
| 4906 | * @see #startActivityForResult |
| 4907 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 4908 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 4909 | int requestCode) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4910 | return startActivityIfNeeded(intent, requestCode, null); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | * A special variation to launch an activity only if a new activity |
| 4915 | * instance is needed to handle the given Intent. In other words, this is |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4916 | * just like {@link #startActivityForResult(Intent, int)} except: if you are |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4917 | * using the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} flag, or |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4918 | * singleTask or singleTop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | * {@link android.R.styleable#AndroidManifestActivity_launchMode launchMode}, |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4920 | * and the activity |
| 4921 | * that handles <var>intent</var> is the same as your currently running |
| 4922 | * activity, then a new instance is not needed. In this case, instead of |
| 4923 | * the normal behavior of calling {@link #onNewIntent} this function will |
| 4924 | * return and you can handle the Intent yourself. |
| 4925 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4926 | * <p>This function can only be called from a top-level activity; if it is |
| 4927 | * called from a child activity, a runtime exception will be thrown. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4928 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | * @param intent The intent to start. |
| 4930 | * @param requestCode If >= 0, this code will be returned in |
| 4931 | * onActivityResult() when the activity exits, as described in |
| 4932 | * {@link #startActivityForResult}. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4933 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 4934 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 4935 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4936 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4937 | * @return If a new activity was launched then true is returned; otherwise |
| 4938 | * false is returned and you must handle the Intent yourself. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 4939 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4940 | * @see #startActivity |
| 4941 | * @see #startActivityForResult |
| 4942 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 4943 | public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent, |
| 4944 | int requestCode, @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4945 | if (mParent == null) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4946 | int result = ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 4948 | Uri referrer = onProvideReferrer(); |
| 4949 | if (referrer != null) { |
| 4950 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 4951 | } |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 4952 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 4953 | intent.prepareToLeaveProcess(this); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4954 | result = ActivityManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4955 | .startActivity(mMainThread.getApplicationThread(), getBasePackageName(), |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4956 | intent, intent.resolveTypeIfNeeded(getContentResolver()), mToken, |
| 4957 | mEmbeddedID, requestCode, ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 4958 | null, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4959 | } catch (RemoteException e) { |
| 4960 | // Empty |
| 4961 | } |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 4962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4963 | Instrumentation.checkStartActivityResult(result, intent); |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 4964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | if (requestCode >= 0) { |
| 4966 | // If this start is requesting a result, we can avoid making |
| 4967 | // the activity visible until the result is received. Setting |
| 4968 | // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the |
| 4969 | // activity hidden during this time, to avoid flickering. |
| 4970 | // This can only be done when a result is requested because |
| 4971 | // that guarantees we will get information back when the |
| 4972 | // activity is finished, no matter what happens to it. |
| 4973 | mStartedActivity = true; |
| 4974 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4975 | return result != ActivityManager.START_RETURN_INTENT_TO_CALLER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | throw new UnsupportedOperationException( |
| 4979 | "startActivityIfNeeded can only be called from a top-level activity"); |
| 4980 | } |
| 4981 | |
| 4982 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4983 | * Same as calling {@link #startNextMatchingActivity(Intent, Bundle)} with |
| 4984 | * no options. |
| 4985 | * |
| 4986 | * @param intent The intent to dispatch to the next activity. For |
| 4987 | * correct behavior, this must be the same as the Intent that started |
| 4988 | * your own activity; the only changes you can make are to the extras |
| 4989 | * inside of it. |
| 4990 | * |
| 4991 | * @return Returns a boolean indicating whether there was another Activity |
| 4992 | * to start: true if there was a next activity to start, false if there |
| 4993 | * wasn't. In general, if true is returned you will then want to call |
| 4994 | * finish() on yourself. |
| 4995 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 4996 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4997 | return startNextMatchingActivity(intent, null); |
| 4998 | } |
| 4999 | |
| 5000 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5001 | * Special version of starting an activity, for use when you are replacing |
| 5002 | * other activity components. You can use this to hand the Intent off |
| 5003 | * to the next Activity that can handle it. You typically call this in |
| 5004 | * {@link #onCreate} with the Intent returned by {@link #getIntent}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5005 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | * @param intent The intent to dispatch to the next activity. For |
| 5007 | * correct behavior, this must be the same as the Intent that started |
| 5008 | * your own activity; the only changes you can make are to the extras |
| 5009 | * inside of it. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5010 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5011 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5012 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5013 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | * @return Returns a boolean indicating whether there was another Activity |
| 5015 | * to start: true if there was a next activity to start, false if there |
| 5016 | * wasn't. In general, if true is returned you will then want to call |
| 5017 | * finish() on yourself. |
| 5018 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5019 | public boolean startNextMatchingActivity(@RequiresPermission @NonNull Intent intent, |
| 5020 | @Nullable Bundle options) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5021 | if (mParent == null) { |
| 5022 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 5023 | intent.migrateExtraStreamToClipData(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5024 | intent.prepareToLeaveProcess(this); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5025 | return ActivityManager.getService() |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5026 | .startNextMatchingActivity(mToken, intent, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5027 | } catch (RemoteException e) { |
| 5028 | // Empty |
| 5029 | } |
| 5030 | return false; |
| 5031 | } |
| 5032 | |
| 5033 | throw new UnsupportedOperationException( |
| 5034 | "startNextMatchingActivity can only be called from a top-level activity"); |
| 5035 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5036 | |
| 5037 | /** |
| 5038 | * Same as calling {@link #startActivityFromChild(Activity, Intent, int, Bundle)} |
| 5039 | * with no options. |
| 5040 | * |
| 5041 | * @param child The activity making the call. |
| 5042 | * @param intent The intent to start. |
| 5043 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5044 | * |
| 5045 | * @throws android.content.ActivityNotFoundException |
| 5046 | * |
| 5047 | * @see #startActivity |
| 5048 | * @see #startActivityForResult |
| 5049 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5050 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5051 | int requestCode) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 5052 | startActivityFromChild(child, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5053 | } |
| 5054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5055 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5056 | * This is called when a child activity of this one calls its |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5057 | * {@link #startActivity} or {@link #startActivityForResult} method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5058 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5059 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5060 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5061 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5062 | * @param child The activity making the call. |
| 5063 | * @param intent The intent to start. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5064 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5065 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5066 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5067 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5068 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5069 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5070 | * |
| 5071 | * @see #startActivity |
| 5072 | * @see #startActivityForResult |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5073 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5074 | public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5075 | int requestCode, @Nullable Bundle options) { |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5076 | options = transferSpringboardActivityOptions(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5077 | Instrumentation.ActivityResult ar = |
| 5078 | mInstrumentation.execStartActivity( |
| 5079 | this, mMainThread.getApplicationThread(), mToken, child, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5080 | intent, requestCode, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5081 | if (ar != null) { |
| 5082 | mMainThread.sendActivityResult( |
| 5083 | mToken, child.mEmbeddedID, requestCode, |
| 5084 | ar.getResultCode(), ar.getResultData()); |
| 5085 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5086 | cancelInputsAndStartExitTransition(options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5087 | } |
| 5088 | |
| 5089 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5090 | * Same as calling {@link #startActivityFromFragment(Fragment, Intent, int, Bundle)} |
| 5091 | * with no options. |
| 5092 | * |
| 5093 | * @param fragment The fragment making the call. |
| 5094 | * @param intent The intent to start. |
| 5095 | * @param requestCode Reply request code. < 0 if reply is not requested. |
| 5096 | * |
| 5097 | * @throws android.content.ActivityNotFoundException |
| 5098 | * |
| 5099 | * @see Fragment#startActivity |
| 5100 | * @see Fragment#startActivityForResult |
| 5101 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5102 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5103 | @RequiresPermission Intent intent, int requestCode) { |
George Mount | abb63cb | 2014-06-23 11:17:58 -0700 | [diff] [blame] | 5104 | startActivityFromFragment(fragment, intent, requestCode, null); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5108 | * This is called when a Fragment in this activity calls its |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5109 | * {@link Fragment#startActivity} or {@link Fragment#startActivityForResult} |
| 5110 | * method. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5111 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5112 | * <p>This method throws {@link android.content.ActivityNotFoundException} |
| 5113 | * if there was no Activity found to run the given Intent. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5114 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5115 | * @param fragment The fragment making the call. |
| 5116 | * @param intent The intent to start. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5117 | * @param requestCode Reply request code. < 0 if reply is not requested. |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5118 | * @param options Additional options for how the Activity should be started. |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 5119 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5120 | * Context.startActivity(Intent, Bundle)} for more details. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5121 | * |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5122 | * @throws android.content.ActivityNotFoundException |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5123 | * |
| 5124 | * @see Fragment#startActivity |
| 5125 | * @see Fragment#startActivityForResult |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5126 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 5127 | public void startActivityFromFragment(@NonNull Fragment fragment, |
| 5128 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options) { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5129 | startActivityForResult(fragment.mWho, intent, requestCode, options); |
| 5130 | } |
| 5131 | |
| 5132 | /** |
| 5133 | * @hide |
| 5134 | */ |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 5135 | public void startActivityAsUserFromFragment(@NonNull Fragment fragment, |
| 5136 | @RequiresPermission Intent intent, int requestCode, @Nullable Bundle options, |
| 5137 | UserHandle user) { |
| 5138 | startActivityForResultAsUser(intent, fragment.mWho, requestCode, options, user); |
| 5139 | } |
| 5140 | |
| 5141 | /** |
| 5142 | * @hide |
| 5143 | */ |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5144 | @Override |
| 5145 | public void startActivityForResult( |
| 5146 | String who, Intent intent, int requestCode, @Nullable Bundle options) { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5147 | Uri referrer = onProvideReferrer(); |
| 5148 | if (referrer != null) { |
| 5149 | intent.putExtra(Intent.EXTRA_REFERRER, referrer); |
| 5150 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 5151 | options = transferSpringboardActivityOptions(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5152 | Instrumentation.ActivityResult ar = |
| 5153 | mInstrumentation.execStartActivity( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5154 | this, mMainThread.getApplicationThread(), mToken, who, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5155 | intent, requestCode, options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5156 | if (ar != null) { |
| 5157 | mMainThread.sendActivityResult( |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5158 | mToken, who, requestCode, |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5159 | ar.getResultCode(), ar.getResultData()); |
| 5160 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 5161 | cancelInputsAndStartExitTransition(options); |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | /** |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 5165 | * @hide |
| 5166 | */ |
| 5167 | @Override |
| 5168 | public boolean canStartActivityForResult() { |
| 5169 | return true; |
| 5170 | } |
| 5171 | |
| 5172 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5173 | * Same as calling {@link #startIntentSenderFromChild(Activity, IntentSender, |
| 5174 | * int, Intent, int, int, int, Bundle)} with no options. |
| 5175 | */ |
| 5176 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5177 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5178 | int extraFlags) |
| 5179 | throws IntentSender.SendIntentException { |
| 5180 | startIntentSenderFromChild(child, intent, requestCode, fillInIntent, |
| 5181 | flagsMask, flagsValues, extraFlags, null); |
| 5182 | } |
| 5183 | |
| 5184 | /** |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5185 | * Like {@link #startActivityFromChild(Activity, Intent, int)}, but |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5186 | * taking a IntentSender; see |
Dianne Hackborn | ae22c05 | 2009-09-17 18:46:22 -0700 | [diff] [blame] | 5187 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5188 | * for more information. |
| 5189 | */ |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5190 | public void startIntentSenderFromChild(Activity child, IntentSender intent, |
| 5191 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5192 | int extraFlags, @Nullable Bundle options) |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 5193 | throws IntentSender.SendIntentException { |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 5194 | startIntentSenderForResultInner(intent, child.mEmbeddedID, requestCode, fillInIntent, |
| 5195 | flagsMask, flagsValues, options); |
| 5196 | } |
| 5197 | |
| 5198 | /** |
| 5199 | * Like {@link #startIntentSenderFromChild}, but taking a Fragment; see |
| 5200 | * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} |
| 5201 | * for more information. |
| 5202 | * |
| 5203 | * @hide |
| 5204 | */ |
| 5205 | public void startIntentSenderFromChildFragment(Fragment child, IntentSender intent, |
| 5206 | int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, |
| 5207 | int extraFlags, @Nullable Bundle options) |
| 5208 | throws IntentSender.SendIntentException { |
| 5209 | startIntentSenderForResultInner(intent, child.mWho, requestCode, fillInIntent, |
| 5210 | flagsMask, flagsValues, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5214 | * Call immediately after one of the flavors of {@link #startActivity(Intent)} |
| 5215 | * or {@link #finish} to specify an explicit transition animation to |
| 5216 | * perform next. |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5217 | * |
| 5218 | * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN} an alternative |
| 5219 | * to using this with starting activities is to supply the desired animation |
| 5220 | * information through a {@link ActivityOptions} bundle to |
Mark Lu | fa43485 | 2016-08-11 17:40:33 -0700 | [diff] [blame] | 5221 | * {@link #startActivity(Intent, Bundle)} or a related function. This allows |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 5222 | * you to specify a custom animation even when starting an activity from |
| 5223 | * outside the context of the current top activity. |
| 5224 | * |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5225 | * @param enterAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5226 | * the incoming activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5227 | * @param exitAnim A resource ID of the animation resource to use for |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 5228 | * the outgoing activity. Use 0 for no animation. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5229 | */ |
| 5230 | public void overridePendingTransition(int enterAnim, int exitAnim) { |
| 5231 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5232 | ActivityManager.getService().overridePendingTransition( |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5233 | mToken, getPackageName(), enterAnim, exitAnim); |
| 5234 | } catch (RemoteException e) { |
| 5235 | } |
| 5236 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5237 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5238 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5239 | * Call this to set the result that your activity will return to its |
| 5240 | * caller. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5241 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5242 | * @param resultCode The result code to propagate back to the originating |
| 5243 | * activity, often RESULT_CANCELED or RESULT_OK |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5244 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5245 | * @see #RESULT_CANCELED |
| 5246 | * @see #RESULT_OK |
| 5247 | * @see #RESULT_FIRST_USER |
| 5248 | * @see #setResult(int, Intent) |
| 5249 | */ |
| 5250 | public final void setResult(int resultCode) { |
| 5251 | synchronized (this) { |
| 5252 | mResultCode = resultCode; |
| 5253 | mResultData = null; |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | /** |
| 5258 | * Call this to set the result that your activity will return to its |
| 5259 | * caller. |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 5260 | * |
| 5261 | * <p>As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}, the Intent |
| 5262 | * you supply here can have {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 5263 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 5264 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} set. This will grant the |
| 5265 | * Activity receiving the result access to the specific URIs in the Intent. |
| 5266 | * Access will remain until the Activity has finished (it will remain across the hosting |
| 5267 | * process being killed and other temporary destruction) and will be added |
| 5268 | * to any existing set of URI permissions it already holds. |
| 5269 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5270 | * @param resultCode The result code to propagate back to the originating |
| 5271 | * activity, often RESULT_CANCELED or RESULT_OK |
| 5272 | * @param data The data to propagate back to the originating activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5273 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5274 | * @see #RESULT_CANCELED |
| 5275 | * @see #RESULT_OK |
| 5276 | * @see #RESULT_FIRST_USER |
| 5277 | * @see #setResult(int) |
| 5278 | */ |
| 5279 | public final void setResult(int resultCode, Intent data) { |
| 5280 | synchronized (this) { |
| 5281 | mResultCode = resultCode; |
| 5282 | mResultData = data; |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | /** |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5287 | * Return information about who launched this activity. If the launching Intent |
| 5288 | * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER}, |
| 5289 | * that will be returned as-is; otherwise, if known, an |
| 5290 | * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the |
| 5291 | * package name that started the Intent will be returned. This may return null if no |
| 5292 | * referrer can be identified -- it is neither explicitly specified, nor is it known which |
| 5293 | * application package was involved. |
| 5294 | * |
| 5295 | * <p>If called while inside the handling of {@link #onNewIntent}, this function will |
| 5296 | * return the referrer that submitted that new intent to the activity. Otherwise, it |
| 5297 | * always returns the referrer of the original Intent.</p> |
| 5298 | * |
| 5299 | * <p>Note that this is <em>not</em> a security feature -- you can not trust the |
| 5300 | * referrer information, applications can spoof it.</p> |
| 5301 | */ |
| 5302 | @Nullable |
| 5303 | public Uri getReferrer() { |
| 5304 | Intent intent = getIntent(); |
Adam Powell | d3c63a6 | 2016-06-09 12:36:16 -0700 | [diff] [blame] | 5305 | try { |
| 5306 | Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); |
| 5307 | if (referrer != null) { |
| 5308 | return referrer; |
| 5309 | } |
| 5310 | String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME); |
| 5311 | if (referrerName != null) { |
| 5312 | return Uri.parse(referrerName); |
| 5313 | } |
| 5314 | } catch (BadParcelableException e) { |
| 5315 | Log.w(TAG, "Cannot read referrer from intent;" |
| 5316 | + " intent extras contain unknown custom Parcelable objects"); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5317 | } |
| 5318 | if (mReferrer != null) { |
| 5319 | return new Uri.Builder().scheme("android-app").authority(mReferrer).build(); |
| 5320 | } |
| 5321 | return null; |
| 5322 | } |
| 5323 | |
| 5324 | /** |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 5325 | * Override to generate the desired referrer for the content currently being shown |
| 5326 | * by the app. The default implementation returns null, meaning the referrer will simply |
| 5327 | * be the android-app: of the package name of this activity. Return a non-null Uri to |
| 5328 | * have that supplied as the {@link Intent#EXTRA_REFERRER} of any activities started from it. |
| 5329 | */ |
| 5330 | public Uri onProvideReferrer() { |
| 5331 | return null; |
| 5332 | } |
| 5333 | |
| 5334 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5335 | * Return the name of the package that invoked this activity. This is who |
| 5336 | * the data in {@link #setResult setResult()} will be sent to. You can |
| 5337 | * use this information to validate that the recipient is allowed to |
| 5338 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5339 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5340 | * <p class="note">Note: if the calling activity is not expecting a result (that is it |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5341 | * did not use the {@link #startActivityForResult} |
| 5342 | * form that includes a request code), then the calling package will be |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5343 | * null.</p> |
| 5344 | * |
| 5345 | * <p class="note">Note: prior to {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
| 5346 | * the result from this method was unstable. If the process hosting the calling |
| 5347 | * package was no longer running, it would return null instead of the proper package |
| 5348 | * name. You can use {@link #getCallingActivity()} and retrieve the package name |
| 5349 | * from that instead.</p> |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5350 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | * @return The package of the activity that will receive your |
| 5352 | * reply, or null if none. |
| 5353 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5354 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | public String getCallingPackage() { |
| 5356 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5357 | return ActivityManager.getService().getCallingPackage(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5358 | } catch (RemoteException e) { |
| 5359 | return null; |
| 5360 | } |
| 5361 | } |
| 5362 | |
| 5363 | /** |
| 5364 | * Return the name of the activity that invoked this activity. This is |
| 5365 | * who the data in {@link #setResult setResult()} will be sent to. You |
| 5366 | * can use this information to validate that the recipient is allowed to |
| 5367 | * receive the data. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5368 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5369 | * <p class="note">Note: if the calling activity is not expecting a result (that is it |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5370 | * did not use the {@link #startActivityForResult} |
| 5371 | * form that includes a request code), then the calling package will be |
| 5372 | * null. |
| 5373 | * |
Dianne Hackborn | 7b92467 | 2013-04-11 18:08:42 -0700 | [diff] [blame] | 5374 | * @return The ComponentName of the activity that will receive your |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5375 | * reply, or null if none. |
| 5376 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5377 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5378 | public ComponentName getCallingActivity() { |
| 5379 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5380 | return ActivityManager.getService().getCallingActivity(mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | } catch (RemoteException e) { |
| 5382 | return null; |
| 5383 | } |
| 5384 | } |
| 5385 | |
| 5386 | /** |
| 5387 | * Control whether this activity's main window is visible. This is intended |
| 5388 | * only for the special case of an activity that is not going to show a |
| 5389 | * UI itself, but can't just finish prior to onResume() because it needs |
| 5390 | * to wait for a service binding or such. Setting this to false allows |
| 5391 | * you to prevent your UI from being shown during that time. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5392 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | * <p>The default value for this is taken from the |
| 5394 | * {@link android.R.attr#windowNoDisplay} attribute of the activity's theme. |
| 5395 | */ |
| 5396 | public void setVisible(boolean visible) { |
| 5397 | if (mVisibleFromClient != visible) { |
| 5398 | mVisibleFromClient = visible; |
| 5399 | if (mVisibleFromServer) { |
| 5400 | if (visible) makeVisible(); |
| 5401 | else mDecor.setVisibility(View.INVISIBLE); |
| 5402 | } |
| 5403 | } |
| 5404 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5406 | void makeVisible() { |
| 5407 | if (!mWindowAdded) { |
| 5408 | ViewManager wm = getWindowManager(); |
| 5409 | wm.addView(mDecor, getWindow().getAttributes()); |
| 5410 | mWindowAdded = true; |
| 5411 | } |
| 5412 | mDecor.setVisibility(View.VISIBLE); |
| 5413 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5415 | /** |
| 5416 | * Check to see whether this activity is in the process of finishing, |
| 5417 | * either because you called {@link #finish} on it or someone else |
| 5418 | * has requested that it finished. This is often used in |
| 5419 | * {@link #onPause} to determine whether the activity is simply pausing or |
| 5420 | * completely finishing. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5421 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5422 | * @return If the activity is finishing, returns true; else returns false. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5423 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5424 | * @see #finish |
| 5425 | */ |
| 5426 | public boolean isFinishing() { |
| 5427 | return mFinished; |
| 5428 | } |
| 5429 | |
| 5430 | /** |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 5431 | * Returns true if the final {@link #onDestroy()} call has been made |
| 5432 | * on the Activity, so this instance is now dead. |
| 5433 | */ |
| 5434 | public boolean isDestroyed() { |
| 5435 | return mDestroyed; |
| 5436 | } |
| 5437 | |
| 5438 | /** |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 5439 | * Check to see whether this activity is in the process of being destroyed in order to be |
| 5440 | * recreated with a new configuration. This is often used in |
| 5441 | * {@link #onStop} to determine whether the state needs to be cleaned up or will be passed |
| 5442 | * on to the next instance of the activity via {@link #onRetainNonConfigurationInstance()}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5443 | * |
Jeff Hamilton | 3d32f6e | 2010-04-01 00:04:16 -0500 | [diff] [blame] | 5444 | * @return If the activity is being torn down in order to be recreated with a new configuration, |
| 5445 | * returns true; else returns false. |
| 5446 | */ |
| 5447 | public boolean isChangingConfigurations() { |
| 5448 | return mChangingConfigurations; |
| 5449 | } |
| 5450 | |
| 5451 | /** |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5452 | * Cause this Activity to be recreated with a new instance. This results |
| 5453 | * in essentially the same flow as when the Activity is created due to |
| 5454 | * a configuration change -- the current instance will go through its |
| 5455 | * lifecycle to {@link #onDestroy} and a new instance then created after it. |
| 5456 | */ |
| 5457 | public void recreate() { |
| 5458 | if (mParent != null) { |
| 5459 | throw new IllegalStateException("Can only be called on top-level activity"); |
| 5460 | } |
| 5461 | if (Looper.myLooper() != mMainThread.getLooper()) { |
| 5462 | throw new IllegalStateException("Must be called from main thread"); |
| 5463 | } |
Chong Zhang | fec694e | 2016-08-09 12:57:38 -0700 | [diff] [blame] | 5464 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5465 | ActivityManager.getService().requestActivityRelaunch(mToken); |
Chong Zhang | fec694e | 2016-08-09 12:57:38 -0700 | [diff] [blame] | 5466 | } catch (RemoteException e) { |
| 5467 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5471 | * Finishes the current activity and specifies whether to remove the task associated with this |
| 5472 | * activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5473 | */ |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 5474 | private void finish(int finishTask) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | if (mParent == null) { |
| 5476 | int resultCode; |
| 5477 | Intent resultData; |
| 5478 | synchronized (this) { |
| 5479 | resultCode = mResultCode; |
| 5480 | resultData = mResultData; |
| 5481 | } |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 5482 | if (false) Log.v(TAG, "Finishing self: token=" + mToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5483 | try { |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 5484 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5485 | resultData.prepareToLeaveProcess(this); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 5486 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5487 | if (ActivityManager.getService() |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5488 | .finishActivity(mToken, resultCode, resultData, finishTask)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5489 | mFinished = true; |
| 5490 | } |
| 5491 | } catch (RemoteException e) { |
| 5492 | // Empty |
| 5493 | } |
| 5494 | } else { |
| 5495 | mParent.finishFromChild(this); |
| 5496 | } |
| 5497 | } |
| 5498 | |
| 5499 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5500 | * Call this when your activity is done and should be closed. The |
| 5501 | * ActivityResult is propagated back to whoever launched you via |
| 5502 | * onActivityResult(). |
| 5503 | */ |
| 5504 | public void finish() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 5505 | finish(DONT_FINISH_TASK_WITH_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5506 | } |
| 5507 | |
| 5508 | /** |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 5509 | * Finish this activity as well as all activities immediately below it |
| 5510 | * in the current task that have the same affinity. This is typically |
| 5511 | * used when an application can be launched on to another task (such as |
| 5512 | * from an ACTION_VIEW of a content type it understands) and the user |
| 5513 | * has used the up navigation to switch out of the current task and in |
| 5514 | * to its own task. In this case, if the user has navigated down into |
| 5515 | * any other activities of the second application, all of those should |
| 5516 | * be removed from the original task as part of the task switch. |
| 5517 | * |
| 5518 | * <p>Note that this finish does <em>not</em> allow you to deliver results |
| 5519 | * to the previous activity, and an exception will be thrown if you are trying |
| 5520 | * to do so.</p> |
| 5521 | */ |
| 5522 | public void finishAffinity() { |
| 5523 | if (mParent != null) { |
| 5524 | throw new IllegalStateException("Can not be called from an embedded activity"); |
| 5525 | } |
| 5526 | if (mResultCode != RESULT_CANCELED || mResultData != null) { |
| 5527 | throw new IllegalStateException("Can not be called to deliver a result"); |
| 5528 | } |
| 5529 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5530 | if (ActivityManager.getService().finishActivityAffinity(mToken)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 5531 | mFinished = true; |
| 5532 | } |
| 5533 | } catch (RemoteException e) { |
| 5534 | // Empty |
| 5535 | } |
| 5536 | } |
| 5537 | |
| 5538 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5539 | * This is called when a child activity of this one calls its |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5540 | * {@link #finish} method. The default implementation simply calls |
| 5541 | * finish() on this activity (the parent), finishing the entire group. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5542 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | * @param child The activity making the call. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5544 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | * @see #finish |
| 5546 | */ |
| 5547 | public void finishFromChild(Activity child) { |
| 5548 | finish(); |
| 5549 | } |
| 5550 | |
| 5551 | /** |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 5552 | * Reverses the Activity Scene entry Transition and triggers the calling Activity |
| 5553 | * to reverse its exit Transition. When the exit Transition completes, |
| 5554 | * {@link #finish()} is called. If no entry Transition was used, finish() is called |
| 5555 | * immediately and the Activity exit Transition is run. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5556 | * @see android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, android.util.Pair[]) |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 5557 | */ |
Craig Mautner | 73f843d | 2014-05-19 09:42:28 -0700 | [diff] [blame] | 5558 | public void finishAfterTransition() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5559 | if (!mActivityTransitionState.startExitBackTransition(this)) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 5560 | finish(); |
| 5561 | } |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 5562 | } |
| 5563 | |
| 5564 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5565 | * Force finish another activity that you had previously started with |
| 5566 | * {@link #startActivityForResult}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5567 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | * @param requestCode The request code of the activity that you had |
| 5569 | * given to startActivityForResult(). If there are multiple |
| 5570 | * activities started with this request code, they |
| 5571 | * will all be finished. |
| 5572 | */ |
| 5573 | public void finishActivity(int requestCode) { |
| 5574 | if (mParent == null) { |
| 5575 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5576 | ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5577 | .finishSubActivity(mToken, mEmbeddedID, requestCode); |
| 5578 | } catch (RemoteException e) { |
| 5579 | // Empty |
| 5580 | } |
| 5581 | } else { |
| 5582 | mParent.finishActivityFromChild(this, requestCode); |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | /** |
| 5587 | * This is called when a child activity of this one calls its |
| 5588 | * finishActivity(). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5589 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5590 | * @param child The activity making the call. |
| 5591 | * @param requestCode Request code that had been used to start the |
| 5592 | * activity. |
| 5593 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5594 | public void finishActivityFromChild(@NonNull Activity child, int requestCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5595 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5596 | ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5597 | .finishSubActivity(mToken, child.mEmbeddedID, requestCode); |
| 5598 | } catch (RemoteException e) { |
| 5599 | // Empty |
| 5600 | } |
| 5601 | } |
| 5602 | |
| 5603 | /** |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5604 | * Call this when your activity is done and should be closed and the task should be completely |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 5605 | * removed as a part of finishing the root activity of the task. |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5606 | */ |
| 5607 | public void finishAndRemoveTask() { |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 5608 | finish(FINISH_TASK_WITH_ROOT_ACTIVITY); |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | /** |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5612 | * Ask that the local app instance of this activity be released to free up its memory. |
| 5613 | * This is asking for the activity to be destroyed, but does <b>not</b> finish the activity -- |
| 5614 | * a new instance of the activity will later be re-created if needed due to the user |
| 5615 | * navigating back to it. |
| 5616 | * |
| 5617 | * @return Returns true if the activity was in a state that it has started the process |
| 5618 | * of destroying its current instance; returns false if for any reason this could not |
| 5619 | * be done: it is currently visible to the user, it is already being destroyed, it is |
| 5620 | * being finished, it hasn't yet saved its state, etc. |
| 5621 | */ |
| 5622 | public boolean releaseInstance() { |
| 5623 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5624 | return ActivityManager.getService().releaseActivityInstance(mToken); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5625 | } catch (RemoteException e) { |
| 5626 | // Empty |
| 5627 | } |
| 5628 | return false; |
| 5629 | } |
| 5630 | |
| 5631 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | * Called when an activity you launched exits, giving you the requestCode |
| 5633 | * you started it with, the resultCode it returned, and any additional |
| 5634 | * data from it. The <var>resultCode</var> will be |
| 5635 | * {@link #RESULT_CANCELED} if the activity explicitly returned that, |
| 5636 | * didn't return any result, or crashed during its operation. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5637 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5638 | * <p>You will receive this call immediately before onResume() when your |
| 5639 | * activity is re-starting. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5640 | * |
Ricardo Cervera | 92f6a74 | 2014-04-04 11:17:06 -0700 | [diff] [blame] | 5641 | * <p>This method is never invoked if your activity sets |
| 5642 | * {@link android.R.styleable#AndroidManifestActivity_noHistory noHistory} to |
| 5643 | * <code>true</code>. |
Ricardo Cervera | 93f94c2 | 2015-01-16 09:54:30 -0800 | [diff] [blame] | 5644 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5645 | * @param requestCode The integer request code originally supplied to |
| 5646 | * startActivityForResult(), allowing you to identify who this |
| 5647 | * result came from. |
| 5648 | * @param resultCode The integer result code returned by the child activity |
| 5649 | * through its setResult(). |
| 5650 | * @param data An Intent, which can return result data to the caller |
| 5651 | * (various data can be attached to Intent "extras"). |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5652 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | * @see #startActivityForResult |
| 5654 | * @see #createPendingResult |
| 5655 | * @see #setResult(int) |
| 5656 | */ |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 5657 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5661 | * Called when an activity you launched with an activity transition exposes this |
| 5662 | * Activity through a returning activity transition, giving you the resultCode |
| 5663 | * and any additional data from it. This method will only be called if the activity |
| 5664 | * set a result code other than {@link #RESULT_CANCELED} and it supports activity |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 5665 | * transitions with {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5666 | * |
| 5667 | * <p>The purpose of this function is to let the called Activity send a hint about |
| 5668 | * its state so that this underlying Activity can prepare to be exposed. A call to |
| 5669 | * this method does not guarantee that the called Activity has or will be exiting soon. |
| 5670 | * It only indicates that it will expose this Activity's Window and it has |
| 5671 | * some data to pass to prepare it.</p> |
| 5672 | * |
| 5673 | * @param resultCode The integer result code returned by the child activity |
| 5674 | * through its setResult(). |
| 5675 | * @param data An Intent, which can return result data to the caller |
| 5676 | * (various data can be attached to Intent "extras"). |
| 5677 | */ |
Craig Mautner | 7a629c2 | 2014-09-04 14:57:04 -0700 | [diff] [blame] | 5678 | public void onActivityReenter(int resultCode, Intent data) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | /** |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5682 | * Create a new PendingIntent object which you can hand to others |
| 5683 | * for them to use to send result data back to your |
| 5684 | * {@link #onActivityResult} callback. The created object will be either |
| 5685 | * one-shot (becoming invalid after a result is sent back) or multiple |
| 5686 | * (allowing any number of results to be sent through it). |
| 5687 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5688 | * @param requestCode Private request code for the sender that will be |
| 5689 | * associated with the result data when it is returned. The sender can not |
| 5690 | * modify this value, allowing you to identify incoming results. |
| 5691 | * @param data Default data to supply in the result, which may be modified |
| 5692 | * by the sender. |
| 5693 | * @param flags May be {@link PendingIntent#FLAG_ONE_SHOT PendingIntent.FLAG_ONE_SHOT}, |
| 5694 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE}, |
| 5695 | * {@link PendingIntent#FLAG_CANCEL_CURRENT PendingIntent.FLAG_CANCEL_CURRENT}, |
| 5696 | * {@link PendingIntent#FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT}, |
| 5697 | * or any of the flags as supported by |
| 5698 | * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts |
| 5699 | * of the intent that can be supplied when the actual send happens. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5700 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5701 | * @return Returns an existing or new PendingIntent matching the given |
| 5702 | * parameters. May return null only if |
| 5703 | * {@link PendingIntent#FLAG_NO_CREATE PendingIntent.FLAG_NO_CREATE} has been |
| 5704 | * supplied. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5705 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5706 | * @see PendingIntent |
| 5707 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5708 | public PendingIntent createPendingResult(int requestCode, @NonNull Intent data, |
| 5709 | @PendingIntent.Flags int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5710 | String packageName = getPackageName(); |
| 5711 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5712 | data.prepareToLeaveProcess(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | IIntentSender target = |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5714 | ActivityManager.getService().getIntentSender( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5715 | ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5716 | mParent == null ? mToken : mParent.mToken, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 5717 | mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null, |
| 5718 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5719 | return target != null ? new PendingIntent(target) : null; |
| 5720 | } catch (RemoteException e) { |
| 5721 | // Empty |
| 5722 | } |
| 5723 | return null; |
| 5724 | } |
| 5725 | |
| 5726 | /** |
| 5727 | * Change the desired orientation of this activity. If the activity |
| 5728 | * is currently in the foreground or otherwise impacting the screen |
| 5729 | * orientation, the screen will immediately be changed (possibly causing |
| 5730 | * the activity to be restarted). Otherwise, this will be used the next |
| 5731 | * time the activity is visible. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5732 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | * @param requestedOrientation An orientation constant as used in |
| 5734 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 5735 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5736 | public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5737 | if (mParent == null) { |
| 5738 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5739 | ActivityManager.getService().setRequestedOrientation( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5740 | mToken, requestedOrientation); |
| 5741 | } catch (RemoteException e) { |
| 5742 | // Empty |
| 5743 | } |
| 5744 | } else { |
| 5745 | mParent.setRequestedOrientation(requestedOrientation); |
| 5746 | } |
| 5747 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5749 | /** |
| 5750 | * Return the current requested orientation of the activity. This will |
| 5751 | * either be the orientation requested in its component's manifest, or |
| 5752 | * the last requested orientation given to |
| 5753 | * {@link #setRequestedOrientation(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5754 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5755 | * @return Returns an orientation constant as used in |
| 5756 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 5757 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5758 | @ActivityInfo.ScreenOrientation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5759 | public int getRequestedOrientation() { |
| 5760 | if (mParent == null) { |
| 5761 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5762 | return ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5763 | .getRequestedOrientation(mToken); |
| 5764 | } catch (RemoteException e) { |
| 5765 | // Empty |
| 5766 | } |
| 5767 | } else { |
| 5768 | return mParent.getRequestedOrientation(); |
| 5769 | } |
| 5770 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 5771 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5773 | /** |
| 5774 | * Return the identifier of the task this activity is in. This identifier |
| 5775 | * will remain the same for the lifetime of the activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5776 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | * @return Task identifier, an opaque integer. |
| 5778 | */ |
| 5779 | public int getTaskId() { |
| 5780 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5781 | return ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5782 | .getTaskForActivity(mToken, false); |
| 5783 | } catch (RemoteException e) { |
| 5784 | return -1; |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | /** |
| 5789 | * Return whether this activity is the root of a task. The root is the |
| 5790 | * first activity in a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5791 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5792 | * @return True if this is the root activity, else false. |
| 5793 | */ |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 5794 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | public boolean isTaskRoot() { |
| 5796 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5797 | return ActivityManager.getService().getTaskForActivity(mToken, true) >= 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | } catch (RemoteException e) { |
| 5799 | return false; |
| 5800 | } |
| 5801 | } |
| 5802 | |
| 5803 | /** |
| 5804 | * Move the task containing this activity to the back of the activity |
| 5805 | * stack. The activity's order within the task is unchanged. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5806 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5807 | * @param nonRoot If false then this only works if the activity is the root |
| 5808 | * of a task; if true it will work for any activity in |
| 5809 | * a task. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5810 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5811 | * @return If the task was moved (or it was already at the |
| 5812 | * back) true is returned, else false. |
| 5813 | */ |
| 5814 | public boolean moveTaskToBack(boolean nonRoot) { |
| 5815 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5816 | return ActivityManager.getService().moveActivityTaskToBack( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | mToken, nonRoot); |
| 5818 | } catch (RemoteException e) { |
| 5819 | // Empty |
| 5820 | } |
| 5821 | return false; |
| 5822 | } |
| 5823 | |
| 5824 | /** |
| 5825 | * Returns class name for this activity with the package prefix removed. |
| 5826 | * This is the default name used to read and write settings. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5827 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | * @return The local class name. |
| 5829 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5830 | @NonNull |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5831 | public String getLocalClassName() { |
| 5832 | final String pkg = getPackageName(); |
| 5833 | final String cls = mComponent.getClassName(); |
| 5834 | int packageLen = pkg.length(); |
| 5835 | if (!cls.startsWith(pkg) || cls.length() <= packageLen |
| 5836 | || cls.charAt(packageLen) != '.') { |
| 5837 | return cls; |
| 5838 | } |
| 5839 | return cls.substring(packageLen+1); |
| 5840 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5842 | /** |
| 5843 | * Returns complete component name of this activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5844 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5845 | * @return Returns the complete component name for this activity |
| 5846 | */ |
| 5847 | public ComponentName getComponentName() |
| 5848 | { |
| 5849 | return mComponent; |
| 5850 | } |
| 5851 | |
| 5852 | /** |
| 5853 | * Retrieve a {@link SharedPreferences} object for accessing preferences |
| 5854 | * that are private to this activity. This simply calls the underlying |
| 5855 | * {@link #getSharedPreferences(String, int)} method by passing in this activity's |
| 5856 | * class name as the preferences name. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5857 | * |
| 5858 | * @param mode Operating mode. Use {@link #MODE_PRIVATE} for the default |
Jeff Sharkey | 634dc42 | 2016-01-30 17:44:15 -0700 | [diff] [blame] | 5859 | * operation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | * |
| 5861 | * @return Returns the single SharedPreferences instance that can be used |
| 5862 | * to retrieve and modify the preference values. |
| 5863 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 5864 | public SharedPreferences getPreferences(@Context.PreferencesMode int mode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5865 | return getSharedPreferences(getLocalClassName(), mode); |
| 5866 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5867 | |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5868 | private void ensureSearchManager() { |
| 5869 | if (mSearchManager != null) { |
| 5870 | return; |
| 5871 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5872 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 5873 | try { |
| 5874 | mSearchManager = new SearchManager(this, null); |
| 5875 | } catch (ServiceNotFoundException e) { |
| 5876 | throw new IllegalStateException(e); |
| 5877 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5878 | } |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5880 | @Override |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 5881 | public Object getSystemService(@ServiceName @NonNull String name) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | if (getBaseContext() == null) { |
| 5883 | throw new IllegalStateException( |
| 5884 | "System services not available to Activities before onCreate()"); |
| 5885 | } |
| 5886 | |
| 5887 | if (WINDOW_SERVICE.equals(name)) { |
| 5888 | return mWindowManager; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 5889 | } else if (SEARCH_SERVICE.equals(name)) { |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 5890 | ensureSearchManager(); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 5891 | return mSearchManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5892 | } |
| 5893 | return super.getSystemService(name); |
| 5894 | } |
| 5895 | |
| 5896 | /** |
| 5897 | * Change the title associated with this activity. If this is a |
| 5898 | * top-level activity, the title for its window will change. If it |
| 5899 | * is an embedded activity, the parent can do whatever it wants |
| 5900 | * with it. |
| 5901 | */ |
| 5902 | public void setTitle(CharSequence title) { |
| 5903 | mTitle = title; |
| 5904 | onTitleChanged(title, mTitleColor); |
| 5905 | |
| 5906 | if (mParent != null) { |
| 5907 | mParent.onChildTitleChanged(this, title); |
| 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | /** |
| 5912 | * Change the title associated with this activity. If this is a |
| 5913 | * top-level activity, the title for its window will change. If it |
| 5914 | * is an embedded activity, the parent can do whatever it wants |
| 5915 | * with it. |
| 5916 | */ |
| 5917 | public void setTitle(int titleId) { |
| 5918 | setTitle(getText(titleId)); |
| 5919 | } |
| 5920 | |
Alan Viverette | 2525d9c | 2013-11-15 14:42:19 -0800 | [diff] [blame] | 5921 | /** |
| 5922 | * Change the color of the title associated with this activity. |
| 5923 | * <p> |
| 5924 | * This method is deprecated starting in API Level 11 and replaced by action |
| 5925 | * bar styles. For information on styling the Action Bar, read the <a |
| 5926 | * href="{@docRoot} guide/topics/ui/actionbar.html">Action Bar</a> developer |
| 5927 | * guide. |
| 5928 | * |
| 5929 | * @deprecated Use action bar styles instead. |
| 5930 | */ |
| 5931 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | public void setTitleColor(int textColor) { |
| 5933 | mTitleColor = textColor; |
| 5934 | onTitleChanged(mTitle, textColor); |
| 5935 | } |
| 5936 | |
| 5937 | public final CharSequence getTitle() { |
| 5938 | return mTitle; |
| 5939 | } |
| 5940 | |
| 5941 | public final int getTitleColor() { |
| 5942 | return mTitleColor; |
| 5943 | } |
| 5944 | |
| 5945 | protected void onTitleChanged(CharSequence title, int color) { |
| 5946 | if (mTitleReady) { |
| 5947 | final Window win = getWindow(); |
| 5948 | if (win != null) { |
| 5949 | win.setTitle(title); |
| 5950 | if (color != 0) { |
| 5951 | win.setTitleColor(color); |
| 5952 | } |
| 5953 | } |
Adam Powell | af2d859 | 2014-08-26 18:06:40 -0700 | [diff] [blame] | 5954 | if (mActionBar != null) { |
| 5955 | mActionBar.setWindowTitle(title); |
| 5956 | } |
Adam Powell | a557fdc | 2014-08-21 18:05:53 -0700 | [diff] [blame] | 5957 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | protected void onChildTitleChanged(Activity childActivity, CharSequence title) { |
| 5961 | } |
| 5962 | |
| 5963 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5964 | * Sets information describing the task with this activity for presentation inside the Recents |
| 5965 | * System UI. When {@link ActivityManager#getRecentTasks} is called, the activities of each task |
| 5966 | * are traversed in order from the topmost activity to the bottommost. The traversal continues |
| 5967 | * for each property until a suitable value is found. For each task the taskDescription will be |
| 5968 | * returned in {@link android.app.ActivityManager.TaskDescription}. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5969 | * |
| 5970 | * @see ActivityManager#getRecentTasks |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5971 | * @see android.app.ActivityManager.TaskDescription |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5972 | * |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5973 | * @param taskDescription The TaskDescription properties that describe the task with this activity |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5974 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 5975 | public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 5976 | if (mTaskDescription != taskDescription) { |
Jorim Jaggi | f4156ea | 2017-04-10 18:39:04 -0700 | [diff] [blame] | 5977 | mTaskDescription.copyFromPreserveHiddenFields(taskDescription); |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 5978 | // Scale the icon down to something reasonable if it is provided |
| 5979 | if (taskDescription.getIconFilename() == null && taskDescription.getIcon() != null) { |
| 5980 | final int size = ActivityManager.getLauncherLargeIconSizeInner(this); |
| 5981 | final Bitmap icon = Bitmap.createScaledBitmap(taskDescription.getIcon(), size, size, |
| 5982 | true); |
| 5983 | mTaskDescription.setIcon(icon); |
| 5984 | } |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5985 | } |
| 5986 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5987 | ActivityManager.getService().setTaskDescription(mToken, mTaskDescription); |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 5988 | } catch (RemoteException e) { |
| 5989 | } |
| 5990 | } |
| 5991 | |
| 5992 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5993 | * Sets the visibility of the progress bar in the title. |
| 5994 | * <p> |
| 5995 | * In order for the progress bar to be shown, the feature must be requested |
| 5996 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 5997 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5998 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 5999 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6001 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6002 | public final void setProgressBarVisibility(boolean visible) { |
| 6003 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, visible ? Window.PROGRESS_VISIBILITY_ON : |
| 6004 | Window.PROGRESS_VISIBILITY_OFF); |
| 6005 | } |
| 6006 | |
| 6007 | /** |
| 6008 | * Sets the visibility of the indeterminate progress bar in the title. |
| 6009 | * <p> |
| 6010 | * In order for the progress bar to be shown, the feature must be requested |
| 6011 | * via {@link #requestWindowFeature(int)}. |
| 6012 | * |
| 6013 | * @param visible Whether to show the progress bars in the title. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6014 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6015 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6016 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6017 | public final void setProgressBarIndeterminateVisibility(boolean visible) { |
| 6018 | getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, |
| 6019 | visible ? Window.PROGRESS_VISIBILITY_ON : Window.PROGRESS_VISIBILITY_OFF); |
| 6020 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | /** |
| 6023 | * Sets whether the horizontal progress bar in the title should be indeterminate (the circular |
| 6024 | * is always indeterminate). |
| 6025 | * <p> |
| 6026 | * In order for the progress bar to be shown, the feature must be requested |
| 6027 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6028 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6029 | * @param indeterminate Whether the horizontal progress bar should be indeterminate. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6030 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6031 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6032 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | public final void setProgressBarIndeterminate(boolean indeterminate) { |
| 6034 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 6035 | indeterminate ? Window.PROGRESS_INDETERMINATE_ON |
| 6036 | : Window.PROGRESS_INDETERMINATE_OFF); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | /** |
| 6040 | * Sets the progress for the progress bars in the title. |
| 6041 | * <p> |
| 6042 | * In order for the progress bar to be shown, the feature must be requested |
| 6043 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6044 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6045 | * @param progress The progress for the progress bar. Valid ranges are from |
| 6046 | * 0 to 10000 (both inclusive). If 10000 is given, the progress |
| 6047 | * bar will be completely filled and will fade out. |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6048 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6049 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6050 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6051 | public final void setProgress(int progress) { |
| 6052 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress + Window.PROGRESS_START); |
| 6053 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6055 | /** |
| 6056 | * Sets the secondary progress for the progress bar in the title. This |
| 6057 | * progress is drawn between the primary progress (set via |
| 6058 | * {@link #setProgress(int)} and the background. It can be ideal for media |
| 6059 | * scenarios such as showing the buffering progress while the default |
| 6060 | * progress shows the play progress. |
| 6061 | * <p> |
| 6062 | * In order for the progress bar to be shown, the feature must be requested |
| 6063 | * via {@link #requestWindowFeature(int)}. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6064 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6065 | * @param secondaryProgress The secondary progress for the progress bar. Valid ranges are from |
| 6066 | * 0 to 10000 (both inclusive). |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6067 | * @deprecated No longer supported starting in API 21. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6068 | */ |
Alan Viverette | 4aef7c8 | 2015-09-04 14:14:50 -0400 | [diff] [blame] | 6069 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | public final void setSecondaryProgress(int secondaryProgress) { |
| 6071 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
| 6072 | secondaryProgress + Window.PROGRESS_SECONDARY_START); |
| 6073 | } |
| 6074 | |
| 6075 | /** |
| 6076 | * Suggests an audio stream whose volume should be changed by the hardware |
| 6077 | * volume controls. |
| 6078 | * <p> |
| 6079 | * The suggested audio stream will be tied to the window of this Activity. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6080 | * Volume requests which are received while the Activity is in the |
| 6081 | * foreground will affect this stream. |
| 6082 | * <p> |
| 6083 | * It is not guaranteed that the hardware volume controls will always change |
| 6084 | * this stream's volume (for example, if a call is in progress, its stream's |
| 6085 | * volume may be changed instead). To reset back to the default, use |
| 6086 | * {@link AudioManager#USE_DEFAULT_STREAM_TYPE}. |
| 6087 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6088 | * @param streamType The type of the audio stream whose volume should be |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6089 | * changed by the hardware volume controls. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6090 | */ |
| 6091 | public final void setVolumeControlStream(int streamType) { |
| 6092 | getWindow().setVolumeControlStream(streamType); |
| 6093 | } |
| 6094 | |
| 6095 | /** |
| 6096 | * Gets the suggested audio stream whose volume should be changed by the |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6097 | * hardware volume controls. |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6098 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | * @return The suggested audio stream type whose volume should be changed by |
| 6100 | * the hardware volume controls. |
| 6101 | * @see #setVolumeControlStream(int) |
| 6102 | */ |
| 6103 | public final int getVolumeControlStream() { |
| 6104 | return getWindow().getVolumeControlStream(); |
| 6105 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6106 | |
| 6107 | /** |
| 6108 | * Sets a {@link MediaController} to send media keys and volume changes to. |
| 6109 | * <p> |
| 6110 | * The controller will be tied to the window of this Activity. Media key and |
| 6111 | * volume events which are received while the Activity is in the foreground |
| 6112 | * will be forwarded to the controller and used to invoke transport controls |
| 6113 | * or adjust the volume. This may be used instead of or in addition to |
| 6114 | * {@link #setVolumeControlStream} to affect a specific session instead of a |
| 6115 | * specific stream. |
| 6116 | * <p> |
| 6117 | * It is not guaranteed that the hardware volume controls will always change |
| 6118 | * this session's volume (for example, if a call is in progress, its |
| 6119 | * stream's volume may be changed instead). To reset back to the default use |
| 6120 | * null as the controller. |
| 6121 | * |
| 6122 | * @param controller The controller for the session which should receive |
| 6123 | * media keys and volume changes. |
| 6124 | */ |
| 6125 | public final void setMediaController(MediaController controller) { |
| 6126 | getWindow().setMediaController(controller); |
| 6127 | } |
| 6128 | |
| 6129 | /** |
| 6130 | * Gets the controller which should be receiving media key and volume events |
| 6131 | * while this activity is in the foreground. |
| 6132 | * |
| 6133 | * @return The controller which should receive events. |
| 6134 | * @see #setMediaController(android.media.session.MediaController) |
| 6135 | */ |
| 6136 | public final MediaController getMediaController() { |
| 6137 | return getWindow().getMediaController(); |
| 6138 | } |
| 6139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6140 | /** |
| 6141 | * Runs the specified action on the UI thread. If the current thread is the UI |
| 6142 | * thread, then the action is executed immediately. If the current thread is |
| 6143 | * not the UI thread, the action is posted to the event queue of the UI thread. |
| 6144 | * |
| 6145 | * @param action the action to run on the UI thread |
| 6146 | */ |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 6147 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6148 | public final void runOnUiThread(Runnable action) { |
| 6149 | if (Thread.currentThread() != mUiThread) { |
| 6150 | mHandler.post(action); |
| 6151 | } else { |
| 6152 | action.run(); |
| 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | /** |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6157 | * Standard implementation of |
| 6158 | * {@link android.view.LayoutInflater.Factory#onCreateView} used when |
| 6159 | * inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6160 | * This implementation does nothing and is for |
| 6161 | * pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB} apps. Newer apps |
| 6162 | * should use {@link #onCreateView(View, String, Context, AttributeSet)}. |
| 6163 | * |
| 6164 | * @see android.view.LayoutInflater#createView |
| 6165 | * @see android.view.Window#getLayoutInflater |
| 6166 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6167 | @Nullable |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6168 | public View onCreateView(String name, Context context, AttributeSet attrs) { |
| 6169 | return null; |
| 6170 | } |
| 6171 | |
| 6172 | /** |
| 6173 | * Standard implementation of |
| 6174 | * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)} |
| 6175 | * used when inflating with the LayoutInflater returned by {@link #getSystemService}. |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6176 | * This implementation handles <fragment> tags to embed fragments inside |
| 6177 | * of the activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6178 | * |
| 6179 | * @see android.view.LayoutInflater#createView |
| 6180 | * @see android.view.Window#getLayoutInflater |
| 6181 | */ |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6182 | public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6183 | if (!"fragment".equals(name)) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6184 | return onCreateView(name, context, attrs); |
Dianne Hackborn | ba51c3d | 2010-05-05 18:49:48 -0700 | [diff] [blame] | 6185 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6186 | |
Adam Powell | 371a809 | 2014-06-20 12:51:12 -0700 | [diff] [blame] | 6187 | return mFragments.onCreateView(parent, name, context, attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | } |
| 6189 | |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6190 | /** |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6191 | * Print the Activity's state into the given stream. This gets invoked if |
Jeff Sharkey | 5554b70 | 2012-04-11 18:30:51 -0700 | [diff] [blame] | 6192 | * you run "adb shell dumpsys activity <activity_component_name>". |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6193 | * |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6194 | * @param prefix Desired prefix to prepend at each line of output. |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6195 | * @param fd The raw file descriptor that the dump is being sent to. |
| 6196 | * @param writer The PrintWriter to which you should dump your state. This will be |
| 6197 | * closed for you after you return. |
| 6198 | * @param args additional arguments to the dump request. |
| 6199 | */ |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6200 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
Dianne Hackborn | 62bea2f | 2012-09-04 18:48:15 -0700 | [diff] [blame] | 6201 | dumpInner(prefix, fd, writer, args); |
| 6202 | } |
| 6203 | |
| 6204 | void dumpInner(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6205 | writer.print(prefix); writer.print("Local Activity "); |
| 6206 | writer.print(Integer.toHexString(System.identityHashCode(this))); |
| 6207 | writer.println(" State:"); |
| 6208 | String innerPrefix = prefix + " "; |
| 6209 | writer.print(innerPrefix); writer.print("mResumed="); |
| 6210 | writer.print(mResumed); writer.print(" mStopped="); |
| 6211 | writer.print(mStopped); writer.print(" mFinished="); |
| 6212 | writer.println(mFinished); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 6213 | writer.print(innerPrefix); writer.print("mChangingConfigurations="); |
| 6214 | writer.println(mChangingConfigurations); |
| 6215 | writer.print(innerPrefix); writer.print("mCurrentConfig="); |
| 6216 | writer.println(mCurrentConfig); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6217 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 6218 | mFragments.dumpLoaders(innerPrefix, fd, writer, args); |
| 6219 | mFragments.getFragmentManager().dump(innerPrefix, fd, writer, args); |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 6220 | if (mVoiceInteractor != null) { |
| 6221 | mVoiceInteractor.dump(innerPrefix, fd, writer, args); |
| 6222 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6223 | |
Michael Wright | 5f48dc7 | 2013-11-01 12:42:49 -0700 | [diff] [blame] | 6224 | if (getWindow() != null && |
| 6225 | getWindow().peekDecorView() != null && |
| 6226 | getWindow().peekDecorView().getViewRootImpl() != null) { |
| 6227 | getWindow().peekDecorView().getViewRootImpl().dump(prefix, fd, writer, args); |
| 6228 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6229 | |
| 6230 | mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6234 | * Bit indicating that this activity is "immersive" and should not be |
| 6235 | * interrupted by notifications if possible. |
| 6236 | * |
| 6237 | * This value is initially set by the manifest property |
| 6238 | * <code>android:immersive</code> but may be changed at runtime by |
| 6239 | * {@link #setImmersive}. |
| 6240 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 6241 | * @see #setImmersive(boolean) |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6242 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 6243 | */ |
| 6244 | public boolean isImmersive() { |
| 6245 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6246 | return ActivityManager.getService().isImmersive(mToken); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6247 | } catch (RemoteException e) { |
| 6248 | return false; |
| 6249 | } |
| 6250 | } |
| 6251 | |
| 6252 | /** |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6253 | * Indication of whether this is the highest level activity in this task. Can be used to |
| 6254 | * determine whether an activity launched by this activity was placed in the same task or |
| 6255 | * another task. |
| 6256 | * |
| 6257 | * @return true if this is the topmost, non-finishing activity in its task. |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6258 | */ |
George Mount | ff24328 | 2014-07-07 16:12:07 -0700 | [diff] [blame] | 6259 | private boolean isTopOfTask() { |
George Mount | f43ea5d | 2016-05-26 09:52:53 -0700 | [diff] [blame] | 6260 | if (mToken == null || mWindow == null) { |
George Mount | d0ca0e0 | 2016-03-29 10:32:56 -0700 | [diff] [blame] | 6261 | return false; |
| 6262 | } |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6263 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6264 | return ActivityManager.getService().isTopOfTask(getActivityToken()); |
Craig Mautner | d61dc20 | 2014-07-07 11:09:11 -0700 | [diff] [blame] | 6265 | } catch (RemoteException e) { |
| 6266 | return false; |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | /** |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6271 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} to a |
| 6272 | * fullscreen opaque Activity. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6273 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6274 | * Call this whenever the background of a translucent Activity has changed to become opaque. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6275 | * Doing so will allow the {@link android.view.Surface} of the Activity behind to be released. |
| 6276 | * <p> |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6277 | * This call has no effect on non-translucent activities or on activities with the |
| 6278 | * {@link android.R.attr#windowIsFloating} attribute. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6279 | * |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6280 | * @see #convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 6281 | * ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6282 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 6283 | * |
| 6284 | * @hide |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6285 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6286 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6287 | public void convertFromTranslucent() { |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6288 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6289 | mTranslucentCallback = null; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6290 | if (ActivityManager.getService().convertFromTranslucent(mToken)) { |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6291 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, true); |
| 6292 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 6293 | } catch (RemoteException e) { |
| 6294 | // pass |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6299 | * Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} back from |
| 6300 | * opaque to translucent following a call to {@link #convertFromTranslucent()}. |
| 6301 | * <p> |
| 6302 | * Calling this allows the Activity behind this one to be seen again. Once all such Activities |
| 6303 | * have been redrawn {@link TranslucentConversionListener#onTranslucentConversionComplete} will |
| 6304 | * be called indicating that it is safe to make this activity translucent again. Until |
| 6305 | * {@link TranslucentConversionListener#onTranslucentConversionComplete} is called the image |
| 6306 | * behind the frontmost Activity will be indeterminate. |
| 6307 | * <p> |
| 6308 | * This call has no effect on non-translucent activities or on activities with the |
| 6309 | * {@link android.R.attr#windowIsFloating} attribute. |
| 6310 | * |
| 6311 | * @param callback the method to call when all visible Activities behind this one have been |
| 6312 | * drawn and it is safe to make this Activity translucent again. |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6313 | * @param options activity options delivered to the activity below this one. The options |
| 6314 | * are retrieved using {@link #getActivityOptions}. |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6315 | * @return <code>true</code> if Window was opaque and will become translucent or |
| 6316 | * <code>false</code> if window was translucent and no change needed to be made. |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6317 | * |
| 6318 | * @see #convertFromTranslucent() |
| 6319 | * @see TranslucentConversionListener |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 6320 | * |
| 6321 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6322 | */ |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6323 | @SystemApi |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6324 | public boolean convertToTranslucent(TranslucentConversionListener callback, |
Jose Lima | 5517ea7 | 2014-06-10 12:31:43 -0700 | [diff] [blame] | 6325 | ActivityOptions options) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6326 | boolean drawComplete; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6327 | try { |
| 6328 | mTranslucentCallback = callback; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6329 | mChangeCanvasToTranslucent = ActivityManager.getService().convertToTranslucent( |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6330 | mToken, options == null ? null : options.toBundle()); |
George Mount | 9e18397 | 2014-09-03 12:35:09 -0700 | [diff] [blame] | 6331 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6332 | drawComplete = true; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6333 | } catch (RemoteException e) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6334 | // Make callback return as though it timed out. |
| 6335 | mChangeCanvasToTranslucent = false; |
| 6336 | drawComplete = false; |
| 6337 | } |
| 6338 | if (!mChangeCanvasToTranslucent && mTranslucentCallback != null) { |
| 6339 | // Window is already translucent. |
| 6340 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6341 | } |
George Mount | 3cc716c | 2014-06-12 16:35:35 -0700 | [diff] [blame] | 6342 | return mChangeCanvasToTranslucent; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | /** @hide */ |
| 6346 | void onTranslucentConversionComplete(boolean drawComplete) { |
| 6347 | if (mTranslucentCallback != null) { |
| 6348 | mTranslucentCallback.onTranslucentConversionComplete(drawComplete); |
| 6349 | mTranslucentCallback = null; |
| 6350 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6351 | if (mChangeCanvasToTranslucent) { |
| 6352 | WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); |
| 6353 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6354 | } |
| 6355 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 6356 | /** @hide */ |
| 6357 | public void onNewActivityOptions(ActivityOptions options) { |
| 6358 | mActivityTransitionState.setEnterActivityOptions(this, options); |
| 6359 | if (!mStopped) { |
| 6360 | mActivityTransitionState.enterReady(this); |
| 6361 | } |
| 6362 | } |
| 6363 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6364 | /** |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6365 | * Retrieve the ActivityOptions passed in from the launching activity or passed back |
| 6366 | * from an activity launched by this activity in its call to {@link |
| 6367 | * #convertToTranslucent(TranslucentConversionListener, ActivityOptions)} |
| 6368 | * |
| 6369 | * @return The ActivityOptions passed to {@link #convertToTranslucent}. |
| 6370 | * @hide |
| 6371 | */ |
| 6372 | ActivityOptions getActivityOptions() { |
| 6373 | try { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6374 | return ActivityOptions.fromBundle( |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6375 | ActivityManager.getService().getActivityOptions(mToken)); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 6376 | } catch (RemoteException e) { |
| 6377 | } |
| 6378 | return null; |
| 6379 | } |
| 6380 | |
| 6381 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6382 | * Activities that want to remain visible behind a translucent activity above them must call |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 6383 | * this method anytime between the start of {@link #onResume()} and the return from |
| 6384 | * {@link #onPause()}. If this call is successful then the activity will remain visible after |
| 6385 | * {@link #onPause()} is called, and is allowed to continue playing media in the background. |
| 6386 | * |
| 6387 | * <p>The actions of this call are reset each time that this activity is brought to the |
| 6388 | * front. That is, every time {@link #onResume()} is called the activity will be assumed |
| 6389 | * to not have requested visible behind. Therefore, if you want this activity to continue to |
| 6390 | * be visible in the background you must call this method again. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6391 | * |
| 6392 | * <p>Only fullscreen opaque activities may make this call. I.e. this call is a nop |
| 6393 | * for dialog and translucent activities. |
| 6394 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 6395 | * <p>Under all circumstances, the activity must stop playing and release resources prior to or |
| 6396 | * within a call to {@link #onVisibleBehindCanceled()} or if this call returns false. |
| 6397 | * |
| 6398 | * <p>False will be returned any time this method is called between the return of onPause and |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6399 | * the next call to onResume. |
| 6400 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6401 | * @deprecated This method's functionality is no longer supported as of |
| 6402 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 6403 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6404 | * @param visible true to notify the system that the activity wishes to be visible behind other |
| 6405 | * translucent activities, false to indicate otherwise. Resources must be |
| 6406 | * released when passing false to this method. |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6407 | * |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 6408 | * @return the resulting visibiity state. If true the activity will remain visible beyond |
| 6409 | * {@link #onPause()} if the next activity is translucent or not fullscreen. If false |
| 6410 | * then the activity may not count on being visible behind other translucent activities, |
| 6411 | * and must stop any media playback and release resources. |
| 6412 | * Returning false may occur in lieu of a call to {@link #onVisibleBehindCanceled()} so |
| 6413 | * the return value must be checked. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6414 | * |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6415 | * @see #onVisibleBehindCanceled() |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6416 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6417 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6418 | public boolean requestVisibleBehind(boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6419 | if (!mResumed) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6420 | // Do not permit paused or stopped activities to do this. |
| 6421 | visible = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6422 | } |
| 6423 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6424 | mVisibleBehind = ActivityManager.getService() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6425 | .requestVisibleBehind(mToken, visible) && visible; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6426 | } catch (RemoteException e) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6427 | mVisibleBehind = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6428 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6429 | return mVisibleBehind; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6433 | * Called when a translucent activity over this activity is becoming opaque or another |
| 6434 | * activity is being launched. Activities that override this method must call |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6435 | * <code>super.onVisibleBehindCanceled()</code> or a SuperNotCalledException will be thrown. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6436 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6437 | * <p>When this method is called the activity has 500 msec to release any resources it may be |
| 6438 | * using while visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6439 | * If the activity has not returned from this method in 500 msec the system will destroy |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6440 | * the activity and kill the process in order to recover the resources for another |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6441 | * process. Otherwise {@link #onStop()} will be called following return. |
| 6442 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6443 | * @see #requestVisibleBehind(boolean) |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6444 | * |
| 6445 | * @deprecated This method's functionality is no longer supported as of |
| 6446 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6447 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6448 | @Deprecated |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 6449 | @CallSuper |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6450 | public void onVisibleBehindCanceled() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6451 | mCalled = true; |
| 6452 | } |
| 6453 | |
| 6454 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6455 | * Translucent activities may call this to determine if there is an activity below them that |
| 6456 | * is currently set to be visible in the background. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6457 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6458 | * @deprecated This method's functionality is no longer supported as of |
| 6459 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 6460 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6461 | * @return true if an activity below is set to visible according to the most recent call to |
| 6462 | * {@link #requestVisibleBehind(boolean)}, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6463 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6464 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6465 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6466 | * @see #onBackgroundVisibleBehindChanged(boolean) |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6467 | * @hide |
| 6468 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6469 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6470 | @SystemApi |
| 6471 | public boolean isBackgroundVisibleBehind() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6472 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6473 | return ActivityManager.getService().isBackgroundVisibleBehind(mToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6474 | } catch (RemoteException e) { |
| 6475 | } |
| 6476 | return false; |
| 6477 | } |
| 6478 | |
| 6479 | /** |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6480 | * The topmost foreground activity will receive this call when the background visibility state |
| 6481 | * of the activity below it changes. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6482 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6483 | * This call may be a consequence of {@link #requestVisibleBehind(boolean)} or might be |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6484 | * due to a background activity finishing itself. |
| 6485 | * |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6486 | * @deprecated This method's functionality is no longer supported as of |
| 6487 | * {@link android.os.Build.VERSION_CODES#O} and will be removed in a future release. |
| 6488 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6489 | * @param visible true if a background activity is visible, false otherwise. |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6490 | * |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6491 | * @see #requestVisibleBehind(boolean) |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 6492 | * @see #onVisibleBehindCanceled() |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6493 | * @hide |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6494 | */ |
Bryce Lee | d59629e | 2017-04-18 14:35:29 -0700 | [diff] [blame] | 6495 | @Deprecated |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 6496 | @SystemApi |
| 6497 | public void onBackgroundVisibleBehindChanged(boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | /** |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 6501 | * Activities cannot draw during the period that their windows are animating in. In order |
| 6502 | * to know when it is safe to begin drawing they can override this method which will be |
| 6503 | * called when the entering animation has completed. |
| 6504 | */ |
| 6505 | public void onEnterAnimationComplete() { |
| 6506 | } |
| 6507 | |
| 6508 | /** |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 6509 | * @hide |
| 6510 | */ |
| 6511 | public void dispatchEnterAnimationComplete() { |
| 6512 | onEnterAnimationComplete(); |
| 6513 | if (getWindow() != null && getWindow().getDecorView() != null) { |
| 6514 | getWindow().getDecorView().getViewTreeObserver().dispatchOnEnterAnimationComplete(); |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | /** |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6519 | * Adjust the current immersive mode setting. |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 6520 | * |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6521 | * Note that changing this value will have no effect on the activity's |
| 6522 | * {@link android.content.pm.ActivityInfo} structure; that is, if |
| 6523 | * <code>android:immersive</code> is set to <code>true</code> |
| 6524 | * in the application's manifest entry for this activity, the {@link |
| 6525 | * android.content.pm.ActivityInfo#flags ActivityInfo.flags} member will |
| 6526 | * always have its {@link android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 6527 | * FLAG_IMMERSIVE} bit set. |
| 6528 | * |
Christopher Tate | 73c2aee | 2012-03-15 16:27:14 -0700 | [diff] [blame] | 6529 | * @see #isImmersive() |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6530 | * @see android.content.pm.ActivityInfo#FLAG_IMMERSIVE |
| 6531 | */ |
| 6532 | public void setImmersive(boolean i) { |
| 6533 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6534 | ActivityManager.getService().setImmersive(mToken, i); |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 6535 | } catch (RemoteException e) { |
| 6536 | // pass |
| 6537 | } |
| 6538 | } |
| 6539 | |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6540 | /** |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 6541 | * Enable or disable virtual reality (VR) mode for this Activity. |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6542 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 6543 | * <p>VR mode is a hint to Android system to switch to a mode optimized for VR applications |
| 6544 | * while this Activity has user focus.</p> |
| 6545 | * |
| 6546 | * <p>It is recommended that applications additionally declare |
| 6547 | * {@link android.R.attr#enableVrMode} in their manifest to allow for smooth activity |
| 6548 | * transitions when switching between VR activities.</p> |
| 6549 | * |
| 6550 | * <p>If the requested {@link android.service.vr.VrListenerService} component is not available, |
| 6551 | * VR mode will not be started. Developers can handle this case as follows:</p> |
| 6552 | * |
| 6553 | * <pre> |
| 6554 | * String servicePackage = "com.whatever.app"; |
| 6555 | * String serviceClass = "com.whatever.app.MyVrListenerService"; |
| 6556 | * |
| 6557 | * // Name of the component of the VrListenerService to start. |
| 6558 | * ComponentName serviceComponent = new ComponentName(servicePackage, serviceClass); |
| 6559 | * |
| 6560 | * try { |
| 6561 | * setVrModeEnabled(true, myComponentName); |
| 6562 | * } catch (PackageManager.NameNotFoundException e) { |
| 6563 | * List<ApplicationInfo> installed = getPackageManager().getInstalledApplications(0); |
| 6564 | * boolean isInstalled = false; |
| 6565 | * for (ApplicationInfo app : installed) { |
| 6566 | * if (app.packageName.equals(servicePackage)) { |
| 6567 | * isInstalled = true; |
| 6568 | * break; |
| 6569 | * } |
| 6570 | * } |
| 6571 | * if (isInstalled) { |
| 6572 | * // Package is installed, but not enabled in Settings. Let user enable it. |
| 6573 | * startActivity(new Intent(Settings.ACTION_VR_LISTENER_SETTINGS)); |
| 6574 | * } else { |
| 6575 | * // Package is not installed. Send an intent to download this. |
| 6576 | * sentIntentToLaunchAppStore(servicePackage); |
| 6577 | * } |
| 6578 | * } |
| 6579 | * </pre> |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6580 | * |
| 6581 | * @param enabled {@code true} to enable this mode. |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 6582 | * @param requestedComponent the name of the component to use as a |
| 6583 | * {@link android.service.vr.VrListenerService} while VR mode is enabled. |
| 6584 | * |
Ruben Brunk | 927d345 | 2016-05-02 19:30:51 -0700 | [diff] [blame] | 6585 | * @throws android.content.pm.PackageManager.NameNotFoundException if the given component |
| 6586 | * to run as a {@link android.service.vr.VrListenerService} is not installed, or has |
| 6587 | * not been enabled in user settings. |
| 6588 | * |
| 6589 | * @see android.content.pm.PackageManager#FEATURE_VR_MODE |
| 6590 | * @see android.content.pm.PackageManager#FEATURE_VR_MODE_HIGH_PERFORMANCE |
| 6591 | * @see android.service.vr.VrListenerService |
| 6592 | * @see android.provider.Settings#ACTION_VR_LISTENER_SETTINGS |
| 6593 | * @see android.R.attr#enableVrMode |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6594 | */ |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 6595 | public void setVrModeEnabled(boolean enabled, @NonNull ComponentName requestedComponent) |
| 6596 | throws PackageManager.NameNotFoundException { |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6597 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6598 | if (ActivityManager.getService().setVrMode(mToken, enabled, requestedComponent) |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 6599 | != 0) { |
| 6600 | throw new PackageManager.NameNotFoundException( |
| 6601 | requestedComponent.flattenToString()); |
| 6602 | } |
Ruben Brunk | dd18a0b | 2015-12-04 16:16:31 -0800 | [diff] [blame] | 6603 | } catch (RemoteException e) { |
| 6604 | // pass |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6609 | * Start an action mode of the default type {@link ActionMode#TYPE_PRIMARY}. |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6610 | * |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6611 | * @param callback Callback that will manage lifecycle events for this action mode |
| 6612 | * @return The ActionMode that was started, or null if it was canceled |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6613 | * |
| 6614 | * @see ActionMode |
| 6615 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6616 | @Nullable |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 6617 | public ActionMode startActionMode(ActionMode.Callback callback) { |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6618 | return mWindow.getDecorView().startActionMode(callback); |
| 6619 | } |
| 6620 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6621 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6622 | * Start an action mode of the given type. |
| 6623 | * |
| 6624 | * @param callback Callback that will manage lifecycle events for this action mode |
| 6625 | * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}. |
| 6626 | * @return The ActionMode that was started, or null if it was canceled |
| 6627 | * |
| 6628 | * @see ActionMode |
| 6629 | */ |
| 6630 | @Nullable |
| 6631 | public ActionMode startActionMode(ActionMode.Callback callback, int type) { |
| 6632 | return mWindow.getDecorView().startActionMode(callback, type); |
| 6633 | } |
| 6634 | |
| 6635 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6636 | * Give the Activity a chance to control the UI for an action mode requested |
| 6637 | * by the system. |
| 6638 | * |
| 6639 | * <p>Note: If you are looking for a notification callback that an action mode |
| 6640 | * has been started for this activity, see {@link #onActionModeStarted(ActionMode)}.</p> |
| 6641 | * |
| 6642 | * @param callback The callback that should control the new action mode |
| 6643 | * @return The new action mode, or <code>null</code> if the activity does not want to |
| 6644 | * provide special handling for this action mode. (It will be handled by the system.) |
| 6645 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6646 | @Nullable |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6647 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6648 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) { |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6649 | // Only Primary ActionModes are represented in the ActionBar. |
| 6650 | if (mActionModeTypeStarting == ActionMode.TYPE_PRIMARY) { |
| 6651 | initWindowDecorActionBar(); |
| 6652 | if (mActionBar != null) { |
| 6653 | return mActionBar.startActionMode(callback); |
| 6654 | } |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6655 | } |
| 6656 | return null; |
| 6657 | } |
| 6658 | |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6659 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6660 | * {@inheritDoc} |
| 6661 | */ |
| 6662 | @Nullable |
| 6663 | @Override |
| 6664 | public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type) { |
| 6665 | try { |
| 6666 | mActionModeTypeStarting = type; |
| 6667 | return onWindowStartingActionMode(callback); |
| 6668 | } finally { |
| 6669 | mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; |
| 6670 | } |
| 6671 | } |
| 6672 | |
| 6673 | /** |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6674 | * Notifies the Activity that an action mode has been started. |
| 6675 | * Activity subclasses overriding this method should call the superclass implementation. |
| 6676 | * |
| 6677 | * @param mode The new action mode. |
| 6678 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 6679 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6680 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6681 | public void onActionModeStarted(ActionMode mode) { |
| 6682 | } |
| 6683 | |
| 6684 | /** |
| 6685 | * Notifies the activity that an action mode has finished. |
| 6686 | * Activity subclasses overriding this method should call the superclass implementation. |
| 6687 | * |
| 6688 | * @param mode The action mode that just finished. |
| 6689 | */ |
Tor Norbye | c615c6f | 2015-03-02 10:11:44 -0800 | [diff] [blame] | 6690 | @CallSuper |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 6691 | @Override |
Adam Powell | debf3be | 2010-11-15 18:58:48 -0800 | [diff] [blame] | 6692 | public void onActionModeFinished(ActionMode mode) { |
| 6693 | } |
| 6694 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6695 | /** |
| 6696 | * Returns true if the app should recreate the task when navigating 'up' from this activity |
| 6697 | * by using targetIntent. |
| 6698 | * |
| 6699 | * <p>If this method returns false the app can trivially call |
| 6700 | * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform |
| 6701 | * up navigation. If this method returns false, the app should synthesize a new task stack |
| 6702 | * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p> |
| 6703 | * |
| 6704 | * @param targetIntent An intent representing the target destination for up navigation |
| 6705 | * @return true if navigating up should recreate a new task stack, false if the same task |
| 6706 | * should be used for the destination |
| 6707 | */ |
| 6708 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 6709 | try { |
| 6710 | PackageManager pm = getPackageManager(); |
| 6711 | ComponentName cn = targetIntent.getComponent(); |
| 6712 | if (cn == null) { |
| 6713 | cn = targetIntent.resolveActivity(pm); |
| 6714 | } |
| 6715 | ActivityInfo info = pm.getActivityInfo(cn, 0); |
| 6716 | if (info.taskAffinity == null) { |
| 6717 | return false; |
| 6718 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6719 | return ActivityManager.getService() |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 6720 | .shouldUpRecreateTask(mToken, info.taskAffinity); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6721 | } catch (RemoteException e) { |
| 6722 | return false; |
| 6723 | } catch (NameNotFoundException e) { |
| 6724 | return false; |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | /** |
| 6729 | * Navigate from this activity to the activity specified by upIntent, finishing this activity |
| 6730 | * in the process. If the activity indicated by upIntent already exists in the task's history, |
| 6731 | * this activity and all others before the indicated activity in the history stack will be |
Adam Powell | 35c064b | 2012-05-02 11:37:15 -0700 | [diff] [blame] | 6732 | * finished. |
| 6733 | * |
| 6734 | * <p>If the indicated activity does not appear in the history stack, this will finish |
| 6735 | * each activity in this task until the root activity of the task is reached, resulting in |
| 6736 | * an "in-app home" behavior. This can be useful in apps with a complex navigation hierarchy |
| 6737 | * when an activity may be reached by a path not passing through a canonical parent |
| 6738 | * activity.</p> |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6739 | * |
| 6740 | * <p>This method should be used when performing up navigation from within the same task |
| 6741 | * as the destination. If up navigation should cross tasks in some cases, see |
| 6742 | * {@link #shouldUpRecreateTask(Intent)}.</p> |
| 6743 | * |
| 6744 | * @param upIntent An intent representing the target destination for up navigation |
| 6745 | * |
| 6746 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 6747 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 6748 | * not be found and this activity was simply finished normally. |
| 6749 | */ |
| 6750 | public boolean navigateUpTo(Intent upIntent) { |
| 6751 | if (mParent == null) { |
| 6752 | ComponentName destInfo = upIntent.getComponent(); |
| 6753 | if (destInfo == null) { |
| 6754 | destInfo = upIntent.resolveActivity(getPackageManager()); |
| 6755 | if (destInfo == null) { |
| 6756 | return false; |
| 6757 | } |
| 6758 | upIntent = new Intent(upIntent); |
| 6759 | upIntent.setComponent(destInfo); |
| 6760 | } |
| 6761 | int resultCode; |
| 6762 | Intent resultData; |
| 6763 | synchronized (this) { |
| 6764 | resultCode = mResultCode; |
| 6765 | resultData = mResultData; |
| 6766 | } |
| 6767 | if (resultData != null) { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6768 | resultData.prepareToLeaveProcess(this); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6769 | } |
| 6770 | try { |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6771 | upIntent.prepareToLeaveProcess(this); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6772 | return ActivityManager.getService().navigateUpTo(mToken, upIntent, |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6773 | resultCode, resultData); |
| 6774 | } catch (RemoteException e) { |
| 6775 | return false; |
| 6776 | } |
| 6777 | } else { |
| 6778 | return mParent.navigateUpToFromChild(this, upIntent); |
| 6779 | } |
| 6780 | } |
| 6781 | |
| 6782 | /** |
| 6783 | * This is called when a child activity of this one calls its |
| 6784 | * {@link #navigateUpTo} method. The default implementation simply calls |
| 6785 | * navigateUpTo(upIntent) on this activity (the parent). |
| 6786 | * |
| 6787 | * @param child The activity making the call. |
| 6788 | * @param upIntent An intent representing the target destination for up navigation |
| 6789 | * |
| 6790 | * @return true if up navigation successfully reached the activity indicated by upIntent and |
| 6791 | * upIntent was delivered to it. false if an instance of the indicated activity could |
| 6792 | * not be found and this activity was simply finished normally. |
| 6793 | */ |
| 6794 | public boolean navigateUpToFromChild(Activity child, Intent upIntent) { |
| 6795 | return navigateUpTo(upIntent); |
| 6796 | } |
| 6797 | |
| 6798 | /** |
| 6799 | * Obtain an {@link Intent} that will launch an explicit target activity specified by |
| 6800 | * this activity's logical parent. The logical parent is named in the application's manifest |
| 6801 | * by the {@link android.R.attr#parentActivityName parentActivityName} attribute. |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 6802 | * Activity subclasses may override this method to modify the Intent returned by |
| 6803 | * super.getParentActivityIntent() or to implement a different mechanism of retrieving |
| 6804 | * the parent intent entirely. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6805 | * |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 6806 | * @return a new Intent targeting the defined parent of this activity or null if |
| 6807 | * there is no valid parent. |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6808 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 6809 | @Nullable |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6810 | public Intent getParentActivityIntent() { |
Adam Powell | 04d5811 | 2012-04-09 10:22:12 -0700 | [diff] [blame] | 6811 | final String parentName = mActivityInfo.parentActivityName; |
| 6812 | if (TextUtils.isEmpty(parentName)) { |
| 6813 | return null; |
| 6814 | } |
Adam Powell | 5a4010c | 2012-09-16 15:14:05 -0700 | [diff] [blame] | 6815 | |
| 6816 | // If the parent itself has no parent, generate a main activity intent. |
| 6817 | final ComponentName target = new ComponentName(this, parentName); |
| 6818 | try { |
| 6819 | final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0); |
| 6820 | final String parentActivity = parentInfo.parentActivityName; |
| 6821 | final Intent parentIntent = parentActivity == null |
| 6822 | ? Intent.makeMainActivity(target) |
| 6823 | : new Intent().setComponent(target); |
| 6824 | return parentIntent; |
| 6825 | } catch (NameNotFoundException e) { |
| 6826 | Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + |
| 6827 | "' in manifest"); |
| 6828 | return null; |
| 6829 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 6830 | } |
| 6831 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 6832 | /** |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6833 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6834 | * android.view.View, String)} was used to start an Activity, <var>callback</var> |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 6835 | * will be called to handle shared elements on the <i>launched</i> Activity. This requires |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 6836 | * {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 6837 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6838 | * @param callback Used to manipulate shared element transitions on the launched Activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 6839 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6840 | public void setEnterSharedElementCallback(SharedElementCallback callback) { |
| 6841 | if (callback == null) { |
| 6842 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 6843 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6844 | mEnterTransitionListener = callback; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 6845 | } |
| 6846 | |
| 6847 | /** |
| 6848 | * When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6849 | * android.view.View, String)} was used to start an Activity, <var>callback</var> |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 6850 | * will be called to handle shared elements on the <i>launching</i> Activity. Most |
| 6851 | * calls will only come when returning from the started Activity. |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 6852 | * This requires {@link Window#FEATURE_ACTIVITY_TRANSITIONS}. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 6853 | * |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6854 | * @param callback Used to manipulate shared element transitions on the launching Activity. |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 6855 | */ |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6856 | public void setExitSharedElementCallback(SharedElementCallback callback) { |
| 6857 | if (callback == null) { |
| 6858 | callback = SharedElementCallback.NULL_CALLBACK; |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 6859 | } |
George Mount | 6558056 | 2014-08-29 08:15:48 -0700 | [diff] [blame] | 6860 | mExitTransitionListener = callback; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 6861 | } |
| 6862 | |
George Mount | 8c2614c | 2014-06-10 11:12:01 -0700 | [diff] [blame] | 6863 | /** |
| 6864 | * Postpone the entering activity transition when Activity was started with |
| 6865 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 6866 | * android.util.Pair[])}. |
| 6867 | * <p>This method gives the Activity the ability to delay starting the entering and |
| 6868 | * shared element transitions until all data is loaded. Until then, the Activity won't |
| 6869 | * draw into its window, leaving the window transparent. This may also cause the |
| 6870 | * returning animation to be delayed until data is ready. This method should be |
| 6871 | * called in {@link #onCreate(android.os.Bundle)} or in |
| 6872 | * {@link #onActivityReenter(int, android.content.Intent)}. |
| 6873 | * {@link #startPostponedEnterTransition()} must be called to allow the Activity to |
| 6874 | * start the transitions. If the Activity did not use |
| 6875 | * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, |
| 6876 | * android.util.Pair[])}, then this method does nothing.</p> |
| 6877 | */ |
| 6878 | public void postponeEnterTransition() { |
| 6879 | mActivityTransitionState.postponeEnterTransition(); |
| 6880 | } |
| 6881 | |
| 6882 | /** |
| 6883 | * Begin postponed transitions after {@link #postponeEnterTransition()} was called. |
| 6884 | * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() |
| 6885 | * to have your Activity start drawing. |
| 6886 | */ |
| 6887 | public void startPostponedEnterTransition() { |
| 6888 | mActivityTransitionState.startPostponedEnterTransition(); |
| 6889 | } |
| 6890 | |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 6891 | /** |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 6892 | * Create {@link DragAndDropPermissions} object bound to this activity and controlling the |
| 6893 | * access permissions for content URIs associated with the {@link DragEvent}. |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 6894 | * @param event Drag event |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 6895 | * @return The {@link DragAndDropPermissions} object used to control access to the content URIs. |
| 6896 | * Null if no content URIs are associated with the event or if permissions could not be granted. |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 6897 | */ |
Vladislav Kaznacheev | 377c328 | 2016-04-20 14:22:23 -0700 | [diff] [blame] | 6898 | public DragAndDropPermissions requestDragAndDropPermissions(DragEvent event) { |
| 6899 | DragAndDropPermissions dragAndDropPermissions = DragAndDropPermissions.obtain(event); |
| 6900 | if (dragAndDropPermissions != null && dragAndDropPermissions.take(getActivityToken())) { |
| 6901 | return dragAndDropPermissions; |
Vladislav Kaznacheev | b23a757 | 2015-12-18 12:23:43 -0800 | [diff] [blame] | 6902 | } |
| 6903 | return null; |
| 6904 | } |
| 6905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6906 | // ------------------ Internal API ------------------ |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | final void setParent(Activity parent) { |
| 6909 | mParent = parent; |
| 6910 | } |
| 6911 | |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6912 | final void attach(Context context, ActivityThread aThread, |
| 6913 | Instrumentation instr, IBinder token, int ident, |
| 6914 | Application application, Intent intent, ActivityInfo info, |
| 6915 | CharSequence title, Activity parent, String id, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 6916 | NonConfigurationInstances lastNonConfigurationInstances, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 6917 | Configuration config, String referrer, IVoiceInteractor voiceInteractor, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 6918 | Window window, ActivityConfigCallback activityConfigCallback) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6919 | attachBaseContext(context); |
| 6920 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 6921 | mFragments.attachHost(null /*parent*/); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 6922 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 6923 | mWindow = new PhoneWindow(this, window, activityConfigCallback); |
Skuhne | ce2faa5 | 2015-08-11 10:36:38 -0700 | [diff] [blame] | 6924 | mWindow.setWindowControllerCallback(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | mWindow.setCallback(this); |
Adam Powell | 117b695 | 2014-05-05 18:14:56 -0700 | [diff] [blame] | 6926 | mWindow.setOnWindowDismissedCallback(this); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 6927 | mWindow.getLayoutInflater().setPrivateFactory(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6928 | if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { |
| 6929 | mWindow.setSoftInputMode(info.softInputMode); |
| 6930 | } |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 6931 | if (info.uiOptions != 0) { |
| 6932 | mWindow.setUiOptions(info.uiOptions); |
| 6933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6934 | mUiThread = Thread.currentThread(); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 6935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6936 | mMainThread = aThread; |
| 6937 | mInstrumentation = instr; |
| 6938 | mToken = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 6939 | mIdent = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | mApplication = application; |
| 6941 | mIntent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 6942 | mReferrer = referrer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6943 | mComponent = intent.getComponent(); |
| 6944 | mActivityInfo = info; |
| 6945 | mTitle = title; |
| 6946 | mParent = parent; |
| 6947 | mEmbeddedID = id; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 6948 | mLastNonConfigurationInstances = lastNonConfigurationInstances; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 6949 | if (voiceInteractor != null) { |
| 6950 | if (lastNonConfigurationInstances != null) { |
| 6951 | mVoiceInteractor = lastNonConfigurationInstances.voiceInteractor; |
| 6952 | } else { |
| 6953 | mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this, |
| 6954 | Looper.myLooper()); |
| 6955 | } |
| 6956 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6957 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6958 | mWindow.setWindowManager( |
| 6959 | (WindowManager)context.getSystemService(Context.WINDOW_SERVICE), |
| 6960 | mToken, mComponent.flattenToString(), |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 6961 | (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | if (mParent != null) { |
| 6963 | mWindow.setContainer(mParent.getWindow()); |
| 6964 | } |
| 6965 | mWindowManager = mWindow.getWindowManager(); |
| 6966 | mCurrentConfig = config; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 6967 | |
| 6968 | mWindow.setColorMode(info.colorMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | } |
| 6970 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 6971 | /** @hide */ |
| 6972 | public final IBinder getActivityToken() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | return mParent != null ? mParent.getActivityToken() : mToken; |
| 6974 | } |
| 6975 | |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 6976 | final void performCreateCommon() { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 6977 | mVisibleFromClient = !mWindow.getWindowStyle().getBoolean( |
| 6978 | com.android.internal.R.styleable.Window_windowNoDisplay, false); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 6979 | mFragments.dispatchActivityCreated(); |
Eino-Ville Talvala | 563df3b | 2016-06-06 22:04:54 +0000 | [diff] [blame] | 6980 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 6981 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 6982 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 6983 | final void performCreate(Bundle icicle) { |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 6984 | restoreHasCurrentPermissionRequest(icicle); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 6985 | onCreate(icicle); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 6986 | mActivityTransitionState.readState(icicle); |
| 6987 | performCreateCommon(); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | final void performCreate(Bundle icicle, PersistableBundle persistentState) { |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 6991 | restoreHasCurrentPermissionRequest(icicle); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 6992 | onCreate(icicle, persistentState); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 6993 | mActivityTransitionState.readState(icicle); |
| 6994 | performCreateCommon(); |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 6995 | } |
| 6996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | final void performStart() { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 6998 | mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions()); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 6999 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7000 | mCalled = false; |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7001 | mFragments.execPendingActions(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7002 | mInstrumentation.callActivityOnStart(this); |
| 7003 | if (!mCalled) { |
| 7004 | throw new SuperNotCalledException( |
| 7005 | "Activity " + mComponent.toShortString() + |
| 7006 | " did not call through to super.onStart()"); |
| 7007 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7008 | mFragments.dispatchStart(); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7009 | mFragments.reportLoaderStart(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7010 | |
| 7011 | // This property is set for all builds except final release |
| 7012 | boolean isDlwarningEnabled = SystemProperties.getInt("ro.bionic.ld.warning", 0) == 1; |
| 7013 | boolean isAppDebuggable = |
| 7014 | (mApplication.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 7015 | |
| 7016 | if (isAppDebuggable || isDlwarningEnabled) { |
| 7017 | String dlwarning = getDlWarning(); |
| 7018 | if (dlwarning != null) { |
Adam Powell | d93f3b1 | 2016-03-03 08:43:37 -0800 | [diff] [blame] | 7019 | String appName = getApplicationInfo().loadLabel(getPackageManager()) |
| 7020 | .toString(); |
Dimitry Ivanov | 4449ef5 | 2016-02-25 17:41:13 -0800 | [diff] [blame] | 7021 | String warning = "Detected problems with app native libraries\n" + |
| 7022 | "(please consult log for detail):\n" + dlwarning; |
| 7023 | if (isAppDebuggable) { |
| 7024 | new AlertDialog.Builder(this). |
| 7025 | setTitle(appName). |
| 7026 | setMessage(warning). |
| 7027 | setPositiveButton(android.R.string.ok, null). |
| 7028 | setCancelable(false). |
| 7029 | show(); |
| 7030 | } else { |
| 7031 | Toast.makeText(this, appName + "\n" + warning, Toast.LENGTH_LONG).show(); |
| 7032 | } |
| 7033 | } |
| 7034 | } |
| 7035 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 7036 | mActivityTransitionState.enterReady(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7037 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7039 | final void performRestart() { |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7040 | mFragments.noteStateNotSaved(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 7041 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7042 | if (mToken != null && mParent == null) { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7043 | // No need to check mStopped, the roots will check if they were actually stopped. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 7044 | WindowManagerGlobal.getInstance().setStoppedState(mToken, false /* stopped */); |
| 7045 | } |
| 7046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | if (mStopped) { |
| 7048 | mStopped = false; |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7049 | |
| 7050 | synchronized (mManagedCursors) { |
| 7051 | final int N = mManagedCursors.size(); |
| 7052 | for (int i=0; i<N; i++) { |
| 7053 | ManagedCursor mc = mManagedCursors.get(i); |
| 7054 | if (mc.mReleased || mc.mUpdated) { |
| 7055 | if (!mc.mCursor.requery()) { |
Dianne Hackborn | a5445d3 | 2011-09-01 14:38:24 -0700 | [diff] [blame] | 7056 | if (getApplicationInfo().targetSdkVersion |
| 7057 | >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 7058 | throw new IllegalStateException( |
| 7059 | "trying to requery an already closed cursor " |
| 7060 | + mc.mCursor); |
| 7061 | } |
Dianne Hackborn | 185e3e2 | 2011-06-03 15:26:01 -0700 | [diff] [blame] | 7062 | } |
| 7063 | mc.mReleased = false; |
| 7064 | mc.mUpdated = false; |
| 7065 | } |
| 7066 | } |
| 7067 | } |
| 7068 | |
| 7069 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | mInstrumentation.callActivityOnRestart(this); |
| 7071 | if (!mCalled) { |
| 7072 | throw new SuperNotCalledException( |
| 7073 | "Activity " + mComponent.toShortString() + |
| 7074 | " did not call through to super.onRestart()"); |
| 7075 | } |
| 7076 | performStart(); |
| 7077 | } |
| 7078 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7080 | final void performResume() { |
| 7081 | performRestart(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7082 | |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7083 | mFragments.execPendingActions(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7084 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 7085 | mLastNonConfigurationInstances = null; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7087 | mCalled = false; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7088 | // mResumed is set by the instrumentation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7089 | mInstrumentation.callActivityOnResume(this); |
| 7090 | if (!mCalled) { |
| 7091 | throw new SuperNotCalledException( |
| 7092 | "Activity " + mComponent.toShortString() + |
| 7093 | " did not call through to super.onResume()"); |
| 7094 | } |
| 7095 | |
Todd Kennedy | ee8c9c6 | 2014-12-10 14:22:59 -0800 | [diff] [blame] | 7096 | // invisible activities must be finished before onResume() completes |
| 7097 | if (!mVisibleFromClient && !mFinished) { |
| 7098 | Log.w(TAG, "An activity without a UI must call finish() before onResume() completes"); |
| 7099 | if (getApplicationInfo().targetSdkVersion |
| 7100 | > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 7101 | throw new IllegalStateException( |
| 7102 | "Activity " + mComponent.toShortString() + |
| 7103 | " did not call finish() prior to onResume() completing"); |
| 7104 | } |
| 7105 | } |
| 7106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7107 | // Now really resume, and install the current status bar and menu. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | mCalled = false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7109 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7110 | mFragments.dispatchResume(); |
Dianne Hackborn | 445646c | 2010-06-25 15:52:59 -0700 | [diff] [blame] | 7111 | mFragments.execPendingActions(); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7113 | onPostResume(); |
| 7114 | if (!mCalled) { |
| 7115 | throw new SuperNotCalledException( |
| 7116 | "Activity " + mComponent.toShortString() + |
| 7117 | " did not call through to super.onPostResume()"); |
| 7118 | } |
| 7119 | } |
| 7120 | |
| 7121 | final void performPause() { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7122 | mDoReportFullyDrawn = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7123 | mFragments.dispatchPause(); |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7124 | mCalled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | onPause(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 7126 | mResumed = false; |
Dianne Hackborn | e794e9f | 2010-08-24 12:32:10 -0700 | [diff] [blame] | 7127 | if (!mCalled && getApplicationInfo().targetSdkVersion |
| 7128 | >= android.os.Build.VERSION_CODES.GINGERBREAD) { |
| 7129 | throw new SuperNotCalledException( |
| 7130 | "Activity " + mComponent.toShortString() + |
| 7131 | " did not call through to super.onPause()"); |
| 7132 | } |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7133 | mResumed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | final void performUserLeaving() { |
| 7137 | onUserInteraction(); |
| 7138 | onUserLeaveHint(); |
| 7139 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7140 | |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7141 | final void performStop(boolean preserveWindow) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 7142 | mDoReportFullyDrawn = false; |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7143 | mFragments.doLoaderStop(mChangingConfigurations /*retain*/); |
Narayan Kamath | ff5659f | 2017-02-02 13:31:33 +0000 | [diff] [blame] | 7144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | if (!mStopped) { |
| 7146 | if (mWindow != null) { |
| 7147 | mWindow.closeAllPanels(); |
| 7148 | } |
| 7149 | |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 7150 | // If we're preserving the window, don't setStoppedState to true, since we |
| 7151 | // need the window started immediately again. Stopping the window will |
| 7152 | // destroys hardware resources and causes flicker. |
| 7153 | if (!preserveWindow && mToken != null && mParent == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7154 | WindowManagerGlobal.getInstance().setStoppedState(mToken, true); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 7155 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7156 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7157 | mFragments.dispatchStop(); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7159 | mCalled = false; |
| 7160 | mInstrumentation.callActivityOnStop(this); |
| 7161 | if (!mCalled) { |
| 7162 | throw new SuperNotCalledException( |
| 7163 | "Activity " + mComponent.toShortString() + |
| 7164 | " did not call through to super.onStop()"); |
| 7165 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 7166 | |
Makoto Onuki | 2f6a018 | 2010-02-22 13:26:59 -0800 | [diff] [blame] | 7167 | synchronized (mManagedCursors) { |
| 7168 | final int N = mManagedCursors.size(); |
| 7169 | for (int i=0; i<N; i++) { |
| 7170 | ManagedCursor mc = mManagedCursors.get(i); |
| 7171 | if (!mc.mReleased) { |
| 7172 | mc.mCursor.deactivate(); |
| 7173 | mc.mReleased = true; |
| 7174 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7175 | } |
| 7176 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7178 | mStopped = true; |
| 7179 | } |
| 7180 | mResumed = false; |
| 7181 | } |
| 7182 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7183 | final void performDestroy() { |
Dianne Hackborn | 6d9dcbc | 2012-10-02 17:51:13 -0700 | [diff] [blame] | 7184 | mDestroyed = true; |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 7185 | mWindow.destroy(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7186 | mFragments.dispatchDestroy(); |
| 7187 | onDestroy(); |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7188 | mFragments.doLoaderDestroy(); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 7189 | if (mVoiceInteractor != null) { |
| 7190 | mVoiceInteractor.detachActivity(); |
| 7191 | } |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 7192 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7193 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7194 | final void dispatchMultiWindowModeChanged(boolean isInMultiWindowMode, |
| 7195 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7196 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7197 | "dispatchMultiWindowModeChanged " + this + ": " + isInMultiWindowMode |
| 7198 | + " " + newConfig); |
| 7199 | mFragments.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7200 | if (mWindow != null) { |
| 7201 | mWindow.onMultiWindowModeChanged(); |
| 7202 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7203 | onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7204 | } |
| 7205 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7206 | final void dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 7207 | Configuration newConfig) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7208 | if (DEBUG_LIFECYCLE) Slog.v(TAG, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7209 | "dispatchPictureInPictureModeChanged " + this + ": " + isInPictureInPictureMode |
| 7210 | + " " + newConfig); |
| 7211 | mFragments.dispatchPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 7212 | if (mWindow != null) { |
| 7213 | mWindow.onPictureInPictureModeChanged(isInPictureInPictureMode); |
| 7214 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 7215 | onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 7216 | } |
| 7217 | |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7218 | /** |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 7219 | * @hide |
| 7220 | */ |
| 7221 | public final boolean isResumed() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7222 | return mResumed; |
| 7223 | } |
| 7224 | |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 7225 | private void storeHasCurrentPermissionRequest(Bundle bundle) { |
| 7226 | if (bundle != null && mHasCurrentPermissionsRequest) { |
| 7227 | bundle.putBoolean(HAS_CURENT_PERMISSIONS_REQUEST_KEY, true); |
| 7228 | } |
| 7229 | } |
| 7230 | |
| 7231 | private void restoreHasCurrentPermissionRequest(Bundle bundle) { |
| 7232 | if (bundle != null) { |
| 7233 | mHasCurrentPermissionsRequest = bundle.getBoolean( |
| 7234 | HAS_CURENT_PERMISSIONS_REQUEST_KEY, false); |
| 7235 | } |
| 7236 | } |
| 7237 | |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 7238 | void dispatchActivityResult(String who, int requestCode, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | int resultCode, Intent data) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 7240 | if (false) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7241 | TAG, "Dispatching result: who=" + who + ", reqCode=" + requestCode |
| 7242 | + ", resCode=" + resultCode + ", data=" + data); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 7243 | mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7244 | if (who == null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7245 | onActivityResult(requestCode, resultCode, data); |
| 7246 | } else if (who.startsWith(REQUEST_PERMISSIONS_WHO_PREFIX)) { |
| 7247 | who = who.substring(REQUEST_PERMISSIONS_WHO_PREFIX.length()); |
| 7248 | if (TextUtils.isEmpty(who)) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7249 | dispatchRequestPermissionsResult(requestCode, data); |
| 7250 | } else { |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 7251 | Fragment frag = mFragments.findFragmentByWho(who); |
| 7252 | if (frag != null) { |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7253 | dispatchRequestPermissionsResultToFragment(requestCode, data, frag); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7254 | } |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 7255 | } |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7256 | } else if (who.startsWith("@android:view:")) { |
| 7257 | ArrayList<ViewRootImpl> views = WindowManagerGlobal.getInstance().getRootViews( |
| 7258 | getActivityToken()); |
| 7259 | for (ViewRootImpl viewRoot : views) { |
| 7260 | if (viewRoot.getView() != null |
| 7261 | && viewRoot.getView().dispatchActivityResult( |
| 7262 | who, requestCode, resultCode, data)) { |
| 7263 | return; |
| 7264 | } |
| 7265 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7266 | } else if (who.startsWith(AUTO_FILL_AUTH_WHO_PREFIX)) { |
Svet Ganov | 00c771dc | 2017-02-19 00:06:22 -0800 | [diff] [blame] | 7267 | Intent resultData = (resultCode == Activity.RESULT_OK) ? data : null; |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 7268 | getAutofillManager().onAuthenticationResult(requestCode, resultData); |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7269 | } else { |
| 7270 | Fragment frag = mFragments.findFragmentByWho(who); |
| 7271 | if (frag != null) { |
| 7272 | frag.onActivityResult(requestCode, resultCode, data); |
| 7273 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | } |
| 7275 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7276 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7277 | /** |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 7278 | * Request to put this Activity in a mode where the user is locked to the |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7279 | * current task. |
| 7280 | * |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7281 | * This will prevent the user from launching other apps, going to settings, or reaching the |
| 7282 | * home screen. This does not include those apps whose {@link android.R.attr#lockTaskMode} |
| 7283 | * values permit launching while locked. |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7284 | * |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7285 | * If {@link DevicePolicyManager#isLockTaskPermitted(String)} returns true or |
| 7286 | * lockTaskMode=lockTaskModeAlways for this component then the app will go directly into |
| 7287 | * Lock Task mode. The user will not be able to exit this mode until |
| 7288 | * {@link Activity#stopLockTask()} is called. |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 7289 | * |
| 7290 | * If {@link DevicePolicyManager#isLockTaskPermitted(String)} returns false |
| 7291 | * then the system will prompt the user with a dialog requesting permission to enter |
Jason Monk | 8863b57 | 2014-07-29 13:49:32 -0400 | [diff] [blame] | 7292 | * this mode. When entered through this method the user can exit at any time through |
| 7293 | * an action described by the request dialog. Calling stopLockTask will also exit the |
| 7294 | * mode. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7295 | * |
| 7296 | * @see android.R.attr#lockTaskMode |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7297 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7298 | public void startLockTask() { |
| 7299 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7300 | ActivityManager.getService().startLockTaskModeByToken(mToken); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7301 | } catch (RemoteException e) { |
| 7302 | } |
| 7303 | } |
| 7304 | |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7305 | /** |
| 7306 | * Allow the user to switch away from the current task. |
| 7307 | * |
| 7308 | * Called to end the mode started by {@link Activity#startLockTask}. This |
| 7309 | * can only be called by activities that have successfully called |
| 7310 | * startLockTask previously. |
| 7311 | * |
| 7312 | * This will allow the user to exit this app and move onto other activities. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 7313 | * <p>Note: This method should only be called when the activity is user-facing. That is, |
| 7314 | * between onResume() and onPause(). |
| 7315 | * <p>Note: If there are other tasks below this one that are also locked then calling this |
| 7316 | * method will immediately finish this task and resume the previous locked one, remaining in |
| 7317 | * lockTask mode. |
| 7318 | * |
| 7319 | * @see android.R.attr#lockTaskMode |
| 7320 | * @see ActivityManager#getLockTaskModeState() |
Jason Monk | a57e5e0 | 2014-05-07 10:06:48 -0400 | [diff] [blame] | 7321 | */ |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7322 | public void stopLockTask() { |
| 7323 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7324 | ActivityManager.getService().stopLockTaskMode(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 7325 | } catch (RemoteException e) { |
| 7326 | } |
| 7327 | } |
| 7328 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7329 | /** |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 7330 | * Shows the user the system defined message for telling the user how to exit |
| 7331 | * lock task mode. The task containing this activity must be in lock task mode at the time |
| 7332 | * of this call for the message to be displayed. |
| 7333 | */ |
| 7334 | public void showLockTaskEscapeMessage() { |
| 7335 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7336 | ActivityManager.getService().showLockTaskEscapeMessage(mToken); |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 7337 | } catch (RemoteException e) { |
| 7338 | } |
| 7339 | } |
| 7340 | |
| 7341 | /** |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 7342 | * Check whether the caption on freeform windows is displayed directly on the content. |
| 7343 | * |
| 7344 | * @return True if caption is displayed on content, false if it pushes the content down. |
| 7345 | * |
Elliot Waite | d5ed3bc | 2017-01-25 15:22:55 -0800 | [diff] [blame] | 7346 | * @see #setOverlayWithDecorCaptionEnabled(boolean) |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 7347 | * @hide |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 7348 | */ |
| 7349 | public boolean isOverlayWithDecorCaptionEnabled() { |
| 7350 | return mWindow.isOverlayWithDecorCaptionEnabled(); |
| 7351 | } |
| 7352 | |
| 7353 | /** |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 7354 | * Set whether the caption should displayed directly on the content rather than push it down. |
| 7355 | * |
| 7356 | * This affects only freeform windows since they display the caption and only the main |
| 7357 | * window of the activity. The caption is used to drag the window around and also shows |
| 7358 | * maximize and close action buttons. |
Wale Ogunwale | 724ca14 | 2017-04-24 13:40:34 -0700 | [diff] [blame] | 7359 | * @hide |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 7360 | */ |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 7361 | public void setOverlayWithDecorCaptionEnabled(boolean enabled) { |
| 7362 | mWindow.setOverlayWithDecorCaptionEnabled(enabled); |
Filip Gruszczynski | 6325065 | 2015-11-18 14:43:01 -0800 | [diff] [blame] | 7363 | } |
| 7364 | |
| 7365 | /** |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7366 | * Interface for informing a translucent {@link Activity} once all visible activities below it |
| 7367 | * have completed drawing. This is necessary only after an {@link Activity} has been made |
| 7368 | * opaque using {@link Activity#convertFromTranslucent()} and before it has been drawn |
| 7369 | * translucent again following a call to {@link |
George Mount | 800d72b | 2014-05-19 07:09:00 -0700 | [diff] [blame] | 7370 | * Activity#convertToTranslucent(android.app.Activity.TranslucentConversionListener, |
| 7371 | * ActivityOptions)} |
Chet Haase | abd3d77 | 2013-09-11 14:33:05 -0700 | [diff] [blame] | 7372 | * |
| 7373 | * @hide |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7374 | */ |
Jose Lima | 1491485 | 2014-08-14 09:14:12 -0700 | [diff] [blame] | 7375 | @SystemApi |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7376 | public interface TranslucentConversionListener { |
| 7377 | /** |
| 7378 | * Callback made following {@link Activity#convertToTranslucent} once all visible Activities |
| 7379 | * below the top one have been redrawn. Following this callback it is safe to make the top |
| 7380 | * Activity translucent because the underlying Activity has been drawn. |
| 7381 | * |
| 7382 | * @param drawComplete True if the background Activity has drawn itself. False if a timeout |
| 7383 | * occurred waiting for the Activity to complete drawing. |
| 7384 | * |
| 7385 | * @see Activity#convertFromTranslucent() |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 7386 | * @see Activity#convertToTranslucent(TranslucentConversionListener, ActivityOptions) |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7387 | */ |
| 7388 | public void onTranslucentConversionComplete(boolean drawComplete); |
| 7389 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7390 | |
| 7391 | private void dispatchRequestPermissionsResult(int requestCode, Intent data) { |
Svetoslav | ffb32b1 | 2015-10-15 16:54:00 -0700 | [diff] [blame] | 7392 | mHasCurrentPermissionsRequest = false; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 7393 | // If the package installer crashed we may have not data - best effort. |
| 7394 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 7395 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 7396 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 7397 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7398 | onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 7399 | } |
| 7400 | |
| 7401 | private void dispatchRequestPermissionsResultToFragment(int requestCode, Intent data, |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 7402 | Fragment fragment) { |
| 7403 | // If the package installer crashed we may have not data - best effort. |
| 7404 | String[] permissions = (data != null) ? data.getStringArrayExtra( |
| 7405 | PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0]; |
| 7406 | final int[] grantResults = (data != null) ? data.getIntArrayExtra( |
| 7407 | PackageManager.EXTRA_REQUEST_PERMISSIONS_RESULTS) : new int[0]; |
| 7408 | fragment.onRequestPermissionsResult(requestCode, permissions, grantResults); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 7409 | } |
| 7410 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7411 | /** @hide */ |
| 7412 | @Override |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 7413 | final public void autofillCallbackAuthenticate(int authenticationId, IntentSender intent, |
| 7414 | Intent fillInIntent) { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7415 | try { |
| 7416 | startIntentSenderForResultInner(intent, AUTO_FILL_AUTH_WHO_PREFIX, |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 7417 | authenticationId, fillInIntent, 0, 0, null); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 7418 | } catch (IntentSender.SendIntentException e) { |
| 7419 | Log.e(TAG, "authenticate() failed for intent:" + intent, e); |
| 7420 | } |
| 7421 | } |
| 7422 | |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 7423 | /** @hide */ |
| 7424 | @Override |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7425 | final public void autofillCallbackResetableStateAvailable() { |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 7426 | mAutoFillResetNeeded = true; |
| 7427 | } |
| 7428 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7429 | /** @hide */ |
| 7430 | @Override |
| 7431 | final public boolean autofillCallbackRequestShowFillUi(@NonNull View anchor, int width, |
| 7432 | int height, @Nullable Rect anchorBounds, IAutofillWindowPresenter presenter) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7433 | final boolean wasShowing; |
| 7434 | |
| 7435 | if (mAutofillPopupWindow == null) { |
| 7436 | wasShowing = false; |
| 7437 | mAutofillPopupWindow = new AutofillPopupWindow(presenter); |
| 7438 | } else { |
| 7439 | wasShowing = mAutofillPopupWindow.isShowing(); |
| 7440 | } |
Svet Ganov | 374cae1 | 2017-05-10 13:42:33 -0700 | [diff] [blame] | 7441 | mAutofillPopupWindow.update(anchor, 0, 0, width, height, anchorBounds); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 7442 | |
| 7443 | return !wasShowing && mAutofillPopupWindow.isShowing(); |
| 7444 | } |
| 7445 | |
| 7446 | /** @hide */ |
| 7447 | @Override |
| 7448 | final public boolean autofillCallbackRequestHideFillUi() { |
| 7449 | if (mAutofillPopupWindow == null) { |
| 7450 | return false; |
| 7451 | } |
| 7452 | mAutofillPopupWindow.dismiss(); |
| 7453 | mAutofillPopupWindow = null; |
| 7454 | return true; |
| 7455 | } |
| 7456 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7457 | /** @hide */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 7458 | @Override |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 7459 | @NonNull public View[] findViewsByAutofillIdTraversal(@NonNull int[] viewIds) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7460 | final View[] views = new View[viewIds.length]; |
| 7461 | final ArrayList<ViewRootImpl> roots = |
| 7462 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 7463 | |
| 7464 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 7465 | final View rootView = roots.get(rootNum).getView(); |
| 7466 | |
| 7467 | if (rootView != null) { |
| 7468 | for (int viewNum = 0; viewNum < viewIds.length; viewNum++) { |
| 7469 | if (views[viewNum] == null) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 7470 | views[viewNum] = rootView.findViewByAutofillIdTraversal( |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7471 | viewIds[viewNum]); |
| 7472 | } |
| 7473 | } |
| 7474 | } |
| 7475 | } |
| 7476 | |
| 7477 | return views; |
| 7478 | } |
| 7479 | |
| 7480 | /** @hide */ |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7481 | @Override |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 7482 | @Nullable public View findViewByAutofillIdTraversal(int viewId) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 7483 | final ArrayList<ViewRootImpl> roots = |
| 7484 | WindowManagerGlobal.getInstance().getRootViews(getActivityToken()); |
| 7485 | for (int rootNum = 0; rootNum < roots.size(); rootNum++) { |
| 7486 | final View rootView = roots.get(rootNum).getView(); |
| 7487 | |
| 7488 | if (rootView != null) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 7489 | final View view = rootView.findViewByAutofillIdTraversal(viewId); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 7490 | if (view != null) { |
| 7491 | return view; |
| 7492 | } |
| 7493 | } |
| 7494 | } |
| 7495 | |
| 7496 | return null; |
| 7497 | } |
| 7498 | |
| 7499 | /** @hide */ |
| 7500 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7501 | @NonNull public boolean[] getViewVisibility(@NonNull int[] viewIds) { |
| 7502 | final boolean[] isVisible = new boolean[viewIds.length]; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 7503 | final View views[] = findViewsByAutofillIdTraversal(viewIds); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7504 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7505 | for (int i = 0; i < viewIds.length; i++) { |
| 7506 | View view = views[i]; |
| 7507 | if (view == null) { |
| 7508 | isVisible[i] = false; |
| 7509 | continue; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7510 | } |
| 7511 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7512 | isVisible[i] = true; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7513 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7514 | // Check if the view is visible by checking all parents |
| 7515 | while (true) { |
| 7516 | if (view instanceof DecorView && view.getViewRootImpl() == view.getParent()) { |
| 7517 | break; |
| 7518 | } |
| 7519 | |
| 7520 | if (view.getVisibility() != View.VISIBLE) { |
| 7521 | isVisible[i] = false; |
| 7522 | break; |
| 7523 | } |
| 7524 | |
| 7525 | if (view.getParent() instanceof View) { |
| 7526 | view = (View) view.getParent(); |
| 7527 | } else { |
| 7528 | break; |
| 7529 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7530 | } |
| 7531 | } |
| 7532 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 7533 | return isVisible; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 7534 | } |
| 7535 | |
| 7536 | /** @hide */ |
| 7537 | @Override |
| 7538 | public boolean isVisibleForAutofill() { |
| 7539 | return !mStopped; |
| 7540 | } |
| 7541 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 7542 | /** |
| 7543 | * If set to true, this indicates to the system that it should never take a |
| 7544 | * screenshot of the activity to be used as a representation while it is not in a started state. |
| 7545 | * <p> |
| 7546 | * Note that the system may use the window background of the theme instead to represent |
| 7547 | * the window when it is not running. |
| 7548 | * <p> |
| 7549 | * Also note that in comparison to {@link android.view.WindowManager.LayoutParams#FLAG_SECURE}, |
| 7550 | * this only affects the behavior when the activity's screenshot would be used as a |
| 7551 | * representation when the activity is not in a started state, i.e. in Overview. The system may |
| 7552 | * still take screenshots of the activity in other contexts; for example, when the user takes a |
| 7553 | * screenshot of the entire screen, or when the active |
| 7554 | * {@link android.service.voice.VoiceInteractionService} requests a screenshot via |
| 7555 | * {@link android.service.voice.VoiceInteractionSession#SHOW_WITH_SCREENSHOT}. |
| 7556 | * |
| 7557 | * @param disable {@code true} to disable preview screenshots; {@code false} otherwise. |
| 7558 | * @hide |
| 7559 | */ |
| 7560 | @SystemApi |
| 7561 | public void setDisablePreviewScreenshots(boolean disable) { |
| 7562 | try { |
| 7563 | ActivityManager.getService().setDisablePreviewScreenshots(mToken, disable); |
| 7564 | } catch (RemoteException e) { |
| 7565 | Log.e(TAG, "Failed to call setDisablePreviewScreenshots", e); |
| 7566 | } |
| 7567 | } |
| 7568 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7569 | class HostCallbacks extends FragmentHostCallback<Activity> { |
| 7570 | public HostCallbacks() { |
| 7571 | super(Activity.this /*activity*/); |
| 7572 | } |
| 7573 | |
| 7574 | @Override |
| 7575 | public void onDump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 7576 | Activity.this.dump(prefix, fd, writer, args); |
| 7577 | } |
| 7578 | |
| 7579 | @Override |
| 7580 | public boolean onShouldSaveFragmentState(Fragment fragment) { |
| 7581 | return !isFinishing(); |
| 7582 | } |
| 7583 | |
| 7584 | @Override |
| 7585 | public LayoutInflater onGetLayoutInflater() { |
| 7586 | final LayoutInflater result = Activity.this.getLayoutInflater(); |
| 7587 | if (onUseFragmentManagerInflaterFactory()) { |
| 7588 | return result.cloneInContext(Activity.this); |
| 7589 | } |
| 7590 | return result; |
| 7591 | } |
| 7592 | |
| 7593 | @Override |
| 7594 | public boolean onUseFragmentManagerInflaterFactory() { |
| 7595 | // Newer platform versions use the child fragment manager's LayoutInflaterFactory. |
| 7596 | return getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP; |
| 7597 | } |
| 7598 | |
| 7599 | @Override |
| 7600 | public Activity onGetHost() { |
| 7601 | return Activity.this; |
| 7602 | } |
| 7603 | |
| 7604 | @Override |
| 7605 | public void onInvalidateOptionsMenu() { |
| 7606 | Activity.this.invalidateOptionsMenu(); |
| 7607 | } |
| 7608 | |
| 7609 | @Override |
| 7610 | public void onStartActivityFromFragment(Fragment fragment, Intent intent, int requestCode, |
| 7611 | Bundle options) { |
| 7612 | Activity.this.startActivityFromFragment(fragment, intent, requestCode, options); |
| 7613 | } |
| 7614 | |
| 7615 | @Override |
Tony Mak | 96d26fe | 2017-04-11 20:05:39 +0100 | [diff] [blame] | 7616 | public void onStartActivityAsUserFromFragment( |
| 7617 | Fragment fragment, Intent intent, int requestCode, Bundle options, |
| 7618 | UserHandle user) { |
| 7619 | Activity.this.startActivityAsUserFromFragment( |
| 7620 | fragment, intent, requestCode, options, user); |
| 7621 | } |
| 7622 | |
| 7623 | @Override |
Clara Bayarri | a0c2dc3 | 2016-04-12 12:00:15 +0100 | [diff] [blame] | 7624 | public void onStartIntentSenderFromFragment(Fragment fragment, IntentSender intent, |
| 7625 | int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, |
| 7626 | int extraFlags, Bundle options) throws IntentSender.SendIntentException { |
| 7627 | if (mParent == null) { |
| 7628 | startIntentSenderForResultInner(intent, fragment.mWho, requestCode, fillInIntent, |
| 7629 | flagsMask, flagsValues, options); |
| 7630 | } else if (options != null) { |
| 7631 | mParent.startIntentSenderFromChildFragment(fragment, intent, requestCode, |
| 7632 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 7633 | } |
| 7634 | } |
| 7635 | |
| 7636 | @Override |
Svetoslav | 970b59c | 2015-06-09 16:05:21 -0700 | [diff] [blame] | 7637 | public void onRequestPermissionsFromFragment(Fragment fragment, String[] permissions, |
| 7638 | int requestCode) { |
| 7639 | String who = REQUEST_PERMISSIONS_WHO_PREFIX + fragment.mWho; |
| 7640 | Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); |
| 7641 | startActivityForResult(who, intent, requestCode, null); |
| 7642 | } |
| 7643 | |
| 7644 | @Override |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7645 | public boolean onHasWindowAnimations() { |
| 7646 | return getWindow() != null; |
| 7647 | } |
| 7648 | |
| 7649 | @Override |
| 7650 | public int onGetWindowAnimations() { |
| 7651 | final Window w = getWindow(); |
| 7652 | return (w == null) ? 0 : w.getAttributes().windowAnimations; |
| 7653 | } |
| 7654 | |
Todd Kennedy | 434bd65 | 2015-05-04 12:29:50 -0700 | [diff] [blame] | 7655 | @Override |
| 7656 | public void onAttachFragment(Fragment fragment) { |
| 7657 | Activity.this.onAttachFragment(fragment); |
| 7658 | } |
| 7659 | |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7660 | @Nullable |
| 7661 | @Override |
Alan Viverette | 04fd470 | 2017-04-13 16:37:06 -0400 | [diff] [blame] | 7662 | public <T extends View> T onFindViewById(int id) { |
Todd Kennedy | a5fc6f0 | 2015-04-14 18:22:54 -0700 | [diff] [blame] | 7663 | return Activity.this.findViewById(id); |
| 7664 | } |
| 7665 | |
| 7666 | @Override |
| 7667 | public boolean onHasView() { |
| 7668 | final Window w = getWindow(); |
| 7669 | return (w != null && w.peekDecorView() != null); |
| 7670 | } |
| 7671 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7672 | } |