ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î

[°³¹ß Tip] ¸ÖƼÅÍÄ¡ (Multi Touch) ±¸Çö ¼Ò½º
8³â Àü
package kr.pe.miksnug;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

/**
* ¾Èµå·ÎÀÌµå ¸ÖƼÅÍÄ¡ ÀÔ´Ï´Ù.<br/>
* <br/>
* ÇÁ·ÎÁ§Æ® ½ÇÇà Main Activity Ŭ·¡½º <br/>
* Android 2.0 ÀÌ»ó Áö¿ø <br/>
* <br/>
* 1. ¸ÖƼÅÍÄ¡ °¨Áö (±¸Çö»ó ¹«ÇÑ´ë)<br/>
* 2. ÅÍÄ¡Á¡¿¡ ¿øÇü Ç¥½Ã<br/>
* 3. ´©¸£´Â Èû¿¡ µû¶ó »ö±ò ¹× Å©±â º¯°æ<br/>
* 4. ´©¸£´Â Èû¿¡ µû¶ó Áøµ¿ º¯°æ<br/>
* <br/>
*
* @author yeongeon
*
*/
public class MainActivity extends Activity {

  /**
   * ¸ÞÀÎ ·¹À̾ƿô ÀνºÅϽº
   */
  private FrameLayout m_mainLayout = null;

  /**
   * µð¹ö±× ÅؽºÆ® Ãâ·Â¿ë ºä
   */
  TextView m_tvDebugText = null;
  TextView m_tvDebugText2 = null;

  
  /**
   * ÀÔ·ÂµÈ À̺¥Æ® ¼ö
   */
  private int m_eventCnt = 0;

  /**
   * ¿ø µµÇü View Ŭ·¡½º
   *
   * @author yeongeon
   */
  class Ball extends View {

    /**
     * X ÁÂÇ¥
     */
    public float m_x;

    /**
     * Y ÁÂÇ¥
     */
    public float m_y;

    /**
     * ¹ÝÁö¸§
     */
    private int m_r;

    /**
     * ÆäÀÎÆ® ÀνºÅϽº
     */
    private Paint m_paint = new Paint(Paint.LINEAR_TEXT_FLAG);

    /**
     * ¿ø µµÇü »ý¼ºÀÚ
     *
     * @param context
     * @param x
     * @param y
     * @param r
     * @param color
     */
    public Ball(Context context, float x, float y, int r, int color) {
      super(context);
      m_paint.setColor(color);
      this.m_x = x;
      this.m_y = y;
      this.m_r = r;
    }

