ForegroundDetector.smali
.class public Lim/tpelyyftgw/ui/components/ForegroundDetector;
.super Ljava/lang/Object;
.source "ForegroundDetector.java"
# interfaces
.implements Landroid/app/Application$ActivityLifecycleCallbacks;
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
}
.end annotation
# static fields
.field private static Instance:Lim/tpelyyftgw/ui/components/ForegroundDetector;
# instance fields
.field private enterBackgroundTime:J
.field private listeners:Ljava/util/concurrent/CopyOnWriteArrayList;
.annotation system Ldalvik/annotation/Signature;
value = {
"Ljava/util/concurrent/CopyOnWriteArrayList<",
"Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;",
">;"
}
.end annotation
.end field
.field private refs:I
.field private wasInBackground:Z
# direct methods
.method static constructor <clinit>()V
.registers 1
.line 28
const/4 v0, 0x0
sput-object v0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->Instance:Lim/tpelyyftgw/ui/components/ForegroundDetector;
return-void
.end method
.method public constructor <init>(Landroid/app/Application;)V
.registers 4
.param p1, "application" # Landroid/app/Application;
.line 34
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 25
const/4 v0, 0x1
iput-boolean v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->wasInBackground:Z
.line 26
const-wide/16 v0, 0x0
iput-wide v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->enterBackgroundTime:J
.line 27
new-instance v0, Ljava/util/concurrent/CopyOnWriteArrayList;
invoke-direct {v0}, Ljava/util/concurrent/CopyOnWriteArrayList;-><init>()V
iput-object v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->listeners:Ljava/util/concurrent/CopyOnWriteArrayList;
.line 35
sput-object p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->Instance:Lim/tpelyyftgw/ui/components/ForegroundDetector;
.line 36
invoke-virtual {p1, p0}, Landroid/app/Application;->registerActivityLifecycleCallbacks(Landroid/app/Application$ActivityLifecycleCallbacks;)V
.line 37
return-void
.end method
.method public static getInstance()Lim/tpelyyftgw/ui/components/ForegroundDetector;
.registers 1
.line 31
sget-object v0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->Instance:Lim/tpelyyftgw/ui/components/ForegroundDetector;
return-object v0
.end method
# virtual methods
.method public addListener(Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;)V
.registers 3
.param p1, "listener" # Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
.line 48
iget-object v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->listeners:Ljava/util/concurrent/CopyOnWriteArrayList;
invoke-virtual {v0, p1}, Ljava/util/concurrent/CopyOnWriteArrayList;->add(Ljava/lang/Object;)Z
.line 49
return-void
.end method
.method public isBackground()Z
.registers 2
.line 44
iget v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->refs:I
if-nez v0, :cond_6
const/4 v0, 0x1
goto :goto_7
:cond_6
const/4 v0, 0x0
:goto_7
return v0
.end method
.method public isForeground()Z
.registers 2
.line 40
iget v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->refs:I
if-lez v0, :cond_6
const/4 v0, 0x1
goto :goto_7
:cond_6
const/4 v0, 0x0
:goto_7
return v0
.end method
.method public isWasInBackground(Z)Z
.registers 7
.param p1, "reset" # Z
.line 75
if-eqz p1, :cond_18
sget v0, Landroid/os/Build$VERSION;->SDK_INT:I
const/16 v1, 0x15
if-lt v0, v1, :cond_18
invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
move-result-wide v0
iget-wide v2, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->enterBackgroundTime:J
sub-long/2addr v0, v2
const-wide/16 v2, 0xc8
cmp-long v4, v0, v2
if-gez v4, :cond_18
.line 76
const/4 v0, 0x0
iput-boolean v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->wasInBackground:Z
.line 78
:cond_18
iget-boolean v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->wasInBackground:Z
return v0
.end method
.method public onActivityCreated(Landroid/app/Activity;Landroid/os/Bundle;)V
.registers 3
.param p1, "activity" # Landroid/app/Activity;
.param p2, "savedInstanceState" # Landroid/os/Bundle;
.line 105
return-void
.end method
.method public onActivityDestroyed(Landroid/app/Activity;)V
.registers 2
.param p1, "activity" # Landroid/app/Activity;
.line 121
return-void
.end method
.method public onActivityPaused(Landroid/app/Activity;)V
.registers 2
.param p1, "activity" # Landroid/app/Activity;
.line 113
return-void
.end method
.method public onActivityResumed(Landroid/app/Activity;)V
.registers 2
.param p1, "activity" # Landroid/app/Activity;
.line 109
return-void
.end method
.method public onActivitySaveInstanceState(Landroid/app/Activity;Landroid/os/Bundle;)V
.registers 3
.param p1, "activity" # Landroid/app/Activity;
.param p2, "outState" # Landroid/os/Bundle;
.line 117
return-void
.end method
.method public onActivityStarted(Landroid/app/Activity;)V
.registers 7
.param p1, "activity" # Landroid/app/Activity;
.line 57
iget v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->refs:I
const/4 v1, 0x1
add-int/2addr v0, v1
iput v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->refs:I
if-ne v0, v1, :cond_3c
.line 58
invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
move-result-wide v0
iget-wide v2, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->enterBackgroundTime:J
sub-long/2addr v0, v2
const-wide/16 v2, 0xc8
cmp-long v4, v0, v2
if-gez v4, :cond_18
.line 59
const/4 v0, 0x0
iput-boolean v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->wasInBackground:Z
.line 61
:cond_18
sget-boolean v0, Lim/tpelyyftgw/messenger/BuildVars;->LOGS_ENABLED:Z
if-eqz v0, :cond_21
.line 62
const-string v0, "switch to foreground"
invoke-static {v0}, Lim/tpelyyftgw/messenger/FileLog;->d(Ljava/lang/String;)V
.line 64
:cond_21
iget-object v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->listeners:Ljava/util/concurrent/CopyOnWriteArrayList;
invoke-virtual {v0}, Ljava/util/concurrent/CopyOnWriteArrayList;->iterator()Ljava/util/Iterator;
move-result-object v0
:goto_27
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v1
if-eqz v1, :cond_3c
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
.line 66
.local v1, "listener":Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
:try_start_33
invoke-interface {v1}, Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;->onBecameForeground()V
:try_end_36
.catch Ljava/lang/Exception; {:try_start_33 .. :try_end_36} :catch_37
.line 69
goto :goto_3b
.line 67
:catch_37
move-exception v2
.line 68
.local v2, "e":Ljava/lang/Exception;
invoke-static {v2}, Lim/tpelyyftgw/messenger/FileLog;->e(Ljava/lang/Throwable;)V
.line 70
.end local v1 # "listener":Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
.end local v2 # "e":Ljava/lang/Exception;
:goto_3b
goto :goto_27
.line 72
:cond_3c
return-void
.end method
.method public onActivityStopped(Landroid/app/Activity;)V
.registers 6
.param p1, "activity" # Landroid/app/Activity;
.line 87
iget v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->refs:I
const/4 v1, 0x1
sub-int/2addr v0, v1
iput v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->refs:I
if-nez v0, :cond_34
.line 88
invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
move-result-wide v2
iput-wide v2, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->enterBackgroundTime:J
.line 89
iput-boolean v1, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->wasInBackground:Z
.line 90
sget-boolean v0, Lim/tpelyyftgw/messenger/BuildVars;->LOGS_ENABLED:Z
if-eqz v0, :cond_19
.line 91
const-string v0, "switch to background"
invoke-static {v0}, Lim/tpelyyftgw/messenger/FileLog;->d(Ljava/lang/String;)V
.line 93
:cond_19
iget-object v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->listeners:Ljava/util/concurrent/CopyOnWriteArrayList;
invoke-virtual {v0}, Ljava/util/concurrent/CopyOnWriteArrayList;->iterator()Ljava/util/Iterator;
move-result-object v0
:goto_1f
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v1
if-eqz v1, :cond_34
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
.line 95
.local v1, "listener":Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
:try_start_2b
invoke-interface {v1}, Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;->onBecameBackground()V
:try_end_2e
.catch Ljava/lang/Exception; {:try_start_2b .. :try_end_2e} :catch_2f
.line 98
goto :goto_33
.line 96
:catch_2f
move-exception v2
.line 97
.local v2, "e":Ljava/lang/Exception;
invoke-static {v2}, Lim/tpelyyftgw/messenger/FileLog;->e(Ljava/lang/Throwable;)V
.line 99
.end local v1 # "listener":Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
.end local v2 # "e":Ljava/lang/Exception;
:goto_33
goto :goto_1f
.line 101
:cond_34
return-void
.end method
.method public removeListener(Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;)V
.registers 3
.param p1, "listener" # Lim/tpelyyftgw/ui/components/ForegroundDetector$Listener;
.line 52
iget-object v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->listeners:Ljava/util/concurrent/CopyOnWriteArrayList;
invoke-virtual {v0, p1}, Ljava/util/concurrent/CopyOnWriteArrayList;->remove(Ljava/lang/Object;)Z
.line 53
return-void
.end method
.method public resetBackgroundVar()V
.registers 2
.line 82
const/4 v0, 0x0
iput-boolean v0, p0, Lim/tpelyyftgw/ui/components/ForegroundDetector;->wasInBackground:Z
.line 83
return-void
.end method