1 /*
2  * Copyright (C) 2023 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 package com.android.car.portraitlauncher.panel;
17 
18 import android.annotation.StringDef;
19 import android.content.ComponentName;
20 
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 
24 /**
25  * Reasons why {@link TaskViewPanel}'s {@link TaskViewPanel.State} changes.
26  * TODO(b/338091566): clean this class for better API structure.
27  */
28 public final class TaskViewPanelStateChangeReason {
29     public static final String ON_ACTIVITY_RESTART_ATTEMPT = "ON_ACTIVITY_RESTART_ATTEMPT";
30     public static final String ON_COLLAPSE_MSG = "ON_COLLAPSE_MSG";
31     public static final String ON_DRIVE_STATE_CHANGED = "ON_DRIVE_STATE_CHANGED";
32     public static final String ON_GRIP_BAR_CLICKED = "ON_GRIP_BAR_CLICKED";
33     public static final String ON_GRIP_BAR_DRAG = "ON_GRIP_BAR_DRAG";
34     public static final String ON_HOME_INTENT = "ON_HOME_INTENT";
35     public static final String ON_HOME_SCREEN_LAYOUT_CHANGED = "ON_HOME_SCREEN_LAYOUT_CHANGED";
36     public static final String ON_IMMERSIVE_REQUEST = "ON_IMMERSIVE_REQUEST";
37     public static final String ON_MEDIA_INTENT = "ON_MEDIA_INTENT";
38     public static final String ON_PANEL_STATE_CHANGE_END = "ON_PANEL_STATE_CHANGE_END";
39     public static final String ON_PANEL_READY = "ON_PANEL_READY";
40     public static final String ON_SUW_STATE_CHANGED = "ON_SUW_STATE_CHANGED";
41     public static final String ON_TASK_MOVED_TO_FRONT = "ON_TASK_MOVED_TO_FRONT";
42     public static final String ON_TASK_REMOVED = "ON_TASK_REMOVED";
43     public static final String ON_CALM_MODE_STARTED = "ON_CALM_MODE_STARTED";
44     public static final String ON_TASK_INFO_CHANGED = "ON_TASK_INFO_CHANGED";
45 
46     private static final int EMPTY_TASK_ID = -1;
47     private final String mReason;
48     private final int mTaskId;
49     private final ComponentName mComponentName;
50 
TaskViewPanelStateChangeReason(@eason String reason, int taskId, ComponentName componentName)51     private TaskViewPanelStateChangeReason(@Reason String reason, int taskId,
52             ComponentName componentName) {
53         mReason = reason;
54         mTaskId = taskId;
55         mComponentName = componentName;
56     }
57 
58     /**
59      * Creates a {@link TaskViewPanelStateChangeReason} with {@link Reason}, taskId and
60      * ComponentName.
61      */
createReason(@eason String reason, int taskId, ComponentName componentName)62     public static TaskViewPanelStateChangeReason createReason(@Reason String reason, int taskId,
63             ComponentName componentName) {
64         return new TaskViewPanelStateChangeReason(reason, taskId, componentName);
65     }
66 
67     /**
68      * Creates a {@link TaskViewPanelStateChangeReason} with {@link Reason} and taskId.
69      */
createReason(@eason String reason, int taskId)70     public static TaskViewPanelStateChangeReason createReason(@Reason String reason, int taskId) {
71         return new TaskViewPanelStateChangeReason(reason, taskId, /* componentName= */ null);
72     }
73 
74     /**
75      * Creates a {@link TaskViewPanelStateChangeReason} with {@link Reason} and ComponentName.
76      */
createReason(@eason String reason, ComponentName componentName)77     public static TaskViewPanelStateChangeReason createReason(@Reason String reason,
78             ComponentName componentName) {
79         return createReason(reason, EMPTY_TASK_ID, componentName);
80     }
81 
82     /**
83      * Creates a {@link TaskViewPanelStateChangeReason} with {@link Reason}.
84      */
createReason(@eason String reason)85     public static TaskViewPanelStateChangeReason createReason(@Reason String reason) {
86         return createReason(reason, EMPTY_TASK_ID, /* componentName= */ null);
87     }
88 
89     @Override
toString()90     public String toString() {
91         return "{ reason=" + mReason + ", taskId=" + mTaskId + ", componentName=" + mComponentName
92                 + "}";
93     }
94 
95     /**
96      * Returns the {@link Reason}.
97      */
getReason()98     public String getReason() {
99         return mReason;
100     }
101 
102     @StringDef({ON_ACTIVITY_RESTART_ATTEMPT,
103             ON_COLLAPSE_MSG,
104             ON_DRIVE_STATE_CHANGED,
105             ON_GRIP_BAR_CLICKED,
106             ON_GRIP_BAR_DRAG,
107             ON_HOME_INTENT,
108             ON_HOME_SCREEN_LAYOUT_CHANGED,
109             ON_IMMERSIVE_REQUEST,
110             ON_MEDIA_INTENT,
111             ON_PANEL_STATE_CHANGE_END,
112             ON_PANEL_READY,
113             ON_SUW_STATE_CHANGED,
114             ON_TASK_MOVED_TO_FRONT,
115             ON_TASK_REMOVED,
116             ON_CALM_MODE_STARTED,
117             ON_TASK_INFO_CHANGED,
118     })
119     @Retention(RetentionPolicy.SOURCE)
120     @interface Reason {
121     }
122 }
123