setting stuff

This commit is contained in:
Mike Schwörer 2018-10-22 13:53:21 +02:00
parent 96a3cbc40a
commit 6dfd7e016b
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
7 changed files with 219 additions and 129 deletions

View File

@ -1,11 +1,13 @@
package com.blackforestbytes.simplecloudnotifier.model;
import android.graphics.Color;
import android.net.Uri;
public class NotificationSettings
{
public boolean EnableSound = false;
public String SoundSource = "";
public String SoundName = "";
public String SoundSource = Uri.EMPTY.toString();
public boolean RepeatSound = false;
public boolean EnableLED = false;

View File

@ -65,6 +65,7 @@ public class SCNSettings
PriorityLow.EnableSound = sharedPref.getBoolean("priority_low:enabled_sound", PriorityLow.EnableSound);
PriorityLow.EnableVibration = sharedPref.getBoolean("priority_low:enabled_vibration", PriorityLow.EnableVibration);
PriorityLow.RepeatSound = sharedPref.getBoolean("priority_low:repeat_sound", PriorityLow.RepeatSound);
PriorityLow.SoundName = sharedPref.getString( "priority_low:sound_name", PriorityLow.SoundName);
PriorityLow.SoundSource = sharedPref.getString( "priority_low:sound_source", PriorityLow.SoundSource);
PriorityLow.LEDColor = sharedPref.getInt( "priority_low:led_color", PriorityLow.LEDColor);
@ -72,6 +73,7 @@ public class SCNSettings
PriorityNorm.EnableSound = sharedPref.getBoolean("priority_norm:enabled_sound", PriorityNorm.EnableSound);
PriorityNorm.EnableVibration = sharedPref.getBoolean("priority_norm:enabled_vibration", PriorityNorm.EnableVibration);
PriorityNorm.RepeatSound = sharedPref.getBoolean("priority_norm:repeat_sound", PriorityNorm.RepeatSound);
PriorityNorm.SoundName = sharedPref.getString( "priority_norm:sound_name", PriorityNorm.SoundName);
PriorityNorm.SoundSource = sharedPref.getString( "priority_norm:sound_source", PriorityNorm.SoundSource);
PriorityNorm.LEDColor = sharedPref.getInt( "priority_norm:led_color", PriorityNorm.LEDColor);
@ -79,6 +81,7 @@ public class SCNSettings
PriorityHigh.EnableSound = sharedPref.getBoolean("priority_high:enabled_sound", PriorityHigh.EnableSound);
PriorityHigh.EnableVibration = sharedPref.getBoolean("priority_high:enabled_vibration", PriorityHigh.EnableVibration);
PriorityHigh.RepeatSound = sharedPref.getBoolean("priority_high:repeat_sound", PriorityHigh.RepeatSound);
PriorityHigh.SoundName = sharedPref.getString( "priority_high:sound_name", PriorityHigh.SoundName);
PriorityHigh.SoundSource = sharedPref.getString( "priority_high:sound_source", PriorityHigh.SoundSource);
PriorityHigh.LEDColor = sharedPref.getInt( "priority_high:led_color", PriorityHigh.LEDColor);
}

View File

@ -16,9 +16,8 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import xyz.aprildown.ultimatemusicpicker.MusicPickerListener;
public class MainActivity extends AppCompatActivity implements MusicPickerListener
public class MainActivity extends AppCompatActivity
{
public TabAdapter adpTabs;
@ -54,14 +53,4 @@ public class MainActivity extends AppCompatActivity implements MusicPickerListen
CMessageList.inst().fullSave();
}
@Override
public void onMusicPick(@NotNull Uri uri, @NotNull String s) {
}
@Override
public void onPickCanceled() {
}
}

View File

