Skip to content

Instantly share code, notes, and snippets.

@deskid
deskid / EditTextUtil.java
Created December 19, 2015 09:30
显示密码toggle
/**
* 设置密码是否可见
*/
public static void passwordVisibleToggle(EditText editText) {
Log.d("input", "passwordVisibleToggle " + editText.getInputType());
if (editText.getInputType() == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT);
} else {
editText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">
<shape>
<solid android:color="@color/main_white_color" />
<stroke
android:width="1px"
public <T extends View> T $(int id) {
return (T) super.findViewById(id);
}
public <T extends View> T $(View view, int id) {
return (T) view.findViewById(id);
}
long[] mClicks = new long[n];
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.arraycopy(mClicks, 1, mClicks, 0, mClicks.length - 1);
mClicks[mClicks.length - 1] = SystemClock.uptimeMillis();
if(mClicks[0] >= (SystemClock.uptimeMillis() - 500)){
doSomething();
/**
* This demonstrates how to test AsyncTasks in android JUnit. Below I used
* an in line implementation of a asyncTask, but in real life you would want
* to replace that with some task in your application.
* @throws Throwable
*/
public void testSomeAsynTask () throws Throwable {
// create a signal to let us know when our task is done.
final CountDownLatch signal = new CountDownLatch(1);
import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.Semaphore;
/**
public class Test {
public static final Map<String,String> sData = new TreeMap<>();
static {
sData.put("a","A");
}
public static final Map<String,String> sData2 = new TreeMap<String,String>(){
{
this.put("a","A");
import android.text.TextWatcher;
/**
* This is a wrapper around {@link TextWatcher} that overrides
* {@link TextWatcher#beforeTextChanged(CharSequence, int, int, int)} and
* {@link TextWatcher#onTextChanged(CharSequence, int, int, int)} with empty bodies.
*/
public abstract class EasyTextWatcher implements TextWatcher {
@Override
@deskid
deskid / callbackMocking.java
Last active August 1, 2016 14:24
mocking of callback function
ArrayList<Entity> list = new ArrayList<Entity>();
someObject.someMethod(p1, p2, new InnerInterface<Entity>() {
@Override
public boolean onEntry(Entity entity)
{
//some logic
legs.add(entry);
return true;
}
});
/**
* Copyright 2016 Harish Sridharan
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software