资源简介
/*
* Pedometer - Android App
* Copyright (C) 2009 Levente Bagi
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package name.bagi.levente.pedometer;
import com.google.tts.TTS;
/**
* Calculates and displays pace (steps / minute), handles input of desired pace,
* notifies user if he/she has to go faster or slower.
*
* Uses {@link PaceNotifier}, calculates speed as product of pace and step length.
*
* @author Levente Bagi
*/
public class SpeedNotifier implements PaceNotifier.Listener, SpeakingTimer.Listener {
public interface Listener {
public void valueChanged(float value);
public void passValue();
}
private Listener mListener;
int mCounter = 0;
float mSpeed = 0;
boolean mIsMetric;
float mStepLength;
PedometerSettings mSettings;
TTS mTts;
/** Desired speed, adjusted by the user */
float mDesiredSpeed;
/** Should we speak? */
boolean mShouldTellFasterslower;
boolean mShouldTellSpeed;
/** When did the TTS speak last time */
private long mSpokenAt = 0;
public SpeedNotifier(Listener listener, PedometerSettings settings, TTS tts) {
mListener = listener;
mTts = tts;
mSettings = settings;
mDesiredSpeed = mSettings.getDesiredSpeed();
reloadSettings();
}
public void setSpeed(float speed) {
mSpeed = speed;
notifyListener();
}
public void reloadSettings() {
mIsMetric = mSettings.isMetric();
mStepLength = mSettings.getStepLength();
mShouldTellSpeed = mSettings.shouldTellSpeed();
mShouldTellFasterslower =
mSettings.shouldTellFasterslower()
&& mSettings.getMaintainOption() == PedometerSettings.M_SPEED;
notifyListener();
}
public void setTts(TTS tts) {
mTts = tts;
}
public void setDesiredSpeed(float desiredSpeed) {
mDesiredSpeed = desiredSpeed;
}
private void notifyListener() {
mListener.valueChanged(mSpeed);
}
@Override
public void paceChanged(int value) {
if (mIsMetric) {
mSpeed = // kilometers / hour
value * mStepLength // centimeters / minute
/ 100000f * 60f; // centimeters/kilometer
}
else {
mSpeed = // miles / hour
value * mStepLength // inches / minute
/ 63360f * 60f; // inches/mile
}
tellFasterSlower();
notifyListener();
}
/**
* Say slower/faster, if needed.
*/
private void tellFasterSlower() {
if (mShouldTellFasterslower && mTts != null) {
long now = System.currentTimeMillis();
if (now - mSpokenAt > 3000 && !mTts.isSpeaking()) {
float little = 0.10f;
float normal = 0.30f;
float much = 0.50f;
boolean spoken = true;
if (mSpeed < mDesiredSpeed * (1 - much)) {
mTts.speak("much faster!", 0, null);
}
else
if (mSpeed > mDesiredSpeed * (1 much)) {
mTts.speak("much slower!", 0, null);
}
else
if (mSpeed < mDesiredSpeed * (1 - normal)) {
mTts.speak("faster!", 0, null);
}
else
if (mSpeed > mDesiredSpeed * (1 normal)) {
mTts.speak("slower!", 0, null);
}
else
if (mSpeed < mDesiredSpeed * (1 - little)) {
mTts.speak("a little faster!", 0, null);
}
else
if (mSpeed > mDesiredSpeed * (1 little)) {
mTts.speak("a little slower!", 0, null);
}
else {
spoken = false;
}
if (spoken) {
mSpokenAt = now;
}
}
}
}
public void passValue() {
// Not used
}
@Override
public void speak() {
if (mSettings.shouldTellSpeed() && mTts != null) {
if (mSpeed >= .01f) {
mTts.speak(("" (mSpeed 0.000001f)).substring(0, 4) (mIsMetric ? " kilometers per hour" : " miles per hour"), 1, null);
}
}
}
}
* Pedometer - Android App
* Copyright (C) 2009 Levente Bagi
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package name.bagi.levente.pedometer;
import com.google.tts.TTS;
/**
* Calculates and displays pace (steps / minute), handles input of desired pace,
* notifies user if he/she has to go faster or slower.
*
* Uses {@link PaceNotifier}, calculates speed as product of pace and step length.
*
* @author Levente Bagi
*/
public class SpeedNotifier implements PaceNotifier.Listener, SpeakingTimer.Listener {
public interface Listener {
public void valueChanged(float value);
public void passValue();
}
private Listener mListener;
int mCounter = 0;
float mSpeed = 0;
boolean mIsMetric;
float mStepLength;
PedometerSettings mSettings;
TTS mTts;
/** Desired speed, adjusted by the user */
float mDesiredSpeed;
/** Should we speak? */
boolean mShouldTellFasterslower;
boolean mShouldTellSpeed;
/** When did the TTS speak last time */
private long mSpokenAt = 0;
public SpeedNotifier(Listener listener, PedometerSettings settings, TTS tts) {
mListener = listener;
mTts = tts;
mSettings = settings;
mDesiredSpeed = mSettings.getDesiredSpeed();
reloadSettings();
}
public void setSpeed(float speed) {
mSpeed = speed;
notifyListener();
}
public void reloadSettings() {
mIsMetric = mSettings.isMetric();
mStepLength = mSettings.getStepLength();
mShouldTellSpeed = mSettings.shouldTellSpeed();
mShouldTellFasterslower =
mSettings.shouldTellFasterslower()
&& mSettings.getMaintainOption() == PedometerSettings.M_SPEED;
notifyListener();
}
public void setTts(TTS tts) {
mTts = tts;
}
public void setDesiredSpeed(float desiredSpeed) {
mDesiredSpeed = desiredSpeed;
}
private void notifyListener() {
mListener.valueChanged(mSpeed);
}
@Override
public void paceChanged(int value) {
if (mIsMetric) {
mSpeed = // kilometers / hour
value * mStepLength // centimeters / minute
/ 100000f * 60f; // centimeters/kilometer
}
else {
mSpeed = // miles / hour
value * mStepLength // inches / minute
/ 63360f * 60f; // inches/mile
}
tellFasterSlower();
notifyListener();
}
/**
* Say slower/faster, if needed.
*/
private void tellFasterSlower() {
if (mShouldTellFasterslower && mTts != null) {
long now = System.currentTimeMillis();
if (now - mSpokenAt > 3000 && !mTts.isSpeaking()) {
float little = 0.10f;
float normal = 0.30f;
float much = 0.50f;
boolean spoken = true;
if (mSpeed < mDesiredSpeed * (1 - much)) {
mTts.speak("much faster!", 0, null);
}
else
if (mSpeed > mDesiredSpeed * (1 much)) {
mTts.speak("much slower!", 0, null);
}
else
if (mSpeed < mDesiredSpeed * (1 - normal)) {
mTts.speak("faster!", 0, null);
}
else
if (mSpeed > mDesiredSpeed * (1 normal)) {
mTts.speak("slower!", 0, null);
}
else
if (mSpeed < mDesiredSpeed * (1 - little)) {
mTts.speak("a little faster!", 0, null);
}
else
if (mSpeed > mDesiredSpeed * (1 little)) {
mTts.speak("a little slower!", 0, null);
}
else {
spoken = false;
}
if (spoken) {
mSpokenAt = now;
}
}
}
}
public void passValue() {
// Not used
}
@Override
public void speak() {
if (mSettings.shouldTellSpeed() && mTts != null) {
if (mSpeed >= .01f) {
mTts.speak(("" (mSpeed 0.000001f)).substring(0, 4) (mIsMetric ? " kilometers per hour" : " miles per hour"), 1, null);
}
}
}
}
代码片段和文件信息
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package android.support.v7.appcompat;
public final class R {
public static final class anim {
public static final int abc_fade_in = 0x7f040000;
public static final int abc_fade_out = 0x7f040001;
public static final int abc_slide_in_bottom = 0x7f040002;
public static final int abc_slide_in_top = 0x7f040003;
public static final int abc_slide_out_bottom = 0x7f040004;
public static final int abc_slide_out_top = 0x7f040005;
}
public static final class attr {
public static final int actionBarDivider = 0x7f01000f;
public static final int actionBarItemBackground = 0x7f010010;
public static final in
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 189504 2016-11-07 22:43 pedometer.zip
目录 0 2015-03-27 14:50 pedometerDemo\
文件 475 2015-03-27 11:37 pedometerDemo\.classpath
文件 849 2015-03-27 11:37 pedometerDemo\.project
目录 0 2015-03-27 14:50 pedometerDemo\.settings\
文件 177 2015-03-27 11:37 pedometerDemo\.settings\org.eclipse.jdt.core.prefs
文件 953 2015-03-27 11:44 pedometerDemo\AndroidManifest.xm
目录 0 2015-03-27 11:37 pedometerDemo\assets\
目录 0 2015-03-27 14:50 pedometerDemo\bin\
文件 953 2015-03-27 13:56 pedometerDemo\bin\AndroidManifest.xm
目录 0 2015-03-27 14:50 pedometerDemo\bin\classes\
文件 1544584 2015-03-27 14:49 pedometerDemo\bin\classes.dex
目录 0 2015-03-27 14:50 pedometerDemo\bin\classes\android\
目录 0 2015-03-27 14:50 pedometerDemo\bin\classes\android\support\
目录 0 2015-03-27 14:50 pedometerDemo\bin\classes\android\support\v7\
目录 0 2015-03-27 14:50 pedometerDemo\bin\classes\android\support\v7\appcompat\
文件 629 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$anim.class
文件 5136 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$attr.class
文件 763 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$bool.class
文件 594 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$color.class
文件 1530 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$dimen.class
文件 5191 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$drawable.class
文件 2556 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$id.class
文件 445 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$integer.class
文件 1629 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$layout.class
文件 1141 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$string.class
文件 9582 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$st
文件 6541 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R$st
文件 1015 2015-03-27 14:49 pedometerDemo\bin\classes\android\support\v7\appcompat\R.class
目录 0 2015-03-27 14:50 pedometerDemo\bin\classes\com\
目录 0 2015-03-27 14:50 pedometerDemo\bin\classes\com\example\
............此处省略85个文件信息
相关资源
- 仿赶集生活android客户端的介绍启动界
- android不错的下拉刷新效果(支持各种
- android 应用启动的时弹出的悬浮带有关
- android 点赞+1效果
- UI设计实现右侧类似抽屉画出的效果
- 一个简单的项目框架
- Android webView和js交互的Demo
- 读取SIM卡联系人相关文件的信息,包
- 带自定义编辑功能的头像设置
- 仿Siri的中文语音助理源码
- Android手机的VoIP客户端Sipdroid
- Fragment的demo 很好的
- 自定义弹出的对话框
- 百度地图官方API
- 横屏的可扩展ListView
- 可扩展的ListView
-
android的fr
amework简介 - android入门视频 - sql语句实现数据库的增删改查 - andr
- android Listview圆角的实现方案
- 自定义侧滑栏的菜单
- 缓存的计算清除
- Android侧滑功能的实现
- 固定头部的listview
- Androidxutils的数据库增删改查带自动更
- 按钮点击的水波纹效果
- android 带删除按钮的输入框
- 主要用于安卓电子书的翻页效果
- WebView开发浏览带FLASH的网页
- Android 使用百度地图定位自己的位置(
- Android 可以每日签到的日历表(Andro
评论
共有 条评论