-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathStatusBarOptions.java
More file actions
84 lines (67 loc) · 3.09 KB
/
StatusBarOptions.java
File metadata and controls
84 lines (67 loc) · 3.09 KB
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
package com.reactnativenavigation.options;
import android.content.Context;
import androidx.annotation.Nullable;
import com.reactnativenavigation.options.params.Bool;
import com.reactnativenavigation.options.params.NullBool;
import com.reactnativenavigation.options.params.ThemeColour;
import com.reactnativenavigation.options.params.NullThemeColour;
import com.reactnativenavigation.options.parsers.BoolParser;
import org.json.JSONObject;
public class StatusBarOptions {
public enum TextColorScheme {
Light("light"), Dark("dark"), None("none");
private String scheme;
TextColorScheme(String scheme) {
this.scheme = scheme;
}
public static TextColorScheme fromString(@Nullable String scheme) {
if (scheme == null) return None;
switch (scheme) {
case "light":
return Light;
case "dark":
return Dark;
default:
return None;
}
}
public boolean hasValue() {
return !scheme.equals(None.scheme);
}
}
public static StatusBarOptions parse(Context context, JSONObject json) {
StatusBarOptions result = new StatusBarOptions();
if (json == null) return result;
result.backgroundColor = ThemeColour.parse(context, json.optJSONObject("backgroundColor"));
result.textColorScheme = TextColorScheme.fromString(json.optString("style"));
result.visible = BoolParser.parse(json, "visible");
result.drawBehind = BoolParser.parse(json, "drawBehind");
result.translucent = BoolParser.parse(json, "translucent");
return result;
}
public ThemeColour backgroundColor = new NullThemeColour();
public TextColorScheme textColorScheme = TextColorScheme.None;
public Bool visible = new NullBool();
public Bool drawBehind = new NullBool();
public Bool translucent = new NullBool();
public void mergeWith(StatusBarOptions other) {
if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
if (other.textColorScheme.hasValue()) textColorScheme = other.textColorScheme;
if (other.visible.hasValue()) visible = other.visible;
if (other.drawBehind.hasValue()) drawBehind = other.drawBehind;
if (other.translucent.hasValue()) translucent = other.translucent;
}
public void mergeWithDefault(StatusBarOptions defaultOptions) {
if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
if (!textColorScheme.hasValue()) textColorScheme = defaultOptions.textColorScheme;
if (!visible.hasValue()) visible = defaultOptions.visible;
if (!drawBehind.hasValue()) drawBehind = defaultOptions.drawBehind;
if (!translucent.hasValue()) translucent = defaultOptions.translucent;
}
public boolean isHiddenOrDrawBehind() {
return drawBehind.isTrue() || visible.isFalse();
}
public boolean hasTransparency() {
return translucent.isTrue() || visible.isFalse() || backgroundColor.hasTransparency();
}
}