上海出租车价格计算器
来源:互联网 发布:广州增城积分计算法 编辑:程序博客网 时间:2024/04/26 17:31
每次查到路线后都想知道打车多少钱,就写了个小小apk,方便些。就是知道从哪到哪多少公里,想知道打车要多少钱。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.taxipricecaculator" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.taxipricecaculator.TaxtPriceCaculator" android:label="@string/app_name" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
主类:TaxtPriceCaculator.java
package com.example.taxipricecaculator;import android.os.Bundle;import android.app.Activity;import android.text.Editable;import android.text.TextWatcher;import android.text.method.ScrollingMovementMethod;import android.view.Menu;import android.widget.Button;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.EditText;import android.widget.Switch;import android.widget.TextView;public class TaxtPriceCaculator extends Activity {private final int BASE_MILES = 3;private final int BASE_MILES_LONG = 10;private final int BASE_PRICE = 14;private static final float PRICE_PER = (float) 2.4;private static final float PRICE_PER_EXTRA = (float) 3.6;private final int BASE_PRICE_NIGHT = 18;private static final float PRICE_PER_NIGHT = (float) 3.1;private static final float PRICE_PER_EXTRA_NIGHT = (float) 4.7;private EditText mMilesInput;private Button mDisplayPrice;private Switch mAddFeeMode;private TextView mIntroduction;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_taxt_price_caculator);findViewById();addListener();init();}private void init() {mIntroduction.setMovementMethod(ScrollingMovementMethod.getInstance());}private void findViewById() {mMilesInput = (EditText) this.findViewById(R.id.mileage_input);mDisplayPrice = (Button) this.findViewById(R.id.price_display);mAddFeeMode = (Switch) this.findViewById(R.id.switch_day_night_modes);mIntroduction = (TextView) this.findViewById(R.id.info);}private void addListener() {// TODO Auto-generated method stubmMilesInput.addTextChangedListener(new TextWatcher(){@Overridepublic void afterTextChanged(Editable s) {// TODO Auto-generated method stubfloat miles = 0;try {miles = Float.parseFloat(s.toString().trim());} catch (NumberFormatException e) {// TODO Auto-generated catch blocke.printStackTrace();}mDisplayPrice.setText(CaculateFee(miles, mAddFeeMode.isChecked()) + "");}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {// TODO Auto-generated method stub}@Overridepublic void onTextChanged(CharSequence s, int start, int before,int count) {// TODO Auto-generated method stub}});mAddFeeMode.setOnCheckedChangeListener(new OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {int miles = 0;try {miles = Integer.parseInt(mMilesInput.getText().toString().trim());} catch (NumberFormatException e) {// TODO Auto-generated catch blocke.printStackTrace();}mDisplayPrice.setText(CaculateFee(miles, mAddFeeMode.isChecked()) + "");}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.taxt_price_caculator, menu);return true;}private float CaculateFee(float miles, boolean night_mode){if(!night_mode){if(miles < BASE_MILES){return BASE_PRICE;}else if (miles > BASE_MILES && miles <= BASE_MILES_LONG){return (BASE_PRICE + (miles - BASE_MILES) * PRICE_PER);}else if(miles > BASE_MILES_LONG){return (float) (BASE_PRICE + (BASE_MILES_LONG - BASE_MILES) * PRICE_PER + (miles - BASE_MILES_LONG) * PRICE_PER_EXTRA);}}else{if(miles <= BASE_MILES){return BASE_PRICE_NIGHT;}else if (miles > BASE_MILES && miles <= BASE_MILES_LONG){return (BASE_PRICE_NIGHT + (miles - BASE_MILES) * PRICE_PER_NIGHT);}else if(miles > BASE_MILES_LONG){return (float) (BASE_PRICE_NIGHT + (BASE_MILES_LONG - BASE_MILES) * PRICE_PER_NIGHT + (miles - BASE_MILES_LONG) * PRICE_PER_EXTRA_NIGHT);}}return -1;}}
layout文件activity_taxt_price_caculator.xml
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".TaxtPriceCaculator" > <LinearLayout android:id="@+id/group_mileage" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/mileage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/label_mileage" /> <EditText android:id="@+id/mileage_input" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="number" android:ems="6" android:singleLine="true"/> <TextView android:id="@+id/mileage_unit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/label_mileage_unit" /> </LinearLayout> <LinearLayout android:id="@+id/group_price" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/group_mileage" > <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/label_price" /> <Button android:id="@+id/price_display" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="6" /> <TextView android:id="@+id/price_unit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/label_price_unit" /> </LinearLayout><Switch android:id="@+id/switch_day_night_modes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/group_price" android:text="@string/night_mode" android:layout_marginBottom="20dip" /><TextView android:id="@+id/info_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/intrduction_title" android:layout_below="@+id/switch_day_night_modes"/><TextView android:id="@+id/info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/intrduction" android:layout_below="@+id/info_title" android:maxLines="10" android:scrollbars="vertical"/></RelativeLayout>
资源文件:strings.xml
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">TaxiPriceCaculator2</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello</string> <string name="label_mileage">"Miles:"</string><string name="label_mileage_unit">Km</string><string name="label_price">"Price:"</string><string name="label_price_unit">RMB</string><string name="night_mode">"During 23:00–05:00"</string><string name="intrduction_title">"上海出租车价格计算方法:"</string><string name="intrduction">"一般状况:车价=起步价【14元】+(里程数 - 起步里程数【3公里】)*每公里单价【2.4元】 (里程数大于3小于10) \n 车价=起步价【14元】 (里程数小于3) \n远程状况:车价=起步价【14元】+(远程里程标准【10公里】 - 起步里程数【3公里】)*每公里单价 + (里程数 - 远程里程标准【10】) *远程每公里单价【3.6元】 (里程数大于10)\n提醒:在5:00---23:00期间,起步费14元(包括一元的燃油费),可运营3公里,超过3公里后每公里2.40元,总里程超过10公里后超过部分按每公里3.60元计算。 \n在23:00---到次日5:00期间,起步费18元(包括一元的燃油费),可运营3公里,超过3公里后每公里3.10元,总里程超过10公里后超过部分按每公里4.70元计算。"</string></resources>
0 0
- 上海出租车价格计算器
- 上海出租车价格计算方法
- 上海出租车电话一览表
- 四川绵阳出租车价格收费标准
- 上海出租车是如何计费的?
- 上海卡拉OK价格图
- 上海代孕产子价格
- 上海个人所得税计算器
- 出租车
- 出租车
- sgh i900水货评测-上海报价,价格
- 上海二手挖掘机市场,二手挖掘机价格优惠
- VUE做的价格计算器.html
- 触动传媒总部人去楼空 上海多家出租车公司追讨欠款
- 上海女大学生包养价格内幕 真相终于大白!
- 上海部分小区地下车位价格翻倍升至70万-车位-价格
- 上海部分小区地下车位价格翻倍升至70万-车位-价格
- 上海部分小区地下车位价格翻倍升至70万-车位-价格
- 自定义公式解析问题
- 漏洞分析---gotofail:苹果 SSL/TLS 重大安全漏洞的细节
- LeetCode Remove Duplicates from Sorted List II
- C++面试出现频率最高的30道题目(一)
- 将字符串转换成整数
- 上海出租车价格计算器
- hdu2594 Simpsons’ Hidden Talents(KMP,前后缀)
- C#结构体中数组的分配
- ubuntu触摸板失灵解决
- vs2012 wp8 应用调试时报错 指定的通信资源(端口) 已由另一个应用程序使
- 证明四点共圆
- spring MVC配置详解
- 电脑眼睛保护色——绿豆沙色
- OTT盒子登堂入室引爆客厅入口之争