Android Open Source - Fall_Prevention_2013 Main






From Project

Back to project page Fall_Prevention_2013.

License

The source code is released under:

Apache License

If you think the Android project Fall_Prevention_2013 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

/*******************************************************************************
 * Licensed to UbiCollab.org under one or more contributor
 * license agreements.  See the NOTICE file distributed 
 * with this work for additional information regarding
 * copyright ownership. UbiCollab.org licenses this file
 * to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * /*w  w w  .  j av a2s.c o m*/
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 ******************************************************************************/
package ntnu.stud.valens.contentprovider;

import ntnu.stud.valens.contentprovider.calculations.ManipulationStarter;
import ntnu.stud.valens.contentprovider.calculations.ManipulatorHelper;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * This is the method for the main activity that is the first and only screen for this application.
 * Contains ability to reset the content provider and to force calculations of gaits.
 * 
 * @author fiLLLip
 * @author Elias
 *
 */
public class Main extends Activity {

  /**
   * Called when the activity is first created. This is where you should do all of your 
   * normal static set up: create views, bind data to lists, etc. This method also 
   * provides you with a Bundle containing the activity's previously frozen state, 
   * if there was one.
   * 
   * @param savedInstance If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new ManipulationStarter().startManipulation(this.getApplicationContext());
    
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
          SQLiteDatabase db = new CPValensDB(getApplicationContext())
              .getWritableDatabase();
          new CPValensDB(getApplicationContext()).reset(db);
          updateDebugFields();
          Toast.makeText(getApplicationContext(), "Deleted data",
              Toast.LENGTH_SHORT).show();
          break;

        case DialogInterface.BUTTON_NEGATIVE:
          // No button clicked
          break;
        }
      }
    };
    final AlertDialog.Builder alertDeleteYesNo = new AlertDialog.Builder(
        this).setPositiveButton("Yes", dialogClickListener)
        .setNegativeButton("No", dialogClickListener);

    DialogInterface.OnClickListener dialogClickListenerCalculations = new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
          Log.v("onCLick", "Pressed button!");
                ManipulatorHelper mh = new ManipulatorHelper(getApplicationContext());
                (new Thread(mh)).start();
          updateDebugFields();
          Toast.makeText(getApplicationContext(), "Did calculations",
              Toast.LENGTH_SHORT).show();
          break;

        case DialogInterface.BUTTON_NEGATIVE:
          // No-button clicked, don't do anything.
          break;
        }
      }
    };
    final AlertDialog.Builder alertDeleteYesNoCalculations = new AlertDialog.Builder(
        this).setPositiveButton("Yes", dialogClickListenerCalculations)
        .setNegativeButton("No", dialogClickListenerCalculations);

    final Button buttonDelete = (Button) findViewById(R.id.btnDeleteDB);
    buttonDelete.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        alertDeleteYesNo.setMessage("Are you sure?").show();
      }
    });

    final Button buttonCalculations = (Button) findViewById(R.id.btnDoCalculations);
    buttonCalculations.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        alertDeleteYesNoCalculations.setMessage("Are you sure?").show();
      }
    });
    updateDebugFields();
  }

  /**
   * Called when the activity will start interacting with the user. 
   * At this point your activity is at the top of the activity stack, 
   * with user input going to it.
   */
  @Override
  protected void onResume() {
    super.onResume();
    updateDebugFields();
  }

  /**
   * Loads new data and refreshes debug labels in the main 
   * activity with these new data.
   */
  private void updateDebugFields() {
    TextView rawSteps = (TextView) findViewById(R.id.txtRawSteps);
    TextView steps = (TextView) findViewById(R.id.txtSteps);
    TextView gaits = (TextView) findViewById(R.id.txtGaits);
    TextView tests = (TextView) findViewById(R.id.txtTests);
    TextView testTypes = (TextView) findViewById(R.id.txtTestTypes);

    SQLiteDatabase db = new CPValensDB(getApplicationContext())
        .getReadableDatabase();

    Cursor mCount = db.rawQuery("select count(*) from "
        + DBSchema.RawSteps.TABLE_NAME, null);
    mCount.moveToFirst();
    rawSteps.setText(Integer.toString(mCount.getInt(0)));
    mCount.close();

    mCount = db.rawQuery("select count(*) from "
        + DBSchema.Steps.TABLE_NAME, null);
    mCount.moveToFirst();
    steps.setText(Integer.toString(mCount.getInt(0)));
    mCount.close();

    mCount = db.rawQuery("select count(*) from "
        + DBSchema.Gaits.TABLE_NAME, null);
    mCount.moveToFirst();
    gaits.setText(Integer.toString(mCount.getInt(0)));
    mCount.close();

    mCount = db.rawQuery("select count(*) from "
        + DBSchema.Tests.TABLE_NAME, null);
    mCount.moveToFirst();
    tests.setText(Integer.toString(mCount.getInt(0)));
    mCount.close();

    mCount = db.rawQuery("select count(*) from "
        + DBSchema.TestTypes.TABLE_NAME, null);
    mCount.moveToFirst();
    testTypes.setText(Integer.toString(mCount.getInt(0)));
    mCount.close();
    
    db.close();
  }
}




Java Source Code List

ntnu.stud.valens.contentprovider.CPValensDB.java
ntnu.stud.valens.contentprovider.DBSchema.java
ntnu.stud.valens.contentprovider.Main.java
ntnu.stud.valens.contentprovider.ValensDataProvider.java
ntnu.stud.valens.contentprovider.calculations.AlarmManagerBroadcastReceiver.java
ntnu.stud.valens.contentprovider.calculations.ContentProviderHelper.java
ntnu.stud.valens.contentprovider.calculations.ManipulationStarter.java
ntnu.stud.valens.contentprovider.calculations.ManipulatorHelper.java
ntnu.stud.valens.demonstration.Constants.java
ntnu.stud.valens.demonstration.NotificationBroadcastReciever.java
ntnu.stud.valens.demonstration.activity.ClearHistory.java
ntnu.stud.valens.demonstration.activity.ContactPerson.java
ntnu.stud.valens.demonstration.activity.CreateContact.java
ntnu.stud.valens.demonstration.activity.EventDetail.java
ntnu.stud.valens.demonstration.activity.EventList.java
ntnu.stud.valens.demonstration.activity.LaunchActivity.java
ntnu.stud.valens.demonstration.activity.MainScreen.java
ntnu.stud.valens.demonstration.activity.NewContact.java
ntnu.stud.valens.demonstration.activity.Related.java
ntnu.stud.valens.demonstration.activity.Settings.java
ntnu.stud.valens.demonstration.activity.Statistics.java
ntnu.stud.valens.demonstration.activity.WriteName.java
ntnu.stud.valens.demonstration.connectivity.AlarmManagerBroadcastReceiver.java
ntnu.stud.valens.demonstration.connectivity.ContentProviderHelper.java
ntnu.stud.valens.demonstration.connectivity.DatabaseContract.java
ntnu.stud.valens.demonstration.connectivity.DatabaseHelper.java
ntnu.stud.valens.demonstration.datastructures.Contact.java
ntnu.stud.valens.demonstration.datastructures.Event.java
ntnu.stud.valens.demonstration.datastructures.RiskStatus.java
ntnu.stud.valens.demonstration.listadapters.EditContactAdapter.java
ntnu.stud.valens.demonstration.listadapters.EventListAdapter.java
ntnu.stud.valens.demonstration.widget.WidgetProvider.java
ntnu.stud.valens.stepdetector.DetectStepsThread.java
ntnu.stud.valens.stepdetector.LaunchActivity.java
ntnu.stud.valens.stepdetector.Methods.java
ntnu.stud.valens.stepdetector.StepMainServiceStarter.java
ntnu.stud.valens.stepdetector.StepMainService.java
ntnu.stud.valens.stepdetector.Values.java
ntnu.stud.valens.stepdetector.calibration.CalibrationActivity.java
ntnu.stud.valens.stepdetector.calibration.CalibrationStartTask.java
ntnu.stud.valens.stepdetector.calibration.CalibrationThread.java