com.danimahardhika.android.helpers.core.FileHelper Java Examples

The following examples show how to use com.danimahardhika.android.helpers.core.FileHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PremiumRequestBuilderTask.java    From candybar with Apache License 2.0 6 votes vote down vote up
private Intent addIntentExtra(@NonNull Intent intent, String emailBody) {
    intent.setType("application/zip");

    if (CandyBarApplication.sZipPath != null) {
        File zip = new File(CandyBarApplication.sZipPath);
        if (zip.exists()) {
            Uri uri = FileHelper.getUriFromFile(mContext.get(), mContext.get().getPackageName(), zip);
            if (uri == null) uri = Uri.fromFile(zip);
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    }

    String subject = "Rebuild Premium Request " + mContext.get().getResources().getString(R.string.app_name);

    intent.putExtra(Intent.EXTRA_EMAIL,
            new String[]{mContext.get().getResources().getString(R.string.dev_email)});
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, emailBody);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    return intent;
}
 
Example #2
Source File: IconRequestBuilderTask.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
private Intent addIntentExtra(@NonNull Intent intent, String emailBody) {
    intent.setType("message/rfc822");

    if (CandyBarApplication.sZipPath != null) {
        File zip = new File(CandyBarApplication.sZipPath);
        if (zip.exists()) {
            Uri uri = FileHelper.getUriFromFile(mContext.get(), mContext.get().getPackageName(), zip);
            if (uri == null) uri = Uri.fromFile(zip);
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    }

    String subject = Preferences.get(mContext.get()).isPremiumRequest() ?
            "Premium Icon Request " : "Icon Request ";
    subject += mContext.get().getResources().getString(R.string.app_name);

    intent.putExtra(Intent.EXTRA_EMAIL,
            new String[]{mContext.get().getResources().getString(R.string.dev_email)});
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, emailBody);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    return intent;
}
 
Example #3
Source File: PremiumRequestBuilderTask.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
private Intent addIntentExtra(@NonNull Intent intent, String emailBody) {
    intent.setType("message/rfc822");

    if (CandyBarApplication.sZipPath != null) {
        File zip = new File(CandyBarApplication.sZipPath);
        if (zip.exists()) {
            Uri uri = FileHelper.getUriFromFile(mContext.get(), mContext.get().getPackageName(), zip);
            if (uri == null) uri = Uri.fromFile(zip);
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    }

    String subject = "Rebuild Premium Request " +mContext.get().getResources().getString(R.string.app_name);

    intent.putExtra(Intent.EXTRA_EMAIL,
            new String[]{mContext.get().getResources().getString(R.string.dev_email)});
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, emailBody);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    return intent;
}
 
Example #4
Source File: WallpaperBoardCrashReport.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
private Intent prepareUri(String deviceInfo, String stackTrace, Intent intent) {
    String crashLog = CrashReportHelper.buildCrashLog(this, getCacheDir(), stackTrace);
    boolean granted = PermissionHelper.isStorageGranted(this);
    if (crashLog != null) {
        Uri uri = FileHelper.getUriFromFile(this, getPackageName(), new File(crashLog));
        if (uri != null) {
            intent.putExtra(Intent.EXTRA_TEXT, deviceInfo +"\n");
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            return intent;
        } else {
            if (granted) {
                uri = Uri.fromFile(new File(crashLog));
                intent.putExtra(Intent.EXTRA_STREAM, uri);
                return intent;
            }
        }
    }

    intent.putExtra(Intent.EXTRA_TEXT, deviceInfo + stackTrace);
    return intent;
}
 
Example #5
Source File: PlaystoreCheckHelper.java    From candybar with Apache License 2.0 5 votes vote down vote up
private void doIfNewVersion() {
    if (Preferences.get(mContext).isNewVersion()) {
        ChangelogFragment.showChangelog(((AppCompatActivity) mContext).getSupportFragmentManager());
        File cache = mContext.getCacheDir();
        FileHelper.clearDirectory(cache);
    }
}
 
Example #6
Source File: CandyBarCrashReport.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
private Intent prepareUri(String deviceInfo, String stackTrace, Intent intent) {
    File crashLog = ReportBugsHelper.buildCrashLog(this, stackTrace);
    if (crashLog != null) {
        Uri uri = FileHelper.getUriFromFile(this, getPackageName(), crashLog);
        if (uri != null) {
            intent.putExtra(Intent.EXTRA_TEXT, deviceInfo +"\n");
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            return intent;
        }
    }

    intent.putExtra(Intent.EXTRA_TEXT, deviceInfo + stackTrace);
    return intent;
}
 
Example #7
Source File: ImageConfig.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
public static ImageLoaderConfiguration getImageLoaderConfiguration(@NonNull Context context) {
    return new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .threadPoolSize(4)
            .tasksProcessingOrder(QueueProcessingType.FIFO)
            .diskCache(new UnlimitedDiskCache(new File(
                    context.getCacheDir().toString() + "/uil-images")))
            .diskCacheSize(256 * FileHelper.MB)
            .memoryCacheSize(6 * FileHelper.MB)
            .build();
}
 
Example #8
Source File: ReportBugsTask.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            List<String> files = new ArrayList<>();

            mStringBuilder.append(DeviceHelper.getDeviceInfo(mContext.get()))
                    .append("\n").append(mDescription).append("\n");

            File brokenAppFilter = ReportBugsHelper.buildBrokenAppFilter(mContext.get());
            if (brokenAppFilter != null) files.add(brokenAppFilter.toString());

            File brokenDrawables = ReportBugsHelper.buildBrokenDrawables(mContext.get());
            if (brokenDrawables != null) files.add(brokenDrawables.toString());

            File activityList = ReportBugsHelper.buildActivityList(mContext.get());
            if (activityList != null) files.add(activityList.toString());

            String stackTrace = Preferences.get(mContext.get()).getLatestCrashLog();
            File crashLog = ReportBugsHelper.buildCrashLog(mContext.get(), stackTrace);
            if (crashLog != null) files.add(crashLog.toString());

            mZipPath = FileHelper.createZip(files, new File(mContext.get().getCacheDir(),
                    RequestHelper.getGeneratedZipName(ReportBugsHelper.REPORT_BUGS)));
            return true;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example #9
Source File: ImageConfig.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
public static ImageLoaderConfiguration getImageLoaderConfiguration(@NonNull Context context) {
    L.writeLogs(false);
    L.writeDebugLogs(false);
    return new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .threadPoolSize(4)
            .tasksProcessingOrder(QueueProcessingType.FIFO)
            .diskCacheSize(256 * FileHelper.MB)
            .diskCache(new UnlimitedDiskCache(new File(
                    context.getCacheDir().toString() + "/uil-images")))
            .memoryCacheSize(8 * FileHelper.MB)
            .build();
}
 
Example #10
Source File: CandyBarCrashReport.java    From candybar with Apache License 2.0 5 votes vote down vote up
private Intent prepareUri(String deviceInfo, String stackTrace, Intent intent) {
    File crashLog = ReportBugsHelper.buildCrashLog(this, stackTrace);
    if (crashLog != null) {
        Uri uri = FileHelper.getUriFromFile(this, getPackageName(), crashLog);
        if (uri != null) {
            intent.putExtra(Intent.EXTRA_TEXT, deviceInfo + "\n");
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            return intent;
        }
    }

    intent.putExtra(Intent.EXTRA_TEXT, deviceInfo + stackTrace);
    return intent;
}
 
Example #11
Source File: ImageConfig.java    From candybar with Apache License 2.0 5 votes vote down vote up
public static ImageLoaderConfiguration getImageLoaderConfiguration(@NonNull Context context) {
    return new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .threadPoolSize(4)
            .tasksProcessingOrder(QueueProcessingType.FIFO)
            .diskCache(new UnlimitedDiskCache(new File(
                    context.getCacheDir().toString() + "/uil-images")))
            .diskCacheSize(256 * FileHelper.MB)
            .memoryCacheSize(6 * FileHelper.MB)
            .build();
}
 
Example #12
Source File: ReportBugsTask.java    From candybar with Apache License 2.0 5 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            List<String> files = new ArrayList<>();

            mStringBuilder.append(DeviceHelper.getDeviceInfo(mContext.get()))
                    .append("\n").append(mDescription).append("\n");

            File brokenAppFilter = ReportBugsHelper.buildBrokenAppFilter(mContext.get());
            if (brokenAppFilter != null) files.add(brokenAppFilter.toString());

            File brokenDrawables = ReportBugsHelper.buildBrokenDrawables(mContext.get());
            if (brokenDrawables != null) files.add(brokenDrawables.toString());

            File activityList = ReportBugsHelper.buildActivityList(mContext.get());
            if (activityList != null) files.add(activityList.toString());

            String stackTrace = Preferences.get(mContext.get()).getLatestCrashLog();
            File crashLog = ReportBugsHelper.buildCrashLog(mContext.get(), stackTrace);
            if (crashLog != null) files.add(crashLog.toString());

            mZipPath = FileHelper.createZip(files, new File(mContext.get().getCacheDir(),
                    RequestHelper.getGeneratedZipName(ReportBugsHelper.REPORT_BUGS)));
            return true;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example #13
Source File: IconRequestBuilderTask.java    From candybar with Apache License 2.0 5 votes vote down vote up
private Intent addIntentExtra(@NonNull Intent intent, String emailBody) {
    intent.setType("application/zip");

    if (CandyBarApplication.sZipPath != null) {
        File zip = new File(CandyBarApplication.sZipPath);
        if (zip.exists()) {
            Uri uri = FileHelper.getUriFromFile(mContext.get(), mContext.get().getPackageName(), zip);
            if (uri == null) uri = Uri.fromFile(zip);
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    }

    String appName = mContext.get().getResources().getString(R.string.app_name);
    String regRequestSubject = appName + " Icon Request";
    String premRequestSubject = appName + " Premium Icon Request";

    if (mContext.get().getResources().getString(R.string.request_email_subject).length() > 0) {
        regRequestSubject = mContext.get().getResources().getString(R.string.request_email_subject);
    }

    if (mContext.get().getResources().getString(R.string.premium_request_email_subject).length() > 0) {
        premRequestSubject = mContext.get().getResources().getString(R.string.premium_request_email_subject);
    }

    String subject = Preferences.get(mContext.get()).isPremiumRequest() ?
            premRequestSubject : regRequestSubject;

    intent.putExtra(Intent.EXTRA_EMAIL,
            new String[]{mContext.get().getResources().getString(R.string.dev_email)});
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, emailBody);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    return intent;
}
 
Example #14
Source File: LicenseCallbackHelper.java    From candybar with Apache License 2.0 5 votes vote down vote up
private void onLicenseChecked(LicenseHelper.Status status) {
    Preferences.get(mContext).setFirstRun(false);
    if (status == LicenseHelper.Status.SUCCESS) {
        Preferences.get(mContext).setLicensed(true);

        if (Preferences.get(mContext).isNewVersion()) {
            ChangelogFragment.showChangelog(((AppCompatActivity) mContext).getSupportFragmentManager());
            File cache = mContext.getCacheDir();
            FileHelper.clearDirectory(cache);
        }
    } else if (status == LicenseHelper.Status.FAILED) {
        Preferences.get(mContext).setLicensed(false);
        ((AppCompatActivity) mContext).finish();
    }
}
 