    /**
     * µµÇü ±×¸®´Â ¸Þ¼Òµå
     *
     * @see android.view.View#onDraw(android.graphics.Canvas)
     */
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawCircle(m_x, m_y, m_r, m_paint);
      super.onDraw(canvas);
    }

  }
  

  /**
   * MyText View Ŭ·¡½º
   *
   * @author yeongeon
   */
  class FloatingText extends View {

    /**
     * X ÁÂÇ¥
     */
    public float m_x;

    /**
     * Y ÁÂÇ¥
     */
    public float m_y;

    /**
     * ¹ÝÁö¸§
     */
    private String m_t;

    /**
     * ÆäÀÎÆ® ÀνºÅϽº
     */
    private Paint m_paint = new Paint(Paint.LINEAR_TEXT_FLAG);

    /**
     * ¿ø µµÇü »ý¼ºÀÚ
     *
     * @param context
     * @param x
     * @param y
     * @param r
     * @param color
     */
    public FloatingText(Context context, float x, float y, String t, int color) {
      super(context);
      m_paint.setColor(color);
      this.m_x = x;
      this.m_y = y;
      this.m_t = t;
    }

    /**
     * µµÇü ±×¸®´Â ¸Þ¼Òµå
     *
     * @see android.view.View#onDraw(android.graphics.Canvas)
     */
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawText(m_t, m_x, m_y, m_paint);
      super.onDraw(canvas);
    }

  }

  /**
   * ÅÍÄ¡ À̺¥Æ® °³º° ³ëµå Ŭ·¡½º
   *
   * @author yeongeon
   */
  class EventNode {
    /**
     * Æ÷ÀÎÅÍ ¾ÆÀ̵ð
     */
    private int m_pointerId = -1;

    /**
     * Æ÷ÀÎÅÍ À妽º
     */
    private int m_pointerIndex = -1;

    /**
     * x ÁÂÇ¥ °ª
     */
    private float m_x = -1;

    /**
     * y ÁÂÇ¥ °ª
     */
    private float m_y = -1;

    /**
     * ¾Ð·Â °ª
     */
    private float m_pressure = -1;

    /**
     * µµÇü ÀνºÅϽº
     */
    private Ball m_ball = null;

    /**
     * Paint »ö
     */
    private int m_color = Color.YELLOW;
    
    /**
     * Áøµ¿ ½Ã°£ °£°Ý
     */
    int m_vibrationInterval = 2;
    
    /**
     * ¹ÝÁö¸§
     */
    int m_radius = 50;
    
    /**
     * ¶°´Ù´Ï´Â ¹®ÀÚ ÀνºÅϽº
     */
    FloatingText m_floatingText = null;
    
    
    /**
     * »ý¼ºÀÚ ÀÔ´Ï´Ù.
     *
     * @param event
     * @param idx
     */
    public EventNode(MotionEvent event, int idx) {
      this.m_pointerId = event.getPointerId(idx);
      this.m_pointerIndex = event.findPointerIndex(this.m_pointerId);
      this.m_x = event.getX(this.m_pointerIndex);
      this.m_y = event.getY(this.m_pointerIndex);
      this.setPressure(event.getPressure(this.m_pointerIndex) );
      if (this.getPressure() >= 0.1 && this.getPressure() < 0.18) {
        this.m_color = Color.GREEN;
        this.m_vibrationInterval = 3;
        this.m_radius = 60;
      } else if (this.getPressure() > 0.25) {
        this.m_color = Color.RED;
        this.m_vibrationInterval = 6;
        this.m_radius = 100;
      } else if (this.getPressure() >= 0.18 && this.getPressure() < 0.25) {
        this.m_color = Color.BLUE;
        this.m_vibrationInterval = 4;
        this.m_radius = 70;
      } else {
        this.m_color = Color.YELLOW;
        this.m_vibrationInterval = 2;
        this.m_radius = 50;
      }
      this.m_ball = new Ball(getApplicationContext(), this.getX(), this
          .getY(), this.m_radius, this.getColor());
      
      this.m_floatingText = new FloatingText(getApplicationContext(), this.getX()-(this.m_radius/2), this
          .getY()-this.m_radius, ""+ this.getPressure(), Color.WHITE );      
      
    }
    
    public FloatingText getFloatingText(){
      return m_floatingText;
    }
    
    public int getVibrationInterval() {
      return this.m_vibrationInterval;
    }

    /**
     * Á¤ÀÇµÈ Paint »ö °ªÀ» ¹ÝȯÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @return
     */
    public int getColor() {
      return this.m_color;
    }

    /**
     * Paint »öÀ» ÇÒ´çÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @param color
     */
    public void setColor(int color) {
      this.m_color = color;
    }

    /**
     * ¾Ð·Â °ªÀ» ¹ÝȯÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @return
     */
    public float getPressure() {
      return this.m_pressure;
    }

    /**
     * ¾Ð·Â °ªÀ» Á¤ÀÇÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @param pressure
     */
    public void setPressure(float pressure) {
      this.m_pressure = pressure;
    }

    /**
     * Æ÷ÀÎÅÍ ¾ÆÀ̵𸦠¹ÝȯÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @return
     */
    public int getPointerId() {
      return this.m_pointerId;
    }

    /**
     * Æ÷ÀÎÅÍ À妽º¸¦ ¹ÝȯÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @return
     */
    public int getPointerIndex() {
      return this.m_pointerIndex;
    }

    /**
     * x ÁÂÇ¥°ªÀ» ¹ÝȯÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @return
     */
    public float getX() {
      return this.m_x;
    }

    /**
     * y ÁÂÇ¥°ªÀ» ¹ÝȯÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @return
     */
    public float getY() {
      return this.m_y;
    }

    /**
     * µµÇü ÀνºÅϽº¸¦ ¹ÝȯÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     *
     * @return
     */
    public Ball getBall() {
      return this.m_ball;
    }

    /**
     * °¢ ÀνºÅϽº °ªÀ» ÃʱâÈ­ÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
     */
    public void setInit() {
      this.m_pointerId = -1;
      this.m_pointerIndex = -1;
      this.m_x = -1;
      this.m_y = -1;
      this.m_pressure = -1;
      this.m_color = Color.GREEN;
      this.m_ball = null;
    }
  }

  /**
   * ¸ð¼Ç À̺¥Æ®¸¦ ´ã¾ÆµÎ´Â ArrayList ÀνºÅϽºÀÔ´Ï´Ù.
   */
  private ArrayList<EventNode> m_aEventNodes = new ArrayList<EventNode>();

  /**
   * Activity »ý¼º½Ã Á¢±Ù ¸Þ¼Òµå
   *
   * @see android.app.Activity#onCreate(android.os.Bundle)
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // ·¹À̾ƿô ÀνºÅϵå ÇÒ´ç
    m_mainLayout = (FrameLayout) this.findViewById(R.id.main);

    // µð¹ö±× ÅؽºÆ® ºä ÀνºÅϽº ÇÒ´ç
    m_tvDebugText = (TextView) this.findViewById(R.id.debug_text);
    m_tvDebugText2 = (TextView) this.findViewById(R.id.debug_text2);
  }

  /**
   * ÅÍÄ¡ÇßÀ»¶§ ¹ÝÀÀÇÏ´Â ¸Þ¼ÒµåÀÔ´Ï´Ù.
   *
   * @see android.app.Activity#onTouchEvent(android.view.MotionEvent)
   */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    m_eventCnt = event.getPointerCount();

    m_tvDebugText.setVisibility(View.VISIBLE);
    m_tvDebugText.setText("Points : " + m_eventCnt
        + " / EventNodes : " + m_aEventNodes.size());

    switch (event.getAction()) {
    // ´­·¶À» ¶§
    case MotionEvent.ACTION_DOWN:
      drawBall(event);
      return true;

      // ´©¸£°í À̵¿ÇÒ ¶§
    case MotionEvent.ACTION_MOVE:
      moveBall(event);
      return true;

      // ¶¼¾úÀ» ¶§
    case MotionEvent.ACTION_UP:
      removeBall();

      m_tvDebugText.setVisibility(View.GONE);
      return true;
    }

    return false;
  }

  /**
   * µµÇü ±×¸®´Â ¸Þ¼Òµå
   *
   * @param event
   */
  private void drawBall(MotionEvent event) {
    removeBall();
    for (int i = 0; i < m_eventCnt; i++) {
      EventNode eventNode = new EventNode(event, i);
      m_aEventNodes.add(eventNode);
      m_mainLayout.addView(eventNode.getBall());
      m_mainLayout.addView(eventNode.getFloatingText());
      ((Vibrator)getSystemService(VIBRATOR_SERVICE)).vibrate(eventNode.getVibrationInterval());
    }

  }

  /**
   * µµÇü À̵¿ ó¸® ¸Þ¼Òµå
   *
   * @param event
   */
  private void moveBall(MotionEvent event) {
    removeBall();
    drawBall(event);
  }

  /**
   * µµÇü Á¦°Å ó¸® ¸Þ¼Òµå
   */
  private void removeBall() {
    int nSize = m_aEventNodes.size();
    for (int i = 0; i < nSize; i++) {
      m_mainLayout.removeView(m_aEventNodes.get(0).getBall());
      m_mainLayout.removeView(m_aEventNodes.get(0).getFloatingText());
      m_aEventNodes.remove(0);
    }
  }

}
ÃßõÃßõ : 236 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,346
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È
1,345
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È (windows server 2019)
1,344
Windows Ãë¾àÁ¡Áø´Ü º¸¾È°¡À̵å¶óÀÎ
1,343
Windows Admin Center¸¦ ÅëÇÑ ¼­¹ö °ü¸®
1,342
À©µµ¿ì ¼­¹ö¿¡¼­ ½ÇÇàµÇ´Â ¼­ºñ½º È®ÀÎ
1,341
Chrome NET::ERR CERT REVOKED ÇØ°á¹æ¹ý
1,340
cmd ¸í·É¾î (¸í·É ÇÁ·ÒÇÁÆ® ¸í·É¾î) ¸ðÀ½
1,339
Windows10 ƯÁ¤ ÇÁ·Î±×·¥(OCS 2007 R2)¿¡¼­ ÷ºÎÆÄÀÏ µå·¡±×¾Øµå·ÓÀÌ ¾È µÇ´Â Çö»ó
1,338
À©µµ¿ì ·Î±×, °ü¸® À̺¥Æ® »èÁ¦
1,337
Ŭ¸° ºÎÆÃ
1,336
Windows ±¸¼º ¿ä¼Ò ÀúÀå¼Ò¿¡¼­ ÆÄÀÏ ¼Õ»ó °Ë»ç
1,335
Windows Defender °Ë»ç ±â·Ï »èÁ¦Çϱâ
1,334
°£´ÜÇÑ À©µµ¿ì 10 Á¤Ç° ÀÎÁõ (Å©·¢ÇÁ·Î±×·¥ ÇÊ¿ä¾øÀ½)
1,333
¿À·ù³­ Æú´õ °­Á¦»èÁ¦ ¹æ¹ý
1,332
Å©·Ò¿¡¼­ Ç÷¡½Ã Ç×»ó Çã¿ëÇϵµ·Ï ¼³Á¤Çϱâ (·¹Áö½ºÆ®¸®) reg ÆÄÀÏ ¸¸µé±â
1,331
GPT µð½ºÅ©¸¦ MBR µð½ºÅ©·Î º¯È¯
1,330
MBR µð½ºÅ©¸¦ GPT µð½ºÅ©·Î º¯È¯
1,329
±¸±Û °Ë»öÀ» 200% È°¿ëÇÏ°Ô ÇØÁÖ´Â °Ë»ö ¸í·É¾î ÃÑÁ¤¸®
1,328
[Jquery] jQuery·Î ¿ìŬ¸¯ ¹æÁö, µå·¡±× ¹æÁö, ¼±Åà ¹æÁö (IE10, ÆÄÀ̾îÆø½º, Å©·Ò È®ÀÎ)
1,327
php »ç¿ëÀÚ Á¢¼ÓIP, ºê¶ó¿ìÀúÁ¤º¸, osÁ¤º¸, http, https Á¢¼ÓÇÁ·ÎÅäÄÝ ¾Ë¾Æ¿À±â
1,326
[PHP] IE ºê¶ó¿ìÀú Á¢¼Ó °ËÃâÇϱâ
1,325
À©µµ¿ì10 ½Ã½ºÅÛ ¿¹¾à ÆÄƼ¼Ç È®ÀÎ ¹× »èÁ¦
1,324
À©µµ¿ì10 º¹±¸ ÆÄƼ¼Ç »èÁ¦ ¹æ¹ý
1,323
À©µµ¿ì10 ºÎÆÃÁö¿¬ °ËÀºÈ­¸é¿¡¼­ ¸îºÐ°£ ¸Ó¹«´Â Çö»ó ÇØ°á¹æ¹ý
1,322
»ï¼º³ëÆ®ºÏ ¹ÙÀÌ¿À½º ÁøÀÔÀÌ ºÒ°¡´ÉÇÑ °æ¿ì ¹ÙÀÌ¿À½º À缳ġ¿Í NVRAM ÃʱâÈ­
1,321
ÀͽºÇ÷η¯(IE)ÀÇ ±¸±Û °Ë»ö°ø±ÞÀÚ Çѱ۷Πº¯°æ ¹æ¹ý
1,320
À©µµ¿ì 10 ±âº» ¾Û »èÁ¦ ¹× º¹±¸
1,319
meta ÅÂ±× http-equiv ¼³Á¤¹æ¹ý°ú Â÷ÀÌÁ¡
1,318
±¸±Û(Google)°Ë»ö¿¡¼­ °í±Þ¿¬»êÀÚ¸¦ ÀÌ¿ëÇÏ¿© ¸¹Àº Á¤º¸¸¦ ¾ò´Â ¹æ¹ý
1,317
ÇÁ·Î±×·¥ ¾øÀÌ Çϵåµð½ºÅ© º¹»ç ¹× ¹é¾÷Çϱâ
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.