Added circle, fixed some minor issues
Limited text input length, improved break reminder design
This commit is contained in:
parent
c6455e92ce
commit
c8b5357599
8 changed files with 173 additions and 46 deletions
|
|
@ -253,11 +253,11 @@ public class BreakReminder extends AppCompatActivity
|
|||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
//FIXME Add flag if New Profile or Resume
|
||||
if (addNewProfile) {
|
||||
//if (addNewProfile) {
|
||||
fillProfiles();
|
||||
profileSpinner = (Spinner) findViewById(R.id.spinner);
|
||||
addNewProfile = false;
|
||||
}
|
||||
// addNewProfile = false;
|
||||
//}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
package orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
public class DynamicListPreference extends ListPreference implements Preference.OnPreferenceChangeListener,DialogInterface.OnClickListener {
|
||||
|
||||
Context mContext;
|
||||
int currentProfile = 0;
|
||||
|
||||
public DynamicListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
|
||||
System.out.println("Verzweiflung " + getValue());
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
String[] allProfile = sharedPreferences.getString("profiles", "").split(";");
|
||||
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
//FIXME Deactivate the onPrefListener in SettingsActivity
|
||||
for (int i = 0; i < allProfile.length; i++) {
|
||||
if (allProfile[i].split(",")[0].equals(getValue())){
|
||||
editor.putString("name_text",allProfile[i].split(",")[0]);
|
||||
editor.putString("work_value",allProfile[i].split(",")[1]);
|
||||
editor.putString("break_value",allProfile[i].split(",")[2]);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
ListView view = new ListView(getContext());
|
||||
view.setAdapter(adapter());
|
||||
setEntries(entries());
|
||||
setEntryValues(entryValues());
|
||||
setValueIndex(currentProfile);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
private ListAdapter adapter() {
|
||||
return new ArrayAdapter(getContext(), android.R.layout.select_dialog_singlechoice);
|
||||
}
|
||||
|
||||
private CharSequence[] entries() {
|
||||
//action to provide entry data in char sequence array for list
|
||||
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
String[] allProfiles = sharedPreferences.getString("profiles", "").split(";");
|
||||
CharSequence[] entries = new CharSequence[allProfiles.length];
|
||||
for (int i = 0; i < allProfiles.length; i++) {
|
||||
String profileName = allProfiles[i].split(",")[0];
|
||||
entries[i] = profileName;
|
||||
if (profileName.equals(sharedPreferences.getString("name_text", "")))
|
||||
currentProfile = i;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
private CharSequence[] entryValues() {
|
||||
//action to provide entry data in char sequence array for list
|
||||
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
String[] allProfiles = sharedPreferences.getString("profiles", "").split(";");
|
||||
CharSequence[] entries = new CharSequence[allProfiles.length];
|
||||
for (int i = 0; i < allProfiles.length; i++) {
|
||||
String profileName = allProfiles[i].split(",")[0];
|
||||
entries[i] = "" + i;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -186,6 +186,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
private SeekBarPreference _seekBarWork;
|
||||
private SeekBarPreference _seekBarBreak;
|
||||
|
||||
private DynamicListPreference dlp;
|
||||
|
||||
private String currentProfile = "";
|
||||
|
||||
@Override
|
||||
|
|
@ -198,6 +200,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
_seekBarWork = (SeekBarPreference) this.findPreference("work_value");
|
||||
_seekBarBreak = (SeekBarPreference) this.findPreference("break_value");
|
||||
|
||||
dlp = (DynamicListPreference) this.findPreference("current_profile");
|
||||
|
||||
// Set listener :
|
||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
|
|
@ -235,12 +239,23 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
|
||||
|
||||
if(key.equals("current_profile")){
|
||||
System.out.println("HOOOOOOOOOOOOOLY SHIIIIIIIIIIIIT");
|
||||
}
|
||||
|
||||
|
||||
System.out.println("--------We change something!!!!! Key: " + key);
|
||||
|
||||
// Set seekbar summary :
|
||||
int radius = PreferenceManager.getDefaultSharedPreferences(this.getActivity()).getInt("work_value", 50);
|
||||
_seekBarWork.setSummary(this.getString(R.string.settings_summary).replace("$1", "" + radius));
|
||||
radius = PreferenceManager.getDefaultSharedPreferences(this.getActivity()).getInt("break_value", 10);
|
||||
_seekBarBreak.setSummary(this.getString(R.string.settings_summary).replace("$1", "" + radius));
|
||||
|
||||
//FIXME Update the preferences of the selected profile
|
||||
if (!key.equals("profiles"))
|
||||
updateProfilesPreference();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -248,12 +263,19 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
public void onPause() {
|
||||
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
|
||||
updateProfilesPreference();
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
private void updateProfilesPreference() {
|
||||
int work_radius = PreferenceManager.getDefaultSharedPreferences(this.getActivity()).getInt("work_value", 50);
|
||||
int break_radius = PreferenceManager.getDefaultSharedPreferences(this.getActivity()).getInt("break_value", 10);
|
||||
String newProfileName = PreferenceManager.getDefaultSharedPreferences(this.getActivity()).getString("name_text", "");
|
||||
String allProfiles = PreferenceManager.getDefaultSharedPreferences(this.getActivity()).getString("profiles", "");
|
||||
|
||||
System.out.println("SETTINGS ACTIVITY0: " + newProfileName + "," + work_radius + "," + break_radius);
|
||||
System.out.println("SETTING ACTIVITY1: " + allProfiles);
|
||||
if (allProfiles.contains(newProfileName + "," + work_radius + "," + break_radius) && newProfileName.equals(currentProfile)) {
|
||||
//Nothing changes
|
||||
System.out.println("No changes for a profile in general settings");
|
||||
|
|
@ -264,16 +286,17 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
if (newProfileName.equals("")) {
|
||||
// Profile name empty
|
||||
System.out.println("EMPTY NAME IN SETTINGS ACTIVITY");
|
||||
Toast.makeText(this.getActivity(), R.string.settings_emptyName, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this.getActivity(), R.string.settings_emptyName, Toast.LENGTH_LONG).show();
|
||||
editor.putString("name_text", currentProfile);
|
||||
editor.apply();
|
||||
findPreference("name_text").setSummary(currentProfile);
|
||||
|
||||
} else if (currentProfile != newProfileName && prefContainsName(newProfileName)) {
|
||||
// Profile name exists already
|
||||
Toast.makeText(this.getActivity(), R.string.settings_doubleName, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this.getActivity(), R.string.settings_doubleName, Toast.LENGTH_LONG).show();
|
||||
editor.putString("name_text", currentProfile);
|
||||
editor.apply();
|
||||
|
||||
findPreference("name_text").setSummary(currentProfile);
|
||||
} else {
|
||||
|
||||
String[] profiles = allProfiles.split(";");
|
||||
|
|
@ -289,11 +312,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
}
|
||||
editor.putString("profiles", builder.toString());
|
||||
editor.apply();
|
||||
|
||||
currentProfile = newProfileName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
private boolean prefContainsName(String profileName) {
|
||||
|
|
|
|||
7
app/src/main/res/drawable/circle.xml
Normal file
7
app/src/main/res/drawable/circle.xml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<corners android:radius="80dip"/>
|
||||
<stroke android:color="@color/black" android:width="2dip"/>
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
</shape>
|
||||
|
|
@ -4,79 +4,66 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:background="@color/white"
|
||||
tools:context="orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder.BreakReminder"
|
||||
tools:showIn="@layout/app_bar_break_reminder">
|
||||
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="83dp"
|
||||
android:popupBackground="@color/white"
|
||||
android:spinnerMode="dropdown"
|
||||
android:layout_centerHorizontal="true" />
|
||||
android:layout_marginTop="49dp" />
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_playStop"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:background="@drawable/button_normal"
|
||||
android:text="@string/play_stop"
|
||||
android:layout_alignTop="@+id/button_reset"
|
||||
android:textColor="@color/white"
|
||||
|
||||
android:layout_below="@+id/textView"
|
||||
android:layout_alignLeft="@+id/textView"
|
||||
android:layout_alignStart="@+id/textView" />
|
||||
android:layout_alignStart="@+id/textView"
|
||||
android:layout_marginTop="39dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_reset"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginBottom="182dp"
|
||||
android:textColor="@color/white"
|
||||
android:background="@drawable/button_normal"
|
||||
android:text="@string/reset"
|
||||
android:layout_toRightOf="@+id/button_playStop"
|
||||
android:textColor="@color/white"
|
||||
android:layout_alignTop="@+id/button_playStop"
|
||||
android:layout_alignRight="@+id/textView"
|
||||
android:layout_alignEnd="@+id/textView" />
|
||||
|
||||
|
||||
<!--
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:shape="ring">
|
||||
<stroke android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:width="2dp"
|
||||
android:color="@color/black" />
|
||||
|
||||
</shape>
|
||||
-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@drawable/circle"
|
||||
android:clickable="true"
|
||||
android:enabled="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/break_reminder_time"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textIsSelectable="false"
|
||||
android:textSize="60sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_above="@+id/button_reset"
|
||||
android:layout_centerHorizontal="true" />
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@
|
|||
<string name="pref_header_general">General</string>
|
||||
<string name="pref_title_display_name">Profile name</string>
|
||||
<string name="pref_default_display_name">Pomodoro</string>
|
||||
|
||||
<string name="pref_current_profile">Select profile</string>
|
||||
<string name="pref_default_profile">Sport</string>
|
||||
|
||||
<!-- settings for Notifications -->
|
||||
<string name="pref_header_notifications">Notifications</string>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,24 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
|
||||
<orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder.DynamicListPreference
|
||||
android:defaultValue="@string/pref_current_profile"
|
||||
android:key="current_profile"
|
||||
android:title="@string/pref_current_profile" />
|
||||
|
||||
<!-- NOTE: EditTextPreference accepts EditText attributes. -->
|
||||
<!-- NOTE: EditTextPreference's summary should be set to its value by the activity code. -->
|
||||
|
||||
<EditTextPreference
|
||||
android:capitalize="words"
|
||||
android:defaultValue="@string/pref_default_display_name"
|
||||
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
android:inputType="textCapWords"
|
||||
android:key="name_text"
|
||||
android:maxLength="9"
|
||||
android:maxLines="1"
|
||||
android:selectAllOnFocus="true"
|
||||
android:singleLine="true"
|
||||
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
android:maxLength="9"
|
||||
android:title="@string/pref_title_display_name" />
|
||||
|
||||
|
||||
|
|
@ -34,4 +40,5 @@
|
|||
android:text="@string/settings_unit"
|
||||
android:title="@string/settings_break_title" />
|
||||
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
|
|
@ -24,10 +24,6 @@
|
|||
android:key="notifications_new_message_vibrate"
|
||||
android:title="@string/pref_title_vibrate" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="notifications_stayOn"
|
||||
android:title="@string/pref_title_stayOn" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
|
|
@ -35,4 +31,10 @@
|
|||
android:key="notifications_new_message_timeLeft"
|
||||
android:title="@string/pref_title_timeLeft" />
|
||||
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="notifications_stayOn"
|
||||
android:title="@string/pref_title_stayOn" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue