/** * Creates a new WebViewer component. * * @param container container the component will be placed in */ public WebViewer(ComponentContainer container) { super(container); webview = new WebView(container.$context()); webview.setWebViewClient(new WebViewerClient()); webview.getSettings().setJavaScriptEnabled(true); webview.setFocusable(true); // enable pinch zooming and zoom controls webview.getSettings().setBuiltInZoomControls(true); container.$add(this); webview.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); // set the initial default properties. Height and Width // will be fill-parent, which will be the default for the web viewer. followLinks = true; HomeUrl(""); Width(LENGTH_FILL_PARENT); Height(LENGTH_FILL_PARENT); }
private void initViewer() { settings.setLoadsImagesAutomatically(true); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setLightTouchEnabled(true); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); viewer.setInitialScale(0); viewer.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); viewer.setHorizontalScrollBarEnabled(false); viewer.setVerticalScrollBarEnabled(false); viewer.setBackgroundColor(0x000000); viewer.clearCache(true); viewer.setFocusable(false); viewer.setWebViewClient( new WebViewClient() { @Override public void onPageFinished(WebView view, String url) {} @Override public void onReceivedError( WebView view, int errorCode, String description, String failingUrl) {} @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); }
/** * 初始化webview,进行必须的设置 * * @param view */ private void initWebView(WebView view) { view.setVerticalScrollBarEnabled(false); view.setHorizontalScrollBarEnabled(false); view.addJavascriptInterface(new JSInterface(), "base"); view.addJavascriptInterface(new JSContactInterface(contact), "contact"); view.addJavascriptInterface(new JSMessageInterface(message), "message"); view.addJavascriptInterface(new JSApplicationInterface(appManager), "application"); view.addJavascriptInterface(new JSMotionInterface(), "motion"); view.setFocusable(false); }
public View getView(int position, View convertView, ViewGroup parent) { MovieYoutubeGridViewHolder viewHolder; TextView tvTitle; TextView tvPublishTime; WebView wvWebViewImage; if (convertView == null) { convertView = inflater.inflate(R.layout.movie_youtube_item_gridview, null); viewHolder = new MovieYoutubeGridViewHolder(); viewHolder.title = tvTitle = (TextView) convertView.findViewById(R.id.title); // title viewHolder.publishTime = tvPublishTime = (TextView) convertView.findViewById(R.id.publishTime); wvWebViewImage = (WebView) convertView.findViewById(R.id.webViewImage); wvWebViewImage.setBackgroundColor(0); wvWebViewImage.setFocusableInTouchMode(false); wvWebViewImage.setFocusable(false); wvWebViewImage.setClickable(false); wvWebViewImage.setLongClickable(false); viewHolder.webViewImage = wvWebViewImage; convertView.setTag(viewHolder); } else { viewHolder = (MovieYoutubeGridViewHolder) convertView.getTag(); tvTitle = viewHolder.title; // title tvPublishTime = viewHolder.publishTime; wvWebViewImage = viewHolder.webViewImage; } YouTubeVideo movie = data.get(position); // Setting all values in listview tvTitle.setText(movie.getTitle()); tvTitle.setTag(movie.getID()); tvPublishTime.setText("Đăng lúc " + movie.getPublishedTime()); String contentImage = "<!DOCTYPE html><head> <meta http-equiv=\"Content-Type\" " + "content=\"text/html; charset=utf-8\"> </head><body><div style=\"background-color: rgba(10,10,10,0.5); " + "\"> " + "<img width='100%' src='" + movie.getThumbnailDefaut() + "'></img>" + "</div> </body></html>"; wvWebViewImage.loadDataWithBaseURL(null, contentImage, "text/html", "utf-8", null); return convertView; }
public static void initWebView(Context context, WebView mWebView) { if (mWebView != null) { mWebView.setDrawingCacheBackgroundColor(0x00000000); mWebView.setFocusableInTouchMode(true); mWebView.setFocusable(true); mWebView.setAnimationCacheEnabled(false); mWebView.setDrawingCacheEnabled(true); mWebView.setBackgroundColor(context.getResources().getColor(android.R.color.white)); mWebView.getRootView().setBackgroundDrawable(null); mWebView.setWillNotCacheDrawing(false); mWebView.setAlwaysDrawnWithCacheEnabled(true); mWebView.setScrollbarFadingEnabled(true); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setVerticalScrollBarEnabled(true); mWebView.setSaveEnabled(true); mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); initializeSettings(mWebView.getSettings(), context); } }
@SuppressLint("SetJavaScriptEnabled") @Override public View getView(int position, View contentView, ViewGroup parent) { info = this.getItem(position); View rowView = this.viewMap.get(position); if (rowView == null) { try { LayoutInflater inflater = ((Activity) this.getContext()).getLayoutInflater(); rowView = inflater.inflate(R.layout.list_items, null); // 屏蔽转发 rowView.findViewById(R.id.forwardCount).setVisibility(View.INVISIBLE); rowView.findViewById(R.id.forwardCount2).setVisibility(View.INVISIBLE); rowView.findViewById(R.id.forwardCount_img).setVisibility(View.INVISIBLE); rowView.findViewById(R.id.forwardCount2_img).setVisibility(View.INVISIBLE); TextView username = (TextView) rowView.findViewById(R.id.username); username.setText(info.getUser().getUserName()); username.getPaint().setFakeBoldText(true); TextView blogText = (TextView) rowView.findViewById(R.id.comment); blogText.setText( new ShareActivity(context) .imgReplaceText( blogText, info.getLiveBlog().getBlogContent(), context, false)); // 转换表情 if (info.getLiveBlog().getBlogPic() != null && !"".equals(info.getLiveBlog().getBlogPic())) { WebView imgThumb = (WebView) rowView.findViewById(R.id.imgThumb); imgThumb.setVisibility(View.VISIBLE); imgThumb.setHorizontalScrollBarEnabled(false); imgThumb.setVerticalScrollBarEnabled(false); imgThumb.setFocusable(false); imgThumb.setBackgroundColor(0); imgThumb.getSettings().setJavaScriptEnabled(true); imgThumb.addJavascriptInterface(this, "miblogscript"); // 在引解析缩略图地址 String[] tempImgPath = info.getLiveBlog().getBlogPic().split(","); String thumbPic = info.getLiveBlog().getLargePic().replace(tempImgPath[0], tempImgPath[1]); info.getLiveBlog().setThumbPic(thumbPic); imgThumb.loadDataWithBaseURL( null, MyMethods.getHtmlWithA( info.getLiveBlog().getLargePic(), info.getLiveBlog().getThumbPic()), "text/html", "UTF-8", null); ImageView pic = (ImageView) rowView.findViewById(R.id.pic); pic.setVisibility(View.VISIBLE); } if (info.getLiveBlog().getOrigBlog() != null) { TextView quote = (TextView) rowView.findViewById(R.id.quote); TextView quotename = (TextView) rowView.findViewById(R.id.quotename); rowView.findViewById(R.id.quotelayou).setVisibility(View.VISIBLE); rowView.findViewById(R.id.quote_bg1).setVisibility(View.VISIBLE); rowView.findViewById(R.id.quote_bg2).setVisibility(View.VISIBLE); quote.setText( new ShareActivity(context).imgReplaceText(quote, "被转发的内容", context, false)); // 转换表情 quotename.setVisibility(View.VISIBLE); quotename.setText("名字需要重新定义"); ShareActivity.otherUserInfo(quotename, 100, this.getContext()); WebView iii = (WebView) rowView.findViewById(R.id.forwordimgThumb); iii.setHorizontalScrollBarEnabled(false); iii.setVerticalScrollBarEnabled(false); iii.setFocusable(false); iii.setBackgroundColor(Color.parseColor("#EEEEEE")); iii.getSettings().setJavaScriptEnabled(true); iii.addJavascriptInterface(this, "miblogscript"); iii.loadDataWithBaseURL( null, MyMethods.getHtmlWithA( info.getLiveBlog().getOrigBlog().getBlogPic(), info.getLiveBlog().getOrigBlog().getLargePic()), "text/html", "UTF-8", null); // TextView resendcount2 = (TextView) rowView.findViewById(R.id.forwardCount2); TextView replaycount2 = (TextView) rowView.findViewById(R.id.replyCount2); // resendcount2.setText("11"); replaycount2.setText("21"); } else { rowView.findViewById(R.id.quotelayou).setVisibility(View.GONE); rowView.findViewById(R.id.quote_bg1).setVisibility(View.GONE); rowView.findViewById(R.id.quote_bg2).setVisibility(View.GONE); } TextView comefrom = (TextView) rowView.findViewById(R.id.comefrom); comefrom.setText(info.getLiveBlog().getSourceFrom()); TextView time = (TextView) rowView.findViewById(R.id.time); time.setText(info.getLiveBlog().getCreateTime()); rowView.findViewById(R.id.statCount).setVisibility(View.VISIBLE); // TextView resendcount = (TextView) rowView.findViewById(R.id.forwardCount); TextView replaycount = (TextView) rowView.findViewById(R.id.replyCount); // resendcount.setText(info.getLiveBlog().getForwardNum() + ""); replaycount.setText(info.getLiveBlog().getCommentNum() + ""); // 头像 WebView imageView = (WebView) rowView.findViewById(R.id.ItemWebImage); imageView.getSettings().setJavaScriptEnabled(true); imageView.setBackgroundColor(Color.parseColor("#EEEEEE")); imageView.setHorizontalScrollBarEnabled(false); imageView.setVerticalScrollBarEnabled(false); imageView.setFocusable(false); imageView.loadDataWithBaseURL( null, MyMethods.getHtml(info.getUser().getUserPic()), "text/html", "UTF-8", null); } catch (Exception e) { e.printStackTrace(); } viewMap.put(position, rowView); } return viewMap.get(position); }
public void handleMessage(Message msg) { if (msg.what == COMPLETE) { webview.setFocusable(true); webview.requestFocus(); } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.intro); JSVersion jsVersion = new JSVersion(); String title = getString(R.string.intro_title, jsVersion.shortVersion()); setTitle(title); WebView wv = (WebView) findViewById(R.id.web); if (wv != null) { wv.getSettings().setJavaScriptEnabled(true); wv.addJavascriptInterface(jsVersion, "JSAppVersion"); wv.loadUrl("file:///android_asset/intro.html"); wv.setFocusable(true); wv.setFocusableInTouchMode(true); wv.requestFocus(); } boolean hideControls = false; Intent i = getIntent(); if (i != null) { Bundle e = i.getExtras(); if (e != null) hideControls = e.getBoolean(EXTRA_NO_CONTROLS); } CheckBox dismiss = (CheckBox) findViewById(R.id.dismiss); if (dismiss != null) { if (hideControls) { dismiss.setVisibility(View.GONE); } else { final PrefsValues pv = new PrefsValues(this); dismiss.setChecked(pv.isIntroDismissed()); dismiss.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { pv.setIntroDismissed(isChecked); } }); } } Button cont = (Button) findViewById(R.id.cont); if (cont != null) { if (hideControls) { cont.setVisibility(View.GONE); } else { cont.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // close activity finish(); } }); } } }
/** * Creates a new Survey component. * * @param container container the component will be placed in * @throws IOException */ public Survey(ComponentContainer container) throws IOException { super(container); mainUI = container.$form(); exportRoot = new java.io.File(Environment.getExternalStorageDirectory(), mainUI.getPackageName()) + java.io.File.separator + "export"; JsonParser parse = new JsonParser(); webview = new WebView(container.$context()); webview.getSettings().setJavaScriptEnabled(true); webview.setFocusable(true); webview.setVerticalScrollBarEnabled(true); container.$add(this); webview.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); // set the initial default properties. Height and Width // will be fill-parent, which will be the default for the web viewer. Width(LENGTH_FILL_PARENT); Height(LENGTH_FILL_PARENT); // set default survey style style = TEXTBOX; // default style // see if the Survey is created by someone tapping on a notification! // create the Survey and load it in the webviewer /* e.g. * value = { * "style": "multipleChoice", * "question": "What is your favorite food" * "options": ["apple", "banana", "strawberry", "orange"], * "surveyGroup": "MIT-food-survey" * } * */ initValues = container.$form().getSurveyStartValues(); Log.i(TAG, "startVal Suvey:" + initValues.toString()); if (initValues != "") { JsonObject values = (JsonObject) parse.parse(initValues); this.style = values.get("style").getAsString(); this.question = values.get("question").getAsString(); this.surveyGroup = values.get("surveyGroup").getAsString(); ArrayList<String> arrOptions = new ArrayList<String>(); JsonArray _options = values.get("options").getAsJsonArray(); for (int i = 0; i < _options.size(); i++) { arrOptions.add(_options.get(i).getAsString()); } this.options = arrOptions; this.styleFromIntent = values.get("style").getAsString(); Log.i(TAG, "Survey component got created"); } }