現在位置をGPSで取得し、目的地の座標を予め入れておき、現在位置から目的地の方向を算出しその方向を矢印によって動的に描画をさせるプログラムを開発している途中なのですが、
このプログラムをどのようにすれば透過できるでしょうか。
アプリ開発初心者なので、サーフェスビューの知識が浅く、すでにこのプログラムで使用しているのでどのようにカメラを透過すればいいか教えていただきたいです。
Android
1 2package com.example.admin.arview1; 3 4 5public class Main extends Activity implements SensorEventListener, LocationListener 6{ 7 private SensorManager sensorManager; 8 private Sensor accelerometer; 9 private MainActivity view; 10 protected final static double RAD2DEG = 180/Math.PI; 11 private boolean isSensorResisted = false; 12 private static float orientation; 13 14 private LocationManager locationManager; 15 private TextView textView; 16 private String text = "start\n"; 17 private Button buttonStart, buttonStop; 18 19 private static final int MinTime = 0; 20 private static final float MinDistance = 0; 21 private final int REQUEST_PERMISSION = 1000; 22 23 24 public void onCreate(Bundle savedInstanceState) { 25 26 super.onCreate(savedInstanceState); 27 28 // 画面を縦表示で固定 29 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 30 31 view = new MainActivity(this); 32 setContentView(view); 33 34 //センサーマネージャの取得 35 sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); 36 37 //センサーの取得 38 List<Sensor> list; 39 list = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); 40 if (list.size() > 0) accelerometer = list.get(0); 41 List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION); 42 if (sensors.size() > 0) { 43 isSensorResisted = sensorManager.registerListener(this, sensors.get(0), SensorManager.SENSOR_DELAY_FASTEST); 44 45 46 47 48 } 49 50*******省略********** 51 52 53 54}
Android
1 2package com.example.admin.arview1; 3 4public class MainActivity extends SurfaceView implements SurfaceHolder.Callback, Runnable{ 5 6 private int gx; 7 private int gy; 8 private int ori; 9 private Paint paint; 10 private SurfaceHolder holder; 11 private Thread thread; 12 private int width; 13 private int height; 14 TextView textView; 15 public String gx2; 16 private Bitmap a,b,c,d,e,f,g,h,a1,a2,a3,a4,a5; 17 18 Calculate calc = new Calculate(); 19 double latitude1 = 35.625068; 20 double longitude1 = 139.343907; 21 double latitude2 = 35.625783; 22 double longitude2 = 139.345091; 23 int ans; 24 25 public MainActivity(Context context) 26 { 27 super(context); 28 holder = null; 29 thread = null; 30 paint = new Paint(); 31 paint.setAntiAlias(true); 32 gx = gy = 0; 33 a = BitmapFactory.decodeResource(getResources(), R.drawable.a); 34 b = BitmapFactory.decodeResource(getResources(), R.drawable.b); 35 c = BitmapFactory.decodeResource(getResources(), R.drawable.c); 36 d = BitmapFactory.decodeResource(getResources(), R.drawable.d); 37 e = BitmapFactory.decodeResource(getResources(), R.drawable.e); 38 f = BitmapFactory.decodeResource(getResources(), R.drawable.f); 39 g = BitmapFactory.decodeResource(getResources(), R.drawable.g); 40 h = BitmapFactory.decodeResource(getResources(), R.drawable.h); 41 a1 = BitmapFactory.decodeResource(getResources(), R.drawable.a1); 42 a2 = BitmapFactory.decodeResource(getResources(), R.drawable.a2); 43 a3 = BitmapFactory.decodeResource(getResources(), R.drawable.a3); 44 a4 = BitmapFactory.decodeResource(getResources(), R.drawable.a4); 45 a5 = BitmapFactory.decodeResource(getResources(), R.drawable.a5); 46 47 48 // getHolder()メソッドでSurfaceHolderを取得。さらにコールバックを登録 49 getHolder().addCallback(this); 50 } 51 52 //SurfaceView生成時に呼び出される 53 public void surfaceCreated(SurfaceHolder holder) 54 { 55 this.holder = holder; 56 thread = new Thread(this); 57// textView = (TextView)findViewById(R.id.textView); 58 ans = calc.getDirection(latitude1,longitude1,latitude2,longitude2); 59 } 60 61 //SurfaceView変更時に呼び出される 62 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) 63 { 64 if(thread != null ) 65 { 66 this.width = width; 67 this.height = height; 68 thread.start(); 69 } 70 71 } 72 73 //SurfaceView破棄時に呼び出される 74 public void surfaceDestroyed(SurfaceHolder holder) 75 { 76 thread = null; 77 } 78 79 //スレッドによるSurfaceView更新処理 80 public void run() 81 { 82 83 while (thread != null) 84 { 85 86 Log.d("aaaaaa",String.valueOf(ori)); 87 Canvas canvas = holder.lockCanvas(); 88// canvas.drawColor(Color.argb(255, 0, 0, 0)); 89 90// Log.d("aaaaaa",String.valueOf(gx2)); 91 92 if(gy >= -200 && gy <= 70 ) { 93 canvas.drawBitmap(a, 0, 600, paint); 94 95 } 96 if(gy > 70 && gy <= 140) { 97 canvas.drawBitmap(b, 0, 600, paint); 98 99 } 100 if(gy > 140 && gy <= 210) { 101 canvas.drawBitmap(c, 0, 600, paint); 102 103 } 104 if(gy > 210 && gy <= 280) { 105 canvas.drawBitmap(d, 0, 600, paint); 106 107 } 108 if(gy > 280 && gy <= 350) { 109 canvas.drawBitmap(e, 0, 600, paint); 110 111 } 112 if(gy > 350 && gy <= 420) { 113 canvas.drawBitmap(f, 0, 600, paint); 114 115 } 116 if(gy > 420 && gy <= 490) { 117 canvas.drawBitmap(g, 0, 600, paint); 118 119 } 120 else if(gy > 490 && gy <= 560){ 121 canvas.drawBitmap(h, 0, 600, paint); 122 } 123 124 125 126 127 128 if(gy >= -200 && gy <= 140 && ori <= 300+ans && ori >= 270+ans ) { 129 canvas.drawBitmap(a5, 0, 600, paint); 130 131 } 132 if(gy > -200 && gy <= 140 && ori > 300+ans && ori <= 360+ans ) { 133 canvas.drawBitmap(a4, 0, 600, paint); 134 135 } 136 if(gy > -200 && gy <= 140 && ori > 330+ans && ori <= 360+ans ) { 137 canvas.drawBitmap(a3, 0, 600, paint); 138 139 } 140 if(gy > -200 && gy <= 140 && ori > 0+ans && ori <= 60+ans) { 141 canvas.drawBitmap(a2, 0, 600, paint); 142 143 } 144 if(gy > -200 && gy <= 140 && ori > 60+ans && ori <= 90+ans) { 145 canvas.drawBitmap(a1, 0, 600, paint); 146 147 } 148 149 holder.unlockCanvasAndPost(canvas); 150 } 151 } 152 153 154 155 // 加速度の更新 156 public void setAcce(int gx, int gy) 157 { 158 this.gx = gx; 159 this.gy = gy; 160 this.gx2 = String.valueOf(gx); 161 } 162 163 //方位の更新 164 public void setOrientation(float ori) { 165 166 this.ori = (int)ori; 167 } 168}
あなたの回答
tips
プレビュー