HERE: graphic reorganization, inizial presets support!

master
Nicolò Balzarotti 2017-10-11 23:25:49 +02:00
parent 6c313e2e9b
commit b6ae04383d
3 changed files with 317 additions and 215 deletions

View File

@ -19,7 +19,10 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.SeekBar;
import android.widget.TextView;
@ -91,34 +94,75 @@ public class AudioSettingsActivity extends AbstractGBActivity {
// right now, I'm just showing 0 dB, Called after changeListener sets the value on
// the device too.
Map<Integer, AudioEffectType> checkboxesIds = new HashMap<Integer, AudioEffectType>();
checkboxesIds.put(R.id.audio_effect_echo, AudioEffectType.ECHO);
checkboxesIds.put(R.id.audio_effect_bassboost, AudioEffectType.BASSBOOST);
checkboxesIds.put(R.id.audio_effect_fuzz, AudioEffectType.FUZZ);
checkboxesIds.put(R.id.audio_effect_flange, AudioEffectType.FLANGE);
checkboxesIds.put(R.id.audio_effect_reverb, AudioEffectType.REVERB);
checkboxesIds.put(R.id.audio_effect_noisemask, AudioEffectType.NOISEMASK);
checkboxesIds.put(R.id.audio_effect_bitcrusher, AudioEffectType.BITCRUSHER);
checkboxesIds.put(R.id.audio_effect_chorus, AudioEffectType.CHORUS);
Map<Integer, AudioEffectType> switchIds = new HashMap<Integer, AudioEffectType>();
switchIds.put(R.id.audio_effect_echo, AudioEffectType.ECHO);
switchIds.put(R.id.audio_effect_bassboost, AudioEffectType.BASSBOOST);
switchIds.put(R.id.audio_effect_fuzz, AudioEffectType.FUZZ);
switchIds.put(R.id.audio_effect_flange, AudioEffectType.FLANGE);
switchIds.put(R.id.audio_effect_reverb, AudioEffectType.REVERB);
switchIds.put(R.id.audio_effect_noisemask, AudioEffectType.NOISEMASK);
switchIds.put(R.id.audio_effect_bitcrusher, AudioEffectType.BITCRUSHER);
switchIds.put(R.id.audio_effect_chorus, AudioEffectType.CHORUS);
for (int id : checkboxesIds.keySet()) {
final AudioEffectType effect = checkboxesIds.get(id);
for (int id : switchIds.keySet()) {
final AudioEffectType effect = switchIds.get(id);
Switch s = (Switch) findViewById(id);
s.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
LOG.info("Toggled " + effect.name());
applyEffect(new AudioEffect(effect, isChecked));
}
});
}
((CheckedTextView) findViewById(id)).setOnClickListener(new View.OnClickListener() {
List<String> defaultPresets = new ArrayList<String>();
defaultPresets.add("8bit");
defaultPresets.add("Example");
RadioGroup presets = (RadioGroup)findViewById(R.id.audio_presets);
for (String preset : defaultPresets) {
RadioButton radioButton = new RadioButton(getBaseContext());
radioButton.setText(preset);
presets.addView(radioButton);
radioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((CheckedTextView) v).toggle();
LOG.info("Toggled " + effect.name());
applyEffect(new AudioEffect(effect, ((CheckedTextView) v).isChecked()));
RadioButton r = (RadioButton) findViewById(getCheckedPreset());
applyPreset(r.getText().toString());
}
});
}
}
private int getCheckedPreset() {
return ((RadioGroup)findViewById(R.id.audio_presets)).getCheckedRadioButtonId();
}
private void setdB(int volume) {
volume_text.setText(" " + (volume - 30) + " dB");
}
void applyEffect(AudioEffect effect) {
private void applyPreset(String preset) {
LOG.info("Applying preset " + preset);
switch(preset) {
case "8bit":
LOG.debug("8bit");
ArrayList<Object> values = new ArrayList<Object>();
values.add("3byte");
values.add(256.0f); // bits
values.add(20000.0f); // freq
AudioEffect effect = new AudioEffect(AudioEffectType.BITCRUSHER,
true, values);
GBApplication.deviceService().onSetAudioProperty(effect);
break;
default:
LOG.error("Missing preset! (Programming error!?");
}
}
private void applyEffect(AudioEffect effect) {
GBApplication.deviceService().onSetAudioProperty(effect);
}
}

