-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
89 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 9 additions & 20 deletions
29
...y/app/receiver/service/UITickService.java → ...fazziclay/opentoday/ui/UITickService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,36 @@ | ||
package ru.fazziclay.opentoday.app.receiver.service; | ||
package ru.fazziclay.opentoday.ui; | ||
|
||
import android.app.Service; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Handler; | ||
import android.os.IBinder; | ||
import android.os.Looper; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import ru.fazziclay.opentoday.app.receiver.ItemsTickReceiver; | ||
|
||
// Тик во время активного интерфейса приложения (раз в секунду) для того что бы изменения | ||
// Были видры резче | ||
public class UITickService extends Service { | ||
public class UITickService { | ||
private final Context context; | ||
private final Handler handler; | ||
private final Runnable runnable = this::tick; | ||
|
||
public UITickService() { | ||
public UITickService(Context context) { | ||
this.context = context; | ||
this.handler = new Handler(Looper.myLooper()); | ||
} | ||
|
||
public void tick() { | ||
sendBroadcast(new Intent(this, ItemsTickReceiver.class)); | ||
context.sendBroadcast(new Intent(context, ItemsTickReceiver.class)); | ||
this.handler.removeCallbacks(runnable); | ||
long millis = System.currentTimeMillis() % 1000; | ||
this.handler.postDelayed(runnable, 1000 - millis); | ||
} | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
public void create() { | ||
handler.post(runnable); | ||
return super.onStartCommand(intent, flags, startId); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
public void destroy() { | ||
handler.removeCallbacks(runnable); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters