Search in sources :

Example 66 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class RootsCache method loadStoppedAuthority.

/**
     * Load roots from a stopped authority. Normal {@link UpdateTask} passes
     * ignore stopped applications.
     */
private void loadStoppedAuthority(String authority) {
    final ContentResolver resolver = mContext.getContentResolver();
    synchronized (mLock) {
        if (!mStoppedAuthorities.contains(authority)) {
            return;
        }
        if (DEBUG) {
            Log.d(TAG, "Loading stopped authority " + authority);
        }
        mRoots.putAll(authority, loadRootsForAuthority(resolver, authority, true));
        mStoppedAuthorities.remove(authority);
    }
}
Also used : ContentResolver(android.content.ContentResolver)

Example 67 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class PackageReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    final ContentResolver resolver = context.getContentResolver();
    final String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
        resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE, null, null);
    } else if (Intent.ACTION_PACKAGE_DATA_CLEARED.equals(action)) {
        final Uri data = intent.getData();
        if (data != null) {
            final String packageName = data.getSchemeSpecificPart();
            resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE_PACKAGE, packageName, null);
        }
    }
}
Also used : Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 68 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class CreateDirectoryFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    final ContentResolver resolver = context.getContentResolver();
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext());
    final View view = dialogInflater.inflate(R.layout.dialog_file_name, null, false);
    final EditText editText = (EditText) view.findViewById(android.R.id.text1);
    builder.setTitle(R.string.menu_create_dir);
    builder.setView(view);
    builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            createDirectory(editText.getText().toString());
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    // Workaround for the problem - virtual keyboard doesn't show on the phone.
    Shared.ensureKeyboardPresent(context, dialog);
    editText.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView view, int actionId, @Nullable KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_DONE) || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.hasNoModifiers())) {
                createDirectory(editText.getText().toString());
                dialog.dismiss();
                return true;
            }
            return false;
        }
    });
    return dialog;
}
Also used : Context(android.content.Context) AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) View(android.view.View) TextView(android.widget.TextView) ContentResolver(android.content.ContentResolver) KeyEvent(android.view.KeyEvent) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView)

Example 69 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class DirectoryLoader method loadInBackground.

@Override
public final DirectoryResult loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        mSignal = new CancellationSignal();
    }
    final ContentResolver resolver = getContext().getContentResolver();
    final String authority = mUri.getAuthority();
    final DirectoryResult result = new DirectoryResult();
    result.doc = mDoc;
    // Use default document when searching
    if (mSearchMode) {
        final Uri docUri = DocumentsContract.buildDocumentUri(mRoot.authority, mRoot.documentId);
        try {
            mDoc = DocumentInfo.fromUri(resolver, docUri);
        } catch (FileNotFoundException e) {
            Log.w(TAG, "Failed to query", e);
            result.exception = e;
            return result;
        }
    }
    if (mUserSortOrder != State.SORT_ORDER_UNKNOWN) {
        result.sortOrder = mUserSortOrder;
    } else {
        if ((mDoc.flags & Document.FLAG_DIR_PREFERS_LAST_MODIFIED) != 0) {
            result.sortOrder = State.SORT_ORDER_LAST_MODIFIED;
        } else {
            result.sortOrder = State.SORT_ORDER_DISPLAY_NAME;
        }
    }
    // Search always uses ranking from provider
    if (mSearchMode) {
        result.sortOrder = State.SORT_ORDER_UNKNOWN;
    }
    if (DEBUG)
        Log.d(TAG, "userSortOrder=" + mUserSortOrder + ", sortOrder=" + result.sortOrder);
    ContentProviderClient client = null;
    Cursor cursor = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
        cursor = client.query(mUri, null, null, null, getQuerySortOrder(result.sortOrder), mSignal);
        if (cursor == null) {
            throw new RemoteException("Provider returned null");
        }
        cursor.registerContentObserver(mObserver);
        cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1);
        if (mSearchMode) {
            // Filter directories out of search results, for now
            cursor = new FilteringCursorWrapper(cursor, null, SEARCH_REJECT_MIMES);
        }
        result.client = client;
        result.cursor = cursor;
    } catch (Exception e) {
        Log.w(TAG, "Failed to query", e);
        result.exception = e;
        ContentProviderClient.releaseQuietly(client);
    } finally {
        synchronized (this) {
            mSignal = null;
        }
    }
    return result;
}
Also used : OperationCanceledException(android.os.OperationCanceledException) FileNotFoundException(java.io.FileNotFoundException) Cursor(android.database.Cursor) Uri(android.net.Uri) OperationCanceledException(android.os.OperationCanceledException) RemoteException(android.os.RemoteException) FileNotFoundException(java.io.FileNotFoundException) ContentResolver(android.content.ContentResolver) RemoteException(android.os.RemoteException) CancellationSignal(android.os.CancellationSignal) ContentProviderClient(android.content.ContentProviderClient)

Example 70 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class DocumentClipper method getClipDataForDocuments.

/**
     * Returns ClipData representing the list of docs, or null if docs is empty,
     * or docs cannot be converted.
     */
@Nullable
public ClipData getClipDataForDocuments(List<DocumentInfo> docs) {
    final ContentResolver resolver = mContext.getContentResolver();
    final String[] mimeTypes = getMimeTypes(resolver, docs);
    ClipData clipData = null;
    for (DocumentInfo doc : docs) {
        if (clipData == null) {
            // TODO: figure out what this string should be.
            // Currently it is not displayed anywhere in the UI, but this might change.
            final String label = "";
            clipData = new ClipData(label, mimeTypes, new ClipData.Item(doc.derivedUri));
        } else {
            // TODO: update list of mime types in ClipData.
            clipData.addItem(new ClipData.Item(doc.derivedUri));
        }
    }
    return clipData;
}
Also used : ClipData(android.content.ClipData) ContentResolver(android.content.ContentResolver) DocumentInfo(com.android.documentsui.model.DocumentInfo) Nullable(android.support.annotation.Nullable)

Aggregations

ContentResolver (android.content.ContentResolver)1198 Uri (android.net.Uri)243 Cursor (android.database.Cursor)196 ContentValues (android.content.ContentValues)116 Intent (android.content.Intent)94 RemoteException (android.os.RemoteException)67 IOException (java.io.IOException)62 Context (android.content.Context)58 ArrayList (java.util.ArrayList)50 File (java.io.File)48 Resources (android.content.res.Resources)46 ComponentName (android.content.ComponentName)44 MediumTest (android.test.suitebuilder.annotation.MediumTest)37 PreferenceScreen (android.support.v7.preference.PreferenceScreen)35 Bitmap (android.graphics.Bitmap)33 ContentObserver (android.database.ContentObserver)28 FileNotFoundException (java.io.FileNotFoundException)28 PendingIntent (android.app.PendingIntent)25 MockContentResolver (android.test.mock.MockContentResolver)25 AssetFileDescriptor (android.content.res.AssetFileDescriptor)24