List of usage examples for android.webkit WebView setOnTouchListener
public void setOnTouchListener(OnTouchListener l)
From source file:de.baumann.browser.helper.helper_webView.java
private static void webView_Touch(final Activity from, final WebView webView) { webView.setOnTouchListener(new class_OnSwipeTouchListener_webview(from) { public void onSwipeRight() { if (webView.canGoBack()) { webView.goBack();//www . jav a 2s . c o m } else { Snackbar.make(webView, R.string.toast_back, Snackbar.LENGTH_SHORT).show(); } } public void onSwipeLeft() { if (webView.canGoForward()) { webView.goForward(); } else { Snackbar.make(webView, R.string.toast_forward, Snackbar.LENGTH_SHORT).show(); } } }); }
From source file:com.tearoffcalendar.activities.FaceDownCardFragment.java
public void updateCardView(String str) { WebView mMainView = (WebView) getActivity().findViewById(R.id.face_down_card_fragment); mMainView.loadDataWithBaseURL("file:///android_res/raw/", str, "text/html", "utf-8", null); mMainView.setOnTouchListener(this); // mMainView.setBackgroundColor(0); // TextView article = (TextView) getActivity().findViewById(R.id.card); // article.setText(str); }
From source file:com.blogspot.holbohistorier.readonfree.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override/* ww w.j a v a2s .c o m*/ public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
From source file:it.angrydroids.epub3reader.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override//www.j a v a2s . c o m public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); view.addJavascriptInterface(new MyJavaScriptInterface(), "INTERFACE"); view.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { view.loadUrl( "javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);"); } }); PreButton = (Button) getView().findViewById(R.id.btn_prev_chunk); TopButton = (Button) getView().findViewById(R.id.btn_display_from_top); FwdButton = (Button) getView().findViewById(R.id.btn_fwd_chunk); PreButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnPrevChunkOnClickListner(v); } }); TopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnDisplayTopOnClickListner(v); } }); FwdButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnFwdChunkOnClickListner(v); } }); loadPage(viewedPage); }
From source file:com.example.manan.enhancedurdureader.EpubReader.BookView.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override//from ww w . ja v a 2s .c o m public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); view.getSettings().setTextZoom(textSize); mScaleDetector = new ScaleGestureDetector(getActivity().getBaseContext(), new ScaleGestureDetector.OnScaleGestureListener() { @Override public void onScaleEnd(ScaleGestureDetector detector) { } @Override public boolean onScaleBegin(ScaleGestureDetector detector) { return true; } @Override public boolean onScale(ScaleGestureDetector detector) { //Log.w(LOG_KEY, "zoom ongoing, scale: " + detector.getScaleFactor()); return false; } }); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { /* if (state == ViewStateEnum.books) swipePage(v, event, 0); //int fontSize, newFont;*/ WebView view = (WebView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: x1 = event.getX(); break; case MotionEvent.ACTION_UP: if (mode != ZOOM && swipeFlag) { //if (state == ViewStateEnum.books) //swipePage(v, event, 0); } break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { mode = ZOOM; } break; case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { float scale = newDist / oldDist; if (scale > 1) { int currentTextSize = view.getSettings().getTextZoom(); textSize = currentTextSize + 15; view.getSettings().setTextZoom(textSize); mode = NONE; swipeFlag = false; } else { int currentTextSize = view.getSettings().getTextZoom(); textSize = currentTextSize - 15; view.getSettings().setTextZoom(textSize); mode = NONE; swipeFlag = false; } } } break; } return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();// w w w. j a va 2 s .co m // TODO: hack to show object history in app feeds JSONObject appState = getAppState(context, content); if (appState != null) { content = appState; } else { Log.e(TAG, "Missing inner content, probably because of format changes"); } boolean rendered = false; AppState ref = new AppState(content); String thumbnail = ref.getThumbnailImage(); if (thumbnail != null) { rendered = true; ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); App.instance().objectImages.lazyLoadImage(thumbnail.hashCode(), thumbnail, imageView); frame.addView(imageView); } thumbnail = ref.getThumbnailText(); if (thumbnail != null) { rendered = true; TextView valueTV = new TextView(context); valueTV.setText(thumbnail); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); } thumbnail = ref.getThumbnailHtml(); if (thumbnail != null) { rendered = true; WebView webview = new WebView(context); webview.loadData(thumbnail, "text/html", "UTF-8"); webview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); Object o = frame.getTag(R.id.object_entry); webview.setOnTouchListener(new WebViewClickListener(frame, (Integer) o)); frame.addView(webview); } if (!rendered) { String appName = content.optString(PACKAGE_NAME); if (appName.contains(".")) { appName = appName.substring(appName.lastIndexOf(".") + 1); } String text = "Welcome to " + appName + "!"; TextView valueTV = new TextView(context); valueTV.setText(text); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); } }
From source file:com.mimo.service.api.MimoOauth2Client.java
/** * Instantiate a webview and allows the user to login to the Api form within * the application/*from ww w.j av a2s.c o m*/ * * @param p_view * : Calling view * * @param p_activity * : Calling Activity reference **/ @SuppressLint("SetJavaScriptEnabled") public void login(View p_view, Activity p_activity) { final Activity m_activity; m_activity = p_activity; String m_url = this.m_api.getAuthUrl(); WebView m_webview = new WebView(p_view.getContext()); m_webview.getSettings().setJavaScriptEnabled(true); m_webview.setVisibility(View.VISIBLE); m_activity.setContentView(m_webview); m_webview.requestFocus(View.FOCUS_DOWN); /** * Open the softkeyboard of the device to input the text in form which * loads in webview. */ m_webview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View p_v, MotionEvent p_event) { switch (p_event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!p_v.hasFocus()) { p_v.requestFocus(); } break; } return false; } }); /** * Show the progressbar in the title of the activity untill the page * loads the give url. */ m_webview.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView p_view, int p_newProgress) { ((Activity) m_context).setProgress(p_newProgress * 100); ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING); if (p_newProgress == 100) ((Activity) m_context).setTitle(m_context.getString(R.string.app_name)); } }); m_webview.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) { } @Override public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url, String p_realm) { p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD); } public void onPageFinished(WebView p_view, String p_url) { if (MimoAPIConstants.DEBUG) { Log.d(TAG, "Page Url = " + p_url); } if (p_url.contains("?code=")) { if (p_url.indexOf("code=") != -1) { String[] m_urlSplit = p_url.split("="); String m_tempString1 = m_urlSplit[1]; if (MimoAPIConstants.DEBUG) { Log.d(TAG, "TempString1 = " + m_tempString1); } String[] m_urlSplit1 = m_tempString1.split("&"); String m_code = m_urlSplit1[0]; if (MimoAPIConstants.DEBUG) { Log.d(TAG, "code = " + m_code); } MimoOauth2Client.this.m_code = m_code; Thread m_thread = new Thread() { public void run() { String m_token = requesttoken(MimoOauth2Client.this.m_code); Log.d(TAG, "Token = " + m_token); Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class); m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token); m_activity.startActivity(m_navigateIntent); } }; m_thread.start(); } else { if (MimoAPIConstants.DEBUG) { Log.d(TAG, "going in else"); } } } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) { if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) { String[] m_urlSplit = p_url.split("="); final String m_token = m_urlSplit[1]; Thread m_thread = new Thread() { public void run() { Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class); m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token); m_activity.startActivity(m_navigateIntent); } }; m_thread.start(); } } }; }); m_webview.loadUrl(m_url); }
From source file:com.sabaibrowser.UI.java
public void setActiveTab(final Tab tab) { if (tab == null) return;//www .j a va 2 s .c o m // block unnecessary focus change animations during tab switch mHandler.removeMessages(MSG_HIDE_TITLEBAR); if ((tab != mActiveTab) && (mActiveTab != null)) { removeTabFromContentView(mActiveTab); WebView web = mActiveTab.getWebView(); if (web != null) { web.setOnTouchListener(null); } } mActiveTab = tab; BrowserWebView web = (BrowserWebView) mActiveTab.getWebView(); updateUrlBarAutoShowManagerTarget(); attachTabToContentView(tab); if (web != null) { web.setTitleBar(mTitleBar); mTitleBar.onScrollChanged(); } mTitleBar.bringToFront(); tab.getTopWindow().requestFocus(); setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); onTabDataChanged(tab); onProgressChanged(tab); mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled()); //if at Nav screen show, detach tab like what showNavScreen() do. if (mShowNav) { detachTab(mActiveTab); } BrowserWebView view = (BrowserWebView) tab.getWebView(); // TabControl.setCurrentTab has been called before this, // so the tab is guaranteed to have a webview if (view == null) { Log.e(LOGTAG, "active tab with no webview detected"); return; } // Request focus on the top window. view.setTitleBar(mTitleBar); // update nav bar state mNavigationBar.onStateChanged(UrlInputView.StateListener.STATE_NORMAL); mLastWebViewScrollY = 0; }
From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java
/** * Creates the UI for the interactive authentication process * //from w w w.j a v a2s . c o m * @param provider * The provider used for the authentication process * @param startUrl * The initial URL for the authentication process * @param endUrl * The final URL for the authentication process * @param context * The context used to create the authentication dialog * @param callback * Callback to invoke when the authentication process finishes */ private void showLoginUI(final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); wv.getSettings().setJavaScriptEnabled(true); DisplayMetrics displaymetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int webViewHeight = displaymetrics.heightPixels; wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight)); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }
From source file:com.azure.webapi.LoginManager.java
/** * Creates the UI for the interactive authentication process * //w ww . j a v a 2 s. c om * @param provider * The provider used for the authentication process * @param startUrl * The initial URL for the authentication process * @param endUrl * The final URL for the authentication process * @param context * The context used to create the authentication dialog * @param callback * Callback to invoke when the authentication process finishes */ protected void showLoginUI(MobileServiceAuthenticationProvider provider, final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setTitle("Connecting to a service"); builder.setCancelable(true); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); // Set cancel button's action builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } wv.destroy(); } }); wv.getSettings().setJavaScriptEnabled(true); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }