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

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

View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import android.Manifest;
import android.app.Activity;
@@ -125,6 +127,7 @@ public class MainActivity extends Activity {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE };
private static int REQUEST_PERMISSION_CODE = 1;
Boolean isExit = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -452,8 +455,7 @@ public class MainActivity extends Activity {
if (list_webView.get(currentPage).canGoBack()) {
list_webView.get(currentPage).goBack();
} else {
// moveTaskToBack(false);
// MenuDialog();
exitBy2Click();
}
}
return true;
@@ -511,7 +513,10 @@ public class MainActivity extends Activity {
}
if (requestCode == 0) {
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 (resultCode == Activity.RESULT_OK) { //是否选择,没选择就不会继续
@@ -651,9 +656,9 @@ public class MainActivity extends Activity {
break;
case 1:
list_webView.remove(currentPage);
if(list_webView.size() == 0){
if (list_webView.size() == 0) {
newWindow(sharedPreferences.getString("homepage","http://www.baidu.com"));
}else{
} else {
currentPage--;
if (currentPage < 0) currentPage = 0;
button_page.setText(currentPage + 1 + "");
@@ -743,6 +748,7 @@ public class MainActivity extends Activity {
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);//设置该属性可以访问
} catch (Exception ex) {
}
try {
field.set(dialog, true);
@@ -780,7 +786,7 @@ public class MainActivity extends Activity {
@Override
public void onReceiveValue(String value) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", value);
if(!"null".equals(value)){
if(!value.equals("null")){
//字符串转Bitmaphttps://www.jianshu.com/p/c9a18050a249
byte[] bitmapArray = Base64.decode(value.split(",")[1], Base64.DEFAULT);
final Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
@@ -795,35 +801,10 @@ public class MainActivity extends Activity {
builder.setPositiveButton("保存", new DialogInterface.OnClickListener() {
@Override
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();
SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss");
String stime = SDF.format(date);
String path = dir + stime + ".jpg";
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);
Uri.parse(MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(), bitmap, stime, "海天鹰浏览器视频截图"));
}
});
builder.setNegativeButton("关闭", new DialogInterface.OnClickListener() {
@@ -832,7 +813,7 @@ public class MainActivity extends Activity {
}
});
builder.create().show();
}else{
} else {
Toast.makeText(getApplicationContext(), "请先播放视频或把视频独立播放", Toast.LENGTH_SHORT).show();
}
}
@@ -846,16 +827,16 @@ public class MainActivity extends Activity {
@Override
public void onReceiveValue(String value) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + value);
if(!"null".equals(value)) {
if(!value.equals("null")) {
try {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
String type = "video/*";
Uri uri = Uri.parse(value);
intent1.setDataAndType(uri, type);
startActivity(intent1);
} catch (ActivityNotFoundException e) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
Toast.makeText(getApplicationContext(), "系统默认播放器不能打开视频", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
@@ -939,7 +920,7 @@ public class MainActivity extends Activity {
}
}
String content="";
for(int i=0; i<rulelist.size(); i++){
for (int i=0; i<rulelist.size(); i++) {
content += rulelist.get(i) + "\n";
}
FileOutputStream outStream = null;
@@ -947,10 +928,8 @@ public class MainActivity extends Activity {
outStream = MainActivity.this.openFileOutput("blockrules", Context.MODE_PRIVATE);
outStream.write((content).getBytes());
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
}
dialogRule.dismiss();
ADBlock();
@@ -974,10 +953,8 @@ public class MainActivity extends Activity {
outStream.write((content+"\n").getBytes());
outStream.close();
ADBlock();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
}
}
@@ -1461,7 +1438,7 @@ public class MainActivity extends Activity {
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + getIntent() + ")");
super.onNewIntent(intent);
setIntent(intent);
if(getIntent().getDataString() != null) {
if (getIntent().getDataString() != null) {
urln = getIntent().getDataString();
Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + urln + ")");
newWindow(urln);
@@ -1556,8 +1533,7 @@ public class MainActivity extends Activity {
try {
urlcon = (HttpURLConnection) url.openConnection();
fileLength = urlcon.getContentLength();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
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();
}
}
}