Browse files

Initial commit.

  • Loading branch information...
1 parent 7564f80 commit 3a0f83506a6f8d4e20f691edb8b7271f1ab6c494 @theUltimateLabs committed Oct 20, 2012
View
8 .classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 .project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>theUltimateWatch</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
4 .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5
View
48 AndroidManifest.xml
@@ -0,0 +1,48 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.theultimatelabs.watch"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="15" />
+
+ <uses-feature android:name="android.hardware.sensor.accelerometer" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+
+
+ <activity
+ android:name=".SettingsActivity2"
+ android:label="Watch Settings"
+ android:configChanges="keyboardHidden|orientation">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name=".WatchActivity"
+ android:label="Watch"
+ android:theme="@android:style/Theme.Translucent.NoTitleBar"
+ android:configChanges="keyboardHidden|orientation" >
+ </activity>
+
+ <service android:name=".WatchService" />
+
+ <broadcastReceiver android:name=".WatchReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ </intent-filter>
+ </broadcastReceiver>
+ </application>
+
+</manifest>
View
BIN ic_launcher-web.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN libs/android-support-v4.jar
Binary file not shown.
View
20 proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
View
14 project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-16
View
BIN res/drawable-hdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-xhdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
82 res/layout/settings.xml
@@ -0,0 +1,82 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="ON Threshold: "
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <Spinner
+ android:id="@+id/onThresholdSpinner"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:entries="@array/on_thresholds"
+ android:gravity="right" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="OFF Threshold:"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <Spinner
+ android:id="@+id/offThresholdSpinner"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:entries="@array/off_thresholds"
+ android:gravity="right" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Sleep Timeout:"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <Spinner
+ android:id="@+id/sleepTimeoutSpinner"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:entries="@array/sleep_timeouts"
+ android:gravity="right" />
+ </LinearLayout>
+
+ <CheckBox
+ android:id="@+id/reverseOrientationCheckBox"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Reverse Screen Orientation" />
+
+ <Button
+ android:id="@+id/callibrateButton"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Callibrate ON Postion" />
+
+ <CheckBox
+ android:id="@+id/enabledCheckBox"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Watch Enabled" />
+
+</LinearLayout>
View
43 res/layout/watch.xml
@@ -0,0 +1,43 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <AnalogClock
+ android:id="@+id/analogClock3"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_centerVertical="true" />
+
+ <Chronometer
+ android:id="@+id/chronometer2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:text="Chronometer"
+ android:textColor="#D3D3D3"
+ android:textSize="65dp" />
+
+ <DigitalClock
+ android:id="@+id/digitalClock2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignTop="@+id/analogClock3"
+ android:text="DigitalClock"
+ android:textColor="#FFFFFF"
+ android:textSize="65dp" />
+
+ <TextView
+ android:id="@+id/dateText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_below="@+id/digitalClock2"
+ android:text="Date"
+ android:textColor="#D3D3D3"
+ android:textSize="40dp" />
+
+</RelativeLayout>
View
6 res/menu/watch.xml
@@ -0,0 +1,6 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/menu_settings"
+ android:title="@string/menu_settings"
+ android:orderInCategory="100"
+ android:showAsAction="never" />
+</menu>
View
5 res/values-v11/styles.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
View
5 res/values-v14/styles.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
View
39 res/values/strings.xml
@@ -0,0 +1,39 @@
+<resources>
+
+ <string name="app_name">The Ultimate Watch</string>
+ <string name="menu_settings">Settings</string>
+ <string name="title_activity_watch">Watch</string>
+ <string name="on_threshold_prompt">ON Threshold</string>
+
+ <string-array name="on_thresholds">
+ <item>1</item>
+ <item>2 (Default)</item>
+ <item>3</item>
+ <item>4</item>
+ <item>5</item>
+ <item>6</item>
+ <item>7</item>
+ <item>9</item>
+ <item>10</item>
+ </string-array>
+ <string-array name="off_thresholds">
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ <item>4 (Default)</item>
+ <item>5</item>
+ <item>6</item>
+ <item>7</item>
+ <item>9</item>
+ <item>10</item>
+ </string-array>
+ <string-array name="sleep_timeouts">
+ <item>Never</item>
+ <item>15 mins.</item>
+ <item>30 mins.</item>
+ <item>1 hour (default)</item>
+ <item>2 hours</item>
+ <item>4 hours</item>
+ </string-array>
+
+</resources>
View
5 res/values/styles.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
View
261 src/com/theultimatelabs/watch/SettingsActivity2.java
@@ -0,0 +1,261 @@
+package com.theultimatelabs.watch;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
+import android.content.res.Configuration;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.Spinner;
+import android.widget.Toast;
+
+public class SettingsActivity2 extends Activity {
+
+ public final static String TAG = "SettingsActvity";
+ private ProgressDialog mCalibrateProgress;
+ private SharedPreferences mSettings;
+
+ public void onConfigurationChange(Configuration newConfig) {
+
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.settings);
+
+ Log.v(TAG, "onCreate");
+
+ startService(new Intent(getApplicationContext(), WatchService.class));
+
+ mSettings = getSharedPreferences(WatchService.PREFS, 0);
+
+ findViewById(R.id.callibrateButton).setOnClickListener(new Calibrate());
+ Spinner onThresholdSpinner = (Spinner) findViewById(R.id.onThresholdSpinner);
+ Spinner offThresholdSpinner = (Spinner) findViewById(R.id.offThresholdSpinner);
+ Spinner sleepTimeoutSpinner = (Spinner) findViewById(R.id.sleepTimeoutSpinner);
+
+ sleepTimeoutSpinner.setSelection(mSettings.getInt("sleepTimeout",4));
+ onThresholdSpinner.setSelection(mSettings.getInt("onThreshold", 2) - 1);
+ offThresholdSpinner
+ .setSelection(mSettings.getInt("offThreshold", 4) - 1);
+ onThresholdSpinner
+ .setOnItemSelectedListener(new OnItemSelectedListener() {
+ public void onItemSelected(AdapterView<?> parent,
+ View view, int position, long id) {
+ mSettings.edit().putInt("onThreshold", position + 1)
+ .commit();
+ startService(new Intent(getApplicationContext(),
+ WatchService.class)); // this refreshes the
+ // prefs in the service
+ }
+
+ public void onNothingSelected(AdapterView<?> arg0) {
+ }
+ });
+ offThresholdSpinner
+ .setOnItemSelectedListener(new OnItemSelectedListener() {
+ public void onItemSelected(AdapterView<?> parent,
+ View view, int position, long id) {
+ mSettings.edit().putInt("offThreshold", position + 1)
+ .commit();
+ startService(new Intent(getApplicationContext(),
+ WatchService.class)); // this refreshes the
+ // prefs in the service
+ }
+
+ public void onNothingSelected(AdapterView<?> arg0) {
+ }
+ });
+
+ sleepTimeoutSpinner
+ .setOnItemSelectedListener(new OnItemSelectedListener() {
+ public void onItemSelected(AdapterView<?> parent,
+ View view, int position, long id) {
+ mSettings
+ .edit()
+ .putInt("sleepTimeout",position).commit();
+ startService(new Intent(getApplicationContext(),
+ WatchService.class)); // this refreshes the
+ // prefs in the service
+ }
+
+ public void onNothingSelected(AdapterView<?> arg0) {
+ }
+ });
+
+ CheckBox reverseScreenOrientationCheckBox = (CheckBox) findViewById(R.id.reverseOrientationCheckBox);
+ reverseScreenOrientationCheckBox
+ .setChecked(mSettings.getInt("orientation",
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) != ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
+ reverseScreenOrientationCheckBox
+ .setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ public void onCheckedChanged(CompoundButton buttonView,
+ boolean isChecked) {
+ if (isChecked) {
+ mSettings
+ .edit()
+ .putInt("orientation",
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
+ .commit();
+ } else {
+ mSettings
+ .edit()
+ .putInt("orientation",
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
+ .commit();
+ }
+ startService(new Intent(getApplicationContext(),
+ WatchService.class));
+
+ }
+ });
+
+ CheckBox enabledCheckBox = (CheckBox) findViewById(R.id.enabledCheckBox);
+ enabledCheckBox.setChecked(mSettings.getBoolean("enabled", true));
+
+ enabledCheckBox
+ .setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ public void onCheckedChanged(CompoundButton buttonView,
+ boolean isChecked) {
+ if (isChecked) {
+ mSettings.edit().putBoolean("enabled", true)
+ .commit();
+ } else {
+ mSettings.edit().putBoolean("enabled", false)
+ .commit();
+ }
+ startService(new Intent(getApplicationContext(),
+ WatchService.class));
+
+ }
+ });
+
+ }
+
+ public class Calibrate implements View.OnClickListener, SensorEventListener {
+
+ private float mXSum;
+ private float mZSum;
+ private float mYSum;
+ private int mEventCount;
+
+ private SensorManager mSensorManager;
+ private Sensor mAccelerometer;
+
+ public void onClick(View v) {
+ AlertDialog.Builder calibrateDialog = new AlertDialog.Builder(
+ SettingsActivity2.this);
+
+ // set dialog message
+ calibrateDialog
+ .setTitle("Calibrate")
+ .setMessage(
+ "Hold the phone in your desired ON position, press Start, continue to hold the postion until calibration completes.")
+ .setCancelable(false)
+ .setPositiveButton("Start",
+ new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog,
+ int id) {
+ mCalibrateProgress = new ProgressDialog(
+ SettingsActivity2.this);
+ mCalibrateProgress
+ .setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ mCalibrateProgress
+ .setMessage("Continue to hold desired ON position.");
+ mCalibrateProgress
+ .setTitle("Calabrating...");
+ mCalibrateProgress.setIndeterminate(true);
+ mCalibrateProgress.setCancelable(false);
+ mCalibrateProgress.show();
+ mXSum = mYSum = mZSum = 0;
+ mEventCount = 0;
+ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+ mAccelerometer = mSensorManager
+ .getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+ Log.i(TAG,
+ "accelerometer calibration started");
+ mSensorManager.registerListener(
+ Calibrate.this, mAccelerometer,
+ SensorManager.SENSOR_DELAY_UI);
+
+ }
+ })
+ .setNegativeButton("Cancel",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int id) {
+ dialog.cancel();
+ }
+ });
+
+ calibrateDialog.create().show();
+
+ }
+
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onSensorChanged(SensorEvent event) {
+ Log.d(TAG, "event: " + new Integer(mEventCount).toString());
+ mXSum += event.values[0];
+ mYSum += event.values[1];
+ mZSum += event.values[2];
+ mEventCount++;
+ if (mEventCount >= 50) {
+ mCalibrateProgress.dismiss();
+ mSensorManager.unregisterListener(this);
+ float xAvg = mXSum / mEventCount;
+ float yAvg = mYSum / mEventCount;
+ float zAvg = mZSum / mEventCount;
+
+ Toast.makeText(getApplicationContext(),
+ String.format("x:%f y:%f z:%f", xAvg, yAvg, zAvg),
+ Toast.LENGTH_LONG).show();
+
+ SharedPreferences.Editor editor = mSettings.edit();
+ editor.putFloat("targetX", xAvg);
+ editor.putFloat("targetY", yAvg);
+ editor.putFloat("targetZ", zAvg);
+ editor.commit();
+ startService(new Intent(getApplicationContext(),
+ WatchService.class)); // this refreshes the prefs in the
+ // service
+ }
+ }
+
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ Log.v(TAG, "onStart");
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.watch, menu);
+ return true;
+ }
+
+}
View
177 src/com/theultimatelabs/watch/WatchActivity.java
@@ -0,0 +1,177 @@
+package com.theultimatelabs.watch;
+
+import java.util.Date;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
+import android.graphics.Color;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.PowerManager;
+import android.os.SystemClock;
+import android.text.format.DateFormat;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnLongClickListener;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Chronometer;
+import android.widget.TextView;
+
+public class WatchActivity extends Activity {
+
+ public final static String TAG = "WatchActivity";
+ private PowerManager mPowerManager;
+ private SharedPreferences mSettings;
+ private static final int RESET = 0;
+ private static final int RUNNING = 1;
+ private static final int PAUSED = 2;
+ private static int sChronometerState = RESET;
+ private static long sChronometerBase;
+ private static long sChronometerPaused;
+ private static long sChronometerStarted;
+ private final int DIM_WHITE = 0x60ffffff;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.watch);
+
+ // Log.v(TAG,"onCreate");
+
+ mSettings = getSharedPreferences(WatchService.PREFS, 0);
+
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ Log.v(TAG, "onStart");
+
+ Intent intent = getIntent();
+
+ // if(intent.getAction().equals("start")) {
+ Log.i(TAG, "START");
+ Window window = getWindow();
+ window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
+ window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
+ // window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+ // window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
+ // /int orientation = intent.getIntExtra("orientation",
+ // ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
+ setRequestedOrientation(mSettings.getInt("orientation",
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE));
+
+ String date = DateFormat
+ .getLongDateFormat(this).format(new Date());
+ Log.i(TAG,"Setting date to: "+date);
+ ((TextView) findViewById(R.id.dateText)).setText(date);
+
+ final Chronometer chronometer = (Chronometer) findViewById(R.id.chronometer2);
+
+ if(sChronometerState == RESET) {
+ chronometer.setTextColor(DIM_WHITE);
+ }
+ else {
+ chronometer.setTextColor(Color.WHITE);
+ }
+ // chronometer.setFormat("H:MM:SS");
+
+ // Log.v(TAG,String.format("base: %d", chronometer.getBase()));
+
+ // Log.v(TAG,String.format("state: %d", sChronometerState));
+ if (sChronometerState == RESET) {
+
+ } else if (sChronometerState == RUNNING) {
+ chronometer.setBase(sChronometerBase);
+ chronometer.start();
+ } else if (sChronometerState == PAUSED) {
+ chronometer.setBase(sChronometerBase
+ + (SystemClock.elapsedRealtime() - sChronometerPaused));
+ }
+
+ chronometer.setOnClickListener(new OnClickListener() {
+
+ public void onClick(View v) {
+
+ Log.v(TAG, String.format("state: %d", sChronometerState));
+
+ if (sChronometerState == RESET) {
+ sChronometerState = RUNNING;
+ sChronometerBase = SystemClock.elapsedRealtime();
+ sChronometerStarted = SystemClock.elapsedRealtime();
+ chronometer.setTextColor(Color.WHITE);
+ chronometer.setBase(sChronometerBase);
+ chronometer.start();
+
+ // Log.v(TAG,String.format("state: %d", sChronometerState));
+ } else if (sChronometerState == RUNNING) {
+ sChronometerState = PAUSED;
+ sChronometerPaused = SystemClock.elapsedRealtime();
+ chronometer.stop();
+ } else if (sChronometerState == PAUSED) {
+ sChronometerState = RUNNING;
+ Log.v(TAG,
+ String.format(
+ "elapsed: %d",
+ (SystemClock.elapsedRealtime() - sChronometerPaused)));
+ chronometer.setBase(sChronometerBase
+ + (SystemClock.elapsedRealtime() - sChronometerPaused));
+ sChronometerBase = chronometer.getBase();
+ sChronometerStarted = SystemClock.elapsedRealtime();
+ chronometer.start();
+ }
+ }
+ });
+
+ chronometer.setOnLongClickListener(new OnLongClickListener() {
+
+ public boolean onLongClick(View v) {
+ sChronometerState = RESET;
+ chronometer.stop();
+ chronometer.setBase(SystemClock.elapsedRealtime());
+ chronometer.setTextColor(DIM_WHITE);
+ return true;
+ }
+ });
+
+ if (Build.VERSION.SDK_INT > 11) {
+ getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LOW_PROFILE);
+ }
+
+ WindowManager.LayoutParams params = getWindow().getAttributes();
+ params.screenBrightness = (float) 1.0;
+ window.setAttributes(params);
+
+ // }
+
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ // Log.v(TAG,"onStop");
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.watch, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ startActivity(new Intent(getApplicationContext(),
+ SettingsActivity2.class));
+ return true;
+ }
+
+}
View
42 src/com/theultimatelabs/watch/WatchReceiver.java
@@ -0,0 +1,42 @@
+package com.theultimatelabs.watch;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.Spinner;
+import android.widget.Toast;
+
+public class WatchReceiver extends BroadcastReceiver {
+
+ public final static String TAG = "WatchReceiver";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.i(TAG,"OnReceive "+intent.getAction());
+ if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ context.startService(new Intent(context,WatchService.class));
+ }
+ }
+
+
+
+}
View
238 src/com/theultimatelabs/watch/WatchService.java
@@ -0,0 +1,238 @@
+package com.theultimatelabs.watch;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+import android.util.Log;
+
+public class WatchService extends Service implements SensorEventListener {
+
+ private SensorManager mSensorManager;
+ private Sensor mAccelerometer;
+ private float mTargetX;// = (float) -5.0;
+ private float mTargetY;// = (float) -1.0;
+ private float mTargetZ;// = (float) 7.0;
+ final float THRESHOLD = (float) 3.0;
+ private PowerManager mPowerManager;
+ private WakeLock mPartialWakeLock;
+ private WakeLock mFullWakeLock;
+ private float mOnThreshold;
+ private float mOffThreshold;
+ static final String TAG = "WatchService";
+ public static final String PREFS = "PREFS";
+ private int mOrientation;
+ private boolean mEnabled;
+ private IntentFilter mFilter;
+ private Handler mHandler;
+ private boolean mSleeping = false;
+ private long mSleepTimeout;
+
+ @Override
+ public void onCreate() {
+
+ Log.v(TAG, "Service Started");
+ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+ mAccelerometer = mSensorManager
+ .getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+
+ mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ mPartialWakeLock = mPowerManager.newWakeLock(
+ PowerManager.PARTIAL_WAKE_LOCK, "partial");
+ mPartialWakeLock.setReferenceCounted(false);
+
+ mFullWakeLock = mPowerManager.newWakeLock(
+ PowerManager.ACQUIRE_CAUSES_WAKEUP
+ | PowerManager.FULL_WAKE_LOCK, "full");
+
+ mFilter = new IntentFilter();
+ mFilter.addAction(Intent.ACTION_SCREEN_OFF);
+ mFilter.addAction(Intent.ACTION_SCREEN_ON);
+ mFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
+ mFilter.addAction(Intent.ACTION_POWER_CONNECTED);
+
+ mHandler = new Handler();
+
+ registerReceiver(mBroadcastReciever, mFilter);
+
+ }
+
+ private void enable() {
+ Log.i(TAG, "enable");
+ mSensorManager.registerListener(this, mAccelerometer,
+ SensorManager.SENSOR_DELAY_NORMAL);
+ mPartialWakeLock.acquire();
+ mFullWakeLock.setReferenceCounted(false);
+ Log.i(TAG,"enabled");
+ }
+
+ private void disable() {
+ Log.i(TAG, "disable");
+ mSensorManager.unregisterListener(this);
+ if (mPartialWakeLock.isHeld()) {
+ mPartialWakeLock.release();
+ }
+
+ if (mFullWakeLock.isHeld()) {
+ mFullWakeLock.release();
+ }
+
+ }
+
+ @Override
+ public void onDestroy() {
+
+ Log.v(TAG, "onDestroy");
+ disable();
+ unregisterReceiver(mBroadcastReciever);
+ super.onDestroy();
+
+ }
+
+ public void onAccuracyChanged(Sensor arg0, int arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public BroadcastReceiver mBroadcastReciever = new BroadcastReceiver() {
+
+
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action == null)
+ return;
+ Log.v(TAG, "onRecevie: " + action);
+ if (action.equals(Intent.ACTION_SCREEN_ON)) {
+ mHandler.removeCallbacks(sleepTimeout);
+ mHandler.postDelayed(sleepTimeout, mSleepTimeout);
+ if(mSleeping == true) {
+ mSleeping = false;
+ enable();
+ }
+ } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
+ mHandler.removeCallbacks(sleepTimeout);
+ mHandler.postDelayed(sleepTimeout, mSleepTimeout);
+ } else if (action.equals(Intent.ACTION_POWER_CONNECTED)) {
+
+ } else if (action.equals(Intent.ACTION_POWER_DISCONNECTED)) {
+
+ }
+ }
+
+ };
+
+ private Runnable sleepTimeout = new Runnable() {
+
+ public void run() {
+ Log.w(TAG,"Sleep Timeout");
+ mSleeping = true;
+ disable();
+ }
+ };
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.v(TAG, "onStartCommand");
+
+ Log.i(TAG, "Refreshing service with new preferences");
+
+ SharedPreferences settings = getSharedPreferences(PREFS, 0);
+ mOnThreshold = (float) settings.getInt("onThreshold", 2);
+ mOffThreshold = (float) settings.getInt("offThreshold", 4);
+ mTargetX = settings.getFloat("targetX", (float) -4.0);
+ mTargetY = settings.getFloat("targetY", (float) -1.0);
+ mTargetZ = settings.getFloat("targetZ", (float) -9.0);
+ mOrientation = settings.getInt("orientation",
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
+ int timeout = settings.getInt("sleepTimeout", 4);
+ mSleepTimeout = timeout==0?0:(1<<(timeout-1))*15*60*1000;
+ Log.i(TAG,String.format("SleepTimeout=%d",mSleepTimeout/(60*1000)));
+ mEnabled = settings.getBoolean("enabled", true);
+ if (mEnabled) {
+ enable();
+ } else {
+ stopSelf();
+ }
+ // We want this service to continue running until it is explicitly
+ // stopped, so return sticky.
+ return START_STICKY;
+ }
+
+ boolean mStarted = false;
+
+ public void onSensorChanged(SensorEvent event) {
+
+
+ float x = event.values[0];
+ float y = event.values[1];
+ float z = event.values[2];
+
+ float mag = (float) Math.sqrt(x*x + y*y + z*z);
+ if(mag > 10.5) {
+ //Restart sleep timer
+ Log.v(TAG, String.format("mag: %f",mag));
+ mHandler.removeCallbacks(sleepTimeout);
+ mHandler.postDelayed(sleepTimeout, mSleepTimeout);
+ }
+
+
+ boolean xOn = (x > (mTargetX - mOnThreshold))
+ && (x < (mTargetX + mOnThreshold));
+ boolean yOn = (y > (mTargetY - mOnThreshold))
+ && (y < (mTargetY + mOnThreshold));
+ boolean zOn = (z > (mTargetZ - mOnThreshold))
+ && (z < (mTargetZ + mOnThreshold));
+
+ boolean xOff = (x < (mTargetX - mOffThreshold))
+ || (x > (mTargetX + mOffThreshold));
+ boolean yOff = (y < (mTargetY - mOffThreshold))
+ || (y > (mTargetY + mOffThreshold));
+ boolean zOff = (z < (mTargetZ - mOffThreshold))
+ || (z > (mTargetZ + mOffThreshold));
+
+ // Log.v(TAG,String.format("%f/%d %f/%d %f/%d",x,xMatch?1:0,y,yMatch?1:0,z,zMatch?1:0));
+ if (xOn && yOn && zOn) {
+ if (!mPowerManager.isScreenOn()) {
+ Log.v(TAG, "starting++++");
+ Intent startIntent = new Intent(getApplicationContext(),
+ WatchActivity.class);
+ startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+ startIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
+ startIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
+ startIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ startIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+
+ mFullWakeLock.acquire();
+ startIntent.setAction("start");
+ startIntent.putExtra("orientation", mOrientation);
+ startActivity(startIntent);
+ }
+ } else if (xOff || yOff || zOff) {
+ if (mFullWakeLock.isHeld()) {
+ Log.v(TAG, "stopping-----");
+ mFullWakeLock.release();
+ }
+ }
+
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
View
BIN web_hi_res_512.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3a0f835

Please sign in to comment.