VegeFruits v7.1版本的 MD5 值为:2ff167dfba698c783e879938fe00b9ce
以下内容为反编译后的 VKOpenAuthActivity.java 源代码,内容仅作参考
package com.vk.sdk;
import android.R;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import com.amazon.android.Kiwi;
import com.amazon.android.activity.AmazonActivity;
import java.util.Locale;
public class VKOpenAuthActivity extends AmazonActivity {
private static final String REDIRECT_URL = "https://oauth.vk.com/blank.html";
public static final String VK_EXTRA_API_VERSION = "version";
public static final String VK_EXTRA_CLIENT_ID = "client_id";
public static final String VK_EXTRA_REVOKE = "revoke";
public static final String VK_EXTRA_SCOPE = "scope";
public static final String VK_EXTRA_TOKEN_DATA = "extra-token-data";
public static final String VK_EXTRA_VALIDATION_URL = "extra-validation-url";
public static final String VK_RESULT_INTENT_NAME = "com.vk.auth-token";
protected WebView mWebView;
@Override
@SuppressLint({"SetJavaScriptEnabled"})
public void onCreate(Bundle savedInstanceState) {
Kiwi.onCreate((Activity) this, false);
super.onCreate(savedInstanceState);
setContentView(new VKOpenAuthView(this));
hideActionBar();
findViewById(R.id.content).setBackgroundColor(Color.rgb(240, 242, 245));
loadPage();
}
public void loadPage() {
try {
Log.d("DIS", "OpenAuth:loadPage()");
String urlToLoad = getIntent().getStringExtra(VK_EXTRA_VALIDATION_URL);
if (urlToLoad == null) {
int appId = getIntent().getIntExtra(VK_EXTRA_CLIENT_ID, 0);
String scope = getIntent().getStringExtra(VK_EXTRA_SCOPE);
String apiV = getIntent().getStringExtra("version");
boolean revoke = getIntent().getBooleanExtra(VK_EXTRA_REVOKE, false);
Locale locale = Locale.US;
Object[] objArr = new Object[5];
objArr[0] = Integer.valueOf(appId);
objArr[1] = scope;
objArr[2] = REDIRECT_URL;
objArr[3] = apiV;
objArr[4] = Integer.valueOf(revoke ? 1 : 0);
urlToLoad = String.format(locale, "https://oauth.vk.com/authorize?client_id=%s&scope=%s&redirect_uri=%s&display=mobile&v=%s&response_type=token&revoke=%d", objArr);
}
this.mWebView = (WebView) findViewById(R.id.copyUrl);
this.mWebView.setWebViewClient(new OAuthWebViewClient(this, null));
WebSettings webSettings = this.mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
this.mWebView.loadUrl(urlToLoad);
this.mWebView.setVisibility(4);
} catch (Exception e) {
Log.d("DIS", "OpenAuth:loadPage() Exception");
setResult(0);
finish();
}
}
@TargetApi(11)
private void hideActionBar() {
try {
if (Build.VERSION.SDK_INT >= 11 && getActionBar() != null) {
getActionBar().hide();
}
} catch (Exception e) {
}
}
public class OAuthWebViewClient extends WebViewClient {
public boolean canShowPage;
private OAuthWebViewClient() {
this.canShowPage = true;
}
OAuthWebViewClient(VKOpenAuthActivity vKOpenAuthActivity, OAuthWebViewClient oAuthWebViewClient) {
this();
}
private boolean processUrl(String url) {
if (!url.startsWith(VKOpenAuthActivity.REDIRECT_URL)) {
return false;
}
Intent data = new Intent(VKOpenAuthActivity.VK_RESULT_INTENT_NAME);
data.putExtra(VKOpenAuthActivity.VK_EXTRA_TOKEN_DATA, url.substring(url.indexOf(35) + 1));
if (VKOpenAuthActivity.this.getIntent().hasExtra(VKOpenAuthActivity.VK_EXTRA_VALIDATION_URL)) {
data.putExtra(VKOpenAuthActivity.VK_EXTRA_VALIDATION_URL, true);
}
VKOpenAuthActivity.this.setResult(-1, data);
VKOpenAuthActivity.this.finish();
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (processUrl(url)) {
return true;
}
this.canShowPage = true;
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
processUrl(url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (this.canShowPage) {
view.setVisibility(0);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
this.canShowPage = false;
Log.d("DIS", "AlertDialog.Builder builder = new AlertDialog.Builder(VKOpenAuthActivity.this)");
Context context = VKUIHelper.getTopActivity();
int btnRetryId = context.getResources().getIdentifier("vk_retry", "string", context.getPackageName());
Log.d("DIS", "btnRetryId = " + btnRetryId);
AlertDialog.Builder builder = new AlertDialog.Builder(VKOpenAuthActivity.this).setMessage(description).setPositiveButton(btnRetryId, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
VKOpenAuthActivity.this.loadPage();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
VKOpenAuthActivity.this.finish();
}
});
builder.setCancelable(false);
try {
builder.show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onBackPressed() {
Intent data = new Intent(VK_RESULT_INTENT_NAME);
setResult(0, data);
super.onBackPressed();
}
private static class VKOpenAuthView extends RelativeLayout {
public VKOpenAuthView(Context context) {
super(context);
ProgressBar progress = new ProgressBar(context);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(-2, -2);
lp.addRule(13, 1);
progress.setLayoutParams(lp);
addView(progress);
WebView webView = new WebView(context);
webView.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
addView(webView);
webView.setId(R.id.copyUrl);
webView.setVisibility(4);
}
}
}