android 快速开发(二)辅助类的使用:加快开发速度

辅助类的使用:加快开发速度

作用

        顾名思义,提高开发速度,也可在不断的开发中优化辅助类,最后还是提升应用质量。

简单的辅助类

        L(Log)

package com.yqy.yqy_abstract.utils;

import android.util.Log;

public class L {

	/**
	 * 是否展示,在不需要的时候设置为false
	 */
	public static boolean isShow = true;
	public static String TAG = "YQY";

	/**
	 * 
	 * @param tag
	 *            设置tag
	 * @param msg
	 */
	public static void e(String tag, String msg) {
		if (isShow)
			Log.e(tag, msg);
	}

	/**
	 * 使用默认tag
	 * 
	 * @param msg
	 */
	public static void e(String msg) {
		if (isShow)
			Log.e(TAG, msg);
	}

	// 同理...

}

        T(Toast)

package com.yqy.yqy_abstract.utils;

import android.content.Context;
import android.widget.Toast;

public class T {

	/**
	 * 是否展示,在不需要的时候设置为false
	 */
	public static boolean isShow = true;

	public static void showShort(Context context, String text) {
		if (isShow)
			Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
	}

	public static void showLong(Context context, String text) {
		if (isShow)
			Toast.makeText(context, text, Toast.LENGTH_LONG).show();
	}

}

        SPUtil(sharedpreferences工具类)
package com.yqy.yqy_abstract.utils;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * sharedpreferences工具类
 * 
 * @author YQY
 * 
 */
public class SPUtil {

	private SharedPreferences sp;
	private static SPUtil instance = null;

	public static SPUtil getInstance() {
		synchronized (SPUtil.class) {
			if (instance == null)
				instance = new SPUtil();
		}
		return instance;
	}

