Added renaming for audio video notes

This commit is contained in:
Bars107 2015-02-24 14:58:03 +02:00
parent c684b01f2b
commit 80be3b8b1c
6 changed files with 73 additions and 120 deletions

View file

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/dashListItemHeight"
android:orientation="vertical">
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/dashNoteIconSize"
android:layout_height="@dimen/dashNoteIconSize"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:layout_marginRight="@dimen/dashFavIconMargin"
tools:src="@drawable/ic_type_audio" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/dashFavNameTextSize"
tools:text="@string/lorem_ipsum" />
<TextView
android:id="@+id/descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textSize="@dimen/showAllButtonTextSize"
android:textColor="?android:textColorSecondary"
tools:text="@string/lorem_ipsum" />
</LinearLayout>
<ImageButton
android:id="@+id/play"
android:layout_width="@dimen/dashListItemHeight"
android:layout_height="@dimen/dashListItemHeight"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_play_light"/>
</LinearLayout>
</LinearLayout>

View file

@ -64,4 +64,13 @@
android:focusable="false"
android:src="?attr/list_settings_icon"/>
<ImageButton
android:id="@+id/play"
android:layout_width="@dimen/dashListItemHeight"
android:layout_height="@dimen/dashListItemHeight"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_play_light"/>
</LinearLayout>

View file

@ -9,6 +9,7 @@
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="rename_failed">Rename failed.</string>
<string name="days_behind">days behind</string>
<string name="currently_recording_track">Currently recording track</string>
<string name="back_to_map">Back to map</string>

View file

@ -67,6 +67,7 @@ import android.media.MediaRecorder;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Display;
import android.view.KeyEvent;
@ -138,9 +139,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
this.file = f;
}
public File file;
private File file;
private String name;
private double lat;
private double lon;
private long duration = -1;
@ -172,12 +172,26 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
}
public void setName(String name) {
this.name = name;
public File getFile() {
return file;
}
public boolean setName(String name) {
int index = file.getAbsolutePath().lastIndexOf("/") + 1;
if (index < 0){
return false;
}
File directory = new File(file.getAbsolutePath().substring(0, index));
File to = new File(directory, name.trim());
if (file.renameTo(to)){
file = to;
return true;
}
return false;
}
public String getName() {
return name;
return file.getName();
}
public boolean isPhoto() {
@ -289,13 +303,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
public String getSmallDescription(Context ctx) {
String nm = name == null ? "" : name;
String time = AndroidUtils.formatDateTime(ctx,file.lastModified());
if (isPhoto()) {
return ctx.getString(R.string.recording_photo_description, nm, time).trim();
return ctx.getString(R.string.recording_photo_description, "", time).trim();
}
return ctx.getString(R.string.recording_description, nm, "", time).trim();
return ctx.getString(R.string.recording_description, "", "", time).trim();
}
private String getDuration(Context ctx) {

View file

@ -94,15 +94,22 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
for (final AudioVideoNotesPlugin.Recording recording : notes){
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dash_audio_video_notes_item, null, false);
View view = inflater.inflate(R.layout.note, null, false);
getNoteView(recording, view, getActivity(), plugin);
view.findViewById(R.id.play).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.playRecording(getActivity(), recording);
}
});
view.findViewById(R.id.options).setVisibility(View.GONE);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15,
new PointDescription(PointDescription.POINT_TYPE_NOTE,
!Algorithms.isEmpty(recording.getName())? recording.getName() : recording.getDescription(getActivity())), true,
(recording.getName() != null) ? recording.getName() : recording.getDescription(getActivity())), true,
recording); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity());
}
@ -113,13 +120,18 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
public static void getNoteView(final AudioVideoNotesPlugin.Recording recording, View view,
final Context ctx, final AudioVideoNotesPlugin plugin) {
if (recording.getName() != null){
((TextView) view.findViewById(R.id.name)).setText(recording.getName());
((TextView) view.findViewById(R.id.descr)).setText(recording.getDescription(ctx));
} else {
((TextView) view.findViewById(R.id.name)).setText(recording.getDescription(ctx));
view.findViewById(R.id.descr).setVisibility(View.GONE);
String name = recording.getName();
TextView nameText = ((TextView) view.findViewById(R.id.name));
if (name != null) {
nameText.setText(name);
} else if (recording.isAudio()) {
nameText.setText(R.string.audio);
} else if (recording.isVideo()) {
nameText.setText(R.string.video);
} else if (recording.isPhoto()) {
nameText.setText(R.string.photo);
}
((TextView) view.findViewById(R.id.descr)).setText(recording.getDescription(ctx));
ImageView icon = (ImageView) view.findViewById(R.id.icon);
if (recording.isAudio()) {
@ -130,12 +142,6 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
icon.setImageResource(R.drawable.ic_type_img);
}
view.findViewById(R.id.play).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.playRecording(ctx, recording);
}
});
}
}

