mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Implement settings screen
This commit is contained in:
@@ -41,6 +41,15 @@
|
|||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value="org.isoron.uhabits.MainActivity"/>
|
android:value="org.isoron.uhabits.MainActivity"/>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".SettingsActivity"
|
||||||
|
android:label="Settings"
|
||||||
|
android:parentActivityName=".MainActivity">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value="org.isoron.uhabits.MainActivity"/>
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.isoron.uhabits;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@ public class MainActivity extends ReplayableActivity
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.list_habits_activity);
|
setContentView(R.layout.list_habits_activity);
|
||||||
|
|
||||||
|
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||||
|
|
||||||
listHabitsFragment = (ListHabitsFragment) getFragmentManager().findFragmentById(
|
listHabitsFragment = (ListHabitsFragment) getFragmentManager().findFragmentById(
|
||||||
R.id.fragment1);
|
R.id.fragment1);
|
||||||
|
|
||||||
@@ -45,9 +48,11 @@ public class MainActivity extends ReplayableActivity
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
switch(item.getItemId())
|
switch (item.getItemId())
|
||||||
{
|
{
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
|
Intent intent = new Intent(this, SettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -43,7 +45,10 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
|
|||||||
|
|
||||||
private void snoozeHabit(Context context, Uri data)
|
private void snoozeHabit(Context context, Uri data)
|
||||||
{
|
{
|
||||||
int delayMinutes = 60;
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
long delayMinutes = Long.parseLong(prefs.getString("pref_snooze_interval", "15"));
|
||||||
|
|
||||||
Habit habit = Habit.get(ContentUris.parseId(data));
|
Habit habit = Habit.get(ContentUris.parseId(data));
|
||||||
ReminderHelper.createReminderAlarm(context, habit,
|
ReminderHelper.createReminderAlarm(context, habit,
|
||||||
new Date().getTime() + delayMinutes * 60 * 1000);
|
new Date().getTime() + delayMinutes * 60 * 1000);
|
||||||
|
|||||||
17
app/src/main/java/org/isoron/uhabits/SettingsActivity.java
Normal file
17
app/src/main/java/org/isoron/uhabits/SettingsActivity.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.dialogs.SettingsFragment;
|
||||||
|
|
||||||
|
public class SettingsActivity extends Activity
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
getFragmentManager().beginTransaction().replace(android.R.id.content,
|
||||||
|
new SettingsFragment()).commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import org.isoron.uhabits.models.Habit;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -14,39 +15,43 @@ import android.view.MenuItem;
|
|||||||
public class ShowHabitActivity extends ReplayableActivity
|
public class ShowHabitActivity extends ReplayableActivity
|
||||||
{
|
{
|
||||||
|
|
||||||
public Habit habit;
|
public Habit habit;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Uri data = getIntent().getData();
|
Uri data = getIntent().getData();
|
||||||
habit = Habit.get(ContentUris.parseId(data));
|
habit = Habit.get(ContentUris.parseId(data));
|
||||||
getActionBar().setTitle(habit.name);
|
getActionBar().setTitle(habit.name);
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 21)
|
if (android.os.Build.VERSION.SDK_INT >= 21)
|
||||||
|
{
|
||||||
getActionBar().setBackgroundDrawable(new ColorDrawable(habit.color));
|
getActionBar().setBackgroundDrawable(new ColorDrawable(habit.color));
|
||||||
|
}
|
||||||
|
|
||||||
setContentView(R.layout.show_habit_activity);
|
setContentView(R.layout.show_habit_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu)
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
{
|
{
|
||||||
getMenuInflater().inflate(R.menu.show_habit_activity_menu, menu);
|
getMenuInflater().inflate(R.menu.show_habit_activity_menu, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
switch(item.getItemId())
|
switch (item.getItemId())
|
||||||
{
|
{
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
|
Intent intent = new Intent(this, SettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package org.isoron.uhabits.dialogs;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
@@ -68,6 +69,7 @@ public class ListHabitsFragment extends Fragment
|
|||||||
private View llEmpty;
|
private View llEmpty;
|
||||||
|
|
||||||
private OnHabitClickListener habitClickListener;
|
private OnHabitClickListener habitClickListener;
|
||||||
|
private boolean short_toggle_enabled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
@@ -123,6 +125,9 @@ public class ListHabitsFragment extends Fragment
|
|||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
updateHeader();
|
updateHeader();
|
||||||
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
short_toggle_enabled = prefs.getBoolean("pref_short_toggle", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateHeader()
|
private void updateHeader()
|
||||||
@@ -265,15 +270,12 @@ public class ListHabitsFragment extends Fragment
|
|||||||
case R.id.tvCheck:
|
case R.id.tvCheck:
|
||||||
{
|
{
|
||||||
lastLongClick = new Date().getTime();
|
lastLongClick = new Date().getTime();
|
||||||
Habit habit = Habit.get((Long) v.getTag(R.string.habit_key));
|
if(!short_toggle_enabled)
|
||||||
int offset = (Integer) v.getTag(R.string.offset_key);
|
{
|
||||||
long timestamp = DateHelper.getStartOfDay(
|
toggleCheck(v);
|
||||||
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
|
Vibrator vb = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
vb.vibrate(100);
|
||||||
executeCommand(habit.new ToggleRepetitionCommand(timestamp));
|
}
|
||||||
|
|
||||||
Vibrator vb = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
|
||||||
vb.vibrate(100);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -282,6 +284,16 @@ public class ListHabitsFragment extends Fragment
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toggleCheck(View v)
|
||||||
|
{
|
||||||
|
Habit habit = Habit.get((Long) v.getTag(R.string.habit_key));
|
||||||
|
int offset = (Integer) v.getTag(R.string.offset_key);
|
||||||
|
long timestamp = DateHelper.getStartOfDay(
|
||||||
|
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
|
||||||
|
|
||||||
|
executeCommand(habit.new ToggleRepetitionCommand(timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
private void executeCommand(Command c)
|
private void executeCommand(Command c)
|
||||||
{
|
{
|
||||||
activity.executeCommand(c);
|
activity.executeCommand(c);
|
||||||
@@ -300,7 +312,10 @@ public class ListHabitsFragment extends Fragment
|
|||||||
switch(v.getId())
|
switch(v.getId())
|
||||||
{
|
{
|
||||||
case R.id.tvCheck:
|
case R.id.tvCheck:
|
||||||
activity.showToast(R.string.long_press_to_toggle);
|
if(short_toggle_enabled)
|
||||||
|
toggleCheck(v);
|
||||||
|
else
|
||||||
|
activity.showToast(R.string.long_press_to_toggle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.isoron.uhabits.dialogs;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
|
||||||
|
public class SettingsFragment extends PreferenceFragment
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="AppBaseTheme" parent="android:Theme.Material">
|
<style name="AppBaseTheme" parent="android:Theme.Material.Light.DarkActionBar">
|
||||||
<item name="android:textColor">#606060</item>
|
<item name="android:textColor">#606060</item>
|
||||||
<item name="android:colorPrimary">@color/primary</item>
|
<item name="android:colorPrimary">@color/primary</item>
|
||||||
<item name="android:colorPrimaryDark">@color/primary_darker</item>
|
<item name="android:colorPrimaryDark">@color/primary_darker</item>
|
||||||
@@ -9,10 +9,6 @@
|
|||||||
<item name="android:windowContentTransitions">true</item>
|
<item name="android:windowContentTransitions">true</item>
|
||||||
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
||||||
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
||||||
<item name="android:actionBarPopupTheme">@style/actionBarStyle</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="actionBarStyle" parent="android:ThemeOverlay.Material.Light">
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="MyDialogStyle" parent="android:Theme.Material.Light.Dialog">
|
<style name="MyDialogStyle" parent="android:Theme.Material.Light.Dialog">
|
||||||
|
|||||||
@@ -9,5 +9,4 @@
|
|||||||
<style name="habitsListCheckStyle" parent="habitsListCheckBasicStyle">
|
<style name="habitsListCheckStyle" parent="habitsListCheckBasicStyle">
|
||||||
<item name="android:background">@drawable/ripple_background</item>
|
<item name="android:background">@drawable/ripple_background</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -3,4 +3,24 @@
|
|||||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
<dimen name="small_square_size">20dp</dimen>
|
<dimen name="small_square_size">20dp</dimen>
|
||||||
<dimen name="check_square_size">42dp</dimen>
|
<dimen name="check_square_size">42dp</dimen>
|
||||||
|
|
||||||
|
<string-array name="snooze_interval_names">
|
||||||
|
<item>15 minutes</item>
|
||||||
|
<item>30 minutes</item>
|
||||||
|
<item>1 hour</item>
|
||||||
|
<item>2 hours</item>
|
||||||
|
<item>4 hours</item>
|
||||||
|
<item>8 hours</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="snooze_interval_values">
|
||||||
|
<item>15</item>
|
||||||
|
<item>30</item>
|
||||||
|
<item>60</item>
|
||||||
|
<item>120</item>
|
||||||
|
<item>240</item>
|
||||||
|
<item>480</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string name="snooze_interval_default">15 minutes</string>
|
||||||
</resources>
|
</resources>
|
||||||
49
app/src/main/res/xml/preferences.xml
Normal file
49
app/src/main/res/xml/preferences.xml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_key_behaviour_settings"
|
||||||
|
android:title="Behavior">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="pref_short_toggle"
|
||||||
|
android:summary="More convenient, but might cause accidental toggles."
|
||||||
|
android:title="Toggle repetitions with short press"/>
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/snooze_interval_default"
|
||||||
|
android:dialogTitle="Snooze interval"
|
||||||
|
android:entries="@array/snooze_interval_names"
|
||||||
|
android:entryValues="@array/snooze_interval_values"
|
||||||
|
android:key="pref_snooze_interval"
|
||||||
|
android:title="Snooze interval on reminders"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_key_links"
|
||||||
|
android:title="Links">
|
||||||
|
|
||||||
|
<Preference android:title="Rate this app in Google Play">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.VIEW"
|
||||||
|
android:data="market://details?id=org.isoron.uhabits"/>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<Preference android:title="Send feedback to developer">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.SENDTO"
|
||||||
|
android:data="mailto:isoron@gmail.com?subject=Feedback%20for%20Habits%20Tracker"/>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<Preference android:title="View source code at GitHub">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.VIEW"
|
||||||
|
android:data="https://github.com/iSoron/uhabits"/>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
Reference in New Issue
Block a user