Search in sources :

Example 6 with Logo

use of com.nightonke.saver.model.Logo 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);
    }
}
Also used : User(com.nightonke.saver.model.User) BmobUser(cn.bmob.v3.BmobUser) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 7 with Logo

use of com.nightonke.saver.model.Logo 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.");
        }
    });
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Aggregations

BmobQuery (cn.bmob.v3.BmobQuery)7 BmobUser (cn.bmob.v3.BmobUser)7 Logo (com.nightonke.saver.model.Logo)7 User (com.nightonke.saver.model.User)7 File (java.io.File)7 Bitmap (android.graphics.Bitmap)6 FutureCallback (com.koushikdutta.async.future.FutureCallback)6 FileNotFoundException (java.io.FileNotFoundException)6 FileInputStream (java.io.FileInputStream)5 BmobFile (cn.bmob.v3.datatype.BmobFile)4 IOException (java.io.IOException)3 DeleteListener (cn.bmob.v3.listener.DeleteListener)1 SaveListener (cn.bmob.v3.listener.SaveListener)1 UpdateListener (cn.bmob.v3.listener.UpdateListener)1 UploadFileListener (cn.bmob.v3.listener.UploadFileListener)1 BmobProFile (com.bmob.BmobProFile)1 ParseException (java.text.ParseException)1