Skip to content

Instantly share code, notes, and snippets.

View hilfritz's full-sized avatar

Hilfritz hilfritz

View GitHub Profile
//from https://gist.github.com/jk2K/67502e1744e081dcfef5
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
@hilfritz
hilfritz / java: jodatime get all datetime in month (including timezone)
Created October 19, 2018 03:20
java: jodatime get all datetime in month (including timezone)
public static final ArrayList<DateTime> getAllDateTimeInMonth(int month, int year, String timezoneID){
Log.d(TAG, "getAllDateTimeInMonth: month:"+month);
DateTimeZone dateTimeZone = DateTimeZone.forID(timezoneID);
DateTime dateTime = new DateTime(year, month, 1,0, 0, dateTimeZone);
Log.d(TAG, "getAllDateTimeInMonth: month:"+month+" year:"+year);
ArrayList<DateTime> daysInMonthLabels = new ArrayList<DateTime>();
use rxPermissions
https://stackoverflow.com/questions/32854169/does-checking-the-never-ask-again-box-when-asking-for-a-runtime-permission-disab
final String[] objects = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION};
findViewById(R.id.enableCamera).setOnClickListener(
view -> rxPermissions
@hilfritz
hilfritz / Example of mocking Retrofit method call
Created November 6, 2018 12:57
Android unit test: Mockito, Retrofit, Robolectric
//MODEL CLASS
interface Model{
void init(Gson gson);
public Single<List<ImgAlbum>> getPhotos();
}
/**
* @author Hilfritz Camallere on 6/11/18
*/
@hilfritz
hilfritz / gist:2401230f5cd4435067437c2b8bb9eff2
Last active November 7, 2018 03:49
Kotlin if else equivalent
property?.let {
//if 'property' is not null
fancyPrint(it) //'it' refers to 'property'
} ?: run {
//'else' clause - property is null
showError()
}
@hilfritz
hilfritz / IOS study
Last active November 19, 2018 12:35
IOS study
//----------------------------------SHORTCUTS----------------------
AUTORESIZE LABEL ACCORDING TO TEXT
- SELECT LABEL + press CMD + '='
STRING CONCAT
//let passwordInput = "HI THERE"
//let usernameInput = "HELLO THERE
let passwordInput:String = passwordField.text ?? ""
let usernameInput:String = userNameField.text ?? ""
let age = 19
@hilfritz
hilfritz / gist:1f6ec5833bae1a47106622fc598b0625
Created November 13, 2018 10:28
Android similar width/height in all device dimentions
//see https://stackoverflow.com/questions/37067271/android-graphics-drawing-same-size-circles
float devicePixelsWidth = fragment.getResources().getDisplayMetrics().widthPixels;
float deviceActualDpi = fragment.getResources().getDisplayMetrics().xdpi ;
float deviceActualInchWidth = devicePixelsWidth / deviceActualDpi ;
float deviceActualCMWidth = deviceActualInchWidth * 2.54f ;
float PixelsForActual3CM = devicePixelsWidth / deviceActualCMWidth * 3;
float radius = (float) (devicePixelsWidth / deviceActualCMWidth * 0.05);
@hilfritz
hilfritz / gist:5a8ca9e172918bc224f03c3dac9c39f3
Last active November 6, 2024 16:19
Android OnClickListener Prevent multiple clicks
import android.view.View;
/**
* inspired and credits
* @see http://stackoverflow.com/questions/16534369/avoid-button-multiple-rapid-clicks
* A Debounced OnClickListener
* Rejects clicks that are too close together in time.
* This class is safe to use as an OnClickListener for multiple views, and will debounce each one separately.
* This class allows a single click and prevents multiple clicks on
* the same button in rapid succession. Setting unclickable is not enough
@hilfritz
hilfritz / gist:f4650863968427e08df9c734e76892c7
Created December 5, 2018 05:57
android: changing dialogfragment width & height
DialogFragmentClass{
@Override
public void onStart() {
super.onStart();
int width = (int)(getResources().getDisplayMetrics().widthPixels*0.95);
int height = (int)(getResources().getDisplayMetrics().heightPixels*0.30);
getDialog().getWindow().setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT);
//THIS WILL MAKE WIDTH 90% OF SCREEN
//HEIGHT WILL BE WRAP_CONTENT
//getDialog().getWindow().setLayout(width, height);
@hilfritz
hilfritz / gist:18776d94d4c6d113c30cde9ed4a04f10
Created December 7, 2018 09:02
Android: Rxjava RxAndroid Countdown timer
//source: https://github.com/ReactiveX/RxJava/issues/3505
####Emit each item 5 seconds after the previous item:
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6));
Observable
.interval(5, TimeUnit.SECONDS)
.map(i -> list.get(i.intValue()))
.take(list.size())
.toBlocking()
.subscribe(System.out::println)