Java Code Examples for com.danimahardhika.android.helpers.core.utils.LogUtil#e()

The following examples show how to use com.danimahardhika.android.helpers.core.utils.LogUtil#e() . 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: RequestFragment.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            if (CandyBarMainActivity.sMissedApps == null) {
                CandyBarMainActivity.sMissedApps = RequestHelper.getMissingApps(getActivity());
            }

            requests = CandyBarMainActivity.sMissedApps;
            return true;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example 2
Source File: DrawableHelper.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Drawable getHighQualityIcon(@NonNull Context context, String packageName) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo info = packageManager.getApplicationInfo(
                packageName, PackageManager.GET_META_DATA);

        Resources resources = packageManager.getResourcesForApplication(packageName);
        int density = DisplayMetrics.DENSITY_XXHIGH;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            density = DisplayMetrics.DENSITY_XXXHIGH;
        }

        Drawable drawable = ResourcesCompat.getDrawableForDensity(
                resources, info.icon, density, null);
        if (drawable != null) return drawable;
        return info.loadIcon(packageManager);
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}
 
Example 3
Source File: CategoryWallpapersFragment.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            Filter filter = new Filter();
            filter.add(Filter.Create(Filter.Column.CATEGORY).setQuery(mCategoryName));

            wallpapers = Database.get(getActivity()).getFilteredWallpapers(filter);
            return true;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example 4
Source File: LocalFavoritesBackupTask.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPreExecute() {
    super.onPreExecute();
    if (mIsStorageGranted) {
        File file = BackupHelper.getDefaultDirectory(mContext.get());
        if (!file.exists()) {
            file.mkdirs();
        }

        File nomedia = new File(file.getParent(), BackupHelper.NOMEDIA);
        if (!nomedia.exists()) {
            try {
                nomedia.createNewFile();
            } catch (IOException e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
        }
    }
}
 
Example 5
Source File: Database.java    From candybar with Apache License 2.0 5 votes vote down vote up
public void deleteWallpapers() {
    if (!openDatabase()) {
        LogUtil.e("Database error: deleteWallpapers() failed to open database");
        return;
    }

    mDatabase.get().mSQLiteDatabase.delete("SQLITE_SEQUENCE", "NAME = ?", new String[]{TABLE_WALLPAPERS});
    mDatabase.get().mSQLiteDatabase.delete(TABLE_WALLPAPERS, null, null);
}
 
Example 6
Source File: ReportBugsHelper.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
@Nullable
public static File buildBrokenAppFilter(@NonNull Context context) {
    try {
        HashMap<String, String> activities = RequestHelper.getAppFilter(context, RequestHelper.Key.ACTIVITY);
        File brokenAppFilter = new File(context.getCacheDir(), BROKEN_APPFILTER);
        Writer writer = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream(brokenAppFilter), "UTF8"));

        boolean first = true;
        for (Map.Entry<String, String> entry : activities.entrySet()) {
            if (first) {
                first = false;
                writer.append("<!-- BROKEN APPFILTER -->")
                        .append("\n").append("<!-- Broken appfilter will check for activities that included in appfilter but doesn\'t have a drawable")
                        .append("\n").append("* ").append("The reason could because misnamed drawable or the drawable not copied to the project -->")
                        .append("\n\n\n");
            }

            int drawable = context.getResources().getIdentifier(
                    entry.getValue(), "drawable", context.getPackageName());
            if (drawable == 0) {
                writer.append("Activity: ").append(entry.getKey())
                        .append("\n")
                        .append("Drawable: ").append(entry.getValue()).append(".png")
                        .append("\n\n");
            }
        }

        writer.flush();
        writer.close();
        return brokenAppFilter;
    } catch (Exception e) {
        LogUtil.e(Log.getStackTraceString(e));
        return null;
    }
}
 
Example 7
Source File: WallpapersFragment.java    From candybar with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(Boolean aBoolean) {
    super.onPostExecute(aBoolean);
    if (getActivity() == null) return;
    if (getActivity().isFinishing()) return;

    mAsyncTask = null;
    mProgress.setVisibility(View.GONE);
    mSwipe.setRefreshing(false);

    if (aBoolean) {
        mRecyclerView.setAdapter(new WallpapersAdapter(getActivity(), wallpapers));

        WallpapersListener listener = (WallpapersListener) getActivity();
        listener.onWallpapersChecked(new Intent()
                .putExtra("size", Preferences.get(getActivity()).getAvailableWallpapersCount())
                .putExtra("packageName", getActivity().getPackageName()));

        try {
            if (getActivity().getResources().getBoolean(R.bool.show_intro)) {
                TapIntroHelper.showWallpapersIntro(getActivity(), mRecyclerView);
            }
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
        }
    } else {
        Toast.makeText(getActivity(), R.string.connection_failed,
                Toast.LENGTH_LONG).show();
    }
    showPopupBubble();
}
 
Example 8
Source File: ColorPalette.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
@ColorInt
public int get(int index) {
    if (index >= 0 && index < mColors.size()) {
        return mColors.get(index);
    }
    LogUtil.e("ColorPalette: index out of bounds");
    return -1;
}
 
Example 9
Source File: Database.java    From candybar with Apache License 2.0 5 votes vote down vote up
public void deleteWallpapers(List<Wallpaper> wallpapers) {
    if (!openDatabase()) {
        LogUtil.e("Database error: deleteWallpapers() failed to open database");
        return;
    }

    for (Wallpaper wallpaper : wallpapers) {
        mDatabase.get().mSQLiteDatabase.delete(TABLE_WALLPAPERS, KEY_URL + " = ?",
                new String[]{wallpaper.getURL()});
    }
}
 
Example 10
Source File: Database.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
public boolean isRequested(String activity) {
    if (!openDatabase()) {
        LogUtil.e("Database error: isRequested() failed to open database");
        return false;
    }

    Cursor cursor = mDatabase.get().mSQLiteDatabase.query(TABLE_REQUEST, null, KEY_ACTIVITY + " = ?",
            new String[]{activity}, null, null, null, null);
    int rowCount = cursor.getCount();
    cursor.close();
    return rowCount > 0;
}
 
Example 11
Source File: LatestFragment.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {
            Thread.sleep(1);
            if (mWallpapers.get(mPosition).getDimensions() != null)
                return true;

            URL url = new URL(mWallpapers.get(mPosition).getUrl());
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(10000);

            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream stream = connection.getInputStream();

                final BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(stream, null, options);

                ImageSize imageSize = new ImageSize(options.outWidth, options.outHeight);
                mWallpapers.get(mPosition).setDimensions(imageSize);

                Database.get(getActivity()).updateWallpaper(
                        mWallpapers.get(mPosition));
                stream.close();
                return true;
            }
            return false;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example 12
