mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Reorganize tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.androidbase.activities;
|
||||
package org.isoron.androidbase;
|
||||
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
@@ -44,13 +44,19 @@ import javax.inject.*;
|
||||
* a bug report, obtaining device information, or requesting runtime
|
||||
* permissions.
|
||||
*/
|
||||
@ActivityScope
|
||||
public class BaseSystem
|
||||
@AppScope
|
||||
public class BaseSystem implements CACertSSLContextProvider
|
||||
{
|
||||
private Context context;
|
||||
|
||||
@Override
|
||||
public Context getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public BaseSystem(@ActivityContext Context context)
|
||||
public BaseSystem(@AppContext Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
@@ -17,10 +17,9 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.utils;
|
||||
package org.isoron.androidbase;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
@@ -29,14 +28,14 @@ import java.security.cert.*;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
|
||||
public abstract class SSLUtils
|
||||
public interface CACertSSLContextProvider
|
||||
{
|
||||
public static SSLContext getCACertSSLContext(@NonNull Context context)
|
||||
default SSLContext getCACertSSLContext()
|
||||
{
|
||||
try
|
||||
{
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
InputStream caInput = context.getAssets().open("cacert.pem");
|
||||
InputStream caInput = getContext().getAssets().open("cacert.pem");
|
||||
Certificate ca = cf.generateCertificate(caInput);
|
||||
|
||||
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
@@ -58,4 +57,5 @@ public abstract class SSLUtils
|
||||
}
|
||||
}
|
||||
|
||||
Context getContext();
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package org.isoron.androidbase.activities;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
|
||||
@@ -24,8 +24,10 @@ import android.graphics.*;
|
||||
import android.graphics.drawable.*;
|
||||
import android.net.*;
|
||||
import android.os.*;
|
||||
import android.provider.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.design.widget.*;
|
||||
import android.support.v4.app.*;
|
||||
import android.support.v4.content.res.*;
|
||||
import android.support.v7.app.*;
|
||||
import android.support.v7.view.ActionMode;
|
||||
@@ -34,10 +36,18 @@ import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static android.media.RingtoneManager.ACTION_RINGTONE_PICKER;
|
||||
import static android.media.RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI;
|
||||
import static android.media.RingtoneManager.EXTRA_RINGTONE_EXISTING_URI;
|
||||
import static android.media.RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT;
|
||||
import static android.media.RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT;
|
||||
import static android.media.RingtoneManager.EXTRA_RINGTONE_TYPE;
|
||||
import static android.media.RingtoneManager.TYPE_NOTIFICATION;
|
||||
import static android.os.Build.VERSION.*;
|
||||
import static android.os.Build.VERSION_CODES.*;
|
||||
import static android.support.v4.content.FileProvider.*;
|
||||
@@ -117,6 +127,21 @@ public class BaseScreen
|
||||
}
|
||||
}
|
||||
|
||||
public static void showRingtonePicker(Fragment fragment,
|
||||
int requestCode)
|
||||
{
|
||||
Uri existingRingtoneUri = RingtoneManager.getRingtoneUri(fragment.getContext());
|
||||
Uri defaultRingtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||
|
||||
Intent intent = new Intent(ACTION_RINGTONE_PICKER);
|
||||
intent.putExtra(EXTRA_RINGTONE_TYPE, TYPE_NOTIFICATION);
|
||||
intent.putExtra(EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
||||
intent.putExtra(EXTRA_RINGTONE_SHOW_SILENT, true);
|
||||
intent.putExtra(EXTRA_RINGTONE_DEFAULT_URI, defaultRingtoneUri);
|
||||
intent.putExtra(EXTRA_RINGTONE_EXISTING_URI, existingRingtoneUri);
|
||||
fragment.startActivityForResult(intent, requestCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the screen that its contents should be updated.
|
||||
*/
|
||||
|
||||
@@ -44,6 +44,8 @@ import dagger.*;
|
||||
})
|
||||
public interface AppComponent
|
||||
{
|
||||
BaseSystem getBaseSystem();
|
||||
|
||||
CommandRunner getCommandRunner();
|
||||
|
||||
@AppContext
|
||||
@@ -75,6 +77,8 @@ public interface AppComponent
|
||||
|
||||
ReminderScheduler getReminderScheduler();
|
||||
|
||||
RingtoneManager getRingtoneManager();
|
||||
|
||||
SyncManager getSyncManager();
|
||||
|
||||
TaskRunner getTaskRunner();
|
||||
@@ -82,4 +86,6 @@ public interface AppComponent
|
||||
WidgetPreferences getWidgetPreferences();
|
||||
|
||||
WidgetUpdater getWidgetUpdater();
|
||||
|
||||
MidnightTimer getMidnightTimer();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public class ListHabitsActivity extends BaseActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
HabitsApplication app = (HabitsApplication) getApplicationContext();
|
||||
midnightTimer = app.getComponent().getMidnightTimer();
|
||||
|
||||
component = DaggerListHabitsComponent
|
||||
.builder()
|
||||
@@ -83,8 +84,6 @@ public class ListHabitsActivity extends BaseActivity
|
||||
screen.setSelectionMenu(selectionMenu);
|
||||
rootView.setController(controller, selectionMenu);
|
||||
|
||||
midnightTimer = component.getMidnightTimer();
|
||||
|
||||
if(prefs.isSyncFeatureEnabled())
|
||||
startService(new Intent(this, SyncService.class));
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ public interface ListHabitsComponent
|
||||
|
||||
ListHabitsMenu getMenu();
|
||||
|
||||
MidnightTimer getMidnightTimer();
|
||||
|
||||
NumberButtonControllerFactory getNumberButtonControllerFactory();
|
||||
|
||||
ListHabitsRootView getRootView();
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.activities.habits.list;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.habits.list.controllers.*;
|
||||
|
||||
@@ -70,13 +70,7 @@ public class HeaderView extends ScrollableChart
|
||||
{
|
||||
HabitsApplication app = (HabitsApplication) appContext;
|
||||
prefs = app.getComponent().getPreferences();
|
||||
}
|
||||
|
||||
if (context instanceof ListHabitsActivity)
|
||||
{
|
||||
ListHabitsComponent component =
|
||||
((ListHabitsActivity) context).getListHabitsComponent();
|
||||
midnightTimer = component.getMidnightTimer();
|
||||
midnightTimer = app.getComponent().getMidnightTimer();
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.activities.habits.show;
|
||||
import android.support.annotation.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
|
||||
@@ -25,10 +25,11 @@ import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.preference.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
{
|
||||
if (requestCode == RINGTONE_REQUEST_CODE)
|
||||
{
|
||||
RingtoneUtils.parseRingtoneData(getContext(), data);
|
||||
RingtoneManager.parseRingtoneData(getContext(), data);
|
||||
updateRingtoneDescription();
|
||||
return;
|
||||
}
|
||||
@@ -113,7 +114,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
if (key.equals("reminderSound"))
|
||||
{
|
||||
RingtoneUtils.startRingtonePickerActivity(this,
|
||||
BaseScreen.showRingtonePicker(this,
|
||||
RINGTONE_REQUEST_CODE);
|
||||
return true;
|
||||
}
|
||||
@@ -158,7 +159,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
private void updateRingtoneDescription()
|
||||
{
|
||||
String ringtoneName = RingtoneUtils.getRingtoneName(getContext());
|
||||
String ringtoneName = RingtoneManager.getRingtoneName(getContext());
|
||||
if (ringtoneName == null) return;
|
||||
Preference ringtonePreference = findPreference("reminderSound");
|
||||
ringtonePreference.setSummary(ringtoneName);
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.*;
|
||||
import javax.inject.*;
|
||||
|
||||
import static android.graphics.BitmapFactory.*;
|
||||
import static org.isoron.uhabits.utils.RingtoneUtils.*;
|
||||
import static org.isoron.uhabits.notifications.RingtoneManager.*;
|
||||
|
||||
@AppScope
|
||||
public class NotificationTray
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.utils;
|
||||
package org.isoron.uhabits.notifications;
|
||||
|
||||
import android.content.*;
|
||||
import android.media.*;
|
||||
@@ -25,14 +25,25 @@ import android.net.*;
|
||||
import android.preference.*;
|
||||
import android.provider.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v4.app.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import static android.media.RingtoneManager.*;
|
||||
|
||||
public abstract class RingtoneUtils
|
||||
@AppScope
|
||||
public class RingtoneManager
|
||||
{
|
||||
private Context context;
|
||||
|
||||
@Inject
|
||||
public RingtoneManager(@AppContext @NonNull Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getRingtoneName(Context context)
|
||||
{
|
||||
@@ -101,18 +112,4 @@ public abstract class RingtoneUtils
|
||||
}
|
||||
}
|
||||
|
||||
public static void startRingtonePickerActivity(Fragment fragment,
|
||||
int requestCode)
|
||||
{
|
||||
Uri existingRingtoneUri = getRingtoneUri(fragment.getContext());
|
||||
Uri defaultRingtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||
|
||||
Intent intent = new Intent(ACTION_RINGTONE_PICKER);
|
||||
intent.putExtra(EXTRA_RINGTONE_TYPE, TYPE_NOTIFICATION);
|
||||
intent.putExtra(EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
||||
intent.putExtra(EXTRA_RINGTONE_SHOW_SILENT, true);
|
||||
intent.putExtra(EXTRA_RINGTONE_DEFAULT_URI, defaultRingtoneUri);
|
||||
intent.putExtra(EXTRA_RINGTONE_EXISTING_URI, existingRingtoneUri);
|
||||
fragment.startActivityForResult(intent, requestCode);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package org.isoron.uhabits.sync;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
import android.util.*;
|
||||
|
||||
@@ -27,7 +26,6 @@ import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.json.*;
|
||||
|
||||
import java.net.*;
|
||||
@@ -84,12 +82,15 @@ public class SyncManager implements CommandRunner.Listener
|
||||
|
||||
private boolean isListening;
|
||||
|
||||
private BaseSystem system;
|
||||
|
||||
@Inject
|
||||
public SyncManager(@AppContext @NonNull Context context,
|
||||
public SyncManager(@NonNull BaseSystem system,
|
||||
@NonNull Preferences prefs,
|
||||
@NonNull CommandRunner commandRunner,
|
||||
@NonNull CommandParser commandParser)
|
||||
{
|
||||
this.system = system;
|
||||
Log.i("SyncManager", this.toString());
|
||||
|
||||
this.prefs = prefs;
|
||||
@@ -105,7 +106,7 @@ public class SyncManager implements CommandRunner.Listener
|
||||
String serverURL = prefs.getSyncAddress();
|
||||
|
||||
Log.d("SyncManager", clientId);
|
||||
connect(context, serverURL);
|
||||
connect(serverURL);
|
||||
}
|
||||
|
||||
private JSONObject toJSONObject(String json)
|
||||
@@ -164,11 +165,11 @@ public class SyncManager implements CommandRunner.Listener
|
||||
isListening = false;
|
||||
}
|
||||
|
||||
private void connect(@AppContext @NonNull Context context, String serverURL)
|
||||
private void connect(String serverURL)
|
||||
{
|
||||
try
|
||||
{
|
||||
IO.setDefaultSSLContext(SSLUtils.getCACertSSLContext(context));
|
||||
IO.setDefaultSSLContext(system.getCACertSSLContext());
|
||||
socket = IO.socket(serverURL);
|
||||
|
||||
logSocketEvent(socket, EVENT_CONNECT, "Connected");
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.support.annotation.*;
|
||||
import com.google.auto.factory.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.util.*;
|
||||
|
||||
public abstract class ColorUtils
|
||||
{
|
||||
|
||||
public static int colorToPaletteIndex(Context context, int color)
|
||||
{
|
||||
StyledResources res = new StyledResources(context);
|
||||
|
||||
@@ -1,77 +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.utils;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* A class that emits events when a new day starts.
|
||||
*/
|
||||
@ActivityScope
|
||||
public class MidnightTimer
|
||||
{
|
||||
private final List<MidnightListener> listeners;
|
||||
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
@Inject
|
||||
public MidnightTimer()
|
||||
{
|
||||
this.listeners = new LinkedList<>();
|
||||
}
|
||||
|
||||
public synchronized void addListener(MidnightListener listener)
|
||||
{
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public synchronized void onPause()
|
||||
{
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
public synchronized void onResume()
|
||||
{
|
||||
executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(() -> notifyListeners(),
|
||||
DateUtils.millisecondsUntilTomorrow() + 1000,
|
||||
DateUtils.millisecondsInOneDay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public synchronized void removeListener(MidnightListener listener)
|
||||
{
|
||||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
private synchronized void notifyListeners()
|
||||
{
|
||||
for (MidnightListener l : listeners) l.atMidnight();
|
||||
}
|
||||
|
||||
public interface MidnightListener
|
||||
{
|
||||
void atMidnight();
|
||||
}
|
||||
}
|
||||
@@ -1,59 +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.utils;
|
||||
|
||||
import android.appwidget.*;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.widgets.*;
|
||||
|
||||
import static android.appwidget.AppWidgetManager.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public abstract class WidgetUtils
|
||||
{
|
||||
@NonNull
|
||||
public static WidgetDimensions getDimensionsFromOptions(
|
||||
@NonNull Context ctx, @NonNull Bundle options)
|
||||
{
|
||||
int maxWidth =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_WIDTH));
|
||||
int maxHeight =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_HEIGHT));
|
||||
int minWidth =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MIN_WIDTH));
|
||||
int minHeight =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MIN_HEIGHT));
|
||||
|
||||
return new WidgetDimensions(minWidth, maxHeight, maxWidth, minHeight);
|
||||
}
|
||||
|
||||
public static void updateAppWidget(@NonNull AppWidgetManager manager,
|
||||
@NonNull BaseWidget widget)
|
||||
{
|
||||
RemoteViews landscape = widget.getLandscapeRemoteViews();
|
||||
RemoteViews portrait = widget.getPortraitRemoteViews();
|
||||
RemoteViews views = new RemoteViews(landscape, portrait);
|
||||
manager.updateAppWidget(widget.getId(), views);
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
import static org.isoron.uhabits.utils.WidgetUtils.*;
|
||||
import static android.appwidget.AppWidgetManager.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
{
|
||||
@@ -39,6 +40,31 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
|
||||
private WidgetPreferences widgetPrefs;
|
||||
|
||||
public static void updateAppWidget(@NonNull AppWidgetManager manager,
|
||||
@NonNull BaseWidget widget)
|
||||
{
|
||||
RemoteViews landscape = widget.getLandscapeRemoteViews();
|
||||
RemoteViews portrait = widget.getPortraitRemoteViews();
|
||||
RemoteViews views = new RemoteViews(landscape, portrait);
|
||||
manager.updateAppWidget(widget.getId(), views);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public WidgetDimensions getDimensionsFromOptions(@NonNull Context ctx,
|
||||
@NonNull Bundle options)
|
||||
{
|
||||
int maxWidth =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_WIDTH));
|
||||
int maxHeight =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_HEIGHT));
|
||||
int minWidth =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MIN_WIDTH));
|
||||
int minHeight =
|
||||
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MIN_HEIGHT));
|
||||
|
||||
return new WidgetDimensions(minWidth, maxHeight, maxWidth, minHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppWidgetOptionsChanged(@Nullable Context context,
|
||||
@Nullable AppWidgetManager manager,
|
||||
@@ -100,7 +126,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
|
||||
updateDependencies(context);
|
||||
|
||||
new Thread(() -> {
|
||||
new Thread(() ->
|
||||
{
|
||||
Looper.prepare();
|
||||
for (int id : widgetIds)
|
||||
update(context, manager, id);
|
||||
@@ -128,8 +155,10 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
RemoteViews errorView =
|
||||
new RemoteViews(context.getPackageName(), R.layout.widget_error);
|
||||
|
||||
if(e instanceof HabitNotFoundException) {
|
||||
errorView.setCharSequence(R.id.label, "setText", context.getString(R.string.habit_not_found));
|
||||
if (e instanceof HabitNotFoundException)
|
||||
{
|
||||
errorView.setCharSequence(R.id.label, "setText",
|
||||
context.getString(R.string.habit_not_found));
|
||||
}
|
||||
|
||||
manager.updateAppWidget(widgetId, errorView);
|
||||
@@ -143,8 +172,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
{
|
||||
BaseWidget widget = getWidgetFromId(context, widgetId);
|
||||
Bundle options = manager.getAppWidgetOptions(widgetId);
|
||||
widget.setDimensions(
|
||||
getDimensionsFromOptions(context, options));
|
||||
widget.setDimensions(getDimensionsFromOptions(context, options));
|
||||
|
||||
updateAppWidget(manager, widget);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user