Reformat code

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

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

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

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

@ -16,7 +16,6 @@
package org.isoron.uhabits;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
@ -31,7 +30,7 @@ public class IntroActivity extends AppIntro2
showStatusBar(false);
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")));
addSlide(AppIntroFragment.newInstance("Create some new habits",

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

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

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

@ -16,10 +16,6 @@
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.Intent;
import android.graphics.drawable.ColorDrawable;
@ -28,6 +24,9 @@ import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import org.isoron.helpers.ReplayableActivity;
import org.isoron.uhabits.models.Habit;
public class ShowHabitActivity extends ReplayableActivity
{

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

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

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

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

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

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

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

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

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

@ -75,7 +75,8 @@ public class RingView extends View
pRing.setColor(Color.GRAY);
pRing.setTextSize(size * 0.2f);
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);
canvas.drawText(label, size / 2, size + lineHeight * 1.2f, pRing);

Loading…
Cancel
Save