Example usage for android.view View clearFocus

List of usage examples for android.view View clearFocus

Introduction

In this page you can find the example usage for android.view View clearFocus.

Prototype

public void clearFocus() 

Source Link

Document

Called when this view wants to give up focus.

Usage

From source file:com.android.printspooler.widget.PrintContentView.java

private void ensureImeClosedAndInputFocusCleared() {
    View focused = findFocus();

    if (focused != null && focused.isFocused()) {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive(focused)) {
            imm.hideSoftInputFromWindow(getWindowToken(), 0);
        }//from w w w. j  a v a  2s  .  c  om
        focused.clearFocus();
    }
}

From source file:com.grarak.kerneladiutor.activities.NavigationActivity.java

private void init(Bundle savedInstanceState) {
    int result = Prefs.getInt("license", -1, this);
    int intentResult = getIntent().getIntExtra("result", -1);

    if ((result == intentResult && (result == 1 || result == 2)) && mLicenseDialog) {
        ViewUtils.dialogBuilder(getString(R.string.license_invalid), null,
                new DialogInterface.OnClickListener() {
                    @Override//from  w  w w.  j  a  v a  2s  . c o m
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }, new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        mLicenseDialog = false;
                        Prefs.saveInt("license", -1, NavigationActivity.this);
                    }
                }, this).show();
    } else if ((result != intentResult || result == 3) && mLicenseDialog) {
        ViewUtils.dialogBuilder(getString(R.string.pirated), null, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        }, new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                mLicenseDialog = false;
                Prefs.saveInt("license", -1, NavigationActivity.this);
            }
        }, this).show();
    } else {
        mLicenseDialog = false;
        if (result == 0) {
            Utils.DONATED = true;
        }
    }

    sCallback = new Callback() {
        @Override
        public void onBannerResize() {
            Fragment fragment = sActualFragments.get(mSelection);
            if (fragment instanceof RecyclerViewFragment) {
                ((RecyclerViewFragment) fragment).resizeBanner();
            }
        }
    };
    setContentView(R.layout.activity_navigation);
    Toolbar toolbar = getToolBar();
    setSupportActionBar(toolbar);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawer, toolbar, 0, 0);
    mDrawer.addDrawerListener(toggle);
    toggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    mNavigationView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                v.clearFocus();
            }
        }
    });
    appendFragments(false);

    if (savedInstanceState != null) {
        mSelection = savedInstanceState.getInt("selection");
        mLicenseDialog = savedInstanceState.getBoolean("license");
        mFetchingAds = savedInstanceState.getBoolean("fetching_ads");
    }

    String section = getIntent().getStringExtra("section");
    if (section != null) {
        for (int id : sActualFragments.keySet()) {
            if (sActualFragments.get(id) != null
                    && sActualFragments.get(id).getClass().getCanonicalName().equals(section)) {
                mSelection = id;
                break;
            }
        }
        getIntent().removeExtra("section");
    }

    if (mSelection == 0 || !sActualFragments.containsKey(mSelection)) {
        mSelection = firstTab();
    }
    onItemSelected(mSelection, false, false);

    startService(new Intent(this, Monitor.class));

    if (!mFetchingAds && !Utils.DONATED) {
        mFetchingAds = true;
        mAdsFetcher = new WebpageReader(this, new WebpageReader.WebpageCallback() {
            @Override
            public void onCallback(String raw, CharSequence html) {
                if (raw == null || raw.isEmpty())
                    return;
                AdNativeExpress.GHAds ghAds = new AdNativeExpress.GHAds(raw);
                if (ghAds.readable()) {
                    ghAds.cache(NavigationActivity.this);
                    for (int id : sActualFragments.keySet()) {
                        Fragment fragment = sActualFragments.get(id);
                        if (fragment instanceof RecyclerViewFragment) {
                            ((RecyclerViewFragment) fragment).ghAdReady();
                        }
                    }
                }
            }
        });
        mAdsFetcher.execute(AdNativeExpress.ADS_FETCH);
    }
}

From source file:org.telegram.ui.ApplicationActivity.java

@Override
protected void onPause() {
    super.onPause();
    ApplicationLoader.lastPauseTime = System.currentTimeMillis();
    if (notificationView != null) {
        notificationView.hide(false);//  www.  ja v a  2  s.c  om
    }
    View focusView = getCurrentFocus();
    if (focusView instanceof EditText) {
        focusView.clearFocus();
    }
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * View??bitmap/*w w w.ja  v  a2s.  co  m*/
 * 
 * @param view
 *            View
 * @return Bitmap
 */
public static Bitmap getBitmapFromView2(View view) {

    view.clearFocus();
    view.setPressed(false);

    // false
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(0);
    if (color != 0) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        if (DEBUG) {
            Log.e(TAG, "failed getViewBitmap(" + view + ")", new RuntimeException());
        }
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

/**
 * Draw the view into a bitmap.//from   w ww  .  j a v a  2s .  c  o m
 */
public static Bitmap getViewBitmap(final View v) {
    v.clearFocus();
    v.setPressed(false);

    boolean willNotCache = v.willNotCacheDrawing();

    // Reset the drawing cache background color to fully transparent
    // for the duration of this operation
    int color = v.getDrawingCacheBackgroundColor();

    if (willNotCache || color != 0) {
        v.setWillNotCacheDrawing(false);
        v.setDrawingCacheBackgroundColor(0);
        v.destroyDrawingCache();
    }

    boolean isDrawinCacheEnabled = v.isDrawingCacheEnabled();

    Bitmap bitmap = null;

    try {
        v.setDrawingCacheEnabled(true);
        v.buildDrawingCache(true);
        bitmap = Bitmap.createBitmap(v.getDrawingCache(true));
    } catch (Exception e) {
        bitmap = null;
    }
    v.setDrawingCacheEnabled(isDrawinCacheEnabled);

    // Restore the view
    if (willNotCache || color != 0) {
        v.destroyDrawingCache();
        v.setDrawingCacheBackgroundColor(color);
        v.setWillNotCacheDrawing(willNotCache);
    }

    return bitmap;
}

From source file:com.b44t.ui.Components.PasscodeView.java

public void onShow() {
    Activity parentActivity = (Activity) getContext();
    if (UserConfig.passcodeType == 1) {
        if (passwordEditText != null) {
            passwordEditText.requestFocus();
            AndroidUtilities.showKeyboard(passwordEditText);
        }// w ww .jav a  2  s .  c  o  m
    } else {
        if (parentActivity != null) {
            View currentFocus = parentActivity.getCurrentFocus();
            if (currentFocus != null) {
                currentFocus.clearFocus();
                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
            }
        }
    }
    checkFingerprint();
    if (getVisibility() == View.VISIBLE) {
        return;
    }
    setAlpha(1.0f);
    setTranslationY(0);
    backgroundDrawable = ApplicationLoader.getCachedWallpaper();
    if (backgroundDrawable != null) {
        backgroundFrameLayout.setBackgroundColor(0xb6000000);
    } else {
        backgroundFrameLayout.setBackgroundColor(Theme.ACTION_BAR_COLOR);
    }

    passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode));

    if (UserConfig.passcodeType == 0) {
        numbersFrameLayout.setVisibility(VISIBLE);
        passwordEditText.setFocusable(false);
        passwordEditText.setFocusableInTouchMode(false);
        checkImage.setVisibility(GONE);
    } else if (UserConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        numbersFrameLayout.setVisibility(GONE);
        passwordEditText.setFocusable(true);
        passwordEditText.setFocusableInTouchMode(true);
        checkImage.setVisibility(VISIBLE);
    }
    setVisibility(VISIBLE);
    passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
            | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setText("");

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}

From source file:com.yahala.ui.LaunchActivity.java

@Override
protected void onPause() {
    super.onPause();
    XMPPManager.foreground = false;/* w w  w .  j  a v  a2s . c o m*/
    ConnectionsManager.lastPauseTime = System.currentTimeMillis();
    if (notificationView != null) {
        notificationView.hide(false);
    }
    View focusView = getCurrentFocus();
    if (focusView instanceof EditText) {
        focusView.clearFocus();
    }

}

From source file:com.bushstar.htmlcoin_android_wallet.ui.ExchangeRatesFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.exchange_rates_fragment_options, menu);

    final View searchView = menu.findItem(R.id.exchange_rates_options_search).getActionView();
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView, new SearchViewCompat.OnQueryTextListenerCompat() {
            @Override/*from  ww w.  ja  v a2 s  .  c o m*/
            public boolean onQueryTextChange(final String newText) {
                query = newText.trim();
                if (query.isEmpty())
                    query = null;

                updateEmptyText();

                getLoaderManager().restartLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);

                return true;
            }

            @Override
            public boolean onQueryTextSubmit(final String query) {
                searchView.clearFocus();

                return true;
            }
        });
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:ir.besteveryeverapp.ui.Components.PasscodeView.java

