Search in sources :

Example 1 with RowBuilder

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder in project AnExplorer by 1hakr.

the class AppsProvider method includeAppFromService.

private void includeAppFromService(MatrixCursor result, String docId, RunningServiceInfo processInfo, String query) {
    String process = processInfo.process;
    final String packageName = processInfo.process;
    process = process.substring(process.lastIndexOf(".") + 1, process.length());
    String summary = "";
    String displayName = "";
    ApplicationInfo appInfo = null;
    try {
        appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo;
        displayName = process;
    } catch (Exception e) {
    }
    if (TextUtils.isEmpty(displayName)) {
        displayName = process;
    }
    if (null != query && !displayName.toLowerCase().contains(query)) {
        return;
    }
    final String path = null != appInfo ? appInfo.sourceDir : "";
    final String mimeType = Document.MIME_TYPE_APK;
    int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL;
    if (isTelevision()) {
        flags |= Document.FLAG_DIR_PREFERS_GRID;
    }
    int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    summary = processTypeCache.get(importance);
    final long size = getProcessSize(processInfo.pid);
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName));
    row.add(Document.COLUMN_DISPLAY_NAME, displayName);
    row.add(Document.COLUMN_SUMMARY, summary);
    row.add(Document.COLUMN_SIZE, size);
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    // row.add(Document.COLUMN_LAST_MODIFIED, processInfo.lastActivityTime);
    row.add(Document.COLUMN_PATH, path);
    row.add(Document.COLUMN_FLAGS, flags);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) FileNotFoundException(java.io.FileNotFoundException) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 2 with RowBuilder

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder in project AnExplorer by 1hakr.

the class AppsProvider method includeAppFromProcess.

private void includeAppFromProcess(MatrixCursor result, String docId, AndroidAppProcess processInfo, String query) {
    String process = processInfo.name;
    final String packageName = processInfo.getPackageName();
    process = process.substring(process.lastIndexOf(".") + 1, process.length());
    String summary = "";
    String displayName = "";
    ApplicationInfo appInfo = null;
    try {
        appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo;
        displayName = process;
    } catch (Exception e) {
    }
    if (TextUtils.isEmpty(displayName)) {
        displayName = process;
    }
    if (null != query && !displayName.toLowerCase().contains(query)) {
        return;
    }
    final String path = null != appInfo ? appInfo.sourceDir : "";
    final String mimeType = Document.MIME_TYPE_APK;
    int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL;
    if (isTelevision()) {
        flags |= Document.FLAG_DIR_PREFERS_GRID;
    }
    int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    summary = processTypeCache.get(importance);
    final long size = getProcessSize(processInfo.pid);
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName));
    row.add(Document.COLUMN_DISPLAY_NAME, displayName);
    row.add(Document.COLUMN_SUMMARY, summary);
    row.add(Document.COLUMN_SIZE, size);
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    // row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
    row.add(Document.COLUMN_PATH, path);
    row.add(Document.COLUMN_FLAGS, flags);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) FileNotFoundException(java.io.FileNotFoundException) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 3 with RowBuilder

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder in project AnExplorer by 1hakr.

the class AppsProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    StorageUtils storageUtils = new StorageUtils(getContext());
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, ROOT_ID_USER_APP);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPER_ADVANCED | Root.FLAG_SUPPORTS_SEARCH);
    row.add(Root.COLUMN_ICON, R.drawable.ic_root_apps);
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_apps));
    row.add(Root.COLUMN_DOCUMENT_ID, ROOT_ID_USER_APP);
    row.add(Root.COLUMN_AVAILABLE_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, false));
    row.add(Root.COLUMN_CAPACITY_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, true));
    final RowBuilder row1 = result.newRow();
    row1.add(Root.COLUMN_ROOT_ID, ROOT_ID_SYSTEM_APP);
    row1.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPER_ADVANCED | Root.FLAG_SUPPORTS_SEARCH);
    row1.add(Root.COLUMN_ICON, R.drawable.ic_root_apps);
    row1.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_system_apps));
    row1.add(Root.COLUMN_DOCUMENT_ID, ROOT_ID_SYSTEM_APP);
    row1.add(Root.COLUMN_AVAILABLE_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, false));
    row1.add(Root.COLUMN_CAPACITY_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, true));
    final RowBuilder row2 = result.newRow();
    row2.add(Root.COLUMN_ROOT_ID, ROOT_ID_PROCESS);
    row2.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPER_ADVANCED | Root.FLAG_SUPPORTS_SEARCH);
    row2.add(Root.COLUMN_ICON, R.drawable.ic_root_process);
    row2.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_processes));
    row2.add(Root.COLUMN_DOCUMENT_ID, ROOT_ID_PROCESS);
    row2.add(Root.COLUMN_AVAILABLE_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_RAM, false));
    row2.add(Root.COLUMN_CAPACITY_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_RAM, true));
    return result;
}
Also used : StorageUtils(dev.dworks.apps.anexplorer.misc.StorageUtils) RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 4 with RowBuilder

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder in project AnExplorer by 1hakr.

the class AppsProvider method includeDefaultDocument.

private void includeDefaultDocument(MatrixCursor result, String docId) {
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
    row.add(Document.COLUMN_FLAGS, Document.FLAG_SUPPORTS_THUMBNAIL | Document.FLAG_SUPPORTS_DELETE);
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder)

Example 5 with RowBuilder

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder in project AnExplorer by 1hakr.

the class DownloadStorageProvider method includeDownloadFromCursor.

@SuppressLint("InlinedApi")
private void includeDownloadFromCursor(MatrixCursor result, Cursor cursor) {
    final long id = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID));
    final String docId = String.valueOf(id);
    final String displayName = cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE));
    String summary = cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_DESCRIPTION));
    String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE));
    if (mimeType == null) {
        // Provide fake MIME type so it's openable
        mimeType = "vnd.android.document/file";
    }
    Long size = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
    if (size == -1) {
        size = null;
    }
    final int status = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
    switch(status) {
        case DownloadManager.STATUS_SUCCESSFUL:
            break;
        case DownloadManager.STATUS_PAUSED:
            summary = getContext().getString(R.string.download_queued);
            break;
        case DownloadManager.STATUS_PENDING:
            summary = getContext().getString(R.string.download_queued);
            break;
        case DownloadManager.STATUS_RUNNING:
            final long progress = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
            if (size != null) {
                final long percent = progress * 100 / size;
                summary = getContext().getString(R.string.download_running_percent, percent);
            } else {
                summary = getContext().getString(R.string.download_running);
            }
            break;
        case DownloadManager.STATUS_FAILED:
        default:
            summary = getContext().getString(R.string.download_error);
            break;
    }
    int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE;
    if (mimeType != null && mimeType.startsWith("image/")) {
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    }
    final long lastModified = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP));
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, displayName);
    row.add(Document.COLUMN_SUMMARY, summary);
    row.add(Document.COLUMN_SIZE, size);
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
    row.add(Document.COLUMN_FLAGS, flags);
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

RowBuilder (dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder)34 Point (android.graphics.Point)11 SuppressLint (android.annotation.SuppressLint)7 MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)7 ApplicationInfo (android.content.pm.ApplicationInfo)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 DocumentFile (android.support.provider.DocumentFile)2 ArrayMap (android.support.v4.util.ArrayMap)1 FileUtils.getTypeForFile (dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile)1 StorageUtils (dev.dworks.apps.anexplorer.misc.StorageUtils)1 DocumentInfo.getCursorString (dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString)1 NetworkConnection (dev.dworks.apps.anexplorer.network.NetworkConnection)1 Map (java.util.Map)1