mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
improved screen event log
This commit is contained in:
parent
871b0a98d9
commit
a10b83eb01
@ -27,9 +27,7 @@ import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.os.BatteryManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.util.JsonSerializer;
|
||||
@ -198,7 +196,7 @@ public class HotMobiLogger {
|
||||
mExecutor.execute(new WriteLogTask(mApplication, accountId, type, events));
|
||||
}
|
||||
|
||||
public static void logScreenEvent(Context context, ScreenEvent.Action action) {
|
||||
getInstance(context).log(ScreenEvent.create(context, action));
|
||||
public static void logScreenEvent(Context context, ScreenEvent.Action action, long presentDuration) {
|
||||
getInstance(context).log(ScreenEvent.create(context, action, presentDuration));
|
||||
}
|
||||
}
|
||||
|
@ -33,11 +33,14 @@ public class ScreenEvent extends BaseEvent {
|
||||
|
||||
@JsonField(name = "action", typeConverter = Action.ScreenActionConverter.class)
|
||||
Action action;
|
||||
@JsonField(name = "present_duration")
|
||||
long presentDuration;
|
||||
|
||||
public static ScreenEvent create(Context context, Action action) {
|
||||
public static ScreenEvent create(Context context, Action action, long presentDuration) {
|
||||
final ScreenEvent event = new ScreenEvent();
|
||||
event.markStart(context);
|
||||
event.setAction(action);
|
||||
event.setPresentDuration(presentDuration);
|
||||
return event;
|
||||
}
|
||||
|
||||
@ -49,15 +52,24 @@ public class ScreenEvent extends BaseEvent {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public long getPresentDuration() {
|
||||
return presentDuration;
|
||||
}
|
||||
|
||||
public void setPresentDuration(long presentDuration) {
|
||||
this.presentDuration = presentDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScreenEvent{" +
|
||||
"action=" + action +
|
||||
", presentDuration=" + presentDuration +
|
||||
"} " + super.toString();
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
ON("on"), OFF("off"), UNKNOWN("unknown");
|
||||
ON("on"), OFF("off"), PRESENT("present"), UNKNOWN("unknown");
|
||||
private final String value;
|
||||
|
||||
Action(String value) {
|
||||
@ -69,6 +81,8 @@ public class ScreenEvent extends BaseEvent {
|
||||
return ON;
|
||||
} else if (OFF.value.equalsIgnoreCase(action)) {
|
||||
return OFF;
|
||||
} else if (PRESENT.value.equalsIgnoreCase(action)) {
|
||||
return PRESENT;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.model.AccountPreferences;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Mentions;
|
||||
@ -148,19 +148,32 @@ public class RefreshService extends Service implements Constants {
|
||||
};
|
||||
|
||||
private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
|
||||
public long mPresentTime = -1;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case Intent.ACTION_SCREEN_ON: {
|
||||
HotMobiLogger.logScreenEvent(context, ScreenEvent.Action.ON);
|
||||
HotMobiLogger.logScreenEvent(context, ScreenEvent.Action.ON, getPresentDuration());
|
||||
break;
|
||||
}
|
||||
case Intent.ACTION_SCREEN_OFF: {
|
||||
HotMobiLogger.logScreenEvent(context, ScreenEvent.Action.OFF);
|
||||
HotMobiLogger.logScreenEvent(context, ScreenEvent.Action.OFF, getPresentDuration());
|
||||
mPresentTime = -1;
|
||||
break;
|
||||
}
|
||||
case Intent.ACTION_USER_PRESENT: {
|
||||
mPresentTime = SystemClock.elapsedRealtime();
|
||||
HotMobiLogger.logScreenEvent(context, ScreenEvent.Action.PRESENT, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long getPresentDuration() {
|
||||
if (mPresentTime < 0) return -1;
|
||||
return SystemClock.elapsedRealtime() - mPresentTime;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
@ -196,6 +209,7 @@ public class RefreshService extends Service implements Constants {
|
||||
final IntentFilter screenFilter = new IntentFilter();
|
||||
screenFilter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
screenFilter.addAction(Intent.ACTION_USER_PRESENT);
|
||||
registerReceiver(mPowerStateReceiver, batteryFilter);
|
||||
registerReceiver(mScreenStateReceiver, screenFilter);
|
||||
PowerStateReceiver.setServiceReceiverStarted(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user