List of usage examples for android.webkit WebView getSettings
public WebSettings getSettings()
From source file:com.openatk.planting.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.main_menu_add) { // Check if have an operation if (operationsList.isEmpty()) { // Show dialog to create operation createOperation(new Callable<Void>() { public Void call() { return addFieldMapView(); }//from w w w . j a v a 2 s .c o m }); } else { addFieldMapView(); } } 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)); } } else if (item.getItemId() == R.id.main_menu_layers) { MenuItem layers = menu.findItem(R.id.main_menu_layers); if (showingHazards == false) { showingHazards = true; layers.setTitle("Hide Hazards"); } else { showingHazards = false; layers.setTitle("Show Hazards"); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("showingHazards", showingHazards); editor.commit(); drawHazards(); } else if (item.getItemId() == R.id.main_menu_list_view) { if (mCurrentState == STATE_LIST_VIEW) { // Show map view Log.d("MainActivity", "Showing map view"); setState(STATE_DEFAULT); //item.setIcon(R.drawable.list_view); this.invalidateOptionsMenu(); } else { // Show list view Log.d("MainActivity", "Showing list view"); setState(STATE_LIST_VIEW); //item.setIcon(R.drawable.map_view); this.invalidateOptionsMenu(); } } 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(); } 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; }
From source file:com.github.dfa.diaspora_android.activity.ShareActivity2.java
@SuppressLint("SetJavaScriptEnabled") @Override/* ww w. j av a 2 s . c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); progressBar = (ProgressBar) findViewById(R.id.progressBar); swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeView.setEnabled(false); toolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Helpers.isOnline(ShareActivity2.this)) { Intent intent = new Intent(ShareActivity2.this, MainActivity.class); startActivityForResult(intent, 100); overridePendingTransition(0, 0); } else { Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } }); podDomain = ((App) getApplication()).getSettings().getPodDomain(); fab = (com.getbase.floatingactionbutton.FloatingActionsMenu) findViewById(R.id.fab_expand_menu_button); fab.setVisibility(View.GONE); webView = (WebView) findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); WebSettings wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d(TAG, url); if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { Log.i(TAG, "Finished loading URL: " + url); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.hideTopBar(wv); } if (progress == 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Snackbar.make(getWindow().findViewById(R.id.drawer_layout), "Unable to get image", Snackbar.LENGTH_SHORT).show(); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); Intent intent = getIntent(); final Bundle extras = intent.getExtras(); String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { if (extras.containsKey(Intent.EXTRA_TEXT) && extras.containsKey(Intent.EXTRA_SUBJECT)) { final String extraText = (String) extras.get(Intent.EXTRA_TEXT); final String extraSubject = (String) extras.get(Intent.EXTRA_SUBJECT); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { finish(); Intent i = new Intent(ShareActivity2.this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); overridePendingTransition(0, 0); return false; } }); webView.loadUrl("javascript:(function() { " + "document.getElementsByTagName('textarea')[0].style.height='110px'; " + "document.getElementsByTagName('textarea')[0].innerHTML = '**[" + extraSubject + "]** " + extraText + " *[shared with #DiasporaWebApp]*'; " + " if(document.getElementById(\"main_nav\")) {" + " document.getElementById(\"main_nav\").parentNode.removeChild(" + " document.getElementById(\"main_nav\"));" + " } else if (document.getElementById(\"main-nav\")) {" + " document.getElementById(\"main-nav\").parentNode.removeChild(" + " document.getElementById(\"main-nav\"));" + " }" + "})();"); } } }); } if (savedInstanceState == null) { if (Helpers.isOnline(ShareActivity2.this)) { webView.loadUrl("https://" + podDomain + "/status_messages/new"); } else { Snackbar.make(getWindow().findViewById(R.id.drawer_layout), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); } } }
From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java
private Cookie checkAntiDDOS(final CloudflareException exception, final HttpHost proxy, CancellableTask task, final Activity activity) { synchronized (lock) { if (processing) return null; processing = true;//from w w w .j a va 2 s .c o m } processing2 = true; currentCookie = null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.createInstance(activity); CookieManager.getInstance().removeAllCookie(); } else { CompatibilityImpl.clearCookies(CookieManager.getInstance()); } final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView(); final WebViewClient client = new WebViewClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } @Override public void onPageFinished(WebView webView, String url) { super.onPageFinished(webView, url); Logger.d(TAG, "Got Page: " + url); String value = null; try { String[] cookies = CookieManager.getInstance().getCookie(url).split("[;]"); for (String cookie : cookies) { if ((cookie != null) && (!cookie.trim().equals("")) && (cookie.startsWith(" " + exception.getRequiredCookieName() + "="))) { value = cookie.substring(exception.getRequiredCookieName().length() + 2); } } } catch (NullPointerException e) { Logger.e(TAG, e); } if (value != null) { BasicClientCookieHC4 cf_cookie = new BasicClientCookieHC4(exception.getRequiredCookieName(), value); cf_cookie.setDomain("." + Uri.parse(url).getHost()); cf_cookie.setPath("/"); currentCookie = cf_cookie; Logger.d(TAG, "Cookie found: " + value); processing2 = false; } else { Logger.d(TAG, "Cookie is not found"); } } }; activity.runOnUiThread(new Runnable() { @SuppressLint("SetJavaScriptEnabled") @Override public void run() { webView = new WebView(activity); webView.setVisibility(View.GONE); layout.addView(webView); webView.setWebViewClient(client); webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING); webView.getSettings().setJavaScriptEnabled(true); webViewContext = webView.getContext(); if (proxy != null) WebViewProxy.setProxy(webViewContext, proxy.getHostName(), proxy.getPort()); webView.loadUrl(exception.getCheckUrl()); } }); long startTime = System.currentTimeMillis(); while (processing2) { long time = System.currentTimeMillis() - startTime; if ((task != null && task.isCancelled()) || time > TIMEOUT) { processing2 = false; } } activity.runOnUiThread(new Runnable() { @Override public void run() { try { layout.removeView(webView); webView.stopLoading(); webView.clearCache(true); webView.destroy(); webView = null; } finally { if (proxy != null) WebViewProxy.setProxy(webViewContext, null, 0); processing = false; } } }); return currentCookie; }
From source file:com.github.dfa.diaspora_android.activity.ShareActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w.j a v a 2 s. co m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main__activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (toolbar != null) { toolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Helpers.isOnline(ShareActivity.this)) { Intent intent = new Intent(ShareActivity.this, MainActivity.class); startActivityForResult(intent, 100); overridePendingTransition(0, 0); finish(); } else { Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } }); } setTitle(R.string.new_post); progressBar = (ProgressBar) findViewById(R.id.progressBar); swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeView.setEnabled(false); podDomain = ((App) getApplication()).getSettings().getPodDomain(); webView = (WebView) findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); WebSettings wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d(TAG, url); if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { Log.i(TAG, "Finished loading URL: " + url); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.applyDiasporaMobileSiteChanges(wv); } if (progress == 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Snackbar.make(getWindow().findViewById(R.id.main__layout), "Unable to get image", Snackbar.LENGTH_LONG).show(); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); if (savedInstanceState == null) { if (Helpers.isOnline(ShareActivity.this)) { webView.loadUrl("https://" + podDomain + "/status_messages/new"); } else { Snackbar.make(getWindow().findViewById(R.id.main__layout), R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { if (intent.hasExtra(Intent.EXTRA_SUBJECT)) { handleSendSubject(intent); } else { handleSendText(intent); } } else if (type.startsWith("image/")) { // TODO Handle single image being sent -> see manifest handleSendImage(intent); } //} else { // Handle other intents, such as being started from the home screen } }
From source file:org.botlibre.sdk.activity.ChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); // Remove flag button if a single bot app. if (MainActivity.launchType == LaunchType.Bot) { //findViewById(R.id.flagButton).setVisibility(View.GONE); }//from w w w.j a v a 2s .com //permission required. ActivityCompat.requestPermissions(ChatActivity.this, new String[] { Manifest.permission.RECORD_AUDIO }, 1); //set/Save the current volume from the device. setStreamVolume(); //Music Volume is Enabled. muteMicBeep(false); //For "scream" issue micLastStat = MainActivity.listenInBackground; getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); this.instance = (InstanceConfig) MainActivity.instance; if (this.instance == null) { return; } /*if (MainActivity.showAds) { AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } else { AdView mAdView = (AdView) findViewById(R.id.adView); mAdView.setVisibility(View.GONE); }*/ setTitle(this.instance.name); ((TextView) findViewById(R.id.title)).setText(this.instance.name); HttpGetImageAction.fetchImage(this, this.instance.avatar, findViewById(R.id.icon)); ttsInit = false; tts = new TextToSpeech(this, this); if (!MainActivity.handsFreeSpeech) { setMicIcon(false, false); } else if (!MainActivity.listenInBackground) { setMicIcon(false, false); } //Last time will be saved for the MIC. if (MainActivity.listenInBackground && MainActivity.handsFreeSpeech) { microphoneThread(thread); } speech = SpeechRecognizer.createSpeechRecognizer(this); speech.setRecognitionListener(this); //scrollVie added and stuff scrollView = findViewById(R.id.chatList); menuMLayout = (LinearLayout) findViewById(R.id.menuMLayout); chatCLayout = (LinearLayout) findViewById(R.id.chatCLayout); responseLayout = (LinearLayout) findViewById(R.id.responseLayout); chatToolBar = (LinearLayout) findViewById(R.id.chatToolBar); videoView = (VideoView) findViewById(R.id.videoView); resetVideoErrorListener(); videoError = false; imageView = (ImageView) findViewById(R.id.imageView); videoLayout = findViewById(R.id.videoLayout); textView = (EditText) findViewById(R.id.messageText); textView.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { submitChat(); return false; } }); if (MainActivity.translate) { findViewById(R.id.yandex).setVisibility(View.VISIBLE); } else { findViewById(R.id.yandex).setVisibility(View.GONE); } Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin); emoteSpin.setAdapter( new EmoteSpinAdapter(this, R.layout.emote_list, Arrays.asList(EmotionalState.values()))); ListView list = (ListView) findViewById(R.id.chatList); list.setAdapter(new ChatListAdapter(this, R.layout.chat_list, this.messages)); list.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); ImageButton button = (ImageButton) findViewById(R.id.speakButton); button.setOnClickListener(new View.OnClickListener() { @TargetApi(23) @Override public void onClick(View v) { if (MainActivity.handsFreeSpeech) { //set the current volume to the setting. setStreamVolume(); //if its ON Or OFF - Switching back and forth MainActivity.listenInBackground = !MainActivity.listenInBackground; //saving the boolean data of MainActivity.listeningInBackground SharedPreferences.Editor cookies = MainActivity.current.getPreferences(Context.MODE_PRIVATE) .edit(); cookies.putBoolean("listenInBackground", MainActivity.listenInBackground); cookies.commit(); if (MainActivity.listenInBackground) { micLastStat = true; try { microphoneThread(thread); } catch (Exception ignore) { } beginListening(); } else { micLastStat = false; microphoneThread(thread); stopListening(); } } else { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language); try { startActivityForResult(intent, RESULT_SPEECH); textView.setText(""); } catch (ActivityNotFoundException a) { Toast t = Toast.makeText(getApplicationContext(), "Your device doesn't support Speech to Text", Toast.LENGTH_SHORT); t.show(); } } } }); //adding functionality on clicking the image imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); //adding functionality on clicking the image videoLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); GestureDetector.SimpleOnGestureListener listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { boolean isVideo = !MainActivity.disableVideo && !videoError && response != null && response.isVideo(); View imageView = findViewById(R.id.imageView); View videoLayout = findViewById(R.id.videoLayout); if (imageView.getVisibility() == View.VISIBLE) { imageView.setVisibility(View.GONE); } else if (!isVideo) { imageView.setVisibility(View.VISIBLE); } if (videoLayout.getVisibility() == View.VISIBLE) { videoLayout.setVisibility(View.GONE); } else if (isVideo) { videoLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector = new GestureDetector(this, listener); findViewById(R.id.chatList).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector.onTouchEvent(event); } }); listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector2 = new GestureDetector(this, listener); /*findViewById(R.id.responseText).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector2.onTouchEvent(event); } });*/ WebView responseView = (WebView) findViewById(R.id.responseText); responseView.getSettings().setJavaScriptEnabled(true); responseView.getSettings().setDomStorageEnabled(true); responseView.addJavascriptInterface(new WebAppInterface(this), "Android"); findViewById(R.id.responseImageView).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } } }); HttpGetImageAction.fetchImage(this, instance.avatar, this.imageView); HttpGetImageAction.fetchImage(this, instance.avatar, (ImageView) findViewById(R.id.responseImageView)); final ChatConfig config = new ChatConfig(); config.instance = instance.id; config.avatar = this.avatarId; if (MainActivity.translate && MainActivity.voice != null) { config.language = MainActivity.voice.language; } if (MainActivity.disableVideo) { config.avatarFormat = "image"; } else { config.avatarFormat = MainActivity.webm ? "webm" : "mp4"; } config.avatarHD = MainActivity.hd; config.speak = !MainActivity.deviceVoice; // This is required because of a bug in TextToSpeech that prevents onInit being called if an AsynchTask is called... Thread thread1 = new Thread() { public void run() { for (int count = 0; count < 5; count++) { if (ttsInit) { break; } try { Thread.sleep(1000); } catch (Exception exception) { } } HttpAction action = new HttpChatAction(ChatActivity.this, config); action.execute(); } }; thread1.start(); }
From source file:com.farmerbb.notepad.activity.MainActivity.java
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.KITKAT)// w w w .j a va 2s .co m 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)); }
From source file:com.doge.dyjw.AboutFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webView = (WebView) getActivity().findViewById(R.id.webView); String html = "<html><head><title></title></head><body style='margin:16px; background:#efefef;'>\n" + "<h1> Android App</h1>\n" + "<hr />\n" + "<p>\n" + "An Android application for students of NEPU to use the JiaoWuGuanLi system on Android.<br />\n" + "??\n" + "</p>\n" + "<p>\n" + "?" + getString(R.string.versionName) + "??<a href='http://weibo.com/hiy0u'>?</a>" + "APP<a href='http://dyjw.fly-kite.com/'>http://dyjw.fly-kite.com/</a><br />\n" + "APK<a href='http://dyjw.fly-kite.com/download/'>http://dyjw.fly-kite.com/download/</a><br />\n" + "??GPLv3???\n" + "</p>\n" + "<h1>?</h1>\n" + "<hr />\n" + "<p>\n" + "APPJsoup?????????\n" + "</p>\n" + "<h1></h1>\n" + "<hr />\n" + "<p>\n" + "??????<br />\n" + "??????????\n" + "</p>\n" + "<h1>??</h1>\n" + "<hr />\n" + "<p>\n" + "?<br />\n" + "APP????DogeFlyKite@gmail.com\n" + "</p>\n" + "<h1>??</h1>\n" + "<hr />\n" + "<p style='background:#dfdfdf;'>\n" + "GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007<br />\n" + "<br />\n" + "Copyright (C) 2015 Doge Studio<br />\n" + "<br />\n" + "This program comes with ABSOLUTELY NO WARRANTY.<br />\n" + "This is free software, and you are welcome to redistribute it under certain conditions.\n" + "</p>\n" + "<br />\n" + "</body>\n" + "</html>"; Log.d("", html); webView.getSettings().setDefaultTextEncodingName("utf-8"); webView.loadData(html, "text/html; charset=utf-8;", null); }
From source file:org.smilec.smile.student.CourseList.java
void setWebviewFontSize(WebView view) { WebSettings webSettings = view.getSettings(); //Determine screen size xlarge 720x960 dp units if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { // 480x640 dp units //Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show(); webSettings.setTextSize(WebSettings.TextSize.LARGER); } /*/*from ww w.j a v a2s.c o m*/ else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { // 320x470 dp units mobile phone Toast.makeText(this, "Normal sized screen" , Toast.LENGTH_LONG).show(); } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { // 320x426 dp units Toast.makeText(this, "Small sized screen" , Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show(); }*/ }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;/* www.j av a 2 s . c om*/ // Import license file if (Intent.ACTION_VIEW.equals(getIntent().getAction())) if (Util.importProLicense(new File(getIntent().getData().getPath())) != null) Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show(); // Set layout setContentView(R.layout.mainlist); setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar)); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // Set sub title if (Util.hasProLicense(this) != null) getSupportActionBar().setSubtitle(R.string.menu_pro); // Annotate Meta.annotate(this.getResources()); // Get localized restriction name List<String> listRestrictionName = new ArrayList<String>( PrivacyManager.getRestrictions(this).navigableKeySet()); listRestrictionName.add(0, getString(R.string.menu_all)); // Build spinner adapter SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item); spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spAdapter.addAll(listRestrictionName); // Handle info ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @SuppressLint("SetJavaScriptEnabled") @Override public void onClick(View view) { int position = spRestriction.getSelectedItemPosition(); if (position != AdapterView.INVALID_POSITION) { String query = (position == 0 ? "restrictions" : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position - 1]); WebView webview = new WebView(ActivityMain.this); webview.getSettings().setUserAgentString("Mozilla/5.0"); // needed for hashtag webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("https://github.com/M66B/XPrivacy#" + query); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this); alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem()); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(webview); alertDialogBuilder.setCancelable(true); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); // Setup category spinner spRestriction = (Spinner) findViewById(R.id.spRestriction); spRestriction.setAdapter(spAdapter); spRestriction.setOnItemSelectedListener(this); int pos = getSelectedCategory(userId); spRestriction.setSelection(pos); // Setup sort mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0")); mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false); // Start task to get app list AppListTask appListTask = new AppListTask(); appListTask.executeOnExecutor(mExecutor, (Object) null); // Check environment Requirements.check(this); // Licensing checkLicense(); // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_ADDED); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; boolean showChangelog = true; // First run if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) { showChangelog = false; optionAbout(); } // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) { showChangelog = false; ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Legacy if (!PrivacyManager.cVersion3) { long now = new Date().getTime(); String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null); if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) { showChangelog = false; PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now)); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.app_name); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setMessage(R.string.title_update_legacy); alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Util.viewUri(ActivityMain.this, Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3")); } }); alertDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } // Show changelog if (showChangelog) { String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null); Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion); Version currentVersion = new Version(Util.getSelfVersionName(this)); if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0) optionChangelog(); } }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
@SuppressLint("NewApi") final private void aboutTaskAutomation() { // common ??/*from w w w.j ava 2s.c om*/ final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); ((TextView) dialog.findViewById(R.id.about_dialog_title)) .setText(getString(R.string.msgs_about_dlg_title) + " Ver " + getApplVersionName()); final WebView func_view = (WebView) dialog.findViewById(R.id.about_dialog_function); // func_view.setWebViewClient(new WebViewClient()); // func_view.getSettings().setJavaScriptEnabled(true); func_view.getSettings().setSupportZoom(true); // func_view.setVerticalScrollbarOverlay(true); func_view.setBackgroundColor(Color.LTGRAY); // func_view.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); func_view.setVerticalScrollBarEnabled(true); func_view.setScrollbarFadingEnabled(false); if (Build.VERSION.SDK_INT > 10) { func_view.getSettings().setDisplayZoomControls(true); func_view.getSettings().setBuiltInZoomControls(true); } else { func_view.getSettings().setBuiltInZoomControls(true); } func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_about_dlg_func_html)); final WebView change_view = (WebView) dialog.findViewById(R.id.about_dialog_change_history); if (Build.VERSION.SDK_INT > 10) { func_view.getSettings().setDisplayZoomControls(true); func_view.getSettings().setBuiltInZoomControls(true); } else { func_view.getSettings().setBuiltInZoomControls(true); } change_view.loadDataWithBaseURL("file:///android_asset/", getString(R.string.msgs_about_dlg_change_desc), "text/html", "UTF-8", ""); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setSupportZoom(true); if (Build.VERSION.SDK_INT > 10) { change_view.getSettings().setDisplayZoomControls(true); change_view.getSettings().setBuiltInZoomControls(true); } else { change_view.getSettings().setBuiltInZoomControls(true); } final Button btnFunc = (Button) dialog.findViewById(R.id.about_dialog_btn_show_func); final Button btnChange = (Button) dialog.findViewById(R.id.about_dialog_btn_show_change); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); func_view.setVisibility(TextView.VISIBLE); change_view.setVisibility(TextView.GONE); btnChange.setBackgroundResource(R.drawable.button_back_ground_color_selector); btnFunc.setBackgroundResource(R.drawable.button_back_ground_color_selector); btnChange.setTextColor(Color.DKGRAY); btnFunc.setTextColor(Color.GREEN); btnFunc.setEnabled(false); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func? btnFunc.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.GONE); func_view.setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); btnFunc.setTextColor(Color.GREEN); btnChange.setTextColor(Color.DKGRAY); btnChange.setEnabled(true); btnFunc.setEnabled(false); } }); // change? btnChange.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.VISIBLE); func_view.setVisibility(TextView.GONE); CommonDialog.setDlgBoxSizeLimit(dialog, true); btnChange.setTextColor(Color.GREEN); btnFunc.setTextColor(Color.DKGRAY); btnChange.setEnabled(false); btnFunc.setEnabled(true); } }); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }