一:点击事件防抖工具类:
public abstract class ThrottleClickListener implements View.OnClickListener {
private long clickLastTimeKey = 0;
private final long thresholdMillis = 500;//milliseconds
@Override
public void onClick(View v) {
long currentTime = SystemClock.elapsedRealtime();
if (Math.abs(currentTime - clickLastTimeKey) >= thresholdMillis) {
//Log.i("ygn","time-"+(currentTime - clickLastTimeKey));
clickLastTimeKey = currentTime;
onThrottleClick(v);
} else {
LogUtils.w( "click fast");
}
}
public abstract void onThrottleClick(View v);
}
二:判断经纬度是否合法,是否在指定范围内的工具类
public class PoiUtil {
/**只校验正数 0-90.000000 0-180.000000 范围内
* 经纬度校验
* 经度longitude: (?:[0-9]|[1-9][0-9]|1[0-7][0-9]|180)\\.([0-9]{6})
* 纬度latitude: (?:[0-9]|[1-8][0-9]|90)\\.([0-9]{6})
* @return boolean
*/
public static boolean checkLoLa(String longitude,String latitude){
String regLo = "(((?:[0-9]|[1-9][0-9]|1[0-7][0-9])\\.([0-9]{0,6}))|((?:180)\\.([0]{0,6}))|((?:[0-9]|[1-9][0-9]|1[0-7][0-9]))|(?:180))";
String regLa = "(((?:[0-9]|[1-8][0-9]|90)\\.([0-9]{0,6}))|(?:[0-9]|[1-8][0-9]|90))";
longitude = longitude.trim();
latitude = latitude.trim();
return longitude.matches(regLo)==true?latitude.matches(regLa):false;
}
/**只校验正数 0-90.000000 范围内
* 纬度校验
* 纬度latitude: (?:[0-9]|[1-8][0-9]|90)\\.([0-9]{6})
* @return boolean
*/
public static boolean checkLatitude(String latitude){
String regLa ="(((?:[0-9]|[1-8][0-9]|90)\\.([0-9]{0,6}))|(?:[0-9]|[1-8][0-9]|90))";
latitude = latitude.trim();
return latitude.matches(regLa);
}
/**只校验正数 0-180.000000 范围内
* 经度校验
* 经度longitude: (?:[0-9]|[1-9][0-9]|1[0-7][0-9]|180)\\.([0-9]{6})
* @return boolean
*/
public static boolean checkLongitude(String longitude){
String regLo = "(((?:[0-9]|[1-9][0-9]|1[0-7][0-9])\\.([0-9]{0,6}))|((?:180)\\.([0]{0,6}))|((?:[0-9]|[1-9][0-9]|1[0-7][0-9]))|(?:180))";
longitude = longitude.trim();
return longitude.matches(regLo);
}
}