Skip to content

Instantly share code, notes, and snippets.

@laaptu
laaptu / tab_privacy_selector.xml
Created October 10, 2014 09:05
Selector for TextView and must be kept on res/color folder and applied as android:textColor="@color/yourselector.xml" to the TextView
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/blue" android:state_pressed="true" />
<item android:color="@color/blue" android:state_selected="true" />
<item android:color="@android:color/white" />
</selector>
@laaptu
laaptu / CreateMomentFragment.java
Created September 3, 2014 07:22
Get last clicked image path
private int getLastImageId() {
final String[] imageColumns = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA};
final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
Cursor imageCursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);
if (imageCursor.moveToFirst()) {
int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
String fullPath = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
Log.d(TAG, "getLastImageId::id " + id);
Log.d(TAG, "getLastImageId::path " + fullPath);
imageCursor.close();
@laaptu
laaptu / MapsAppDirection.java
Created August 1, 2014 04:21
Using intent to open maps for direction
//http://stackoverflow.com/questions/2662531/launching-google-maps-directions-via-an-intent-on-android
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+latitude_source+","+longitude_source+"&daddr="+latitude_dest+","+longitude_dest));
startActivity(intent);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=an+address+city"));
@laaptu
laaptu / EditTextScrollView.java
Created July 28, 2014 04:25
Edit Text inside scrollview
//http://stackoverflow.com/questions/13812892/enable-scrollable-edittext-within-a-scrollview-and-viewflipper/13815747#13815747
EditText EtOne = (EditText) findViewById(R.id.EditText01);
EtOne.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.comment1) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
@laaptu
laaptu / EmailIntentWithAttachment.java
Created July 23, 2014 11:07
Send email with attachment
Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Payment Information");
emailIntent.putExtra(Intent.EXTRA_TEXT, stringBuilder.toString());
emailIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { emailValue });
ArrayList<Uri> uris = new ArrayList<Uri>();
// convert from paths to Android friendly Parcelable Uri's
Uri uri = null;
@laaptu
laaptu / DialogWIthLinkableText.java
Created July 22, 2014 08:42
Dialog with linkable text, Dialog having clickable text
final TextView tv = new TextView(this);
final SpannableString s = new SpannableString(response);
Linkify.addLinks(s, Linkify.WEB_URLS);
tv.setText(s);
tv.setMovementMethod(LinkMovementMethod.getInstance());
AlertDialog dialog = new AlertDialog.Builder(this)
.setPositiveButton(android.R.string.ok, null)
.setView(tv).create();
dialog.show();
@laaptu
laaptu / CreditCardValid.java
Created July 22, 2014 07:07
Check whether a credit card number is valid or not? Valid credit card Number. Luhns algorithm
//http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Java
public static boolean isEmptyString(String stringValue) {
return stringValue == null || stringValue.trim().length() == 0;
}
public static boolean isCreditCardValid(String number) {
if (isEmptyString(number))
return false;
int s1 = 0, s2 = 0;
[
{
"IsAddedByMe": true,
"IsFavorite": true,
"Latitude": 27.684554,
"LocationAddress": "test",
"LocationId": 6068,
"LocationImgUrl": "http://firesonar.blob.core.windows.net/checkinlocations/test.png",
"LocationName": "test",
"Longitude": 85.333882,
@laaptu
laaptu / ViewPagerCurrentFragment.java
Created June 20, 2014 05:58
Method to get ViewPager Current Fragment
Fragment fragment = (Fragment) mPagerAdapter.instantiateItem(mPager, mPager.getCurrentItem());
@laaptu
laaptu / DialogWithLinkText.java
Created June 20, 2014 05:54
TextView with autolink or link on a dialog
final TextView tv = new TextView(this);
final SpannableString s = new SpannableString(result);
Linkify.addLinks(s, Linkify.WEB_URLS);
tv.setText(s);
tv.setMovementMethod(LinkMovementMethod.getInstance());
DialogFragment dg = new DialogFragment() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())