Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import java.io.File;
import java.util.ArrayList;
public class MainCanvas extends AppCompatActivity {
private CView canvas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main_canvas);
getReadStoragePermission();
canvas = new CView(this);
setContentView(canvas);
}
private class CView extends View{
public CView(Context context){
super(context);
}
private double[] linearEquation(double x1,double x2,double y1,double y2){
double[] mb = new double[2];
mb[0] = (y2-y1)/(x2-x1);
mb[1] = y2 - mb[0]*x2;
return mb;
}
private int locationCalc(double[] mb, double x){
return (int)(mb[0]*x + mb[1]);
}
private int[] imageLocations(ImageCollections imgc, JpgMetadata jpgData){
ImageView image = (ImageView) findViewById(R.id.canvasView);
int imageWidth = canvas.getWidth();
int imageHeight = canvas.getHeight();
//double[] linEq_width = linearEquation(0, imageWidth, imgc.getNw_lon(), imgc.getSe_lon());
//double[] linEq_height = linearEquation(0, imageHeight, imgc.getSe_lat(), imgc.getNw_lat());
double[] latlon = jpgData.getDecimalLatLon();
int[] XY = new int[2];
//jpgData.setX_location_onImage(XY[0] = locationCalc(linEq_width, latlon[1]));
//jpgData.setY_location_onImage(XY[1] = locationCalc(linEq_height, latlon[0]));
jpgData.setX_location_onImage(XY[0] = (int)(imageWidth/360 + (180 + latlon[1])));
jpgData.setY_location_onImage(XY[1] = (int)(imageHeight/180 + (90 - latlon[0])));
return XY;
}
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//ImageView myImage = (ImageView) findViewById(R.id.canvasView);
//Bitmap tempBitmap = Bitmap.createBitmap(myImage.getWidth(), myImage.getHeight(), Bitmap.Config.RGB_565);
//Canvas tempCanvas = new Canvas(tempBitmap);
String dirPath = System.getenv("EXTERNAL_STORAGE") + "/Pictures/volga_field_dji/";
ArrayList<JpgMetadata> listJpgData = ImageDataParser.iterateFiles(dirPath);
ImageCollections imgCollections = new ImageCollections(dirPath, listJpgData);
for(int i = 0; i < listJpgData.size(); i ++){
JpgMetadata jpgData = listJpgData.get(i);
File file = jpgData.getFile();
Log.d("Image INSERT:" , "inserting " + jpgData.getName());
if(file.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
int[] XY = imageLocations(imgCollections, jpgData);
Paint p = new Paint();
Log.d("InsertLocations:", "X:" + String.valueOf(XY[0]) + " " + "Y:" + String.valueOf(XY[1]));
Log.d("SizeOfCanvas :", "Width:" + String.valueOf(canvas.getWidth()) + " " + "Height:" + String.valueOf(canvas.getHeight()));
canvas.drawBitmap(Bitmap.createScaledBitmap(myBitmap, 50, 50, false), XY[0], XY[1], p);
}
}
//myImage.setImageDrawable(new BitmapDrawable(getResources(), tempBitmap));
}
}
private void getReadStoragePermission() {
if(checkPermissionForReadExtertalStorage()){
//everything gucci
return;
}else{
try {
requestPermissionForReadExtertalStorage();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private boolean checkPermissionForReadExtertalStorage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int result = this.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED;
}
return false;
}
public void requestPermissionForReadExtertalStorage() throws Exception {
try {
ActivityCompat.requestPermissions((Activity) this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
1);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment