diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/ExpandableListAdapter.java b/app/src/main/java/de/apps4ics/mountainnavigation/ExpandableListAdapter.java
new file mode 100644
index 0000000..3ef2b5c
--- /dev/null
+++ b/app/src/main/java/de/apps4ics/mountainnavigation/ExpandableListAdapter.java
@@ -0,0 +1,119 @@
+/**
+ * This file is part of MountainNavigation.
+ *
+ * MountainNavigation is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * MountainNavigation is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MountainNavigation. If not, see .
+ *
+ * @copyright Copyright (c) 2016 Vinzenz Rosenkanz
+ *
+ * @author Vinzenz Rosenkranz
+ */
+
+package de.apps4ics.mountainnavigation;
+
+import android.content.Context;
+import android.graphics.PorterDuff;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseExpandableListAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class ExpandableListAdapter extends BaseExpandableListAdapter {
+ private Context context;
+ private List headers;
+ private HashMap> children;
+ private HashMap> childrenImgs;
+
+ public ExpandableListAdapter(Context context, List headers, HashMap> children, HashMap> childrenImgs) {
+ this.context = context;
+ this.headers = headers;
+ this.children = children;
+ this.childrenImgs = childrenImgs;
+ }
+
+ @Override
+ public int getGroupCount() {
+ return headers.size();
+ }
+
+ @Override
+ public int getChildrenCount(int groupPosition) {
+ return children.get(getGroup(groupPosition)).size();
+ }
+
+ @Override
+ public Object getGroup(int groupPosition) {
+ return headers.get(groupPosition);
+ }
+
+ @Override
+ public Object getChild(int groupPosition, int childPosition) {
+ return children.get(getGroup(groupPosition)).get(childPosition);
+ }
+
+ public Object getChildImg(int groupPosition, int childPosition) {
+ return childrenImgs.get(getGroup(groupPosition)).get(childPosition);
+ }
+
+ @Override
+ public long getGroupId(int groupPosition) {
+ return groupPosition;
+ }
+
+ @Override
+ public long getChildId(int groupPosition, int childPosition) {
+ return childPosition;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+
+ @Override
+ public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
+ String title = (String) getGroup(groupPosition);
+ if(convertView == null) {
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(R.layout.drawer_list_simple, null);
+ }
+ TextView listHeader = (TextView) convertView.findViewById(R.id.simple_textview);
+ listHeader.setText(title);
+ return convertView;
+ }
+
+ @Override
+ public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
+ if(convertView == null) {
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ if(getChildrenCount(groupPosition) > 0) convertView = inflater.inflate(R.layout.drawer_list_item, null);
+ else return null;
+ }
+ ImageView childImg = (ImageView) convertView.findViewById(R.id.toggleEntryImg);
+ TextView listChild = (TextView) convertView.findViewById(R.id.toggleEntryDesc);
+ listChild.setText((String) getChild(groupPosition, childPosition));
+ childImg.setImageResource((Integer) getChildImg(groupPosition, childPosition));
+ childImg.setColorFilter(context.getResources().getColor(R.color.icon_unselected_gray), PorterDuff.Mode.DST_OUT);
+ return convertView;
+ }
+
+ @Override
+ public boolean isChildSelectable(int groupPosition, int childPosition) {
+ return groupPosition == 0;
+ }
+}
diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java
index 1997959..56069b9 100644
--- a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java
+++ b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java
@@ -59,8 +59,8 @@
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
+import android.widget.ExpandableListView;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TableLayout;
@@ -85,11 +85,12 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import de.apps4ics.mountainnavigation.adapters.HikeListAdapter;
-import de.apps4ics.mountainnavigation.adapters.ImageListAdapter;
import de.apps4ics.mountainnavigation.handlers.DatabaseHandler;
import de.apps4ics.mountainnavigation.handlers.HikeHandler;
import de.apps4ics.mountainnavigation.handlers.PoiHandler;
@@ -146,9 +147,7 @@
private ActionBarDrawerToggle drawerToggle;
private DrawerLayout drawerLayout;
- private LinearLayout poiView;
- private LinearLayout hikeView;
- private LinearLayout menuView;
+ private ExpandableListView poiView;
private ImageView weatherSymbol;
private TextView weatherCity;
private TextView weatherDesc;
@@ -241,9 +240,7 @@
}
});
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- menuView = (LinearLayout) findViewById(R.id.menuList);
- hikeView = (LinearLayout) findViewById(R.id.hikeList);
- poiView = (LinearLayout) findViewById(R.id.poiList);
+ poiView = (ExpandableListView) findViewById(R.id.poiList);
weatherSymbol = (ImageView) findViewById(R.id.weather_symbol);
weatherCity = (TextView) findViewById(R.id.weather_city);
weatherDesc = (TextView) findViewById(R.id.weather_desc);
@@ -252,318 +249,329 @@
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
-// poiView.setItemsCanFocus(false);
- ImageListAdapter adapter = new ImageListAdapter(MainActivity.this, PoiHandler.getEntries(), PoiHandler.getEntryImgs(), false);
- for(int i=0; i hikeAdapter = new ArrayAdapter<>(MainActivity.this, R.layout.drawer_list_simple, hikeEntries);
- for(int i=0; i hikePoints = (ArrayList) hikeHandler.getPoints();
+ List emptyChild = new ArrayList<>();
+ List emptyChildImg = new ArrayList<>();
+ final List headers = new ArrayList<>();
+ final List headerKeys = new ArrayList<>();
+ HashMap> children = new HashMap<>();
+ HashMap> childrenImgs = new HashMap<>();
- LayoutInflater inflater = getLayoutInflater();
- View hikeDialog = inflater.inflate(R.layout.hike_dialog, null, true);
- final EditText input = (EditText) hikeDialog.findViewById(R.id.hike_name);
- final Spinner flooring = (Spinner) hikeDialog.findViewById(R.id.hike_flooring_spinner);
- TextView lengthView = (TextView) hikeDialog.findViewById(R.id.hike_length);
- final TextView timeView = (TextView) hikeDialog.findViewById(R.id.hike_time);
- final TextView heightUpView = (TextView) hikeDialog.findViewById(R.id.hike_height_up);
- final TextView heightDownView = (TextView) hikeDialog.findViewById(R.id.hike_height_down);
+ //Add POI entry
+ String layerKey = getString(R.string.drawer_entry_layers);
+ headers.add(layerKey);
+ headerKeys.add(null); //there is no action for expandable poi layer
+ children.put(layerKey, Arrays.asList(PoiHandler.getEntries()));
+ childrenImgs.put(layerKey, Arrays.asList(PoiHandler.getEntryImgs()));
- ArrayAdapter adapter = ArrayAdapter.createFromResource(MainActivity.this,
- R.array.hike_floorings, android.R.layout.simple_spinner_item);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- flooring.setAdapter(adapter);
- flooring.setSelection(Features.HIKE_FLOORING_TRAIL);
- flooring.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- String key = getResources().getStringArray(R.array.hike_floorings_keys)[position];
- if (key.equals(getString(R.string.hike_flooring_street_key))) {
- } else if (key.equals(getString(R.string.hike_flooring_grit_key))) {
- } else if (key.equals(getString(R.string.hike_flooring_trail_key))) {
- }
- }
-
- @Override
- public void onNothingSelected(AdapterView> parent) {
- }
- });
-
- int lengthRest = hikeHandler.getTime();
-
- lengthView.setText(String.format(Locale.getDefault(), "Length so far: %.02fm", hikeHandler.getLength()));
- timeView.setText("Time so far: " + formatTimeIntervalToHms(lengthRest));
- heightUpView.setText(String.format(Locale.getDefault(), "Up: %.02fm", hikeHandler.getUp()));
- heightDownView.setText(String.format(Locale.getDefault(), "Down: %.02fm", hikeHandler.getDown()));
-
- AlertDialog.Builder saveHikeBuilder = new AlertDialog.Builder(MainActivity.this);
- saveHikeBuilder.setTitle(R.string.hike_save_title)
- .setView(hikeDialog)
- .setPositiveButton(R.string.hike_save_ok_button, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- String name = input.getText().toString().trim();
- if (!name.equals("")) {
- hikeHandler.stopRecording();
- view.setText(hikeEntries[position]);
- int floor = flooring.getSelectedItemPosition();
- long time = System.currentTimeMillis();
- long hikeId = poiHandler.addPoi(new Hike(0, hikeHandler.getLength(), hikeHandler.getTime(), (int) (time % 3),
- name, "You", time, hikeHandler.getUp(), hikeHandler.getDown(), floor));
- for (HikePoint hp : hikePoints) {
- poiHandler.addGp(new DbGeoPoint(hp.getLocation(), hp.getTimestamp(), hikeId, Types.HIKE));
- }
- }
- }
- })
- .setNeutralButton(R.string.hike_save_discard, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- hikeHandler.resetRecording();
- view.setText(hikeEntries[position]);
- }
- })
- .setNegativeButton(R.string.hike_save_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- });
- final AlertDialog saveHikeDialog = saveHikeBuilder.create();
- saveHikeDialog.show();
- final Button saveHikeDialogButton = saveHikeDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- Button discardHikeDialogButton = saveHikeDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
- Button keepHikeDialogButton = saveHikeDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
- saveHikeDialogButton.setEnabled(false);
- saveHikeDialogButton.setTextSize(12);
- discardHikeDialogButton.setTextSize(12);
- keepHikeDialogButton.setTextSize(12);
-
- input.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- if (s.length() > 0) saveHikeDialogButton.setEnabled(true);
- else saveHikeDialogButton.setEnabled(false);
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- }
- });
- } else {
- AlertDialog.Builder startHikeBuilder = new AlertDialog.Builder(MainActivity.this);
- startHikeBuilder
- .setTitle(R.string.hike_start_question)
- .setMessage(R.string.hike_start_desc)
- .setPositiveButton(R.string.hike_start_ok_button, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- hikeHandler.startRecording();
- view.setText(res.getString(R.string.hike_title_stop_rec));
- Toaster(res.getString(R.string.hike_is_recording), true);
- }
- })
- .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- });
- AlertDialog startHikeDialog = startHikeBuilder.create();
- startHikeDialog.show();
- }
- } else if (key.equals(getString(R.string.hike_title_show_key))) {
- if (mLocation == null) {
- Toaster("No location found!", true); //TODO dialog
- } else {
- final List hikes = poiHandler.getHikesAround(mLocation);
- final List> points = new ArrayList<>();
- for (Hike hike : hikes) {
- points.add(dbHandler.getGeoPointsForPoi(hike.getId(), hike.getType()));
- }
- AlertDialog.Builder showHikesDialogBuilder = new AlertDialog.Builder(MainActivity.this)
- .setTitle(R.string.hike_list_title)
- .setNegativeButton(R.string.close_button, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- });
- if(hikes.size() > 0) {
- showHikesDialogBuilder
- .setAdapter(new HikeListAdapter(MainActivity.this, hikes, points), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Polyline hikePath = new Polyline(MainActivity.this);
- Hike hike = hikes.get(which);
- List dbPoints = points.get(which);
- List pathPoints = new ArrayList<>();
- float[] elevationDataPoints = new float[dbPoints.size()];
- String[] elevationDataPointsNames = new String[dbPoints.size()];
- final String[] elevationDataPointsTimes = new String[dbPoints.size()];
- double min = Double.MAX_VALUE;
- double max = Double.MIN_VALUE;
- long startTime = dbPoints.get(0).getTime();
- for (int i = 0; i < dbPoints.size(); i++) {
- DbGeoPoint dbGeoPoint = dbPoints.get(i);
- elevationDataPointsTimes[i] = formatTimeIntervalToHms((int) (dbGeoPoint.getTime() - startTime));
- Log.d(TAG, "formatted: " + elevationDataPointsTimes[i]);
- double alt = dbGeoPoint.getAlt();
- pathPoints.add(new GeoPoint(dbGeoPoint.getLat(), dbGeoPoint.getLon(), alt));
- //TODO REMOVE
- alt = (int) (Math.random() * 100) + 40;
- elevationDataPoints[i] = (int) alt;
- elevationDataPointsNames[i] = (dbGeoPoint.getTime() - startTime) + "s";
- if (alt < min) min = alt;
- if (alt > max) max = alt;
- }
- LayoutInflater inflater = getLayoutInflater();
- View rowView = inflater.inflate(R.layout.hike_list_detail, null, true);
- TextView titleView = (TextView) rowView.findViewById(R.id.hike_list_detail_title);
- TextView authorView = (TextView) rowView.findViewById(R.id.hike_list_detail_author);
- TextView lengthView = (TextView) rowView.findViewById(R.id.hike_list_detail_length);
- TextView timeView = (TextView) rowView.findViewById(R.id.hike_list_detail_time);
- TextView difficultyView = (TextView) rowView.findViewById(R.id.hike_list_detail_difficulty);
- TextView upView = (TextView) rowView.findViewById(R.id.hike_list_detail_up);
- TextView downView = (TextView) rowView.findViewById(R.id.hike_list_detail_down);
- LineChartView elevationProfileNew = (LineChartView) rowView.findViewById(R.id.hike_list_detail_elevation_profile);
- MapView hikeMap = (MapView) rowView.findViewById(R.id.hike_list_detail_map);
- titleView.setText(hike.getName());
- authorView.setText(String.format(Locale.getDefault(), res.getString(R.string.hike_list_author), hike.getAuthor()));
- lengthView.setText(String.format(Locale.getDefault(), "Length: %.02fm", hike.getLength()));
- timeView.setText(String.format(Locale.getDefault(), "Time: %ds", hike.getTime()));
- difficultyView.setText(res.getStringArray(R.array.hike_difficulties)[hike.getDifficulty()]);
- Drawable difficultyDrawable = null;
- switch (hike.getDifficulty()) {
- case 0:
- difficultyDrawable = res.getDrawable(R.drawable.difficulty_indicator_easy, null);
- break;
- case 1:
- difficultyDrawable = res.getDrawable(R.drawable.difficulty_indicator_medium, null);
- break;
- case 2:
- difficultyDrawable = res.getDrawable(R.drawable.difficulty_indicator_hard, null);
- break;
- }
- difficultyView.setCompoundDrawablesWithIntrinsicBounds(difficultyDrawable, null, null, null);
- upView.setText(String.format(Locale.getDefault(), "Up: %.02fm", hike.getHeightUp()));
- downView.setText(String.format(Locale.getDefault(), "Down: %.02fm", hike.getHeightDown()));
- final LineSet lineSet = new LineSet(elevationDataPointsNames, elevationDataPoints);
- lineSet.setDotsColor(res.getColor(R.color.white));
- lineSet.setDotsStrokeColor(res.getColor(R.color.elevation_line));
- lineSet.setColor(res.getColor(R.color.elevation_line));
- lineSet.setFill(res.getColor(R.color.elevation_bg));
- lineSet.setDotsRadius(6);
- lineSet.setDotsStrokeThickness(3);
- lineSet.setThickness(4);
- int minDisp = (int) min;
- int maxDisp = (int) max;
- int padding = (maxDisp - minDisp) / 10;
- minDisp = Math.max(0, minDisp - padding);
- maxDisp += padding;
- minDisp = Math.max(0, minDisp - (minDisp % 10));
- maxDisp += (10 - (maxDisp % 10));
- int step = (maxDisp - minDisp) / 2;
- elevationProfileNew.setAxisBorderValues(minDisp, maxDisp, step);
- elevationProfileNew.setXLabels(AxisController.LabelPosition.NONE);
- elevationProfileNew.setXAxis(false);
- elevationProfileNew.setYAxis(false);
- elevationProfileNew.setGrid(ChartView.GridType.HORIZONTAL, new Paint());
- elevationProfileNew.addData(lineSet);
-
- elevationProfileNew.setOnEntryClickListener(new OnEntryClickListener() {
- @Override
- public void onClick(int setIndex, int entryIndex, Rect rect) {
- Toaster(lineSet.getEntry(entryIndex).getValue() + "m @ " + elevationDataPointsTimes[entryIndex], true);
- }
- });
-
- elevationProfileNew.show(new Animation(1000));
- hikeMap.setTileSource(TileSourceFactory.MAPNIK);
- hikeMap.setBuiltInZoomControls(true);
- hikeMap.setMultiTouchControls(true);
- IMapController hikeMapController = hikeMap.getController();
- hikeMapController.setZoom(ZOOM_LEVEL);
- hikeMapController.setCenter(pathPoints.get(pathPoints.size() / 2));
-
- AlertDialog detailHikeDialog = new AlertDialog.Builder(MainActivity.this)
- .setTitle(String.format(Locale.getDefault(), res.getString(R.string.hike_detail_title), hike.getName()))
- .setView(rowView)
- .setPositiveButton(R.string.hike_start_navigation, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- })
- .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- })
- .create();
- detailHikeDialog.show();
- hikePath.setPoints(pathPoints);
- hikePath.setColor(res.getColor(R.color.polyline_color));
- hikeMap.getOverlays().add(hikePath);
- hikeMap.invalidate();
- }
- });
- } else {
- showHikesDialogBuilder.setMessage(R.string.hike_list_no_hikes);
- }
- AlertDialog showHikesDialog = showHikesDialogBuilder.create();
- showHikesDialog.show();
- }
- }
- }
- });
- menuView.addView(view);
+ String[] hikeEntries = res.getStringArray(R.array.hikeEntries);
+ String[] hikeEntriesKeys = res.getStringArray(R.array.hikeEntriesKeys);
+ for(int i=0; i menuAdapter = new ArrayAdapter<>(MainActivity.this, R.layout.drawer_list_simple, menuEntries);
- for(int i=0; i hikePoints = (ArrayList) hikeHandler.getPoints();
+
+ LayoutInflater inflater = getLayoutInflater();
+ View hikeDialog = inflater.inflate(R.layout.hike_dialog, null, true);
+ final EditText input = (EditText) hikeDialog.findViewById(R.id.hike_name);
+ final Spinner flooring = (Spinner) hikeDialog.findViewById(R.id.hike_flooring_spinner);
+ TextView lengthView = (TextView) hikeDialog.findViewById(R.id.hike_length);
+ final TextView timeView = (TextView) hikeDialog.findViewById(R.id.hike_time);
+ final TextView heightUpView = (TextView) hikeDialog.findViewById(R.id.hike_height_up);
+ final TextView heightDownView = (TextView) hikeDialog.findViewById(R.id.hike_height_down);
+
+ ArrayAdapter adapter = ArrayAdapter.createFromResource(MainActivity.this,
+ R.array.hike_floorings, android.R.layout.simple_spinner_item);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ flooring.setAdapter(adapter);
+ flooring.setSelection(Features.HIKE_FLOORING_TRAIL);
+ flooring.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+ String key = getResources().getStringArray(R.array.hike_floorings_keys)[position];
+ if (key.equals(getString(R.string.hike_flooring_street_key))) {
+ } else if (key.equals(getString(R.string.hike_flooring_grit_key))) {
+ } else if (key.equals(getString(R.string.hike_flooring_trail_key))) {
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) {
+ }
+ });
+
+ int lengthRest = hikeHandler.getTime();
+
+ lengthView.setText(String.format(Locale.getDefault(), "Length so far: %.02fm", hikeHandler.getLength()));
+ timeView.setText("Time so far: " + formatTimeIntervalToHms(lengthRest));
+ heightUpView.setText(String.format(Locale.getDefault(), "Up: %.02fm", hikeHandler.getUp()));
+ heightDownView.setText(String.format(Locale.getDefault(), "Down: %.02fm", hikeHandler.getDown()));
+
+ AlertDialog.Builder saveHikeBuilder = new AlertDialog.Builder(MainActivity.this);
+ saveHikeBuilder.setTitle(R.string.hike_save_title)
+ .setView(hikeDialog)
+ .setPositiveButton(R.string.hike_save_ok_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ String name = input.getText().toString().trim();
+ if (!name.equals("")) {
+ hikeHandler.stopRecording();
+ view.setText(headers.get(groupPosition));
+ int floor = flooring.getSelectedItemPosition();
+ long time = System.currentTimeMillis();
+ long hikeId = poiHandler.addPoi(new Hike(0, hikeHandler.getLength(), hikeHandler.getTime(), (int) (time % 3),
+ name, "You", time, hikeHandler.getUp(), hikeHandler.getDown(), floor));
+ for (HikePoint hp : hikePoints) {
+ poiHandler.addGp(new DbGeoPoint(hp.getLocation(), hp.getTimestamp(), hikeId, Types.HIKE));
+ }
+ }
+ }
+ })
+ .setNeutralButton(R.string.hike_save_discard, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ hikeHandler.resetRecording();
+ view.setText(headers.get(groupPosition));
+ }
+ })
+ .setNegativeButton(R.string.hike_save_cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ }
+ });
+ final AlertDialog saveHikeDialog = saveHikeBuilder.create();
+ saveHikeDialog.show();
+ final Button saveHikeDialogButton = saveHikeDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+ Button discardHikeDialogButton = saveHikeDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
+ Button keepHikeDialogButton = saveHikeDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
+ saveHikeDialogButton.setEnabled(false);
+ saveHikeDialogButton.setTextSize(12);
+ discardHikeDialogButton.setTextSize(12);
+ keepHikeDialogButton.setTextSize(12);
+
+ input.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ if (s.length() > 0) saveHikeDialogButton.setEnabled(true);
+ else saveHikeDialogButton.setEnabled(false);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+ });
+ } else {
+ AlertDialog.Builder startHikeBuilder = new AlertDialog.Builder(MainActivity.this);
+ startHikeBuilder
+ .setTitle(R.string.hike_start_question)
+ .setMessage(R.string.hike_start_desc)
+ .setPositiveButton(R.string.hike_start_ok_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ hikeHandler.startRecording();
+ view.setText(res.getString(R.string.hike_title_stop_rec));
+ Toaster(res.getString(R.string.hike_is_recording), true);
+ }
+ })
+ .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ }
+ });
+ AlertDialog startHikeDialog = startHikeBuilder.create();
+ startHikeDialog.show();
+ }
+ } else if (key.equals(getString(R.string.hike_title_show_key))) {
+ if (mLocation == null) {
+ Toaster("No location found!", true); //TODO dialog
+ } else {
+ final List hikes = poiHandler.getHikesAround(mLocation);
+ final List> points = new ArrayList<>();
+ for (Hike hike : hikes) {
+ points.add(dbHandler.getGeoPointsForPoi(hike.getId(), hike.getType()));
+ }
+ AlertDialog.Builder showHikesDialogBuilder = new AlertDialog.Builder(MainActivity.this)
+ .setTitle(R.string.hike_list_title)
+ .setNegativeButton(R.string.close_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ }
+ });
+ if(hikes.size() > 0) {
+ showHikesDialogBuilder
+ .setAdapter(new HikeListAdapter(MainActivity.this, hikes, points), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Polyline hikePath = new Polyline(MainActivity.this);
+ Hike hike = hikes.get(which);
+ List dbPoints = points.get(which);
+ List pathPoints = new ArrayList<>();
+ float[] elevationDataPoints = new float[dbPoints.size()];
+ String[] elevationDataPointsNames = new String[dbPoints.size()];
+ final String[] elevationDataPointsTimes = new String[dbPoints.size()];
+ double min = Double.MAX_VALUE;
+ double max = Double.MIN_VALUE;
+ long startTime = dbPoints.get(0).getTime();
+ for (int i = 0; i < dbPoints.size(); i++) {
+ DbGeoPoint dbGeoPoint = dbPoints.get(i);
+ elevationDataPointsTimes[i] = formatTimeIntervalToHms((int) (dbGeoPoint.getTime() - startTime));
+ Log.d(TAG, "formatted: " + elevationDataPointsTimes[i]);
+ double alt = dbGeoPoint.getAlt();
+ pathPoints.add(new GeoPoint(dbGeoPoint.getLat(), dbGeoPoint.getLon(), alt));
+ //TODO REMOVE
+ alt = (int) (Math.random() * 100) + 40;
+ elevationDataPoints[i] = (int) alt;
+ elevationDataPointsNames[i] = (dbGeoPoint.getTime() - startTime) + "s";
+ if (alt < min) min = alt;
+ if (alt > max) max = alt;
+ }
+ LayoutInflater inflater = getLayoutInflater();
+ View rowView = inflater.inflate(R.layout.hike_list_detail, null, true);
+ TextView titleView = (TextView) rowView.findViewById(R.id.hike_list_detail_title);
+ TextView authorView = (TextView) rowView.findViewById(R.id.hike_list_detail_author);
+ TextView lengthView = (TextView) rowView.findViewById(R.id.hike_list_detail_length);
+ TextView timeView = (TextView) rowView.findViewById(R.id.hike_list_detail_time);
+ TextView difficultyView = (TextView) rowView.findViewById(R.id.hike_list_detail_difficulty);
+ TextView upView = (TextView) rowView.findViewById(R.id.hike_list_detail_up);
+ TextView downView = (TextView) rowView.findViewById(R.id.hike_list_detail_down);
+ LineChartView elevationProfileNew = (LineChartView) rowView.findViewById(R.id.hike_list_detail_elevation_profile);
+ MapView hikeMap = (MapView) rowView.findViewById(R.id.hike_list_detail_map);
+ titleView.setText(hike.getName());
+ authorView.setText(String.format(Locale.getDefault(), res.getString(R.string.hike_list_author), hike.getAuthor()));
+ lengthView.setText(String.format(Locale.getDefault(), "Length: %.02fm", hike.getLength()));
+ timeView.setText(String.format(Locale.getDefault(), "Time: %ds", hike.getTime()));
+ difficultyView.setText(res.getStringArray(R.array.hike_difficulties)[hike.getDifficulty()]);
+ Drawable difficultyDrawable = null;
+ switch (hike.getDifficulty()) {
+ case 0:
+ difficultyDrawable = res.getDrawable(R.drawable.difficulty_indicator_easy, null);
+ break;
+ case 1:
+ difficultyDrawable = res.getDrawable(R.drawable.difficulty_indicator_medium, null);
+ break;
+ case 2:
+ difficultyDrawable = res.getDrawable(R.drawable.difficulty_indicator_hard, null);
+ break;
+ }
+ difficultyView.setCompoundDrawablesWithIntrinsicBounds(difficultyDrawable, null, null, null);
+ upView.setText(String.format(Locale.getDefault(), "Up: %.02fm", hike.getHeightUp()));
+ downView.setText(String.format(Locale.getDefault(), "Down: %.02fm", hike.getHeightDown()));
+ final LineSet lineSet = new LineSet(elevationDataPointsNames, elevationDataPoints);
+ lineSet.setDotsColor(res.getColor(R.color.white));
+ lineSet.setDotsStrokeColor(res.getColor(R.color.elevation_line));
+ lineSet.setColor(res.getColor(R.color.elevation_line));
+ lineSet.setFill(res.getColor(R.color.elevation_bg));
+ lineSet.setDotsRadius(6);
+ lineSet.setDotsStrokeThickness(3);
+ lineSet.setThickness(4);
+ int minDisp = (int) min;
+ int maxDisp = (int) max;
+ int padding = (maxDisp - minDisp) / 10;
+ minDisp = Math.max(0, minDisp - padding);
+ maxDisp += padding;
+ minDisp = Math.max(0, minDisp - (minDisp % 10));
+ maxDisp += (10 - (maxDisp % 10));
+ int step = (maxDisp - minDisp) / 2;
+ elevationProfileNew.setAxisBorderValues(minDisp, maxDisp, step);
+ elevationProfileNew.setXLabels(AxisController.LabelPosition.NONE);
+ elevationProfileNew.setXAxis(false);
+ elevationProfileNew.setYAxis(false);
+ elevationProfileNew.setGrid(ChartView.GridType.HORIZONTAL, new Paint());
+ elevationProfileNew.addData(lineSet);
+
+ elevationProfileNew.setOnEntryClickListener(new OnEntryClickListener() {
+ @Override
+ public void onClick(int setIndex, int entryIndex, Rect rect) {
+ Toaster(lineSet.getEntry(entryIndex).getValue() + "m @ " + elevationDataPointsTimes[entryIndex], true);
+ }
+ });
+
+ elevationProfileNew.show(new Animation(1000));
+ hikeMap.setTileSource(TileSourceFactory.MAPNIK);
+ hikeMap.setBuiltInZoomControls(true);
+ hikeMap.setMultiTouchControls(true);
+ IMapController hikeMapController = hikeMap.getController();
+ hikeMapController.setZoom(ZOOM_LEVEL);
+ hikeMapController.setCenter(pathPoints.get(pathPoints.size() / 2));
+
+ AlertDialog detailHikeDialog = new AlertDialog.Builder(MainActivity.this)
+ .setTitle(String.format(Locale.getDefault(), res.getString(R.string.hike_detail_title), hike.getName()))
+ .setView(rowView)
+ .setPositiveButton(R.string.hike_start_navigation, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ }
+ })
+ .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ }
+ })
+ .create();
+ detailHikeDialog.show();
+ hikePath.setPoints(pathPoints);
+ hikePath.setColor(res.getColor(R.color.polyline_color));
+ hikeMap.getOverlays().add(hikePath);
+ hikeMap.invalidate();
+ }
+ });
+ } else {
+ showHikesDialogBuilder.setMessage(R.string.hike_list_no_hikes);
+ }
+ AlertDialog showHikesDialog = showHikesDialogBuilder.create();
+ showHikesDialog.show();
+ }
+ } else if(key.equals(getString(R.string.menu_title_about_key))) {
+ Intent about = new Intent(MainActivity.this, AboutActivity.class);
+ startActivity(about);
+ } else if(key.equals(getString(R.string.menu_title_settings_key))) {
+ Intent settings = new Intent(MainActivity.this, SettingsActivity.class);
+ startActivity(settings);
+ } else if(key.equals(getString(R.string.menu_title_download_key))) {
+ Intent download = new Intent(MainActivity.this, DownloadActivity.class);
+ startActivity(download);
+ }
+ return false;
+ }
+ });
+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 8299d1a..e6ccd0f 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -135,7 +135,7 @@
android:textStyle="italic"/>
-
-
-
-
-
diff --git a/app/src/main/res/layout/drawer_list_item.xml b/app/src/main/res/layout/drawer_list_item.xml
index 47cd051..83f30e1 100644
--- a/app/src/main/res/layout/drawer_list_item.xml
+++ b/app/src/main/res/layout/drawer_list_item.xml
@@ -27,8 +27,7 @@
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
- android:layout_marginRight="16dp"
- android:background="?attr/selectableItemBackground" >
+ android:layout_marginRight="16dp" >
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/drawer_list_simple.xml b/app/src/main/res/layout/drawer_list_simple.xml
index 691b6eb..147b7af 100644
--- a/app/src/main/res/layout/drawer_list_simple.xml
+++ b/app/src/main/res/layout/drawer_list_simple.xml
@@ -1,13 +1,20 @@
-
+ android:layout_height="match_parent">
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml
index d543575..57a5fa5 100644
--- a/app/src/main/res/values-de-rDE/strings.xml
+++ b/app/src/main/res/values-de-rDE/strings.xml
@@ -98,6 +98,7 @@
d.MM.yyyy, HH:mm \'Uhr\'
Example action
+ Ebenen
Einstellungen
Über
Herunterladen
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1408d3b..a353b83 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -100,6 +100,7 @@
MM/d/yyyy, hh:mm a
Example action
+ Layers
Settings
About
Download