Gps Detector Library

What does the library do for you?

  1.  It checks whether GPS is enabled in your device. If it’s already enabled – you’ll be informed about it.
  2. In case that GPS is disabled, a dialog will appear (as can be seen on the right). Once you press “accept”, the GPS will be turned on.

The library speeds up the GPS enabling process, by sparing the user to change the settings in the android system.

So, let’s figure out how to use it.

Keep Reading

SharedPreferences helper class example

Set:

ShPref.put(R.string.some_key, System.currentTimeMillis());
//...
ShPref.put("some_hard_coded_key", System.currentTimeMillis());

Get:

ShPref.getLong(R.string.some_key, -1); // -1 default value
//...
ShPref.getLong("some_hard_coded_key", -1); // -1 default value

Keep Reading

Hot to get bitmap from VectorDrawable?

* Checked on API: 17, 21, 23

public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
    Drawable drawable = AppCompatDrawableManager.get()
            .getDrawable(context, drawableId);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        drawable = (DrawableCompat.wrap(drawable)).mutate();
    }

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}

Keep Reading

SearchView – Text color and icons change

 
SearchView mSearchView = (SearchView) findViewById(R.id.searchview);

SearchView.SearchAutoComplete mSearchSrcTextView = (SearchView.SearchAutoComplete) 
        findViewById(R.id.search_src_text);
mSearchSrcTextView.setTextColor(Color.WHITE);

ImageView mClearImage = (ImageView) findViewById(R.id.search_close_btn);
mClearImage.setImageResource(R.drawable.custom_x_button);

ImageView mHintIcon = (ImageView) findViewById(R.id.search_mag_icon);
mHintIcon.setImageResource(R.drawable.customSearchButton);

Hide/Show soft keyboard methods


private void showSoftKeyboard(View v) {
    InputMethodManager imm = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
}

Keep Reading

Handle links in TextView by Activity

1. Link creation (don’t forget to change the package name):

        mTextView= (TextView) findViewById(R.id.init_terms_text);
        mTextView.setText(
                Html.fromHtml("By continuing you accept our " +
                        "<a href=\"net.your.packagename://terms\">terms</a> " +
                        " and " +
                        "<a href=\"net.your.packagename://privacy\">privacy policy</a> "));
        mTextView.setMovementMethod(LinkMovementMethod.getInstance());
        mTextView.setLinksClickable(true);

2. Add target Activity to AndroidManifest.xml (don’t forget to change the package name):
Keep Reading

Clickable links in TextView

An example how to set text and clickable links in TextView:

textViewLinks

TextView textView = (TextView) findViewById(R.id.init_terms_text);
textView.setText(
        Html.fromHtml("By continuing you accept our " +
                "<a href=\"http://www.terms.com\">terms</a> " +
                " and " +
                "<a href=\"http://www.privacypolicy.com\">privacy policy</a> "));
textView.setMovementMethod(LinkMovementMethod.getInstance());