收藏夹增加在新窗口打开,简化视频截图代码
This commit is contained in:
parent
df3f62afed
commit
523181494c
|
@ -2,7 +2,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hty.browser"
|
||||
android:versionCode="4"
|
||||
android:versionName="4.19">
|
||||
android:versionName="4.21">
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
|
|
@ -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://www.jianshu.com/p/c9a18050a249" target="_blank">字符串转Bitmap</a></p>
|
||||
<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.18 (2021-06-01)</h3><ol><li>增加动态权限请求。</li></ol>
|
||||
<h3>V4.17 (2021-03-02)</h3><ol><li>允许HTTPS、HTTP混合内容,解决微信网页视频无法播放的问题。</li></ol>
|
||||
|
|
|
@ -76,11 +76,12 @@ public class FavoriteActivity extends Activity {
|
|||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||
String title = ((TextView) info.targetView.findViewById(R.id.title)).getText().toString();
|
||||
menu.setHeaderIcon(R.drawable.link);
|
||||
menu.setHeaderTitle(title);
|
||||
menu.add(0, 0, 0, "复制链接");
|
||||
menu.add(0, 1, 1, "删除");
|
||||
menu.add(0, 2, 2, "修改");
|
||||
menu.add(0, 3, 3, "分享");
|
||||
String[] sm = { "在新窗口中打开", "复制链接", "分享", "修改", "删除" };
|
||||
for (int i=0; i<sm.length; i++) {
|
||||
menu.add(0, i, i, sm[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
listView.setOnTouchListener(new View.OnTouchListener() {
|
||||
|
@ -93,8 +94,6 @@ public class FavoriteActivity extends Activity {
|
|||
search(editText.getText().toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
String[] sm = { "导出HTML", "导出CSV" };
|
||||
|
@ -140,24 +139,31 @@ public class FavoriteActivity extends Activity {
|
|||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
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()) {
|
||||
case 0:
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
String url = ((TextView) menuInfo.targetView.findViewById(R.id.website)).getText().toString();
|
||||
cm.setPrimaryClip(ClipData.newPlainText("link", url));
|
||||
Toast.makeText(getApplicationContext(), "链接已复制", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(FavoriteActivity.this, MainActivity.class);
|
||||
intent.putExtra("url", surl);
|
||||
intent.putExtra("newWindow", true);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
break;
|
||||
case 1:
|
||||
int id = Integer.parseInt(((TextView) menuInfo.targetView.findViewById(R.id.id)).getText().toString());
|
||||
DBHelper helper = new DBHelper(getApplicationContext());
|
||||
helper.del(id);
|
||||
search(editText.getText().toString());
|
||||
ClipboardManager CM = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
CM.setPrimaryClip(ClipData.newPlainText("link", surl));
|
||||
Toast.makeText(getApplicationContext(), "链接已复制", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case 2:
|
||||
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();
|
||||
intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
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);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
final EditText ET_title = new EditText(FavoriteActivity.this);
|
||||
|
@ -236,12 +242,11 @@ public class FavoriteActivity extends Activity {
|
|||
});
|
||||
builder.create().show();
|
||||
break;
|
||||
case 3:
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, ((TextView) menuInfo.targetView.findViewById(R.id.title)).getText().toString() + "\n" + ((TextView) menuInfo.targetView.findViewById(R.id.website)).getText().toString());
|
||||
intent.setType("text/plain");
|
||||
startActivity(Intent.createChooser(intent, "分享"));
|
||||
case 4:
|
||||
int id = Integer.parseInt(((TextView) menuInfo.targetView.findViewById(R.id.id)).getText().toString());
|
||||
DBHelper helper = new DBHelper(getApplicationContext());
|
||||
helper.del(id);
|
||||
search(editText.getText().toString());
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -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")){
|
||||
//字符串转Bitmap,https://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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -31,7 +31,7 @@
|
|||
<ImageButton
|
||||
android:id="@+id/imageButton_clear"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="#ffffff"
|
||||
android:paddingLeft="-15dp"
|
||||
|
|
Loading…
Reference in New Issue