package com.basic.security.manager;
|
|
import android.graphics.Bitmap;
|
import android.graphics.BitmapFactory;
|
|
import com.basic.security.R;
|
import com.basic.security.activity.MainActivity;
|
import com.basic.security.base.BaseApplication;
|
import com.basic.security.model.ModelAdapter;
|
|
public class AccountManager extends BaseManager {
|
private static ModelAdapter adminAccount;
|
|
public static ModelAdapter getAdminAccount() {
|
return adminAccount;
|
}
|
|
public static void setAdminAccount(ModelAdapter admin) {
|
if (admin != null) {
|
try {
|
BaseApplication.getApplication().activity.lastAdminClickTime = System.currentTimeMillis();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
AccountManager.adminAccount = admin;
|
if (adminAccount != null) {
|
setAdminPhoto();
|
}
|
}
|
|
private static void setAdminPhoto() {
|
try {
|
MainActivity activity = BaseApplication.getApplication().activity;
|
if (activity == null) {
|
return;
|
}
|
String a = adminAccount.getString("person_id");
|
ModelAdapter admin_person = PersonManager.findPersonById(a);
|
if (admin_person == null) {
|
return;
|
}
|
if (!"person".equals(admin_person.getString("table"))) {
|
return;
|
}
|
String name = admin_person.getString("name");
|
Bitmap b = null;
|
byte[] blob = admin_person.getBlob("camera_image_path");
|
byte[] data;
|
if (blob != null) {
|
data = blob;
|
if (data != null) {
|
b = BitmapFactory.decodeByteArray(data, 0, data.length);
|
}
|
}
|
if (b == null) {
|
b = BitmapFactory.decodeResource(activity.getResources(), R.drawable.u1280);
|
}
|
if (b != null) {
|
activity.fragment_toolbar.admin_photo.setImageBitmap(b);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
//保存账号
|
public static ModelAdapter getAccount(String account, String password) {
|
return findOne("select * from user where username='" + account + "'" + " and password='" + password + "'");
|
}
|
|
// 管理员是否已经登录
|
public static boolean adminLoggedIn() {
|
return adminAccount != null;
|
}
|
|
public static String getCurrentAdminPassword() {
|
return adminAccount.getString("password");
|
}
|
|
public static void setAdminId(String person_id) {
|
ModelAdapter admin_user_table = BaseManager.findById("user", DeviceManager.getDeviceId() + "admin_user");
|
setAdminAccount(admin_user_table);
|
}
|
|
public static void saveAccount(ModelAdapter modelAdapter) {
|
save(modelAdapter);
|
}
|
}
|