From 7885e266d53b5927c25d7717d1680d24489daae1 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Sun, 13 Mar 2016 22:49:32 +0300 Subject: [PATCH] better notification --- .../activities/RecordingActivity.java | 48 +- .../audiorecorder/widgets/OpenFileDialog.java | 561 ++++++++++-------- .../widgets/StoragePathPreference.java | 20 +- app/src/main/res/drawable-hdpi/ic_up.png | Bin 352 -> 0 bytes app/src/main/res/drawable-mdpi/ic_up.png | Bin 271 -> 0 bytes app/src/main/res/drawable-xhdpi/ic_up.png | Bin 440 -> 0 bytes app/src/main/res/drawable-xxhdpi/ic_up.png | Bin 589 -> 0 bytes .../res/layout/notifictaion_recording.xml | 76 ++- 8 files changed, 402 insertions(+), 303 deletions(-) delete mode 100644 app/src/main/res/drawable-hdpi/ic_up.png delete mode 100644 app/src/main/res/drawable-mdpi/ic_up.png delete mode 100644 app/src/main/res/drawable-xhdpi/ic_up.png delete mode 100644 app/src/main/res/drawable-xxhdpi/ic_up.png diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java index e723f50..a578103 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java @@ -58,6 +58,7 @@ public class RecordingActivity extends AppCompatActivity { public static final String CLOSE_ACTIVITY = RecordingActivity.class.getCanonicalName() + ".CLOSE_ACTIVITY"; public static final int NOTIFICATION_RECORDING_ICON = 0; public static String SHOW_ACTIVITY = RecordingActivity.class.getCanonicalName() + ".SHOW_ACTIVITY"; + public static String PAUSE = RecordingActivity.class.getCanonicalName() + ".PAUSE"; public static final String PHONE_STATE = "android.intent.action.PHONE_STATE"; @@ -66,6 +67,7 @@ public class RecordingActivity extends AppCompatActivity { Handler handle = new Handler(); FileEncoder encoder; + boolean start = false; Thread thread; // dynamic buffer size. big for backgound recording. small for realtime view updates. Integer bufferSize = 0; @@ -100,6 +102,9 @@ public class RecordingActivity extends AppCompatActivity { if (intent.getAction().equals(SHOW_ACTIVITY)) { showRecordingActivity(); } + if (intent.getAction().equals(PAUSE)) { + pauseButton(); + } } } @@ -153,6 +158,7 @@ public class RecordingActivity extends AppCompatActivity { filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(SHOW_ACTIVITY); + filter.addAction(PAUSE); registerReceiver(receiver, filter); SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this); @@ -198,13 +204,7 @@ public class RecordingActivity extends AppCompatActivity { pause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (thread != null) { - stopRecording("pause"); - } else { - if (permitted(PERMISSIONS)) { - resumeRecording(); - } - } + pauseButton(); } }); @@ -238,20 +238,33 @@ public class RecordingActivity extends AppCompatActivity { startActivity(intent); } + void pauseButton() { + if (thread != null) { + stopRecording("pause"); + } else { + if (permitted(PERMISSIONS)) { + resumeRecording(); + } + } + } + @Override protected void onResume() { super.onResume(); + Log.d(TAG, "onResume"); // start once - if (thread == null) { + if (start == false) { + start = true; if (permitted()) { record(); } } - Log.d(TAG, "onResume"); updateBufferSize(false); - pitch.resume(); + + if (thread != null) + pitch.resume(); } @Override @@ -267,6 +280,8 @@ public class RecordingActivity extends AppCompatActivity { pause.setImageResource(R.drawable.ic_mic_24dp); stopRecording(); + + showNotificationAlarm(true); } void stopRecording() { @@ -338,8 +353,6 @@ public class RecordingActivity extends AppCompatActivity { void record() { state.setText("recording"); - showNotificationAlarm(true); - silent(); pause.setImageResource(R.drawable.ic_pause_24dp); @@ -454,6 +467,8 @@ public class RecordingActivity extends AppCompatActivity { } }, "RecordingThread"); thread.start(); + + showNotificationAlarm(true); } long getSamples(long len) { @@ -497,8 +512,15 @@ public class RecordingActivity extends AppCompatActivity { new Intent(SHOW_ACTIVITY), PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pe = PendingIntent.getBroadcast(this, 0, + new Intent(PAUSE), + PendingIntent.FLAG_UPDATE_CURRENT); + RemoteViews view = new RemoteViews(getPackageName(), R.layout.notifictaion_recording); - view.setOnClickPendingIntent(R.id.notification_base, main); + view.setOnClickPendingIntent(R.id.status_bar_latest_event_content, main); + view.setTextViewText(R.id.notification_text, ".../" + targetFile.getName()); + view.setOnClickPendingIntent(R.id.notification_pause, pe); + view.setImageViewResource(R.id.notification_pause, thread == null ? R.drawable.play : R.drawable.pause); Notification.Builder builder = new Notification.Builder(this) .setOngoing(true) diff --git a/app/src/main/java/com/github/axet/audiorecorder/widgets/OpenFileDialog.java b/app/src/main/java/com/github/axet/audiorecorder/widgets/OpenFileDialog.java index f54f92d..38418e1 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/widgets/OpenFileDialog.java +++ b/app/src/main/java/com/github/axet/audiorecorder/widgets/OpenFileDialog.java @@ -7,69 +7,93 @@ import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Environment; -import android.preference.EditTextPreference; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; import android.view.Display; -import android.view.Gravity; -import android.view.Menu; -import android.view.MenuInflater; +import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupMenu; import android.widget.TextView; import android.widget.Toast; -import com.github.axet.audiorecorder.R; - import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; -import java.util.List; public class OpenFileDialog extends AlertDialog.Builder { - private String currentPath = Environment.getExternalStorageDirectory().getPath(); - private TextView title; - private ListView listView; - private FilenameFilter filenameFilter; - private int selectedIndex = -1; - private OpenDialogListener listener; - private Drawable folderIcon; - private Drawable fileIcon; - private Drawable upIcon; + public static String RENAME = "Rename"; + public static String DELETE = "Delete"; + public static String NEW_FOLDER = "New Folder"; + public static String FOLDER_NAME = "Folder Name"; + public static String UNABLE_CREATE_FOLDER = "Unable create folder: '%s'"; + public static String FOLDER_CREATED = "Folder '%s' created"; + public static String DELETED = "Folder '%s' deleted"; + public static String RENAMED = "Renamed to: '%s'"; + public static String EMPTY_LIST = "Empty List"; + + File currentPath; + TextView title; + ListView listView; + FilenameFilter filenameFilter; + int folderIcon; + int fileIcon; FileAdapter adapter; - public interface OpenDialogListener { - public void onFileSelected(String fileName); - } + int paddingLeft; + int paddingRight; + int paddingBottom; + int paddingTop; + int iconSize; static class SortFiles implements Comparator { + // for symlinks + boolean isFile(File f) { + return !f.isDirectory(); + } + @Override - public int compare(File file, File file2) { - if (file.isDirectory() && file2.isFile()) + public int compare(File f1, File f2) { + if (f1.isDirectory() && isFile(f2)) return -1; - else if (file.isFile() && file2.isDirectory()) + else if (isFile(f1) && f2.isDirectory()) return 1; else - return file.getPath().compareTo(file2.getPath()); + return f1.getPath().compareTo(f2.getPath()); } } - class FileAdapter extends ArrayAdapter { - public FileAdapter(Context context, List files) { - super(context, android.R.layout.simple_list_item_1, files); + public class FileAdapter extends ArrayAdapter { + int selectedIndex = -1; + int colorSelected; + int colorTransparent; + + public FileAdapter(Context context) { + super(context, android.R.layout.simple_list_item_1); + + if (Build.VERSION.SDK_INT >= 23) { + colorSelected = getContext().getResources().getColor(android.R.color.holo_blue_dark, getContext().getTheme()); + colorTransparent = getContext().getResources().getColor(android.R.color.transparent, getContext().getTheme()); + } else { + colorSelected = getContext().getResources().getColor(android.R.color.holo_blue_dark); + colorTransparent = getContext().getResources().getColor(android.R.color.transparent); + } } @Override @@ -79,14 +103,14 @@ public class OpenFileDialog extends AlertDialog.Builder { if (view != null) { view.setText(file.getName()); if (file.isDirectory()) { - setDrawable(view, folderIcon); + setDrawable(view, getDrawable(folderIcon)); } else { - setDrawable(view, fileIcon); + setDrawable(view, getDrawable(fileIcon)); } if (selectedIndex == position) - view.setBackgroundColor(getContext().getResources().getColor(android.R.color.holo_blue_dark)); + view.setBackgroundColor(colorSelected); else - view.setBackgroundColor(getContext().getResources().getColor(android.R.color.transparent)); + view.setBackgroundColor(colorTransparent); } return view; } @@ -94,55 +118,252 @@ public class OpenFileDialog extends AlertDialog.Builder { private void setDrawable(TextView view, Drawable drawable) { if (view != null) { if (drawable != null) { - drawable.setBounds(0, 0, 60, 60); + drawable.setBounds(0, 0, iconSize, iconSize); view.setCompoundDrawables(drawable, null, null, null); } else { view.setCompoundDrawables(null, null, null, null); } } } + + public void scan(File dir) { + selectedIndex = -1; + + clear(); + + File[] files = dir.listFiles(filenameFilter); + + if (files == null) + return; + + ArrayList list = new ArrayList<>(Arrays.asList(files)); + + addAll(list); + + sort(new SortFiles()); + + notifyDataSetChanged(); + } + } + + + public static class EditTextDialog extends AlertDialog.Builder { + EditText input; + + public EditTextDialog(Context context) { + super(context); + + input = new EditText(getContext()); + + setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + dialog.cancel(); + } + }); + setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + dialog.cancel(); + } + }); + + setView(input); + } + + public void setText(String s) { + input.setText(s); + input.setSelection(s.length()); + } + + public String getText() { + return input.getText().toString(); + } + + public AlertDialog show() { + final AlertDialog d = super.show(); + + return d; + } } public OpenFileDialog(Context context) { super(context); + + currentPath = Environment.getExternalStorageDirectory(); + paddingLeft = dp2px(14); + paddingRight = dp2px(14); + paddingTop = dp2px(14); + paddingBottom = dp2px(14); + iconSize = dp2px(30); } - public void init() { - Context context = getContext(); + public int dp2px(int dp) { + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getContext().getResources().getDisplayMetrics()); + } - title = createTitle(context); - changeTitle(); - LinearLayout linearLayout = createMainLayout(context); - linearLayout.addView(createBackItem(context)); - listView = createListView(context); - linearLayout.addView(listView); - setCustomTitle(title); - setView(linearLayout); - setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (listener != null) { - if (selectedIndex > -1) - listener.onFileSelected(listView.getItemAtPosition(selectedIndex).toString()); - else - listener.onFileSelected(currentPath.toString()); - } - } - }); - setNegativeButton(android.R.string.cancel, null); + void toast(String msg) { + Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show(); } @Override public AlertDialog show() { - adapter = new FileAdapter(getContext(), getFiles(currentPath)); - adapter.sort(new SortFiles()); + title = (TextView) LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_1, null); + title.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + title.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + changeTitle(); + setCustomTitle(title); + + // main view, linearlayout + final LinearLayout main = new LinearLayout(getContext()); + main.setOrientation(LinearLayout.VERTICAL); + main.setMinimumHeight(getLinearLayoutMinHeight(getContext())); + main.setPadding(paddingLeft, 0, paddingRight, 0); + + // add toolbar (UP / NEWFOLDER) + { + LinearLayout toolbar = new LinearLayout(getContext()); + toolbar.setOrientation(LinearLayout.HORIZONTAL); + toolbar.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + + { + TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_1, null); + textView.setText("[..]"); + Drawable icon = getDrawable(folderIcon); + icon.setBounds(0, 0, iconSize, iconSize); + textView.setCompoundDrawables(icon, null, null, null); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + lp.weight = 1; + textView.setLayoutParams(lp); + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + File parentDirectory = currentPath.getParentFile(); + if (parentDirectory != null) { + currentPath = parentDirectory; + RebuildFiles(); + } + } + }); + toolbar.addView(textView); + } + + { + Button textView = new Button(getContext()); + textView.setPadding(paddingLeft, 0, paddingRight, 0); + textView.setText(NEW_FOLDER); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + final EditTextDialog builder = new EditTextDialog(getContext()); + builder.setTitle(FOLDER_NAME); + builder.setText(""); + builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + File f = new File(currentPath, builder.getText()); + if (!f.mkdirs()) { + toast(String.format(UNABLE_CREATE_FOLDER, builder.getText())); + } else { + toast(String.format(FOLDER_CREATED, builder.getText())); + } + adapter.scan(currentPath); + dialog.cancel(); + } + }); + builder.show(); + } + }); + toolbar.addView(textView, lp); + } + + main.addView(toolbar); + } + + // ADD FILES LIST + { + listView = new ListView(getContext()); + listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { + final PopupMenu p = new PopupMenu(getContext(), view); + p.getMenu().add(RENAME); + p.getMenu().add(DELETE); + p.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + if (item.getTitle().equals(RENAME)) { + final File ff = adapter.getItem(position); + final EditTextDialog b = new EditTextDialog(getContext()); + b.setTitle(FOLDER_NAME); + b.setText(ff.getName()); + b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + File f = new File(ff.getParent(), b.getText()); + ff.renameTo(f); + toast(String.format(RENAMED, f.getName())); + adapter.scan(currentPath); + dialog.cancel(); + } + }); + b.show(); + return true; + } + if (item.getTitle().equals(DELETE)) { + File ff = adapter.getItem(position); + ff.delete(); + toast(String.format(DELETED, ff.getName())); + adapter.scan(currentPath); + return true; + } + return false; + } + }); + p.show(); + return true; + } + }); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int index, long l) { + File file = adapter.getItem(index); + if (file.isDirectory()) { + currentPath = file; + RebuildFiles(); + } else { + if (index != adapter.selectedIndex) + adapter.selectedIndex = index; + else + adapter.selectedIndex = -1; + adapter.notifyDataSetChanged(); + } + } + }); + main.addView(listView); + } + + { + TextView text = (TextView) LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_1, null); + text.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + text.setText(EMPTY_LIST); + text.setVisibility(View.GONE); + + listView.setEmptyView(text); + main.addView(text); + } + + setView(main); + setNegativeButton(android.R.string.cancel, null); + + adapter = new FileAdapter(getContext()); + adapter.scan(currentPath); listView.setAdapter(adapter); + return super.show(); } public OpenFileDialog setFilter(final String filter) { filenameFilter = new FilenameFilter() { - @Override public boolean accept(File file, String fileName) { File tempFile = new File(String.format("%s/%s", file.getPath(), fileName)); @@ -154,26 +375,20 @@ public class OpenFileDialog extends AlertDialog.Builder { return this; } - public OpenFileDialog setOpenDialogListener(OpenDialogListener listener) { - this.listener = listener; - return this; - } - - public OpenFileDialog setFolderIcon(Drawable drawable) { + public OpenFileDialog setFolderIcon(int drawable) { this.folderIcon = drawable; return this; } - public OpenFileDialog setUpIcon(Drawable drawable) { - this.upIcon = drawable; - return this; - } - - public void setCurrentPath(String path) { + public void setCurrentPath(File path) { currentPath = path; } - public OpenFileDialog setFileIcon(Drawable drawable) { + public File getCurrentPath() { + return currentPath; + } + + public OpenFileDialog setFileIcon(int drawable) { this.fileIcon = drawable; return this; } @@ -182,6 +397,13 @@ public class OpenFileDialog extends AlertDialog.Builder { return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); } + Drawable getDrawable(int resid) { + if (Build.VERSION.SDK_INT >= 21) + return getContext().getResources().getDrawable(resid, getContext().getTheme()); + else + return getContext().getResources().getDrawable(resid); + } + private static Point getScreenSize(Context context) { Point screeSize = new Point(); getDefaultDisplay(context).getSize(screeSize); @@ -192,122 +414,6 @@ public class OpenFileDialog extends AlertDialog.Builder { return getScreenSize(context).y; } - private LinearLayout createMainLayout(Context context) { - LinearLayout linearLayout = new LinearLayout(context); - linearLayout.setOrientation(LinearLayout.VERTICAL); - linearLayout.setMinimumHeight(getLinearLayoutMinHeight(context)); - return linearLayout; - } - - private int getItemHeight(Context context) { - TypedValue value = new TypedValue(); - DisplayMetrics metrics = new DisplayMetrics(); - context.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeightSmall, value, true); - getDefaultDisplay(context).getMetrics(metrics); - return (int) TypedValue.complexToDimension(value.data, metrics); - } - - private TextView createTextView(Context context, int style) { - TextView textView = new TextView(context); - textView.setTextAppearance(context, style); - int itemHeight = getItemHeight(context); - textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight)); - textView.setMinHeight(itemHeight); - textView.setGravity(Gravity.CENTER_VERTICAL); - textView.setPadding(15, 0, 0, 0); - return textView; - } - - private TextView createTitle(Context context) { - TextView textView = createTextView(context, android.R.style.TextAppearance_DeviceDefault_DialogWindowTitle); - return textView; - } - - private View createBackItem(Context context) { - LinearLayout ll = new LinearLayout(context); - ll.setOrientation(LinearLayout.HORIZONTAL); - ll.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - - TextView textView = createTextView(context, android.R.style.TextAppearance_DeviceDefault_Small); - Drawable drawable = getContext().getResources().getDrawable(android.R.drawable.ic_menu_directions); - drawable.setBounds(0, 0, 60, 60); - if (upIcon != null) - upIcon.setBounds(0, 0, 60, 60); - textView.setCompoundDrawables(upIcon == null ? drawable : upIcon, null, null, null); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - lp.weight = 1; - textView.setLayoutParams(lp); - textView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - File file = new File(currentPath); - File parentDirectory = file.getParentFile(); - if (parentDirectory != null) { - currentPath = parentDirectory.getPath(); - RebuildFiles(); - } - } - }); - - ll.addView(textView); - - ll.addView(createNewFolder(context)); - - return ll; - } - - public interface EditClick { - public void click(String text); - } - - AlertDialog.Builder createEditDialog(Context context, String title, String value, final EditClick ok) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - LinearLayout ll = new LinearLayout(context); - ll.setOrientation(LinearLayout.VERTICAL); - TextView text = createTitle(context); - text.setText(title); - ll.addView(text); - final EditText input = new EditText(context); - input.setText(value); - ll.addView(input); - builder.setView(ll); - builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - ok.click(input.getText().toString().trim()); - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - dialog.cancel(); - } - }); - return builder; - } - - private TextView createNewFolder(final Context context) { - Button textView = new Button(context); - textView.setPadding(15, 0, 15, 0); - textView.setText("New Folder"); - textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - textView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - AlertDialog.Builder builder = createEditDialog(context, "Folder Name", "", new EditClick() { - @Override - public void click(String value) { - File f = new File(currentPath, value); - if (!f.mkdir()) { - Toast.makeText(context, "Unable create folder: '" + value + "'", Toast.LENGTH_SHORT).show(); - } - RebuildFiles(); - } - }); - builder.show(); - } - }); - return textView; - } - public int getTextWidth(String text, Paint paint) { Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); @@ -315,7 +421,14 @@ public class OpenFileDialog extends AlertDialog.Builder { } private void changeTitle() { - String titleText = currentPath; + if (listView != null) { + if (listView.getBackground() != null) + Log.d("123", "" + listView.getBackground().getMinimumWidth() + " " + listView.getWidth() + " " + listView.getMinimumHeight()); + else + Log.d("123", "" + listView.getWidth() + " " + listView.getMinimumHeight()); + } + + String titleText = currentPath.getAbsolutePath(); int screenWidth = getScreenSize(getContext()).x; int maxWidth = (int) (screenWidth * 0.99); if (getTextWidth(titleText, title.getPaint()) > maxWidth) { @@ -332,81 +445,9 @@ public class OpenFileDialog extends AlertDialog.Builder { } } - private List getFiles(String directoryPath) { - File directory = new File(directoryPath); - File[] files = directory.listFiles(filenameFilter); - if (files == null) { - return new ArrayList<>(); - } - return new ArrayList<>(Arrays.asList(files)); - } - private void RebuildFiles() { - selectedIndex = -1; - adapter.clear(); - adapter.addAll(getFiles(currentPath)); - adapter.sort(new SortFiles()); - adapter.notifyDataSetChanged(); + adapter.scan(currentPath); + listView.setSelection(0); changeTitle(); } - - public static final String RENAME = "Rename"; - public static final String DELETE = "Delete"; - - private ListView createListView(final Context context) { - ListView listView = new ListView(context); - listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { - PopupMenu p = new PopupMenu(context, view); - p.getMenu().add(RENAME); - p.getMenu().add(DELETE); - p.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - if (item.getTitle().equals(RENAME)) { - final File ff = (File) adapter.getItem(position); - AlertDialog.Builder b = createEditDialog(context, "Folder Name", ff.getName(), new EditClick() { - @Override - public void click(String text) { - File f = new File(ff.getParent(), text); - ff.renameTo(f); - RebuildFiles(); - } - }); - b.show(); - return true; - } - if (item.getTitle().equals(DELETE)) { - File ff = (File) adapter.getItem(position); - ff.delete(); - RebuildFiles(); - return true; - } - return false; - } - }); - p.show(); - return true; - } - }); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - - @Override - public void onItemClick(AdapterView adapterView, View view, int index, long l) { - File file = adapter.getItem(index); - if (file.isDirectory()) { - currentPath = file.getPath(); - RebuildFiles(); - } else { - if (index != selectedIndex) - selectedIndex = index; - else - selectedIndex = -1; - adapter.notifyDataSetChanged(); - } - } - }); - return listView; - } } \ No newline at end of file diff --git a/app/src/main/java/com/github/axet/audiorecorder/widgets/StoragePathPreference.java b/app/src/main/java/com/github/axet/audiorecorder/widgets/StoragePathPreference.java index 9119ec3..ef85f0d 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/widgets/StoragePathPreference.java +++ b/app/src/main/java/com/github/axet/audiorecorder/widgets/StoragePathPreference.java @@ -2,6 +2,7 @@ package com.github.axet.audiorecorder.widgets; import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.TypedArray; import android.net.Uri; @@ -44,17 +45,16 @@ public class StoragePathPreference extends EditTextPreference { @Override protected void showDialog(Bundle state) { f = new OpenFileDialog(getContext()); - f.setCurrentPath(getText()); - f.setFolderIcon(getContext().getResources().getDrawable(R.drawable.ic_folder_24dp)); - f.setFileIcon(getContext().getResources().getDrawable(R.drawable.ic_file)); - f.setUpIcon(getContext().getResources().getDrawable(R.drawable.ic_up)); - f.init(); - f.setOpenDialogListener(new OpenFileDialog.OpenDialogListener() { + f.setCurrentPath(new File(getText())); + f.setFolderIcon(R.drawable.ic_folder_24dp); + f.setFileIcon(R.drawable.ic_file); + f.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override - public void onFileSelected(String fileName) { - File f = new File(fileName); - if (!f.isDirectory()) - fileName = f.getParent(); + public void onClick(DialogInterface dialog, int which) { + File ff = f.getCurrentPath(); + String fileName = ff.getName(); + if (!ff.isDirectory()) + fileName = ff.getParent(); if (callChangeListener(fileName)) { setText(fileName); } diff --git a/app/src/main/res/drawable-hdpi/ic_up.png b/app/src/main/res/drawable-hdpi/ic_up.png deleted file mode 100644 index adba100f052199d685077bde1af6471acc9c2ce9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 352 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezr3(FsggHIEGZ*N=}eqU7R4&(-dgH z<#y13wWp`YPe(`RlJljH4(+EIRx&%-#K*Y>Z@$XJ1=r}NIjX(e0< zeeI7f`}p{XIUfS5j#_Lf*H*r1<3>*YtmDkG8eB`t9)Doq@ZY$7d%Dz=zU!ARC9wrv z{%9dLP5u#k_AY;=ClwlYj6P|*nsx6=GpwBKQpM0>URYH0iI3}eaY4Zc=9RiC7IJOY zuU@~FWWVw;fW2h$!-|MH4w(S{4VyP}Gs+6~wG|gw{IC$)`j1(T`$fadnUS*X?0o#4 zT{%~n7t2X}J+Ok^&DP+N?E;1+VMzzM-PpR diff --git a/app/src/main/res/drawable-mdpi/ic_up.png b/app/src/main/res/drawable-mdpi/ic_up.png deleted file mode 100644 index 2cbbbc341c0c53cbbb2eb270038df44ca55320f0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 271 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJYo0ESAr-fh6C_v{Cx`?vsHmz& zvR`5B>FK%ZAY&9TZ8yV8V~3h4GiOG&uA8=b!v+t=mCOO`4Ii@V>gxD*Md<14pJ!Sk zrVz<@?0~?^h2a;TFN*Ga!eKru>fDhdDU3_}9v3laL^WJgb{0N;^Tv&q#w&g{(++=d z$}kDEeRz_=`2bf-qvPA=w3nPSWH>f&-pqYLSzN*T!3~F$!-4EQRtXPe6tuKXv7O1= zd`jElX)z4*}Q$iB}+1zA> diff --git a/app/src/main/res/drawable-xhdpi/ic_up.png b/app/src/main/res/drawable-xhdpi/ic_up.png deleted file mode 100644 index a7924e4fa935d6df5bd2a10db6f56c59192d84ed..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 440 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7T#lEV669aaSW-r^>)U7@52rfZJ%EY zaY&j-lyc_@nO{8Uc+s<IIvdqYDICKJp9Pk(qPEQ-(#hrR$gb&v`KpUfHW` zkM6FPulU(^>C*Rw_f=Ou7j)uKY!Ptc_!<4kV&00^x5_uw1d13QTl)UDwI7$mN9G>$ zCzc#dmdj5q{;)~w{u4Fd%V#=2IdypU{FY-hI(}{X`c+y-EZztIQ;z8Nz5TteJfL#w zas!_9oV&j(d!~yq8iiNRQxBW!KPiRhaaqTwvsyAy!EtwA%;AmxH@U?$`di)a-A_a1 z3XaY&+hxPIC9>xoKkJE@DXEf@k#?syi9D`q0cv?O`xmo?)Yd(xwAU$gFMIp9ZP_Q^ zcLl1F=Fjr@nZ7+a?3e%Hlc)E^y#3!-uDMlUyyb$@gNxsmJ8&&vKtTlo4FXAA{-tyE zH$4?}`uF(Z)~3R&pbvAWZ{eK4K4tlL`+f2K*O;#cFv@aWa20V?wJW&0BS!a diff --git a/app/src/main/res/drawable-xxhdpi/ic_up.png b/app/src/main/res/drawable-xxhdpi/ic_up.png deleted file mode 100644 index e11a5e0edcaa32a836c295d9080731a4fd575795..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 589 zcmV-T0P!V)q9gN8zAsfHTDp@axpni`vez?QZmuohdSp{b>%sllP4p=hX} zBC9{D-^m?;sNH$KcShe2{CGEq=keZqeM{2-0000000000000<3hGEPW3WXR+M8Gu7 z30WR>UEd*%kY%%3OO{KSFPV3F5*A1$MDndKJK?)?n@A*vNhX|qe^HjtmICZKt5hmF z2`OY*)~GCZZNhJkJQ-W0q=<9cIqwv{Gq15&Y=*Sd?EBllgzrv0l}ZhfSf9`P_G!ms z0rs4bTAw77$+RptKEik32kWF4P_bAvWI6R4zBAAAKA0rMVEg`NkKwy>mC0lhB-sP` z_D;$260iV!E7~VbpVH}cQkLtW;kzR*@nur=$o@4e4*C_oGY|22e2jFx?fa`8t{Q^Q zMLwT5Nw^EsG{;RZT{gpvV4S8 zfIT(-loC;${d0iXa100mG0DBy1}3}arFs@IXi4oM9F04O^e zuF32%%~^?}gQ^zIKh+N0NC8I_5bYdOK(te(01BXhuunlHnO&wiCCV* diff --git a/app/src/main/res/layout/notifictaion_recording.xml b/app/src/main/res/layout/notifictaion_recording.xml index b4ca372..42f0c72 100644 --- a/app/src/main/res/layout/notifictaion_recording.xml +++ b/app/src/main/res/layout/notifictaion_recording.xml @@ -1,27 +1,63 @@ - + android:layout_height="64dp"> + android:backgroundTint="@android:color/black" /> - - + android:layout_gravity="top" + android:layout_marginLeft="@dimen/notification_large_icon_width" + android:layout_marginStart="@dimen/notification_large_icon_width" + android:layout_marginTop="5dp" + android:minHeight="@dimen/notification_large_icon_height" + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + +