List of usage examples for android.webkit WebSettings setBuiltInZoomControls
public abstract void setBuiltInZoomControls(boolean enabled);
From source file:com.wellsandwhistles.android.redditsp.fragments.WebViewFragment.java
@SuppressLint("NewApi") @Override//w w w . j a va 2 s .c o m public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { mActivity = (AppCompatActivity) getActivity(); CookieSyncManager.createInstance(mActivity); outer = (FrameLayout) inflater.inflate(R.layout.web_view_fragment, null); webView = (WebViewFixed) outer.findViewById(R.id.web_view_fragment_webviewfixed); final FrameLayout loadingViewFrame = (FrameLayout) outer .findViewById(R.id.web_view_fragment_loadingview_frame); /*handle download links show an alert box to load this outside the internal browser*/ webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { { new AlertDialog.Builder(mActivity).setTitle(R.string.download_link_title) .setMessage(R.string.download_link_message) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); getContext().startActivity(i); mActivity.onBackPressed(); //get back from internal browser } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mActivity.onBackPressed(); //get back from internal browser } }).setIcon(android.R.drawable.ic_dialog_alert).show(); } } }); /*handle download links end*/ progressView = new ProgressBar(mActivity, null, android.R.attr.progressBarStyleHorizontal); loadingViewFrame.addView(progressView); loadingViewFrame.setPadding(General.dpToPixels(mActivity, 10), 0, General.dpToPixels(mActivity, 10), 0); final WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(false); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setDomStorageEnabled(true); settings.setDisplayZoomControls(false); // TODO handle long clicks webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, final int newProgress) { super.onProgressChanged(view, newProgress); General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressView.setProgress(newProgress); progressView.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE); } }); } }); if (mUrl != null) { webView.loadUrl(mUrl); } else { webView.loadDataWithBaseURL("https://reddit.com/", html, "text/html; charset=UTF-8", null, null); } webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if (url == null) return false; if (url.startsWith("data:")) { // Prevent imgur bug where we're directed to some random data URI return true; } // Go back if loading same page to prevent redirect loops. if (goingBack && currentUrl != null && url.equals(currentUrl)) { General.quickToast(mActivity, String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt), Toast.LENGTH_SHORT); lastBackDepthAttempt--; if (webView.canGoBackOrForward(lastBackDepthAttempt)) { webView.goBackOrForward(lastBackDepthAttempt); } else { mActivity.finish(); } } else { if (RedditURLParser.parse(Uri.parse(url)) != null) { LinkHandler.onLinkClicked(mActivity, url, false); } else { webView.loadUrl(url); currentUrl = url; } } return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (mUrl != null && url != null) { final AppCompatActivity activity = mActivity; if (activity != null) { activity.setTitle(url); } } } @Override public void onPageFinished(final WebView view, final String url) { super.onPageFinished(view, url); new Timer().schedule(new TimerTask() { @Override public void run() { General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { if (currentUrl == null || url == null) return; if (!url.equals(view.getUrl())) return; if (goingBack && url.equals(currentUrl)) { General.quickToast(mActivity, String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt)); lastBackDepthAttempt--; if (webView.canGoBackOrForward(lastBackDepthAttempt)) { webView.goBackOrForward(lastBackDepthAttempt); } else { mActivity.finish(); } } else { goingBack = false; } } }); } }, 1000); } @Override public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) { super.doUpdateVisitedHistory(view, url, isReload); } }); final FrameLayout outerFrame = new FrameLayout(mActivity); outerFrame.addView(outer); return outerFrame; }
From source file:cn.zy.ef.fragment.WebViewFragment.java
protected void configureWebView(WebSettings settings) { settings.setJavaScriptCanOpenWindowsAutomatically(true);//js??window.open()false settings.setJavaScriptEnabled(true);//??jsfalsetrue????XSS? settings.setSupportZoom(true);//??true settings.setBuiltInZoomControls(false);//?false settings.setUseWideViewPort(true);//??? settings.setLoadWithOverviewMode(true);//setUseWideViewPort(true) settings.setAppCacheEnabled(true);//? settings.setDomStorageEnabled(true);//DOM Storage settings.setCacheMode(WebSettings.LOAD_DEFAULT); }
From source file:com.wpi.assistments.HomeTabbedActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_webview); final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...", true); isTeacher = false;//from w w w. j av a 2 s.c o m toggle = true; logoutFlag = false; homeWebView = (WebView) findViewById(R.id.homeWebView); homeWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { Log.i("test", view.getUrl()); if (view.getUrl().equals("https://www.assistments.org/account/login") && !logoutFlag) { Intent intent = new Intent(getApplicationContext(), LoginActivity.class); intent.putExtra("showPopup", "true"); startActivity(intent); finish(); } else if (view.getUrl().equals("https://www.assistments.org/teacher")) { isTeacher = true; } else if (view.getUrl().equals("https://www.assistments.org/account/login") && logoutFlag) { Intent intent = new Intent(getApplicationContext(), LoginActivity.class); startActivity(intent); } if (!homeWebView.canGoBack()) { btnBack.setEnabled(false); } else { btnBack.setEnabled(true); } if (!homeWebView.canGoForward()) { btnForward.setEnabled(false); } else { btnForward.setEnabled(true); } if (pd.isShowing() && pd != null) { pd.dismiss(); } } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { pd.show(); view.loadUrl(url); return true; } }); homeWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { new AlertDialog.Builder(webviewContext).setTitle("ASSISTments").setMessage(message) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { logoutFlag = true; result.confirm(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.cancel(); } }).create().show(); return true; } }); if (savedInstanceState != null) { homeWebView.restoreState(savedInstanceState); } else { /** Scaling, replaced by overview mode and wide view port Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); if (size.x <= 780) { int scaleRate = (int) ((size.x) / 7.8); Log.i("test", Integer.toString(size.x)); homeWebView.setInitialScale(scaleRate); } */ Intent intent = getIntent(); if (intent.getStringExtra("username").equals("") && intent.getStringExtra("password").equals("")) { homeWebView.loadUrl("https://www.assistments.org/signup"); } else { String username = intent.getStringExtra("username"); String password = intent.getStringExtra("password"); String postData = "login=" + username + "&password=" + password + "&commit=Log in"; homeWebView.postUrl("https://www.assistments.org/account/login", EncodingUtils.getBytes(postData, "BASE64")); } } WebSettings settings = homeWebView.getSettings(); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setSupportMultipleWindows(true); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); settings.setAppCacheEnabled(false); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); settings.setUseWideViewPort(false); settings.setLoadWithOverviewMode(true); homeWebView.clearCache(true); homeWebView.setPadding(0, 0, 0, 0); homeWebView.setInitialScale(getScale()); btnBack = (Button) findViewById(R.id.btnBack); btnBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { homeWebView.goBack(); } }); btnRefresh = (Button) findViewById(R.id.btnRefresh); btnRefresh.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //homeWebView.zoomOut(); homeWebView.scrollTo(1000, 0); Log.i("test", "111"); //homeWebView.reload(); } }); btnForward = (Button) findViewById(R.id.btnForward); btnForward.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { homeWebView.goForward(); } }); btnOffline = (Button) findViewById(R.id.btnOffline); btnOffline.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (toggle) { homeWebView.loadUrl( "https://www.assistments.org/assistments/student/index.html#offlineUserAssignmentList/"); btnOffline.setText("Home"); toggle = false; } else { if (isTeacher) { homeWebView.loadUrl("https://www.assistments.org/teacher"); } else { homeWebView.loadUrl("https://www.assistments.org/tutor"); } btnOffline.setText("Offline"); toggle = true; } } }); }
From source file:com.zbrown.droidsteal.activities.HijackActivity.java
private void setupWebView() { webview = (WebView) findViewById(R.id.webviewhijack); webview.setWebViewClient(new MyWebViewClient()); WebSettings webSettings = webview.getSettings(); webSettings.setUserAgentString(/*from w ww . j ava2 s. c om*/ "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"); webSettings.setJavaScriptEnabled(true); //Blah blah JavaScript is scary blah blah webSettings.setAppCacheEnabled(false); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webview.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { HijackActivity.this.setProgress(progress * 100); int fprogress = (Window.PROGRESS_END) / 100 * progress; setProgress(fprogress); if (progress == 100) { setProgressBarIndeterminateVisibility(false); } } }); }
From source file:com.example.administrator.mywebviewdrawsign.SysWebView.java
/** * Initialize webview./* ww w . j a v a 2s. com*/ */ @SuppressLint({ "NewApi", "SetJavaScriptEnabled" }) private void setup() { this.setInitialScale(0); this.setVerticalScrollBarEnabled(true); this.setHorizontalScrollBarEnabled(true); this.requestFocusFromTouch(); // Enable JavaScript WebSettings settings = this.getSettings(); settings.setBuiltInZoomControls(false);// ?? settings.setUseWideViewPort(false); settings.setLoadWithOverviewMode(true); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); settings.setAllowFileAccess(true); settings.setAppCacheMaxSize(1024 * 1024 * 32); settings.setAppCachePath(mContext.getFilesDir().getPath() + "/cache"); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_DEFAULT); // Set Cache Mode: LOAD_NO_CACHE is noly for debug //settings.setCacheMode(WebSettings.LOAD_NO_CACHE); //enablePageCache(settings,5); //enableWorkers(settings); // Enable database settings.setDatabaseEnabled(true); String databasePath = mContext.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); // Improve render performance settings.setRenderPriority(WebSettings.RenderPriority.HIGH); if (Build.VERSION.SDK_INT >= 21) { settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } }
From source file:com.github.dfa.diaspora_android.activity.ShareActivity2.java
@SuppressLint("SetJavaScriptEnabled") @Override// ww w.j a va 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:com.cihon.androidrestart_keven.activity.CarNumActivity.java
/** * webview/* w w w .j a va 2 s. c om*/ */ public void initWebView() { MyWebViewClient webViewClient = new MyWebViewClient(); mWebView.setWebViewClient(webViewClient); WebSettings webSettings = mWebView.getSettings(); // webSettings.setLoadWithOverviewMode(true); //webview webSettings.setUseWideViewPort(true); // webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setJavaScriptEnabled(true); // mWebView.loadUrl("http://webservice.cihon.cn/onStarActive1/reupload.html"); mWebView.loadUrl("http://123.57.60.91/onStar3/vehicle-License.html"); // mWebView.loadUrl("http://wxpay.wxutil.com/mch/pay/h5.v2.php"); // jsjava mWebView.addJavascriptInterface(new JsInterface(this), "demo"); }
From source file:com.paulshantanu.bputapp.PdfViewerAcitvity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pdf_notice); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setSubtitle("View Notice"); String link = getIntent().getExtras().getString("link"); Log.i("debug", "pdfintent: " + link); url = URLDecoder.getDecodedUrl(link); progressBar = ButteryProgressBar.getInstance(PdfViewerAcitvity.this); progressBar.setVisibility(View.VISIBLE); webView = (WebView) findViewById(R.id.notice_view); webView.setVisibility(View.INVISIBLE); WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { //required for running javascript on android 4.1 or later settings.setAllowFileAccessFromFileURLs(true); settings.setAllowUniversalAccessFromFileURLs(true); }//from ww w . ja v a2 s . com settings.setBuiltInZoomControls(true); webView.setWebChromeClient(new WebChromeClient()); new DownloadTask(PdfViewerAcitvity.this).execute(url); }
From source file:io.github.calvinmikael.anymanga.WebViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w ww . j a v a 2 s .c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_web_view, container, false); mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar); mProgressBar.setVisibility(View.GONE); mWebView = (ObservableWebView) view.findViewById(R.id.webView); mWebView.setScrollViewCallbacks(this); WebSettings settings = mWebView.getSettings(); settings.setLoadsImagesAutomatically(true); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (!mProgressBar.isShown()) { mProgressBar.setVisibility(View.VISIBLE); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (mProgressBar.isShown()) { mProgressBar.setVisibility(View.GONE); } } }); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onShowCustomView(View view, CustomViewCallback callback) { // if a view already exists then immediately terminate the new one if (mCustomView != null) { onHideCustomView(); return; } // Save the current state mCustomView = view; mOriginalSystemUiVisibility = getActivity().getWindow().getDecorView().getSystemUiVisibility(); // Save the custom view callback mCustomViewCallback = callback; // Add the custom view to the view hierarchy FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView(); decorView.addView(mCustomView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mTabStrip = (PagerSlidingTabStrip) getActivity().findViewById(R.id.tabs); mTabStrip.setVisibility(View.GONE); // Go fullscreen if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { getActivity().getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getActivity().getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } @Override public void onHideCustomView() { // Remove the custom view FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView(); decorView.removeView(mCustomView); mCustomView = null; mTabStrip.setVisibility(View.VISIBLE); // Restore the original form getActivity().getWindow().getDecorView().setSystemUiVisibility(mOriginalSystemUiVisibility); // Call the custom view callback mCustomViewCallback.onCustomViewHidden(); mCustomViewCallback = null; } }); // The back button must be handled within the mWebView for the // mWebView to have back behavior based on the current mPage // if back behavior is not handled with this listener then // back behavior will be entirely dependent on the first mPage mWebView.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack() && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { mWebView.goBack(); return true; } return false; } }); if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { if (mPage == 1) { mWebView.loadUrl(getString(R.string.website_kissmanga)); } else if (mPage == 2) { mWebView.loadUrl(getString(R.string.website_mangapark)); } else if (mPage == 3) { mWebView.loadUrl(getString(R.string.website_line_webtoon)); } } return view; }
From source file:com.github.dfa.diaspora_android.activity.ShareActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override// w ww. j a v a 2 s . c o 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 } }