Skip to content

Commit

Permalink
Completed ChartActivity.java. Base features complete.
Browse files Browse the repository at this point in the history
TODO:
AddChart.java Require name to be filled
Allow Deletion and Updating of airports and charts
  • Loading branch information
daniyaalk committed May 24, 2019
1 parent c4255e2 commit b667738
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 38 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ChartActivity" />
<activity android:name=".ChartActivity" >
</activity>
</application>

</manifest>
35 changes: 33 additions & 2 deletions app/src/main/java/com/daniyaalkhan/imgmap/AddPoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.PointF;
import android.net.Uri;
Expand All @@ -23,6 +24,7 @@
import org.w3c.dom.Text;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Arrays;

Expand Down Expand Up @@ -129,6 +131,7 @@ public void onClick(View v) {
String name=extras.getString("name");

Uri uri = Uri.parse(extras.getString("uri"));
Log.i("URIx", uri.getPath());

PointF geocoords1, geocoords2, pixelcoords1, pixelcoords2;

Expand All @@ -140,11 +143,39 @@ public void onClick(View v) {
geocoords2 = new PointF(Float.valueOf(geoCoordsString[0]), Float.valueOf(geoCoordsString[1]));
pixelcoords2 = new PointF(Float.valueOf(pixelCoordsString[0]), Float.valueOf(pixelCoordsString[1]));

//Get Scaling
int imageViewHeight=chartView.getHeight(), imageViewWidth=chartView.getWidth();
int imageResx, imageResy;

//Get Image dimensions
BitmapFactory.Options dimensions = new BitmapFactory.Options();
dimensions.inJustDecodeBounds = true;
Bitmap mBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
try{
InputStream ims = getContentResolver().openInputStream(uri);
mBitmap = BitmapFactory.decodeStream(ims);
}catch (Exception e){
Toast.makeText(context,"Couldn't add chart", Toast.LENGTH_SHORT).show();
Intent goHome = new Intent(getApplicationContext(), MainActivity.class);
startActivity(goHome);
}
imageResx = mBitmap.getWidth();
imageResy = mBitmap.getHeight();

//Set Scaled values
PointF scaledPixelcoords1, scaledPixelcoords2;
scaledPixelcoords1 = new PointF(
(pixelcoords1.x/imageViewWidth)*imageResx, (pixelcoords1.y/imageViewHeight)*imageResy
);
scaledPixelcoords2 = new PointF(
(pixelcoords2.x/imageViewWidth)*imageResx, (pixelcoords2.y/imageViewHeight)*imageResy
);

//Send Received values to DB
Log.d("Reached", "yup");
DBHandler db = new DBHandler(context);
boolean addToDB = db.addChart(icao, Uri.parse(extras.getString("uri")),
geocoords1, geocoords2, pixelcoords1, pixelcoords2, name, context);
boolean addToDB = db.addChart(icao, uri,
geocoords1, geocoords2, scaledPixelcoords1, scaledPixelcoords2, name, context);
if(!addToDB){

Toast failed = Toast.makeText(context, "Failed to add to database", Toast.LENGTH_SHORT);
Expand Down
53 changes: 20 additions & 33 deletions app/src/main/java/com/daniyaalkhan/imgmap/ChartActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory;
import android.graphics.PointF;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.PermissionChecker;
Expand All @@ -33,11 +33,11 @@ public class ChartActivity extends Activity implements LocationListener{
private ImgMap imgMap;
private ImageView locationPin;



private int chartPicture;
private ImageView chartView;

private int imageWidth, imageHeight;
private double[][] cords1, cords2;

String[] appPermissions = {
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
Expand All @@ -49,41 +49,16 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chart_activity);

double[][] cords1, cords2;

Bundle chartName = getIntent().getExtras();
Log.i("chartName", chartName.getString("icao"));

if(chartName.getString("icao").equals("VAAU")){
this.chartPicture = R.drawable.mozilla_page_011;

//Cords for VAAU testing:
cords1 = new double[][]{{20.16666667, 75.16666667}, {264, 192}};
cords2 = new double[][]{{19.66666667, 75.66666667}, {1054, 960}};
}else{
this.chartPicture = R.drawable.vidp_sid;

//Cords for VIDP testing:
cords1 = new double[][]{{28.75000000,75.88222222}, {197, 225}};
cords2 = new double[][]{{27.83333333,77.71666667}, {700, 1100}};
}

Bundle extras = getIntent().getExtras();

this.chartView = findViewById(R.id.chartView);
this.chartView.setImageResource(this.chartPicture);
this.locationPin = findViewById(R.id.locationPin);
this.textView = findViewById(R.id.textView);

//Get image dimensions
BitmapFactory.Options dimensions = new BitmapFactory.Options();
dimensions.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), chartPicture, dimensions);
int imageHeight = dimensions.outHeight;
int imageWidth = dimensions.outWidth;

setChartData(extras.getInt("id"));

imgMap = new ImgMap(cords1, cords2);
imgMap.setScaleRes(imageWidth, imageHeight);
imgMap.setScaleRes(this.imageWidth, this.imageHeight);

/* LOCATION CODE BELOW THIS POINT */
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Expand All @@ -97,7 +72,19 @@ protected void onCreate(Bundle savedInstanceState) {

}

private PointF pointf = new PointF();
private void setChartData(int id){

DBHandler db = new DBHandler(this);

Chart chart = db.getChart(id);

this.chartView.setImageBitmap(chart.chartBitmap);
this.cords1 = chart.coords1;
this.cords2 = chart.coords2;
this.imageHeight = chart.imageHeight;
this.imageWidth = chart.imageWidth;

}

@Override
public void onLocationChanged(Location location){
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/daniyaalkhan/imgmap/Charts.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ private void populateListView(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int chartId = chartsList.get(position).id;
Log.d("ChartId", String.valueOf(chartId));
Intent openChart = new Intent(getApplicationContext(), ChartActivity.class);
openChart.putExtra("id", chartId);
startActivity(openChart);
}
});

Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/daniyaalkhan/imgmap/DBHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public boolean addChart(String icao, Uri uri, PointF geoCoords1, PointF geoCoord
return false;
}

//Convert Image to ByteArray
ByteArrayOutputStream stream = new ByteArrayOutputStream();
chartBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
Expand Down Expand Up @@ -162,4 +163,31 @@ public List<Chart> getChartsList(String icao){
return chartsList;

}

public Chart getChart(int id){

SQLiteDatabase db = getReadableDatabase();

String query = "SELECT * FROM charts WHERE id=?";
Cursor cursor = db.rawQuery(query, new String[]{String.valueOf(id)});

cursor.moveToFirst();

Chart chart = new Chart();

chart.id = id;
chart.name = cursor.getString(cursor.getColumnIndex("name"));
chart.coords1 = new double[][]{
{cursor.getDouble(cursor.getColumnIndex("cords1x")), cursor.getDouble(cursor.getColumnIndex("cords1y"))},
{cursor.getDouble(cursor.getColumnIndex("pixel1y")), cursor.getDouble(cursor.getColumnIndex("pixel1x"))}
};
chart.coords2 = new double[][]{
{cursor.getDouble(cursor.getColumnIndex("cords2x")), cursor.getDouble(cursor.getColumnIndex("cords2y"))},
{cursor.getDouble(cursor.getColumnIndex("pixel2y")), cursor.getDouble(cursor.getColumnIndex("pixel2x"))}
};
chart.setBitmap(cursor.getBlob(cursor.getColumnIndex("chart")));

return chart;

}
}
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_add_points.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

<ImageView
android:id="@+id/chartView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
app:srcCompat="@android:drawable/screen_background_dark_transparent" />

Expand Down

0 comments on commit b667738

Please sign in to comment.