Skip to content

Instantly share code, notes, and snippets.

View nontravis's full-sized avatar

Nonthawit Doungsodsri nontravis

View GitHub Profile
@nontravis
nontravis / ManagerForTest.java
Created February 19, 2017 08:41
Example_Manager_for_test
class Manager{
public void requestSomeSerice(){
// some logic for get response form server
...
if( response.isSuccess(){
RxBus.get().post(new SuccesEvent());
}else{
RxBus.get().post(new FailEvent());
@nontravis
nontravis / PresenterManagerIntegrationTest.java
Last active February 19, 2017 10:53
Example_Integration_test
@RunWith(JUnit4.class)
class PresenterManagerIntegrationTest{
@Before
public void setup(){
...
}
@Test
public void requestSevice(){
@nontravis
nontravis / RxSchedulersOverrideRule.java
Created April 27, 2017 08:34
RxSchedulersOverrideRule
/**
* This rule registers SchedulerHooks for RxJava and RxAndroid to ensure that subscriptions
* always subscribeOn and observeOn Schedulers.immediate().
* Warning, this rule will reset RxAndroidPlugins and RxJavaPlugins before and after each test so
* if the application code uses RxJava plugins this may affect the behaviour of the testing method.
*/
public class RxSchedulersOverrideRule implements TestRule {
private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
@nontravis
nontravis / TextView-setText.java
Created July 29, 2017 09:29
TextView-setText.java
private void setText(CharSequence text, BufferType type,
boolean notifyBefore, int oldlen) {
if (text == null) {
text = "";
}
// If suggestions are not enabled, remove the suggestion spans from the text
if (!isSuggestionsEnabled()) {
text = removeSuggestionSpans(text);
}
@nontravis
nontravis / SpannableStringBuilder-append.java
Created July 29, 2017 09:30
SpannableStringBuilder-append.java
public SpannableStringBuilder append(CharSequence text) {
int length = length();
return replace(length, length, text, 0, text.length());
}
...
public SpannableStringBuilder replace(final int start, final int end,
CharSequence tb, int tbstart, int tbend) {
checkRange("replace", start, end);
@nontravis
nontravis / DashTextWatcher-wrong.java
Created July 29, 2017 10:12
DashTextWatcher-wrong.java
public class DashTextWatcher implements TextWatcher{
private final String format;
private EditText edt;
private String strAfter;
private String strBefore;
private int selectionIndex;
private int maxLength;
public DashTextWatcher( EditText edt, String format ){
this.format = format;
@nontravis
nontravis / font-xml-example.xml
Created October 25, 2017 05:02
font-xml-example
<?xml version="1.0" encoding="utf-8"?>
<font-family 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"
tools:ignore="UnusedAttribute">
<font
android:font="@font/productsans_regular"
android:fontStyle="normal"
android:fontWeight="400"
@nontravis
nontravis / lollipop_round_primary_selector.xml
Created December 8, 2017 04:47
lollipop_round_primary_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorAccent">
<item
android:id="@android:id/mask"
android:drawable="@drawable/lollipop_round_primary_mask"/>
<item>
<selector>
<item android:drawable="@drawable/lollipop_round_primary_focused"
android:state_focused="true" />
@nontravis
nontravis / lollipop_round_primary_mask.xml
Created December 8, 2017 04:51
lollipop_round_primary_mask.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="30dp"/>
<solid android:color="@android:color/black"/>
</shape>
@nontravis
nontravis / slide_example.xml
Created December 26, 2017 09:59
slide_example.xml
[ slide_in_from_right.xml ]
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/fragment_transition_time"
android:fromXDelta="100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="0" />
</set>