Updated renaming notes functionality and created view for selected tracks

This commit is contained in:
Denis 2015-02-25 18:02:50 +02:00
parent ae33cac5bd
commit 7061dfd881
8 changed files with 122 additions and 12 deletions

View file

@ -30,6 +30,36 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/showed_on_map"/>
<Button
android:id="@+id/turn_off_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/turn_off_all"/>
</LinearLayout>
<ListView
android:id="@+id/gpx_on_map"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<ExpandableListView
android:id="@android:id/list"

View file

@ -98,6 +98,14 @@
android:layout_gravity="center_vertical"
android:background="?attr/options_button_background"
android:src="@drawable/ic_action_gsave_dark"/>
<CheckBox
android:id="@+id/check"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:focusable="false"
android:visibility="gone"/>
</LinearLayout>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<?xml version='1.0' encoding='utf-8'?>
<resources>
<!--
Disclaimer:
@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="turn_off_all">Turn_off_all</string>
<string name="showed_on_map">Showed on map</string>
<string name="rename_failed">Rename failed.</string>
<string name="days_behind">days behind</string>
<string name="currently_recording_track">Currently recording track</string>

View file

@ -29,6 +29,7 @@ import net.osmand.plus.R;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms;
@ -62,12 +63,15 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@ -118,6 +122,18 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
updateCurrentTrack(getView());
updateShowedOnMapTracks();
}
private void updateShowedOnMapTracks() {
View v = getView();
if (v == null) {
return;
}
ListView onMap = (ListView)v.findViewById(R.id.gpx_on_map);
onMap.setAdapter(new ShowedOnMapAdapter(getActivity(), R.layout.dash_gpx_track_item));
}
@ -1367,4 +1383,40 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
return fileName = file.getName();
}
}
class ShowedOnMapAdapter extends ArrayAdapter<GpxInfo>{
public ShowedOnMapAdapter(Context context, int resource) {
super(context, resource);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.dash_gpx_track_item, parent, false);
}
GpxInfo gpxInfo = getItem(position);
TextView viewName = ((TextView) v.findViewById(R.id.name));
viewName.setText(gpxInfo.getName());
v.findViewById(R.id.show_on_map).setVisibility(View.GONE);
v.findViewById(R.id.stop).setVisibility(View.GONE);
v.findViewById(R.id.divider).setVisibility(View.GONE);
String description = GpxUiHelper.getDescription(getMyApplication(), gpxInfo.gpx, gpxInfo.file, true);
int startindex = description.indexOf(">");
int endindex = description.indexOf("</font>");
String distnace = description.substring(startindex + 1, endindex);
((TextView) v.findViewById(R.id.distance)).
setText(distnace);
CompoundButton check = (CompoundButton)v.findViewById(R.id.check);
check.setVisibility(View.VISIBLE);
return v;
}
}
}

View file

@ -170,7 +170,7 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
@Override
public PointDescription getObjectName(Object o) {
if(o instanceof Recording){
if(((Recording)o).getName() == null) {
if(((Recording)o).getName().isEmpty()) {
return new PointDescription(PointDescription.POINT_TYPE_NOTE, view.getResources().getString(R.string.recording_default_name));
}
return new PointDescription(PointDescription.POINT_TYPE_NOTE, ((Recording)o).getName());

View file

@ -21,6 +21,7 @@ import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.data.DataTileManager;
import net.osmand.data.Street;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
@ -190,10 +191,22 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return false;
}
public String getName() {
public String getFileName() {
return file.getName();
}
public String getName() {
String fileName = file.getName();
String hash;
int hashInd = fileName.lastIndexOf("_");
if (hashInd != -1) {
return fileName.substring(0, hashInd - 1);
} else {
return "";
}
}
public boolean isPhoto() {
return file.getName().endsWith(IMG_EXTENSION);
}

View file

@ -124,7 +124,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
final Context ctx, final AudioVideoNotesPlugin plugin) {
String name = recording.getName();
TextView nameText = ((TextView) view.findViewById(R.id.name));
if (name != null) {
if (!name.isEmpty()) {
nameText.setText(name);
} else if (recording.isAudio()) {
nameText.setText(R.string.audio);

View file

@ -1,6 +1,7 @@
package net.osmand.plus.audionotes;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
@ -13,6 +14,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ExpandableListView;
@ -211,21 +213,24 @@ public class NotesFragment extends ListFragment {
getListView(), false);
final EditText editText = (EditText) v.findViewById(R.id.name);
builder.setView(v);
String fileName = recording.getName();
int extInd = recording.getName().lastIndexOf(".");
final String extension;
if (extInd >= 0){
extension = fileName.substring(extInd, fileName.length());
String fileName = recording.getFileName();
final String hash;
int hashInd = fileName.lastIndexOf("_");
if (hashInd == -1) {
hash = "_" + fileName;
} else {
extension = "";
hash = fileName.substring(hashInd, fileName.length());
}
editText.setText(recording.getName().substring(0, extInd));
editText.setText(recording.getName());
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.setPositiveButton(R.string.default_buttons_apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(!recording.setName(editText.getText().toString() + extension)) {
if(!recording.setName(editText.getText().toString() + hash)) {
Toast.makeText(getActivity(),R.string.rename_failed,Toast.LENGTH_SHORT).show();
}
recording.setDescription();