Skip to content

Instantly share code, notes, and snippets.

View gibson-khs's full-sized avatar
🤡
GIBSON

Gibson Kim gibson-khs

🤡
GIBSON
View GitHub Profile
@gibson-khs
gibson-khs / .gitignore
Last active February 8, 2019 02:49
unity git ignore
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/
# Never ignore Asset meta data
![Aa]ssets/**/*.meta
@gibson-khs
gibson-khs / Api.kt
Last active December 29, 2017 02:30
kotlin_retrofit
class Api {
companion object {
private val BASE_URL = "http://domain/"
private var apiService: ApiInterface? = null
fun getService(): ApiInterface {
if (apiService == null) {
apiService = setApiService()
@gibson-khs
gibson-khs / ZoomView.java
Last active November 28, 2017 08:27
ZoomView
public class ZoomView extends FrameLayout {
public interface ZoomViewListener {
void onZoomStarted(float zoom, float zoomx, float zoomy);
void onZooming(float zoom, float zoomx, float zoomy);
void onZoomEnded(float zoom, float zoomx, float zoomy);
}
@gibson-khs
gibson-khs / DeepScrollView.java
Created June 20, 2017 12:57 — forked from alecplumb/DeepScrollView.java
Scroll an android ScrollView to a non-direct child
public class DeepScrollView extends ScrollView {
public ShrinkWatchScrollView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public ShrinkWatchScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static ActivityOptionsCompat getTransitionOptions(View... views) {
Activity activity = (Activity) views[0].getContext();
Pair<View, String>[] pairs = new Pair[views.length];
for (int i = 0; i < views.length; i++) {
View view = views[i];
pairs[i] = Pair.create(view, view.getTransitionName());
}
return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pairs);
@gibson-khs
gibson-khs / RatioFrameLayout.java
Last active November 28, 2017 08:28
Android/RatioFrameLayout
public class RatioFrameLayout extends FrameLayout {
private int widthRatio;
private int heightRatio;
private boolean widthStandards;
public RatioFrameLayout(Context context) {
super(context);
}
public class RestError {
@SerializedName("toast_message")
public String toast_message;
}
public static void setErrorToast(Context context, Throwable throwable) {
try {
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
// Api.retrofit == Retrofit object
public class KeyboardUtils {
public static void hideKeyboard(Context context) {
try {
((Activity) context).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
if ((((Activity) context).getCurrentFocus() != null) && (((Activity) context).getCurrentFocus().getWindowToken() != null)) {
((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(), 0);
}
} catch (Exception e) {
e.printStackTrace();
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
RestError restError = (RestError) retrofit.responseBodyConverter(
RestError.class, RestError.class.getAnnotations()).convert(exception.response().errorBody());
String errorMessage = restError.message;
if (!TextUtils.isEmpty(errorMessage)) {
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, context.getResources().getString(R.string.default_error), Toast.LENGTH_LONG).show();
}
public abstract class BaseViewHolder<T> extends RecyclerView.ViewHolder {
protected Context context;
protected View parent;
public BaseViewHolder(View itemView, Context context) {
super(itemView);
ButterKnife.bind(this, itemView);
this.context = context;
parent = itemView;