Commit 61a67d0c authored by Daniel Dutra Rufasto's avatar Daniel Dutra Rufasto
Browse files

Criado MapView, LocationLister, MapActivity

parent fecffd2c
...@@ -2,11 +2,16 @@ ...@@ -2,11 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ufpr.inf.pet.geoloc" > package="ufpr.inf.pet.geoloc" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme" >
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" > android:label="@string/app_name" >
...@@ -16,9 +21,10 @@ ...@@ -16,9 +21,10 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".MapActivity"
android:label="@string/title_activity_map" >
</activity>
</application> </application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
</manifest> </manifest>
package ufpr.inf.pet.geoloc;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
/**
* Created by pet on 23/09/15.
*/
public class GelocLocationListener implements LocationListener {
private boolean upateMapView = true;
private MapView mapView;
public GelocLocationListener(MapActivity mapActivity, MapView mapView) {
this.mapView = mapView;
}
@Override
public void onLocationChanged(Location location) {
float lat;
float lng;
float alt;
do {
lat = (float) (location.getLatitude());
lng = (float) (location.getLongitude());
alt = (float) (location.getAltitude());
}while(!upateMapView && location == null); //Só atualiza os textos se não estiver pausado e o location tiver uma posição
Log.d(MainActivity.TAG, "Latitude: " + String.valueOf(lat));
Log.d(MainActivity.TAG, "Longitude: " + String.valueOf(lng));
Log.d(MainActivity.TAG, "Altitude: " + String.valueOf(alt));
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
Log.d(MainActivity.TAG, "Novo provedor habilitado: " + provider);
}
@Override
public void onProviderDisabled(String provider) {
Log.d(MainActivity.TAG, "Provedor desabilitado: " + provider);
}
public void setUpateMapView(boolean upateMapView) {
this.upateMapView = upateMapView;
}
public void setMapView(MapView mapView) {
this.mapView = mapView;
}
}
...@@ -17,6 +17,7 @@ import android.util.DisplayMetrics; ...@@ -17,6 +17,7 @@ import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
...@@ -33,7 +34,7 @@ import java.net.URL; ...@@ -33,7 +34,7 @@ import java.net.URL;
public class MainActivity extends ActionBarActivity implements LocationListener { public class MainActivity extends ActionBarActivity implements LocationListener {
protected static final String TAG = "geoloc"; public static final String TAG = "geoloc";
/** /**
* Última localização obtida * Última localização obtida
...@@ -166,4 +167,9 @@ public class MainActivity extends ActionBarActivity implements LocationListener ...@@ -166,4 +167,9 @@ public class MainActivity extends ActionBarActivity implements LocationListener
public void onProviderDisabled(String provider) { public void onProviderDisabled(String provider) {
Log.d(TAG, "Provedor desabilitado: " + provider); Log.d(TAG, "Provedor desabilitado: " + provider);
} }
public void openMap(View view){
Intent mapAcitivityIntent = new Intent(this,MapActivity.class);
startActivity(mapAcitivityIntent);
}
} }
package ufpr.inf.pet.geoloc;
import android.app.DialogFragment;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MapActivity extends ActionBarActivity {
private MapView mapView;
private LocationManager locationManager;
private GelocLocationListener locationListener;
private String provider;
private void init(){
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
this.locationListener = new GelocLocationListener(this,mapView);
this.locationManager = (LocationManager) this.getSystemService(this.LOCATION_SERVICE);
//Verify if the gps is enable, if not ask(s?) for the user enable it
boolean isGPSEnabled = false;
do{
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
DialogFragment dialog = new EnableGpsDialogFragment();
dialog.show(getFragmentManager(), "habilitar gps");
}
while(!isGPSEnabled);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location lastLocation = locationManager.getLastKnownLocation(provider);
if(lastLocation != null){
Log.d(MainActivity.TAG, "Provedor " + provider + " foi selecionado.");
}else{
Log.d(MainActivity.TAG, "Sem localização!");
}
//TODO: See if the time and the distance selected are the best
locationManager.requestLocationUpdates(provider, 400, 1, locationListener);
}
//TODO: See if the menu is needed
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_map, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
package ufpr.inf.pet.geoloc;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.location.Location;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by pet on 23/09/15.
*/
public class MapView extends View {
private int viewWidth;
private int viewHeight;
private TilesProvider tilesProvider;
private TilesManager tilesManager;
private Paint fontPaint;
private Paint circlePaint;
private PointD seekLocation;
private Location gpsLocation;
public MapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setGpsLocation(Location location){
this.gpsLocation=location;
}
public void drawTiles(Canvas canvas,int pointOffset){
}
public void onDraw(Canvas canvas){
}
}
...@@ -38,4 +38,13 @@ ...@@ -38,4 +38,13 @@
android:layout_below="@+id/altitude_label" android:layout_below="@+id/altitude_label"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="113dp" /> android:layout_marginTop="113dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mapa"
android:id="@+id/mapBt"
android:layout_alignBottom="@+id/tile_image"
android:layout_centerHorizontal="true"
android:onClick="openMap"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="ufpr.inf.pet.geoloc.MapActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
</LinearLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context="ufpr.inf.pet.geoloc.MapActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
<resources>
<declare-styleable name="MapView">
<attr name="exampleString" format="string" />
<attr name="exampleDimension" format="dimension" />
<attr name="exampleColor" format="color" />
<attr name="exampleDrawable" format="color|reference" />
</declare-styleable>
</resources>
...@@ -8,4 +8,5 @@ ...@@ -8,4 +8,5 @@
<string name="dialog_warn">Aviso</string> <string name="dialog_warn">Aviso</string>
<string name="dialog_enable_gps">Habilitar o GPS</string> <string name="dialog_enable_gps">Habilitar o GPS</string>
<string name="cancel">Cancelar</string> <string name="cancel">Cancelar</string>
<string name="title_activity_map">MapActivity</string>
</resources> </resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment