Drop support for Android ICS and Jelly Bean; remove obsolete code

pull/231/merge
Alinson S. Xavier 8 years ago
parent 96bdb42365
commit e92ffb3894

1
.gitignore vendored

@ -3,6 +3,7 @@
*.class
*.dex
*.iml
*.local
*.local.*
*.swp
*.trace

@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId "org.isoron.uhabits"
minSdkVersion 15
minSdkVersion 19
targetSdkVersion 25
buildConfigField "Integer", "databaseVersion", "19"

@ -31,6 +31,8 @@ import java.io.*;
import java.util.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.view.View.MeasureSpec.*;
import static junit.framework.Assert.*;
@ -157,8 +159,8 @@ public class BaseViewTest extends BaseAndroidTest
private String getVersionedPath(String path)
{
int version = SDK_INT;
if (version >= 21) version = 21;
else if (version >= 15) version = 15;
if (version >= LOLLIPOP) version = LOLLIPOP;
else if (version >= KITKAT) version = KITKAT;
return String.format("views-v%d/%s", version, path);
}

@ -19,7 +19,6 @@
package org.isoron.uhabits;
import android.os.*;
import android.support.test.runner.*;
import android.test.suitebuilder.annotation.*;
@ -29,8 +28,8 @@ import org.junit.runner.*;
import java.io.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
@ -39,9 +38,6 @@ public class HabitsApplicationTest extends BaseAndroidTest
@Test
public void test_getLogcat() throws IOException
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
return;
String msg = "LOGCAT TEST";
new RuntimeException(msg).printStackTrace();

@ -49,8 +49,6 @@ public interface AppComponent
CreateHabitCommandFactory getCreateHabitCommandFactory();
DirFinder getDirFinder();
EditHabitCommandFactory getEditHabitCommandFactory();
GenericImporter getGenericImporter();

@ -1,191 +0,0 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities.common.dialogs;
import android.content.*;
import android.support.annotation.*;
import android.support.v7.app.*;
import android.view.*;
import android.view.WindowManager.*;
import android.widget.*;
import com.google.auto.factory.*;
import org.isoron.uhabits.activities.*;
import java.io.*;
import java.util.*;
/**
* Dialog that allows the user to pick a file.
*/
@AutoFactory(allowSubclasses = true)
public class FilePickerDialog implements AdapterView.OnItemClickListener
{
private static final String PARENT_DIR = "..";
private final Context context;
private ListView list;
private AppCompatDialog dialog;
private File currentPath;
private OnFileSelectedListener listener;
public FilePickerDialog(@Provided @ActivityContext Context context,
File initialDirectory)
{
this.context = context;
list = new ListView(context);
list.setOnItemClickListener(this);
dialog = new AppCompatDialog(context);
dialog.setContentView(list);
dialog
.getWindow()
.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
navigateTo(initialDirectory);
}
public AppCompatDialog getDialog()
{
return dialog;
}
@Override
public void onItemClick(AdapterView<?> parent,
View view,
int which,
long id)
{
String filename = (String) list.getItemAtPosition(which);
File file;
if (filename.equals(PARENT_DIR)) file = currentPath.getParentFile();
else file = new File(currentPath, filename);
if (file.isDirectory())
{
navigateTo(file);
}
else
{
if (listener != null) listener.onFileSelected(file);
dialog.dismiss();
}
}
public void setListener(OnFileSelectedListener listener)
{
this.listener = listener;
}
public void show()
{
dialog.show();
}
@NonNull
private String[] getFileList(File path, File[] dirs, File[] files)
{
int count = 0;
int length = dirs.length + files.length;
String[] fileList;
if (path.getParentFile() == null || !path.getParentFile().canRead())
{
fileList = new String[length];
}
else
{
fileList = new String[length + 1];
fileList[count++] = PARENT_DIR;
}
Arrays.sort(dirs);
Arrays.sort(files);
for (File dir : dirs)
fileList[count++] = dir.getName();
for (File file : files)
fileList[count++] = file.getName();
return fileList;
}
private void navigateTo(File path)
{
if (!path.exists()) return;
File[] dirs = path.listFiles(new ReadableDirFilter());
File[] files = path.listFiles(new RegularReadableFileFilter());
if (dirs == null || files == null) return;
this.currentPath = path;
dialog.setTitle(currentPath.getPath());
list.setAdapter(new FilePickerAdapter(getFileList(path, dirs, files)));
}
public interface OnFileSelectedListener
{
void onFileSelected(File file);
}
private static class ReadableDirFilter implements FileFilter
{
@Override
public boolean accept(File file)
{
return (file.isDirectory() && file.canRead());
}
}
private class FilePickerAdapter extends ArrayAdapter<String>
{
public FilePickerAdapter(@NonNull String[] fileList)
{
super(FilePickerDialog.this.context,
android.R.layout.simple_list_item_1, fileList);
}
@Override
public View getView(int pos, View view, ViewGroup parent)
{
view = super.getView(pos, view, parent);
TextView tv = (TextView) view;
tv.setSingleLine(true);
return view;
}
}
private class RegularReadableFileFilter implements FileFilter
{
@Override
public boolean accept(File file)
{
return !file.isDirectory() && file.canRead();
}
}
}

@ -35,7 +35,6 @@ import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*;
import org.isoron.uhabits.activities.habits.edit.*;
import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.io.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*;
import org.isoron.uhabits.utils.*;
@ -46,8 +45,6 @@ import java.lang.reflect.*;
import javax.inject.*;
import static android.content.DialogInterface.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static android.view.inputmethod.EditorInfo.*;
@ActivityScope
@ -74,18 +71,12 @@ public class ListHabitsScreen extends BaseScreen
@NonNull
private final IntentFactory intentFactory;
@NonNull
private final DirFinder dirFinder;
@NonNull
private final CommandRunner commandRunner;
@NonNull
private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
@NonNull
private final FilePickerDialogFactory filePickerDialogFactory;
@NonNull
private final ColorPickerDialogFactory colorPickerFactory;
@ -101,12 +92,10 @@ public class ListHabitsScreen extends BaseScreen
@Inject
public ListHabitsScreen(@NonNull BaseActivity activity,
@NonNull CommandRunner commandRunner,
@NonNull DirFinder dirFinder,
@NonNull ListHabitsRootView rootView,
@NonNull IntentFactory intentFactory,
@NonNull ThemeSwitcher themeSwitcher,
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
@NonNull FilePickerDialogFactory filePickerDialogFactory,
@NonNull ColorPickerDialogFactory colorPickerFactory,
@NonNull EditHabitDialogFactory editHabitDialogFactory,
@NonNull Preferences prefs)
@ -118,8 +107,6 @@ public class ListHabitsScreen extends BaseScreen
this.commandRunner = commandRunner;
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
this.editHabitDialogFactory = editHabitDialogFactory;
this.dirFinder = dirFinder;
this.filePickerDialogFactory = filePickerDialogFactory;
this.intentFactory = intentFactory;
this.themeSwitcher = themeSwitcher;
}
@ -237,39 +224,10 @@ public class ListHabitsScreen extends BaseScreen
public void showImportScreen()
{
if (SDK_INT < KITKAT)
{
showImportScreenPreKitKat();
return;
}
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
Intent intent = intentFactory.openDocument();
activity.startActivityForResult(intent, REQUEST_OPEN_DOCUMENT);
}
public void showImportScreenPreKitKat()
{
File dir = dirFinder.findStorageDir(null);
if (dir == null)
{
showMessage(R.string.could_not_import);
return;
}
FilePickerDialog picker = filePickerDialogFactory.create(dir);
if (controller != null)
picker.setListener(file -> controller.onImportData(file, () ->
{
}));
activity.showDialog(picker.getDialog());
}
public void showIntroScreen()
{
Intent intent = intentFactory.startIntroActivity(activity);

@ -45,6 +45,14 @@ public class IntentFactory
return buildViewIntent(url);
}
public Intent openDocument()
{
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
return intent;
}
public Intent rateApp(Context context)
{
String url = context.getString(R.string.playStoreURL);

@ -30,6 +30,7 @@ import javax.inject.*;
import static android.app.AlarmManager.*;
import static android.content.Context.*;
import static android.os.Build.VERSION_CODES.M;
@AppScope
public class IntentScheduler
@ -44,18 +45,9 @@ public class IntentScheduler
public void schedule(@NonNull Long timestamp, PendingIntent intent)
{
if (Build.VERSION.SDK_INT >= 23)
{
if (Build.VERSION.SDK_INT >= M)
manager.setExactAndAllowWhileIdle(RTC_WAKEUP, timestamp, intent);
return;
}
if (Build.VERSION.SDK_INT >= 19)
{
else
manager.setExact(RTC_WAKEUP, timestamp, intent);
return;
}
manager.set(RTC_WAKEUP, timestamp, intent);
}
}