@ -1,57 +1,65 @@
package com.blackforestbytes.simplecloudnotifier.view;
import android.content.Context;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import com.blackforestbytes.simplecloudnotifier.R;
import com.blackforestbytes.simplecloudnotifier.SCNApp;
import com.blackforestbytes.simplecloudnotifier.model.SCNSettings;
import org.jetbrains.annotations.NotNull;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import xyz.aprildown.ultimatemusicpicker.MusicPickerListener;
import xyz.aprildown.ultimatemusicpicker.UltimateMusicPicker;
public class SettingsFragment extends Fragment
public class SettingsFragment extends Fragment implements MusicPickerListener
{
private Switch prefAppEnabled;
private Spinner prefLocalCacheSize;
private Button prefUpgradeAccount;
private Switch prefMsgLowEnableSound;
private TextView tvMsgLowRingtone_value;
private View prevMsgLowRingtone;
private View prefMsgLowRingtone;
private Switch prefMsgLowRepeatSound;
private Switch prefMsgLowEnableLED;
private TextView tvMsgLowLedColor;
private ImageView prefMsgLowLedColor;
private View prefMsgLowLedColor_container;
private ImageView prefMsgLowLedColor_value;
private Switch prefMsgLowEnableVibrations;
private Switch prefMsgNormEnableSound;
private TextView tvMsgNormRingtone_value;
private View prevMsgNormRingtone;
private View prefMsgNormRingtone;
private Switch prefMsgNormRepeatSound;
private Switch prefMsgNormEnableLED;
private TextView tvMsgNormLedColor;
private ImageView prefMsgNormLedColor;
private View prefMsgNormLedColor_container;
private ImageView prefMsgNormLedColor_value;
private Switch prefMsgNormEnableVibrations;
private Switch prefMsgHighEnableSound;
private TextView tvMsgHighRingtone_value;
private View prevMsgHighRingtone;
private View prefMsgHighRingtone;
private Switch prefMsgHighRepeatSound;
private Switch prefMsgHighEnableLED;
private TextView tvMsgHighLedColor;
private ImageView prefMsgHighLedColor;
private View prefMsgHighLedColor_container;
private ImageView prefMsgHighLedColor_value;
private Switch prefMsgHighEnableVibrations;
private int musicPickerSwitch = -1;
public SettingsFragment()
{
// Required empty public constructor
@ -62,70 +70,102 @@ public class SettingsFragment extends Fragment
{
View v = inflater.inflate(R.layout.fragment_settings, container, false);
{
prefAppEnabled = v.findViewById(R.id.prefAppEnabled);
prefLocalCacheSize = v.findViewById(R.id.prefLocalCacheSize);
prefMsgLowEnableSound = v.findViewById(R.id.prefMsgLowEnableSound);
tvMsgLowRingtone_value = v.findViewById(R.id.tvMsgLowRingtone_value);
prevMsgLowRingtone = v.findViewById(R.id.prevMsgLowRingtone);
prefMsgLowRepeatSound = v.findViewById(R.id.prefMsgLowRepeatSound);
prefMsgLowEnableLED = v.findViewById(R.id.prefMsgLowEnableLED);
tvMsgLowLedColor = v.findViewById(R.id.tvMsgLowLedColor);
prefMsgLowLedColor = v.findViewById(R.id.prefMsgLowLedColor);
prefMsgLowEnableVibrations = v.findViewById(R.id.prefMsgLowEnableVibrations);
prefMsgNormEnableSound = v.findViewById(R.id.prefMsgNormEnableSound);
tvMsgNormRingtone_value = v.findViewById(R.id.tvMsgNormRingtone_value);
prevMsgNormRingtone = v.findViewById(R.id.prevMsgNormRingtone);
prefMsgNormRepeatSound = v.findViewById(R.id.prefMsgNormRepeatSound);
prefMsgNormEnableLED = v.findViewById(R.id.prefMsgNormEnableLED);
tvMsgNormLedColor = v.findViewById(R.id.tvMsgNormLedColor);
prefMsgNormLedColor = v.findViewById(R.id.prefMsgNormLedColor);
prefMsgNormEnableVibrations = v.findViewById(R.id.prefMsgNormEnableVibrations);
prefMsgHighEnableSound = v.findViewById(R.id.prefMsgHighEnableSound);
tvMsgHighRingtone_value = v.findViewById(R.id.tvMsgHighRingtone_value);
prevMsgHighRingtone = v.findViewById(R.id.prevMsgHighRingtone);
prefMsgHighRepeatSound = v.findViewById(R.id.prefMsgHighRepeatSound);
prefMsgHighEnableLED = v.findViewById(R.id.prefMsgHighEnableLED);
tvMsgHighLedColor = v.findViewById(R.id.tvMsgHighLedColor);
prefMsgHighLedColor = v.findViewById(R.id.prefMsgHighLedColor);
prefMsgHighEnableVibrations = v.findViewById(R.id.prefMsgHighEnableVibrations);
}
{
SCNSettings s = SCNSettings.inst();
prefAppEnabled.setChecked(s.Enabled);
prefAppEnabled.setOnCheckedChangeListener((a,b) -> onUpdate());
ArrayAdapter<Integer> plcsa = new ArrayAdapter<>(v.getContext(), android.R.layout.simple_spinner_item, SCNSettings.CHOOSABLE_CACHE_SIZES);
plcsa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
prefLocalCacheSize.setAdapter(plcsa);
prefLocalCacheSize.setSelection(getCacheSizeIndex(s.LocalCacheSize));
prefLocalCacheSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { onUpdate(); }
@Override public void onNothingSelected(AdapterView<?> parent) { onUpdate(); }
});
//TODO ...
prevMsgLowRingtone.setOnClickListener((a) -> chooseRingtoneLow());
}
initFields(v);
updateUI();
initListener();
return v;
}
private void onUpdate()
private void initFields(View v)
{
prefAppEnabled = v.findViewById(R.id.prefAppEnabled);
prefLocalCacheSize = v.findViewById(R.id.prefLocalCacheSize);
prefUpgradeAccount = v.findViewById(R.id.prefUpgradeAccount);
prefMsgLowEnableSound = v.findViewById(R.id.prefMsgLowEnableSound);
tvMsgLowRingtone_value = v.findViewById(R.id.tvMsgLowRingtone_value);
prefMsgLowRingtone = v.findViewById(R.id.prefMsgLowRingtone);
prefMsgLowRepeatSound = v.findViewById(R.id.prefMsgLowRepeatSound);
prefMsgLowEnableLED = v.findViewById(R.id.prefMsgLowEnableLED);
prefMsgLowLedColor_value = v.findViewById(R.id.prefMsgLowLedColor_value);
prefMsgLowLedColor_container = v.findViewById(R.id.prefMsgLowLedColor_container);
prefMsgLowEnableVibrations = v.findViewById(R.id.prefMsgLowEnableVibrations);
prefMsgNormEnableSound = v.findViewById(R.id.prefMsgNormEnableSound);
tvMsgNormRingtone_value = v.findViewById(R.id.tvMsgNormRingtone_value);
prefMsgNormRingtone = v.findViewById(R.id.prefMsgNormRingtone);
prefMsgNormRepeatSound = v.findViewById(R.id.prefMsgNormRepeatSound);
prefMsgNormEnableLED = v.findViewById(R.id.prefMsgNormEnableLED);
prefMsgNormLedColor_value = v.findViewById(R.id.prefMsgNormLedColor_value);
prefMsgNormLedColor_container = v.findViewById(R.id.prefMsgNormLedColor_container);
prefMsgNormEnableVibrations = v.findViewById(R.id.prefMsgNormEnableVibrations);
prefMsgHighEnableSound = v.findViewById(R.id.prefMsgHighEnableSound);
tvMsgHighRingtone_value = v.findViewById(R.id.tvMsgHighRingtone_value);
prefMsgHighRingtone = v.findViewById(R.id.prefMsgHighRingtone);
prefMsgHighRepeatSound = v.findViewById(R.id.prefMsgHighRepeatSound);
prefMsgHighEnableLED = v.findViewById(R.id.prefMsgHighEnableLED);
prefMsgHighLedColor_value = v.findViewById(R.id.prefMsgHighLedColor_value);
prefMsgHighLedColor_container = v.findViewById(R.id.prefMsgHighLedColor_container);
prefMsgHighEnableVibrations = v.findViewById(R.id.prefMsgHighEnableVibrations);
}
private void updateUI()
{
SCNSettings s = SCNSettings.inst();
Context c = getContext();
if (c == null) return;
prefAppEnabled.setChecked(s.Enabled);
ArrayAdapter<Integer> plcsa = new ArrayAdapter<>(c, android.R.layout.simple_spinner_item, SCNSettings.CHOOSABLE_CACHE_SIZES);
plcsa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
prefLocalCacheSize.setAdapter(plcsa);
prefLocalCacheSize.setSelection(getCacheSizeIndex(s.LocalCacheSize));
prefMsgLowEnableSound.setChecked(s.PriorityLow.EnableSound);
tvMsgLowRingtone_value.setText(s.PriorityLow.SoundName);
prefMsgLowRepeatSound.setChecked(s.PriorityLow.RepeatSound);
prefMsgLowEnableLED.setChecked(s.PriorityLow.EnableLED);
prefMsgLowLedColor_value.setColorFilter(s.PriorityLow.LEDColor);
prefMsgLowEnableVibrations.setChecked(s.PriorityLow.EnableVibration);
}
private void initListener()
{
SCNSettings s = SCNSettings.inst();
s.Enabled = prefAppEnabled.isChecked();
s.LocalCacheSize = prefLocalCacheSize.getSelectedItemPosition()>=0 ? SCNSettings.CHOOSABLE_CACHE_SIZES[prefLocalCacheSize.getSelectedItemPosition()] : 100;
prefAppEnabled.setOnCheckedChangeListener((a,b) -> { s.Enabled=b; saveAndUpdate(); });
s.save();
prefLocalCacheSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
s.LocalCacheSize = prefLocalCacheSize.getSelectedItemPosition()>=0 ? SCNSettings.CHOOSABLE_CACHE_SIZES[prefLocalCacheSize.getSelectedItemPosition()] : 100;
saveAndUpdate();
}
@Override public void onNothingSelected(AdapterView<?> parent) { /* */ }
});
prefUpgradeAccount.setOnClickListener(a -> onUpgradeAccount());
prefMsgLowEnableSound.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.EnableSound=b; saveAndUpdate(); });
prefMsgLowRingtone.setOnClickListener(a -> chooseRingtoneLow());
prefMsgLowRepeatSound.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.RepeatSound=b; saveAndUpdate(); });
prefMsgLowEnableLED.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.EnableLED=b; saveAndUpdate(); });
prefMsgLowLedColor_container.setOnClickListener(a -> chooseLEDColorLow());
prefMsgLowEnableVibrations.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.EnableVibration=b; saveAndUpdate(); });
}
private void saveAndUpdate()
{
SCNSettings.inst().save();
updateUI();
}
private void onUpgradeAccount()
{
//TODO
}
private int getCacheSizeIndex(int value)
@ -139,6 +179,7 @@ public class SettingsFragment extends Fragment
private void chooseRingtoneLow()
{
musicPickerSwitch = 1;
new UltimateMusicPicker()
.windowTitle("Choose notification sound")
.removeSilent()
@ -147,6 +188,55 @@ public class SettingsFragment extends Fragment
.notification()
.alarm()
.music()
.goWithDialog(SCNApp.getMainActivity().getSupportFragmentManager());
.goWithDialog(getChildFragmentManager());
}
private void chooseRingtoneNorm()
{
musicPickerSwitch = 2;
new UltimateMusicPicker()
.windowTitle("Choose notification sound")
.removeSilent()
.streamType(AudioManager.STREAM_ALARM)
.ringtone()
.notification()
.alarm()
.music()
.goWithDialog(getChildFragmentManager());
}
private void chooseRingtoneHigh()
{
musicPickerSwitch = 3;
new UltimateMusicPicker()
.windowTitle("Choose notification sound")
.removeSilent()
.streamType(AudioManager.STREAM_ALARM)
.ringtone()
.notification()
.alarm()
.music()
.goWithDialog(getChildFragmentManager());
}
private void chooseLEDColorLow()
{
//
}
@Override
public void onMusicPick(@NotNull Uri uri, @NotNull String s)
{
if (musicPickerSwitch == 1) { SCNSettings.inst().PriorityLow.SoundSource =uri.toString(); SCNSettings.inst().PriorityLow.SoundName =s; saveAndUpdate(); }
if (musicPickerSwitch == 2) { SCNSettings.inst().PriorityNorm.SoundSource=uri.toString(); SCNSettings.inst().PriorityNorm.SoundName=s; saveAndUpdate(); }
if (musicPickerSwitch == 3) { SCNSettings.inst().PriorityHigh.SoundSource=uri.toString(); SCNSettings.inst().PriorityHigh.SoundName=s; saveAndUpdate(); }
musicPickerSwitch = -1;
}
@Override
public void onPickCanceled()
{
musicPickerSwitch = -1;
}
}

View File

@ -26,6 +26,7 @@
<TextView
android:background="@color/colorHeader"
android:textColor="@color/colorHeaderForeground"
android:textSize="16sp"
android:padding="4dp"
android:text="@string/str_common_settings"
@ -104,7 +105,7 @@
<Button
android:id="@+id/prefUpgradeAccount"
android:text="Upgrade account"
android:text="@string/str_upgrade_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
@ -129,6 +130,7 @@
<TextView
android:background="@color/colorHeader"
android:textColor="@color/colorHeaderForeground"
android:textSize="16sp"
android:padding="4dp"
android:text="@string/str_header_prio0"
@ -168,7 +170,7 @@
android:minHeight="48dp">
<LinearLayout
android:id="@+id/prevMsgLowRingtone"
android:id="@+id/prefMsgLowRingtone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@ -252,6 +254,7 @@
android:background="#c0c0c0"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/prefMsgLowLedColor_container"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_width="match_parent"
@ -259,13 +262,12 @@
android:minHeight="48dp">
<TextView
android:id="@+id/tvMsgLowLedColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_ledcolor"
android:textColor="#000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/prefMsgLowLedColor"
app:layout_constraintEnd_toStartOf="@+id/prefMsgLowLedColor_value"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -273,7 +275,7 @@
<ImageView
android:src="@drawable/circle"
android:layout_marginEnd="4dp"
android:id="@+id/prefMsgLowLedColor"
android:id="@+id/prefMsgLowLedColor_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dialog"
@ -326,6 +328,7 @@
<TextView
android:background="@color/colorHeader"
android:textColor="@color/colorHeaderForeground"
android:textSize="16sp"
android:padding="4dp"
android:text="@string/str_header_prio1"
@ -365,7 +368,7 @@
android:minHeight="48dp">
<LinearLayout
android:id="@+id/prevMsgNormRingtone"
android:id="@+id/prefMsgNormRingtone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@ -449,6 +452,7 @@
android:background="#c0c0c0"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/prefMsgNormLedColor_container"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_width="match_parent"
@ -456,13 +460,12 @@
android:minHeight="48dp">
<TextView
android:id="@+id/tvMsgNormLedColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_ledcolor"
android:textColor="#000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/prefMsgNormLedColor"
app:layout_constraintEnd_toStartOf="@+id/prefMsgNormLedColor_value"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -470,7 +473,7 @@
<ImageView
android:src="@drawable/circle"
android:layout_marginEnd="4dp"
android:id="@+id/prefMsgNormLedColor"
android:id="@+id/prefMsgNormLedColor_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dialog"
@ -523,6 +526,7 @@
<TextView
android:background="@color/colorHeader"
android:textColor="@color/colorHeaderForeground"
android:textSize="16sp"
android:padding="4dp"
android:text="@string/str_header_prio2"
@ -562,7 +566,7 @@
android:minHeight="48dp">
<LinearLayout
android:id="@+id/prevMsgHighRingtone"
android:id="@+id/prefMsgHighRingtone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@ -646,6 +650,7 @@
android:background="#c0c0c0"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/prefMsgHighLedColor_container"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_width="match_parent"
@ -653,13 +658,12 @@
android:minHeight="48dp">
<TextView
android:id="@+id/tvMsgHighLedColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_ledcolor"
android:textColor="#000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/prefMsgHighLedColor"
app:layout_constraintEnd_toStartOf="@+id/prefMsgHighLedColor_value"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -667,7 +671,7 @@
<ImageView
android:src="@drawable/circle"
android:layout_marginEnd="4dp"
android:id="@+id/prefMsgHighLedColor"
android:id="@+id/prefMsgHighLedColor_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dialog"

View File

@ -3,7 +3,8 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorHeader">#67809F</color>
<color name="colorHeader">#3F51B5</color>
<color name="colorHeaderForeground">#FFFFFF</color>
<color name="colorBlack">#000</color>
</resources>

View File

@ -27,4 +27,5 @@
<string name="str_enable_led">Enable notification light</string>
<string name="str_ledcolor">Notification light color</string>
<string name="str_enable_vibration">Enable notification vibration</string>
<string name="str_upgrade_account">Upgrade account</string>
</resources>