Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/util/CompatibilityFileProvider.java

Issue 2143133002: Do screenshot capture async for share intents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to util/ Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.util;
6
7 import android.database.Cursor;
8 import android.database.MatrixCursor;
9 import android.net.Uri;
10 import android.provider.MediaStore;
11 import android.support.v4.content.FileProvider;
12
13 import java.util.Arrays;
14
15 /**
16 * A FileProvider which works around a bad assumption that particular MediaStore columns exist by
17 * certain third party applications.
18 * http://crbug.com/467423.
19 */
20 public class CompatibilityFileProvider extends FileProvider {
21 @Override
22 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
23 String sortOrder) {
24 Cursor source = super.query(uri, projection, selection, selectionArgs, s ortOrder);
25
26 String[] columnNames = source.getColumnNames();
27 String[] newColumnNames = columnNamesWithData(columnNames);
28 if (columnNames == newColumnNames) return source;
29
30 MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount() );
31
32 source.moveToPosition(-1);
33 while (source.moveToNext()) {
34 MatrixCursor.RowBuilder row = cursor.newRow();
35 for (int i = 0; i < columnNames.length; i++) {
36 switch (source.getType(i)) {
37 case Cursor.FIELD_TYPE_INTEGER:
38 row.add(source.getInt(i));
39 break;
40 case Cursor.FIELD_TYPE_FLOAT:
41 row.add(source.getFloat(i));
42 break;
43 case Cursor.FIELD_TYPE_STRING:
44 row.add(source.getString(i));
45 break;
46 case Cursor.FIELD_TYPE_BLOB:
47 row.add(source.getBlob(i));
48 break;
49 case Cursor.FIELD_TYPE_NULL:
50 default:
51 row.add(null);
52 break;
53 }
54 }
55 }
56
57 source.close();
58 return cursor;
59 }
60
61 private String[] columnNamesWithData(String[] columnNames) {
62 for (String columnName : columnNames) {
63 if (MediaStore.MediaColumns.DATA.equals(columnName)) return columnNa mes;
64 }
65
66 String[] newColumnNames = Arrays.copyOf(columnNames, columnNames.length + 1);
67 newColumnNames[columnNames.length] = MediaStore.MediaColumns.DATA;
68 return newColumnNames;
69 }
70 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/util/ChromeFileProvider.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698