package com.tk20.tk20android;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.support.wearable.view.BoxInsetLayout;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MainActivity extends WearableActivity {

  private static final SimpleDateFormat AMBIENT_DATE_FORMAT =
      new SimpleDateFormat("HH:mm", Locale.US);

  private BoxInsetLayout mContainerView;
  private TextView mTextView;
  private TextView mClockView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setAmbientEnabled();

    mContainerView = (BoxInsetLayout) findViewById(R.id.container);
    mTextView = (TextView) findViewById(R.id.text);
    mClockView = (TextView) findViewById(R.id.clock);

    SensorManager manager = (SensorManager)getSystemService(SENSOR_SERVICE);
    Sensor hSensor = manager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
    manager.registerListener(new SensorEventListener() {
      @Override
      public void onSensorChanged(SensorEvent event) {
        mTextView.setText("" + event.values[0]);
      }

      @Override
      public void onAccuracyChanged(Sensor sensor, int accuracy) {

      }
    },hSensor,SensorManager.SENSOR_DELAY_NORMAL);
  }

  @Override
  public void onEnterAmbient(Bundle ambientDetails) {
    super.onEnterAmbient(ambientDetails);
    updateDisplay();
  }

  @Override
  public void onUpdateAmbient() {
    super.onUpdateAmbient();
    updateDisplay();
  }

  @Override
  public void onExitAmbient() {
    updateDisplay();
    super.onExitAmbient();
  }

  private void updateDisplay() {
    if (isAmbient()) {
      mContainerView.setBackgroundColor(getResources().getColor(android.R.color.black));
      mTextView.setTextColor(getResources().getColor(android.R.color.white));
      mClockView.setVisibility(View.VISIBLE);

      mClockView.setText(AMBIENT_DATE_FORMAT.format(new Date()));
    } else {
      mContainerView.setBackground(null);
      mTextView.setTextColor(getResources().getColor(android.R.color.black));
      mClockView.setVisibility(View.GONE);
    }
  }
}

@@ -319,33 +319,8 @@
 ut;%0A
-import android.util.Log;%0A
 impo
@@ -341,16 +341,16 @@
 w.View;%0A
+
 import a
@@ -726,16 +726,65 @@
 kView;%0A%0A
+  private SensorEventListener mListener = null;%0A%0A
   @Overr
@@ -1284,31 +1284,16 @@
    m
-anager.register
 Listener
 (new
@@ -1288,17 +1288,19 @@
 Listener
-(
+ = 
 new Sens
@@ -1439,16 +1439,112 @@
 es%5B0%5D);%0A
+        // Send notification in emergency case.%0A        // Wearable.MessageApi.sendMessage(...%0A%0A
       %7D%0A
@@ -1645,17 +1645,58 @@
    %7D
-,
+;%0A    manager.registerListener(mListener, 
 hSensor,
 Sens
@@ -1691,16 +1691,17 @@
 hSensor,
+ 
 SensorMa
@@ -2573,24 +2573,24 @@
 View.GONE);%0A
-
     %7D%0A  %7D%0A%7D%0A
@@ -2586,11 +2586,248 @@
    %7D%0A  %7D
+%0A%0A  @Override%0A  protected void onPause() %7B%0A    super.onPause();%0A    finish();%0A  %7D%0A%0A  @Override%0A  protected void onDestroy() %7B%0A    ((SensorManager)getSystemService(SENSOR_SERVICE)).unregisterListener(mListener);%0A    super.onDestroy();%0A  %7D
 %0A%7D%0A

Add function to get heart rate