Welcome to mirror list, hosted at ThFree Co, Russian Federation.

IntentCompat.java « holoeverywhere « org « src « library « HoloEverywhere « 3rd_party « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 25f7a2954938bd79f0e2459f51ede24026c99830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

package org.holoeverywhere;

import org.holoeverywhere.app.Application;

import android.content.ClipData;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;

public final class IntentCompat {
    /**
     * Declare chooser activity in manifest:
     *
     * <pre>
     *  &lt;activity android:name="org.holoeverywhere.ChooserActivity"
     *      android:theme="@style/Holo.Theme.Dialog.Alert.Light"
     *      android:finishOnCloseSystemDialogs="true"
     *      android:excludeFromRecents="true"
     *      android:multiprocess="true" /&gt;
     * </pre>
     */
    public static Intent createChooser(Intent target, CharSequence title) {
        if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
            return Intent.createChooser(target, title);
        }
        Intent intent = new Intent();
        intent.setClass(Application.getLastInstance(), ChooserActivity.class);
        intent.putExtra(Intent.EXTRA_INTENT, target);
        if (title != null) {
            intent.putExtra(Intent.EXTRA_TITLE, title);
        }
        int permFlags = target.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        if (permFlags != 0) {
            ClipData targetClipData = target.getClipData();
            if (targetClipData == null && target.getData() != null) {
                ClipData.Item item = new ClipData.Item(target.getData());
                String[] mimeTypes;
                if (target.getType() != null) {
                    mimeTypes = new String[] {
                            target.getType()
                    };
                } else {
                    mimeTypes = new String[] {};
                }
                targetClipData = new ClipData(null, mimeTypes, item);
            }
            if (targetClipData != null) {
                intent.setClipData(targetClipData);
                intent.addFlags(permFlags);
            }
        }
        return intent;
    }

    private IntentCompat() {
    }
}