1 /* 2 * Copyright (C) 2022 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.car.app; 18 19 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.content.Intent; 23 24 /** 25 * This class provides the required configuration to create a 26 * {@link ControlledRemoteCarTaskView}. 27 * @hide 28 */ 29 @SystemApi 30 public final class ControlledRemoteCarTaskViewConfig { 31 private static final String TAG = ControlledRemoteCarTaskViewConfig.class.getSimpleName(); 32 33 final Intent mActivityIntent; 34 final boolean mShouldAutoRestartOnTaskRemoval; 35 final boolean mShouldCaptureGestures; 36 final boolean mShouldCaptureLongPress; 37 ControlledRemoteCarTaskViewConfig( Intent activityIntent, boolean shouldAutoRestartOnTaskRemoval, boolean shouldCaptureGestures, boolean shouldCaptureLongPress)38 private ControlledRemoteCarTaskViewConfig( 39 Intent activityIntent, 40 boolean shouldAutoRestartOnTaskRemoval, 41 boolean shouldCaptureGestures, 42 boolean shouldCaptureLongPress) { 43 mActivityIntent = activityIntent; 44 mShouldAutoRestartOnTaskRemoval = shouldAutoRestartOnTaskRemoval; 45 mShouldCaptureGestures = shouldCaptureGestures; 46 mShouldCaptureLongPress = shouldCaptureLongPress; 47 } 48 49 /** See {@link Builder#setActivityIntent(Intent)}. */ 50 @NonNull getActivityIntent()51 public Intent getActivityIntent() { 52 return mActivityIntent; 53 } 54 55 /** See {@link Builder#setShouldAutoRestartOnTaskRemoval(boolean)}. */ shouldAutoRestartOnCrash()56 public boolean shouldAutoRestartOnCrash() { 57 return mShouldAutoRestartOnTaskRemoval; 58 } 59 60 /** See {@link Builder#setShouldCaptureGestures(boolean)}. */ shouldCaptureGestures()61 public boolean shouldCaptureGestures() { 62 return mShouldCaptureGestures; 63 } 64 65 /** See {@link Builder#setShouldCaptureLongPress(boolean)}. */ shouldCaptureLongPress()66 public boolean shouldCaptureLongPress() { 67 return mShouldCaptureLongPress; 68 } 69 70 @Override toString()71 public String toString() { 72 return TAG + " {" 73 + "activityIntent=" + mActivityIntent 74 + ", mShouldAutoRestartOnTaskRemoval=" + mShouldAutoRestartOnTaskRemoval 75 + ", shouldCaptureGestures=" + mShouldCaptureGestures 76 + ", shouldCaptureLongPress=" + mShouldCaptureLongPress 77 + '}'; 78 } 79 80 /** 81 * A builder class for {@link ControlledRemoteCarTaskViewConfig}. 82 * @hide 83 */ 84 @SystemApi 85 public static final class Builder { 86 private Intent mActivityIntent; 87 private boolean mShouldAutoRestartOnCrash; 88 private boolean mShouldCaptureGestures; 89 private boolean mShouldCaptureLongPress; 90 Builder()91 public Builder() { 92 } 93 94 /** 95 * Sets the intent of the activity that is meant to be started in this {@link 96 * ControlledRemoteCarTaskView}. 97 * 98 * @param activityIntent the intent of the activity that is meant to be started in this 99 * task view. 100 */ 101 @NonNull setActivityIntent(@onNull Intent activityIntent)102 public Builder setActivityIntent(@NonNull Intent activityIntent) { 103 mActivityIntent = activityIntent; 104 return this; 105 } 106 107 /** 108 * Sets the auto restart functionality. If set, the {@link ControlledRemoteCarTaskView} 109 * will restart the task by re-launching the intent set via {@link 110 * #setActivityIntent(Intent)} when the task is removed. 111 * 112 * The task might get removed because of multiple reasons like: 113 * <ul> 114 * <li>Due to memory pressure</li> 115 * <li>Due to the apk update</li> 116 * <li>etc.</li> 117 * </ul> 118 * 119 * @param shouldAutoRestartOnTaskRemoval denotes if the auto restart functionality should be 120 * enabled or not. 121 */ 122 @NonNull setShouldAutoRestartOnTaskRemoval(boolean shouldAutoRestartOnTaskRemoval)123 public Builder setShouldAutoRestartOnTaskRemoval(boolean shouldAutoRestartOnTaskRemoval) { 124 mShouldAutoRestartOnCrash = shouldAutoRestartOnTaskRemoval; 125 return this; 126 } 127 128 /** 129 * Enables the swipe gesture capturing over {@link ControlledRemoteCarTaskView}. When 130 * enabled, the swipe gestures won't be sent to the embedded app and will instead be 131 * forwarded to the host activity. 132 * 133 * @param shouldCaptureGestures denotes if the swipe gesture capturing should be enabled or 134 * not. 135 */ 136 @NonNull setShouldCaptureGestures(boolean shouldCaptureGestures)137 public Builder setShouldCaptureGestures(boolean shouldCaptureGestures) { 138 mShouldCaptureGestures = shouldCaptureGestures; 139 return this; 140 } 141 142 /** 143 * Enables the long press capturing over {@link ControlledRemoteCarTaskView}. When enabled, 144 * the long press won't be sent to the embedded app and will instead be sent to the listener 145 * specified via {@link 146 * ControlledRemoteCarTaskView#setOnLongClickListener(View.OnLongClickListener)}. 147 * 148 * <p>If disabled, the listener supplied via {@link 149 * ControlledRemoteCarTaskView#setOnLongClickListener(View.OnLongClickListener)} won't be 150 * called. 151 * 152 * @param shouldCaptureLongPress denotes if the long press capturing should be enabled or 153 * not. 154 */ 155 @NonNull setShouldCaptureLongPress(boolean shouldCaptureLongPress)156 public Builder setShouldCaptureLongPress(boolean shouldCaptureLongPress) { 157 mShouldCaptureLongPress = shouldCaptureLongPress; 158 return this; 159 } 160 161 /** Creates the {@link ControlledRemoteCarTaskViewConfig} object. */ 162 @NonNull build()163 public ControlledRemoteCarTaskViewConfig build() { 164 if (mActivityIntent == null) { 165 throw new IllegalArgumentException("mActivityIntent can't be null"); 166 } 167 return new ControlledRemoteCarTaskViewConfig( 168 mActivityIntent, mShouldAutoRestartOnCrash, mShouldCaptureGestures, 169 mShouldCaptureLongPress); 170 } 171 } 172 } 173