View File

@ -8,12 +8,13 @@
android:orientation="vertical"
android:weightSum="1">
<SeekBar
android:id="@+id/volume_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="36"
android:scaleY="4.0" />
/>
<LinearLayout
android:id="@+id/audio_volume_text"
@ -48,49 +49,6 @@
android:baselineAligned="false"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_echo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_echo"
android:textAppearance="?android:attr/textAppearanceSmall" />
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_reverb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_reverb"
android:textAppearance="?android:attr/textAppearanceSmall" />
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_noisemask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_noisemask"
android:textAppearance="?android:attr/textAppearanceSmall" />
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_fuzz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_fuzz"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
@ -100,168 +58,265 @@
android:baselineAligned="false"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_flange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_flange"
android:textAppearance="?android:attr/textAppearanceSmall" />
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_bitcrusher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_bitcrusher"
android:textAppearance="?android:attr/textAppearanceSmall" />
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_bassboost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_bassboost"
android:textAppearance="?android:attr/textAppearanceSmall" />
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/audio_effect_chorus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/audio_effect_chorus"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Switch
android:id="@+id/audio_effect_bitcrusher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_bitcrusher"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Switch
android:id="@+id/audio_effect_fuzz"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_fuzz"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Switch
android:id="@+id/audio_effect_flange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_flange"
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>
<TableRow
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Switch
android:id="@+id/audio_effect_echo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_echo" />
<Switch
android:id="@+id/audio_effect_reverb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_reverb"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Switch
android:id="@+id/audio_effect_chorus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_chorus"
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>
<TableRow
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Switch
android:id="@+id/audio_effect_noisemask"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_noisemask"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Switch
android:id="@+id/audio_effect_bassboost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_effect_bassboost"
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/audio_effect_echo" />
<SeekBar
android:id="@+id/seekBar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/audio_delay" />
<SeekBar
android:id="@+id/seekBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/audio_level" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/audio_equalizer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_equalizer" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="horizontal">
<SeekBar
android:id="@+id/equalizer_band_0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="30" />
<TextView
android:id="@+id/equalizer_band_0_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/equalizer_band_0" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<SeekBar
android:id="@+id/equalizer_band_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="30" />
<TextView
android:id="@+id/equalizer_band_1_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/equalizer_band_1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<SeekBar
android:id="@+id/equalizer_band_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="30" />
<TextView
android:id="@+id/equalizer_band_2_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/equalizer_band_2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<SeekBar
android:id="@+id/equalizer_band_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:max="30" />
<TextView
android:id="@+id/equalizer_band_3_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/equalizer_band_3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<SeekBar
android:id="@+id/equalizer_band_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="30" />
<TextView
android:id="@+id/equalizer_band_4_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/equalizer_band_4" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/audio_equalizer_text"
android:id="@+id/audio_presets_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/audio_equalizer" />
android:text="@string/audio_presets" />
<LinearLayout
<RadioGroup
android:id="@+id/audio_presets"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="1">
android:layout_height="match_parent" />
<SeekBar
android:id="@+id/equalizer_band_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:max="30"
android:scaleY="2.0" />
<TextView
android:id="@+id/equalizer_band_0_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/equalizer_band_0" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="1">
<SeekBar
android:id="@+id/equalizer_band_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:max="30"
android:scaleY="2.0" />
<TextView
android:id="@+id/equalizer_band_1_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/equalizer_band_1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="1">
<SeekBar
android:id="@+id/equalizer_band_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:max="30"
android:scaleY="2.0" />
<TextView
android:id="@+id/equalizer_band_2_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/equalizer_band_2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="1">
<SeekBar
android:id="@+id/equalizer_band_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:max="30"
android:scaleY="2.0" />
<TextView
android:id="@+id/equalizer_band_3_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/equalizer_band_3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="1">
<SeekBar
android:id="@+id/equalizer_band_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:max="30"
android:scaleY="2.0" />
<TextView
android:id="@+id/equalizer_band_4_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/equalizer_band_4" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -492,4 +492,7 @@
<string name="equalizer_band_4">6.8 kHz</string>
<string name="audio_effect_bitcrusher">Bit Crusher</string>
<string name="audio_effect_chorus">Chorus</string>
<string name="audio_presets">Presets</string>
<string name="audio_delay">Delay</string>
<string name="audio_level">Level</string>
</resources>