@ -1,106 +0,0 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.io;
import android.content.*;
import android.os.*;
import android.support.annotation.*;
import android.util.*;
import org.isoron.uhabits.*;
import java.io.*;
import javax.inject.*;
import static android.support.v4.content.ContextCompat.*;
/**
* A DirFinder locates suitable directories for storing user files.
*/
public class DirFinder
{
private static final String TAG = "DirFinder";
private final Context context;
@Inject
public DirFinder(@AppContext Context context)
{
this.context = context;
}
@Nullable
public File findSDCardDir(@Nullable String subpath)
{
File parents[] = new File[]{
Environment.getExternalStorageDirectory()
};
return findDir(parents, subpath);
}
@Nullable
public File findStorageDir(@Nullable String relativePath)
{
File potentialParents[] = getExternalFilesDirs(context, null);
if (potentialParents == null)
{
Log.e(TAG, "getFilesDir: getExternalFilesDirs returned null");
return null;
}
return findDir(potentialParents, relativePath);
}
@Nullable
private File findDir(@NonNull File potentialParents[],
@Nullable String relativePath)
{
if (relativePath == null) relativePath = "";
File chosenDir = null;
for (File dir : potentialParents)
{
if (dir == null || !dir.canWrite()) continue;
chosenDir = dir;
break;
}
if (chosenDir == null)
{
Log.e(TAG,
"getDir: all potential parents are null or non-writable");
return null;
}
File dir = new File(
String.format("%s/%s/", chosenDir.getAbsolutePath(), relativePath));
if (!dir.exists() && !dir.mkdirs())
{
Log.e(TAG,
"getDir: chosen dir does not exist and cannot be created");
return null;
}
return dir;
}
}

@ -24,8 +24,6 @@ import android.support.annotation.*;
import java.text.*;
import java.util.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static android.text.format.DateFormat.*;
public class DateFormats
@ -43,10 +41,7 @@ public class DateFormats
public static SimpleDateFormat fromSkeleton(@NonNull String skeleton)
{
Locale locale = Locale.getDefault();
if (SDK_INT >= JELLY_BEAN_MR2)
skeleton = getBestDateTimePattern(locale, skeleton);
return fromSkeleton(skeleton, locale);
}

@ -28,8 +28,6 @@ import android.widget.*;
import org.isoron.uhabits.widgets.*;
import static android.appwidget.AppWidgetManager.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*;
public abstract class WidgetUtils
@ -38,9 +36,6 @@ public abstract class WidgetUtils
public static WidgetDimensions getDimensionsFromOptions(
@NonNull Context ctx, @NonNull Bundle options)
{
if (SDK_INT < JELLY_BEAN)
throw new AssertionError("method requires jelly-bean");
int maxWidth =
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_WIDTH));
int maxHeight =
@ -55,13 +50,6 @@ public abstract class WidgetUtils
public static void updateAppWidget(@NonNull AppWidgetManager manager,
@NonNull BaseWidget widget)
{
if (SDK_INT < JELLY_BEAN)
{
RemoteViews portrait = widget.getPortraitRemoteViews();
manager.updateAppWidget(widget.getId(), portrait);
}
else
{
RemoteViews landscape = widget.getLandscapeRemoteViews();
RemoteViews portrait = widget.getPortraitRemoteViews();
@ -69,4 +57,3 @@ public abstract class WidgetUtils
manager.updateAppWidget(widget.getId(), views);
}
}
}

