aboutsummaryrefslogtreecommitdiff
path: root/resources/src/main/java/org/robolectric/manifest/ActivityData.java
blob: 7088115b1f4f1fb4f2cf505550000b4c192b616e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package org.robolectric.manifest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ActivityData {
  private static final String ALLOW_TASK_REPARENTING = "allowTaskReparenting";
  private static final String ALWAYS_RETAIN_TASK_STATE = "alwaysRetainTaskState";
  private static final String CLEAR_TASK_ON_LAUNCH = "clearTaskOnLaunch";
  private static final String CONFIG_CHANGES = "configChanges";
  private static final String ENABLED = "enabled";
  private static final String EXCLUDE_FROM_RECENTS = "excludeFromRecents";
  private static final String EXPORTED = "exported";
  private static final String FINISH_ON_TASK_LAUNCH = "finishOnTaskLaunch";
  private static final String HARDWARE_ACCELERATED = "hardwareAccelerated";
  private static final String ICON = "icon";
  private static final String LABEL = "label";
  private static final String LAUNCH_MODE = "launchMode";
  private static final String MULTIPROCESS = "multiprocess";
  private static final String NAME = "name";
  private static final String NO_HISTORY = "noHistory";
  private static final String PARENT_ACTIVITY_NAME = "parentActivityName";
  private static final String PERMISSION = "permission";
  private static final String PROCESS = "process";
  private static final String SCREEN_ORIENTATION = "screenOrientation";
  private static final String STATE_NOT_NEEDED = "stateNotNeeded";
  private static final String TARGET_ACTIVITY = "targetActivity";
  private static final String TASK_AFFINITY = "taskAffinity";
  private static final String THEME = "theme";
  private static final String UI_OPTIONS = "uiOptions";
  private static final String WINDOW_SOFT_INPUT_MODE = "windowSoftInputMode";

  private final List<IntentFilterData> intentFilters;
  private final HashMap<String, String> attrs;
  // Non-null only for activity-alias'es.
  private final ActivityData targetActivity;

  /**
   * XML Namespace used for android.
   */
  private final String xmlns;
  private final MetaData metaData;

  public ActivityData(Map<String, String> attrMap, List<IntentFilterData> intentFilters) {
    this("android", attrMap, intentFilters);
  }

  public ActivityData(String xmlns, Map<String, String> attrMap, List<IntentFilterData> intentFilters) {
    this(xmlns, attrMap, intentFilters, null, null);
  }

  public ActivityData(String xmlns, Map<String, String> attrMap, List<IntentFilterData> intentFilters,
      ActivityData targetActivity, MetaData metaData) {
    this.xmlns = xmlns;
    attrs = new HashMap<>();
    attrs.putAll(attrMap);
    this.intentFilters = new ArrayList<>(intentFilters);
    this.targetActivity = targetActivity;
    this.metaData = metaData;
  }

  public boolean isAllowTaskReparenting() {
    return getBooleanAttr(withXMLNS(ALLOW_TASK_REPARENTING), false);
  }

  public boolean isAlwaysRetainTaskState() {
    return getBooleanAttr(withXMLNS(ALWAYS_RETAIN_TASK_STATE), false);
  }

  public boolean isClearTaskOnLaungh() {
    return getBooleanAttr(withXMLNS(CLEAR_TASK_ON_LAUNCH), false);
  }

  public String getConfigChanges() {
    return attrs.get(withXMLNS(CONFIG_CHANGES));
  }

  public boolean isEnabled() {
    return getBooleanAttr(withXMLNS(ENABLED), true);
  }

  public boolean isExcludedFromRecents() {
    return getBooleanAttr(withXMLNS(EXCLUDE_FROM_RECENTS), false);
  }

  public boolean isExported() {
    boolean defaultValue = false;
    return getBooleanAttr(withXMLNS(EXPORTED), defaultValue);
  }

  public boolean isFinishOnTaskLaunch() {
    return getBooleanAttr(withXMLNS(FINISH_ON_TASK_LAUNCH), false);
  }

  public boolean isHardwareAccelerated() {
    return getBooleanAttr(withXMLNS(HARDWARE_ACCELERATED), false);
  }

  /* TODO: public boolean getIcon() {} */

  public String getLabel() {
    return attrs.get(withXMLNS(LABEL));
  }

  public String getLaunchMode() {
    return attrs.get(withXMLNS(LAUNCH_MODE));
  }

  public boolean isMultiprocess() {
    return getBooleanAttr(withXMLNS(MULTIPROCESS), false);
  }

  public String getName() {
    return attrs.get(withXMLNS(NAME));
  }

  public boolean isNoHistory() {
    return getBooleanAttr(withXMLNS(NO_HISTORY), false);
  }

  public String getParentActivityName() {
    return attrs.get(withXMLNS(PARENT_ACTIVITY_NAME));
  }

  public String getPermission() {
    return attrs.get(withXMLNS(PERMISSION));
  }

  public String getProcess() {
    return attrs.get(withXMLNS(PROCESS));
  }

  public String getScreenOrientation() {
    return attrs.get(withXMLNS(SCREEN_ORIENTATION));
  }

  public boolean isStateNotNeeded() {
    return getBooleanAttr(withXMLNS(STATE_NOT_NEEDED), false);
  }

  public String getTargetActivityName() {
    return attrs.get(withXMLNS(TARGET_ACTIVITY));
  }

  public String getTaskAffinity() {
    return attrs.get(withXMLNS(TASK_AFFINITY));
  }

  /**
   * Convenience accessor for value of android:THEME attribute.
   *
   * @return The theme attribute.
   */
  public String getThemeRef() {
    return attrs.get(withXMLNS(THEME));
  }

  public String getUIOptions() {
    return attrs.get(withXMLNS(UI_OPTIONS));
  }

  public String getWindowSoftInputMode() {
    return attrs.get(withXMLNS(WINDOW_SOFT_INPUT_MODE));
  }

  private boolean getBooleanAttr(String n, boolean defaultValue) {
    return (attrs.containsKey(n) ? Boolean.parseBoolean(attrs.get(n)): defaultValue);
  }

  private String withXMLNS(String attr) {
    return withXMLNS(xmlns, attr);
  }

  /**
   * Get the map for all attributes defined for the activity XML.
   * @return map of attributes names to values from the manifest. Not null.
   */
  public Map<String, String> getAllAttributes() {
    return attrs;
  }

  /**
   * Get the intent filters defined for activity.
   * @return A list of intent filters. Not null.
   */
  public List<IntentFilterData> getIntentFilters() {
    return intentFilters;
  }

  public MetaData getMetaData() {
    return metaData;
  }

  public ActivityData getTargetActivity() {
    return targetActivity;
  }

  private static String withXMLNS(String xmlns, String attr) {
    return String.format("%s:%s", xmlns, attr);
  }

  public static String getNameAttr(String xmlns) {
    return withXMLNS(xmlns, NAME);
  }

  public static String getTargetAttr(String xmlns) {
    return withXMLNS("android", TARGET_ACTIVITY);
  }
}