BackgroundManager.java
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.crashlytics.android.answers;
import io.fabric.sdk.android.Fabric;
import io.fabric.sdk.android.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
class BackgroundManager
{
private static final int BACKGROUND_DELAY = 5000;
final AtomicReference<ScheduledFuture<?>> backgroundFutureRef = new AtomicReference();
private final ScheduledExecutorService executorService;
private volatile boolean flushOnBackground = true;
boolean inBackground = true;
private final List<Listener> listeners = new ArrayList();
public BackgroundManager(ScheduledExecutorService paramScheduledExecutorService)
{
this.executorService = paramScheduledExecutorService;
}
private void notifyBackground()
{
Iterator localIterator = this.listeners.iterator();
while (localIterator.hasNext()) {
((Listener)localIterator.next()).onBackground();
}
}
public void onActivityPaused()
{
if ((this.flushOnBackground) && (!this.inBackground)) {
this.inBackground = true;
}
try
{
this.backgroundFutureRef.compareAndSet(null, this.executorService.schedule(new Runnable()
{
public void run()
{
BackgroundManager.this.backgroundFutureRef.set(null);
BackgroundManager.this.notifyBackground();
}
}, 5000L, TimeUnit.MILLISECONDS));
return;
}
catch (RejectedExecutionException localRejectedExecutionException)
{
Fabric.getLogger().d("Answers", "Failed to schedule background detector", localRejectedExecutionException);
}
}
public void onActivityResumed()
{
this.inBackground = false;
ScheduledFuture localScheduledFuture = (ScheduledFuture)this.backgroundFutureRef.getAndSet(null);
if (localScheduledFuture != null) {
localScheduledFuture.cancel(false);
}
}
public void registerListener(Listener paramListener)
{
this.listeners.add(paramListener);
}
public void setFlushOnBackground(boolean paramBoolean)
{
this.flushOnBackground = paramBoolean;
}
public static abstract interface Listener
{
public abstract void onBackground();
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/crashlytics/android/answers/BackgroundManager.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/