react-native-navigation的迁移库

SubtitleOptions.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.reactnativenavigation.parse;
  2. import android.graphics.Typeface;
  3. import android.support.annotation.Nullable;
  4. import com.reactnativenavigation.parse.params.Color;
  5. import com.reactnativenavigation.parse.params.Fraction;
  6. import com.reactnativenavigation.parse.params.NullColor;
  7. import com.reactnativenavigation.parse.params.NullFraction;
  8. import com.reactnativenavigation.parse.params.NullText;
  9. import com.reactnativenavigation.parse.params.Text;
  10. import com.reactnativenavigation.parse.parsers.ColorParser;
  11. import com.reactnativenavigation.parse.parsers.FractionParser;
  12. import com.reactnativenavigation.parse.parsers.TextParser;
  13. import com.reactnativenavigation.utils.TypefaceLoader;
  14. import org.json.JSONObject;
  15. public class SubtitleOptions {
  16. public static SubtitleOptions parse(TypefaceLoader typefaceManager, JSONObject json) {
  17. final SubtitleOptions options = new SubtitleOptions();
  18. if (json == null) {
  19. return options;
  20. }
  21. options.text = TextParser.parse(json, "text");
  22. options.color = ColorParser.parse(json, "color");
  23. options.fontSize = FractionParser.parse(json, "fontSize");
  24. options.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", ""));
  25. options.alignment = Alignment.fromString(TextParser.parse(json, "alignment").get(""));
  26. return options;
  27. }
  28. public Text text = new NullText();
  29. public Color color = new NullColor();
  30. public Fraction fontSize = new NullFraction();
  31. @Nullable public Typeface fontFamily;
  32. public Alignment alignment = Alignment.Default;
  33. void mergeWith(final SubtitleOptions other) {
  34. if (other.text.hasValue()) text = other.text;
  35. if (other.color.hasValue()) color = other.color;
  36. if (other.fontSize.hasValue()) fontSize = other.fontSize;
  37. if (other.fontFamily != null) fontFamily = other.fontFamily;
  38. if (other.alignment != Alignment.Default) alignment = other.alignment;
  39. }
  40. void mergeWithDefault(SubtitleOptions defaultOptions) {
  41. if (!text.hasValue()) text = defaultOptions.text;
  42. if (!color.hasValue()) color = defaultOptions.color;
  43. if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
  44. if (fontFamily == null) fontFamily = defaultOptions.fontFamily;
  45. if (alignment == Alignment.Default) alignment = defaultOptions.alignment;
  46. }
  47. }