增加GIF屏蔽;在Activity中处理屏蔽规则
This commit is contained in:
parent
7f634cc998
commit
9361ad849d
|
@ -2,11 +2,11 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hty.browser"
|
||||
android:versionCode="4"
|
||||
android:versionName="4.31">
|
||||
android:versionName="4.32">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 查询网络状态权限 -->
|
||||
<uses-permission android:name="andorid.permission.CHANGE_CONFIGURATION" />
|
||||
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
@ -17,7 +17,6 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
@ -63,6 +62,11 @@
|
|||
android:icon="@android:drawable/btn_star_big_on"
|
||||
android:label="收藏夹"
|
||||
android:parentActivityName=".MainActivity" />
|
||||
<activity
|
||||
android:name=".ADBlockActivity"
|
||||
android:icon="@drawable/adb"
|
||||
android:label="广告屏蔽"
|
||||
android:parentActivityName=".MainActivity" />
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:icon="@android:drawable/ic_menu_preferences"
|
||||
|
|
|
@ -9,7 +9,7 @@ p { text-indent:2em; }
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.30</h2>
|
||||
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.32</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.32 (2023-11-19)</h3><ol><li>增加GIF屏蔽。</li><li>在Activity中处理广告屏蔽规则。</li></ol>
|
||||
<h3>V4.31 (2023-04-17)</h3><ol><li>取消自动升级,以免因升级错误引起崩溃。</li></ol>
|
||||
<h3>V4.30 (2023-03-23)</h3><ol><li>收藏夹测试 ExpandableListView 控件</li></ol>
|
||||
<h3>V4.29 (2023-03-01)</h3><ol><li>收藏夹增加分类。</li><li>收藏夹分类的修改和删除。</li><li>修改导出HTML和CSV方法。</li><li>新建收藏和修改收藏编辑框设置最大行数,避免窗口撑大不完整。</li></ol>
|
||||
|
|
|
@ -0,0 +1,285 @@
|
|||
package com.hty.browser;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Color;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ADBlockActivity extends Activity {
|
||||
EditText editText;
|
||||
ImageButton imageButton_clear;
|
||||
ListView listView;
|
||||
ArrayAdapter<String> adapter;
|
||||
List<String> datas0, datas;
|
||||
//String[] SL;
|
||||
InputMethodManager IMM;
|
||||
int position;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_adblock);
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
IMM = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
editText = (EditText) findViewById(R.id.editText);
|
||||
editText.addTextChangedListener(new TextWatcher(){
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (s.toString().equals("")) {
|
||||
imageButton_clear.setVisibility(View.GONE);
|
||||
} else {
|
||||
imageButton_clear.setVisibility(View.VISIBLE);
|
||||
}
|
||||
search();
|
||||
}
|
||||
});
|
||||
|
||||
imageButton_clear = (ImageButton) findViewById(R.id.imageButton_clear);
|
||||
imageButton_clear.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
editText.setText("");
|
||||
}
|
||||
});
|
||||
imageButton_clear.setVisibility(View.GONE);
|
||||
|
||||
datas0 = new ArrayList<>();
|
||||
datas = new ArrayList<>();
|
||||
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, datas);
|
||||
listView = (ListView) findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
String title = ((TextView) info.targetView.findViewById(android.R.id.text1)).getText().toString();
|
||||
menu.setHeaderTitle(title);
|
||||
menu.setHeaderIcon(R.drawable.link);
|
||||
String[] sm = { "打开", "复制", "分享", "修改", "删除" };
|
||||
for (int i=0; i<sm.length; i++) {
|
||||
menu.add(0, i, i, sm[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//SL = readFile("blockrules").split(",");
|
||||
datas0 = Arrays.asList(readFile("blockrules").split(","));
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "Read: " + datas0.toString());
|
||||
search();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
String[] sm = { "重载", "保存", "退出" };
|
||||
for (int i=0; i<sm.length; i++) {
|
||||
menu.add(0, i, i, sm[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case 0:
|
||||
//SL = readFile("blockrules").split(",");
|
||||
datas0 = Arrays.asList(readFile("blockrules").split(","));
|
||||
search();
|
||||
break;
|
||||
case 1:
|
||||
String s = datas.toString().replace("[", "").replace("]", "");
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "Write: " + s);
|
||||
writeFile("blockrules", s);
|
||||
break;
|
||||
case 2:
|
||||
finish();
|
||||
break;
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
|
||||
int index = menuInfo.position;
|
||||
position = listView.getFirstVisiblePosition();
|
||||
String url = ((TextView) menuInfo.targetView.findViewById(android.R.id.text1)).getText().toString();
|
||||
switch (item.getItemId()) {
|
||||
case 0:
|
||||
Intent intent = new Intent(ADBlockActivity.this, MainActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
intent.putExtra("newWindow", true);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
break;
|
||||
case 1:
|
||||
ClipboardManager CM = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
CM.setPrimaryClip(ClipData.newPlainText("link", url));
|
||||
Toast.makeText(getApplicationContext(), "已复制", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case 2:
|
||||
intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
intent.setType("text/plain");
|
||||
startActivity(Intent.createChooser(intent, "分享"));
|
||||
break;
|
||||
case 3:
|
||||
final EditText editText_url = new EditText(ADBlockActivity.this);
|
||||
editText_url.setMaxLines(3);
|
||||
editText_url.setHint("网址");
|
||||
editText_url.setText(url);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ADBlockActivity.this);
|
||||
builder.setIcon(android.R.drawable.btn_star_big_on);
|
||||
builder.setTitle("修改");
|
||||
builder.setView(editText_url);
|
||||
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String surl = editText_url.getText().toString();
|
||||
Field field = null;
|
||||
try {
|
||||
//通过反射获取dialog中的私有属性mShowing
|
||||
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
|
||||
field.setAccessible(true);//设置该属性可以访问
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (surl.startsWith("http://") || surl.startsWith("https://") && !url.equals(surl)) {
|
||||
datas.set(index, surl);
|
||||
adapter.notifyDataSetChanged();
|
||||
} else {
|
||||
editText_url.setError("网址错误!");
|
||||
try {
|
||||
//设置dialog不可关闭
|
||||
field.set(dialog, false);
|
||||
dialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
IMM.hideSoftInputFromWindow(editText_url.getWindowToken(), 0);
|
||||
Field field = null;
|
||||
try {
|
||||
//通过反射获取dialog中的私有属性mShowing
|
||||
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
|
||||
field.setAccessible(true);//设置该属性可以访问
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
field.set(dialog, true);
|
||||
dialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
break;
|
||||
case 4:
|
||||
position = listView.getFirstVisiblePosition();
|
||||
datas.remove(url);
|
||||
adapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void search() {
|
||||
datas.clear();
|
||||
String s = editText.getText().toString();
|
||||
for (int i=0; i<datas0.size(); i++) {
|
||||
if (s.equals("") || datas0.get(i).contains(s))
|
||||
datas.add(datas0.get(i));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
String readFile(String filename) {
|
||||
String s = "";
|
||||
FileInputStream FIS;
|
||||
try {
|
||||
FIS = openFileInput(filename);
|
||||
byte[] buffer = new byte[1024];
|
||||
ByteArrayOutputStream BAOS = new ByteArrayOutputStream();
|
||||
int len;
|
||||
while ((len = FIS.read(buffer)) != -1) {
|
||||
BAOS.write(buffer, 0, len);
|
||||
}
|
||||
s = BAOS.toString();
|
||||
FIS.close();
|
||||
BAOS.close();
|
||||
return s;
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
void writeFile(String filename, String s) {
|
||||
FileOutputStream outStream = null;
|
||||
try {
|
||||
outStream = openFileOutput("blockrules", Context.MODE_PRIVATE);
|
||||
outStream.write(s.getBytes());
|
||||
outStream.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -43,7 +43,6 @@ import android.content.res.Configuration;
|
|||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.media.MediaScannerConnection;
|
||||
|
@ -150,6 +149,14 @@ public class MainActivity extends Activity {
|
|||
dir.mkdirs();
|
||||
}
|
||||
|
||||
String path1 = getFilesDir().getAbsolutePath() + "/blockrules";
|
||||
File file = new File(path1);
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
|
||||
|
@ -673,7 +680,7 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
|
||||
private void MenuDialog() {
|
||||
String[] items = { "新建窗口", "关闭当前窗口", "收藏当前页", "收藏夹", "查找", "分享", "网页信息", "视频独立播放", "视频截图", "视频在播放器中打开", "资源探查", "查看源码", "保存", "全屏", "广告过滤规则", "清除当前页面缓存", "设置", "检查更新", "关于", "退出", "ExpandableListView" };
|
||||
String[] items = { "新建窗口", "关闭当前窗口", "收藏当前页", "收藏夹", "查找", "分享", "网页信息", "视频独立播放", "视频截图", "视频在播放器中打开", "资源探查", "查看源码", "保存", "全屏", "广告屏蔽", "清除当前页面缓存", "设置", "检查更新", "关于", "退出", "ExpandableListView" };
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("菜单");
|
||||
//builder.setIcon(android.R.drawable.ic_menu_preferences);
|
||||
|
@ -689,7 +696,7 @@ public class MainActivity extends Activity {
|
|||
case 1:
|
||||
list_webView.remove(currentPage);
|
||||
if (list_webView.size() == 0) {
|
||||
newWindow(sharedPreferences.getString("homepage","http://www.baidu.com"));
|
||||
newWindow(sharedPreferences.getString("homepage", "http://www.baidu.com"));
|
||||
} else {
|
||||
if (currentPage == list_webView.size())
|
||||
currentPage--;
|
||||
|
@ -716,7 +723,7 @@ public class MainActivity extends Activity {
|
|||
editText_url.setText(list_webView.get(currentPage).getUrl());
|
||||
layout.addView(editText_url);
|
||||
final Spinner spinner = new Spinner(MainActivity.this);
|
||||
spinner.setBackgroundColor(Color.GRAY);
|
||||
//spinner.setBackgroundColor(Color.GRAY);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
DBHelper helper = new DBHelper(MainActivity.this);
|
||||
Cursor cursor = helper.category();
|
||||
|
@ -940,7 +947,7 @@ public class MainActivity extends Activity {
|
|||
isFullScreen = true;
|
||||
break;
|
||||
case 14:
|
||||
DialogBlockList();
|
||||
startActivityForResult(new Intent(MainActivity.this, ADBlockActivity.class), 0);
|
||||
break;
|
||||
case 15:
|
||||
list_webView.get(currentPage).clearCache(true);
|
||||
|
@ -970,19 +977,19 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
|
||||
void DialogBlock(String content){
|
||||
final EditText ETrule = new EditText(this);
|
||||
ETrule.setText(content);
|
||||
final AlertDialog dialogRule = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setTitle("屏蔽规则").setView(ETrule).setCancelable(false).setPositiveButton("添加",null).setNeutralButton("删除",null).setNegativeButton("取消",null).create();
|
||||
dialogRule.show();
|
||||
dialogRule.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
final EditText edit_rule = new EditText(this);
|
||||
edit_rule.setText(content);
|
||||
final AlertDialog dialog = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setTitle("屏蔽规则").setView(edit_rule).setCancelable(false).setPositiveButton("添加",null).setNegativeButton("取消",null).create();
|
||||
dialog.show();
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean exist = false;
|
||||
String rule = ETrule.getText().toString();
|
||||
List<String> rulelist = new ArrayList<String>(Arrays.asList(ReadFile("blockrules").split("\n")));
|
||||
for(int i=0;i<rulelist.size();i++){
|
||||
if(rulelist.get(i).equals(rule)){
|
||||
String rule = edit_rule.getText().toString();
|
||||
List<String> list_rule = new ArrayList<>(Arrays.asList(readFile("blockrules").split(",")));
|
||||
for (int i=0; i<list_rule.size(); i++) {
|
||||
if (list_rule.get(i).equals(rule)) {
|
||||
Toast.makeText(MainActivity.this, "此条规则已经存在!", Toast.LENGTH_SHORT).show();
|
||||
exist = true;
|
||||
break;
|
||||
|
@ -990,55 +997,26 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
if (!exist) {
|
||||
addRule(rule);
|
||||
dialogRule.dismiss();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
dialogRule.getButton(AlertDialog.BUTTON_NEUTRAL)
|
||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String rule = ETrule.getText().toString();
|
||||
List<String> rulelist = new ArrayList<String>(Arrays.asList(ReadFile("blockrules").split("\n")));
|
||||
for(int i=0;i<rulelist.size();i++){
|
||||
if(rulelist.get(i).equals(rule)){
|
||||
rulelist.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
String content="";
|
||||
for (int i=0; i<rulelist.size(); i++) {
|
||||
content += rulelist.get(i) + "\n";
|
||||
}
|
||||
FileOutputStream outStream = null;
|
||||
try {
|
||||
outStream = MainActivity.this.openFileOutput("blockrules", Context.MODE_PRIVATE);
|
||||
outStream.write((content).getBytes());
|
||||
outStream.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
|
||||
}
|
||||
dialogRule.dismiss();
|
||||
ADBlock();
|
||||
}
|
||||
}
|
||||
);
|
||||
dialogRule.getButton(AlertDialog.BUTTON_NEGATIVE)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialogRule.dismiss();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void addRule(String content){
|
||||
void addRule(String content) {
|
||||
FileOutputStream outStream = null;
|
||||
try {
|
||||
outStream = openFileOutput("blockrules", Context.MODE_APPEND);
|
||||
outStream.write((content+"\n").getBytes());
|
||||
outStream.write(("," + content).getBytes());
|
||||
outStream.close();
|
||||
ADBlock();
|
||||
} catch (Exception e) {
|
||||
|
@ -1046,102 +1024,44 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
void DialogBlockList(){
|
||||
final String[] datas = ReadFile("blockrules").split("\n");
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, datas);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setIcon(R.drawable.ic_launcher);
|
||||
builder.setTitle("屏蔽规则列表:");
|
||||
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
DialogBlock(datas[which]);
|
||||
//Toast.makeText(MainActivity.this, "你点击了第" + which + "个item", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton("清空", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
|
||||
builder1.setMessage("操作不可逆,确认清空吗?");
|
||||
builder1.setIcon(R.drawable.ic_launcher);
|
||||
builder1.setTitle("警告");
|
||||
builder1.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String filepath = getFilesDir().getAbsolutePath() + "/blockrules";
|
||||
File file = new File(filepath);
|
||||
//if(file.isFile() && file.exists()) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", String.valueOf(file.delete()));
|
||||
//}
|
||||
}
|
||||
});
|
||||
builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
builder1.create().show();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
String ReadFile(String filename) {
|
||||
String readFile(String filename) {
|
||||
String s = "";
|
||||
FileInputStream istream;
|
||||
try {
|
||||
istream = MainActivity.this.openFileInput(filename);
|
||||
istream = openFileInput(filename);
|
||||
byte[] buffer = new byte[1024];
|
||||
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
|
||||
int len;
|
||||
while ((len = istream.read(buffer)) != -1) {
|
||||
ostream.write(buffer, 0, len);
|
||||
}
|
||||
s = new String(ostream.toByteArray());
|
||||
s = ostream.toString();
|
||||
istream.close();
|
||||
ostream.close();
|
||||
return s;
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
String path = getFilesDir().getAbsolutePath() + "/blockrules";
|
||||
File file = new File(path);
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e1) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e1);
|
||||
}
|
||||
return s;
|
||||
} catch (IOException e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
void ADBlock(){
|
||||
String s = ReadFile("blockrules");
|
||||
void ADBlock() {
|
||||
String s = readFile("blockrules");
|
||||
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + s);
|
||||
if(!"".equals(s)) {
|
||||
String rules = s.replace("\n", ",");
|
||||
if (rules.endsWith(",")) {
|
||||
rules = rules.substring(0, rules.length() - 1);
|
||||
}
|
||||
String js = "javascript:var rules='" + rules + "';var rule=new Array();rule=rules.split(',');var img=document.getElementsByTagName('img');for(i=0;i<img.length;i++){for(j=0;j<rule.length;j++){if(img[i].src.indexOf(rule[j])!=-1){img[i].style.display='none';}}}";
|
||||
if(!s.equals("")) {
|
||||
// if (s.endsWith(",")) {
|
||||
// s = s.substring(0, s.length() - 1);
|
||||
// }
|
||||
String js = "javascript:var rules='" + s + "';var rule=new Array();rule=rules.split(',');var img=document.getElementsByTagName('img');for(i=0;i<img.length;i++){for(j=0;j<rule.length;j++){if(img[i].src.indexOf(rule[j])!=-1){img[i].style.display='none';}}}";
|
||||
list_webView.get(currentPage).loadUrl(js);
|
||||
}
|
||||
}
|
||||
|
||||
void GIFBlock() {
|
||||
String js = "javascript:var img=document.getElementsByTagName('img');for(i=0;i<img.length;i++){if(img[i].src.indexOf('.gif')!=-1){img[i].style.display='none';}}";
|
||||
list_webView.get(currentPage).loadUrl(js);
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -1414,6 +1334,9 @@ public class MainActivity extends Activity {
|
|||
if (sharedPreferences.getBoolean("switch_adBlock", false)) {
|
||||
ADBlock();
|
||||
}
|
||||
if (sharedPreferences.getBoolean("switch_gifBlock", false)) {
|
||||
GIFBlock();
|
||||
}
|
||||
if (sharedPreferences.getBoolean("switch_iframeBlock", false)) {
|
||||
if (view.getUrl() != null) {
|
||||
if (!view.getUrl().contains("baidu.com")) {
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="搜索"
|
||||
android:singleLine="true" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/imageButton_clear"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@null"
|
||||
android:src="@android:drawable/ic_menu_close_clear_cancel" />
|
||||
</LinearLayout>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
|
@ -14,9 +14,14 @@
|
|||
android:title="电脑模式"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="switch_adBlock"
|
||||
android:defaultValue="true"
|
||||
android:title="广告过滤"/>
|
||||
android:title="广告过滤" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="switch_gifBlock"
|
||||
android:title="GIF过滤" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="switch_iframeBlock"
|
||||
|
|
Loading…
Reference in New Issue