View file

@ -28,6 +28,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.dialogs.DirectionsDialogs;
import android.support.v4.app.ListFragment;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
@ -89,27 +90,8 @@ public class NotesFragment extends ListFragment {
}
final AudioVideoNotesPlugin.Recording recording = getItem(position);
String name = recording.getName();
TextView nameText = ((TextView) row.findViewById(R.id.name));
if (name != null) {
nameText.setText(name);
} else if (recording.isAudio()) {
nameText.setText(R.string.audio);
} else if (recording.isVideo()) {
nameText.setText(R.string.video);
} else if (recording.isPhoto()) {
nameText.setText(R.string.photo);
}
((TextView) row.findViewById(R.id.descr)).setText(recording.getDescription(getActivity()));
ImageView icon = (ImageView) row.findViewById(R.id.icon);
if (recording.isAudio()) {
icon.setImageResource(R.drawable.ic_type_audio);
} else if (recording.isVideo()) {
icon.setImageResource(R.drawable.ic_type_video);
} else {
icon.setImageResource(R.drawable.ic_type_img);
}
DashAudioVideoNotesFragment.getNoteView(recording, row, getActivity(), plugin);
row.findViewById(R.id.play).setVisibility(View.GONE);
ImageButton options = (ImageButton) row.findViewById(R.id.options);
options.setOnClickListener(new View.OnClickListener() {
@Override
@ -173,15 +155,15 @@ public class NotesFragment extends ListFragment {
public boolean onMenuItemClick(MenuItem item) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
if (recording.isPhoto()) {
Uri screenshotUri = Uri.parse(recording.file.getAbsolutePath());
Uri screenshotUri = Uri.parse(recording.getFile().getAbsolutePath());
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
} else if (recording.isAudio()) {
Uri audioUri = Uri.parse(recording.file.getAbsolutePath());
Uri audioUri = Uri.parse(recording.getFile().getAbsolutePath());
sharingIntent.setType("audio/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, audioUri);
} else if (recording.isVideo()) {
Uri videoUri = Uri.parse(recording.file.getAbsolutePath());
Uri videoUri = Uri.parse(recording.getFile().getAbsolutePath());
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, videoUri);
}
@ -229,12 +211,23 @@ public class NotesFragment extends ListFragment {
getListView(), false);
final EditText editText = (EditText) v.findViewById(R.id.name);
builder.setView(v);
editText.setText(recording.getName());
String fileName = recording.getName();
int extInd = recording.getName().lastIndexOf(".");
final String extension;
if (extInd >= 0){
extension = fileName.substring(extInd, fileName.length());
} else {
extension = "";
}
editText.setText(recording.getName().substring(0, extInd));
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) {
recording.setName(editText.getText().toString());
if(!recording.setName(editText.getText().toString() + extension)) {
Toast.makeText(getActivity(),R.string.rename_failed,Toast.LENGTH_SHORT).show();
}
recording.setDescription();
listAdapter.notifyDataSetInvalidated();
}