Android Open Source - drive-android-svg Coordinate Util






From Project

Back to project page drive-android-svg.

License

The source code is released under:

Apache License

If you think the Android project drive-android-svg listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.goodow.drive.android.svg.utils;
//from   ww  w .  ja  va 2 s .  c  o  m
import android.view.ViewGroup;

import com.goodow.realtime.store.Document;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * Created by liudenghui on 14-7-11.
 */
@Singleton
public class CoordinateUtil {
  private int width;
  private int height;
  private ViewGroup view;
  @Inject
  private DrawUtil drawUtil;

  public void setView(ViewGroup view) {
    this.view = view;
  }

  public double translateX2proportion(int x) {
//    System.out.println((double) x / width);
    return (double) x / width;
  }

  public float translateY2proportion(int y) {
//    System.out.println((double) y / height);
    return (float) y / height;
  }

  public int translateX2local(double x) {
//    System.out.println((int) (x * width));
    return (int) (x * width);
  }

  public int translateY2local(double y) {
//    System.out.println((int) (y * height));
    return (int) (y * height);
  }

  public void setRatio(Document doc) {
    int viewWidth = view.getWidth();
    int viewHeight = view.getHeight();
//    System.out.println(viewWidth + "," + viewHeight);
    Double ratio = doc.getModel().getRoot().get("ratio");
    double currentRatio = (double) viewHeight / viewWidth;
    if (ratio > currentRatio) {
      width = (int) (viewHeight / ratio);
      height = viewHeight;
    } else {
      height = (int) (viewWidth * ratio);
      width = viewWidth;
    }
//    System.out.println("width=" + width + ",height=" + height);
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    layoutParams.height = height;
    layoutParams.width = width;
    view.setLayoutParams(layoutParams);
//    System.out.println("surface"+view.getWidth());
  }

}




Java Source Code List

com.goodow.drive.android.svg.DriveAndroidSvgModule.java
com.goodow.drive.android.svg.OnRemoteChangeListener.java
com.goodow.drive.android.svg.OnShowPopupListener.java
com.goodow.drive.android.svg.SvgMainActivity.java
com.goodow.drive.android.svg.SvgModule.java
com.goodow.drive.android.svg.graphics.MyBaseShape.java
com.goodow.drive.android.svg.graphics.MyEllipse.java
com.goodow.drive.android.svg.graphics.MyLine.java
com.goodow.drive.android.svg.graphics.MyPath.java
com.goodow.drive.android.svg.graphics.MyRect.java
com.goodow.drive.android.svg.samples.demo.MainActivity.java
com.goodow.drive.android.svg.utils.CoordinateUtil.java
com.goodow.drive.android.svg.utils.DrawUtil.java
com.goodow.drive.android.svg.utils.ParseUtil.java
com.goodow.drive.android.svg.utils.SwitchUtil.java
com.goodow.drive.android.svg.view.FillColorDialog.java
com.goodow.drive.android.svg.view.LeftMenuLayout.java
com.goodow.drive.android.svg.view.MyDrawable.java
com.goodow.drive.android.svg.view.MySurfaceView.java
com.goodow.drive.android.svg.view.MyViewGroup.java
com.goodow.drive.android.svg.view.MyView.java
com.goodow.drive.android.svg.view.StrokeColorDialog.java
com.goodow.drive.android.svg.view.StrokeWidthDialog.java