From 80368d1ccca71f8f62cf0340aec689037df9ea1c Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Sat, 26 Feb 2022 08:41:23 +0300 Subject: [PATCH] add Recording Source Prop --- .../RecordingSourcePreferenceCompat.java | 77 +++++++++++++++++++ app/src/main/res/xml/pref_general.xml | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/github/axet/audiorecorder/widgets/RecordingSourcePreferenceCompat.java diff --git a/app/src/main/java/com/github/axet/audiorecorder/widgets/RecordingSourcePreferenceCompat.java b/app/src/main/java/com/github/axet/audiorecorder/widgets/RecordingSourcePreferenceCompat.java new file mode 100644 index 0000000..1a8388f --- /dev/null +++ b/app/src/main/java/com/github/axet/audiorecorder/widgets/RecordingSourcePreferenceCompat.java @@ -0,0 +1,77 @@ +package com.github.axet.audiorecorder.widgets; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.TypedArray; +import android.os.Build; +import android.preference.PreferenceManager; +import android.support.v7.preference.ListPreference; +import android.util.AttributeSet; + +import com.github.axet.audiolibrary.app.Sound; +import com.github.axet.audiorecorder.R; +import com.github.axet.audiorecorder.app.AudioApplication; +import com.github.axet.audiorecorder.app.Storage; + +import java.util.ArrayList; +import java.util.Date; + +public class RecordingSourcePreferenceCompat extends ListPreference { + public RecordingSourcePreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public RecordingSourcePreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public RecordingSourcePreferenceCompat(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public RecordingSourcePreferenceCompat(Context context) { + super(context); + } + + @Override + public boolean callChangeListener(Object newValue) { + update(newValue); + return super.callChangeListener(newValue); + } + + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + Object def = super.onGetDefaultValue(a, index); + update(def); + return def; + } + + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + super.onSetInitialValue(restoreValue, defaultValue); + CharSequence[] text = getEntries(); + CharSequence[] values = getEntryValues(); + ArrayList tt = new ArrayList<>(); + ArrayList vv = new ArrayList<>(); + String raw = getContext().getString(R.string.source_raw); + String internal = getContext().getString(R.string.source_internal); + for (int i = 0; i < values.length; i++) { + String v = values[i].toString(); + String t = text[i].toString(); + if (v.equals(raw) && !Sound.isUnprocessedSupported(getContext())) + continue; + if (v.equals(internal) && Build.VERSION.SDK_INT < 29) + continue; + vv.add(v); + tt.add(t); + } + setEntryValues(vv.toArray(new CharSequence[0])); + setEntries(tt.toArray(new CharSequence[0])); + update(getValue()); // defaultValue null after defaults set + } + + public void update(Object value) { + String v = (String) value; + setSummary(v); + } +} diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 7cf8dc3..2605104 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -7,7 +7,7 @@ android:summary="/sdcard/some/" android:title="@string/pref_storage_title" /> -