Search in sources :

Example 1 with CountItemsOrAndSizeTask

use of com.amaze.filemanager.asynchronous.asynctasks.CountItemsOrAndSizeTask in project AmazeFileManager by TeamAmaze.

the class GeneralDialogCreation method showPropertiesDialog.

private static void showPropertiesDialog(final HybridFileParcelable baseFile, final String permissions, ThemedActivity base, boolean isRoot, AppTheme appTheme, boolean showPermissions, boolean forStorage) {
    final ExecutorService executor = Executors.newFixedThreadPool(3);
    final Context c = base.getApplicationContext();
    int accentColor = base.getColorPreference().getColor(ColorUsage.ACCENT);
    long last = baseFile.getDate();
    final String date = Utils.getDate(last), items = c.getString(R.string.calculating), name = baseFile.getName(), parent = baseFile.getReadablePath(baseFile.getParent(c));
    MaterialDialog.Builder builder = new MaterialDialog.Builder(base);
    builder.title(c.getString(R.string.properties));
    builder.theme(appTheme.getMaterialDialogTheme());
    View v = base.getLayoutInflater().inflate(R.layout.properties_dialog, null);
    TextView itemsText = (TextView) v.findViewById(R.id.t7);
    /*View setup*/
    {
        TextView mNameTitle = (TextView) v.findViewById(R.id.title_name);
        mNameTitle.setTextColor(accentColor);
        TextView mDateTitle = (TextView) v.findViewById(R.id.title_date);
        mDateTitle.setTextColor(accentColor);
        TextView mSizeTitle = (TextView) v.findViewById(R.id.title_size);
        mSizeTitle.setTextColor(accentColor);
        TextView mLocationTitle = (TextView) v.findViewById(R.id.title_location);
        mLocationTitle.setTextColor(accentColor);
        TextView md5Title = (TextView) v.findViewById(R.id.title_md5);
        md5Title.setTextColor(accentColor);
        TextView sha256Title = (TextView) v.findViewById(R.id.title_sha256);
        sha256Title.setTextColor(accentColor);
        ((TextView) v.findViewById(R.id.t5)).setText(name);
        ((TextView) v.findViewById(R.id.t6)).setText(parent);
        itemsText.setText(items);
        ((TextView) v.findViewById(R.id.t8)).setText(date);
        LinearLayout mNameLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_name);
        LinearLayout mLocationLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_location);
        LinearLayout mSizeLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_size);
        LinearLayout mDateLinearLayout = (LinearLayout) v.findViewById(R.id.properties_dialog_date);
        // setting click listeners for long press
        mNameLinearLayout.setOnLongClickListener(v1 -> {
            FileUtils.copyToClipboard(c, name);
            Toast.makeText(c, c.getResources().getString(R.string.name) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
        mLocationLinearLayout.setOnLongClickListener(v12 -> {
            FileUtils.copyToClipboard(c, parent);
            Toast.makeText(c, c.getResources().getString(R.string.location) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
        mSizeLinearLayout.setOnLongClickListener(v13 -> {
            FileUtils.copyToClipboard(c, items);
            Toast.makeText(c, c.getResources().getString(R.string.size) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
        mDateLinearLayout.setOnLongClickListener(v14 -> {
            FileUtils.copyToClipboard(c, date);
            Toast.makeText(c, c.getResources().getString(R.string.date) + " " + c.getResources().getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
    }
    CountItemsOrAndSizeTask countItemsOrAndSizeTask = new CountItemsOrAndSizeTask(c, itemsText, baseFile, forStorage);
    countItemsOrAndSizeTask.executeOnExecutor(executor);
    GenerateHashesTask hashGen = new GenerateHashesTask(baseFile, c, v);
    hashGen.executeOnExecutor(executor);
    /*Chart creation and data loading*/
    {
        boolean isRightToLeft = c.getResources().getBoolean(R.bool.is_right_to_left);
        boolean isDarkTheme = appTheme.getMaterialDialogTheme() == Theme.DARK;
        PieChart chart = (PieChart) v.findViewById(R.id.chart);
        chart.setTouchEnabled(false);
        chart.setDrawEntryLabels(false);
        chart.setDescription(null);
        chart.setNoDataText(c.getString(R.string.loading));
        chart.setRotationAngle(!isRightToLeft ? 0f : 180f);
        chart.setHoleColor(Color.TRANSPARENT);
        chart.setCenterTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
        chart.getLegend().setEnabled(true);
        chart.getLegend().setForm(Legend.LegendForm.CIRCLE);
        chart.getLegend().setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        chart.getLegend().setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
        chart.getLegend().setTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
        chart.animateY(1000);
        if (forStorage) {
            final String[] LEGENDS = new String[] { c.getString(R.string.used), c.getString(R.string.free) };
            final int[] COLORS = { Utils.getColor(c, R.color.piechart_red), Utils.getColor(c, R.color.piechart_green) };
            long totalSpace = baseFile.getTotal(c), freeSpace = baseFile.getUsableSpace(), usedSpace = totalSpace - freeSpace;
            List<PieEntry> entries = new ArrayList<>();
            entries.add(new PieEntry(usedSpace, LEGENDS[0]));
            entries.add(new PieEntry(freeSpace, LEGENDS[1]));
            PieDataSet set = new PieDataSet(entries, null);
            set.setColors(COLORS);
            set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
            set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
            set.setSliceSpace(5f);
            set.setAutomaticallyDisableSliceSpacing(true);
            set.setValueLinePart2Length(1.05f);
            set.setSelectionShift(0f);
            PieData pieData = new PieData(set);
            pieData.setValueFormatter(new SizeFormatter(c));
            pieData.setValueTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
            String totalSpaceFormatted = Formatter.formatFileSize(c, totalSpace);
            chart.setCenterText(new SpannableString(c.getString(R.string.total) + "\n" + totalSpaceFormatted));
            chart.setData(pieData);
        } else {
            LoadFolderSpaceDataTask loadFolderSpaceDataTask = new LoadFolderSpaceDataTask(c, appTheme, chart, baseFile);
            loadFolderSpaceDataTask.executeOnExecutor(executor);
        }
        chart.invalidate();
    }
    if (!forStorage && showPermissions) {
        final MainFragment main = ((MainActivity) base).mainFragment;
        AppCompatButton appCompatButton = (AppCompatButton) v.findViewById(R.id.permissionsButton);
        appCompatButton.setAllCaps(true);
        final View permissionsTable = v.findViewById(R.id.permtable);
        final View button = v.findViewById(R.id.set);
        if (isRoot && permissions.length() > 6) {
            appCompatButton.setVisibility(View.VISIBLE);
            appCompatButton.setOnClickListener(v15 -> {
                if (permissionsTable.getVisibility() == View.GONE) {
                    permissionsTable.setVisibility(View.VISIBLE);
                    button.setVisibility(View.VISIBLE);
                    setPermissionsDialog(permissionsTable, button, baseFile, permissions, c, main);
                } else {
                    button.setVisibility(View.GONE);
                    permissionsTable.setVisibility(View.GONE);
                }
            });
        }
    }
    builder.customView(v, true);
    builder.positiveText(base.getResources().getString(R.string.ok));
    builder.positiveColor(accentColor);
    builder.dismissListener(dialog -> executor.shutdown());
    MaterialDialog materialDialog = builder.build();
    materialDialog.show();
    materialDialog.getActionButton(DialogAction.NEGATIVE).setEnabled(false);
/*
        View bottomSheet = c.findViewById(R.id.design_bottom_sheet);
        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
        bottomSheetBehavior.setPeekHeight(BottomSheetBehavior.STATE_DRAGGING);
        */
}
Also used : LinearLayout(android.widget.LinearLayout) PreferencesConstants(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants) ColorUsage(com.amaze.filemanager.utils.color.ColorUsage) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) Uri(android.net.Uri) WindowManager(android.view.WindowManager) TextInputLayout(android.support.design.widget.TextInputLayout) ThemedActivity(com.amaze.filemanager.activities.superclasses.ThemedActivity) AppTheme(com.amaze.filemanager.utils.theme.AppTheme) CompressedHelper(com.amaze.filemanager.filesystem.compressed.CompressedHelper) RootHelper(com.amaze.filemanager.filesystem.RootHelper) GeneralSecurityException(java.security.GeneralSecurityException) CheckBox(android.widget.CheckBox) View(android.view.View) Button(android.widget.Button) RootUtils(com.amaze.filemanager.utils.RootUtils) PreferenceManager(android.preference.PreferenceManager) PieChart(com.github.mikephil.charting.charts.PieChart) PieData(com.github.mikephil.charting.data.PieData) LoadFolderSpaceDataTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFolderSpaceDataTask) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) M(android.os.Build.VERSION_CODES.M) AsyncTask(android.os.AsyncTask) Entry(com.github.mikephil.charting.data.Entry) InputType(android.text.InputType) FingerprintManager(android.hardware.fingerprint.FingerprintManager) Executors(java.util.concurrent.Executors) CryptUtil(com.amaze.filemanager.utils.files.CryptUtil) List(java.util.List) TextView(android.widget.TextView) HiddenAdapter(com.amaze.filemanager.adapters.HiddenAdapter) R(com.amaze.filemanager.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CountItemsOrAndSizeTask(com.amaze.filemanager.asynchronous.asynctasks.CountItemsOrAndSizeTask) AppCompatEditText(android.support.v7.widget.AppCompatEditText) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) Context(android.content.Context) IValueFormatter(com.github.mikephil.charting.formatter.IValueFormatter) HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) FingerprintHandler(com.amaze.filemanager.utils.FingerprintHandler) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi) FileUtils.toHybridFileArrayList(com.amaze.filemanager.utils.files.FileUtils.toHybridFileArrayList) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) MainActivity(com.amaze.filemanager.activities.MainActivity) ArrayList(java.util.ArrayList) AppCompatButton(android.support.v7.widget.AppCompatButton) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) PieDataSet(com.github.mikephil.charting.data.PieDataSet) Toast(android.widget.Toast) DataUtils(com.amaze.filemanager.utils.DataUtils) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ExecutorService(java.util.concurrent.ExecutorService) Formatter(android.text.format.Formatter) GenerateHashesTask(com.amaze.filemanager.asynchronous.asynctasks.GenerateHashesTask) SpannableString(android.text.SpannableString) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) File(java.io.File) Theme(com.afollestad.materialdialogs.Theme) EncryptDecryptUtils(com.amaze.filemanager.utils.files.EncryptDecryptUtils) Color(android.graphics.Color) Utils(com.amaze.filemanager.utils.Utils) SharedPreferences(android.content.SharedPreferences) BasicActivity(com.amaze.filemanager.activities.superclasses.BasicActivity) ViewPortHandler(com.github.mikephil.charting.utils.ViewPortHandler) FileUtils(com.amaze.filemanager.utils.files.FileUtils) DialogUtils(com.afollestad.materialdialogs.util.DialogUtils) TextInputEditText(android.support.design.widget.TextInputEditText) PieEntry(com.github.mikephil.charting.data.PieEntry) OpenMode(com.amaze.filemanager.utils.OpenMode) EditText(android.widget.EditText) PieEntry(com.github.mikephil.charting.data.PieEntry) SpannableString(android.text.SpannableString) MainActivity(com.amaze.filemanager.activities.MainActivity) MainFragment(com.amaze.filemanager.fragments.MainFragment) PieChart(com.github.mikephil.charting.charts.PieChart) PieDataSet(com.github.mikephil.charting.data.PieDataSet) TextView(android.widget.TextView) List(java.util.List) FileUtils.toHybridFileArrayList(com.amaze.filemanager.utils.files.FileUtils.toHybridFileArrayList) ArrayList(java.util.ArrayList) Context(android.content.Context) GenerateHashesTask(com.amaze.filemanager.asynchronous.asynctasks.GenerateHashesTask) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) View(android.view.View) TextView(android.widget.TextView) CountItemsOrAndSizeTask(com.amaze.filemanager.asynchronous.asynctasks.CountItemsOrAndSizeTask) AppCompatButton(android.support.v7.widget.AppCompatButton) SpannableString(android.text.SpannableString) LoadFolderSpaceDataTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFolderSpaceDataTask) ExecutorService(java.util.concurrent.ExecutorService) PieData(com.github.mikephil.charting.data.PieData) LinearLayout(android.widget.LinearLayout)

Aggregations

Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Color (android.graphics.Color)1 Typeface (android.graphics.Typeface)1 FingerprintManager (android.hardware.fingerprint.FingerprintManager)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Build (android.os.Build)1 M (android.os.Build.VERSION_CODES.M)1 PreferenceManager (android.preference.PreferenceManager)1 RequiresApi (android.support.annotation.RequiresApi)1 TextInputEditText (android.support.design.widget.TextInputEditText)1 TextInputLayout (android.support.design.widget.TextInputLayout)1 AppCompatButton (android.support.v7.widget.AppCompatButton)1 AppCompatEditText (android.support.v7.widget.AppCompatEditText)1 Editable (android.text.Editable)1 InputType (android.text.InputType)1 SpannableString (android.text.SpannableString)1 TextUtils (android.text.TextUtils)1