Android Open Source - MaterialManager Cut Cab






From Project

Back to project page MaterialManager.

License

The source code is released under:

There is no license, someone decided to pretty much republish Cabinet with no credit so I?m taking away the license altogether.

If you think the Android project MaterialManager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.afollestad.cabinet.cab;
//  w  ww  .  jav  a 2 s.c om
import android.app.ProgressDialog;
import android.support.v7.view.ActionMode;
import android.text.Html;
import android.text.Spanned;
import android.view.MenuItem;
import android.widget.Toast;

import com.afollestad.cabinet.R;
import com.afollestad.cabinet.cab.base.BaseFileCab;
import com.afollestad.cabinet.file.CloudFile;
import com.afollestad.cabinet.file.LocalFile;
import com.afollestad.cabinet.file.base.File;
import com.afollestad.cabinet.sftp.SftpClient;
import com.afollestad.cabinet.utils.Utils;

public class CutCab extends BaseFileCab {

    public CutCab() {
        super();
    }

    @Override
    public Spanned getTitle() {
        if (getFiles().size() == 1)
            return Html.fromHtml(getContext().getString(R.string.cut_x, getFiles().get(0).getName()));
        return Html.fromHtml(getContext().getString(R.string.cut_xfiles, getFiles().size()));
    }

    private transient boolean shouldCancel;
    private transient int cutCount;
    private transient int cutTotal;

    @Override
    public boolean canShowFab() {
        return true;
    }

    @Override
    public void paste() {
        Utils.lockOrientation(getContext());
        final ProgressDialog mDialog = new ProgressDialog(getContext());
        mDialog.setMessage(getContext().getString(R.string.copying));
        if (getFiles().size() > 1) {
            mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mDialog.setMax(getFiles().size());
        } else mDialog.setIndeterminate(true);
        mDialog.setCancelable(false);
        mDialog.show();
        cutCount = 0;
        cutTotal = getFiles().size();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (final File file : getFiles()) {
                    if (shouldCancel) break;
                    final File newFile = getDirectory().isRemote() ?
                            new CloudFile(getContext(), (CloudFile) getDirectory(), file.getName(), file.isDirectory()) :
                            new LocalFile(getContext(), getDirectory(), file.getName());
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            file.rename(newFile, new SftpClient.FileCallback() {
                                @Override
                                public void onComplete(File file) {
                                    getFragment().getAdapter().add(file);
                                    getFragment().setListShown(true);
                                    if (getFiles().size() > 0)
                                        mDialog.setProgress(mDialog.getProgress() + 1);
                                    cutCount++;
                                    if (cutCount == cutTotal) {
                                        Utils.unlockOrientation(getContext());
                                        if (getDirectory().isRemote()) {
                                            Toast.makeText(getContext(), getContext().getString(R.string.uploaded_to, getDirectory().getPath()), Toast.LENGTH_SHORT).show();
                                        } else {
                                            Toast.makeText(getContext(), getContext().getString(R.string.moved_to, newFile.getPath()), Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                }

                                @Override
                                public void onError(Exception e) {
                                    Utils.unlockOrientation(getContext());
                                    shouldCancel = true;
                                }
                            });
                        }
                    });
                }
                getContext().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mDialog.dismiss();
                        finish();
                    }
                });
            }
        }).start();
    }

    @Override
    public PasteMode canPaste() {
        return isActive() ? PasteMode.ENABLED : PasteMode.DISABLED;
    }

    @Override
    public boolean canPasteIntoSameDir() {
        return false;
    }

    @Override
    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
        return false;
    }
}




Java Source Code List

com.afollestad.cabinet.App.java
com.afollestad.cabinet.ApplicationTest.java
com.afollestad.cabinet.adapters.FileAdapter.java
com.afollestad.cabinet.adapters.NavigationDrawerAdapter.java
com.afollestad.cabinet.cab.CopyCab.java
com.afollestad.cabinet.cab.CutCab.java
com.afollestad.cabinet.cab.MainCab.java
com.afollestad.cabinet.cab.PickerCab.java
com.afollestad.cabinet.cab.base.BaseCab.java
com.afollestad.cabinet.cab.base.BaseFileCab.java
com.afollestad.cabinet.comparators.AlphabeticalComparator.java
com.afollestad.cabinet.comparators.ExtensionComparator.java
com.afollestad.cabinet.comparators.FoldersFirstComparator.java
com.afollestad.cabinet.comparators.HighLowSizeComparator.java
com.afollestad.cabinet.comparators.LastModifiedComparator.java
com.afollestad.cabinet.comparators.LowHighSizeComparator.java
com.afollestad.cabinet.file.CloudFile.java
com.afollestad.cabinet.file.LocalFile.java
com.afollestad.cabinet.file.Remote.java
com.afollestad.cabinet.file.base.FileFilter.java
com.afollestad.cabinet.file.base.File.java
com.afollestad.cabinet.file.root.LsParser.java
com.afollestad.cabinet.file.root.LsTokenizer.java
com.afollestad.cabinet.file.root.RootFile.java
com.afollestad.cabinet.fragments.AboutDialog.java
com.afollestad.cabinet.fragments.DetailsDialog.java
com.afollestad.cabinet.fragments.DirectoryFragment.java
com.afollestad.cabinet.fragments.NavigationDrawerFragment.java
com.afollestad.cabinet.fragments.RemoteConnectionDialog.java
com.afollestad.cabinet.fragments.WelcomeFragment.java
com.afollestad.cabinet.services.NetworkService.java
com.afollestad.cabinet.sftp.FileNotExistsException.java
com.afollestad.cabinet.sftp.SftpClient.java
com.afollestad.cabinet.ui.DrawerActivity.java
com.afollestad.cabinet.ui.SettingsActivity.java
com.afollestad.cabinet.ui.TextEditor.java
com.afollestad.cabinet.ui.base.NetworkedActivity.java
com.afollestad.cabinet.ui.base.ThemableActivity.java
com.afollestad.cabinet.utils.APKIconDownloader.java
com.afollestad.cabinet.utils.PauseOnScrollListener.java
com.afollestad.cabinet.utils.Perm.java
com.afollestad.cabinet.utils.Pins.java
com.afollestad.cabinet.utils.StorageHelper.java
com.afollestad.cabinet.utils.ThemeUtils.java
com.afollestad.cabinet.utils.TimeUtils.java
com.afollestad.cabinet.utils.Utils.java
com.afollestad.cabinet.zip.Unzipper.java
com.afollestad.cabinet.zip.Zipper.java
eu.chainfire.libsuperuser.ApplicationTest.java
eu.chainfire.libsuperuser.Application.java
eu.chainfire.libsuperuser.Debug.java
eu.chainfire.libsuperuser.HideOverlaysReceiver.java
eu.chainfire.libsuperuser.ShellNotClosedException.java
eu.chainfire.libsuperuser.ShellOnMainThreadException.java
eu.chainfire.libsuperuser.Shell.java
eu.chainfire.libsuperuser.StreamGobbler.java