List of usage examples for android.webkit WebViewClient WebViewClient
WebViewClient
From source file:org.zeroxlab.benchmark.Benchmark.java
private void initViews() { /*/*from w w w. ja v a 2 s. c o m*/ mRun = (Button)findViewById(R.id.btn_run); mRun.setOnClickListener(this); mShow = (Button)findViewById(R.id.btn_show); mShow.setOnClickListener(this); mShow.setClickable(false); mLinearLayout = (LinearLayout)findViewById(R.id.list_container); mMainView = (LinearLayout)findViewById(R.id.main_view); mBannerInfo = (TextView)findViewById(R.id.banner_info); mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com"); */ mTabHost = getTabHost(); int length = mCases.size(); mCheckList = new CheckBox[length]; mDesc = new TextView[length]; for (int i = 0; i < length; i++) { mCheckList[i] = new CheckBox(this); mCheckList[i].setText(mCases.get(i).getTitle()); mDesc[i] = new TextView(this); mDesc[i].setText(mCases.get(i).getDescription()); mDesc[i].setTextSize(mDesc[i].getTextSize() - 2); mDesc[i].setPadding(42, 0, 10, 10); } TabContentFactory mTCF = new TabContentFactory() { public View createTabContent(String tag) { ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); wrapContent.gravity = Gravity.CENTER; LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); weightedFillWrap.weight = 1; if (tag.equals(MAIN)) { LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this); mMainViewContainer.setOrientation(1); ImageView mIconView = new ImageView(Benchmark.this); mIconView.setImageResource(R.drawable.icon); TextView mBannerInfo = new TextView(Benchmark.this); mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:"); d2CheckBox = new CheckBox(Benchmark.this); d2CheckBox.setText(D2); d2CheckBox.setOnClickListener(Benchmark.this); d2HWCheckBox = new CheckBox(Benchmark.this); d2HWCheckBox.setText(D2HW); d2HWCheckBox.setOnClickListener(Benchmark.this); d2SW1CheckBox = new CheckBox(Benchmark.this); d2SW1CheckBox.setText(D2SW1); d2SW1CheckBox.setOnClickListener(Benchmark.this); d2SW2CheckBox = new CheckBox(Benchmark.this); d2SW2CheckBox.setText(D2SW2); d2SW2CheckBox.setOnClickListener(Benchmark.this); d3CheckBox = new CheckBox(Benchmark.this); d3CheckBox.setText(D3); d3CheckBox.setOnClickListener(Benchmark.this); mathCheckBox = new CheckBox(Benchmark.this); mathCheckBox.setText(MATH); mathCheckBox.setOnClickListener(Benchmark.this); vmCheckBox = new CheckBox(Benchmark.this); vmCheckBox.setText(VM); vmCheckBox.setOnClickListener(Benchmark.this); nativeCheckBox = new CheckBox(Benchmark.this); nativeCheckBox.setText(NATIVE); nativeCheckBox.setOnClickListener(Benchmark.this); miscCheckBox = new CheckBox(Benchmark.this); miscCheckBox.setText(MISC); miscCheckBox.setOnClickListener(Benchmark.this); filterBitmapCheckBox = new CheckBox(Benchmark.this); filterBitmapCheckBox.setText("Filter Bitmap in Draw Image"); filterBitmapCheckBox.setOnClickListener(Benchmark.this); useGradientCheckBox = new CheckBox(Benchmark.this); useGradientCheckBox.setText("Use Gradient in Draw Canvas/Circle/Rect/Arc"); useGradientCheckBox.setOnClickListener(Benchmark.this); useTextureCheckBox = new CheckBox(Benchmark.this); useTextureCheckBox.setText("Use Texture in Draw Canvas/Circle/Rect/Arc"); useTextureCheckBox.setOnClickListener(Benchmark.this); TextView mWebInfo = new TextView(Benchmark.this); mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com"); LinearLayout mButtonContainer = new LinearLayout(Benchmark.this); mRun = new Button(Benchmark.this); mShow = new Button(Benchmark.this); mRun.setText("Run"); mShow.setText("Show"); mRun.setOnClickListener(Benchmark.this); mShow.setOnClickListener(Benchmark.this); mButtonContainer.addView(mRun, weightedFillWrap); mButtonContainer.addView(mShow, weightedFillWrap); WebView mTracker = new WebView(Benchmark.this); mTracker.clearCache(true); mTracker.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url); } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "Track err: " + description); } }); mTracker.loadUrl(trackerUrl); mMainViewContainer.addView(mIconView, wrapContent); mMainViewContainer.addView(mBannerInfo); mMainViewContainer.addView(mathCheckBox); mMainViewContainer.addView(d2CheckBox); mMainViewContainer.addView(d2HWCheckBox); mMainViewContainer.addView(d2SW1CheckBox); mMainViewContainer.addView(d2SW2CheckBox); mMainViewContainer.addView(d3CheckBox); mMainViewContainer.addView(vmCheckBox); mMainViewContainer.addView(nativeCheckBox); mMainViewContainer.addView(miscCheckBox); mMainViewContainer.addView(filterBitmapCheckBox); mMainViewContainer.addView(useGradientCheckBox); mMainViewContainer.addView(useTextureCheckBox); mMainViewContainer.addView(mWebInfo); mMainViewContainer.addView(mButtonContainer, fillWrap); mMainViewContainer.addView(mTracker, 0, 0); mListScroll.addView(mMainViewContainer, fillParent); mMainView.addView(mListScroll, fillWrap); return mMainView; } LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mListContainer = new LinearLayout(Benchmark.this); mListContainer.setOrientation(1); mListScroll.addView(mListContainer, fillParent); mMainView.addView(mListScroll, fillWrap); boolean gray = true; int length = mCases.size(); Log.i(TAG, "L: " + length); Log.i(TAG, "TCF: " + tag); for (int i = 0; i < length; i++) { if (!mCategory.get(tag).contains(mCases.get(i))) continue; Log.i(TAG, "Add: " + i); mListContainer.addView(mCheckList[i], fillWrap); mListContainer.addView(mDesc[i], fillWrap); if (gray) { int color = 0xFF333333; //ARGB mCheckList[i].setBackgroundColor(color); mDesc[i].setBackgroundColor(color); } gray = !gray; } return mMainView; } }; mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2HW).setIndicator(D2HW, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2SW1).setIndicator(D2SW1, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2SW2).setIndicator(D2SW2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(NATIVE) .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc)) .setContent(mTCF)); }
From source file:com.openatk.fieldnotebook.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.main_menu_add) { addFieldMapView();/*from ww w. j a va 2 s . c o m*/ return true; } else if (item.getItemId() == R.id.main_menu_current_location) { Location myLoc = map.getMyLocation(); if (myLoc == null) { Toast.makeText(this, "Still searching for your location", Toast.LENGTH_SHORT).show(); } else { CameraPosition oldPos = map.getCameraPosition(); CameraPosition newPos = new CameraPosition(new LatLng(myLoc.getLatitude(), myLoc.getLongitude()), map.getMaxZoomLevel(), oldPos.tilt, oldPos.bearing); map.animateCamera(CameraUpdateFactory.newCameraPosition(newPos)); } return true; } else if (item.getItemId() == R.id.main_menu_list_view) { /*if(sliderIsShowing == 0){ showSlider(true); } else { hideSlider(true); } if (mCurrentState == STATE_LIST_VIEW) { // Show map view Log.d("MainActivity", "Showing map view"); setState(STATE_DEFAULT); //item.setIcon(R.drawable.list_view); } else { // Show list view Log.d("MainActivity", "Showing list view"); setState(STATE_LIST_VIEW); //item.setIcon(R.drawable.map_view); }*/ return true; } else if (item.getItemId() == R.id.main_menu_help) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Help"); WebView wv = new WebView(this); wv.loadUrl("file:///android_asset/Help.html"); wv.getSettings().setSupportZoom(true); wv.getSettings().setBuiltInZoomControls(true); wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); alert.setView(wv); alert.setNegativeButton("Close", null); alert.show(); return true; } else if (item.getItemId() == R.id.main_menu_legal) { CharSequence licence = "The MIT License (MIT)\n" + "\n" + "Copyright (c) 2013 Purdue University\n" + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy " + "of this software and associated documentation files (the \"Software\"), to deal " + "in the Software without restriction, including without limitation the rights " + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell " + "copies of the Software, and to permit persons to whom the Software is " + "furnished to do so, subject to the following conditions:" + "\n" + "The above copyright notice and this permission notice shall be included in " + "all copies or substantial portions of the Software.\n" + "\n" + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR " + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, " + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER " + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, " + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN " + "THE SOFTWARE.\n"; new AlertDialog.Builder(this).setTitle("Legal").setMessage(licence) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton("Close", null).show(); return true; } return super.onOptionsItemSelected(item); }
From source file:org.brandroid.openmanager.fragments.DialogHandler.java
public static void showAboutDialog(final Context mContext) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = li.inflate(R.layout.about, null); String sVersionInfo = ""; try {// w ww. j ava2 s.co m PackageInfo pi = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0); sVersionInfo += pi.versionName; if (!pi.versionName.contains("" + pi.versionCode)) sVersionInfo += " (" + pi.versionCode + ")"; if (OpenExplorer.IS_DEBUG_BUILD) sVersionInfo += " *debug*"; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String sBuildTime = ""; try { sBuildTime = SimpleDateFormat.getInstance() .format(new Date(new ZipFile( mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0).sourceDir) .getEntry("classes.dex").getTime())); } catch (Exception e) { Logger.LogError("Couldn't get Build Time.", e); } WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); Display d = wm.getDefaultDisplay(); String sHardwareInfo = "Display:\n"; sHardwareInfo += "Size: " + d.getWidth() + "x" + d.getHeight() + "\n"; if (dm != null) sHardwareInfo += "Density: " + dm.density + "\n"; sHardwareInfo += "Rotation: " + d.getRotation() + "\n\n"; sHardwareInfo += getNetworkInfo(mContext); sHardwareInfo += getDeviceInfo(); ((TextView) view.findViewById(R.id.about_hardware)).setText(sHardwareInfo); final String sSubject = "Feedback for OpenExplorer " + sVersionInfo; OnClickListener email = new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //intent.addCategory(Intent.CATEGORY_APP_EMAIL); intent.putExtra(android.content.Intent.EXTRA_TEXT, "\n" + getDeviceInfo()); intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "brandroid64@gmail.com" }); intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sSubject); mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.s_chooser_email))); } }; OnClickListener viewsite = new OnClickListener() { public void onClick(View v) { mContext.startActivity( new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://brandroid.org/open/"))); } }; view.findViewById(R.id.about_email).setOnClickListener(email); view.findViewById(R.id.about_email_btn).setOnClickListener(email); view.findViewById(R.id.about_site).setOnClickListener(viewsite); view.findViewById(R.id.about_site_btn).setOnClickListener(viewsite); final View mRecentLabel = view.findViewById(R.id.about_recent_status_label); final WebView mRecent = (WebView) view.findViewById(R.id.about_recent); final OpenChromeClient occ = new OpenChromeClient(); occ.mStatus = (TextView) view.findViewById(R.id.about_recent_status); mRecent.setWebChromeClient(occ); mRecent.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { occ.mStatus.setVisibility(View.GONE); mRecent.setVisibility(View.GONE); mRecentLabel.setVisibility(View.GONE); } }); mRecent.setBackgroundColor(Color.TRANSPARENT); mRecent.loadUrl("http://brandroid.org/open/?show=recent"); ((TextView) view.findViewById(R.id.about_version)).setText(sVersionInfo); if (sBuildTime != "") ((TextView) view.findViewById(R.id.about_buildtime)).setText(sBuildTime); else ((TableRow) view.findViewById(R.id.row_buildtime)).setVisibility(View.GONE); fillShortcutsTable((TableLayout) view.findViewById(R.id.shortcuts_table)); final View tab1 = view.findViewById(R.id.tab1); final View tab2 = view.findViewById(R.id.tab2); final View tab3 = view.findViewById(R.id.tab3); ((Button) view.findViewById(R.id.btn_recent)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.VISIBLE); tab2.setVisibility(View.GONE); tab3.setVisibility(View.GONE); } }); ((Button) view.findViewById(R.id.btn_hardware)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.GONE); tab2.setVisibility(View.VISIBLE); tab3.setVisibility(View.GONE); } }); ((Button) view.findViewById(R.id.btn_shortcuts)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.GONE); tab2.setVisibility(View.GONE); tab3.setVisibility(View.VISIBLE); } }); AlertDialog mDlgAbout = new AlertDialog.Builder(mContext).setTitle(R.string.app_name).setView(view) .create(); mDlgAbout.getWindow().getAttributes().windowAnimations = R.style.SlideDialogAnimation; mDlgAbout.getWindow().getAttributes().alpha = 0.9f; mDlgAbout.show(); }
From source file:com.mobicage.rogerthat.plugins.friends.ActionScreenActivity.java
@SuppressLint({ "SetJavaScriptEnabled", "JavascriptInterface", "NewApi" }) @Override//w ww . ja va 2 s. c om public void onCreate(Bundle savedInstanceState) { if (CloudConstants.isContentBrandingApp()) { super.setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen); } super.onCreate(savedInstanceState); setContentView(R.layout.action_screen); mBranding = (WebView) findViewById(R.id.branding); WebSettings brandingSettings = mBranding.getSettings(); brandingSettings.setJavaScriptEnabled(true); brandingSettings.setCacheMode(WebSettings.LOAD_DEFAULT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { brandingSettings.setAllowFileAccessFromFileURLs(true); } mBrandingHttp = (WebView) findViewById(R.id.branding_http); mBrandingHttp.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); WebSettings brandingSettingsHttp = mBrandingHttp.getSettings(); brandingSettingsHttp.setJavaScriptEnabled(true); brandingSettingsHttp.setCacheMode(WebSettings.LOAD_DEFAULT); if (CloudConstants.isContentBrandingApp()) { mSoundThread = new HandlerThread("rogerthat_actionscreenactivity_sound"); mSoundThread.start(); Looper looper = mSoundThread.getLooper(); mSoundHandler = new Handler(looper); int cameraPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (cameraPermission == PackageManager.PERMISSION_GRANTED) { mQRCodeScanner = QRCodeScanner.getInstance(this); final LinearLayout previewHolder = (LinearLayout) findViewById(R.id.preview_view); previewHolder.addView(mQRCodeScanner.view); } mBranding.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { initFullScreenForContentBranding(); } }); mBrandingHttp.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { initFullScreenForContentBranding(); } }); } final View brandingHeader = findViewById(R.id.branding_header_container); final ImageView brandingHeaderClose = (ImageView) findViewById(R.id.branding_header_close); final TextView brandingHeaderText = (TextView) findViewById(R.id.branding_header_text); brandingHeaderClose .setColorFilter(UIUtils.imageColorFilter(getResources().getColor(R.color.mc_homescreen_text))); brandingHeaderClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mQRCodeScanner != null) { mQRCodeScanner.onResume(); } brandingHeader.setVisibility(View.GONE); mBrandingHttp.setVisibility(View.GONE); mBranding.setVisibility(View.VISIBLE); mBrandingHttp.loadUrl("about:blank"); } }); final View brandingFooter = findViewById(R.id.branding_footer_container); if (CloudConstants.isContentBrandingApp()) { brandingHeaderClose.setVisibility(View.GONE); final ImageView brandingFooterClose = (ImageView) findViewById(R.id.branding_footer_close); final TextView brandingFooterText = (TextView) findViewById(R.id.branding_footer_text); brandingFooterText.setText(getString(R.string.back)); brandingFooterClose .setColorFilter(UIUtils.imageColorFilter(getResources().getColor(R.color.mc_homescreen_text))); brandingFooter.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mQRCodeScanner != null) { mQRCodeScanner.onResume(); } brandingHeader.setVisibility(View.GONE); brandingFooter.setVisibility(View.GONE); mBrandingHttp.setVisibility(View.GONE); mBranding.setVisibility(View.VISIBLE); mBrandingHttp.loadUrl("about:blank"); } }); } final RelativeLayout openPreview = (RelativeLayout) findViewById(R.id.preview_holder); openPreview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mQRCodeScanner != null) { mQRCodeScanner.previewHolderClicked(); } } }); mBranding.addJavascriptInterface(new JSInterface(this), "__rogerthat__"); mBranding.setWebChromeClient(new WebChromeClient() { @Override public void onConsoleMessage(String message, int lineNumber, String sourceID) { if (sourceID != null) { try { sourceID = new File(sourceID).getName(); } catch (Exception e) { L.d("Could not get fileName of sourceID: " + sourceID, e); } } if (mIsHtmlContent) { L.i("[BRANDING] " + sourceID + ":" + lineNumber + " | " + message); } else { L.d("[BRANDING] " + sourceID + ":" + lineNumber + " | " + message); } } }); mBranding.setWebViewClient(new WebViewClient() { private boolean isExternalUrl(String url) { for (String regularExpression : mBrandingResult.externalUrlPatterns) { if (url.matches(regularExpression)) { return true; } } return false; } @SuppressLint("DefaultLocale") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { L.i("Branding is loading url: " + url); Uri uri = Uri.parse(url); String lowerCaseUrl = url.toLowerCase(); if (lowerCaseUrl.startsWith("tel:") || lowerCaseUrl.startsWith("mailto:") || isExternalUrl(url)) { Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); return true; } else if (lowerCaseUrl.startsWith(POKE)) { String tag = url.substring(POKE.length()); poke(tag); return true; } else if (lowerCaseUrl.startsWith("http://") || lowerCaseUrl.startsWith("https://")) { if (mQRCodeScanner != null) { mQRCodeScanner.onPause(); } brandingHeaderText.setText(getString(R.string.loading)); brandingHeader.setVisibility(View.VISIBLE); if (CloudConstants.isContentBrandingApp()) { brandingFooter.setVisibility(View.VISIBLE); } mBranding.setVisibility(View.GONE); mBrandingHttp.setVisibility(View.VISIBLE); mBrandingHttp.loadUrl(url); return true; } else { brandingHeader.setVisibility(View.GONE); brandingFooter.setVisibility(View.GONE); mBrandingHttp.setVisibility(View.GONE); mBranding.setVisibility(View.VISIBLE); } return false; } @Override public void onPageFinished(WebView view, String url) { L.i("onPageFinished " + url); if (!mInfoSet && mService != null && mIsHtmlContent) { Map<String, Object> info = mFriendsPlugin.getRogerthatUserAndServiceInfo(mServiceEmail, mServiceFriend); executeJS(true, "if (typeof rogerthat !== 'undefined') rogerthat._setInfo(%s)", JSONValue.toJSONString(info)); mInfoSet = true; } } @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { L.i("Checking access to: '" + url + "'"); final URL parsedUrl; try { parsedUrl = new URL(url); } catch (MalformedURLException e) { L.d("Webview tried to load malformed URL"); return new WebResourceResponse("text/plain", "UTF-8", null); } if (!parsedUrl.getProtocol().equals("file")) { return null; } File urlPath = new File(parsedUrl.getPath()); if (urlPath.getAbsolutePath().startsWith(mBrandingResult.dir.getAbsolutePath())) { return null; } L.d("404: Webview tries to load outside its sandbox."); return new WebResourceResponse("text/plain", "UTF-8", null); } }); mBrandingHttp.setWebViewClient(new WebViewClient() { @SuppressLint("DefaultLocale") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { L.i("BrandingHttp is loading url: " + url); return false; } @Override public void onPageFinished(WebView view, String url) { brandingHeaderText.setText(view.getTitle()); L.i("onPageFinished " + url); } }); Intent intent = getIntent(); mBrandingKey = intent.getStringExtra(BRANDING_KEY); mServiceEmail = intent.getStringExtra(SERVICE_EMAIL); mItemTagHash = intent.getStringExtra(ITEM_TAG_HASH); mItemLabel = intent.getStringExtra(ITEM_LABEL); mItemCoords = intent.getLongArrayExtra(ITEM_COORDS); mRunInBackground = intent.getBooleanExtra(RUN_IN_BACKGROUND, true); }
From source file:busradar.madison.StopDialog.java
@Override public void show() { new Thread() { @Override// w ww.j a v a 2 s . c om public void run() { for (final RouteURL r : routes) { G.activity.runOnUiThread(new Runnable() { public void run() { cur_loading_text .setText(String.format("Loading route %s...", G.route_points[r.route].name)); } }); final ArrayList<RouteTime> curtimes = new ArrayList<RouteTime>(); try { System.err.printf("BusRadar URL %s\n", TRANSITTRACKER_URL + r.url); URL url = new URL(TRANSITTRACKER_URL + r.url); URLConnection url_conn = url.openConnection(); if (url_conn instanceof HttpsURLConnection) { ((HttpsURLConnection) url_conn).setHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }); } InputStream is = url_conn.getInputStream(); Scanner scan = new Scanner(is, "UTF-8"); //String outstr_cur = "Route " + r.route + "\n"; if (scan.findWithinHorizon(num_vehicles_re, 0) != null) { while (scan.findWithinHorizon(time_re, 0) != null) { RouteTime time = new RouteTime(); time.route = r.route; time.time = scan.match().group(1).replace(".", ""); time.dir = scan.match().group(2); //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time); SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US); time.date = f.parse(time.time); r.status = RouteURL.DONE; //outstr_cur += String.format("%s to %s\n", time.time, time.dir); curtimes.add(time); } while (scan.findWithinHorizon(time_re_backup, 0) != null) { RouteTime time = new RouteTime(); time.route = r.route; time.time = scan.match().group(1).replace(".", ""); //time.dir = scan.match().group(2); //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time); SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US); time.date = f.parse(time.time); r.status = RouteURL.DONE; //outstr_cur += String.format("%s to %s\n", time.time, time.dir); curtimes.add(time); } } // else if (scan.findWithinHorizon(no_busses_re, 0) != null) { // r.status = RouteURL.NO_MORE_TODAY; // } // else if (scan.findWithinHorizon(no_timepoints_re, 0) != null) { // r.status = RouteURL.NO_TIMEPOINTS; // } // else { // r.status = RouteURL.ERROR; // System.out.printf("BusRadar: Could not get stop info for %s\n", r.url); // // throw new Exception("Error parsing TransitTracker webpage."); // } else { r.status = RouteURL.NO_STOPS_UNKONWN; } //r.text = outstr_cur; G.activity.runOnUiThread(new Runnable() { public void run() { times.addAll(curtimes); StopDialog.this.update_times(); } }); } // catch (final IOException ioe) { // log_problem(ioe); // G.activity.runOnUiThread(new Runnable() { // public void run() { // final Context ctx = StopDialog.this.getContext(); // // StopDialog.this.setContentView(new RelativeLayout(ctx) {{ // addView(new TextView(ctx) {{ // setText(Html.fromHtml("Error downloading data. Is the data connection enabled?"+ // "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>"+ioe)); // setPadding(5, 5, 5, 5); // this.setMovementMethod(LinkMovementMethod.getInstance()); // }}, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); // }}); // } // }); // return; // } catch (Exception e) { log_problem(e); String custom_msg = ""; final String turl = TRANSITTRACKER_URL + r.url; if ((e instanceof SocketException) || (e instanceof UnknownHostException)) { // data connection doesn't work custom_msg = "Error downloading data. Is the data connection enabled?" + "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>" + TextUtils.htmlEncode(e.toString()); } else { String rurl = String.format( "http://www.cityofmadison.com/metro/BusStopDepartures/StopID/%04d.pdf", stopid); custom_msg = "Trouble retrieving real-time arrival estimates from <a href='" + turl + "'>this</a> TransitTracker webpage, which is displayed below. " + "Meanwhile, try PDF timetable <a href='" + rurl + "'>here</a>. " + "Contact us at <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a> to report the problem.<p>" + TextUtils.htmlEncode(e.toString()); } final String msg = custom_msg; G.activity.runOnUiThread(new Runnable() { public void run() { final Context ctx = StopDialog.this.getContext(); StopDialog.this.setContentView(new RelativeLayout(ctx) { { addView(new TextView(ctx) { { setId(1); setText(Html.fromHtml(msg)); setPadding(5, 5, 5, 5); this.setMovementMethod(LinkMovementMethod.getInstance()); } }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); addView(new WebView(ctx) { { setWebViewClient(new WebViewClient()); loadUrl(turl); } }, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT) { { addRule(RelativeLayout.BELOW, 1); } }); } }); } }); return; } } G.activity.runOnUiThread(new Runnable() { public void run() { cur_loading_text.setText(""); } }); } }.start(); super.show(); }
From source file:com.near.chimerarevo.fragments.PostFragment.java
@SuppressLint("SetJavaScriptEnabled") private void addWebObject(String width, String height, String url) { WebView wv = new WebView(getActivity()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); wv.setLayoutParams(params);//from w ww . j a v a 2 s . com wv.getSettings().setUseWideViewPort(true); wv.getSettings().setLoadWithOverviewMode(true); wv.getSettings().setSupportZoom(false); wv.setVerticalScrollBarEnabled(true); wv.setHorizontalScrollBarEnabled(true); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); wv.setWebViewClient(new WebViewClient()); String frame = "<iframe width=\"" + width + "\" height=\"" + height + "\" frameborder=\"0\" src=\"" + url + "\"/>"; wv.loadDataWithBaseURL(url, frame, "html/plain", "UTF-8", null); lay.addView(wv); }
From source file:im.vector.util.VectorUtils.java
/** * Open a webview above the current activity. * @param activity the activity//from w w w . j a v a 2 s .c o m * @param url the url to open */ private static void displayInWebview(final Activity activity, String url) { AlertDialog.Builder alert = new AlertDialog.Builder(activity); WebView wv = new WebView(activity); wv.loadUrl(url); wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); alert.setView(wv); alert.setPositiveButton(android.R.string.ok, null); alert.show(); }
From source file:com.almunt.jgcaap.systemupdater.MainActivity.java
public void LicencesDialog() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Open Source Licenses"); WebView wv = new WebView(this); wv.loadUrl("file:///android_asset/open_source_licenses.html"); wv.setWebViewClient(new WebViewClient() { @Override/*from w w w. j a v a2 s . co m*/ public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); alert.setView(wv); alert.setPositiveButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alert.show(); }
From source file:im.neon.util.VectorUtils.java
/** * Open a webview above the current activity. * * @param context the application context * @param url the url to open// w w w . j av a 2s .co m */ private static void displayInWebview(final Context context, String url) { AlertDialog.Builder alert = new AlertDialog.Builder(context); WebView wv = new WebView(context); wv.loadUrl(url); wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); alert.setView(wv); alert.setPositiveButton(android.R.string.ok, null); alert.show(); }
From source file:com.farmerbb.notepad.activity.MainActivity.java
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.KITKAT)/*from w ww .j a v a 2 s .c om*/ public void printNote(String contentToPrint) { SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE); // Create a WebView object specifically for printing boolean generateHtml = !(pref.getBoolean("markdown", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); WebView webView = generateHtml ? new WebView(this) : new MarkdownView(this); // Apply theme String theme = pref.getString("theme", "light-sans"); int textSize = -1; String fontFamily = null; if (theme.contains("sans")) { fontFamily = "sans-serif"; } if (theme.contains("serif")) { fontFamily = "serif"; } if (theme.contains("monospace")) { fontFamily = "monospace"; } switch (pref.getString("font_size", "normal")) { case "smallest": textSize = 12; break; case "small": textSize = 14; break; case "normal": textSize = 16; break; case "large": textSize = 18; break; case "largest": textSize = 20; break; } String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom_print) / getResources().getDisplayMetrics().density) + "px"; String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right_print) / getResources().getDisplayMetrics().density) + "px"; String fontSize = " " + Integer.toString(textSize) + "px"; String css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "}"; webView.getSettings().setJavaScriptEnabled(false); webView.getSettings().setLoadsImagesAutomatically(false); webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(final WebView view, String url) { createWebPrintJob(view); } }); // Load content into WebView if (generateHtml) { webView.loadDataWithBaseURL(null, "<link rel='stylesheet' type='text/css' href='data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT) + "' /><html><body><p>" + StringUtils.replace(contentToPrint, "\n", "<br>") + "</p></body></html>", "text/HTML", "UTF-8", null); } else ((MarkdownView) webView).loadMarkdown(contentToPrint, "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT)); }