Android Open Source - RazorRunner-AndroidProject History Activity






From Project

Back to project page RazorRunner-AndroidProject.

License

The source code is released under:

Apache License

If you think the Android project RazorRunner-AndroidProject listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.uark.csce.razorrunner;
/*w  w w .j a v a  2 s.c  o  m*/
import java.text.SimpleDateFormat;
import java.util.Date;

import com.google.android.gms.common.internal.m;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;


public class HistoryActivity extends Activity {
  TextView dateText, stepsText, distanceText, durationText, nameText;
  Intent intent;
  private GoogleMap mMap;
  
  @SuppressLint("SimpleDateFormat")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    
    intent = getIntent();
    nameText = (TextView) findViewById(R.id.wOut_Name);
    dateText = (TextView) findViewById(R.id.date_text);
    distanceText = (TextView) findViewById(R.id.distance_text);
    durationText = (TextView) findViewById(R.id.duration_text);
        stepsText = (TextView) findViewById(R.id.steps_text);

    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
  
    setTextViews();
        showLocationA();
        showLocationB();
  }
  
  private void setTextViews() {
    // TODO Auto-generated method stub
    String workoutName = intent.getStringExtra("Workout_Name");
    long dateString = intent.getLongExtra("Workout_Date", 0L);    
    String workoutTime = intent.getStringExtra("Workout_Time");
      String distance = String.valueOf(intent.getFloatExtra("Distance", 0.0f));
        String steps = String.valueOf(intent.getIntExtra("Total_Steps", 0));

    nameText.setText(workoutName);
    
    Date d = new Date(dateString);
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy 'at' hh:mm a");  
    String _dateText = sdf.format(d);
    dateText.setText(_dateText);
    
    distanceText.setText(distance);
        stepsText.setText(steps);
    durationText.setText(workoutTime);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.history, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
            startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
      return true;
    }
    return super.onOptionsItemSelected(item);
  }

    public void showLocationA(){
        double lat = intent.getDoubleExtra("Latitude_A", 0.0),
               lng = intent.getDoubleExtra("Longitude_A", 0.0);

        LatLng location = new LatLng(lat, lng);
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(location,
                16);
        mMap.animateCamera(update);
        mMap.addMarker(new MarkerOptions().position(location).title(
                "Starting Location"));
    }

    public void showLocationB(){
        double lat = intent.getDoubleExtra("Latitude_B", 0.0),
                lng = intent.getDoubleExtra("Longitude_B", 0.0);

        LatLng location = new LatLng(lat, lng);
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(location,
                16);
        mMap.animateCamera(update);
        mMap.addMarker(new MarkerOptions().position(location).title(
                "Ending Location"));
    }

  public void deleteWorkout(View view)
  {
    intent.putExtra("listPosition", intent.getExtras().getInt("position"));
    
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

      builder.setTitle("Confirm");
      builder.setMessage("Are you sure?");

      builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int which) {
              // Do nothing but close the dialog
            setResult(RESULT_OK, intent);
              dialog.dismiss();
          finish();

          }

      });
      
      builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
              // Do nothing
              dialog.dismiss();
          }
      });

      AlertDialog alert = builder.create();
      alert.show();
  }
  
  public void onBackButton(View view)
  {
    finish();
  }
}




Java Source Code List

edu.uark.csce.razorrunner.ActivityUtils.java
edu.uark.csce.razorrunner.BuildConfig.java
edu.uark.csce.razorrunner.DistanceNotifier.java
edu.uark.csce.razorrunner.HistoryActivity.java
edu.uark.csce.razorrunner.Manifest.java
edu.uark.csce.razorrunner.OverviewActivity.java
edu.uark.csce.razorrunner.PedometerSettings.java
edu.uark.csce.razorrunner.ProfileActivity.java
edu.uark.csce.razorrunner.RemoveDetection.java
edu.uark.csce.razorrunner.RequestDetection.java
edu.uark.csce.razorrunner.StepDetector.java
edu.uark.csce.razorrunner.StepDisplayer.java
edu.uark.csce.razorrunner.StepListener.java
edu.uark.csce.razorrunner.UserActivityRecognition.java
edu.uark.csce.razorrunner.UserSettingsActivity.java
edu.uark.csce.razorrunner.UserStepRecognition.java
edu.uark.csce.razorrunner.WorkoutActivity.java
edu.uark.csce.razorrunner.WorkoutContentProvider.java
edu.uark.csce.razorrunner.WorkoutData.java
edu.uark.csce.razorrunner.WorkoutItemAdapter.java