1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 12:22:08 +01:00

Prewarm customTabs

This commit is contained in:
vanitasvitae 2016-09-21 22:49:37 +02:00
parent 52d6947d3e
commit bd8b5381ea
3 changed files with 23 additions and 2 deletions

View file

@ -42,6 +42,8 @@ import android.os.Handler;
import android.os.StrictMode; import android.os.StrictMode;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.annotation.NonNull; 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.AppBarLayout;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
@ -107,7 +109,7 @@ import info.guardianproject.netcipher.NetCipher;
import info.guardianproject.netcipher.webkit.WebkitProxy; import info.guardianproject.netcipher.webkit.WebkitProxy;
public class MainActivity extends AppCompatActivity 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; private static final int INPUT_FILE_REQUEST_CODE_NEW = 1;
@ -141,6 +143,7 @@ public class MainActivity extends AppCompatActivity
private Snackbar snackbarExitApp; private Snackbar snackbarExitApp;
private Snackbar snackbarNoInternet; private Snackbar snackbarNoInternet;
private String textToBeShared = null; private String textToBeShared = null;
private CustomTabsSession customTabsSession;
/** /**
* UI Bindings * UI Bindings
@ -196,6 +199,7 @@ public class MainActivity extends AppCompatActivity
podUserProfile.setListener(this); podUserProfile.setListener(this);
urls = new DiasporaUrlHelper(appSettings); urls = new DiasporaUrlHelper(appSettings);
customTabActivityHelper = new CustomTabActivityHelper(); customTabActivityHelper = new CustomTabActivityHelper();
customTabActivityHelper.setConnectionCallback(this);
setupUI(savedInstanceState); setupUI(savedInstanceState);
@ -1079,6 +1083,19 @@ public class MainActivity extends AppCompatActivity
invalidateOptionsMenu(); 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 { private class JavaScriptInterface {
@JavascriptInterface @JavascriptInterface
public void setUserProfile(final String webMessage) throws JSONException { public void setUserProfile(final String webMessage) throws JSONException {

View file

@ -118,6 +118,10 @@ public class CustomTabActivityHelper {
return session.mayLaunchUrl(uri, extras, otherLikelyBundles); 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 * A Callback for when the service is connected or disconnected. Use those callbacks to
* handle UI changes when the service is connected or disconnected * handle UI changes when the service is connected or disconnected

View file

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { 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' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong