FrontPage

IDEOS

ここはandroid端末のIDEOSについて語る場です

スペック


■OS: Android 2.2
■CPU: 528MHz
■RAM: 256MB + 512MB NAND,200MB
■外部メモリ: microSD/microSDHC(最大16GB)
■ディスプレイ: 2.8インチ QVGA (320×240) TFTタッチパネル
■カメラ: 3.2MP
■サイズ: 104×54.8×13.5mm

IJIROID

現在制作中のANDROID版IJIRO

■試作品1
動画 うまく撮れないので今後に期待。背景黒だからかな…。


プログラム(コメントは今後追加します)
メモ:プログラムが長いので文字を収納する方法を調べる。

 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);
  }

  /**
   * ijiroを移動する。
   *
   * @param mx
   * @param my
   */
  public void move(float mx, float my) {
   this.x -= (mx * 2f);//動く速さ
   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);
   }

   }
  }
 }



■試作品2
動画


プログラム

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());
		invalidate(); // 通知
		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);
			}
			}
		}
}



■試作品3
動画
ネットから拾った画像加工したやつだからあげていいのか…あとで画像作り直して動画にします


プログラム

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;
		}
		invalidate(); // 通知
		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?のactivity内にandroid:screenOrientation="portrait(landscape)"で縦(横)固定が出来る

参考サイト

タッチイベント http://techbooster.jpn.org/andriod/application/715/
センサの取得 http://techbooster.jpn.org/andriod/device/1437/
色々      http://wikiwiki.jp/android/


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-08-07 (日) 14:36:12 (437d)