* [android] abstract transform parse code, share code

Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/48c083d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/48c083d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/48c083d2

Branch: refs/heads/release-0.16
Commit: 48c083d2ca1ff0c48d70c61fa74ef1af2a6010a7
Parents: 6486bc9
Author: jianbai.gbj <jianbai....@alibaba-inc.com>
Authored: Mon Nov 13 10:59:00 2017 +0800
Committer: jianbai.gbj <jianbai....@alibaba-inc.com>
Committed: Mon Nov 13 10:59:00 2017 +0800

----------------------------------------------------------------------
 .../weex/ui/animation/WXAnimationBean.java      | 123 +------------------
 1 file changed, 1 insertion(+), 122 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/48c083d2/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationBean.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationBean.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationBean.java
index e66b270..0abe3d7 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationBean.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationBean.java
@@ -115,128 +115,7 @@ public class WXAnimationBean {
 
     private static Map<Property<View,Float>, Float> parseTransForm(@Nullable 
String rawTransform, final int width,
                                                 final int height,final int 
viewportW) {
-      if (!TextUtils.isEmpty(rawTransform)) {
-        FunctionParser<Property<View,Float>, Float> parser = new 
FunctionParser<>
-            (rawTransform, new FunctionParser.Mapper<Property<View,Float>, 
Float>() {
-              @Override
-              public Map<Property<View,Float>, Float> map(String functionName, 
List<String> raw) {
-                if (raw != null && !raw.isEmpty()) {
-                  if (wxToAndroidMap.containsKey(functionName)) {
-                    return convertParam(width, height,viewportW, 
wxToAndroidMap.get(functionName), raw);
-                  }
-                }
-                return new HashMap<>();
-              }
-
-              private Map<Property<View,Float>, Float> convertParam(int width, 
int height,int viewportW,
-                                                      @NonNull 
List<Property<View,Float>> propertyList,
-                                                      @NonNull List<String> 
rawValue) {
-                Map<Property<View,Float>, Float> result = 
WXDataStructureUtil.newHashMapWithExpectedSize(propertyList.size());
-                List<Float> convertedList = new 
ArrayList<>(propertyList.size());
-                if (propertyList.contains(View.ROTATION) ||
-                    propertyList.contains(View.ROTATION_X) ||
-                    propertyList.contains(View.ROTATION_Y)) {
-                  convertedList.addAll(parseRotationZ(rawValue));
-                }else if (propertyList.contains(View.TRANSLATION_X) ||
-                           propertyList.contains(View.TRANSLATION_Y)) {
-                  convertedList.addAll(parseTranslation(propertyList, width, 
height, rawValue,viewportW));
-                } else if (propertyList.contains(View.SCALE_X) ||
-                           propertyList.contains(View.SCALE_Y)) {
-                  convertedList.addAll(parseScale(propertyList.size(), 
rawValue));
-                }
-                else 
if(propertyList.contains(CameraDistanceProperty.getInstance())){
-                  convertedList.add(parseCameraDistance(rawValue));
-                }
-                if (propertyList.size() == convertedList.size()) {
-                  for (int i = 0; i < propertyList.size(); i++) {
-                    result.put(propertyList.get(i), convertedList.get(i));
-                  }
-                }
-                return result;
-              }
-
-              private List<Float> parseScale(int size, @NonNull List<String> 
rawValue) {
-                List<Float> convertedList = new ArrayList<>(rawValue.size() * 
2);
-                List<Float> rawFloat = new ArrayList<>(rawValue.size());
-                for (String item : rawValue) {
-                  rawFloat.add(WXUtils.fastGetFloat(item));
-                }
-                convertedList.addAll(rawFloat);
-                if (size != 1 && rawValue.size() == 1) {
-                  convertedList.addAll(rawFloat);
-                }
-                return convertedList;
-              }
-
-              private @NonNull List<Float> parseRotationZ(@NonNull 
List<String> rawValue) {
-                List<Float> convertedList = new ArrayList<>(1);
-                int suffix;
-                for (String raw : rawValue) {
-                  if ((suffix = raw.lastIndexOf(DEG)) != -1) {
-                    convertedList.add(WXUtils.fastGetFloat(raw.substring(0, 
suffix)));
-                  } else {
-                    convertedList.add((float) 
Math.toDegrees(Double.parseDouble(raw)));
-                  }
-                }
-                return convertedList;
-              }
-
-              /**
-               * As "translate(50%, 25%)" or "translate(25px, 30px)" both are 
valid,
-               * parsing translate is complicated than other method.
-               * Add your waste time here if you try to optimize this method 
like {@link #parseScale(int, List)}
-               * Time: 0.5h
-               */
-              private List<Float> parseTranslation(List<Property<View,Float>> 
propertyList,
-                                                   int width, int height,
-                                                   @NonNull List<String> 
rawValue,int viewportW) {
-                List<Float> convertedList = new ArrayList<>(2);
-                String first = rawValue.get(0);
-                if (propertyList.size() == 1) {
-                  parseSingleTranslation(propertyList, width, height, 
convertedList, first,viewportW);
-                } else {
-                  parseDoubleTranslation(width, height, rawValue, 
convertedList, first,viewportW);
-                }
-                return convertedList;
-              }
-
-              private void parseSingleTranslation(List<Property<View,Float>> 
propertyList, int width, int height,
-                                                  List<Float> convertedList, 
String first,int viewportW) {
-                if (propertyList.contains(View.TRANSLATION_X)) {
-                  convertedList.add(parsePercentOrPx(first, width,viewportW));
-                } else if (propertyList.contains(View.TRANSLATION_Y)) {
-                  convertedList.add(parsePercentOrPx(first, height,viewportW));
-                }
-              }
-
-              private void parseDoubleTranslation(int width, int height,
-                                                  @NonNull List<String> 
rawValue,
-                                                  List<Float> convertedList, 
String first,int viewportW) {
-                String second;
-                if (rawValue.size() == 1) {
-                  second = first;
-                } else {
-                  second = rawValue.get(1);
-                }
-                convertedList.add(parsePercentOrPx(first, width,viewportW));
-                convertedList.add(parsePercentOrPx(second, height,viewportW));
-              }
-
-              private Float parseCameraDistance(List<String> rawValue){
-                float ret=Float.MAX_VALUE;
-                if(rawValue.size() == 1){
-                  float value = 
WXViewUtils.getRealPxByWidth(WXUtils.getFloat(rawValue.get(0)), viewportW);
-                  float scale = 
WXEnvironment.getApplication().getResources().getDisplayMetrics().density;
-                  if (!Float.isNaN(value) && value > 0) {
-                    ret = value * scale;
-                  }
-                }
-                return ret;
-              }
-            });
-        return parser.parse();
-      }
-      return new LinkedHashMap<>();
+      return  TransformParser.parseTransForm(rawTransform, width, height, 
viewportW);
     }
 
     private static Pair<Float, Float> parsePivot(@Nullable String 
transformOrigin,

Reply via email to