Update browseable samples for lmp-docs
Synced to commit df5e5013422b81b4fd05c0ac9fd964b13624847a. Includes new samples for Android Auto. Change-Id: I3fec46e2a6b3f196682a92f1afd91eb682dc2dc1
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
<color name="card_action_positive_ripple">#CCA0CC00</color>
|
||||
</resources>
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
import android.animation.Animator;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
public interface CardStream {
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
import android.animation.Animator;
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
package com.example.android.batchstepsensor.cardstream;
|
||||
|
||||
public interface OnCardClickListener {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user