Minor appearance tweaks - updated tab icons, made the date utilities better

pull/14/head
Tim Su 14 years ago
parent d3e33d0d8b
commit 807b8ffa9f

@ -25,6 +25,9 @@ public class DateUtilities {
@Autowired
public Integer monthsResource;
@Autowired
public Integer weeksResource;
@Autowired
public Integer daysResource;
@ -77,10 +80,10 @@ public class DateUtilities {
}
/** Represents a single day */
public static long ONE_DAY = 3600000L;
public static long ONE_DAY = 24 * 3600000L;
/** Represents a single week */
public static long ONE_WEEK = 7 * 3600000L;
public static long ONE_WEEK = 7 * ONE_DAY;
/* ======================================================================
* =========================================================== formatters
@ -193,35 +196,67 @@ public class DateUtilities {
*/
public String getDurationString(long duration, int unitsToShow, boolean withPreposition) {
Resources r = ContextManager.getContext().getResources();
int years, months, days, hours, minutes, seconds;
short unitsDisplayed = 0;
duration = Math.abs(duration);
if(duration == 0)
return r.getQuantityString(secondsResource, 0, 0);
Date now = new Date();
Date then = new Date(DateUtilities.now() + duration);
Date now = new Date(80, 1, 1);
Date then = new Date(now.getTime() + duration);
int[] values = new int[] {
then.getYear() - now.getYear(),
then.getMonth() - now.getMonth(),
(then.getDate() - now.getDate())/7,
(then.getDate() - now.getDate()) - (then.getDate() - now.getDate())/7*7,
then.getHours() - now.getHours(),
then.getMinutes() - now.getMinutes(),
then.getSeconds() - now.getSeconds(),
};
int[] maxValues = new int[] {
Integer.MAX_VALUE,
12,
5,
7,
24,
60,
60
};
// perform rounding (this is definitely magic... trust the unit tests)
int cursor = 0;
while(values[cursor] == 0 && ++cursor < values.length)
;
int postCursor = cursor + unitsToShow;
for(int i = values.length - 1; i >= postCursor; i--) {
if(values[i] >= maxValues[i]/2) {
values[i-1]++;
}
}
for(int i = Math.min(values.length, postCursor) - 1; i >= 1; i--) {
if(values[i] == maxValues[i]) {
values[i-1]++;
for(int j = i; j < values.length; j++)
values[j] = 0;
}
}
years = then.getYear() - now.getYear();
months = then.getMonth() - now.getMonth();
days = then.getDate() - now.getDate();
hours = then.getHours() - now.getHours();
minutes = then.getMinutes() - now.getMinutes();
seconds = then.getSeconds() - now.getSeconds();
StringBuilder result = new StringBuilder();
unitsDisplayed = displayUnits(r, yearsResource, unitsToShow, years, months >= 6,
unitsDisplayed = displayUnits(r, yearsResource, unitsToShow, values[0],
unitsDisplayed, result);
unitsDisplayed = displayUnits(r, monthsResource, unitsToShow, values[1],
unitsDisplayed, result);
unitsDisplayed = displayUnits(r, monthsResource, unitsToShow, months, days >= 15,
unitsDisplayed = displayUnits(r, weeksResource, unitsToShow, values[2],
unitsDisplayed, result);
unitsDisplayed = displayUnits(r, daysResource, unitsToShow, days, hours >= 12,
unitsDisplayed = displayUnits(r, daysResource, unitsToShow, values[3],
unitsDisplayed, result);
unitsDisplayed = displayUnits(r, hoursResource, unitsToShow, hours, minutes >= 30,
unitsDisplayed = displayUnits(r, hoursResource, unitsToShow, values[4],
unitsDisplayed, result);
unitsDisplayed = displayUnits(r, minutesResource, unitsToShow, minutes, seconds >= 30,
unitsDisplayed = displayUnits(r, minutesResource, unitsToShow, values[5],
unitsDisplayed, result);
unitsDisplayed = displayUnits(r, secondsResource, unitsToShow, seconds, false,
unitsDisplayed = displayUnits(r, secondsResource, unitsToShow, values[6],
unitsDisplayed, result);
return result.toString().trim();
@ -229,11 +264,8 @@ public class DateUtilities {
/** Display units, rounding up if necessary. Returns units to show */
private short displayUnits(Resources r, int resource, int unitsToShow, int value,
boolean shouldRound, short unitsDisplayed, StringBuilder result) {
short unitsDisplayed, StringBuilder result) {
if(unitsDisplayed < unitsToShow && value > 0) {
// round up if needed
if(unitsDisplayed + 1 == unitsToShow && shouldRound)
value++;
result.append(r.getQuantityString(resource, value, value)).
append(' ');
unitsDisplayed++;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

@ -85,12 +85,20 @@
android:autoText="true"
android:capitalize="sentences"
android:singleLine="false" />
<!-- separator -->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:padding="5dip"
android:background="@android:drawable/divider_horizontal_dark" />
<!-- buttons -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:paddingTop="5dip"
android:baselineAligned="false">
<Button
@ -209,12 +217,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- separator -->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:padding="5dip"
android:background="@android:drawable/divider_horizontal_dark" />
<!-- buttons -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:paddingTop="5dip"
android:baselineAligned="false">
<Button
@ -252,6 +268,11 @@
android:layout_height="fill_parent">
<!-- calendar integration -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/TEA_calendar_label"
style="@style/TextAppearance.GEN_EditLabel" />
<CheckBox
android:id="@+id/add_to_calendar"
android:layout_width="fill_parent"
@ -291,11 +312,19 @@
android:id="@+id/elapsedDuration"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<!-- separator -->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:padding="5dip"
android:background="@android:drawable/divider_horizontal_dark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:paddingTop="5dip"
android:baselineAligned="false">
<Button

@ -30,6 +30,11 @@
<item quantity="one">1 Month</item>
<item quantity="other">%d Months</item>
</plurals>
<plurals name="DUt_weeks">
<!-- plurals: days -->
<item quantity="one">1 Week</item>
<item quantity="other">%d Weeks</item>
</plurals>
<plurals name="DUt_days">
<!-- plurals: days -->
<item quantity="one">1 Day</item>
@ -267,7 +272,10 @@ to the plugin creator for fastest service.
<string name="TEA_elapsedDuration_label">Time Already Spent on Task</string>
<!-- Label for adding task to calendar -->
<string name="TEA_addToCalendar_label">Add Task To Calendar</string>
<string name="TEA_calendar_label">Calendar Integration:</string>
<!-- Label for adding task to calendar -->
<string name="TEA_addToCalendar_label">Create Calendar Event</string>
<!-- Label when calendar event already exists -->
<string name="TEA_showCalendar_label">Open Calendar Event</string>

@ -37,6 +37,7 @@ import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
@ -966,8 +967,7 @@ public final class TaskEditActivity extends TabActivity {
public class ReminderControlSet implements TaskEditControlSet {
private final CheckBox during, after, random;
private final Spinner mode;
private final long periodic = Preferences.getIntegerFromString(R.string.p_notif_defaultRemind)
* DateUtilities.ONE_DAY;
private long periodic;
public ReminderControlSet(int duringId, int afterId, int randomId, int modeId) {
during = (CheckBox)findViewById(duringId);
@ -975,8 +975,9 @@ public final class TaskEditActivity extends TabActivity {
random = (CheckBox)findViewById(randomId);
mode = (Spinner)findViewById(modeId);
random.setText(getString(R.string.TEA_reminder_random,
dateUtilities.getDurationString(periodic, 1, true)));
periodic = Preferences.getIntegerFromString(R.string.p_notif_defaultRemind)
* DateUtilities.ONE_DAY;
updatePeriodicString();
String[] list = new String[] {
getString(R.string.TEA_reminder_alarm_off),
@ -988,6 +989,15 @@ public final class TaskEditActivity extends TabActivity {
mode.setAdapter(adapter);
}
@SuppressWarnings("nls")
private void updatePeriodicString() {
if(periodic == 0)
periodic = DateUtilities.ONE_WEEK;
String dateString = "<a href='#'>" + dateUtilities.getDurationString(periodic, 1, true) + "</a>";
random.setText(Html.fromHtml(getString(R.string.TEA_reminder_random,
dateString)));
}
public void setValue(int flags) {
during.setChecked((flags & Task.NOTIFY_AT_DEADLINE) > 0);
after.setChecked((flags &
@ -1010,6 +1020,11 @@ public final class TaskEditActivity extends TabActivity {
@Override
public void readFromModel() {
setValue(model.getValue(Task.NOTIFICATION_FLAGS));
periodic = model.getValue(Task.NOTIFICATIONS);
if(periodic > 0) {
random.setChecked(true);
updatePeriodicString();
}
}
@Override

@ -73,6 +73,7 @@ public class AstridDependencyInjector implements AbstractDependencyInjector {
injectables.put("dateUtilities", DateUtilities.class);
injectables.put("yearsResource", R.plurals.DUt_years);
injectables.put("monthsResource", R.plurals.DUt_months);
injectables.put("weeksResource", R.plurals.DUt_weeks);
injectables.put("daysResource", R.plurals.DUt_days);
injectables.put("hoursResource", R.plurals.DUt_hours);
injectables.put("minutesResource", R.plurals.DUt_minutes);

@ -19,12 +19,12 @@ import com.timsu.astrid.appwidget.AstridAppWidgetProvider.UpdateService;
import com.timsu.astrid.sync.SynchronizationService;
import com.timsu.astrid.utilities.BackupService;
import com.timsu.astrid.utilities.Notifications;
import com.timsu.astrid.utilities.Preferences;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.service.ExceptionService.TodorooUncaughtExceptionHandler;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Preferences;
/**
* Service which handles jobs that need to be run when user's phone or Astrid
@ -73,7 +73,7 @@ public class StartupService extends BroadcastReceiver {
ContextManager.setContext(context);
// read current version
int latestSetVersion = Preferences.getCurrentVersion(context);
int latestSetVersion = Preferences.getCurrentVersion();
int version = 0;
try {
PackageManager pm = context.getPackageManager();
@ -87,7 +87,7 @@ public class StartupService extends BroadcastReceiver {
boolean justUpgraded = latestSetVersion != version;
if(justUpgraded) {
upgradeService.performUpgrade(latestSetVersion);
Preferences.setCurrentVersion(context, version);
Preferences.setCurrentVersion(version);
}
// perform startup activities in a background thread
@ -113,7 +113,7 @@ public class StartupService extends BroadcastReceiver {
}
}).start();
Preferences.setPreferenceDefaults(context);
Preferences.setPreferenceDefaults();
// check for task killers
if(!Constants.OEM)
@ -122,8 +122,10 @@ public class StartupService extends BroadcastReceiver {
hasStartedUp = true;
}
private static final String P_TASK_KILLER_HELP = "taskkiller"; //$NON-NLS-1$
private static void showTaskKillerHelp(final Context context) {
if(!Preferences.shouldShowTaskKillerHelp(context))
if(!Preferences.getBoolean(P_TASK_KILLER_HELP, false))
return;
// search for task killers. if they exist, show the help!
@ -142,7 +144,7 @@ public class StartupService extends BroadcastReceiver {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
Preferences.disableTaskKillerHelp(context);
Preferences.setBoolean(P_TASK_KILLER_HELP, true);
}
};

@ -13,7 +13,6 @@ import com.todoroo.astrid.model.Task;
public class Preferences {
private static final String P_CURRENT_VERSION = "cv"; //$NON-NLS-1$
private static final String P_READ_INTRODUCTION = "ri"; //$NON-NLS-1$
/** Set preference defaults, if unset. called at startup */
public static void setPreferenceDefaults() {
@ -52,20 +51,6 @@ public class Preferences {
editor.commit();
}
/** ReadIntroduction: whether the user has read the introductory notes */
public static boolean hasReadIntroduction() {
Context context = ContextManager.getContext();
return getPrefs(context).getBoolean(P_READ_INTRODUCTION, false);
}
/** ReadIntroduction: whether the user has read the introductory notes */
public static void setReadIntroduction(boolean value) {
Context context = ContextManager.getContext();
Editor editor = getPrefs(context).edit();
editor.putBoolean(P_READ_INTRODUCTION, value);
editor.commit();
}
/* ======================================================================
* ======================================================= helper methods
* ====================================================================== */
@ -124,7 +109,6 @@ public class Preferences {
/** Gets an integer value from a string preference. Returns null
* if the value is not set or not an integer.
*
* @param context
* @param keyResource resource from string.xml
* @return integer value, or null on error
*/
@ -145,7 +129,6 @@ public class Preferences {
/** Gets an float value from a string preference. Returns null
* if the value is not set or not an flat.
*
* @param context
* @param keyResource resource from string.xml
* @return
*/
@ -163,7 +146,6 @@ public class Preferences {
/** Gets a boolean preference (e.g. a CheckBoxPreference setting)
*
* @param context
* @param key
* @param defValue
* @return default if value is unset otherwise the value
@ -172,4 +154,26 @@ public class Preferences {
Context context = ContextManager.getContext();
return getPrefs(context).getBoolean(key, defValue);
}
/** Gets a boolean preference (e.g. a CheckBoxPreference setting)
*
* @param keyResource
* @param defValue
* @return default if value is unset otherwise the value
*/
public static boolean getBoolean(int keyResources, boolean defValue) {
return getBoolean(ContextManager.getString(keyResources), defValue);
}
/**
* Sets boolean preference
* @param key
* @param value
*/
public static void setBoolean(String key, boolean value) {
Context context = ContextManager.getContext();
Editor editor = getPrefs(context).edit();
editor.putBoolean(key, value);
editor.commit();
}
}

Loading…
Cancel
Save