public void onShow() {
    Activity parentActivity = (Activity) getContext();
    if (UserConfig.passcodeType == 1) {
        if (passwordEditText != null) {
            passwordEditText.requestFocus();
            AndroidUtilities.showKeyboard(passwordEditText);
        }//w w w  .ja va  2  s .c  o  m
    } else {
        if (parentActivity != null) {
            View currentFocus = parentActivity.getCurrentFocus();
            if (currentFocus != null) {
                currentFocus.clearFocus();
                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
            }
        }
    }
    checkFingerprint();
    if (getVisibility() == View.VISIBLE) {
        return;
    }
    setAlpha(1.0f);
    setTranslationY(0);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    int selectedBackground = preferences.getInt("selectedBackground", 1000001);
    if (selectedBackground == 1000001) {
        backgroundFrameLayout.setBackgroundColor(0xff517c9e);
    } else {
        backgroundDrawable = ApplicationLoader.getCachedWallpaper();
        if (backgroundDrawable != null) {
            backgroundFrameLayout.setBackgroundColor(0xbf000000);
        } else {
            backgroundFrameLayout.setBackgroundColor(0xff517c9e);
        }
    }

    passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode));

    if (UserConfig.passcodeType == 0) {
        //InputFilter[] filterArray = new InputFilter[1];
        //filterArray[0] = new InputFilter.LengthFilter(4);
        //passwordEditText.setFilters(filterArray);
        //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        //passwordEditText.setFocusable(false);
        //passwordEditText.setFocusableInTouchMode(false);
        numbersFrameLayout.setVisibility(VISIBLE);
        passwordEditText.setVisibility(GONE);
        passwordEditText2.setVisibility(VISIBLE);
        checkImage.setVisibility(GONE);
    } else if (UserConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        numbersFrameLayout.setVisibility(GONE);
        passwordEditText.setFocusable(true);
        passwordEditText.setFocusableInTouchMode(true);
        passwordEditText.setVisibility(VISIBLE);
        passwordEditText2.setVisibility(GONE);
        checkImage.setVisibility(VISIBLE);
    }
    setVisibility(VISIBLE);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setText("");
    passwordEditText2.eraseAllCharacters(false);

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}

From source file:com.goftagram.telegram.ui.Components.PasscodeView.java

public void onShow() {
    Activity parentActivity = (Activity) getContext();
    if (UserConfig.passcodeType == 1) {
        if (passwordEditText != null) {
            passwordEditText.requestFocus();
            AndroidUtilities.showKeyboard(passwordEditText);
        }/*from w w w  .  j av  a 2  s .com*/
    } else {
        if (parentActivity != null) {
            View currentFocus = parentActivity.getCurrentFocus();
            if (currentFocus != null) {
                currentFocus.clearFocus();
                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
            }
        }
    }
    checkFingerprint();
    if (getVisibility() == View.VISIBLE) {
        return;
    }
    if (Build.VERSION.SDK_INT >= 14) {
        ViewProxy.setAlpha(this, 1.0f);
        ViewProxy.setTranslationY(this, 0);
        this.clearAnimation();
    }
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    int selectedBackground = preferences.getInt("selectedBackground", 1000001);
    if (selectedBackground == 1000001) {
        backgroundFrameLayout.setBackgroundColor(0xff517c9e);
    } else {
        backgroundDrawable = ApplicationLoader.getCachedWallpaper();
        if (backgroundDrawable != null) {
            backgroundFrameLayout.setBackgroundColor(0xbf000000);
        } else {
            backgroundFrameLayout.setBackgroundColor(0xff517c9e);
        }
    }

    passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode));

    if (UserConfig.passcodeType == 0) {
        //InputFilter[] filterArray = new InputFilter[1];
        //filterArray[0] = new InputFilter.LengthFilter(4);
        //passwordEditText.setFilters(filterArray);
        //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        //passwordEditText.setFocusable(false);
        //passwordEditText.setFocusableInTouchMode(false);
        numbersFrameLayout.setVisibility(VISIBLE);
        passwordEditText.setVisibility(GONE);
        passwordEditText2.setVisibility(VISIBLE);
        checkImage.setVisibility(GONE);
    } else if (UserConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        numbersFrameLayout.setVisibility(GONE);
        passwordEditText.setFocusable(true);
        passwordEditText.setFocusableInTouchMode(true);
        passwordEditText.setVisibility(VISIBLE);
        passwordEditText2.setVisibility(GONE);
        checkImage.setVisibility(VISIBLE);
    }
    setVisibility(VISIBLE);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setText("");
    passwordEditText2.eraseAllCharacters(false);

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}