优化猜测下载文件名

This commit is contained in:
sonichy 2020-10-01 19:25:00 +08:00
parent 8162313777
commit 847b9462b6
8 changed files with 42 additions and 25 deletions

BIN
app.apk

Binary file not shown.

View File

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hty.browser"
android:versionCode="4"
android:versionName="4.14">
android:versionName="4.15">
<application
android:icon="@drawable/ic_launcher"

View File

@ -9,7 +9,7 @@ p { text-indent:2em; }
</style>
</head>
<body>
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.14</h2>
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.15</h2>
<p>内置扩展的浏览器。</p>
<p>扩展:链接关键字过滤,链接关键字高亮,图片自定义过滤,视频独立播放。</p>
<p>作者:海天鹰</p>
@ -23,6 +23,7 @@ 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://www.jianshu.com/p/c9a18050a249" target="_blank">字符串转Bitmap</a></p>
<h3>更新日志:</h3>
<h3>V4.15 (2020-10-01)</h3><ol><li>优化猜测下载文件名。</li></ol>
<h3>V4.14 (2020-09-20)</h3><ol><li>优化下载对话框百度网页图片文件名填充,支持修改下载文件名。</li></ol>
<h3>V4.13 (2020-08-30)</h3><ol><li>图片查看改为在新窗口中打开。</li><li>修复修改、删除收藏不能记忆位置问题。</li></ol>
<h3>V4.12 (2020-07-17)</h3><ol><li>适配全面屏导航栏背景色。</li><li>收藏夹无标题栏自定义菜单改成标题栏菜单。</li></ol>

View File

