• 大小: 2.68M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2020-12-23
  • 标签: 地图  计步器    

资源简介

/*
 *  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.xml
     目录           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.xml
     目录           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$style.class
     文件        6541  2015-03-27 14:49  pedometerDemo\bin\classes\android\support\v7\appcompat\R$styleable.class
     文件        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个文件信息

评论

共有 条评论