Skip to content

Instantly share code, notes, and snippets.

Artur forceLain

Block or report user

Report or block forceLain

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:e74c9b82caa72e878938776c404f4452
class SerializableObservable<T : Serializable>(private val onChange: (oldValue: T?, newValue: T?) -> Unit) : ReadWriteProperty<Any?, T?>, Serializable {
var value: T? = null
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
return value
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
val old = this.value
@forceLain
forceLain / gist:d4dd90ef7ebdf3c8b72b
Last active Nov 15, 2017
Espresso custom actions
View gist:d4dd90ef7ebdf3c8b72b
import android.view.View;
import com.google.android.apps.common.testing.ui.espresso.PerformException;
import com.google.android.apps.common.testing.ui.espresso.UiController;
import com.google.android.apps.common.testing.ui.espresso.ViewAction;
import com.google.android.apps.common.testing.ui.espresso.util.HumanReadables;
import com.google.android.apps.common.testing.ui.espresso.util.TreeIterables;
import org.hamcrest.Description;
@forceLain
forceLain / gist:2c7930143d5a4e467c70
Last active Aug 29, 2015
simple sensor listener
View gist:2c7930143d5a4e467c70
public class SensorActivity extends Activity, implements SensorEventListener {
private final SensorManager sensorManager;
private final Sensor accelerometer;
public SensorActivity() {
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); //Датчик освещённости
}
protected void onResume() {
@forceLain
forceLain / gist:5300e11e0eed316d3f55
Created Apr 8, 2015
light sensor manager with low pass filter
View gist:5300e11e0eed316d3f55
public class LightSensorManager implements SensorEventListener {
private enum Environment {DAY, NIGHT}
public interface EnvironmentChangedListener {
void onDayDetected();
void onNightDetected();
}
private static final float SMOOTHING = 10;
@forceLain
forceLain / gist:3cedbc0ee45a7d306d88
Created Apr 8, 2015
double threshold light sensor manager
View gist:3cedbc0ee45a7d306d88
public class LightSensorManager implements SensorEventListener {
private enum Environment {DAY, NIGHT}
public interface EnvironmentChangedListener {
void onDayDetected();
void onNightDetected();
}
private static final int THRESHOLD_DAY_LUX = 50;
@forceLain
forceLain / gist:52b8dce0f524884600b1
Created Apr 8, 2015
one threshold light sensor manager
View gist:52b8dce0f524884600b1
public class LightSensorManager implements SensorEventListener {
private enum Environment {DAY, NIGHT}
public interface EnvironmentChangedListener {
void onDayDetected();
void onNightDetected();
}
private static final int THRESHOLD_LUX = 50;
You can’t perform that action at this time.