Skip to content

Instantly share code, notes, and snippets.

View klarcrk's full-sized avatar
🎯
Focusing

klarcrk klarcrk

🎯
Focusing
View GitHub Profile
@klarcrk
klarcrk / ToStringConverterFactory.java
Created March 21, 2016 10:14
for retrofit2.0. Get request result as string.
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
@klarcrk
klarcrk / JsonObjectConverterFactory.java
Created March 21, 2016 10:26
retrofit2 convert factory. get retrofit result as JsonObject.
/**
* Created by yh on 2016/3/21.
*/
public class JsonObjectConverterFactory
extends Converter.Factory {
/**
* Create an instance using {@code gson} for conversion. Encoding to JSON and
* decoding from JSON (when no charset is specified by a header) will use UTF-8.
*/
@klarcrk
klarcrk / 0_reuse_code.js
Created April 27, 2016 07:34
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@klarcrk
klarcrk / NumberTest.java
Created June 16, 2016 03:59
formate string with separator in fixed length index
/**
* formate string with separator in fixed length index
*
* @param inputCardNumber
* @param separator
* @return
*/
public static String addSeparatorToString(String inputCardNumber, String separator) {
int separatorLength = 4;
String formattingText = inputCardNumber.replaceAll(separator, "");
@klarcrk
klarcrk / GravitySnapHelper.java
Created January 3, 2017 06:42
a snahelper to reclerview with linearlayout,keep first item completely show
/*
* Copyright (C) 2016 The Android Open Source Project
* Copyright (C) 2016 Rúben Sousa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@klarcrk
klarcrk / SetDrawerWidth.java
Created January 18, 2017 09:33
set drawer width in Drawlayout,based on screen width
float offset = 0.22f * getResources().getDisplayMetrics().widthPixels;
float width = getResources().getDisplayMetrics().widthPixels - offset;
DrawerLayout.LayoutParams params =
(android.support.v4.widget.DrawerLayout.LayoutParams) navView.getLayoutParams();
params.width = (int) width;
navView.setLayoutParams(params);
@klarcrk
klarcrk / HomeGoodsListTypeDelegate.java
Created January 20, 2017 06:25
tint drawable color
Drawable arrowDrawable = ContextCompat.getDrawable(context, R.drawable.right_3x);
DrawableCompat.setTint(arrowDrawable, ContextCompat.getColor(context, R.color.common_text_color_33));
moreView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, arrowDrawable, null);
@klarcrk
klarcrk / FlowableExample.java
Created March 23, 2017 06:16
Rxjava2 operator
public class FlowableExample {
public static void main1(String[] args) {
//reduce 操作符 结果为50+1+2
Flowable<Integer> flowable = Flowable.just(1, 2);
flowable.reduce(50, (t1, t2) -> {
System.out.println("f1:" + t1);
System.out.println("f2:" + t2);
return t1 + t2;
}).subscribeWith(new SingleObserver<Integer>() {
@klarcrk
klarcrk / Rxjava2Test.java
Last active May 7, 2018 08:09
Rxjava2 取消订阅
public class Rxjava2Test {
public static void main1(String[] args) {
//停止某个定时任务
PublishSubject stop = PublishSubject.create();
final Observable<Long> observable = Observable.interval(1, TimeUnit.SECONDS).takeUntil(stop);
observable.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
//do something
}
@klarcrk
klarcrk / ShopTabFragment.java
Created April 7, 2017 06:07
Scroll up show button
shopTabRecyclerBinding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
private boolean scrollUp = true;
private long showTime = 2000;
private Runnable disappearRunnable = new Runnable() {
@Override
public void run() {
shopTabRecyclerBinding.homeScrollUpIco.animate().alpha(0).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {