Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29095983 authored by Steve McKay's avatar Steve McKay Committed by Android (Google) Code Review
Browse files

Merge "Use an explicit intent for "Quick View"..."

parents f9efa737 c78bcb8c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -657,6 +657,15 @@ public class Intent implements Parcelable, Cloneable {
     */
    public static final String ACTION_DEFAULT = ACTION_VIEW;

    /**
     * Activity Action: Quick view the data.
     * <p>Input: {@link #getData} is URI from which to retrieve data.
     * <p>Output: nothing.
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_QUICK_VIEW = "android.intent.action.QUICK_VIEW";

    /**
     * Used to indicate that some piece of data should be attached to some other
     * place.  For example, image data could be attached to a contact.  It is up
+42 −13
Original line number Diff line number Diff line
@@ -20,10 +20,12 @@ import static com.android.documentsui.DirectoryFragment.ANIM_DOWN;
import static com.android.documentsui.DirectoryFragment.ANIM_NONE;
import static com.android.documentsui.DirectoryFragment.ANIM_UP;

import android.annotation.Nullable;
import android.app.Activity;
import android.app.FragmentManager;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -57,6 +59,7 @@ import java.util.List;
 * Standalone file management activity.
 */
public class StandaloneActivity extends BaseActivity {

    public static final String TAG = "StandaloneFileManagement";

    private Toolbar mToolbar;
@@ -283,21 +286,47 @@ public class StandaloneActivity extends BaseActivity {
    @Override
    public void onDocumentPicked(DocumentInfo doc) {
        if (doc.isDirectory()) {
            openFolder(doc);
        } else {
            openDocument(doc);
        }
    }

    private void openFolder(DocumentInfo doc) {
        mState.stack.push(doc);
        mState.stackTouched = true;
        onCurrentDirectoryChanged(ANIM_DOWN);
        } else {
            // Fall back to viewing
            final Intent view = new Intent(Intent.ACTION_VIEW);
            view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            view.setData(doc.derivedUri);
    }

    /**
     * Launches an intent to view the specified document.
     */
    private void openDocument(DocumentInfo doc) {
        Intent intent = getQuickViewIntent(doc);
        if (intent == null) {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setData(doc.derivedUri);
        }

        try {
                startActivity(view);
            startActivity(intent);
        } catch (ActivityNotFoundException ex2) {
            Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
        }
    }

    private @Nullable Intent getQuickViewIntent(DocumentInfo doc) {
        Intent intent = new Intent(Intent.ACTION_QUICK_VIEW);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setData(doc.derivedUri);

        ComponentName handler = intent.resolveActivity(getPackageManager());
        if (handler != null) {
            return intent;
        }

        return null;
    }

    @Override