收藏夹增加在新窗口打开,简化视频截图代码

This commit is contained in:
sonichy 2021-11-21 15:57:33 +08:00
parent df3f62afed
commit 523181494c
7 changed files with 77 additions and 76 deletions

BIN
app.apk

Binary file not shown.

View File

@ -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.19"> android:versionName="4.21">
<application <application
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"

View File

@ -23,6 +23,8 @@ 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.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.19 (2021-06-27)</h3><ol><li>增加请求电脑版网页。</li></ol> <h3>V4.19 (2021-06-27)</h3><ol><li>增加请求电脑版网页。</li></ol>
<h3>V4.18 (2021-06-01)</h3><ol><li>增加动态权限请求。</li></ol> <h3>V4.18 (2021-06-01)</h3><ol><li>增加动态权限请求。</li></ol>
<h3>V4.17 (2021-03-02)</h3><ol><li>允许HTTPS、HTTP混合内容解决微信网页视频无法播放的问题。</li></ol> <h3>V4.17 (2021-03-02)</h3><ol><li>允许HTTPS、HTTP混合内容解决微信网页视频无法播放的问题。</li></ol>

View File

@ -76,11 +76,12 @@ public class FavoriteActivity extends Activity {
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
String title = ((TextView) info.targetView.findViewById(R.id.title)).getText().toString(); String title = ((TextView) info.targetView.findViewById(R.id.title)).getText().toString();
menu.setHeaderIcon(R.drawable.link);
menu.setHeaderTitle(title); menu.setHeaderTitle(title);
menu.add(0, 0, 0, "复制链接"); String[] sm = { "在新窗口中打开", "复制链接", "分享", "修改", "删除" };
menu.add(0, 1, 1, "删除"); for (int i=0; i<sm.length; i++) {
menu.add(0, 2, 2, "修改"); menu.add(0, i, i, sm[i]);
menu.add(0, 3, 3, "分享"); }
} }
}); });
listView.setOnTouchListener(new View.OnTouchListener() { listView.setOnTouchListener(new View.OnTouchListener() {
@ -93,8 +94,6 @@ public class FavoriteActivity extends Activity {
search(editText.getText().toString()); search(editText.getText().toString());
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
String[] sm = { "导出HTML", "导出CSV" }; String[] sm = { "导出HTML", "导出CSV" };
@ -140,24 +139,31 @@ public class FavoriteActivity extends Activity {
@Override @Override
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo(); AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
position = menuInfo.position; position = listView.getFirstVisiblePosition();
final String sid = ((TextView) menuInfo.targetView.findViewById(R.id.id)).getText().toString();
final String stitle = ((TextView) menuInfo.targetView.findViewById(R.id.title)).getText().toString();
final String surl = ((TextView) menuInfo.targetView.findViewById(R.id.website)).getText().toString();
switch (item.getItemId()) { switch (item.getItemId()) {
case 0: case 0:
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); Intent intent = new Intent(FavoriteActivity.this, MainActivity.class);
String url = ((TextView) menuInfo.targetView.findViewById(R.id.website)).getText().toString(); intent.putExtra("url", surl);
cm.setPrimaryClip(ClipData.newPlainText("link", url)); intent.putExtra("newWindow", true);
Toast.makeText(getApplicationContext(), "链接已复制", Toast.LENGTH_SHORT).show(); setResult(RESULT_OK, intent);
finish();
break; break;
case 1: case 1:
int id = Integer.parseInt(((TextView) menuInfo.targetView.findViewById(R.id.id)).getText().toString()); ClipboardManager CM = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
DBHelper helper = new DBHelper(getApplicationContext()); CM.setPrimaryClip(ClipData.newPlainText("link", surl));
helper.del(id); Toast.makeText(getApplicationContext(), "链接已复制", Toast.LENGTH_SHORT).show();
search(editText.getText().toString());
break; break;
case 2: case 2:
final String sid = ((TextView) menuInfo.targetView.findViewById(R.id.id)).getText().toString(); intent = new Intent();
final String stitle = ((TextView) menuInfo.targetView.findViewById(R.id.title)).getText().toString(); intent.setAction(Intent.ACTION_SEND);
final String surl = ((TextView) menuInfo.targetView.findViewById(R.id.website)).getText().toString(); intent.putExtra(Intent.EXTRA_TEXT, stitle + "\n" + surl);
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "分享"));
break;
case 3:
LinearLayout layout = new LinearLayout(FavoriteActivity.this); LinearLayout layout = new LinearLayout(FavoriteActivity.this);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
final EditText ET_title = new EditText(FavoriteActivity.this); final EditText ET_title = new EditText(FavoriteActivity.this);
@ -236,12 +242,11 @@ public class FavoriteActivity extends Activity {
}); });
builder.create().show(); builder.create().show();
break; break;
case 3: case 4:
Intent intent = new Intent(); int id = Integer.parseInt(((TextView) menuInfo.targetView.findViewById(R.id.id)).getText().toString());
intent.setAction(Intent.ACTION_SEND); DBHelper helper = new DBHelper(getApplicationContext());
intent.putExtra(Intent.EXTRA_TEXT, ((TextView) menuInfo.targetView.findViewById(R.id.title)).getText().toString() + "\n" + ((TextView) menuInfo.targetView.findViewById(R.id.website)).getText().toString()); helper.del(id);
intent.setType("text/plain"); search(editText.getText().toString());
startActivity(Intent.createChooser(intent, "分享"));
break; break;
} }
return true; return true;

View File

@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
@ -125,6 +127,7 @@ public class MainActivity extends Activity {
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
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;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -452,8 +455,7 @@ public class MainActivity extends Activity {
if (list_webView.get(currentPage).canGoBack()) { if (list_webView.get(currentPage).canGoBack()) {
list_webView.get(currentPage).goBack(); list_webView.get(currentPage).goBack();
} else { } else {
// moveTaskToBack(false); exitBy2Click();
// MenuDialog();
} }
} }
return true; return true;
@ -511,7 +513,10 @@ public class MainActivity extends Activity {
} }
if (requestCode == 0) { if (requestCode == 0) {
if (intent != null) if (intent != null)
list_webView.get(currentPage).loadUrl(intent.getStringExtra("url")); if (intent.getBooleanExtra("newWindow", false))
newWindow(intent.getStringExtra("url"));
else
list_webView.get(currentPage).loadUrl(intent.getStringExtra("url"));
} }
if (requestCode == FILECHOOSER_DOWNLOAD_PATH) { if (requestCode == FILECHOOSER_DOWNLOAD_PATH) {
if (resultCode == Activity.RESULT_OK) { //是否选择没选择就不会继续 if (resultCode == Activity.RESULT_OK) { //是否选择没选择就不会继续
@ -651,9 +656,9 @@ public class MainActivity extends Activity {
break; break;
case 1: case 1:
list_webView.remove(currentPage); list_webView.remove(currentPage);
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--; currentPage--;
if (currentPage < 0) currentPage = 0; if (currentPage < 0) currentPage = 0;
button_page.setText(currentPage + 1 + ""); button_page.setText(currentPage + 1 + "");
@ -743,6 +748,7 @@ public class MainActivity extends Activity {
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);//设置该属性可以访问 field.setAccessible(true);//设置该属性可以访问
} catch (Exception ex) { } catch (Exception ex) {
} }
try { try {
field.set(dialog, true); field.set(dialog, true);
@ -780,7 +786,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(!"null".equals(value)){ if(!value.equals("null")){
//字符串转Bitmaphttps://www.jianshu.com/p/c9a18050a249 //字符串转Bitmaphttps://www.jianshu.com/p/c9a18050a249
byte[] bitmapArray = Base64.decode(value.split(",")[1], Base64.DEFAULT); byte[] bitmapArray = Base64.decode(value.split(",")[1], Base64.DEFAULT);
final Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); final Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
@ -795,35 +801,10 @@ public class MainActivity extends Activity {
builder.setPositiveButton("保存", new DialogInterface.OnClickListener() { builder.setPositiveButton("保存", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() + File.separator + "Screenshots";
File temp = new File(dir); // 如果文件夹不存在则创建
if (!temp.exists()) {
temp.mkdir();
}
Date date = new Date(); Date date = new Date();
SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss");
String stime = SDF.format(date); String stime = SDF.format(date);
String path = dir + stime + ".jpg"; Uri.parse(MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(), bitmap, stime, "海天鹰浏览器视频截图"));
File file = new File(path);
BufferedOutputStream BOS = null;
try {
BOS = new BufferedOutputStream(new FileOutputStream(file));
}catch (FileNotFoundException e){
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, BOS);
try {
BOS.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
BOS.close();
}catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), "保存到:"+path, Toast.LENGTH_SHORT).show();
MediaScannerConnection.scanFile(MainActivity.this, new String[] { path }, null, null);
} }
}); });
builder.setNegativeButton("关闭", new DialogInterface.OnClickListener() { builder.setNegativeButton("关闭", new DialogInterface.OnClickListener() {
@ -832,7 +813,7 @@ public class MainActivity extends Activity {
} }
}); });
builder.create().show(); builder.create().show();
}else{ } else {
Toast.makeText(getApplicationContext(), "请先播放视频或把视频独立播放", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "请先播放视频或把视频独立播放", Toast.LENGTH_SHORT).show();
} }
} }
@ -846,16 +827,16 @@ 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(!"null".equals(value)) { 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/*";
Uri uri = Uri.parse(value); Uri uri = Uri.parse(value);
intent1.setDataAndType(uri, type); intent1.setDataAndType(uri, type);
startActivity(intent1); startActivity(intent1);
} catch (ActivityNotFoundException e) { } catch (Exception e) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e); Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
Toast.makeText(getApplicationContext(), "系统默认播放器不能打开视频", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
} }
} }
} }
@ -939,7 +920,7 @@ public class MainActivity extends Activity {
} }
} }
String content=""; String content="";
for(int i=0; i<rulelist.size(); i++){ for (int i=0; i<rulelist.size(); i++) {
content += rulelist.get(i) + "\n"; content += rulelist.get(i) + "\n";
} }
FileOutputStream outStream = null; FileOutputStream outStream = null;
@ -947,10 +928,8 @@ public class MainActivity extends Activity {
outStream = MainActivity.this.openFileOutput("blockrules", Context.MODE_PRIVATE); outStream = MainActivity.this.openFileOutput("blockrules", Context.MODE_PRIVATE);
outStream.write((content).getBytes()); outStream.write((content).getBytes());
outStream.close(); outStream.close();
} catch (FileNotFoundException e) { } catch (Exception e) {
e.printStackTrace(); Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
}catch (IOException e) {
e.printStackTrace();
} }
dialogRule.dismiss(); dialogRule.dismiss();
ADBlock(); ADBlock();
@ -974,10 +953,8 @@ public class MainActivity extends Activity {
outStream.write((content+"\n").getBytes()); outStream.write((content+"\n").getBytes());
outStream.close(); outStream.close();
ADBlock(); ADBlock();
} catch (FileNotFoundException e) { } catch (Exception e) {
e.printStackTrace(); Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
}catch (IOException e) {
e.printStackTrace();
} }
} }
@ -1461,7 +1438,7 @@ public class MainActivity extends Activity {
//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) { if (getIntent().getDataString() != null) {
urln = getIntent().getDataString(); urln = getIntent().getDataString();
Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + urln + ")"); Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + urln + ")");
newWindow(urln); newWindow(urln);
@ -1556,8 +1533,7 @@ public class MainActivity extends Activity {
try { try {
urlcon = (HttpURLConnection) url.openConnection(); urlcon = (HttpURLConnection) url.openConnection();
fileLength = urlcon.getContentLength(); fileLength = urlcon.getContentLength();
} catch (Exception e) {
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
Message message = Message.obtain(); Message message = Message.obtain();
@ -1567,4 +1543,22 @@ public class MainActivity extends Activity {
} }
} }
//双击返回键退出https://blog.csdn.net/woaixiaozhe/article/details/7575976
void exitBy2Click() {
Timer timer;
if (isExit == false) {
isExit = true;
Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
isExit = false;
}
}, 2000);
} else {
finish();
}
}
} }

View File

@ -31,7 +31,7 @@
<ImageButton <ImageButton
android:id="@+id/imageButton_clear" android:id="@+id/imageButton_clear"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:background="#ffffff" android:background="#ffffff"
android:paddingLeft="-15dp" android:paddingLeft="-15dp"

View File

@ -1 +1 @@
4.19 4.21