DisplayUtil
public class DisplayUtil {
public static int getDispW(Context context){
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
return display.getWidth();
}
public static int getDispH(Context context){
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
return display.getHeight();
}
}
Log
public class _L {
private static final boolean D = true;
private static final boolean V = true;
private static final boolean I = true;
private static final boolean W = true;
private static final boolean E = true;
private static final String DEFAULT_TAG = "_L";
public static void d(String tag, String msg){
d(tag, "#### __Debug__ " + msg, null);
}
public static void d(String tag, String msg, Throwable tr){
if(D){
if(tr == null){
Log.d(tag, msg);
}else{
Log.d(tag, msg, tr);
}
}
}
public static void v( String msg){
v(DEFAULT_TAG, msg, null);
}
public static void v(String tag, String msg){
v(tag, msg, null);
}
public static void v(String tag, String msg, Throwable tr){
if(V){
if(tr == null){
Log.v(tag, msg);
}else{
Log.v(tag, msg, tr);
}
}
}
public static void i(String tag, String msg){
i(tag, msg, null);
}
public static void i(String tag, String msg, Throwable tr){
if(I){
if(tr == null){
Log.i(tag, msg);
}else{
Log.i(tag, msg, tr);
}
}
}
public static void w(String tag, String msg){
w(tag, msg, null);
}
public static void w(String tag, String msg, Throwable tr){
if(W){
if(tr == null){
Log.w(tag, msg);
}else{
Log.w(tag, msg, tr);
}
}
}
public static void e(String tag, String msg){
e(tag, msg, null);
}
public static void e(String tag, String msg, Throwable tr){
if(E){
if(tr == null){
Log.e(tag, msg);
}else{
Log.e(tag, msg, tr);
}
}
}
}
BitmapUtil
public class BitmapUtil {
public static Bitmap resizeBitmap(Bitmap bitmap, float resizeWidth, float resizeHeight){
float resizeScaleWidth;
float resizeScaleHeight;
Matrix matrix = new Matrix();
resizeScaleWidth = resizeWidth / bitmap.getWidth();
resizeScaleHeight = resizeHeight / bitmap.getHeight();
matrix.postScale(resizeScaleWidth, resizeScaleHeight);
Bitmap resizeBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return resizeBitmap;
}
public static Bitmap getBitmap(Context context, Uri imageUri) throws IOException {
BitmapFactory.Options mOptions = new BitmapFactory.Options();
mOptions.inSampleSize = 10;
Bitmap resizeBitmap = null;
InputStream is = context.getContentResolver().openInputStream(imageUri);
resizeBitmap = BitmapFactory.decodeStream(is, null, mOptions);
is.close();
return resizeBitmap;
}
}
DialogUtil
public class AlertDialogUtil {
public static void showAlert(Context context, String title, String message){
new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setPositiveButton(context.getResources().getString(R.string.ok), null)
.show();
}
public static void showAlert(Context context, String title, String message, String buttonLabel){
new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setPositiveButton(buttonLabel, null)
.show();
}
public static void showAlert(Context context, String title, String message, OnClickListener listener){
new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setPositiveButton(context.getResources().getString(R.string.ok), listener)
.show();
}
public static void showAlertHasCancel(Context context, String title, String message, OnClickListener listener){
new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setPositiveButton(context.getResources().getString(R.string.ok), listener)
.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
BitmapDrawableRect
public class BitmapDrawableRect {
private BitmapDrawable bitmapDrawabel;
private Rect rect;
public BitmapDrawableRect(BitmapDrawable bitmapDrawabel, Rect rect) {
super();
this.bitmapDrawabel = bitmapDrawabel;
this.rect = rect;
}
public void draw(Canvas canvas) {
this.bitmapDrawabel.setBounds(this.rect);
this.bitmapDrawabel.draw(canvas);
}
public void draw(int x, int y, Canvas canvas) {
this.rect = new Rect( x, y, x + this.bitmapDrawabel.getIntrinsicWidth(), y + this.bitmapDrawabel.getIntrinsicHeight());
this.bitmapDrawabel.setBounds(this.rect);
this.bitmapDrawabel.draw(canvas);
}
public void close(){
bitmapDrawabel.getBitmap().recycle();
bitmapDrawabel = null;
}
}
DateUtil
public class DateUtil {
public static String now() {
return now("/");
}
public static String now(String sep) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy" + sep + "MM" + sep
+ "dd HH:mm:ss");
return sdf.format(date);
}
}