@ -77,6 +77,7 @@ import android.webkit.ConsoleMessage;
import android.webkit.DownloadListener;
import android.webkit.GeolocationPermissions;
import android.webkit.JsResult;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebChromeClient.CustomViewCallback;
@ -105,7 +106,7 @@ public class MainActivity extends Activity {
ImageButton button_back, button_forward, button_menu, button_go, button_search_prev, button_search_next, button_search_close, button_info, button_play;
// RelativeLayout RelativeLayout1;
LinearLayout LinearLayout1, LinearLayout2;
FrameLayout webViewLayout, video, searchBar;
FrameLayout webViewLayout, videoLayout, searchBar;
InputMethodManager IMM;
ProgressBar pgb1;
String urlo = "", HTRE = "", ptitle = "", urln = "";
@ -139,7 +140,7 @@ public class MainActivity extends Activity {
LinearLayout2 = (LinearLayout) findViewById(R.id.LinearLayout2);
// RelativeLayout1 = (RelativeLayout) findViewById(R.id.RelativeLayout1);
webViewLayout = (FrameLayout) findViewById(R.id.webViewLayout);
video = (FrameLayout) findViewById(R.id.video);
videoLayout = (FrameLayout) findViewById(R.id.videoLayout);
searchBar = (FrameLayout) findViewById(R.id.searchBar);
searchBar.setVisibility(View.GONE);
pgb1 = (ProgressBar) findViewById(R.id.progressBar1);
@ -252,7 +253,7 @@ public class MainActivity extends Activity {
private void setFullScreen() {
// RelativeLayout1.setVisibility(View.GONE);
LinearLayout1.setVisibility(View.GONE);
video.setVisibility(View.VISIBLE);
videoLayout.setVisibility(View.VISIBLE);
// imageView1.setVisibility(View.VISIBLE);
// 横屏显示
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
@ -272,7 +273,7 @@ public class MainActivity extends Activity {
LinearLayout1.setVisibility(View.VISIBLE);
LinearLayout2.setVisibility(View.VISIBLE);
pgb1.setVisibility(View.VISIBLE);
video.setVisibility(View.GONE);
videoLayout.setVisibility(View.GONE);
// imageView1.setVisibility(View.GONE);
// 用户当前的首选方向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
@ -391,7 +392,7 @@ public class MainActivity extends Activity {
WebView w = (WebView) v;
HitTestResult result = w.getHitTestResult();
HTRE = result.getExtra();
Log.e(Thread.currentThread().getStackTrace()[2] + ": ", HTRE);
Log.e(Thread.currentThread().getStackTrace()[2] + " ", HTRE + "");
menu.setHeaderTitle(HTRE);
if (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
menu.setHeaderIcon(android.R.drawable.ic_menu_gallery);
@ -427,7 +428,7 @@ public class MainActivity extends Activity {
break;
case 2:
String mime = URLConnection.getFileNameMap().getContentTypeFor(HTRE);
Log.e(Thread.currentThread().getStackTrace()[2] + ": ", "" + mime);
Log.e(Thread.currentThread().getStackTrace()[2] + " ", "" + mime);
if (mime == null) mime = "";
dialog_download(HTRE, "", mime, 0);
break;
@ -613,8 +614,13 @@ public class MainActivity extends Activity {
@Override
protected void onPause() {
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "onPause");
pauseVideo();
Log.e(Thread.currentThread().getStackTrace()[2] + "", "onPause");
// Log.e(Thread.currentThread().getStackTrace()[2] + "", "pauseVideo = " + sharedPreferences.getBoolean("switch_pasueVideoOnPause", true));
// if (sharedPreferences.getBoolean("switch_pasueVideoOnPause", true)) {
// pauseVideo();
// } else {
// playVideo();
// }
if (isFullScreen) {
button_play.setVisibility(View.VISIBLE);
}
@ -1078,7 +1084,7 @@ public class MainActivity extends Activity {
}
}
void iframeBlock(){
void iframeBlock() {
String js = "javascript:var iframes=document.getElementsByTagName('iframe');for(i=0;i<iframes.length;i++){iframes[i].style.display='none';}document.getElementById('win-pop-foot').style.display='none';document.getElementById('win-pop-foot1').style.display='none';";
list_webView.get(currentPage).loadUrl(js);
}
@ -1265,7 +1271,7 @@ public class MainActivity extends Activity {
super.onReceivedError(view, errorCode, description, failingUrl);
Toast.makeText(getApplicationContext(), "ReceivedError:" + errorCode, Toast.LENGTH_SHORT).show();
if (isNetworkConnected()) {
switch(errorCode){
switch (errorCode) {
case WebViewClient.ERROR_HOST_LOOKUP: // 找不到主机跳转百度搜索
Log.e(Thread.currentThread().getStackTrace()[2] + "", failingUrl);
String url = "http://m.baidu.com/s?word=" + urlo;
@ -1336,10 +1342,10 @@ public class MainActivity extends Activity {
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
pgb1.setProgress(newProgress);
if(sharedPreferences.getBoolean("switch_adBlock",false)){
if (sharedPreferences.getBoolean("switch_adBlock", false)) {
ADBlock();
}
if(sharedPreferences.getBoolean("switch_iframeBlock",false)) {
if (sharedPreferences.getBoolean("switch_iframeBlock", false)) {
if (view.getUrl() != null) {
if (!view.getUrl().contains("baidu.com")) {
iframeBlock();
@ -1351,21 +1357,21 @@ public class MainActivity extends Activity {
String sf = sharedPreferences.getString("filter", "");
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + sf);
if(!sf.equals("")) {
String js = "javascript:var s='"+sf+"';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].textContent='';}}}";
String js = "javascript:var s='" + sf + "';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].textContent='';}}}";
view.loadUrl(js);
}
}
// 链接关键字高亮
if(sharedPreferences.getBoolean("switch_highlight", false)){
if (sharedPreferences.getBoolean("switch_highlight", false)) {
String shl = sharedPreferences.getString("highlight", "");
//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';}}}";
view.loadUrl(js);
}
}
//图片宽度超出父元素适应父元素
if(sharedPreferences.getBoolean("switch_shrink",false)) {
if (sharedPreferences.getBoolean("switch_shrink", false)) {
String js = "javascript:var imgs=document.getElementsByTagName('img');for(var i=0;i<imgs.length;i++){if(imgs[i].parentNode.clientWidth > 0){if(imgs[i].clientWidth>imgs[i].parentNode.clientWidth){imgs[i].width=imgs[i].parentNode.clientWidth;}}}";
view.loadUrl(js);
}
@ -1391,7 +1397,7 @@ public class MainActivity extends Activity {
//Toast.makeText(getApplicationContext(), "onShowCustomView", Toast.LENGTH_SHORT).show();
customViewCallback = callback;
// 将video放到当前视图中
video.addView(view);
videoLayout.addView(view);
// 设置全屏
setFullScreen();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
@ -1474,6 +1480,8 @@ public class MainActivity extends Activity {
Date date = new Date();
String stime = SDF.format(date);
filename = stime + ".jpg";
} else {
filename = URLUtil.guessFileName(surl, null, null);
}
editText_download_filename.setText(filename);
editText_download_path = (EditText) view.findViewById(R.id.editText_download_path);
@ -1527,7 +1535,6 @@ public class MainActivity extends Activity {
public void handleMessage(android.os.Message msg) {
switch (msg.what){
case 0:
//textView_filesize.setText(formatFileSize(msg.arg1));
textView_filesize.setText(Formatter.formatFileSize(MainActivity.this, msg.arg1));
break;
}

View File

@ -5,6 +5,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceActivity;
import android.util.Log;
public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{
@ -34,11 +35,12 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
@Override
// 修改后显示
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("homepage")){
Log.e(Thread.currentThread().getStackTrace()[2] + "", key);
if (key.equals("homepage")) {
ETP_homepage.setSummary(sharedPreferences.getString(key, ""));
}else if(key.equals("filter")){
} else if(key.equals("filter")) {
ETP_filter.setSummary(sharedPreferences.getString(key, ""));
}else if(key.equals("highlight")){
} else if(key.equals("highlight")) {
ETP_highlight.setSummary(sharedPreferences.getString(key, ""));
}
}

View File

@ -4,7 +4,7 @@
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/video"
android:id="@+id/videoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"

View File

@ -60,4 +60,11 @@
</PreferenceCategory>
<!--
<SwitchPreference
android:key="switch_pasueVideoOnPause"
android:defaultValue="true"
android:title="后台暂停播放视频"/>
-->
</PreferenceScreen>

View File

@ -1 +1 @@
4.14
4.15