use of cn.bmob.v3.BmobQuery in project CoCoin by Nightonke.
the class AccountBookListViewActivity method loadLogo.
private void loadLogo() {
User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
if (user != null) {
try {
File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
if (!logoFile.exists()) {
// the local logo file is missed
// try to get from the server
BmobQuery<Logo> bmobQuery = new BmobQuery();
bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {
@Override
public void onSuccess(List<Logo> object) {
// there has been an old logo in the server/////////////////////////////////////////////////////////
String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
if (BuildConfig.DEBUG)
Log.d("CoCoin", "Logo in server: " + url);
Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {
@Override
public void onCompleted(Exception e, File file) {
profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
}
});
}
@Override
public void onError(int code, String msg) {
// the picture is lost
if (BuildConfig.DEBUG)
Log.d("CoCoin", "Can't find the old logo in server.");
}
});
} else {
// the user logo is in the storage
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
profileImage.setImageBitmap(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
// use the default logo
profileImage.setImageResource(R.drawable.default_user_logo);
}
}
use of cn.bmob.v3.BmobQuery in project CoCoin by Nightonke.
the class AccountBookMonthViewActivity method loadLogo.
private void loadLogo() {
User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
if (user != null) {
try {
File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
if (!logoFile.exists()) {
// the local logo file is missed
// try to get from the server
BmobQuery<Logo> bmobQuery = new BmobQuery();
bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {
@Override
public void onSuccess(List<Logo> object) {
// there has been an old logo in the server/////////////////////////////////////////////////////////
String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
if (BuildConfig.DEBUG)
Log.d("CoCoin", "Logo in server: " + url);
Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {
@Override
public void onCompleted(Exception e, File file) {
profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
}
});
}
@Override
public void onError(int code, String msg) {
// the picture is lost
if (BuildConfig.DEBUG)
Log.d("CoCoin", "Can't find the old logo in server.");
}
});
} else {
// the user logo is in the storage
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
profileImage.setImageBitmap(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
// use the default logo
profileImage.setImageResource(R.drawable.default_user_logo);
}
}
use of cn.bmob.v3.BmobQuery in project CoCoin by Nightonke.
the class AccountBookSettingActivity method downloadLogoFromServer.
// download logo to local///////////////////////////////////////////////////////////////////////////
private void downloadLogoFromServer() {
User user = getCurrentUser();
if (user.getLogoObjectId() == null) {
// the user has no logo
return;
}
BmobQuery<Logo> bmobQuery = new BmobQuery();
bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {
@Override
public void onSuccess(List<Logo> object) {
// there has been an old logo in the server/////////////////////////////////////////////////////////
Log.d("Saver", "There is an old logo");
String url = object.get(0).getFile().getUrl();
Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {
@Override
public void onCompleted(Exception e, File file) {
Bitmap bitmap = BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
if (bitmap == null) {
Log.d("Saver", "Logo misses");
} else {
logo.setImageBitmap(bitmap);
}
SettingManager.getInstance().setHasLogo(true);
}
});
SettingManager.getInstance().setTodayViewLogoShouldChange(true);
}
@Override
public void onError(int code, String msg) {
// the picture is lost
Log.d("Saver", "Can't find the old logo in server.");
}
});
}
Aggregations