Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions src/androidTest/java/com/aragaer/jtt/JttServiceTest.java

This file was deleted.

1 change: 0 additions & 1 deletion src/androidTest/java/com/aragaer/jtt/WidgetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private void setInitialLocation(Context context) {
@Before public void setUp() {
Context context = getInstrumentation().getTargetContext();
setInitialLocation(context);
context.startService(new Intent(getInstrumentation().getTargetContext(), JttService.class));
}

private void putWidgetOnHome(String widgetName) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import androidx.test.filters.LargeTest;

import com.aragaer.jtt.JttService;
import com.aragaer.jtt.Settings;
import com.aragaer.jtt.mechanics.AndroidTicker;

Expand All @@ -31,12 +30,9 @@ public class NotificationTest {
context = instrumentation.getTargetContext();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
settings.edit().putString(Settings.PREF_LOCALE, "1").commit();
Intent intent = new Intent(context, JttService.class);
context.startService(intent);
}

@After public void cleanUp() {
context.stopService(new Intent(context, JttService.class));
context.removeStickyBroadcast(new Intent(AndroidTicker.ACTION_JTT_TICK));
device.pressHome();
}
Expand Down

This file was deleted.

15 changes: 6 additions & 9 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:label="@string/app_name"
android:name=".android.JttApplication">
<activity
android:name=".JTTMainActivity"
android:label="@string/app_name"
Expand All @@ -28,11 +29,13 @@
</activity>

<service
android:name=".JttService"
android:name=".JttStatus"
android:exported="false" />
<receiver android:name=".android.BootReceiver" >
<receiver android:name=".android.TickerStart" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.DATE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
<receiver android:name="JTTWidgetProvider$Widget1"
Expand All @@ -55,11 +58,5 @@
android:name="android.appwidget.provider"
android:resource="@xml/widget12" />
</receiver>
<receiver android:name=".android.TimeChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
</application>
</manifest>
4 changes: 2 additions & 2 deletions src/main/java/com/aragaer/jtt/ClockView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// vim: et ts=4 sts=4 sw=4 syntax=java
package com.aragaer.jtt;

import com.aragaer.jtt.android.JttApplication;
import com.aragaer.jtt.core.Hour;
import com.aragaer.jtt.graphics.ArrowView;
import com.aragaer.jtt.graphics.WadokeiView;
import com.aragaer.jtt.resources.RuntimeResources;
import com.aragaer.jtt.resources.StringResources;
import com.aragaer.jtt.wadokei.AutoresizeTextView;

Expand All @@ -26,7 +26,7 @@ public class ClockView extends ViewGroup implements StringResources.StringResour

public ClockView(Context context) {
super(context);
sr = RuntimeResources.get(context).getStringResources();
sr = ((JttApplication) context.getApplicationContext()).getStringResources();
sr.registerStringResourceChangeListener(this, StringResources.TYPE_HOUR_NAME);
wadokei = new WadokeiView(context);
arrow = new ArrowView(context);
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/aragaer/jtt/JTTMainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import android.app.Activity;
import android.app.FragmentManager;
import android.content.*;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;

import com.aragaer.jtt.android.JttApplication;
import com.aragaer.jtt.android.fragments.LocationFragment;

import org.jetbrains.annotations.NotNull;
Expand All @@ -20,11 +20,7 @@ public class JTTMainActivity extends Activity implements SharedPreferences.OnSha
public void onCreate(Bundle savedInstanceState) {
setTheme(Settings.getAppTheme(this));
super.onCreate(savedInstanceState);
Intent serviceIntent = new Intent(this, JttService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startForegroundService(serviceIntent);
else
startService(serviceIntent);
((JttApplication) getApplicationContext()).startTicker();
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
pref.registerOnSharedPreferenceChangeListener(this);
if (savedInstanceState == null) { // Otherwise we assume that fragments are saved/restored
Expand Down
48 changes: 15 additions & 33 deletions src/main/java/com/aragaer/jtt/JTTWidgetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import java.util.Map;
import java.util.HashMap;

import com.aragaer.jtt.android.JttApplication;
import com.aragaer.jtt.core.Hour;
import com.aragaer.jtt.graphics.Paints;
import com.aragaer.jtt.graphics.WadokeiDraw;
import com.aragaer.jtt.mechanics.AndroidTicker;
import com.aragaer.jtt.resources.RuntimeResources;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
Expand All @@ -18,7 +17,6 @@
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.*;
import android.os.Build;
import android.util.Log;
import android.widget.RemoteViews;

Expand All @@ -45,7 +43,7 @@ private static final class WidgetHolder {
}

static private final Map<Class<?>, WidgetHolder> classes = new HashMap<>();
static void draw_all(final Context c) {
public static void draw_all(final Context c) {
for (WidgetHolder holder : classes.values())
draw(c, null, holder);
}
Expand All @@ -65,37 +63,21 @@ protected JTTWidget(final int frequency, final Class<? extends WidgetPainter> pa
}
}

public void onReceive(Context c, Intent i) {
final String action = i.getAction();
if (action == null)
return;
if (action.equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE))
update(c, i);
else if (action.equals(AndroidTicker.ACTION_JTT_TICK))
tick(c, i, getClass());
else
Log.d("Widgets", "Got action "+action);
}

private void update(Context c, Intent i) {
Intent intent = new Intent(c, JttService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
c.startForegroundService(intent);
else
c.startService(intent);
int[] ids = i.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
draw(c, ids, classes.get(getClass()));
@Override public void onUpdate(Context context, AppWidgetManager manager, int[] ids) {
((JttApplication) context.getApplicationContext()).startTicker();
draw(context, ids, classes.get(getClass()));
}
}

private static void tick(Context c, Intent i, Class<?> cls) {
int wrapped = i.getIntExtra("jtt", 0);
final WidgetHolder holder = classes.get(cls);
Hour hour = Hour.fromTickNumber(wrapped, holder.granularity);
if (hour.equals(holder.last_update))
return;
holder.last_update = hour;
draw(c, null, holder);
public static void tick(Context context, Intent intent) {
int wrapped = intent.getIntExtra("jtt", 0);
for (WidgetHolder holder : classes.values()) {
Hour hour = Hour.fromTickNumber(wrapped, holder.granularity);
if (hour.equals(holder.last_update))
continue;
holder.last_update = hour;
draw(context, null, holder);
}
}

private static void draw(Context c, int[] ids, final WidgetHolder holder) {
Expand Down Expand Up @@ -229,7 +211,7 @@ public Bitmap get_bmp(Context c, Hour h) {

@Override
public String get_text(Context c, Hour h) {
return RuntimeResources.get(c).getStringResources().formatHourForWidget(h.num);
return ((JttApplication) c.getApplicationContext()).getStringResources().formatHourForWidget(h.num);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Component(modules={AstronomyModule.class,
CoreModule.class,
MechanicsModule.class})
interface ServiceComponent {
public interface JttComponent {
Ticker getTicker();
Clockwork provideClockwork();
IntervalProvider provideIntervalProvider();
Expand Down
Loading