This file contains hidden or 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
| //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; |
This file contains hidden or 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 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>(); |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| //MODEL CLASS | |
| interface Model{ | |
| void init(Gson gson); | |
| public Single<List<ImgAlbum>> getPhotos(); | |
| } | |
| /** | |
| * @author Hilfritz Camallere on 6/11/18 | |
| */ |
This file contains hidden or 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
| property?.let { | |
| //if 'property' is not null | |
| fancyPrint(it) //'it' refers to 'property' | |
| } ?: run { | |
| //'else' clause - property is null | |
| showError() | |
| } |
This file contains hidden or 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
| //----------------------------------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 |
This file contains hidden or 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
| //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); |
This file contains hidden or 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.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 |
This file contains hidden or 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
| 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); |
This file contains hidden or 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
| //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) |