	public void write(String key, String value) {
		Editor editor = sp.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public void write(String key, int value) {
		Editor editor = sp.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public void write(String key, boolean value) {
		Editor editor = sp.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	/**
	 * 删除key
	 * 
	 * @param key
	 */
	public void remove(String key) {
		Editor editor = sp.edit();
		editor.remove(key);
		editor.commit();
	}
	
	public int read(String key, int defaultValue) {
		return sp.getInt(key, defaultValue);
	}

	public boolean read(String key, Boolean defaultValue) {
		return sp.getBoolean(key, defaultValue);
	}
	
	public String read(String key, String defaultValue) {
		return sp.getString(key, defaultValue);
	}
}

        TextUtils(一个方法,判断是否为空,4.0以上才会有isEmpty方法,自己写一个方法比较合适)
package com.yqy.yqy_abstract.utils;

public class TextUtils {
	
	public static boolean isEmpty(String str) {
		if (str == null || str.length() == 0)
			return true;
		return false;
	}

}

        FormatTools(判断一些格式的工具类)
package com.yqy.yqy_abstract.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.util.Log;

/**
 * 判断一些格式的工具类
 * 
 * @author YQY
 * 
 */
public class FormatTools {

	/**
	 * 判断姓名
	 */
	public static boolean isName(String name) {
		String str = "^[\u4e00-\u9fa5]{2,5}$";
		Pattern p = Pattern.compile(str);
		Matcher m = p.matcher(name);
		return m.matches();
	}
	
	/****
	 * 判断客户名称 和全名 
	 * 匹配中文,英文字母和数字及_  , 同时判断长度 2-15
	 * ***/
	public static boolean isNameCus(String name)
	{
		String str = "[\u4e00-\u9fa5_a-zA-Z0-9_]{2,15}" ;
		Pattern p = Pattern.compile(str);
		Matcher m = p.matcher(name);
		return m.matches();
	}
	
	
	/**
	 * 判断网址
	 */
	public static boolean isWebSite(String name) {
		String str = "\\.[a-zA-Z]{3}$";
		Pattern p = Pattern.compile(str);
		Matcher m = p.matcher(name);
		return m.matches();
	}
	
	/**
	 * 判断邮箱
	 * 
	 * @param email
	 * @return
	 */
	public static boolean isEmail(String email) {
		String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		Pattern p = Pattern.compile(str);
		Matcher m = p.matcher(email);

		return m.matches();
	}

	// 判断手机号
	public static boolean IsPhoneNum(String mobiles) {
		if (mobiles.trim().length() == 11) {
			Pattern p = Pattern
					.compile("^((13[0-9])|(15[0-9])|(18[0-9])|(17[0-9]))\\d{8}$");
			Matcher m = p.matcher(mobiles);
			Log.d("IsPhoneNum", m.matches() + "");
			return m.matches();
		}
		return false;

	}

	// 判断座机
	public static boolean IsCallNum(String mobiles) {
		boolean isValid = false;
		CharSequence inputStr = mobiles;
		String expression = "^(0\\d{2,3})(\\d{7,8})(\\d{3,})?$";
		Pattern pattern = Pattern.compile(expression);
		Matcher matcher = pattern.matcher(inputStr);
		if (matcher.matches()) {
			isValid = true;
		}
		return isValid;
	}

	// 判断手机或座机
	public static boolean IsAllCallNum(String mobiles) {
		boolean isValid = false;
		String expression = "(^((13[0-9])|(15[^4,\\D])|(18[0,2,5-9]))\\d{8}$)|"
				+ "(^(0\\d{2,3})(\\d{7,8})(\\d{3,})?$)";
		CharSequence inputStr = mobiles;
		Pattern pattern = Pattern.compile(expression);
		Matcher matcher = pattern.matcher(inputStr);
		if (matcher.matches()) {
			isValid = true;
		}
		return isValid;
	}

	// 判断字符串是数字
	public static boolean isNumeric(String str) {
		for (int i = 0; i < str.length(); i++) {
			// System.out.println(str.charAt(i));
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 判断是否为整数
	 * 
	 * @param str
	 *            传入的字符串
	 * 
	 * @return 是整数返回true,否则返回false
	 */

	public static boolean isInteger(String str) {
		Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
		return pattern.matcher(str).matches();
	}

	/**
	 * 判断是否符合密码规则 6-16为字母数字集合 不包含非法字符
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isPwd(String str) {
		Pattern pattern = Pattern.compile("^[a-z0-9A-Z]+$");
		return pattern.matcher(str).matches();
	}

	/**
	 * 将秒转换成小时分钟
	 * 
	 * @param second
	 * @return
	 */
	public static String changeTotime(int second) {
		int h = 0;
		int d = 0;
		int s = 0;
		int temp = second % 3600;
		if (second > 3600) {
			h = second / 3600;
			if (temp != 0) {
				if (temp > 60) {
					d = temp / 60;
					if (temp % 60 != 0) {
						s = temp % 60;
					}
				} else {
					s = temp;
				}
			}
		} else {
			d = second / 60;
			if (second % 60 != 0) {
				s = second % 60;
			}
		}

		// return h + "小时" + d + "分钟" + s + "秒";
		return h + "小时" + d + "分钟";
	}

	/**
	 * 判断是否包含非法字符 & /
	 * 
	 * @return
	 */
	public static boolean isContent(String content) {
		if (content.contains("&") || content.contains("/")) {
			return true;
		}
		return false;
	}

	/**
	 * 米转换成公里
	 */
	public static String miToGl(int distance) {
		double dis = Math.round(distance / 100d) / 10d;
		return dis + "公里";
	}

	/**
	 * 匹配非表情符号的正则表达式
	 */
	public static boolean notMood(String str_mood) {
		boolean isValid = false;
		CharSequence inputStr = str_mood;
		String expression = "^([a-z]|[A-Z]|[0-9]|[\u2E80-\u9FFF]){3,}|@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?|[wap.]{4}|[www.]{4}|[blog.]{5}|[bbs.]{4}|[.com]{4}|[.cn]{3}|[.net]{4}|[.org]{4}|[http://]{7}|[ftp://]{6}$|(^[A-Za-z\\d\\u4E00-\\u9FA5\\p{P}‘’“”]+$)|(^[0-9a-zA-Z\u4E00-\u9FA5]+)";
		Pattern pattern = Pattern.compile(expression);
		Matcher matcher = pattern.matcher(inputStr);
		if (matcher.matches()) {
			isValid = true;
		}
		return isValid;
	}
}

        ScreenUtils(屏幕 工具类)
package com.yqy.yqy_abstract.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;

/**
 * 屏幕 工具类
 * 
 * @author YQY
 * 
 */
public class ScreenUtils {

	/**
	 * 获得屏幕宽度
	 * 
	 */
	public static int getScreenWidth(Context context) {
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics outMetrics = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(outMetrics);
		int width = outMetrics.widthPixels;
		return width;
	}

	/**
	 * 获得屏幕高度
	 */
	public static int getScreenHeight(Context context) {
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics outMetrics = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(outMetrics);
		int height = outMetrics.heightPixels;
		return height;
	}

	/**
	 * 获得屏幕密度
	 */
	public static float getScreenDensity(Context context) {
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics outMetrics = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(outMetrics);
		float density = outMetrics.density;
		return density;
	}

	/**
	 * 获得状态栏的高度
	 */
	public static int getStatusHeight(Context context) {

		int statusHeight = -1;
		try {
			Class<?> clazz = Class.forName("com.android.internal.R$dimen");
			Object object = clazz.newInstance();
			int height = Integer.parseInt(clazz.getField("status_bar_height")
					.get(object).toString());
			statusHeight = context.getResources().getDimensionPixelSize(height);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return statusHeight;
	}

	/**
	 * 获取当前屏幕截图,包含状态栏
	 */
	public static Bitmap snapShotWithStatusBar(Activity activity) {
		View view = activity.getWindow().getDecorView();
		view.setDrawingCacheEnabled(true);
		view.buildDrawingCache();
		Bitmap bmp = view.getDrawingCache();
		int width = getScreenWidth(activity);
		int height = getScreenHeight(activity);
		Bitmap bp = null;
		bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
		view.destroyDrawingCache();
		return bp;

	}

	/**
	 * 获取当前屏幕截图,不包含状态栏
	 */
	public static Bitmap snapShotWithoutStatusBar(Activity activity) {
		View view = activity.getWindow().getDecorView();
		view.setDrawingCacheEnabled(true);
		view.buildDrawingCache();
		Bitmap bmp = view.getDrawingCache();
		Rect frame = new Rect();
		activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
		int statusBarHeight = frame.top;

		int width = getScreenWidth(activity);
		int height = getScreenHeight(activity);
		Bitmap bp = null;
		bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
				- statusBarHeight);
		view.destroyDrawingCache();
		return bp;
	}

}




基于STM32F407,使用DFS算法实现最短迷宫路径检索,分为三种模式:1.DEBUG模式,2. 训练模式,3. 主程序模式 ,DEBUG模式主要分析bug,测量必要数据,训练模式用于DFS算法训练最短路径,并将最短路径以链表形式存储Flash, 主程序模式从Flash中….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Android翻山之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值