List of usage examples for android.view View hasFocus
@ViewDebug.ExportedProperty(category = "focus") public boolean hasFocus()
From source file:org.cobaltians.cobalt.fragments.CobaltFragment.java
protected void setWebViewSettings(CobaltFragment javascriptInterface) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD) mWebView.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS); mWebView.setScrollListener(this); mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); // Enables JS WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); // Enables and setups JS local storage webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); //@deprecated since API 19. But calling this method have simply no effect for API 19+ webSettings.setDatabasePath(mContext.getFilesDir().getParentFile().getPath() + "/databases/"); // Enables cross-domain calls for Ajax allowAjax();/*from w ww .j av a 2 s. com*/ // Fix some focus issues on old devices like HTC Wildfire // keyboard was not properly showed on input touch. mWebView.requestFocus(View.FOCUS_DOWN); mWebView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!view.hasFocus()) { view.requestFocus(); } break; default: break; } return false; } }); //Enable Webview debugging from chrome desktop if (Cobalt.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } // Add JavaScript interface so JavaScript can call native functions. mWebView.addJavascriptInterface(javascriptInterface, "Android"); mWebView.addJavascriptInterface(new LocalStorageJavaScriptInterface(mContext), "LocalStorage"); WebViewClient webViewClient = new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { executeWaitingCalls(); } }; mWebView.setWebViewClient(webViewClient); }
From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java
@Override public void create() { try {//from ww w . ja v a 2 s . com setContentView(R.layout.romanblack_html_main); root = (FrameLayout) findViewById(R.id.romanblack_root_layout); webView = new ObservableWebView(this); webView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); root.addView(webView); webView.setHorizontalScrollBarEnabled(false); setTitle("HTML"); Intent currentIntent = getIntent(); Bundle store = currentIntent.getExtras(); widget = (Widget) store.getSerializable("Widget"); if (widget == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } appName = widget.getAppName(); if (widget.getPluginXmlData().length() == 0) { if (currentIntent.getStringExtra("WidgetFile").length() == 0) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } } if (widget.getTitle() != null && widget.getTitle().length() > 0) { setTopBarTitle(widget.getTitle()); } else { setTopBarTitle(getResources().getString(R.string.romanblack_html_web)); } currentUrl = (String) getSession(); if (currentUrl == null) { currentUrl = ""; } ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isConnectedOrConnecting()) { isOnline = true; } // topbar initialization setTopBarLeftButtonText(getString(R.string.common_home_upper), true, new View.OnClickListener() { @Override public void onClick(View view) { onBackPressed(); } }); if (isOnline) { webView.getSettings().setJavaScriptEnabled(true); } webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.getSettings().setGeolocationEnabled(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setUseWideViewPort(false); webView.getSettings().setSavePassword(false); webView.clearHistory(); webView.invalidate(); if (Build.VERSION.SDK_INT >= 19) { } webView.getSettings().setUserAgentString( "Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.invalidate(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { } break; case MotionEvent.ACTION_UP: { if (!v.hasFocus()) { v.requestFocus(); } } break; case MotionEvent.ACTION_MOVE: { } break; } return false; } }); webView.setBackgroundColor(Color.WHITE); try { if (widget.getBackgroundColor() != Color.TRANSPARENT) { webView.setBackgroundColor(widget.getBackgroundColor()); } } catch (IllegalArgumentException e) { } webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); } }); webView.setWebChromeClient(new WebChromeClient() { FrameLayout.LayoutParams LayoutParameters = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); @Override public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) { AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this); builder.setTitle(R.string.location_dialog_title); builder.setMessage(R.string.location_dialog_description); builder.setCancelable(true); builder.setPositiveButton(R.string.location_dialog_allow, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callback.invoke(origin, true, false); } }); builder.setNegativeButton(R.string.location_dialog_not_allow, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callback.invoke(origin, false, false); } }); AlertDialog alert = builder.create(); alert.show(); } @Override public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { if (customView != null) { customViewCallback.onCustomViewHidden(); return; } view.setBackgroundColor(Color.BLACK); view.setLayoutParams(LayoutParameters); root.addView(view); customView = view; customViewCallback = callback; webView.setVisibility(View.GONE); } @Override public void onHideCustomView() { if (customView == null) { return; } else { closeFullScreenVideo(); } } public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT);//Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); isMedia = true; startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } // For Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } //For Android 4.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); isMedia = true; i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { isV21 = true; mUploadMessageV21 = filePathCallback; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); return true; } @Override public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) { super.onReceivedTouchIconUrl(view, url, precomposed); } }); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (state == states.EMPTY) { currentUrl = url; setSession(currentUrl); state = states.LOAD_START; handler.sendEmptyMessage(SHOW_PROGRESS); } } @Override public void onLoadResource(WebView view, String url) { if (!alreadyLoaded && (url.startsWith("http://www.youtube.com/get_video_info?") || url.startsWith("https://www.youtube.com/get_video_info?")) && Build.VERSION.SDK_INT < 11) { try { String path = url.contains("https://www.youtube.com/get_video_info?") ? url.replace("https://www.youtube.com/get_video_info?", "") : url.replace("http://www.youtube.com/get_video_info?", ""); String[] parqamValuePairs = path.split("&"); String videoId = null; for (String pair : parqamValuePairs) { if (pair.startsWith("video_id")) { videoId = pair.split("=")[1]; break; } } if (videoId != null) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")) .setData(Uri.parse("http://www.youtube.com/watch?v=" + videoId))); needRefresh = true; alreadyLoaded = !alreadyLoaded; return; } } catch (Exception ex) { } } else { super.onLoadResource(view, url); } } @Override public void onPageFinished(WebView view, String url) { if (hideProgress) { if (TextUtils.isEmpty(WebPlugin.this.url)) { state = states.LOAD_COMPLETE; handler.sendEmptyMessage(HIDE_PROGRESS); super.onPageFinished(view, url); } else { view.loadUrl("javascript:(function(){" + "l=document.getElementById('link');" + "e=document.createEvent('HTMLEvents');" + "e.initEvent('click',true,true);" + "l.dispatchEvent(e);" + "})()"); hideProgress = false; } } else { state = states.LOAD_COMPLETE; handler.sendEmptyMessage(HIDE_PROGRESS); super.onPageFinished(view, url); } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (errorCode == WebViewClient.ERROR_BAD_URL) { startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), DOWNLOAD_REQUEST_CODE); } } @Override public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) { final AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this); builder.setMessage(R.string.notification_error_ssl_cert_invalid); builder.setPositiveButton(WebPlugin.this.getResources().getString(R.string.wp_continue), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.proceed(); } }); builder.setNegativeButton(WebPlugin.this.getResources().getString(R.string.wp_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.show(); } @Override public void onFormResubmission(WebView view, Message dontResend, Message resend) { super.onFormResubmission(view, dontResend, resend); } @Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { return super.shouldInterceptRequest(view, request); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { try { if (url.contains("youtube.com/watch")) { if (Build.VERSION.SDK_INT < 11) { try { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")) .setData(Uri.parse(url))); return true; } catch (Exception ex) { return false; } } else { return false; } } else if (url.contains("paypal.com")) { if (url.contains("&bn=ibuildapp_SP")) { return false; } else { url = url + "&bn=ibuildapp_SP"; webView.loadUrl(url); return true; } } else if (url.contains("sms:")) { try { Intent smsIntent = new Intent(Intent.ACTION_VIEW); smsIntent.setData(Uri.parse(url)); startActivity(smsIntent); return true; } catch (Exception ex) { Log.e("", ex.getMessage()); return false; } } else if (url.contains("tel:")) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(url)); startActivity(callIntent); return true; } else if (url.contains("mailto:")) { MailTo mailTo = MailTo.parse(url); Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { mailTo.getTo() }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mailTo.getSubject()); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mailTo.getBody()); WebPlugin.this.startActivity(Intent.createChooser(emailIntent, getString(R.string.romanblack_html_send_email))); return true; } else if (url.contains("rtsp:")) { Uri address = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, address); final PackageManager pm = getPackageManager(); final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0); if (matches.size() > 0) { startActivity(intent); } else { Toast.makeText(WebPlugin.this, getString(R.string.romanblack_html_no_video_player), Toast.LENGTH_SHORT).show(); } return true; } else if (url.startsWith("intent:") || url.startsWith("market:") || url.startsWith("col-g2m-2:")) { Intent it = new Intent(); it.setData(Uri.parse(url)); startActivity(it); return true; } else if (url.contains("//play.google.com/")) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else { if (url.contains("ibuildapp.com-1915109")) { String param = Uri.parse(url).getQueryParameter("widget"); finish(); if (param != null && param.equals("1001")) com.appbuilder.sdk.android.Statics.launchMain(); else if (param != null && !"".equals(param)) { View.OnClickListener widget = Statics.linkWidgets.get(Integer.valueOf(param)); if (widget != null) widget.onClick(view); } return false; } currentUrl = url; setSession(currentUrl); if (!isOnline) { handler.sendEmptyMessage(HIDE_PROGRESS); handler.sendEmptyMessage(STOP_LOADING); } else { String pageType = "application/html"; if (!url.contains("vk.com")) { getPageType(url); } if (pageType.contains("application") && !pageType.contains("html") && !pageType.contains("xml")) { startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), DOWNLOAD_REQUEST_CODE); return super.shouldOverrideUrlLoading(view, url); } else { view.getSettings().setLoadWithOverviewMode(true); view.getSettings().setUseWideViewPort(true); view.setBackgroundColor(Color.WHITE); } } return false; } } catch (Exception ex) { // Error Logging return false; } } }); handler.sendEmptyMessage(SHOW_PROGRESS); new Thread() { @Override public void run() { EntityParser parser; if (widget.getPluginXmlData() != null) { if (widget.getPluginXmlData().length() > 0) { parser = new EntityParser(widget.getPluginXmlData()); } else { String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile")); parser = new EntityParser(xmlData); } } else { String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile")); parser = new EntityParser(xmlData); } parser.parse(); url = parser.getUrl(); html = parser.getHtml(); if (url.length() > 0 && !isOnline) { handler.sendEmptyMessage(NEED_INTERNET_CONNECTION); } else { if (isOnline) { } else { if (html.length() == 0) { } } if (html.length() > 0 || url.length() > 0) { handler.sendEmptyMessageDelayed(SHOW_HTML, 700); } else { handler.sendEmptyMessage(HIDE_PROGRESS); handler.sendEmptyMessage(INITIALIZATION_FAILED); } } } }.start(); } catch (Exception ex) { } }
From source file:android.support.v17.leanback.app.BrowseFragment.java
private void createHeadersTransition() { mHeadersTransition = TransitionHelper.loadTransition(getActivity(), mShowingHeaders ? R.transition.lb_browse_headers_in : R.transition.lb_browse_headers_out); TransitionHelper.addTransitionListener(mHeadersTransition, new TransitionListener() { @Override// w ww . j ava2 s . co m public void onTransitionStart(Object transition) { } @Override public void onTransitionEnd(Object transition) { mHeadersTransition = null; if (mMainFragmentAdapter != null) { mMainFragmentAdapter.onTransitionEnd(); if (!mShowingHeaders && mMainFragment != null) { View mainFragmentView = mMainFragment.getView(); if (mainFragmentView != null && !mainFragmentView.hasFocus()) { mainFragmentView.requestFocus(); } } } if (mHeadersFragment != null) { mHeadersFragment.onTransitionEnd(); if (mShowingHeaders) { VerticalGridView headerGridView = mHeadersFragment.getVerticalGridView(); if (headerGridView != null && !headerGridView.hasFocus()) { headerGridView.requestFocus(); } } } // Animate TitleView once header animation is complete. updateTitleViewVisibility(); if (mBrowseTransitionListener != null) { mBrowseTransitionListener.onHeadersTransitionStop(mShowingHeaders); } } }); }
From source file:android.support.v17.leanback.app.BrowseSupportFragment.java
private void createHeadersTransition() { mHeadersTransition = TransitionHelper.loadTransition(getActivity(), mShowingHeaders ? R.transition.lb_browse_headers_in : R.transition.lb_browse_headers_out); TransitionHelper.addTransitionListener(mHeadersTransition, new TransitionListener() { @Override/* ww w . ja v a 2 s . c om*/ public void onTransitionStart(Object transition) { } @Override public void onTransitionEnd(Object transition) { mHeadersTransition = null; if (mMainFragmentAdapter != null) { mMainFragmentAdapter.onTransitionEnd(); if (!mShowingHeaders && mMainFragment != null) { View mainFragmentView = mMainFragment.getView(); if (mainFragmentView != null && !mainFragmentView.hasFocus()) { mainFragmentView.requestFocus(); } } } if (mHeadersSupportFragment != null) { mHeadersSupportFragment.onTransitionEnd(); if (mShowingHeaders) { VerticalGridView headerGridView = mHeadersSupportFragment.getVerticalGridView(); if (headerGridView != null && !headerGridView.hasFocus()) { headerGridView.requestFocus(); } } } // Animate TitleView once header animation is complete. updateTitleViewVisibility(); if (mBrowseTransitionListener != null) { mBrowseTransitionListener.onHeadersTransitionStop(mShowingHeaders); } } }); }
From source file:com.rbware.github.androidcouchpotato.app.BrowseFragment.java
void createHeadersTransition() { mHeadersTransition = TransitionHelper.loadTransition(getActivity(), mShowingHeaders ? R.transition.lb_browse_headers_in : R.transition.lb_browse_headers_out); TransitionHelper.addTransitionListener(mHeadersTransition, new TransitionListener() { @Override//from ww w .jav a 2 s. co m public void onTransitionStart(Object transition) { } @Override public void onTransitionEnd(Object transition) { mHeadersTransition = null; if (mMainFragmentAdapter != null) { mMainFragmentAdapter.onTransitionEnd(); if (!mShowingHeaders && mMainFragment != null) { View mainFragmentView = mMainFragment.getView(); if (mainFragmentView != null && !mainFragmentView.hasFocus()) { mainFragmentView.requestFocus(); } } } if (mHeadersFragment != null) { mHeadersFragment.onTransitionEnd(); if (mShowingHeaders) { VerticalGridView headerGridView = mHeadersFragment.getVerticalGridView(); if (headerGridView != null && !headerGridView.hasFocus()) { headerGridView.requestFocus(); } } } // Animate TitleView once header animation is complete. updateTitleViewVisibility(); if (mBrowseTransitionListener != null) { mBrowseTransitionListener.onHeadersTransitionStop(mShowingHeaders); } } }); }
From source file:com.rbware.github.androidcouchpotato.app.BrowseSupportFragment.java
void createHeadersTransition() { mHeadersTransition = TransitionHelper.loadTransition(getActivity(), mShowingHeaders ? R.transition.lb_browse_headers_in : R.transition.lb_browse_headers_out); TransitionHelper.addTransitionListener(mHeadersTransition, new TransitionListener() { @Override//from ww w .j ava 2 s . com public void onTransitionStart(Object transition) { } @Override public void onTransitionEnd(Object transition) { mHeadersTransition = null; if (mMainFragmentAdapter != null) { mMainFragmentAdapter.onTransitionEnd(); if (!mShowingHeaders && mMainFragment != null) { View mainFragmentView = mMainFragment.getView(); if (mainFragmentView != null && !mainFragmentView.hasFocus()) { mainFragmentView.requestFocus(); } } } if (mHeadersSupportFragment != null) { mHeadersSupportFragment.onTransitionEnd(); if (mShowingHeaders) { VerticalGridView headerGridView = mHeadersSupportFragment.getVerticalGridView(); if (headerGridView != null && !headerGridView.hasFocus()) { headerGridView.requestFocus(); } } } // Animate TitleView once header animation is complete. updateTitleViewVisibility(); if (mBrowseTransitionListener != null) { mBrowseTransitionListener.onHeadersTransitionStop(mShowingHeaders); } } }); }
From source file:org.liberty.android.fantastischmemo.downloader.google.GoogleOAuth2AccessCodeRetrievalFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); final View v = inflater.inflate(R.layout.oauth_login_layout, container, false); final WebView webview = (WebView) v.findViewById(R.id.login_page); final View loadingText = v.findViewById(R.id.auth_page_load_text); final View progressDialog = v.findViewById(R.id.auth_page_load_progress); final LinearLayout ll = (LinearLayout) v.findViewById(R.id.ll); // We have to set up the dialog's webview size manually or the webview will be zero size. // This should be a bug of Android. Rect displayRectangle = new Rect(); Window window = mActivity.getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle); ll.setMinimumWidth((int) (displayRectangle.width() * 0.9f)); ll.setMinimumHeight((int) (displayRectangle.height() * 0.8f)); webview.getSettings().setJavaScriptEnabled(true); try {//from w w w .j av a2 s. c o m String uri = String.format( "https://accounts.google.com/o/oauth2/auth?client_id=%s&response_type=%s&redirect_uri=%s&scope=%s", URLEncoder.encode(AMEnv.GOOGLE_CLIENT_ID, "UTF-8"), URLEncoder.encode("code", "UTF-8"), URLEncoder.encode(AMEnv.GOOGLE_REDIRECT_URI, "UTF-8"), URLEncoder.encode(AMEnv.GDRIVE_SCOPE, "UTF-8")); webview.loadUrl(uri); } catch (Exception e) { throw new RuntimeException(e); } // This is workaround to show input on some android version. webview.requestFocus(View.FOCUS_DOWN); webview.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); webview.setWebViewClient(new WebViewClient() { private boolean authenticated = false; @Override public void onPageFinished(WebView view, String url) { loadingText.setVisibility(View.GONE); progressDialog.setVisibility(View.GONE); webview.setVisibility(View.VISIBLE); if (authenticated == true) { return; } String code = getAuthCodeFromUrl(url); String error = getErrorFromUrl(url); if (error != null) { authCodeReceiveListener.onAuthCodeError(error); authenticated = true; dismiss(); } if (code != null) { authenticated = true; authCodeReceiveListener.onAuthCodeReceived(code); dismiss(); } } }); return v; }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void test27766012() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear_with_button_onleft); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.horizontal_item); intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 2); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_UPDATE_SIZE, false); initActivity(intent);// w w w . j a v a 2 s .c o m mOrientation = BaseGridView.VERTICAL; mNumRows = 1; // set remove animator two seconds mGridView.getItemAnimator().setRemoveDuration(2000); final View view = mGridView.getChildAt(1); runTestOnUiThread(new Runnable() { @Override public void run() { view.requestFocus(); } }); assertTrue(view.hasFocus()); runTestOnUiThread(new Runnable() { @Override public void run() { mActivity.removeItems(0, 2); } }); // wait one second, removing second view is still attached to parent Thread.sleep(1000); assertSame(view.getParent(), mGridView); runTestOnUiThread(new Runnable() { @Override public void run() { // refocus to the removed item and do a focus search. view.requestFocus(); view.focusSearch(View.FOCUS_UP); } }); }
From source file:org.bangbang.support.v4.widget.HListView.java
/** * To avoid horizontal focus searches changing the selected item, we * manually focus search within the selected item (as applicable), and * prevent focus from jumping to something within another item. * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT} * @return Whether this consumes the key event. *//*w ww . j ava2s .co m*/ private boolean handleHorizontalFocusWithinListItem(int direction) { if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) { throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}"); } final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // do the math to get interesting rect in next focus' coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // we are blocking the key from being handled (by returning true) // if the global result is going to be some other view within this // list. this is to acheive the overall goal of having // horizontal d-pad navigation remain in the current item. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }
From source file:com.rbware.github.androidcouchpotato.widget.GridLayoutManager.java
private void scrollToFocusViewInLayout(boolean hadFocus, boolean alignToView) { View focusView = findViewByPosition(mFocusPosition); if (focusView != null && alignToView) { scrollToView(focusView, false);/*from w ww . ja v a 2 s . c o m*/ } if (focusView != null && hadFocus && !focusView.hasFocus()) { focusView.requestFocus(); } else if (!hadFocus && !mBaseGridView.hasFocus()) { if (focusView != null && focusView.hasFocusable()) { mBaseGridView.focusableViewAvailable(focusView); } else { for (int i = 0, count = getChildCount(); i < count; i++) { focusView = getChildAt(i); if (focusView != null && focusView.hasFocusable()) { mBaseGridView.focusableViewAvailable(focusView); break; } } // focusViewAvailable() might focus to the view, scroll to it if that is the case. if (alignToView && focusView != null && focusView.hasFocus()) { scrollToView(focusView, false); } } } }