Commit c13e619e authored by fallenstardust's avatar fallenstardust

更换浏览器

parent 03268629
......@@ -1867,6 +1867,9 @@ void Game::CloseDuelWindow() {
wReplaySave->setVisible(false);
stHintMsg->setVisible(false);
btnSideOK->setVisible(false);
btnSideShuffle->setVisible(false);
btnSideSort->setVisible(false);
btnSideReload->setVisible(false);
btnLeaveGame->setVisible(false);
btnSpectatorSwap->setVisible(false);
btnChainIgnore->setVisible(false);
......
......@@ -81,8 +81,7 @@ dependencies {
implementation 'com.tubb.smrv:swipemenu-recyclerview:5.4.0'
//
implementation(name: 'libWindbot', ext: 'aar')
//
mycardImplementation(name: 'xwalk_core_library-22.52.561.4', ext: 'aar')
//mycardImplementation(name: 'xwalk_core_library-22.52.561.4', ext: 'aar')
implementation 'com.nightonke:boommenu:2.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
......
......@@ -24,7 +24,7 @@ public interface Constants {
String PREF_OPENGL_VERSION = "pref_key_game_ogles_config";
int PREF_DEF_OPENGL_VERSION = 1;
String PREF_PENDULUM_SCALE = "pref_key_game_lab_pendulum_scale";
boolean PREF_DEF_PENDULUM_SCALE = false;
boolean PREF_DEF_PENDULUM_SCALE = true;
String PREF_SOUND_EFFECT = "pref_key_game_sound_effect";
boolean PREF_DEF_SOUND_EFFECT = true;
String PREF_LOCK_SCREEN = "pref_key_game_screen_orientation";
......
......@@ -26,7 +26,7 @@ public class WebActivity extends BaseActivity {
setSupportActionBar(toolbar);
enableBackHome();
mWebViewPlus = $(R.id.webbrowser);
mWebViewPlus.enableHtml5();
/*mWebViewPlus.enableHtml5();
mWebViewPlus.setWebChromeClient(new DefWebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
......@@ -37,7 +37,7 @@ public class WebActivity extends BaseActivity {
setTitle(title);
}
}
});
});*/
if (doIntent(getIntent())) {
mWebViewPlus.loadUrl(mUrl);
}
......@@ -93,14 +93,14 @@ public class WebActivity extends BaseActivity {
@Override
protected void onResume() {
mWebViewPlus.resumeTimers();
mWebViewPlus.onShow();
//mWebViewPlus.onShow();
super.onResume();
}
@Override
protected void onPause() {
mWebViewPlus.pauseTimers();
mWebViewPlus.onHide();
//mWebViewPlus.onHide();
super.onPause();
}
......@@ -109,7 +109,7 @@ public class WebActivity extends BaseActivity {
mWebViewPlus.stopLoading();
mWebViewPlus.setWebChromeClient(null);
mWebViewPlus.setWebViewClient(null);
mWebViewPlus.onDestroy();
//mWebViewPlus.onDestroy();
super.onDestroy();
}
......
......@@ -372,10 +372,11 @@ abstract class HomeActivity extends BaseActivity implements NavigationView.OnNav
}
private void checkForceUpdateSilent() {
UpdateHelper.getInstance().init(getApplicationContext(), Color.parseColor("#0A93DB"));
UpdateHelper.getInstance().init(getContext(), Color.parseColor("#0A93DB"));
UpdateHelper.getInstance().setDebugMode(false);
long intervalMillis = 0 * 1000L;
UpdateHelper.getInstance().autoUpdate(getPackageName(), false, intervalMillis);
UpdateHelper.getInstance().manualUpdate(getPackageName());
/*long intervalMillis = 0 * 1000L;
UpdateHelper.getInstance().autoUpdate(getPackageName(), false, intervalMillis);*/
}
public void AnimationShake(){
......
package cn.garymb.ygomobile.ui.plus;
import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import com.tencent.smtt.export.external.interfaces.ConsoleMessage;
import com.tencent.smtt.sdk.WebChromeClient;
import cn.garymb.ygomobile.lite.BuildConfig;
public class DefWebChromeClient extends WebChromeClient {
@Override
/* @Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
super.onConsoleMessage(message, lineNumber, sourceID);
if (BuildConfig.DEBUG)
......@@ -19,5 +20,5 @@ public class DefWebChromeClient extends WebChromeClient {
if (BuildConfig.DEBUG)
Log.i("webview", consoleMessage.sourceId() + ":" + consoleMessage.lineNumber() + "\n" + consoleMessage.message());
return true;
}
}*/
}
package cn.garymb.ygomobile.ui.plus;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
public class DefWebViewClient extends WebViewClient {
@Override
......
......@@ -3,10 +3,10 @@ package cn.garymb.ygomobile.ui.widget;
import android.content.Context;
import android.util.AttributeSet;
import cn.garymb.ygomobile.ui.plus.XWebView;
import cn.garymb.ygomobile.ui.plus.X5WebView;
public class WebViewPlus extends XWebView {
public class WebViewPlus extends X5WebView {
public WebViewPlus(Context context) {
super(context);
}
......
......@@ -81,7 +81,6 @@
app:bmb_piecePlaceEnum="piecePlace_dot_9_1">
<ImageView
android:id="@+id/cube2"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center"
......
......@@ -9,7 +9,7 @@ import android.net.Uri;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.JavascriptInterface;
import org.json.JSONArray;
......@@ -26,7 +26,8 @@ import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.YGOStarter;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.plus.DefWebViewClient;
import cn.garymb.ygomobile.ui.online.mcchat.management.UserManagement;
import com.tencent.smtt.sdk.*;
import static junit.framework.Assert.assertEquals;
......@@ -191,40 +192,40 @@ public class MyCard {
mListener = listener;
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void edit_deck() {
activity.startActivity(new Intent(activity, DeckManagerActivity.class));
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void watch_replay() {
if (mListener != null) {
activity.runOnUiThread(mListener::watchReplay);
}
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void puzzle_mode() {
if (mListener != null) {
activity.runOnUiThread(mListener::puzzleMode);
}
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void openDrawer() {
if (mListener != null) {
activity.runOnUiThread(mListener::openDrawer);
}
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void backHome() {
if (mListener != null) {
activity.runOnUiThread(mListener::backHome);
}
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void share(String text) {
if (mListener != null) {
activity.runOnUiThread(() -> {
......@@ -233,14 +234,14 @@ public class MyCard {
}
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void closeDrawer() {
if (mListener != null) {
activity.runOnUiThread(mListener::closeDrawer);
}
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void join(String host, int port, String name, String room) {
try {
final YGOGameOptions options = new YGOGameOptions();
......@@ -266,7 +267,7 @@ public class MyCard {
* return: 文件名数组的 JSON 字符串
* 失败抛异常或返回空数组
*/
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public String readdir(String path) {
File file = new File(settings.getResourcePath(), path);
String[] result = file.list();
......@@ -279,7 +280,7 @@ public class MyCard {
* return: 文件内容的 base64
* 读取失败抛异常
*/
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public String readFile(String path) throws IOException {
File file = new File(settings.getResourcePath(), path);
byte[] result = new byte[(int) file.length()];
......@@ -295,7 +296,7 @@ public class MyCard {
* data: 文件内容的 base64
* 写入失败抛异常
*/
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void writeFile(String path, String data) throws IOException {
File file = new File(settings.getResourcePath(), path);
FileOutputStream stream = new FileOutputStream(file);
......@@ -307,7 +308,7 @@ public class MyCard {
* 删除文件
* 删除失败返回 false
*/
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public boolean unlink(String path) {
File file = new File(settings.getResourcePath(), path);
lastModified.edit().remove(path).apply();
......@@ -320,13 +321,13 @@ public class MyCard {
* return: 修改时间
* 文件不存在返回 0
*/
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public long getFileLastModified(String path) {
File file = new File(settings.getResourcePath(), path);
return getWrappedLastModified(path, file.lastModified());
}
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void updateUser(String name, String headurl, String status) {
if (mListener != null) {
mUser.name = name;
......@@ -345,7 +346,7 @@ public class MyCard {
* path: 文件绝对路径
* time: 时间
*/
@org.xwalk.core.JavascriptInterface
@JavascriptInterface
public void setFileLastModified(String path, long time) {
File file = new File(settings.getResourcePath(), path);
if (file.setLastModified(time)) {
......
......@@ -16,13 +16,12 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import org.xwalk.core.XWalkSettings;
import org.xwalk.core.XWalkUIClient;
import org.xwalk.core.XWalkView;
import com.tencent.smtt.sdk.*;
import java.text.MessageFormat;
......@@ -32,6 +31,7 @@ import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.activities.BaseActivity;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.online.mcchat.SplashActivity;
import cn.garymb.ygomobile.ui.plus.X5WebView;
public class MyCardActivity extends BaseActivity implements MyCard.MyCardListener, NavigationView.OnNavigationItemSelectedListener {
......@@ -41,6 +41,8 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
private ImageView mHeadView;
private TextView mNameView, mStatusView;
private ProgressBar mProgressBar;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -56,6 +58,8 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
mMyCard = new MyCard(this);
mWebViewPlus = $(R.id.webbrowser);
mDrawerlayout = $(R.id.drawer_layout);
mProgressBar = $(R.id.progressBar);
mProgressBar.setMax(100);
NavigationView navigationView = $(R.id.nav_main);
navigationView.setNavigationItemSelectedListener(this);
......@@ -63,9 +67,9 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
mHeadView = (ImageView) navHead.findViewById(R.id.img_head);
mNameView = (TextView) navHead.findViewById(R.id.tv_name);
mStatusView = (TextView) navHead.findViewById(R.id.tv_dp);
mWebViewPlus.enableHtml5();
//mWebViewPlus.enableHtml5();
XWalkSettings settings = mWebViewPlus.getSettings();
WebSettings settings = mWebViewPlus.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + MessageFormat.format(
" YGOMobile/{0} ({1} {2,number,#})",
BuildConfig.VERSION_NAME,
......@@ -73,7 +77,23 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
BuildConfig.VERSION_CODE
));
mWebViewPlus.setUIClient(new XWalkUIClient(mWebViewPlus) {
mWebViewPlus.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
mProgressBar.setVisibility(View.GONE);
} else {
if (View.GONE == mProgressBar.getVisibility()) {
mProgressBar.setVisibility(View.VISIBLE);
}
mProgressBar.setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
}
});
/*mWebViewPlus.setUIClient(new XWalkUIClient(mWebViewPlus) {
@Override
public void onReceivedTitle(XWalkView view, String title) {
super.onReceivedTitle(view, title);
......@@ -81,12 +101,12 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
}
@Override
public boolean onConsoleMessage(XWalkView view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
public boolean onConsoleMessage(X5WebView view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
if (BuildConfig.DEBUG)
Log.i("webview", sourceId + ":" + lineNumber + "\n" + message);
return super.onConsoleMessage(view, message, lineNumber, sourceId, messageType);
}
});
});*/
mMyCard.attachWeb(mWebViewPlus, this);
mWebViewPlus.loadUrl(mMyCard.getHomeUrl());
}
......@@ -104,7 +124,7 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
}
}
@Override
/*@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mWebViewPlus != null) {
mWebViewPlus.onActivityResult(requestCode, resultCode, data);
......@@ -117,7 +137,7 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
if (mWebViewPlus != null) {
mWebViewPlus.onNewIntent(intent);
}
}
}*/
@Override
public void onBackPressed() {
......@@ -133,7 +153,7 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
@Override
protected void onDestroy() {
mWebViewPlus.stopLoading();
mWebViewPlus.onDestroy();
//mWebViewPlus.onDestroy();
YGOStarter.onDestroy(this);
super.onDestroy();
}
......@@ -239,4 +259,8 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
}
return false;
}
public void ProgressBar(){
}
}
......@@ -3,9 +3,9 @@ package cn.garymb.ygomobile.ui.online;
import android.content.Context;
import android.util.AttributeSet;
import cn.garymb.ygomobile.ui.widget.WebViewPlus;
import cn.garymb.ygomobile.ui.plus.X5WebView;
public class MyCardWebView extends WebViewPlus {
public class MyCardWebView extends X5WebView {
public MyCardWebView(Context context) {
super(context);
}
......
package cn.garymb.ygomobile.ui.plus;
import android.annotation.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.widget.*;
import com.tencent.smtt.sdk.*;
public class X5WebView extends WebView {
private WebViewClient client = new WebViewClient() {
/**
* 防止加载网页时调起系统浏览器
*/
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
};
@SuppressLint("SetJavaScriptEnabled")
public X5WebView(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
this.setWebViewClient(client);
// this.setWebChromeClient(chromeClient);
// WebStorage webStorage = WebStorage.getInstance();
initWebViewSettings();
this.getView().setClickable(true);
}
private void initWebViewSettings() {
WebSettings webSetting = this.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
webSetting.setAllowFileAccess(true);
//webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
webSetting.setSupportZoom(true);
webSetting.setBuiltInZoomControls(true);
webSetting.setUseWideViewPort(true);
webSetting.setSupportMultipleWindows(false);
// webSetting.setLoadWithOverviewMode(true);
webSetting.setAppCacheEnabled(true);
// webSetting.setDatabaseEnabled(true);
webSetting.setDomStorageEnabled(true);
webSetting.setGeolocationEnabled(true);
webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSetting.setDatabaseEnabled(true);
webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
/*boolean ret = super.drawChild(canvas, child, drawingTime);
canvas.save();
Paint paint = new Paint();
paint.setColor(0x7fff0000);
paint.setTextSize(24.f);
paint.setAntiAlias(true);
if (getX5WebViewExtension() != null) {
canvas.drawText(this.getContext().getPackageName() + "-pid:"
+ android.os.Process.myPid(), 10, 50, paint);
canvas.drawText(
"X5 Core:" + QbSdk.getTbsVersion(this.getContext()), 10,
100, paint);
} else {
canvas.drawText(this.getContext().getPackageName() + "-pid:"
+ android.os.Process.myPid(), 10, 50, paint);
canvas.drawText("Sys Core", 10, 100, paint);
}
canvas.drawText(Build.MANUFACTURER, 10, 150, paint);
canvas.drawText(Build.MODEL, 10, 200, paint);
canvas.restore();
return ret;*/
return super.drawChild(canvas,child,drawingTime);
}
public X5WebView(Context arg0) {
super(arg0);
setBackgroundColor(85621);
}
}
package cn.garymb.ygomobile.ui.plus;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import org.xwalk.core.XWalkDownloadListener;
import org.xwalk.core.XWalkNavigationItem;
import org.xwalk.core.XWalkPreferences;
import org.xwalk.core.XWalkResourceClient;
import org.xwalk.core.XWalkUIClient;
import org.xwalk.core.XWalkView;
import cn.garymb.ygomobile.lite.BuildConfig;
public class XWebView extends XWalkView {
static {
XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, BuildConfig.DEBUG);
XWalkPreferences.setValue(XWalkPreferences.ENABLE_THEME_COLOR, true);
XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true);
XWalkPreferences.setValue(XWalkPreferences.ALLOW_UNIVERSAL_ACCESS_FROM_FILE, true);
}
public XWebView(Context context) {
super(context);
}
public XWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public XWebView(Context context, Activity activity) {
super(context, activity);
}
public void setWebViewClient(WebViewClient webViewClient) {
if (webViewClient == null) return;
setResourceClient(new XWalkResourceClient(this) {
@Override
public void onLoadStarted(XWalkView view, String url) {
super.onLoadStarted(view, url);
webViewClient.onPageStarted(null, url, null);
}
@Override
public void onLoadFinished(XWalkView view, String url) {
super.onLoadFinished(view, url);
webViewClient.onPageFinished(null, url);
}
@Override
public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
return webViewClient.shouldOverrideUrlLoading(null, url);
}
});
}
public void setWebChromeClient(final WebChromeClient webChromeClient) {
if (webChromeClient == null) return;
setUIClient(new XWalkUIClient(this) {
@Override
public boolean onConsoleMessage(XWalkView view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
if (BuildConfig.DEBUG) {
Log.i("webview", sourceId + ":" + lineNumber + "\n" + message);
}
return super.onConsoleMessage(view, message, lineNumber, sourceId, messageType);
}
@Override
public void onReceivedTitle(XWalkView view, String title) {
super.onReceivedTitle(view, title);
webChromeClient.onReceivedTitle(null, title);
}
});
}
public boolean canGoBack() {
return getNavigationHistory().canGoBack();
}
public void enableHtml5() {
getSettings().setSaveFormData(true);
getSettings().setDatabaseEnabled(true);
getSettings().setDomStorageEnabled(true);
// HTML5 configuration settings.
// getSettings().setAppCacheMaxSize(Long.MAX_VALUE);
// getSettings().setAppCachePath(context.getDir("appcache", Context.MODE_PRIVATE).getPath());
// getSettings().setDatabasePath(context.getDir("databases", Context.MODE_PRIVATE).getPath());
// getSettings().setGeolocationDatabasePath(context.getDir("geolocation", 0).getPath());
getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
setHorizontalScrollBarEnabled(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
GeolocationPermissions.getInstance();
}
getSettings().setAllowContentAccess(true);
getSettings().setAllowFileAccess(true);
setDownloadListener(new XWalkDownloadListener(getContext()) {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
getContext().startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void loadUrl(String url) {
super.load(url, null);
}
public void loadData(String data, String mimeType, String encoding) {
super.load(null, data);
}
public void goBack() {
int index = getNavigationHistory().getCurrentIndex();
if (getNavigationHistory().hasItemAt(index - 1)) {
XWalkNavigationItem item = getNavigationHistory().getItemAt(index - 1);
// item.getUrl();
if (item != null) {
loadUrl(item.getUrl());
}
}
}
}
......@@ -10,15 +10,26 @@
android:fitsSystemWindows="true"
tools:openDrawer="left">
<FrameLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<cn.garymb.ygomobile.ui.online.MyCardWebView
android:id="@+id/webbrowser"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
android:layout_height="match_parent" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</cn.garymb.ygomobile.ui.online.MyCardWebView>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_main"
......@@ -30,4 +41,7 @@
app:itemIconTint="@color/gold"
app:itemTextColor="@color/mediumPurple"
app:menu="@menu/nav_mycard_menu" />
</android.support.v4.widget.DrawerLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment