package net.kazhik.android.tokyorunners;
-import java.util.ArrayList;
import java.util.Date;
+import java.util.Iterator;
-import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
+import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
-import android.net.Uri;
+import android.media.AudioManager;
+import android.media.ToneGenerator;
import android.os.Bundle;
+import android.os.Debug;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.util.Log;
-import android.view.GestureDetector;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.ListView;
+import android.widget.TabHost;
import android.widget.TextView;
-import com.google.android.maps.GeoPoint;
+public class TokyoRunners extends TabActivity implements LocationListener {
-
-public class TokyoRunners extends Activity implements
- LocationListener, GestureDetector.OnDoubleTapListener, GestureDetector.OnGestureListener {
-
private SharedPreferences m_prefs;
private LocationManager m_locMgr;
private Chronometer m_elapsedTime;
private Chronometer m_lapTime;
private boolean m_running = false;
-
+
private boolean m_useGPS = false;
private boolean m_autosplit = false;
+
+ private static RunningRecord m_runningRecord;
- private GestureDetector m_gestureDetector;
-
- private RunningRecord m_runningRecord;
-
- class StartStopButton implements OnClickListener {
+ private static final int m_minAccuracy = 200;
+
+ class StartStopButton implements OnClickListener {
public void onClick(View v) {
if (m_running == true) {
stop();
start();
}
}
- };
- class ResetLapButton implements OnClickListener {
+ };
+
+ class ResetLapButton implements OnClickListener {
public void onClick(View v) {
if (m_running == true) {
lap();
reset();
}
}
- };
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- m_gestureDetector = new GestureDetector(this, this);
-
- if (m_gestureDetector.isLongpressEnabled() == false) {
- Log.d(this.getClass().getName(), "Longpress disabled");
- } else {
- Log.d(this.getClass().getName(), "Longpress enabled");
- }
- setContentView(R.layout.stopwatch);
-
- m_runningRecord = new RunningRecord(getContentResolver());
-
- m_prefs = PreferenceManager.getDefaultSharedPreferences(this);
- m_useGPS = m_prefs.getBoolean("use_gps", true);
- if (m_useGPS) {
- m_locMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
-
- m_autosplit = m_prefs.getBoolean("auto_split", false);
- if (m_autosplit) {
- int interval = Integer.parseInt(m_prefs.getString("split_interval", "5"));
- m_runningRecord.setSplitInterval(interval);
-
- }
-
- }
-
- m_elapsedTime = (Chronometer)findViewById(R.id.elapsed_time);
- m_lapTime = (Chronometer)findViewById(R.id.lap_time);
-
- Button btnStartStop = (Button)findViewById(R.id.button_start_stop);
- btnStartStop.setOnClickListener(new StartStopButton());
-
- Button btnResetLap = (Button)findViewById(R.id.button_reset_lap);
- btnResetLap.setOnClickListener(new ResetLapButton());
-
- ListView lvLaptime = (ListView)findViewById(R.id.lap_history);
- ArrayAdapter<String> arrayAdapter
- = new ArrayAdapter<String>(this, R.layout.laptime);
- lvLaptime.setAdapter(arrayAdapter);
-
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
-
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
-
- switch (requestCode) {
- case Constants.REQUEST_CODE_SETTINGS:
- m_useGPS = m_prefs.getBoolean("use_gps", true);
- m_autosplit = m_prefs.getBoolean("auto_split", false);
- break;
- case Constants.REQUEST_CODE_HISTORY:
- if (data != null) {
- long selectedStartTime = data.getLongExtra("startTime", 0);
- readHistory(selectedStartTime);
- }
- break;
- }
- }
-
- private void readHistory(long startTime) {
-
- Uri uri = Uri.parse(
- "content://net.kazhik.android.tokyorunners.runningrecordprovider/runningrecords");
- String[] columns = {
- RunningRecordProvider.CURRENT_TIME,
- RunningRecordProvider.LATITUDE,
- RunningRecordProvider.LONGITUDE};
- String selection = RunningRecordProvider.START_TIME + " = ?";
- String[] selectionArgs = {Long.toString(startTime)};
- String sortOrder = RunningRecordProvider.CURRENT_TIME + " desc";
- Cursor cursor = managedQuery(uri, columns, selection, selectionArgs, sortOrder);
- if (cursor == null) {
- return;
- }
-
- reset();
- ListView listLaptime = (ListView)findViewById(R.id.lap_history);
- ArrayAdapter<String> lapHistory = (ArrayAdapter<String>)listLaptime.getAdapter();
-
- ArrayList<String> history = new ArrayList<String>();
- long currentTime = 0;
- int latitude = 0;
- int longitude = 0;
- long prevTime = startTime;
-
- TextView elapsedTimeView = (TextView)findViewById(R.id.elapsed_time);
- TextView lapTimeView = (TextView)findViewById(R.id.lap_time);
- TextView distanceView = (TextView)findViewById(R.id.distance);
-
- String laptimeLabel = "";
- String laptimeValue = "";
- while (cursor.moveToNext()) {
- currentTime = cursor.getLong(cursor.getColumnIndex(RunningRecordProvider.CURRENT_TIME));
- latitude = cursor.getInt(cursor.getColumnIndex(RunningRecordProvider.LATITUDE));
- longitude = cursor.getInt(cursor.getColumnIndex(RunningRecordProvider.LONGITUDE));
-
- // Laptime History
- Location loc = new Location(LocationManager.GPS_PROVIDER);
- loc.setLatitude(latitude);
- loc.setLongitude(longitude);
- m_runningRecord.addRecord(new Date(currentTime), loc, "");
- if (currentTime != startTime) {
- int historyCount = lapHistory.getCount() + 1;
- laptimeLabel = "laptime " + historyCount + ": ";
- laptimeValue = DateUtils.formatElapsedTime((currentTime - prevTime) / 1000);
- lapHistory.insert(laptimeLabel + laptimeValue, 0);
- }
-
- prevTime = currentTime;
- }
- // Elapsed Time
- elapsedTimeView.setText(DateUtils.formatElapsedTime((currentTime - startTime) / 1000));
- // Latest Laptime
- lapTimeView.setText(laptimeValue);
- // Distance
- distanceView.setText(Float.toString(m_runningRecord.getDistance()));
-
- }
-
-
- @Override
- public void onDestroy() {
- getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
-
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE, Constants.MENU_SAVE, Menu.NONE, R.string.menu_save).setIcon(android.R.drawable.ic_menu_save);
- menu.add(Menu.NONE, Constants.MENU_HISTORY, Menu.NONE, R.string.menu_history).setIcon(R.drawable.history2);
- menu.add(Menu.NONE, Constants.MENU_MAP, Menu.NONE, R.string.menu_map).setIcon(android.R.drawable.ic_menu_mapmode);
- menu.add(Menu.NONE, Constants.MENU_SETTING, Menu.NONE, R.string.menu_setting).setIcon(android.R.drawable.ic_menu_preferences);
-
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- menu.findItem(Constants.MENU_MAP).setEnabled(m_useGPS);
-
- return super.onPrepareOptionsMenu(menu);
- }
-
- @Override
- public Dialog onCreateDialog (int id) {
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- switch (id) {
- case Constants.DIALOG_SAVE_ID:
- builder.setTitle(R.string.dialog_save_title);
- builder.setMessage(R.string.dialog_save_message);
- builder.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- saveRecord();
+ };
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Debug.startMethodTracing("tokyorunners");
+
+ setContentView(R.layout.stopwatch);
+
+ // タブの設定
+ TabHost tabHost = getTabHost();
+
+ TabHost.TabSpec stopwatchTab = tabHost.newTabSpec("stopwatch");
+ stopwatchTab.setIndicator(getString(R.string.title_stopwatch));
+ stopwatchTab.setContent(R.id.stopwatchmode);
+ tabHost.addTab(stopwatchTab);
+
+ TabHost.TabSpec mapTab = tabHost.newTabSpec("map");
+ mapTab.setIndicator(getString(R.string.title_map));
+ mapTab.setContent(new Intent(this, MapMode.class));
+ tabHost.addTab(mapTab);
+
+ tabHost.setCurrentTab(0);
+
+ tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
+ @Override
+ public void onTabChanged(String tag) {
+ if (tag.equals("stopwatch")) {
+ } else if (tag.equals("map")) {
}
- });
- builder.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
-
- }
- });
- break;
+ }
+ });
+
+ m_runningRecord = new RunningRecord(getContentResolver());
+
+ m_prefs = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // GPS設定
+ m_useGPS = m_prefs.getBoolean("use_gps", true);
+ if (m_useGPS) {
+ m_locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
+
+ String strGpsFreq = m_prefs.getString("gps_frequency", "0");
+ int gps_freq = Integer.parseInt(strGpsFreq);
+ m_locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER,
+ gps_freq * 1000, 5, this);
+
+ m_autosplit = m_prefs.getBoolean("auto_split", false);
+ if (m_autosplit) {
+ int interval = Integer.parseInt(m_prefs.getString(
+ "split_interval", "5"));
+ m_runningRecord.setSplitInterval(interval);
+ }
+
+ }
+
+ // タイム表示
+ m_elapsedTime = (Chronometer) findViewById(R.id.elapsed_time);
+ m_lapTime = (Chronometer) findViewById(R.id.lap_time);
+
+ // ボタン
+ Button btnStartStop = (Button) findViewById(R.id.button_start_stop);
+ btnStartStop.setOnClickListener(new StartStopButton());
+
+ Button btnResetLap = (Button) findViewById(R.id.button_reset_lap);
+ btnResetLap.setOnClickListener(new ResetLapButton());
+
+ // スプリットタイム/ラップタイム履歴
+ ListView lvLaptime = (ListView) findViewById(R.id.lap_history);
+ ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
+ R.layout.laptime);
+ lvLaptime.setAdapter(arrayAdapter);
+
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ switch (requestCode) {
+ case Constants.REQUEST_CODE_SETTINGS:
+ m_useGPS = m_prefs.getBoolean("use_gps", true);
+ m_autosplit = m_prefs.getBoolean("auto_split", false);
+ break;
+ case Constants.REQUEST_CODE_HISTORY:
+ if (data != null) {
+ long selectedStartTime = data.getLongExtra("startTime", 0);
+ readHistory(selectedStartTime);
+ }
+ break;
+ }
+ }
+
+ private void readHistory(long startTime) {
+
+ String[] columns = { RunningRecordProvider.CURRENT_TIME,
+ RunningRecordProvider.LATITUDE,
+ RunningRecordProvider.LONGITUDE,
+ RunningRecordProvider.POINT_NAME };
+ String selection = RunningRecordProvider.START_TIME + " = ?";
+ String[] selectionArgs = { Long.toString(startTime) };
+ String sortOrder = RunningRecordProvider.CURRENT_TIME + " asc";
+ Cursor cursor = managedQuery(RunningRecordProvider.REC_URI, columns,
+ selection, selectionArgs, sortOrder);
+ if (cursor == null) {
+ return;
+ }
+
+ Log.d(this.getClass().getName(), "row count:" + cursor.getCount());
+
+ reset();
+
+ ListView listLaptime = (ListView) findViewById(R.id.lap_history);
+ ArrayAdapter<String> lapHistory = (ArrayAdapter<String>) listLaptime
+ .getAdapter();
+
+ long currentTime = 0;
+ int latitude = 0;
+ int longitude = 0;
+ String pointName = "";
+ long prevTime = startTime;
+
+ TextView elapsedTimeView = (TextView) findViewById(R.id.elapsed_time);
+ TextView lapTimeView = (TextView) findViewById(R.id.lap_time);
+ TextView distanceView = (TextView) findViewById(R.id.distance);
+
+ while (cursor.moveToNext()) {
+ currentTime = cursor.getLong(cursor
+ .getColumnIndex(RunningRecordProvider.CURRENT_TIME));
+ latitude = cursor.getInt(cursor
+ .getColumnIndex(RunningRecordProvider.LATITUDE));
+ longitude = cursor.getInt(cursor
+ .getColumnIndex(RunningRecordProvider.LONGITUDE));
+ pointName = cursor.getString(cursor
+ .getColumnIndex(RunningRecordProvider.POINT_NAME));
+
+ // Laptime History
+ Location loc = null;
+
+ if (latitude != 0 && longitude != 0) {
+ loc = new Location(LocationManager.GPS_PROVIDER);
+
+ loc.setLatitude((double) (latitude / 1E6));
+ loc.setLongitude((double) (longitude / 1E6));
+ }
+ m_runningRecord.addRecord(new Date(currentTime), loc, pointName, false);
+
+ if (pointName.length() == 0) {
+ } else if (currentTime != startTime) {
+ StringBuffer strBuff = new StringBuffer();
+ strBuff.append(pointName);
+ strBuff.append(": ");
+ strBuff.append(DateUtils
+ .formatElapsedTime((currentTime - startTime) / 1000));
+ strBuff.append("/");
+ strBuff.append(DateUtils
+ .formatElapsedTime((currentTime - prevTime) / 1000));
+ lapHistory.insert(strBuff.toString(), 0);
+ prevTime = currentTime;
+ }
+
+ }
+ // Elapsed Time
+ elapsedTimeView.setText(DateUtils
+ .formatElapsedTime((currentTime - startTime) / 1000));
+ // Latest Laptime
+ lapTimeView.setText(DateUtils
+ .formatElapsedTime((currentTime - prevTime) / 1000));
+ // Distance
+ distanceView.setText(m_runningRecord.getDistanceString());
+
+
+ }
+
+ @Override
+ public void onDestroy() {
+ Log.d(this.getClass().getName(), "onDestroy():");
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+
+ m_runningRecord = null;
+
+ if (m_useGPS) {
+ m_locMgr.removeUpdates(this);
+ }
+
+ super.onDestroy();
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ menu.add(Menu.NONE, Constants.MENU_HISTORY, Menu.NONE,
+ R.string.menu_history).setIcon(R.drawable.history2);
+ menu.add(Menu.NONE, Constants.MENU_SETTING, Menu.NONE,
+ R.string.menu_setting).setIcon(
+ android.R.drawable.ic_menu_preferences);
+ return super.onCreateOptionsMenu(menu);
+ }
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ boolean enabled;
+ if (getTabHost().getCurrentTabTag().equals("stopwatch")) {
+ enabled = !m_running;
+ } else {
+ enabled = false;
+ }
+ menu.findItem(Constants.MENU_HISTORY).setEnabled(enabled);
+
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
+ public Dialog onCreateDialog(int id) {
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ switch (id) {
+ case Constants.DIALOG_EXIT_ID:
+ builder.setTitle(R.string.dialog_exit_title);
+ builder.setMessage(R.string.dialog_exit_message);
+ builder.setPositiveButton(R.string.dialog_yes,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Debug.stopMethodTracing();
+ finish();
+
+ }
+ });
+ builder.setNegativeButton(R.string.dialog_no,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+
+ }
+ });
+
+ break;
+ default:
+ break;
+ }
+
+ AlertDialog alertDialog = builder.create();
+ return alertDialog;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ Intent intent;
+ switch (item.getItemId()) {
+ case Constants.MENU_HISTORY:
+ intent = new Intent(this, RunningHistory.class);
+ intent.setAction(Intent.ACTION_VIEW);
+ startActivityForResult(intent, Constants.REQUEST_CODE_HISTORY);
+ break;
+ case Constants.MENU_SETTING:
+ intent = new Intent(this, Config.class);
+ intent.setAction(Intent.ACTION_VIEW);
+ startActivityForResult(intent, Constants.REQUEST_CODE_SETTINGS);
+ break;
default:
break;
- }
-
- AlertDialog alertDialog = builder.create();
- return alertDialog;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- Intent intent;
- switch (item.getItemId()) {
- case Constants.MENU_SAVE:
- showDialog(Constants.DIALOG_SAVE_ID);
- break;
- case Constants.MENU_HISTORY:
- intent = new Intent(this, RunningHistory.class);
- intent.setAction(Intent.ACTION_VIEW);
- startActivityForResult(intent, Constants.REQUEST_CODE_HISTORY);
- break;
- case Constants.MENU_MAP:
- intent = new Intent(this, MapMode.class);
- intent.setAction(Intent.ACTION_VIEW);
- startActivity(intent);
- break;
- case Constants.MENU_SETTING:
- intent = new Intent(this, Config.class);
- intent.setAction(Intent.ACTION_VIEW);
- startActivityForResult(intent, Constants.REQUEST_CODE_SETTINGS);
- break;
- default:
- break;
- }
- return false;
- }
+ }
+ return false;
+ }
+
public void onLocationChanged(Location location) {
- Log.d(this.getClass().getName(),
- "onLocationChanged(): latitude: " + location.getLatitude() +
- "; longitude: " + location.getLongitude() );
+ ExLog.put(location.toString());
+
+ // 走行中でない場合は何もしない
+ if (m_running == false) {
+ return;
+ }
- m_runningRecord.addRecord(new Date(), location, "");
+ // 音声出力でスタートを知らせる
+ Location prevLocation = m_runningRecord.getPrevLocation();
+ if (prevLocation == null) {
+ ToneGenerator toneGenerator = new ToneGenerator(
+ AudioManager.STREAM_SYSTEM,
+ ToneGenerator.MAX_VOLUME);
+ toneGenerator.startTone(ToneGenerator.TONE_PROP_BEEP);
+ toneGenerator.stopTone();
+ }
+
- float distance_km = m_runningRecord.getDistance();
-
- TextView distanceView = (TextView)findViewById(R.id.distance);
- distanceView.setText(Float.toString(distance_km));
+ // 精度が低いデータは無視
+ // 移動距離が精度より小さい場合も無視
+ if (location.hasAccuracy()) {
+ if (location.getAccuracy() > m_minAccuracy) {
+ ExLog.put("Accuracy low: " + location.getAccuracy() + ";" + m_minAccuracy);
+ return;
+ }
+ if (prevLocation != null && prevLocation.distanceTo(location) < location.getAccuracy()) {
+ ExLog.put("Move not enough: " + location.getAccuracy() + ";" + prevLocation.distanceTo(location));
+ return;
+ }
+
+ }
+ Date recDate = new Date(location.getTime());
+ String pointName = m_runningRecord.addRecord(recDate, location, "");
+
+ // ラップタイム履歴
+ if (pointName.length() > 0) {
+ String laptimeStr = calculateSplitAndLap();
+
+ ListView listLaptime = (ListView) findViewById(R.id.lap_history);
+ ArrayAdapter<String> lapHistory = (ArrayAdapter<String>) listLaptime
+ .getAdapter();
+
+ String strLaptime = pointName + ": " + laptimeStr;
+
+ lapHistory.insert(strLaptime, 0);
+ }
+
+ // 距離
+ TextView distanceView = (TextView) findViewById(R.id.distance);
+ distanceView.setText(m_runningRecord.getDistanceString());
+
+ // MapModeに通知
+ Intent intent = new Intent("NewRunningRecord");
+ intent.putExtra("RunningRecord", location.getTime());
+ sendBroadcast(intent);
+
}
public void onProviderDisabled(String provider) {
-
+ Log.d(this.getClass().getName(), "onProviderDisabled()");
+ m_locMgr.removeUpdates(this);
+
}
public void onProviderEnabled(String provider) {
-
+ Log.d(this.getClass().getName(), "onProviderEnabled()");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
break;
}
Log.d(this.getClass().getName(), "onStatusChanged(): " + statusStr);
-
+
}
+
private void start() {
reset();
- m_elapsedTime.start();
- m_lapTime.start();
-
- if (m_useGPS) {
- String strGpsFreq = m_prefs.getString("gps_frequency", "0");
- int gps_freq =Integer.parseInt(strGpsFreq);
- m_locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, gps_freq * 1000, 1, this);
-
- }
- m_runningRecord.addRecord(new Date(), null, "");
-
- Button startStopButton = (Button)findViewById(R.id.button_start_stop);
- Button resetLapButton = (Button)findViewById(R.id.button_reset_lap);
+ m_elapsedTime.start();
+ m_lapTime.start();
+
+ Location startPoint = m_locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+
+ m_runningRecord.addRecord(new Date(), startPoint, "start");
+
+ Button startStopButton = (Button) findViewById(R.id.button_start_stop);
+ Button resetLapButton = (Button) findViewById(R.id.button_reset_lap);
startStopButton.setText(R.string.button_stop);
if (m_autosplit) {
resetLapButton.setEnabled(false);
}
m_running = true;
}
+
private void stop() {
- lap();
-
+ Location finishPoint = m_locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+
+ m_runningRecord.addRecord(new Date(), finishPoint, "finish");
+
m_elapsedTime.stop();
m_lapTime.stop();
-
- if (m_useGPS) {
- m_locMgr.removeUpdates(this);
- }
- Button startStopButton = (Button)findViewById(R.id.button_start_stop);
- Button resetLapButton = (Button)findViewById(R.id.button_reset_lap);
+ Button startStopButton = (Button) findViewById(R.id.button_start_stop);
+ Button resetLapButton = (Button) findViewById(R.id.button_reset_lap);
startStopButton.setText(R.string.button_start);
if (m_autosplit) {
resetLapButton.setEnabled(true);
resetLapButton.setText(R.string.button_reset);
}
m_running = false;
-
+
}
+
private void reset() {
+ m_runningRecord.clearRecord();
+
long elapsedRealTime = SystemClock.elapsedRealtime();
m_elapsedTime.setBase(elapsedRealTime);
- m_lapTime.setBase(elapsedRealTime);
+ m_lapTime.setBase(elapsedRealTime);
+
+ // 距離
+ TextView distanceView = (TextView) findViewById(R.id.distance);
+ distanceView.setText(m_runningRecord.getDistanceString());
- ListView listLaptime = (ListView)findViewById(R.id.lap_history);
- ArrayAdapter<String> lapHistory = (ArrayAdapter<String>)listLaptime.getAdapter();
+ ListView listLaptime = (ListView) findViewById(R.id.lap_history);
+ ArrayAdapter<String> lapHistory = (ArrayAdapter<String>) listLaptime
+ .getAdapter();
lapHistory.clear();
-
+
}
- private void lap() {
+
+ private String calculateSplitAndLap() {
long elapsedRealTime = SystemClock.elapsedRealtime();
+ long splitTimeMillis = elapsedRealTime - m_elapsedTime.getBase();
long lapTimeMillis = elapsedRealTime - m_lapTime.getBase();
-
- ListView listLaptime = (ListView)findViewById(R.id.lap_history);
-
- m_runningRecord.addRecord(new Date(), null, "");
-
- ArrayAdapter<String> lapHistory = (ArrayAdapter<String>)listLaptime.getAdapter();
-
- int historyCount = lapHistory.getCount() + 1;
-
- String strLaptime = "laptime " + historyCount + ": "
- + DateUtils.formatElapsedTime(lapTimeMillis / 1000);
-
- lapHistory.insert(strLaptime, 0);
-
+ String splitTimeStr = DateUtils
+ .formatElapsedTime(splitTimeMillis / 1000);
+ String lapTimeStr = DateUtils.formatElapsedTime(lapTimeMillis / 1000);
+
m_lapTime.setBase(elapsedRealTime);
-
- }
-
- private void saveRecord() {
- if (m_running) {
- return;
- }
- m_runningRecord.save();
-
-/*
- FileOutputStream outFile = null;
- OutputStreamWriter stWriter = null;
- try {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
- outFile = openFileOutput(formatter.format(new Date(m_startTime)) + ".xml", MODE_PRIVATE);
- stWriter = new OutputStreamWriter(outFile);
- m_runningRecord.save(stWriter);
- } catch (IOException e) {
- } finally {
- try {
- if (stWriter != null) {
- stWriter.close();
- }
- if (outFile != null) {
- outFile.close();
- }
- } catch (IOException e) {
- }
- }
-*/
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- Log.d(this.getClass().getName(), "onTouchEvent():" );
- if (m_gestureDetector.onTouchEvent(event)) {
- return true;
- }
- return super.onTouchEvent(event);
- }
-
- public boolean onDown(MotionEvent arg0) {
- Log.d(this.getClass().getName(), "onDown():" );
- return false;
- }
- public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
- float arg3) {
- Log.d(this.getClass().getName(), "onFling():" );
- return false;
+ return splitTimeStr + "/" + lapTimeStr;
+
}
- public void onLongPress(MotionEvent arg0) {
- Log.d(this.getClass().getName(), "onLongPress():" );
-
- Intent intent = new Intent(TokyoRunners.this, MapMode.class);
- intent.setAction(Intent.ACTION_VIEW);
- startActivity(intent);
-
+
+ private void lap() {
+ String laptimeStr = calculateSplitAndLap();
+
+ ListView listLaptime = (ListView) findViewById(R.id.lap_history);
+
+ ArrayAdapter<String> lapHistory = (ArrayAdapter<String>) listLaptime
+ .getAdapter();
+
+ String strLapNo = Integer.toString(lapHistory.getCount() + 1);
+
+ lapHistory.insert(strLapNo + ": " + laptimeStr, 0);
+
+ m_runningRecord.addRecord(new Date(), null, strLapNo);
+
}
- public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
- float arg3) {
- Log.d(this.getClass().getName(), "onScroll():" );
- return false;
+
+ public static Record getRecord(long recordTime) {
+
+ return m_runningRecord.getRecord(new Date(recordTime));
+
}
- public void onShowPress(MotionEvent arg0) {
- Log.d(this.getClass().getName(), "onShowPress():" );
+
+ public static Record getNextRecord(long recordTime) {
+
+ return m_runningRecord.getNextRecord(new Date(recordTime));
+
}
- public boolean onSingleTapUp(MotionEvent arg0) {
- Log.d(this.getClass().getName(), "onSingleTapUp():" );
- return false;
+ public static Iterator<Record> getRecordIterator() {
+ return m_runningRecord.getIterator();
}
- public boolean onDoubleTap(MotionEvent arg0) {
- Log.d(this.getClass().getName(), "onDoubleTap():" );
- return false;
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ return super.dispatchKeyEvent(event);
}
- public boolean onDoubleTapEvent(MotionEvent arg0) {
- Log.d(this.getClass().getName(), "onDoubleTapEvent():" );
- return false;
- }
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ showDialog(Constants.DIALOG_EXIT_ID);
+ return true;
+ }
+
+ return super.onKeyDown(keyCode, event);
- public boolean onSingleTapConfirmed(MotionEvent arg0) {
- Log.d(this.getClass().getName(), "onSingleTapConfirmed():" );
- return false;
}
+
}
\ No newline at end of file