Skip to content

Commit

Permalink
Activity for entering lat lon by hand.
Browse files Browse the repository at this point in the history
Clear redundant source code.
Allow changing sportsCategory everytime.
  • Loading branch information
Starcommander committed Oct 7, 2018
1 parent 62c0503 commit e072058
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 89 deletions.
6 changes: 6 additions & 0 deletions PocketMaps/app/src/main/AndroidManifest.xml
Expand Up @@ -38,6 +38,12 @@
android:screenOrientation="portrait"
android:theme="@style/MYAppTheme" >
</activity>
<activity
android:name=".activities.LatLonActivity"
android:label="@string/enter_lat_lon"
android:screenOrientation="portrait"
android:theme="@style/MYAppTheme" >
</activity>
<activity
android:name=".activities.DownloadMapActivity"
android:label="@string/title_activity_download"
Expand Down
Expand Up @@ -4,7 +4,6 @@
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
Expand All @@ -17,7 +16,6 @@
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.junjunguo.pocketmaps.R;
import com.junjunguo.pocketmaps.db.DBtrackingPoints;
import com.junjunguo.pocketmaps.model.SportCategory;
import com.junjunguo.pocketmaps.model.listeners.TrackingListener;
import com.junjunguo.pocketmaps.map.Tracking;
Expand Down
@@ -0,0 +1,140 @@
package com.junjunguo.pocketmaps.activities;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Properties;

import org.oscim.core.GeoPoint;

import com.junjunguo.pocketmaps.R;
import com.junjunguo.pocketmaps.fragments.MessageDialog;
import com.junjunguo.pocketmaps.fragments.MyAddressAdapter;
import com.junjunguo.pocketmaps.geocoding.AddressLoc;
import com.junjunguo.pocketmaps.geocoding.GeocoderGlobal;
import com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener;
import com.junjunguo.pocketmaps.util.Variable;

import android.content.Context;
import android.location.Address;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;

public class LatLonActivity extends AppCompatActivity implements OnClickListener
{
private static OnClickAddressListener callbackListener;
EditText txtLat;
EditText txtLon;
Button okButton;

/** Set pre-settings.
* @param newCallbackListener The Callback listener, called on selected Address. **/
public static void setPre(OnClickAddressListener newCallbackListener)
{
callbackListener = newCallbackListener;
}

@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_latlon);
okButton = (Button) findViewById(R.id.latLonEnterOk);
txtLat = (EditText) findViewById(R.id.latLocationEnter);
txtLon = (EditText) findViewById(R.id.lonLocationEnter);
okButton.setOnClickListener(this);
}

@Override protected void onResume()
{
super.onResume();
}

@Override protected void onDestroy()
{
super.onDestroy();
}

@Override
public void onClick(View v)
{
if (v.getId()==R.id.latLonEnterOk)
{
log("Selected: Ok for LatLon");
double lat = 0;
double lon = 0;
try
{
lat = Double.parseDouble(txtLat.getText().toString());
lon = Double.parseDouble(txtLon.getText().toString());
}
catch (NumberFormatException e)
{
logUser("Nuber format error! Enter number as 111.123");
return;
}
if (lat>90)
{
logUser("Latitude must not be more than 90");
return;
}
if (lat<-90)
{
logUser("Latitude must not be less than -90");
return;
}
if (lon>180)
{
logUser("Longitude must not be more than 180");
return;
}
if (lon<-180)
{
logUser("Longitude must not be less than -180");
return;
}
Address address = new Address(Locale.GERMANY);
address.setLatitude(lat);
address.setLongitude(lon);
address.setAddressLine(0, "" + lat + ", " + lon);
LatLonActivity.this.finish();
callbackListener.onClick(address);
}
}

private void log(String str)
{
Log.i(LatLonActivity.class.getName(), str);
}

private void logUser(String str)
{
Log.i(LatLonActivity.class.getName(), str);
try
{
Toast.makeText(this.getBaseContext(), str, Toast.LENGTH_SHORT).show();
}
catch (Exception e) { e.printStackTrace(); }
}
}

0 comments on commit e072058

Please sign in to comment.