Example #15
Source File: CandyBarMainActivity.java    From candybar with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.setTheme(Preferences.get(this).isDarkTheme() ?
            R.style.AppThemeDark : R.style.AppTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ColorHelper.setupStatusBarIconColor(this);
    ColorHelper.setNavigationBarColor(this, ContextCompat.getColor(this,
            Preferences.get(this).isDarkTheme() ?
                    R.color.navigationBarDark : R.color.navigationBar));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !Preferences.get(this).isDarkTheme()) {
        int flags = 0;
        if (ColorHelper.isLightColor(ContextCompat.getColor(this, R.color.navigationBar)))
            flags = flags | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
        if (ColorHelper.isLightColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)))
            flags = flags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        if (flags != 0) {
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            this.getWindow().getDecorView().setSystemUiVisibility(flags);
            this.getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
        }
    }

    registerBroadcastReceiver();
    startService(new Intent(this, CandyBarService.class));

    //Todo: wait until google fix the issue, then enable wallpaper crop again on API 26+
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Preferences.get(this).setCropWallpaper(false);
    }

    mConfig = onInit();
    InAppBillingProcessor.get(this).init(mConfig.getLicenseKey());

    mDrawerLayout = findViewById(R.id.drawer_layout);
    mNavigationView = findViewById(R.id.navigation_view);
    Toolbar toolbar = findViewById(R.id.toolbar);
    mToolbarTitle = findViewById(R.id.toolbar_title);

    toolbar.setPopupTheme(Preferences.get(this).isDarkTheme() ?
            R.style.AppThemeDark : R.style.AppTheme);
    toolbar.setTitle("");
    setSupportActionBar(toolbar);

    mFragManager = getSupportFragmentManager();

    initNavigationView(toolbar);
    initNavigationViewHeader();

    mPosition = mLastPosition = 0;
    if (savedInstanceState != null) {
        mPosition = mLastPosition = savedInstanceState.getInt(Extras.EXTRA_POSITION, 0);
        onSearchExpanded(false);
    }

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        int position = bundle.getInt(Extras.EXTRA_POSITION, -1);
        if (position >= 0 && position < 5) {
            mPosition = mLastPosition = position;
        }
    }

    IntentHelper.sAction = IntentHelper.getAction(getIntent());
    if (IntentHelper.sAction == IntentHelper.ACTION_DEFAULT) {
        setFragment(getFragment(mPosition));
    } else {
        setFragment(getActionFragment(IntentHelper.sAction));
    }

    checkWallpapers();
    IconRequestTask.start(this, AsyncTask.THREAD_POOL_EXECUTOR);
    IconsLoaderTask.start(this);

    new PlaystoreCheckHelper(this).run();

    if (Preferences.get(this).isFirstRun() && mConfig.isLicenseCheckerEnabled()) {
        mLicenseHelper = new LicenseHelper(this);
        mLicenseHelper.run(mConfig.getLicenseKey(), mConfig.getRandomString(), new LicenseCallbackHelper(this));
        return;
    }

    if (!Preferences.get(this).isPlaystoreCheckEnabled() && !mConfig.isLicenseCheckerEnabled()) {
        if (Preferences.get(this).isNewVersion()) {
            ChangelogFragment.showChangelog(mFragManager);
            File cache = this.getCacheDir();
            FileHelper.clearDirectory(cache);
        }
    }

    if (mConfig.isLicenseCheckerEnabled() && !Preferences.get(this).isLicensed()) {
        finish();
    }
}
 
Example #16
Source File: SettingsFragment.java    From wallpaperboard with Apache License 2.0 4 votes vote down vote up
private void initSettings() {
    List<Setting> settings = new ArrayList<>();

    double cache = (double) FileHelper.getDirectorySize(getActivity().getCacheDir()) / FileHelper.MB;
    NumberFormat formatter = new DecimalFormat("#0.00");

    settings.add(Setting.Builder(Setting.Type.HEADER)
            .icon(R.drawable.ic_toolbar_storage)
            .title(getActivity().getResources().getString(R.string.pref_data_header))
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.CACHE)
            .subtitle(getActivity().getResources().getString(R.string.pref_data_cache))
            .content(getActivity().getResources().getString(R.string.pref_data_cache_desc))
            .footer(String.format(getActivity().getResources().getString(R.string.pref_data_cache_size),
                    formatter.format(cache) + " MB"))
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.HEADER)
            .icon(R.drawable.ic_toolbar_theme)
            .title(getActivity().getResources().getString(R.string.pref_theme_header))
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.THEME)
            .subtitle(getActivity().getResources().getString(R.string.pref_theme_dark))
            .content(getActivity().getResources().getString(R.string.pref_theme_dark_desc))
            .checkboxState(Preferences.get(getActivity()).isDarkTheme() ? 1 : 0)
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.HEADER)
            .icon(R.drawable.ic_toolbar_wallpapers)
            .title(getActivity().getResources().getString(R.string.pref_wallpaper_header))
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.PREVIEW_QUALITY)
            .subtitle(getActivity().getResources().getString(R.string.pref_wallpaper_high_quality_preview))
            .content(Preferences.get(getActivity()).isHighQualityPreviewEnabled() ?
                    getActivity().getResources().getString(R.string.pref_wallpaper_high_quality_preview_high) :
                    getActivity().getResources().getString(R.string.pref_wallpaper_high_quality_preview_low))
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.WALLPAPER)
            .subtitle(getActivity().getResources().getString(R.string.pref_wallpaper_location))
            .content(WallpaperHelper.getDefaultWallpapersDirectory(getActivity()).toString())
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.HEADER)
            .icon(R.drawable.ic_toolbar_language)
            .title(getActivity().getResources().getString(R.string.pref_language_header))
            .build()
    );

    Language language = LocaleHelper.getCurrentLanguage(getActivity());
    settings.add(Setting.Builder(Setting.Type.LANGUAGE)
            .subtitle(Preferences.get(getActivity()).isLocaleDefault() ?
                    getString(R.string.pref_options_default) : language.getName())
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.HEADER)
            .icon(R.drawable.ic_toolbar_others)
            .title(getActivity().getResources().getString(R.string.pref_others_header))
            .build()
    );

    settings.add(Setting.Builder(Setting.Type.RESET_TUTORIAL)
            .subtitle(getActivity().getResources().getString(R.string.pref_others_reset_tutorial))
            .build()
    );

    mRecyclerView.setAdapter(new SettingsAdapter(getActivity(), settings));
}
 
Example #17
Source File: SettingsFragment.java    From candybar-library with Apache License 2.0 4 votes vote down vote up
private void initSettings() {
    List<Setting> settings = new ArrayList<>();

    double cache = (double) FileHelper.getDirectorySize(getActivity().getCacheDir()) / FileHelper.MB;
    NumberFormat formatter = new DecimalFormat("#0.00");

    settings.add(new Setting(R.drawable.ic_toolbar_storage,
            getActivity().getResources().getString(R.string.pref_data_header),
            "", "", "", Setting.Type.HEADER, -1));

    settings.add(new Setting(-1, "",
            getActivity().getResources().getString(R.string.pref_data_cache),
            getActivity().getResources().getString(R.string.pref_data_cache_desc),
            String.format(getActivity().getResources().getString(R.string.pref_data_cache_size),
                    formatter.format(cache) + " MB"),
            Setting.Type.CACHE, -1));

    if (getActivity().getResources().getBoolean(R.bool.enable_icon_request) ||
            Preferences.get(getActivity()).isPremiumRequestEnabled() &&
                    !getActivity().getResources().getBoolean(R.bool.enable_icon_request_limit)) {
        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_data_request),
                getActivity().getResources().getString(R.string.pref_data_request_desc),
                "", Setting.Type.ICON_REQUEST, -1));
    }

    if (Preferences.get(getActivity()).isPremiumRequestEnabled()) {
        settings.add(new Setting(R.drawable.ic_toolbar_premium_request,
                getActivity().getResources().getString(R.string.pref_premium_request_header),
                "", "", "", Setting.Type.HEADER, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_premium_request_restore),
                getActivity().getResources().getString(R.string.pref_premium_request_restore_desc),
                "", Setting.Type.RESTORE, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_premium_request_rebuild),
                getActivity().getResources().getString(R.string.pref_premium_request_rebuild_desc),
                "", Setting.Type.PREMIUM_REQUEST, -1));
    }

    if (CandyBarApplication.getConfiguration().isDashboardThemingEnabled()) {
        settings.add(new Setting(R.drawable.ic_toolbar_theme,
                getActivity().getResources().getString(R.string.pref_theme_header),
                "", "", "", Setting.Type.HEADER, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_theme_dark),
                getActivity().getResources().getString(R.string.pref_theme_dark_desc),
                "", Setting.Type.THEME, Preferences.get(getActivity()).isDarkTheme() ? 1 : 0));
    }

    if (WallpaperHelper.getWallpaperType(getActivity()) == WallpaperHelper.CLOUD_WALLPAPERS) {
        settings.add(new Setting(R.drawable.ic_toolbar_wallpapers,
                getActivity().getResources().getString(R.string.pref_wallpaper_header),
                "", "", "", Setting.Type.HEADER, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_wallpaper_location),
                WallpaperHelper.getDefaultWallpapersDirectory(getActivity()).toString(), "",
                Setting.Type.WALLPAPER, -1));
    }

    settings.add(new Setting(R.drawable.ic_toolbar_language,
            getActivity().getResources().getString(R.string.pref_language_header),
            "", "", "", Setting.Type.HEADER, -1));

    Language language = LocaleHelper.getCurrentLanguage(getActivity());
    settings.add(new Setting(-1, "",
            language.getName(),
            "", "", Setting.Type.LANGUAGE, -1));

    settings.add(new Setting(R.drawable.ic_toolbar_others,
            getActivity().getResources().getString(R.string.pref_others_header),
            "", "", "", Setting.Type.HEADER, -1));

    settings.add(new Setting(-1, "",
            getActivity().getResources().getString(R.string.pref_others_changelog),
            "", "", Setting.Type.CHANGELOG, -1));

    if (getActivity().getResources().getBoolean(R.bool.enable_apply)) {
        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_others_report_bugs),
                "", "", Setting.Type.REPORT_BUGS, -1));
    }

    settings.add(new Setting(-1, "",
            getActivity().getResources().getString(R.string.pref_others_reset_tutorial),
            "", "", Setting.Type.RESET_TUTORIAL, -1));

    mRecyclerView.setAdapter(new SettingsAdapter(getActivity(), settings));
}
 
Example #18
Source File: SettingsFragment.java    From candybar-library with Apache License 2.0 4 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            File directory = getActivity().getCacheDir();
            requests = Database.get(getActivity()).getPremiumRequest(null);
            if (requests.size() == 0) return true;

            File appFilter = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.APPFILTER);
            File appMap = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.APPMAP);
            File themeResources = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.THEME_RESOURCES);
            List<String> files = new ArrayList<>();

            for (int i = 0; i < requests.size(); i++) {
                Drawable drawable = DrawableHelper.getHighQualityIcon(
                        getActivity(), requests.get(i).getPackageName());
                String icon = IconsHelper.saveIcon(files, directory, drawable, requests.get(i).getName());
                if (icon != null) files.add(icon);
            }

            if (appFilter != null) {
                files.add(appFilter.toString());
            }

            if (appMap != null) {
                files.add(appMap.toString());
            }

            if (themeResources != null) {
                files.add(themeResources.toString());
            }
            CandyBarApplication.sZipPath = FileHelper.createZip(files, new File(directory.toString(),
                    RequestHelper.getGeneratedZipName(RequestHelper.REBUILD_ZIP)));
            return true;
        } catch (Exception e) {
            log = e.toString();
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example #19
Source File: RequestFragment.java    From candybar-library with Apache License 2.0 4 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
                    getResources().getString(R.string.dev_email),
                    null));
            List<ResolveInfo> resolveInfos = getActivity().getPackageManager()
                    .queryIntentActivities(intent, 0);
            if (resolveInfos.size() == 0) {
                noEmailClientError = true;
                return false;
            }

            if (Preferences.get(getActivity()).isPremiumRequest()) {
                TransactionDetails details = InAppBillingProcessor.get(getActivity())
                        .getProcessor().getPurchaseTransactionDetails(
                        Preferences.get(getActivity()).getPremiumRequestProductId());
                if (details == null) return false;

                CandyBarApplication.sRequestProperty = new Request.Property(null,
                        details.purchaseInfo.purchaseData.orderId,
                        details.purchaseInfo.purchaseData.productId);
            }

            RequestFragment.sSelectedRequests = mAdapter.getSelectedItems();
            List<Request> requests = mAdapter.getSelectedApps();
            File appFilter = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.APPFILTER);
            File appMap = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.APPMAP);
            File themeResources = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.THEME_RESOURCES);

            File directory = getActivity().getCacheDir();
            List<String> files = new ArrayList<>();

            for (Request request : requests) {
                Drawable drawable = getHighQualityIcon(getActivity(), request.getPackageName());
                String icon = IconsHelper.saveIcon(files, directory, drawable, request.getName());
                if (icon != null) files.add(icon);
            }

            if (appFilter != null) {
                files.add(appFilter.toString());
            }

            if (appMap != null) {
                files.add(appMap.toString());
            }

            if (themeResources != null) {
                files.add(themeResources.toString());
            }

            CandyBarApplication.sZipPath = FileHelper.createZip(files, new File(directory.toString(),
                    RequestHelper.getGeneratedZipName(RequestHelper.ZIP)));
            return true;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example #20
Source File: SettingsFragment.java    From candybar with Apache License 2.0 4 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            File directory = getActivity().getCacheDir();
            requests = Database.get(getActivity()).getPremiumRequest(null);
            if (requests.size() == 0) return true;

            File appFilter = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.APPFILTER);
            File appMap = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.APPMAP);
            File themeResources = RequestHelper.buildXml(getActivity(), requests, RequestHelper.XmlType.THEME_RESOURCES);
            List<String> files = new ArrayList<>();

            for (int i = 0; i < requests.size(); i++) {
                Drawable drawable = getReqIcon(getActivity(), requests.get(i).getActivity());
                String icon = IconsHelper.saveIcon(files, directory, drawable, requests.get(i).getName());
                if (icon != null) files.add(icon);
            }

            if (appFilter != null) {
                files.add(appFilter.toString());
            }

            if (appMap != null) {
                files.add(appMap.toString());
            }

            if (themeResources != null) {
                files.add(themeResources.toString());
            }
            CandyBarApplication.sZipPath = FileHelper.createZip(files, new File(directory.toString(),
                    RequestHelper.getGeneratedZipName(RequestHelper.REBUILD_ZIP)));
            return true;
        } catch (Exception e) {
            log = e.toString();
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example #21
Source File: SettingsFragment.java    From candybar with Apache License 2.0 4 votes vote down vote up
private void initSettings() {
    List<Setting> settings = new ArrayList<>();

    double cache = (double) FileHelper.getDirectorySize(getActivity().getCacheDir()) / FileHelper.MB;
    NumberFormat formatter = new DecimalFormat("#0.00");

    settings.add(new Setting(R.drawable.ic_toolbar_storage,
            getActivity().getResources().getString(R.string.pref_data_header),
            "", "", "", Setting.Type.HEADER, -1));

    settings.add(new Setting(-1, "",
            getActivity().getResources().getString(R.string.pref_data_cache),
            getActivity().getResources().getString(R.string.pref_data_cache_desc),
            String.format(getActivity().getResources().getString(R.string.pref_data_cache_size),
                    formatter.format(cache) + " MB"),
            Setting.Type.CACHE, -1));

    if (getActivity().getResources().getBoolean(R.bool.enable_icon_request) ||
            Preferences.get(getActivity()).isPremiumRequestEnabled() &&
                    !getActivity().getResources().getBoolean(R.bool.enable_icon_request_limit)) {
        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_data_request),
                getActivity().getResources().getString(R.string.pref_data_request_desc),
                "", Setting.Type.ICON_REQUEST, -1));
    }

    if (Preferences.get(getActivity()).isPremiumRequestEnabled()) {
        settings.add(new Setting(R.drawable.ic_toolbar_premium_request,
                getActivity().getResources().getString(R.string.pref_premium_request_header),
                "", "", "", Setting.Type.HEADER, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_premium_request_restore),
                getActivity().getResources().getString(R.string.pref_premium_request_restore_desc),
                "", Setting.Type.RESTORE, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_premium_request_rebuild),
                getActivity().getResources().getString(R.string.pref_premium_request_rebuild_desc),
                "", Setting.Type.PREMIUM_REQUEST, -1));
    }

    if (CandyBarApplication.getConfiguration().isDashboardThemingEnabled()) {
        settings.add(new Setting(R.drawable.ic_toolbar_theme,
                getActivity().getResources().getString(R.string.pref_theme_header),
                "", "", "", Setting.Type.HEADER, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_theme_dark),
                getActivity().getResources().getString(R.string.pref_theme_dark_desc),
                "", Setting.Type.THEME, Preferences.get(getActivity()).isDarkTheme() ? 1 : 0));
    }

    if (WallpaperHelper.getWallpaperType(getActivity()) == WallpaperHelper.CLOUD_WALLPAPERS) {
        settings.add(new Setting(R.drawable.ic_toolbar_wallpapers,
                getActivity().getResources().getString(R.string.pref_wallpaper_header),
                "", "", "", Setting.Type.HEADER, -1));

        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_wallpaper_location),
                WallpaperHelper.getDefaultWallpapersDirectory(getActivity()).toString(), "",
                Setting.Type.WALLPAPER, -1));
    }

    settings.add(new Setting(R.drawable.ic_toolbar_language,
            getActivity().getResources().getString(R.string.pref_language_header),
            "", "", "", Setting.Type.HEADER, -1));

    Language language = LocaleHelper.getCurrentLanguage(getActivity());
    settings.add(new Setting(-1, "",
            language.getName(),
            "", "", Setting.Type.LANGUAGE, -1));

    settings.add(new Setting(R.drawable.ic_toolbar_others,
            getActivity().getResources().getString(R.string.pref_others_header),
            "", "", "", Setting.Type.HEADER, -1));

    settings.add(new Setting(-1, "",
            getActivity().getResources().getString(R.string.pref_others_changelog),
            "", "", Setting.Type.CHANGELOG, -1));

    if (getActivity().getResources().getBoolean(R.bool.enable_apply)) {
        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_others_report_bugs),
                "", "", Setting.Type.REPORT_BUGS, -1));
    }

    if (getActivity().getResources().getBoolean(R.bool.show_intro)) {
        settings.add(new Setting(-1, "",
                getActivity().getResources().getString(R.string.pref_others_reset_tutorial),
                "", "", Setting.Type.RESET_TUTORIAL, -1));
    }

    mRecyclerView.setAdapter(new SettingsAdapter(getActivity(), settings));
}