ecsoftware/directionboard — pull request #6 by spremkumar09 (2014-03-20 10:09:12+00:00)
Title: highlight sections in direction board

package com.example.image;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnTouchListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView topimage=(ImageView)findViewById(R.id.image_areas);

topimage.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
float eventX = event.getX();
float eventY = event.getY();
float[] eventXY = new float[] {eventX, eventY};

Matrix invertMatrix = new Matrix();
((ImageView)v).getImageMatrix().invert(invertMatrix);

invertMatrix.mapPoints(eventXY);
int x = Integer.valueOf((int)eventXY[0]);
int y = Integer.valueOf((int)eventXY[1]);
ImageView img=((ImageView)v);
Bitmap bitmap=((BitmapDrawable)img.getDrawable()).getBitmap();
if(x < 0){
x = 0;
}else if(x > bitmap.getWidth()-1){
x = bitmap.getWidth()-1;
}

if(y < 0){
y = 0;
}else if(y > bitmap.getHeight()-1){
y = bitmap.getHeight()-1;
}

int pixel = bitmap.getPixel(x,y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
Log.e("x1", String.valueOf(Integer.toHexString(pixel)));
Log.e("x2", String.valueOf(blueValue));
Log.e("x3", String.valueOf(greenValue));

String color=String.valueOf(Integer.toHexString(pixel));
if(color.equals("ffba0000")){
Toast.makeText(getApplicationContext(), "WOW!",
Toast.LENGTH_LONG).show();
}
if(color.equals("ff244aaa")){
Toast.makeText(getApplicationContext(), "Hi!",
Toast.LENGTH_LONG).show();
}
if(pixel == Color.GREEN){
Log.e("ggg", "Magenta");
}
break;
}
/* int x=0;
int y=0;
ImageView img=((ImageView)v);
Bitmap bitmap=((BitmapDrawable)img.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);*/
return true;
}
});

}

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}

}