diff options
684 files changed, 10105 insertions, 10212 deletions
diff --git a/samples/browseable/ActionBarCompat-Basic/AndroidManifest.xml b/samples/browseable/ActionBarCompat-Basic/AndroidManifest.xml index 332c055be..2e19220d2 100644 --- a/samples/browseable/ActionBarCompat-Basic/AndroidManifest.xml +++ b/samples/browseable/ActionBarCompat-Basic/AndroidManifest.xml @@ -21,9 +21,7 @@ android:versionName="1.0"> <!-- ActionBarCompat provides an Action Bar from API v7 onwards --> - <uses-sdk - android:minSdkVersion="7" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:icon="@drawable/ic_launcher" diff --git a/samples/browseable/ActionBarCompat-Basic/_index.jd b/samples/browseable/ActionBarCompat-Basic/_index.jd index 4e7737126..0d3a2d878 100644 --- a/samples/browseable/ActionBarCompat-Basic/_index.jd +++ b/samples/browseable/ActionBarCompat-Basic/_index.jd @@ -1,15 +1,12 @@ - - - page.tags="ActionBarCompat-Basic" sample.group=UI @jd:body -<p>This sample demonstrates how to create a basic action bar that displays -action items. The sample shows how to inflate items from a menu resource, and -how to add items programatically. To reduce clutter, rarely used actions are -displayed in an action bar overflow.</p> -<p>The activity in this sample extends from -{@link android.support.v7.app.ActionBarActivity}, which provides the -functionality necessary to display a compatible action bar on devices -running Android 2.1 and higher.</p> +<p> + + This sample shows you how to use ActionBarCompat to create a basic Activity which + displays action items. It covers inflating items from a menu resource, as well as adding + an item in code. Items that are not shown as action items on the Action Bar are + displayed in the action bar overflow. + + </p> diff --git a/samples/browseable/ActionBarCompat-Basic/res/values-v21/template-styles.xml b/samples/browseable/ActionBarCompat-Basic/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActionBarCompat-Basic/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/ActionBarCompat-Basic/res/values/base-strings.xml b/samples/browseable/ActionBarCompat-Basic/res/values/base-strings.xml index 8edd1b232..18f71a67d 100644 --- a/samples/browseable/ActionBarCompat-Basic/res/values/base-strings.xml +++ b/samples/browseable/ActionBarCompat-Basic/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">ActionBarCompat-Basic</string> <string name="intro_message"> diff --git a/samples/browseable/ActionBarCompat-ListPopupMenu/AndroidManifest.xml b/samples/browseable/ActionBarCompat-ListPopupMenu/AndroidManifest.xml index 114053ed6..695d4e07e 100644 --- a/samples/browseable/ActionBarCompat-ListPopupMenu/AndroidManifest.xml +++ b/samples/browseable/ActionBarCompat-ListPopupMenu/AndroidManifest.xml @@ -21,9 +21,7 @@ android:versionName="1.0"> <!-- ActionBarCompat provides an implementation of Popup Menu from API v7 onwards --> - <uses-sdk - android:minSdkVersion="7" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:icon="@drawable/ic_launcher" diff --git a/samples/browseable/ActionBarCompat-ListPopupMenu/_index.jd b/samples/browseable/ActionBarCompat-ListPopupMenu/_index.jd index 9da5bdd19..8696da2ff 100644 --- a/samples/browseable/ActionBarCompat-ListPopupMenu/_index.jd +++ b/samples/browseable/ActionBarCompat-ListPopupMenu/_index.jd @@ -1,14 +1,10 @@ - - - page.tags="ActionBarCompat-ListPopupMenu" sample.group=UI @jd:body -<p>This sample demonstrates how to use a backward compatible -{@link android.support.v7.widget.PopupMenu PopupMenu} to create a list, where -each list item contains a dropdown menu.</p> -<p>The activity in this sample extends from -{@link android.support.v7.app.ActionBarActivity}, which provides the -functionality necessary to display a compatible action bar on devices -running Android 2.1 and higher.</p> +<p> + + This sample shows you how to use {@link android.support.v7.widget.PopupMenu PopupMenu} + from ActionBarCompat to create a list, with each item having a dropdown menu. + + </p> diff --git a/samples/browseable/ActionBarCompat-ListPopupMenu/res/values-v21/template-styles.xml b/samples/browseable/ActionBarCompat-ListPopupMenu/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActionBarCompat-ListPopupMenu/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/ActionBarCompat-ListPopupMenu/res/values/base-strings.xml b/samples/browseable/ActionBarCompat-ListPopupMenu/res/values/base-strings.xml index 130e2daa3..db43f8c6c 100644 --- a/samples/browseable/ActionBarCompat-ListPopupMenu/res/values/base-strings.xml +++ b/samples/browseable/ActionBarCompat-ListPopupMenu/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">ActionBarCompat-ListPopupMenu</string> <string name="intro_message"> diff --git a/samples/browseable/ActionBarCompat-ShareActionProvider/AndroidManifest.xml b/samples/browseable/ActionBarCompat-ShareActionProvider/AndroidManifest.xml index be1ed4961..18dfc27fd 100644 --- a/samples/browseable/ActionBarCompat-ShareActionProvider/AndroidManifest.xml +++ b/samples/browseable/ActionBarCompat-ShareActionProvider/AndroidManifest.xml @@ -23,9 +23,7 @@ <!-- ActionBarCompat provides an Action Bar from API v7 onwards --> - <uses-sdk - android:minSdkVersion="7" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:icon="@drawable/ic_launcher" diff --git a/samples/browseable/ActionBarCompat-ShareActionProvider/_index.jd b/samples/browseable/ActionBarCompat-ShareActionProvider/_index.jd index 63ac59ade..6752a39a4 100644 --- a/samples/browseable/ActionBarCompat-ShareActionProvider/_index.jd +++ b/samples/browseable/ActionBarCompat-ShareActionProvider/_index.jd @@ -1,14 +1,10 @@ - - - page.tags="ActionBarCompat-ShareActionProvider" sample.group=UI @jd:body -<p>This sample demonstrates how to use a -context-sensitive {@link android.support.v7.widget.ShareActionProvider} that is -backward compatible.</p> -<p>The activity in this sample extends from -{@link android.support.v7.app.ActionBarActivity}, which provides the -functionality necessary to display a compatible action bar on devices -running Android 2.1 and higher.</p> +<p> + + This sample shows you how a provide a context-sensitive ShareActionProvider with + ActionBarCompat, backwards compatible to API v7. + + </p> diff --git a/samples/browseable/ActionBarCompat-ShareActionProvider/res/values-v21/template-styles.xml b/samples/browseable/ActionBarCompat-ShareActionProvider/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActionBarCompat-ShareActionProvider/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/ActionBarCompat-ShareActionProvider/res/values/base-strings.xml b/samples/browseable/ActionBarCompat-ShareActionProvider/res/values/base-strings.xml index 904f4f1b2..2e0aae49d 100644 --- a/samples/browseable/ActionBarCompat-ShareActionProvider/res/values/base-strings.xml +++ b/samples/browseable/ActionBarCompat-ShareActionProvider/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">ActionBarCompat-ShareActionProvider</string> <string name="intro_message"> diff --git a/samples/browseable/ActionBarCompat-Styled/AndroidManifest.xml b/samples/browseable/ActionBarCompat-Styled/AndroidManifest.xml index 06394c705..b9d266cf3 100644 --- a/samples/browseable/ActionBarCompat-Styled/AndroidManifest.xml +++ b/samples/browseable/ActionBarCompat-Styled/AndroidManifest.xml @@ -20,9 +20,7 @@ android:versionCode="1" android:versionName="1.0" > - <uses-sdk - android:minSdkVersion="7" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <!-- Theme is set on the application so that our custom theme is used by diff --git a/samples/browseable/ActionBarCompat-Styled/_index.jd b/samples/browseable/ActionBarCompat-Styled/_index.jd index 06fee1aaa..f2f3b3c33 100644 --- a/samples/browseable/ActionBarCompat-Styled/_index.jd +++ b/samples/browseable/ActionBarCompat-Styled/_index.jd @@ -1,13 +1,10 @@ - - - page.tags="ActionBarCompat-Styled" sample.group=UI @jd:body -<p>This sample demonstrates how to use a backward compatible -{@link android.support.v7.app.ActionBar} with a customized theme.</p> -<p>The activity in this sample extends from -{@link android.support.v7.app.ActionBarActivity}, which provides the -functionality necessary to display a compatible action bar on devices -running Android 2.1 and higher.</p> +<p> + + This sample shows you how to use ActionBarCompat with a customized theme. It utilizes a + split action bar when running on a device with a narrow display, and show three tabs. + + </p> diff --git a/samples/browseable/ActionBarCompat-Styled/res/values-v21/template-styles.xml b/samples/browseable/ActionBarCompat-Styled/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActionBarCompat-Styled/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/ActionBarCompat-Styled/res/values/base-strings.xml b/samples/browseable/ActionBarCompat-Styled/res/values/base-strings.xml index 7adb0c6eb..324726d76 100644 --- a/samples/browseable/ActionBarCompat-Styled/res/values/base-strings.xml +++ b/samples/browseable/ActionBarCompat-Styled/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">ActionBarCompat-Styled</string> <string name="intro_message"> diff --git a/samples/browseable/ActivityInstrumentation/AndroidManifest.xml b/samples/browseable/ActivityInstrumentation/AndroidManifest.xml index 547d95ee7..da5c824e8 100644 --- a/samples/browseable/ActivityInstrumentation/AndroidManifest.xml +++ b/samples/browseable/ActivityInstrumentation/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/ActivityInstrumentation/_index.jd b/samples/browseable/ActivityInstrumentation/_index.jd index 369ff7eb6..77f1e2479 100644 --- a/samples/browseable/ActivityInstrumentation/_index.jd +++ b/samples/browseable/ActivityInstrumentation/_index.jd @@ -1,13 +1,10 @@ - - - page.tags="ActivityInstrumentation" sample.group=Testing @jd:body -<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 -Android Activity</a>.</p> +<p> + + This sample provides a basic example of using an InstrumentationTest to probe the + internal state of an Activity. + + </p> diff --git a/samples/browseable/ActivityInstrumentation/res/values-v21/template-styles.xml b/samples/browseable/ActivityInstrumentation/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ActivityInstrumentation/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/ActivityInstrumentation/res/values/base-strings.xml b/samples/browseable/ActivityInstrumentation/res/values/base-strings.xml index dfe40f4f6..2b3f65692 100644 --- a/samples/browseable/ActivityInstrumentation/res/values/base-strings.xml +++ b/samples/browseable/ActivityInstrumentation/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">ActivityInstrumentation</string> <string name="intro_message"> diff --git a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java index 741cd26ea..958900890 100644 --- a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java +++ b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/DetailActivity.java @@ -65,8 +65,8 @@ public class DetailActivity extends Activity { * This could be done in the layout XML, but exposing it via static variables allows easy * querying from other Activities */ - mHeaderImageView.setViewName(VIEW_NAME_HEADER_IMAGE); - mHeaderTitle.setViewName(VIEW_NAME_HEADER_TITLE); + mHeaderImageView.setTransitionName(VIEW_NAME_HEADER_IMAGE); + mHeaderTitle.setTransitionName(VIEW_NAME_HEADER_TITLE); // END_INCLUDE(detail_set_view_name) loadItem(item); diff --git a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java index 363099038..9c51789db 100644 --- a/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java +++ b/samples/browseable/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/MainActivity.java @@ -135,8 +135,8 @@ public class MainActivity extends Activity implements AdapterView.OnItemClickLis * As we're in an adapter we need to set each view's name dynamically, using the * item's ID so that the names are unique. */ - image.setViewName("grid:image:" + item.getId()); - name.setViewName("grid:name:" + item.getId()); + image.setTransitionName("grid:image:" + item.getId()); + name.setTransitionName("grid:name:" + item.getId()); // END_INCLUDE(grid_set_view_name) return view; diff --git a/samples/browseable/AdapterTransition/AndroidManifest.xml b/samples/browseable/AdapterTransition/AndroidManifest.xml index 01b414d9c..a998a4c7a 100644 --- a/samples/browseable/AdapterTransition/AndroidManifest.xml +++ b/samples/browseable/AdapterTransition/AndroidManifest.xml @@ -19,9 +19,7 @@ limitations under the License. android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="19" - android:targetSdkVersion="19"/> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/AdapterTransition/_index.jd b/samples/browseable/AdapterTransition/_index.jd index d5c48a392..a2d134ac5 100644 --- a/samples/browseable/AdapterTransition/_index.jd +++ b/samples/browseable/AdapterTransition/_index.jd @@ -1,12 +1,9 @@ - - - page.tags="AdapterTransition" sample.group=UI @jd:body <p> -{@link android.transition.Transition Transition} cannot be directly applied to -{@link android.widget.AdapterView AdapterView}s. This sample demonstrates how to -create a overlay layout and how to run a transition on it. -</p> + + Transition cannot be directly applied to AdapterViews. In this sample, we demonstrate how to create an overlay layout and run a Transition on it. Press the action bar button to toggle between ListView and GridView. + + </p> diff --git a/samples/browseable/AdapterTransition/res/values-v21/template-styles.xml b/samples/browseable/AdapterTransition/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/AdapterTransition/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/AdapterTransition/res/values/base-strings.xml b/samples/browseable/AdapterTransition/res/values/base-strings.xml index ee0c4bd59..09f86cdfe 100644 --- a/samples/browseable/AdapterTransition/res/values/base-strings.xml +++ b/samples/browseable/AdapterTransition/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">AdapterTransition</string> <string name="intro_message"> diff --git a/samples/browseable/AdapterTransition/res/values/strings.xml b/samples/browseable/AdapterTransition/res/values/strings.xml index 02b87cf79..02b87cf79 100755..100644 --- a/samples/browseable/AdapterTransition/res/values/strings.xml +++ b/samples/browseable/AdapterTransition/res/values/strings.xml diff --git a/samples/browseable/AdapterTransition/src/com.example.android.adaptertransition/MainActivity.java b/samples/browseable/AdapterTransition/src/com.example.android.adaptertransition/MainActivity.java index a45632c70..0adb84284 100644 --- a/samples/browseable/AdapterTransition/src/com.example.android.adaptertransition/MainActivity.java +++ b/samples/browseable/AdapterTransition/src/com.example.android.adaptertransition/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.adaptertransition; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - AdapterTransitionFragment fragment = new AdapterTransitionFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + AdapterTransitionFragment fragment = new AdapterTransitionFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/AdvancedImmersiveMode/AndroidManifest.xml b/samples/browseable/AdvancedImmersiveMode/AndroidManifest.xml index 1d01856c8..a96ebb429 100644 --- a/samples/browseable/AdvancedImmersiveMode/AndroidManifest.xml +++ b/samples/browseable/AdvancedImmersiveMode/AndroidManifest.xml @@ -27,7 +27,7 @@ <!-- This sample is to demonstrate features released in API 19. So while it would technically run on an earlier version of Android, there wouldn't be much point) --> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <!-- allowBackup declares if the app can be part of device-wide backups such as "adb backup" --> <!-- theme is a way of applying UI decisions across your entire application. You can also define it on a per-application basis. --> diff --git a/samples/browseable/AdvancedImmersiveMode/_index.jd b/samples/browseable/AdvancedImmersiveMode/_index.jd index 7048fe838..ee91eb7e3 100644 --- a/samples/browseable/AdvancedImmersiveMode/_index.jd +++ b/samples/browseable/AdvancedImmersiveMode/_index.jd @@ -1,19 +1,12 @@ - - - page.tags="AdvancedImmersiveMode" sample.group=UI @jd:body <p> -Android 4.4 introduces a way for you to provide a more immersive screen -experience in your app by letting users show or hide the status bar and -the navigation bar with a swipe. -</p> - -<p> -This sample demonstrates how this feature interacts with some of the other -UI flags related to full-screen apps. The sample also shows how to implement a -"sticky" mode, which re-hides the bars a few seconds after the user swipes -them back in. -</p>
\ No newline at end of file + + \n\n\n\"Immersive Mode\", added in Android 4.4, improves the \"hide full screen\" and + \"hide nav bar\" modes, by letting users swipe the bars in and out. This sample + lets the user experiment with immersive mode by seeing how it interacts + with some of the other UI flags related to full-screen apps. + + </p> diff --git a/samples/browseable/AdvancedImmersiveMode/res/values-v21/template-styles.xml b/samples/browseable/AdvancedImmersiveMode/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/AdvancedImmersiveMode/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/AdvancedImmersiveMode/res/values/base-strings.xml b/samples/browseable/AdvancedImmersiveMode/res/values/base-strings.xml index 8e4c710cf..b1c7f5e87 100644 --- a/samples/browseable/AdvancedImmersiveMode/res/values/base-strings.xml +++ b/samples/browseable/AdvancedImmersiveMode/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">AdvancedImmersiveMode</string> <string name="intro_message"> diff --git a/samples/browseable/AdvancedImmersiveMode/src/com.example.android.advancedimmersivemode/MainActivity.java b/samples/browseable/AdvancedImmersiveMode/src/com.example.android.advancedimmersivemode/MainActivity.java index e32355760..4fc40afa7 100644 --- a/samples/browseable/AdvancedImmersiveMode/src/com.example.android.advancedimmersivemode/MainActivity.java +++ b/samples/browseable/AdvancedImmersiveMode/src/com.example.android.advancedimmersivemode/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.advancedimmersivemode; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - AdvancedImmersiveModeFragment fragment = new AdvancedImmersiveModeFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + AdvancedImmersiveModeFragment fragment = new AdvancedImmersiveModeFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/AgendaData/Application/AndroidManifest.xml b/samples/browseable/AgendaData/Application/AndroidManifest.xml index b5bebc39c..be342317c 100644 --- a/samples/browseable/AgendaData/Application/AndroidManifest.xml +++ b/samples/browseable/AgendaData/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.agendadata"> + package="com.example.android.wearable.agendadata"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> @@ -34,7 +34,7 @@ android:value="@integer/google_play_services_version" /> <activity - android:name="com.example.android.agendadata.MainActivity" + android:name="com.example.android.wearable.agendadata.MainActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize"> <intent-filter> @@ -43,6 +43,6 @@ </intent-filter> </activity> - <service android:name="com.example.android.agendadata.CalendarQueryService"/> + <service android:name="com.example.android.wearable.agendadata.CalendarQueryService"/> </application> </manifest> diff --git a/samples/browseable/AgendaData/Application/res/values-v21/template-styles.xml b/samples/browseable/AgendaData/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/AgendaData/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/CalendarQueryService.java b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/CalendarQueryService.java index fe7fa277f..c39a5ed1b 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/CalendarQueryService.java +++ b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/CalendarQueryService.java @@ -14,21 +14,21 @@ * limitations under the License. */ -package com.example.android.agendadata; +package com.example.android.wearable.agendadata; -import static com.example.android.agendadata.Constants.TAG; -import static com.example.android.agendadata.Constants.CONNECTION_TIME_OUT_MS; -import static com.example.android.agendadata.Constants.CAL_DATA_ITEM_PATH_PREFIX; -import static com.example.android.agendadata.Constants.ALL_DAY; -import static com.example.android.agendadata.Constants.BEGIN; -import static com.example.android.agendadata.Constants.DATA_ITEM_URI; -import static com.example.android.agendadata.Constants.DESCRIPTION; -import static com.example.android.agendadata.Constants.END; -import static com.example.android.agendadata.Constants.EVENT_ID; -import static com.example.android.agendadata.Constants.ID; -import static com.example.android.agendadata.Constants.PROFILE_PIC; -import static com.example.android.agendadata.Constants.TITLE; +import static com.example.android.wearable.agendadata.Constants.TAG; +import static com.example.android.wearable.agendadata.Constants.CONNECTION_TIME_OUT_MS; +import static com.example.android.wearable.agendadata.Constants.CAL_DATA_ITEM_PATH_PREFIX; +import static com.example.android.wearable.agendadata.Constants.ALL_DAY; +import static com.example.android.wearable.agendadata.Constants.BEGIN; +import static com.example.android.wearable.agendadata.Constants.DATA_ITEM_URI; +import static com.example.android.wearable.agendadata.Constants.DESCRIPTION; +import static com.example.android.wearable.agendadata.Constants.END; +import static com.example.android.wearable.agendadata.Constants.EVENT_ID; +import static com.example.android.wearable.agendadata.Constants.ID; +import static com.example.android.wearable.agendadata.Constants.PROFILE_PIC; +import static com.example.android.wearable.agendadata.Constants.TITLE; import android.app.IntentService; import android.content.ContentResolver; diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/Constants.java b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/Constants.java index d66e7caa2..6dc6952ca 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/Constants.java +++ b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.agendadata; +package com.example.android.wearable.agendadata; /** Constants used in companion app. */ public final class Constants { diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/MainActivity.java b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/MainActivity.java index e999fde20..8e4063d8c 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/MainActivity.java +++ b/samples/browseable/AgendaData/Application/src/com.example.android.wearable.agendadata/MainActivity.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.example.android.agendadata; +package com.example.android.wearable.agendadata; -import static com.example.android.agendadata.Constants.TAG; +import static com.example.android.wearable.agendadata.Constants.TAG; import android.app.Activity; import android.content.Intent; diff --git a/samples/browseable/AgendaData/Shared/AndroidManifest.xml b/samples/browseable/AgendaData/Shared/AndroidManifest.xml deleted file mode 100644 index 07bc15316..000000000 --- a/samples/browseable/AgendaData/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.agendadata.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/AgendaData/Wearable/AndroidManifest.xml b/samples/browseable/AgendaData/Wearable/AndroidManifest.xml index c91f09c3e..f2576af2a 100644 --- a/samples/browseable/AgendaData/Wearable/AndroidManifest.xml +++ b/samples/browseable/AgendaData/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.agendadata" > + package="com.example.android.wearable.agendadata" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -32,13 +32,13 @@ android:value="@integer/google_play_services_version" /> <service - android:name="com.example.android.agendadata.HomeListenerService" > + android:name="com.example.android.wearable.agendadata.HomeListenerService" > <intent-filter> <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> </intent-filter> </service> - <service android:name="com.example.android.agendadata.DeleteService"/> + <service android:name="com.example.android.wearable.agendadata.DeleteService"/> <activity android:name="android.support.wearable.activity.ConfirmationActivity"/> diff --git a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/Constants.java b/samples/browseable/AgendaData/Wearable/src/com.example.android.wearable.agendadata/Constants.java index 5b5175185..176a21eb1 100644 --- a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/Constants.java +++ b/samples/browseable/AgendaData/Wearable/src/com.example.android.wearable.agendadata/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.agendadata; +package com.example.android.wearable.agendadata; /** Constants used in wearable app. */ public final class Constants { diff --git a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/DeleteService.java b/samples/browseable/AgendaData/Wearable/src/com.example.android.wearable.agendadata/DeleteService.java index 7c6bb9baf..86aafe03d 100644 --- a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/DeleteService.java +++ b/samples/browseable/AgendaData/Wearable/src/com.example.android.wearable.agendadata/DeleteService.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.example.android.agendadata; +package com.example.android.wearable.agendadata; -import static com.example.android.agendadata.Constants.TAG; -import static com.example.android.agendadata.Constants.EXTRA_SILENT; +import static com.example.android.wearable.agendadata.Constants.TAG; +import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT; import android.app.IntentService; import android.content.Intent; diff --git a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/HomeListenerService.java b/samples/browseable/AgendaData/Wearable/src/com.example.android.wearable.agendadata/HomeListenerService.java index 7a4691151..ef47977e3 100644 --- a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/HomeListenerService.java +++ b/samples/browseable/AgendaData/Wearable/src/com.example.android.wearable.agendadata/HomeListenerService.java @@ -14,17 +14,17 @@ * limitations under the License. */ -package com.example.android.agendadata; +package com.example.android.wearable.agendadata; -import static com.example.android.agendadata.Constants.TAG; -import static com.example.android.agendadata.Constants.EXTRA_SILENT; +import static com.example.android.wearable.agendadata.Constants.TAG; +import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT; -import static com.example.android.agendadata.Constants.ALL_DAY; -import static com.example.android.agendadata.Constants.BEGIN; -import static com.example.android.agendadata.Constants.DESCRIPTION; -import static com.example.android.agendadata.Constants.END; -import static com.example.android.agendadata.Constants.PROFILE_PIC; -import static com.example.android.agendadata.Constants.TITLE; +import static com.example.android.wearable.agendadata.Constants.ALL_DAY; +import static com.example.android.wearable.agendadata.Constants.BEGIN; +import static com.example.android.wearable.agendadata.Constants.DESCRIPTION; +import static com.example.android.wearable.agendadata.Constants.END; +import static com.example.android.wearable.agendadata.Constants.PROFILE_PIC; +import static com.example.android.wearable.agendadata.Constants.TITLE; import android.app.Notification; import android.app.NotificationManager; diff --git a/samples/browseable/AppRestrictions/AndroidManifest.xml b/samples/browseable/AppRestrictions/AndroidManifest.xml index b492bbfce..ddac9cfd1 100644 --- a/samples/browseable/AppRestrictions/AndroidManifest.xml +++ b/samples/browseable/AppRestrictions/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="18" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> diff --git a/samples/browseable/AppRestrictions/_index.jd b/samples/browseable/AppRestrictions/_index.jd index 83aa08cb7..e0c8b2df8 100644 --- a/samples/browseable/AppRestrictions/_index.jd +++ b/samples/browseable/AppRestrictions/_index.jd @@ -1,6 +1,3 @@ - - - page.tags="AppRestrictions" sample.group=Content @jd:body diff --git a/samples/browseable/AppRestrictions/res/values-v21/template-styles.xml b/samples/browseable/AppRestrictions/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/AppRestrictions/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/AppRestrictions/res/values/base-strings.xml b/samples/browseable/AppRestrictions/res/values/base-strings.xml index 08a466397..d90326c59 100644 --- a/samples/browseable/AppRestrictions/res/values/base-strings.xml +++ b/samples/browseable/AppRestrictions/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">AppRestrictions</string> <string name="intro_message"> diff --git a/samples/browseable/BasicAccessibility/AndroidManifest.xml b/samples/browseable/BasicAccessibility/AndroidManifest.xml index d61d7899e..281114db3 100644 --- a/samples/browseable/BasicAccessibility/AndroidManifest.xml +++ b/samples/browseable/BasicAccessibility/AndroidManifest.xml @@ -22,9 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="11" - android:targetSdkVersion="16" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/BasicAccessibility/_index.jd b/samples/browseable/BasicAccessibility/_index.jd index 761aa117e..91c34ec21 100644 --- a/samples/browseable/BasicAccessibility/_index.jd +++ b/samples/browseable/BasicAccessibility/_index.jd @@ -1,12 +1,9 @@ - - - page.tags="BasicAccessibility" sample.group=UI @jd:body -<p>This sample demonstrates how to create applications that are accessible for -users with visual or physical disabilities.</p> -<p>To learn how to make the most of the accessibility features built into -the Android framework, see -<a href="{@docRoot}training/accessibility/index.html">Implementing Accessibility</a>.</p> +<p> + + This sample demonstrates how to create an accessible application, using a mix of different widgets demonstrating different ways of adding accessibility markup to a UI. + + </p> diff --git a/samples/browseable/BasicAccessibility/res/values-v21/template-styles.xml b/samples/browseable/BasicAccessibility/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicAccessibility/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicAccessibility/res/values/base-strings.xml b/samples/browseable/BasicAccessibility/res/values/base-strings.xml index 20790c75d..ac4db70ad 100644 --- a/samples/browseable/BasicAccessibility/res/values/base-strings.xml +++ b/samples/browseable/BasicAccessibility/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicAccessibility</string> <string name="intro_message"> diff --git a/samples/browseable/BasicAndroidKeyStore/AndroidManifest.xml b/samples/browseable/BasicAndroidKeyStore/AndroidManifest.xml index 28d256c2d..1c3b255fa 100644 --- a/samples/browseable/BasicAndroidKeyStore/AndroidManifest.xml +++ b/samples/browseable/BasicAndroidKeyStore/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/BasicAndroidKeyStore/_index.jd b/samples/browseable/BasicAndroidKeyStore/_index.jd index 5b7af605c..a3d5960b1 100644 --- a/samples/browseable/BasicAndroidKeyStore/_index.jd +++ b/samples/browseable/BasicAndroidKeyStore/_index.jd @@ -1,15 +1,14 @@ - - - page.tags="BasicAndroidKeyStore" sample.group=Security @jd:body -<p>This sample demonstrates how to use a {java.security.KeyStore} to -safely create and store encryption keys that only your application can access. -You can also sign data using those keys.</p> -<p>To see this in action, run the sample application and click:</p> -<ul> -<li><strong>Create</strong> to create a new KeyPair.</li> -<li><strong>Sign</strong> to sign some data using a KeyPair.</li> -<li><strong>Verify</strong> to verify the data using the signature provided.</li> +<p> + + Welcome to the <b>Basic Android Key Store</b> sample!\n\n + This sample demonstrates how to use the Android Key Store to safely create and store + encryption keys that only your application can access. You can also sign data + using those keys.\n\n + To create a new KeyPair, click \"Create\".\n\n + To sign some data using a KeyPair, click \"Sign\".\n\n + To verify the data using the signature provided, click \"Verify\".\n\n + </p> diff --git a/samples/browseable/BasicAndroidKeyStore/res/values-v21/template-styles.xml b/samples/browseable/BasicAndroidKeyStore/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicAndroidKeyStore/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicAndroidKeyStore/res/values/base-strings.xml b/samples/browseable/BasicAndroidKeyStore/res/values/base-strings.xml index 0699a4aee..484618c0f 100644 --- a/samples/browseable/BasicAndroidKeyStore/res/values/base-strings.xml +++ b/samples/browseable/BasicAndroidKeyStore/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicAndroidKeyStore</string> <string name="intro_message"> diff --git a/samples/browseable/BasicAndroidKeyStore/src/com.example.android.basicandroidkeystore/MainActivity.java b/samples/browseable/BasicAndroidKeyStore/src/com.example.android.basicandroidkeystore/MainActivity.java index 7711f3506..7fd9466e2 100644 --- a/samples/browseable/BasicAndroidKeyStore/src/com.example.android.basicandroidkeystore/MainActivity.java +++ b/samples/browseable/BasicAndroidKeyStore/src/com.example.android.basicandroidkeystore/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.basicandroidkeystore; import android.graphics.Color; diff --git a/samples/browseable/BasicContactables/AndroidManifest.xml b/samples/browseable/BasicContactables/AndroidManifest.xml index 62b9812cc..079db2334 100644 --- a/samples/browseable/BasicContactables/AndroidManifest.xml +++ b/samples/browseable/BasicContactables/AndroidManifest.xml @@ -23,9 +23,7 @@ <!-- BEGIN_INCLUDE(contacts_permission) --> <uses-permission android:name="android.permission.READ_CONTACTS"/> <!-- END_INCLUDE(contacts_permission) --> - <uses-sdk - android:minSdkVersion="18" - android:targetSdkVersion="18" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <permission android:name="android"></permission> <application diff --git a/samples/browseable/BasicContactables/_index.jd b/samples/browseable/BasicContactables/_index.jd index f5bb3fce4..8a0a506a3 100644 --- a/samples/browseable/BasicContactables/_index.jd +++ b/samples/browseable/BasicContactables/_index.jd @@ -1,13 +1,11 @@ - - - page.tags="BasicContactables" sample.group=Content @jd:body -<p>This sample demonstrates how to use the -{@link android.provider.ContactsContract.Data} table to search for contacts.</p> -<p>The sample sends consolidated query strings to the -{@link android.provider.ContactsContract.Data} table to match both contact -names and phone numbers. This approach helps to reduce the number of -queries needed when searching the contacts database.</p> +<p> + + This sample demonstrates how to use the Contactables table to search for contacts. + \n\nQuery strings sent to the Contactables table will match both contact names and phone numbers, + reducing the number of queries your application needs to use when searching the contacts database! + + </p> diff --git a/samples/browseable/BasicContactables/res/values-v21/template-styles.xml b/samples/browseable/BasicContactables/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicContactables/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicContactables/res/values/base-strings.xml b/samples/browseable/BasicContactables/res/values/base-strings.xml index 0fc07ef4a..acbaaf5d4 100644 --- a/samples/browseable/BasicContactables/res/values/base-strings.xml +++ b/samples/browseable/BasicContactables/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicContactables</string> <string name="intro_message"> diff --git a/samples/browseable/BasicGestureDetect/AndroidManifest.xml b/samples/browseable/BasicGestureDetect/AndroidManifest.xml index 87ed60345..aaa4f41c1 100644 --- a/samples/browseable/BasicGestureDetect/AndroidManifest.xml +++ b/samples/browseable/BasicGestureDetect/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="13" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/BasicGestureDetect/_index.jd b/samples/browseable/BasicGestureDetect/_index.jd index 762217ad6..1e5d0d26c 100644 --- a/samples/browseable/BasicGestureDetect/_index.jd +++ b/samples/browseable/BasicGestureDetect/_index.jd @@ -1,12 +1,10 @@ - - - page.tags="BasicGestureDetect" sample.group=Input @jd:body -<p>This sample demonstrates how to use the {@link android.view.GestureDetector} -API to detect simple dragging and tapping gestures.</p> -<p>To learn more about detecting basic touch gestures such as scrolling, -flinging, and double-tapping, see -<a href="{@docRoot}training/gestures/detector.html">Detecting Common Gestures</a>.</p> +<p> + + Welcome to Basic Gesture Detect! + In order to try this sample out, try dragging or tapping this text to see what happens! + + </p> diff --git a/samples/browseable/BasicGestureDetect/res/values-v21/template-styles.xml b/samples/browseable/BasicGestureDetect/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicGestureDetect/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicGestureDetect/res/values/base-strings.xml b/samples/browseable/BasicGestureDetect/res/values/base-strings.xml index e9ce7cd0d..8b96af7a1 100644 --- a/samples/browseable/BasicGestureDetect/res/values/base-strings.xml +++ b/samples/browseable/BasicGestureDetect/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicGestureDetect</string> <string name="intro_message"> diff --git a/samples/browseable/BasicGestureDetect/res/values/strings.xml b/samples/browseable/BasicGestureDetect/res/values/strings.xml index c047c4fcc..826d90f15 100644 --- a/samples/browseable/BasicGestureDetect/res/values/strings.xml +++ b/samples/browseable/BasicGestureDetect/res/values/strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="sample_action">Clear Text</string> </resources> diff --git a/samples/browseable/BasicGestureDetect/src/com.example.android.basicgesturedetect/MainActivity.java b/samples/browseable/BasicGestureDetect/src/com.example.android.basicgesturedetect/MainActivity.java index de4a39f82..57d935447 100644 --- a/samples/browseable/BasicGestureDetect/src/com.example.android.basicgesturedetect/MainActivity.java +++ b/samples/browseable/BasicGestureDetect/src/com.example.android.basicgesturedetect/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.basicgesturedetect; import android.graphics.Color; diff --git a/samples/browseable/BasicImmersiveMode/AndroidManifest.xml b/samples/browseable/BasicImmersiveMode/AndroidManifest.xml index 00b4e3c64..d483d5bf0 100644 --- a/samples/browseable/BasicImmersiveMode/AndroidManifest.xml +++ b/samples/browseable/BasicImmersiveMode/AndroidManifest.xml @@ -19,7 +19,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/BasicImmersiveMode/_index.jd b/samples/browseable/BasicImmersiveMode/_index.jd index 625e7a2ac..15298470c 100644 --- a/samples/browseable/BasicImmersiveMode/_index.jd +++ b/samples/browseable/BasicImmersiveMode/_index.jd @@ -1,12 +1,11 @@ - - - page.tags="BasicImmersiveMode" sample.group=UI @jd:body -<p>Android 4.4 introduces a way for you to provide a more immersive screen -experience in your app, by letting users show or hide the status bar and -navigation bar with a swipe.</p> -<p>This sample demonstrates how to enable and disable this feature -programmatically.</p> +<p> + + \"Immersive Mode\" is a new UI mode which improves \"hide full screen\" and + \"hide nav bar\" modes, by letting users swipe the bars in and out. This sample + demonstrates how to enable and disable immersive mode programmatically. + + </p> diff --git a/samples/browseable/BasicImmersiveMode/res/values-v21/template-styles.xml b/samples/browseable/BasicImmersiveMode/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicImmersiveMode/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicImmersiveMode/res/values/base-strings.xml b/samples/browseable/BasicImmersiveMode/res/values/base-strings.xml index 20a06479b..46ee0f5d3 100644 --- a/samples/browseable/BasicImmersiveMode/res/values/base-strings.xml +++ b/samples/browseable/BasicImmersiveMode/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicImmersiveMode</string> <string name="intro_message"> diff --git a/samples/browseable/BasicImmersiveMode/res/values/strings.xml b/samples/browseable/BasicImmersiveMode/res/values/strings.xml index e845261aa..dc12528d2 100644 --- a/samples/browseable/BasicImmersiveMode/res/values/strings.xml +++ b/samples/browseable/BasicImmersiveMode/res/values/strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="sample_action">Toggle Immersive Mode!</string> </resources> diff --git a/samples/browseable/BasicImmersiveMode/src/com.example.android.basicimmersivemode/MainActivity.java b/samples/browseable/BasicImmersiveMode/src/com.example.android.basicimmersivemode/MainActivity.java index 0c1bcefed..5ffe90295 100644 --- a/samples/browseable/BasicImmersiveMode/src/com.example.android.basicimmersivemode/MainActivity.java +++ b/samples/browseable/BasicImmersiveMode/src/com.example.android.basicimmersivemode/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.basicimmersivemode; import android.graphics.Color; diff --git a/samples/browseable/BasicMediaDecoder/AndroidManifest.xml b/samples/browseable/BasicMediaDecoder/AndroidManifest.xml index d19149110..02a674e77 100644 --- a/samples/browseable/BasicMediaDecoder/AndroidManifest.xml +++ b/samples/browseable/BasicMediaDecoder/AndroidManifest.xml @@ -20,7 +20,8 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="17"/> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> + <application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> <activity diff --git a/samples/browseable/BasicMediaDecoder/_index.jd b/samples/browseable/BasicMediaDecoder/_index.jd index 3d1a33c21..769d8a666 100644 --- a/samples/browseable/BasicMediaDecoder/_index.jd +++ b/samples/browseable/BasicMediaDecoder/_index.jd @@ -1,9 +1,10 @@ - - - page.tags="BasicMediaDecoder" sample.group=Media @jd:body -<p>This sample demonstrates how to decode a video using -the {@link android.media.MediaCodec} API and render in an activity.</p> +<p> + + This activity uses a TextureView to render the frames of a video decoded using the + MediaCodec API. + + </p> diff --git a/samples/browseable/BasicMediaDecoder/res/values-v21/template-styles.xml b/samples/browseable/BasicMediaDecoder/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicMediaDecoder/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicMediaDecoder/res/values/base-strings.xml b/samples/browseable/BasicMediaDecoder/res/values/base-strings.xml index 94d02a896..73405222b 100644 --- a/samples/browseable/BasicMediaDecoder/res/values/base-strings.xml +++ b/samples/browseable/BasicMediaDecoder/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicMediaDecoder</string> <string name="intro_message"> diff --git a/samples/browseable/BasicMediaRouter/AndroidManifest.xml b/samples/browseable/BasicMediaRouter/AndroidManifest.xml index 33c20d582..f84b7dfea 100644 --- a/samples/browseable/BasicMediaRouter/AndroidManifest.xml +++ b/samples/browseable/BasicMediaRouter/AndroidManifest.xml @@ -20,9 +20,7 @@ android:versionCode="1" android:versionName="1.0" > - <uses-sdk - android:minSdkVersion="17" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/BasicMediaRouter/_index.jd b/samples/browseable/BasicMediaRouter/_index.jd index 54081ede7..9d2f3f5b9 100644 --- a/samples/browseable/BasicMediaRouter/_index.jd +++ b/samples/browseable/BasicMediaRouter/_index.jd @@ -1,18 +1,14 @@ - - - page.tags="BasicMediaRouter" sample.group=Media @jd:body -<p>This sample demonstrates how to use the {@link android.media.MediaRouter} -API to display content on a secondary display.</p> -<p>To see this in action, run the sample and use the -<strong>Media Route Action Item</strong> in the action bar to select an -output device. If your device supports Miracast wireless displays, you may -need to enable <strong>Wireless Display</strong> functionality in the -system settings.</p> -<p>You can also enable secondary screen simulation from the -<em>Developer options</em> in the system Settings. Once -connected, use the <strong>Change Color</strong> button to change the -background color of the secondary screen.</p> +<p> + + This sample demonstrates the use of the MediaRouter API to display + content on a secondary display.\n\nUse the "Media Route Action Item" in the ActionBar + to select an output device. If your device supports Miracast wireless displays, + you may need to enable "Wireless Display" functionality in the system settings. + Secondary screen simulation can also be enabled from the "Developer Options".\n\n +Once connected, use the "Change Color" button to change the background color of the secondary screen. + + </p> diff --git a/samples/browseable/BasicMediaRouter/res/values-v21/template-styles.xml b/samples/browseable/BasicMediaRouter/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicMediaRouter/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicMediaRouter/res/values/base-strings.xml b/samples/browseable/BasicMediaRouter/res/values/base-strings.xml index 211577118..6f16407f3 100644 --- a/samples/browseable/BasicMediaRouter/res/values/base-strings.xml +++ b/samples/browseable/BasicMediaRouter/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicMediaRouter</string> <string name="intro_message"> diff --git a/samples/browseable/BasicMultitouch/AndroidManifest.xml b/samples/browseable/BasicMultitouch/AndroidManifest.xml index 043345c19..fc11177cf 100644 --- a/samples/browseable/BasicMultitouch/AndroidManifest.xml +++ b/samples/browseable/BasicMultitouch/AndroidManifest.xml @@ -20,9 +20,7 @@ android:versionCode="1" android:versionName="1.0" > - <uses-sdk - android:minSdkVersion="8" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/BasicMultitouch/_index.jd b/samples/browseable/BasicMultitouch/_index.jd index 43a1e9020..f09a7f433 100644 --- a/samples/browseable/BasicMultitouch/_index.jd +++ b/samples/browseable/BasicMultitouch/_index.jd @@ -1,12 +1,12 @@ - - - page.tags="BasicMultitouch" sample.group=Input @jd:body -<p>This samples demonstrates how to use the {@link android.view.MotionEvent} -API to keep track of individual touches across multiple touch events.</p> -<p>To see this in action, run the sample and touch the screen with multiple -fingers to show that the pointer id (also represented by a colour) does not -change as new touch events are received.</p> +<p> + +This samples demonstrates the use of MotionEvent properties to keep track of individual touches +across multiple touch events. +\n\nTouch the screen with multiple fingers to show that the pointer id +(also represented by a colour) does not change as new touch events are received.</string> + + </p> diff --git a/samples/browseable/BasicMultitouch/res/values-v21/template-styles.xml b/samples/browseable/BasicMultitouch/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicMultitouch/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicMultitouch/res/values/base-strings.xml b/samples/browseable/BasicMultitouch/res/values/base-strings.xml index a5388a7d6..9079d1ed7 100644 --- a/samples/browseable/BasicMultitouch/res/values/base-strings.xml +++ b/samples/browseable/BasicMultitouch/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicMultitouch</string> <string name="intro_message"> diff --git a/samples/browseable/BasicNetworking/AndroidManifest.xml b/samples/browseable/BasicNetworking/AndroidManifest.xml index 48bfeac46..b51279007 100644 --- a/samples/browseable/BasicNetworking/AndroidManifest.xml +++ b/samples/browseable/BasicNetworking/AndroidManifest.xml @@ -20,7 +20,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> diff --git a/samples/browseable/BasicNetworking/_index.jd b/samples/browseable/BasicNetworking/_index.jd index 223ba765a..3b7a39a23 100644 --- a/samples/browseable/BasicNetworking/_index.jd +++ b/samples/browseable/BasicNetworking/_index.jd @@ -1,10 +1,12 @@ - - - page.tags="BasicNetworking" sample.group=Connectivity @jd:body -<p>This sample demonstrates how to use the -{@link android.net.ConnectivityManager} to determine if the device has an -active network connection, and if so, retrieve the connection type.</p> +<p> + + This sample demonstrates how to use the ConnectivityManager to determine if you have + a network connection, and if so, what type of connection it is. + \n\nA "NetworkInfo" object is retrieved from the ConnectivityManager, which contains information + on the active connection, and then the connection type is printed to an on-screen console. + + </p> diff --git a/samples/browseable/BasicNetworking/res/values-v21/template-styles.xml b/samples/browseable/BasicNetworking/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicNetworking/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicNetworking/res/values/base-strings.xml b/samples/browseable/BasicNetworking/res/values/base-strings.xml index 668bcdfb6..9a86c89d7 100644 --- a/samples/browseable/BasicNetworking/res/values/base-strings.xml +++ b/samples/browseable/BasicNetworking/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicNetworking</string> <string name="intro_message"> diff --git a/samples/browseable/BasicNotifications/AndroidManifest.xml b/samples/browseable/BasicNotifications/AndroidManifest.xml index 1e37d0bf6..01f8e3a7a 100644 --- a/samples/browseable/BasicNotifications/AndroidManifest.xml +++ b/samples/browseable/BasicNotifications/AndroidManifest.xml @@ -20,9 +20,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="8" - android:targetSdkVersion="17"/> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/BasicNotifications/_index.jd b/samples/browseable/BasicNotifications/_index.jd index 02a9b5677..d34b8fbc0 100644 --- a/samples/browseable/BasicNotifications/_index.jd +++ b/samples/browseable/BasicNotifications/_index.jd @@ -1,10 +1,11 @@ - - - page.tags="BasicNotifications" -sample.group=UI +sample.group=Notification @jd:body -<p>This sample demonstrates how to display events in the system's notification -bar. The {@link android.support.v4.app.NotificationCompat} API is used for -compatibility with devices running Android 2.2 or higher.</p> +<p> + + This sample demonstrates how to display events in the system\'s notification bar. The + NotificationCompat API is used for compatibility with older devices, running Android + 2.2 (Froyo) or newer. + + </p> diff --git a/samples/browseable/BasicNotifications/res/values-v21/template-styles.xml b/samples/browseable/BasicNotifications/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicNotifications/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicNotifications/res/values/base-strings.xml b/samples/browseable/BasicNotifications/res/values/base-strings.xml index 15dafec61..87f5bf0c9 100644 --- a/samples/browseable/BasicNotifications/res/values/base-strings.xml +++ b/samples/browseable/BasicNotifications/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicNotifications</string> <string name="intro_message"> diff --git a/samples/browseable/BasicRenderScript/AndroidManifest.xml b/samples/browseable/BasicRenderScript/AndroidManifest.xml index e1e2dfc1b..3bc65ffa4 100644 --- a/samples/browseable/BasicRenderScript/AndroidManifest.xml +++ b/samples/browseable/BasicRenderScript/AndroidManifest.xml @@ -20,9 +20,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="8" - android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/BasicRenderScript/_index.jd b/samples/browseable/BasicRenderScript/_index.jd index a40a26422..3a4ffe0ff 100644 --- a/samples/browseable/BasicRenderScript/_index.jd +++ b/samples/browseable/BasicRenderScript/_index.jd @@ -1,13 +1,10 @@ - - - page.tags="BasicRenderScript" sample.group=RenderScript @jd:body <p> - This sample demonstrates the basic steps for using RenderScript. In this - example, the app uses <a href= - "{@docRoot}guide/topics/renderscript/compute.html">RenderScript</a> to - perform graphical filter operations on a image. -</p> + + BasicRenderScript sample demonstrates basic steps how to use renderScript. + In the sample, it performs graphical filter operation on a image with renderScript. + + </p> diff --git a/samples/browseable/BasicRenderScript/res/values-v21/template-styles.xml b/samples/browseable/BasicRenderScript/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicRenderScript/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicRenderScript/res/values/base-strings.xml b/samples/browseable/BasicRenderScript/res/values/base-strings.xml index a35b3206f..36c701597 100644 --- a/samples/browseable/BasicRenderScript/res/values/base-strings.xml +++ b/samples/browseable/BasicRenderScript/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicRenderScript</string> <string name="intro_message"> diff --git a/samples/browseable/BasicRenderScript/src/com.example.android.common.media/MediaCodecWrapper.java b/samples/browseable/BasicRenderScript/src/com.example.android.common.media/MediaCodecWrapper.java index a511221f5..a48337404 100644 --- a/samples/browseable/BasicRenderScript/src/com.example.android.common.media/MediaCodecWrapper.java +++ b/samples/browseable/BasicRenderScript/src/com.example.android.common.media/MediaCodecWrapper.java @@ -21,6 +21,7 @@ import android.os.Handler; import android.os.Looper; import android.view.Surface; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayDeque; import java.util.Queue; @@ -136,7 +137,7 @@ public class MediaCodecWrapper { * @return */ public static MediaCodecWrapper fromVideoFormat(final MediaFormat trackFormat, - Surface surface) { + Surface surface) throws IOException { MediaCodecWrapper result = null; MediaCodec videoCodec = null; diff --git a/samples/browseable/BasicSyncAdapter/AndroidManifest.xml b/samples/browseable/BasicSyncAdapter/AndroidManifest.xml index dd59b066a..4222b4790 100644 --- a/samples/browseable/BasicSyncAdapter/AndroidManifest.xml +++ b/samples/browseable/BasicSyncAdapter/AndroidManifest.xml @@ -23,9 +23,7 @@ android:versionName="1.0"> <!-- SyncAdapters are available in API 5 and above. We use API 7 as a baseline for samples. --> - <uses-sdk - android:minSdkVersion="7" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <!-- Required for fetching feed data. --> <uses-permission android:name="android.permission.INTERNET"/> diff --git a/samples/browseable/BasicSyncAdapter/_index.jd b/samples/browseable/BasicSyncAdapter/_index.jd index 7217e9a56..a079768e9 100644 --- a/samples/browseable/BasicSyncAdapter/_index.jd +++ b/samples/browseable/BasicSyncAdapter/_index.jd @@ -1,14 +1,14 @@ - - - page.tags="BasicSyncAdapter" sample.group=Connectivity @jd:body -<p>This sample demonstrates how to implement a sync adapter to fetch background -data for an app that doesn't require a user-visible account type or two-way -synchronization.</p> -<p>The sample periodically downloads the feed from the <a href="http://android-developers.blogspot.com/">Android Developers Blog</a> and caches the data in a content provider. At runtime, the cached feed data is -displayed inside a {@link android.widget.ListView}.</p> -<p>To learn more about creating and using sync adapters, see -<a href="{@docRoot}training/sync-adapters/index.html">Transferring Data Using Sync Adapters</a>.</p> +<p> + + This sample demonstrates using SyncAdapter to fetch background data for an app that + doesn\'t require a user-visible account type or 2-way synchronization. + + \n\nThis sample periodically downloads the feed from the Android Developer Blog and + caches the data in a content provider. At runtime, the cached feed data is displayed + inside a ListView. + + </p> diff --git a/samples/browseable/BasicSyncAdapter/res/values-v21/template-styles.xml b/samples/browseable/BasicSyncAdapter/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicSyncAdapter/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicSyncAdapter/res/values/base-strings.xml b/samples/browseable/BasicSyncAdapter/res/values/base-strings.xml index 26704848d..849d026e7 100644 --- a/samples/browseable/BasicSyncAdapter/res/values/base-strings.xml +++ b/samples/browseable/BasicSyncAdapter/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicSyncAdapter</string> <string name="intro_message"> diff --git a/samples/browseable/BasicTransition/AndroidManifest.xml b/samples/browseable/BasicTransition/AndroidManifest.xml index b4698d688..435f5e0c2 100644 --- a/samples/browseable/BasicTransition/AndroidManifest.xml +++ b/samples/browseable/BasicTransition/AndroidManifest.xml @@ -19,7 +19,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/BasicTransition/_index.jd b/samples/browseable/BasicTransition/_index.jd index af2a6e739..16415f685 100644 --- a/samples/browseable/BasicTransition/_index.jd +++ b/samples/browseable/BasicTransition/_index.jd @@ -1,12 +1,10 @@ - - - page.tags="BasicTransition" sample.group=UI @jd:body <p> -This sample demonstrates the basic use of the transition framework introduced in KitKat. -Select each of the radio buttons to switch between the -{@link android.transition.Scene Scene}s. -</p> + + This sample demonstrates the basic use of the transition framework introduced in KitKat. + Select each of the RadioButtons to switch between the Scenes. + + </p> diff --git a/samples/browseable/BasicTransition/res/values-v21/template-styles.xml b/samples/browseable/BasicTransition/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BasicTransition/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BasicTransition/res/values/base-strings.xml b/samples/browseable/BasicTransition/res/values/base-strings.xml index 466e59069..d14eb5465 100644 --- a/samples/browseable/BasicTransition/res/values/base-strings.xml +++ b/samples/browseable/BasicTransition/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BasicTransition</string> <string name="intro_message"> diff --git a/samples/browseable/BasicTransition/res/values/strings.xml b/samples/browseable/BasicTransition/res/values/strings.xml index 319cf3151..319cf3151 100755..100644 --- a/samples/browseable/BasicTransition/res/values/strings.xml +++ b/samples/browseable/BasicTransition/res/values/strings.xml diff --git a/samples/browseable/BasicTransition/src/com.example.android.basictransition/MainActivity.java b/samples/browseable/BasicTransition/src/com.example.android.basictransition/MainActivity.java index 1e7c3017b..7eeac2e6d 100644 --- a/samples/browseable/BasicTransition/src/com.example.android.basictransition/MainActivity.java +++ b/samples/browseable/BasicTransition/src/com.example.android.basictransition/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.basictransition; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - BasicTransitionFragment fragment = new BasicTransitionFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + BasicTransitionFragment fragment = new BasicTransitionFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/BatchStepSensor/AndroidManifest.xml b/samples/browseable/BatchStepSensor/AndroidManifest.xml index 2c4e4f296..9063770f3 100644 --- a/samples/browseable/BatchStepSensor/AndroidManifest.xml +++ b/samples/browseable/BatchStepSensor/AndroidManifest.xml @@ -23,7 +23,7 @@ android:versionName="1.0"> <!-- This sample requires at least Android KitKat for sensor batching support --> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <!-- Require the step counter and step detector sensors. See the method BatchStepSensorFragment#isKitkatWithStepSensor() for a programmatic check if diff --git a/samples/browseable/BatchStepSensor/_index.jd b/samples/browseable/BatchStepSensor/_index.jd index a361294a4..23a41e786 100644 --- a/samples/browseable/BatchStepSensor/_index.jd +++ b/samples/browseable/BatchStepSensor/_index.jd @@ -1,27 +1,18 @@ - - - page.tags="BatchStepSensor" sample.group=Sensors @jd:body <p> - This sample demonstrates the use of the two step sensors (step detector and - counter) and sensor batching. It shows how to register a {@link - android.hardware.SensorEventListener} with and without batching and shows how - these events are received. -</p> - -<p> - The Step Detector sensor fires an event when a step is detected, while the - step counter returns the total number of steps since a listener was first - registered for this sensor. Both sensors only count steps while a listener is - registered. -</p> - -<p> - This sample only covers the basic case, where a listener is only registered - while the app is running. Likewise, batched sensors can be used in the - background (when the CPU is suspended), which requires manually flushing the - sensor event queue before it overflows, which is not covered in this sample. -</p> + + This sample demonstrates the use of the two step sensors (step detector and counter) and + sensor batching.\n\n It shows how to register a SensorEventListener with and without + batching and shows how these events are received.\n\nThe Step Detector sensor fires an + event when a step is detected, while the step counter returns the total number of + steps since a listener was first registered for this sensor. + Both sensors only count steps while a listener is registered. This sample only covers the + basic case, where a listener is only registered while the app is running. Likewise, + batched sensors can be used in the background (when the CPU is suspended), which + requires manually flushing the sensor event queue before it overflows, which is not + covered in this sample. + + </p> diff --git a/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg.xml b/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg.xml new file mode 100644 index 000000000..978415a75 --- /dev/null +++ b/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2014 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. +--> +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="@color/card_action_ripple"> + <item android:drawable="@color/card_action_item_bg" /> +</ripple> diff --git a/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg_negative.xml b/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg_negative.xml new file mode 100644 index 000000000..feed3c6db --- /dev/null +++ b/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg_negative.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2014 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. +--> +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="@color/card_action_negative_ripple"> + <item android:drawable="@color/card_action_item_bg" /> +</ripple> diff --git a/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg_positive.xml b/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg_positive.xml new file mode 100644 index 000000000..0d568cee6 --- /dev/null +++ b/samples/browseable/BatchStepSensor/res/drawable-v21/card_action_bg_positive.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2014 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. +--> +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="@color/card_action_positive_ripple"> + <item android:drawable="@color/card_action_item_bg" /> +</ripple> diff --git a/samples/browseable/BatchStepSensor/res/layout/activity_main.xml b/samples/browseable/BatchStepSensor/res/layout/activity_main.xml index 63f129787..a3c1fa9d0 100755 --- a/samples/browseable/BatchStepSensor/res/layout/activity_main.xml +++ b/samples/browseable/BatchStepSensor/res/layout/activity_main.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <fragment android:id="@+id/fragment_cardstream" android:name="com.example.android.batchstepsensor.cardstream.CardStreamFragment" diff --git a/samples/browseable/BatchStepSensor/res/layout/card.xml b/samples/browseable/BatchStepSensor/res/layout/card.xml index 5deb6f5bb..6350e6a3d 100644 --- a/samples/browseable/BatchStepSensor/res/layout/card.xml +++ b/samples/browseable/BatchStepSensor/res/layout/card.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <com.example.android.batchstepsensor.cardstream.CardLayout android:id="@+id/card_layout" style="@style/Card" diff --git a/samples/browseable/BatchStepSensor/res/layout/card_button_negative.xml b/samples/browseable/BatchStepSensor/res/layout/card_button_negative.xml index 7ca967720..86d9c2d2e 100644 --- a/samples/browseable/BatchStepSensor/res/layout/card_button_negative.xml +++ b/samples/browseable/BatchStepSensor/res/layout/card_button_negative.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <com.example.android.batchstepsensor.cardstream.CardActionButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/card_button" style="@style/CardActionNegative" diff --git a/samples/browseable/BatchStepSensor/res/layout/card_button_neutral.xml b/samples/browseable/BatchStepSensor/res/layout/card_button_neutral.xml index da7444870..c993df85d 100644 --- a/samples/browseable/BatchStepSensor/res/layout/card_button_neutral.xml +++ b/samples/browseable/BatchStepSensor/res/layout/card_button_neutral.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <com.example.android.batchstepsensor.cardstream.CardActionButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/card_button" style="@style/CardActionNeutral" diff --git a/samples/browseable/BatchStepSensor/res/layout/card_button_positive.xml b/samples/browseable/BatchStepSensor/res/layout/card_button_positive.xml index afbda8acf..7a3baf68c 100644 --- a/samples/browseable/BatchStepSensor/res/layout/card_button_positive.xml +++ b/samples/browseable/BatchStepSensor/res/layout/card_button_positive.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <com.example.android.batchstepsensor.cardstream.CardActionButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/card_button" style="@style/CardActionPositive" diff --git a/samples/browseable/BatchStepSensor/res/layout/cardstream.xml b/samples/browseable/BatchStepSensor/res/layout/cardstream.xml index a6b917bc0..889d69cbb 100644 --- a/samples/browseable/BatchStepSensor/res/layout/cardstream.xml +++ b/samples/browseable/BatchStepSensor/res/layout/cardstream.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" diff --git a/samples/browseable/BatchStepSensor/res/values-v21/template-styles.xml b/samples/browseable/BatchStepSensor/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BatchStepSensor/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BatchStepSensor/res/values/base-strings.xml b/samples/browseable/BatchStepSensor/res/values/base-strings.xml index 341b6bc7b..6421966fc 100644 --- a/samples/browseable/BatchStepSensor/res/values/base-strings.xml +++ b/samples/browseable/BatchStepSensor/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BatchStepSensor</string> <string name="intro_message"> diff --git a/samples/browseable/BatchStepSensor/res/values/color.xml b/samples/browseable/BatchStepSensor/res/values/color.xml index 98717d8d8..593ccfdfa 100644 --- a/samples/browseable/BatchStepSensor/res/values/color.xml +++ b/samples/browseable/BatchStepSensor/res/values/color.xml @@ -11,12 +11,15 @@ <!-- Neutral Actions --> <color name="card_action_focused">#FFE3F4FC</color> <color name="card_action">#FF47B4EA</color> + <color name="card_action_ripple">#CC47B4EA</color> <!-- Negative Actions --> <color name="card_action_negative_focused">#FFFBCBCA</color> <color name="card_action_negative">#FFF64940</color> + <color name="card_action_negative_ripple">#CCF64940</color> <!-- Positive Actions --> <color name="card_action_positive_focused">#FFE4F0AF</color> <color name="card_action_positive">#FFA0CC00</color> -</resources>
\ No newline at end of file + <color name="card_action_positive_ripple">#CCA0CC00</color> +</resources> diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/MainActivity.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/MainActivity.java index 5e4f7e3e7..536269387 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/MainActivity.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/MainActivity.java @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - - package com.example.android.batchstepsensor; import android.os.Bundle; @@ -58,7 +55,7 @@ public class MainActivity extends SampleActivityBase implements CardStream { } // Use fragment as click listener for cards, but must implement correct interface - if(!(fragment instanceof OnCardClickListener)){ + if (!(fragment instanceof OnCardClickListener)){ throw new ClassCastException("BatchStepSensorFragment must " + "implement OnCardClickListener interface."); } diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/Card.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/Card.java index a3723e80c..2a342f6bd 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/Card.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/Card.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.animation.Animator; diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardActionButton.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardActionButton.java index 01c7094fb..054cc7248 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardActionButton.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardActionButton.java @@ -14,12 +14,11 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.content.Context; +import android.os.Build; +import android.support.v4.view.ViewCompat; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.animation.BounceInterpolator; @@ -46,20 +45,28 @@ public class CardActionButton extends Button { @Override public boolean onTouchEvent(MotionEvent event) { - switch(event.getAction()){ - case MotionEvent.ACTION_DOWN: + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: { setPressed(true); - animate().scaleX(0.98f).scaleY(0.98f).alpha(0.8f).setDuration(100). - setInterpolator(new DecelerateInterpolator()); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { + animate().scaleX(0.98f).scaleY(0.98f).setDuration(100) + .setInterpolator(new DecelerateInterpolator()); + } else { + ViewCompat.setElevation(this, 8.f); + } break; + } case MotionEvent.ACTION_UP: - animate().scaleX(1.0f).scaleY(1.f).alpha(1.0f).setDuration(50). - setInterpolator(new BounceInterpolator()); - break; - case MotionEvent.ACTION_CANCEL: - animate().scaleX(1.0f).scaleY(1.f).alpha(1.0f).setDuration(50). - setInterpolator(new BounceInterpolator()); + case MotionEvent.ACTION_CANCEL: { + setPressed(false); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { + animate().scaleX(1.f).scaleY(1.f).setDuration(50) + .setInterpolator(new BounceInterpolator()); + } else { + ViewCompat.setElevation(this, 0.f); + } break; + } } return super.onTouchEvent(event); diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardLayout.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardLayout.java index ce20f7f36..84ee7b5d3 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardLayout.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardLayout.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.content.Context; diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStream.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStream.java index 70cc5dd41..6e4e10ab8 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStream.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStream.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; public interface CardStream { diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamAnimator.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamAnimator.java index de06cf658..91a05aeeb 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamAnimator.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamAnimator.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.animation.ObjectAnimator; diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamFragment.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamFragment.java index 5388cd9ce..82ea62249 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamFragment.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamFragment.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.os.Bundle; diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamLinearLayout.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamLinearLayout.java index 5e4ba158a..9515c007d 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamLinearLayout.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamLinearLayout.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.animation.Animator; diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamState.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamState.java index 57ba177ab..59f337c50 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamState.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamState.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import java.util.HashSet; diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/DefaultCardStreamAnimator.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/DefaultCardStreamAnimator.java index 21e54d3a0..9f085535d 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/DefaultCardStreamAnimator.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/DefaultCardStreamAnimator.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.animation.ObjectAnimator; diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/OnCardClickListener.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/OnCardClickListener.java index 90ba21e03..31da7cd09 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/OnCardClickListener.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/OnCardClickListener.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; public interface OnCardClickListener { diff --git a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/StreamRetentionFragment.java b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/StreamRetentionFragment.java index 51d5428a3..71d2a880c 100644 --- a/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/StreamRetentionFragment.java +++ b/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/StreamRetentionFragment.java @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - - package com.example.android.batchstepsensor.cardstream; import android.os.Bundle; diff --git a/samples/browseable/BluetoothChat/AndroidManifest.xml b/samples/browseable/BluetoothChat/AndroidManifest.xml new file mode 100644 index 000000000..53dc5ab29 --- /dev/null +++ b/samples/browseable/BluetoothChat/AndroidManifest.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2014 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 + package="com.example.android.bluetoothchat" + xmlns:android="http://schemas.android.com/apk/res/android" + android:versionCode="1" + android:versionName="1.0"> + + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> + + <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> + <uses-permission android:name="android.permission.BLUETOOTH"/> + + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/AppTheme"> + + <activity + android:name=".MainActivity" + android:configChanges="orientation|keyboardHidden" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + + <activity + android:name=".DeviceListActivity" + android:configChanges="orientation|keyboardHidden" + android:label="@string/select_device" + android:theme="@android:style/Theme.Holo.Dialog"/> + + </application> + +</manifest> diff --git a/samples/browseable/BluetoothChat/_index.jd b/samples/browseable/BluetoothChat/_index.jd new file mode 100644 index 000000000..6d1e37a41 --- /dev/null +++ b/samples/browseable/BluetoothChat/_index.jd @@ -0,0 +1,15 @@ +page.tags="BluetoothChat" +sample.group=Connectivity +@jd:body + +<p> + + This application allows two Android devices to carry out two-way text chat over + Bluetooth. It demonstrates all the fundamental Bluetooth API capabilites, such as: + (1) Scanning for other Bluetooth devices + (2) Querying the local Bluetooth adapter for paired Bluetooth devices + (3) Establishing RFCOMM channels/sockets + (4) Connecting to a remote device + (5) Transfering data over Bluetooth + + </p> diff --git a/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_action_device_access_bluetooth_searching.png Binary files differnew file mode 100755 index 000000000..fc0491e63 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_action_device_access_bluetooth_searching.png diff --git a/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..092887b72 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-hdpi/ic_launcher.png diff --git a/samples/browseable/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png b/samples/browseable/BluetoothChat/res/drawable-hdpi/tile.9.png Binary files differindex 135862883..135862883 100644 --- a/samples/browseable/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png +++ b/samples/browseable/BluetoothChat/res/drawable-hdpi/tile.9.png diff --git a/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_action_device_access_bluetooth_searching.png Binary files differnew file mode 100755 index 000000000..d65de0251 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_action_device_access_bluetooth_searching.png diff --git a/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..1c51ccd7c --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-mdpi/ic_launcher.png diff --git a/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_action_device_access_bluetooth_searching.png Binary files differnew file mode 100755 index 000000000..c4b236eea --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_action_device_access_bluetooth_searching.png diff --git a/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..3fa260b7c --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-xhdpi/ic_launcher.png diff --git a/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_action_device_access_bluetooth_searching.png b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_action_device_access_bluetooth_searching.png Binary files differnew file mode 100755 index 000000000..de264301c --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_action_device_access_bluetooth_searching.png diff --git a/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..6beccf392 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/drawable-xxhdpi/ic_launcher.png diff --git a/samples/browseable/BluetoothChat/res/layout-w720dp/activity_main.xml b/samples/browseable/BluetoothChat/res/layout-w720dp/activity_main.xml new file mode 100755 index 000000000..c9a52f621 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/layout-w720dp/activity_main.xml @@ -0,0 +1,73 @@ +<!-- + 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="horizontal" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/sample_main_layout"> + + <LinearLayout + android:id="@+id/sample_output" + android:layout_width="0px" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <FrameLayout + style="@style/Widget.SampleMessageTile" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <TextView + style="@style/Widget.SampleMessage" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingLeft="@dimen/margin_medium" + android:paddingRight="@dimen/margin_medium" + android:paddingTop="@dimen/margin_large" + android:paddingBottom="@dimen/margin_large" + android:text="@string/intro_message" /> + </FrameLayout> + + <View + android:layout_width="match_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_width="match_parent" + android:layout_height="0px" + android:layout_weight="1" /> + + </LinearLayout> + + <View + android:layout_width="1dp" + android:layout_height="match_parent" + android:background="@android:color/darker_gray" /> + + <FrameLayout + android:id="@+id/sample_content_fragment" + android:layout_weight="2" + android:layout_width="0px" + android:layout_height="match_parent" /> + +</LinearLayout> + + diff --git a/samples/browseable/BluetoothChat/res/layout/activity_device_list.xml b/samples/browseable/BluetoothChat/res/layout/activity_device_list.xml new file mode 100644 index 000000000..ae7242cf9 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/layout/activity_device_list.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + > + + <TextView + android:id="@+id/title_paired_devices" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#666" + android:paddingLeft="5dp" + android:text="@string/title_paired_devices" + android:textColor="#fff" + android:visibility="gone" + /> + + <ListView + android:id="@+id/paired_devices" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:stackFromBottom="true" + /> + + <TextView + android:id="@+id/title_new_devices" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#666" + android:paddingLeft="5dp" + android:text="@string/title_other_devices" + android:textColor="#fff" + android:visibility="gone" + /> + + <ListView + android:id="@+id/new_devices" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="2" + android:stackFromBottom="true" + /> + + <Button + android:id="@+id/button_scan" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/button_scan" + /> +</LinearLayout> diff --git a/samples/browseable/BluetoothChat/res/layout/activity_main.xml b/samples/browseable/BluetoothChat/res/layout/activity_main.xml new file mode 100755 index 000000000..1ae4f981e --- /dev/null +++ b/samples/browseable/BluetoothChat/res/layout/activity_main.xml @@ -0,0 +1,65 @@ +<!-- + 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="match_parent" + android:layout_height="match_parent" + android:id="@+id/sample_main_layout"> + + <ViewAnimator + android:id="@+id/sample_output" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1"> + + <ScrollView + style="@style/Widget.SampleMessageTile" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + style="@style/Widget.SampleMessage" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingLeft="@dimen/horizontal_page_margin" + android:paddingRight="@dimen/horizontal_page_margin" + android:paddingTop="@dimen/vertical_page_margin" + android:paddingBottom="@dimen/vertical_page_margin" + android:text="@string/intro_message" /> + </ScrollView> + + <fragment + android:name="com.example.android.common.logger.LogFragment" + android:id="@+id/log_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + </ViewAnimator> + + <View + android:layout_width="match_parent" + android:layout_height="1dp" + android:background="@android:color/darker_gray" /> + + <FrameLayout + android:id="@+id/sample_content_fragment" + android:layout_weight="2" + android:layout_width="match_parent" + android:layout_height="0px" /> + +</LinearLayout> + diff --git a/samples/browseable/AgendaData/Shared/res/values/strings.xml b/samples/browseable/BluetoothChat/res/layout/device_name.xml index 0f2bb9075..28f57cca0 100644 --- a/samples/browseable/AgendaData/Shared/res/values/strings.xml +++ b/samples/browseable/BluetoothChat/res/layout/device_name.xml @@ -13,6 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. --> -<resources> - <string name="app_name">Shared</string> -</resources> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="5dp" + android:textSize="18sp" + /> diff --git a/samples/browseable/BluetoothChat/res/layout/fragment_bluetooth_chat.xml b/samples/browseable/BluetoothChat/res/layout/fragment_bluetooth_chat.xml new file mode 100644 index 000000000..91bad206f --- /dev/null +++ b/samples/browseable/BluetoothChat/res/layout/fragment_bluetooth_chat.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2014 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:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <ListView + android:id="@+id/in" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_weight="1" + android:stackFromBottom="true" + android:transcriptMode="alwaysScroll" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" > + + <EditText + android:id="@+id/edit_text_out" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:layout_weight="1" /> + + <Button + android:id="@+id/button_send" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/send" /> + </LinearLayout> + +</LinearLayout> diff --git a/samples/browseable/EmbeddedApp/Shared/res/values/strings.xml b/samples/browseable/BluetoothChat/res/layout/message.xml index 0f2bb9075..28f57cca0 100644 --- a/samples/browseable/EmbeddedApp/Shared/res/values/strings.xml +++ b/samples/browseable/BluetoothChat/res/layout/message.xml @@ -13,6 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. --> -<resources> - <string name="app_name">Shared</string> -</resources> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="5dp" + android:textSize="18sp" + /> diff --git a/samples/browseable/BluetoothChat/res/menu/bluetooth_chat.xml b/samples/browseable/BluetoothChat/res/menu/bluetooth_chat.xml new file mode 100644 index 000000000..a965104b5 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/menu/bluetooth_chat.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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/secure_connect_scan" + android:icon="@drawable/ic_action_device_access_bluetooth_searching" + android:showAsAction="ifRoom" + android:title="@string/secure_connect"/> + + <item + android:id="@+id/insecure_connect_scan" + android:showAsAction="never" + android:title="@string/insecure_connect"/> + + <item + android:id="@+id/discoverable" + android:showAsAction="never" + android:title="@string/discoverable"/> + +</menu> diff --git a/samples/browseable/BluetoothChat/res/menu/main.xml b/samples/browseable/BluetoothChat/res/menu/main.xml new file mode 100644 index 000000000..b49c2c526 --- /dev/null +++ b/samples/browseable/BluetoothChat/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/menu_toggle_log" + android:showAsAction="always" + android:title="@string/sample_show_log" /> +</menu> diff --git a/samples/browseable/BluetoothChat/res/values-sw600dp/template-dimens.xml b/samples/browseable/BluetoothChat/res/values-sw600dp/template-dimens.xml new file mode 100644 index 000000000..22074a2bd --- /dev/null +++ b/samples/browseable/BluetoothChat/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/BluetoothChat/res/values-sw600dp/template-styles.xml b/samples/browseable/BluetoothChat/res/values-sw600dp/template-styles.xml new file mode 100644 index 000000000..03d197418 --- /dev/null +++ b/samples/browseable/BluetoothChat/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/SlidingTabsBasic/res/values/strings.xml b/samples/browseable/BluetoothChat/res/values-v11/template-styles.xml index 7b9d9ec4f..8c1ea66f2 100755..100644 --- a/samples/browseable/SlidingTabsBasic/res/values/strings.xml +++ b/samples/browseable/BluetoothChat/res/values-v11/template-styles.xml @@ -12,8 +12,11 @@ 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_show_log">Show Log</string> - <string name="sample_hide_log">Hide Log</string> + + <!-- Activity themes --> + <style name="Theme.Base" parent="android:Theme.Holo.Light" /> + </resources> diff --git a/samples/browseable/BluetoothChat/res/values-v21/template-styles.xml b/samples/browseable/BluetoothChat/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BluetoothChat/res/values/base-strings.xml b/samples/browseable/BluetoothChat/res/values/base-strings.xml new file mode 100644 index 000000000..fe175fbe3 --- /dev/null +++ b/samples/browseable/BluetoothChat/res/values/base-strings.xml @@ -0,0 +1,34 @@ +<?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">BluetoothChat</string> + <string name="intro_message"> + <![CDATA[ + + + This application allows two Android devices to carry out two-way text chat over + Bluetooth. It demonstrates all the fundamental Bluetooth API capabilites, such as: + (1) Scanning for other Bluetooth devices + (2) Querying the local Bluetooth adapter for paired Bluetooth devices + (3) Establishing RFCOMM channels/sockets + (4) Connecting to a remote device + (5) Transfering data over Bluetooth + + + ]]> + </string> +</resources> diff --git a/samples/browseable/AdvancedImmersiveMode/res/values/strings.xml b/samples/browseable/BluetoothChat/res/values/fragmentview_strings.xml index 7b9d9ec4f..7b9d9ec4f 100755 --- a/samples/browseable/AdvancedImmersiveMode/res/values/strings.xml +++ b/samples/browseable/BluetoothChat/res/values/fragmentview_strings.xml diff --git a/samples/browseable/BluetoothChat/res/values/strings.xml b/samples/browseable/BluetoothChat/res/values/strings.xml new file mode 100644 index 000000000..a38d82daf --- /dev/null +++ b/samples/browseable/BluetoothChat/res/values/strings.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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 xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <!-- BluetoothChat --> + <string name="send">Send</string> + <string name="not_connected">You are not connected to a device</string> + <string name="bt_not_enabled_leaving">Bluetooth was not enabled. Leaving Bluetooth Chat.</string> + <string name="title_connecting">connecting...</string> + <string name="title_connected_to">connected to <xliff:g id="device_name">%1$s</xliff:g></string> + <string name="title_not_connected">not connected</string> + + <!-- DeviceListActivity --> + <string name="scanning">scanning for devices...</string> + <string name="select_device">select a device to connect</string> + <string name="none_paired">No devices have been paired</string> + <string name="none_found">No devices found</string> + <string name="title_paired_devices">Paired Devices</string> + <string name="title_other_devices">Other Available Devices</string> + <string name="button_scan">Scan for devices</string> + + <!-- Options Menu --> + <string name="secure_connect">Connect a device - Secure</string> + <string name="insecure_connect">Connect a device - Insecure</string> + <string name="discoverable">Make discoverable</string> + +</resources> diff --git a/samples/browseable/BluetoothChat/res/values/template-dimens.xml b/samples/browseable/BluetoothChat/res/values/template-dimens.xml new file mode 100644 index 000000000..39e710b5c --- /dev/null +++ b/samples/browseable/BluetoothChat/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/BluetoothChat/res/values/template-styles.xml b/samples/browseable/BluetoothChat/res/values/template-styles.xml new file mode 100644 index 000000000..6e7d593dd --- /dev/null +++ b/samples/browseable/BluetoothChat/res/values/template-styles.xml @@ -0,0 +1,42 @@ +<!-- + 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.Light" /> + + <style name="Theme.Sample" parent="Theme.Base" /> + + <style name="AppTheme" parent="Theme.Sample" /> + <!-- 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> + +</resources> diff --git a/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/BluetoothChatFragment.java b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/BluetoothChatFragment.java new file mode 100644 index 000000000..8ee906246 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/BluetoothChatFragment.java @@ -0,0 +1,402 @@ +/* + * Copyright (C) 2014 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.bluetoothchat; + +import android.app.ActionBar; +import android.app.Activity; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.android.common.logger.Log; + +/** + * This fragment controls Bluetooth to communicate with other devices. + */ +public class BluetoothChatFragment extends Fragment { + + private static final String TAG = "BluetoothChatFragment"; + + // Intent request codes + private static final int REQUEST_CONNECT_DEVICE_SECURE = 1; + private static final int REQUEST_CONNECT_DEVICE_INSECURE = 2; + private static final int REQUEST_ENABLE_BT = 3; + + // Layout Views + private ListView mConversationView; + private EditText mOutEditText; + private Button mSendButton; + + /** + * Name of the connected device + */ + private String mConnectedDeviceName = null; + + /** + * Array adapter for the conversation thread + */ + private ArrayAdapter<String> mConversationArrayAdapter; + + /** + * String buffer for outgoing messages + */ + private StringBuffer mOutStringBuffer; + + /** + * Local Bluetooth adapter + */ + private BluetoothAdapter mBluetoothAdapter = null; + + /** + * Member object for the chat services + */ + private BluetoothChatService mChatService = null; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + // Get local Bluetooth adapter + mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + + // If the adapter is null, then Bluetooth is not supported + if (mBluetoothAdapter == null) { + FragmentActivity activity = getActivity(); + Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show(); + activity.finish(); + } + } + + + @Override + public void onStart() { + super.onStart(); + // If BT is not on, request that it be enabled. + // setupChat() will then be called during onActivityResult + if (!mBluetoothAdapter.isEnabled()) { + Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); + startActivityForResult(enableIntent, REQUEST_ENABLE_BT); + // Otherwise, setup the chat session + } else if (mChatService == null) { + setupChat(); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (mChatService != null) { + mChatService.stop(); + } + } + + @Override + public void onResume() { + super.onResume(); + + // Performing this check in onResume() covers the case in which BT was + // not enabled during onStart(), so we were paused to enable it... + // onResume() will be called when ACTION_REQUEST_ENABLE activity returns. + if (mChatService != null) { + // Only if the state is STATE_NONE, do we know that we haven't started already + if (mChatService.getState() == BluetoothChatService.STATE_NONE) { + // Start the Bluetooth chat services + mChatService.start(); + } + } + } + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_bluetooth_chat, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + mConversationView = (ListView) view.findViewById(R.id.in); + mOutEditText = (EditText) view.findViewById(R.id.edit_text_out); + mSendButton = (Button) view.findViewById(R.id.button_send); + } + + /** + * Set up the UI and background operations for chat. + */ + private void setupChat() { + Log.d(TAG, "setupChat()"); + + // Initialize the array adapter for the conversation thread + mConversationArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.message); + + mConversationView.setAdapter(mConversationArrayAdapter); + + // Initialize the compose field with a listener for the return key + mOutEditText.setOnEditorActionListener(mWriteListener); + + // Initialize the send button with a listener that for click events + mSendButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + // Send a message using content of the edit text widget + View view = getView(); + if (null != view) { + TextView textView = (TextView) view.findViewById(R.id.edit_text_out); + String message = textView.getText().toString(); + sendMessage(message); + } + } + }); + + // Initialize the BluetoothChatService to perform bluetooth connections + mChatService = new BluetoothChatService(getActivity(), mHandler); + + // Initialize the buffer for outgoing messages + mOutStringBuffer = new StringBuffer(""); + } + + /** + * Makes this device discoverable. + */ + private void ensureDiscoverable() { + if (mBluetoothAdapter.getScanMode() != + BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { + Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); + discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); + startActivity(discoverableIntent); + } + } + + /** + * Sends a message. + * + * @param message A string of text to send. + */ + private void sendMessage(String message) { + // Check that we're actually connected before trying anything + if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) { + Toast.makeText(getActivity(), R.string.not_connected, Toast.LENGTH_SHORT).show(); + return; + } + + // Check that there's actually something to send + if (message.length() > 0) { + // Get the message bytes and tell the BluetoothChatService to write + byte[] send = message.getBytes(); + mChatService.write(send); + + // Reset out string buffer to zero and clear the edit text field + mOutStringBuffer.setLength(0); + mOutEditText.setText(mOutStringBuffer); + } + } + + /** + * The action listener for the EditText widget, to listen for the return key + */ + private TextView.OnEditorActionListener mWriteListener + = new TextView.OnEditorActionListener() { + public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { + // If the action is a key-up event on the return key, send the message + if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_UP) { + String message = view.getText().toString(); + sendMessage(message); + } + return true; + } + }; + + /** + * Updates the status on the action bar. + * + * @param resId a string resource ID + */ + private void setStatus(int resId) { + FragmentActivity activity = getActivity(); + if (null == activity) { + return; + } + final ActionBar actionBar = activity.getActionBar(); + if (null == actionBar) { + return; + } + actionBar.setSubtitle(resId); + } + + /** + * Updates the status on the action bar. + * + * @param subTitle status + */ + private void setStatus(CharSequence subTitle) { + FragmentActivity activity = getActivity(); + if (null == activity) { + return; + } + final ActionBar actionBar = activity.getActionBar(); + if (null == actionBar) { + return; + } + actionBar.setSubtitle(subTitle); + } + + /** + * The Handler that gets information back from the BluetoothChatService + */ + private final Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + FragmentActivity activity = getActivity(); + switch (msg.what) { + case Constants.MESSAGE_STATE_CHANGE: + switch (msg.arg1) { + case BluetoothChatService.STATE_CONNECTED: + setStatus(getString(R.string.title_connected_to, mConnectedDeviceName)); + mConversationArrayAdapter.clear(); + break; + case BluetoothChatService.STATE_CONNECTING: + setStatus(R.string.title_connecting); + break; + case BluetoothChatService.STATE_LISTEN: + case BluetoothChatService.STATE_NONE: + setStatus(R.string.title_not_connected); + break; + } + break; + case Constants.MESSAGE_WRITE: + byte[] writeBuf = (byte[]) msg.obj; + // construct a string from the buffer + String writeMessage = new String(writeBuf); + mConversationArrayAdapter.add("Me: " + writeMessage); + break; + case Constants.MESSAGE_READ: + byte[] readBuf = (byte[]) msg.obj; + // construct a string from the valid bytes in the buffer + String readMessage = new String(readBuf, 0, msg.arg1); + mConversationArrayAdapter.add(mConnectedDeviceName + ": " + readMessage); + break; + case Constants.MESSAGE_DEVICE_NAME: + // save the connected device's name + mConnectedDeviceName = msg.getData().getString(Constants.DEVICE_NAME); + if (null != activity) { + Toast.makeText(activity, "Connected to " + + mConnectedDeviceName, Toast.LENGTH_SHORT).show(); + } + break; + case Constants.MESSAGE_TOAST: + if (null != activity) { + Toast.makeText(activity, msg.getData().getString(Constants.TOAST), + Toast.LENGTH_SHORT).show(); + } + break; + } + } + }; + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + case REQUEST_CONNECT_DEVICE_SECURE: + // When DeviceListActivity returns with a device to connect + if (resultCode == Activity.RESULT_OK) { + connectDevice(data, true); + } + break; + case REQUEST_CONNECT_DEVICE_INSECURE: + // When DeviceListActivity returns with a device to connect + if (resultCode == Activity.RESULT_OK) { + connectDevice(data, false); + } + break; + case REQUEST_ENABLE_BT: + // When the request to enable Bluetooth returns + if (resultCode == Activity.RESULT_OK) { + // Bluetooth is now enabled, so set up a chat session + setupChat(); + } else { + // User did not enable Bluetooth or an error occurred + Log.d(TAG, "BT not enabled"); + Toast.makeText(getActivity(), R.string.bt_not_enabled_leaving, + Toast.LENGTH_SHORT).show(); + getActivity().finish(); + } + } + } + + /** + * Establish connection with other divice + * + * @param data An {@link Intent} with {@link DeviceListActivity#EXTRA_DEVICE_ADDRESS} extra. + * @param secure Socket Security type - Secure (true) , Insecure (false) + */ + private void connectDevice(Intent data, boolean secure) { + // Get the device MAC address + String address = data.getExtras() + .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); + // Get the BluetoothDevice object + BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); + // Attempt to connect to the device + mChatService.connect(device, secure); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.bluetooth_chat, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.secure_connect_scan: { + // Launch the DeviceListActivity to see devices and do scan + Intent serverIntent = new Intent(getActivity(), DeviceListActivity.class); + startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE); + return true; + } + case R.id.insecure_connect_scan: { + // Launch the DeviceListActivity to see devices and do scan + Intent serverIntent = new Intent(getActivity(), DeviceListActivity.class); + startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE); + return true; + } + case R.id.discoverable: { + // Ensure this device is discoverable by others + ensureDiscoverable(); + return true; + } + } + return false; + } + +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/BluetoothChatService.java b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/BluetoothChatService.java new file mode 100644 index 000000000..b88b160d2 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/BluetoothChatService.java @@ -0,0 +1,519 @@ +/* + * Copyright (C) 2014 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.bluetoothchat; + +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothServerSocket; +import android.bluetooth.BluetoothSocket; +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; + +import com.example.android.common.logger.Log; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.UUID; + +/** + * This class does all the work for setting up and managing Bluetooth + * connections with other devices. It has a thread that listens for + * incoming connections, a thread for connecting with a device, and a + * thread for performing data transmissions when connected. + */ +public class BluetoothChatService { + // Debugging + private static final String TAG = "BluetoothChatService"; + + // Name for the SDP record when creating server socket + private static final String NAME_SECURE = "BluetoothChatSecure"; + private static final String NAME_INSECURE = "BluetoothChatInsecure"; + + // Unique UUID for this application + private static final UUID MY_UUID_SECURE = + UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66"); + private static final UUID MY_UUID_INSECURE = + UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66"); + + // Member fields + private final BluetoothAdapter mAdapter; + private final Handler mHandler; + private AcceptThread mSecureAcceptThread; + private AcceptThread mInsecureAcceptThread; + private ConnectThread mConnectThread; + private ConnectedThread mConnectedThread; + private int mState; + + // Constants that indicate the current connection state + public static final int STATE_NONE = 0; // we're doing nothing + public static final int STATE_LISTEN = 1; // now listening for incoming connections + public static final int STATE_CONNECTING = 2; // now initiating an outgoing connection + public static final int STATE_CONNECTED = 3; // now connected to a remote device + + /** + * Constructor. Prepares a new BluetoothChat session. + * + * @param context The UI Activity Context + * @param handler A Handler to send messages back to the UI Activity + */ + public BluetoothChatService(Context context, Handler handler) { + mAdapter = BluetoothAdapter.getDefaultAdapter(); + mState = STATE_NONE; + mHandler = handler; + } + + /** + * Set the current state of the chat connection + * + * @param state An integer defining the current connection state + */ + private synchronized void setState(int state) { + Log.d(TAG, "setState() " + mState + " -> " + state); + mState = state; + + // Give the new state to the Handler so the UI Activity can update + mHandler.obtainMessage(Constants.MESSAGE_STATE_CHANGE, state, -1).sendToTarget(); + } + + /** + * Return the current connection state. + */ + public synchronized int getState() { + return mState; + } + + /** + * Start the chat service. Specifically start AcceptThread to begin a + * session in listening (server) mode. Called by the Activity onResume() + */ + public synchronized void start() { + Log.d(TAG, "start"); + + // Cancel any thread attempting to make a connection + if (mConnectThread != null) { + mConnectThread.cancel(); + mConnectThread = null; + } + + // Cancel any thread currently running a connection + if (mConnectedThread != null) { + mConnectedThread.cancel(); + mConnectedThread = null; + } + + setState(STATE_LISTEN); + + // Start the thread to listen on a BluetoothServerSocket + if (mSecureAcceptThread == null) { + mSecureAcceptThread = new AcceptThread(true); + mSecureAcceptThread.start(); + } + if (mInsecureAcceptThread == null) { + mInsecureAcceptThread = new AcceptThread(false); + mInsecureAcceptThread.start(); + } + } + + /** + * Start the ConnectThread to initiate a connection to a remote device. + * + * @param device The BluetoothDevice to connect + * @param secure Socket Security type - Secure (true) , Insecure (false) + */ + public synchronized void connect(BluetoothDevice device, boolean secure) { + Log.d(TAG, "connect to: " + device); + + // Cancel any thread attempting to make a connection + if (mState == STATE_CONNECTING) { + if (mConnectThread != null) { + mConnectThread.cancel(); + mConnectThread = null; + } + } + + // Cancel any thread currently running a connection + if (mConnectedThread != null) { + mConnectedThread.cancel(); + mConnectedThread = null; + } + + // Start the thread to connect with the given device + mConnectThread = new ConnectThread(device, secure); + mConnectThread.start(); + setState(STATE_CONNECTING); + } + + /** + * Start the ConnectedThread to begin managing a Bluetooth connection + * + * @param socket The BluetoothSocket on which the connection was made + * @param device The BluetoothDevice that has been connected + */ + public synchronized void connected(BluetoothSocket socket, BluetoothDevice + device, final String socketType) { + Log.d(TAG, "connected, Socket Type:" + socketType); + + // Cancel the thread that completed the connection + if (mConnectThread != null) { + mConnectThread.cancel(); + mConnectThread = null; + } + + // Cancel any thread currently running a connection + if (mConnectedThread != null) { + mConnectedThread.cancel(); + mConnectedThread = null; + } + + // Cancel the accept thread because we only want to connect to one device + if (mSecureAcceptThread != null) { + mSecureAcceptThread.cancel(); + mSecureAcceptThread = null; + } + if (mInsecureAcceptThread != null) { + mInsecureAcceptThread.cancel(); + mInsecureAcceptThread = null; + } + + // Start the thread to manage the connection and perform transmissions + mConnectedThread = new ConnectedThread(socket, socketType); + mConnectedThread.start(); + + // Send the name of the connected device back to the UI Activity + Message msg = mHandler.obtainMessage(Constants.MESSAGE_DEVICE_NAME); + Bundle bundle = new Bundle(); + bundle.putString(Constants.DEVICE_NAME, device.getName()); + msg.setData(bundle); + mHandler.sendMessage(msg); + + setState(STATE_CONNECTED); + } + + /** + * Stop all threads + */ + public synchronized void stop() { + Log.d(TAG, "stop"); + + if (mConnectThread != null) { + mConnectThread.cancel(); + mConnectThread = null; + } + + if (mConnectedThread != null) { + mConnectedThread.cancel(); + mConnectedThread = null; + } + + if (mSecureAcceptThread != null) { + mSecureAcceptThread.cancel(); + mSecureAcceptThread = null; + } + + if (mInsecureAcceptThread != null) { + mInsecureAcceptThread.cancel(); + mInsecureAcceptThread = null; + } + setState(STATE_NONE); + } + + /** + * Write to the ConnectedThread in an unsynchronized manner + * + * @param out The bytes to write + * @see ConnectedThread#write(byte[]) + */ + public void write(byte[] out) { + // Create temporary object + ConnectedThread r; + // Synchronize a copy of the ConnectedThread + synchronized (this) { + if (mState != STATE_CONNECTED) return; + r = mConnectedThread; + } + // Perform the write unsynchronized + r.write(out); + } + + /** + * Indicate that the connection attempt failed and notify the UI Activity. + */ + private void connectionFailed() { + // Send a failure message back to the Activity + Message msg = mHandler.obtainMessage(Constants.MESSAGE_TOAST); + Bundle bundle = new Bundle(); + bundle.putString(Constants.TOAST, "Unable to connect device"); + msg.setData(bundle); + mHandler.sendMessage(msg); + + // Start the service over to restart listening mode + BluetoothChatService.this.start(); + } + + /** + * Indicate that the connection was lost and notify the UI Activity. + */ + private void connectionLost() { + // Send a failure message back to the Activity + Message msg = mHandler.obtainMessage(Constants.MESSAGE_TOAST); + Bundle bundle = new Bundle(); + bundle.putString(Constants.TOAST, "Device connection was lost"); + msg.setData(bundle); + mHandler.sendMessage(msg); + + // Start the service over to restart listening mode + BluetoothChatService.this.start(); + } + + /** + * This thread runs while listening for incoming connections. It behaves + * like a server-side client. It runs until a connection is accepted + * (or until cancelled). + */ + private class AcceptThread extends Thread { + // The local server socket + private final BluetoothServerSocket mmServerSocket; + private String mSocketType; + + public AcceptThread(boolean secure) { + BluetoothServerSocket tmp = null; + mSocketType = secure ? "Secure" : "Insecure"; + + // Create a new listening server socket + try { + if (secure) { + tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, + MY_UUID_SECURE); + } else { + tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( + NAME_INSECURE, MY_UUID_INSECURE); + } + } catch (IOException e) { + Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); + } + mmServerSocket = tmp; + } + + public void run() { + Log.d(TAG, "Socket Type: " + mSocketType + + "BEGIN mAcceptThread" + this); + setName("AcceptThread" + mSocketType); + + BluetoothSocket socket = null; + + // Listen to the server socket if we're not connected + while (mState != STATE_CONNECTED) { + try { + // This is a blocking call and will only return on a + // successful connection or an exception + socket = mmServerSocket.accept(); + } catch (IOException e) { + Log.e(TAG, "Socket Type: " + mSocketType + "accept() failed", e); + break; + } + + // If a connection was accepted + if (socket != null) { + synchronized (BluetoothChatService.this) { + switch (mState) { + case STATE_LISTEN: + case STATE_CONNECTING: + // Situation normal. Start the connected thread. + connected(socket, socket.getRemoteDevice(), + mSocketType); + break; + case STATE_NONE: + case STATE_CONNECTED: + // Either not ready or already connected. Terminate new socket. + try { + socket.close(); + } catch (IOException e) { + Log.e(TAG, "Could not close unwanted socket", e); + } + break; + } + } + } + } + Log.i(TAG, "END mAcceptThread, socket Type: " + mSocketType); + + } + + public void cancel() { + Log.d(TAG, "Socket Type" + mSocketType + "cancel " + this); + try { + mmServerSocket.close(); + } catch (IOException e) { + Log.e(TAG, "Socket Type" + mSocketType + "close() of server failed", e); + } + } + } + + + /** + * This thread runs while attempting to make an outgoing connection + * with a device. It runs straight through; the connection either + * succeeds or fails. + */ + private class ConnectThread extends Thread { + private final BluetoothSocket mmSocket; + private final BluetoothDevice mmDevice; + private String mSocketType; + + public ConnectThread(BluetoothDevice device, boolean secure) { + mmDevice = device; + BluetoothSocket tmp = null; + mSocketType = secure ? "Secure" : "Insecure"; + + // Get a BluetoothSocket for a connection with the + // given BluetoothDevice + try { + if (secure) { + tmp = device.createRfcommSocketToServiceRecord( + MY_UUID_SECURE); + } else { + tmp = device.createInsecureRfcommSocketToServiceRecord( + MY_UUID_INSECURE); + } + } catch (IOException e) { + Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e); + } + mmSocket = tmp; + } + + public void run() { + Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType); + setName("ConnectThread" + mSocketType); + + // Always cancel discovery because it will slow down a connection + mAdapter.cancelDiscovery(); + + // Make a connection to the BluetoothSocket + try { + // This is a blocking call and will only return on a + // successful connection or an exception + mmSocket.connect(); + } catch (IOException e) { + // Close the socket + try { + mmSocket.close(); + } catch (IOException e2) { + Log.e(TAG, "unable to close() " + mSocketType + + " socket during connection failure", e2); + } + connectionFailed(); + return; + } + + // Reset the ConnectThread because we're done + synchronized (BluetoothChatService.this) { + mConnectThread = null; + } + + // Start the connected thread + connected(mmSocket, mmDevice, mSocketType); + } + + public void cancel() { + try { + mmSocket.close(); + } catch (IOException e) { + Log.e(TAG, "close() of connect " + mSocketType + " socket failed", e); + } + } + } + + /** + * This thread runs during a connection with a remote device. + * It handles all incoming and outgoing transmissions. + */ + private class ConnectedThread extends Thread { + private final BluetoothSocket mmSocket; + private final InputStream mmInStream; + private final OutputStream mmOutStream; + + public ConnectedThread(BluetoothSocket socket, String socketType) { + Log.d(TAG, "create ConnectedThread: " + socketType); + mmSocket = socket; + InputStream tmpIn = null; + OutputStream tmpOut = null; + + // Get the BluetoothSocket input and output streams + try { + tmpIn = socket.getInputStream(); + tmpOut = socket.getOutputStream(); + } catch (IOException e) { + Log.e(TAG, "temp sockets not created", e); + } + + mmInStream = tmpIn; + mmOutStream = tmpOut; + } + + public void run() { + Log.i(TAG, "BEGIN mConnectedThread"); + byte[] buffer = new byte[1024]; + int bytes; + + // Keep listening to the InputStream while connected + while (true) { + try { + // Read from the InputStream + bytes = mmInStream.read(buffer); + + // Send the obtained bytes to the UI Activity + mHandler.obtainMessage(Constants.MESSAGE_READ, bytes, -1, buffer) + .sendToTarget(); + } catch (IOException e) { + Log.e(TAG, "disconnected", e); + connectionLost(); + // Start the service over to restart listening mode + BluetoothChatService.this.start(); + break; + } + } + } + + /** + * Write to the connected OutStream. + * + * @param buffer The bytes to write + */ + public void write(byte[] buffer) { + try { + mmOutStream.write(buffer); + + // Share the sent message back to the UI Activity + mHandler.obtainMessage(Constants.MESSAGE_WRITE, -1, -1, buffer) + .sendToTarget(); + } catch (IOException e) { + Log.e(TAG, "Exception during write", e); + } + } + + public void cancel() { + try { + mmSocket.close(); + } catch (IOException e) { + Log.e(TAG, "close() of connect socket failed", e); + } + } + } +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/Constants.java b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/Constants.java new file mode 100644 index 000000000..3500e8e70 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/Constants.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2014 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.bluetoothchat; + +/** + * Defines several constants used between {@link BluetoothChatService} and the UI. + */ +public interface Constants { + + // Message types sent from the BluetoothChatService Handler + public static final int MESSAGE_STATE_CHANGE = 1; + public static final int MESSAGE_READ = 2; + public static final int MESSAGE_WRITE = 3; + public static final int MESSAGE_DEVICE_NAME = 4; + public static final int MESSAGE_TOAST = 5; + + // Key names received from the BluetoothChatService Handler + public static final String DEVICE_NAME = "device_name"; + public static final String TOAST = "toast"; + +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/DeviceListActivity.java b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/DeviceListActivity.java new file mode 100644 index 000000000..8b70adc4c --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/DeviceListActivity.java @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2014 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.bluetoothchat; + +import android.app.Activity; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.view.View; +import android.view.Window; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.TextView; + +import com.example.android.common.logger.Log; + +import java.util.Set; + +/** + * This Activity appears as a dialog. It lists any paired devices and + * devices detected in the area after discovery. When a device is chosen + * by the user, the MAC address of the device is sent back to the parent + * Activity in the result Intent. + */ +public class DeviceListActivity extends Activity { + + /** + * Tag for Log + */ + private static final String TAG = "DeviceListActivity"; + + /** + * Return Intent extra + */ + public static String EXTRA_DEVICE_ADDRESS = "device_address"; + + /** + * Member fields + */ + private BluetoothAdapter mBtAdapter; + + /** + * Newly discovered devices + */ + private ArrayAdapter<String> mNewDevicesArrayAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Setup the window + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + setContentView(R.layout.activity_device_list); + + // Set result CANCELED in case the user backs out + setResult(Activity.RESULT_CANCELED); + + // Initialize the button to perform device discovery + Button scanButton = (Button) findViewById(R.id.button_scan); + scanButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + doDiscovery(); + v.setVisibility(View.GONE); + } + }); + + // Initialize array adapters. One for already paired devices and + // one for newly discovered devices + ArrayAdapter<String> pairedDevicesArrayAdapter = + new ArrayAdapter<String>(this, R.layout.device_name); + mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name); + + // Find and set up the ListView for paired devices + ListView pairedListView = (ListView) findViewById(R.id.paired_devices); + pairedListView.setAdapter(pairedDevicesArrayAdapter); + pairedListView.setOnItemClickListener(mDeviceClickListener); + + // Find and set up the ListView for newly discovered devices + ListView newDevicesListView = (ListView) findViewById(R.id.new_devices); + newDevicesListView.setAdapter(mNewDevicesArrayAdapter); + newDevicesListView.setOnItemClickListener(mDeviceClickListener); + + // Register for broadcasts when a device is discovered + IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); + this.registerReceiver(mReceiver, filter); + + // Register for broadcasts when discovery has finished + filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); + this.registerReceiver(mReceiver, filter); + + // Get the local Bluetooth adapter + mBtAdapter = BluetoothAdapter.getDefaultAdapter(); + + // Get a set of currently paired devices + Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); + + // If there are paired devices, add each one to the ArrayAdapter + if (pairedDevices.size() > 0) { + findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); + for (BluetoothDevice device : pairedDevices) { + pairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); + } + } else { + String noDevices = getResources().getText(R.string.none_paired).toString(); + pairedDevicesArrayAdapter.add(noDevices); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + // Make sure we're not doing discovery anymore + if (mBtAdapter != null) { + mBtAdapter.cancelDiscovery(); + } + + // Unregister broadcast listeners + this.unregisterReceiver(mReceiver); + } + + /** + * Start device discover with the BluetoothAdapter + */ + private void doDiscovery() { + Log.d(TAG, "doDiscovery()"); + + // Indicate scanning in the title + setProgressBarIndeterminateVisibility(true); + setTitle(R.string.scanning); + + // Turn on sub-title for new devices + findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE); + + // If we're already discovering, stop it + if (mBtAdapter.isDiscovering()) { + mBtAdapter.cancelDiscovery(); + } + + // Request discover from BluetoothAdapter + mBtAdapter.startDiscovery(); + } + + /** + * The on-click listener for all devices in the ListViews + */ + private AdapterView.OnItemClickListener mDeviceClickListener + = new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) { + // Cancel discovery because it's costly and we're about to connect + mBtAdapter.cancelDiscovery(); + + // Get the device MAC address, which is the last 17 chars in the View + String info = ((TextView) v).getText().toString(); + String address = info.substring(info.length() - 17); + + // Create the result Intent and include the MAC address + Intent intent = new Intent(); + intent.putExtra(EXTRA_DEVICE_ADDRESS, address); + + // Set result and finish this Activity + setResult(Activity.RESULT_OK, intent); + finish(); + } + }; + + /** + * The BroadcastReceiver that listens for discovered devices and changes the title when + * discovery is finished + */ + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + + // When discovery finds a device + if (BluetoothDevice.ACTION_FOUND.equals(action)) { + // Get the BluetoothDevice object from the Intent + BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + // If it's already paired, skip it, because it's been listed already + if (device.getBondState() != BluetoothDevice.BOND_BONDED) { + mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); + } + // When discovery is finished, change the Activity title + } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { + setProgressBarIndeterminateVisibility(false); + setTitle(R.string.select_device); + if (mNewDevicesArrayAdapter.getCount() == 0) { + String noDevices = getResources().getText(R.string.none_found).toString(); + mNewDevicesArrayAdapter.add(noDevices); + } + } + } + }; + +} diff --git a/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/MainActivity.java b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/MainActivity.java new file mode 100644 index 000000000..cf4ec47e3 --- /dev/null +++ b/samples/browseable/BluetoothChat/src/com.example.android.bluetoothchat/MainActivity.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. +*/ + +package com.example.android.bluetoothchat; + +import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.ViewAnimator; + +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, sample log and a custom + * {@link android.support.v4.app.Fragment} which can display a view. + * <p> + * For devices with displays with a width of 720dp or greater, the sample log is always visible, + * on other devices it's visibility is controlled by an item on the Action Bar. + */ +public class MainActivity extends SampleActivityBase { + + public static final String TAG = "MainActivity"; + + // Whether the Log Fragment is currently shown + private boolean mLogShown; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + BluetoothChatFragment fragment = new BluetoothChatFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + MenuItem logToggle = menu.findItem(R.id.menu_toggle_log); + logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator); + logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log); + + return super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch(item.getItemId()) { + case R.id.menu_toggle_log: + mLogShown = !mLogShown; + ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output); + if (mLogShown) { + output.setDisplayedChild(1); + } else { + output.setDisplayedChild(0); + } + supportInvalidateOptionsMenu(); + return true; + } + return super.onOptionsItemSelected(item); + } + + /** 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/AgendaData/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/BluetoothChat/src/com.example.android.common/activities/SampleActivityBase.java index 3228927b7..3228927b7 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/activities/SampleActivityBase.java diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/Log.java index 17503c568..17503c568 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/Log.java +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/Log.java diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogFragment.java index b302acd4b..b302acd4b 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogFragment.java diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogNode.java index bc37cabc0..bc37cabc0 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogNode.java diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogView.java index c01542b91..c01542b91 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogView.java diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogWrapper.java index 16a9e7ba2..16a9e7ba2 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/LogWrapper.java diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/MessageOnlyLogFilter.java index 19967dcd4..19967dcd4 100644 --- a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ b/samples/browseable/BluetoothChat/src/com.example.android.common/logger/MessageOnlyLogFilter.java diff --git a/samples/browseable/BluetoothLeGatt/AndroidManifest.xml b/samples/browseable/BluetoothLeGatt/AndroidManifest.xml index babd6df2d..d3cf25757 100644 --- a/samples/browseable/BluetoothLeGatt/AndroidManifest.xml +++ b/samples/browseable/BluetoothLeGatt/AndroidManifest.xml @@ -22,8 +22,8 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="18" - android:targetSdkVersion="18"/> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> + <!-- Declare this required feature if you want to make the app available to BLE-capable devices only. If you want to make your app available to devices that don't support BLE, you should omit this in the manifest. Instead, determine BLE capability by using diff --git a/samples/browseable/BluetoothLeGatt/_index.jd b/samples/browseable/BluetoothLeGatt/_index.jd index 6e8966940..13d9cb68c 100644 --- a/samples/browseable/BluetoothLeGatt/_index.jd +++ b/samples/browseable/BluetoothLeGatt/_index.jd @@ -1,12 +1,10 @@ - - - page.tags="BluetoothLeGatt" sample.group=Connectivity @jd:body -<p>This sample demonstrates how to use the Bluetooth Low Energy Generic -Attribute Profile (GATT) to transmit arbitrary data between devices. For more -information about using Android's suppport for Bluetooth Low Energy, see -<a href="{@docRoot}guide/topics/connectivity/bluetooth-le.html">Bluetooth Low -Energy</a>.</p> +<p> + + This sample demonstrates how to use the Bluetooth LE Generic Attribute Profile (GATT) + to transmit arbitrary data between devices. + + </p> diff --git a/samples/browseable/BluetoothLeGatt/res/values-v21/template-styles.xml b/samples/browseable/BluetoothLeGatt/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BluetoothLeGatt/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BluetoothLeGatt/res/values/base-strings.xml b/samples/browseable/BluetoothLeGatt/res/values/base-strings.xml index 58b49a95f..f3b546cba 100644 --- a/samples/browseable/BluetoothLeGatt/res/values/base-strings.xml +++ b/samples/browseable/BluetoothLeGatt/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BluetoothLeGatt</string> <string name="intro_message"> diff --git a/samples/browseable/BorderlessButtons/AndroidManifest.xml b/samples/browseable/BorderlessButtons/AndroidManifest.xml index 34b28985d..90b92cfb5 100644 --- a/samples/browseable/BorderlessButtons/AndroidManifest.xml +++ b/samples/browseable/BorderlessButtons/AndroidManifest.xml @@ -28,7 +28,7 @@ This sample requires API 14 for use of theme attributes such as ?android:listPreferredItemPaddingLeft. --> - <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher" diff --git a/samples/browseable/BorderlessButtons/_index.jd b/samples/browseable/BorderlessButtons/_index.jd index 0d43c98be..a940d1848 100644 --- a/samples/browseable/BorderlessButtons/_index.jd +++ b/samples/browseable/BorderlessButtons/_index.jd @@ -1,9 +1,10 @@ - - - page.tags="BorderlessButtons" sample.group=UI @jd:body -<p>This sample demonstrates how to apply borderless buttons, bottom button bars -(OK and Cancel), and dividers to establish visual structure.</p> +<p> + + This sample demonstrates the use of borderless buttons, bottom button bars + (OK and Cancel) and dividers to establish visual structure. + + </p> diff --git a/samples/browseable/BorderlessButtons/res/values-v21/template-styles.xml b/samples/browseable/BorderlessButtons/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/BorderlessButtons/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/BorderlessButtons/res/values/base-strings.xml b/samples/browseable/BorderlessButtons/res/values/base-strings.xml index efbd14d01..14f5df2d6 100644 --- a/samples/browseable/BorderlessButtons/res/values/base-strings.xml +++ b/samples/browseable/BorderlessButtons/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">BorderlessButtons</string> <string name="intro_message"> diff --git a/samples/browseable/CardEmulation/AndroidManifest.xml b/samples/browseable/CardEmulation/AndroidManifest.xml index 4a4af0882..fba9a74d7 100644 --- a/samples/browseable/CardEmulation/AndroidManifest.xml +++ b/samples/browseable/CardEmulation/AndroidManifest.xml @@ -21,7 +21,7 @@ android:versionName="1.0"> <!-- Card emulation was introduced in API 19. --> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <uses-feature android:name="android.hardware.nfc.hce" android:required="true" /> <uses-permission android:name="android.permission.NFC" /> diff --git a/samples/browseable/CardEmulation/_index.jd b/samples/browseable/CardEmulation/_index.jd index 1f3e3c7d3..6a4ce5d72 100644 --- a/samples/browseable/CardEmulation/_index.jd +++ b/samples/browseable/CardEmulation/_index.jd @@ -1,19 +1,14 @@ - - - page.tags="CardEmulation" sample.group=Connectivity @jd:body <p> - This sample demonstrates how to emulate an NFC card, using the <a href= - "{@docRoot}guide/topics/connectivity/nfc/hce.html">Host Card Emulation</a> - feature added in Android 4.4. This sample makes the device appear as a - loyalty card whenever the screen is on and the user taps their device on an - appropriately configured NFC reader. -</p> - -<p> - The <a href="{@docRoot}samples/CardReader/index.html">CardReader</a> sample - can be used to read the loyalty card implemented in this sample. -</p> + + This sample demonstrates how to emulate an NFC card, using the "host card emulation" + feature added in Android 4.4. This sample makes the device appear as a loyalty card + whenever the screen is on and the user taps their device on an appropriately configured + NFC reader. + + The "CardReader" sample can be used to read the loyalty card implemented in this sample. + + </p> diff --git a/samples/browseable/CardEmulation/res/values-v21/template-styles.xml b/samples/browseable/CardEmulation/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CardEmulation/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/CardEmulation/res/values/base-strings.xml b/samples/browseable/CardEmulation/res/values/base-strings.xml index 9062a239a..8bd733216 100644 --- a/samples/browseable/CardEmulation/res/values/base-strings.xml +++ b/samples/browseable/CardEmulation/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">CardEmulation</string> <string name="intro_message"> diff --git a/samples/browseable/CardEmulation/res/values/strings.xml b/samples/browseable/CardEmulation/res/values/strings.xml index f7082845f..f7082845f 100755..100644 --- a/samples/browseable/CardEmulation/res/values/strings.xml +++ b/samples/browseable/CardEmulation/res/values/strings.xml diff --git a/samples/browseable/CardEmulation/src/com.example.android.cardemulation/MainActivity.java b/samples/browseable/CardEmulation/src/com.example.android.cardemulation/MainActivity.java index 0515609d0..af0b9f310 100644 --- a/samples/browseable/CardEmulation/src/com.example.android.cardemulation/MainActivity.java +++ b/samples/browseable/CardEmulation/src/com.example.android.cardemulation/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.cardemulation; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - CardEmulationFragment fragment = new CardEmulationFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + CardEmulationFragment fragment = new CardEmulationFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/CardReader/AndroidManifest.xml b/samples/browseable/CardReader/AndroidManifest.xml index a8ebd133a..ed25c6f56 100644 --- a/samples/browseable/CardReader/AndroidManifest.xml +++ b/samples/browseable/CardReader/AndroidManifest.xml @@ -21,7 +21,7 @@ android:versionName="1.0"> <!-- NFC Reader Mode was added in API 19. --> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <uses-permission android:name="android.permission.NFC" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /> diff --git a/samples/browseable/CardReader/_index.jd b/samples/browseable/CardReader/_index.jd index 9ba051e19..4322b3fb6 100644 --- a/samples/browseable/CardReader/_index.jd +++ b/samples/browseable/CardReader/_index.jd @@ -1,20 +1,14 @@ - - - page.tags="CardReader" sample.group=Connectivity @jd:body <p> - This sample demonstrates how to implement a low-level NFC card reader, for - reading cards that do not contain NDEF or Android Beam data. This sample is - designed to read the virtual loyalty card implemented in the <a href= - "{@docRoot}samples/CardEmulation/index.html">CardEmulation</a> sample. -</p> - -<p> - In particular, this sample demonstrates how to disable Android Beam, select - which AIDs the reader is interested in, and establish communication with the - card. See <a href="{@docRoot}guide/topics/connectivity/nfc/hce.html">Host-based - Card Emulation</a> for more information on the HCE APIs. -</p> + + This sample demonstrates how to implement a low-level NFC card reader, for reading cards + that do not contain NDEF or Android Beam data. This sample is designed to read the virtual + loyalty card implemented in the "CardEmulation" sample.\n\n + + In particular, this sample demonstrates how to disable Android Beam, select which AIDs the + reader is interested, and establish communication with the card + + </p> diff --git a/samples/browseable/CardReader/res/values-v21/template-styles.xml b/samples/browseable/CardReader/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CardReader/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/CardReader/res/values/base-strings.xml b/samples/browseable/CardReader/res/values/base-strings.xml index ac1248054..efede3bce 100644 --- a/samples/browseable/CardReader/res/values/base-strings.xml +++ b/samples/browseable/CardReader/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">CardReader</string> <string name="intro_message"> diff --git a/samples/browseable/CardReader/res/values/strings.xml b/samples/browseable/CardReader/res/values/strings.xml index b1b1a4954..b1b1a4954 100755..100644 --- a/samples/browseable/CardReader/res/values/strings.xml +++ b/samples/browseable/CardReader/res/values/strings.xml diff --git a/samples/browseable/CardReader/src/com.example.android.cardreader/MainActivity.java b/samples/browseable/CardReader/src/com.example.android.cardreader/MainActivity.java index e0280e998..ac6327d30 100644 --- a/samples/browseable/CardReader/src/com.example.android.cardreader/MainActivity.java +++ b/samples/browseable/CardReader/src/com.example.android.cardreader/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.cardreader; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - CardReaderFragment fragment = new CardReaderFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + CardReaderFragment fragment = new CardReaderFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/CustomChoiceList/AndroidManifest.xml b/samples/browseable/CustomChoiceList/AndroidManifest.xml index 8c194f536..8b0653e57 100644 --- a/samples/browseable/CustomChoiceList/AndroidManifest.xml +++ b/samples/browseable/CustomChoiceList/AndroidManifest.xml @@ -19,7 +19,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher" diff --git a/samples/browseable/CustomChoiceList/_index.jd b/samples/browseable/CustomChoiceList/_index.jd index 67a23cc93..65ad14ff5 100644 --- a/samples/browseable/CustomChoiceList/_index.jd +++ b/samples/browseable/CustomChoiceList/_index.jd @@ -1,9 +1,10 @@ - - - page.tags="CustomChoiceList" sample.group=UI @jd:body -<p>This sample demonstrates how to implement a custom single-choice or -multi-choice {@link android.widget.ListView} user interface.</p> +<p> + + This sample demonstrates how to create custom checkable layouts, for use with ListView\'s choiceMode + attribute. + + </p> diff --git a/samples/browseable/CustomChoiceList/res/values-v21/template-styles.xml b/samples/browseable/CustomChoiceList/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CustomChoiceList/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/CustomChoiceList/res/values/base-strings.xml b/samples/browseable/CustomChoiceList/res/values/base-strings.xml index e2890c46a..b5fdc00f9 100644 --- a/samples/browseable/CustomChoiceList/res/values/base-strings.xml +++ b/samples/browseable/CustomChoiceList/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">CustomChoiceList</string> <string name="intro_message"> diff --git a/samples/browseable/CustomNotifications/AndroidManifest.xml b/samples/browseable/CustomNotifications/AndroidManifest.xml index b20a41196..3054ad7cf 100644 --- a/samples/browseable/CustomNotifications/AndroidManifest.xml +++ b/samples/browseable/CustomNotifications/AndroidManifest.xml @@ -22,9 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="4" - android:targetSdkVersion="18" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/CustomNotifications/_index.jd b/samples/browseable/CustomNotifications/_index.jd index ab3499c1c..86c829a27 100644 --- a/samples/browseable/CustomNotifications/_index.jd +++ b/samples/browseable/CustomNotifications/_index.jd @@ -1,9 +1,9 @@ - - - page.tags="CustomNotifications" -sample.group=UI +sample.group=Notification @jd:body -<p>This sample demonstrates how to implement expanded notifications that -display custom views.</p> +<p> + + This sample demonstrates notifications with custom content views. + + </p> diff --git a/samples/browseable/CustomNotifications/res/values-v21/template-styles.xml b/samples/browseable/CustomNotifications/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CustomNotifications/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/CustomNotifications/res/values/base-strings.xml b/samples/browseable/CustomNotifications/res/values/base-strings.xml index 7ddbc2dc2..ad3bb89cd 100644 --- a/samples/browseable/CustomNotifications/res/values/base-strings.xml +++ b/samples/browseable/CustomNotifications/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">CustomNotifications</string> <string name="intro_message"> diff --git a/samples/browseable/CustomTransition/AndroidManifest.xml b/samples/browseable/CustomTransition/AndroidManifest.xml index b3328f19a..010cf7836 100644 --- a/samples/browseable/CustomTransition/AndroidManifest.xml +++ b/samples/browseable/CustomTransition/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/CustomTransition/_index.jd b/samples/browseable/CustomTransition/_index.jd index c68a76201..f5f16feb3 100644 --- a/samples/browseable/CustomTransition/_index.jd +++ b/samples/browseable/CustomTransition/_index.jd @@ -1,8 +1,9 @@ - - - page.tags="CustomTransition" sample.group=UI @jd:body -<p>This sample demonstrates how to create and use a custom {@link android.transition.Transition}.</p> +<p> + + This sample demonstrates how to create and use a custom Transition. + + </p> diff --git a/samples/browseable/CustomTransition/res/values-v21/template-styles.xml b/samples/browseable/CustomTransition/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/CustomTransition/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/CustomTransition/res/values/base-strings.xml b/samples/browseable/CustomTransition/res/values/base-strings.xml index 68c9c4146..ee1dad40a 100644 --- a/samples/browseable/CustomTransition/res/values/base-strings.xml +++ b/samples/browseable/CustomTransition/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">CustomTransition</string> <string name="intro_message"> diff --git a/samples/browseable/CustomTransition/src/com.example.android.customtransition/MainActivity.java b/samples/browseable/CustomTransition/src/com.example.android.customtransition/MainActivity.java index 04c4e4d9b..bbb6dc06e 100644 --- a/samples/browseable/CustomTransition/src/com.example.android.customtransition/MainActivity.java +++ b/samples/browseable/CustomTransition/src/com.example.android.customtransition/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.customtransition; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - CustomTransitionFragment fragment = new CustomTransitionFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + CustomTransitionFragment fragment = new CustomTransitionFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/DataLayer/Application/AndroidManifest.xml b/samples/browseable/DataLayer/Application/AndroidManifest.xml index f382b255a..787e27361 100644 --- a/samples/browseable/DataLayer/Application/AndroidManifest.xml +++ b/samples/browseable/DataLayer/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.datalayer" > + package="com.example.android.wearable.datalayer" > <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/DataLayer/Application/res/values-v21/template-styles.xml b/samples/browseable/DataLayer/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/DataLayer/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java b/samples/browseable/DataLayer/Application/src/com.example.android.wearable.datalayer/MainActivity.java index d94261dd9..23bc696d3 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java +++ b/samples/browseable/DataLayer/Application/src/com.example.android.wearable.datalayer/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.datalayer; +package com.example.android.wearable.datalayer; import android.app.Activity; import android.content.Context; diff --git a/samples/browseable/DataLayer/Wearable/AndroidManifest.xml b/samples/browseable/DataLayer/Wearable/AndroidManifest.xml index 7bde39a8c..38c079830 100644 --- a/samples/browseable/DataLayer/Wearable/AndroidManifest.xml +++ b/samples/browseable/DataLayer/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.datalayer" > + package="com.example.android.wearable.datalayer" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -47,7 +47,7 @@ <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter> - <action android:name="com.example.android.datalayer.EXAMPLE"/> + <action android:name="com.example.android.wearable.datalayer.EXAMPLE"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> diff --git a/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/DataLayerListenerService.java b/samples/browseable/DataLayer/Wearable/src/com.example.android.wearable.datalayer/DataLayerListenerService.java index 9356f394b..64abaf54d 100644 --- a/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/DataLayerListenerService.java +++ b/samples/browseable/DataLayer/Wearable/src/com.example.android.wearable.datalayer/DataLayerListenerService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.datalayer; +package com.example.android.wearable.datalayer; import android.content.Intent; import android.net.Uri; diff --git a/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/MainActivity.java b/samples/browseable/DataLayer/Wearable/src/com.example.android.wearable.datalayer/MainActivity.java index 5f763b8b2..b3121352e 100644 --- a/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/MainActivity.java +++ b/samples/browseable/DataLayer/Wearable/src/com.example.android.wearable.datalayer/MainActivity.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.example.android.datalayer; +package com.example.android.wearable.datalayer; -import static com.example.android.datalayer.DataLayerListenerService.LOGD; +import static com.example.android.wearable.datalayer.DataLayerListenerService.LOGD; import android.app.Activity; import android.content.Context; diff --git a/samples/browseable/DelayedConfirmation/Application/AndroidManifest.xml b/samples/browseable/DelayedConfirmation/Application/AndroidManifest.xml index 115ebec43..3fa1f36fc 100644 --- a/samples/browseable/DelayedConfirmation/Application/AndroidManifest.xml +++ b/samples/browseable/DelayedConfirmation/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.delayedconfirmation" > + package="com.example.android.wearable.delayedconfirmation" > <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/DelayedConfirmation/Application/res/values-v21/template-styles.xml b/samples/browseable/DelayedConfirmation/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/DelayedConfirmation/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/DelayedConfirmation/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.wearable.delayedconfirmation/MainActivity.java index 6fe681f62..3ffda5374 100644 --- a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java +++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.wearable.delayedconfirmation/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.delayedconfirmation; +package com.example.android.wearable.delayedconfirmation; import android.app.Activity; import android.os.Bundle; diff --git a/samples/browseable/DelayedConfirmation/Wearable/AndroidManifest.xml b/samples/browseable/DelayedConfirmation/Wearable/AndroidManifest.xml index a2200089e..b73af6276 100644 --- a/samples/browseable/DelayedConfirmation/Wearable/AndroidManifest.xml +++ b/samples/browseable/DelayedConfirmation/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.delayedconfirmation" > + package="com.example.android.wearable.delayedconfirmation" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> diff --git a/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/MainActivity.java b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.wearable.delayedconfirmation/MainActivity.java index 2e169c797..f9b126db3 100644 --- a/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/MainActivity.java +++ b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.wearable.delayedconfirmation/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.delayedconfirmation; +package com.example.android.wearable.delayedconfirmation; import android.app.Activity; import android.app.Notification; diff --git a/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/WearableMessageListenerService.java b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.wearable.delayedconfirmation/WearableMessageListenerService.java index 0032fda71..bb2ec9193 100644 --- a/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/WearableMessageListenerService.java +++ b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.wearable.delayedconfirmation/WearableMessageListenerService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.delayedconfirmation; +package com.example.android.wearable.delayedconfirmation; import android.content.Intent; diff --git a/samples/browseable/DisplayingBitmaps/AndroidManifest.xml b/samples/browseable/DisplayingBitmaps/AndroidManifest.xml index 23db308a3..a58027743 100644 --- a/samples/browseable/DisplayingBitmaps/AndroidManifest.xml +++ b/samples/browseable/DisplayingBitmaps/AndroidManifest.xml @@ -20,7 +20,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> diff --git a/samples/browseable/DisplayingBitmaps/_index.jd b/samples/browseable/DisplayingBitmaps/_index.jd index eb880978f..e4b4f1570 100644 --- a/samples/browseable/DisplayingBitmaps/_index.jd +++ b/samples/browseable/DisplayingBitmaps/_index.jd @@ -1,21 +1,15 @@ - - - page.tags="DisplayingBitmaps" sample.group=UI @jd:body -<p>This is a sample application for the -<a href="{@docRoot}training/displaying-bitmaps/index.html">Displaying -Bitmaps Efficiently</a> Android Training class.</p> - <p> -The sample demonstrates: -</p> -<ul> -<li>Loading large bitmaps efficiently outside the main UI thread.</li> -<li>Caching bitmaps (both in memory and on disk).</li> -<li>Managing bitmap memory.</li> -<li>Displaying bitmaps in UI elements (such as {@link android.support.v4.view.ViewPager ViewPager}, -{@link android.widget.ListView ListView}, and {@link android.widget.GridView GridView}).</li> -</ul>
\ No newline at end of file + + This is a sample application for the Android Training class + "Displaying Bitmaps Efficiently" + (http://developer.android.com/training/displaying-bitmaps/).\n\n + + It demonstrates how to load large bitmaps efficiently off the main UI thread, caching + bitmaps (both in memory and on disk), managing bitmap memory and displaying bitmaps + in UI elements such as ViewPager and ListView/GridView. + + </p> diff --git a/samples/browseable/DisplayingBitmaps/res/values-v21/template-styles.xml b/samples/browseable/DisplayingBitmaps/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/DisplayingBitmaps/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/DisplayingBitmaps/res/values/base-strings.xml b/samples/browseable/DisplayingBitmaps/res/values/base-strings.xml index a6a8390a6..440137171 100644 --- a/samples/browseable/DisplayingBitmaps/res/values/base-strings.xml +++ b/samples/browseable/DisplayingBitmaps/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">DisplayingBitmaps</string> <string name="intro_message"> diff --git a/samples/browseable/DoneBar/AndroidManifest.xml b/samples/browseable/DoneBar/AndroidManifest.xml index 473111435..820fae590 100644 --- a/samples/browseable/DoneBar/AndroidManifest.xml +++ b/samples/browseable/DoneBar/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher" diff --git a/samples/browseable/DoneBar/_index.jd b/samples/browseable/DoneBar/_index.jd index 8ef219c9a..b692bb981 100644 --- a/samples/browseable/DoneBar/_index.jd +++ b/samples/browseable/DoneBar/_index.jd @@ -1,12 +1,15 @@ - - - page.tags="DoneBar" sample.group=UI @jd:body -<p>This sample demonstrates a user interface design pattern for simple data -entry from an {@link android.app.ActionBar}. The sample implements a custom -<strong>Done/Cancel</strong> bar to provide users with an easy way to directly -save or cancel their changes. This design pattern is suitable for scenarios -where no additional view details or actions are needed in the action bar.</p> +<p> + + This sample demonstrates two alternative presentations of the + action bar that are well-suited for simple data entry scenarios. + + In this presentation, a done bar replaces the action + bar entirely, providing two direct actions to persist or dismiss changes. This is + suitable for cases where no additional view details or actions are needed in the + action bar. + + </p> diff --git a/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml b/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml index 38987ee20..516d28989 100644 --- a/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml +++ b/samples/browseable/DoneBar/res/layout/sample_dashboard_item.xml @@ -14,19 +14,37 @@ limitations under the License. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - style="@style/Widget.SampleDashboard.Item" +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> + android:layout_height="wrap_content"> + <!-- The CardView needs to be wrapped to ensure spacing is applied correctly. --> - <TextView android:id="@android:id/text1" - style="@style/Widget.SampleDashboard.Item.Title" + <android.support.v7.widget.CardView + style="@style/Widget.SampleDashboard.Card" android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content"> - <TextView android:id="@android:id/text2" - style="@style/Widget.SampleDashboard.Item.Description" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> -</LinearLayout> + <LinearLayout + style="@style/Widget.SampleDashboard.Item" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@android:id/text1" + style="@style/Widget.SampleDashboard.Item.Title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Hello world" /> + + <TextView + android:id="@android:id/text2" + style="@style/Widget.SampleDashboard.Item.Description" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + </LinearLayout> + + </android.support.v7.widget.CardView> + +</FrameLayout> diff --git a/samples/browseable/DoneBar/res/values-v21/template-styles.xml b/samples/browseable/DoneBar/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/DoneBar/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/DoneBar/res/values/activitycards-colors.xml b/samples/browseable/DoneBar/res/values/activitycards-colors.xml new file mode 100644 index 000000000..79605c7c9 --- /dev/null +++ b/samples/browseable/DoneBar/res/values/activitycards-colors.xml @@ -0,0 +1,21 @@ +<!-- + Copyright 2014 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> + <color name="teal">#009688</color> + <color name="black_87">#DD000000</color> + <color name="black_54">#89000000</color> +</resources> diff --git a/samples/browseable/DoneBar/res/values/activitycards-dimens.xml b/samples/browseable/DoneBar/res/values/activitycards-dimens.xml new file mode 100644 index 000000000..714cb00f2 --- /dev/null +++ b/samples/browseable/DoneBar/res/values/activitycards-dimens.xml @@ -0,0 +1,22 @@ +<!-- + 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> + + <dimen name="card_padding">16dp</dimen> + <dimen name="card_margin">8dp</dimen> + +</resources>
\ No newline at end of file diff --git a/samples/browseable/DoneBar/res/values/activitycards-strings.xml b/samples/browseable/DoneBar/res/values/activitycards-strings.xml index 5c2557c97..430286c31 100644 --- a/samples/browseable/DoneBar/res/values/activitycards-strings.xml +++ b/samples/browseable/DoneBar/res/values/activitycards-strings.xml @@ -15,9 +15,6 @@ limitations under the License. --> - - - <resources> <string name="donebaractivity_title">Done Bar</string> <string name="donebaractivity_description">In this presentation, a done bar replaces the action bar entirely, providing diff --git a/samples/browseable/DoneBar/res/values/base-strings.xml b/samples/browseable/DoneBar/res/values/base-strings.xml index 22a4fae9f..f7e0540ca 100644 --- a/samples/browseable/DoneBar/res/values/base-strings.xml +++ b/samples/browseable/DoneBar/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">DoneBar</string> <string name="intro_message"> diff --git a/samples/browseable/DelayedConfirmation/Shared/res/values/strings.xml b/samples/browseable/DoneBar/res/values/template-attrs.xml index 0f2bb9075..442ed7781 100644 --- a/samples/browseable/DelayedConfirmation/Shared/res/values/strings.xml +++ b/samples/browseable/DoneBar/res/values/template-attrs.xml @@ -1,18 +1,15 @@ <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2014 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">Shared</string> -</resources> +</resources>
\ No newline at end of file diff --git a/samples/browseable/DoneBar/res/values/template-styles.xml b/samples/browseable/DoneBar/res/values/template-styles.xml index cafe531a4..374dc515d 100644 --- a/samples/browseable/DoneBar/res/values/template-styles.xml +++ b/samples/browseable/DoneBar/res/values/template-styles.xml @@ -34,9 +34,10 @@ <item name="android:paddingRight">@dimen/horizontal_page_margin</item> </style> - <style name="Widget.SampleMessage"> +<style name="Widget.SampleMessage"> <item name="android:textAppearance">?android:textAppearanceMedium</item> <item name="android:lineSpacingMultiplier">1.1</item> + <item name="android:textColor">@color/black_54</item> </style> <style name="Widget.SampleDashboard.Grid" parent="Widget"> @@ -44,28 +45,32 @@ <item name="android:columnWidth">200dp</item> <item name="android:numColumns">auto_fit</item> <item name="android:drawSelectorOnTop">true</item> - <item name="android:horizontalSpacing">@dimen/margin_medium</item> - <item name="android:verticalSpacing">@dimen/margin_medium</item> + <item name="android:horizontalSpacing">0dp</item> + <item name="android:verticalSpacing">0dp</item> + </style> + + <style name="Widget.SampleDashboard.Card" parent="Widget"> + <item name="android:gravity">center</item> + <item name="android:layout_margin">@dimen/card_margin</item> + <item name="cardCornerRadius">4dp</item> + <item name="cardElevation">5dp</item> + <item name="contentPadding">@dimen/card_padding</item> </style> <style name="Widget.SampleDashboard.Item" parent="Widget"> - <item name="android:background">@drawable/sample_dashboard_item_background</item> - <item name="android:paddingTop">@dimen/margin_small</item> - <item name="android:paddingLeft">@dimen/margin_medium</item> - <item name="android:paddingRight">@dimen/margin_medium</item> - <item name="android:paddingBottom">@dimen/margin_medium</item> </style> <style name="Widget.SampleDashboard.Item.Title" parent="Widget"> <item name="android:layout_marginBottom">@dimen/margin_tiny</item> <item name="android:textAppearance">?android:textAppearanceLarge</item> - <item name="android:textColor">#09c</item> - <item name="android:textStyle">bold</item> + <item name="android:textColor">@color/teal</item> + <item name="android:fontFamily">sans-serif</item> <item name="android:textSize">24sp</item> </style> <style name="Widget.SampleDashboard.Item.Description" parent="Widget"> <item name="android:textAppearance">?android:textAppearanceSmall</item> <item name="android:fontFamily">sans-serif-light</item> + <item name="android:textColor">@color/black_87</item> </style> </resources> diff --git a/samples/browseable/DoneBar/src/com.example.android.donebar/MainActivity.java b/samples/browseable/DoneBar/src/com.example.android.donebar/MainActivity.java index 8b1e8a469..c51996c4c 100644 --- a/samples/browseable/DoneBar/src/com.example.android.donebar/MainActivity.java +++ b/samples/browseable/DoneBar/src/com.example.android.donebar/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.donebar; import android.app.Activity; diff --git a/samples/browseable/ElizaChat/Application/AndroidManifest.xml b/samples/browseable/ElizaChat/Application/AndroidManifest.xml index e653fa9d6..14e982383 100644 --- a/samples/browseable/ElizaChat/Application/AndroidManifest.xml +++ b/samples/browseable/ElizaChat/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.elizachat" > + package="com.example.android.wearable.elizachat" > <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> @@ -36,8 +36,8 @@ <service android:name=".ResponderService"> <intent-filter> - <action android:name="com.example.android.elizachat.REPLY" /> - <action android:name="com.example.android.elizachat.CONVERSATION" /> + <action android:name="com.example.android.wearable.elizachat.REPLY" /> + <action android:name="com.example.android.wearable.elizachat.CONVERSATION" /> </intent-filter> </service> </application> diff --git a/samples/browseable/ElizaChat/Application/res/values-v21/template-styles.xml b/samples/browseable/ElizaChat/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ElizaChat/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/ElizaChat/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/ElizaChat/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ElizaResponder.java index e87f6debd..e6c054251 100644 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java +++ b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ElizaResponder.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.elizachat; +package com.example.android.wearable.elizachat; import android.text.TextUtils; diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/MainActivity.java index 421dcb85a..982e3def5 100644 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java +++ b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.elizachat; +package com.example.android.wearable.elizachat; import android.app.Activity; import android.content.BroadcastReceiver; @@ -35,10 +35,10 @@ public class MainActivity extends Activity { public static final String EXTRA_MESSAGE = "message"; - public static final String ACTION_NOTIFY = "com.example.android.elizachat.NOTIFY"; + public static final String ACTION_NOTIFY = "com.example.android.wearable.elizachat.NOTIFY"; public static final String ACTION_GET_CONVERSATION - = "com.example.android.elizachat.CONVERSATION"; + = "com.example.android.wearable.elizachat.CONVERSATION"; private BroadcastReceiver mReceiver; diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ResponderService.java index 6d6cd9ab6..3bef19c6b 100644 --- a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java +++ b/samples/browseable/ElizaChat/Application/src/com.example.android.wearable.elizachat/ResponderService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.elizachat; +package com.example.android.wearable.elizachat; import android.app.Notification; import android.app.PendingIntent; @@ -36,9 +36,9 @@ import android.util.Log; */ public class ResponderService extends Service { - public static final String ACTION_INCOMING = "com.example.android.elizachat.INCOMING"; + public static final String ACTION_INCOMING = "com.example.android.wearable.elizachat.INCOMING"; - public static final String ACTION_RESPONSE = "com.example.android.elizachat.REPLY"; + public static final String ACTION_RESPONSE = "com.example.android.wearable.elizachat.REPLY"; public static final String EXTRA_REPLY = "reply"; diff --git a/samples/browseable/ElizaChat/Shared/AndroidManifest.xml b/samples/browseable/ElizaChat/Shared/AndroidManifest.xml index 9c02d59fc..dfbb0927d 100644 --- a/samples/browseable/ElizaChat/Shared/AndroidManifest.xml +++ b/samples/browseable/ElizaChat/Shared/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.elizachat.common"> + package="com.example.android.wearable.elizachat.common"> <application android:allowBackup="true" android:label="@string/app_name"> diff --git a/samples/browseable/EmbeddedApp/Application/AndroidManifest.xml b/samples/browseable/EmbeddedApp/Application/AndroidManifest.xml index 2d266f271..ee47ffeda 100644 --- a/samples/browseable/EmbeddedApp/Application/AndroidManifest.xml +++ b/samples/browseable/EmbeddedApp/Application/AndroidManifest.xml @@ -15,8 +15,8 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.embeddedapp" > - <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="19" /> + package="com.example.android.wearable.embeddedapp" > + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" diff --git a/samples/browseable/EmbeddedApp/Application/res/values-v21/template-styles.xml b/samples/browseable/EmbeddedApp/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/EmbeddedApp/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/EmbeddedApp/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.wearable.embeddedapp/PhoneActivity.java index de95938ce..5a2f5ca3a 100644 --- a/samples/browseable/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java +++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.wearable.embeddedapp/PhoneActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.embeddedapp; +package com.example.android.wearable.embeddedapp; import android.app.Activity; import android.os.Bundle; diff --git a/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml b/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml deleted file mode 100644 index f026bc505..000000000 --- a/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.embeddedapp.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/EmbeddedApp/Wearable/AndroidManifest.xml b/samples/browseable/EmbeddedApp/Wearable/AndroidManifest.xml index fd07d3c9e..2c1d52c5f 100644 --- a/samples/browseable/EmbeddedApp/Wearable/AndroidManifest.xml +++ b/samples/browseable/EmbeddedApp/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.embeddedapp" > + package="com.example.android.wearable.embeddedapp" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> diff --git a/samples/browseable/EmbeddedApp/Wearable/src/com.example.android.embeddedapp/WearableActivity.java b/samples/browseable/EmbeddedApp/Wearable/src/com.example.android.wearable.embeddedapp/WearableActivity.java index 1ae0c1f0c..3703f3425 100644 --- a/samples/browseable/EmbeddedApp/Wearable/src/com.example.android.embeddedapp/WearableActivity.java +++ b/samples/browseable/EmbeddedApp/Wearable/src/com.example.android.wearable.embeddedapp/WearableActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.embeddedapp; +package com.example.android.wearable.embeddedapp; import android.app.Activity; import android.os.Bundle; diff --git a/samples/browseable/FindMyPhone/Application/AndroidManifest.xml b/samples/browseable/FindMyPhone/Application/AndroidManifest.xml index 5ca8c8a54..e88a04669 100644 --- a/samples/browseable/FindMyPhone/Application/AndroidManifest.xml +++ b/samples/browseable/FindMyPhone/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.findphone"> + package="com.example.android.wearable.findphone"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> @@ -32,7 +32,7 @@ android:value="@integer/google_play_services_version" /> <service - android:name="com.example.android.findphone.SoundAlarmListenerService" > + android:name="com.example.android.wearable.findphone.SoundAlarmListenerService" > <intent-filter> <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> </intent-filter> diff --git a/samples/browseable/FindMyPhone/Application/res/values-v21/template-styles.xml b/samples/browseable/FindMyPhone/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/FindMyPhone/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/FindMyPhone/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.wearable.findphone/SoundAlarmListenerService.java index 106a47a22..c89db9d3c 100644 --- a/samples/browseable/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java +++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.wearable.findphone/SoundAlarmListenerService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.findphone; +package com.example.android.wearable.findphone; import android.media.AudioManager; import android.media.MediaPlayer; diff --git a/samples/browseable/FindMyPhone/Shared/res/values/strings.xml b/samples/browseable/FindMyPhone/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/FindMyPhone/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/FindMyPhone/Wearable/AndroidManifest.xml b/samples/browseable/FindMyPhone/Wearable/AndroidManifest.xml index b81dd336d..fd6d27480 100644 --- a/samples/browseable/FindMyPhone/Wearable/AndroidManifest.xml +++ b/samples/browseable/FindMyPhone/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.findphone" > + package="com.example.android.wearable.findphone" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -39,7 +39,7 @@ </intent-filter> </service> - <service android:name="com.example.android.findphone.FindPhoneService"/> + <service android:name="com.example.android.wearable.findphone.FindPhoneService"/> <activity android:name=".FindPhoneActivity" diff --git a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/DisconnectListenerService.java b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.wearable.findphone/DisconnectListenerService.java index 749a38d45..42237de3e 100644 --- a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/DisconnectListenerService.java +++ b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.wearable.findphone/DisconnectListenerService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.findphone; +package com.example.android.wearable.findphone; import android.app.Notification; import android.app.NotificationManager; diff --git a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneActivity.java b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.wearable.findphone/FindPhoneActivity.java index 8251bab0e..d4eb18bf4 100644 --- a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneActivity.java +++ b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.wearable.findphone/FindPhoneActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.findphone; +package com.example.android.wearable.findphone; import android.app.Activity; import android.app.Notification; diff --git a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneService.java b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.wearable.findphone/FindPhoneService.java index cb9f96120..e5fa6c0ca 100644 --- a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneService.java +++ b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.wearable.findphone/FindPhoneService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.findphone; +package com.example.android.wearable.findphone; import android.app.IntentService; import android.content.Intent; diff --git a/samples/browseable/Flashlight/Application/AndroidManifest.xml b/samples/browseable/Flashlight/Application/AndroidManifest.xml index 27103130f..44cfdd3c4 100644 --- a/samples/browseable/Flashlight/Application/AndroidManifest.xml +++ b/samples/browseable/Flashlight/Application/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.flashlight"> + package="com.example.android.wearable.flashlight"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/Flashlight/Application/res/values-v21/template-styles.xml b/samples/browseable/Flashlight/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/Flashlight/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/Flashlight/Shared/AndroidManifest.xml b/samples/browseable/Flashlight/Shared/AndroidManifest.xml deleted file mode 100644 index c7893c7f5..000000000 --- a/samples/browseable/Flashlight/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.flashlight.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/Flashlight/Shared/res/values/strings.xml b/samples/browseable/Flashlight/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/Flashlight/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/Flashlight/Wearable/AndroidManifest.xml b/samples/browseable/Flashlight/Wearable/AndroidManifest.xml index f22e1abfb..1800e7648 100644 --- a/samples/browseable/Flashlight/Wearable/AndroidManifest.xml +++ b/samples/browseable/Flashlight/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.flashlight" > + package="com.example.android.wearable.flashlight" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> diff --git a/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/MainActivity.java b/samples/browseable/Flashlight/Wearable/src/com.example.android.wearable.flashlight/MainActivity.java index 9e4bae5f5..f87cae878 100644 --- a/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/MainActivity.java +++ b/samples/browseable/Flashlight/Wearable/src/com.example.android.wearable.flashlight/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.flashlight; +package com.example.android.wearable.flashlight; import android.app.Activity; import android.app.Fragment; diff --git a/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/PartyLightView.java b/samples/browseable/Flashlight/Wearable/src/com.example.android.wearable.flashlight/PartyLightView.java index 02247d652..33f061e15 100644 --- a/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/PartyLightView.java +++ b/samples/browseable/Flashlight/Wearable/src/com.example.android.wearable.flashlight/PartyLightView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.flashlight; +package com.example.android.wearable.flashlight; import android.animation.ArgbEvaluator; import android.content.Context; diff --git a/samples/browseable/FragmentTransition/AndroidManifest.xml b/samples/browseable/FragmentTransition/AndroidManifest.xml index 8d02eb0a4..2cfe40604 100644 --- a/samples/browseable/FragmentTransition/AndroidManifest.xml +++ b/samples/browseable/FragmentTransition/AndroidManifest.xml @@ -19,7 +19,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/FragmentTransition/_index.jd b/samples/browseable/FragmentTransition/_index.jd index f0efe32fd..afab623ea 100644 --- a/samples/browseable/FragmentTransition/_index.jd +++ b/samples/browseable/FragmentTransition/_index.jd @@ -1,8 +1,9 @@ - - - page.tags="FragmentTransition" sample.group=UI @jd:body -<p>This sample demonstrates how to start a transition right after a fragment transaction.</p> +<p> + + This sample demonstrates how to start a transition right after a fragment transaction. + + </p> diff --git a/samples/browseable/FragmentTransition/res/values-v21/template-styles.xml b/samples/browseable/FragmentTransition/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/FragmentTransition/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/FragmentTransition/res/values/base-strings.xml b/samples/browseable/FragmentTransition/res/values/base-strings.xml index 933e1f28e..92707c9ef 100644 --- a/samples/browseable/FragmentTransition/res/values/base-strings.xml +++ b/samples/browseable/FragmentTransition/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">FragmentTransition</string> <string name="intro_message"> diff --git a/samples/browseable/FragmentTransition/res/values/strings.xml b/samples/browseable/FragmentTransition/res/values/strings.xml index 5f7778987..5f7778987 100755..100644 --- a/samples/browseable/FragmentTransition/res/values/strings.xml +++ b/samples/browseable/FragmentTransition/res/values/strings.xml diff --git a/samples/browseable/FragmentTransition/src/com.example.android.fragmenttransition/MainActivity.java b/samples/browseable/FragmentTransition/src/com.example.android.fragmenttransition/MainActivity.java index 7d6ca6f4d..fa019bee4 100644 --- a/samples/browseable/FragmentTransition/src/com.example.android.fragmenttransition/MainActivity.java +++ b/samples/browseable/FragmentTransition/src/com.example.android.fragmenttransition/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.fragmenttransition; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - FragmentTransitionFragment fragment = new FragmentTransitionFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + FragmentTransitionFragment fragment = new FragmentTransitionFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/Geofencing/Application/AndroidManifest.xml b/samples/browseable/Geofencing/Application/AndroidManifest.xml index 519aa14e6..ba978157d 100644 --- a/samples/browseable/Geofencing/Application/AndroidManifest.xml +++ b/samples/browseable/Geofencing/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.geofencing"> + package="com.example.android.wearable.geofencing"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/Geofencing/Application/res/values-v21/template-styles.xml b/samples/browseable/Geofencing/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/Geofencing/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/Geofencing/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/Geofencing/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/Geofencing/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/Geofencing/Application/src/com.example.android.geofencing/Constants.java b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/Constants.java index b90aa3b11..6da9151dc 100644 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/Constants.java +++ b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.geofencing; +package com.example.android.wearable.geofencing; import android.net.Uri; diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/GeofenceTransitionsIntentService.java index 1af7bc68f..5d1ea48e0 100644 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java +++ b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/GeofenceTransitionsIntentService.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.example.android.geofencing; +package com.example.android.wearable.geofencing; -import static com.example.android.geofencing.Constants.CONNECTION_TIME_OUT_MS; -import static com.example.android.geofencing.Constants.GEOFENCE_DATA_ITEM_PATH; -import static com.example.android.geofencing.Constants.GEOFENCE_DATA_ITEM_URI; -import static com.example.android.geofencing.Constants.KEY_GEOFENCE_ID; -import static com.example.android.geofencing.Constants.TAG; +import static com.example.android.wearable.geofencing.Constants.CONNECTION_TIME_OUT_MS; +import static com.example.android.wearable.geofencing.Constants.GEOFENCE_DATA_ITEM_PATH; +import static com.example.android.wearable.geofencing.Constants.GEOFENCE_DATA_ITEM_URI; +import static com.example.android.wearable.geofencing.Constants.KEY_GEOFENCE_ID; +import static com.example.android.wearable.geofencing.Constants.TAG; import android.app.IntentService; import android.content.Intent; diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/MainActivity.java index 67dcd077d..baef21755 100644 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java +++ b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/MainActivity.java @@ -14,19 +14,19 @@ * limitations under the License. */ -package com.example.android.geofencing; - -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_ID; -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_LATITUDE; -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_LONGITUDE; -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_RADIUS_METERS; -import static com.example.android.geofencing.Constants.CONNECTION_FAILURE_RESOLUTION_REQUEST; -import static com.example.android.geofencing.Constants.GEOFENCE_EXPIRATION_TIME; -import static com.example.android.geofencing.Constants.TAG; -import static com.example.android.geofencing.Constants.YERBA_BUENA_ID; -import static com.example.android.geofencing.Constants.YERBA_BUENA_LATITUDE; -import static com.example.android.geofencing.Constants.YERBA_BUENA_LONGITUDE; -import static com.example.android.geofencing.Constants.YERBA_BUENA_RADIUS_METERS; +package com.example.android.wearable.geofencing; + +import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_ID; +import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_LATITUDE; +import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_LONGITUDE; +import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_RADIUS_METERS; +import static com.example.android.wearable.geofencing.Constants.CONNECTION_FAILURE_RESOLUTION_REQUEST; +import static com.example.android.wearable.geofencing.Constants.GEOFENCE_EXPIRATION_TIME; +import static com.example.android.wearable.geofencing.Constants.TAG; +import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_ID; +import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_LATITUDE; +import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_LONGITUDE; +import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_RADIUS_METERS; import android.app.Activity; import android.app.PendingIntent; diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofence.java b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/SimpleGeofence.java index 8e175269d..50f02c371 100644 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofence.java +++ b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/SimpleGeofence.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.geofencing; +package com.example.android.wearable.geofencing; import com.google.android.gms.location.Geofence; diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofenceStore.java b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/SimpleGeofenceStore.java index fcdf8f814..47584f5a3 100644 --- a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofenceStore.java +++ b/samples/browseable/Geofencing/Application/src/com.example.android.wearable.geofencing/SimpleGeofenceStore.java @@ -14,17 +14,17 @@ * limitations under the License. */ -package com.example.android.geofencing; +package com.example.android.wearable.geofencing; -import static com.example.android.geofencing.Constants.INVALID_FLOAT_VALUE; -import static com.example.android.geofencing.Constants.INVALID_INT_VALUE; -import static com.example.android.geofencing.Constants.INVALID_LONG_VALUE; -import static com.example.android.geofencing.Constants.KEY_EXPIRATION_DURATION; -import static com.example.android.geofencing.Constants.KEY_LATITUDE; -import static com.example.android.geofencing.Constants.KEY_LONGITUDE; -import static com.example.android.geofencing.Constants.KEY_PREFIX; -import static com.example.android.geofencing.Constants.KEY_RADIUS; -import static com.example.android.geofencing.Constants.KEY_TRANSITION_TYPE; +import static com.example.android.wearable.geofencing.Constants.INVALID_FLOAT_VALUE; +import static com.example.android.wearable.geofencing.Constants.INVALID_INT_VALUE; +import static com.example.android.wearable.geofencing.Constants.INVALID_LONG_VALUE; +import static com.example.android.wearable.geofencing.Constants.KEY_EXPIRATION_DURATION; +import static com.example.android.wearable.geofencing.Constants.KEY_LATITUDE; +import static com.example.android.wearable.geofencing.Constants.KEY_LONGITUDE; +import static com.example.android.wearable.geofencing.Constants.KEY_PREFIX; +import static com.example.android.wearable.geofencing.Constants.KEY_RADIUS; +import static com.example.android.wearable.geofencing.Constants.KEY_TRANSITION_TYPE; import android.content.Context; import android.content.SharedPreferences; diff --git a/samples/browseable/Geofencing/Shared/AndroidManifest.xml b/samples/browseable/Geofencing/Shared/AndroidManifest.xml deleted file mode 100644 index 2b60180a8..000000000 --- a/samples/browseable/Geofencing/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.geofencing.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/Geofencing/Shared/res/values/strings.xml b/samples/browseable/Geofencing/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/Geofencing/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/Geofencing/Wearable/AndroidManifest.xml b/samples/browseable/Geofencing/Wearable/AndroidManifest.xml index 85c41cdf8..97ce90e94 100644 --- a/samples/browseable/Geofencing/Wearable/AndroidManifest.xml +++ b/samples/browseable/Geofencing/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.geofencing" > + package="com.example.android.wearable.geofencing" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -32,7 +32,7 @@ android:value="@integer/google_play_services_version" /> <service - android:name="com.example.android.geofencing.HomeListenerService" > + android:name="com.example.android.wearable.geofencing.HomeListenerService" > <intent-filter> <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> </intent-filter> diff --git a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/CheckInAndDeleteDataItemsService.java b/samples/browseable/Geofencing/Wearable/src/com.example.android.wearable.geofencing/CheckInAndDeleteDataItemsService.java index 1cc9baf76..7b8ba1150 100644 --- a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/CheckInAndDeleteDataItemsService.java +++ b/samples/browseable/Geofencing/Wearable/src/com.example.android.wearable.geofencing/CheckInAndDeleteDataItemsService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.geofencing; +package com.example.android.wearable.geofencing; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; @@ -31,11 +31,11 @@ import android.util.Log; import java.util.concurrent.TimeUnit; -import static com.example.android.geofencing.Constants.ACTION_CHECK_IN; -import static com.example.android.geofencing.Constants.ACTION_DELETE_DATA_ITEM; -import static com.example.android.geofencing.Constants.CONNECTION_TIME_OUT_MS; -import static com.example.android.geofencing.Constants.NOTIFICATION_ID; -import static com.example.android.geofencing.Constants.TAG; +import static com.example.android.wearable.geofencing.Constants.ACTION_CHECK_IN; +import static com.example.android.wearable.geofencing.Constants.ACTION_DELETE_DATA_ITEM; +import static com.example.android.wearable.geofencing.Constants.CONNECTION_TIME_OUT_MS; +import static com.example.android.wearable.geofencing.Constants.NOTIFICATION_ID; +import static com.example.android.wearable.geofencing.Constants.TAG; /** * Handles "Check In" action on the location-based notification. Also deletes orphan DataItems diff --git a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/Constants.java b/samples/browseable/Geofencing/Wearable/src/com.example.android.wearable.geofencing/Constants.java index 23ee99ef9..ef6e8c6ed 100644 --- a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/Constants.java +++ b/samples/browseable/Geofencing/Wearable/src/com.example.android.wearable.geofencing/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.geofencing; +package com.example.android.wearable.geofencing; /** Constants used in wearable app. */ public final class Constants { diff --git a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/HomeListenerService.java b/samples/browseable/Geofencing/Wearable/src/com.example.android.wearable.geofencing/HomeListenerService.java index b0b1b13c3..415fc46aa 100644 --- a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/HomeListenerService.java +++ b/samples/browseable/Geofencing/Wearable/src/com.example.android.wearable.geofencing/HomeListenerService.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package com.example.android.geofencing; +package com.example.android.wearable.geofencing; -import static com.example.android.geofencing.Constants.ACTION_CHECK_IN; -import static com.example.android.geofencing.Constants.ACTION_DELETE_DATA_ITEM; -import static com.example.android.geofencing.Constants.ANDROID_BUILDING_ID; -import static com.example.android.geofencing.Constants.KEY_GEOFENCE_ID; -import static com.example.android.geofencing.Constants.NOTIFICATION_ID; -import static com.example.android.geofencing.Constants.TAG; -import static com.example.android.geofencing.Constants.YERBA_BUENA_ID; +import static com.example.android.wearable.geofencing.Constants.ACTION_CHECK_IN; +import static com.example.android.wearable.geofencing.Constants.ACTION_DELETE_DATA_ITEM; +import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_ID; +import static com.example.android.wearable.geofencing.Constants.KEY_GEOFENCE_ID; +import static com.example.android.wearable.geofencing.Constants.NOTIFICATION_ID; +import static com.example.android.wearable.geofencing.Constants.TAG; +import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_ID; import android.app.Notification; import android.app.Notification.Action; diff --git a/samples/browseable/GridViewPager/Application/AndroidManifest.xml b/samples/browseable/GridViewPager/Application/AndroidManifest.xml index eaa91d753..57241ce3c 100644 --- a/samples/browseable/GridViewPager/Application/AndroidManifest.xml +++ b/samples/browseable/GridViewPager/Application/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.gridviewpager"> + package="com.example.android.wearable.gridviewpager"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/GridViewPager/Application/res/values-v21/template-styles.xml b/samples/browseable/GridViewPager/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/GridViewPager/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/GridViewPager/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/GridViewPager/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/GridViewPager/Shared/AndroidManifest.xml b/samples/browseable/GridViewPager/Shared/AndroidManifest.xml deleted file mode 100644 index 1be08aaeb..000000000 --- a/samples/browseable/GridViewPager/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.gridviewpager.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/GridViewPager/Shared/res/values/strings.xml b/samples/browseable/GridViewPager/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/GridViewPager/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/GridViewPager/Wearable/AndroidManifest.xml b/samples/browseable/GridViewPager/Wearable/AndroidManifest.xml index baadee268..3f9c4b1a3 100644 --- a/samples/browseable/GridViewPager/Wearable/AndroidManifest.xml +++ b/samples/browseable/GridViewPager/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.gridviewpager" > + package="com.example.android.wearable.gridviewpager" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -28,7 +28,7 @@ android:label="@string/app_name" android:theme="@android:style/Theme.DeviceDefault.Light" > <activity - android:name="com.example.android.gridviewpager.MainActivity" + android:name="com.example.android.wearable.gridviewpager.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> diff --git a/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/MainActivity.java b/samples/browseable/GridViewPager/Wearable/src/com.example.android.wearable.gridviewpager/MainActivity.java index 0ca304eba..20751a309 100644 --- a/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/MainActivity.java +++ b/samples/browseable/GridViewPager/Wearable/src/com.example.android.wearable.gridviewpager/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.gridviewpager; +package com.example.android.wearable.gridviewpager; import android.app.Activity; import android.content.res.Resources; diff --git a/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/SampleGridPagerAdapter.java b/samples/browseable/GridViewPager/Wearable/src/com.example.android.wearable.gridviewpager/SampleGridPagerAdapter.java index c9dde0724..8f9bcf961 100644 --- a/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/SampleGridPagerAdapter.java +++ b/samples/browseable/GridViewPager/Wearable/src/com.example.android.wearable.gridviewpager/SampleGridPagerAdapter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.gridviewpager; +package com.example.android.wearable.gridviewpager; import android.app.Fragment; import android.app.FragmentManager; diff --git a/samples/browseable/HorizontalPaging/AndroidManifest.xml b/samples/browseable/HorizontalPaging/AndroidManifest.xml index 33b9e15b9..1f6fdd2a0 100644 --- a/samples/browseable/HorizontalPaging/AndroidManifest.xml +++ b/samples/browseable/HorizontalPaging/AndroidManifest.xml @@ -22,9 +22,7 @@ <!-- While ViewPager will work on API 4 or above, tabs require an ActionBar. ActionBar is only available in API 11 or above. --> - <uses-sdk - android:minSdkVersion="11" - android:targetSdkVersion="16" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/HorizontalPaging/_index.jd b/samples/browseable/HorizontalPaging/_index.jd index acdc1b148..4e4ba00a2 100644 --- a/samples/browseable/HorizontalPaging/_index.jd +++ b/samples/browseable/HorizontalPaging/_index.jd @@ -1,10 +1,10 @@ - - - page.tags="HorizontalPaging" sample.group=UI @jd:body -<p>This sample demonstrates how to implement horizontal paging between -fragments in an application that has an {@link android.app.ActionBar}, using a -{@link android.support.v4.view.ViewPager} widget.</p> +<p> + + This sample demonstrates how to implement horizontal paging between fragments in + applications that use ActionBar, using a ViewPager widget. + + </p> diff --git a/samples/browseable/HorizontalPaging/res/values-v21/template-styles.xml b/samples/browseable/HorizontalPaging/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/HorizontalPaging/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/HorizontalPaging/res/values/base-strings.xml b/samples/browseable/HorizontalPaging/res/values/base-strings.xml index 70484bcb4..3f5d5a9cb 100644 --- a/samples/browseable/HorizontalPaging/res/values/base-strings.xml +++ b/samples/browseable/HorizontalPaging/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">HorizontalPaging</string> <string name="intro_message"> diff --git a/samples/browseable/ImmersiveMode/AndroidManifest.xml b/samples/browseable/ImmersiveMode/AndroidManifest.xml index 72a60ce15..b558db6d4 100644 --- a/samples/browseable/ImmersiveMode/AndroidManifest.xml +++ b/samples/browseable/ImmersiveMode/AndroidManifest.xml @@ -19,7 +19,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/ImmersiveMode/_index.jd b/samples/browseable/ImmersiveMode/_index.jd index ab3b7182d..38c7fbdd0 100644 --- a/samples/browseable/ImmersiveMode/_index.jd +++ b/samples/browseable/ImmersiveMode/_index.jd @@ -1,12 +1,11 @@ - - - page.tags="ImmersiveMode" sample.group=UI @jd:body -<p>Android 4.4 introduces a way for you to provide a more immersive screen -experience in your app, by letting users show or hide the status bar and -navigation bar with a swipe.</p> -<p>This sample demonstrates how to enable toggling of this feature in a -{@link android.support.v4.app.Fragment}.</p> +<p> + + One of the features introduced in KitKat is "immersive mode". Immersive mode gives the + user the ability to show/hide the status bar and navigation bar with a swipe. To try, + click the "Toggle immersive mode" button, then try swiping the bar in and out! + + </p> diff --git a/samples/browseable/ImmersiveMode/res/values-v21/template-styles.xml b/samples/browseable/ImmersiveMode/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/ImmersiveMode/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/ImmersiveMode/res/values/base-strings.xml b/samples/browseable/ImmersiveMode/res/values/base-strings.xml index 2092f63a4..a247c6bfc 100644 --- a/samples/browseable/ImmersiveMode/res/values/base-strings.xml +++ b/samples/browseable/ImmersiveMode/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">ImmersiveMode</string> <string name="intro_message"> diff --git a/samples/browseable/ImmersiveMode/res/values/strings.xml b/samples/browseable/ImmersiveMode/res/values/strings.xml index 8a1e9e16f..65ee47d33 100644 --- a/samples/browseable/ImmersiveMode/res/values/strings.xml +++ b/samples/browseable/ImmersiveMode/res/values/strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="sample_action">Toggle immersive mode!</string> </resources> diff --git a/samples/browseable/ImmersiveMode/src/com.example.android.immersivemode/MainActivity.java b/samples/browseable/ImmersiveMode/src/com.example.android.immersivemode/MainActivity.java index 8fb6e345c..645e92f8a 100644 --- a/samples/browseable/ImmersiveMode/src/com.example.android.immersivemode/MainActivity.java +++ b/samples/browseable/ImmersiveMode/src/com.example.android.immersivemode/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.immersivemode; import android.graphics.Color; diff --git a/samples/browseable/JobScheduler/src/com.example.android.jobscheduler/MainActivity.java b/samples/browseable/JobScheduler/src/com.example.android.jobscheduler/MainActivity.java index f495bf1b6..624e22d02 100644 --- a/samples/browseable/JobScheduler/src/com.example.android.jobscheduler/MainActivity.java +++ b/samples/browseable/JobScheduler/src/com.example.android.jobscheduler/MainActivity.java @@ -140,9 +140,9 @@ public class MainActivity extends Activity { boolean requiresUnmetered = mWiFiConnectivityRadioButton.isChecked(); boolean requiresAnyConnectivity = mAnyConnectivityRadioButton.isChecked(); if (requiresUnmetered) { - builder.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED); + builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); } else if (requiresAnyConnectivity) { - builder.setRequiredNetworkCapabilities(JobInfo.NetworkType.ANY); + builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); } builder.setRequiresDeviceIdle(mRequiresIdleCheckbox.isChecked()); builder.setRequiresCharging(mRequiresChargingCheckBox.isChecked()); diff --git a/samples/browseable/JumpingJack/Application/AndroidManifest.xml b/samples/browseable/JumpingJack/Application/AndroidManifest.xml index 652f895e0..e778437f6 100644 --- a/samples/browseable/JumpingJack/Application/AndroidManifest.xml +++ b/samples/browseable/JumpingJack/Application/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.jumpingjack"> + package="com.example.android.wearable.jumpingjack"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/JumpingJack/Application/res/values-v21/template-styles.xml b/samples/browseable/JumpingJack/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/JumpingJack/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/JumpingJack/Shared/AndroidManifest.xml b/samples/browseable/JumpingJack/Shared/AndroidManifest.xml deleted file mode 100644 index 7ba3326c6..000000000 --- a/samples/browseable/JumpingJack/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.jumpingjack.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/JumpingJack/Shared/res/values/strings.xml b/samples/browseable/JumpingJack/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/JumpingJack/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/JumpingJack/Wearable/AndroidManifest.xml b/samples/browseable/JumpingJack/Wearable/AndroidManifest.xml index e0448d95c..f123f77a7 100644 --- a/samples/browseable/JumpingJack/Wearable/AndroidManifest.xml +++ b/samples/browseable/JumpingJack/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.jumpingjack"> + package="com.example.android.wearable.jumpingjack"> <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/MainActivity.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/MainActivity.java index 4fe2e79f6..cdaaf6ec7 100644 --- a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/MainActivity.java +++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/MainActivity.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.example.android.jumpingjack; +package com.example.android.wearable.jumpingjack; -import com.example.android.jumpingjack.fragments.CounterFragment; -import com.example.android.jumpingjack.fragments.SettingsFragment; +import com.example.android.wearable.jumpingjack.fragments.CounterFragment; +import com.example.android.wearable.jumpingjack.fragments.SettingsFragment; import android.app.Activity; import android.content.Context; diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/PagerAdapter.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/PagerAdapter.java index 47fe86c93..f7ac2b010 100644 --- a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/PagerAdapter.java +++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/PagerAdapter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.jumpingjack; +package com.example.android.wearable.jumpingjack; import android.app.Fragment; import android.app.FragmentManager; diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/Utils.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/Utils.java index 90fc296cf..4db66c9a8 100644 --- a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/Utils.java +++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/Utils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.jumpingjack; +package com.example.android.wearable.jumpingjack; import android.content.Context; import android.content.SharedPreferences; diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/CounterFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/CounterFragment.java index aa6fa5323..c55eb9b04 100644 --- a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/CounterFragment.java +++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/CounterFragment.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.example.android.jumpingjack.fragments; +package com.example.android.wearable.jumpingjack.fragments; -import com.example.android.jumpingjack.R; -import com.example.android.jumpingjack.Utils; +import com.example.android.wearable.jumpingjack.R; +import com.example.android.wearable.jumpingjack.Utils; import android.app.Fragment; import android.graphics.drawable.Drawable; diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/SettingsFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/SettingsFragment.java index 0ef7a43f2..fffe8fb71 100644 --- a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/SettingsFragment.java +++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.wearable.jumpingjack/fragments/SettingsFragment.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.example.android.jumpingjack.fragments; +package com.example.android.wearable.jumpingjack.fragments; -import com.example.android.jumpingjack.MainActivity; -import com.example.android.jumpingjack.R; +import com.example.android.wearable.jumpingjack.MainActivity; +import com.example.android.wearable.jumpingjack.R; import android.app.Fragment; import android.os.Bundle; diff --git a/samples/browseable/LNotifications/_index.jd b/samples/browseable/LNotifications/_index.jd index a993bb7c9..d156267db 100644 --- a/samples/browseable/LNotifications/_index.jd +++ b/samples/browseable/LNotifications/_index.jd @@ -1,5 +1,5 @@ page.tags="LNotifications Sample" -sample.group=UI +sample.group=Notification @jd:body <p> diff --git a/samples/browseable/MediaBrowserService/AndroidManifest.xml b/samples/browseable/MediaBrowserService/AndroidManifest.xml new file mode 100644 index 000000000..6d05c2791 --- /dev/null +++ b/samples/browseable/MediaBrowserService/AndroidManifest.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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.mediabrowserservice" + android:versionCode="1" + android:versionName="1.0" > + + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.WAKE_LOCK" /> + + <uses-sdk + android:minSdkVersion="21" + android:targetSdkVersion="21" /> + + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/AppTheme"> + + <meta-data android:name="com.google.android.gms.car.application" + android:resource="@xml/automotive_app_desc"/> + + + <activity android:name="com.example.android.mediabrowserservice.MusicPlayerActivity" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <!-- (OPTIONAL) use this meta data to indicate which icon should be used in media + notifications (for example, when the music changes and the user is + looking at another app) --> + <meta-data + android:name="com.google.android.gms.car.notification.SmallIcon" + android:resource="@drawable/ic_notification" /> + + <service + android:name="com.example.android.mediabrowserservice.MusicService" + android:exported="true" + > + <intent-filter> + <action android:name="android.media.browse.MediaBrowserService" /> + </intent-filter> + </service> + + </application> + +</manifest> diff --git a/samples/browseable/MediaBrowserService/_index.jd b/samples/browseable/MediaBrowserService/_index.jd new file mode 100644 index 000000000..ada73c419 --- /dev/null +++ b/samples/browseable/MediaBrowserService/_index.jd @@ -0,0 +1,11 @@ +page.tags="MediaBrowserService" +sample.group=Media +@jd:body + +<p> + + This sample shows how to implement an audio media app that provides + media library metadata and playback controls through a standard + service. + + </p> diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..47d6854e2 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_launcher.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_notification.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_notification.png Binary files differnew file mode 100644 index 000000000..d8ea5a906 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_notification.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_pause_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_pause_white_24dp.png Binary files differnew file mode 100644 index 000000000..b4bdbb558 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_pause_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_play_arrow_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_play_arrow_white_24dp.png Binary files differnew file mode 100644 index 000000000..164385d04 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_play_arrow_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_shuffle_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_shuffle_white_24dp.png Binary files differnew file mode 100644 index 000000000..3eeb0ef5b --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_shuffle_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_next_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_next_white_24dp.png Binary files differnew file mode 100644 index 000000000..4eaf7caab --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_next_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_previous_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_previous_white_24dp.png Binary files differnew file mode 100644 index 000000000..e59dedb62 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-hdpi/ic_skip_previous_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-mdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..01b53fd50 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-mdpi/ic_launcher.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_off.png b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_off.png Binary files differnew file mode 100644 index 000000000..e435d2a9f --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_off.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_on.png b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_on.png Binary files differnew file mode 100644 index 000000000..0c75bb6da --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-night-xxhdpi/ic_star_on.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_equalizer_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_equalizer_white_24dp.png Binary files differnew file mode 100644 index 000000000..dbba844df --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_equalizer_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..af762f2be --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_launcher.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_pause_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_pause_white_24dp.png Binary files differnew file mode 100644 index 000000000..14b6d17d4 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_pause_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_play_arrow_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_play_arrow_white_24dp.png Binary files differnew file mode 100644 index 000000000..a55d19922 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_play_arrow_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_shuffle_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_shuffle_white_24dp.png Binary files differnew file mode 100644 index 000000000..8ce3a6008 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_shuffle_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_next_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_next_white_24dp.png Binary files differnew file mode 100644 index 000000000..f282b9245 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_next_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_previous_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_previous_white_24dp.png Binary files differnew file mode 100644 index 000000000..2522877df --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xhdpi/ic_skip_previous_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_by_genre.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_by_genre.png Binary files differnew file mode 100644 index 000000000..da3b4a74c --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_by_genre.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_default_art.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_default_art.png Binary files differnew file mode 100644 index 000000000..dfb9e670a --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_default_art.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_equalizer_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_equalizer_white_24dp.png Binary files differnew file mode 100644 index 000000000..b82a8d98d --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_equalizer_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..eef47aa34 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_launcher.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_pause_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_pause_white_24dp.png Binary files differnew file mode 100644 index 000000000..72dfa9fa6 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_pause_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png Binary files differnew file mode 100644 index 000000000..043acd808 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_shuffle_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_shuffle_white_24dp.png Binary files differnew file mode 100644 index 000000000..718b6b5ce --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_shuffle_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_next_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_next_white_24dp.png Binary files differnew file mode 100644 index 000000000..4fe60888b --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_next_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png Binary files differnew file mode 100644 index 000000000..2c9310af9 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_off.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_off.png Binary files differnew file mode 100644 index 000000000..836085b68 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_off.png diff --git a/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_on.png b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_on.png Binary files differnew file mode 100644 index 000000000..7cd6cfc52 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/drawable-xxhdpi/ic_star_on.png diff --git a/samples/browseable/MediaBrowserService/res/layout/activity_player.xml b/samples/browseable/MediaBrowserService/res/layout/activity_player.xml new file mode 100644 index 000000000..21cdbbd9c --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/layout/activity_player.xml @@ -0,0 +1,22 @@ +<!-- + Copyright (C) 2014 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. + --> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/container" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MusicPlayerActivity" + tools:ignore="MergeRootFrame" /> diff --git a/samples/browseable/MediaBrowserService/res/layout/fragment_list.xml b/samples/browseable/MediaBrowserService/res/layout/fragment_list.xml new file mode 100644 index 000000000..c169fec97 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/layout/fragment_list.xml @@ -0,0 +1,60 @@ +<!-- + Copyright (C) 2014 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="match_parent" + android:layout_height="match_parent" + android:padding="@dimen/fragment_list_padding"> + + <LinearLayout + android:id="@+id/controls" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <ImageButton + android:id="@+id/skip_previous" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:src="@drawable/ic_skip_previous_white_24dp" + android:contentDescription="@string/skip_previous"/> + + <ImageButton + android:id="@+id/play_pause" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:src="@drawable/ic_play_arrow_white_24dp" + android:contentDescription="@string/play_pause"/> + + <ImageButton + android:id="@+id/skip_next" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:src="@drawable/ic_skip_next_white_24dp" + android:contentDescription="@string/skip_next"/> + + </LinearLayout> + + <ListView + android:id="@+id/list_view" + android:layout_width="match_parent" + android:layout_height="match_parent"> + </ListView> + +</LinearLayout> diff --git a/samples/browseable/MediaBrowserService/res/layout/media_list_item.xml b/samples/browseable/MediaBrowserService/res/layout/media_list_item.xml new file mode 100644 index 000000000..72c0ccf35 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/layout/media_list_item.xml @@ -0,0 +1,55 @@ +<!-- + Copyright (C) 2014 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:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?android:listPreferredItemHeight" + android:orientation="horizontal"> + + <ImageView + android:id="@+id/play_eq" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:contentDescription="@string/play_item" + android:src="@drawable/ic_play_arrow_white_24dp"/> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?android:attr/listPreferredItemHeight" + android:mode="twoLine" + android:padding="@dimen/list_item_padding" + android:orientation="vertical"> + + <TextView + android:id="@+id/title" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/margin_text_view" + android:layout_marginTop="@dimen/margin_text_view" + android:textAppearance="?android:attr/textAppearanceMedium"/> + + <TextView + android:id="@+id/description" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/margin_text_view" + android:layout_marginTop="@dimen/margin_text_view" + android:textAppearance="?android:attr/textAppearanceSmall"/> + + </LinearLayout> + +</LinearLayout> diff --git a/samples/browseable/MediaBrowserService/res/values-v21/styles.xml b/samples/browseable/MediaBrowserService/res/values-v21/styles.xml new file mode 100644 index 000000000..21bb211b7 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/values-v21/styles.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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="AppBaseTheme" parent="android:Theme.Material"> + <!-- colorPrimary is used for Notification icon and bottom facet bar icons + and overflow actions --> + <item name="android:colorPrimary">#ffff5722</item> + + <!-- colorPrimaryDark is used for background --> + <item name="android:colorPrimaryDark">#ffbf360c</item> + + <!-- colorAccent is sparingly used for accents, like floating action button highlight, + progress on playbar--> + <item name="android:colorAccent">#ffff5722</item> + + </style> + +</resources> diff --git a/samples/browseable/MediaBrowserService/res/values/dimens.xml b/samples/browseable/MediaBrowserService/res/values/dimens.xml new file mode 100644 index 000000000..e57a8c919 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/values/dimens.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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> + <dimen name="fragment_list_padding">16dp</dimen> + <dimen name="list_item_padding">4dp</dimen> + <dimen name="margin_text_view">6dp</dimen> +</resources> diff --git a/samples/browseable/MediaBrowserService/res/values/strings.xml b/samples/browseable/MediaBrowserService/res/values/strings.xml new file mode 100644 index 000000000..7a012e870 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/values/strings.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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">Auto Music Demo</string> + <string name="favorite">Favorite</string> + <string name="error_no_metadata">Unable to retrieve metadata.</string> + <string name="browse_genres">Genres</string> + <string name="browse_genre_subtitle">Songs by genre</string> + <string name="browse_musics_by_genre_subtitle">%1$s songs</string> + <string name="random_queue_title">Random music</string> + <string name="error_cannot_skip">Cannot skip</string> + <string name="error_loading_media">Error Loading Media</string> + <string name="play_item">Play item</string> + <string name="skip_previous">Skip to previous</string> + <string name="play_pause">play or pause</string> + <string name="skip_next">Skip to next</string> + +</resources> diff --git a/samples/browseable/MediaBrowserService/res/values/strings_notifications.xml b/samples/browseable/MediaBrowserService/res/values/strings_notifications.xml new file mode 100644 index 000000000..f406ba667 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/values/strings_notifications.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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="label_pause">Pause</string> + <string name="label_play">Play</string> + <string name="label_previous">Previous</string> + <string name="label_next">Next</string> + <string name="error_empty_metadata">Empty metadata!</string> +</resources> diff --git a/samples/browseable/MediaBrowserService/res/values/styles.xml b/samples/browseable/MediaBrowserService/res/values/styles.xml new file mode 100644 index 000000000..3be59c152 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/values/styles.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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="AppTheme" parent="AppBaseTheme"> + </style> + + <style name="AppBaseTheme" parent="android:Theme.Light"> + </style> + +</resources>
\ No newline at end of file diff --git a/samples/browseable/MediaBrowserService/res/xml/automotive_app_desc.xml b/samples/browseable/MediaBrowserService/res/xml/automotive_app_desc.xml new file mode 100644 index 000000000..a84750b04 --- /dev/null +++ b/samples/browseable/MediaBrowserService/res/xml/automotive_app_desc.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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. + --> +<automotiveApp> + <uses name="media"/> +</automotiveApp> diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/BrowseFragment.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/BrowseFragment.java new file mode 100644 index 000000000..726ae15b6 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/BrowseFragment.java @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2014 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.mediabrowserservice; + +import android.app.Fragment; +import android.content.ComponentName; +import android.content.Context; +import android.media.browse.MediaBrowser; +import android.media.session.MediaController; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.android.mediabrowserservice.utils.LogHelper; + +import java.util.ArrayList; +import java.util.List; + +/** + * A Fragment that lists all the various browsable queues available + * from a {@link android.service.media.MediaBrowserService}. + * <p/> + * It uses a {@link MediaBrowser} to connect to the {@link MusicService}. Once connected, + * the fragment subscribes to get all the children. All {@link MediaBrowser.MediaItem}'s + * that can be browsed are shown in a ListView. + */ +public class BrowseFragment extends Fragment { + + private static final String TAG = BrowseFragment.class.getSimpleName(); + + public static final String ARG_MEDIA_ID = "media_id"; + + public static interface FragmentDataHelper { + void onMediaItemSelected(MediaBrowser.MediaItem item); + } + + // The mediaId to be used for subscribing for children using the MediaBrowser. + private String mMediaId; + + private MediaBrowser mMediaBrowser; + private BrowseAdapter mBrowserAdapter; + + private MediaBrowser.SubscriptionCallback mSubscriptionCallback = new MediaBrowser.SubscriptionCallback() { + + @Override + public void onChildrenLoaded(String parentId, List<MediaBrowser.MediaItem> children) { + mBrowserAdapter.clear(); + mBrowserAdapter.notifyDataSetInvalidated(); + for (MediaBrowser.MediaItem item : children) { + mBrowserAdapter.add(item); + } + mBrowserAdapter.notifyDataSetChanged(); + } + + @Override + public void onError(String id) { + Toast.makeText(getActivity(), R.string.error_loading_media, + Toast.LENGTH_LONG).show(); + } + }; + + private MediaBrowser.ConnectionCallback mConnectionCallback = + new MediaBrowser.ConnectionCallback() { + @Override + public void onConnected() { + LogHelper.d(TAG, "onConnected: session token " + mMediaBrowser.getSessionToken()); + + if (mMediaId == null) { + mMediaId = mMediaBrowser.getRoot(); + } + mMediaBrowser.subscribe(mMediaId, mSubscriptionCallback); + if (mMediaBrowser.getSessionToken() == null) { + throw new IllegalArgumentException("No Session token"); + } + MediaController mediaController = new MediaController(getActivity(), + mMediaBrowser.getSessionToken()); + getActivity().setMediaController(mediaController); + } + + @Override + public void onConnectionFailed() { + LogHelper.d(TAG, "onConnectionFailed"); + } + + @Override + public void onConnectionSuspended() { + LogHelper.d(TAG, "onConnectionSuspended"); + getActivity().setMediaController(null); + } + }; + + public static BrowseFragment newInstance(String mediaId) { + Bundle args = new Bundle(); + args.putString(ARG_MEDIA_ID, mediaId); + BrowseFragment fragment = new BrowseFragment(); + fragment.setArguments(args); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_list, container, false); + + mBrowserAdapter = new BrowseAdapter(getActivity()); + + View controls = rootView.findViewById(R.id.controls); + controls.setVisibility(View.GONE); + + ListView listView = (ListView) rootView.findViewById(R.id.list_view); + listView.setAdapter(mBrowserAdapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + MediaBrowser.MediaItem item = mBrowserAdapter.getItem(position); + try { + FragmentDataHelper listener = (FragmentDataHelper) getActivity(); + listener.onMediaItemSelected(item); + } catch (ClassCastException ex) { + Log.e(TAG, "Exception trying to cast to FragmentDataHelper", ex); + } + } + }); + + Bundle args = getArguments(); + mMediaId = args.getString(ARG_MEDIA_ID, null); + + mMediaBrowser = new MediaBrowser(getActivity(), + new ComponentName(getActivity(), MusicService.class), + mConnectionCallback, null); + + return rootView; + } + + @Override + public void onStart() { + super.onStart(); + mMediaBrowser.connect(); + } + + @Override + public void onStop() { + super.onStop(); + mMediaBrowser.disconnect(); + } + + // An adapter for showing the list of browsed MediaItem's + private static class BrowseAdapter extends ArrayAdapter<MediaBrowser.MediaItem> { + + public BrowseAdapter(Context context) { + super(context, R.layout.media_list_item, new ArrayList<MediaBrowser.MediaItem>()); + } + + static class ViewHolder { + ImageView mImageView; + TextView mTitleView; + TextView mDescriptionView; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + ViewHolder holder; + + if (convertView == null) { + convertView = LayoutInflater.from(getContext()) + .inflate(R.layout.media_list_item, parent, false); + holder = new ViewHolder(); + holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq); + holder.mImageView.setVisibility(View.GONE); + holder.mTitleView = (TextView) convertView.findViewById(R.id.title); + holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + + MediaBrowser.MediaItem item = getItem(position); + holder.mTitleView.setText(item.getDescription().getTitle()); + holder.mDescriptionView.setText(item.getDescription().getDescription()); + if (item.isPlayable()) { + holder.mImageView.setImageDrawable( + getContext().getDrawable(R.drawable.ic_play_arrow_white_24dp)); + holder.mImageView.setVisibility(View.VISIBLE); + } + return convertView; + } + } +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MediaNotification.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MediaNotification.java new file mode 100644 index 000000000..7b8631a45 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MediaNotification.java @@ -0,0 +1,381 @@ +/* + * Copyright (C) 2014 Google Inc. All Rights Reserved. + * + * 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.mediabrowserservice; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.media.MediaDescription; +import android.media.MediaMetadata; +import android.media.session.MediaController; +import android.media.session.MediaSession; +import android.media.session.PlaybackState; +import android.os.AsyncTask; +import android.util.LruCache; +import android.util.SparseArray; + +import com.example.android.mediabrowserservice.utils.BitmapHelper; +import com.example.android.mediabrowserservice.utils.LogHelper; + +import java.io.IOException; + +/** + * Keeps track of a notification and updates it automatically for a given + * MediaSession. Maintaining a visible notification (usually) guarantees that the music service + * won't be killed during playback. + */ +public class MediaNotification extends BroadcastReceiver { + private static final String TAG = "MediaNotification"; + + private static final int NOTIFICATION_ID = 412; + + public static final String ACTION_PAUSE = "com.example.android.mediabrowserservice.pause"; + public static final String ACTION_PLAY = "com.example.android.mediabrowserservice.play"; + public static final String ACTION_PREV = "com.example.android.mediabrowserservice.prev"; + public static final String ACTION_NEXT = "com.example.android.mediabrowserservice.next"; + + private static final int MAX_ALBUM_ART_CACHE_SIZE = 1024*1024; + + private final MusicService mService; + private MediaSession.Token mSessionToken; + private MediaController mController; + private MediaController.TransportControls mTransportControls; + private final SparseArray<PendingIntent> mIntents = new SparseArray<PendingIntent>(); + private final LruCache<String, Bitmap> mAlbumArtCache; + + private PlaybackState mPlaybackState; + private MediaMetadata mMetadata; + + private Notification.Builder mNotificationBuilder; + private NotificationManager mNotificationManager; + private Notification.Action mPlayPauseAction; + + private String mCurrentAlbumArt; + private int mNotificationColor; + + private boolean mStarted = false; + + public MediaNotification(MusicService service) { + mService = service; + updateSessionToken(); + + // simple album art cache that holds no more than + // MAX_ALBUM_ART_CACHE_SIZE bytes: + mAlbumArtCache = new LruCache<String, Bitmap>(MAX_ALBUM_ART_CACHE_SIZE) { + @Override + protected int sizeOf(String key, Bitmap value) { + return value.getByteCount(); + } + }; + + mNotificationColor = getNotificationColor(); + + mNotificationManager = (NotificationManager) mService + .getSystemService(Context.NOTIFICATION_SERVICE); + + String pkg = mService.getPackageName(); + mIntents.put(R.drawable.ic_pause_white_24dp, PendingIntent.getBroadcast(mService, 100, + new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT)); + mIntents.put(R.drawable.ic_play_arrow_white_24dp, PendingIntent.getBroadcast(mService, 100, + new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT)); + mIntents.put(R.drawable.ic_skip_previous_white_24dp, PendingIntent.getBroadcast(mService, 100, + new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT)); + mIntents.put(R.drawable.ic_skip_next_white_24dp, PendingIntent.getBroadcast(mService, 100, + new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT)); + } + + protected int getNotificationColor() { + int notificationColor = 0; + String packageName = mService.getPackageName(); + try { + Context packageContext = mService.createPackageContext(packageName, 0); + ApplicationInfo applicationInfo = + mService.getPackageManager().getApplicationInfo(packageName, 0); + packageContext.setTheme(applicationInfo.theme); + Resources.Theme theme = packageContext.getTheme(); + TypedArray ta = theme.obtainStyledAttributes( + new int[] {android.R.attr.colorPrimary}); + notificationColor = ta.getColor(0, Color.DKGRAY); + ta.recycle(); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return notificationColor; + } + + /** + * Posts the notification and starts tracking the session to keep it + * updated. The notification will automatically be removed if the session is + * destroyed before {@link #stopNotification} is called. + */ + public void startNotification() { + if (!mStarted) { + mController.registerCallback(mCb); + IntentFilter filter = new IntentFilter(); + filter.addAction(ACTION_NEXT); + filter.addAction(ACTION_PAUSE); + filter.addAction(ACTION_PLAY); + filter.addAction(ACTION_PREV); + mService.registerReceiver(this, filter); + + mMetadata = mController.getMetadata(); + mPlaybackState = mController.getPlaybackState(); + + mStarted = true; + // The notification must be updated after setting started to true + updateNotificationMetadata(); + } + } + + /** + * Removes the notification and stops tracking the session. If the session + * was destroyed this has no effect. + */ + public void stopNotification() { + mStarted = false; + mController.unregisterCallback(mCb); + try { + mNotificationManager.cancel(NOTIFICATION_ID); + mService.unregisterReceiver(this); + } catch (IllegalArgumentException ex) { + // ignore if the receiver is not registered. + } + mService.stopForeground(true); + } + + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + LogHelper.d(TAG, "Received intent with action " + action); + if (ACTION_PAUSE.equals(action)) { + mTransportControls.pause(); + } else if (ACTION_PLAY.equals(action)) { + mTransportControls.play(); + } else if (ACTION_NEXT.equals(action)) { + mTransportControls.skipToNext(); + } else if (ACTION_PREV.equals(action)) { + mTransportControls.skipToPrevious(); + } + } + + /** + * Update the state based on a change on the session token. Called either when + * we are running for the first time or when the media session owner has destroyed the session + * (see {@link android.media.session.MediaController.Callback#onSessionDestroyed()}) + */ + private void updateSessionToken() { + MediaSession.Token freshToken = mService.getSessionToken(); + if (mSessionToken == null || !mSessionToken.equals(freshToken)) { + if (mController != null) { + mController.unregisterCallback(mCb); + } + mSessionToken = freshToken; + mController = new MediaController(mService, mSessionToken); + mTransportControls = mController.getTransportControls(); + if (mStarted) { + mController.registerCallback(mCb); + } + } + } + + private final MediaController.Callback mCb = new MediaController.Callback() { + @Override + public void onPlaybackStateChanged(PlaybackState state) { + mPlaybackState = state; + LogHelper.d(TAG, "Received new playback state", state); + updateNotificationPlaybackState(); + } + + @Override + public void onMetadataChanged(MediaMetadata metadata) { + mMetadata = metadata; + LogHelper.d(TAG, "Received new metadata ", metadata); + updateNotificationMetadata(); + } + + @Override + public void onSessionDestroyed() { + super.onSessionDestroyed(); + LogHelper.d(TAG, "Session was destroyed, resetting to the new session token"); + updateSessionToken(); + } + }; + + private void updateNotificationMetadata() { + LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); + if (mMetadata == null || mPlaybackState == null) { + return; + } + + updatePlayPauseAction(); + + mNotificationBuilder = new Notification.Builder(mService); + int playPauseActionIndex = 0; + + // If skip to previous action is enabled + if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) { + mNotificationBuilder + .addAction(R.drawable.ic_skip_previous_white_24dp, + mService.getString(R.string.label_previous), + mIntents.get(R.drawable.ic_skip_previous_white_24dp)); + playPauseActionIndex = 1; + } + + mNotificationBuilder.addAction(mPlayPauseAction); + + // If skip to next action is enabled + if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) { + mNotificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, + mService.getString(R.string.label_next), + mIntents.get(R.drawable.ic_skip_next_white_24dp)); + } + + MediaDescription description = mMetadata.getDescription(); + + String fetchArtUrl = null; + Bitmap art = description.getIconBitmap(); + if (art == null && description.getIconUri() != null) { + // This sample assumes the iconUri will be a valid URL formatted String, but + // it can actually be any valid Android Uri formatted String. + // async fetch the album art icon + String artUrl = description.getIconUri().toString(); + art = mAlbumArtCache.get(artUrl); + if (art == null) { + fetchArtUrl = artUrl; + // use a placeholder art while the remote art is being downloaded + art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); + } + } + + mNotificationBuilder + .setStyle(new Notification.MediaStyle() + .setShowActionsInCompactView(playPauseActionIndex) // only show play/pause in compact view + .setMediaSession(mSessionToken)) + .setColor(mNotificationColor) + .setSmallIcon(R.drawable.ic_notification) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setUsesChronometer(true) + .setContentTitle(description.getTitle()) + .setContentText(description.getSubtitle()) + .setLargeIcon(art); + + updateNotificationPlaybackState(); + + mService.startForeground(NOTIFICATION_ID, mNotificationBuilder.build()); + if (fetchArtUrl != null) { + fetchBitmapFromURLAsync(fetchArtUrl); + } + } + + private void updatePlayPauseAction() { + LogHelper.d(TAG, "updatePlayPauseAction"); + String playPauseLabel = ""; + int playPauseIcon; + if (mPlaybackState.getState() == PlaybackState.STATE_PLAYING) { + playPauseLabel = mService.getString(R.string.label_pause); + playPauseIcon = R.drawable.ic_pause_white_24dp; + } else { + playPauseLabel = mService.getString(R.string.label_play); + playPauseIcon = R.drawable.ic_play_arrow_white_24dp; + } + if (mPlayPauseAction == null) { + mPlayPauseAction = new Notification.Action(playPauseIcon, playPauseLabel, + mIntents.get(playPauseIcon)); + } else { + mPlayPauseAction.icon = playPauseIcon; + mPlayPauseAction.title = playPauseLabel; + mPlayPauseAction.actionIntent = mIntents.get(playPauseIcon); + } + } + + private void updateNotificationPlaybackState() { + LogHelper.d(TAG, "updateNotificationPlaybackState. mPlaybackState=" + mPlaybackState); + if (mPlaybackState == null || !mStarted) { + LogHelper.d(TAG, "updateNotificationPlaybackState. cancelling notification!"); + mService.stopForeground(true); + return; + } + if (mNotificationBuilder == null) { + LogHelper.d(TAG, "updateNotificationPlaybackState. there is no notificationBuilder. Ignoring request to update state!"); + return; + } + if (mPlaybackState.getPosition() >= 0) { + LogHelper.d(TAG, "updateNotificationPlaybackState. updating playback position to ", + (System.currentTimeMillis() - mPlaybackState.getPosition()) / 1000, " seconds"); + mNotificationBuilder + .setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()) + .setShowWhen(true) + .setUsesChronometer(true); + mNotificationBuilder.setShowWhen(true); + } else { + LogHelper.d(TAG, "updateNotificationPlaybackState. hiding playback position"); + mNotificationBuilder + .setWhen(0) + .setShowWhen(false) + .setUsesChronometer(false); + } + + updatePlayPauseAction(); + + // Make sure that the notification can be dismissed by the user when we are not playing: + mNotificationBuilder.setOngoing(mPlaybackState.getState() == PlaybackState.STATE_PLAYING); + + mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); + } + + public void fetchBitmapFromURLAsync(final String source) { + LogHelper.d(TAG, "getBitmapFromURLAsync: starting asynctask to fetch ", source); + new AsyncTask<Void, Void, Bitmap>() { + @Override + protected Bitmap doInBackground(Void[] objects) { + Bitmap bitmap = null; + try { + bitmap = BitmapHelper.fetchAndRescaleBitmap(source, + BitmapHelper.MEDIA_ART_BIG_WIDTH, BitmapHelper.MEDIA_ART_BIG_HEIGHT); + mAlbumArtCache.put(source, bitmap); + } catch (IOException e) { + LogHelper.e(TAG, e, "getBitmapFromURLAsync: " + source); + } + return bitmap; + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + if (bitmap != null && mMetadata != null && + mNotificationBuilder != null && mMetadata.getDescription() != null && + !source.equals(mMetadata.getDescription().getIconUri())) { + // If the media is still the same, update the notification: + LogHelper.d(TAG, "getBitmapFromURLAsync: set bitmap to ", source); + mNotificationBuilder.setLargeIcon(bitmap); + mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); + } + } + }.execute(); + } + +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MusicPlayerActivity.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MusicPlayerActivity.java new file mode 100644 index 000000000..648d26896 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MusicPlayerActivity.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2014 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.mediabrowserservice; + +import android.app.Activity; +import android.media.browse.MediaBrowser; +import android.media.session.MediaController; +import android.os.Bundle; + +/** + * Main activity for the music player. + */ +public class MusicPlayerActivity extends Activity + implements BrowseFragment.FragmentDataHelper { + + private static final String TAG = MusicPlayerActivity.class.getSimpleName(); + + private MediaBrowser mMediaBrowser; + private MediaController mMediaController; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_player); + if (savedInstanceState == null) { + getFragmentManager().beginTransaction() + .add(R.id.container, BrowseFragment.newInstance(null)) + .commit(); + } + } + + @Override + public void onMediaItemSelected(MediaBrowser.MediaItem item) { + if (item.isPlayable()) { + getMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null); + QueueFragment queueFragment = QueueFragment.newInstance(); + getFragmentManager().beginTransaction() + .replace(R.id.container, queueFragment) + .addToBackStack(null) + .commit(); + } else if (item.isBrowsable()) { + getFragmentManager().beginTransaction() + .replace(R.id.container, BrowseFragment.newInstance(item.getMediaId())) + .addToBackStack(null) + .commit(); + } + } +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MusicService.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MusicService.java new file mode 100644 index 000000000..a7a9ae2e7 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/MusicService.java @@ -0,0 +1,936 @@ +/* + * Copyright (C) 2014 Google Inc. All Rights Reserved. + * + * 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.mediabrowserservice; + +import android.content.Context; +import android.content.Intent; +import android.media.AudioManager; +import android.media.MediaDescription; +import android.media.MediaMetadata; +import android.media.MediaPlayer; +import android.media.MediaPlayer.OnCompletionListener; +import android.media.MediaPlayer.OnErrorListener; +import android.media.MediaPlayer.OnPreparedListener; +import android.media.browse.MediaBrowser; +import android.media.browse.MediaBrowser.MediaItem; +import android.media.session.MediaSession; +import android.media.session.PlaybackState; +import android.net.Uri; +import android.net.wifi.WifiManager; +import android.net.wifi.WifiManager.WifiLock; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.PowerManager; +import android.os.SystemClock; +import android.service.media.MediaBrowserService; + +import com.example.android.mediabrowserservice.model.MusicProvider; +import com.example.android.mediabrowserservice.utils.LogHelper; +import com.example.android.mediabrowserservice.utils.MediaIDHelper; +import com.example.android.mediabrowserservice.utils.QueueHelper; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static com.example.android.mediabrowserservice.utils.MediaIDHelper.MEDIA_ID_MUSICS_BY_GENRE; +import static com.example.android.mediabrowserservice.utils.MediaIDHelper.MEDIA_ID_ROOT; +import static com.example.android.mediabrowserservice.utils.MediaIDHelper.createBrowseCategoryMediaID; +import static com.example.android.mediabrowserservice.utils.MediaIDHelper.extractBrowseCategoryFromMediaID; + +/** + * This class provides a MediaBrowser through a service. It exposes the media library to a browsing + * client, through the onGetRoot and onLoadChildren methods. It also creates a MediaSession and + * exposes it through its MediaSession.Token, which allows the client to create a MediaController + * that connects to and send control commands to the MediaSession remotely. This is useful for + * user interfaces that need to interact with your media session, like Android Auto. You can + * (should) also use the same service from your app's UI, which gives a seamless playback + * experience to the user. + * + * To implement a MediaBrowserService, you need to: + * + * <ul> + * + * <li> Extend {@link android.service.media.MediaBrowserService}, implementing the media browsing + * related methods {@link android.service.media.MediaBrowserService#onGetRoot} and + * {@link android.service.media.MediaBrowserService#onLoadChildren}; + * <li> In onCreate, start a new {@link android.media.session.MediaSession} and notify its parent + * with the session's token {@link android.service.media.MediaBrowserService#setSessionToken}; + * + * <li> Set a callback on the + * {@link android.media.session.MediaSession#setCallback(android.media.session.MediaSession.Callback)}. + * The callback will receive all the user's actions, like play, pause, etc; + * + * <li> Handle all the actual music playing using any method your app prefers (for example, + * {@link android.media.MediaPlayer}) + * + * <li> Update playbackState, "now playing" metadata and queue, using MediaSession proper methods + * {@link android.media.session.MediaSession#setPlaybackState(android.media.session.PlaybackState)} + * {@link android.media.session.MediaSession#setMetadata(android.media.MediaMetadata)} and + * {@link android.media.session.MediaSession#setQueue(java.util.List)}) + * + * <li> Declare and export the service in AndroidManifest with an intent receiver for the action + * android.media.browse.MediaBrowserService + * + * </ul> + * + * To make your app compatible with Android Auto, you also need to: + * + * <ul> + * + * <li> Declare a meta-data tag in AndroidManifest.xml linking to a xml resource + * with a <automotiveApp> root element. For a media app, this must include + * an <uses name="media"/> element as a child. + * For example, in AndroidManifest.xml: + * <meta-data android:name="com.google.android.gms.car.application" + * android:resource="@xml/automotive_app_desc"/> + * And in res/values/automotive_app_desc.xml: + * <automotiveApp> + * <uses name="media"/> + * </automotiveApp> + * + * </ul> + + * @see <a href="README.md">README.md</a> for more details. + * + */ + +public class MusicService extends MediaBrowserService implements OnPreparedListener, + OnCompletionListener, OnErrorListener, AudioManager.OnAudioFocusChangeListener { + + private static final String TAG = "MusicService"; + + // Action to thumbs up a media item + private static final String CUSTOM_ACTION_THUMBS_UP = "thumbs_up"; + // Delay stopSelf by using a handler. + private static final int STOP_DELAY = 30000; + + // The volume we set the media player to when we lose audio focus, but are + // allowed to reduce the volume instead of stopping playback. + public static final float VOLUME_DUCK = 0.2f; + + // The volume we set the media player when we have audio focus. + public static final float VOLUME_NORMAL = 1.0f; + public static final String ANDROID_AUTO_PACKAGE_NAME = "com.google.android.projection.gearhead"; + public static final String ANDROID_AUTO_EMULATOR_PACKAGE_NAME = "com.google.android.mediasimulator"; + + // Music catalog manager + private MusicProvider mMusicProvider; + + private MediaSession mSession; + private MediaPlayer mMediaPlayer; + + // "Now playing" queue: + private List<MediaSession.QueueItem> mPlayingQueue; + private int mCurrentIndexOnQueue; + + // Current local media player state + private int mState = PlaybackState.STATE_NONE; + + // Wifi lock that we hold when streaming files from the internet, in order + // to prevent the device from shutting off the Wifi radio + private WifiLock mWifiLock; + + private MediaNotification mMediaNotification; + + // Indicates whether the service was started. + private boolean mServiceStarted; + + enum AudioFocus { + NoFocusNoDuck, // we don't have audio focus, and can't duck + NoFocusCanDuck, // we don't have focus, but can play at a low volume + // ("ducking") + Focused // we have full audio focus + } + + // Type of audio focus we have: + private AudioFocus mAudioFocus = AudioFocus.NoFocusNoDuck; + private AudioManager mAudioManager; + + // Indicates if we should start playing immediately after we gain focus. + private boolean mPlayOnFocusGain; + + private Handler mDelayedStopHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + if ((mMediaPlayer != null && mMediaPlayer.isPlaying()) || + mPlayOnFocusGain) { + LogHelper.d(TAG, "Ignoring delayed stop since the media player is in use."); + return; + } + LogHelper.d(TAG, "Stopping service with delay handler."); + stopSelf(); + mServiceStarted = false; + } + }; + + /* + * (non-Javadoc) + * @see android.app.Service#onCreate() + */ + @Override + public void onCreate() { + super.onCreate(); + LogHelper.d(TAG, "onCreate"); + + mPlayingQueue = new ArrayList<>(); + + // Create the Wifi lock (this does not acquire the lock, this just creates it) + mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) + .createWifiLock(WifiManager.WIFI_MODE_FULL, "MusicDemo_lock"); + + + // Create the music catalog metadata provider + mMusicProvider = new MusicProvider(); + mMusicProvider.retrieveMedia(new MusicProvider.Callback() { + @Override + public void onMusicCatalogReady(boolean success) { + mState = success ? PlaybackState.STATE_NONE : PlaybackState.STATE_ERROR; + } + }); + + mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); + + // Start a new MediaSession + mSession = new MediaSession(this, "MusicService"); + setSessionToken(mSession.getSessionToken()); + mSession.setCallback(new MediaSessionCallback()); + mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | + MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); + + // Use these extras to reserve space for the corresponding actions, even when they are disabled + // in the playbackstate, so the custom actions don't reflow. + Bundle extras = new Bundle(); + extras.putBoolean( + "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_NEXT", + true); + extras.putBoolean( + "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_PREVIOUS", + true); + // If you want to reserve the Queue slot when there is no queue + // (mSession.setQueue(emptylist)), uncomment the lines below: + // extras.putBoolean( + // "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_QUEUE", + // true); + mSession.setExtras(extras); + + updatePlaybackState(null); + + mMediaNotification = new MediaNotification(this); + } + + /* + * (non-Javadoc) + * @see android.app.Service#onDestroy() + */ + @Override + public void onDestroy() { + LogHelper.d(TAG, "onDestroy"); + + // Service is being killed, so make sure we release our resources + handleStopRequest(null); + + mDelayedStopHandler.removeCallbacksAndMessages(null); + // In particular, always release the MediaSession to clean up resources + // and notify associated MediaController(s). + mSession.release(); + } + + + @Override + public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) { + LogHelper.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName, + "; clientUid=" + clientUid + " ; rootHints=", rootHints); + // To ensure you are not allowing any arbitrary app to browse your app's contents, you + // need to check the origin: + if (!ANDROID_AUTO_PACKAGE_NAME.equals(clientPackageName) && + !ANDROID_AUTO_EMULATOR_PACKAGE_NAME.equals(clientPackageName) && + !getApplication().getPackageName().equals(clientPackageName)) { + // If the request comes from an untrusted package, return null. No further calls will + // be made to other media browsing methods. + LogHelper.w(TAG, "OnGetRoot: IGNORING request from untrusted package " + clientPackageName); + return null; + } + if (ANDROID_AUTO_PACKAGE_NAME.equals(clientPackageName)) { + // Optional: if your app needs to adapt ads, music library or anything else that + // needs to run differently when connected to the car, this is where you should handle + // it. + } + return new BrowserRoot(MEDIA_ID_ROOT, null); + } + + @Override + public void onLoadChildren(final String parentMediaId, final Result<List<MediaItem>> result) { + if (!mMusicProvider.isInitialized()) { + // Use result.detach to allow calling result.sendResult from another thread: + result.detach(); + + mMusicProvider.retrieveMedia(new MusicProvider.Callback() { + @Override + public void onMusicCatalogReady(boolean success) { + if (success) { + loadChildrenImpl(parentMediaId, result); + } else { + updatePlaybackState(getString(R.string.error_no_metadata)); + result.sendResult(new ArrayList<MediaItem>()); + } + } + }); + + } else { + // If our music catalog is already loaded/cached, load them into result immediately + loadChildrenImpl(parentMediaId, result); + } + } + + /** + * Actual implementation of onLoadChildren that assumes that MusicProvider is already + * initialized. + */ + private void loadChildrenImpl(final String parentMediaId, + final Result<List<MediaBrowser.MediaItem>> result) { + LogHelper.d(TAG, "OnLoadChildren: parentMediaId=", parentMediaId); + + List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>(); + + if (MEDIA_ID_ROOT.equals(parentMediaId)) { + LogHelper.d(TAG, "OnLoadChildren.ROOT"); + mediaItems.add(new MediaBrowser.MediaItem( + new MediaDescription.Builder() + .setMediaId(MEDIA_ID_MUSICS_BY_GENRE) + .setTitle(getString(R.string.browse_genres)) + .setIconUri(Uri.parse("android.resource://" + + "com.example.android.mediabrowserservice/drawable/ic_by_genre")) + .setSubtitle(getString(R.string.browse_genre_subtitle)) + .build(), MediaBrowser.MediaItem.FLAG_BROWSABLE + )); + + } else if (MEDIA_ID_MUSICS_BY_GENRE.equals(parentMediaId)) { + LogHelper.d(TAG, "OnLoadChildren.GENRES"); + for (String genre: mMusicProvider.getGenres()) { + MediaBrowser.MediaItem item = new MediaBrowser.MediaItem( + new MediaDescription.Builder() + .setMediaId(createBrowseCategoryMediaID(MEDIA_ID_MUSICS_BY_GENRE, genre)) + .setTitle(genre) + .setSubtitle(getString(R.string.browse_musics_by_genre_subtitle, genre)) + .build(), MediaBrowser.MediaItem.FLAG_BROWSABLE + ); + mediaItems.add(item); + } + + } else if (parentMediaId.startsWith(MEDIA_ID_MUSICS_BY_GENRE)) { + String genre = extractBrowseCategoryFromMediaID(parentMediaId)[1]; + LogHelper.d(TAG, "OnLoadChildren.SONGS_BY_GENRE genre=", genre); + for (MediaMetadata track: mMusicProvider.getMusicsByGenre(genre)) { + // Since mediaMetadata fields are immutable, we need to create a copy, so we + // can set a hierarchy-aware mediaID. We will need to know the media hierarchy + // when we get a onPlayFromMusicID call, so we can create the proper queue based + // on where the music was selected from (by artist, by genre, random, etc) + String hierarchyAwareMediaID = MediaIDHelper.createTrackMediaID( + MEDIA_ID_MUSICS_BY_GENRE, genre, track); + MediaMetadata trackCopy = new MediaMetadata.Builder(track) + .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID) + .build(); + MediaBrowser.MediaItem bItem = new MediaBrowser.MediaItem( + trackCopy.getDescription(), MediaItem.FLAG_PLAYABLE); + mediaItems.add(bItem); + } + } else { + LogHelper.w(TAG, "Skipping unmatched parentMediaId: ", parentMediaId); + } + result.sendResult(mediaItems); + } + + + + private final class MediaSessionCallback extends MediaSession.Callback { + @Override + public void onPlay() { + LogHelper.d(TAG, "play"); + + if (mPlayingQueue == null || mPlayingQueue.isEmpty()) { + mPlayingQueue = QueueHelper.getRandomQueue(mMusicProvider); + mSession.setQueue(mPlayingQueue); + mSession.setQueueTitle(getString(R.string.random_queue_title)); + // start playing from the beginning of the queue + mCurrentIndexOnQueue = 0; + } + + if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) { + handlePlayRequest(); + } + } + + @Override + public void onSkipToQueueItem(long queueId) { + LogHelper.d(TAG, "OnSkipToQueueItem:" + queueId); + if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) { + + // set the current index on queue from the music Id: + mCurrentIndexOnQueue = QueueHelper.getMusicIndexOnQueue(mPlayingQueue, queueId); + + // play the music + handlePlayRequest(); + } + } + + @Override + public void onPlayFromMediaId(String mediaId, Bundle extras) { + LogHelper.d(TAG, "playFromMediaId mediaId:", mediaId, " extras=", extras); + + // The mediaId used here is not the unique musicId. This one comes from the + // MediaBrowser, and is actually a "hierarchy-aware mediaID": a concatenation of + // the hierarchy in MediaBrowser and the actual unique musicID. This is necessary + // so we can build the correct playing queue, based on where the track was + // selected from. + mPlayingQueue = QueueHelper.getPlayingQueue(mediaId, mMusicProvider); + mSession.setQueue(mPlayingQueue); + String queueTitle = getString(R.string.browse_musics_by_genre_subtitle, + MediaIDHelper.extractBrowseCategoryValueFromMediaID(mediaId)); + mSession.setQueueTitle(queueTitle); + + if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) { + String uniqueMusicID = MediaIDHelper.extractMusicIDFromMediaID(mediaId); + // set the current index on queue from the music Id: + mCurrentIndexOnQueue = QueueHelper.getMusicIndexOnQueue( + mPlayingQueue, uniqueMusicID); + + // play the music + handlePlayRequest(); + } + } + + @Override + public void onPause() { + LogHelper.d(TAG, "pause. current state=" + mState); + handlePauseRequest(); + } + + @Override + public void onStop() { + LogHelper.d(TAG, "stop. current state=" + mState); + handleStopRequest(null); + } + + @Override + public void onSkipToNext() { + LogHelper.d(TAG, "skipToNext"); + mCurrentIndexOnQueue++; + if (mPlayingQueue != null && mCurrentIndexOnQueue >= mPlayingQueue.size()) { + mCurrentIndexOnQueue = 0; + } + if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) { + mState = PlaybackState.STATE_PLAYING; + handlePlayRequest(); + } else { + LogHelper.e(TAG, "skipToNext: cannot skip to next. next Index=" + + mCurrentIndexOnQueue + " queue length=" + + (mPlayingQueue == null ? "null" : mPlayingQueue.size())); + handleStopRequest("Cannot skip"); + } + } + + @Override + public void onSkipToPrevious() { + LogHelper.d(TAG, "skipToPrevious"); + + mCurrentIndexOnQueue--; + if (mPlayingQueue != null && mCurrentIndexOnQueue < 0) { + // This sample's behavior: skipping to previous when in first song restarts the + // first song. + mCurrentIndexOnQueue = 0; + } + if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) { + mState = PlaybackState.STATE_PLAYING; + handlePlayRequest(); + } else { + LogHelper.e(TAG, "skipToPrevious: cannot skip to previous. previous Index=" + + mCurrentIndexOnQueue + " queue length=" + + (mPlayingQueue == null ? "null" : mPlayingQueue.size())); + handleStopRequest("Cannot skip"); + } + } + + @Override + public void onCustomAction(String action, Bundle extras) { + if (CUSTOM_ACTION_THUMBS_UP.equals(action)) { + LogHelper.i(TAG, "onCustomAction: favorite for current track"); + MediaMetadata track = getCurrentPlayingMusic(); + if (track != null) { + String mediaId = track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); + mMusicProvider.setFavorite(mediaId, !mMusicProvider.isFavorite(mediaId)); + } + updatePlaybackState(null); + } else { + LogHelper.e(TAG, "Unsupported action: ", action); + } + + } + + @Override + public void onPlayFromSearch(String query, Bundle extras) { + LogHelper.d(TAG, "playFromSearch query=", query); + + mPlayingQueue = QueueHelper.getPlayingQueueFromSearch(query, mMusicProvider); + LogHelper.d(TAG, "playFromSearch playqueue.length=" + mPlayingQueue.size()); + mSession.setQueue(mPlayingQueue); + + if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) { + + // start playing from the beginning of the queue + mCurrentIndexOnQueue = 0; + + handlePlayRequest(); + } + } + } + + + + /* + * Called when media player is done playing current song. + * @see android.media.MediaPlayer.OnCompletionListener + */ + @Override + public void onCompletion(MediaPlayer player) { + LogHelper.d(TAG, "onCompletion from MediaPlayer"); + // The media player finished playing the current song, so we go ahead + // and start the next. + if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) { + // In this sample, we restart the playing queue when it gets to the end: + mCurrentIndexOnQueue++; + if (mCurrentIndexOnQueue >= mPlayingQueue.size()) { + mCurrentIndexOnQueue = 0; + } + handlePlayRequest(); + } else { + // If there is nothing to play, we stop and release the resources: + handleStopRequest(null); + } + } + + /* + * Called when media player is done preparing. + * @see android.media.MediaPlayer.OnPreparedListener + */ + @Override + public void onPrepared(MediaPlayer player) { + LogHelper.d(TAG, "onPrepared from MediaPlayer"); + // The media player is done preparing. That means we can start playing if we + // have audio focus. + configMediaPlayerState(); + } + + /** + * Called when there's an error playing media. When this happens, the media + * player goes to the Error state. We warn the user about the error and + * reset the media player. + * + * @see android.media.MediaPlayer.OnErrorListener + */ + @Override + public boolean onError(MediaPlayer mp, int what, int extra) { + LogHelper.e(TAG, "Media player error: what=" + what + ", extra=" + extra); + handleStopRequest("MediaPlayer error " + what + " (" + extra + ")"); + return true; // true indicates we handled the error + } + + + + + /** + * Called by AudioManager on audio focus changes. + */ + @Override + public void onAudioFocusChange(int focusChange) { + LogHelper.d(TAG, "onAudioFocusChange. focusChange=" + focusChange); + if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { + // We have gained focus: + mAudioFocus = AudioFocus.Focused; + + } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS || + focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || + focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { + // We have lost focus. If we can duck (low playback volume), we can keep playing. + // Otherwise, we need to pause the playback. + boolean canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK; + mAudioFocus = canDuck ? AudioFocus.NoFocusCanDuck : AudioFocus.NoFocusNoDuck; + + // If we are playing, we need to reset media player by calling configMediaPlayerState + // with mAudioFocus properly set. + if (mState == PlaybackState.STATE_PLAYING && !canDuck) { + // If we don't have audio focus and can't duck, we save the information that + // we were playing, so that we can resume playback once we get the focus back. + mPlayOnFocusGain = true; + } + } else { + LogHelper.e(TAG, "onAudioFocusChange: Ignoring unsupported focusChange: " + focusChange); + } + + configMediaPlayerState(); + } + + + + /** + * Handle a request to play music + */ + private void handlePlayRequest() { + LogHelper.d(TAG, "handlePlayRequest: mState=" + mState); + + mDelayedStopHandler.removeCallbacksAndMessages(null); + if (!mServiceStarted) { + LogHelper.v(TAG, "Starting service"); + // The MusicService needs to keep running even after the calling MediaBrowser + // is disconnected. Call startService(Intent) and then stopSelf(..) when we no longer + // need to play media. + startService(new Intent(getApplicationContext(), MusicService.class)); + mServiceStarted = true; + } + + mPlayOnFocusGain = true; + tryToGetAudioFocus(); + + if (!mSession.isActive()) { + mSession.setActive(true); + } + + // actually play the song + if (mState == PlaybackState.STATE_PAUSED) { + // If we're paused, just continue playback and restore the + // 'foreground service' state. + configMediaPlayerState(); + } else { + // If we're stopped or playing a song, + // just go ahead to the new song and (re)start playing + playCurrentSong(); + } + } + + + /** + * Handle a request to pause music + */ + private void handlePauseRequest() { + LogHelper.d(TAG, "handlePauseRequest: mState=" + mState); + + if (mState == PlaybackState.STATE_PLAYING) { + // Pause media player and cancel the 'foreground service' state. + mState = PlaybackState.STATE_PAUSED; + if (mMediaPlayer.isPlaying()) { + mMediaPlayer.pause(); + } + // while paused, retain the MediaPlayer but give up audio focus + relaxResources(false); + giveUpAudioFocus(); + } + updatePlaybackState(null); + } + + /** + * Handle a request to stop music + */ + private void handleStopRequest(String withError) { + LogHelper.d(TAG, "handleStopRequest: mState=" + mState + " error=", withError); + mState = PlaybackState.STATE_STOPPED; + + // let go of all resources... + relaxResources(true); + giveUpAudioFocus(); + updatePlaybackState(withError); + + mMediaNotification.stopNotification(); + + // service is no longer necessary. Will be started again if needed. + stopSelf(); + mServiceStarted = false; + } + + /** + * Releases resources used by the service for playback. This includes the + * "foreground service" status, the wake locks and possibly the MediaPlayer. + * + * @param releaseMediaPlayer Indicates whether the Media Player should also + * be released or not + */ + private void relaxResources(boolean releaseMediaPlayer) { + LogHelper.d(TAG, "relaxResources. releaseMediaPlayer=" + releaseMediaPlayer); + // stop being a foreground service + stopForeground(true); + + // reset the delayed stop handler. + mDelayedStopHandler.removeCallbacksAndMessages(null); + mDelayedStopHandler.sendEmptyMessageDelayed(0, STOP_DELAY); + + // stop and release the Media Player, if it's available + if (releaseMediaPlayer && mMediaPlayer != null) { + mMediaPlayer.reset(); + mMediaPlayer.release(); + mMediaPlayer = null; + } + + // we can also release the Wifi lock, if we're holding it + if (mWifiLock.isHeld()) { + mWifiLock.release(); + } + } + + /** + * Reconfigures MediaPlayer according to audio focus settings and + * starts/restarts it. This method starts/restarts the MediaPlayer + * respecting the current audio focus state. So if we have focus, it will + * play normally; if we don't have focus, it will either leave the + * MediaPlayer paused or set it to a low volume, depending on what is + * allowed by the current focus settings. This method assumes mPlayer != + * null, so if you are calling it, you have to do so from a context where + * you are sure this is the case. + */ + private void configMediaPlayerState() { + LogHelper.d(TAG, "configAndStartMediaPlayer. mAudioFocus=" + mAudioFocus); + if (mAudioFocus == AudioFocus.NoFocusNoDuck) { + // If we don't have audio focus and can't duck, we have to pause, + if (mState == PlaybackState.STATE_PLAYING) { + handlePauseRequest(); + } + } else { // we have audio focus: + if (mAudioFocus == AudioFocus.NoFocusCanDuck) { + mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet + } else { + mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again + } + // If we were playing when we lost focus, we need to resume playing. + if (mPlayOnFocusGain) { + if (!mMediaPlayer.isPlaying()) { + LogHelper.d(TAG, "configAndStartMediaPlayer startMediaPlayer."); + mMediaPlayer.start(); + } + mPlayOnFocusGain = false; + mState = PlaybackState.STATE_PLAYING; + } + } + updatePlaybackState(null); + } + + /** + * Makes sure the media player exists and has been reset. This will create + * the media player if needed, or reset the existing media player if one + * already exists. + */ + private void createMediaPlayerIfNeeded() { + LogHelper.d(TAG, "createMediaPlayerIfNeeded. needed? " + (mMediaPlayer==null)); + if (mMediaPlayer == null) { + mMediaPlayer = new MediaPlayer(); + + // Make sure the media player will acquire a wake-lock while + // playing. If we don't do that, the CPU might go to sleep while the + // song is playing, causing playback to stop. + mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); + + // we want the media player to notify us when it's ready preparing, + // and when it's done playing: + mMediaPlayer.setOnPreparedListener(this); + mMediaPlayer.setOnCompletionListener(this); + mMediaPlayer.setOnErrorListener(this); + } else { + mMediaPlayer.reset(); + } + } + + /** + * Starts playing the current song in the playing queue. + */ + void playCurrentSong() { + MediaMetadata track = getCurrentPlayingMusic(); + if (track == null) { + LogHelper.e(TAG, "playSong: ignoring request to play next song, because cannot" + + " find it." + + " currentIndex=" + mCurrentIndexOnQueue + + " playQueue.size=" + (mPlayingQueue==null?"null": mPlayingQueue.size())); + return; + } + String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE); + LogHelper.d(TAG, "playSong: current (" + mCurrentIndexOnQueue + ") in playingQueue. " + + " musicId=" + track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID) + + " source=" + source); + + mState = PlaybackState.STATE_STOPPED; + relaxResources(false); // release everything except MediaPlayer + + try { + createMediaPlayerIfNeeded(); + + mState = PlaybackState.STATE_BUFFERING; + + mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + mMediaPlayer.setDataSource(source); + + // Starts preparing the media player in the background. When + // it's done, it will call our OnPreparedListener (that is, + // the onPrepared() method on this class, since we set the + // listener to 'this'). Until the media player is prepared, + // we *cannot* call start() on it! + mMediaPlayer.prepareAsync(); + + // If we are streaming from the internet, we want to hold a + // Wifi lock, which prevents the Wifi radio from going to + // sleep while the song is playing. + mWifiLock.acquire(); + + updatePlaybackState(null); + updateMetadata(); + + } catch (IOException ex) { + LogHelper.e(TAG, ex, "IOException playing song"); + updatePlaybackState(ex.getMessage()); + } + } + + + + private void updateMetadata() { + if (!QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) { + LogHelper.e(TAG, "Can't retrieve current metadata."); + mState = PlaybackState.STATE_ERROR; + updatePlaybackState(getResources().getString(R.string.error_no_metadata)); + return; + } + MediaSession.QueueItem queueItem = mPlayingQueue.get(mCurrentIndexOnQueue); + String mediaId = queueItem.getDescription().getMediaId(); + MediaMetadata track = mMusicProvider.getMusic(mediaId); + String trackId = track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); + if (!mediaId.equals(trackId)) { + throw new IllegalStateException("track ID (" + trackId + ") " + + "should match mediaId (" + mediaId + ")"); + } + LogHelper.d(TAG, "Updating metadata for MusicID= " + mediaId); + mSession.setMetadata(track); + } + + + /** + * Update the current media player state, optionally showing an error message. + * + * @param error if not null, error message to present to the user. + * + */ + private void updatePlaybackState(String error) { + + LogHelper.d(TAG, "updatePlaybackState, setting session playback state to " + mState); + long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN; + if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { + position = mMediaPlayer.getCurrentPosition(); + } + PlaybackState.Builder stateBuilder = new PlaybackState.Builder() + .setActions(getAvailableActions()); + + setCustomAction(stateBuilder); + + // If there is an error message, send it to the playback state: + if (error != null) { + // Error states are really only supposed to be used for errors that cause playback to + // stop unexpectedly and persist until the user takes action to fix it. + stateBuilder.setErrorMessage(error); + mState = PlaybackState.STATE_ERROR; + } + stateBuilder.setState(mState, position, 1.0f, SystemClock.elapsedRealtime()); + + // Set the activeQueueItemId if the current index is valid. + if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) { + MediaSession.QueueItem item = mPlayingQueue.get(mCurrentIndexOnQueue); + stateBuilder.setActiveQueueItemId(item.getQueueId()); + } + + mSession.setPlaybackState(stateBuilder.build()); + + if (mState == PlaybackState.STATE_PLAYING || mState == PlaybackState.STATE_PAUSED) { + mMediaNotification.startNotification(); + } + } + + private void setCustomAction(PlaybackState.Builder stateBuilder) { + MediaMetadata currentMusic = getCurrentPlayingMusic(); + if (currentMusic != null) { + // Set appropriate "Favorite" icon on Custom action: + String mediaId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); + int favoriteIcon = R.drawable.ic_star_off; + if (mMusicProvider.isFavorite(mediaId)) { + favoriteIcon = R.drawable.ic_star_on; + } + LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ", + mediaId, " current favorite=", mMusicProvider.isFavorite(mediaId)); + stateBuilder.addCustomAction(CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite), + favoriteIcon); + } + } + + private long getAvailableActions() { + long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | + PlaybackState.ACTION_PLAY_FROM_SEARCH; + if (mPlayingQueue == null || mPlayingQueue.isEmpty()) { + return actions; + } + if (mState == PlaybackState.STATE_PLAYING) { + actions |= PlaybackState.ACTION_PAUSE; + } + if (mCurrentIndexOnQueue > 0) { + actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS; + } + if (mCurrentIndexOnQueue < mPlayingQueue.size() - 1) { + actions |= PlaybackState.ACTION_SKIP_TO_NEXT; + } + return actions; + } + + private MediaMetadata getCurrentPlayingMusic() { + if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) { + MediaSession.QueueItem item = mPlayingQueue.get(mCurrentIndexOnQueue); + if (item != null) { + LogHelper.d(TAG, "getCurrentPlayingMusic for musicId=", + item.getDescription().getMediaId()); + return mMusicProvider.getMusic(item.getDescription().getMediaId()); + } + } + return null; + } + + /** + * Try to get the system audio focus. + */ + void tryToGetAudioFocus() { + LogHelper.d(TAG, "tryToGetAudioFocus"); + if (mAudioFocus != AudioFocus.Focused) { + int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, + AudioManager.AUDIOFOCUS_GAIN); + if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { + mAudioFocus = AudioFocus.Focused; + } + } + } + + /** + * Give up the audio focus. + */ + void giveUpAudioFocus() { + LogHelper.d(TAG, "giveUpAudioFocus"); + if (mAudioFocus == AudioFocus.Focused) { + if (mAudioManager.abandonAudioFocus(this) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { + mAudioFocus = AudioFocus.NoFocusNoDuck; + } + } + } +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/QueueAdapter.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/QueueAdapter.java new file mode 100644 index 000000000..4f24e9944 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/QueueAdapter.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2014 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.mediabrowserservice; + +import android.app.Activity; +import android.media.session.MediaSession; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.ArrayList; + +/** + * A list adapter for items in a queue + */ +public class QueueAdapter extends ArrayAdapter<MediaSession.QueueItem> { + + // The currently selected/active queue item Id. + private long mActiveQueueItemId = MediaSession.QueueItem.UNKNOWN_ID; + + public QueueAdapter(Activity context) { + super(context, R.layout.media_list_item, new ArrayList<MediaSession.QueueItem>()); + } + + public void setActiveQueueItemId(long id) { + this.mActiveQueueItemId = id; + } + + private static class ViewHolder { + ImageView mImageView; + TextView mTitleView; + TextView mDescriptionView; + } + + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder holder; + + if (convertView == null) { + convertView = LayoutInflater.from(getContext()) + .inflate(R.layout.media_list_item, parent, false); + holder = new ViewHolder(); + holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq); + holder.mTitleView = (TextView) convertView.findViewById(R.id.title); + holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + + MediaSession.QueueItem item = getItem(position); + holder.mTitleView.setText(item.getDescription().getTitle()); + if (item.getDescription().getDescription() != null) { + holder.mDescriptionView.setText(item.getDescription().getDescription()); + } + + // If the itemId matches the active Id then use a different icon + if (mActiveQueueItemId == item.getQueueId()) { + holder.mImageView.setImageDrawable( + getContext().getDrawable(R.drawable.ic_equalizer_white_24dp)); + } else { + holder.mImageView.setImageDrawable( + getContext().getDrawable(R.drawable.ic_play_arrow_white_24dp)); + } + return convertView; + } +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/QueueFragment.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/QueueFragment.java new file mode 100644 index 000000000..f6076bc88 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/QueueFragment.java @@ -0,0 +1,295 @@ +/* + * Copyright (C) 2014 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.mediabrowserservice; + +import android.app.Fragment; +import android.content.ComponentName; +import android.media.browse.MediaBrowser; +import android.media.session.MediaController; +import android.media.session.MediaSession; +import android.media.session.PlaybackState; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ImageButton; +import android.widget.ListView; + +import com.example.android.mediabrowserservice.utils.LogHelper; + +import java.util.List; + +/** + * A class that shows the Media Queue to the user. + */ +public class QueueFragment extends Fragment { + + private static final String TAG = QueueFragment.class.getSimpleName(); + + private ImageButton mSkipNext; + private ImageButton mSkipPrevious; + private ImageButton mPlayPause; + + private MediaBrowser mMediaBrowser; + private MediaController.TransportControls mTransportControls; + private MediaController mMediaController; + private PlaybackState mPlaybackState; + + private QueueAdapter mQueueAdapter; + + private MediaBrowser.ConnectionCallback mConnectionCallback = + new MediaBrowser.ConnectionCallback() { + @Override + public void onConnected() { + LogHelper.d(TAG, "onConnected: session token ", mMediaBrowser.getSessionToken()); + + if (mMediaBrowser.getSessionToken() == null) { + throw new IllegalArgumentException("No Session token"); + } + + mMediaController = new MediaController(getActivity(), + mMediaBrowser.getSessionToken()); + mTransportControls = mMediaController.getTransportControls(); + mMediaController.registerCallback(mSessionCallback); + + getActivity().setMediaController(mMediaController); + mPlaybackState = mMediaController.getPlaybackState(); + + List<MediaSession.QueueItem> queue = mMediaController.getQueue(); + if (queue != null) { + mQueueAdapter.clear(); + mQueueAdapter.notifyDataSetInvalidated(); + mQueueAdapter.addAll(queue); + mQueueAdapter.notifyDataSetChanged(); + } + onPlaybackStateChanged(mPlaybackState); + } + + @Override + public void onConnectionFailed() { + LogHelper.d(TAG, "onConnectionFailed"); + } + + @Override + public void onConnectionSuspended() { + LogHelper.d(TAG, "onConnectionSuspended"); + mMediaController.unregisterCallback(mSessionCallback); + mTransportControls = null; + mMediaController = null; + getActivity().setMediaController(null); + } + }; + + // Receive callbacks from the MediaController. Here we update our state such as which queue + // is being shown, the current title and description and the PlaybackState. + private MediaController.Callback mSessionCallback = new MediaController.Callback() { + + @Override + public void onSessionDestroyed() { + LogHelper.d(TAG, "Session destroyed. Need to fetch a new Media Session"); + } + + @Override + public void onPlaybackStateChanged(PlaybackState state) { + if (state == null) { + return; + } + LogHelper.d(TAG, "Received playback state change to state ", state.getState()); + mPlaybackState = state; + QueueFragment.this.onPlaybackStateChanged(state); + } + + @Override + public void onQueueChanged(List<MediaSession.QueueItem> queue) { + LogHelper.d(TAG, "onQueueChanged ", queue); + if (queue != null) { + mQueueAdapter.clear(); + mQueueAdapter.notifyDataSetInvalidated(); + mQueueAdapter.addAll(queue); + mQueueAdapter.notifyDataSetChanged(); + } + } + }; + + public static QueueFragment newInstance() { + return new QueueFragment(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_list, container, false); + + mSkipPrevious = (ImageButton) rootView.findViewById(R.id.skip_previous); + mSkipPrevious.setEnabled(false); + mSkipPrevious.setOnClickListener(mButtonListener); + + mSkipNext = (ImageButton) rootView.findViewById(R.id.skip_next); + mSkipNext.setEnabled(false); + mSkipNext.setOnClickListener(mButtonListener); + + mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); + mPlayPause.setEnabled(true); + mPlayPause.setOnClickListener(mButtonListener); + + mQueueAdapter = new QueueAdapter(getActivity()); + + ListView mListView = (ListView) rootView.findViewById(R.id.list_view); + mListView.setAdapter(mQueueAdapter); + mListView.setFocusable(true); + mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + MediaSession.QueueItem item = mQueueAdapter.getItem(position); + mTransportControls.skipToQueueItem(item.getQueueId()); + } + }); + + mMediaBrowser = new MediaBrowser(getActivity(), + new ComponentName(getActivity(), MusicService.class), + mConnectionCallback, null); + + return rootView; + } + + @Override + public void onResume() { + super.onResume(); + if (mMediaBrowser != null) { + mMediaBrowser.connect(); + } + } + + @Override + public void onPause() { + super.onPause(); + if (mMediaController != null) { + mMediaController.unregisterCallback(mSessionCallback); + } + if (mMediaBrowser != null) { + mMediaBrowser.disconnect(); + } + } + + + private void onPlaybackStateChanged(PlaybackState state) { + LogHelper.d(TAG, "onPlaybackStateChanged ", state); + if (state == null) { + return; + } + mQueueAdapter.setActiveQueueItemId(state.getActiveQueueItemId()); + mQueueAdapter.notifyDataSetChanged(); + boolean enablePlay = false; + StringBuilder statusBuilder = new StringBuilder(); + switch (state.getState()) { + case PlaybackState.STATE_PLAYING: + statusBuilder.append("playing"); + enablePlay = false; + break; + case PlaybackState.STATE_PAUSED: + statusBuilder.append("paused"); + enablePlay = true; + break; + case PlaybackState.STATE_STOPPED: + statusBuilder.append("ended"); + enablePlay = true; + break; + case PlaybackState.STATE_ERROR: + statusBuilder.append("error: ").append(state.getErrorMessage()); + break; + case PlaybackState.STATE_BUFFERING: + statusBuilder.append("buffering"); + break; + case PlaybackState.STATE_NONE: + statusBuilder.append("none"); + enablePlay = false; + break; + case PlaybackState.STATE_CONNECTING: + statusBuilder.append("connecting"); + break; + default: + statusBuilder.append(mPlaybackState); + } + statusBuilder.append(" -- At position: ").append(state.getPosition()); + LogHelper.d(TAG, statusBuilder.toString()); + + if (enablePlay) { + mPlayPause.setImageDrawable( + getActivity().getDrawable(R.drawable.ic_play_arrow_white_24dp)); + } else { + mPlayPause.setImageDrawable(getActivity().getDrawable(R.drawable.ic_pause_white_24dp)); + } + + mSkipPrevious.setEnabled((state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0); + mSkipNext.setEnabled((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0); + + LogHelper.d(TAG, "Queue From MediaController *** Title " + + mMediaController.getQueueTitle() + "\n: Queue: " + mMediaController.getQueue() + + "\n Metadata " + mMediaController.getMetadata()); + } + + private View.OnClickListener mButtonListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + final int state = mPlaybackState == null ? + PlaybackState.STATE_NONE : mPlaybackState.getState(); + switch (v.getId()) { + case R.id.play_pause: + LogHelper.d(TAG, "Play button pressed, in state " + state); + if (state == PlaybackState.STATE_PAUSED || + state == PlaybackState.STATE_STOPPED || + state == PlaybackState.STATE_NONE) { + playMedia(); + } else if (state == PlaybackState.STATE_PLAYING) { + pauseMedia(); + } + break; + case R.id.skip_previous: + LogHelper.d(TAG, "Start button pressed, in state " + state); + skipToPrevious(); + break; + case R.id.skip_next: + skipToNext(); + break; + } + } + }; + + private void playMedia() { + if (mTransportControls != null) { + mTransportControls.play(); + } + } + + private void pauseMedia() { + if (mTransportControls != null) { + mTransportControls.pause(); + } + } + + private void skipToPrevious() { + if (mTransportControls != null) { + mTransportControls.skipToPrevious(); + } + } + + private void skipToNext() { + if (mTransportControls != null) { + mTransportControls.skipToNext(); + } + } +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/model/MusicProvider.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/model/MusicProvider.java new file mode 100644 index 000000000..ae90fb092 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/model/MusicProvider.java @@ -0,0 +1,296 @@ +/* + * Copyright (C) 2014 Google Inc. All Rights Reserved. + * + * 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.mediabrowserservice.model; + +import android.media.MediaMetadata; +import android.os.AsyncTask; + +import com.example.android.mediabrowserservice.utils.LogHelper; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Utility class to get a list of MusicTrack's based on a server-side JSON + * configuration. + */ +public class MusicProvider { + + private static final String TAG = "MusicProvider"; + + private static final String CATALOG_URL = "http://storage.googleapis.com/automotive-media/music.json"; + + public static final String CUSTOM_METADATA_TRACK_SOURCE = "__SOURCE__"; + + private static String JSON_MUSIC = "music"; + private static String JSON_TITLE = "title"; + private static String JSON_ALBUM = "album"; + private static String JSON_ARTIST = "artist"; + private static String JSON_GENRE = "genre"; + private static String JSON_SOURCE = "source"; + private static String JSON_IMAGE = "image"; + private static String JSON_TRACK_NUMBER = "trackNumber"; + private static String JSON_TOTAL_TRACK_COUNT = "totalTrackCount"; + private static String JSON_DURATION = "duration"; + + private final ReentrantLock initializationLock = new ReentrantLock(); + + // Categorized caches for music track data: + private final HashMap<String, List<MediaMetadata>> mMusicListByGenre; + private final HashMap<String, MediaMetadata> mMusicListById; + + private final HashSet<String> mFavoriteTracks; + + enum State { + NON_INITIALIZED, INITIALIZING, INITIALIZED; + } + + private State mCurrentState = State.NON_INITIALIZED; + + + public interface Callback { + void onMusicCatalogReady(boolean success); + } + + public MusicProvider() { + mMusicListByGenre = new HashMap<>(); + mMusicListById = new HashMap<>(); + mFavoriteTracks = new HashSet<>(); + } + + /** + * Get an iterator over the list of genres + * + * @return + */ + public Iterable<String> getGenres() { + if (mCurrentState != State.INITIALIZED) { + return new ArrayList<String>(0); + } + return mMusicListByGenre.keySet(); + } + + /** + * Get music tracks of the given genre + * + * @return + */ + public Iterable<MediaMetadata> getMusicsByGenre(String genre) { + if (mCurrentState != State.INITIALIZED || !mMusicListByGenre.containsKey(genre)) { + return new ArrayList<MediaMetadata>(); + } + return mMusicListByGenre.get(genre); + } + + /** + * Very basic implementation of a search that filter music tracks which title containing + * the given query. + * + * @return + */ + public Iterable<MediaMetadata> searchMusics(String titleQuery) { + ArrayList<MediaMetadata> result = new ArrayList<>(); + if (mCurrentState != State.INITIALIZED) { + return result; + } + titleQuery = titleQuery.toLowerCase(); + for (MediaMetadata track: mMusicListById.values()) { + if (track.getString(MediaMetadata.METADATA_KEY_TITLE).toLowerCase() + .contains(titleQuery)) { + result.add(track); + } + } + return result; + } + + public MediaMetadata getMusic(String mediaId) { + return mMusicListById.get(mediaId); + } + + public void setFavorite(String mediaId, boolean favorite) { + if (favorite) { + mFavoriteTracks.add(mediaId); + } else { + mFavoriteTracks.remove(mediaId); + } + } + + public boolean isFavorite(String musicId) { + return mFavoriteTracks.contains(musicId); + } + + public boolean isInitialized() { + return mCurrentState == State.INITIALIZED; + } + + /** + * Get the list of music tracks from a server and caches the track information + * for future reference, keying tracks by mediaId and grouping by genre. + * + * @return + */ + public void retrieveMedia(final Callback callback) { + + if (mCurrentState == State.INITIALIZED) { + // Nothing to do, execute callback immediately + callback.onMusicCatalogReady(true); + return; + } + + // Asynchronously load the music catalog in a separate thread + new AsyncTask() { + @Override + protected Object doInBackground(Object[] objects) { + retrieveMediaAsync(callback); + return null; + } + }.execute(); + } + + private void retrieveMediaAsync(Callback callback) { + initializationLock.lock(); + + try { + if (mCurrentState == State.NON_INITIALIZED) { + mCurrentState = State.INITIALIZING; + + int slashPos = CATALOG_URL.lastIndexOf('/'); + String path = CATALOG_URL.substring(0, slashPos + 1); + JSONObject jsonObj = parseUrl(CATALOG_URL); + + JSONArray tracks = jsonObj.getJSONArray(JSON_MUSIC); + if (tracks != null) { + for (int j = 0; j < tracks.length(); j++) { + MediaMetadata item = buildFromJSON(tracks.getJSONObject(j), path); + String genre = item.getString(MediaMetadata.METADATA_KEY_GENRE); + List<MediaMetadata> list = mMusicListByGenre.get(genre); + if (list == null) { + list = new ArrayList<>(); + } + list.add(item); + mMusicListByGenre.put(genre, list); + mMusicListById.put(item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID), + item); + } + } + mCurrentState = State.INITIALIZED; + } + } catch (RuntimeException | JSONException e) { + LogHelper.e(TAG, e, "Could not retrieve music list"); + } finally { + if (mCurrentState != State.INITIALIZED) { + // Something bad happened, so we reset state to NON_INITIALIZED to allow + // retries (eg if the network connection is temporary unavailable) + mCurrentState = State.NON_INITIALIZED; + } + initializationLock.unlock(); + if (callback != null) { + callback.onMusicCatalogReady(mCurrentState == State.INITIALIZED); + } + } + } + + private MediaMetadata buildFromJSON(JSONObject json, String basePath) throws JSONException { + String title = json.getString(JSON_TITLE); + String album = json.getString(JSON_ALBUM); + String artist = json.getString(JSON_ARTIST); + String genre = json.getString(JSON_GENRE); + String source = json.getString(JSON_SOURCE); + String iconUrl = json.getString(JSON_IMAGE); + int trackNumber = json.getInt(JSON_TRACK_NUMBER); + int totalTrackCount = json.getInt(JSON_TOTAL_TRACK_COUNT); + int duration = json.getInt(JSON_DURATION) * 1000; // ms + + LogHelper.d(TAG, "Found music track: ", json); + + // Media is stored relative to JSON file + if (!source.startsWith("http")) { + source = basePath + source; + } + if (!iconUrl.startsWith("http")) { + iconUrl = basePath + iconUrl; + } + // Since we don't have a unique ID in the server, we fake one using the hashcode of + // the music source. In a real world app, this could come from the server. + String id = String.valueOf(source.hashCode()); + + // Adding the music source to the MediaMetadata (and consequently using it in the + // mediaSession.setMetadata) is not a good idea for a real world music app, because + // the session metadata can be accessed by notification listeners. This is done in this + // sample for convenience only. + return new MediaMetadata.Builder() + .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id) + .putString(CUSTOM_METADATA_TRACK_SOURCE, source) + .putString(MediaMetadata.METADATA_KEY_ALBUM, album) + .putString(MediaMetadata.METADATA_KEY_ARTIST, artist) + .putLong(MediaMetadata.METADATA_KEY_DURATION, duration) + .putString(MediaMetadata.METADATA_KEY_GENRE, genre) + .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, iconUrl) + .putString(MediaMetadata.METADATA_KEY_TITLE, title) + .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, trackNumber) + .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, totalTrackCount) + .build(); + } + + /** + * Download a JSON file from a server, parse the content and return the JSON + * object. + * + * @param urlString + * @return + */ + private JSONObject parseUrl(String urlString) { + InputStream is = null; + try { + java.net.URL url = new java.net.URL(urlString); + URLConnection urlConnection = url.openConnection(); + is = new BufferedInputStream(urlConnection.getInputStream()); + BufferedReader reader = new BufferedReader(new InputStreamReader( + urlConnection.getInputStream(), "iso-8859-1")); + StringBuilder sb = new StringBuilder(); + String line = null; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + return new JSONObject(sb.toString()); + } catch (Exception e) { + LogHelper.e(TAG, "Failed to parse the json for media list", e); + return null; + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } + } +}
\ No newline at end of file diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/BitmapHelper.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/BitmapHelper.java new file mode 100644 index 000000000..5f0e76754 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/BitmapHelper.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2014 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.mediabrowserservice.utils; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +public class BitmapHelper { + + // Bitmap size for album art in media notifications when there are more than 3 playback actions + public static final int MEDIA_ART_SMALL_WIDTH=64; + public static final int MEDIA_ART_SMALL_HEIGHT=64; + + // Bitmap size for album art in media notifications when there are no more than 3 playback actions + public static final int MEDIA_ART_BIG_WIDTH=128; + public static final int MEDIA_ART_BIG_HEIGHT=128; + + public static final Bitmap scaleBitmap(int scaleFactor, InputStream is) { + // Get the dimensions of the bitmap + BitmapFactory.Options bmOptions = new BitmapFactory.Options(); + + // Decode the image file into a Bitmap sized to fill the View + bmOptions.inJustDecodeBounds = false; + bmOptions.inSampleSize = scaleFactor; + + Bitmap bitmap = BitmapFactory.decodeStream(is, null, bmOptions); + return bitmap; + } + + public static final int findScaleFactor(int targetW, int targetH, InputStream is) { + // Get the dimensions of the bitmap + BitmapFactory.Options bmOptions = new BitmapFactory.Options(); + bmOptions.inJustDecodeBounds = true; + BitmapFactory.decodeStream(is, null, bmOptions); + int actualW = bmOptions.outWidth; + int actualH = bmOptions.outHeight; + + // Determine how much to scale down the image + return Math.min(actualW/targetW, actualH/targetH); + } + + public static final Bitmap fetchAndRescaleBitmap(String uri, int width, int height) + throws IOException { + URL url = new URL(uri); + HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); + httpConnection.setDoInput(true); + httpConnection.connect(); + InputStream inputStream = httpConnection.getInputStream(); + int scaleFactor = findScaleFactor(width, height, inputStream); + + httpConnection = (HttpURLConnection) url.openConnection(); + httpConnection.setDoInput(true); + httpConnection.connect(); + inputStream = httpConnection.getInputStream(); + Bitmap bitmap = scaleBitmap(scaleFactor, inputStream); + return bitmap; + } + +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/LogHelper.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/LogHelper.java new file mode 100644 index 000000000..92b2e099e --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/LogHelper.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2014 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.mediabrowserservice.utils; + +import android.util.Log; + +public class LogHelper { + public static void v(String tag, Object... messages) { + log(tag, Log.VERBOSE, null, messages); + } + + public static void d(String tag, Object... messages) { + log(tag, Log.DEBUG, null, messages); + } + + public static void i(String tag, Object... messages) { + log(tag, Log.INFO, null, messages); + } + + public static void w(String tag, Object... messages) { + log(tag, Log.WARN, null, messages); + } + + public static void w(String tag, Throwable t, Object... messages) { + log(tag, Log.WARN, t, messages); + } + + public static void e(String tag, Object... messages) { + log(tag, Log.ERROR, null, messages); + } + + public static void e(String tag, Throwable t, Object... messages) { + log(tag, Log.ERROR, t, messages); + } + + public static void log(String tag, int level, Throwable t, Object... messages) { + if (messages != null && Log.isLoggable(tag, level)) { + String message; + if (messages.length == 1) { + message = messages[0] == null ? null : messages[0].toString(); + } else { + StringBuilder sb = new StringBuilder(); + for (Object m: messages) { + sb.append(m); + } + if (t != null) { + sb.append("\n").append(Log.getStackTraceString(t)); + } + message = sb.toString(); + } + Log.println(level, tag, message); + } + } +} diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/MediaIDHelper.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/MediaIDHelper.java new file mode 100644 index 000000000..68e6db9e3 --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/MediaIDHelper.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2014 Google Inc. All Rights Reserved. + * + * 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.mediabrowserservice.utils; + +import android.media.MediaMetadata; + +/** + * Utility class to help on queue related tasks. + */ +public class MediaIDHelper { + + private static final String TAG = "MediaIDHelper"; + + // Media IDs used on browseable items of MediaBrowser + public static final String MEDIA_ID_ROOT = "__ROOT__"; + public static final String MEDIA_ID_MUSICS_BY_GENRE = "__BY_GENRE__"; + + public static final String createTrackMediaID(String categoryType, String categoryValue, + MediaMetadata track) { + // MediaIDs are of the form <categoryType>/<categoryValue>|<musicUniqueId>, to make it easy to + // find the category (like genre) that a music was selected from, so we + // can correctly build the playing queue. This is specially useful when + // one music can appear in more than one list, like "by genre -> genre_1" + // and "by artist -> artist_1". + return categoryType + "/" + categoryValue + "|" + + track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); + } + + public static final String createBrowseCategoryMediaID(String categoryType, String categoryValue) { + return categoryType + "/" + categoryValue; + } + + /** + * Extracts unique musicID from the mediaID. mediaID is, by this sample's convention, a + * concatenation of category (eg "by_genre"), categoryValue (eg "Classical") and unique + * musicID. This is necessary so we know where the user selected the music from, when the music + * exists in more than one music list, and thus we are able to correctly build the playing queue. + * + * @param musicID + * @return + */ + public static final String extractMusicIDFromMediaID(String musicID) { + String[] segments = musicID.split("\\|", 2); + return segments.length == 2 ? segments[1] : null; + } + + /** + * Extracts category and categoryValue from the mediaID. mediaID is, by this sample's + * convention, a concatenation of category (eg "by_genre"), categoryValue (eg "Classical") and + * mediaID. This is necessary so we know where the user selected the music from, when the music + * exists in more than one music list, and thus we are able to correctly build the playing queue. + * + * @param mediaID + * @return + */ + public static final String[] extractBrowseCategoryFromMediaID(String mediaID) { + if (mediaID.indexOf('|') >= 0) { + mediaID = mediaID.split("\\|")[0]; + } + if (mediaID.indexOf('/') == 0) { + return new String[]{mediaID, null}; + } else { + return mediaID.split("/", 2); + } + } + + public static final String extractBrowseCategoryValueFromMediaID(String mediaID) { + String[] categoryAndValue = extractBrowseCategoryFromMediaID(mediaID); + if (categoryAndValue != null && categoryAndValue.length == 2) { + return categoryAndValue[1]; + } + return null; + } +}
\ No newline at end of file diff --git a/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/QueueHelper.java b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/QueueHelper.java new file mode 100644 index 000000000..abe3d34cd --- /dev/null +++ b/samples/browseable/MediaBrowserService/src/com.example.android.mediabrowserservice/utils/QueueHelper.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2014 Google Inc. All Rights Reserved. + * + * 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.mediabrowserservice.utils; + +import android.media.MediaMetadata; +import android.media.session.MediaSession; + +import com.example.android.mediabrowserservice.model.MusicProvider; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static com.example.android.mediabrowserservice.utils.MediaIDHelper.MEDIA_ID_MUSICS_BY_GENRE; + +/** + * Utility class to help on queue related tasks. + */ +public class QueueHelper { + + private static final String TAG = "QueueHelper"; + + public static final List<MediaSession.QueueItem> getPlayingQueue(String mediaId, + MusicProvider musicProvider) { + + // extract the category and unique music ID from the media ID: + String[] category = MediaIDHelper.extractBrowseCategoryFromMediaID(mediaId); + + // This sample only supports genre category. + if (!category[0].equals(MEDIA_ID_MUSICS_BY_GENRE) || category.length != 2) { + LogHelper.e(TAG, "Could not build a playing queue for this mediaId: ", mediaId); + return null; + } + + String categoryValue = category[1]; + LogHelper.e(TAG, "Creating playing queue for musics of genre ", categoryValue); + + List<MediaSession.QueueItem> queue = convertToQueue( + musicProvider.getMusicsByGenre(categoryValue)); + + return queue; + } + + public static final List<MediaSession.QueueItem> getPlayingQueueFromSearch(String query, + MusicProvider musicProvider) { + + LogHelper.e(TAG, "Creating playing queue for musics from search ", query); + + return convertToQueue(musicProvider.searchMusics(query)); + } + + + public static final int getMusicIndexOnQueue(Iterable<MediaSession.QueueItem> queue, + String mediaId) { + int index = 0; + for (MediaSession.QueueItem item: queue) { + if (mediaId.equals(item.getDescription().getMediaId())) { + return index; + } + index++; + } + return -1; + } + + public static final int getMusicIndexOnQueue(Iterable<MediaSession.QueueItem> queue, + long queueId) { + int index = 0; + for (MediaSession.QueueItem item: queue) { + if (queueId == item.getQueueId()) { + return index; + } + index++; + } + return -1; + } + + private static final List<MediaSession.QueueItem> convertToQueue( + Iterable<MediaMetadata> tracks) { + List<MediaSession.QueueItem> queue = new ArrayList<>(); + int count = 0; + for (MediaMetadata track : tracks) { + // We don't expect queues to change after created, so we use the item index as the + // queueId. Any other number unique in the queue would work. + MediaSession.QueueItem item = new MediaSession.QueueItem( + track.getDescription(), count++); + queue.add(item); + } + return queue; + + } + + /** + * Create a random queue. For simplicity sake, instead of a random queue, we create a + * queue using the first genre, + * + * @param musicProvider + * @return + */ + public static final List<MediaSession.QueueItem> getRandomQueue(MusicProvider musicProvider) { + Iterator<String> genres = musicProvider.getGenres().iterator(); + if (!genres.hasNext()) { + return new ArrayList<>(); + } + String genre = genres.next(); + Iterable<MediaMetadata> tracks = musicProvider.getMusicsByGenre(genre); + + return convertToQueue(tracks); + } + + + + public static final boolean isIndexPlayable(int index, List<MediaSession.QueueItem> queue) { + return (queue != null && index >= 0 && index < queue.size()); + } +} diff --git a/samples/browseable/MediaEffects/AndroidManifest.xml b/samples/browseable/MediaEffects/AndroidManifest.xml new file mode 100644 index 000000000..556f3c196 --- /dev/null +++ b/samples/browseable/MediaEffects/AndroidManifest.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2014 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 + package="com.example.android.mediaeffects" + xmlns:android="http://schemas.android.com/apk/res/android" + android:versionCode="1" + android:versionName="1.0"> + + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> + + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/AppTheme"> + + <activity + android:name=".MainActivity" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + + </application> + +</manifest> diff --git a/samples/browseable/MediaEffects/_index.jd b/samples/browseable/MediaEffects/_index.jd new file mode 100644 index 000000000..76448c36d --- /dev/null +++ b/samples/browseable/MediaEffects/_index.jd @@ -0,0 +1,12 @@ +page.tags="MediaEffects" +sample.group=Media +@jd:body + +<p> + + This sample shows how to use the Media Effects APIs that were introduced in Android 4.0. + These APIs let you apply effects to image frames represented as OpenGL ES 2.0 textures. + Image frames can be images loaded from disk, frames from the device\'s camera, or other + video streams. + + </p> diff --git a/samples/browseable/MediaEffects/res/drawable-hdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..960dc8eb1 --- /dev/null +++ b/samples/browseable/MediaEffects/res/drawable-hdpi/ic_launcher.png diff --git a/samples/browseable/NavigationDrawer/res/drawable-xhdpi/sample_dashboard_item_background.9.png b/samples/browseable/MediaEffects/res/drawable-hdpi/tile.9.png Binary files differindex 135862883..135862883 100644 --- a/samples/browseable/NavigationDrawer/res/drawable-xhdpi/sample_dashboard_item_background.9.png +++ b/samples/browseable/MediaEffects/res/drawable-hdpi/tile.9.png diff --git a/samples/browseable/MediaEffects/res/drawable-mdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..9356f268e --- /dev/null +++ b/samples/browseable/MediaEffects/res/drawable-mdpi/ic_launcher.png diff --git a/samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg b/samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg Binary files differnew file mode 100644 index 000000000..ef79be200 --- /dev/null +++ b/samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg diff --git a/samples/browseable/MediaEffects/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..230d5584d --- /dev/null +++ b/samples/browseable/MediaEffects/res/drawable-xhdpi/ic_launcher.png diff --git a/samples/browseable/MediaEffects/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/MediaEffects/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..c825d4e4e --- /dev/null +++ b/samples/browseable/MediaEffects/res/drawable-xxhdpi/ic_launcher.png diff --git a/samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml b/samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml new file mode 100755 index 000000000..c9a52f621 --- /dev/null +++ b/samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml @@ -0,0 +1,73 @@ +<!-- + 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="horizontal" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/sample_main_layout"> + + <LinearLayout + android:id="@+id/sample_output" + android:layout_width="0px" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <FrameLayout + style="@style/Widget.SampleMessageTile" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <TextView + style="@style/Widget.SampleMessage" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingLeft="@dimen/margin_medium" + android:paddingRight="@dimen/margin_medium" + android:paddingTop="@dimen/margin_large" + android:paddingBottom="@dimen/margin_large" + android:text="@string/intro_message" /> + </FrameLayout> + + <View + android:layout_width="match_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_width="match_parent" + android:layout_height="0px" + android:layout_weight="1" /> + + </LinearLayout> + + <View + android:layout_width="1dp" + android:layout_height="match_parent" + android:background="@android:color/darker_gray" /> + + <FrameLayout + android:id="@+id/sample_content_fragment" + android:layout_weight="2" + android:layout_width="0px" + android:layout_height="match_parent" /> + +</LinearLayout> + + diff --git a/samples/browseable/MediaEffects/res/layout/activity_main.xml b/samples/browseable/MediaEffects/res/layout/activity_main.xml new file mode 100755 index 000000000..1ae4f981e --- /dev/null +++ b/samples/browseable/MediaEffects/res/layout/activity_main.xml @@ -0,0 +1,65 @@ +<!-- + 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="match_parent" + android:layout_height="match_parent" + android:id="@+id/sample_main_layout"> + + <ViewAnimator + android:id="@+id/sample_output" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1"> + + <ScrollView + style="@style/Widget.SampleMessageTile" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + style="@style/Widget.SampleMessage" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingLeft="@dimen/horizontal_page_margin" + android:paddingRight="@dimen/horizontal_page_margin" + android:paddingTop="@dimen/vertical_page_margin" + android:paddingBottom="@dimen/vertical_page_margin" + android:text="@string/intro_message" /> + </ScrollView> + + <fragment + android:name="com.example.android.common.logger.LogFragment" + android:id="@+id/log_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + </ViewAnimator> + + <View + android:layout_width="match_parent" + android:layout_height="1dp" + android:background="@android:color/darker_gray" /> + + <FrameLayout + android:id="@+id/sample_content_fragment" + android:layout_weight="2" + android:layout_width="match_parent" + android:layout_height="0px" /> + +</LinearLayout> + diff --git a/samples/browseable/MediaEffects/res/layout/fragment_media_effects.xml b/samples/browseable/MediaEffects/res/layout/fragment_media_effects.xml new file mode 100644 index 000000000..4fb1ce1bc --- /dev/null +++ b/samples/browseable/MediaEffects/res/layout/fragment_media_effects.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical"> + + <android.opengl.GLSurfaceView + android:id="@+id/effectsview" + android:layout_width="fill_parent" + android:layout_height="0dp" + android:layout_weight="0.93"/> +</LinearLayout> diff --git a/samples/browseable/MediaEffects/res/menu/main.xml b/samples/browseable/MediaEffects/res/menu/main.xml new file mode 100644 index 000000000..b49c2c526 --- /dev/null +++ b/samples/browseable/MediaEffects/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/menu_toggle_log" + android:showAsAction="always" + android:title="@string/sample_show_log" /> +</menu> diff --git a/samples/browseable/MediaEffects/res/menu/media_effects.xml b/samples/browseable/MediaEffects/res/menu/media_effects.xml new file mode 100644 index 000000000..c37a9ac6b --- /dev/null +++ b/samples/browseable/MediaEffects/res/menu/media_effects.xml @@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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/none" + android:title="@string/none" + android:showAsAction="never" /> + + <item android:id="@+id/autofix" + android:title="@string/autofix" + android:showAsAction="never" /> + + <item android:id="@+id/bw" + android:title="@string/bw" + android:showAsAction="never" /> + + <item android:id="@+id/brightness" + android:title="@string/brightness" + android:showAsAction="never" /> + + <item android:id="@+id/contrast" + android:title="@string/contrast" + android:showAsAction="never" /> + + <item android:id="@+id/crossprocess" + android:title="@string/crossprocess" + android:showAsAction="never" /> + + <item android:id="@+id/documentary" + android:title="@string/documentary" + android:showAsAction="never" /> + + <item android:id="@+id/duotone" + android:title="@string/duotone" + android:showAsAction="never" /> + + <item android:id="@+id/filllight" + android:title="@string/filllight" + android:showAsAction="never" /> + + <item android:id="@+id/fisheye" + android:title="@string/fisheye" + android:showAsAction="never" /> + + <item android:id="@+id/flipvert" + android:title="@string/flipvert" + android:showAsAction="never" /> + + <item android:id="@+id/fliphor" + android:title="@string/fliphor" + android:showAsAction="never" /> + + <item android:id="@+id/grain" + android:title="@string/grain" + android:showAsAction="never" /> + + <item android:id="@+id/grayscale" + android:title="@string/grayscale" + android:showAsAction="never" /> + + <item android:id="@+id/lomoish" + android:title="@string/lomoish" + android:showAsAction="never" /> + + <item android:id="@+id/negative" + android:title="@string/negative" + android:showAsAction="never" /> + + <item android:id="@+id/posterize" + android:title="@string/posterize" + android:showAsAction="never" /> + + <item android:id="@+id/rotate" + android:title="@string/rotate" + android:showAsAction="never" /> + + <item android:id="@+id/saturate" + android:title="@string/saturate" + android:showAsAction="never" /> + + <item android:id="@+id/sepia" + android:title="@string/sepia" + android:showAsAction="never" /> + + <item android:id="@+id/sharpen" + android:title="@string/sharpen" + android:showAsAction="never" /> + + <item android:id="@+id/temperature" + android:title="@string/temperature" + android:showAsAction="never" /> + + <item android:id="@+id/tint" + android:title="@string/tint" + android:showAsAction="never" /> + + <item android:id="@+id/vignette" + android:title="@string/vignette" + android:showAsAction="never" /> +</menu> diff --git a/samples/browseable/MediaEffects/res/values-sw600dp/template-dimens.xml b/samples/browseable/MediaEffects/res/values-sw600dp/template-dimens.xml new file mode 100644 index 000000000..22074a2bd --- /dev/null +++ b/samples/browseable/MediaEffects/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/MediaEffects/res/values-sw600dp/template-styles.xml b/samples/browseable/MediaEffects/res/values-sw600dp/template-styles.xml new file mode 100644 index 000000000..03d197418 --- /dev/null +++ b/samples/browseable/MediaEffects/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/MediaEffects/res/values-v11/template-styles.xml b/samples/browseable/MediaEffects/res/values-v11/template-styles.xml new file mode 100644 index 000000000..8c1ea66f2 --- /dev/null +++ b/samples/browseable/MediaEffects/res/values-v11/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + 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" /> + +</resources> diff --git a/samples/browseable/MediaEffects/res/values-v21/template-styles.xml b/samples/browseable/MediaEffects/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/MediaEffects/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/DataLayer/Shared/AndroidManifest.xml b/samples/browseable/MediaEffects/res/values/base-strings.xml index b7d03bfaa..1acde2131 100644 --- a/samples/browseable/DataLayer/Shared/AndroidManifest.xml +++ b/samples/browseable/MediaEffects/res/values/base-strings.xml @@ -14,12 +14,18 @@ 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.datalayer.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> +<resources> + <string name="app_name">MediaEffects</string> + <string name="intro_message"> + <![CDATA[ + + + This sample shows how to use the Media Effects APIs that were introduced in Android 4.0. + These APIs let you apply effects to image frames represented as OpenGL ES 2.0 textures. + Image frames can be images loaded from disk, frames from the device\'s camera, or other + video streams. + + + ]]> + </string> +</resources> diff --git a/samples/browseable/CustomTransition/res/values/strings.xml b/samples/browseable/MediaEffects/res/values/fragmentview_strings.xml index 7b9d9ec4f..7b9d9ec4f 100755 --- a/samples/browseable/CustomTransition/res/values/strings.xml +++ b/samples/browseable/MediaEffects/res/values/fragmentview_strings.xml diff --git a/samples/browseable/MediaEffects/res/values/strings.xml b/samples/browseable/MediaEffects/res/values/strings.xml new file mode 100644 index 000000000..399cf6117 --- /dev/null +++ b/samples/browseable/MediaEffects/res/values/strings.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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="none">None</string> + <string name="autofix">Autofix</string> + <string name="bw">Min/Max Color Intensity</string> + <string name="brightness">Brightness</string> + <string name="contrast">Contrast</string> + <string name="crossprocess">Cross Process</string> + <string name="documentary">Documentary</string> + <string name="duotone">Duo Tone</string> + <string name="filllight">Fill Light</string> + <string name="fisheye">Fish Eye</string> + <string name="flipvert">Flip Vertical</string> + <string name="fliphor">Flip Horizontal</string> + <string name="grain">Grain</string> + <string name="grayscale">Grayscale</string> + <string name="lomoish">Lomoish</string> + <string name="negative">Negative</string> + <string name="posterize">Posterize</string> + <string name="rotate">Rotate</string> + <string name="saturate">Saturate</string> + <string name="sepia">Sepia</string> + <string name="sharpen">Sharpen</string> + <string name="temperature">Temperature</string> + <string name="tint">Tint</string> + <string name="vignette">Vignette</string> +</resources> diff --git a/samples/browseable/MediaEffects/res/values/template-dimens.xml b/samples/browseable/MediaEffects/res/values/template-dimens.xml new file mode 100644 index 000000000..39e710b5c --- /dev/null +++ b/samples/browseable/MediaEffects/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/MediaEffects/res/values/template-styles.xml b/samples/browseable/MediaEffects/res/values/template-styles.xml new file mode 100644 index 000000000..6e7d593dd --- /dev/null +++ b/samples/browseable/MediaEffects/res/values/template-styles.xml @@ -0,0 +1,42 @@ +<!-- + 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.Light" /> + + <style name="Theme.Sample" parent="Theme.Base" /> + + <style name="AppTheme" parent="Theme.Sample" /> + <!-- 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> + +</resources> diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/MediaEffects/src/com.example.android.common/activities/SampleActivityBase.java index 3228927b7..3228927b7 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ b/samples/browseable/MediaEffects/src/com.example.android.common/activities/SampleActivityBase.java diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/Log.java index 17503c568..17503c568 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/Log.java +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/Log.java diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogFragment.java index b302acd4b..b302acd4b 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogFragment.java diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogNode.java index bc37cabc0..bc37cabc0 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogNode.java diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogView.java index c01542b91..c01542b91 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogView.java diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogWrapper.java index 16a9e7ba2..16a9e7ba2 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/LogWrapper.java diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/MediaEffects/src/com.example.android.common/logger/MessageOnlyLogFilter.java index 19967dcd4..19967dcd4 100644 --- a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ b/samples/browseable/MediaEffects/src/com.example.android.common/logger/MessageOnlyLogFilter.java diff --git a/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/GLToolbox.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/GLToolbox.java new file mode 100644 index 000000000..02a8c590d --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/GLToolbox.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014 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.mediaeffects; + +import android.opengl.GLES20; + +public class GLToolbox { + + public static int loadShader(int shaderType, String source) { + int shader = GLES20.glCreateShader(shaderType); + if (shader != 0) { + GLES20.glShaderSource(shader, source); + GLES20.glCompileShader(shader); + int[] compiled = new int[1]; + GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); + if (compiled[0] == 0) { + String info = GLES20.glGetShaderInfoLog(shader); + GLES20.glDeleteShader(shader); + throw new RuntimeException("Could not compile shader " + shaderType + ":" + info); + } + } + return shader; + } + + public static int createProgram(String vertexSource, String fragmentSource) { + int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource); + if (vertexShader == 0) { + return 0; + } + int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); + if (pixelShader == 0) { + return 0; + } + + int program = GLES20.glCreateProgram(); + if (program != 0) { + GLES20.glAttachShader(program, vertexShader); + checkGlError("glAttachShader"); + GLES20.glAttachShader(program, pixelShader); + checkGlError("glAttachShader"); + GLES20.glLinkProgram(program); + int[] linkStatus = new int[1]; + GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, + 0); + if (linkStatus[0] != GLES20.GL_TRUE) { + String info = GLES20.glGetProgramInfoLog(program); + GLES20.glDeleteProgram(program); + throw new RuntimeException("Could not link program: " + info); + } + } + return program; + } + + public static void checkGlError(String op) { + int error; + while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { + throw new RuntimeException(op + ": glError " + error); + } + } + + public static void initTexParams() { + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, + GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, + GLES20.GL_CLAMP_TO_EDGE); + } + +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MainActivity.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MainActivity.java new file mode 100644 index 000000000..be6224310 --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MainActivity.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. +*/ + +package com.example.android.mediaeffects; + +import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.ViewAnimator; + +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, sample log and a custom + * {@link android.support.v4.app.Fragment} which can display a view. + * <p> + * For devices with displays with a width of 720dp or greater, the sample log is always visible, + * on other devices it's visibility is controlled by an item on the Action Bar. + */ +public class MainActivity extends SampleActivityBase { + + public static final String TAG = "MainActivity"; + + // Whether the Log Fragment is currently shown + private boolean mLogShown; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + MediaEffectsFragment fragment = new MediaEffectsFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + MenuItem logToggle = menu.findItem(R.id.menu_toggle_log); + logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator); + logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log); + + return super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch(item.getItemId()) { + case R.id.menu_toggle_log: + mLogShown = !mLogShown; + ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output); + if (mLogShown) { + output.setDisplayedChild(1); + } else { + output.setDisplayedChild(0); + } + supportInvalidateOptionsMenu(); + return true; + } + return super.onOptionsItemSelected(item); + } + + /** 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/MediaEffects/src/com.example.android.mediaeffects/MediaEffectsFragment.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MediaEffectsFragment.java new file mode 100644 index 000000000..5af16845f --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/MediaEffectsFragment.java @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2014 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.mediaeffects; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; +import android.opengl.GLES20; +import android.opengl.GLSurfaceView; +import android.opengl.GLUtils; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +public class MediaEffectsFragment extends Fragment implements GLSurfaceView.Renderer { + + private static final String STATE_CURRENT_EFFECT = "current_effect"; + + private GLSurfaceView mEffectView; + private int[] mTextures = new int[2]; + private EffectContext mEffectContext; + private Effect mEffect; + private TextureRenderer mTexRenderer = new TextureRenderer(); + private int mImageWidth; + private int mImageHeight; + private boolean mInitialized = false; + private int mCurrentEffect; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_media_effects, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + mEffectView = (GLSurfaceView) view.findViewById(R.id.effectsview); + mEffectView.setEGLContextClientVersion(2); + mEffectView.setRenderer(this); + mEffectView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); + if (null != savedInstanceState && savedInstanceState.containsKey(STATE_CURRENT_EFFECT)) { + setCurrentEffect(savedInstanceState.getInt(STATE_CURRENT_EFFECT)); + } else { + setCurrentEffect(R.id.none); + } + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.media_effects, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + setCurrentEffect(item.getItemId()); + mEffectView.requestRender(); + return true; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putInt(STATE_CURRENT_EFFECT, mCurrentEffect); + } + + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) { + // Nothing to do here + } + + @Override + public void onSurfaceChanged(GL10 gl, int width, int height) { + if (mTexRenderer != null) { + mTexRenderer.updateViewSize(width, height); + } + } + + @Override + public void onDrawFrame(GL10 gl) { + if (!mInitialized) { + //Only need to do this once + mEffectContext = EffectContext.createWithCurrentGlContext(); + mTexRenderer.init(); + loadTextures(); + mInitialized = true; + } + if (mCurrentEffect != R.id.none) { + //if an effect is chosen initialize it and apply it to the texture + initEffect(); + applyEffect(); + } + renderResult(); + } + + private void setCurrentEffect(int effect) { + mCurrentEffect = effect; + } + + private void loadTextures() { + // Generate textures + GLES20.glGenTextures(2, mTextures, 0); + + // Load input bitmap + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.puppy); + mImageWidth = bitmap.getWidth(); + mImageHeight = bitmap.getHeight(); + mTexRenderer.updateTextureSize(mImageWidth, mImageHeight); + + // Upload to texture + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]); + GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); + + // Set texture parameters + GLToolbox.initTexParams(); + } + + private void initEffect() { + EffectFactory effectFactory = mEffectContext.getFactory(); + if (mEffect != null) { + mEffect.release(); + } + // Initialize the correct effect based on the selected menu/action item + switch (mCurrentEffect) { + + case R.id.none: + break; + + case R.id.autofix: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_AUTOFIX); + mEffect.setParameter("scale", 0.5f); + break; + + case R.id.bw: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BLACKWHITE); + mEffect.setParameter("black", .1f); + mEffect.setParameter("white", .7f); + break; + + case R.id.brightness: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BRIGHTNESS); + mEffect.setParameter("brightness", 2.0f); + break; + + case R.id.contrast: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CONTRAST); + mEffect.setParameter("contrast", 1.4f); + break; + + case R.id.crossprocess: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CROSSPROCESS); + break; + + case R.id.documentary: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DOCUMENTARY); + break; + + case R.id.duotone: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DUOTONE); + mEffect.setParameter("first_color", Color.YELLOW); + mEffect.setParameter("second_color", Color.DKGRAY); + break; + + case R.id.filllight: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FILLLIGHT); + mEffect.setParameter("strength", .8f); + break; + + case R.id.fisheye: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FISHEYE); + mEffect.setParameter("scale", .5f); + break; + + case R.id.flipvert: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP); + mEffect.setParameter("vertical", true); + break; + + case R.id.fliphor: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP); + mEffect.setParameter("horizontal", true); + break; + + case R.id.grain: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAIN); + mEffect.setParameter("strength", 1.0f); + break; + + case R.id.grayscale: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAYSCALE); + break; + + case R.id.lomoish: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_LOMOISH); + break; + + case R.id.negative: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_NEGATIVE); + break; + + case R.id.posterize: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_POSTERIZE); + break; + + case R.id.rotate: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_ROTATE); + mEffect.setParameter("angle", 180); + break; + + case R.id.saturate: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SATURATE); + mEffect.setParameter("scale", .5f); + break; + + case R.id.sepia: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SEPIA); + break; + + case R.id.sharpen: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SHARPEN); + break; + + case R.id.temperature: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TEMPERATURE); + mEffect.setParameter("scale", .9f); + break; + + case R.id.tint: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT); + mEffect.setParameter("tint", Color.MAGENTA); + break; + + case R.id.vignette: + mEffect = effectFactory.createEffect(EffectFactory.EFFECT_VIGNETTE); + mEffect.setParameter("scale", .5f); + break; + + default: + break; + } + } + + private void applyEffect() { + mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]); + } + + private void renderResult() { + if (mCurrentEffect != R.id.none) { + // if no effect is chosen, just render the original bitmap + mTexRenderer.renderTexture(mTextures[1]); + } else { + // render the result of applyEffect() + mTexRenderer.renderTexture(mTextures[0]); + } + } + +} diff --git a/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/TextureRenderer.java b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/TextureRenderer.java new file mode 100644 index 000000000..9c77927d2 --- /dev/null +++ b/samples/browseable/MediaEffects/src/com.example.android.mediaeffects/TextureRenderer.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2014 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.mediaeffects; + +import android.opengl.GLES20; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +public class TextureRenderer { + + private int mProgram; + private int mTexSamplerHandle; + private int mTexCoordHandle; + private int mPosCoordHandle; + + private FloatBuffer mTexVertices; + private FloatBuffer mPosVertices; + + private int mViewWidth; + private int mViewHeight; + + private int mTexWidth; + private int mTexHeight; + + private static final String VERTEX_SHADER = + "attribute vec4 a_position;\n" + + "attribute vec2 a_texcoord;\n" + + "varying vec2 v_texcoord;\n" + + "void main() {\n" + + " gl_Position = a_position;\n" + + " v_texcoord = a_texcoord;\n" + + "}\n"; + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "void main() {\n" + + " gl_FragColor = texture2D(tex_sampler, v_texcoord);\n" + + "}\n"; + + private static final float[] TEX_VERTICES = { + 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f + }; + + private static final float[] POS_VERTICES = { + -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f + }; + + private static final int FLOAT_SIZE_BYTES = 4; + + public void init() { + // Create program + mProgram = GLToolbox.createProgram(VERTEX_SHADER, FRAGMENT_SHADER); + + // Bind attributes and uniforms + mTexSamplerHandle = GLES20.glGetUniformLocation(mProgram, + "tex_sampler"); + mTexCoordHandle = GLES20.glGetAttribLocation(mProgram, "a_texcoord"); + mPosCoordHandle = GLES20.glGetAttribLocation(mProgram, "a_position"); + + // Setup coordinate buffers + mTexVertices = ByteBuffer.allocateDirect( + TEX_VERTICES.length * FLOAT_SIZE_BYTES) + .order(ByteOrder.nativeOrder()).asFloatBuffer(); + mTexVertices.put(TEX_VERTICES).position(0); + mPosVertices = ByteBuffer.allocateDirect( + POS_VERTICES.length * FLOAT_SIZE_BYTES) + .order(ByteOrder.nativeOrder()).asFloatBuffer(); + mPosVertices.put(POS_VERTICES).position(0); + } + + public void tearDown() { + GLES20.glDeleteProgram(mProgram); + } + + public void updateTextureSize(int texWidth, int texHeight) { + mTexWidth = texWidth; + mTexHeight = texHeight; + computeOutputVertices(); + } + + public void updateViewSize(int viewWidth, int viewHeight) { + mViewWidth = viewWidth; + mViewHeight = viewHeight; + computeOutputVertices(); + } + + public void renderTexture(int texId) { + // Bind default FBO + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); + + // Use our shader program + GLES20.glUseProgram(mProgram); + GLToolbox.checkGlError("glUseProgram"); + + // Set viewport + GLES20.glViewport(0, 0, mViewWidth, mViewHeight); + GLToolbox.checkGlError("glViewport"); + + // Disable blending + GLES20.glDisable(GLES20.GL_BLEND); + + // Set the vertex attributes + GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT, false, + 0, mTexVertices); + GLES20.glEnableVertexAttribArray(mTexCoordHandle); + GLES20.glVertexAttribPointer(mPosCoordHandle, 2, GLES20.GL_FLOAT, false, + 0, mPosVertices); + GLES20.glEnableVertexAttribArray(mPosCoordHandle); + GLToolbox.checkGlError("vertex attribute setup"); + + // Set the input texture + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + GLToolbox.checkGlError("glActiveTexture"); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId); + GLToolbox.checkGlError("glBindTexture"); + GLES20.glUniform1i(mTexSamplerHandle, 0); + + // Draw + GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); + GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); + } + + private void computeOutputVertices() { + if (mPosVertices != null) { + float imgAspectRatio = mTexWidth / (float)mTexHeight; + float viewAspectRatio = mViewWidth / (float)mViewHeight; + float relativeAspectRatio = viewAspectRatio / imgAspectRatio; + float x0, y0, x1, y1; + if (relativeAspectRatio > 1.0f) { + x0 = -1.0f / relativeAspectRatio; + y0 = -1.0f; + x1 = 1.0f / relativeAspectRatio; + y1 = 1.0f; + } else { + x0 = -1.0f; + y0 = -relativeAspectRatio; + x1 = 1.0f; + y1 = relativeAspectRatio; + } + float[] coords = new float[] { x0, y0, x1, y0, x0, y1, x1, y1 }; + mPosVertices.put(coords).position(0); + } + } + +} diff --git a/samples/browseable/MediaRecorder/AndroidManifest.xml b/samples/browseable/MediaRecorder/AndroidManifest.xml index 32f88f64f..539dc2c3d 100644 --- a/samples/browseable/MediaRecorder/AndroidManifest.xml +++ b/samples/browseable/MediaRecorder/AndroidManifest.xml @@ -22,9 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="14" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <!-- This app records A/V content from camera and stores it to disk --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> diff --git a/samples/browseable/MediaRecorder/_index.jd b/samples/browseable/MediaRecorder/_index.jd index dac835aa8..28c55901f 100644 --- a/samples/browseable/MediaRecorder/_index.jd +++ b/samples/browseable/MediaRecorder/_index.jd @@ -2,6 +2,10 @@ page.tags="MediaRecorder" sample.group=Media @jd:body -<p>This sample demonstrates how to use the {@link android.media.MediaRecorder} -API to record video from a camera or camcorder, and display a preview of the -recording.</p> +<p> + + This sample uses the camera/camcorder as the A/V source for the MediaRecorder API. + A TextureView is used as the camera preview which limits the code to API 14+. This + can be easily replaced with a SurfaceView to run on older devices. + + </p> diff --git a/samples/browseable/MediaRecorder/res/values-v21/template-styles.xml b/samples/browseable/MediaRecorder/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/MediaRecorder/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/MediaRecorder/res/values/base-strings.xml b/samples/browseable/MediaRecorder/res/values/base-strings.xml index f9ade8c45..3e2b6baae 100644 --- a/samples/browseable/MediaRecorder/res/values/base-strings.xml +++ b/samples/browseable/MediaRecorder/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">MediaRecorder</string> <string name="intro_message"> diff --git a/samples/browseable/MediaRecorder/src/com.example.android.common.media/MediaCodecWrapper.java b/samples/browseable/MediaRecorder/src/com.example.android.common.media/MediaCodecWrapper.java index a511221f5..a48337404 100644 --- a/samples/browseable/MediaRecorder/src/com.example.android.common.media/MediaCodecWrapper.java +++ b/samples/browseable/MediaRecorder/src/com.example.android.common.media/MediaCodecWrapper.java @@ -21,6 +21,7 @@ import android.os.Handler; import android.os.Looper; import android.view.Surface; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayDeque; import java.util.Queue; @@ -136,7 +137,7 @@ public class MediaCodecWrapper { * @return */ public static MediaCodecWrapper fromVideoFormat(final MediaFormat trackFormat, - Surface surface) { + Surface surface) throws IOException { MediaCodecWrapper result = null; MediaCodec videoCodec = null; diff --git a/samples/browseable/MediaRouter/AndroidManifest.xml b/samples/browseable/MediaRouter/AndroidManifest.xml index 0b5bec450..18057497c 100644 --- a/samples/browseable/MediaRouter/AndroidManifest.xml +++ b/samples/browseable/MediaRouter/AndroidManifest.xml @@ -28,9 +28,8 @@ remote display using system alert window. --> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> - <uses-sdk android:targetSdkVersion="19" - android:minSdkVersion="7"/> - + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> + <!-- The smallest screen this app works on is a phone. The app will scale its UI to larger screens but doesn't make good use of them so allow the compatibility mode button to be shown (mostly because diff --git a/samples/browseable/MediaRouter/_index.jd b/samples/browseable/MediaRouter/_index.jd index 5ca94679e..66ac11357 100644 --- a/samples/browseable/MediaRouter/_index.jd +++ b/samples/browseable/MediaRouter/_index.jd @@ -1,10 +1,7 @@ - - - page.tags="MediaRouter" sample.group=Media @jd:body <p> -This sample demonstrates how to create a custom media route provider. -</p>
\ No newline at end of file + Demonstrates how to create a custom media route provider. + </p> diff --git a/samples/browseable/MediaRouter/res/values-v21/template-styles.xml b/samples/browseable/MediaRouter/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/MediaRouter/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/MediaRouter/res/values/base-strings.xml b/samples/browseable/MediaRouter/res/values/base-strings.xml index 8b494cc82..667c735f3 100644 --- a/samples/browseable/MediaRouter/res/values/base-strings.xml +++ b/samples/browseable/MediaRouter/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">MediaRouter</string> <string name="intro_message"> diff --git a/samples/browseable/MessagingService/AndroidManifest.xml b/samples/browseable/MessagingService/AndroidManifest.xml new file mode 100644 index 000000000..f8a5850d1 --- /dev/null +++ b/samples/browseable/MessagingService/AndroidManifest.xml @@ -0,0 +1,52 @@ +<!-- + Copyright (C) 2014 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.messagingservice"> + + <application android:allowBackup="true" + android:label="@string/app_name" + android:icon="@drawable/ic_launcher" + android:theme="@style/AppTheme"> + + <meta-data android:name="com.google.android.gms.car.application" + android:resource="@xml/automotive_app_desc"/> + + <activity + android:name=".MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <service android:name=".MessagingService"> + </service> + + <receiver android:name=".MessageReadReceiver"> + <intent-filter> + <action android:name="com.example.android.messagingservice.ACTION_MESSAGE_READ"/> + </intent-filter> + </receiver> + + <receiver android:name=".MessageReplyReceiver"> + <intent-filter> + <action android:name="com.example.android.messagingservice.ACTION_MESSAGE_REPLY"/> + </intent-filter> + </receiver> + </application> +</manifest> diff --git a/samples/browseable/MessagingService/_index.jd b/samples/browseable/MessagingService/_index.jd new file mode 100644 index 000000000..ceaba3440 --- /dev/null +++ b/samples/browseable/MessagingService/_index.jd @@ -0,0 +1,12 @@ +page.tags="MessagingService" +sample.group=Notification +@jd:body + +<p> + +This sample shows a simple service that sends notifications using +NotificationCompat. In addition to sending a notification, it also extends +the notification with a CarExtender to make it compatible with Android Auto. +Each unread conversation from a user is sent as a distinct notification. + + </p> diff --git a/samples/browseable/MessagingService/res/drawable-hdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-hdpi/android_contact.png Binary files differnew file mode 100644 index 000000000..00d0ec43a --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-hdpi/android_contact.png diff --git a/samples/browseable/MessagingService/res/drawable-hdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..06d85f166 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-hdpi/ic_launcher.png diff --git a/samples/browseable/MessagingService/res/drawable-hdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-hdpi/notification_icon.png Binary files differnew file mode 100644 index 000000000..9cdfca1e5 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-hdpi/notification_icon.png diff --git a/samples/browseable/MessagingService/res/drawable-mdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-mdpi/android_contact.png Binary files differnew file mode 100644 index 000000000..771cb6bb8 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-mdpi/android_contact.png diff --git a/samples/browseable/MessagingService/res/drawable-mdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..4e1cc86b4 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-mdpi/ic_launcher.png diff --git a/samples/browseable/MessagingService/res/drawable-mdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-mdpi/notification_icon.png Binary files differnew file mode 100644 index 000000000..d6069ebc9 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-mdpi/notification_icon.png diff --git a/samples/browseable/MessagingService/res/drawable-xhdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-xhdpi/android_contact.png Binary files differnew file mode 100644 index 000000000..bdba57b6b --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-xhdpi/android_contact.png diff --git a/samples/browseable/MessagingService/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..92f1e2ddd --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-xhdpi/ic_launcher.png diff --git a/samples/browseable/MessagingService/res/drawable-xhdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-xhdpi/notification_icon.png Binary files differnew file mode 100644 index 000000000..786ed17b7 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-xhdpi/notification_icon.png diff --git a/samples/browseable/MessagingService/res/drawable-xxhdpi/android_contact.png b/samples/browseable/MessagingService/res/drawable-xxhdpi/android_contact.png Binary files differnew file mode 100644 index 000000000..b36ec1730 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-xxhdpi/android_contact.png diff --git a/samples/browseable/MessagingService/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/MessagingService/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..2476cbddd --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-xxhdpi/ic_launcher.png diff --git a/samples/browseable/MessagingService/res/drawable-xxhdpi/notification_icon.png b/samples/browseable/MessagingService/res/drawable-xxhdpi/notification_icon.png Binary files differnew file mode 100644 index 000000000..005207cc0 --- /dev/null +++ b/samples/browseable/MessagingService/res/drawable-xxhdpi/notification_icon.png diff --git a/samples/browseable/MessagingService/res/layout-land/fragment_message_me.xml b/samples/browseable/MessagingService/res/layout-land/fragment_message_me.xml new file mode 100644 index 000000000..8f7b60a23 --- /dev/null +++ b/samples/browseable/MessagingService/res/layout-land/fragment_message_me.xml @@ -0,0 +1,67 @@ +<!-- + Copyright (C) 2014 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:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:orientation="horizontal" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin"> + <LinearLayout + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + <Button + android:id="@+id/send_1_conversation" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/send_1_conversation"/> + + <Button + android:id="@+id/send_2_conversations" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/send_2_conversations"/> + + <Button + android:id="@+id/send_1_conversation_3_messages" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/send_1_conv_3_messages"/> + </LinearLayout> + <RelativeLayout + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="2"> + <Button + android:id="@+id/clear" + android:layout_alignParentBottom="true" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/clear_log"/> + + <TextView + android:id="@+id/data_port" + android:layout_above="@id/clear" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:maxLines="20" + android:scrollbars="vertical"/> + </RelativeLayout> +</LinearLayout> diff --git a/samples/browseable/MessagingService/res/layout/activity_main.xml b/samples/browseable/MessagingService/res/layout/activity_main.xml new file mode 100644 index 000000000..59eec805e --- /dev/null +++ b/samples/browseable/MessagingService/res/layout/activity_main.xml @@ -0,0 +1,22 @@ +<!-- + Copyright (C) 2014 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. + --> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/container" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MainActivity" + tools:ignore="MergeRootFrame" /> diff --git a/samples/browseable/MessagingService/res/layout/fragment_message_me.xml b/samples/browseable/MessagingService/res/layout/fragment_message_me.xml new file mode 100644 index 000000000..d01c5137a --- /dev/null +++ b/samples/browseable/MessagingService/res/layout/fragment_message_me.xml @@ -0,0 +1,58 @@ +<!-- + Copyright (C) 2014 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" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:gravity="center_horizontal" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin"> + + <Button + android:id="@+id/send_1_conversation" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/send_1_conversation"/> + + <Button + android:id="@+id/send_2_conversations" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/send_2_conversations"/> + + <Button + android:id="@+id/send_1_conversation_3_messages" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/send_1_conv_3_messages"/> + + <TextView + android:id="@+id/data_port" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:maxLines="20" + android:scrollbars="vertical"/> + <Button + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/clear" + android:text="@string/clear_log"/> + +</LinearLayout> diff --git a/samples/browseable/MessagingService/res/values-v21/styles.xml b/samples/browseable/MessagingService/res/values-v21/styles.xml new file mode 100644 index 000000000..f30c97a7a --- /dev/null +++ b/samples/browseable/MessagingService/res/values-v21/styles.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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="AppTheme" parent="android:Theme.Material.Light"> + <item name="android:colorPrimary">@color/default_color_light</item> + <item name="android:colorPrimaryDark">@color/default_color_dark</item> + </style> +</resources> diff --git a/samples/browseable/MessagingService/res/values/colors.xml b/samples/browseable/MessagingService/res/values/colors.xml new file mode 100644 index 000000000..0e6825b0e --- /dev/null +++ b/samples/browseable/MessagingService/res/values/colors.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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> + <color name="default_color_light">#ff4092c3</color> + <color name="default_color_dark">#ff241c99</color> +</resources> diff --git a/samples/browseable/MessagingService/res/values/dimens.xml b/samples/browseable/MessagingService/res/values/dimens.xml new file mode 100644 index 000000000..574a35d20 --- /dev/null +++ b/samples/browseable/MessagingService/res/values/dimens.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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> + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> +</resources> diff --git a/samples/browseable/MessagingService/res/values/strings.xml b/samples/browseable/MessagingService/res/values/strings.xml new file mode 100644 index 000000000..001b10eed --- /dev/null +++ b/samples/browseable/MessagingService/res/values/strings.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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">Messaging Sample</string> + <string name="action_settings">Settings</string> + <string name="title">Messaging Sample</string> + <string name="notification_reply">Reply by Voice</string> + <string name="send_2_conversations">Send 2 conversations with 1 message</string> + <string name="send_1_conversation">Send 1 conversation with 1 message</string> + <string name="send_1_conv_3_messages">Send 1 conversation with 3 messages</string> + <string name="clear_log">Clear Log</string> +</resources> diff --git a/samples/browseable/MessagingService/res/values/styles.xml b/samples/browseable/MessagingService/res/values/styles.xml new file mode 100644 index 000000000..3f1a6af88 --- /dev/null +++ b/samples/browseable/MessagingService/res/values/styles.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> + </style> +</resources> diff --git a/samples/browseable/MessagingService/res/xml/automotive_app_desc.xml b/samples/browseable/MessagingService/res/xml/automotive_app_desc.xml new file mode 100644 index 000000000..9e9f1741f --- /dev/null +++ b/samples/browseable/MessagingService/res/xml/automotive_app_desc.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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. + --> +<automotiveApp> + <uses name="notification"/> +</automotiveApp> diff --git a/samples/browseable/MessagingService/src/com.example.android.messagingservice/Conversations.java b/samples/browseable/MessagingService/src/com.example.android.messagingservice/Conversations.java new file mode 100644 index 000000000..210e061f0 --- /dev/null +++ b/samples/browseable/MessagingService/src/com.example.android.messagingservice/Conversations.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2014 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.messagingservice; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +/** + * A simple class that denotes unread conversations and messages. In a real world application, + * this would be replaced by a content provider that actually gets the unread messages to be + * shown to the user. + */ +public class Conversations { + + /** + * Set of strings used as messages by the sample. + */ + private static final String[] MESSAGES = new String[]{ + "Are you at home?", + "Can you give me a call?", + "Hey yt?", + "Don't forget to get some milk on your way back home", + "Is that project done?", + "Did you finish the Messaging app yet?" + }; + + /** + * Senders of the said messages. + */ + private static final String[] PARTICIPANTS = new String[]{ + "John Rambo", + "Han Solo", + "Rocky Balboa", + "Lara Croft" + }; + + static class Conversation { + + private final int conversationId; + + private final String participantName; + + /** + * A given conversation can have a single or multiple messages. + * Note that the messages are sorted from *newest* to *oldest* + */ + private final List<String> messages; + + private final long timestamp; + + public Conversation(int conversationId, String participantName, + List<String> messages) { + this.conversationId = conversationId; + this.participantName = participantName; + this.messages = messages == null ? Collections.<String>emptyList() : messages; + this.timestamp = System.currentTimeMillis(); + } + + public int getConversationId() { + return conversationId; + } + + public String getParticipantName() { + return participantName; + } + + public List<String> getMessages() { + return messages; + } + + public long getTimestamp() { + return timestamp; + } + + public String toString() { + return "[Conversation: conversationId=" + conversationId + + ", participantName=" + participantName + + ", messages=" + messages + + ", timestamp=" + timestamp + "]"; + } + } + + private Conversations() { + } + + public static Conversation[] getUnreadConversations(int howManyConversations, + int messagesPerConversation) { + Conversation[] conversations = new Conversation[howManyConversations]; + for (int i = 0; i < howManyConversations; i++) { + conversations[i] = new Conversation( + ThreadLocalRandom.current().nextInt(), + name(), makeMessages(messagesPerConversation)); + } + return conversations; + } + + private static List<String> makeMessages(int messagesPerConversation) { + int maxLen = MESSAGES.length; + List<String> messages = new ArrayList<>(messagesPerConversation); + for (int i = 0; i < messagesPerConversation; i++) { + messages.add(MESSAGES[ThreadLocalRandom.current().nextInt(0, maxLen)]); + } + return messages; + } + + private static String name() { + return PARTICIPANTS[ThreadLocalRandom.current().nextInt(0, PARTICIPANTS.length)]; + } +} diff --git a/samples/browseable/MessagingService/src/com.example.android.messagingservice/MainActivity.java b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MainActivity.java new file mode 100644 index 000000000..e558a64a8 --- /dev/null +++ b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MainActivity.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014 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.messagingservice; + +import android.app.Activity; +import android.os.Bundle; + +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + if (savedInstanceState == null) { + getFragmentManager().beginTransaction() + .add(R.id.container, new MessagingFragment()) + .commit(); + } + } +} diff --git a/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageLogger.java b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageLogger.java new file mode 100644 index 000000000..d1007b5ad --- /dev/null +++ b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageLogger.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 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.messagingservice; + +import android.content.Context; +import android.content.SharedPreferences; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * A simple logger that uses shared preferences to log messages, their reads + * and replies. Don't use this in a real world application. This logger is only + * used for displaying the messages in the text view. + */ +public class MessageLogger { + + private static final String PREF_MESSAGE = "MESSAGE_LOGGER"; + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + public static final String LOG_KEY = "message_data"; + public static final String LINE_BREAKS = "\n\n"; + + public static void logMessage(Context context, String message) { + SharedPreferences prefs = getPrefs(context); + message = DATE_FORMAT.format(new Date(System.currentTimeMillis())) + ": " + message; + prefs.edit() + .putString(LOG_KEY, prefs.getString(LOG_KEY, "") + LINE_BREAKS + message) + .apply(); + } + + public static SharedPreferences getPrefs(Context context) { + return context.getSharedPreferences(PREF_MESSAGE, Context.MODE_PRIVATE); + } + + public static String getAllMessages(Context context) { + return getPrefs(context).getString(LOG_KEY, ""); + } + + public static void clear(Context context) { + getPrefs(context).edit().remove(LOG_KEY).apply(); + } +} diff --git a/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageReadReceiver.java b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageReadReceiver.java new file mode 100644 index 000000000..f28a3a778 --- /dev/null +++ b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageReadReceiver.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 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.messagingservice; + +import android.app.NotificationManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.NotificationManagerCompat; +import android.util.Log; + +public class MessageReadReceiver extends BroadcastReceiver { + private static final String TAG = MessageReadReceiver.class.getSimpleName(); + + private static final String CONVERSATION_ID = "conversation_id"; + + @Override + public void onReceive(Context context, Intent intent) { + Log.d(TAG, "onReceive"); + int conversationId = intent.getIntExtra(CONVERSATION_ID, -1); + if (conversationId != -1) { + Log.d(TAG, "Conversation " + conversationId + " was read"); + MessageLogger.logMessage(context, "Conversation " + conversationId + " was read."); + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + notificationManager.cancel(conversationId); + } + } +} diff --git a/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageReplyReceiver.java b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageReplyReceiver.java new file mode 100644 index 000000000..0a3eba692 --- /dev/null +++ b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessageReplyReceiver.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014 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.messagingservice; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.RemoteInput; +import android.util.Log; + +/** + * A receiver that gets called when a reply is sent to a given conversationId + */ +public class MessageReplyReceiver extends BroadcastReceiver { + + private static final String TAG = MessageReplyReceiver.class.getSimpleName(); + + @Override + public void onReceive(Context context, Intent intent) { + if (MessagingService.REPLY_ACTION.equals(intent.getAction())) { + int conversationId = intent.getIntExtra(MessagingService.CONVERSATION_ID, -1); + CharSequence reply = getMessageText(intent); + if (conversationId != -1) { + Log.d(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId); + MessageLogger.logMessage(context, "ConversationId: " + conversationId + + " received a reply: [" + reply + "]"); + } + } + } + + /** + * Get the message text from the intent. + * Note that you should call {@code RemoteInput#getResultsFromIntent(intent)} to process + * the RemoteInput. + */ + private CharSequence getMessageText(Intent intent) { + Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); + if (remoteInput != null) { + return remoteInput.getCharSequence(MessagingService.EXTRA_VOICE_REPLY); + } + return null; + } +} diff --git a/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessagingFragment.java b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessagingFragment.java new file mode 100644 index 000000000..f8efcc0c7 --- /dev/null +++ b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessagingFragment.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2014 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.messagingservice; + +import android.app.Fragment; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.IBinder; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import android.text.method.ScrollingMovementMethod; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +/** + * The main fragment that shows the buttons and the text view containing the log. + */ +public class MessagingFragment extends Fragment implements View.OnClickListener { + + private static final String TAG = MessagingFragment.class.getSimpleName(); + + private Button mSendSingleConversation; + private Button mSendTwoConversations; + private Button mSendConversationWithThreeMessages; + private TextView mDataPortView; + private Button mClearLogButton; + + private Messenger mService; + private boolean mBound; + + private ServiceConnection mConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName componentName, IBinder service) { + mService = new Messenger(service); + mBound = true; + setButtonsState(true); + } + + @Override + public void onServiceDisconnected(ComponentName componentName) { + mService = null; + mBound = false; + setButtonsState(false); + } + }; + + private SharedPreferences.OnSharedPreferenceChangeListener listener = + new SharedPreferences.OnSharedPreferenceChangeListener() { + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (MessageLogger.LOG_KEY.equals(key)) { + mDataPortView.setText(MessageLogger.getAllMessages(getActivity())); + } + } + }; + + public MessagingFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_message_me, container, false); + + mSendSingleConversation = (Button) rootView.findViewById(R.id.send_1_conversation); + mSendSingleConversation.setOnClickListener(this); + + mSendTwoConversations = (Button) rootView.findViewById(R.id.send_2_conversations); + mSendTwoConversations.setOnClickListener(this); + + mSendConversationWithThreeMessages = + (Button) rootView.findViewById(R.id.send_1_conversation_3_messages); + mSendConversationWithThreeMessages.setOnClickListener(this); + + mDataPortView = (TextView) rootView.findViewById(R.id.data_port); + mDataPortView.setMovementMethod(new ScrollingMovementMethod()); + + mClearLogButton = (Button) rootView.findViewById(R.id.clear); + mClearLogButton.setOnClickListener(this); + + setButtonsState(false); + + return rootView; + } + + @Override + public void onClick(View view) { + if (view == mSendSingleConversation) { + sendMsg(1, 1); + } else if (view == mSendTwoConversations) { + sendMsg(2, 1); + } else if (view == mSendConversationWithThreeMessages) { + sendMsg(1, 3); + } else if (view == mClearLogButton) { + MessageLogger.clear(getActivity()); + mDataPortView.setText(MessageLogger.getAllMessages(getActivity())); + } + } + + @Override + public void onStart() { + super.onStart(); + getActivity().bindService(new Intent(getActivity(), MessagingService.class), mConnection, + Context.BIND_AUTO_CREATE); + } + + @Override + public void onPause() { + super.onPause(); + MessageLogger.getPrefs(getActivity()).unregisterOnSharedPreferenceChangeListener(listener); + } + + @Override + public void onResume() { + super.onResume(); + mDataPortView.setText(MessageLogger.getAllMessages(getActivity())); + MessageLogger.getPrefs(getActivity()).registerOnSharedPreferenceChangeListener(listener); + } + + @Override + public void onStop() { + super.onStop(); + if (mBound) { + getActivity().unbindService(mConnection); + mBound = false; + } + } + + private void sendMsg(int howManyConversations, int messagesPerConversation) { + if (mBound) { + Message msg = Message.obtain(null, MessagingService.MSG_SEND_NOTIFICATION, + howManyConversations, messagesPerConversation); + try { + mService.send(msg); + } catch (RemoteException e) { + Log.e(TAG, "Error sending a message", e); + MessageLogger.logMessage(getActivity(), "Error occurred while sending a message."); + } + } + } + + private void setButtonsState(boolean enable) { + mSendSingleConversation.setEnabled(enable); + mSendTwoConversations.setEnabled(enable); + mSendConversationWithThreeMessages.setEnabled(enable); + } +} diff --git a/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessagingService.java b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessagingService.java new file mode 100644 index 000000000..f980375d5 --- /dev/null +++ b/samples/browseable/MessagingService/src/com.example.android.messagingservice/MessagingService.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2014 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.messagingservice; + +import android.app.PendingIntent; +import android.app.Service; +import android.content.Intent; +import android.graphics.BitmapFactory; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.os.Messenger; +import android.preview.support.v4.app.NotificationCompat.CarExtender; +import android.preview.support.v4.app.NotificationCompat.CarExtender.UnreadConversation; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationManagerCompat; +import android.support.v4.app.RemoteInput; +import android.util.Log; + +import java.util.Iterator; + +public class MessagingService extends Service { + private static final String TAG = MessagingService.class.getSimpleName(); + + public static final String READ_ACTION = + "com.example.android.messagingservice.ACTION_MESSAGE_READ"; + public static final String REPLY_ACTION = + "com.example.android.messagingservice.ACTION_MESSAGE_REPLY"; + public static final String CONVERSATION_ID = "conversation_id"; + public static final String EXTRA_VOICE_REPLY = "extra_voice_reply"; + public static final int MSG_SEND_NOTIFICATION = 1; + public static final String EOL = "\n"; + + private NotificationManagerCompat mNotificationManager; + + private final Messenger mMessenger = new Messenger(new IncomingHandler()); + + /** + * Handler of incoming messages from clients. + */ + class IncomingHandler extends Handler { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_SEND_NOTIFICATION: + int howManyConversations = msg.arg1 <= 0 ? 1 : msg.arg1; + int messagesPerConv = msg.arg2 <= 0 ? 1 : msg.arg2; + sendNotification(howManyConversations, messagesPerConv); + break; + default: + super.handleMessage(msg); + } + } + } + + @Override + public void onCreate() { + Log.d(TAG, "onCreate"); + mNotificationManager = NotificationManagerCompat.from(getApplicationContext()); + } + + @Override + public IBinder onBind(Intent intent) { + Log.d(TAG, "onBind"); + return mMessenger.getBinder(); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.d(TAG, "onStartCommand"); + return START_STICKY; + } + + @Override + public void onDestroy() { + super.onDestroy(); + Log.d(TAG, "onDestroy"); + } + + // Creates an intent that will be triggered when a message is marked as read. + private Intent getMessageReadIntent(int id) { + return new Intent() + .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) + .setAction(READ_ACTION) + .putExtra(CONVERSATION_ID, id); + } + + // Creates an Intent that will be triggered when a voice reply is received. + private Intent getMessageReplyIntent(int conversationId) { + return new Intent() + .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) + .setAction(REPLY_ACTION) + .putExtra(CONVERSATION_ID, conversationId); + } + + private void sendNotification(int howManyConversations, int messagesPerConversation) { + Conversations.Conversation[] conversations = Conversations.getUnreadConversations( + howManyConversations, messagesPerConversation); + for (Conversations.Conversation conv : conversations) { + sendNotificationForConversation(conv); + } + } + + private void sendNotificationForConversation(Conversations.Conversation conversation) { + // A pending Intent for reads + PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), + conversation.getConversationId(), + getMessageReadIntent(conversation.getConversationId()), + PendingIntent.FLAG_UPDATE_CURRENT); + + // Build a RemoteInput for receiving voice input in a Car Notification + RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) + .setLabel(getApplicationContext().getString(R.string.notification_reply)) + .build(); + + // Building a Pending Intent for the reply action to trigger + PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), + conversation.getConversationId(), + getMessageReplyIntent(conversation.getConversationId()), + PendingIntent.FLAG_UPDATE_CURRENT); + + // Create the UnreadConversation and populate it with the participant name, + // read and reply intents. + UnreadConversation.Builder unreadConvBuilder = + new UnreadConversation.Builder(conversation.getParticipantName()) + .setLatestTimestamp(conversation.getTimestamp()) + .setReadPendingIntent(readPendingIntent) + .setReplyAction(replyIntent, remoteInput); + + // Note: Add messages from oldest to newest to the UnreadConversation.Builder + StringBuilder messageForNotification = new StringBuilder(); + for (Iterator<String> messages = conversation.getMessages().iterator(); + messages.hasNext(); ) { + String message = messages.next(); + unreadConvBuilder.addMessage(message); + messageForNotification.append(message); + if (messages.hasNext()) { + messageForNotification.append(EOL); + } + } + + NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) + .setSmallIcon(R.drawable.notification_icon) + .setLargeIcon(BitmapFactory.decodeResource( + getApplicationContext().getResources(), R.drawable.android_contact)) + .setContentText(messageForNotification.toString()) + .setWhen(conversation.getTimestamp()) + .setContentTitle(conversation.getParticipantName()) + .setContentIntent(readPendingIntent) + .extend(new CarExtender() + .setUnreadConversation(unreadConvBuilder.build()) + .setColor(getApplicationContext() + .getResources().getColor(R.color.default_color_light))); + + MessageLogger.logMessage(getApplicationContext(), "Sending notification " + + conversation.getConversationId() + " conversation: " + conversation); + + mNotificationManager.notify(conversation.getConversationId(), builder.build()); + } +} diff --git a/samples/browseable/DataLayer/Shared/res/values/strings.xml b/samples/browseable/NavigationDrawer/res/values/template-attrs.xml index 0f2bb9075..442ed7781 100644 --- a/samples/browseable/DataLayer/Shared/res/values/strings.xml +++ b/samples/browseable/NavigationDrawer/res/values/template-attrs.xml @@ -1,18 +1,15 @@ <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2014 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">Shared</string> -</resources> +</resources>
\ No newline at end of file diff --git a/samples/browseable/NetworkConnect/AndroidManifest.xml b/samples/browseable/NetworkConnect/AndroidManifest.xml index 1ae29df9a..00ce7f3d0 100644 --- a/samples/browseable/NetworkConnect/AndroidManifest.xml +++ b/samples/browseable/NetworkConnect/AndroidManifest.xml @@ -23,7 +23,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> diff --git a/samples/browseable/NetworkConnect/_index.jd b/samples/browseable/NetworkConnect/_index.jd index eaac88496..7d67dd3dd 100644 --- a/samples/browseable/NetworkConnect/_index.jd +++ b/samples/browseable/NetworkConnect/_index.jd @@ -1,10 +1,10 @@ - - - page.tags="NetworkConnect" sample.group=Connectivity @jd:body -<p>This sample demonstrates how to connect to the network and fetch raw HTML. -The sample uses {@link android.os.AsyncTask} to perform the fetch on a -background thread.</p> +<p> + + This sample demonstrates how to connect to the network and fetch raw HTML using + HttpURLConnection. AsyncTask is used to perform the fetch on a background thread. + + </p> diff --git a/samples/browseable/NetworkConnect/res/values-v21/template-styles.xml b/samples/browseable/NetworkConnect/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/NetworkConnect/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/NetworkConnect/res/values/base-strings.xml b/samples/browseable/NetworkConnect/res/values/base-strings.xml index 0248814b8..75b3a8cb0 100644 --- a/samples/browseable/NetworkConnect/res/values/base-strings.xml +++ b/samples/browseable/NetworkConnect/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">NetworkConnect</string> <string name="intro_message"> diff --git a/samples/browseable/Notifications/Application/AndroidManifest.xml b/samples/browseable/Notifications/Application/AndroidManifest.xml index 005d7451b..a0ed72939 100644 --- a/samples/browseable/Notifications/Application/AndroidManifest.xml +++ b/samples/browseable/Notifications/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.notifications" > + package="com.example.android.support.wearable.notifications" > <uses-sdk android:minSdkVersion="19" @@ -40,9 +40,9 @@ <receiver android:name=".NotificationIntentReceiver" android:exported="false"> <intent-filter> - <action android:name="com.example.android.notifications.ACTION_EXAMPLE" /> - <action android:name="com.example.android.notifications.ACTION_ENABLE_MESSAGES" /> - <action android:name="com.example.android.notifications.ACTION_DISABLE_MESSAGES" /> + <action android:name="com.example.android.support.wearable.notifications.ACTION_EXAMPLE" /> + <action android:name="com.example.android.support.wearable.notifications.ACTION_ENABLE_MESSAGES" /> + <action android:name="com.example.android.support.wearable.notifications.ACTION_DISABLE_MESSAGES" /> </intent-filter> </receiver> diff --git a/samples/browseable/Notifications/Application/res/values-v21/template-styles.xml b/samples/browseable/Notifications/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/Notifications/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Notifications/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/Notifications/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/Notifications/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/Notifications/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/Notifications/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/ActionsPreset.java index 32be1a698..a550912df 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/ActionsPreset.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.content.Context; import android.support.v4.app.NotificationCompat; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/ActionsPresets.java index 2481ac8d3..ff639dcb9 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/ActionsPresets.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.content.Context; import android.support.v4.app.NotificationCompat; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/BackgroundPickers.java index 69263b25f..aedd548df 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/BackgroundPickers.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.content.Context; import android.content.res.Resources; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/MainActivity.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/MainActivity.java index 22b105975..c2be39539 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/MainActivity.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Activity; import android.app.Notification; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NamedPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NamedPreset.java index b97bcb9cb..afc5f169d 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NamedPreset.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NamedPreset.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; /** * Base class for presets that have a simple name to display. diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationIntentReceiver.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationIntentReceiver.java index 8dabb342a..39a1c7850 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationIntentReceiver.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationIntentReceiver.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.content.BroadcastReceiver; import android.content.Context; @@ -28,11 +28,11 @@ import android.widget.Toast; */ public class NotificationIntentReceiver extends BroadcastReceiver { public static final String ACTION_EXAMPLE = - "com.example.android.notifications.ACTION_EXAMPLE"; + "com.example.android.support.wearable.notifications.ACTION_EXAMPLE"; public static final String ACTION_ENABLE_MESSAGES = - "com.example.android.notifications.ACTION_ENABLE_MESSAGES"; + "com.example.android.support.wearable.notifications.ACTION_ENABLE_MESSAGES"; public static final String ACTION_DISABLE_MESSAGES = - "com.example.android.notifications.ACTION_DISABLE_MESSAGES"; + "com.example.android.support.wearable.notifications.ACTION_DISABLE_MESSAGES"; private boolean mEnableMessages = true; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationPreset.java index 3ab792be5..a0dff1874 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPreset.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationPreset.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Notification; import android.content.Context; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPresets.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationPresets.java index b6fe24aac..e175d1120 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPresets.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationPresets.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Notification; import android.content.Context; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationUtil.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationUtil.java index b5c43e501..389b90a5a 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationUtil.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/NotificationUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.PendingIntent; import android.content.Context; @@ -22,9 +22,9 @@ import android.content.Intent; public class NotificationUtil { public static final String EXTRA_MESSAGE = - "com.example.android.notifications.MESSAGE"; + "com.example.android.support.wearable.notifications.MESSAGE"; public static final String EXTRA_REPLY = - "com.example.android.notifications.REPLY"; + "com.example.android.support.wearable.notifications.REPLY"; public static PendingIntent getExamplePendingIntent(Context context, int messageResId) { Intent intent = new Intent(NotificationIntentReceiver.ACTION_EXAMPLE) diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/PriorityPreset.java index eaddb83f2..b4298fd30 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPreset.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/PriorityPreset.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.support.v4.app.NotificationCompat; diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPresets.java b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/PriorityPresets.java index 7d1ed7c0a..c33b59d7a 100644 --- a/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPresets.java +++ b/samples/browseable/Notifications/Application/src/com.example.android.support.wearable.notifications/PriorityPresets.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Notification; import android.support.v4.app.NotificationCompat; diff --git a/samples/browseable/Notifications/Shared/AndroidManifest.xml b/samples/browseable/Notifications/Shared/AndroidManifest.xml deleted file mode 100644 index 00541435e..000000000 --- a/samples/browseable/Notifications/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.notifications.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/Notifications/Shared/res/values/strings.xml b/samples/browseable/Notifications/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/Notifications/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/Notifications/Wearable/AndroidManifest.xml b/samples/browseable/Notifications/Wearable/AndroidManifest.xml index 99640f58f..57cd7c45d 100644 --- a/samples/browseable/Notifications/Wearable/AndroidManifest.xml +++ b/samples/browseable/Notifications/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.notifications" > + package="com.example.android.support.wearable.notifications" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/AnimatedNotificationDisplayActivity.java b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/AnimatedNotificationDisplayActivity.java index f14acef84..2e0b2eed4 100644 --- a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/AnimatedNotificationDisplayActivity.java +++ b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/AnimatedNotificationDisplayActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/BasicNotificationDisplayActivity.java b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/BasicNotificationDisplayActivity.java index a6cc5fbfb..d029f436b 100644 --- a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/BasicNotificationDisplayActivity.java +++ b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/BasicNotificationDisplayActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Activity; import android.os.Bundle; diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/MainActivity.java b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/MainActivity.java index fe7e1343a..d564e13a3 100644 --- a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/MainActivity.java +++ b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Activity; import android.app.Notification; diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPreset.java b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/NotificationPreset.java index db1546792..d6570d5ba 100644 --- a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPreset.java +++ b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/NotificationPreset.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Notification; import android.content.Context; diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPresets.java b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/NotificationPresets.java index 04a4d15d8..5578659e1 100644 --- a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPresets.java +++ b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/NotificationPresets.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.app.Notification; import android.app.PendingIntent; diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/WearableListItemLayout.java b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/WearableListItemLayout.java index cb08a9ce1..773dfe4cc 100644 --- a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/WearableListItemLayout.java +++ b/samples/browseable/Notifications/Wearable/src/com.example.android.support.wearable.notifications/WearableListItemLayout.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.notifications; +package com.example.android.support.wearable.notifications; import android.content.Context; import android.graphics.drawable.GradientDrawable; diff --git a/samples/browseable/DelayedConfirmation/Shared/AndroidManifest.xml b/samples/browseable/PdfRendererBasic/AndroidManifest.xml index 2c9b6698a..22870679a 100644 --- a/samples/browseable/DelayedConfirmation/Shared/AndroidManifest.xml +++ b/samples/browseable/PdfRendererBasic/AndroidManifest.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 2013 The Android Open Source Project + Copyright 2014 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. @@ -16,10 +16,23 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.delayedconfirmation.common"> + package="com.example.android.pdfrendererbasic" + android:versionCode="1" + android:versionName="1.0"> <application android:allowBackup="true" - android:label="@string/app_name"> + android:label="@string/app_name" + android:icon="@drawable/ic_launcher" + android:theme="@style/AppTheme"> + + <activity android:name=".MainActivity" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> </application> + </manifest> diff --git a/samples/browseable/PdfRendererBasic/_index.jd b/samples/browseable/PdfRendererBasic/_index.jd new file mode 100644 index 000000000..59c5a5309 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/_index.jd @@ -0,0 +1,9 @@ +page.tags="PdfRendererBasic" +sample.group=UI +@jd:body + +<p> + + This sample demonstrates how to use PdfRenderer to display PDF documents on the screen. + + </p> diff --git a/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_action_info.png Binary files differnew file mode 100644 index 000000000..32bd1aabc --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_action_info.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..0c9b69468 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/ic_launcher.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-hdpi/tile.9.png b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/tile.9.png Binary files differnew file mode 100644 index 000000000..135862883 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-hdpi/tile.9.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_action_info.png Binary files differnew file mode 100644 index 000000000..8efbbf8b3 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_action_info.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..1a6c3d0d8 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-mdpi/ic_launcher.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_action_info.png Binary files differnew file mode 100644 index 000000000..ba143ea7a --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_action_info.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..2081f403b --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-xhdpi/ic_launcher.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_action_info.png b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_action_info.png Binary files differnew file mode 100644 index 000000000..394eb7e53 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_action_info.png diff --git a/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..b506de4d5 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/drawable-xxhdpi/ic_launcher.png diff --git a/samples/browseable/PdfRendererBasic/res/layout/activity_main.xml b/samples/browseable/PdfRendererBasic/res/layout/activity_main.xml new file mode 100755 index 000000000..be1aa49d9 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/layout/activity_main.xml @@ -0,0 +1,36 @@ +<!-- + 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:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <LinearLayout style="@style/Widget.SampleMessageTile" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView style="@style/Widget.SampleMessage" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginLeft="@dimen/horizontal_page_margin" + android:layout_marginRight="@dimen/horizontal_page_margin" + android:layout_marginTop="@dimen/vertical_page_margin" + android:layout_marginBottom="@dimen/vertical_page_margin" + android:text="@string/intro_message" /> + </LinearLayout> +</LinearLayout> diff --git a/samples/browseable/PdfRendererBasic/res/layout/activity_main_real.xml b/samples/browseable/PdfRendererBasic/res/layout/activity_main_real.xml new file mode 100644 index 000000000..dcd52beaf --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/layout/activity_main_real.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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. +--> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/container" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MainActivity" + tools:ignore="MergeRootFrame" /> diff --git a/samples/browseable/PdfRendererBasic/res/layout/fragment_pdf_renderer_basic.xml b/samples/browseable/PdfRendererBasic/res/layout/fragment_pdf_renderer_basic.xml new file mode 100644 index 000000000..4a7799b7b --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/layout/fragment_pdf_renderer_basic.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + tools:context=".MainActivity$PlaceholderFragment"> + + <ImageView + android:id="@+id/image" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:background="@android:color/white" + android:scaleType="fitCenter" /> + + <LinearLayout + style="?android:attr/buttonBarStyle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:measureWithLargestChild="true" + android:orientation="horizontal"> + + <Button + android:id="@+id/previous" + style="?android:attr/buttonBarButtonStyle" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="@string/previous" /> + + <Button + android:id="@+id/next" + style="?android:attr/buttonBarButtonStyle" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="@string/next" /> + </LinearLayout> + +</LinearLayout> diff --git a/samples/browseable/PdfRendererBasic/res/menu/main.xml b/samples/browseable/PdfRendererBasic/res/menu/main.xml new file mode 100644 index 000000000..fa452e108 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/menu/main.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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/action_info" + android:icon="@drawable/ic_action_info" + android:showAsAction="always" + android:title="@string/info" /> + +</menu>
\ No newline at end of file diff --git a/samples/browseable/PdfRendererBasic/res/values-sw600dp/template-dimens.xml b/samples/browseable/PdfRendererBasic/res/values-sw600dp/template-dimens.xml new file mode 100644 index 000000000..22074a2bd --- /dev/null +++ b/samples/browseable/PdfRendererBasic/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/PdfRendererBasic/res/values-sw600dp/template-styles.xml b/samples/browseable/PdfRendererBasic/res/values-sw600dp/template-styles.xml new file mode 100644 index 000000000..03d197418 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/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/PdfRendererBasic/res/values-v11/template-styles.xml b/samples/browseable/PdfRendererBasic/res/values-v11/template-styles.xml new file mode 100644 index 000000000..8c1ea66f2 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/values-v11/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + 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" /> + +</resources> diff --git a/samples/browseable/PdfRendererBasic/res/values-v21/template-styles.xml b/samples/browseable/PdfRendererBasic/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/FindMyPhone/Shared/AndroidManifest.xml b/samples/browseable/PdfRendererBasic/res/values/base-strings.xml index 80efe2e2d..d97b3c6a8 100644 --- a/samples/browseable/FindMyPhone/Shared/AndroidManifest.xml +++ b/samples/browseable/PdfRendererBasic/res/values/base-strings.xml @@ -14,12 +14,15 @@ 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.findphone.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> +<resources> + <string name="app_name">PdfRendererBasic</string> + <string name="intro_message"> + <![CDATA[ + + + This sample demonstrates how to use PdfRenderer to display PDF documents on the screen. + + + ]]> + </string> +</resources> diff --git a/samples/browseable/PdfRendererBasic/res/values/strings.xml b/samples/browseable/PdfRendererBasic/res/values/strings.xml new file mode 100644 index 000000000..e0182fd39 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/values/strings.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014 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_with_index">PdfRendererBasic (%1$d/%2$d)</string> + <string name="info">Info</string> + <string name="previous">Previous</string> + <string name="next">Next</string> + +</resources> diff --git a/samples/browseable/PdfRendererBasic/res/values/template-dimens.xml b/samples/browseable/PdfRendererBasic/res/values/template-dimens.xml new file mode 100644 index 000000000..39e710b5c --- /dev/null +++ b/samples/browseable/PdfRendererBasic/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/PdfRendererBasic/res/values/template-styles.xml b/samples/browseable/PdfRendererBasic/res/values/template-styles.xml new file mode 100644 index 000000000..6e7d593dd --- /dev/null +++ b/samples/browseable/PdfRendererBasic/res/values/template-styles.xml @@ -0,0 +1,42 @@ +<!-- + 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.Light" /> + + <style name="Theme.Sample" parent="Theme.Base" /> + + <style name="AppTheme" parent="Theme.Sample" /> + <!-- 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> + +</resources> diff --git a/samples/browseable/PdfRendererBasic/src/com.example.android.pdfrendererbasic/MainActivity.java b/samples/browseable/PdfRendererBasic/src/com.example.android.pdfrendererbasic/MainActivity.java new file mode 100644 index 000000000..6b7e8b454 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/src/com.example.android.pdfrendererbasic/MainActivity.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2014 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.pdfrendererbasic; + +import android.app.Activity; +import android.app.AlertDialog; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +public class MainActivity extends Activity { + + public static final String FRAGMENT_PDF_RENDERER_BASIC = "pdf_renderer_basic"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main_real); + if (savedInstanceState == null) { + getFragmentManager().beginTransaction() + .add(R.id.container, new PdfRendererBasicFragment(), + FRAGMENT_PDF_RENDERER_BASIC) + .commit(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_info: + new AlertDialog.Builder(this) + .setMessage(R.string.intro_message) + .setPositiveButton(android.R.string.ok, null) + .show(); + return true; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/samples/browseable/PdfRendererBasic/src/com.example.android.pdfrendererbasic/PdfRendererBasicFragment.java b/samples/browseable/PdfRendererBasic/src/com.example.android.pdfrendererbasic/PdfRendererBasicFragment.java new file mode 100644 index 000000000..e413c6599 --- /dev/null +++ b/samples/browseable/PdfRendererBasic/src/com.example.android.pdfrendererbasic/PdfRendererBasicFragment.java @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2014 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.pdfrendererbasic; + +import android.app.Activity; +import android.app.Fragment; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.pdf.PdfRenderer; +import android.os.Bundle; +import android.os.ParcelFileDescriptor; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.Toast; + +import java.io.IOException; + +/** + * This fragment has a big {@ImageView} that shows PDF pages, and 2 {@link android.widget.Button}s to move between + * pages. We use a {@link android.graphics.pdf.PdfRenderer} to render PDF pages as {@link android.graphics.Bitmap}s. + */ +public class PdfRendererBasicFragment extends Fragment implements View.OnClickListener { + + /** + * Key string for saving the state of current page index. + */ + private static final String STATE_CURRENT_PAGE_INDEX = "current_page_index"; + + /** + * File descriptor of the PDF. + */ + private ParcelFileDescriptor mFileDescriptor; + + /** + * {@link android.graphics.pdf.PdfRenderer} to render the PDF. + */ + private PdfRenderer mPdfRenderer; + + /** + * Page that is currently shown on the screen. + */ + private PdfRenderer.Page mCurrentPage; + + /** + * {@link android.widget.ImageView} that shows a PDF page as a {@link android.graphics.Bitmap} + */ + private ImageView mImageView; + + /** + * {@link android.widget.Button} to move to the previous page. + */ + private Button mButtonPrevious; + + /** + * {@link android.widget.Button} to move to the next page. + */ + private Button mButtonNext; + + public PdfRendererBasicFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_pdf_renderer_basic, container, false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + // Retain view references. + mImageView = (ImageView) view.findViewById(R.id.image); + mButtonPrevious = (Button) view.findViewById(R.id.previous); + mButtonNext = (Button) view.findViewById(R.id.next); + // Bind events. + mButtonPrevious.setOnClickListener(this); + mButtonNext.setOnClickListener(this); + // Show the first page by default. + int index = 0; + // If there is a savedInstanceState (screen orientations, etc.), we restore the page index. + if (null != savedInstanceState) { + index = savedInstanceState.getInt(STATE_CURRENT_PAGE_INDEX, 0); + } + showPage(index); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + openRenderer(activity); + } catch (IOException e) { + e.printStackTrace(); + Toast.makeText(activity, "Error! " + e.getMessage(), Toast.LENGTH_SHORT).show(); + activity.finish(); + } + } + + @Override + public void onDetach() { + try { + closeRenderer(); + } catch (IOException e) { + e.printStackTrace(); + } + super.onDetach(); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + if (null != mCurrentPage) { + outState.putInt(STATE_CURRENT_PAGE_INDEX, mCurrentPage.getIndex()); + } + } + + /** + * Sets up a {@link android.graphics.pdf.PdfRenderer} and related resources. + */ + private void openRenderer(Context context) throws IOException { + // In this sample, we read a PDF from the assets directory. + mFileDescriptor = context.getAssets().openFd("sample.pdf").getParcelFileDescriptor(); + // This is the PdfRenderer we use to render the PDF. + mPdfRenderer = new PdfRenderer(mFileDescriptor); + } + + /** + * Closes the {@link android.graphics.pdf.PdfRenderer} and related resources. + * + * @throws java.io.IOException When the PDF file cannot be closed. + */ + private void closeRenderer() throws IOException { + if (null != mCurrentPage) { + mCurrentPage.close(); + } + mPdfRenderer.close(); + mFileDescriptor.close(); + } + + /** + * Shows the specified page of PDF to the screen. + * + * @param index The page index. + */ + private void showPage(int index) { + if (mPdfRenderer.getPageCount() <= index) { + return; + } + // Make sure to close the current page before opening another one. + if (null != mCurrentPage) { + mCurrentPage.close(); + } + // Use `openPage` to open a specific page in PDF. + mCurrentPage = mPdfRenderer.openPage(index); + // Important: the destination bitmap must be ARGB (not RGB). + Bitmap bitmap = Bitmap.createBitmap(mCurrentPage.getWidth(), mCurrentPage.getHeight(), + Bitmap.Config.ARGB_8888); + // Here, we render the page onto the Bitmap. + // To render a portion of the page, use the second and third parameter. Pass nulls to get + // the default result. + // Pass either RENDER_MODE_FOR_DISPLAY or RENDER_MODE_FOR_PRINT for the last parameter. + mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); + // We are ready to show the Bitmap to user. + mImageView.setImageBitmap(bitmap); + updateUi(); + } + + /** + * Updates the state of 2 control buttons in response to the current page index. + */ + private void updateUi() { + int index = mCurrentPage.getIndex(); + int pageCount = mPdfRenderer.getPageCount(); + mButtonPrevious.setEnabled(0 != index); + mButtonNext.setEnabled(index + 1 < pageCount); + getActivity().setTitle(getString(R.string.app_name_with_index, index + 1, pageCount)); + } + + /** + * Gets the number of pages in the PDF. This method is marked as public for testing. + * + * @return The number of pages. + */ + public int getPageCount() { + return mPdfRenderer.getPageCount(); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.previous: { + // Move to the previous page + showPage(mCurrentPage.getIndex() - 1); + break; + } + case R.id.next: { + // Move to the next page + showPage(mCurrentPage.getIndex() + 1); + break; + } + } + } + +} diff --git a/samples/browseable/Quiz/Application/AndroidManifest.xml b/samples/browseable/Quiz/Application/AndroidManifest.xml index 40e36027e..ce7213542 100644 --- a/samples/browseable/Quiz/Application/AndroidManifest.xml +++ b/samples/browseable/Quiz/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.quiz" > + package="com.example.android.wearable.quiz" > <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> @@ -29,7 +29,7 @@ android:value="@integer/google_play_services_version" /> <activity - android:name="com.example.android.quiz.MainActivity" + android:name="com.example.android.wearable.quiz.MainActivity" android:label="@string/app_name" android:windowSoftInputMode="stateHidden" android:configChanges="keyboardHidden|orientation|screenSize" > diff --git a/samples/browseable/Quiz/Application/res/values-v21/template-styles.xml b/samples/browseable/Quiz/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/Quiz/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Quiz/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/Quiz/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/Quiz/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/Quiz/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/Quiz/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/Quiz/Application/src/com.example.android.quiz/Constants.java b/samples/browseable/Quiz/Application/src/com.example.android.wearable.quiz/Constants.java index ea5c56b5e..2bcfe5f18 100644 --- a/samples/browseable/Quiz/Application/src/com.example.android.quiz/Constants.java +++ b/samples/browseable/Quiz/Application/src/com.example.android.wearable.quiz/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.quiz; +package com.example.android.wearable.quiz; /** Constants used in the companion app. */ public final class Constants { diff --git a/samples/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java b/samples/browseable/Quiz/Application/src/com.example.android.wearable.quiz/JsonUtils.java index a0f98c12b..df8c8998e 100644 --- a/samples/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java +++ b/samples/browseable/Quiz/Application/src/com.example.android.wearable.quiz/JsonUtils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.quiz; +package com.example.android.wearable.quiz; import android.content.Context; diff --git a/samples/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java b/samples/browseable/Quiz/Application/src/com.example.android.wearable.quiz/MainActivity.java index ab8e3b45b..0ff41f42d 100644 --- a/samples/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java +++ b/samples/browseable/Quiz/Application/src/com.example.android.wearable.quiz/MainActivity.java @@ -14,21 +14,21 @@ * limitations under the License. */ -package com.example.android.quiz; - -import static com.example.android.quiz.Constants.ANSWERS; -import static com.example.android.quiz.Constants.CHOSEN_ANSWER_CORRECT; -import static com.example.android.quiz.Constants.CORRECT_ANSWER_INDEX; -import static com.example.android.quiz.Constants.NUM_CORRECT; -import static com.example.android.quiz.Constants.NUM_INCORRECT; -import static com.example.android.quiz.Constants.NUM_SKIPPED; -import static com.example.android.quiz.Constants.QUESTION; -import static com.example.android.quiz.Constants.QUESTION_INDEX; -import static com.example.android.quiz.Constants.QUESTION_WAS_ANSWERED; -import static com.example.android.quiz.Constants.QUESTION_WAS_DELETED; -import static com.example.android.quiz.Constants.QUIZ_ENDED_PATH; -import static com.example.android.quiz.Constants.QUIZ_EXITED_PATH; -import static com.example.android.quiz.Constants.RESET_QUIZ_PATH; +package com.example.android.wearable.quiz; + +import static com.example.android.wearable.quiz.Constants.ANSWERS; +import static com.example.android.wearable.quiz.Constants.CHOSEN_ANSWER_CORRECT; +import static com.example.android.wearable.quiz.Constants.CORRECT_ANSWER_INDEX; +import static com.example.android.wearable.quiz.Constants.NUM_CORRECT; +import static com.example.android.wearable.quiz.Constants.NUM_INCORRECT; +import static com.example.android.wearable.quiz.Constants.NUM_SKIPPED; +import static com.example.android.wearable.quiz.Constants.QUESTION; +import static com.example.android.wearable.quiz.Constants.QUESTION_INDEX; +import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_ANSWERED; +import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_DELETED; +import static com.example.android.wearable.quiz.Constants.QUIZ_ENDED_PATH; +import static com.example.android.wearable.quiz.Constants.QUIZ_EXITED_PATH; +import static com.example.android.wearable.quiz.Constants.RESET_QUIZ_PATH; import android.app.Activity; import android.graphics.Color; diff --git a/samples/browseable/Quiz/Shared/AndroidManifest.xml b/samples/browseable/Quiz/Shared/AndroidManifest.xml deleted file mode 100644 index 0d7b8a69c..000000000 --- a/samples/browseable/Quiz/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.quiz.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/Quiz/Shared/res/values/strings.xml b/samples/browseable/Quiz/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/Quiz/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/Quiz/Wearable/AndroidManifest.xml b/samples/browseable/Quiz/Wearable/AndroidManifest.xml index 7954e3271..fd20def89 100644 --- a/samples/browseable/Quiz/Wearable/AndroidManifest.xml +++ b/samples/browseable/Quiz/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.quiz" > + package="com.example.android.wearable.quiz" > <uses-sdk android:minSdkVersion="20" diff --git a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/Constants.java b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/Constants.java index 8218ad91d..8b81f59be 100644 --- a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/Constants.java +++ b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.quiz; +package com.example.android.wearable.quiz; /** Constants used in the wearable app. */ public final class Constants { diff --git a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/DeleteQuestionService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/DeleteQuestionService.java index 38b5e4a94..78e81ca0c 100644 --- a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/DeleteQuestionService.java +++ b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/DeleteQuestionService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.quiz; +package com.example.android.wearable.quiz; import android.app.IntentService; import android.content.Intent; @@ -33,8 +33,8 @@ import com.google.android.gms.wearable.Wearable; import java.util.concurrent.TimeUnit; -import static com.example.android.quiz.Constants.CONNECT_TIMEOUT_MS; -import static com.example.android.quiz.Constants.QUESTION_WAS_DELETED; +import static com.example.android.wearable.quiz.Constants.CONNECT_TIMEOUT_MS; +import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_DELETED; /** * Used to update quiz status on the phone when user dismisses a question on the watch. diff --git a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizListenerService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/QuizListenerService.java index 3226f9b42..020a37b8d 100644 --- a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizListenerService.java +++ b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/QuizListenerService.java @@ -14,20 +14,20 @@ * limitations under the License. */ -package com.example.android.quiz; - -import static com.example.android.quiz.Constants.ANSWERS; -import static com.example.android.quiz.Constants.CONNECT_TIMEOUT_MS; -import static com.example.android.quiz.Constants.CORRECT_ANSWER_INDEX; -import static com.example.android.quiz.Constants.NUM_CORRECT; -import static com.example.android.quiz.Constants.NUM_INCORRECT; -import static com.example.android.quiz.Constants.NUM_SKIPPED; -import static com.example.android.quiz.Constants.QUESTION; -import static com.example.android.quiz.Constants.QUESTION_INDEX; -import static com.example.android.quiz.Constants.QUESTION_WAS_ANSWERED; -import static com.example.android.quiz.Constants.QUESTION_WAS_DELETED; -import static com.example.android.quiz.Constants.QUIZ_ENDED_PATH; -import static com.example.android.quiz.Constants.QUIZ_EXITED_PATH; +package com.example.android.wearable.quiz; + +import static com.example.android.wearable.quiz.Constants.ANSWERS; +import static com.example.android.wearable.quiz.Constants.CONNECT_TIMEOUT_MS; +import static com.example.android.wearable.quiz.Constants.CORRECT_ANSWER_INDEX; +import static com.example.android.wearable.quiz.Constants.NUM_CORRECT; +import static com.example.android.wearable.quiz.Constants.NUM_INCORRECT; +import static com.example.android.wearable.quiz.Constants.NUM_SKIPPED; +import static com.example.android.wearable.quiz.Constants.QUESTION; +import static com.example.android.wearable.quiz.Constants.QUESTION_INDEX; +import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_ANSWERED; +import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_DELETED; +import static com.example.android.wearable.quiz.Constants.QUIZ_ENDED_PATH; +import static com.example.android.wearable.quiz.Constants.QUIZ_EXITED_PATH; import android.app.Notification; import android.app.NotificationManager; diff --git a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizReportActionService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/QuizReportActionService.java index 4ca55be83..956bdaf38 100644 --- a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizReportActionService.java +++ b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/QuizReportActionService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.quiz; +package com.example.android.wearable.quiz; import android.app.IntentService; import android.content.Intent; @@ -28,15 +28,15 @@ import com.google.android.gms.wearable.Wearable; import java.util.concurrent.TimeUnit; -import static com.example.android.quiz.Constants.CONNECT_TIMEOUT_MS; -import static com.example.android.quiz.Constants.RESET_QUIZ_PATH; +import static com.example.android.wearable.quiz.Constants.CONNECT_TIMEOUT_MS; +import static com.example.android.wearable.quiz.Constants.RESET_QUIZ_PATH; /** * Service to reset the quiz (by sending a message to the phone) when the Reset Quiz * action on the Quiz Report is selected. */ public class QuizReportActionService extends IntentService { - public static final String ACTION_RESET_QUIZ = "com.example.android.quiz.RESET_QUIZ"; + public static final String ACTION_RESET_QUIZ = "com.example.android.wearable.quiz.RESET_QUIZ"; private static final String TAG = "QuizReportActionReceiver"; diff --git a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/UpdateQuestionService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/UpdateQuestionService.java index 671ecad2c..e06c30346 100644 --- a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/UpdateQuestionService.java +++ b/samples/browseable/Quiz/Wearable/src/com.example.android.wearable.quiz/UpdateQuestionService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.quiz; +package com.example.android.wearable.quiz; import android.app.IntentService; import android.app.NotificationManager; @@ -34,9 +34,9 @@ import com.google.android.gms.wearable.Wearable; import java.util.concurrent.TimeUnit; -import static com.example.android.quiz.Constants.CHOSEN_ANSWER_CORRECT; -import static com.example.android.quiz.Constants.QUESTION_INDEX; -import static com.example.android.quiz.Constants.QUESTION_WAS_ANSWERED; +import static com.example.android.wearable.quiz.Constants.CHOSEN_ANSWER_CORRECT; +import static com.example.android.wearable.quiz.Constants.QUESTION_INDEX; +import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_ANSWERED; /** * Updates quiz status on the phone when user selects an answer to a question on the watch. diff --git a/samples/browseable/RecipeAssistant/Application/AndroidManifest.xml b/samples/browseable/RecipeAssistant/Application/AndroidManifest.xml index db13ed99e..3ddff205c 100644 --- a/samples/browseable/RecipeAssistant/Application/AndroidManifest.xml +++ b/samples/browseable/RecipeAssistant/Application/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.recipeassistant" > + package="com.example.android.wearable.recipeassistant" > <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/RecipeAssistant/Application/res/values-v21/template-styles.xml b/samples/browseable/RecipeAssistant/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/RecipeAssistant/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/AssetUtils.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/AssetUtils.java index b9ad8d5bd..8753582af 100644 --- a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/AssetUtils.java +++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/AssetUtils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.recipeassistant; +package com.example.android.wearable.recipeassistant; import android.content.Context; import android.graphics.Bitmap; diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Constants.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/Constants.java index e6d367d77..fae49ee7a 100644 --- a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Constants.java +++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.recipeassistant; +package com.example.android.wearable.recipeassistant; public final class Constants { private Constants() { @@ -34,7 +34,7 @@ public final class Constants { public static final String RECIPE_FIELD_STEP_IMAGE = "step_image"; static final String ACTION_START_COOKING = - "com.example.android.recipeassistant.START_COOKING"; + "com.example.android.wearable.recipeassistant.START_COOKING"; public static final String EXTRA_RECIPE = "recipe"; public static final int NOTIFICATION_ID = 0; diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/MainActivity.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/MainActivity.java index 5738e2ad3..4cc860f49 100644 --- a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/MainActivity.java +++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.recipeassistant; +package com.example.android.wearable.recipeassistant; import android.app.ListActivity; import android.content.Intent; diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Recipe.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/Recipe.java index 355190735..e470c0f4e 100644 --- a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Recipe.java +++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/Recipe.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.recipeassistant; +package com.example.android.wearable.recipeassistant; import android.content.Context; import android.os.Bundle; diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeActivity.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/RecipeActivity.java index 4b9d72dd3..cc7f034a7 100644 --- a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeActivity.java +++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/RecipeActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.recipeassistant; +package com.example.android.wearable.recipeassistant; import android.app.Activity; import android.app.PendingIntent; diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeListAdapter.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/RecipeListAdapter.java index bc602a181..746603a31 100644 --- a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeListAdapter.java +++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/RecipeListAdapter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.recipeassistant; +package com.example.android.wearable.recipeassistant; import android.content.Context; import android.database.DataSetObserver; diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeService.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/RecipeService.java index 74bbfda72..4abdf97f0 100644 --- a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeService.java +++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.wearable.recipeassistant/RecipeService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.recipeassistant; +package com.example.android.wearable.recipeassistant; import android.app.Notification; import android.app.Service; diff --git a/samples/browseable/RecipeAssistant/Shared/AndroidManifest.xml b/samples/browseable/RecipeAssistant/Shared/AndroidManifest.xml index 1951e2693..00c86930a 100644 --- a/samples/browseable/RecipeAssistant/Shared/AndroidManifest.xml +++ b/samples/browseable/RecipeAssistant/Shared/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.recipeassistant.common"> + package="com.example.android.wearable.recipeassistant.common"> <application android:allowBackup="true" android:label="@string/app_name"> diff --git a/samples/browseable/RenderScriptIntrinsic/AndroidManifest.xml b/samples/browseable/RenderScriptIntrinsic/AndroidManifest.xml index 566ef8ae7..e108aff20 100644 --- a/samples/browseable/RenderScriptIntrinsic/AndroidManifest.xml +++ b/samples/browseable/RenderScriptIntrinsic/AndroidManifest.xml @@ -20,9 +20,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="8" - android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/RenderScriptIntrinsic/_index.jd b/samples/browseable/RenderScriptIntrinsic/_index.jd index 2724c1a3a..f5d5e4e06 100644 --- a/samples/browseable/RenderScriptIntrinsic/_index.jd +++ b/samples/browseable/RenderScriptIntrinsic/_index.jd @@ -1,15 +1,11 @@ - - - page.tags="RenderScriptIntrinsic" sample.group=RenderScript @jd:body <p> - This sample demonstrates how to use <a href= - "http://android-developers.blogspot.com/2013/08/renderscript-intrinsics.html"> - RenderScript intrinsics</a>. The app creates several RenderScript intrinsics - and shows a filtering result with various parameters. The sample also shows - how to extend {@link android.widget.RadioButton} with {@link - android.graphics.drawable.StateListDrawable}. -</p> + + RenderScriptIntrinsic sample that demonstrates how to use RenderScript intrinsics. + Creates several RenderScript intrinsics and shows a filtering result with various parameters. + Also shows how to extends RedioButton with StateListDrawable. + + </p> diff --git a/samples/browseable/RenderScriptIntrinsic/res/values-v21/template-styles.xml b/samples/browseable/RenderScriptIntrinsic/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/RenderScriptIntrinsic/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/RenderScriptIntrinsic/res/values/base-strings.xml b/samples/browseable/RenderScriptIntrinsic/res/values/base-strings.xml index c8488beed..e32a25973 100644 --- a/samples/browseable/RenderScriptIntrinsic/res/values/base-strings.xml +++ b/samples/browseable/RenderScriptIntrinsic/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">RenderScriptIntrinsic</string> <string name="intro_message"> diff --git a/samples/browseable/RepeatingAlarm/AndroidManifest.xml b/samples/browseable/RepeatingAlarm/AndroidManifest.xml index b7d02e570..0fbdc7a7e 100644 --- a/samples/browseable/RepeatingAlarm/AndroidManifest.xml +++ b/samples/browseable/RepeatingAlarm/AndroidManifest.xml @@ -19,7 +19,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/RepeatingAlarm/_index.jd b/samples/browseable/RepeatingAlarm/_index.jd index 69f7ee1c3..1735034c8 100644 --- a/samples/browseable/RepeatingAlarm/_index.jd +++ b/samples/browseable/RepeatingAlarm/_index.jd @@ -1,9 +1,10 @@ - - - page.tags="RepeatingAlarm" sample.group=Background @jd:body - - -<p>This sample demonstrates how to implement a repeating alarm using an {@link android.app.AlarmManager}.</p> + +<p> + + Introductory text that explains what the sample is intended to demonstrate. Edit + in template-params.xml. + + </p> diff --git a/samples/browseable/RepeatingAlarm/res/values-v21/template-styles.xml b/samples/browseable/RepeatingAlarm/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/RepeatingAlarm/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/RepeatingAlarm/res/values/base-strings.xml b/samples/browseable/RepeatingAlarm/res/values/base-strings.xml index 6b89192f6..e6170d2bc 100644 --- a/samples/browseable/RepeatingAlarm/res/values/base-strings.xml +++ b/samples/browseable/RepeatingAlarm/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">RepeatingAlarm</string> <string name="intro_message"> diff --git a/samples/browseable/RepeatingAlarm/res/values/strings.xml b/samples/browseable/RepeatingAlarm/res/values/strings.xml index 2013d95c1..59a8ff229 100644 --- a/samples/browseable/RepeatingAlarm/res/values/strings.xml +++ b/samples/browseable/RepeatingAlarm/res/values/strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="sample_action">Set Alarm</string> </resources> diff --git a/samples/browseable/RepeatingAlarm/src/com.example.android.repeatingalarm/MainActivity.java b/samples/browseable/RepeatingAlarm/src/com.example.android.repeatingalarm/MainActivity.java index 147f5761a..b7527d526 100644 --- a/samples/browseable/RepeatingAlarm/src/com.example.android.repeatingalarm/MainActivity.java +++ b/samples/browseable/RepeatingAlarm/src/com.example.android.repeatingalarm/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.repeatingalarm; import android.graphics.Color; diff --git a/samples/browseable/SkeletonWearableApp/Application/AndroidManifest.xml b/samples/browseable/SkeletonWearableApp/Application/AndroidManifest.xml index 7e1968079..0cbc0370b 100644 --- a/samples/browseable/SkeletonWearableApp/Application/AndroidManifest.xml +++ b/samples/browseable/SkeletonWearableApp/Application/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.skeletonwearableapp"> + package="com.example.android.google.wearable.app"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/SkeletonWearableApp/Application/res/values-v21/template-styles.xml b/samples/browseable/SkeletonWearableApp/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SkeletonWearableApp/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/SkeletonWearableApp/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/SkeletonWearableApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/SkeletonWearableApp/Shared/AndroidManifest.xml b/samples/browseable/SkeletonWearableApp/Shared/AndroidManifest.xml deleted file mode 100644 index 5e29d53dc..000000000 --- a/samples/browseable/SkeletonWearableApp/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.skeletonwearableapp.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/SkeletonWearableApp/Shared/res/values/strings.xml b/samples/browseable/SkeletonWearableApp/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/SkeletonWearableApp/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/SkeletonWearableApp/Wearable/AndroidManifest.xml b/samples/browseable/SkeletonWearableApp/Wearable/AndroidManifest.xml index 3e9310e51..bf1c1a4f6 100644 --- a/samples/browseable/SkeletonWearableApp/Wearable/AndroidManifest.xml +++ b/samples/browseable/SkeletonWearableApp/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.skeletonwearableapp" > + package="com.example.android.google.wearable.app" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -42,7 +42,7 @@ <activity android:name=".GridExampleActivity"> <intent-filter> - <action android:name="com.example.android.skeletonwearableapp.GRID_ACTIVITY"/> + <action android:name="com.example.android.google.wearable.app.GRID_ACTIVITY"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> diff --git a/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/GridExampleActivity.java b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.google.wearable.app/GridExampleActivity.java index c0d0b2b32..0a88c04d0 100644 --- a/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/GridExampleActivity.java +++ b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.google.wearable.app/GridExampleActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.skeletonwearableapp; +package com.example.android.google.wearable.app; import android.app.Activity; import android.app.Fragment; diff --git a/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/MainActivity.java b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.google.wearable.app/MainActivity.java index b7a91e69f..817e195a8 100644 --- a/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/MainActivity.java +++ b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.google.wearable.app/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.skeletonwearableapp; +package com.example.android.google.wearable.app; import android.app.Activity; import android.app.Notification; diff --git a/samples/browseable/SlidingTabsBasic/AndroidManifest.xml b/samples/browseable/SlidingTabsBasic/AndroidManifest.xml index 31cbfb893..441c3de8e 100644 --- a/samples/browseable/SlidingTabsBasic/AndroidManifest.xml +++ b/samples/browseable/SlidingTabsBasic/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/SlidingTabsBasic/_index.jd b/samples/browseable/SlidingTabsBasic/_index.jd index 261885c75..ec30b9f9f 100644 --- a/samples/browseable/SlidingTabsBasic/_index.jd +++ b/samples/browseable/SlidingTabsBasic/_index.jd @@ -1,14 +1,10 @@ - - - page.tags="SlidingTabsBasic" sample.group=UI @jd:body <p> - This sample shows how to use <code><a href= - "{@docRoot}samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html"> - SlidingTabLayout</a></code> to display a custom {@link - android.support.v4.view.ViewPager ViewPager} title strip that gives - continuous feedback to the user when scrolling. -</p>
\ No newline at end of file + + A basic sample which shows how to use SlidingTabLayout to display a custom + ViewPager title strip which gives continuous feedback to the user when scrolling. + + </p> diff --git a/samples/browseable/SlidingTabsBasic/res/values-v21/template-styles.xml b/samples/browseable/SlidingTabsBasic/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SlidingTabsBasic/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SlidingTabsBasic/res/values/base-strings.xml b/samples/browseable/SlidingTabsBasic/res/values/base-strings.xml index c7f26bf55..ea90429e6 100644 --- a/samples/browseable/SlidingTabsBasic/res/values/base-strings.xml +++ b/samples/browseable/SlidingTabsBasic/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">SlidingTabsBasic</string> <string name="intro_message"> diff --git a/samples/browseable/SlidingTabsBasic/src/com.example.android.slidingtabsbasic/MainActivity.java b/samples/browseable/SlidingTabsBasic/src/com.example.android.slidingtabsbasic/MainActivity.java index ac405d19b..d7d2ff50f 100644 --- a/samples/browseable/SlidingTabsBasic/src/com.example.android.slidingtabsbasic/MainActivity.java +++ b/samples/browseable/SlidingTabsBasic/src/com.example.android.slidingtabsbasic/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.slidingtabsbasic; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/SlidingTabsColors/AndroidManifest.xml b/samples/browseable/SlidingTabsColors/AndroidManifest.xml index be4a43ad2..5ff4240d6 100644 --- a/samples/browseable/SlidingTabsColors/AndroidManifest.xml +++ b/samples/browseable/SlidingTabsColors/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/SlidingTabsColors/_index.jd b/samples/browseable/SlidingTabsColors/_index.jd index 342ee1545..5fc023eb3 100644 --- a/samples/browseable/SlidingTabsColors/_index.jd +++ b/samples/browseable/SlidingTabsColors/_index.jd @@ -1,14 +1,10 @@ - - - page.tags="SlidingTabsColors" sample.group=UI @jd:body <p> - This sample shows a more advanced example of how to use a <code><a href= - "{@docRoot}samples/SlidingTabsColors/src/com.example.android.common/view/SlidingTabLayout.html"> - SlidingTabLayout</a></code> to display a custom {@link - android.support.v4.view.ViewPager ViewPager} title strip, with custom - coloring for each tab. -</p>
\ No newline at end of file + + A more advanced sample which shows how to use SlidingTabLayout to display a custom + ViewPager title strip, with custom coloring for each tab. + + </p> diff --git a/samples/browseable/SlidingTabsColors/res/values-v21/template-styles.xml b/samples/browseable/SlidingTabsColors/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SlidingTabsColors/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SlidingTabsColors/res/values/base-strings.xml b/samples/browseable/SlidingTabsColors/res/values/base-strings.xml index 89cac2d6e..66070a411 100644 --- a/samples/browseable/SlidingTabsColors/res/values/base-strings.xml +++ b/samples/browseable/SlidingTabsColors/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">SlidingTabsColors</string> <string name="intro_message"> diff --git a/samples/browseable/SlidingTabsColors/res/values/strings.xml b/samples/browseable/SlidingTabsColors/res/values/strings.xml index e1b0846b9..e1b0846b9 100755..100644 --- a/samples/browseable/SlidingTabsColors/res/values/strings.xml +++ b/samples/browseable/SlidingTabsColors/res/values/strings.xml diff --git a/samples/browseable/SlidingTabsColors/src/com.example.android.slidingtabscolors/MainActivity.java b/samples/browseable/SlidingTabsColors/src/com.example.android.slidingtabscolors/MainActivity.java index d3d7567cd..dc1205ba1 100644 --- a/samples/browseable/SlidingTabsColors/src/com.example.android.slidingtabscolors/MainActivity.java +++ b/samples/browseable/SlidingTabsColors/src/com.example.android.slidingtabscolors/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.slidingtabscolors; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - SlidingTabsColorsFragment fragment = new SlidingTabsColorsFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + SlidingTabsColorsFragment fragment = new SlidingTabsColorsFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/SpeedTracker/Application/res/values-v21/template-styles.xml b/samples/browseable/SpeedTracker/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SpeedTracker/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/SpeedTracker/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/SpeedTracker/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/SpeedTracker/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/SpeedTracker/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/SpeedTracker/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/SpeedTracker/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/StorageClient/AndroidManifest.xml b/samples/browseable/StorageClient/AndroidManifest.xml index d35a4ec22..0bcfde911 100644 --- a/samples/browseable/StorageClient/AndroidManifest.xml +++ b/samples/browseable/StorageClient/AndroidManifest.xml @@ -19,7 +19,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/StorageClient/_index.jd b/samples/browseable/StorageClient/_index.jd index e81e6b254..d1444f5a5 100644 --- a/samples/browseable/StorageClient/_index.jd +++ b/samples/browseable/StorageClient/_index.jd @@ -1,12 +1,12 @@ - - - page.tags="StorageClient" sample.group=Content @jd:body -<p>This sample demonstrates how to use the -{@link android.content.Intent#ACTION_OPEN_DOCUMENT} intent to let users -choose a file via the system's file browser. This intent allows a client -application to access a list of document providers on the device, and choose -a file from any of them.</p> +<p> + + Using the OPEN_DOCUMENT intent, a client app can access a list of Document Providers + on the device, and choose a file from any of them. + \n\nTo demonstrate this, click the button below to open up the Storage Access Framework + interface, and choose an image on your device. It will be displayed in this app. + + </p> diff --git a/samples/browseable/StorageClient/res/values-v21/template-styles.xml b/samples/browseable/StorageClient/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/StorageClient/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/StorageClient/res/values/base-strings.xml b/samples/browseable/StorageClient/res/values/base-strings.xml index 9498a2dab..0e3659dd1 100644 --- a/samples/browseable/StorageClient/res/values/base-strings.xml +++ b/samples/browseable/StorageClient/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">StorageClient</string> <string name="intro_message"> diff --git a/samples/browseable/StorageClient/res/values/strings.xml b/samples/browseable/StorageClient/res/values/strings.xml index 303776fbf..c571bb586 100644 --- a/samples/browseable/StorageClient/res/values/strings.xml +++ b/samples/browseable/StorageClient/res/values/strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="sample_action">Show Me The Image</string> </resources> diff --git a/samples/browseable/StorageClient/src/com.example.android.storageclient/MainActivity.java b/samples/browseable/StorageClient/src/com.example.android.storageclient/MainActivity.java index 106f26b6f..2925d011c 100644 --- a/samples/browseable/StorageClient/src/com.example.android.storageclient/MainActivity.java +++ b/samples/browseable/StorageClient/src/com.example.android.storageclient/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.storageclient; import android.graphics.Color; diff --git a/samples/browseable/StorageProvider/AndroidManifest.xml b/samples/browseable/StorageProvider/AndroidManifest.xml index e4704dc8f..53e78196e 100644 --- a/samples/browseable/StorageProvider/AndroidManifest.xml +++ b/samples/browseable/StorageProvider/AndroidManifest.xml @@ -21,9 +21,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="19" - android:targetSdkVersion="19"/> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> diff --git a/samples/browseable/StorageProvider/_index.jd b/samples/browseable/StorageProvider/_index.jd index 562a83217..02e8c660d 100644 --- a/samples/browseable/StorageProvider/_index.jd +++ b/samples/browseable/StorageProvider/_index.jd @@ -1,7 +1,10 @@ -page.tags="Storage access framework", storage, documents +page.tags="MyCloud" 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> +<p> + + \nA simple implementation of a documents provider using the storage access framework in + Android 4.4. + + </p> diff --git a/samples/browseable/StorageProvider/res/values-v21/template-styles.xml b/samples/browseable/StorageProvider/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/StorageProvider/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/StorageProvider/res/values/base-strings.xml b/samples/browseable/StorageProvider/res/values/base-strings.xml index d3674af60..3453e88e3 100644 --- a/samples/browseable/StorageProvider/res/values/base-strings.xml +++ b/samples/browseable/StorageProvider/res/values/base-strings.xml @@ -14,9 +14,6 @@ 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"> diff --git a/samples/browseable/StorageProvider/res/values/strings.xml b/samples/browseable/StorageProvider/res/values/strings.xml index df0327374..cde5fb53c 100644 --- a/samples/browseable/StorageProvider/res/values/strings.xml +++ b/samples/browseable/StorageProvider/res/values/strings.xml @@ -14,9 +14,6 @@ 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/src/com.example.android.storageprovider/MainActivity.java b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MainActivity.java index 3108c1f50..e46a55a1e 100644 --- a/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MainActivity.java +++ b/samples/browseable/StorageProvider/src/com.example.android.storageprovider/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.storageprovider; import android.graphics.Color; diff --git a/samples/browseable/SwipeRefreshLayoutBasic/AndroidManifest.xml b/samples/browseable/SwipeRefreshLayoutBasic/AndroidManifest.xml index fa754537a..245097d3a 100644 --- a/samples/browseable/SwipeRefreshLayoutBasic/AndroidManifest.xml +++ b/samples/browseable/SwipeRefreshLayoutBasic/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/SwipeRefreshLayoutBasic/_index.jd b/samples/browseable/SwipeRefreshLayoutBasic/_index.jd index bfbaddbbb..ca15805fa 100644 --- a/samples/browseable/SwipeRefreshLayoutBasic/_index.jd +++ b/samples/browseable/SwipeRefreshLayoutBasic/_index.jd @@ -1,11 +1,11 @@ - - - page.tags="SwipeRefreshLayoutBasic" sample.group=UI @jd:body -<p>This sample demonstrates how to use {@link android.support.v4.widget.SwipeRefreshLayout} to add -the <em>swipe-to-refresh</em> gesture to a {@link android.view.View}, which enables you to trigger -a refresh by swiping down on the {@link android.view.View}. In this sample, the view that can -be freshed is a {@link android.widget.ListView}.</p> +<p> + + A basic sample which shows how to use SwipeRefreshLayout to add the \'swipe-to-refresh\' + gesture to a View, enabling the ability to trigger a refresh from swiping down on the view. + In this sample the View which can be refreshed is a ListView. + + </p> diff --git a/samples/browseable/SwipeRefreshLayoutBasic/res/values-v21/template-styles.xml b/samples/browseable/SwipeRefreshLayoutBasic/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SwipeRefreshLayoutBasic/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SwipeRefreshLayoutBasic/res/values/base-strings.xml b/samples/browseable/SwipeRefreshLayoutBasic/res/values/base-strings.xml index 665d16fed..a9f797f56 100644 --- a/samples/browseable/SwipeRefreshLayoutBasic/res/values/base-strings.xml +++ b/samples/browseable/SwipeRefreshLayoutBasic/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">SwipeRefreshLayoutBasic</string> <string name="intro_message"> diff --git a/samples/browseable/SwipeRefreshLayoutBasic/res/values/strings.xml b/samples/browseable/SwipeRefreshLayoutBasic/res/values/strings.xml index 6bdb32e3c..6bdb32e3c 100755..100644 --- a/samples/browseable/SwipeRefreshLayoutBasic/res/values/strings.xml +++ b/samples/browseable/SwipeRefreshLayoutBasic/res/values/strings.xml diff --git a/samples/browseable/SwipeRefreshLayoutBasic/src/com.example.android.swiperefreshlayoutbasic/MainActivity.java b/samples/browseable/SwipeRefreshLayoutBasic/src/com.example.android.swiperefreshlayoutbasic/MainActivity.java index f90aed1fc..61e70fc5f 100644 --- a/samples/browseable/SwipeRefreshLayoutBasic/src/com.example.android.swiperefreshlayoutbasic/MainActivity.java +++ b/samples/browseable/SwipeRefreshLayoutBasic/src/com.example.android.swiperefreshlayoutbasic/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.swiperefreshlayoutbasic; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - SwipeRefreshLayoutBasicFragment fragment = new SwipeRefreshLayoutBasicFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + SwipeRefreshLayoutBasicFragment fragment = new SwipeRefreshLayoutBasicFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/SwipeRefreshListFragment/AndroidManifest.xml b/samples/browseable/SwipeRefreshListFragment/AndroidManifest.xml index be449304e..48f1a8d72 100644 --- a/samples/browseable/SwipeRefreshListFragment/AndroidManifest.xml +++ b/samples/browseable/SwipeRefreshListFragment/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/SwipeRefreshListFragment/_index.jd b/samples/browseable/SwipeRefreshListFragment/_index.jd index 3a34bb032..bbbedf738 100644 --- a/samples/browseable/SwipeRefreshListFragment/_index.jd +++ b/samples/browseable/SwipeRefreshListFragment/_index.jd @@ -1,12 +1,12 @@ - - - page.tags="SwipeRefreshListFragment" sample.group=UI @jd:body -<p>This sample demonstrates how to use {@link android.support.v4.widget.SwipeRefreshLayout} within -{@link android.app.ListFragment} to add the <em>swipe-to-refresh</em> gesture to a -{@link android.widget.ListView}, which enables you to trigger a refresh by swiping down on that -view. This functionality is provided by the <code>SwipeRefreshListFragment</code> class, which you -can reuse.</p> +<p> + + A sample which shows how to use SwipeRefreshLayout within a ListFragment to add the + \'swipe-to-refresh\' gesture to a ListView, enabling the ability to trigger a refresh + from swiping down on that view. This is provided through the re-usable + SwipeRefreshListFragment class. + + </p> diff --git a/samples/browseable/SwipeRefreshListFragment/res/values-v21/template-styles.xml b/samples/browseable/SwipeRefreshListFragment/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SwipeRefreshListFragment/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SwipeRefreshListFragment/res/values/base-strings.xml b/samples/browseable/SwipeRefreshListFragment/res/values/base-strings.xml index f84c807b3..4a327dd0f 100644 --- a/samples/browseable/SwipeRefreshListFragment/res/values/base-strings.xml +++ b/samples/browseable/SwipeRefreshListFragment/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">SwipeRefreshListFragment</string> <string name="intro_message"> diff --git a/samples/browseable/SwipeRefreshListFragment/res/values/strings.xml b/samples/browseable/SwipeRefreshListFragment/res/values/strings.xml index 21bbcaffe..21bbcaffe 100755..100644 --- a/samples/browseable/SwipeRefreshListFragment/res/values/strings.xml +++ b/samples/browseable/SwipeRefreshListFragment/res/values/strings.xml diff --git a/samples/browseable/SwipeRefreshListFragment/src/com.example.android.swiperefreshlistfragment/MainActivity.java b/samples/browseable/SwipeRefreshListFragment/src/com.example.android.swiperefreshlistfragment/MainActivity.java index 7f7a7c8f4..ca3a5bf01 100644 --- a/samples/browseable/SwipeRefreshListFragment/src/com.example.android.swiperefreshlistfragment/MainActivity.java +++ b/samples/browseable/SwipeRefreshListFragment/src/com.example.android.swiperefreshlistfragment/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.swiperefreshlistfragment; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - SwipeRefreshListFragmentFragment fragment = new SwipeRefreshListFragmentFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + SwipeRefreshListFragmentFragment fragment = new SwipeRefreshListFragmentFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/SwipeRefreshMultipleViews/AndroidManifest.xml b/samples/browseable/SwipeRefreshMultipleViews/AndroidManifest.xml index aba15e066..b987db446 100644 --- a/samples/browseable/SwipeRefreshMultipleViews/AndroidManifest.xml +++ b/samples/browseable/SwipeRefreshMultipleViews/AndroidManifest.xml @@ -22,7 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" android:label="@string/app_name" diff --git a/samples/browseable/SwipeRefreshMultipleViews/_index.jd b/samples/browseable/SwipeRefreshMultipleViews/_index.jd index 70ff8ea89..0cc246bb2 100644 --- a/samples/browseable/SwipeRefreshMultipleViews/_index.jd +++ b/samples/browseable/SwipeRefreshMultipleViews/_index.jd @@ -1,12 +1,12 @@ - - - page.tags="SwipeRefreshMultipleViews" sample.group=UI @jd:body -<p>This sample demonstrates how to use {@link android.support.v4.widget.SwipeRefreshLayout} to add -the <em>swipe-to-refresh</em> gesture to a layout with multiple children, which enables you to -trigger a refresh by swiping down on the view. In this sample -{@link android.support.v4.widget.SwipeRefreshLayout} contains a scrollable -{@link android.widget.GridView} with an empty {@link android.widget.TextView}.</p> +<p> + + A sample which shows how to use SwipeRefreshLayout to add the \'swipe-to-refresh\' + gesture to a layout with multiple children, enabling the ability to trigger a + refresh from swiping down on the visible view. In this sample, SwipeRefreshLayout + contains a scrollable GridView, along with a TextView empty view. + + </p> diff --git a/samples/browseable/SwipeRefreshMultipleViews/res/values-v21/template-styles.xml b/samples/browseable/SwipeRefreshMultipleViews/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SwipeRefreshMultipleViews/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SwipeRefreshMultipleViews/res/values/base-strings.xml b/samples/browseable/SwipeRefreshMultipleViews/res/values/base-strings.xml index d7c1c9eb3..f7d434123 100644 --- a/samples/browseable/SwipeRefreshMultipleViews/res/values/base-strings.xml +++ b/samples/browseable/SwipeRefreshMultipleViews/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">SwipeRefreshMultipleViews</string> <string name="intro_message"> diff --git a/samples/browseable/SwipeRefreshMultipleViews/res/values/strings.xml b/samples/browseable/SwipeRefreshMultipleViews/res/values/strings.xml index 991f0e8bd..991f0e8bd 100755..100644 --- a/samples/browseable/SwipeRefreshMultipleViews/res/values/strings.xml +++ b/samples/browseable/SwipeRefreshMultipleViews/res/values/strings.xml diff --git a/samples/browseable/SwipeRefreshMultipleViews/src/com.example.android.swiperefreshmultipleviews/MainActivity.java b/samples/browseable/SwipeRefreshMultipleViews/src/com.example.android.swiperefreshmultipleviews/MainActivity.java index 0191d87de..a8bbf4dda 100644 --- a/samples/browseable/SwipeRefreshMultipleViews/src/com.example.android.swiperefreshmultipleviews/MainActivity.java +++ b/samples/browseable/SwipeRefreshMultipleViews/src/com.example.android.swiperefreshmultipleviews/MainActivity.java @@ -14,9 +14,6 @@ * limitations under the License. */ - - - package com.example.android.swiperefreshmultipleviews; import android.os.Bundle; @@ -50,10 +47,12 @@ public class MainActivity extends SampleActivityBase { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - SwipeRefreshMultipleViewsFragment fragment = new SwipeRefreshMultipleViewsFragment(); - transaction.replace(R.id.sample_content_fragment, fragment); - transaction.commit(); + if (savedInstanceState == null) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + SwipeRefreshMultipleViewsFragment fragment = new SwipeRefreshMultipleViewsFragment(); + transaction.replace(R.id.sample_content_fragment, fragment); + transaction.commit(); + } } @Override diff --git a/samples/browseable/SynchronizedNotifications/Application/AndroidManifest.xml b/samples/browseable/SynchronizedNotifications/Application/AndroidManifest.xml index c46f77298..eb6a1495e 100644 --- a/samples/browseable/SynchronizedNotifications/Application/AndroidManifest.xml +++ b/samples/browseable/SynchronizedNotifications/Application/AndroidManifest.xml @@ -18,7 +18,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.synchronizednotifications" + package="com.example.android.wearable.synchronizednotifications" android:versionCode="1" android:versionName="1.0"> @@ -47,7 +47,7 @@ </intent-filter> <intent-filter> <action - android:name="com.example.android.wearable.synchronizednotifications.DISMISS" /> + android:name="com.example.android.wearable.wearable.synchronizednotifications.DISMISS" /> </intent-filter> </service> </application> diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values-v21/template-styles.xml b/samples/browseable/SynchronizedNotifications/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/SynchronizedNotifications/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/DismissListener.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.wearable.synchronizednotifications/DismissListener.java index 864814845..8d5cca440 100644 --- a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/DismissListener.java +++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.wearable.synchronizednotifications/DismissListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.synchronizednotifications; +package com.example.android.wearable.synchronizednotifications; import static com.google.android.gms.wearable.PutDataRequest.WEAR_URI_SCHEME; @@ -24,7 +24,7 @@ import android.os.Bundle; import android.support.v4.app.NotificationManagerCompat; import android.util.Log; -import com.example.android.synchronizednotifications.common.Constants; +import com.example.android.wearable.synchronizednotifications.common.Constants; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/MainActivity.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.wearable.synchronizednotifications/MainActivity.java index 44b7ff732..994643065 100644 --- a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/MainActivity.java +++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.wearable.synchronizednotifications/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.synchronizednotifications; +package com.example.android.wearable.synchronizednotifications; import android.graphics.Color; import android.os.Bundle; diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/SynchronizedNotificationsFragment.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.wearable.synchronizednotifications/SynchronizedNotificationsFragment.java index 537f81660..240af9b27 100644 --- a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/SynchronizedNotificationsFragment.java +++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.wearable.synchronizednotifications/SynchronizedNotificationsFragment.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.synchronizednotifications; +package com.example.android.wearable.synchronizednotifications; import android.app.PendingIntent; import android.content.Intent; @@ -31,7 +31,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Toast; -import com.example.android.synchronizednotifications.common.Constants; +import com.example.android.wearable.synchronizednotifications.common.Constants; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/samples/browseable/SynchronizedNotifications/Shared/AndroidManifest.xml b/samples/browseable/SynchronizedNotifications/Shared/AndroidManifest.xml index 7235ace4a..5362fc736 100644 --- a/samples/browseable/SynchronizedNotifications/Shared/AndroidManifest.xml +++ b/samples/browseable/SynchronizedNotifications/Shared/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.synchronizednotifications.common"> + package="com.example.android.wearable.synchronizednotifications.common"> <application android:allowBackup="true" android:label="@string/app_name"> diff --git a/samples/browseable/SynchronizedNotifications/Shared/src/com.example.android.synchronizednotifications.common/Constants.java b/samples/browseable/SynchronizedNotifications/Shared/src/com.example.android.wearable.synchronizednotifications.common/Constants.java index 5a45583d5..2e1d46c83 100644 --- a/samples/browseable/SynchronizedNotifications/Shared/src/com.example.android.synchronizednotifications.common/Constants.java +++ b/samples/browseable/SynchronizedNotifications/Shared/src/com.example.android.wearable.synchronizednotifications.common/Constants.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.example.android.synchronizednotifications.common; +package com.example.android.wearable.synchronizednotifications.common; /** * Constants that are used in both the Application and the Wearable modules. @@ -33,5 +33,5 @@ public final class Constants { public static final String KEY_CONTENT = "content"; public static final String ACTION_DISMISS - = "com.example.android.synchronizednotifications.DISMISS"; + = "com.example.android.wearable.synchronizednotifications.DISMISS"; } diff --git a/samples/browseable/SynchronizedNotifications/Wearable/AndroidManifest.xml b/samples/browseable/SynchronizedNotifications/Wearable/AndroidManifest.xml index 97702ce27..b8d5e8538 100644 --- a/samples/browseable/SynchronizedNotifications/Wearable/AndroidManifest.xml +++ b/samples/browseable/SynchronizedNotifications/Wearable/AndroidManifest.xml @@ -17,7 +17,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.synchronizednotifications"> + package="com.example.android.wearable.synchronizednotifications"> <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -46,7 +46,7 @@ </intent-filter> <intent-filter> <action - android:name="com.example.android.synchronizednotifications.DISMISS" /> + android:name="com.example.android.wearable.synchronizednotifications.DISMISS" /> </intent-filter> </service> diff --git a/samples/browseable/SynchronizedNotifications/Wearable/res/values/strings.xml b/samples/browseable/SynchronizedNotifications/Wearable/res/values/strings.xml index 4240ff50e..aa51a71fd 100644 --- a/samples/browseable/SynchronizedNotifications/Wearable/res/values/strings.xml +++ b/samples/browseable/SynchronizedNotifications/Wearable/res/values/strings.xml @@ -15,6 +15,6 @@ --> <resources> - <string name="app_name">Sample Wearable app</string> + <string name="app_name">Synchronized Notifications</string> </resources> diff --git a/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/NotificationUpdateService.java b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.wearable.synchronizednotifications/NotificationUpdateService.java index b8963cd15..8b46bf3ae 100644 --- a/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/NotificationUpdateService.java +++ b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.wearable.synchronizednotifications/NotificationUpdateService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.synchronizednotifications; +package com.example.android.wearable.synchronizednotifications; import static com.google.android.gms.wearable.PutDataRequest.WEAR_URI_SCHEME; @@ -26,7 +26,7 @@ import android.net.Uri; import android.os.Bundle; import android.util.Log; -import com.example.android.synchronizednotifications.common.Constants; +import com.example.android.wearable.synchronizednotifications.common.Constants; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; diff --git a/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/WearableActivity.java b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.wearable.synchronizednotifications/WearableActivity.java index 28736ad9b..6ef2f1bd2 100644 --- a/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/WearableActivity.java +++ b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.wearable.synchronizednotifications/WearableActivity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.example.android.synchronizednotifications; +package com.example.android.wearable.synchronizednotifications; import android.app.Activity; import android.os.Bundle; diff --git a/samples/browseable/TextLinkify/AndroidManifest.xml b/samples/browseable/TextLinkify/AndroidManifest.xml index 49b4eae0b..eb55f205b 100644 --- a/samples/browseable/TextLinkify/AndroidManifest.xml +++ b/samples/browseable/TextLinkify/AndroidManifest.xml @@ -22,9 +22,7 @@ android:versionCode="1" android:versionName="1.0"> - <uses-sdk - android:minSdkVersion="4" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/TextLinkify/_index.jd b/samples/browseable/TextLinkify/_index.jd index 36aa07515..5b4c000b8 100644 --- a/samples/browseable/TextLinkify/_index.jd +++ b/samples/browseable/TextLinkify/_index.jd @@ -1,16 +1,10 @@ - - - page.tags="TextLinkify" sample.group=Views @jd:body -<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.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> -</ul> -</p> +<p> + + This sample illustrates how links can be added to a TextView. This can be done either + automatically by setting the "autoLink" property or explicitly. + + </p> diff --git a/samples/browseable/TextLinkify/res/values-v21/template-styles.xml b/samples/browseable/TextLinkify/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/TextLinkify/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/TextLinkify/res/values/base-strings.xml b/samples/browseable/TextLinkify/res/values/base-strings.xml index f2eb104c4..831f4b2a2 100644 --- a/samples/browseable/TextLinkify/res/values/base-strings.xml +++ b/samples/browseable/TextLinkify/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">TextLinkify</string> <string name="intro_message"> diff --git a/samples/browseable/TextSwitcher/AndroidManifest.xml b/samples/browseable/TextSwitcher/AndroidManifest.xml index 7f512a335..70884cde2 100644 --- a/samples/browseable/TextSwitcher/AndroidManifest.xml +++ b/samples/browseable/TextSwitcher/AndroidManifest.xml @@ -20,9 +20,7 @@ android:versionCode="1" android:versionName="1.0" > - <uses-sdk - android:minSdkVersion="4" - android:targetSdkVersion="17" /> + <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:allowBackup="true" diff --git a/samples/browseable/TextSwitcher/_index.jd b/samples/browseable/TextSwitcher/_index.jd index 0fc5c3254..ddcc042ed 100644 --- a/samples/browseable/TextSwitcher/_index.jd +++ b/samples/browseable/TextSwitcher/_index.jd @@ -1,11 +1,11 @@ - - - page.tags="TextSwitcher" sample.group=UI @jd:body -<p>This sample demonstrates how to use the {@link android.widget.TextSwitcher} -view with animations. A {@link android.widget.TextSwitcher} is a type of -{@link android.widget.ViewSwitcher} that animates text transitions on screen -when {@link android.widget.TextSwitcher#setText(CharSequence)} is called.</p> +<p> + + This sample illustrates the use of a TextSwitcher to display text. + \n\nClick the button below to set new text in the TextSwitcher and observe the + in and out fade animations. + + </p> diff --git a/samples/browseable/TextSwitcher/res/values-v21/template-styles.xml b/samples/browseable/TextSwitcher/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/TextSwitcher/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/TextSwitcher/res/values/base-strings.xml b/samples/browseable/TextSwitcher/res/values/base-strings.xml index 2497e8610..223f06847 100644 --- a/samples/browseable/TextSwitcher/res/values/base-strings.xml +++ b/samples/browseable/TextSwitcher/res/values/base-strings.xml @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - <resources> <string name="app_name">TextSwitcher</string> <string name="intro_message"> diff --git a/samples/browseable/Timer/Application/AndroidManifest.xml b/samples/browseable/Timer/Application/AndroidManifest.xml index b8ebd74be..bd610eb34 100644 --- a/samples/browseable/Timer/Application/AndroidManifest.xml +++ b/samples/browseable/Timer/Application/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.timer"> + package="com.example.android.wearable.timer"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/Timer/Application/res/values-v21/template-styles.xml b/samples/browseable/Timer/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/Timer/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Timer/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/Timer/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/Timer/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/Timer/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/Timer/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/Timer/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/Timer/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/Timer/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/Timer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/Timer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/Timer/Shared/AndroidManifest.xml b/samples/browseable/Timer/Shared/AndroidManifest.xml deleted file mode 100644 index c332a848b..000000000 --- a/samples/browseable/Timer/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.timer.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/Timer/Shared/res/values/strings.xml b/samples/browseable/Timer/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/Timer/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/Timer/Wearable/AndroidManifest.xml b/samples/browseable/Timer/Wearable/AndroidManifest.xml index 3dabadc1d..9e2794744 100644 --- a/samples/browseable/Timer/Wearable/AndroidManifest.xml +++ b/samples/browseable/Timer/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.timer" > + package="com.example.android.wearable.timer" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/SetTimerActivity.java b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/SetTimerActivity.java index 52855891f..f660f9ff1 100644 --- a/samples/browseable/Timer/Wearable/src/com.example.android.timer/SetTimerActivity.java +++ b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/SetTimerActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.timer; +package com.example.android.wearable.timer; import android.app.Activity; import android.app.AlarmManager; @@ -32,8 +32,8 @@ import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.TextView; -import com.example.android.timer.util.Constants; -import com.example.android.timer.util.TimerFormat; +import com.example.android.wearable.timer.util.Constants; +import com.example.android.wearable.timer.util.TimerFormat; /** This class sets a timer. */ public class SetTimerActivity extends Activity implements WearableListView.ClickListener { diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/TimerNotificationService.java b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/TimerNotificationService.java index 709b94921..5822fe410 100644 --- a/samples/browseable/Timer/Wearable/src/com.example.android.timer/TimerNotificationService.java +++ b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/TimerNotificationService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.timer; +package com.example.android.wearable.timer; import android.app.AlarmManager; import android.app.IntentService; @@ -25,7 +25,7 @@ import android.content.Context; import android.content.Intent; import android.util.Log; -import com.example.android.timer.util.Constants; +import com.example.android.wearable.timer.util.Constants; /** * Service class that manages notifications of the timer. diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/WearableListItemLayout.java b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/WearableListItemLayout.java index 739213dbd..0bbc58720 100644 --- a/samples/browseable/Timer/Wearable/src/com.example.android.timer/WearableListItemLayout.java +++ b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/WearableListItemLayout.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.timer; +package com.example.android.wearable.timer; import android.content.Context; import android.graphics.drawable.GradientDrawable; diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/Constants.java b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/util/Constants.java index 18254f1d8..85885e415 100644 --- a/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/Constants.java +++ b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/util/Constants.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.timer.util; +package com.example.android.wearable.timer.util; import android.net.Uri; diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerFormat.java b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/util/TimerFormat.java index b1c1dabc2..b40351ba4 100644 --- a/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerFormat.java +++ b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/util/TimerFormat.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.timer.util; +package com.example.android.wearable.timer.util; /** Helper class to format the timer. Based on com.android.deskclock.timer.CountingTimerView. */ public final class TimerFormat { diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerObj.java b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/util/TimerObj.java index 47f019fbd..52f7244c8 100644 --- a/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerObj.java +++ b/samples/browseable/Timer/Wearable/src/com.example.android.wearable.timer/util/TimerObj.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.timer.util; +package com.example.android.wearable.timer.util; import android.os.SystemClock; diff --git a/samples/browseable/WatchViewStub/Application/AndroidManifest.xml b/samples/browseable/WatchViewStub/Application/AndroidManifest.xml index aa0d790c6..e98a62f12 100644 --- a/samples/browseable/WatchViewStub/Application/AndroidManifest.xml +++ b/samples/browseable/WatchViewStub/Application/AndroidManifest.xml @@ -16,7 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.watchviewstub"> + package="com.example.android.google.wearable.watchviewstub"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> diff --git a/samples/browseable/WatchViewStub/Application/res/values-v21/template-styles.xml b/samples/browseable/WatchViewStub/Application/res/values-v21/template-styles.xml new file mode 100644 index 000000000..134fcd9d3 --- /dev/null +++ b/samples/browseable/WatchViewStub/Application/res/values-v21/template-styles.xml @@ -0,0 +1,22 @@ +<!-- + Copyright 2014 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.Material.Light" /> + +</resources> diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/activities/SampleActivityBase.java deleted file mode 100644 index 3228927b7..000000000 --- a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/activities/SampleActivityBase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* 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/WatchViewStub/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/Log.java deleted file mode 100644 index 17503c568..000000000 --- a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/Log.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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/WatchViewStub/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogFragment.java deleted file mode 100644 index b302acd4b..000000000 --- a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/WatchViewStub/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogNode.java deleted file mode 100644 index bc37cabc0..000000000 --- a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/WatchViewStub/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogView.java deleted file mode 100644 index c01542b91..000000000 --- a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogView.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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/WatchViewStub/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogWrapper.java deleted file mode 100644 index 16a9e7ba2..000000000 --- a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/WatchViewStub/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java deleted file mode 100644 index 19967dcd4..000000000 --- a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/WatchViewStub/Shared/AndroidManifest.xml b/samples/browseable/WatchViewStub/Shared/AndroidManifest.xml deleted file mode 100644 index 846fa9d2e..000000000 --- a/samples/browseable/WatchViewStub/Shared/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?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.watchviewstub.common"> - - <application android:allowBackup="true" - android:label="@string/app_name"> - </application> - -</manifest> diff --git a/samples/browseable/WatchViewStub/Shared/res/values/strings.xml b/samples/browseable/WatchViewStub/Shared/res/values/strings.xml deleted file mode 100644 index 0f2bb9075..000000000 --- a/samples/browseable/WatchViewStub/Shared/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2014 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">Shared</string> -</resources> diff --git a/samples/browseable/WatchViewStub/Wearable/AndroidManifest.xml b/samples/browseable/WatchViewStub/Wearable/AndroidManifest.xml index 5b3304491..baa3f7853 100644 --- a/samples/browseable/WatchViewStub/Wearable/AndroidManifest.xml +++ b/samples/browseable/WatchViewStub/Wearable/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.watchviewstub" > + package="com.example.android.google.wearable.watchviewstub" > <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" /> @@ -28,7 +28,7 @@ android:label="@string/app_name" android:theme="@android:style/Theme.DeviceDefault"> <activity - android:name="com.example.android.watchviewstub.MainActivity" + android:name="com.example.android.google.wearable.watchviewstub.MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> diff --git a/samples/browseable/WatchViewStub/Wearable/src/com.example.android.watchviewstub/MainActivity.java b/samples/browseable/WatchViewStub/Wearable/src/com.example.android.google.wearable.watchviewstub/MainActivity.java index 1e931dc23..e4271d24b 100644 --- a/samples/browseable/WatchViewStub/Wearable/src/com.example.android.watchviewstub/MainActivity.java +++ b/samples/browseable/WatchViewStub/Wearable/src/com.example.android.google.wearable.watchviewstub/MainActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.watchviewstub; +package com.example.android.google.wearable.watchviewstub; import android.app.Activity; import android.os.Bundle; |