diff options
Diffstat (limited to 'samples/browseable/BatchStepSensor')
26 files changed, 121 insertions, 92 deletions
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; |
