Renamed Constants => SqlConstants for disambiguity, deeper integration with addon servce

pull/14/head
Tim Su 14 years ago
parent ad4e1db7a4
commit 397f24320f

@ -1,12 +1,12 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.AND;
import static com.todoroo.andlib.sql.Constants.EXISTS;
import static com.todoroo.andlib.sql.Constants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.Constants.NOT;
import static com.todoroo.andlib.sql.Constants.OR;
import static com.todoroo.andlib.sql.Constants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.AND;
import static com.todoroo.andlib.sql.SqlConstants.EXISTS;
import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.NOT;
import static com.todoroo.andlib.sql.SqlConstants.OR;
import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public abstract class Criterion {
protected final Operator operator;

@ -1,7 +1,7 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.AS;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.AS;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public abstract class DBObject<T extends DBObject<?>> implements Cloneable {
protected String alias;

@ -1,11 +1,11 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.AND;
import static com.todoroo.andlib.sql.Constants.BETWEEN;
import static com.todoroo.andlib.sql.Constants.COMMA;
import static com.todoroo.andlib.sql.Constants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.Constants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.AND;
import static com.todoroo.andlib.sql.SqlConstants.BETWEEN;
import static com.todoroo.andlib.sql.SqlConstants.COMMA;
import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public class Field extends DBObject<Field> {

@ -1,8 +1,8 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.JOIN;
import static com.todoroo.andlib.sql.Constants.ON;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.JOIN;
import static com.todoroo.andlib.sql.SqlConstants.ON;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public class Join {
private final SqlTable joinTable;

@ -1,6 +1,6 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
import java.util.HashMap;
import java.util.Map;

@ -1,6 +1,6 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public class Order {
private final Object expression;

@ -1,15 +1,15 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.ALL;
import static com.todoroo.andlib.sql.Constants.COMMA;
import static com.todoroo.andlib.sql.Constants.FROM;
import static com.todoroo.andlib.sql.Constants.GROUP_BY;
import static com.todoroo.andlib.sql.Constants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.Constants.ORDER_BY;
import static com.todoroo.andlib.sql.Constants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.Constants.SELECT;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.Constants.WHERE;
import static com.todoroo.andlib.sql.SqlConstants.ALL;
import static com.todoroo.andlib.sql.SqlConstants.COMMA;
import static com.todoroo.andlib.sql.SqlConstants.FROM;
import static com.todoroo.andlib.sql.SqlConstants.GROUP_BY;
import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.ORDER_BY;
import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS;
import static com.todoroo.andlib.sql.SqlConstants.SELECT;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.WHERE;
import static com.todoroo.andlib.sql.SqlTable.table;
import static java.util.Arrays.asList;

@ -1,11 +1,11 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.COMMA;
import static com.todoroo.andlib.sql.Constants.GROUP_BY;
import static com.todoroo.andlib.sql.Constants.LIMIT;
import static com.todoroo.andlib.sql.Constants.ORDER_BY;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.Constants.WHERE;
import static com.todoroo.andlib.sql.SqlConstants.COMMA;
import static com.todoroo.andlib.sql.SqlConstants.GROUP_BY;
import static com.todoroo.andlib.sql.SqlConstants.LIMIT;
import static com.todoroo.andlib.sql.SqlConstants.ORDER_BY;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.WHERE;
import static java.util.Arrays.asList;
import java.util.ArrayList;

@ -1,7 +1,7 @@
package com.todoroo.andlib.sql;
@SuppressWarnings("nls")
public final class Constants {
public final class SqlConstants {
static final String SELECT = "SELECT";
static final String SPACE = " ";
static final String AS = "AS";

@ -1,6 +1,6 @@
package com.todoroo.andlib.sql;
import static com.todoroo.andlib.sql.Constants.SPACE;
import static com.todoroo.andlib.sql.SqlConstants.SPACE;
public class UnaryCriterion extends Criterion {
protected final Field expression;

@ -4,6 +4,7 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.service.AddOnService;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TaskService;
@ -27,6 +28,9 @@ public final class PluginServices {
@Autowired
MetadataService metadataService;
@Autowired
AddOnService addOnService;
private static PluginServices instance;
private PluginServices() {
@ -53,4 +57,7 @@ public final class PluginServices {
return getInstance().metadataService;
}
public static AddOnService getAddOnService() {
return getInstance().addOnService;
}
}

@ -14,7 +14,6 @@ import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.service.AddOnService;
/**
* Exposes {@link TaskDecoration} for timers
@ -32,7 +31,7 @@ public class TimerActionExposer extends BroadcastReceiver {
if(taskId == -1)
return;
if(!AddOnService.isPowerPack())
if(!PluginServices.getAddOnService().isPowerPack())
return;
Task task = PluginServices.getTaskService().fetchById(taskId, Task.ID, Task.TIMER_START,

@ -129,6 +129,9 @@ public final class TaskEditActivity extends TabActivity {
@Autowired
private DateUtilities dateUtilities;
@Autowired
private AddOnService addOnService;
// --- UI components
private EditText title;
@ -211,7 +214,7 @@ public final class TaskEditActivity extends TabActivity {
controls.add(new RepeatControlSet(this, extrasAddons));
LinearLayout addonsAddons = (LinearLayout) findViewById(R.id.tab_addons_addons);
if(AddOnService.isPowerPack()) {
if(addOnService.isPowerPack()) {
controls.add(new GCalControlSet(this, addonsAddons));
controls.add(new TimerControlSet(this, addonsAddons));
}

@ -56,6 +56,7 @@ import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.backup.BackupActivity;
import com.todoroo.astrid.core.CoreFilterExposer;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
@ -64,6 +65,7 @@ import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.reminders.ReminderService;
import com.todoroo.astrid.reminders.ReminderService.AlarmScheduler;
import com.todoroo.astrid.rmilk.MilkPreferences;
import com.todoroo.astrid.service.AddOnService;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.StartupService;
@ -124,6 +126,9 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
@Autowired
protected Database database;
@Autowired
private AddOnService addOnService;
protected TaskAdapter taskAdapter = null;
protected DetailReceiver detailReceiver = new DetailReceiver();
@ -206,6 +211,14 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
int length = resolveInfoList.size();
for(int i = 0; i < length; i++) {
ResolveInfo resolveInfo = resolveInfoList.get(i);
if(!Constants.SYNC &&
MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name))
continue;
if(!addOnService.isPowerPack() &&
BackupActivity.class.getName().equals(resolveInfo.activityInfo.name))
continue;
item = menu.add(Menu.NONE, MENU_ADDON_INTENT_ID, Menu.NONE,
resolveInfo.loadLabel(pm));
item.setIcon(resolveInfo.loadIcon(pm));

@ -10,7 +10,6 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
@ -47,24 +46,15 @@ public class AddOnService {
private static Boolean isPowerPack = null;
/** Checks whether power pack should be enabled */
public static boolean isPowerPack() {
if (isPowerPack != null)
return isPowerPack;
isPowerPack = false;
if (Preferences.getBoolean(PREF_OEM, false))
isPowerPack = true;
else {
try {
Context context = ContextManager.getContext();
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(
POWER_PACK_PACKAGE, 0);
if(applicationInfo.uid == context.getApplicationInfo().uid)
isPowerPack = true;
} catch (PackageManager.NameNotFoundException e) {
// not found
}
public boolean isPowerPack() {
if (isPowerPack == null) {
isPowerPack = false;
if (Preferences.getBoolean(PREF_OEM, false))
isPowerPack = true;
else if(isInstalled(POWER_PACK_PACKAGE, true))
isPowerPack = true;
}
return isPowerPack;
}
@ -147,18 +137,27 @@ public class AddOnService {
* @return
*/
public boolean isInstalled(AddOn addOn) {
return isInstalled(addOn.getPackageName(), addOn.isInternal());
}
/**
* Check whether a given add-on is installed
* @param addOn
* @return
*/
private boolean isInstalled(String packageName, boolean internal) {
Context context = ContextManager.getContext();
ApplicationInfo applicationInfo;
try {
applicationInfo = context.getPackageManager().getApplicationInfo(
addOn.getPackageName(), 0);
packageName, 0);
} catch (Exception e) {
return false;
}
if(applicationInfo == null)
return false;
if(!addOn.isInternal())
if(!internal)
return true;
return applicationInfo.uid == context.getApplicationInfo().uid;
}

@ -102,7 +102,7 @@ public class AstridDependencyInjector implements AbstractDependencyInjector {
injectables.put("taskService", TaskService.class);
injectables.put("metadataService", MetadataService.class);
injectables.put("upgradeService", UpgradeService.class);
injectables.put("addonService", AddOnService.class);
injectables.put("addOnService", AddOnService.class);
// com.timsu.astrid.data
injectables.put("tasksTable", "tasks");

@ -21,6 +21,11 @@ public final class Constants {
*/
public static final boolean OEM = false;
/**
* Whether this is an installation with sync disabled
*/
public static final boolean SYNC = true;
/**
* Interval to update the widget (in order to detect hidden tasks
* becoming visible)

Loading…
Cancel
Save