@ -30,8 +30,6 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.preferences.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static android.view.View.MeasureSpec.*;
public abstract class BaseWidget
@ -126,7 +124,6 @@ public abstract class BaseWidget
Bitmap bitmap = getBitmapFromView(view);
remoteViews.setImageViewBitmap(R.id.imageView, bitmap);
if (SDK_INT >= JELLY_BEAN)
adjustRemoteViewsPadding(remoteViews, view, width, height);
PendingIntent onClickIntent = getOnClickPendingIntent(context);

@ -31,8 +31,6 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static org.isoron.uhabits.utils.WidgetUtils.*;
public abstract class BaseWidgetProvider extends AppWidgetProvider
@ -144,13 +142,9 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
try
{
BaseWidget widget = getWidgetFromId(context, widgetId);
if (SDK_INT > JELLY_BEAN)
{
Bundle options = manager.getAppWidgetOptions(widgetId);
widget.setDimensions(
getDimensionsFromOptions(context, options));
}
updateAppWidget(manager, widget);
}

@ -21,7 +21,6 @@ package org.isoron.uhabits.activities.habits.list;
import android.content.*;
import android.support.v7.app.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
@ -30,15 +29,12 @@ import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*;
import org.isoron.uhabits.activities.habits.edit.*;
import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.io.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*;
import org.junit.*;
import org.junit.runner.*;
import org.junit.runners.*;
import java.io.*;
import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.anyInt;
@ -62,12 +58,8 @@ public class ListHabitsScreenTest extends BaseUnitTest
private ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
private FilePickerDialogFactory filePickerDialogFactory;
private IntentFactory intentFactory;
private DirFinder dirFinder;
private CommandRunner commandRunner;
private ColorPickerDialogFactory colorPickerDialogFactory;
@ -76,8 +68,6 @@ public class ListHabitsScreenTest extends BaseUnitTest
private ThemeSwitcher themeSwitcher;
private ListHabitsScreen baseScreen;
private Preferences prefs;
@Before
@ -88,20 +78,17 @@ public class ListHabitsScreenTest extends BaseUnitTest
activity = mock(BaseActivity.class);
commandRunner = mock(CommandRunner.class);
dirFinder = mock(DirFinder.class);
rootView = mock(ListHabitsRootView.class);
intentFactory = mock(IntentFactory.class);
themeSwitcher = mock(ThemeSwitcher.class);
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
filePickerDialogFactory = mock(FilePickerDialogFactory.class);
colorPickerDialogFactory = mock(ColorPickerDialogFactory.class);
dialogFactory = mock(EditHabitDialogFactory.class);
prefs = mock(Preferences.class);
screen = spy(new ListHabitsScreen(activity, commandRunner, dirFinder,
rootView, intentFactory, themeSwitcher, confirmDeleteDialogFactory,
filePickerDialogFactory, colorPickerDialogFactory, dialogFactory,
prefs));
screen = spy(new ListHabitsScreen(activity, commandRunner, rootView,
intentFactory, themeSwitcher, confirmDeleteDialogFactory,
colorPickerDialogFactory, dialogFactory, prefs));
doNothing().when(screen).showMessage(anyInt());
@ -240,25 +227,9 @@ public class ListHabitsScreenTest extends BaseUnitTest
@Test
public void testShowImportScreen()
{
File dir = mock(File.class);
when(dirFinder.findStorageDir(any())).thenReturn(dir);
FilePickerDialog picker = mock(FilePickerDialog.class);
AppCompatDialog dialog = mock(AppCompatDialog.class);
when(picker.getDialog()).thenReturn(dialog);
when(filePickerDialogFactory.create(dir)).thenReturn(picker);
screen.showImportScreen();
verify(activity).showDialog(dialog);
}
@Test
public void testShowImportScreen_withInvalidPath()
{
when(dirFinder.findStorageDir(any())).thenReturn(null);
when(intentFactory.openDocument()).thenReturn(intent);
screen.showImportScreen();
verify(screen).showMessage(R.string.could_not_import);
verify(activity).startActivityForResult(intent, REQUEST_OPEN_DOCUMENT);
}
@Test

Loading…
Cancel
Save