package com.ysf.browser;
import android.app.*;
import android.content.*;
import android.net.*;
import android.os.*;
import android.webkit.*;
import android.widget.*;
//import com.ysf.libs.*;
import android.view.*;
import com.ysf.browser.activity.*;
import com.ysf.browser.other.*;
import android.text.*;
import android.view.inputmethod.*;
import com.ysf.libs.base.*;
import android.view.ContextMenu.*;
import android.webkit.WebView.HitTestResult;
import android.util.*;
//import Jama.*;
import android.graphics.drawable.*;
public class MainActivity extends Activity implements SlideListView.RemoveListener,SearchView.OnQueryTextListener,View.OnClickListener,AdapterView.OnItemClickListener,CompoundButton.OnCheckedChangeListener,View.OnCreateContextMenuListener,View.OnLongClickListener
{
private WebView webview;
private WebSettings settings;
private Activity activity;
private SPHelper sphelper;
private SlideListView recordList;
private SearchView searchView,goToWeb;
private FilterListAdapter recordAdapter;
private LinearLayout operateView;
private TextView recordNumtv,recordStatetv,recordMiddle;
private Switch recordSwitch;
private int recordnum = 0;
private boolean openDialog = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
activity = this;
sphelper = new SPHelper(activity,"WebViewSetting");
webview = (WebView)findViewById(R.id.mainWebView);
StaticValues.mainWebView = webview;
StaticValues.sphelper = this.sphelper;
goToWeb = new SearchView(activity);
searchView = (SearchView)findViewById(R.id.searhview);
recordList = (SlideListView)findViewById(R.id.recordListView);
operateView = (LinearLayout)findViewById(R.id.OperatLayout);
recordNumtv = (TextView)findViewById(R.id.recordNumTV);
recordStatetv = (TextView)findViewById(R.id.recordItemEndTV);
recordMiddle = (TextView)findViewById(R.id.recordMiddleTV);
recordSwitch = (Switch)findViewById(R.id.recordSwitch);
recordSwitch.setOnCheckedChangeListener(this);
findViewById(R.id.ClearRecordBtn).setOnClickListener(this);
findViewById(R.id.RecordCloseBtn).setOnClickListener(this);
findViewById(R.id.FilterSettingTV).setOnClickListener(this);
findViewById(R.id.FilterSettingTV).setOnLongClickListener(this);
recordList.setTextFilterEnabled(true);
searchView.setQueryHint("请输入关键字");
recordList.setRemoveListener(this);
searchView.setOnQueryTextListener(this);
searchView.setSubmitButtonEnabled(false);
goToWeb.setSubmitButtonEnabled(true);
goToWeb.setQueryHint("请输入网址");
recordAdapter = new FilterListAdapter(StaticValues.WebRecordings,activity);
recordList.setAdapter(recordAdapter);
recordList.setOnItemClickListener(this);
settings = webview.getSettings();
initWebView();
StaticValues.initWebSet();
goToWeb.setOnQueryTextListener(new SearchView.OnQueryTextListener(){
@Override
public boolean onQueryTextChange(String p1){return false;}
@Override
public boolean onQueryTextSubmit(String url)
{
if (url.contains("://"))
{
if (!(url.startsWith("http://")||url.startsWith("https://")))
openBrowser(url);
else webview.loadUrl(url);
}else webview.loadUrl("http://"+url);
return true;
}
});
goToWeb.setOnSearchClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1)
{
goToWeb.setQuery(webview.getUrl(),false);
}
});
}
private void initWebView()
{
settings.setJavaScriptEnabled(sphelper.getBoolInfo(StaticValues.SupportJS,true));
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setUseWideViewPort(true);
settings.setUserAgentString(StaticValues.UserAgentList[sphelper.getIntInfo(StaticValues.UserAgent,0)]);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) webview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webview.setScrollBarStyle(0);
webview.loadUrl("http://www.baidu.com");
webview.setOnCreateContextMenuListener(this);
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view,String url)
{
view.loadUrl(url);
return true;
}
public void onLoadResource(WebView view, String url)
{
if (!StaticValues.isFilter) return;
if (StaticValues.RecordFilterStr.trim().equals(""))
{
StaticValues.WebRecordings.add(url);
recordAdapter.notifyDataSetChanged();
recordNumtv.setText((recordnum++)+"");
}
else
{
if (url.contains(StaticValues.RecordFilterStr))
{
StaticValues.WebRecordings.add(url);
recordAdapter.notifyDataSetChanged();
recordNumtv.setText((recordnum++)+"");
}
}
}
});
webview.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
if (url != null && url.startsWith("http://"))
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
}
@Override
public boolean onLongClick(View p1)
{
StaticValues.isFilter = !StaticValues.isFilter;
if (StaticValues.isFilter) Toast.makeText(this,"已开始记录",0).show();
else Toast.makeText(this,"已停止记录",0).show();
return true;
}
@Override
public void onClick(View p1)
{
switch (p1.getId())
{
case R.id.RecordCloseBtn:
operateView.setVisibility(View.GONE);
break;
case R.id.ClearRecordBtn:
StaticValues.WebRecordings.clear();
recordAdapter.notifyDataSetChanged();
recordnum = 0; recordNumtv.setText("0");
recordStatetv.setText(""); recordMiddle.setText("");
break;
case R.id.FilterSettingTV:
final EditText tedit = new EditText(activity);tedit.setHint("请输入关键字");
new AlertDialog.Builder(activity).setTitle("url.contains").setView(tedit).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2)
{
String tRegs = tedit.getText().toString().trim();
if (tRegs.equals("")) Toast.makeText(activity,"记录时取消筛选",0).show();
else Toast.makeText(activity,"已启动记录时筛选条目",0).show();
StaticValues.RecordFilterStr = tRegs;
}
}).show().setCanceledOnTouchOutside(true);
break;
default:break;
}
}
@Override
public boolean onQueryTextChange(String newText)
{
if (TextUtils.isEmpty(newText)) recordAdapter.getFilter().filter(null);
else recordAdapter.getFilter().filter(newText.toString());
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
return true;
}
@Override
public void onCheckedChanged(CompoundButton p1, boolean p2)
{
openDialog = p2;
Toast.makeText(activity,"点击功能切换",0).show();
}
@Override
public void removeItem(SlideListView.RemoveDirection direction, int position) {
recordAdapter.remove(position);
switch (direction) {
case RIGHT:
Toast.makeText(activity, "向右删除"+ position, Toast.LENGTH_SHORT).show();
recordnum--; recordNumtv.setText(recordnum+"");
break;
case LEFT:
Toast.makeText(activity, "向左删除"+ position, Toast.LENGTH_SHORT).show();
recordnum--; recordNumtv.setText(recordnum+"");
break;
default:
Toast.makeText(activity, "default"+ position, Toast.LENGTH_SHORT).show();
break;
}
}
@Override
p
评论2