src\MyApplication\app\src\main\java\com\example\administrator\myapplication\entity\BgPicEntity.java

This commit is contained in:
zhangnaifu15 2018-05-08 21:18:49 +08:00
parent 8aae4b6343
commit 1c30286513
7 changed files with 688 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package com.example.administrator.myapplication.entity;
import android.graphics.Bitmap;
public class BgPicEntity {
public Bitmap bitmap;
public String path;
}

View File

@ -0,0 +1,32 @@
//package com.htq.baidu.coolnote.entity;
//
//
//import java.io.Serializable;
//
//import cn.bmob.v3.BmobObject;
//
//
//@SuppressWarnings("serial")
//public abstract class Entity extends BmobObject implements Serializable {
//
//
// protected int id;
//
// protected String cacheKey;
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
// public String getCacheKey() {
// return cacheKey;
// }
//
// public void setCacheKey(String cacheKey) {
// this.cacheKey = cacheKey;
// }
//}

View File

@ -0,0 +1,245 @@
package com.example.administrator.myapplication.entity;
import android.content.Context;
import cn.bmob.v3.BmobObject;
import cn.bmob.v3.listener.DeleteListener;
import cn.bmob.v3.listener.SaveListener;
import cn.bmob.v3.listener.UpdateListener;
public class NotebookData extends BmobObject implements /*Serializable,*/
Comparable<NotebookData> {
private int id;
private int iid;
private String userId;//用于服务器端存储需要
private String unixTime;
private String date;
private String content;
private String colorText;
private int color;
public static final String NOTE_USER_ID = "userId";
@Override
public boolean equals(Object o) {
if (super.equals(o)) {
return true;
} else {
if (o instanceof NotebookData) {
NotebookData data = (NotebookData) o;
try {
return (this.id == data.getId())
&& (this.iid == data.getIid())
&& (this.unixTime == data.getUnixTime())
&& (this.date.equals(data.getDate()))
&& (this.content == data.getContent())
&& (this.color == data.getColor());
} catch (NullPointerException e) {
return false;
}
} else {
return false;
}
}
}
public void postNoteToServer(Context context,final com.example.administrator.myapplication.entity.OnResponseListener listener)
{
// for(int i=0;i<data.size();i++) {
save(context, new SaveListener() {
@Override
public void onSuccess() {
if (listener != null) {
com.example.administrator.myapplication.entity.Response response = new Response();
response.setIsSucces(true);
listener.onResponse(response);
}
}
@Override
public void onFailure(int code, String msg) {
if (listener != null) {
com.example.administrator.myapplication.entity.Response response = new Response();
response.setIsSucces(false);
response.setMsg(msg);
listener.onResponse(response);
}
}
});
// }
}
/**
*
* @param context
* @param listener
*/
public void updateNoteInServe(Context context,String objectId,final com.example.administrator.myapplication.entity.OnResponseListener listener)
{
//objectId,
update(context, new UpdateListener() {
@Override
public void onSuccess() {
if (listener != null) {
com.example.administrator.myapplication.entity.Response response = new Response();
response.setIsSucces(true);
listener.onResponse(response);
}
}
@Override
public void onFailure(int code, String msg) {
if (listener != null) {
com.example.administrator.myapplication.entity.Response response = new Response();
response.setIsSucces(false);
response.setMsg(msg);
listener.onResponse(response);
}
}
});
}
public void deleteNoteInServe(Context context,/*int noteId,*/final com.example.administrator.myapplication.entity.OnResponseListener listener)
{
// String objectId=new NoteDatabase().query();
delete(context, new DeleteListener() {
@Override
public void onSuccess() {
if (listener != null) {
com.example.administrator.myapplication.entity.Response response = new Response();
response.setIsSucces(true);
listener.onResponse(response);
}
}
@Override
public void onFailure(int code, String msg) {
if (listener != null) {
com.example.administrator.myapplication.entity.Response response = new Response();
response.setIsSucces(false);
response.setMsg(msg);
listener.onResponse(response);
}
}
});
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getIid() {
return iid;
}
public void setIid(int iid) {
this.iid = iid;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getUnixTime() {
return unixTime;
}
public void setUnixTime(String time) {
this.unixTime = time;
// setServerUpdateTime(time);
}
public String getColorText() {
return colorText;
}
public void setColorText(String color) {
this.colorText = color;
}
public int getColor() {
// 客户端始终以当前手机上的颜色为准
if ("blue".equals(colorText)) {
this.color = 3;
} else if ("red".equals(colorText)) {
this.color = 2;
} else if ("yellow".equals(colorText)) {
this.color = 1;
} else if ("purple".equals(colorText)) {
this.color = 4;
} else if ("green".equals(colorText)) {
this.color = 0;
}
return color;
}
// public String getServerUpdateTime() {
// return serverUpdateTime;
// }
//
// public void setServerUpdateTime(String serverUpdateTime) {
// this.serverUpdateTime = serverUpdateTime;
// }
public void setColor(int color) {
switch (color) {
case 0:
colorText = "green";
break;
case 1:
colorText = "yellow";
break;
case 2:
colorText = "red";
break;
case 3:
colorText = "blue";
break;
case 4:
colorText = "purple";
break;
default:
this.color = color;
break;
}
}
@Override
public int compareTo(NotebookData another) {
return this.iid - another.getIid();
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}

View File

@ -0,0 +1,17 @@
package com.example.administrator.myapplication.entity;
/**
*
* 服务器回复的回调接口
*
*/
public interface OnResponseListener {
/**
* 成功
* @param response 回复的结果
*/
void onResponse(com.example.administrator.myapplication.entity.Response response);
}

View File

@ -0,0 +1,59 @@
package com.example.administrator.myapplication.entity;
import android.graphics.Bitmap;
import java.util.List;
/**
* 服务器响应类
*
*/
public class Response {
private String msg;
private boolean isSucces;
private List<NotebookData> noteItemList;
// private List<DiaryItem> diaryItemList;
private Bitmap bitmap;
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean isSucces() {
return isSucces;
}
public void setIsSucces(boolean isSucces) {
this.isSucces = isSucces;
}
public List<NotebookData> getNoteItemList() {
return noteItemList;
}
public void setNoteItemList(List<NotebookData> noteItemList) {
this.noteItemList = noteItemList;
}
// public List<DiaryItem> getDiaryItemList() {
// return diaryItemList;
// }
//
// public void setDiaryItemList(List<DiaryItem> diaryItemList) {
// this.diaryItemList = diaryItemList;
// }
}

View File

@ -0,0 +1,29 @@
package com.example.administrator.myapplication.entity;
/**
* 配合EvetnBus使用
*/
public class UpdataEvent {
public static final int UPDATE_NOTES = 0;
public static final int UPDATE_DIARIES = 1;
public static final int UPDATE_USER_INFOS = 2;
private int type;
private String content;
public void setType(int type) {
this.type = type;
}
public int getType() {
return type;
}
public void setString(String str)
{
this.content=str;
}
public String getString()
{
return content;
}
}

View File

@ -0,0 +1,298 @@
package com.example.administrator.myapplication.entity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;
import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.app.BaseApplication;
import com.example.administrator.myapplication.utils.AccountUtils;
import com.example.administrator.myapplication.utils.BmobConstants;
import com.example.administrator.myapplication.utils.ImageLoadOptions;
import com.example.administrator.myapplication.utils.SPUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.datatype.BmobFile;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.DeleteListener;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.LogInListener;
import cn.bmob.v3.listener.SaveListener;
import cn.bmob.v3.listener.UpdateListener;
public class User extends BmobUser implements Serializable{
private String nickname;
private String sex;
private String notePwd;
private String headUrl;
public String getUserNickname() {
if (!TextUtils.isEmpty(nickname))
return nickname;
else
return "";
}
public void setUserNickname(String nickname) {
this.nickname = nickname;
}
public String getUserSex() {
if (!TextUtils.isEmpty(sex))
return sex;
else
return "";
}
public void setUserSex(String sex) {
this.sex = sex;
}
public String getUserNotePwd() {
if (!TextUtils.isEmpty(notePwd))
return notePwd;
else
return "";
}
public void setUserNotePwd(String notePwd) {
this.notePwd = notePwd;
}
public String getUserHeadUrl() {
if (!TextUtils.isEmpty(headUrl))
return headUrl;
else
return "";
}
public void setUserHeadUrl(String headUrl) {
this.headUrl = headUrl;
}
public void Login(String account ,String pwd ,final Context context)
{
}
static public void setUserHeadFromCache(Context context, ImageView img){
String mSavePath=context.getCacheDir().getAbsolutePath();
File saveFile = new File(mSavePath, "userHead");
Bitmap bitmap = BitmapFactory.decodeFile(saveFile.getAbsolutePath());
img.setImageBitmap(bitmap);
}
/**
* 更新头像 refreshAvatar
*
* @return void
* @throws
*/
static public void refreshAvatarFromServe(String avatar,ImageView headIcon) {
if (avatar != null && !avatar.equals("")) {
ImageLoader.getInstance().displayImage(avatar,headIcon,
ImageLoadOptions.getOptions());
} else {
headIcon.setImageResource(R.mipmap.mine_avatar);
}
}
static public void refreshAvatarFromLoca(Context context,ImageView headIcon) {
// if (avatar != null && !avatar.equals("")) {
//imageLoader.init();
File saveFile = new File(BmobConstants.MyAvatarDir, "avatarIcon.png");
if(saveFile.exists())//先从本地获取
{
Bitmap bitmap = BitmapFactory.decodeFile(saveFile.getAbsolutePath());
headIcon.setImageBitmap(bitmap);
}else//从网络上获取如果失败显示默认图片
{
initDefaultAvatar(context, headIcon);
}
// Bitmap bitmap = BitmapFactory.decodeFile(saveFile.getAbsolutePath());
// headIcon.setImageBitmap(bitmap);
// ImageLoader.getInstance().displayImage(/*"file://"+*/avatar,headIcon,
// ImageLoadOptions.getOptions());
// } else {
// headIcon.setImageResource(R.drawable.default_head);
// }
}
static public void initDefaultAvatar(Context context,ImageView headIcon)
{
// String defaultPath= BmobConstants.MyAvatarDir+"avatarIcon.png";
if(!setUserHeadFromServer(context, headIcon))
{
headIcon.setImageResource(R.drawable.default_head);
}
// boolean isSetAvatar= (boolean) SPUtils.get(context,"isSetAvatar",false);
// if(!isSetAvatar)
//
// else
// {
// Log.i("head","get user icon form srver");
// setUserHeadFromServer(context, headIcon);
//// ImageLoader.getInstance().displayImage("file://"+defaultPath,headIcon,
//// ImageLoadOptions.getOptions());
// }
}
static public void autoLogin(Context context, final OnResponseListener listener)
{
if(SPUtils.contains(context,"user_name"))
{
String name=(String)SPUtils.get(context,"user_name","");
String pwd=(String)SPUtils.get(context,"pwd","");
BmobUser user = new BmobUser();
user.setUsername(name);
user.setPassword(pwd);
user.login(context, new SaveListener() {
@Override
public void onSuccess() {
if(listener!=null)
{
Response response = new Response();
response.setIsSucces(true);
listener.onResponse(response);
}
// Snackbar.make(loginBtn,"登录成功!",Snackbar.LENGTH_SHORT).show();
}
@Override
public void onFailure(int code, String msg) {
if(listener!=null)
{
Response response = new Response();
response.setIsSucces(false);
response.setMsg(msg);
listener.onResponse(response);
}
}
});
}
}
static public void getUserNotes(Context context, String user_id,final OnResponseListener listener){
// Bmob.initialize(context, Constants.APPLICATION_ID);
final List<NotebookData> list = new ArrayList<NotebookData>();
BmobQuery<NotebookData> query = new BmobQuery<NotebookData>();
query.addWhereEqualTo(NotebookData.NOTE_USER_ID, user_id);
//返回50条数据如果不加上这条语句默认返回10条数据
query.setLimit(50);
//按更新日期降序排列
query.order("-updatedAt");
//执行查询方法
query.findObjects(context, new FindListener<NotebookData>() {
@Override
public void onSuccess(List<NotebookData> object) {
if (listener != null) {
Response response = new Response();
response.setIsSucces(true);
response.setNoteItemList(object);
listener.onResponse(response);
}
}
@Override
public void onError(int code, String msg) {
Response response = new Response();
response.setIsSucces(false);
response.setMsg(msg);
listener.onResponse(response);
}
});
}
/**
* 更新用户表单中的头像列
*
* @param picUrl 图片的url
*/
private void updateUserHead(Context context, String picUrl, final OnResponseListener listener) {
String oldUrl = AccountUtils.getUserHeadUrl(context);
if (!TextUtils.isEmpty(oldUrl) && !oldUrl.equals("")) {
//删除服务器上的旧头像
deleteUserOldHead(context, oldUrl);
}
AccountUtils.saveUserHeadUrl(context, picUrl);
User user = new User();
user.setUserHeadUrl(picUrl);
user.update(context, AccountUtils.getUserId(context), new UpdateListener() {
@Override
public void onSuccess() {
if (listener != null) {
Response response = new Response();
response.setIsSucces(true);
listener.onResponse(response);
}
}
@Override
public void onFailure(int code, String msg) {
if (listener != null) {
Response response = new Response();
response.setIsSucces(false);
response.setMsg(msg);
listener.onResponse(response);
}
}
});
}
/**
* 删除服务器上的旧头像
*
* @param oldUrl 旧头像的url
*/
private void deleteUserOldHead(Context context, String oldUrl) {
BmobFile file = new BmobFile();
file.setUrl(oldUrl);//此url是上传文件成功之后通过bmobFile.getUrl()方法获取的
file.delete(context, new DeleteListener() {
@Override
public void onSuccess() {
}
@Override
public void onFailure(int code, String msg) {
}
});
}
static public boolean setUserHeadFromServer(Context context, ImageView headIcon) {
String photoUrl = AccountUtils.getUserHeadUrl(context).trim();
// Toast.makeText(context,photoUrl,Toast.LENGTH_LONG).show();
if (!TextUtils.isEmpty(photoUrl) && !photoUrl.equals("")) {
ImageLoader.getInstance().displayImage(photoUrl,headIcon,
ImageLoadOptions.getOptions());
return true;
}
return false;//说明用户第一次使用该App或者未修改head
}
// static public String getUserHeadPath()
// {
// String path=null;
// return path;
// }
}