From bd8b5381ea5fcfc29cad36aba61cd22084d3e941 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Wed, 21 Sep 2016 22:49:37 +0200 Subject: [PATCH] Prewarm customTabs --- .../activity/MainActivity.java | 19 ++++++++++++++++++- .../CustomTabActivityHelper.java | 4 ++++ build.gradle | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index c736489e..1bc40b64 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -42,6 +42,8 @@ import android.os.Handler; import android.os.StrictMode; import android.provider.MediaStore; import android.support.annotation.NonNull; +import android.support.customtabs.CustomTabsClient; +import android.support.customtabs.CustomTabsSession; import android.support.design.widget.AppBarLayout; import android.support.design.widget.NavigationView; import android.support.design.widget.Snackbar; @@ -107,7 +109,7 @@ import info.guardianproject.netcipher.NetCipher; import info.guardianproject.netcipher.webkit.WebkitProxy; public class MainActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener { + implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener, CustomTabActivityHelper.ConnectionCallback { private static final int INPUT_FILE_REQUEST_CODE_NEW = 1; @@ -141,6 +143,7 @@ public class MainActivity extends AppCompatActivity private Snackbar snackbarExitApp; private Snackbar snackbarNoInternet; private String textToBeShared = null; + private CustomTabsSession customTabsSession; /** * UI Bindings @@ -196,6 +199,7 @@ public class MainActivity extends AppCompatActivity podUserProfile.setListener(this); urls = new DiasporaUrlHelper(appSettings); customTabActivityHelper = new CustomTabActivityHelper(); + customTabActivityHelper.setConnectionCallback(this); setupUI(savedInstanceState); @@ -1079,6 +1083,19 @@ public class MainActivity extends AppCompatActivity invalidateOptionsMenu(); } + @Override + public void onCustomTabsConnected() { + if(customTabsSession == null) { + AppLog.i(this, "CustomTabs warmup: "+customTabActivityHelper.warmup(0)); + customTabsSession = customTabActivityHelper.getSession(); + } + } + + @Override + public void onCustomTabsDisconnected() { + + } + private class JavaScriptInterface { @JavascriptInterface public void setUserProfile(final String webMessage) throws JSONException { diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabActivityHelper.java b/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabActivityHelper.java index e43ce0b0..2ab3fc3b 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabActivityHelper.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabActivityHelper.java @@ -118,6 +118,10 @@ public class CustomTabActivityHelper { return session.mayLaunchUrl(uri, extras, otherLikelyBundles); } + public boolean warmup(int flags) { + return mClient.warmup(flags); + } + /** * A Callback for when the service is connected or disconnected. Use those callbacks to * handle UI changes when the service is connected or disconnected diff --git a/build.gradle b/build.gradle index 052b2e6a..54903cde 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:2.2.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // NOTE: Do not place your application dependencies here; they belong