FrontPage

IDEOS



IJIROID




package jp.Ijiro;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class Ijiro extends Activity implements SensorEventListener {

private SensorManager sensorManager;
private SensorView sensorView;

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 sensorView = new SensorView(this);
 setContentView(sensorView);

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
 

 List<Sensor> sensors = sensorManager
   .getSensorList(Sensor.TYPE_ACCELEROMETER);
 if (sensors.size() > 0) {
  sensorManager.registerListener(this, sensors.get(0),
    SensorManager.SENSOR_DELAY_GAME);
 }
}

@Override
protected void onDestroy() {
 super.onDestroy();
 sensorManager.unregisterListener(this);
}

@Override
public void onAccuracyChanged(final Sensor sensor, int accuracy) {
 // TODO Auto-generated method stub
}

@Override
public void onSensorChanged(final SensorEvent event) {
 Sensor sensor = event.sensor;
 switch (sensor.getType()) {
 case Sensor.TYPE_ACCELEROMETER:
  // Log.d(LOG_TAG, "ACCELEROMETER : " + event.values[0] + ","
  // + event.values[1] + "," + event.values[2]);
  sensorView.move(event.values[0], event.values[1]);
  break;
 default:
  break;
 }
}

class SensorView extends View {
 private static final int IJIRO_SIZE = 50;
 private Bitmap ijiroid;
 private Bitmap ijiroidsu;
 private Bitmap ijiroidun;
 private int w;
 private int h;
 private float x;
 private float y;

 public SensorView(Context context) {
  super(context);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  ijiroid = BitmapFactory.decodeResource(context.getResources(),
    R.drawable.ijiroid);
  ijiroidsu = BitmapFactory.decodeResource(context.getResources(),
		     R.drawable.ijiroidsu);
  ijiroidun = BitmapFactory.decodeResource(context.getResources(),
		     R.drawable.ijiroidun);
 }

 /**

  *
  * @param mx
  * @param my
  */
 public void move(float mx, float my) {

  this.y += (my * 2f);
  
  if (this.x < 0) {
   this.x = 0;
  } else if ((this.x + IJIRO_SIZE) > this.w) {
   this.x = this.w - IJIRO_SIZE;
  }

  if (this.y < 0) {
   this.y = 0;
  } else if ((this.y + IJIRO_SIZE) > this.h) {
   this.y = this.h - IJIRO_SIZE;
  }

  invalidate();
 }

 @Override
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  this.w = w+100;
  this.h = h+100;
  this.x = (w - IJIRO_SIZE) / 2f;
  this.y = (h - IJIRO_SIZE) / 2f;
 }

 @Override
 protected void onDraw(Canvas canvas) {
  
  if(x==0 && y < 250){
	   canvas.drawBitmap(ijiroidsu, x, y, null);
  }else if(y >= 250){
	   canvas.drawBitmap(ijiroidun, x, y, null);
  }else{
	   canvas.drawBitmap(ijiroid, x, y, null);
  }
  
  }
 }
}




package com.ijiro2ndedition.jp;

import java.util.ArrayList;

import com.ijiro2ndedition.jp.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.util.Log;

public class Ijiro2nd extends Activity {
	/** Called when the activity is first created. */
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 requestWindowFeature(Window.FEATURE_NO_TITLE);
	
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
		 MyView view = new MyView(this);
		 setContentView(view);
		}
	
	
	class MyView extends View {
		public MyView(Context context) {
		super(context);
		
		 Resources r = context.getResources();
	
     ijiroid = BitmapFactory.decodeResource(r,
			             R.drawable.ijiroid);
	  ijiroidhi = BitmapFactory.decodeResource(r,
					     R.drawable.ijiroidhi);
	  ijiroidmi = BitmapFactory.decodeResource(r,
					     R.drawable.ijiroidmi);
	  ijiroidma = BitmapFactory.decodeResource(r,
			             R.drawable.ijiroidma);
	  setFocusable(true);
		}
		
	  public Bitmap ijiroid;
	  public Bitmap ijiroidhi;
	  public Bitmap ijiroidmi;
	  public Bitmap ijiroidma;
	  public int x;
	  public int y;
	  
	  
	  
	  	  
		@Override
	public boolean onTouchEvent(MotionEvent event){
		// TODO Auto-generated method stub
	    
		x = (int)event.getX();
		y = (int)event.getY();
		Log.v("TouchEvent", "X:" + event.getX() + ",Y:" + event.getY());

		return true;
		}
		
	
		@Override
		public void onDraw(Canvas canvas){
			if(0<x && x<120)
			{
				Log.v("TouchEvent2", "A:" + x + ",B:" + y);
				int w = ijiroidhi.getWidth();
		        int h = ijiroidhi.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
		        canvas.drawBitmap(ijiroidhi, src, dst, null);
			}else if(155<=x && x<185 )
			{
				int w = ijiroidhi.getWidth();
		        int h = ijiroidhi.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
				canvas.drawBitmap(ijiroidma,src,dst,null);
			}else if(220<=x && x<320 )
			{
				int w = ijiroidhi.getWidth();
		        int h = ijiroidhi.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
				canvas.drawBitmap(ijiroidmi,src,dst,null);
			}else{
				int w = ijiroidhi.getWidth();
		        int h = ijiroidhi.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
				canvas.drawBitmap(ijiroid,src,dst,null);
			}
			}
		}
}





package com.ijiroid3;

import java.util.ArrayList;

import com.ijiroid3.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.util.Log;

public class Ijiroid3 extends Activity {
	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 requestWindowFeature(Window.FEATURE_NO_TITLE);
		 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
		 MyView view = new MyView(this);
		 setContentView(view);
		}
	
	
	class MyView extends View {
		public MyView(Context context) {
		super(context);
		
		 Resources r = context.getResources();
	
		 image2917 = BitmapFactory.decodeResource(r,
			             R.drawable.image2917);
		 image2918 = BitmapFactory.decodeResource(r,
					     R.drawable.image2918);
		 image2919 = BitmapFactory.decodeResource(r,
					     R.drawable.image2919);
		 image2920 = BitmapFactory.decodeResource(r,
			             R.drawable.image2920);
	  setFocusable(true);
		}
		
	  public Bitmap image2917;
	  public Bitmap image2918;
	  public Bitmap image2919;
	  public Bitmap image2920;
	  public int A=0;
	  public int B=0;
	  public int x;
	  public int y;
	  public int z=0;
	  	  
		@Override
	public boolean onTouchEvent(MotionEvent event){
		// TODO Auto-generated method stub
	    
		x = (int)event.getX();
		y = (int)event.getY();
		//Log.v("TouchEvent", "X:" + event.getX() + ",Y:" + event.getY());
		
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
	        //Log.d("TouchEvent", "getAction()" + "ACTION_DOWN");
	        A=1;
	        break;
	    case MotionEvent.ACTION_UP:
	        //Log.d("TouchEvent", "getAction()" + "ACTION_UP");
	        A=0;
	        break;
	    case MotionEvent.ACTION_MOVE:
	        //Log.d("TouchEvent", "getAction()" + "ACTION_MOVE");
	        A=2;
	        break;
	    case MotionEvent.ACTION_CANCEL:
	        //Log.d("TouchEvent", "getAction()" + "ACTION_CANCEL");
	        A=3;
	        break;
		}

		return true;
		}

		@Override
		public void onDraw(Canvas canvas){
			if(A==1)
			{
				B++;
			}
			if(A==2)
			{
				B++;
			}
			if(A==3)
			{
				B--;
			}
			Log.v("TouchEvent2","B:" + B);
			if(20<B && B<40)
			{
				//Log.v("TouchEvent2", "A:" + x + ",B:" + y);
				int w = image2917.getWidth();
		        int h = image2917.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
		        canvas.drawBitmap(image2918, src, dst, null);
			}else if(40<=B && B<60)
			{
				int w = image2917.getWidth();
		        int h = image2917.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
				canvas.drawBitmap(image2919,src,dst,null);
			}else if(60<=B)
			{
				int w = image2917.getWidth();
		        int h = image2917.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
				canvas.drawBitmap(image2920,src,dst,null);
			}else{
				int w = image2917.getWidth();
		        int h = image2917.getHeight();

		        Rect src = new Rect(0, 0, w, h);

		        Rect dst = new Rect(0, 0, w*2, h*2);
				canvas.drawBitmap(image2917,src,dst,null);
			}
			if(170<x && x<200 && 260<y)
			{
				B=0;
			}
			}
		}
}



AndroidManifest?

http://techbooster.jpn.org/andriod/application/715/ http://techbooster.jpn.org/andriod/device/1437/ http://wikiwiki.jp/android/



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS