Reformat code

pull/30/head
Alinson S. Xavier 10 years ago
parent 1ee3fc79f0
commit c8de4e13f9

@ -108,22 +108,17 @@ public class DateHelper
} }
else else
{ {
if(days == 0) if (days == 0) s.append("Today");
s.append("Today"); else if (days == 1 && negative) s.append("Yesterday");
else if(days == 1 && negative) else if (days == 1 && !negative) s.append("Tomorrow");
s.append("Yesterday");
else if(days == 1 && !negative)
s.append("Tomorrow");
else else
{ {
if(negative) if (negative) s.append("past ");
s.append("past ");
s.append(new SimpleDateFormat("EEEE").format(to)); s.append(new SimpleDateFormat("EEEE").format(to));
} }
} }
if(negative && days > 6) if (negative && days > 6) s.append(" ago");
s.append(" ago");
return s.toString(); return s.toString();
} }

@ -50,8 +50,8 @@ public abstract class DialogHelper
public static void showSoftKeyboard(View view) public static void showSoftKeyboard(View view)
{ {
InputMethodManager imm = (InputMethodManager) InputMethodManager imm = (InputMethodManager) view.getContext()
view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); .getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
} }
} }

@ -81,8 +81,7 @@ abstract public class ReplayableActivity extends Activity
toast.show(); toast.show();
} }
public void executeCommand(final Command command, Boolean clearRedoStack, public void executeCommand(final Command command, Boolean clearRedoStack, final Long refreshKey)
final Long refreshKey)
{ {
undoList.push(command); undoList.push(command);

@ -16,7 +16,6 @@
package org.isoron.uhabits; package org.isoron.uhabits;
import android.app.Activity;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
@ -31,7 +30,7 @@ public class IntroActivity extends AppIntro2
showStatusBar(false); showStatusBar(false);
addSlide(AppIntroFragment.newInstance("Welcome", addSlide(AppIntroFragment.newInstance("Welcome",
"Habits Tracker helps you create and maintain good habits.", R.drawable.tutorial_1, "Loop helps you create and maintain good habits.", R.drawable.tutorial_1,
Color.parseColor("#194673"))); Color.parseColor("#194673")));
addSlide(AppIntroFragment.newInstance("Create some new habits", addSlide(AppIntroFragment.newInstance("Create some new habits",

@ -41,8 +41,8 @@ public class MainActivity extends ReplayableActivity
PreferenceManager.setDefaultValues(this, R.xml.preferences, false); PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
listHabitsFragment = (ListHabitsFragment) getFragmentManager().findFragmentById( listHabitsFragment =
R.id.fragment1); (ListHabitsFragment) getFragmentManager().findFragmentById(R.id.fragment1);
ReminderHelper.createReminderAlarms(MainActivity.this); ReminderHelper.createReminderAlarms(MainActivity.this);

@ -62,9 +62,9 @@ public class ReminderHelper
alarmIntent.setAction(ReminderAlarmReceiver.ACTION_REMIND); alarmIntent.setAction(ReminderAlarmReceiver.ACTION_REMIND);
alarmIntent.setData(uri); alarmIntent.setData(uri);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, PendingIntent pendingIntent =
((int) (habit.getId() % Integer.MAX_VALUE)) + 1, alarmIntent, PendingIntent.getBroadcast(context, ((int) (habit.getId() % Integer.MAX_VALUE)) + 1,
PendingIntent.FLAG_UPDATE_CURRENT); alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= 19) if (Build.VERSION.SDK_INT >= 19)

@ -27,7 +27,8 @@ public class SettingsActivity extends Activity
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, getFragmentManager().beginTransaction()
new SettingsFragment()).commit(); .replace(android.R.id.content, new SettingsFragment())
.commit();
} }
} }

@ -16,10 +16,6 @@
package org.isoron.uhabits; package org.isoron.uhabits;
import org.isoron.helpers.ReplayableActivity;
import org.isoron.uhabits.models.Habit;
import android.app.Activity;
import android.content.ContentUris; import android.content.ContentUris;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
@ -28,6 +24,9 @@ import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import org.isoron.helpers.ReplayableActivity;
import org.isoron.uhabits.models.Habit;
public class ShowHabitActivity extends ReplayableActivity public class ShowHabitActivity extends ReplayableActivity
{ {

@ -23,7 +23,6 @@ import android.graphics.ColorMatrix;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -45,9 +44,6 @@ import org.isoron.helpers.DialogHelper.OnSavedListener;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit; import org.isoron.uhabits.models.Habit;
import java.util.Date;
import java.util.TimeZone;
public class EditHabitFragment extends DialogFragment implements OnClickListener public class EditHabitFragment extends DialogFragment implements OnClickListener
{ {
private int mode; private int mode;
@ -67,8 +63,8 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
public SolidColorMatrix(int color) public SolidColorMatrix(int color)
{ {
float matrix[] = {0.0f, 0.0f, 0.0f, 0.0f, Color.red(color), 0.0f, 0.0f, 0.0f, 0.0f, float matrix[] = {0.0f, 0.0f, 0.0f, 0.0f, Color.red(color), 0.0f, 0.0f, 0.0f, 0.0f,
Color.green(color), 0.0f, 0.0f, 0.0f, 0.0f, Color.blue(color), 0.0f, 0.0f, Color.green(color), 0.0f, 0.0f, 0.0f, 0.0f, Color.blue(color), 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0 }; 1.0f, 0};
set(matrix); set(matrix);
} }
} }
@ -160,9 +156,10 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
{ {
public void onClick(View view) public void onClick(View view)
{ {
ColorPickerDialog picker = ColorPickerDialog.newInstance( ColorPickerDialog picker =
R.string.color_picker_default_title, ColorPickerDialog.newInstance(R.string.color_picker_default_title,
ColorHelper.palette, modified_habit.color, 4, ColorPickerDialog.SIZE_SMALL); ColorHelper.palette, modified_habit.color, 4,
ColorPickerDialog.SIZE_SMALL);
picker.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() picker.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener()
{ {
@ -193,8 +190,9 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
if (modified_habit.reminder_hour != null) if (modified_habit.reminder_hour != null)
{ {
tvInputReminder.setTextColor(Color.BLACK); tvInputReminder.setTextColor(Color.BLACK);
tvInputReminder.setText(DateHelper.formatTime(getActivity(), tvInputReminder.setText(
modified_habit.reminder_hour, modified_habit.reminder_min)); DateHelper.formatTime(getActivity(), modified_habit.reminder_hour,
modified_habit.reminder_min));
} }
else else
{ {
@ -223,7 +221,8 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
int default_hour = 8; int default_hour = 8;
int default_min = 0; int default_min = 0;
if(modified_habit.reminder_hour != null) { if (modified_habit.reminder_hour != null)
{
default_hour = modified_habit.reminder_hour; default_hour = modified_habit.reminder_hour;
default_min = modified_habit.reminder_min; default_min = modified_habit.reminder_min;
} }
@ -280,8 +279,7 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
valid = false; valid = false;
} }
if(!valid) if (!valid) return;
return;
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt("pref_default_habit_freq_num", modified_habit.freq_num); editor.putInt("pref_default_habit_freq_num", modified_habit.freq_num);
@ -296,11 +294,9 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
savedHabit = originalHabit; savedHabit = originalHabit;
} }
if(mode == CREATE_MODE) if (mode == CREATE_MODE) command = new Habit.CreateCommand(modified_habit);
command = new Habit.CreateCommand(modified_habit);
if(onSavedListener != null) if (onSavedListener != null) onSavedListener.onSaved(command, savedHabit);
onSavedListener.onSaved(command, savedHabit);
dismiss(); dismiss();
} }

@ -140,8 +140,8 @@ public class ListHabitsFragment extends Fragment
listView.setOnTouchListener(controller); listView.setOnTouchListener(controller);
listView.setDragEnabled(true); listView.setDragEnabled(true);
Typeface fontawesome = Typeface.createFromAsset(getActivity().getAssets(), Typeface fontawesome =
"fontawesome-webfont.ttf"); Typeface.createFromAsset(getActivity().getAssets(), "fontawesome-webfont.ttf");
((TextView) view.findViewById(R.id.tvStarEmpty)).setTypeface(fontawesome); ((TextView) view.findViewById(R.id.tvStarEmpty)).setTypeface(fontawesome);
llEmpty = view.findViewById(R.id.llEmpty); llEmpty = view.findViewById(R.id.llEmpty);
@ -192,8 +192,9 @@ public class ListHabitsFragment extends Fragment
{ {
View check = inflater.inflate(R.layout.list_habits_header_check, null); View check = inflater.inflate(R.layout.list_habits_header_check, null);
Button btCheck = (Button) check.findViewById(R.id.tvCheck); Button btCheck = (Button) check.findViewById(R.id.tvCheck);
btCheck.setText(day.getDisplayName(GregorianCalendar.DAY_OF_WEEK, btCheck.setText(
GregorianCalendar.SHORT, Locale.US) + "\n" + day.getDisplayName(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.SHORT,
Locale.US) + "\n" +
Integer.toString(day.get(GregorianCalendar.DAY_OF_MONTH))); Integer.toString(day.get(GregorianCalendar.DAY_OF_MONTH)));
llButtonsHeader.addView(check); llButtonsHeader.addView(check);
@ -353,10 +354,8 @@ public class ListHabitsFragment extends Fragment
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
final Habit habit = habits.get(info.id); final Habit habit = habits.get(info.id);
if(habit.isArchived()) if (habit.isArchived()) menu.findItem(R.id.action_archive_habit).setVisible(false);
menu.findItem(R.id.action_archive_habit).setVisible(false); else menu.findItem(R.id.action_unarchive_habit).setVisible(false);
else
menu.findItem(R.id.action_unarchive_habit).setVisible(false);
} }
@Override @Override
@ -436,10 +435,8 @@ public class ListHabitsFragment extends Fragment
private void updateEmptyMessage() private void updateEmptyMessage()
{ {
if(lastLoadedTimestamp == null) if (lastLoadedTimestamp == null) llEmpty.setVisibility(View.GONE);
llEmpty.setVisibility(View.GONE); else llEmpty.setVisibility(habits.size() > 0 ? View.GONE : View.VISIBLE);
else
llEmpty.setVisibility(habits.size() > 0 ? View.GONE : View.VISIBLE);
} }
@Override @Override
@ -453,7 +450,8 @@ public class ListHabitsFragment extends Fragment
if (!short_toggle_enabled) if (!short_toggle_enabled)
{ {
toggleCheck(v); toggleCheck(v);
Vibrator vb = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); Vibrator vb =
(Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
vb.vibrate(100); vb.vibrate(100);
} }
@ -472,10 +470,8 @@ public class ListHabitsFragment extends Fragment
long timestamp = DateHelper.getStartOfDay( long timestamp = DateHelper.getStartOfDay(
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay); DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
if(v.getTag(R.string.toggle_key).equals(2)) if (v.getTag(R.string.toggle_key).equals(2)) updateCheck(habit.color, (TextView) v, 0);
updateCheck(habit.color, (TextView) v, 0); else updateCheck(habit.color, (TextView) v, 2);
else
updateCheck(habit.color, (TextView) v, 2);
executeCommand(habit.new ToggleRepetitionCommand(timestamp), habit.getId()); executeCommand(habit.new ToggleRepetitionCommand(timestamp), habit.getId());
} }
@ -503,10 +499,8 @@ public class ListHabitsFragment extends Fragment
switch (v.getId()) switch (v.getId())
{ {
case R.id.tvCheck: case R.id.tvCheck:
if(short_toggle_enabled) if (short_toggle_enabled) toggleCheck(v);
toggleCheck(v); else activity.showToast(R.string.long_press_to_toggle);
else
activity.showToast(R.string.long_press_to_toggle);
return; return;
} }
} }
@ -548,14 +542,14 @@ public class ListHabitsFragment extends Fragment
{ {
final Habit habit = positionToHabit.get(position); final Habit habit = positionToHabit.get(position);
if (view == null || (Long) view.getTag(R.id.KEY_TIMESTAMP) != if (view == null ||
DateHelper.getStartOfToday()) (Long) view.getTag(R.id.KEY_TIMESTAMP) != DateHelper.getStartOfToday())
{ {
view = inflater.inflate(R.layout.list_habits_item, null); view = inflater.inflate(R.layout.list_habits_item, null);
((TextView) view.findViewById(R.id.tvStar)).setTypeface(fontawesome); ((TextView) view.findViewById(R.id.tvStar)).setTypeface(fontawesome);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(tvNameWidth, LinearLayout.LayoutParams params =
LayoutParams.WRAP_CONTENT, 1); new LinearLayout.LayoutParams(tvNameWidth, LayoutParams.WRAP_CONTENT, 1);
view.findViewById(R.id.tvName).setLayoutParams(params); view.findViewById(R.id.tvName).setLayoutParams(params);
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)) Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))

@ -23,7 +23,8 @@ import android.preference.PreferenceFragment;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener public class SettingsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener
{ {
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)

@ -80,9 +80,9 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
tvStreaks.setTextColor(habit.color); tvStreaks.setTextColor(habit.color);
LinearLayout llOverview = (LinearLayout) view.findViewById(R.id.llOverview); LinearLayout llOverview = (LinearLayout) view.findViewById(R.id.llOverview);
llOverview.addView(new RingView(activity, (int) activity.getResources().getDimension( llOverview.addView(new RingView(activity,
R.dimen.small_square_size) * 4, habit.color, (int) activity.getResources().getDimension(R.dimen.small_square_size) * 4,
((float) habit.getScore() / Habit.MAX_SCORE), "Habit strength")); habit.color, ((float) habit.getScore() / Habit.MAX_SCORE), "Habit strength"));
LinearLayout llStrength = (LinearLayout) view.findViewById(R.id.llStrength); LinearLayout llStrength = (LinearLayout) view.findViewById(R.id.llStrength);
llStrength.addView(new HabitScoreView(activity, habit, llStrength.addView(new HabitScoreView(activity, habit,

@ -121,10 +121,8 @@ public class Habit extends Model
protected static From select() protected static From select()
{ {
if(includeArchived) if (includeArchived) return new Select().from(Habit.class).orderBy("position");
return new Select().from(Habit.class).orderBy("position"); else return new Select().from(Habit.class).where("archived = 0").orderBy("position");
else
return new Select().from(Habit.class).where("archived = 0").orderBy("position");
} }
public static void setIncludeArchived(boolean includeArchived) public static void setIncludeArchived(boolean includeArchived)
@ -155,7 +153,8 @@ public class Habit extends Model
public static java.util.List<Habit> getHighlightedHabits() public static java.util.List<Habit> getHighlightedHabits()
{ {
return select().where("highlight = 1").orderBy("reminder_hour desc, reminder_min desc") return select().where("highlight = 1")
.orderBy("reminder_hour desc, reminder_min desc")
.execute(); .execute();
} }
@ -170,9 +169,11 @@ public class Habit extends Model
Habit h = Habit.getByPosition(from); Habit h = Habit.getByPosition(from);
if (to < from) new Update(Habit.class).set("position = position + 1") if (to < from) new Update(Habit.class).set("position = position + 1")
.where("position >= ? and position < ?", to, from).execute(); .where("position >= ? and position < ?", to, from)
.execute();
else new Update(Habit.class).set("position = position - 1") else new Update(Habit.class).set("position = position - 1")
.where("position > ? and position <= ?", from, to).execute(); .where("position > ? and position <= ?", from, to)
.execute();
h.position = to; h.position = to;
h.save(); h.save();
@ -193,8 +194,7 @@ public class Habit extends Model
} }
ActiveAndroid.setTransactionSuccessful(); ActiveAndroid.setTransactionSuccessful();
} } finally
finally
{ {
ActiveAndroid.endTransaction(); ActiveAndroid.endTransaction();
} }
@ -271,8 +271,10 @@ public class Habit extends Model
public void deleteReps(long timestamp) public void deleteReps(long timestamp)
{ {
new Delete().from(Repetition.class).where("habit = ?", getId()) new Delete().from(Repetition.class)
.and("timestamp = ?", timestamp).execute(); .where("habit = ?", getId())
.and("timestamp = ?", timestamp)
.execute();
} }
public void deleteCheckmarksNewerThan(long timestamp) public void deleteCheckmarksNewerThan(long timestamp)
@ -339,8 +341,7 @@ public class Habit extends Model
beginning = newestCheckmark.timestamp + day; beginning = newestCheckmark.timestamp + day;
} }
if(beginning > today) if (beginning > today) return;
return;
long beginningExtended = beginning - (long) (freq_den) * day; long beginningExtended = beginning - (long) (freq_den) * day;
List<Repetition> reps = selectRepsFromTo(beginningExtended, today).execute(); List<Repetition> reps = selectRepsFromTo(beginningExtended, today).execute();
@ -382,8 +383,7 @@ public class Habit extends Model
} }
ActiveAndroid.setTransactionSuccessful(); ActiveAndroid.setTransactionSuccessful();
} } finally
finally
{ {
ActiveAndroid.endTransaction(); ActiveAndroid.endTransaction();
} }
@ -419,10 +419,7 @@ public class Habit extends Model
public Repetition getOldestRepNewerThan(long timestamp) public Repetition getOldestRepNewerThan(long timestamp)
{ {
return selectReps() return selectReps().where("timestamp > ?", timestamp).limit(1).executeSingle();
.where("timestamp > ?", timestamp)
.limit(1)
.executeSingle();
} }
public void toggleRepetition(long timestamp) public void toggleRepetition(long timestamp)
@ -471,13 +468,18 @@ public class Habit extends Model
public Score getNewestScore() public Score getNewestScore()
{ {
return new Select().from(Score.class).where("habit = ?", getId()).orderBy("timestamp desc") return new Select().from(Score.class)
.limit(1).executeSingle(); .where("habit = ?", getId())
.orderBy("timestamp desc")
.limit(1)
.executeSingle();
} }
public void deleteScoresNewerThan(long timestamp) public void deleteScoresNewerThan(long timestamp)
{ {
new Delete().from(Score.class).where("habit = ?", getId()).and("timestamp >= ?", timestamp) new Delete().from(Score.class)
.where("habit = ?", getId())
.and("timestamp >= ?", timestamp)
.execute(); .execute();
} }
@ -533,8 +535,7 @@ public class Habit extends Model
} }
ActiveAndroid.setTransactionSuccessful(); ActiveAndroid.setTransactionSuccessful();
} } finally
finally
{ {
ActiveAndroid.endTransaction(); ActiveAndroid.endTransaction();
} }
@ -549,17 +550,18 @@ public class Habit extends Model
public List<Score> getScores(long fromTimestamp, long toTimestamp, int divisor, long offset) public List<Score> getScores(long fromTimestamp, long toTimestamp, int divisor, long offset)
{ {
return new Select().from(Score.class).where("habit = ? and timestamp > ? and " + return new Select().from(Score.class)
"timestamp <= ? and (timestamp - ?) % ? = 0", getId(), fromTimestamp, toTimestamp, .where("habit = ? and timestamp > ? and " +
offset, divisor).execute(); "timestamp <= ? and (timestamp - ?) % ? = 0", getId(), fromTimestamp,
toTimestamp, offset, divisor)
.execute();
} }
public List<Streak> getStreaks() public List<Streak> getStreaks()
{ {
updateStreaks(); updateStreaks();
return new Select() return new Select().from(Streak.class)
.from(Streak.class)
.where("habit = ?", getId()) .where("habit = ?", getId())
.orderBy("end asc") .orderBy("end asc")
.execute(); .execute();
@ -567,8 +569,7 @@ public class Habit extends Model
public Streak getNewestStreak() public Streak getNewestStreak()
{ {
return new Select() return new Select().from(Streak.class)
.from(Streak.class)
.where("habit = ?", getId()) .where("habit = ?", getId())
.orderBy("end desc") .orderBy("end desc")
.limit(1) .limit(1)
@ -614,8 +615,7 @@ public class Habit extends Model
if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current - day); if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current - day);
} }
if(list.size() % 2 == 1) if (list.size() % 2 == 1) list.add(current);
list.add(current);
ActiveAndroid.beginTransaction(); ActiveAndroid.beginTransaction();
@ -632,8 +632,7 @@ public class Habit extends Model
} }
ActiveAndroid.setTransactionSuccessful(); ActiveAndroid.setTransactionSuccessful();
} } finally
finally
{ {
ActiveAndroid.endTransaction(); ActiveAndroid.endTransaction();
} }
@ -657,7 +656,8 @@ public class Habit extends Model
{ {
savedHabit.save(); savedHabit.save();
savedId = savedHabit.getId(); savedId = savedHabit.getId();
} else }
else
{ {
savedHabit.save(savedId); savedHabit.save(savedId);
} }

@ -21,7 +21,8 @@ import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table; import com.activeandroid.annotation.Table;
@Table(name = "Repetitions") @Table(name = "Repetitions")
public class Repetition extends Model { public class Repetition extends Model
{
@Column(name = "habit") @Column(name = "habit")
public Habit habit; public Habit habit;

@ -29,13 +29,11 @@ import android.view.View;
import org.isoron.helpers.ColorHelper; import org.isoron.helpers.ColorHelper;
import org.isoron.helpers.DateHelper; import org.isoron.helpers.DateHelper;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Checkmark;
import org.isoron.uhabits.models.Habit; import org.isoron.uhabits.models.Habit;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List;
public class HabitHistoryView extends View public class HabitHistoryView extends View
{ {
@ -160,12 +158,14 @@ public class HabitHistoryView extends View
pTextHeader); pTextHeader);
previousMonth = month; previousMonth = month;
justPrintedYear = false; justPrintedYear = false;
} else if (!year.equals(previousYear)) }
else if (!year.equals(previousYear))
{ {
canvas.drawText(year, square.left, square.bottom - headerTextOffset, pTextHeader); canvas.drawText(year, square.left, square.bottom - headerTextOffset, pTextHeader);
previousYear = year; previousYear = year;
justPrintedYear = true; justPrintedYear = true;
} else }
else
{ {
justPrintedYear = false; justPrintedYear = false;
} }
@ -247,7 +247,6 @@ public class HabitHistoryView extends View
invalidate(); invalidate();
return true; return true;
} }
else else return false;
return false;
} }
} }

@ -98,8 +98,8 @@ public class HabitScoreView extends View
for (int i = 0; i < nColumns * BUCKET_SIZE; i++) for (int i = 0; i < nColumns * BUCKET_SIZE; i++)
fromTimestamp -= DateHelper.millisecondsInOneDay; fromTimestamp -= DateHelper.millisecondsInOneDay;
scores = habit.getScores(fromTimestamp, toTimestamp, BUCKET_SIZE * DateHelper.millisecondsInOneDay, scores = habit.getScores(fromTimestamp, toTimestamp,
toTimestamp); BUCKET_SIZE * DateHelper.millisecondsInOneDay, toTimestamp);
} }
@Override @Override
@ -167,7 +167,8 @@ public class HabitScoreView extends View
if (!month.equals(previousMonth)) if (!month.equals(previousMonth))
{ {
canvas.drawText(month, r.centerX(), r.bottom + lineHeight * 1.2f, pText); canvas.drawText(month, r.centerX(), r.bottom + lineHeight * 1.2f, pText);
} else }
else
{ {
canvas.drawText(day, r.centerX(), r.bottom + lineHeight * 1.2f, pText); canvas.drawText(day, r.centerX(), r.bottom + lineHeight * 1.2f, pText);
} }
@ -263,6 +264,7 @@ public class HabitScoreView extends View
fetchScores(); fetchScores();
invalidate(); invalidate();
return true; return true;
} else return false; }
else return false;
} }
} }

@ -26,7 +26,6 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import org.isoron.helpers.ColorHelper; import org.isoron.helpers.ColorHelper;
import org.isoron.helpers.DateHelper;
import org.isoron.uhabits.models.Habit; import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.Streak; import org.isoron.uhabits.models.Streak;
@ -182,7 +181,6 @@ public class HabitStreakView extends View
invalidate(); invalidate();
return true; return true;
} }
else else return false;
return false;
} }
} }

@ -75,7 +75,8 @@ public class RingView extends View
pRing.setColor(Color.GRAY); pRing.setColor(Color.GRAY);
pRing.setTextSize(size * 0.2f); pRing.setTextSize(size * 0.2f);
lineHeight = pRing.getFontSpacing(); lineHeight = pRing.getFontSpacing();
canvas.drawText(String.format("%.0f%%", perc * 100), r.centerX(), r.centerY()+lineHeight/3, pRing); canvas.drawText(String.format("%.0f%%", perc * 100), r.centerX(),
r.centerY() + lineHeight / 3, pRing);
pRing.setTextSize(size * 0.15f); pRing.setTextSize(size * 0.15f);
canvas.drawText(label, size / 2, size + lineHeight * 1.2f, pRing); canvas.drawText(label, size / 2, size + lineHeight * 1.2f, pRing);

Loading…
Cancel
Save