Android Open Source - TheFirstMyth01 Move Test






From Project

Back to project page TheFirstMyth01.

License

The source code is released under:

MIT License

If you think the Android project TheFirstMyth01 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.example.gametest1;
// w  w  w  . ja  v  a  2 s . co  m
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.View;

class CustomView1 extends View {

  private Paint paint;
  private ArrayList<PointF> graphics = new ArrayList<PointF>();
  private Paint lPaint;
  private Path mPath;
  private int of = 0;
  private Boolean over = false;
  private float mX, mY;
  private static final float TOUCH_TOLERANCE = 4;

  public CustomView1(Context context) {
    super(context);
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(65);

    lPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    lPaint.setColor(Color.BLACK);
    lPaint.setStyle(Paint.Style.STROKE);// ??
    lPaint.setStrokeJoin(Paint.Join.ROUND);
    lPaint.setStrokeCap(Paint.Cap.ROUND);
    lPaint.setStrokeWidth(5);

    mPath = new Path();

  }

  @Override
  public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
      over = false;
      graphics.clear();
      of = 0;
      graphics.add(new PointF(x, y));
      touch_start(x, y);
      invalidate();
      break;
    case MotionEvent.ACTION_MOVE:
      graphics.add(new PointF(x, y));
      touch_move(x, y);
      invalidate();
      break;
    case MotionEvent.ACTION_UP:
      over = true;
      touch_up();
      invalidate();
      break;
    }

    return true;
  }

  private float spacing(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return FloatMath.sqrt(x * x + y * y);
  }

  private void touch_start(float x, float y) {
    mPath.reset();
    mPath.moveTo(x, y);
    mX = x;
    mY = y;
  }

  private void touch_move(float x, float y) {
    float dx = Math.abs(x - mX);
    float dy = Math.abs(y - mY);
    if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
      mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
      mX = x;
      mY = y;
    }
  }

  private void touch_up() {
    mPath.lineTo(mX, mY);
  }

  @Override
  protected void onDraw(Canvas canvas) {
    // canvas.drawColor(Color.TRANSPARENT,Mode.CLEAR);
    canvas.drawColor(Color.WHITE);// ????
    canvas.drawPath(mPath, lPaint);
    if (over && graphics.size() > 0) {
      canvas.drawPoint(graphics.get(of).x, graphics.get(of).y, paint);
      of += 1;
      if (of < graphics.size()) {
        if (of == graphics.size() - 1) {
          mPath.reset();// ??????????????
        }
        invalidate();
      }
    }
  }
}




Java Source Code List

com.example.gametest1.GameActivity.java
com.example.gametest1.GameMainActivity.java
com.example.gametest1.GameView.java
com.example.gametest1.MoveTest.java
com.game.base.BaseInfo.java
com.game.base.GameBackGround.java
com.game.base.GameMap.java
com.game.base.PubSet.java
com.game.commen.ActionToDo.java
com.game.commen.BitmapUtil.java
com.game.commen.Direction.java
com.game.commen.EffectName.java
com.game.commen.GetImgCommen.java
com.game.commen.MapName.java
com.game.commen.ToDo.java
com.game.data.BaseInfo.java
com.game.data.RoleData_Main.java
com.game.data.RoleData.java
com.game.effect.SpecialEffect1.java
com.game.effect.SpecialEffect.java
com.game.renwu.Objs.java
com.game.renwu.SpiritMain.java
com.game.renwu.Spirit_Main.java
com.game.renwu.Spirit_NPC.java
com.game.renwu.Spirit.java
com.game.renwu.Spiritgirl.java