compileSdkVersion updated and tabbed interface - yay

master
y20k 2016-10-25 16:38:27 +02:00
parent c9e1f1c750
commit 4905e4258d
7 changed files with 103 additions and 114 deletions

View File

@ -1,15 +1,15 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 24 compileSdkVersion 25
buildToolsVersion "24.0.3" buildToolsVersion "24.0.3"
defaultConfig { defaultConfig {
applicationId "org.y20k.trackbook" applicationId "org.y20k.trackbook"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 24 targetSdkVersion 25
versionCode 6 versionCode 7
versionName "0.9.5 (The Great Gig in the Sky)" versionName "1.0.0 (Astronomy Domine )"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }
buildTypes { buildTypes {
@ -23,8 +23,8 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:24.2.1' compile 'com.android.support:design:25.0.0'
compile 'org.osmdroid:osmdroid-android:5.4.1:release@aar' compile 'org.osmdroid:osmdroid-android:5.5:release@aar'
compile 'com.google.code.gson:gson:2.7' compile 'com.google.code.gson:gson:2.7'
} }

View File

@ -42,6 +42,7 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
@ -71,6 +72,7 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
private List<String> mMissingPermissions; private List<String> mMissingPermissions;
private FloatingActionButton mFloatingActionButton; private FloatingActionButton mFloatingActionButton;
private MainActivityMapFragment mMainActivityMapFragment; private MainActivityMapFragment mMainActivityMapFragment;
private MainActivityTrackFragment mMainActivityTrackFragment;
private BroadcastReceiver mTrackingStoppedReceiver; private BroadcastReceiver mTrackingStoppedReceiver;
private int mSelectedTab; private int mSelectedTab;
@ -101,7 +103,39 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
// set up main layout // set up main layout
setupLayout(); setupLayout();
// setupTestLayout();
}
@Override
protected void onStart() {
super.onStart();
// add listeners to button
if (mFloatingActionButton != null) {
mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// onClick: start / stop tracking
handleFloatingActionButtonClick(view);
}
});
mFloatingActionButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
// onLongClick: clear map
if (mTrackerServiceRunning || mMainActivityMapFragment == null) {
return false;
} else {
// show clear dialog
DialogFragment dialog = new DialogClearFragment();
dialog.show(getFragmentManager(), "DialogClearFragment");
return true;
}
}
});
}
// register broadcast receiver for stopped tracking // register broadcast receiver for stopped tracking
mTrackingStoppedReceiver = createTrackingStoppedReceiver(); mTrackingStoppedReceiver = createTrackingStoppedReceiver();
@ -216,6 +250,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
// clear the map // clear the map
mMainActivityMapFragment.clearMap(); mMainActivityMapFragment.clearMap();
// reset current track
mMainActivityTrackFragment.refreshTrackView();
// dismiss notification // dismiss notification
NotificationHelper.stop(); NotificationHelper.stop();
} }
@ -230,66 +267,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
/* Set up main layout */ /* Set up main layout */
private void setupLayout() { private void setupLayout() {
if (mPermissionsGranted) {
// point to the main map layout
setContentView(R.layout.activity_main);
// show action bar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// get reference to fragment
mMainActivityMapFragment = (MainActivityMapFragment)getSupportFragmentManager().findFragmentById(R.id.content_main);
// show the record button and attach listener
mFloatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// onClick: start / stop tracking
handleFloatingActionButtonClick(view);
}
});
mFloatingActionButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
// onLongClick: clear map
if (mTrackerServiceRunning || mMainActivityMapFragment == null) {
return false;
} else {
// show clear dialog
DialogFragment dialog = new DialogClearFragment();
dialog.show(getFragmentManager(), "DialogClearFragment");
return true;
}
}
});
} else {
// point to the on main onboarding layout
setContentView(R.layout.activity_main_onboarding);
// show the okay button and attach listener
Button okButton = (Button) findViewById(R.id.button_okay);
okButton.setOnClickListener(new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onClick(View view) {
if (mMissingPermissions != null && !mMissingPermissions.isEmpty()) {
// request permissions
String[] params = mMissingPermissions.toArray(new String[mMissingPermissions.size()]);
requestPermissions(params, REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
}
}
});
}
}
/* TEST: Set up main layout */
private void setupTestLayout() {
if (mPermissionsGranted) { if (mPermissionsGranted) {
// point to the main map layout // point to the main map layout
setContentView(R.layout.activity_main_test); setContentView(R.layout.activity_main_test);
@ -298,9 +275,7 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
/* BEGIN NEW STUFF */ // create adapter that returns fragments for the maim map and the last track display
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
@ -314,10 +289,10 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
@Override @Override
public void onTabSelected(TabLayout.Tab tab) { public void onTabSelected(TabLayout.Tab tab) {
switch (tab.getPosition()) { switch (tab.getPosition()) {
case 0: case FRAGMENT_ID_MAP:
mFloatingActionButton.show(); mFloatingActionButton.show();
break; break;
case 1: case FRAGMENT_ID_TRACK:
mFloatingActionButton.hide(); mFloatingActionButton.hide();
break; break;
default: default:
@ -336,31 +311,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
} }
}); });
/* END NEW STUFF */
// get reference to fragment
mMainActivityMapFragment = (MainActivityMapFragment)getSupportFragmentManager().findFragmentById(R.id.content_main);
// show the record button and attach listener // show the record button and attach listener
mFloatingActionButton = (FloatingActionButton) findViewById(R.id.fab); mFloatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// onClick: start / stop tracking
handleFloatingActionButtonClick(view);
}
});
mFloatingActionButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
// onLongClick: clear map
if (mTrackerServiceRunning || mMainActivityMapFragment == null) {
return false;
} else {
return true;
}
}
});
} else { } else {
// point to the on main onboarding layout // point to the on main onboarding layout
@ -385,8 +338,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
} }
/* Handles tap on the record button */ /* Handles tap on the record button */
private void handleFloatingActionButtonClick(View view) { private void handleFloatingActionButtonClick(View view) {
if (mTrackerServiceRunning) { if (mTrackerServiceRunning) {
@ -523,17 +474,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
public Fragment getItem(int position) { public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page. // getItem is called to instantiate the fragment for the given page.
switch (position) { switch (position) {
case 0: case FRAGMENT_ID_MAP:
// if (mMainActivityMapFragment == null) {
// mMainActivityMapFragment = new MainActivityMapFragment();
// }
// return mMainActivityMapFragment;
return new MainActivityMapFragment(); return new MainActivityMapFragment();
case 1: case FRAGMENT_ID_TRACK:
// if (mMainActivityMapFragment == null) {
// mMainActivityMapFragment = new MainActivityMapFragment();
// }
// return mMainActivityMapFragment;
return new MainActivityTrackFragment(); return new MainActivityTrackFragment();
} }
return null; return null;
@ -548,14 +491,28 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
@Override @Override
public CharSequence getPageTitle(int position) { public CharSequence getPageTitle(int position) {
switch (position) { switch (position) {
case 0: case FRAGMENT_ID_MAP:
return getString(R.string.tab_map); return getString(R.string.tab_map);
case 1: case FRAGMENT_ID_TRACK:
return getString(R.string.tab_last_track); return getString(R.string.tab_last_track);
} }
return null; return null;
} }
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
// save references to created Fragments
switch (position) {
case FRAGMENT_ID_MAP:
mMainActivityMapFragment = (MainActivityMapFragment)createdFragment;
break;
case FRAGMENT_ID_TRACK:
mMainActivityTrackFragment = (MainActivityTrackFragment)createdFragment;
break;
}
return createdFragment;
}
} }
/** /**
* End of inner class * End of inner class

View File

@ -390,6 +390,8 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
/* Removes track crumbs from map */ /* Removes track crumbs from map */
public void clearMap() { public void clearMap() {
LogHelper.v(LOG_TAG, "!!! Ding clear.");
// clear map // clear map
if (mTrackOverlay != null) { if (mTrackOverlay != null) {
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show(); Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();

View File

@ -133,7 +133,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper(); LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
loadTrackAsyncHelper.execute(); loadTrackAsyncHelper.execute();
} else { } else {
// display map and statistics // just display map and statistics
displayTrack(); displayTrack();
} }
@ -179,6 +179,20 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
} }
/* Removes current track display */
public void refreshTrackView() {
// remove previous track
if (mMapView != null && mTrackOverlay != null) {
mMapView.getOverlays().remove(mTrackOverlay);
}
// load track and display map and statistics
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
loadTrackAsyncHelper.execute();
}
/* Displays map and statistics for track */ /* Displays map and statistics for track */
private void displayTrack() { private void displayTrack() {
GeoPoint position; GeoPoint position;
@ -239,8 +253,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid); super.onPostExecute(aVoid);
// clear track object
// LogHelper.v(LOG_TAG, "!!! TRACK:" + mTrack.getWayPoints().get(0).getLocation().getExtras());
LogHelper.v(LOG_TAG, "Display map and statistics of track."); LogHelper.v(LOG_TAG, "Display map and statistics of track.");
displayTrack(); displayTrack();
} }

View File

@ -17,6 +17,7 @@
package org.y20k.trackbook.core; package org.y20k.trackbook.core;
import android.location.Location; import android.location.Location;
import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@ -29,12 +30,23 @@ public class WayPoint implements Parcelable {
private Location mLocation; private Location mLocation;
private boolean mIsStopOver; private boolean mIsStopOver;
private float mDistanceToStartingPoint; private float mDistanceToStartingPoint;
private int mNumberSatellites;
/* Constructor */ /* Constructor */
public WayPoint(Location location, boolean isStopOver, float distanceToStartingPoint) { public WayPoint(Location location, boolean isStopOver, float distanceToStartingPoint) {
mLocation = location; mLocation = location;
mIsStopOver = isStopOver; mIsStopOver = isStopOver;
mDistanceToStartingPoint = distanceToStartingPoint; mDistanceToStartingPoint = distanceToStartingPoint;
// save number of satellites
Bundle extras = location.getExtras();
if (extras != null && extras.containsKey("satellites")) {
mNumberSatellites = extras.getInt("satellites", 0);
mLocation.setExtras(null); // necessary because Location Extras cause cannot be serialized properly by GSON
} else {
mNumberSatellites = 0;
}
} }
/* Constructor used by CREATOR */ /* Constructor used by CREATOR */
@ -43,6 +55,7 @@ public class WayPoint implements Parcelable {
mLocation = Location.CREATOR.createFromParcel(in); mLocation = Location.CREATOR.createFromParcel(in);
mIsStopOver = in.readByte() != 0; mIsStopOver = in.readByte() != 0;
mDistanceToStartingPoint = in.readFloat(); mDistanceToStartingPoint = in.readFloat();
mNumberSatellites = in.readInt();
} }
@ -104,9 +117,10 @@ public class WayPoint implements Parcelable {
@Override @Override
public void writeToParcel(Parcel parcel, int flags) { public void writeToParcel(Parcel parcel, int flags) {
// parcel.writeParcelable(mLocation, flags); // parcel.writeParcelable(mLocation, flags);
mLocation.setExtras(null); // necessary because: Location Extras cause cannot be serialized properly by GSON mLocation.setExtras(null); // necessary because Location Extras cause cannot be serialized properly by GSON
mLocation.writeToParcel(parcel, flags); mLocation.writeToParcel(parcel, flags);
parcel.writeByte((byte) (mIsStopOver ? 1 : 0)); parcel.writeByte((byte) (mIsStopOver ? 1 : 0));
parcel.writeFloat(mDistanceToStartingPoint); parcel.writeFloat(mDistanceToStartingPoint);
parcel.writeInt(mNumberSatellites);
} }
} }

View File

@ -69,6 +69,10 @@ public interface TrackbookKeys {
String INSTANCE_ZOOM_LEVEL_TRACK_MAP = "zoomLevelTrackMap"; String INSTANCE_ZOOM_LEVEL_TRACK_MAP = "zoomLevelTrackMap";
String INSTANCE_CURRENT_LOCATION = "currentLocation"; String INSTANCE_CURRENT_LOCATION = "currentLocation";
/* FRAGMENT IDS */
int FRAGMENT_ID_MAP = 0;
int FRAGMENT_ID_TRACK = 1;
/* RESULTS */ /* RESULTS */
/* CONSTANTS */ /* CONSTANTS */

View File

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.0' classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files