Skip to content

Instantly share code, notes, and snippets.

@nikolaevmaks
nikolaevmaks / SingleSelectableViewAdapter.java
Created July 14, 2015 23:46
SingleSelectableViewAdapter
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
public abstract class SingleSelectableViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnTouchListener {
private int mItemPressedPos = -1;
@Override
public boolean onTouch(View view, MotionEvent event) {
@nikolaevmaks
nikolaevmaks / TouchUtils.java
Last active August 29, 2015 14:24
TouchUtils
import android.support.v4.view.MotionEventCompat;
import android.view.MotionEvent;
public class TouchUtils {
public static int getAction(MotionEvent event) {
return MotionEventCompat.getActionMasked(event);
}
public static int getPointerIndex(MotionEvent event) {
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.RelativeLayout;
import travel.ozon.mobile.view.utils.OnInterceptTouchEventListener;
public class RelativeLayoutEx extends RelativeLayout {
private static final String TAG = "RelativeLayoutEx";
@nikolaevmaks
nikolaevmaks / NothingSelectedSpinnerAdapter.java
Last active August 29, 2015 14:24
NothingSelectedSpinnerAdapter
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
public abstract class NothingSelectedSpinnerAdapter<T> extends BaseAdapter {
private static final int DUMMY_DROPDOWN_VIEW_TYPE_TAG = 1;
private final Spinner mSpinner;
private T mNothingSelectedDataItem;
@nikolaevmaks
nikolaevmaks / CustomGestureDetector.java
Created July 13, 2015 21:38
CustomGestureDetector
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
@nikolaevmaks
nikolaevmaks / gist:4f37ed8f7aa33f128937
Created July 13, 2015 21:12
simple GeoLocationUtils
public class GeoLocationUtils {
private static final double EARTH_RADIUS = 6371000;
private static final double EARTH_CIRCLE_LENGTH = 2 * Math.PI * EARTH_RADIUS;
private static final double DISTANCE_PER_EARTH_CIRCLE_DEGREE = Math.PI * EARTH_RADIUS / 180;
/**
* @see <a href="http://en.wikipedia.org/wiki/Great-circle_distance">Great-circle distance</a>
*/
public static double getDistance(double latitude0, double longitude0, double latitude1, double longitude1) {
@nikolaevmaks
nikolaevmaks / LinearLayoutWeighted.java
Last active August 29, 2015 14:24
LinearLayoutWeighted
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
// only horizontal now
// use with MATCH_PARENT or exact width attribute
public class LinearLayoutWeighted extends ViewGroup {