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 com.android.car.carlauncher; 18 19 import android.content.Intent; 20 21 /** This class provides the required configuration to create a {@link ControlledCarTaskView}. */ 22 public final class ControlledCarTaskViewConfig { 23 final Intent mActivityIntent; 24 // TODO(b/242861717): When mAutoRestartOnCrash is enabled, mPackagesThatCanRestart doesn't make 25 // a lot of sense. Consider removing it when there is more confidence with mAutoRestartOnCrash. 26 final boolean mAutoRestartOnCrash; 27 final boolean mCaptureGestures; 28 final boolean mCaptureLongPress; 29 ControlledCarTaskViewConfig( Intent activityIntent, boolean autoRestartOnCrash, boolean captureGestures, boolean captureLongPress)30 private ControlledCarTaskViewConfig( 31 Intent activityIntent, 32 boolean autoRestartOnCrash, 33 boolean captureGestures, 34 boolean captureLongPress) { 35 mActivityIntent = activityIntent; 36 mAutoRestartOnCrash = autoRestartOnCrash; 37 mCaptureGestures = captureGestures; 38 mCaptureLongPress = captureLongPress; 39 } 40 41 /** 42 * Creates a {@link Builder} object that is used to create instances of {@link 43 * ControlledCarTaskViewConfig}. 44 */ builder()45 public static Builder builder() { 46 return new Builder(); 47 } 48 49 /** A builder class for {@link ControlledCarTaskViewConfig}. */ 50 public static final class Builder { 51 private Intent mActivityIntent; 52 private boolean mAutoRestartOnCrash; 53 private boolean mCaptureGestures; 54 private boolean mCaptureLongPress; 55 Builder()56 private Builder() {} 57 58 /** 59 * The intent of the activity that is meant to be started in this {@link 60 * ControlledCarTaskView}. 61 */ setActivityIntent(Intent activityIntent)62 public Builder setActivityIntent(Intent activityIntent) { 63 mActivityIntent = activityIntent; 64 return this; 65 } 66 67 /** 68 * Sets the auto restart functionality. If set, the {@link ControlledCarTaskView} will 69 * restart the task by re-launching the intent set via {@link #setActivityIntent(Intent)} 70 * when the task crashes. 71 */ setAutoRestartOnCrash(boolean autoRestartOnCrash)72 public Builder setAutoRestartOnCrash(boolean autoRestartOnCrash) { 73 mAutoRestartOnCrash = autoRestartOnCrash; 74 return this; 75 } 76 77 /** 78 * Enables the swipe gesture capturing over {@link ControlledCarTaskView}. When enabled, the 79 * swipe gestures won't be sent to the embedded app and will instead be forwarded to the 80 * host activity. 81 */ setCaptureGestures(boolean captureGestures)82 public Builder setCaptureGestures(boolean captureGestures) { 83 mCaptureGestures = captureGestures; 84 return this; 85 } 86 87 /** 88 * Enables the long press capturing over {@link ControlledCarTaskView}. When enabled, the 89 * long press won't be sent to the embedded app and will instead be sent to the listener 90 * specified via {@link 91 * ControlledCarTaskView#setOnLongClickListener(View.OnLongClickListener)}. 92 * 93 * <p>If disabled, the listener supplied via {@link 94 * ControlledCarTaskView#setOnLongClickListener(View.OnLongClickListener)} won't be called. 95 */ setCaptureLongPress(boolean captureLongPress)96 public Builder setCaptureLongPress(boolean captureLongPress) { 97 mCaptureLongPress = captureLongPress; 98 return this; 99 } 100 101 /** Creates the {@link ControlledCarTaskViewConfig} object. */ build()102 public ControlledCarTaskViewConfig build() { 103 if (mActivityIntent == null) { 104 throw new IllegalArgumentException("mActivityIntent can't be null"); 105 } 106 return new ControlledCarTaskViewConfig( 107 mActivityIntent, mAutoRestartOnCrash, mCaptureGestures, mCaptureLongPress); 108 } 109 } 110 } 111