use of com.nightonke.saver.model.Logo in project CoCoin by Nightonke.
the class AccountBookTagViewActivity 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 com.nightonke.saver.model.Logo in project CoCoin by Nightonke.
the class AccountBookTodayViewActivity 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();
Log.d("CoCoin", user.getLogoObjectId());
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 com.nightonke.saver.model.Logo in project CoCoin by Nightonke.
the class AccountBookSettingActivity method uploadLogoToServer.
// update a logo to server//////////////////////////////////////////////////////////////////////////
private void uploadLogoToServer() {
if (!SettingManager.getInstance().getHasLogo()) {
// the user haven't set the logo
return;
}
final File file = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
final User user = getCurrentUser();
// if login/////////////////////////////////////////////////////////////////////////////////////////
if (user != null) {
if (user.getLogoObjectId() != "") {
// if the logo id is not null, then there must be a logo and a logo file in the server//////////////
// judge whether there is an old logo of the same user//////////////////////////////////////////////
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/////////////////////////////////////////////////////////
// then there must be an old logo file in server////////////////////////////////////////////////////
// then we should delete the old one////////////////////////////////////////////////////////////////
Log.d("Saver", "There is an old logo");
String url = object.get(0).getFile().getUrl();
BmobFile oldLogoFile = new BmobFile();
oldLogoFile.setUrl(url);
oldLogoFile.delete(CoCoinApplication.getAppContext(), new DeleteListener() {
@Override
public void onSuccess() {
Log.d("Saver", "Successfully delete the old logo.");
// after delete, we should upload a new logo file///////////////////////////////////////////////////
final BmobFile newLogoFile = new BmobFile(file);
newLogoFile.uploadblock(CoCoinApplication.getAppContext(), new UploadFileListener() {
@Override
public void onSuccess() {
// after upload the new logo file, we should put the new logo the Logo table////////////////////////
Logo newLogo = new Logo(newLogoFile);
newLogo.update(CoCoinApplication.getAppContext(), user.getLogoObjectId(), new UpdateListener() {
@Override
public void onSuccess() {
Log.d("Saver", "Update logo successfully");
}
@Override
public void onFailure(int arg0, String arg1) {
Log.d("Saver", "Update logo failed " + arg1);
}
});
}
@Override
public void onProgress(Integer arg0) {
}
@Override
public void onFailure(int arg0, String arg1) {
Log.d("Saver", "Upload failed " + arg1);
}
});
}
@Override
public void onFailure(int code, String msg) {
Log.d("Saver", "Fail to delete the old logo. " + msg);
}
});
}
@Override
public void onError(int code, String msg) {
// the picture is lost
Log.d("Saver", "Can't find the old logo in server.");
}
});
} else {
// the user has no logo before//////////////////////////////////////////////////////////////////////
final BmobFile newLogoFile = new BmobFile(file);
newLogoFile.uploadblock(CoCoinApplication.getAppContext(), new UploadFileListener() {
@Override
public void onSuccess() {
String url = newLogoFile.getFileUrl(CoCoinApplication.getAppContext());
Log.d("Saver", "Upload successfully " + url);
final Logo newLogo = new Logo(newLogoFile);
newLogo.save(CoCoinApplication.getAppContext(), new SaveListener() {
@Override
public void onSuccess() {
Log.d("Saver", "Save the new logo successfully.");
SettingManager.getInstance().setLogoObjectId(newLogo.getObjectId());
updateSettingsToServer(UPDATE_LOGO_ID);
}
@Override
public void onFailure(int i, String s) {
Log.d("Saver", "Save the new logo fail.");
}
});
}
@Override
public void onProgress(Integer arg0) {
}
@Override
public void onFailure(int arg0, String arg1) {
Log.d("Saver", "Upload failed " + arg1);
}
});
}
}
}
use of com.nightonke.saver.model.Logo in project CoCoin by Nightonke.
the class AccountBookSettingActivity method loadLogo.
// Load logo from local/////////////////////////////////////////////////////////////////////////////
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) {
logo.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));
logo.setImageBitmap(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
// use the default logo
logo.setImageResource(R.drawable.default_user_logo);
}
}
use of com.nightonke.saver.model.Logo 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);
}
}
Aggregations