Skip to content

Instantly share code, notes, and snippets.

View hilfritz's full-sized avatar

Hilfritz hilfritz

View GitHub Profile
@hilfritz
hilfritz / Android: open pdf using external app
Created July 19, 2018 03:41
Android: open pdf using external app
public static void openPDFFiile(Context context,File file){
//OPEN THE PDF
String mimeTypeStr = "application/pdf";
Intent intent2 = new Intent(Intent.ACTION_VIEW);
//intent2.setDataAndType(uri, mimeTypeStr);
//Uri apkURI = FileProvider.getUriForFile(
// context,
// context.getApplicationContext()
// .getPackageName() + ".provider", file);
@hilfritz
hilfritz / Android: Perform process in background
Created July 18, 2018 07:31
Android: Perform process in background
AsyncTask.execute(new Runnable() {
@Override
public void run() {
//ADD YOUR CODE TO EXECUTE IN BACKGROUND THREAD HERE
}
});
@hilfritz
hilfritz / java decimal places for double
Created July 17, 2018 06:44
java decimal places for double
/**
* from here: https://stackoverflow.com/questions/22186778/using-math-round-to-round-to-one-decimal-place
* @param value double value with decimal places 123.123456789
* @param precision 1 number of decimal places desired ex. 1 (result => 123.1)
* @return
*/
public static double roundToDecimalPlaces(double value, int precision) {
int scale = (int) Math.pow(10, precision);
return (double) Math.round(value * scale) / scale;
}
@hilfritz
hilfritz / android questions
Created July 10, 2018 13:41
android questions
https://github.com/MindorksOpenSource/android-interview-questions#data-structures-and-algorithms
https://www.toptal.com/android/interview-questions
What is a ContentProvider and what is it typically used for?
-A ContentProvider manages access to a structured set of data. It encapsulates the data and provide mechanisms for defining data security. ContentProvider is the standard interface that connects data in one process with code running in another process.
Under what condition could the code sample below crash your application? How would you modify the code to avoid this potential problem? Explain your answer.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
@hilfritz
hilfritz / gist:08c4fe44dc533ed211b69c49593cff35
Last active June 21, 2018 14:23
Android Java logger that makes sure the logs are not cut when the string is too long
public class Logger {
public static final void logd(String tag, String message){
Logger.d(tag, message);
}
public static void d(String TAG, String message) {
int maxLogSize = 1000;
for(int i = 0; i <= message.length() / maxLogSize; i++) {
int start = i * maxLogSize;
int end = (i+1) * maxLogSize;
//kotlin code
editText.
filters = arrayOf<InputFilter>(object : InputFilter.AllCaps() {
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence {
return source.toString().toLowerCase()
}
})
//xml layout
<?xml version="1.0" encoding="utf-8"?>
@hilfritz
hilfritz / gist:23ae7e8072de6f9ff1577a439828e016
Created June 5, 2018 06:42
Scrollable TextView inside Recyclerview
//recyclerview list item layout xml with scrollable textview
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
> <TextView
@hilfritz
hilfritz / gist:bc97f6844343b3a36d17637a08ab8881
Created January 15, 2018 06:31
Android show/hide view with fade
private void animateCountdown(final View textView){
ValueAnimator valueAnimator = ValueAnimator.ofFloat(1f, 0f);
valueAnimator.setDuration(800);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float alpha = Float.parseFloat(animation.getAnimatedValue().toString());
textView.setAlpha(alpha);
}
});
@hilfritz
hilfritz / Add filter to edittext
Last active November 28, 2017 06:52
Limit the inputs the edittext will receive
/**
* Usage:
* val limit0to24 = EditTextInputFilter(0, 23)
* val limitChars = EditTextInputFilter(arrayListOf("a","b","c","d","e","f","g","h", "ab", "cd"))
* input1.setFilters(arrayOf(limit0to24))
* input2.setFilters(arrayOf(limitChars))
*
*/
class EditTextInputFilter : InputFilter {
@hilfritz
hilfritz / gist:c34aaaacef191830ff80cd9b72cc8e6f
Last active November 23, 2017 06:37
Android Kotlin Clean Arch Boilerplates
-------------------------------------------------------------------
------------------------build.gradle-------------------------------
-------------------------------------------------------------------
/**
* RxJava2 and RxAndroid2 gradle setup
implementation 'com.android.support:design:26.1.0'
compile group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.1.5'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
*/