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

[°³¹ß 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,106
[Source] Åõ¸íÀ©µµ¿ì
1,105
[Source] WebView¸¦ ÀÌ¿ëÇؼ­, ÀÌÀü À¥ÆäÀÌÁö·Î À̵¿
1,104
[Source] ŸÀÌƲ¹ÙÀÇ ±ÛÀÚ»ö º¯°æ
1,103
[Source] Splash Screen
1,102
[Source] À̹ÌÁöÆÄÀÏ ´Ù¿î·Îµå
1,101
[Source] URLÀ» ÅëÇÑ À̹ÌÁö µå·ÎÀ×
1,100
[Source] PopupWindow »ç¿ë¿¹
1,099
[Source] WebView »ç¿ë¿¹ (loadUrl, loadData)
1,098
µ¿ÀûÀ¸·Î LinearLayout È­¸é¿¡ À̹ÌÁö Ãß°¡Çϱâ2
1,097
[Source] µ¿ÀûÀ¸·Î LinearLayout È­¸é¿¡ À̹ÌÁö Ãß°¡Çϱâ
1,096
[Source] Ä«¸Þ¶ó Á¦¾î
1,095
[Source] °£´ÜÇÑ MP3 Ç÷¹ÀÌ¾î ¿¹Á¦
1,094
[Source] Æù³» À½¾Ç ÆÄÀÏ ¸ñ·Ï Àоî¿À±â
1,093
[Source] MP3 ÆÄÀÏ ½ÇÇàÇϱâ
1,092
[android] ¹Ìµð¾î Ç÷¹À̾î·Î ¿Àµð¿À ºñµð¿À Àç»ýÇϱâ
1,091
µµ½º À©µµ ³×Æ®¿öÅ© ¸í·É¾î
1,090
[¾Èµå·ÎÀ̵å]ÆÄÀÏ ¿¬°á - Intent setDataAndType(Uri , MimeType)
1,089
±¸±Û °Ë»ö ÆÁ (±¸±Û¸µ, ±¸±Û °Ë»ö¹æ¹ý)
1,088
Windows 8 - Windows ±¸¼º ¿ä¼Ò ÀúÀå¼Ò¿¡¼­ ÆÄÀÏ ¼Õ»ó °Ë»ç
1,087
ÀÎÅÍ³Ý ÀͽºÇ÷η¯ 8 Á¤½Ä ´Ù¿î·Îµå
1,086
À©µµ¿ìÁî Windows 8, 8.1 ÀÇ ¹öÀüº° ei.cfg ÆÄÀÏ »ý¼ºÇÏ´Â ¹ý
1,085
Windows ¼³Ä¡ ÇÁ·Î±×·¥ ¹öÀü ±¸¼º ¹× Á¦Ç° ID ÆÄÀÏ(EI.cfg ¹× PID.txt)
1,084
ÀÌÁß ºÎÆà PC¿¡ ºÎÆà ¸Þ´º ¼³Á¤ ¶Ç´Â º¹±¸
1,083
ÆäÀ̽ººÏ µ¿¿µ»ó°ú À¯Æ©ºê µ¿¿µ»ó ´Ù¿î¹Þ´Â ¹æ¹ý
1,082
Å©·Ò(Chrome)¿¡¼­ DNS Áö¿ì±â - chrome dns flush
1,081
IE10, IE11 ¿¡¼­ Flash °¡ Á¤»óÀûÀ¸·Î ³ªÅ¸³ªÁö ¾ÊÀ» ¶§...
1,080
HTML5 ¾Ö´Ï¸ÞÀÌ¼Ç Á¦ÀÛ ÇÁ·Î±×·¥
1,079
¾µ¸¸ÇÑ jquery Ç÷¯±×ÀÎ
1,078
Windows ´ÜÃàÅ°
1,077
Internet ExplorerÀÇ ÀÛµ¿ÀÌ ÁßÁöµÇ¾ú½À´Ï´Ù-ÇØ°á ¹æ¹ý
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.