Add android version checks

pull/253/head
Alex Baker 10 years ago
parent 9141cbfc99
commit 2de5824ddf

@ -15,6 +15,8 @@ import android.view.View;
import org.tasks.R; import org.tasks.R;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastHoneycomb;
public class FloatingActionButton extends View { public class FloatingActionButton extends View {
private final Paint mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
@ -49,7 +51,7 @@ public class FloatingActionButton extends View {
mBitmap = ((BitmapDrawable) drawable).getBitmap(); mBitmap = ((BitmapDrawable) drawable).getBitmap();
} }
setWillNotDraw(false); setWillNotDraw(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (atLeastHoneycomb()) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null); setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} }
} }

@ -9,6 +9,7 @@ import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -346,11 +347,36 @@ public class AndroidUtilities {
} }
} }
/** public static boolean preFroyo() {
* @return Android SDK version as an integer. Works on all versions return !atLeastFroyo();
*/ }
public static int getSdkVersion() {
return Integer.parseInt(android.os.Build.VERSION.SDK); public static boolean preGingerbreadMR1() {
return !atLeastGingerbreadMR1();
}
public static boolean preIceCreamSandwich() {
return !atLeastIceCreamSandwich();
}
public static boolean atLeastFroyo() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
}
public static boolean atLeastGingerbread() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
}
public static boolean atLeastGingerbreadMR1() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1;
}
public static boolean atLeastHoneycomb() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
public static boolean atLeastIceCreamSandwich() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
} }
/** /**

@ -47,6 +47,8 @@ import java.util.Map.Entry;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.preFroyo;
/** /**
* Displays the preference screen for users to edit their preferences * Displays the preference screen for users to edit their preferences
* *
@ -362,7 +364,7 @@ public class EditPreferences extends TodorooPreferenceActivity {
} }
}); });
if (AndroidUtilities.getSdkVersion() <= 7) { if (preFroyo()) {
searchForAndRemovePreference(getPreferenceScreen(), getString(R.string.p_calendar_reminders)); searchForAndRemovePreference(getPreferenceScreen(), getString(R.string.p_calendar_reminders));
} else { } else {
findPreference(getString(R.string.p_calendar_reminders)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { findPreference(getString(R.string.p_calendar_reminders)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

@ -96,6 +96,7 @@ import javax.inject.Inject;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.InjectView; import butterknife.InjectView;
import static com.todoroo.andlib.utility.AndroidUtilities.preGingerbreadMR1;
import static org.tasks.files.FileHelper.getPathFromUri; import static org.tasks.files.FileHelper.getPathFromUri;
/** /**
@ -885,7 +886,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
menu.clear(); menu.clear();
inflater.inflate(R.menu.task_edit_fragment, menu); inflater.inflate(R.menu.task_edit_fragment, menu);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD_MR1) { if (preGingerbreadMR1()) {
// media recorder aac support requires api level 10 // media recorder aac support requires api level 10
// approximately 1% of current installs are using api level 7-9 // approximately 1% of current installs are using api level 7-9
menu.findItem(R.id.menu_record_note).setVisible(false); menu.findItem(R.id.menu_record_note).setVisible(false);

@ -63,6 +63,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastGingerbread;
import static org.tasks.date.DateTimeUtils.newDate; import static org.tasks.date.DateTimeUtils.newDate;
/** /**
@ -481,7 +482,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
params.height = LayoutParams.WRAP_CONTENT; params.height = LayoutParams.WRAP_CONTENT;
Configuration config = fragment.getResources().getConfiguration(); Configuration config = fragment.getResources().getConfiguration();
int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
if (AndroidUtilities.getSdkVersion() >= 9 && size == Configuration.SCREENLAYOUT_SIZE_XLARGE) { if (atLeastGingerbread() && size == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
DisplayMetrics metrics = fragment.getResources().getDisplayMetrics(); DisplayMetrics metrics = fragment.getResources().getDisplayMetrics();
params.width = metrics.widthPixels / 2; params.width = metrics.widthPixels / 2;
} }

@ -9,7 +9,6 @@ import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Constants;
@ -25,6 +24,8 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.preFroyo;
public class CalendarAlarmReceiver extends InjectingBroadcastReceiver { public class CalendarAlarmReceiver extends InjectingBroadcastReceiver {
private static final Logger log = LoggerFactory.getLogger(CalendarAlarmReceiver.class); private static final Logger log = LoggerFactory.getLogger(CalendarAlarmReceiver.class);
@ -80,7 +81,7 @@ public class CalendarAlarmReceiver extends InjectingBroadcastReceiver {
ContentResolver cr = context.getContentResolver(); ContentResolver cr = context.getContentResolver();
Uri eventUri = Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS); Uri eventUri = Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
if (AndroidUtilities.getSdkVersion() <= 7) { if (preFroyo()) {
return; return;
} }

@ -12,6 +12,9 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import javax.inject.Singleton; import javax.inject.Singleton;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastFroyo;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastIceCreamSandwich;
@Singleton @Singleton
public class Calendars { public class Calendars {
@ -19,7 +22,7 @@ public class Calendars {
public static final String CALENDAR_CONTENT_EVENTS = "events"; public static final String CALENDAR_CONTENT_EVENTS = "events";
public static final String CALENDAR_CONTENT_ATTENDEES = "attendees"; public static final String CALENDAR_CONTENT_ATTENDEES = "attendees";
private static final boolean USE_ICS_NAMES = AndroidUtilities.getSdkVersion() >= 14; private static final boolean USE_ICS_NAMES = AndroidUtilities.atLeastIceCreamSandwich();
public static final String ID_COLUMN_NAME = "_id"; public static final String ID_COLUMN_NAME = "_id";
public static final String CALENDARS_DISPLAY_COL = (USE_ICS_NAMES ? CalendarContract.Calendars.CALENDAR_DISPLAY_NAME : "displayName"); public static final String CALENDARS_DISPLAY_COL = (USE_ICS_NAMES ? CalendarContract.Calendars.CALENDAR_DISPLAY_NAME : "displayName");
@ -48,11 +51,11 @@ public class Calendars {
* @param table provider table, something like calendars, events * @param table provider table, something like calendars, events
*/ */
public static Uri getCalendarContentUri(String table) { public static Uri getCalendarContentUri(String table) {
if (AndroidUtilities.getSdkVersion() >= 14) { if (atLeastIceCreamSandwich()) {
return getIcsUri(table); return getIcsUri(table);
} }
if(AndroidUtilities.getSdkVersion() >= 8) { if(atLeastFroyo()) {
return Uri.parse("content://com.android.calendar/" + table); return Uri.parse("content://com.android.calendar/" + table);
} else { } else {
return Uri.parse("content://calendar/" + table); return Uri.parse("content://calendar/" + table);

@ -30,6 +30,8 @@ import java.util.TimeZone;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastIceCreamSandwich;
import static com.todoroo.andlib.utility.AndroidUtilities.preIceCreamSandwich;
import static com.todoroo.astrid.gcal.Calendars.getCalendarContentUri; import static com.todoroo.astrid.gcal.Calendars.getCalendarContentUri;
public class GCalHelper { public class GCalHelper {
@ -106,7 +108,7 @@ public class GCalHelper {
values.put("title", task.getTitle()); values.put("title", task.getTitle());
values.put("description", task.getNotes()); values.put("description", task.getNotes());
values.put("hasAlarm", 0); values.put("hasAlarm", 0);
if (AndroidUtilities.getSdkVersion() < 14) { if (preIceCreamSandwich()) {
values.put("transparency", 0); values.put("transparency", 0);
values.put("visibility", 0); values.put("visibility", 0);
} }
@ -241,7 +243,7 @@ public class GCalHelper {
} }
private static void adjustDateForIcs(ContentValues values) { private static void adjustDateForIcs(ContentValues values) {
if (AndroidUtilities.getSdkVersion() >= 14) { if (atLeastIceCreamSandwich()) {
if ("1".equals(values.get("allDay"))) { if ("1".equals(values.get("allDay"))) {
values.put("eventTimezone", Time.TIMEZONE_UTC); values.put("eventTimezone", Time.TIMEZONE_UTC);
} else { } else {

@ -43,6 +43,7 @@ import java.text.ParseException;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastGingerbread;
import static org.tasks.date.DateTimeUtils.newDate; import static org.tasks.date.DateTimeUtils.newDate;
/** /**
@ -259,7 +260,7 @@ public class DateChangedAlerts {
params.height = LayoutParams.WRAP_CONTENT; params.height = LayoutParams.WRAP_CONTENT;
Configuration config = context.getResources().getConfiguration(); Configuration config = context.getResources().getConfiguration();
int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
if (AndroidUtilities.getSdkVersion() >= 9 && size == Configuration.SCREENLAYOUT_SIZE_XLARGE || size == Configuration.SCREENLAYOUT_SIZE_LARGE) { if (atLeastGingerbread() && size == Configuration.SCREENLAYOUT_SIZE_XLARGE || size == Configuration.SCREENLAYOUT_SIZE_LARGE) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics(); DisplayMetrics metrics = context.getResources().getDisplayMetrics();
params.width = metrics.widthPixels / 2; params.width = metrics.widthPixels / 2;
} }

@ -29,6 +29,7 @@ import org.tasks.widget.WidgetHelper;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.preIceCreamSandwich;
import static com.todoroo.astrid.api.AstridApiConstants.BROADCAST_EVENT_TASK_LIST_UPDATED; import static com.todoroo.astrid.api.AstridApiConstants.BROADCAST_EVENT_TASK_LIST_UPDATED;
public class TasksWidget extends InjectingAppWidgetProvider { public class TasksWidget extends InjectingAppWidgetProvider {
@ -76,7 +77,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
ContextManager.setContext(context); ContextManager.setContext(context);
super.onUpdate(context, appWidgetManager, appWidgetIds); super.onUpdate(context, appWidgetManager, appWidgetIds);
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (preIceCreamSandwich()) {
// Start in service to prevent Application Not Responding timeout // Start in service to prevent Application Not Responding timeout
updateWidgets(context); updateWidgets(context);
} else { } else {
@ -97,7 +98,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
} }
suppressUpdateFlag = 0; suppressUpdateFlag = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (preIceCreamSandwich()) {
context.startService(new Intent(context, WidgetUpdateService.class)); context.startService(new Intent(context, WidgetUpdateService.class));
} else { } else {
updateScrollableWidgets(context, null); updateScrollableWidgets(context, null);

@ -30,6 +30,8 @@ import org.tasks.widget.WidgetHelper;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.preIceCreamSandwich;
public class WidgetConfigActivity extends InjectingListActivity { public class WidgetConfigActivity extends InjectingListActivity {
public static final String PREF_TITLE = "widget-title-"; public static final String PREF_TITLE = "widget-title-";
@ -49,7 +51,7 @@ public class WidgetConfigActivity extends InjectingListActivity {
@Inject ActivityPreferences preferences; @Inject ActivityPreferences preferences;
private void updateWidget() { private void updateWidget() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (preIceCreamSandwich()) {
Intent intent = new Intent(this, WidgetUpdateService.class); Intent intent = new Intent(this, WidgetUpdateService.class);
intent.putExtra(WidgetUpdateService.EXTRA_WIDGET_ID, mAppWidgetId); intent.putExtra(WidgetUpdateService.EXTRA_WIDGET_ID, mAppWidgetId);
startService(intent); startService(intent);

@ -13,6 +13,8 @@ import org.tasks.R;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastIceCreamSandwich;
@Singleton @Singleton
public class ActivityPreferences extends Preferences { public class ActivityPreferences extends Preferences {
@ -49,8 +51,7 @@ public class ActivityPreferences extends Preferences {
} }
public int getEditDialogTheme() { public int getEditDialogTheme() {
boolean ics = AndroidUtilities.getSdkVersion() >= 14; return atLeastIceCreamSandwich() ? R.style.TEA_Dialog_Light_ICS : R.style.TEA_Dialog;
return ics ? R.style.TEA_Dialog_Light_ICS : R.style.TEA_Dialog;
} }
/** /**

@ -39,6 +39,7 @@ import javax.inject.Singleton;
import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static com.todoroo.andlib.utility.AndroidUtilities.preIceCreamSandwich;
@Singleton @Singleton
public class WidgetHelper { public class WidgetHelper {
@ -46,7 +47,7 @@ public class WidgetHelper {
public static int flags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK; public static int flags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK;
public static void startWidgetService(Context context) { public static void startWidgetService(Context context) {
Class widgetServiceClass = android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH Class widgetServiceClass = preIceCreamSandwich()
? WidgetUpdateService.class ? WidgetUpdateService.class
: ScrollableWidgetUpdateService.class; : ScrollableWidgetUpdateService.class;
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

Loading…
Cancel
Save