diff options
author | Trevor Johns <trevorjohns@google.com> | 2015-04-23 22:08:11 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-23 22:08:11 +0000 |
commit | 831ae650bb03e88391ecc3761b93b4f858c866ac (patch) | |
tree | 4bb585ae202ca2bcd4dbbce8dd22bd9f1810f92c | |
parent | f4d1982e31b3a27ae19bae89f3981df5ad76394f (diff) | |
parent | bc576e3e5dcebe446e7ad7d00e7277433fd70bf8 (diff) | |
download | android_development-831ae650bb03e88391ecc3761b93b4f858c866ac.tar.gz android_development-831ae650bb03e88391ecc3761b93b4f858c866ac.tar.bz2 android_development-831ae650bb03e88391ecc3761b93b4f858c866ac.zip |
am bc576e3e: am 13b15893: Update sample browseables
* commit 'bc576e3e5dcebe446e7ad7d00e7277433fd70bf8':
Update sample browseables
2 files changed, 64 insertions, 51 deletions
diff --git a/samples/browseable/NfcProvisioning/src/com.example.android.nfcprovisioning/NfcProvisioningFragment.java b/samples/browseable/NfcProvisioning/src/com.example.android.nfcprovisioning/NfcProvisioningFragment.java index f46d0f22c..3aef6178c 100644 --- a/samples/browseable/NfcProvisioning/src/com.example.android.nfcprovisioning/NfcProvisioningFragment.java +++ b/samples/browseable/NfcProvisioning/src/com.example.android.nfcprovisioning/NfcProvisioningFragment.java @@ -123,6 +123,12 @@ public class NfcProvisioningFragment extends Fragment implements properties.put(e.getKey(), value); } } + // Make sure to put local time in the properties. This is necessary on some devices to + // reliably download the device owner APK from an HTTPS connection. + if (!properties.contains(DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME)) { + properties.put(DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME, + String.valueOf(System.currentTimeMillis())); + } try { properties.store(stream, getString(R.string.nfc_comment)); NdefRecord record = NdefRecord.createMime( diff --git a/samples/browseable/StorageClient/src/com.example.android.storageclient/StorageClientFragment.java b/samples/browseable/StorageClient/src/com.example.android.storageclient/StorageClientFragment.java index 7f9f73eeb..97733b075 100644 --- a/samples/browseable/StorageClient/src/com.example.android.storageclient/StorageClientFragment.java +++ b/samples/browseable/StorageClient/src/com.example.android.storageclient/StorageClientFragment.java @@ -117,69 +117,27 @@ public class StorageClientFragment extends Fragment { // Since the URI is to an image, create and show a DialogFragment to display the // image to the user. FragmentManager fm = getActivity().getSupportFragmentManager(); - ImageDialogFragment imageDialog = new ImageDialogFragment(uri); + ImageDialogFragment imageDialog = new ImageDialogFragment(); + Bundle fragmentArguments = new Bundle(); + fragmentArguments.putParcelable("URI", uri); + imageDialog.setArguments(fragmentArguments); imageDialog.show(fm, "image_dialog"); } // END_INCLUDE (create_show_image_dialog) } - /** - * Grabs metadata for a document specified by URI, logs it to the screen. - * - * @param uri The uri for the document whose metadata should be printed. - */ - public void dumpImageMetaData(Uri uri) { - // BEGIN_INCLUDE (dump_metadata) - - // The query, since it only applies to a single document, will only return one row. - // no need to filter, sort, or select fields, since we want all fields for one - // document. - Cursor cursor = getActivity().getContentResolver() - .query(uri, null, null, null, null, null); - - try { - // moveToFirst() returns false if the cursor has 0 rows. Very handy for - // "if there's anything to look at, look at it" conditionals. - if (cursor != null && cursor.moveToFirst()) { - - // Note it's called "Display Name". This is provider-specific, and - // might not necessarily be the file name. - String displayName = cursor.getString( - cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); - Log.i(TAG, "Display Name: " + displayName); - - int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); - // If the size is unknown, the value stored is null. But since an int can't be - // null in java, the behavior is implementation-specific, which is just a fancy - // term for "unpredictable". So as a rule, check if it's null before assigning - // to an int. This will happen often: The storage API allows for remote - // files, whose size might not be locally known. - String size = null; - if (!cursor.isNull(sizeIndex)) { - // Technically the column stores an int, but cursor.getString will do the - // conversion automatically. - size = cursor.getString(sizeIndex); - } else { - size = "Unknown"; - } - Log.i(TAG, "Size: " + size); - } - } finally { - cursor.close(); - } - // END_INCLUDE (dump_metadata) - } /** * DialogFragment which displays an image, given a URI. */ - private class ImageDialogFragment extends DialogFragment { + public static class ImageDialogFragment extends DialogFragment { private Dialog mDialog; private Uri mUri; - public ImageDialogFragment(Uri uri) { - super(); - mUri = uri; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mUri = getArguments().getParcelable("URI"); } /** Create a Bitmap from the URI for that image and return it. @@ -251,5 +209,54 @@ public class StorageClientFragment extends Fragment { getDialog().dismiss(); } } + + /** + * Grabs metadata for a document specified by URI, logs it to the screen. + * + * @param uri The uri for the document whose metadata should be printed. + */ + public void dumpImageMetaData(Uri uri) { + // BEGIN_INCLUDE (dump_metadata) + + // The query, since it only applies to a single document, will only return one row. + // no need to filter, sort, or select fields, since we want all fields for one + // document. + Cursor cursor = getActivity().getContentResolver() + .query(uri, null, null, null, null, null); + + try { + // moveToFirst() returns false if the cursor has 0 rows. Very handy for + // "if there's anything to look at, look at it" conditionals. + if (cursor != null && cursor.moveToFirst()) { + + // Note it's called "Display Name". This is provider-specific, and + // might not necessarily be the file name. + String displayName = cursor.getString( + cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); + Log.i(TAG, "Display Name: " + displayName); + + int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); + // If the size is unknown, the value stored is null. But since an int can't be + // null in java, the behavior is implementation-specific, which is just a fancy + // term for "unpredictable". So as a rule, check if it's null before assigning + // to an int. This will happen often: The storage API allows for remote + // files, whose size might not be locally known. + String size = null; + if (!cursor.isNull(sizeIndex)) { + // Technically the column stores an int, but cursor.getString will do the + // conversion automatically. + size = cursor.getString(sizeIndex); + } else { + size = "Unknown"; + } + Log.i(TAG, "Size: " + size); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + // END_INCLUDE (dump_metadata) + } } } |