mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 17:48:52 -06:00
Implement settings screen
This commit is contained in:
@@ -3,6 +3,7 @@ package org.isoron.uhabits;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
@@ -22,6 +23,8 @@ public class MainActivity extends ReplayableActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.list_habits_activity);
|
||||
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
|
||||
listHabitsFragment = (ListHabitsFragment) getFragmentManager().findFragmentById(
|
||||
R.id.fragment1);
|
||||
|
||||
@@ -45,9 +48,11 @@ public class MainActivity extends ReplayableActivity
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch(item.getItemId())
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.action_settings:
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
||||
@@ -8,9 +8,11 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -43,7 +45,10 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
|
||||
|
||||
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));
|
||||
ReminderHelper.createReminderAlarm(context, habit,
|
||||
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.content.ContentUris;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@@ -14,39 +15,43 @@ import android.view.MenuItem;
|
||||
public class ShowHabitActivity extends ReplayableActivity
|
||||
{
|
||||
|
||||
public Habit habit;
|
||||
public Habit habit;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Uri data = getIntent().getData();
|
||||
habit = Habit.get(ContentUris.parseId(data));
|
||||
getActionBar().setTitle(habit.name);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21)
|
||||
{
|
||||
getActionBar().setBackgroundDrawable(new ColorDrawable(habit.color));
|
||||
}
|
||||
|
||||
setContentView(R.layout.show_habit_activity);
|
||||
}
|
||||
setContentView(R.layout.show_habit_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.show_habit_activity_menu, menu);
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.show_habit_activity_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch(item.getItemId())
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.action_settings:
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
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.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Display;
|
||||
@@ -68,6 +69,7 @@ public class ListHabitsFragment extends Fragment
|
||||
private View llEmpty;
|
||||
|
||||
private OnHabitClickListener habitClickListener;
|
||||
private boolean short_toggle_enabled;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -123,6 +125,9 @@ public class ListHabitsFragment extends Fragment
|
||||
{
|
||||
super.onResume();
|
||||
updateHeader();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
short_toggle_enabled = prefs.getBoolean("pref_short_toggle", false);
|
||||
}
|
||||
|
||||
private void updateHeader()
|
||||
@@ -265,15 +270,12 @@ public class ListHabitsFragment extends Fragment
|
||||
case R.id.tvCheck:
|
||||
{
|
||||
lastLongClick = new Date().getTime();
|
||||
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));
|
||||
|
||||
Vibrator vb = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vb.vibrate(100);
|
||||
if(!short_toggle_enabled)
|
||||
{
|
||||
toggleCheck(v);
|
||||
Vibrator vb = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vb.vibrate(100);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -282,6 +284,16 @@ public class ListHabitsFragment extends Fragment
|
||||
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)
|
||||
{
|
||||
activity.executeCommand(c);
|
||||
@@ -300,7 +312,10 @@ public class ListHabitsFragment extends Fragment
|
||||
switch(v.getId())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user