List of usage examples for android.view View hasFocus
@ViewDebug.ExportedProperty(category = "focus") public boolean hasFocus()
From source file:android.support.v17.leanback.widget.AbstractMediaItemPresenter.java
/** * Each media item row can have multiple focusable elements; the details on the left and a set * of optional custom actions on the right. * The selector is a highlight that moves to highlight to cover whichever views is in focus. * * @param selectorView the selector view used to highlight an individual element within a row. * @param focusChangedView The component within the media row whose focus got changed. * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width * and x-translation, generated by this method and stored for the each * {@link ViewHolder}. * @param isDetails Whether the changed-focused view is for a media item details (true) or * an action (false)./*ww w. j a v a 2s .c o m*/ */ private static ValueAnimator updateSelector(final View selectorView, View focusChangedView, ValueAnimator layoutAnimator, boolean isDetails) { int animationDuration = focusChangedView.getContext().getResources() .getInteger(android.R.integer.config_shortAnimTime); DecelerateInterpolator interpolator = new DecelerateInterpolator(); int layoutDirection = ViewCompat.getLayoutDirection(selectorView); if (!focusChangedView.hasFocus()) { // if neither of the details or action views are in focus (ie. another row is in focus), // animate the selector out. selectorView.animate().cancel(); selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start(); // keep existing layout animator return layoutAnimator; } else { // cancel existing layout animator if (layoutAnimator != null) { layoutAnimator.cancel(); layoutAnimator = null; } float currentAlpha = selectorView.getAlpha(); selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start(); final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams(); ViewGroup rootView = (ViewGroup) selectorView.getParent(); sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight()); rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect); if (isDetails) { if (layoutDirection == View.LAYOUT_DIRECTION_RTL) { sTempRect.right += rootView.getHeight(); sTempRect.left -= rootView.getHeight() / 2; } else { sTempRect.left -= rootView.getHeight(); sTempRect.right += rootView.getHeight() / 2; } } final int targetLeft = sTempRect.left; final int targetWidth = sTempRect.width(); final float deltaWidth = lp.width - targetWidth; final float deltaLeft = lp.leftMargin - targetLeft; if (deltaLeft == 0f && deltaWidth == 0f) { // no change needed } else if (currentAlpha == 0f) { // change selector to the proper width and marginLeft without animation. lp.width = targetWidth; lp.leftMargin = targetLeft; selectorView.requestLayout(); } else { // animate the selector to the proper width and marginLeft. layoutAnimator = ValueAnimator.ofFloat(0f, 1f); layoutAnimator.setDuration(animationDuration); layoutAnimator.setInterpolator(interpolator); layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // Set width to the proper width for this animation step. float fractionToEnd = 1f - valueAnimator.getAnimatedFraction(); lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd); lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd); selectorView.requestLayout(); } }); layoutAnimator.start(); } return layoutAnimator; } }
From source file:com.rbware.github.androidcouchpotato.widget.AbstractMediaItemPresenter.java
/** * Each media item row can have multiple focusable elements; the details on the left and a set * of optional custom actions on the right. * The selector is a highlight that moves to highlight to cover whichever views is in focus. * * @param selectorView the selector view used to highlight an individual element within a row. * @param focusChangedView The component within the media row whose focus got changed. * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width * and x-translation, generated by this method and stored for the each * {@link ViewHolder}. * @param isDetails Whether the changed-focused view is for a media item details (true) or * an action (false)./*www .j ava 2s .com*/ */ static ValueAnimator updateSelector(final View selectorView, View focusChangedView, ValueAnimator layoutAnimator, boolean isDetails) { int animationDuration = focusChangedView.getContext().getResources() .getInteger(android.R.integer.config_shortAnimTime); DecelerateInterpolator interpolator = new DecelerateInterpolator(); int layoutDirection = ViewCompat.getLayoutDirection(selectorView); if (!focusChangedView.hasFocus()) { // if neither of the details or action views are in focus (ie. another row is in focus), // animate the selector out. selectorView.animate().cancel(); selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start(); // keep existing layout animator return layoutAnimator; } else { // cancel existing layout animator if (layoutAnimator != null) { layoutAnimator.cancel(); layoutAnimator = null; } float currentAlpha = selectorView.getAlpha(); selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start(); final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams(); ViewGroup rootView = (ViewGroup) selectorView.getParent(); sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight()); rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect); if (isDetails) { if (layoutDirection == View.LAYOUT_DIRECTION_RTL) { sTempRect.right += rootView.getHeight(); sTempRect.left -= rootView.getHeight() / 2; } else { sTempRect.left -= rootView.getHeight(); sTempRect.right += rootView.getHeight() / 2; } } final int targetLeft = sTempRect.left; final int targetWidth = sTempRect.width(); final float deltaWidth = lp.width - targetWidth; final float deltaLeft = lp.leftMargin - targetLeft; if (deltaLeft == 0f && deltaWidth == 0f) { // no change needed } else if (currentAlpha == 0f) { // change selector to the proper width and marginLeft without animation. lp.width = targetWidth; lp.leftMargin = targetLeft; selectorView.requestLayout(); } else { // animate the selector to the proper width and marginLeft. layoutAnimator = ValueAnimator.ofFloat(0f, 1f); layoutAnimator.setDuration(animationDuration); layoutAnimator.setInterpolator(interpolator); layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // Set width to the proper width for this animation step. float fractionToEnd = 1f - valueAnimator.getAnimatedFraction(); lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd); lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd); selectorView.requestLayout(); } }); layoutAnimator.start(); } return layoutAnimator; } }
From source file:org.apache.taverna.mobile.ui.login.LoginFragment.java
@Override public void onFocusChange(View v, boolean hasFocus) { switch (v.getId()) { case R.id.etEmail: if (!v.hasFocus()) { validateEmail();/*from w w w.j ava2 s . c o m*/ } break; case R.id.etPassword: if (!v.hasFocus()) { validatePassword(); } break; } }
From source file:de.elanev.studip.android.app.backend.net.oauth.WebAuthFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); }/*w ww . ja va 2 s.co m*/ setHasOptionsMenu(true); String url = getArguments().getString(AUTH_URL); mWebView.setWebViewClient(new LoginWebViewClient()); // Workaround for embedded WebView Bug in Android 2.3, // https://code.google.com/p/android/issues/detail?id=7189 if (!ApiUtils.isOverApi11()) { mWebView.requestFocus(View.FOCUS_DOWN); mWebView.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; } }); } mWebView.loadUrl(url); }
From source file:au.com.wallaceit.reddinator.TabWebFragment.java
@SuppressLint("SetJavaScriptEnabled") public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContext = this.getActivity(); if (container == null) { return null; }// w ww . j a v a 2 s.c o m if (mFirstTime) { // get shared preferences SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(this.getActivity().getApplicationContext()); // work out the url this instance should load boolean commentswv = false; if (this.getArguments() != null) { commentswv = this.getArguments().getBoolean("loadcom", false); } int fontsize; String url; if (commentswv) { url = "http://reddit.com" + getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_PERMALINK) + ".compact"; fontsize = Integer.parseInt(prefs.getString("commentfontpref", "22")); } else { url = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_URL); fontsize = Integer.parseInt(prefs.getString("contentfontpref", "18")); } // setup progressbar mActivity = this.getActivity(); mActivity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); ll = (LinearLayout) inflater.inflate(R.layout.tab1, container, false); mWebView = (WebView) ll.findViewById(R.id.webView1); // fixes for webview not taking keyboard input on some devices mWebView.requestFocus(View.FOCUS_DOWN); mWebView.setOnTouchListener(new View.OnTouchListener() { @Override 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; } }); mWebView.getSettings().setJavaScriptEnabled(true); // enable ecmascript mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setUseWideViewPort(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setDisplayZoomControls(true); mWebView.getSettings().setDefaultFontSize(fontsize); mChromeClient = newchromeclient; mWebView.setWebChromeClient(mChromeClient); mWebView.setWebViewClient(new WebViewClient()); mWebView.loadUrl(url); mFirstTime = false; //System.out.println("Created fragment"); } else { ((ViewGroup) ll.getParent()).removeView(ll); } return ll; }
From source file:org.gdgsp.fragment.WebViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); view = inflater.inflate(R.layout.fragment_webview, container, false); webView = (WebView) view.findViewById(R.id.webview); progress = (ProgressBar) view.findViewById(R.id.progress); webView.setWebViewClient(new webViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(getArguments().getString("url")); webView.setOnTouchListener(new View.OnTouchListener() { @Override//from ww w .java 2 s . co m 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.setOnKeyListener(new OnKeyListener() { @SuppressWarnings("static-access") public boolean onKey(View view, int keyCode, KeyEvent event) { if (event.getAction() == event.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (webView.canGoBack()) { webView.goBack(); } else { getActivity().finish(); } return true; } } return false; } }); return view; }
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 w w w. j ava 2 s .c om * * @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.azure.webapi.LoginManager.java
/** * Creates the UI for the interactive authentication process * //w w w . 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(); }
From source file:io.github.clendy.leanback.widget.SpanLayoutManager.java
@Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { super.onLayoutChildren(recycler, state); if (mFocusPosition != NO_POSITION && mFocusPositionOffset != Integer.MIN_VALUE) { mFocusPosition = mFocusPosition + mFocusPositionOffset; }// w w w . j a v a2s . c o m mFocusPositionOffset = 0; boolean hadFocus = mBaseGridView.hasFocus(); final boolean scrollToFocus = !isSmoothScrolling() && mFocusScrollStrategy == BaseGridView.FOCUS_SCROLL_ALIGNED; // appends items till focus position. if (mFocusPosition != NO_POSITION) { View focusView = findViewByPosition(mFocusPosition); if (focusView != null) { if (scrollToFocus) { scrollToView(focusView, false); } if (hadFocus && !focusView.hasFocus()) { focusView.requestFocus(); } } } }
From source file:com.pixby.texo.EditTools.ColorTool.java
private void drawBackground(View v) { int color = mSampleColors.get(v.getId()); LayerDrawable layerDrawable = (LayerDrawable) v.getBackground(); if (layerDrawable != null) { GradientDrawable shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_fill); shape.setColorFilter(color, PorterDuff.Mode.MULTIPLY); shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_focus); int alpha = v.hasFocus() ? 255 : 0; shape.setAlpha(alpha);//from w w w . j av a 2 s. c om } }