Search in sources :

Example 16 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method onUncompressDocuments.

public boolean onUncompressDocuments(ArrayList<DocumentInfo> docs) {
    final Context context = getActivity();
    final ContentResolver resolver = context.getContentResolver();
    boolean hadTrouble = false;
    for (DocumentInfo doc : docs) {
        if (!doc.isArchiveSupported()) {
            Log.w(TAG, "Skipping " + doc);
            hadTrouble = true;
            continue;
        }
        try {
            hadTrouble = !DocumentsContract.uncompressDocument(resolver, doc.derivedUri);
        } catch (Exception e) {
            Log.w(TAG, "Failed to Uncompress " + doc);
            CrashReportingManager.logException(e);
            hadTrouble = true;
        }
    }
    return hadTrouble;
}
Also used : Context(android.content.Context) OperationCanceledException(android.os.OperationCanceledException) ContentResolver(android.content.ContentResolver) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 17 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method onShareDocuments.

private void onShareDocuments(ArrayList<DocumentInfo> docs) {
    Intent intent;
    if (docs.size() == 1) {
        final DocumentInfo doc = docs.get(0);
        intent = new Intent(Intent.ACTION_SEND);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        // intent.addCategory(Intent.CATEGORY_DEFAULT);
        if (!MimePredicate.mimeMatches(MimePredicate.SHARE_SKIP_MIMES, doc.mimeType)) {
            intent.setType(doc.mimeType);
        } else {
            intent.setType(MimeTypes.ALL_MIME_TYPES);
        }
        intent.putExtra(Intent.EXTRA_STREAM, doc.derivedUri);
        Bundle params = new Bundle();
        String type = IconUtils.getTypeNameFromMimeType(doc.mimeType);
        params.putString(FILE_TYPE, type);
        params.putInt(FILE_COUNT, docs.size());
        AnalyticsManager.logEvent("share" + "_" + type, params);
    } else if (docs.size() > 1) {
        intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        // intent.addCategory(Intent.CATEGORY_DEFAULT);
        final ArrayList<String> mimeTypes = new ArrayList<>();
        final ArrayList<Uri> uris = new ArrayList<>();
        for (DocumentInfo doc : docs) {
            mimeTypes.add(doc.mimeType);
            uris.add(doc.derivedUri);
        }
        String mimeType = findCommonMimeType(mimeTypes);
        if (!MimePredicate.mimeMatches(MimePredicate.SHARE_SKIP_MIMES, mimeType)) {
            intent.setType(mimeType);
        } else {
            intent.setType(MimeTypes.ALL_MIME_TYPES);
        }
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        Bundle params = new Bundle();
        params.putInt(FILE_COUNT, docs.size());
        AnalyticsManager.logEvent("share", params);
    } else {
        return;
    }
    intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via));
    if (Utils.isIntentAvailable(getActivity(), intent)) {
        startActivity(intent);
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) DocumentInfo.getCursorString(dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 18 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method forceStopApps.

private void forceStopApps(ArrayList<DocumentInfo> docs) {
    ArrayList<String> packageList = new ArrayList<>();
    for (DocumentInfo documentInfo : docs) {
        packageList.add(AppsProvider.getPackageForDocId(documentInfo.documentId));
    }
    Intent intent = new Intent(ACTION_FORCE_STOP_REQUEST);
    intent.putExtra(EXTRA_PACKAGE_NAMES, packageList);
    getActivity().sendBroadcast(intent);
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) DocumentInfo.getCursorString(dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 19 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class CreateFileFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext());
    final View view = dialogInflater.inflate(R.layout.dialog_create_dir, null, false);
    final EditText text1 = (EditText) view.findViewById(android.R.id.text1);
    Utils.tintWidget(text1);
    String title = getArguments().getString(EXTRA_DISPLAY_NAME);
    if (!TextUtils.isEmpty(title)) {
        text1.setText(title);
        text1.setSelection(title.length());
    }
    builder.setTitle(R.string.menu_create_file);
    builder.setView(view);
    builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String displayName = text1.getText().toString();
            final String mimeType = getArguments().getString(EXTRA_MIME_TYPE);
            String extension = FileUtils.getExtFromFilename(displayName);
            final DocumentsActivity activity = (DocumentsActivity) getActivity();
            final DocumentInfo cwd = activity.getCurrentDirectory();
            new CreateFileTask(activity, cwd, TextUtils.isEmpty(extension) ? mimeType : extension, displayName).executeOnExecutor(ProviderExecutor.forAuthority(cwd.authority));
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    return builder.create();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DocumentsActivity(dev.dworks.apps.anexplorer.DocumentsActivity) DialogInterface(android.content.DialogInterface) View(android.view.View) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 20 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class FileUtils method updateMediaStore.

public static void updateMediaStore(Context context, ArrayList<DocumentInfo> docs, String parentPath) {
    try {
        if (Utils.hasKitKat()) {
            ArrayList<String> paths = new ArrayList<>();
            for (DocumentInfo doc : docs) {
                paths.add(parentPath + File.separator + doc.displayName);
            }
            String[] pathsArray = paths.toArray(new String[paths.size()]);
            FileUtils.updateMediaStore(context, pathsArray);
        } else {
            Uri contentUri = Uri.fromFile(new File(parentPath).getParentFile());
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri);
            context.sendBroadcast(mediaScanIntent);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) Uri(android.net.Uri) DocumentFile(android.support.provider.DocumentFile) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Aggregations

DocumentInfo (dev.dworks.apps.anexplorer.model.DocumentInfo)20 Context (android.content.Context)6 ContentResolver (android.content.ContentResolver)5 Uri (android.net.Uri)5 RootInfo (dev.dworks.apps.anexplorer.model.RootInfo)5 ArrayList (java.util.ArrayList)5 FragmentManager (android.app.FragmentManager)4 Intent (android.content.Intent)4 OperationCanceledException (android.os.OperationCanceledException)4 DocumentInfo.getCursorString (dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString)4 Bundle (android.os.Bundle)3 MenuItem (android.view.MenuItem)3 ContentValues (android.content.ContentValues)2 DialogInterface (android.content.DialogInterface)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 Cursor (android.database.Cursor)2 Point (android.graphics.Point)2 AlertDialog (android.support.v7.app.AlertDialog)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2