This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert Imageview to grayscale | |
private void convertToGrayScale(ImageView imageView, boolean convert) { | |
if (!convert) { | |
ColorMatrix matrix = new ColorMatrix(); | |
matrix.setSaturation(0); | |
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); | |
imageView.setColorFilter(filter); | |
} else { | |
imageView.setColorFilter(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.util.AttributeSet; | |
import android.view.Gravity; | |
import android.widget.TextView; | |
public class VerticalTextView extends TextView { | |
final boolean topDown; | |
public VerticalTextView(Context context, AttributeSet attrs){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Date Format | |
final static String DATE_FORMAT = "dd-MM-yyyy"; | |
public static boolean isDateValid(String inputDate) { | |
try { | |
DateFormat df = new SimpleDateFormat(DATE_FORMAT); | |
df.setLenient(false); | |
df.parse(inputDate); | |
return true; | |
} catch (ParseException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isEmailValid(CharSequence email) { | |
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
public class TimeAgo { | |
public static final List<Long> times = Arrays.asList( | |
TimeUnit.DAYS.toMillis(365), | |
TimeUnit.DAYS.toMillis(30), | |
TimeUnit.DAYS.toMillis(1), | |
TimeUnit.HOURS.toMillis(1), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// disable edittext | |
editText.setFocusable(false); | |
// enable edittext | |
editText.setFocusable(true); | |
editText.setFocusableInTouchMode(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Useful for viewPagers. | |
public class MyFragment extends Fragment { | |
@Override | |
public void setUserVisibleHint(boolean isVisibleToUser) { | |
super.setUserVisibleHint(isVisibleToUser); | |
if (isVisibleToUser) { | |
// User is viewing the fragment, | |
// or fragment is inside the screen | |
doYourThing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DisplayMetrics metrics = new DisplayMetrics(); | |
getWindowManager().getDefaultDisplay().getMetrics(metrics); | |
// With Picasso | |
Picasso .with(this) | |
.load(pictureURI) | |
.resize(metrics.widthPixels, metrics.heightPixels) | |
.centerCrop() | |
.into(imageView); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void hideKeyboard(){ | |
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | |
imm.hideSoftInputFromWindow(edittext.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple c++ program to | |
// illustrate basic encryption | |
// and decryption | |
#include<iostream> | |
using namespace std; | |
void encrypt(char *); | |
void decrypt(char *); |
OlderNewer