diff options
Diffstat (limited to 'samples/browseable')
39 files changed, 1981 insertions, 4 deletions
diff --git a/samples/browseable/ActivityInstrumentation/_index.jd b/samples/browseable/ActivityInstrumentation/_index.jd index 1cf01c84b..fcf341082 100644 --- a/samples/browseable/ActivityInstrumentation/_index.jd +++ b/samples/browseable/ActivityInstrumentation/_index.jd @@ -8,6 +8,6 @@ sample.group=Testing <p>This sample demonstrates how to use an {@link android.test.InstrumentationTestCase} to test the internal state of an {@link android.app.Activity}.</p> -<p>To learn more about using Android's custom testing framework, see -<a href="{@docRoot}/training/activity-testing/index.html">Testing Your +<p>To learn more about using Android's custom testing framework, see +<a href="{@docRoot}training/activity-testing/index.html">Testing Your Android Activity</a>.</p> diff --git a/samples/browseable/StorageProvider/AndroidManifest.xml b/samples/browseable/StorageProvider/AndroidManifest.xml new file mode 100644 index 000000000..e4704dc8f --- /dev/null +++ b/samples/browseable/StorageProvider/AndroidManifest.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.storageprovider" + android:versionCode="1" + android:versionName="1.0"> + + <uses-sdk + android:minSdkVersion="19" + android:targetSdkVersion="19"/> + + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> + + <application + android:allowBackup="true" + android:label="@string/app_name" + android:icon="@drawable/ic_launcher" + android:theme="@style/MyAppTheme"> + + <activity + android:name=".MainActivity" + android:uiOptions="splitActionBarWhenNarrow" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + + <!--BEGIN_INCLUDE(provider_manifest)--> + <!-- + Declare the document provider class MyCloudProvider to the system. The MANAGE_DOCUMENTS + permission belongs only to the Android system, ensuring this provider will never be used + directly by another app. The provider must grant URI permissions in order to expose the + specific documents(s) chosen, while not sharing all of its data by default. It must be + exported to be visible outside the application, and it must include a filter with the intent + "android.content.action.DOCUMENTS_PROVIDER" in order to be shown in the system document + picker UI. + --> + <provider + android:name="com.example.android.storageprovider.MyCloudProvider" + android:authorities="com.example.android.storageprovider.documents" + android:grantUriPermissions="true" + android:exported="true" + android:permission="android.permission.MANAGE_DOCUMENTS"> + <intent-filter> + <action android:name="android.content.action.DOCUMENTS_PROVIDER"/> + </intent-filter> + </provider> + <!--END_INCLUDE(provider_manifest)--> + + </application> + +</manifest> diff --git a/samples/browseable/StorageProvider/_index.jd b/samples/browseable/StorageProvider/_index.jd new file mode 100644 index 000000000..562a83217 --- /dev/null +++ b/samples/browseable/StorageProvider/_index.jd @@ -0,0 +1,7 @@ +page.tags="Storage access framework", storage, documents +sample.group=Content +@jd:body + +<p>This sample demonstrates how to use the +{@link android.provider.DocumentsProvider} API to manage documents and +expose them to the Android system for sharing.</p> diff --git a/samples/browseable/StorageProvider/res/drawable-hdpi/ic_launcher.png b/samples/browseable/StorageProvider/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..c5d697220 --- /dev/null +++ b/samples/browseable/StorageProvider/res/drawable-hdpi/ic_launcher.png diff --git a/samples/browseable/StorageProvider/res/drawable-hdpi/tile.9.png b/samples/browseable/StorageProvider/res/drawable-hdpi/tile.9.png Binary files differnew file mode 100644 index 000000000..135862883 --- /dev/null +++ b/samples/browseable/StorageProvider/res/drawable-hdpi/tile.9.png diff --git a/samples/browseable/StorageProvider/res/drawable-mdpi/ic_launcher.png b/samples/browseable/StorageProvider/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..59e6bd9ea --- /dev/null +++ b/samples/browseable/StorageProvider/res/drawable-mdpi/ic_launcher.png diff --git a/samples/browseable/StorageProvider/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/StorageProvider/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..5b8b7be20 --- /dev/null +++ b/samples/browseable/StorageProvider/res/drawable-xhdpi/ic_launcher.png diff --git a/samples/browseable/StorageProvider/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/StorageProvider/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..474bbd248 --- /dev/null +++ b/samples/browseable/StorageProvider/res/drawable-xxhdpi/ic_launcher.png diff --git a/samples/browseable/StorageProvider/res/ic_launcher.png b/samples/browseable/StorageProvider/res/ic_launcher.png Binary files differnew file mode 100755 index 000000000..c5d697220 --- /dev/null +++ b/samples/browseable/StorageProvider/res/ic_launcher.png diff --git a/samples/browseable/StorageProvider/res/layout/activity_main.xml b/samples/browseable/StorageProvider/res/layout/activity_main.xml new file mode 100755 index 000000000..bc5a57591 --- /dev/null +++ b/samples/browseable/StorageProvider/res/layout/activity_main.xml @@ -0,0 +1,38 @@ +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:id="@+id/sample_main_layout"> + <TextView android:id="@+id/sample_output" + style="@style/Widget.SampleMessage" + android:layout_weight="1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:text="@string/intro_message" /> + <View + android:layout_width="fill_parent" + android:layout_height="1dp" + android:background="@android:color/darker_gray"/> + <fragment + android:name="com.example.android.common.logger.LogFragment" + android:id="@+id/log_fragment" + android:layout_weight="1" + android:layout_width="match_parent" + android:layout_height="match_parent" /> +</LinearLayout> diff --git a/samples/browseable/StorageProvider/res/menu/main.xml b/samples/browseable/StorageProvider/res/menu/main.xml new file mode 100644 index 000000000..2c3515dd4 --- /dev/null +++ b/samples/browseable/StorageProvider/res/menu/main.xml @@ -0,0 +1,21 @@ +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@+id/sample_action" + android:showAsAction="ifRoom|withText" + android:title="@string/sample_action" /> +</menu> diff --git a/samples/browseable/StorageProvider/res/raw/android_computer_android_studio.jpg b/samples/browseable/StorageProvider/res/raw/android_computer_android_studio.jpg Binary files differnew file mode 100755 index 000000000..b916136c8 --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/android_computer_android_studio.jpg diff --git a/samples/browseable/StorageProvider/res/raw/android_computer_back.jpg b/samples/browseable/StorageProvider/res/raw/android_computer_back.jpg Binary files differnew file mode 100755 index 000000000..4ba49298f --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/android_computer_back.jpg diff --git a/samples/browseable/StorageProvider/res/raw/android_dinner.jpg b/samples/browseable/StorageProvider/res/raw/android_dinner.jpg Binary files differnew file mode 100755 index 000000000..6c5491fbf --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/android_dinner.jpg diff --git a/samples/browseable/StorageProvider/res/raw/android_pumpkins_fall.jpg b/samples/browseable/StorageProvider/res/raw/android_pumpkins_fall.jpg Binary files differnew file mode 100755 index 000000000..6111f32da --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/android_pumpkins_fall.jpg diff --git a/samples/browseable/StorageProvider/res/raw/android_rose.jpg b/samples/browseable/StorageProvider/res/raw/android_rose.jpg Binary files differnew file mode 100755 index 000000000..396eb90b1 --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/android_rose.jpg diff --git a/samples/browseable/StorageProvider/res/raw/cat_names.txt b/samples/browseable/StorageProvider/res/raw/cat_names.txt new file mode 100644 index 000000000..b67570b3e --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/cat_names.txt @@ -0,0 +1,17 @@ +Top cat names of 2013 + +1. Angel +2. Charlie +3. Mittens +4. Milkshake +5. Oreo +6. Ella +7. Lily +8. Ellie +9. Pepsi +10. Amber +11. Molly +12. Truffles +13. Peanut +14. Tiger Lilly +15. Snowball
\ No newline at end of file diff --git a/samples/browseable/StorageProvider/res/raw/dog_names.txt b/samples/browseable/StorageProvider/res/raw/dog_names.txt new file mode 100644 index 000000000..ca43dd67f --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/dog_names.txt @@ -0,0 +1,17 @@ +Top dog names of 2013 + +1. Gus +2. Trapper +3. Finn +4. Bailey +5. Cooper +6. Hawkeye +7. Wrigley +8. Boomer +9. Ace +10. Butch +11. Delgado +12. Evan +13. Lucky +14. Otto +15. Buddy
\ No newline at end of file diff --git a/samples/browseable/StorageProvider/res/raw/example.docx b/samples/browseable/StorageProvider/res/raw/example.docx Binary files differnew file mode 100644 index 000000000..1f6e016f1 --- /dev/null +++ b/samples/browseable/StorageProvider/res/raw/example.docx diff --git a/samples/browseable/StorageProvider/res/values-sw600dp/template-dimens.xml b/samples/browseable/StorageProvider/res/values-sw600dp/template-dimens.xml new file mode 100644 index 000000000..22074a2bd --- /dev/null +++ b/samples/browseable/StorageProvider/res/values-sw600dp/template-dimens.xml @@ -0,0 +1,24 @@ +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<resources> + + <!-- Semantic definitions --> + + <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen> + <dimen name="vertical_page_margin">@dimen/margin_medium</dimen> + +</resources> diff --git a/samples/browseable/StorageProvider/res/values-sw600dp/template-styles.xml b/samples/browseable/StorageProvider/res/values-sw600dp/template-styles.xml new file mode 100644 index 000000000..03d197418 --- /dev/null +++ b/samples/browseable/StorageProvider/res/values-sw600dp/template-styles.xml @@ -0,0 +1,25 @@ +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<resources> + + <style name="Widget.SampleMessage"> + <item name="android:textAppearance">?android:textAppearanceLarge</item> + <item name="android:lineSpacingMultiplier">1.2</item> + <item name="android:shadowDy">-6.5</item> + </style> + +</resources> diff --git a/samples/browseable/StorageProvider/res/values/app_strings.xml b/samples/browseable/StorageProvider/res/values/app_strings.xml new file mode 100644 index 000000000..fa60e14d3 --- /dev/null +++ b/samples/browseable/StorageProvider/res/values/app_strings.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright 2013 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + + +<resources> + <string name="log_in">Log in</string> + <string name="log_out">Log out</string> + <string name="logged_in_info">You are currently logged in, which means the documents in MyCloud are visible to other applications.</string> + <string name="logged_out_info">You are currently logged out, so MyCloud is not visible as a document provider.</string> + <string name="root_summary">cloudy with a chance of …</string> + <string name="key_logged_in">logged_in</string> +</resources> diff --git a/samples/browseable/StorageProvider/res/values/arrays.xml b/samples/browseable/StorageProvider/res/values/arrays.xml new file mode 100644 index 000000000..b79a5a927 --- /dev/null +++ b/samples/browseable/StorageProvider/res/values/arrays.xml @@ -0,0 +1,34 @@ +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources> + <array name="image_res_ids"> + <item>@raw/android_dinner</item> + <item>@raw/android_rose</item> + <item>@raw/android_pumpkins_fall</item> + <item>@raw/android_computer_back</item> + <item>@raw/android_computer_android_studio</item> + </array> + + <array name="text_res_ids"> + <item>@raw/cat_names</item> + <item>@raw/dog_names</item> + </array> + + <array name="docx_res_ids"> + <item>@raw/example</item> + </array> +</resources> diff --git a/samples/browseable/StorageProvider/res/values/base-strings.xml b/samples/browseable/StorageProvider/res/values/base-strings.xml new file mode 100644 index 000000000..d3674af60 --- /dev/null +++ b/samples/browseable/StorageProvider/res/values/base-strings.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + + + +<resources> + <string name="app_name">MyCloud</string> + <string name="intro_message"> + <![CDATA[ + + + \nA simple implementation of a documents provider using the storage access framework in + Android 4.4. + + + ]]> + </string> +</resources> diff --git a/samples/browseable/StorageProvider/res/values/strings.xml b/samples/browseable/StorageProvider/res/values/strings.xml new file mode 100644 index 000000000..df0327374 --- /dev/null +++ b/samples/browseable/StorageProvider/res/values/strings.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + + + +<resources> + <string name="sample_action">Log in</string> +</resources> diff --git a/samples/browseable/StorageProvider/res/values/styles.xml b/samples/browseable/StorageProvider/res/values/styles.xml new file mode 100644 index 000000000..b325e362b --- /dev/null +++ b/samples/browseable/StorageProvider/res/values/styles.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources> + + <style name="MyAppTheme" parent="AppTheme"> + <item name="android:textViewStyle">@style/MyTextViewStyle</item> + <item name="android:actionBarStyle">@style/MyActionBarStyle</item> + <item name="android:actionMenuTextColor">@android:color/white</item> + </style> + + <style name="MyActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse"> + <item name="android:background">#5E2D79</item> + <item name="android:backgroundSplit">#5E2D79</item> + </style> + + <style name="MyTextViewStyle" parent="android:TextAppearance.Holo.Widget.TextView"> + <item name="android:textSize">18sp</item> + <item name="android:paddingRight">@dimen/margin_medium</item> + <item name="android:paddingLeft">@dimen/margin_medium</item> + <item name="android:fontFamily">sans-serif-light</item> + </style> + +</resources> diff --git a/samples/browseable/StorageProvider/res/values/template-dimens.xml b/samples/browseable/StorageProvider/res/values/template-dimens.xml new file mode 100644 index 000000000..39e710b5c --- /dev/null +++ b/samples/browseable/StorageProvider/res/values/template-dimens.xml @@ -0,0 +1,32 @@ +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<resources> + + <!-- Define standard dimensions to comply with Holo-style grids and rhythm. --> + + <dimen name="margin_tiny">4dp</dimen> + <dimen name="margin_small">8dp</dimen> + <dimen name="margin_medium">16dp</dimen> + <dimen name="margin_large">32dp</dimen> + <dimen name="margin_huge">64dp</dimen> + + <!-- Semantic definitions --> + + <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen> + <dimen name="vertical_page_margin">@dimen/margin_medium</dimen> + +</resources> diff --git a/samples/browseable/StorageProvider/res/values/template-styles.xml b/samples/browseable/StorageProvider/res/values/template-styles.xml new file mode 100644 index 000000000..d3f82ff64 --- /dev/null +++ b/samples/browseable/StorageProvider/res/values/template-styles.xml @@ -0,0 +1,51 @@ +<!-- + Copyright 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<resources> + + <!-- Activity themes --> + + <style name="Theme.Base" parent="android:Theme.Holo.Light" /> + + <style name="AppTheme" parent="Theme.Base" /> + <!-- Widget styling --> + + <style name="Widget" /> + + <style name="Widget.SampleMessage"> + <item name="android:textAppearance">?android:textAppearanceMedium</item> + <item name="android:lineSpacingMultiplier">1.1</item> + </style> + + <style name="Widget.SampleMessageTile"> + <item name="android:background">@drawable/tile</item> + <item name="android:shadowColor">#7F000000</item> + <item name="android:shadowDy">-3.5</item> + <item name="android:shadowRadius">2</item> + </style> + + + <style name="Widget.SampleOutput"> + <item name="android:padding">@dimen/margin_medium</item> + <item name="android:textAppearance">?android:textAppearanceMedium</item> + <item name="android:lineSpacingMultiplier">1.1</item> + </style> + + <style name="Log" parent="Widget.SampleOutput"> + <item name="android:typeface">monospace</item> + </style> + +</resources> diff --git a/samples/browseable/StorageProvider/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/StorageProvider/src/com.example.android.common/activities/SampleActivityBase.java new file mode 100644 index 000000000..3228927b7 --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.common/activities/SampleActivityBase.java @@ -0,0 +1,52 @@ +/* +* Copyright 2013 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.example.android.common.activities; + +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; + +import com.example.android.common.logger.Log; +import com.example.android.common.logger.LogWrapper; + +/** + * Base launcher activity, to handle most of the common plumbing for samples. + */ +public class SampleActivityBase extends FragmentActivity { + + public static final String TAG = "SampleActivityBase"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected void onStart() { + super.onStart(); + initializeLogging(); + } + + /** Set up targets to receive log data */ + public void initializeLogging() { + // Using Log, front-end to the logging chain, emulates android.util.log method signatures. + // Wraps Android's native log framework + LogWrapper logWrapper = new LogWrapper(); + Log.setLogNode(logWrapper); + + Log.i(TAG, "Ready"); + } +} diff --git a/samples/browseable/StorageProvider/src/com.example.android.common/logger/Log.java b/samples/browseable/StorageProvider/src/com.example.android.common/logger/Log.java new file mode 100644 index 000000000..17503c568 --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.common/logger/Log.java @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.android.common.logger; + +/** + * Helper class for a list (or tree) of LoggerNodes. + * + * <p>When this is set as the head of the list, + * an instance of it can function as a drop-in replacement for {@link android.util.Log}. + * Most of the methods in this class server only to map a method call in Log to its equivalent + * in LogNode.</p> + */ +public class Log { + // Grabbing the native values from Android's native logging facilities, + // to make for easy migration and interop. + public static final int NONE = -1; + public static final int VERBOSE = android.util.Log.VERBOSE; + public static final int DEBUG = android.util.Log.DEBUG; + public static final int INFO = android.util.Log.INFO; + public static final int WARN = android.util.Log.WARN; + public static final int ERROR = android.util.Log.ERROR; + public static final int ASSERT = android.util.Log.ASSERT; + + // Stores the beginning of the LogNode topology. + private static LogNode mLogNode; + + /** + * Returns the next LogNode in the linked list. + */ + public static LogNode getLogNode() { + return mLogNode; + } + + /** + * Sets the LogNode data will be sent to. + */ + public static void setLogNode(LogNode node) { + mLogNode = node; + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void println(int priority, String tag, String msg, Throwable tr) { + if (mLogNode != null) { + mLogNode.println(priority, tag, msg, tr); + } + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + */ + public static void println(int priority, String tag, String msg) { + println(priority, tag, msg, null); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void v(String tag, String msg, Throwable tr) { + println(VERBOSE, tag, msg, tr); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void v(String tag, String msg) { + v(tag, msg, null); + } + + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void d(String tag, String msg, Throwable tr) { + println(DEBUG, tag, msg, tr); + } + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void d(String tag, String msg) { + d(tag, msg, null); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void i(String tag, String msg, Throwable tr) { + println(INFO, tag, msg, tr); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void i(String tag, String msg) { + i(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, String msg, Throwable tr) { + println(WARN, tag, msg, tr); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void w(String tag, String msg) { + w(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, Throwable tr) { + w(tag, null, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void e(String tag, String msg, Throwable tr) { + println(ERROR, tag, msg, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void e(String tag, String msg) { + e(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, String msg, Throwable tr) { + println(ASSERT, tag, msg, tr); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void wtf(String tag, String msg) { + wtf(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, Throwable tr) { + wtf(tag, null, tr); + } +} diff --git a/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogFragment.java new file mode 100644 index 000000000..b302acd4b --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogFragment.java @@ -0,0 +1,109 @@ +/* +* Copyright 2013 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* + * Copyright 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.common.logger; + +import android.graphics.Typeface; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ScrollView; + +/** + * Simple fraggment which contains a LogView and uses is to output log data it receives + * through the LogNode interface. + */ +public class LogFragment extends Fragment { + + private LogView mLogView; + private ScrollView mScrollView; + + public LogFragment() {} + + public View inflateViews() { + mScrollView = new ScrollView(getActivity()); + ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT); + mScrollView.setLayoutParams(scrollParams); + + mLogView = new LogView(getActivity()); + ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); + logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; + mLogView.setLayoutParams(logParams); + mLogView.setClickable(true); + mLogView.setFocusable(true); + mLogView.setTypeface(Typeface.MONOSPACE); + + // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! + int paddingDips = 16; + double scale = getResources().getDisplayMetrics().density; + int paddingPixels = (int) ((paddingDips * (scale)) + .5); + mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); + mLogView.setCompoundDrawablePadding(paddingPixels); + + mLogView.setGravity(Gravity.BOTTOM); + mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); + + mScrollView.addView(mLogView); + return mScrollView; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + View result = inflateViews(); + + mLogView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) {} + + @Override + public void afterTextChanged(Editable s) { + mScrollView.fullScroll(ScrollView.FOCUS_DOWN); + } + }); + return result; + } + + public LogView getLogView() { + return mLogView; + } +}
\ No newline at end of file diff --git a/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogNode.java b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogNode.java new file mode 100644 index 000000000..bc37cabc0 --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogNode.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.android.common.logger; + +/** + * Basic interface for a logging system that can output to one or more targets. + * Note that in addition to classes that will output these logs in some format, + * one can also implement this interface over a filter and insert that in the chain, + * such that no targets further down see certain data, or see manipulated forms of the data. + * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data + * it received to HTML and sent it along to the next node in the chain, without printing it + * anywhere. + */ +public interface LogNode { + + /** + * Instructs first LogNode in the list to print the log data provided. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public void println(int priority, String tag, String msg, Throwable tr); + +} diff --git a/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogView.java b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogView.java new file mode 100644 index 000000000..c01542b91 --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogView.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.android.common.logger; + +import android.app.Activity; +import android.content.Context; +import android.util.*; +import android.widget.TextView; + +/** Simple TextView which is used to output log data received through the LogNode interface. +*/ +public class LogView extends TextView implements LogNode { + + public LogView(Context context) { + super(context); + } + + public LogView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public LogView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + /** + * Formats the log data and prints it out to the LogView. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + + + String priorityStr = null; + + // For the purposes of this View, we want to print the priority as readable text. + switch(priority) { + case android.util.Log.VERBOSE: + priorityStr = "VERBOSE"; + break; + case android.util.Log.DEBUG: + priorityStr = "DEBUG"; + break; + case android.util.Log.INFO: + priorityStr = "INFO"; + break; + case android.util.Log.WARN: + priorityStr = "WARN"; + break; + case android.util.Log.ERROR: + priorityStr = "ERROR"; + break; + case android.util.Log.ASSERT: + priorityStr = "ASSERT"; + break; + default: + break; + } + + // Handily, the Log class has a facility for converting a stack trace into a usable string. + String exceptionStr = null; + if (tr != null) { + exceptionStr = android.util.Log.getStackTraceString(tr); + } + + // Take the priority, tag, message, and exception, and concatenate as necessary + // into one usable line of text. + final StringBuilder outputBuilder = new StringBuilder(); + + String delimiter = "\t"; + appendIfNotNull(outputBuilder, priorityStr, delimiter); + appendIfNotNull(outputBuilder, tag, delimiter); + appendIfNotNull(outputBuilder, msg, delimiter); + appendIfNotNull(outputBuilder, exceptionStr, delimiter); + + // In case this was originally called from an AsyncTask or some other off-UI thread, + // make sure the update occurs within the UI thread. + ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { + @Override + public void run() { + // Display the text we just generated within the LogView. + appendToLog(outputBuilder.toString()); + } + }))); + + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } + + public LogNode getNext() { + return mNext; + } + + public void setNext(LogNode node) { + mNext = node; + } + + /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since + * the logger takes so many arguments that might be null, this method helps cut out some of the + * agonizing tedium of writing the same 3 lines over and over. + * @param source StringBuilder containing the text to append to. + * @param addStr The String to append + * @param delimiter The String to separate the source and appended strings. A tab or comma, + * for instance. + * @return The fully concatenated String as a StringBuilder + */ + private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { + if (addStr != null) { + if (addStr.length() == 0) { + delimiter = ""; + } + + return source.append(addStr).append(delimiter); + } + return source; + } + + // The next LogNode in the chain. + LogNode mNext; + + /** Outputs the string as a new line of log data in the LogView. */ + public void appendToLog(String s) { + append("\n" + s); + } + + +} diff --git a/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogWrapper.java new file mode 100644 index 000000000..16a9e7ba2 --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.common/logger/LogWrapper.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.android.common.logger; + +import android.util.Log; + +/** + * Helper class which wraps Android's native Log utility in the Logger interface. This way + * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. + */ +public class LogWrapper implements LogNode { + + // For piping: The next node to receive Log data after this one has done its work. + private LogNode mNext; + + /** + * Returns the next LogNode in the linked list. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + + /** + * Prints data out to the console using Android's native log mechanism. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + // There actually are log methods that don't take a msg parameter. For now, + // if that's the case, just convert null to the empty string and move on. + String useMsg = msg; + if (useMsg == null) { + useMsg = ""; + } + + // If an exeption was provided, convert that exception to a usable string and attach + // it to the end of the msg method. + if (tr != null) { + msg += "\n" + Log.getStackTraceString(tr); + } + + // This is functionally identical to Log.x(tag, useMsg); + // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) + Log.println(priority, tag, useMsg); + + // If this isn't the last node in the chain, move things along. + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } +} diff --git a/samples/browseable/StorageProvider/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/StorageProvider/src/com.example.android.common/logger/MessageOnlyLogFilter.java new file mode 100644 index 000000000..19967dcd4 --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.common/logger/MessageOnlyLogFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.android.common.logger; + +/** + * Simple {@link LogNode} filter, removes everything except the message. + * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, + * just easy-to-read message updates as they're happening. + */ +public class MessageOnlyLogFilter implements LogNode { + + LogNode mNext; + + /** + * Takes the "next" LogNode as a parameter, to simplify chaining. + * + * @param next The next LogNode in the pipeline. + */ + public MessageOnlyLogFilter(LogNode next) { + mNext = next; + } + + public MessageOnlyLogFilter() { + } + + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + if (mNext != null) { + getNext().println(Log.NONE, null, msg, null); + } + } + + /** + * Returns the next LogNode in the chain. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + +} diff --git a/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MainActivity.java b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MainActivity.java new file mode 100644 index 000000000..5f04a62b9 --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MainActivity.java @@ -0,0 +1,80 @@ +/* +* Copyright 2013 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + + + +package com.example.android.storageprovider; + +import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.view.Menu; + +import com.example.android.common.activities.SampleActivityBase; +import com.example.android.common.logger.Log; +import com.example.android.common.logger.LogFragment; +import com.example.android.common.logger.LogWrapper; +import com.example.android.common.logger.MessageOnlyLogFilter; + +/** + * A simple launcher activity containing a summary sample description + * and a few action bar buttons. + */ +public class MainActivity extends SampleActivityBase { + + public static final String TAG = "MainActivity"; + + public static final String FRAGTAG = "MyCloudFragment"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + if (getSupportFragmentManager().findFragmentByTag(FRAGTAG) == null ) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + MyCloudFragment fragment = new MyCloudFragment(); + transaction.add(fragment, FRAGTAG); + transaction.commit(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + /** Create a chain of targets that will receive log data */ + @Override + public void initializeLogging() { + // Wraps Android's native log framework. + LogWrapper logWrapper = new LogWrapper(); + // Using Log, front-end to the logging chain, emulates android.util.log method signatures. + Log.setLogNode(logWrapper); + + // Filter strips out everything except the message text. + MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter(); + logWrapper.setNext(msgFilter); + + // On screen logging via a fragment with a TextView. + LogFragment logFragment = (LogFragment) getSupportFragmentManager() + .findFragmentById(R.id.log_fragment); + msgFilter.setNext(logFragment.getLogView()); + + Log.i(TAG, "Ready"); + } +} diff --git a/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MyCloudFragment.java b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MyCloudFragment.java new file mode 100644 index 000000000..f624e908a --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MyCloudFragment.java @@ -0,0 +1,105 @@ +/* +* Copyright 2013 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package com.example.android.storageprovider; + + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.provider.DocumentsContract; +import android.support.v4.app.Fragment; +import android.view.Menu; +import android.view.MenuItem; + +import com.example.android.common.logger.Log; + +/** + * Toggles the user's login status via a login menu option, and enables/disables the cloud storage + * content provider. + */ +public class MyCloudFragment extends Fragment { + + private static final String TAG = "MyCloudFragment"; + private static final String AUTHORITY = "com.example.android.storageprovider.documents"; + private boolean mLoggedIn = false; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mLoggedIn = readLoginValue(); + + setHasOptionsMenu(true); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + MenuItem item = menu.findItem(R.id.sample_action); + item.setTitle(mLoggedIn ? R.string.log_out : R.string.log_in); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.sample_action) { + toggleLogin(); + item.setTitle(mLoggedIn ? R.string.log_out : R.string.log_in); + + // BEGIN_INCLUDE(notify_change) + // Notify the system that the status of our roots has changed. This will trigger + // a call to MyCloudProvider.queryRoots() and force a refresh of the system + // picker UI. It's important to call this or stale results may persist. + getActivity().getContentResolver().notifyChange(DocumentsContract.buildRootsUri + (AUTHORITY), null, false); + // END_INCLUDE(notify_change) + } + return true; + } + + /** + * Dummy function to change the user's authorization status. + */ + private void toggleLogin() { + // Replace this with your standard method of authentication to determine if your app + // should make the user's documents available. + mLoggedIn = !mLoggedIn; + writeLoginValue(mLoggedIn); + Log.i(TAG, getString(mLoggedIn ? R.string.logged_in_info : R.string.logged_out_info)); + } + + /** + * Dummy function to save whether the user is logged in. + */ + private void writeLoginValue(boolean loggedIn) { + final SharedPreferences sharedPreferences = + getActivity().getSharedPreferences(getString(R.string.app_name), + getActivity().MODE_PRIVATE); + sharedPreferences.edit().putBoolean(getString(R.string.key_logged_in), loggedIn).commit(); + } + + /** + * Dummy function to determine whether the user is logged in. + */ + private boolean readLoginValue() { + final SharedPreferences sharedPreferences = + getActivity().getSharedPreferences(getString(R.string.app_name), + getActivity().MODE_PRIVATE); + return sharedPreferences.getBoolean(getString(R.string.key_logged_in), false); + } + +} + + diff --git a/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MyCloudProvider.java b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MyCloudProvider.java new file mode 100644 index 000000000..d8be8138b --- /dev/null +++ b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MyCloudProvider.java @@ -0,0 +1,621 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.example.android.storageprovider; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.AssetFileDescriptor; +import android.content.res.TypedArray; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.graphics.Point; +import android.os.CancellationSignal; +import android.os.Handler; +import android.os.ParcelFileDescriptor; +import android.provider.DocumentsContract.Document; +import android.provider.DocumentsContract.Root; +import android.provider.DocumentsProvider; +import android.webkit.MimeTypeMap; + +import com.example.android.common.logger.Log; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.PriorityQueue; +import java.util.Set; + +/** + * Manages documents and exposes them to the Android system for sharing. + */ +public class MyCloudProvider extends DocumentsProvider { + private static final String TAG = MyCloudProvider.class.getSimpleName(); + + // Use these as the default columns to return information about a root if no specific + // columns are requested in a query. + private static final String[] DEFAULT_ROOT_PROJECTION = new String[]{ + Root.COLUMN_ROOT_ID, + Root.COLUMN_MIME_TYPES, + Root.COLUMN_FLAGS, + Root.COLUMN_ICON, + Root.COLUMN_TITLE, + Root.COLUMN_SUMMARY, + Root.COLUMN_DOCUMENT_ID, + Root.COLUMN_AVAILABLE_BYTES + }; + + // Use these as the default columns to return information about a document if no specific + // columns are requested in a query. + private static final String[] DEFAULT_DOCUMENT_PROJECTION = new String[]{ + Document.COLUMN_DOCUMENT_ID, + Document.COLUMN_MIME_TYPE, + Document.COLUMN_DISPLAY_NAME, + Document.COLUMN_LAST_MODIFIED, + Document.COLUMN_FLAGS, + Document.COLUMN_SIZE + }; + + // No official policy on how many to return, but make sure you do limit the number of recent + // and search results. + private static final int MAX_SEARCH_RESULTS = 20; + private static final int MAX_LAST_MODIFIED = 5; + + private static final String ROOT = "root"; + + // A file object at the root of the file hierarchy. Depending on your implementation, the root + // does not need to be an existing file system directory. For example, a tag-based document + // provider might return a directory containing all tags, represented as child directories. + private File mBaseDir; + + @Override + public boolean onCreate() { + Log.v(TAG, "onCreate"); + + mBaseDir = getContext().getFilesDir(); + + writeDummyFilesToStorage(); + + return true; + } + + // BEGIN_INCLUDE(query_roots) + @Override + public Cursor queryRoots(String[] projection) throws FileNotFoundException { + Log.v(TAG, "queryRoots"); + + // Create a cursor with either the requested fields, or the default projection. This + // cursor is returned to the Android system picker UI and used to display all roots from + // this provider. + final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); + + // If user is not logged in, return an empty root cursor. This removes our provider from + // the list entirely. + if (!isUserLoggedIn()) { + return result; + } + + // It's possible to have multiple roots (e.g. for multiple accounts in the same app) - + // just add multiple cursor rows. + // Construct one row for a root called "MyCloud". + final MatrixCursor.RowBuilder row = result.newRow(); + + row.add(Root.COLUMN_ROOT_ID, ROOT); + row.add(Root.COLUMN_SUMMARY, getContext().getString(R.string.root_summary)); + + // FLAG_SUPPORTS_CREATE means at least one directory under the root supports creating + // documents. FLAG_SUPPORTS_RECENTS means your application's most recently used + // documents will show up in the "Recents" category. FLAG_SUPPORTS_SEARCH allows users + // to search all documents the application shares. + row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | + Root.FLAG_SUPPORTS_RECENTS | + Root.FLAG_SUPPORTS_SEARCH); + + // COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider). + row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_name)); + + // This document id must be unique within this provider and consistent across time. The + // system picker UI may save it and refer to it later. + row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(mBaseDir)); + + // The child MIME types are used to filter the roots and only present to the user roots + // that contain the desired type somewhere in their file hierarchy. + row.add(Root.COLUMN_MIME_TYPES, getChildMimeTypes(mBaseDir)); + row.add(Root.COLUMN_AVAILABLE_BYTES, mBaseDir.getFreeSpace()); + row.add(Root.COLUMN_ICON, R.drawable.ic_launcher); + + return result; + } + // END_INCLUDE(query_roots) + + // BEGIN_INCLUDE(query_recent_documents) + @Override + public Cursor queryRecentDocuments(String rootId, String[] projection) + throws FileNotFoundException { + Log.v(TAG, "queryRecentDocuments"); + + // This example implementation walks a local file structure to find the most recently + // modified files. Other implementations might include making a network call to query a + // server. + + // Create a cursor with the requested projection, or the default projection. + final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); + + final File parent = getFileForDocId(rootId); + + // Create a queue to store the most recent documents, which orders by last modified. + PriorityQueue<File> lastModifiedFiles = new PriorityQueue<File>(5, new Comparator<File>() { + public int compare(File i, File j) { + return Long.compare(i.lastModified(), j.lastModified()); + } + }); + + // Iterate through all files and directories in the file structure under the root. If + // the file is more recent than the least recently modified, add it to the queue, + // limiting the number of results. + final LinkedList<File> pending = new LinkedList<File>(); + + // Start by adding the parent to the list of files to be processed + pending.add(parent); + + // Do while we still have unexamined files + while (!pending.isEmpty()) { + // Take a file from the list of unprocessed files + final File file = pending.removeFirst(); + if (file.isDirectory()) { + // If it's a directory, add all its children to the unprocessed list + Collections.addAll(pending, file.listFiles()); + } else { + // If it's a file, add it to the ordered queue. + lastModifiedFiles.add(file); + } + } + + // Add the most recent files to the cursor, not exceeding the max number of results. + for (int i = 0; i < Math.min(MAX_LAST_MODIFIED + 1, lastModifiedFiles.size()); i++) { + final File file = lastModifiedFiles.remove(); + includeFile(result, null, file); + } + return result; + } + // END_INCLUDE(query_recent_documents) + + // BEGIN_INCLUDE(query_search_documents) + @Override + public Cursor querySearchDocuments(String rootId, String query, String[] projection) + throws FileNotFoundException { + Log.v(TAG, "querySearchDocuments"); + + // Create a cursor with the requested projection, or the default projection. + final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); + final File parent = getFileForDocId(rootId); + + // This example implementation searches file names for the query and doesn't rank search + // results, so we can stop as soon as we find a sufficient number of matches. Other + // implementations might use other data about files, rather than the file name, to + // produce a match; it might also require a network call to query a remote server. + + // Iterate through all files in the file structure under the root until we reach the + // desired number of matches. + final LinkedList<File> pending = new LinkedList<File>(); + + // Start by adding the parent to the list of files to be processed + pending.add(parent); + + // Do while we still have unexamined files, and fewer than the max search results + while (!pending.isEmpty() && result.getCount() < MAX_SEARCH_RESULTS) { + // Take a file from the list of unprocessed files + final File file = pending.removeFirst(); + if (file.isDirectory()) { + // If it's a directory, add all its children to the unprocessed list + Collections.addAll(pending, file.listFiles()); + } else { + // If it's a file and it matches, add it to the result cursor. + if (file.getName().toLowerCase().contains(query)) { + includeFile(result, null, file); + } + } + } + return result; + } + // END_INCLUDE(query_search_documents) + + // BEGIN_INCLUDE(open_document_thumbnail) + @Override + public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint, + CancellationSignal signal) + throws FileNotFoundException { + Log.v(TAG, "openDocumentThumbnail"); + + final File file = getFileForDocId(documentId); + final ParcelFileDescriptor pfd = + ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); + return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH); + } + // END_INCLUDE(open_document_thumbnail) + + // BEGIN_INCLUDE(query_document) + @Override + public Cursor queryDocument(String documentId, String[] projection) + throws FileNotFoundException { + Log.v(TAG, "queryDocument"); + + // Create a cursor with the requested projection, or the default projection. + final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); + includeFile(result, documentId, null); + return result; + } + // END_INCLUDE(query_document) + + // BEGIN_INCLUDE(query_child_documents) + @Override + public Cursor queryChildDocuments(String parentDocumentId, String[] projection, + String sortOrder) throws FileNotFoundException { + Log.v(TAG, "queryChildDocuments, parentDocumentId: " + + parentDocumentId + + " sortOrder: " + + sortOrder); + + final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); + final File parent = getFileForDocId(parentDocumentId); + for (File file : parent.listFiles()) { + includeFile(result, null, file); + } + return result; + } + // END_INCLUDE(query_child_documents) + + + // BEGIN_INCLUDE(open_document) + @Override + public ParcelFileDescriptor openDocument(final String documentId, final String mode, + CancellationSignal signal) + throws FileNotFoundException { + Log.v(TAG, "openDocument, mode: " + mode); + // It's OK to do network operations in this method to download the document, as long as you + // periodically check the CancellationSignal. If you have an extremely large file to + // transfer from the network, a better solution may be pipes or sockets + // (see ParcelFileDescriptor for helper methods). + + final File file = getFileForDocId(documentId); + final int accessMode = ParcelFileDescriptor.parseMode(mode); + + final boolean isWrite = (mode.indexOf('w') != -1); + if (isWrite) { + // Attach a close listener if the document is opened in write mode. + try { + Handler handler = new Handler(getContext().getMainLooper()); + return ParcelFileDescriptor.open(file, accessMode, handler, + new ParcelFileDescriptor.OnCloseListener() { + @Override + public void onClose(IOException e) { + + // Update the file with the cloud server. The client is done writing. + Log.i(TAG, "A file with id " + documentId + " has been closed! Time to " + + "update the server."); + } + + }); + } catch (IOException e) { + throw new FileNotFoundException("Failed to open document with id " + documentId + + " and mode " + mode); + } + } else { + return ParcelFileDescriptor.open(file, accessMode); + } + } + // END_INCLUDE(open_document) + + + // BEGIN_INCLUDE(create_document) + @Override + public String createDocument(String documentId, String mimeType, String displayName) + throws FileNotFoundException { + Log.v(TAG, "createDocument"); + + File parent = getFileForDocId(documentId); + File file = new File(parent.getPath(), displayName); + try { + file.createNewFile(); + file.setWritable(true); + file.setReadable(true); + } catch (IOException e) { + throw new FileNotFoundException("Failed to create document with name " + + displayName +" and documentId " + documentId); + } + return getDocIdForFile(file); + } + // END_INCLUDE(create_document) + + // BEGIN_INCLUDE(delete_document) + @Override + public void deleteDocument(String documentId) throws FileNotFoundException { + Log.v(TAG, "deleteDocument"); + File file = getFileForDocId(documentId); + if (file.delete()) { + Log.i(TAG, "Deleted file with id " + documentId); + } else { + throw new FileNotFoundException("Failed to delete document with id " + documentId); + } + } + // END_INCLUDE(delete_document) + + + @Override + public String getDocumentType(String documentId) throws FileNotFoundException { + File file = getFileForDocId(documentId); + return getTypeForFile(file); + } + + /** + * @param projection the requested root column projection + * @return either the requested root column projection, or the default projection if the + * requested projection is null. + */ + private static String[] resolveRootProjection(String[] projection) { + return projection != null ? projection : DEFAULT_ROOT_PROJECTION; + } + + private static String[] resolveDocumentProjection(String[] projection) { + return projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION; + } + + /** + * Get a file's MIME type + * + * @param file the File object whose type we want + * @return the MIME type of the file + */ + private static String getTypeForFile(File file) { + if (file.isDirectory()) { + return Document.MIME_TYPE_DIR; + } else { + return getTypeForName(file.getName()); + } + } + + /** + * Get the MIME data type of a document, given its filename. + * + * @param name the filename of the document + * @return the MIME data type of a document + */ + private static String getTypeForName(String name) { + final int lastDot = name.lastIndexOf('.'); + if (lastDot >= 0) { + final String extension = name.substring(lastDot + 1); + final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + if (mime != null) { + return mime; + } + } + return "application/octet-stream"; + } + + /** + * Gets a string of unique MIME data types a directory supports, separated by newlines. This + * should not change. + * + * @param parent the File for the parent directory + * @return a string of the unique MIME data types the parent directory supports + */ + private String getChildMimeTypes(File parent) { + Set<String> mimeTypes = new HashSet<String>(); + mimeTypes.add("image/*"); + mimeTypes.add("text/*"); + mimeTypes.add("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + + // Flatten the list into a string and insert newlines between the MIME type strings. + StringBuilder mimeTypesString = new StringBuilder(); + for (String mimeType : mimeTypes) { + mimeTypesString.append(mimeType).append("\n"); + } + + return mimeTypesString.toString(); + } + + /** + * Get the document ID given a File. The document id must be consistent across time. Other + * applications may save the ID and use it to reference documents later. + * <p/> + * This implementation is specific to this demo. It assumes only one root and is built + * directly from the file structure. However, it is possible for a document to be a child of + * multiple directories (for example "android" and "images"), in which case the file must have + * the same consistent, unique document ID in both cases. + * + * @param file the File whose document ID you want + * @return the corresponding document ID + */ + private String getDocIdForFile(File file) { + String path = file.getAbsolutePath(); + + // Start at first char of path under root + final String rootPath = mBaseDir.getPath(); + if (rootPath.equals(path)) { + path = ""; + } else if (rootPath.endsWith("/")) { + path = path.substring(rootPath.length()); + } else { + path = path.substring(rootPath.length() + 1); + } + + return "root" + ':' + path; + } + + /** + * Add a representation of a file to a cursor. + * + * @param result the cursor to modify + * @param docId the document ID representing the desired file (may be null if given file) + * @param file the File object representing the desired file (may be null if given docID) + * @throws java.io.FileNotFoundException + */ + private void includeFile(MatrixCursor result, String docId, File file) + throws FileNotFoundException { + if (docId == null) { + docId = getDocIdForFile(file); + } else { + file = getFileForDocId(docId); + } + + int flags = 0; + + if (file.isDirectory()) { + // Request the folder to lay out as a grid rather than a list. This also allows a larger + // thumbnail to be displayed for each image. + // flags |= Document.FLAG_DIR_PREFERS_GRID; + + // Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory. + if (file.isDirectory() && file.canWrite()) { + flags |= Document.FLAG_DIR_SUPPORTS_CREATE; + } + } else if (file.canWrite()) { + // If the file is writable set FLAG_SUPPORTS_WRITE and + // FLAG_SUPPORTS_DELETE + flags |= Document.FLAG_SUPPORTS_WRITE; + flags |= Document.FLAG_SUPPORTS_DELETE; + } + + final String displayName = file.getName(); + final String mimeType = getTypeForFile(file); + + if (mimeType.startsWith("image/")) { + // Allow the image to be represented by a thumbnail rather than an icon + flags |= Document.FLAG_SUPPORTS_THUMBNAIL; + } + + final MatrixCursor.RowBuilder row = result.newRow(); + row.add(Document.COLUMN_DOCUMENT_ID, docId); + row.add(Document.COLUMN_DISPLAY_NAME, displayName); + row.add(Document.COLUMN_SIZE, file.length()); + row.add(Document.COLUMN_MIME_TYPE, mimeType); + row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); + row.add(Document.COLUMN_FLAGS, flags); + + // Add a custom icon + row.add(Document.COLUMN_ICON, R.drawable.ic_launcher); + } + + /** + * Translate your custom URI scheme into a File object. + * + * @param docId the document ID representing the desired file + * @return a File represented by the given document ID + * @throws java.io.FileNotFoundException + */ + private File getFileForDocId(String docId) throws FileNotFoundException { + File target = mBaseDir; + if (docId.equals(ROOT)) { + return target; + } + final int splitIndex = docId.indexOf(':', 1); + if (splitIndex < 0) { + throw new FileNotFoundException("Missing root for " + docId); + } else { + final String path = docId.substring(splitIndex + 1); + target = new File(target, path); + if (!target.exists()) { + throw new FileNotFoundException("Missing file for " + docId + " at " + target); + } + return target; + } + } + + + /** + * Preload sample files packaged in the apk into the internal storage directory. This is a + * dummy function specific to this demo. The MyCloud mock cloud service doesn't actually + * have a backend, so it simulates by reading content from the device's internal storage. + */ + private void writeDummyFilesToStorage() { + if (mBaseDir.list().length > 0) { + return; + } + + int[] imageResIds = getResourceIdArray(R.array.image_res_ids); + for (int resId : imageResIds) { + writeFileToInternalStorage(resId, ".jpeg"); + } + + int[] textResIds = getResourceIdArray(R.array.text_res_ids); + for (int resId : textResIds) { + writeFileToInternalStorage(resId, ".txt"); + } + + int[] docxResIds = getResourceIdArray(R.array.docx_res_ids); + for (int resId : docxResIds) { + writeFileToInternalStorage(resId, ".docx"); + } + } + + /** + * Write a file to internal storage. Used to set up our dummy "cloud server". + * + * @param resId the resource ID of the file to write to internal storage + * @param extension the file extension (ex. .png, .mp3) + */ + private void writeFileToInternalStorage(int resId, String extension) { + InputStream ins = getContext().getResources().openRawResource(resId); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + int size; + byte[] buffer = new byte[1024]; + try { + while ((size = ins.read(buffer, 0, 1024)) >= 0) { + outputStream.write(buffer, 0, size); + } + ins.close(); + buffer = outputStream.toByteArray(); + String filename = getContext().getResources().getResourceEntryName(resId) + extension; + FileOutputStream fos = getContext().openFileOutput(filename, Context.MODE_PRIVATE); + fos.write(buffer); + fos.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + private int[] getResourceIdArray(int arrayResId) { + TypedArray ar = getContext().getResources().obtainTypedArray(arrayResId); + int len = ar.length(); + int[] resIds = new int[len]; + for (int i = 0; i < len; i++) { + resIds[i] = ar.getResourceId(i, 0); + } + ar.recycle(); + return resIds; + } + + /** + * Dummy function to determine whether the user is logged in. + */ + private boolean isUserLoggedIn() { + final SharedPreferences sharedPreferences = + getContext().getSharedPreferences(getContext().getString(R.string.app_name), + Context.MODE_PRIVATE); + return sharedPreferences.getBoolean(getContext().getString(R.string.key_logged_in), false); + } + + +} diff --git a/samples/browseable/TextLinkify/_index.jd b/samples/browseable/TextLinkify/_index.jd index cab17fd21..30499c54b 100644 --- a/samples/browseable/TextLinkify/_index.jd +++ b/samples/browseable/TextLinkify/_index.jd @@ -5,10 +5,10 @@ page.tags="TextLinkify" sample.group=Views @jd:body -<p>This sample demonstrates how to add clickable links to a +<p>This sample demonstrates how to add clickable links to a {@link android.widget.TextView}, by using these techniques: <ul> -<li>Setting the {@link android.widget.TextView#attr_android:autoLink} property +<li>Setting the {@link android.R.styleable#TextView_autoLink} property to automatically convert the text to a link.</li> <li>Parsing a String as HTML</li> <li>Manually by constructing a {@link android.text.SpannableString}.</li> |
