forked from upstream-mirrors/quik
Don't show QK Reply while in app
This commit is contained in:
@@ -34,6 +34,7 @@ import com.android.mms.util.RateController;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
import com.moez.QKSMS.common.AnalyticsManager;
|
||||
import com.moez.QKSMS.common.LifecycleHandler;
|
||||
import com.moez.QKSMS.common.LiveViewManager;
|
||||
import com.moez.QKSMS.common.google.DraftCache;
|
||||
import com.moez.QKSMS.common.google.PduLoaderManager;
|
||||
@@ -89,6 +90,8 @@ public class QKSMSAppBase extends MultiDexApplication {
|
||||
mPduLoaderManager = new PduLoaderManager(context);
|
||||
mThumbnailManager = new ThumbnailManager(context);
|
||||
|
||||
registerActivityLifecycleCallbacks(new LifecycleHandler());
|
||||
|
||||
ThemeManager.init(this);
|
||||
MmsConfig.init(this);
|
||||
Contact.init(this);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.moez.QKSMS.common;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* http://stackoverflow.com/questions/3667022/checking-if-an-android-application-is-running-in-the-background/
|
||||
*/
|
||||
public class LifecycleHandler implements Application.ActivityLifecycleCallbacks {
|
||||
private final String TAG = "LifecycleHandler";
|
||||
|
||||
private static int sResumed;
|
||||
private static int sPaused;
|
||||
private static int sStarted;
|
||||
private static int sStopped;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
sResumed++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
sPaused++;
|
||||
Log.i("test", "application is in foreground: " + (sResumed > sPaused));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
sStarted++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
sStopped++;
|
||||
Log.i("test", "application is visible: " + (sStarted > sStopped));
|
||||
}
|
||||
|
||||
public static boolean isApplicationVisible() {
|
||||
return sStarted > sStopped;
|
||||
}
|
||||
|
||||
public static boolean isApplicationInForeground() {
|
||||
return sResumed > sPaused;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,12 @@ import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.IBinder;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import com.moez.QKSMS.common.ConversationPrefsHelper;
|
||||
import com.moez.QKSMS.common.LifecycleHandler;
|
||||
import com.moez.QKSMS.data.ContactHelper;
|
||||
import com.moez.QKSMS.data.Message;
|
||||
import com.moez.QKSMS.common.ConversationPrefsHelper;
|
||||
import com.moez.QKSMS.transaction.SmsHelper;
|
||||
import com.moez.QKSMS.ui.MainActivity;
|
||||
import com.moez.QKSMS.ui.popup.QKReplyActivity;
|
||||
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
||||
|
||||
@@ -53,7 +52,7 @@ public class NotificationService extends Service {
|
||||
|
||||
if (conversationPrefs.getNotificationsEnabled()) {
|
||||
// Only show QuickReply if we're outside of the app, and they have popups and QuickReply enabled.
|
||||
if (!QKReplyActivity.sIsShowing && message.getThreadId() != MainActivity.sThreadShowing &&
|
||||
if (!LifecycleHandler.isApplicationVisible() &&
|
||||
intent.getBooleanExtra(EXTRA_POPUP, false) && prefs.getBoolean(SettingsFragment.QUICKREPLY, true)) {
|
||||
|
||||
popupIntent = new Intent(context, QKReplyActivity.class);
|
||||
|
||||
@@ -40,7 +40,6 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface.
|
||||
public static final String EXTRA_THREAD_ID = "thread_id";
|
||||
public static final String EXTRA_SHOW_KEYBOARD = "open_keyboard";
|
||||
|
||||
public static boolean sIsShowing = false;
|
||||
private static long sThreadId;
|
||||
|
||||
private Conversation mConversation;
|
||||
@@ -141,8 +140,6 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface.
|
||||
|
||||
mComposeView.saveDraft();
|
||||
|
||||
sIsShowing = false;
|
||||
|
||||
// When the home button is pressed, this ensures that the QK Reply is shut down
|
||||
// Don't shut it down if it pauses and the screen is off though
|
||||
if (!mIsStartingActivity && !isChangingConfigurations() && isScreenOn()) {
|
||||
@@ -163,7 +160,6 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface.
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
sIsShowing = true;
|
||||
sThreadId = mConversationLegacy.getThreadId();
|
||||
mIsStartingActivity = false;
|
||||
ThemeManager.setActiveColor(mConversationPrefsHelper.getColor());
|
||||
@@ -273,7 +269,6 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface.
|
||||
*/
|
||||
public static void dismiss(long threadId) {
|
||||
if (sThreadId == threadId) {
|
||||
sIsShowing = false;
|
||||
sThreadId = 0;
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user