优化地址栏和错误信息
This commit is contained in:
parent
ef76eaf0b7
commit
9c8fbad7cc
|
@ -2,7 +2,7 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.hty.browser"
|
package="com.hty.browser"
|
||||||
android:versionCode="4"
|
android:versionCode="4"
|
||||||
android:versionName="4.21">
|
android:versionName="4.24">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
|
@ -12,7 +12,8 @@
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@android:style/Theme.Holo.Light.NoActionBar"
|
android:theme="@android:style/Theme.Holo.Light.NoActionBar"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize">
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
|
android:launchMode="singleInstance">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
@ -21,16 +22,21 @@
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
<category android:name="android.intent.category.BROWSABLE"/>
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
<action android:name="android.intent.action.SEARCH"/>
|
|
||||||
<action android:name="android.intent.action.WEB_SEARCH"/>
|
|
||||||
<data android:scheme="file"/>
|
<data android:scheme="file"/>
|
||||||
<data android:scheme="content"/>
|
<data android:scheme="content"/>
|
||||||
<data android:scheme="https"/>
|
<data android:scheme="https"/>
|
||||||
<data android:scheme="http"/>
|
<data android:scheme="http"/>
|
||||||
<data android:mimeType="text/html"/>
|
<data android:mimeType="*/*"/>
|
||||||
<data android:mimeType="text/plain"/>
|
|
||||||
<data android:host="*"/>
|
<data android:host="*"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.WEB_SEARCH"/>
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="*/*"/>
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".FavoriteActivity"
|
android:name=".FavoriteActivity"
|
||||||
|
|
|
@ -9,11 +9,11 @@ p { text-indent:2em; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.18</h2>
|
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.24</h2>
|
||||||
<p>内置扩展的浏览器。</p>
|
<p>内置扩展的浏览器。</p>
|
||||||
<p>扩展:链接关键字过滤,链接关键字高亮,图片自定义过滤,视频独立播放。</p>
|
<p>扩展:链接关键字过滤,链接关键字高亮,图片自定义过滤,视频独立播放。</p>
|
||||||
<p>作者:海天鹰</p>
|
<p>作者:海天鹰</p>
|
||||||
<p>源码:<a href="https://github.com/sonichy/Android_HTYBrowser" target="_blank">https://github.com/sonichy/Android_HTYBrowser</a></p>
|
<p>源码:<a href="https://gitee.com/sonichy/HTYBrowser_Android/" target="_blank">https://gitee.com/sonichy/HTYBrowser_Android/</a></p>
|
||||||
<p>E-mail:sonichy@163.com</p>
|
<p>E-mail:sonichy@163.com</p>
|
||||||
<h3>参考:</h3>
|
<h3>参考:</h3>
|
||||||
<p><a href="https://gitee.com/daiji111/flying_browser/blob/master/app/src/main/java/com/daiji/feixiang/BrowserActivity.java">多窗口管理</a></p>
|
<p><a href="https://gitee.com/daiji111/flying_browser/blob/master/app/src/main/java/com/daiji/feixiang/BrowserActivity.java">多窗口管理</a></p>
|
||||||
|
@ -23,6 +23,9 @@ p { text-indent:2em; }
|
||||||
<p><a href="https://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon" target="_blank">获取网页图标</a></p>
|
<p><a href="https://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon" target="_blank">获取网页图标</a></p>
|
||||||
<p><a href="https://www.jianshu.com/p/c9a18050a249" target="_blank">字符串转Bitmap</a></p>
|
<p><a href="https://www.jianshu.com/p/c9a18050a249" target="_blank">字符串转Bitmap</a></p>
|
||||||
<h3>更新日志:</h3>
|
<h3>更新日志:</h3>
|
||||||
|
<h3>V4.24 (2022-04-27)</h3><ol><li>修复网页未加载,地址栏没有更新的问题。</li><li>优化错误信息页面。</li><li>链接增加分享菜单。</li><li>增加接收分享。</li><li>如果不是最后一页,点击返回关闭当前页。</li><li>加入QQ、微信、阿里云盘文件打开列表。</li></ol>
|
||||||
|
<h3>V4.23 (2021-12-14)</h3><ol><li>增加保存网页,但是存在严重问题,< 全变成 \u003C。</li></ol>
|
||||||
|
<h3>V4.22 (2021-12-02)</h3><ol><li>解决高亮扩展链接内部含有 <font color="*">,文字颜色设置失效问题。</li></ol>
|
||||||
<h3>V4.21 (2021-11-21)</h3><ol><li>收藏夹增加在新窗口打开。</li><li>简化视频截图代码。</li></ol>
|
<h3>V4.21 (2021-11-21)</h3><ol><li>收藏夹增加在新窗口打开。</li><li>简化视频截图代码。</li></ol>
|
||||||
<h3>V4.20 (2021-08-10)</h3><ol><li><a href="https://blog.csdn.net/woaixiaozhe/article/details/7575976" _target="_blank">双击返回键退出</a></li></ol>
|
<h3>V4.20 (2021-08-10)</h3><ol><li><a href="https://blog.csdn.net/woaixiaozhe/article/details/7575976" _target="_blank">双击返回键退出</a></li></ol>
|
||||||
<h3>V4.19 (2021-06-27)</h3><ol><li>增加请求电脑版网页。</li></ol>
|
<h3>V4.19 (2021-06-27)</h3><ol><li>增加请求电脑版网页。</li></ol>
|
||||||
|
|
|
@ -292,7 +292,7 @@ public class FavoriteActivity extends Activity {
|
||||||
});
|
});
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", position + "");
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", position + "");
|
||||||
listView.setSelection(position);
|
//listView.setSelection(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
class EditChangedListener implements TextWatcher {
|
class EditChangedListener implements TextWatcher {
|
||||||
|
@ -319,7 +319,7 @@ public class FavoriteActivity extends Activity {
|
||||||
File file = new File(MainActivity.dir, filename);
|
File file = new File(MainActivity.dir, filename);
|
||||||
try {
|
try {
|
||||||
BufferedWriter BW = new BufferedWriter(new FileWriter(file, false)); //false覆盖
|
BufferedWriter BW = new BufferedWriter(new FileWriter(file, false)); //false覆盖
|
||||||
if(filename.endsWith(".csv")){
|
if (filename.endsWith(".csv")) {
|
||||||
BW.write('\ufeff'); // Excel通过文件的BOM头来判断文件编码
|
BW.write('\ufeff'); // Excel通过文件的BOM头来判断文件编码
|
||||||
BW.flush();
|
BW.flush();
|
||||||
}
|
}
|
||||||
|
@ -328,6 +328,7 @@ public class FavoriteActivity extends Activity {
|
||||||
Toast.makeText(FavoriteActivity.this, "写文件 " + MainActivity.dir + File.separator + filename + " 成功", Toast.LENGTH_SHORT).show();
|
Toast.makeText(FavoriteActivity.this, "写文件 " + MainActivity.dir + File.separator + filename + " 成功", Toast.LENGTH_SHORT).show();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
|
||||||
|
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,13 @@ package com.hty.browser;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -15,6 +17,7 @@ import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -128,6 +131,7 @@ public class MainActivity extends Activity {
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE };
|
Manifest.permission.WRITE_EXTERNAL_STORAGE };
|
||||||
private static int REQUEST_PERMISSION_CODE = 1;
|
private static int REQUEST_PERMISSION_CODE = 1;
|
||||||
Boolean isExit = false;
|
Boolean isExit = false;
|
||||||
|
ClipboardManager clipboardManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -139,6 +143,7 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
IMM = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
IMM = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "HTYBrowser";
|
String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "HTYBrowser";
|
||||||
|
@ -245,6 +250,8 @@ public class MainActivity extends Activity {
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
|
intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
|
||||||
registerReceiver(receiver, intentFilter);
|
registerReceiver(receiver, intentFilter);
|
||||||
|
|
||||||
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", "Intent(" + getIntent() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFullScreen() {
|
private void setFullScreen() {
|
||||||
|
@ -319,7 +326,7 @@ public class MainActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
if(which != currentPage) {
|
if (which != currentPage) {
|
||||||
webViewLayout.removeAllViews();
|
webViewLayout.removeAllViews();
|
||||||
WebView webView = list_webView.get(which);
|
WebView webView = list_webView.get(which);
|
||||||
webViewLayout.addView(webView);
|
webViewLayout.addView(webView);
|
||||||
|
@ -394,16 +401,18 @@ public class MainActivity extends Activity {
|
||||||
if (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
if (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||||
menu.setHeaderIcon(android.R.drawable.ic_menu_gallery);
|
menu.setHeaderIcon(android.R.drawable.ic_menu_gallery);
|
||||||
menu.add(0, 0, 0, "查看图片");
|
menu.add(0, 0, 0, "查看图片");
|
||||||
//menu.add(0, 1, 1, "复制图片");
|
//menu.add(0, 1, 1, "复制图片"); // 未实现
|
||||||
menu.add(0, 2, 2, "保存图片").setIcon(android.R.drawable.ic_menu_save); // Context menu items do not support icons
|
menu.add(0, 2, 2, "保存图片").setIcon(android.R.drawable.ic_menu_save); // Context menu items do not support icons
|
||||||
menu.add(0, 3, 3, "复制链接");
|
menu.add(0, 3, 3, "复制链接");
|
||||||
menu.add(0, 4, 4, "屏蔽图片");
|
menu.add(0, 4, 4, "分享");
|
||||||
menu.add(0, 5, 5, "隐藏图片");
|
menu.add(0, 5, 5, "屏蔽图片");
|
||||||
|
menu.add(0, 6, 6, "隐藏图片");
|
||||||
} else if (result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
|
} else if (result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
|
||||||
menu.setHeaderIcon(R.drawable.link);
|
menu.setHeaderIcon(R.drawable.link);
|
||||||
menu.add(0, 0, 0, "在新窗口打开链接");
|
menu.add(0, 0, 0, "在新窗口打开链接");
|
||||||
menu.add(0, 2, 2, "下载");
|
menu.add(0, 2, 2, "下载");
|
||||||
menu.add(0, 3, 3, "复制链接");
|
menu.add(0, 3, 3, "复制链接");
|
||||||
|
menu.add(0, 4, 4, "分享");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,29 +423,34 @@ public class MainActivity extends Activity {
|
||||||
newWindow(HTRE);
|
newWindow(HTRE);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
Bitmap bitmap = null;
|
||||||
ContentValues values = new ContentValues(2);
|
// HTRE -> bitmap
|
||||||
values.put(MediaStore.Images.Media.MIME_TYPE, "image/*");
|
Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(), bitmap, "HTYBrowser", HTRE));
|
||||||
values.put(MediaStore.Images.Media.DATA, HTRE);
|
ClipData clipData = ClipData.newUri(getContentResolver(), "Image", uri);
|
||||||
Uri imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
|
||||||
ClipData clipData = ClipData.newUri(getContentResolver(), "Image", imageUri);
|
|
||||||
clipboardManager.setPrimaryClip(clipData);
|
clipboardManager.setPrimaryClip(clipData);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
String mime = URLConnection.getFileNameMap().getContentTypeFor(HTRE);
|
String mime = URLConnection.getFileNameMap().getContentTypeFor(HTRE);
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + " ", "" + mime);
|
Log.e(Thread.currentThread().getStackTrace()[2] + " ", "" + mime);
|
||||||
if (mime == null) mime = "";
|
if (mime == null)
|
||||||
|
mime = "";
|
||||||
dialog_download(HTRE, "", mime, 0);
|
dialog_download(HTRE, "", mime, 0);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
|
||||||
clipboardManager.setPrimaryClip(ClipData.newPlainText("link", HTRE));
|
clipboardManager.setPrimaryClip(ClipData.newPlainText("link", HTRE));
|
||||||
Toast.makeText(getApplicationContext(), "链接已复制", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "链接已复制", Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
DialogBlock(HTRE);
|
Intent intent = new Intent();
|
||||||
|
intent.setAction(Intent.ACTION_SEND);
|
||||||
|
intent.putExtra(Intent.EXTRA_TEXT, HTRE);
|
||||||
|
intent.setType("text/plain");
|
||||||
|
startActivity(Intent.createChooser(intent, "分享"));
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
DialogBlock(HTRE);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
String js = "javascript:var imgs=document.getElementsByTagName('img');for(i=0;i<imgs.length;i++){if(imgs[i].src=='" + HTRE +"'){imgs[i].style.display='none';break;}}";
|
String js = "javascript:var imgs=document.getElementsByTagName('img');for(i=0;i<imgs.length;i++){if(imgs[i].src=='" + HTRE +"'){imgs[i].style.display='none';break;}}";
|
||||||
list_webView.get(currentPage).loadUrl(js);
|
list_webView.get(currentPage).loadUrl(js);
|
||||||
break;
|
break;
|
||||||
|
@ -454,6 +468,19 @@ public class MainActivity extends Activity {
|
||||||
} else {
|
} else {
|
||||||
if (list_webView.get(currentPage).canGoBack()) {
|
if (list_webView.get(currentPage).canGoBack()) {
|
||||||
list_webView.get(currentPage).goBack();
|
list_webView.get(currentPage).goBack();
|
||||||
|
} else if (currentPage > 0) {
|
||||||
|
list_webView.remove(currentPage);
|
||||||
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", currentPage + "");
|
||||||
|
if (currentPage == list_webView.size())
|
||||||
|
currentPage--;
|
||||||
|
button_page.setText(currentPage + 1 + "");
|
||||||
|
webViewLayout.removeAllViews();
|
||||||
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", currentPage + "");
|
||||||
|
WebView webView = list_webView.get(currentPage);
|
||||||
|
webViewLayout.addView(webView);
|
||||||
|
button_title.setText(webView.getTitle());
|
||||||
|
editText_url.setText(webView.getUrl());
|
||||||
|
button_info.setImageBitmap(webView.getFavicon());
|
||||||
} else {
|
} else {
|
||||||
exitBy2Click();
|
exitBy2Click();
|
||||||
}
|
}
|
||||||
|
@ -511,12 +538,17 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
mUploadMessageForAndroid5 = null;
|
mUploadMessageForAndroid5 = null;
|
||||||
}
|
}
|
||||||
if (requestCode == 0) {
|
if (requestCode == 0) { //收藏夹返回
|
||||||
if (intent != null)
|
if (intent != null) {
|
||||||
if (intent.getBooleanExtra("newWindow", false))
|
String surl = intent.getStringExtra("url");
|
||||||
newWindow(intent.getStringExtra("url"));
|
if (intent.getBooleanExtra("newWindow", false)) {
|
||||||
else
|
newWindow(surl);
|
||||||
list_webView.get(currentPage).loadUrl(intent.getStringExtra("url"));
|
} else {
|
||||||
|
list_webView.get(currentPage).loadUrl(surl);
|
||||||
|
button_title.setText(surl);
|
||||||
|
editText_url.setText(surl);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (requestCode == FILECHOOSER_DOWNLOAD_PATH) {
|
if (requestCode == FILECHOOSER_DOWNLOAD_PATH) {
|
||||||
if (resultCode == Activity.RESULT_OK) { //是否选择,没选择就不会继续
|
if (resultCode == Activity.RESULT_OK) { //是否选择,没选择就不会继续
|
||||||
|
@ -641,7 +673,7 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuDialog() {
|
private void MenuDialog() {
|
||||||
String[] items = { "新建窗口", "关闭当前窗口", "收藏当前页", "收藏夹", "查找", "分享", "视频独立播放", "视频截图", "视频在播放器中打开", "查看源码", "主页", "全屏", "广告过滤规则", "设置", "检查更新", "关于", "退出", "清除缓存" };
|
String[] items = { "新建窗口", "关闭当前窗口", "收藏当前页", "收藏夹", "查找", "分享", "视频独立播放", "视频截图", "视频在播放器中打开", "查看源码", "保存", "全屏", "广告过滤规则", "设置", "检查更新", "关于", "退出", "清除缓存" };
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle("菜单");
|
builder.setTitle("菜单");
|
||||||
//builder.setIcon(android.R.drawable.ic_menu_preferences);
|
//builder.setIcon(android.R.drawable.ic_menu_preferences);
|
||||||
|
@ -659,8 +691,8 @@ public class MainActivity extends Activity {
|
||||||
if (list_webView.size() == 0) {
|
if (list_webView.size() == 0) {
|
||||||
newWindow(sharedPreferences.getString("homepage","http://www.baidu.com"));
|
newWindow(sharedPreferences.getString("homepage","http://www.baidu.com"));
|
||||||
} else {
|
} else {
|
||||||
currentPage--;
|
if (currentPage == list_webView.size())
|
||||||
if (currentPage < 0) currentPage = 0;
|
currentPage--;
|
||||||
button_page.setText(currentPage + 1 + "");
|
button_page.setText(currentPage + 1 + "");
|
||||||
webViewLayout.removeAllViews();
|
webViewLayout.removeAllViews();
|
||||||
WebView webView = list_webView.get(currentPage);
|
WebView webView = list_webView.get(currentPage);
|
||||||
|
@ -827,7 +859,7 @@ public class MainActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveValue(String value) {
|
public void onReceiveValue(String value) {
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + value);
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + value);
|
||||||
if(!value.equals("null")) {
|
if (!value.equals("null")) {
|
||||||
try {
|
try {
|
||||||
Intent intent1 = new Intent(Intent.ACTION_VIEW);
|
Intent intent1 = new Intent(Intent.ACTION_VIEW);
|
||||||
String type = "video/*";
|
String type = "video/*";
|
||||||
|
@ -842,12 +874,20 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 9://改多标签后失效
|
case 9://查看源码改多标签后失效
|
||||||
js = "javascript:var s='<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'; document.body.innerHTML=''; var pre=document.createElement('pre'); document.body.appendChild(pre); pre.textContent=s;";
|
js = "javascript:var s='<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'; document.body.innerHTML=''; var pre=document.createElement('pre'); document.body.appendChild(pre); pre.textContent=s;";
|
||||||
list_webView.get(currentPage).loadUrl(js);
|
list_webView.get(currentPage).loadUrl(js);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
list_webView.get(currentPage).loadUrl(sharedPreferences.getString("homepage",""));
|
js = "javascript:function save(){var s='<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'; return s;}";
|
||||||
|
list_webView.get(currentPage).loadUrl(js);
|
||||||
|
list_webView.get(currentPage).evaluateJavascript("javascript:save()", new ValueCallback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onReceiveValue(String value) {
|
||||||
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + value);
|
||||||
|
writeFile(button_title.getText().toString() + ".htm", value);
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
|
@ -900,7 +940,7 @@ public class MainActivity extends Activity {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!exist) {
|
if (!exist) {
|
||||||
addRule(rule);
|
addRule(rule);
|
||||||
dialogRule.dismiss();
|
dialogRule.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -949,7 +989,7 @@ public class MainActivity extends Activity {
|
||||||
void addRule(String content){
|
void addRule(String content){
|
||||||
FileOutputStream outStream = null;
|
FileOutputStream outStream = null;
|
||||||
try {
|
try {
|
||||||
outStream = this.openFileOutput("blockrules", Context.MODE_APPEND);
|
outStream = openFileOutput("blockrules", Context.MODE_APPEND);
|
||||||
outStream.write((content+"\n").getBytes());
|
outStream.write((content+"\n").getBytes());
|
||||||
outStream.close();
|
outStream.close();
|
||||||
ADBlock();
|
ADBlock();
|
||||||
|
@ -1170,6 +1210,8 @@ public class MainActivity extends Activity {
|
||||||
list_webView.add(webView);
|
list_webView.add(webView);
|
||||||
currentPage = list_webView.size() - 1;
|
currentPage = list_webView.size() - 1;
|
||||||
button_page.setText(currentPage + 1 + "");
|
button_page.setText(currentPage + 1 + "");
|
||||||
|
button_title.setText(surl);
|
||||||
|
editText_url.setText(surl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void settingWebView(WebView webView) {
|
void settingWebView(WebView webView) {
|
||||||
|
@ -1207,16 +1249,12 @@ public class MainActivity extends Activity {
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", url);
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", url);
|
||||||
// 协议过滤
|
// 协议过滤
|
||||||
if (url.startsWith("http") || url.startsWith("ftp://") && !url.startsWith("https://cdn-haokanapk.baidu.com/")) {
|
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp://") && !url.startsWith("https://cdn-haokanapk.baidu.com/")) {
|
||||||
if (url.startsWith("https://baiduyunbo.com/?id=")) {
|
view.loadUrl(url);
|
||||||
String id = url.replace("https://baiduyunbo.com/?id=","");
|
return false; // continue load
|
||||||
view.loadUrl("https://m3u8.cdnpan.com/"+ id + ".m3u8");
|
} else {
|
||||||
} else {
|
return true; // abort load
|
||||||
view.loadUrl(url);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true; //不跳转
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1246,35 +1284,32 @@ public class MainActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||||
Toast.makeText(getApplicationContext(), "ReceivedError:" + errorCode, Toast.LENGTH_SHORT).show();
|
//Toast.makeText(getApplicationContext(), "ReceivedError:" + errorCode, Toast.LENGTH_SHORT).show();
|
||||||
if (isNetworkConnected()) {
|
//if (isNetworkConnected()) {
|
||||||
switch (errorCode) {
|
switch (errorCode) {
|
||||||
case WebViewClient.ERROR_HOST_LOOKUP: // 找不到主机,跳转百度搜索
|
// case WebViewClient.ERROR_HOST_LOOKUP: // 找不到主机,跳转百度搜索
|
||||||
|
// Log.e(Thread.currentThread().getStackTrace()[2] + "", failingUrl);
|
||||||
|
// String url = "http://m.baidu.com/s?word=" + urlo;
|
||||||
|
// editText_url.setText(url);
|
||||||
|
// view.loadUrl(url);
|
||||||
|
// urln = url;
|
||||||
|
// break;
|
||||||
|
default:
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", failingUrl);
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", failingUrl);
|
||||||
String url = "http://m.baidu.com/s?word=" + urlo;
|
view.loadDataWithBaseURL(failingUrl, "<html><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"/><title>" + failingUrl + "</title><body><h1>无法访问此网站</h1><p>" + failingUrl + " 无法访问,因为:<br>" + description + "</p></body></html>", "text/html", "utf-8", "");
|
||||||
editText_url.setText(url);
|
|
||||||
view.loadUrl(url);
|
|
||||||
urln = url;
|
|
||||||
break;
|
|
||||||
case WebViewClient.ERROR_UNSUPPORTED_SCHEME:
|
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + "",failingUrl);
|
|
||||||
}
|
}
|
||||||
} else {
|
//} else {
|
||||||
view.loadDataWithBaseURL(
|
// view.loadDataWithBaseURL("", "<html><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"/><title>网络未连接</title><style>h1{font-size:10vw;margin:40vh auto;text-align:center;}</style><body><h1>网络未连接</h1></body></html>", "text/html", "utf-8", "");
|
||||||
"",
|
//}
|
||||||
"<html><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"/><title>网络未连接</title><style>h1{font-size:10vw;margin:40vh auto;text-align:center;}</style><body><h1>网络未连接</h1></body></html>",
|
|
||||||
"text/html", "utf-8", "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
webView.setFindListener(new FindListener() {
|
webView.setFindListener(new FindListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) {
|
public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) {
|
||||||
if(numberOfMatches == 0){
|
if (numberOfMatches == 0) {
|
||||||
textView_searchCount.setText(activeMatchOrdinal + "/" + numberOfMatches);
|
textView_searchCount.setText(activeMatchOrdinal + "/" + numberOfMatches);
|
||||||
}else{
|
} else {
|
||||||
textView_searchCount.setText(activeMatchOrdinal + 1 + "/" + numberOfMatches);
|
textView_searchCount.setText(activeMatchOrdinal + 1 + "/" + numberOfMatches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1330,7 +1365,7 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 链接关键字屏蔽
|
// 链接关键字屏蔽
|
||||||
if(sharedPreferences.getBoolean("switch_filter", false)){
|
if (sharedPreferences.getBoolean("switch_filter", false)) {
|
||||||
String sf = sharedPreferences.getString("filter", "");
|
String sf = sharedPreferences.getString("filter", "");
|
||||||
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + sf);
|
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + sf);
|
||||||
if(!sf.equals("")) {
|
if(!sf.equals("")) {
|
||||||
|
@ -1343,7 +1378,7 @@ public class MainActivity extends Activity {
|
||||||
String shl = sharedPreferences.getString("highlight", "");
|
String shl = sharedPreferences.getString("highlight", "");
|
||||||
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + shl);
|
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + shl);
|
||||||
if (!shl.equals("")) {
|
if (!shl.equals("")) {
|
||||||
String js = "javascript:var s='"+shl+"';var sl=s.split(';');var a=document.getElementsByTagName('a');for(var i=0;i<a.length;i++){for(var j=0;j<sl.length;j++){if(a[i].textContent.indexOf(sl[j])!=-1){a[i].style.color='white';a[i].style.backgroundColor='#DA3434';}}}";
|
String js = "javascript:var s='"+shl+"';var sl=s.split(';');var a=document.getElementsByTagName('a');for(var i=0;i<a.length;i++){for(var j=0;j<sl.length;j++){if(a[i].textContent.indexOf(sl[j])!=-1){a[i].style.color='white';a[i].style.backgroundColor='#DA3434';a[i].innerHTML=a[i].textContent;}}}";
|
||||||
view.loadUrl(js);
|
view.loadUrl(js);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1403,10 +1438,10 @@ public class MainActivity extends Activity {
|
||||||
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// target="_blank" 处理
|
// target="_blank" 处理,Android 11 崩溃无Log
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
|
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
|
||||||
if(isUserGesture) {
|
if (isUserGesture) {
|
||||||
WebView webView = new WebView(MainActivity.this);
|
WebView webView = new WebView(MainActivity.this);
|
||||||
settingWebView(webView);
|
settingWebView(webView);
|
||||||
webViewLayout.removeAllViews();
|
webViewLayout.removeAllViews();
|
||||||
|
@ -1417,8 +1452,10 @@ public class MainActivity extends Activity {
|
||||||
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
|
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
|
||||||
transport.setWebView(webView);
|
transport.setWebView(webView);
|
||||||
resultMsg.sendToTarget();
|
resultMsg.sendToTarget();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1429,20 +1466,16 @@ public class MainActivity extends Activity {
|
||||||
urln = intent.getDataString();
|
urln = intent.getDataString();
|
||||||
newWindow(urln);
|
newWindow(urln);
|
||||||
} else {
|
} else {
|
||||||
newWindow(sharedPreferences.getString("homepage","http://www.baidu.com"));
|
newWindow(sharedPreferences.getString("homepage", "http://www.baidu.com"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + getIntent() + ")");
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + getIntent() + ")");
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
if (getIntent().getDataString() != null) {
|
getDataFromIntent(intent);
|
||||||
urln = getIntent().getDataString();
|
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + urln + ")");
|
|
||||||
newWindow(urln);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dialog_download(final String surl, String contentDisposition, String mimeType, long contentLength){
|
void dialog_download(final String surl, String contentDisposition, String mimeType, long contentLength){
|
||||||
|
@ -1452,7 +1485,7 @@ public class MainActivity extends Activity {
|
||||||
final EditText editText_download_filename = (EditText) view.findViewById(R.id.editText_download_filename);
|
final EditText editText_download_filename = (EditText) view.findViewById(R.id.editText_download_filename);
|
||||||
String filename = surl.substring(surl.lastIndexOf("/") + 1);
|
String filename = surl.substring(surl.lastIndexOf("/") + 1);
|
||||||
Log.e(Thread.currentThread().getStackTrace()[2] + " ", "FileName: " + filename);
|
Log.e(Thread.currentThread().getStackTrace()[2] + " ", "FileName: " + filename);
|
||||||
if (filename.contains("&f=JPEG?")) {//百度网页图片重命名
|
if (filename.contains("&f=JPEG?")) { //百度网页图片重命名
|
||||||
SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
String stime = SDF.format(date);
|
String stime = SDF.format(date);
|
||||||
|
@ -1561,4 +1594,19 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeFile(String filename, String s) {
|
||||||
|
File file = new File(MainActivity.dir, filename);
|
||||||
|
try {
|
||||||
|
BufferedWriter BW = new BufferedWriter(new FileWriter(file, false)); //false覆盖
|
||||||
|
BW.write(s);
|
||||||
|
BW.flush();
|
||||||
|
String filepath = MainActivity.dir + File.separator + filename;
|
||||||
|
MediaScannerConnection.scanFile(MainActivity.this, new String[] { filepath }, null, null);
|
||||||
|
Toast.makeText(MainActivity.this, "写文件 " + MainActivity.dir + File.separator + filename + " 成功", Toast.LENGTH_SHORT).show();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
|
||||||
|
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue