com.backendless.SocialAsyncCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of android Show documentation
Show all versions of android Show documentation
Android SDK used by developers to provide Backendless API in apps.
package com.backendless;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.RelativeLayout;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.social.AbstractSocialLoginStrategy;
import org.json.JSONObject;
public class SocialAsyncCallback implements AsyncCallback
{
private AbstractSocialLoginStrategy loginStrategy;
private AsyncCallback responder;
public SocialAsyncCallback( AbstractSocialLoginStrategy loginStrategy, AsyncCallback responder )
{
this.loginStrategy = loginStrategy;
this.responder = responder;
loginStrategy.createSpinner();
}
@Override
public void handleResponse( String response )
{
WebView webView = loginStrategy.getWebView();
final Context context = loginStrategy.getContext();
final ProgressDialog spinner = loginStrategy.getSpinner();
if( webView == null )
{
webView = new android.webkit.WebView( context );
loginStrategy.setWebView( webView );
}
if( Build.VERSION.SDK_INT >= 11 )
webView.setLayerType( View.LAYER_TYPE_SOFTWARE, null );
String jsMethodName = new StringBuilder( "Backendless_Android_" ).append( Backendless.getApplicationId().replace( "-", "_" ) ).append( "_" ).append( Backendless.getVersion() ).toString();
webView.addJavascriptInterface( loginStrategy.getJSInterface( responder ), jsMethodName );
webView.getSettings().setJavaScriptEnabled( true );
webView.getSettings().setLoadWithOverviewMode( false );
webView.getSettings().setDefaultTextEncodingName( "utf-8" );
webView.setHorizontalScrollBarEnabled( true );
webView.setVerticalScrollBarEnabled( true );
webView.getSettings().setSavePassword( false );
webView.setLayoutParams( new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) );
webView.setWebViewClient( new android.webkit.WebViewClient()
{
@Override
public void onPageFinished( android.webkit.WebView view, String url )
{
if( spinner.isShowing() )
spinner.dismiss();
}
@Override
public void onPageStarted( android.webkit.WebView view, String url, android.graphics.Bitmap favicon )
{
if( !loginStrategy.getContext().isFinishing() && !spinner.isShowing() )
spinner.show();
}
@Override
public void onReceivedSslError( android.webkit.WebView view, android.webkit.SslErrorHandler handler,
android.net.http.SslError error )
{
//TODO add ssl
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading( android.webkit.WebView view, String url )
{
if( url.startsWith( "market://" ) )
return true;
return false;
}
} );
webView.requestFocus( View.FOCUS_DOWN );
loginStrategy.createLayout();
webView.loadUrl( response );
}
@Override
public void handleFault( BackendlessFault fault )
{
if( responder != null )
responder.handleFault( fault );
}
}