Search in sources :

Example 6 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class ImportAsyncTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    boolean importSuccessful = true;
    try {
        ZipManager zipManager = new ZipManager(mContext);
        zipManager.unzip(backupZieFilePath, new FileManager(mContext, FileManager.BACKUP_DIR).getDirAbsolutePath() + "/");
        loadBackupJsonFileIntoManager();
        importSuccessful = importTopic();
    } catch (Exception e) {
        Log.e(TAG, "import flow fail", e);
        importSuccessful = false;
    } finally {
        backupFileManager.clearDir();
    }
    return importSuccessful;
}
Also used : FileManager(com.kiminonawa.mydiary.shared.FileManager) IOException(java.io.IOException)

Example 7 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class SettingActivity method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.But_setting_theme_default_bg:
            IV_setting_profile_bg.setImageDrawable(new ColorDrawable(tempMainColorCode));
            profileBgFileName = "";
            isAddNewProfileBg = true;
            break;
        case R.id.IV_setting_profile_bg:
            if (PermissionHelper.checkPermission(this, REQUEST_WRITE_ES_PERMISSION)) {
                FileManager.startBrowseImageFile(this, SELECT_PROFILE_BG);
            }
            break;
        case R.id.But_setting_theme_default:
            IV_setting_theme_main_color.setImageDrawable(new ColorDrawable(ColorTools.getColor(this, R.color.themeColor_custom_default)));
            IV_setting_theme_dark_color.setImageDrawable(new ColorDrawable(ColorTools.getColor(this, R.color.theme_dark_color_custom_default)));
            //Also revert the tempMainColor & profile bg
            tempMainColorCode = ColorTools.getColor(this, R.color.themeColor_custom_default);
            if (IV_setting_profile_bg.getDrawable() instanceof ColorDrawable) {
                IV_setting_profile_bg.setImageDrawable(new ColorDrawable(tempMainColorCode));
            }
            break;
        case R.id.But_setting_theme_apply:
            //Save custom theme value
            if (themeManager.getCurrentTheme() == ThemeManager.CUSTOM) {
                //Check is add new profile
                if (isAddNewProfileBg) {
                    //For checking new profile bg is image or color.
                    boolean hasCustomProfileBannerBg = false;
                    if (!"".equals(profileBgFileName)) {
                        try {
                            //Copy the profile into setting dir
                            FileManager.copy(new File(tempFileManager.getDir().getAbsoluteFile() + "/" + profileBgFileName), new File(new FileManager(this, FileManager.SETTING_DIR).getDir().getAbsoluteFile() + "/" + ThemeManager.CUSTOM_PROFILE_BANNER_BG_FILENAME));
                            hasCustomProfileBannerBg = true;
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(this, getString(R.string.toast_save_profile_banner_fail), Toast.LENGTH_SHORT).show();
                            break;
                        }
                    } else {
                        new File(new FileManager(this, FileManager.SETTING_DIR).getDir().getAbsoluteFile() + "/" + ThemeManager.CUSTOM_PROFILE_BANNER_BG_FILENAME).delete();
                    }
                    SPFManager.setCustomProfileBannerBg(this, hasCustomProfileBannerBg);
                }
                //Save new color
                SPFManager.setMainColor(this, ((ColorDrawable) IV_setting_theme_main_color.getDrawable()).getColor());
                SPFManager.setSecondaryColor(this, ((ColorDrawable) IV_setting_theme_dark_color.getDrawable()).getColor());
            }
            //Save new theme style
            themeManager.saveTheme(SettingActivity.this, SP_setting_theme.getSelectedItemPosition());
            //Send Toast
            Toast.makeText(this, getString(R.string.toast_change_theme), Toast.LENGTH_SHORT).show();
            applySetting(false);
            break;
        case R.id.IV_setting_theme_main_color:
            SettingColorPickerFragment mainColorPickerFragment = SettingColorPickerFragment.newInstance(themeManager.getThemeMainColor(this), R.id.IV_setting_theme_main_color);
            mainColorPickerFragment.show(getSupportFragmentManager(), "mainColorPickerFragment");
            break;
        case R.id.IV_setting_theme_dark_color:
            SettingColorPickerFragment secColorPickerFragment = SettingColorPickerFragment.newInstance(themeManager.getThemeDarkColor(this), R.id.IV_setting_theme_dark_color);
            secColorPickerFragment.show(getSupportFragmentManager(), "secColorPickerFragment");
            break;
        case R.id.But_setting_fix_photo_17_dir:
            //The new diary dir was updated in version 17
            //But , some device have a problem , so I add this setting.
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        if (OldVersionHelper.Version17MoveTheDiaryIntoNewDir(SettingActivity.this)) {
                            SettingActivity.this.runOnUiThread(new Runnable() {

                                public void run() {
                                    Toast.makeText(SettingActivity.this, getString(R.string.toast_setting_successful), Toast.LENGTH_LONG).show();
                                }
                            });
                        } else {
                            SettingActivity.this.runOnUiThread(new Runnable() {

                                public void run() {
                                    Toast.makeText(SettingActivity.this, getString(R.string.toast_setting_wont_fix), Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        SettingActivity.this.runOnUiThread(new Runnable() {

                            public void run() {
                                Toast.makeText(SettingActivity.this, getString(R.string.toast_setting_fail), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                }
            }).run();
            break;
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) IOException(java.io.IOException) File(java.io.File) FileManager(com.kiminonawa.mydiary.shared.FileManager) IOException(java.io.IOException)

Example 8 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class TopicDetailDialogFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SELECT_TOPIC_BG) {
        if (resultCode == RESULT_OK) {
            if (data != null && data.getData() != null) {
                int topicBgWidth = ThemeManager.getInstance().getTopicBgWidth(getActivity());
                int topicBgHeight;
                if (topicType == ITopic.TYPE_DIARY) {
                    topicBgHeight = ThemeManager.getInstance().getTopicBgHeight(getActivity());
                } else {
                    topicBgHeight = ThemeManager.getInstance().getTopicBgWithoutEditBarHeight(getActivity());
                }
                FileManager tempFileManager = new FileManager(getContext(), FileManager.TEMP_DIR);
                //Clear the old photo file
                tempFileManager.clearDir();
                UCrop.Options options = new UCrop.Options();
                options.setToolbarColor(ThemeManager.getInstance().getThemeMainColor(getActivity()));
                options.setStatusBarColor(ThemeManager.getInstance().getThemeDarkColor(getActivity()));
                UCrop.of(data.getData(), Uri.fromFile(new File(tempFileManager.getDir() + "/" + FileManager.createRandomFileName()))).withMaxResultSize(topicBgWidth, topicBgHeight).withAspectRatio(topicBgWidth, topicBgHeight).withOptions(options).start(getActivity(), this);
            } else {
                Toast.makeText(getActivity(), getString(R.string.toast_photo_intent_error), Toast.LENGTH_LONG).show();
            }
        }
    } else if (requestCode == UCrop.REQUEST_CROP) {
        if (resultCode == RESULT_OK) {
            if (data != null) {
                final Uri resultUri = UCrop.getOutput(data);
                IV_topic_detail_topic_bg.setImageBitmap(BitmapFactory.decodeFile(resultUri.getPath()));
                newTopicBgFileName = FileManager.getFileNameByUri(getActivity(), resultUri);
                But_topic_detail_default_bg.setEnabled(true);
                topicBgStatus = TOPIC_BG_ADD_PHOTO;
            } else {
                Toast.makeText(getActivity(), getString(R.string.toast_crop_profile_banner_fail), Toast.LENGTH_LONG).show();
            //sample error
            // final Throwable cropError = UCrop.getError(data);
            }
        }
    }
}
Also used : UCrop(com.yalantis.ucrop.UCrop) File(java.io.File) Uri(android.net.Uri) FileManager(com.kiminonawa.mydiary.shared.FileManager)

Example 9 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class YourNameDialogFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SELECT_PROFILE_PICTURE_BG) {
        if (resultCode == RESULT_OK) {
            if (data != null && data.getData() != null) {
                //Create fileManager for get temp folder
                tempFileManager = new FileManager(getActivity(), FileManager.TEMP_DIR);
                tempFileManager.clearDir();
                //Compute the bg size
                int photoSize = ScreenHelper.dpToPixel(getResources(), 50);
                UCrop.Options options = new UCrop.Options();
                options.setToolbarColor(ThemeManager.getInstance().getThemeMainColor(getActivity()));
                options.setStatusBarColor(ThemeManager.getInstance().getThemeDarkColor(getActivity()));
                UCrop.of(data.getData(), Uri.fromFile(new File(tempFileManager.getDir() + "/" + FileManager.createRandomFileName()))).withMaxResultSize(photoSize, photoSize).withAspectRatio(1, 1).withOptions(options).start(getActivity(), this);
            } else {
                Toast.makeText(getActivity(), getString(R.string.toast_photo_intent_error), Toast.LENGTH_LONG).show();
            }
        }
    } else if (requestCode == UCrop.REQUEST_CROP) {
        if (resultCode == RESULT_OK) {
            if (data != null) {
                final Uri resultUri = UCrop.getOutput(data);
                IV_your_name_profile_picture.setImageBitmap(BitmapFactory.decodeFile(resultUri.getPath()));
                profilePictureFileName = FileManager.getFileNameByUri(getActivity(), resultUri);
                isAddNewProfilePicture = true;
            } else {
                Toast.makeText(getActivity(), getString(R.string.toast_crop_profile_picture_fail), Toast.LENGTH_LONG).show();
            //sample error
            // final Throwable cropError = UCrop.getError(data);
            }
        }
    }
}
Also used : UCrop(com.yalantis.ucrop.UCrop) File(java.io.File) Uri(android.net.Uri) FileManager(com.kiminonawa.mydiary.shared.FileManager)

Example 10 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class UpdateDiaryTask method doInBackground.

@Override
protected Integer doInBackground(Long... params) {
    int updateResult = RESULT_UPDATE_SUCCESSFUL;
    long topicId = params[0];
    long diaryId = params[1];
    // so make it insert some update and show toast.
    try {
        dbManager.opeDB();
        //Delete all item first
        dbManager.delAllDiaryItemByDiaryId(diaryId);
        //Delete old photo
        diaryFileManager = new FileManager(mContext, topicId, diaryId);
        diaryFileManager.clearDir();
        //Update Diary
        dbManager.updateDiary(diaryId, time, title, moodPosition, weatherPosition, location, attachment);
        for (int i = 0; i < diaryItemHelper.getItemSize(); i++) {
            //Copy photo from temp to diary dir
            if (diaryItemHelper.get(i).getType() == IDairyRow.TYPE_PHOTO) {
                savePhoto(diaryItemHelper.get(i).getContent());
            }
            //Save new data item
            dbManager.insertDiaryContent(diaryItemHelper.get(i).getType(), i, diaryItemHelper.get(i).getContent(), diaryId);
        }
        //Delete all dir if it is no file.
        if (diaryFileManager.getDir().listFiles().length == 0) {
            FileUtils.deleteDirectory(diaryFileManager.getDir());
        }
    } catch (Exception e) {
        updateResult = RESULT_UPDATE_ERROR;
    } finally {
        dbManager.closeDB();
        editCrashFileManager.clearDir();
    }
    return updateResult;
}
Also used : FileManager(com.kiminonawa.mydiary.shared.FileManager)

Aggregations

FileManager (com.kiminonawa.mydiary.shared.FileManager)13 File (java.io.File)5 IOException (java.io.IOException)5 Uri (android.net.Uri)2 DBManager (com.kiminonawa.mydiary.db.DBManager)2 UCrop (com.yalantis.ucrop.UCrop)2 Cursor (android.database.Cursor)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Handler (android.os.Handler)1 DiaryActivity (com.kiminonawa.mydiary.entries.DiaryActivity)1