src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\BmobConstants.java
This commit is contained in:
parent
f0e86d92d3
commit
5b8d278bfb
|
@ -1,110 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.example.administrator.myapplication.entity.User;
|
||||
|
||||
|
||||
/**
|
||||
* 用户信息管理类
|
||||
*/
|
||||
public class AccountUtils {
|
||||
|
||||
private static final String USER_NAME = "user_name";
|
||||
private static final String USER_PWD = "user_pwd";
|
||||
private static final String USER_ID = "user_id";
|
||||
private static final String USER_EMAIL = "user_email";
|
||||
private static final String USER_NICK_NAME = "user_nickname";
|
||||
private static final String USER_NOTE_PWD = "user_note_pwd";
|
||||
private static final String USER_SEX = "user_sex";
|
||||
private static final String USER_HEAD_URL = "user_head_url";
|
||||
|
||||
/**
|
||||
* 保存用户的所有信息
|
||||
* @param context
|
||||
* @param user
|
||||
* @param user_pwd 用户的登录密码
|
||||
*/
|
||||
public static void saveUserInfos(Context context, User user, String user_pwd) {
|
||||
saveUserName(context, user.getUsername());
|
||||
saveUserPwd(context, user_pwd);
|
||||
saveUserId(context, user.getObjectId());
|
||||
saveUserNickName(context, user.getUserNickname());
|
||||
saveUserEmail(context, user.getEmail());
|
||||
saveUserDiaryPwd(context, user.getUserNotePwd());
|
||||
saveUserSex(context, user.getUserSex());
|
||||
saveUserHeadUrl(context, user.getUserHeadUrl());
|
||||
}
|
||||
|
||||
|
||||
public static String getUserName(Context context) {
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_NAME, "");
|
||||
}
|
||||
|
||||
public static void saveUserName(Context context, String str) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_NAME, str);
|
||||
}
|
||||
|
||||
public static String getUserPwd(Context context) {
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_PWD, "");
|
||||
}
|
||||
|
||||
public static void saveUserPwd(Context context, String str) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_PWD, str);
|
||||
}
|
||||
|
||||
public static String getUserId(Context context) {
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_ID, "");
|
||||
}
|
||||
|
||||
public static void saveUserId(Context context, String str) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_ID, str);
|
||||
}
|
||||
|
||||
public static String getUserEmail(Context context) {
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_EMAIL, "");
|
||||
}
|
||||
|
||||
public static void saveUserEmail(Context context, String str) {
|
||||
if (!TextUtils.isEmpty(str)) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_EMAIL, str);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUserNickName(Context context) {
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_NICK_NAME, "");
|
||||
}
|
||||
|
||||
public static void saveUserNickName(Context context, String str) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_NICK_NAME, str);
|
||||
}
|
||||
|
||||
public static String getUserDiaryPwd(Context context) {
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_NOTE_PWD, "");
|
||||
}
|
||||
|
||||
public static void saveUserDiaryPwd(Context context, String str) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_NOTE_PWD, str);
|
||||
}
|
||||
|
||||
public static String getUserSex(Context context) {
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_SEX, "");
|
||||
}
|
||||
|
||||
public static void saveUserSex(Context context, String str) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_SEX, str);
|
||||
}
|
||||
|
||||
public static String getUserHeadUrl(Context context){
|
||||
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_HEAD_URL, "");
|
||||
}
|
||||
|
||||
|
||||
public static void saveUserHeadUrl(Context context, String str) {
|
||||
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_HEAD_URL, str);
|
||||
}
|
||||
public static void clearAllInfos(Context context){
|
||||
com.example.administrator.myapplication.utils.SPUtils.clear(context);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Environment;
|
||||
|
||||
|
||||
@SuppressLint("SdCardPath")
|
||||
public class BmobConstants {
|
||||
|
||||
/**
|
||||
* <EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD>Ŀ¼
|
||||
*/
|
||||
public static String BMOB_PICTURE_PATH = Environment.getExternalStorageDirectory() + "/bmobimdemo/image/";
|
||||
|
||||
/**
|
||||
* <EFBFBD>ҵ<EFBFBD>ͷ<EFBFBD><EFBFBD>Ŀ¼
|
||||
*/
|
||||
public static String MyAvatarDir = "/sdcard/soucang/avatar/";
|
||||
/**
|
||||
* <EFBFBD><EFBFBD><EFBFBD>ջص<EFBFBD>
|
||||
*/
|
||||
public static final int REQUESTCODE_UPLOADAVATAR_CAMERA = 1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>
|
||||
public static final int REQUESTCODE_UPLOADAVATAR_LOCATION = 2;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>
|
||||
public static final int REQUESTCODE_UPLOADAVATAR_CROP = 3;//ϵͳ<EFBFBD>ü<EFBFBD>ͷ<EFBFBD><EFBFBD>
|
||||
|
||||
public static final int REQUESTCODE_TAKE_CAMERA = 0x000001;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public static final int REQUESTCODE_TAKE_LOCAL = 0x000002;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ
|
||||
public static final int REQUESTCODE_TAKE_LOCATION = 0x000003;//λ<EFBFBD><EFBFBD>
|
||||
public static final String EXTRA_STRING = "extra_string";
|
||||
|
||||
|
||||
public static final String ACTION_REGISTER_SUCCESS_FINISH ="register.success.finish";//ע<EFBFBD><EFBFBD>ɹ<EFBFBD>֮<EFBFBD><EFBFBD><EFBFBD>½ҳ<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
public class CommonUtils {
|
||||
|
||||
/** <20><><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
public static boolean isNetworkAvailable(Context context) {
|
||||
NetworkInfo info = getNetworkInfo(context);
|
||||
if (info != null) {
|
||||
return info.isAvailable();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** <20><><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>WIFI */
|
||||
public static boolean isWifi(Context context) {
|
||||
NetworkInfo info = getNetworkInfo(context);
|
||||
if (info != null) {
|
||||
if (info.getType() == ConnectivityManager.TYPE_WIFI)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** <20><><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD> */
|
||||
public static boolean isMobile(Context context) {
|
||||
NetworkInfo info = getNetworkInfo(context);
|
||||
if (info != null) {
|
||||
if (info.getType() == ConnectivityManager.TYPE_MOBILE)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static NetworkInfo getNetworkInfo(Context context) {
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm.getActiveNetworkInfo();
|
||||
}
|
||||
|
||||
/** <20><><EFBFBD>SD<53><44><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD> */
|
||||
public static boolean checkSdCard() {
|
||||
if (android.os.Environment.getExternalStorageState().equals(
|
||||
android.os.Environment.MEDIA_MOUNTED))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/8/10.
|
||||
*/
|
||||
public class Constants {
|
||||
public final static String BUNDLE_KEY_PAGE = "BUNDLE_KEY_PAGE";
|
||||
public final static String BUNDLE_KEY_ARGS = "BUNDLE_KEY_ARGS";
|
||||
public static final String ALART_CONTENT="alart_content";
|
||||
public static final String TEXT_SIZE="text_size";
|
||||
public static final int TEXT_SMALL = 0;
|
||||
public static final int TEXT_MEDIUM = 1;
|
||||
public static final int TEXT_LARGE = 2;
|
||||
public static final int TEXT_SUPER = 3;
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
||||
public class DialogHelp {
|
||||
|
||||
/***
|
||||
* 获取一个dialog
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static AlertDialog.Builder getDialog(Context context) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取一个耗时等待对话框
|
||||
* @param context
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public static ProgressDialog getWaitDialog(Context context, String message) {
|
||||
ProgressDialog waitDialog = new ProgressDialog(context);
|
||||
if (!TextUtils.isEmpty(message)) {
|
||||
waitDialog.setMessage(message);
|
||||
}
|
||||
return waitDialog;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取一个信息对话框,注意需要自己手动调用show方法显示
|
||||
* @param context
|
||||
* @param message
|
||||
* @param onClickListener
|
||||
* @return
|
||||
*/
|
||||
public static AlertDialog.Builder getMessageDialog(Context context, String message, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton("确定", onClickListener);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getMessageDialog(Context context, String message) {
|
||||
return getMessageDialog(context, message, null);
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context, String message, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setMessage(Html.fromHtml(message));
|
||||
builder.setPositiveButton("确定", onClickListener);
|
||||
builder.setNegativeButton("取消", null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context, String message, DialogInterface.OnClickListener onOkClickListener, DialogInterface.OnClickListener onCancleClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton("确定", onOkClickListener);
|
||||
builder.setNegativeButton("取消", onCancleClickListener);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context,
|
||||
String message,
|
||||
String okString,
|
||||
String cancleString,
|
||||
DialogInterface.OnClickListener onOkClickListener,
|
||||
DialogInterface.OnClickListener onCancleClickListener) {
|
||||
return getConfirmDialog(context, "", message, okString, cancleString, onOkClickListener, onCancleClickListener);
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context,
|
||||
String title,
|
||||
String message,
|
||||
String okString,
|
||||
String cancleString,
|
||||
DialogInterface.OnClickListener onOkClickListener,
|
||||
DialogInterface.OnClickListener onCancleClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton(okString, onOkClickListener);
|
||||
builder.setNegativeButton(cancleString, onCancleClickListener);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSelectDialog(Context context, String title, String[] arrays, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setItems(arrays, onClickListener);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
builder.setPositiveButton("取消", null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSelectDialog(Context context, String[] arrays, DialogInterface.OnClickListener onClickListener) {
|
||||
return getSelectDialog(context, "", arrays, onClickListener);
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSingleChoiceDialog(Context context, String title, String[] arrays, int selectIndex, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setSingleChoiceItems(arrays, selectIndex, onClickListener);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
builder.setNegativeButton("取消", null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSingleChoiceDialog(Context context, String[] arrays, int selectIndex, DialogInterface.OnClickListener onClickListener) {
|
||||
return getSingleChoiceDialog(context, "", arrays, selectIndex, onClickListener);
|
||||
}
|
||||
}
|
|
@ -1,189 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.AnticipateInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.view.animation.RotateAnimation;
|
||||
import android.view.animation.ScaleAnimation;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
/**
|
||||
* 录音动画类
|
||||
*/
|
||||
public class HTQAnimations {
|
||||
|
||||
/**
|
||||
* 旋转 Rotate
|
||||
*/
|
||||
public static Animation getRotateAnimation(float fromDegrees,
|
||||
float toDegrees, long durationMillis) {
|
||||
RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
|
||||
0.5f);
|
||||
rotate.setDuration(durationMillis);
|
||||
rotate.setFillAfter(true);
|
||||
return rotate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 透明度 Alpha
|
||||
*/
|
||||
public static Animation getAlphaAnimation(float fromAlpha, float toAlpha,
|
||||
long durationMillis) {
|
||||
AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha);
|
||||
alpha.setDuration(durationMillis);
|
||||
alpha.setFillAfter(true);
|
||||
return alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缩放 Scale
|
||||
*/
|
||||
public static Animation getScaleAnimation(float scaleXY, long durationMillis) {
|
||||
ScaleAnimation scale = new ScaleAnimation(1.0f, scaleXY, 1.0f, scaleXY,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
|
||||
0.5f);
|
||||
scale.setDuration(durationMillis);
|
||||
return scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 位移 Translate
|
||||
*/
|
||||
public static Animation getTranslateAnimation(float fromXDelta,
|
||||
float toXDelta, float fromYDelta, float toYDelta,
|
||||
long durationMillis) {
|
||||
TranslateAnimation translate = new TranslateAnimation(fromXDelta,
|
||||
toXDelta, fromYDelta, toYDelta);
|
||||
translate.setDuration(durationMillis);
|
||||
translate.setFillAfter(true);
|
||||
return translate;
|
||||
}
|
||||
|
||||
public static Animation clickAnimation(float scaleXY, long durationMillis) {
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
set.addAnimation(getScaleAnimation(scaleXY, durationMillis));
|
||||
set.setDuration(durationMillis);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static Animation shakeAnimation(int X) {
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
Animation anim1 = getTranslateAnimation(0, -200, 0, 0, 100);
|
||||
anim1.setStartOffset(100);
|
||||
set.addAnimation(anim1);
|
||||
Animation anim2 = getTranslateAnimation(-200, 400, 0, 0, 200);
|
||||
anim2.setStartOffset(300);
|
||||
set.addAnimation(anim2);
|
||||
Animation anim3 = getTranslateAnimation(400, -200, 0, 0, 200);
|
||||
anim3.setStartOffset(500);
|
||||
set.addAnimation(anim3);
|
||||
Animation anim4 = getTranslateAnimation(-200, 0, 0, 0, 100);
|
||||
anim4.setStartOffset(600);
|
||||
set.addAnimation(anim4);
|
||||
set.setFillAfter(true);
|
||||
set.setDuration(640);
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开的动画
|
||||
*
|
||||
* @param relativeLayout
|
||||
* 子菜单容器
|
||||
* @param background
|
||||
* 子菜单背景
|
||||
* @param menu
|
||||
* 菜单按钮
|
||||
* @param durationMillis
|
||||
* 动画时间
|
||||
*/
|
||||
public static void openAnimation(RelativeLayout relativeLayout,
|
||||
ImageView menu, long durationMillis) {
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
for (int i = 1; i < relativeLayout.getChildCount(); i++) {
|
||||
ImageView imageView = null;
|
||||
if (relativeLayout.getChildAt(i) instanceof ImageView) {
|
||||
imageView = (ImageView) relativeLayout.getChildAt(i);
|
||||
} else {
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
int top = imageView.getTop();
|
||||
int left = imageView.getLeft();
|
||||
if (top == 0) {
|
||||
top = (menu.getHeight() + 50) * i;
|
||||
}
|
||||
if (left == 0) {
|
||||
left = menu.getLeft();
|
||||
}
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
set.addAnimation(getRotateAnimation(-360, 0, durationMillis));
|
||||
set.addAnimation(getAlphaAnimation(0.5f, 1.0f, durationMillis));
|
||||
set.addAnimation(getTranslateAnimation(menu.getLeft() - left, 0,
|
||||
menu.getTop() - top + 30, 0, durationMillis));// 加30是由于图片上部有一些透明高度
|
||||
set.setFillAfter(true);
|
||||
set.setDuration(durationMillis);
|
||||
set.setStartOffset((i * 100)
|
||||
/ (-1 + relativeLayout.getChildCount()));
|
||||
set.setInterpolator(new OvershootInterpolator(1f));
|
||||
imageView.startAnimation(set);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭的动画
|
||||
*
|
||||
* @param relativeLayout
|
||||
* 子菜单容器
|
||||
* @param background
|
||||
* 子菜单背景
|
||||
* @param menu
|
||||
* 菜单按钮
|
||||
* @param durationMillis
|
||||
* 动画时间
|
||||
*/
|
||||
public static void closeAnimation(final RelativeLayout relativeLayout,
|
||||
final ImageView menu, long durationMillis) {
|
||||
for (int i = 1; i < relativeLayout.getChildCount(); i++) {
|
||||
ImageView imageView = null;
|
||||
if (relativeLayout.getChildAt(i) instanceof ImageView) {
|
||||
imageView = (ImageView) relativeLayout.getChildAt(i);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
set.addAnimation(getRotateAnimation(0, -360, durationMillis));
|
||||
set.addAnimation(getAlphaAnimation(1.0f, 0.5f, durationMillis));
|
||||
set.addAnimation(getTranslateAnimation(0, menu.getLeft()
|
||||
- imageView.getLeft(), 0,
|
||||
menu.getTop() - imageView.getTop() + 30, durationMillis));// 加30是由于图片上部有一些透明高度
|
||||
set.setFillAfter(true);
|
||||
set.setDuration(durationMillis);
|
||||
set.setStartOffset(((relativeLayout.getChildCount() - i) * 100)
|
||||
/ (-1 + relativeLayout.getChildCount()));
|
||||
set.setInterpolator(new AnticipateInterpolator(1f));
|
||||
set.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation arg0) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation arg0) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation arg0) {
|
||||
relativeLayout.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
imageView.startAnimation(set);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
|
||||
public class ImageLoadOptions {
|
||||
|
||||
public static DisplayImageOptions getOptions() {
|
||||
DisplayImageOptions options = new DisplayImageOptions.Builder()
|
||||
// // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ͼƬ
|
||||
// .showImageOnLoading(R.drawable.small_image_holder_listpage)
|
||||
// // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬUriΪ<EFBFBD>ջ<EFBFBD><EFBFBD>Ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ͼƬ
|
||||
// .showImageForEmptyUri(R.drawable.small_image_holder_listpage)
|
||||
// // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ͼƬ
|
||||
// .showImageOnFail(R.drawable.small_image_holder_listpage)
|
||||
.cacheInMemory(true)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ͼƬ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>
|
||||
.cacheOnDisc(true)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ͼƬ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>SD<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.considerExifParams(true)
|
||||
.imageScaleType(ImageScaleType.EXACTLY)// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>εı<EFBFBD><EFBFBD>뷽ʽ<EFBFBD><EFBFBD>ʾ
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// .decodingOptions(android.graphics.BitmapFactory.Options
|
||||
// decodingOptions)//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.considerExifParams(true)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>
|
||||
// .delayBeforeLoading(int delayInMillis)//int
|
||||
// delayInMillisΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ӳ<EFBFBD>ʱ<EFBFBD><EFBFBD>
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>bitmap<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <EFBFBD><EFBFBD>preProcessor(BitmapProcessor preProcessor)
|
||||
.resetViewBeforeLoading(true)// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD>λ
|
||||
// .displayer(new RoundedBitmapDisplayer(20))//<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪԲ<EFBFBD>ǣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.displayer(new FadeInBitmapDisplayer(100))// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.build();
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
|
||||
public class MD5Util {
|
||||
public static String MD5(String str) {
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
|
||||
char[] charArray = str.toCharArray();
|
||||
byte[] byteArray = new byte[charArray.length];
|
||||
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
byteArray[i] = (byte) charArray[i];
|
||||
}
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
|
||||
StringBuffer hexValue = new StringBuffer();
|
||||
for (int i = 0; i < md5Bytes.length; i++) {
|
||||
int val = ((int) md5Bytes[i]) & 0xff;
|
||||
if (val < 16) {
|
||||
hexValue.append("0");
|
||||
}
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
}
|
||||
|
||||
// 可逆的加密算法
|
||||
public static String encryptmd5(String str) {
|
||||
char[] a = str.toCharArray();
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
a[i] = (char) (a[i] ^ 'l');
|
||||
}
|
||||
String s = new String(a);
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,255 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.media.ExifInterface;
|
||||
import android.media.ThumbnailUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PhotoUtil {
|
||||
|
||||
|
||||
public static void recycle(Bitmap bitmap) {
|
||||
if (bitmap != null && !bitmap.isRecycled()) {
|
||||
bitmap.recycle();
|
||||
bitmap = null;
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
public static Bitmap getImageThumbnail(String imagePath, int width,
|
||||
int height) {
|
||||
Bitmap bitmap = null;
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
|
||||
bitmap = BitmapFactory.decodeFile(imagePath, options);
|
||||
options.inJustDecodeBounds = false;
|
||||
int h = options.outHeight;
|
||||
int w = options.outWidth;
|
||||
int beWidth = w / width;
|
||||
int beHeight = h / height;
|
||||
int be = 1;
|
||||
if (beWidth < beHeight) {
|
||||
be = beWidth;
|
||||
} else {
|
||||
be = beHeight;
|
||||
}
|
||||
if (be <= 0) {
|
||||
be = 1;
|
||||
}
|
||||
options.inSampleSize = be;
|
||||
bitmap = BitmapFactory.decodeFile(imagePath, options);
|
||||
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
|
||||
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* saveBitmap
|
||||
*
|
||||
* @param @param filename
|
||||
* @param @param bitmap
|
||||
* @param @param isDelete
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
public static void saveBitmap(String dirpath, String filename,
|
||||
Bitmap bitmap, boolean isDelete) {
|
||||
File dir = new File(dirpath);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
File file = new File(dirpath, filename);
|
||||
if (isDelete) {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
out = new FileOutputStream(file);
|
||||
if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)) {
|
||||
out.flush();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static File getFilePath(String filePath, String fileName) {
|
||||
File file = null;
|
||||
makeRootDirectory(filePath);
|
||||
try {
|
||||
file = new File(filePath + fileName);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void makeRootDirectory(String filePath) {
|
||||
File file = null;
|
||||
try {
|
||||
file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int readPictureDegree(String path) {
|
||||
int degree = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
degree = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
degree = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
degree = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return degree;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Bitmap rotaingImageView(int angle, Bitmap bitmap) {
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(angle);
|
||||
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
|
||||
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||
return resizedBitmap;
|
||||
}
|
||||
|
||||
|
||||
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
|
||||
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
|
||||
bitmap.getHeight(), Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
|
||||
final int color = 0xff424242;
|
||||
final Paint paint = new Paint();
|
||||
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
final RectF rectF = new RectF(rect);
|
||||
final float roundPx = pixels;
|
||||
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
paint.setColor(color);
|
||||
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
|
||||
|
||||
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmap, rect, rect, paint);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
public static Bitmap toRoundBitmap(Bitmap bitmap) {
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
float roundPx;
|
||||
float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
|
||||
if (width <= height) {
|
||||
roundPx = width / 2;
|
||||
|
||||
left = 0;
|
||||
top = 0;
|
||||
right = width;
|
||||
bottom = width;
|
||||
|
||||
height = width;
|
||||
|
||||
dst_left = 0;
|
||||
dst_top = 0;
|
||||
dst_right = width;
|
||||
dst_bottom = width;
|
||||
} else {
|
||||
roundPx = height / 2;
|
||||
|
||||
float clip = (width - height) / 2;
|
||||
|
||||
left = clip;
|
||||
right = width - clip;
|
||||
top = 0;
|
||||
bottom = height;
|
||||
width = height;
|
||||
|
||||
dst_left = 0;
|
||||
dst_top = 0;
|
||||
dst_right = height;
|
||||
dst_bottom = height;
|
||||
}
|
||||
|
||||
Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
|
||||
final Paint paint = new Paint();
|
||||
final Rect src = new Rect((int) left, (int) top, (int) right,
|
||||
(int) bottom);
|
||||
final Rect dst = new Rect((int) dst_left, (int) dst_top,
|
||||
(int) dst_right, (int) dst_bottom);
|
||||
final RectF rectF = new RectF(dst);
|
||||
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
|
||||
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
|
||||
|
||||
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmap, src, dst, paint);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import com.example.administrator.myapplication.R;
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/9/15.
|
||||
*/
|
||||
public class ResourceParser {
|
||||
public static final int TEXT_SMALL = 0;
|
||||
public static final int TEXT_MEDIUM = 1;
|
||||
public static final int TEXT_LARGE = 2;
|
||||
public static final int TEXT_SUPER = 3;
|
||||
|
||||
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
|
||||
|
||||
public static class TextAppearanceResources {
|
||||
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
|
||||
R.style.TextAppearanceNormal,
|
||||
R.style.TextAppearanceMedium,
|
||||
R.style.TextAppearanceLarge,
|
||||
R.style.TextAppearanceSuper
|
||||
};
|
||||
|
||||
public static int getTexAppearanceResource(int id) {
|
||||
/**
|
||||
* HACKME: Fix bug of store the resource id in shared preference.
|
||||
* The id may larger than the length of resources, in this case,
|
||||
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
|
||||
*/
|
||||
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
|
||||
return BG_DEFAULT_FONT_SIZE;
|
||||
}
|
||||
return TEXTAPPEARANCE_RESOURCES[id];
|
||||
}
|
||||
|
||||
public static int getResourcesSize() {
|
||||
return TEXTAPPEARANCE_RESOURCES.length;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Wentong WANG on 2016/6/6.
|
||||
*/
|
||||
public class SPUtils {
|
||||
/**
|
||||
* 保存在手机里面的文件名
|
||||
*/
|
||||
public static final String FILE_NAME = "user_data";
|
||||
|
||||
/**
|
||||
* 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
|
||||
*
|
||||
* @param context
|
||||
* @param key
|
||||
* @param object
|
||||
*/
|
||||
public static void put(Context context, String key, Object object)
|
||||
{
|
||||
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
if (object instanceof String)
|
||||
{
|
||||
editor.putString(key, (String) object);
|
||||
} else if (object instanceof Integer)
|
||||
{
|
||||
editor.putInt(key, (Integer) object);
|
||||
} else if (object instanceof Boolean)
|
||||
{
|
||||
editor.putBoolean(key, (Boolean) object);
|
||||
} else if (object instanceof Float)
|
||||
{
|
||||
editor.putFloat(key, (Float) object);
|
||||
} else if (object instanceof Long)
|
||||
{
|
||||
editor.putLong(key, (Long) object);
|
||||
} else
|
||||
{
|
||||
editor.putString(key, object.toString());
|
||||
}
|
||||
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
|
||||
*
|
||||
* @param context
|
||||
* @param key
|
||||
* @param defaultObject
|
||||
* @return
|
||||
*/
|
||||
public static Object get(Context context, String key, Object defaultObject)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
if (defaultObject instanceof String)
|
||||
{
|
||||
return sp.getString(key, (String) defaultObject);
|
||||
} else if (defaultObject instanceof Integer)
|
||||
{
|
||||
return sp.getInt(key, (Integer) defaultObject);
|
||||
} else if (defaultObject instanceof Boolean)
|
||||
{
|
||||
return sp.getBoolean(key, (Boolean) defaultObject);
|
||||
} else if (defaultObject instanceof Float)
|
||||
{
|
||||
return sp.getFloat(key, (Float) defaultObject);
|
||||
} else if (defaultObject instanceof Long)
|
||||
{
|
||||
return sp.getLong(key, (Long) defaultObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除某个key值已经对应的值
|
||||
* @param context
|
||||
* @param key
|
||||
*/
|
||||
public static void remove(Context context, String key)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.remove(key);
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有数据
|
||||
* @param context
|
||||
*/
|
||||
public static void clear(Context context)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询某个key是否已经存在
|
||||
* @param context
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static boolean contains(Context context, String key)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
return sp.contains(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有的键值对
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, ?> getAll(Context context)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
return sp.getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
|
||||
*
|
||||
* @author zhy
|
||||
*
|
||||
*/
|
||||
private static class SharedPreferencesCompat
|
||||
{
|
||||
private static final Method sApplyMethod = findApplyMethod();
|
||||
|
||||
/**
|
||||
* 反射查找apply的方法
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static Method findApplyMethod()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class clz = SharedPreferences.Editor.class;
|
||||
return clz.getMethod("apply");
|
||||
} catch (NoSuchMethodException e)
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果找到则使用apply执行,否则使用commit
|
||||
*
|
||||
* @param editor
|
||||
*/
|
||||
public static void apply(SharedPreferences.Editor editor)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sApplyMethod != null)
|
||||
{
|
||||
sApplyMethod.invoke(editor);
|
||||
return;
|
||||
}
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
} catch (IllegalAccessException e)
|
||||
{
|
||||
} catch (InvocationTargetException e)
|
||||
{
|
||||
}
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,598 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 字符串操作工具包
|
||||
*
|
||||
* @author liux (http://my.oschina.net/liux)
|
||||
* @version 1.0
|
||||
* @created 2012-3-21
|
||||
*/
|
||||
public class StringUtils {
|
||||
private final static Pattern emailer = Pattern
|
||||
.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
|
||||
|
||||
private final static Pattern IMG_URL = Pattern
|
||||
.compile(".*?(gif|jpeg|png|jpg|bmp)");
|
||||
|
||||
private final static Pattern URL = Pattern
|
||||
.compile("^(https|http)://.*?$(net|com|.com.cn|org|me|)");
|
||||
|
||||
private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
};
|
||||
|
||||
private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
};
|
||||
|
||||
private final static ThreadLocal<SimpleDateFormat> dateFormat3 = new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 将字符串转位日期类型
|
||||
*
|
||||
* @param sdate
|
||||
* @return
|
||||
*/
|
||||
public static Date toDate(String sdate) {
|
||||
return toDate(sdate, dateFormater.get());
|
||||
}
|
||||
|
||||
public static Date toDate(String sdate, SimpleDateFormat dateFormater) {
|
||||
try {
|
||||
return dateFormater.parse(sdate);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDateString(Date date) {
|
||||
return dateFormater.get().format(date);
|
||||
}
|
||||
|
||||
public static String getDateString(String sdate) {
|
||||
return dateFormat3.get().format(toDate(sdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 以友好的方式显示时间
|
||||
*
|
||||
* @param sdate
|
||||
* @return
|
||||
*/
|
||||
public static String friendly_time(String sdate) {
|
||||
Date time = null;
|
||||
|
||||
if (TimeZoneUtil.isInEasternEightZones())
|
||||
time = toDate(sdate);
|
||||
else
|
||||
time = TimeZoneUtil.transformTime(toDate(sdate),
|
||||
TimeZone.getTimeZone("GMT+08"), TimeZone.getDefault());
|
||||
|
||||
if (time == null) {
|
||||
return "Unknown";
|
||||
}
|
||||
String ftime = "";
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
// 判断是否是同一天
|
||||
String curDate = dateFormater2.get().format(cal.getTime());
|
||||
String paramDate = dateFormater2.get().format(time);
|
||||
if (curDate.equals(paramDate)) {
|
||||
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
|
||||
if (hour == 0)
|
||||
ftime = Math.max(
|
||||
(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
|
||||
+ "分钟前";
|
||||
else
|
||||
ftime = hour + "小时前";
|
||||
return ftime;
|
||||
}
|
||||
|
||||
long lt = time.getTime() / 86400000;
|
||||
long ct = cal.getTimeInMillis() / 86400000;
|
||||
int days = (int) (ct - lt);
|
||||
if (days == 0) {
|
||||
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
|
||||
if (hour == 0)
|
||||
ftime = Math.max(
|
||||
(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
|
||||
+ "分钟前";
|
||||
else
|
||||
ftime = hour + "小时前";
|
||||
} else if (days == 1) {
|
||||
ftime = "昨天";
|
||||
} else if (days == 2) {
|
||||
ftime = "前天 ";
|
||||
} else if (days > 2 && days < 31) {
|
||||
ftime = days + "天前";
|
||||
} else if (days >= 31 && days <= 2 * 31) {
|
||||
ftime = "一个月前";
|
||||
} else if (days > 2 * 31 && days <= 3 * 31) {
|
||||
ftime = "2个月前";
|
||||
} else if (days > 3 * 31 && days <= 4 * 31) {
|
||||
ftime = "3个月前";
|
||||
} else {
|
||||
ftime = dateFormater2.get().format(time);
|
||||
}
|
||||
return ftime;
|
||||
}
|
||||
|
||||
public static String friendly_time2(String sdate) {
|
||||
String res = "";
|
||||
if (isEmpty(sdate))
|
||||
return "";
|
||||
|
||||
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
String currentData = StringUtils.getDataTime("MM-dd");
|
||||
int currentDay = toInt(currentData.substring(3));
|
||||
int currentMoth = toInt(currentData.substring(0, 2));
|
||||
|
||||
int sMoth = toInt(sdate.substring(5, 7));
|
||||
int sDay = toInt(sdate.substring(8, 10));
|
||||
int sYear = toInt(sdate.substring(0, 4));
|
||||
Date dt = new Date(sYear, sMoth - 1, sDay - 1);
|
||||
|
||||
if (sDay == currentDay && sMoth == currentMoth) {
|
||||
res = "今天 / " + weekDays[getWeekOfDate(new Date())];
|
||||
} else if (sDay == currentDay + 1 && sMoth == currentMoth) {
|
||||
res = "昨天 / " + weekDays[(getWeekOfDate(new Date()) + 6) % 7];
|
||||
} else {
|
||||
if (sMoth < 10) {
|
||||
res = "0";
|
||||
}
|
||||
res += sMoth + "/";
|
||||
if (sDay < 10) {
|
||||
res += "0";
|
||||
}
|
||||
res += sDay + " / " + weekDays[getWeekOfDate(dt)];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 智能格式化
|
||||
*/
|
||||
public static String friendly_time3(String sdate) {
|
||||
String res = "";
|
||||
if (isEmpty(sdate))
|
||||
return "";
|
||||
|
||||
Date date = StringUtils.toDate(sdate);
|
||||
if (date == null)
|
||||
return sdate;
|
||||
|
||||
SimpleDateFormat format = dateFormater2.get();
|
||||
|
||||
if (isToday(date.getTime())) {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "上午 hh:mm" : "下午 hh:mm");
|
||||
res = format.format(date);
|
||||
} else if (isYesterday(date.getTime())) {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "昨天 上午 hh:mm" : "昨天 下午 hh:mm");
|
||||
res = format.format(date);
|
||||
} else if (isCurrentYear(date.getTime())) {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "MM-dd 上午 hh:mm" : "MM-dd 下午 hh:mm");
|
||||
res = format.format(date);
|
||||
} else {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "yyyy-MM-dd 上午 hh:mm" : "yyyy-MM-dd 下午 hh:mm");
|
||||
res = format.format(date);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是上午
|
||||
*/
|
||||
public static boolean isMorning(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int hour = time.hour;
|
||||
return (hour >= 0) && (hour < 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是今天
|
||||
*/
|
||||
public static boolean isToday(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int thenYear = time.year;
|
||||
int thenMonth = time.month;
|
||||
int thenMonthDay = time.monthDay;
|
||||
|
||||
time.set(System.currentTimeMillis());
|
||||
return (thenYear == time.year)
|
||||
&& (thenMonth == time.month)
|
||||
&& (thenMonthDay == time.monthDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是昨天
|
||||
*/
|
||||
public static boolean isYesterday(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int thenYear = time.year;
|
||||
int thenMonth = time.month;
|
||||
int thenMonthDay = time.monthDay;
|
||||
|
||||
time.set(System.currentTimeMillis());
|
||||
return (thenYear == time.year)
|
||||
&& (thenMonth == time.month)
|
||||
&& (time.monthDay - thenMonthDay == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是今年
|
||||
*/
|
||||
public static boolean isCurrentYear(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int thenYear = time.year;
|
||||
|
||||
time.set(System.currentTimeMillis());
|
||||
return (thenYear == time.year);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期是星期几<br>
|
||||
*
|
||||
* @param dt
|
||||
* @return 当前日期是星期几
|
||||
*/
|
||||
public static int getWeekOfDate(Date dt) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(dt);
|
||||
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (w < 0)
|
||||
w = 0;
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断给定字符串时间是否为今日
|
||||
*
|
||||
* @param sdate
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isToday(String sdate) {
|
||||
boolean b = false;
|
||||
Date time = toDate(sdate);
|
||||
Date today = new Date();
|
||||
if (time != null) {
|
||||
String nowDate = dateFormater2.get().format(today);
|
||||
String timeDate = dateFormater2.get().format(time);
|
||||
if (nowDate.equals(timeDate)) {
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是相同的一天
|
||||
* @param sDate1 sDate1
|
||||
* @param sDate2 sDate2
|
||||
* @return
|
||||
*/
|
||||
public static boolean isSameDay(String sDate1,String sDate2){
|
||||
if(TextUtils.isEmpty(sDate1) || TextUtils.isEmpty(sDate2)){
|
||||
return false;
|
||||
}
|
||||
boolean b = false;
|
||||
Date date1 = toDate(sDate1);
|
||||
Date date2 = toDate(sDate2);
|
||||
if(date1!= null && date2 != null){
|
||||
String d1 = dateFormater2.get().format(date1);
|
||||
String d2 = dateFormater2.get().format(date2);
|
||||
if (d1.equals(d2)) {
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回long类型的今天的日期
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static long getToday() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String curDate = dateFormater2.get().format(cal.getTime());
|
||||
curDate = curDate.replace("-", "");
|
||||
return Long.parseLong(curDate);
|
||||
}
|
||||
|
||||
public static String getCurTimeStr() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String curDate = dateFormater.get().format(cal.getTime());
|
||||
return curDate;
|
||||
}
|
||||
|
||||
/***
|
||||
* 计算两个时间差,返回的是的秒s
|
||||
*
|
||||
* @param dete1
|
||||
* @param date2
|
||||
* @return
|
||||
* @author 火蚁 2015-2-9 下午4:50:06
|
||||
*/
|
||||
public static long calDateDifferent(String dete1, String date2) {
|
||||
|
||||
long diff = 0;
|
||||
|
||||
Date d1 = null;
|
||||
Date d2 = null;
|
||||
|
||||
try {
|
||||
d1 = dateFormater.get().parse(dete1);
|
||||
d2 = dateFormater.get().parse(date2);
|
||||
|
||||
// 毫秒ms
|
||||
diff = d2.getTime() - d1.getTime();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return diff / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断给定字符串是否空白串。 空白串是指由空格、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true
|
||||
*
|
||||
* @param input
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isEmpty(String input) {
|
||||
if (input == null || "".equals(input))
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是一个合法的电子邮件地址
|
||||
*
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmail(String email) {
|
||||
if (email == null || email.trim().length() == 0)
|
||||
return false;
|
||||
return emailer.matcher(email).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一个url是否为图片url
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isImgUrl(String url) {
|
||||
if (url == null || url.trim().length() == 0)
|
||||
return false;
|
||||
return IMG_URL.matcher(url).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为一个合法的url地址
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isUrl(String str) {
|
||||
if (str == null || str.trim().length() == 0)
|
||||
return false;
|
||||
return URL.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转整数
|
||||
*
|
||||
* @param str
|
||||
* @param defValue
|
||||
* @return
|
||||
*/
|
||||
public static int toInt(String str, int defValue) {
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转整数
|
||||
*
|
||||
* @param obj
|
||||
* @return 转换异常返回 0
|
||||
*/
|
||||
public static int toInt(Object obj) {
|
||||
if (obj == null)
|
||||
return 0;
|
||||
return toInt(obj.toString(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转整数
|
||||
*
|
||||
* @param obj
|
||||
* @return 转换异常返回 0
|
||||
*/
|
||||
public static long toLong(String obj) {
|
||||
try {
|
||||
return Long.parseLong(obj);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转布尔值
|
||||
*
|
||||
* @param b
|
||||
* @return 转换异常返回 false
|
||||
*/
|
||||
public static boolean toBool(String b) {
|
||||
try {
|
||||
return Boolean.parseBoolean(b);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getString(String s) {
|
||||
return s == null ? "" : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个InputStream流转换成字符串
|
||||
*
|
||||
* @param is
|
||||
* @return
|
||||
*/
|
||||
public static String toConvertString(InputStream is) {
|
||||
StringBuffer res = new StringBuffer();
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader read = new BufferedReader(isr);
|
||||
try {
|
||||
String line;
|
||||
line = read.readLine();
|
||||
while (line != null) {
|
||||
res.append(line + "<br>");
|
||||
line = read.readLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (null != isr) {
|
||||
isr.close();
|
||||
isr.close();
|
||||
}
|
||||
if (null != read) {
|
||||
read.close();
|
||||
read = null;
|
||||
}
|
||||
if (null != is) {
|
||||
is.close();
|
||||
is = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
/***
|
||||
* 截取字符串
|
||||
*
|
||||
* @param start 从那里开始,0算起
|
||||
* @param num 截取多少个
|
||||
* @param str 截取的字符串
|
||||
* @return
|
||||
*/
|
||||
public static String getSubString(int start, int num, String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
int leng = str.length();
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
if (start > leng) {
|
||||
start = leng;
|
||||
}
|
||||
if (num < 0) {
|
||||
num = 1;
|
||||
}
|
||||
int end = start + num;
|
||||
if (end > leng) {
|
||||
end = leng;
|
||||
}
|
||||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间为每年第几周
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getWeekOfYear() {
|
||||
return getWeekOfYear(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间为每年第几周
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static int getWeekOfYear(Date date) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
c.setTime(date);
|
||||
int week = c.get(Calendar.WEEK_OF_YEAR) - 1;
|
||||
week = week == 0 ? 52 : week;
|
||||
return week > 0 ? week : 1;
|
||||
}
|
||||
|
||||
public static int[] getCurrentDate() {
|
||||
int[] dateBundle = new int[3];
|
||||
String[] temp = getDataTime("yyyy-MM-dd").split("-");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
dateBundle[i] = Integer.parseInt(temp[i]);
|
||||
} catch (Exception e) {
|
||||
dateBundle[i] = 0;
|
||||
}
|
||||
}
|
||||
return dateBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前系统时间
|
||||
*/
|
||||
public static String getDataTime(String format) {
|
||||
SimpleDateFormat df = new SimpleDateFormat(format);
|
||||
return df.format(new Date());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.example.administrator.myapplication.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
|
||||
public class SystemUtils {
|
||||
|
||||
private Context context;
|
||||
private String PREF_NAME = "creativelocker.pref";
|
||||
public final String KEY_NOTE_DRAFT = "KEY_NOTE_DRAFT";
|
||||
private final String BG_PIC_PATH ="bg_pic_path";
|
||||
|
||||
public SystemUtils(Context context)
|
||||
{
|
||||
this.context=context;
|
||||
}
|
||||
|
||||
public String getNoteDraft() {
|
||||
return getPreferences().getString(
|
||||
KEY_NOTE_DRAFT , "");
|
||||
}
|
||||
|
||||
|
||||
public void setNoteDraft(String draft) {
|
||||
set(KEY_NOTE_DRAFT , draft);
|
||||
}
|
||||
|
||||
public void set(String key, String value) {
|
||||
SharedPreferences.Editor editor = getPreferences().edit();
|
||||
editor.putString(key, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public SharedPreferences getPreferences() {
|
||||
SharedPreferences pre =context.getSharedPreferences(PREF_NAME,
|
||||
Context.MODE_MULTI_PROCESS);
|
||||
return pre;
|
||||
}
|
||||
|
||||
public boolean isFirstUse()
|
||||
{
|
||||
if(getString("isFirstUse")==null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isTarn()
|
||||
{
|
||||
return getBoolean("isTran");
|
||||
}
|
||||
public String getString(String str)
|
||||
{
|
||||
SharedPreferences share= getPreferences();
|
||||
return share.getString(str,null);
|
||||
}
|
||||
public boolean getBoolean(String str)
|
||||
{
|
||||
SharedPreferences share= getPreferences();
|
||||
return share.getBoolean(str,false);
|
||||
}
|
||||
public void setBoolean(String str,boolean bool)
|
||||
{
|
||||
SharedPreferences.Editor editor = getPreferences().edit();
|
||||
editor.putBoolean(str,bool);
|
||||
editor.commit();
|
||||
}
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public SharedPreferences getPreferences(String prefName) {
|
||||
return context.getSharedPreferences(prefName,
|
||||
Context.MODE_MULTI_PROCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕宽度
|
||||
*/
|
||||
public static int getScreenW(Context aty) {
|
||||
DisplayMetrics dm = aty.getResources().getDisplayMetrics();
|
||||
return dm.widthPixels;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕高度
|
||||
*/
|
||||
public static int getScreenH(Context aty) {
|
||||
DisplayMetrics dm = aty.getResources().getDisplayMetrics();
|
||||
return dm.heightPixels;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存背景皮肤图片的地址
|
||||
*/
|
||||
public void saveBgPicPath(String path)
|
||||
{
|
||||
set(BG_PIC_PATH,path);
|
||||
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return getString(BG_PIC_PATH);
|
||||
}
|
||||
|
||||
public Bitmap getBitmapByPath(Activity aty, String path) {
|
||||
AssetManager am = aty.getAssets();
|
||||
Bitmap bitmap = null;
|
||||
InputStream is =null;
|
||||
try {
|
||||
is = am.open("bkgs/" + path);
|
||||
bitmap = BitmapFactory.decodeStream(is);
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author htq_
|
||||
* @param mActivity
|
||||
* bolg:bolg.csdn.net/htq__
|
||||
*/
|
||||
public static void shareApp(Activity mActivity)
|
||||
{
|
||||
String shareAppContent="各位亲爱的小伙伴们,我发现了一款非常好用且颜值爆表的一件收藏App,分享给大家";
|
||||
|
||||
new File(mActivity.getFilesDir(), "share.jpg").deleteOnExit();
|
||||
FileOutputStream fileOutputStream=null;
|
||||
try {
|
||||
fileOutputStream = mActivity.openFileOutput(
|
||||
"share.jpg", MODE_PRIVATE);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bitmap pic=BitmapFactory.decodeResource(mActivity.getResources(),R.mipmap.app_icon);
|
||||
pic.compress(Bitmap.CompressFormat.JPEG, 100,fileOutputStream);
|
||||
|
||||
|
||||
Intent intent = new Intent("android.intent.action.SEND");
|
||||
intent.setType("image/*");
|
||||
intent.putExtra("sms_body", shareAppContent);
|
||||
intent.putExtra("android.intent.extra.TEXT",shareAppContent);
|
||||
intent.putExtra("android.intent.extra.STREAM",
|
||||
Uri.fromFile(new File(mActivity.getFilesDir(), "share.jpg")));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mActivity.startActivity(Intent.createChooser(intent,"好东西要与小伙伴们一起分享"));
|
||||
}
|
||||
|
||||
public static void shareNote(Activity mActivity,String noteContent)
|
||||
{
|
||||
|
||||
// new File(mActivity.getFilesDir(), "share.jpg").deleteOnExit();
|
||||
// FileOutputStream fileOutputStream=null;
|
||||
// try {
|
||||
// fileOutputStream = mActivity.openFileOutput(
|
||||
// "share.jpg", 1);
|
||||
// } catch (FileNotFoundException e) {
|
||||
//
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// Bitmap pic=BitmapFactory.decodeResource(mActivity.getResources(),R.mipmap.app_icon);
|
||||
// pic.compress(Bitmap.CompressFormat.JPEG, 100,fileOutputStream);
|
||||
|
||||
|
||||
Intent intent = new Intent("android.intent.action.SEND");
|
||||
// intent.setType("image/*");
|
||||
intent.setType("text/plain");
|
||||
// intent.putExtra("sms_body", noteContent);
|
||||
intent.putExtra("android.intent.extra.TEXT",noteContent);
|
||||
// intent.putExtra("android.intent.extra.STREAM",
|
||||
// Uri.fromFile(new File(mActivity.getFilesDir(), "share.jpg")));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mActivity.startActivity(Intent.createChooser(intent,"好东西要与小伙伴们一起分享"));
|
||||
}
|
||||
/**
|
||||
* 分享功能
|
||||
* @param msgTitle
|
||||
* 消息标题
|
||||
* @param msgText
|
||||
* 消息内容
|
||||
* @param imgPath
|
||||
* 图片路径,不分享图片则传null
|
||||
*/
|
||||
public static void shareMsg(Activity mActivity, String msgTitle, String msgText,
|
||||
String imgPath) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
if (imgPath == null || imgPath.equals("")) {
|
||||
intent.setType("text/plain"); // 纯文本
|
||||
} else {
|
||||
File f = new File(imgPath);
|
||||
if (f != null && f.exists() && f.isFile()) {
|
||||
intent.setType("image/jpg");
|
||||
Uri u = Uri.fromFile(f);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, u);
|
||||
}
|
||||
}
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, msgText);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mActivity.startActivity(Intent.createChooser(intent,"好东西要与小伙伴们一起分享"));
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author HuangWenwei
|
||||
*
|
||||
* @date 2014年10月9日
|
||||
*/
|
||||
public class TimeZoneUtil {
|
||||
|
||||
/**
|
||||
* 判断用户的设备时区是否为东八区(中国) 2014年7月31日
|
||||
* @return
|
||||
*/
|
||||
public static boolean isInEasternEightZones() {
|
||||
boolean defaultVaule = true;
|
||||
if (TimeZone.getDefault() == TimeZone.getTimeZone("GMT+08"))
|
||||
defaultVaule = true;
|
||||
else
|
||||
defaultVaule = false;
|
||||
return defaultVaule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据不同时区,转换时间 2014年7月31日
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public static Date transformTime(Date date, TimeZone oldZone, TimeZone newZone) {
|
||||
Date finalDate = null;
|
||||
if (date != null) {
|
||||
int timeOffset = oldZone.getOffset(date.getTime())
|
||||
- newZone.getOffset(date.getTime());
|
||||
finalDate = new Date(date.getTime() - timeOffset);
|
||||
}
|
||||
return finalDate;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue