react-native-navigation的迁移库

StatusBarOptions.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.reactnativenavigation.parse;
  2. import android.support.annotation.Nullable;
  3. import com.reactnativenavigation.parse.params.Bool;
  4. import com.reactnativenavigation.parse.params.Color;
  5. import com.reactnativenavigation.parse.params.NullBool;
  6. import com.reactnativenavigation.parse.params.NullColor;
  7. import com.reactnativenavigation.parse.parsers.BoolParser;
  8. import com.reactnativenavigation.parse.parsers.ColorParser;
  9. import org.json.JSONObject;
  10. public class StatusBarOptions {
  11. public enum TextColorScheme {
  12. Light("light"), Dark("dark"), None("none");
  13. private String scheme;
  14. TextColorScheme(String scheme) {
  15. this.scheme = scheme;
  16. }
  17. public static TextColorScheme fromString(@Nullable String scheme) {
  18. if (scheme == null) return None;
  19. switch (scheme) {
  20. case "light":
  21. return Light;
  22. case "dark":
  23. return Dark;
  24. default:
  25. return None;
  26. }
  27. }
  28. public boolean hasValue() {
  29. return !scheme.equals(None.scheme);
  30. }
  31. }
  32. public static StatusBarOptions parse(JSONObject json) {
  33. StatusBarOptions result = new StatusBarOptions();
  34. if (json == null) return result;
  35. result.backgroundColor = ColorParser.parse(json, "backgroundColor");
  36. result.textColorScheme = TextColorScheme.fromString(json.optString("style"));
  37. result.visible = BoolParser.parse(json, "visible");
  38. result.drawBehind = BoolParser.parse(json, "drawBehind");
  39. return result;
  40. }
  41. public Color backgroundColor = new NullColor();
  42. public TextColorScheme textColorScheme = TextColorScheme.None;
  43. public Bool visible = new NullBool();
  44. public Bool drawBehind = new NullBool();
  45. public void mergeWith(StatusBarOptions other) {
  46. if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
  47. if (other.textColorScheme.hasValue()) textColorScheme = other.textColorScheme;
  48. if (other.visible.hasValue()) visible = other.visible;
  49. if (other.drawBehind.hasValue()) drawBehind = other.drawBehind;
  50. }
  51. public void mergeWithDefault(StatusBarOptions defaultOptions) {
  52. if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
  53. if (!textColorScheme.hasValue()) textColorScheme = defaultOptions.textColorScheme;
  54. if (!visible.hasValue()) visible = defaultOptions.visible;
  55. if (!drawBehind.hasValue()) drawBehind = defaultOptions.drawBehind;
  56. }
  57. }