my first compelte android application

这是一个简单的BMI计算器应用程序源代码,使用Java编写并针对Android平台。该应用允许用户输入身高和体重,然后计算并显示BMI指数及健康建议。

 

bmi.java file content:

package com.demo.android.bmi;

import java.text.DecimalFormat;

import android.app.Activity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.view.View;

public class bmi extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Button button=(Button)findViewById(R.id.submit);
        button.setOnClickListener(calcBMI);
    }

private OnClickListener calcBMI=new OnClickListener()
{
    public void onClick(View v)
    {
        DecimalFormat nf=new DecimalFormat("0.00");
        EditText fieldheight=(EditText)findViewById(R.id.height);
        EditText fieldweight=(EditText)findViewById(R.id.weight);
        double height=Double.parseDouble(fieldheight.getText().toString())/100;
        double weight=Double.parseDouble(fieldweight.getText().toString());
       
        double bmi=weight/(height*height);
       
        TextView result =(TextView)findViewById(R.id.result);
        result.setText("Your bmi is "+nf.format(bmi));
       
        TextView suggest =(TextView)findViewById(R.id.suggest);
        if(bmi>25)
        suggest.setText(R.string.advice_heavy);
        else if(bmi<20)
            suggest.setText(R.string.advice_light);
        else suggest.setText(R.string.advice_average);
       
       
    }
};
}

main.xml file content:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/height"
    />
 <EditText android:id="@+id/height"
 android:layout_width="fill_parent"
  android:layout_height="wrap_content"
 android:numeric="integer"
 android:text=""
 />
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/weight"
    />
 <EditText android:id="@+id/weight"
 android:layout_width="fill_parent"
  android:layout_height="wrap_content"
 android:numeric="integer"
 android:text=""
 />
 <Button
 android:id="@+id/submit"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="计算 BIM 值"
 />
 <TextView android:id="@+id/result"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text=""
    />
    <TextView android:id="@+id/suggest"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text=""
    />
</LinearLayout>

string.xml content:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, bmi!</string>
    <string name="app_name">bmi</string>
    <string name="height">身高(CM)</string>
    <string name="weight">体重(Kg)</string>
</resources>
advice.xml content:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="advice_light">you should eat more!</string>
<string name="advice_average">you have good healthy</string>
<string name="advice_heavy">you should have a diet</string>
</resources>

public void MoveDone(int moveID, int matID) { CompleteMove completeMove = null; lock (this.mMoveList) { foreach (MoveWrapper moveWrapper in this.mMoveList) // 遍历mMoveList,查找moveID匹配的moveWrapper对象 { if (moveID != moveWrapper.SchMove.MoveID) { continue; } // found the move <> this.mMoveList.Remove(moveWrapper); // 匹配,移除已经完成的动作 completeMove = moveWrapper.SchMove as CompleteMove; // keep the done move if it is a CompleteMove // 发布MoveDone事件,通知系统移动操作已经完成 Notifier.GetIns().PostEvent(CoordinatorEvents.MoveDone, new CoordEventArgs(moveWrapper), string.Format("MoveManager::MoveDone({0}, {1})", moveID, matID)); // 存在待处理移动列表mPendingMoves,移除已完成的移动操作。如果所有待处理移动都已完成,发布 PendingMovesDone 事件,并记录日志。 if (this.mPendingMoves != null && this.mPendingMoves.Contains(moveWrapper.SchMove)) { this.mPendingMoves.Remove(moveWrapper.SchMove); if (this.mPendingMoves.Count == 0) { this.mPendingMoves = null; Notifier.GetIns().PostEvent(CoordinatorEvents.PendingMovesDone, null, string.Format("MoveManager::MoveDone({0}, {1})", moveID, matID)); Coordinator.GetIns().GetLogger().WarnFormat("MoveManager::MoveDone(): Trigger 'PendingMovesDone' for all pending moves DONE."); } } break; } } lock (TaskManager.GetIns().TaskList) { lock (this.mMaterials) { if (completeMove != null) { matID = completeMove.PreMove.MatID; // override matID for CompleteMove } if (!this.mMaterials.ContainsKey(matID)) { return; // no such material mMaterials中不存在matID对应的物料,直接返回 } // 更新物料状态 MaterialWrapper specifiedMat = (MaterialWrapper)this.mMaterials[matID]; // 如果物料不在源站且未离开源站,并且满足某些条件,调用CheckAllLeftSrc if (specifiedMat.Source != specifiedMat.StationName && !specifiedMat.LeftSrc && (!ModuleManager.GetIns().Robots.ContainsKey(specifiedMat.StationName) || !specifiedMat.IsFromPureJob) /*<><>yangy 20160416: trigger pipeline after on-arm-mat placed from PURE-JOB (except manual move)<><>*/) { //this.UpdateMatLeftSrc(specifiedMat); // material left source on first time <> if (completeMove != null) { return; } specifiedMat.LeftSrc = true; this.CheckAllLeftSrc(specifiedMat, specifiedMat.TaskID); } // 如果物料离开源站并且现在是目标站,根据 completeMove 的存在与否,更新 specifiedMat 的状态 if (specifiedMat.LeftSrc && specifiedMat.Destination == specifiedMat.StationName) //&& completeMove != null) // <><><> yangy 20150617: for individual LP CompleteMove after place mat back to dest LP { //this.UpdateMatInDest(specifiedMat); // material in dest if (completeMove == null) { specifiedMat.InDest = true; // update pos info specifiedMat.NeedSchedule = false; // in dest, so no need schedule } else if (specifiedMat.InDest && !specifiedMat.NeedSchedule) { if ((completeMove.Station == specifiedMat.Destination) || (!specifiedMat.IsFromPureJob)) // xianghf_20240227, AP300 LB pumpdown issue after LB door close compelte, only after LL CompleteMove need CheckAllInDest { // only LoadPort's 'completeMove' can trigger CheckAllInDest() // this.CheckAllInDest(specifiedMat, specifiedMat.TaskID); // <><><> yangy 20160422: lock 'TaskManager::mTaskList' inside } } } } } }详细解释 lock (TaskManager.GetIns().TaskList)里面的内容
09-02
public void MoveDone(int moveID, int matID) { CompleteMove completeMove = null; lock (this.mMoveList) { foreach (MoveWrapper moveWrapper in this.mMoveList) // 遍历mMoveList,查找moveID匹配的moveWrapper对象 { if (moveID != moveWrapper.SchMove.MoveID) { continue; } // found the move <> this.mMoveList.Remove(moveWrapper); // 匹配,移除已经完成的动作 completeMove = moveWrapper.SchMove as CompleteMove; // keep the done move if it is a CompleteMove // 发布MoveDone事件,通知系统移动操作已经完成 Notifier.GetIns().PostEvent(CoordinatorEvents.MoveDone, new CoordEventArgs(moveWrapper), string.Format("MoveManager::MoveDone({0}, {1})", moveID, matID)); // 存在待处理移动列表mPendingMoves,移除已完成的移动操作。如果所有待处理移动都已完成,发布 PendingMovesDone 事件,并记录日志。 if (this.mPendingMoves != null && this.mPendingMoves.Contains(moveWrapper.SchMove)) { this.mPendingMoves.Remove(moveWrapper.SchMove); if (this.mPendingMoves.Count == 0) { this.mPendingMoves = null; Notifier.GetIns().PostEvent(CoordinatorEvents.PendingMovesDone, null, string.Format("MoveManager::MoveDone({0}, {1})", moveID, matID)); Coordinator.GetIns().GetLogger().WarnFormat("MoveManager::MoveDone(): Trigger 'PendingMovesDone' for all pending moves DONE."); } } break; } } lock (TaskManager.GetIns().TaskList) { lock (this.mMaterials) { if (completeMove != null) { matID = completeMove.PreMove.MatID; // override matID for CompleteMove } if (!this.mMaterials.ContainsKey(matID)) { return; // no such material mMaterials中不存在matID对应的物料,直接返回 } // 更新物料状态 MaterialWrapper specifiedMat = (MaterialWrapper)this.mMaterials[matID]; // 如果物料不在源站且未离开源站,并且满足某些条件,调用CheckAllLeftSrc if (specifiedMat.Source != specifiedMat.StationName && !specifiedMat.LeftSrc && (!ModuleManager.GetIns().Robots.ContainsKey(specifiedMat.StationName) || !specifiedMat.IsFromPureJob) /*<><>yangy 20160416: trigger pipeline after on-arm-mat placed from PURE-JOB (except manual move)<><>*/) { //this.UpdateMatLeftSrc(specifiedMat); // material left source on first time <> if (completeMove != null) { return; } specifiedMat.LeftSrc = true; this.CheckAllLeftSrc(specifiedMat, specifiedMat.TaskID); } // 如果物料离开源站并且现在是目标站,根据 completeMove 的存在与否,更新 specifiedMat 的状态 if (specifiedMat.LeftSrc && specifiedMat.Destination == specifiedMat.StationName) //&& completeMove != null) // <><><> yangy 20150617: for individual LP CompleteMove after place mat back to dest LP { //this.UpdateMatInDest(specifiedMat); // material in dest if (completeMove == null) { specifiedMat.InDest = true; // update pos info specifiedMat.NeedSchedule = false; // in dest, so no need schedule } else if (specifiedMat.InDest && !specifiedMat.NeedSchedule) { if ((completeMove.Station == specifiedMat.Destination) || (!specifiedMat.IsFromPureJob)) // xianghf_20240227, AP300 LB pumpdown issue after LB door close compelte, only after LL CompleteMove need CheckAllInDest { // only LoadPort's 'completeMove' can trigger CheckAllInDest() // this.CheckAllInDest(specifiedMat, specifiedMat.TaskID); // <><><> yangy 20160422: lock 'TaskManager::mTaskList' inside } } } } } }详细解释 lock (TaskManager.GetIns().TaskList)里面的内容
09-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值