Source File: Database.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
public void updateWallpapers(@NonNull List<Wallpaper> wallpapers) {
    if (!openDatabase()) {
        LogUtil.e("Database error: updateWallpapers() failed to open database");
        return;
    }

    String query = "UPDATE " +TABLE_WALLPAPERS+ " SET " +KEY_FAVORITE+ " = ?, " +KEY_SIZE+ " = ?, "
            +KEY_MIME_TYPE+ " = ?, " +KEY_WIDTH+ " = ?," +KEY_HEIGHT+ " = ?, " +KEY_COLOR+ " = ? "
            +"WHERE " +KEY_URL+ " = ?";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (Wallpaper wallpaper : wallpapers) {
        statement.clearBindings();

        statement.bindLong(1, wallpaper.isFavorite() ? 1 : 0);
        statement.bindLong(2, wallpaper.getSize());

        String mimeType = wallpaper.getMimeType();
        if (mimeType != null) {
            statement.bindString(3, mimeType);
        } else {
            statement.bindNull(3);
        }

        ImageSize dimension = wallpaper.getDimensions();
        int width = dimension == null ? 0 : dimension.getWidth();
        int height = dimension == null ? 0 : dimension.getHeight();
        statement.bindLong(4, width);
        statement.bindLong(5, height);

        statement.bindLong(6, wallpaper.getColor());
        statement.bindString(7, wallpaper.getUrl());
        statement.execute();
    }

    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example 13
Source File: InAppBillingProcessor.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onBillingError(int errorCode, Throwable error) {
    if (mInAppBilling == null || mInAppBilling.get() == null) {
        LogUtil.e("InAppBillingProcessor error: not initialized");
        return;
    }

    if (errorCode == Constants.BILLING_ERROR_FAILED_TO_INITIALIZE_PURCHASE) {
        mInAppBilling.get().mIsInitialized = false;
    }
}
 
Example 14
Source File: WallpaperApplyTask.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
public AsyncTask start(@NonNull Executor executor) {
    if (mDialog == null) {
        int color = mWallpaper.getColor();
        if (color == 0) {
            color = ColorHelper.getAttributeColor(mContext.get(), R.attr.colorAccent);
        }

        final MaterialDialog.Builder builder = new MaterialDialog.Builder(mContext.get());
        builder.widgetColor(color)
                .typeface(TypefaceHelper.getMedium(mContext.get()), TypefaceHelper.getRegular(mContext.get()))
                .progress(true, 0)
                .cancelable(false)
                .progressIndeterminateStyle(true)
                .content(R.string.wallpaper_loading)
                .positiveColor(color)
                .positiveText(android.R.string.cancel)
                .onPositive((dialog, which) -> {
                    ImageLoader.getInstance().stop();
                    cancel(true);
                });

        mDialog = builder.build();
    }

    if (!mDialog.isShowing()) mDialog.show();

    mExecutor = executor;
    if (mWallpaper == null) {
        LogUtil.e("WallpaperApply cancelled, wallpaper is null");
        return null;
    }

    if (mWallpaper.getDimensions() == null) {
        return WallpaperPropertiesLoaderTask.prepare(mContext.get())
                .wallpaper(mWallpaper)
                .callback(this)
                .start(AsyncTask.THREAD_POOL_EXECUTOR);
    }
    return executeOnExecutor(executor);
}
 
Example 15
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 16
Source File: WallpaperPropertiesLoaderTask.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);
            if (mWallpaper == null) return false;

            if (mWallpaper.getDimensions() != null &&
                    mWallpaper.getMimeType() != null &&
                    mWallpaper.getSize() > 0) {
                return false;
            }

            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;

            URL url = new URL(mWallpaper.getURL());
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(15000);

            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream stream = connection.getInputStream();
                BitmapFactory.decodeStream(stream, null, options);

                ImageSize imageSize = new ImageSize(options.outWidth, options.outHeight);
                mWallpaper.setDimensions(imageSize);
                mWallpaper.setMimeType(options.outMimeType);

                int contentLength = connection.getContentLength();
                if (contentLength > 0) {
                    mWallpaper.setSize(contentLength);
                }

                Database.get(mContext.get()).updateWallpaper(mWallpaper);
                stream.close();
                return true;
            }
            return false;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}
 
Example 17
Source File: Database.java    From candybar with Apache License 2.0 4 votes vote down vote up
public void addWallpapers(List<?> list) {
    if (!openDatabase()) {
        LogUtil.e("Database error: addWallpapers() failed to open database");
        return;
    }

    String query = "INSERT OR IGNORE INTO " + TABLE_WALLPAPERS + " (" + KEY_NAME + "," + KEY_AUTHOR + "," + KEY_URL + ","
            + KEY_THUMB_URL + "," + KEY_ADDED_ON + ") VALUES (?,?,?,?,?);";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (int i = 0; i < list.size(); i++) {
        statement.clearBindings();

        Wallpaper wallpaper;
        if (list.get(i) instanceof Wallpaper) {
            wallpaper = (Wallpaper) list.get(i);
        } else {
            wallpaper = JsonHelper.getWallpaper(list.get(i));
        }

        if (wallpaper != null) {
            if (wallpaper.getURL() != null) {
                String name = wallpaper.getName();
                if (name == null) name = "";

                statement.bindString(1, name);

                if (wallpaper.getAuthor() != null) {
                    statement.bindString(2, wallpaper.getAuthor());
                } else {
                    statement.bindNull(2);
                }

                statement.bindString(3, wallpaper.getURL());
                statement.bindString(4, wallpaper.getThumbUrl());
                statement.bindString(5, TimeHelper.getLongDateTime());
                statement.execute();
            }
        }
    }
    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example 18
Source File: Database.java    From candybar-library with Apache License 2.0 4 votes vote down vote up
public void addWallpapers(List<?> list) {
    if (!openDatabase()) {
        LogUtil.e("Database error: addWallpapers() failed to open database");
        return;
    }

    String query = "INSERT OR IGNORE INTO " +TABLE_WALLPAPERS+ " (" +KEY_NAME+ "," +KEY_AUTHOR+ "," +KEY_URL+ ","
            +KEY_THUMB_URL+ "," +KEY_ADDED_ON+ ") VALUES (?,?,?,?,?);";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (int i = 0; i < list.size(); i++) {
        statement.clearBindings();

        Wallpaper wallpaper;
        if (list.get(i) instanceof Wallpaper) {
            wallpaper = (Wallpaper) list.get(i);
        } else {
            wallpaper = JsonHelper.getWallpaper(list.get(i));
        }

        if (wallpaper != null) {
            if (wallpaper.getURL() != null) {
                String name = wallpaper.getName();
                if (name == null) name = "";

                statement.bindString(1, name);

                if (wallpaper.getAuthor() != null) {
                    statement.bindString(2, wallpaper.getAuthor());
                } else {
                    statement.bindNull(2);
                }

                statement.bindString(3, wallpaper.getURL());
                statement.bindString(4, wallpaper.getThumbUrl());
                statement.bindString(5, TimeHelper.getLongDateTime());
                statement.execute();
            }
        }
    }
    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example 19
Source File: Database.java    From wallpaperboard with Apache License 2.0 4 votes vote down vote up
@Nullable
public Wallpaper getRandomWallpaper() {
    if (!openDatabase()) {
        LogUtil.e("Database error: getRandomWallpaper() failed to open database");
        return null;
    }

    Wallpaper wallpaper = null;
    List<String> selected = getSelectedCategories(true);
    List<String> selection = new ArrayList<>();
    if (selected.size() == 0) return null;

    StringBuilder CONDITION = new StringBuilder();
    for (String item : selected) {
        if (CONDITION.length() > 0 ) {
            CONDITION.append(" OR ").append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?");
        } else {
            CONDITION.append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?");
        }
        selection.add("%" +item.toLowerCase(Locale.getDefault())+ "%");
    }

    Cursor cursor = mDatabase.get().mSQLiteDatabase.query(TABLE_WALLPAPERS, null, CONDITION.toString(),
            selection.toArray(new String[selection.size()]), null, null, "RANDOM()", "1");
    if (cursor.moveToFirst()) {
        do {
            int id = cursor.getInt(cursor.getColumnIndex(KEY_ID));
            String name = cursor.getString(cursor.getColumnIndex(KEY_NAME));
            if (name.length() == 0) {
                name = "Wallpaper "+ id;
            }

            wallpaper = Wallpaper.Builder()
                    .name(name)
                    .author(cursor.getString(cursor.getColumnIndex(KEY_AUTHOR)))
                    .url(cursor.getString(cursor.getColumnIndex(KEY_URL)))
                    .thumbUrl(cursor.getString(cursor.getColumnIndex(KEY_THUMB_URL)))
                    .category(cursor.getString(cursor.getColumnIndex(KEY_CATEGORY)))
                    .build();
        } while (cursor.moveToNext());
    }
    cursor.close();
    return wallpaper;
}
 
Example 20
Source File: WallpaperPropertiesLoaderTask.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);
            if (mWallpaper == null) return false;

            if (mWallpaper.getDimensions() != null &&
                    mWallpaper.getMimeType() != null &&
                    mWallpaper.getSize() > 0) {
                return false;
            }

            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;

            URL url = new URL(mWallpaper.getURL());
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(15000);

            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream stream = connection.getInputStream();
                BitmapFactory.decodeStream(stream, null, options);

                ImageSize imageSize = new ImageSize(options.outWidth, options.outHeight);
                mWallpaper.setDimensions(imageSize);
                mWallpaper.setMimeType(options.outMimeType);

                int contentLength = connection.getContentLength();
                if (contentLength > 0) {
                    mWallpaper.setSize(contentLength);
                }

                Database.get(mContext.get()).updateWallpaper(mWallpaper);
                stream.close();
                return true;
            }
            return false;
        } catch (Exception e) {
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}