├── assets ├── play.bmp ├── Thumbs.db ├── email.bmp ├── phone.bmp ├── timer.bmp ├── idle_call.bmp ├── idle_sms.bmp ├── message.bmp ├── idle_gmail.bmp ├── idle_icons_row.bmp ├── weather_cloudy.bmp ├── weather_rain.bmp ├── weather_snow.bmp ├── weather_sunny.bmp ├── weather_wind.bmp ├── metawatch_16pt_11pxl.ttf ├── weather_thunderstorm.bmp ├── metawatch_8pt_5pxl_CAPS.ttf ├── metawatch_8pt_7pxl_CAPS.ttf └── mdpi │ └── _pre_production │ └── notification.svg ├── res ├── drawable-hdpi │ ├── icon.png │ ├── connected.png │ ├── disconnected.png │ ├── connected_large.png │ └── disconnected_large.png ├── drawable-ldpi │ └── icon.png ├── drawable-mdpi │ └── icon.png ├── layout │ ├── main.xml │ ├── device_selection.xml │ ├── notification.xml │ ├── list_item.xml │ └── settings.xml ├── menu │ ├── menu.xml │ └── test.xml └── values │ └── strings.xml ├── .settings └── org.eclipse.jdt.core.prefs ├── .classpath ├── default.properties ├── project.properties ├── src └── org │ ├── anddev │ └── android │ │ └── weatherforecast │ │ └── weather │ │ ├── WeatherUtils.java │ │ ├── WeatherSet.java │ │ ├── WeatherForecastCondition.java │ │ ├── WeatherCurrentCondition.java │ │ └── GoogleWeatherHandler.java │ └── metawatch │ └── manager │ ├── BootUpReceiver.java │ ├── CallVibrate.java │ ├── AlarmReceiver.java │ ├── TestSmsLoop.java │ ├── ImageViewer.java │ ├── CallStateListener.java │ ├── MediaControl.java │ ├── Settings.java │ ├── Call.java │ ├── ApiIntentReceiver.java │ ├── MetaWatch.java │ ├── Message.java │ ├── Application.java │ ├── IntentReceiver.java │ ├── Test.java │ ├── Utils.java │ ├── Idle.java │ ├── DeviceSelection.java │ ├── NotificationBuilder.java │ ├── GmailMonitor.java │ ├── Monitors.java │ ├── Notification.java │ └── MetaWatchService.java ├── NOTICE ├── README ├── MW_v0.2.4b_APK_API.txt ├── .project ├── proguard.cfg ├── AndroidManifest.xml └── LICENSE /assets/play.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/play.bmp -------------------------------------------------------------------------------- /assets/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/Thumbs.db -------------------------------------------------------------------------------- /assets/email.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/email.bmp -------------------------------------------------------------------------------- /assets/phone.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/phone.bmp -------------------------------------------------------------------------------- /assets/timer.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/timer.bmp -------------------------------------------------------------------------------- /assets/idle_call.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/idle_call.bmp -------------------------------------------------------------------------------- /assets/idle_sms.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/idle_sms.bmp -------------------------------------------------------------------------------- /assets/message.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/message.bmp -------------------------------------------------------------------------------- /assets/idle_gmail.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/idle_gmail.bmp -------------------------------------------------------------------------------- /assets/idle_icons_row.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/idle_icons_row.bmp -------------------------------------------------------------------------------- /assets/weather_cloudy.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/weather_cloudy.bmp -------------------------------------------------------------------------------- /assets/weather_rain.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/weather_rain.bmp -------------------------------------------------------------------------------- /assets/weather_snow.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/weather_snow.bmp -------------------------------------------------------------------------------- /assets/weather_sunny.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/weather_sunny.bmp -------------------------------------------------------------------------------- /assets/weather_wind.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/weather_wind.bmp -------------------------------------------------------------------------------- /res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /assets/metawatch_16pt_11pxl.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/metawatch_16pt_11pxl.ttf -------------------------------------------------------------------------------- /assets/weather_thunderstorm.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/weather_thunderstorm.bmp -------------------------------------------------------------------------------- /res/drawable-hdpi/connected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/res/drawable-hdpi/connected.png -------------------------------------------------------------------------------- /assets/metawatch_8pt_5pxl_CAPS.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/metawatch_8pt_5pxl_CAPS.ttf -------------------------------------------------------------------------------- /assets/metawatch_8pt_7pxl_CAPS.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/assets/metawatch_8pt_7pxl_CAPS.ttf -------------------------------------------------------------------------------- /res/drawable-hdpi/disconnected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/res/drawable-hdpi/disconnected.png -------------------------------------------------------------------------------- /res/drawable-hdpi/connected_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/res/drawable-hdpi/connected_large.png -------------------------------------------------------------------------------- /res/drawable-hdpi/disconnected_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MetaWatchOpenProjects/MWM-for-Android-Gen1/HEAD/res/drawable-hdpi/disconnected_large.png -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Sun May 22 00:01:09 CEST 2011 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-13 12 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-13 12 | -------------------------------------------------------------------------------- /src/org/anddev/android/weatherforecast/weather/WeatherUtils.java: -------------------------------------------------------------------------------- 1 | package org.anddev.android.weatherforecast.weather; 2 | 3 | /** Useful Utility in working with temperatures. (conversions). */ 4 | public class WeatherUtils { 5 | 6 | public static int fahrenheitToCelsius(int tFahrenheit) { 7 | return (int) ((5.0f / 9.0f) * (tFahrenheit - 32)); 8 | } 9 | 10 | public static int celsiusToFahrenheit(int tCelsius) { 11 | return (int) ((9.0f / 5.0f) * tCelsius + 32); 12 | } 13 | } -------------------------------------------------------------------------------- /res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file for Meta Watch Manager for Android == 3 | == == 4 | ========================================================================= 5 | 6 | Meta Watch Manager for Android 7 | Copyright 2011 Meta Watch Ltd. 8 | 9 | Android Weather Forecast - Google Weather API 10 | This software were developed by plusminus from anddev.org 11 | (Android Weather Forecast - Google Weather API) 12 | 13 | 14 | -------------------------------------------------------------------------------- /res/layout/device_selection.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Welcome. This is the Meta Watch Manager (MWM) for Android project. 2 | 3 | Read the LICENSE and the NOTICE files in the root. 4 | 5 | Visit us at http://www.metawatch.org 6 | 7 | Report bugs and request enhancements at: http://bugs.metawatch.org 8 | 9 | Meta Watch will be keeping this project up to date and periodically releasing new 10 | stable versions on the Metawatch.org website and on the Android Market. 11 | 12 | Contributing your code to this project is encouraged. 13 | To contribute your code, you must please fill out and submit a contributor agreement. 14 | You can find this in the developer section of the metawatch.org website. 15 | 16 | Have fun! -------------------------------------------------------------------------------- /MW_v0.2.4b_APK_API.txt: -------------------------------------------------------------------------------- 1 | Handled: 2 | 3 | org.metawatch.manager.NOTIFICATION 4 | "array" - int[96*96] 5 | or 6 | "buffer" - byte[96*96/8] // encoded buffer 7 | -- 8 | "vibrate_on" - int // ms 9 | "vibrate_off" - int // ms 10 | "vibrate_cycles" - int 11 | 12 | org.metawatch.manager.APPLICATION_UPDATE 13 | "array" - int[96*96] 14 | or 15 | "buffer" - byte[96*96/8] // encoded buffer 16 | 17 | org.metawatch.manager.APPLICATION_START 18 | 19 | org.metawatch.manager.APPLICATION_STOP 20 | 21 | 22 | org.metawatch.manager.IDLE_BUTTONS_OVERRIDE 23 | "buttons" - byte[] // buttons to override 24 | 25 | 26 | 27 | 28 | 29 | 30 | Broadcasted: 31 | 32 | org.metawatch.manager.BUTTON_PRESS 33 | "button" - byte 34 | "mode" - String // ("application", "idle") 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/BootUpReceiver.java: -------------------------------------------------------------------------------- 1 | package org.metawatch.manager; 2 | 3 | import org.metawatch.manager.MetaWatchService.Preferences; 4 | 5 | import android.content.BroadcastReceiver; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.SharedPreferences; 9 | import android.preference.PreferenceManager; 10 | 11 | public class BootUpReceiver extends BroadcastReceiver { 12 | 13 | @Override 14 | public void onReceive(Context context, Intent intent) { 15 | 16 | SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); 17 | 18 | 19 | if (sharedPreferences.getBoolean("StartOnBoot", Preferences.startOnBoot)) { 20 | context.startService(new Intent(context, MetaWatchService.class)); 21 | } 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /res/layout/notification.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 19 | -------------------------------------------------------------------------------- /res/layout/list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 12 | 13 | 22 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | MetaWatch 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembernames class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembernames class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers enum * { 30 | public static **[] values(); 31 | public static ** valueOf(java.lang.String); 32 | } 33 | 34 | -keep class * implements android.os.Parcelable { 35 | public static final android.os.Parcelable$Creator *; 36 | } 37 | -------------------------------------------------------------------------------- /src/org/anddev/android/weatherforecast/weather/WeatherSet.java: -------------------------------------------------------------------------------- 1 | package org.anddev.android.weatherforecast.weather; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * Combines one WeatherCurrentCondition with a List of 7 | * WeatherForecastConditions. 8 | */ 9 | public class WeatherSet { 10 | 11 | // =========================================================== 12 | // Fields 13 | // =========================================================== 14 | 15 | private WeatherCurrentCondition myCurrentCondition = null; 16 | private ArrayList myForecastConditions = 17 | new ArrayList(4); 18 | 19 | // =========================================================== 20 | // Getter & Setter 21 | // =========================================================== 22 | 23 | public WeatherCurrentCondition getWeatherCurrentCondition() { 24 | return myCurrentCondition; 25 | } 26 | 27 | public void setWeatherCurrentCondition( 28 | WeatherCurrentCondition myCurrentWeather) { 29 | this.myCurrentCondition = myCurrentWeather; 30 | } 31 | 32 | public ArrayList getWeatherForecastConditions() { 33 | return this.myForecastConditions; 34 | } 35 | 36 | public WeatherForecastCondition getLastWeatherForecastCondition() { 37 | return this.myForecastConditions 38 | .get(this.myForecastConditions.size() - 1); 39 | } 40 | } -------------------------------------------------------------------------------- /res/menu/test.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | MetaWatch 4 | 5 | Main 6 | 7 | Start On Boot 8 | Start MetaWatch service on boot 9 | 10 | 11 | Notifications 12 | Call 13 | Incoming call notification 14 | SMS 15 | New text message notification 16 | K9 mail 17 | New E-mail notification (K-9 mail) 18 | Alarm 19 | Alarm clock alert 20 | Music 21 | Music track/artist info 22 | 23 | Device 24 | MAC 25 | Watch Bluetooth MAC address 26 | 27 | 28 | Small 29 | Medium 30 | Large 31 | 32 | 33 | 1 34 | 2 35 | 3 36 | 37 | 38 | Other 39 | 40 | 41 | Tests 42 | Settings 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/org/anddev/android/weatherforecast/weather/WeatherForecastCondition.java: -------------------------------------------------------------------------------- 1 | package org.anddev.android.weatherforecast.weather; 2 | 3 | /** 4 | * Holds the information between the -tag of what the 5 | * Google Weather API returned. 6 | */ 7 | public class WeatherForecastCondition { 8 | 9 | // =========================================================== 10 | // Fields 11 | // =========================================================== 12 | 13 | private String dayofWeek = null; 14 | private Integer tempMin = null; 15 | private Integer tempMax = null; 16 | private String iconURL = null; 17 | private String condition = null; 18 | 19 | // =========================================================== 20 | // Constructors 21 | // =========================================================== 22 | 23 | public WeatherForecastCondition() { 24 | 25 | } 26 | 27 | // =========================================================== 28 | // Getter & Setter 29 | // =========================================================== 30 | 31 | public String getDayofWeek() { 32 | return dayofWeek; 33 | } 34 | 35 | public void setDayofWeek(String dayofWeek) { 36 | this.dayofWeek = dayofWeek; 37 | } 38 | 39 | public Integer getTempMinCelsius() { 40 | return tempMin; 41 | } 42 | 43 | public void setTempMinCelsius(Integer tempMin) { 44 | this.tempMin = tempMin; 45 | } 46 | 47 | public Integer getTempMaxCelsius() { 48 | return tempMax; 49 | } 50 | 51 | public void setTempMaxCelsius(Integer tempMax) { 52 | this.tempMax = tempMax; 53 | } 54 | 55 | public String getIconURL() { 56 | return iconURL; 57 | } 58 | 59 | public void setIconURL(String iconURL) { 60 | this.iconURL = iconURL; 61 | } 62 | 63 | public String getCondition() { 64 | return condition; 65 | } 66 | 67 | public void setCondition(String condition) { 68 | this.condition = condition; 69 | } 70 | } -------------------------------------------------------------------------------- /src/org/anddev/android/weatherforecast/weather/WeatherCurrentCondition.java: -------------------------------------------------------------------------------- 1 | package org.anddev.android.weatherforecast.weather; 2 | 3 | /** 4 | * Holds the information between the -tag of what the Google 5 | * Weather API returned. 6 | */ 7 | public class WeatherCurrentCondition { 8 | 9 | // =========================================================== 10 | // Fields 11 | // =========================================================== 12 | 13 | private String dayofWeek = null; 14 | private Integer tempCelcius = null; 15 | private Integer tempFahrenheit = null; 16 | private String iconURL = null; 17 | private String condition = null; 18 | private String windCondition = null; 19 | private String humidity = null; 20 | private String city = null; 21 | 22 | // =========================================================== 23 | // Constructors 24 | // =========================================================== 25 | 26 | public WeatherCurrentCondition() { 27 | 28 | } 29 | 30 | // =========================================================== 31 | // Getter & Setter 32 | // =========================================================== 33 | 34 | public String getCity() { 35 | return this.city; 36 | } 37 | 38 | public String getDayofWeek() { 39 | return this.dayofWeek; 40 | } 41 | 42 | public void setDayofWeek(String dayofWeek) { 43 | this.dayofWeek = dayofWeek; 44 | } 45 | 46 | public Integer getTempCelcius() { 47 | return this.tempCelcius; 48 | } 49 | 50 | public void setTempCelcius(Integer temp) { 51 | this.tempCelcius = temp; 52 | } 53 | 54 | public Integer getTempFahrenheit() { 55 | return this.tempFahrenheit; 56 | } 57 | 58 | public void setTempFahrenheit(Integer temp) { 59 | this.tempFahrenheit = temp; 60 | } 61 | 62 | public String getIconURL() { 63 | return this.iconURL; 64 | } 65 | 66 | public void setCity(String city) { 67 | this.city = city; 68 | } 69 | 70 | public void setIconURL(String iconURL) { 71 | this.iconURL = iconURL; 72 | } 73 | 74 | public String getCondition() { 75 | return this.condition; 76 | } 77 | 78 | public void setCondition(String condition) { 79 | this.condition = condition; 80 | } 81 | 82 | public String getWindCondition() { 83 | return this.windCondition; 84 | } 85 | 86 | public void setWindCondition(String windCondition) { 87 | this.windCondition = windCondition; 88 | } 89 | 90 | public String getHumidity() { 91 | return this.humidity; 92 | } 93 | 94 | public void setHumidity(String humidity) { 95 | this.humidity = humidity; 96 | } 97 | } -------------------------------------------------------------------------------- /src/org/metawatch/manager/CallVibrate.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * CallVibrate.java * 27 | * CallVibrate * 28 | * While in incoming call mode * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import org.metawatch.manager.MetaWatchService.WatchType; 36 | 37 | public class CallVibrate implements Runnable { 38 | 39 | public void run() { 40 | 41 | while (Call.isRinging) { 42 | Protocol.vibrate(1000, 0, 1); 43 | if (MetaWatchService.watchType == WatchType.DIGITAL) 44 | Protocol.updateDisplay(2); 45 | else 46 | Protocol.updateOledsNotification(); 47 | 48 | try { 49 | Thread.sleep(2000); 50 | } catch (InterruptedException e) { 51 | } 52 | } 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/AlarmReceiver.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | /***************************************************************************** 8 | * Copyright (c) 2011 Meta Watch Ltd. * 9 | * www.MetaWatch.org * 10 | * * 11 | ============================================================================= 12 | * * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); * 14 | * you may not use this file except in compliance with the License. * 15 | * You may obtain a copy of the License at * 16 | * * 17 | * http://www.apache.org/licenses/LICENSE-2.0 * 18 | * * 19 | * Unless required by applicable law or agreed to in writing, software * 20 | * distributed under the License is distributed on an "AS IS" BASIS, * 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 | * See the License for the specific language governing permissions and * 23 | * limitations under the License. * 24 | * * 25 | *****************************************************************************/ 26 | 27 | /***************************************************************************** 28 | * AlarmReceiver.java * 29 | * AlarmReceiver * 30 | * Receiver for RTC wakeup intents used for weather updates * 31 | * * 32 | * * 33 | *****************************************************************************/ 34 | 35 | package org.metawatch.manager; 36 | 37 | import android.content.BroadcastReceiver; 38 | import android.content.Context; 39 | import android.content.Intent; 40 | import android.util.Log; 41 | 42 | public class AlarmReceiver extends BroadcastReceiver { 43 | 44 | @Override 45 | public void onReceive(Context context, Intent intent) { 46 | 47 | Log.d(MetaWatch.TAG, "intent rec: "+ intent.toString()); 48 | 49 | if (intent.hasExtra("action_update")) { 50 | 51 | Monitors.updateWeatherData(context); 52 | 53 | return; 54 | } 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/TestSmsLoop.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * TestSmsLoop.java * 27 | * TestSmsLoop * 28 | * Sending test SMS in a loop * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import android.content.Context; 36 | 37 | public class TestSmsLoop implements Runnable { 38 | 39 | Context context; 40 | boolean runLoop; 41 | 42 | public TestSmsLoop(Context context) { 43 | this.context = context; 44 | } 45 | 46 | public void run() { 47 | runLoop = true; 48 | for (int i = 1; runLoop; i++) { 49 | NotificationBuilder.createSMS(context, "123-456-789", "\n Test SMS #" + i); 50 | try { 51 | Thread.sleep(MetaWatchService.Preferences.smsLoopInterval*1000); 52 | } catch (InterruptedException e) { 53 | } 54 | } 55 | } 56 | 57 | public void stop() { 58 | runLoop = false; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/ImageViewer.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * ImageViewer.java * 27 | * ImageViewer * 28 | * System wide "Send to watch" that shows pictures in app mode * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import android.app.Activity; 36 | import android.content.Intent; 37 | import android.graphics.BitmapFactory; 38 | import android.os.Bundle; 39 | import android.util.Log; 40 | 41 | public class ImageViewer extends Activity { 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | 47 | Intent i = getIntent(); 48 | 49 | Log.d(MetaWatch.TAG, "action: " + i.getAction()); 50 | Log.d(MetaWatch.TAG, "data: "+ i.getData().getPath() ); 51 | 52 | Application.updateAppMode(this, BitmapFactory.decodeFile(i.getData().getPath())); 53 | 54 | finish(); 55 | } 56 | 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /assets/mdpi/_pre_production/notification.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 9 | 13 | 14 | 15 | 18 | 22 | 23 | 24 | 27 | 30 | 31 | 32 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/CallStateListener.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * CallStateListener.java * 27 | * CallStateListener * 28 | * Listener waiting for incoming call * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import android.content.Context; 36 | import android.telephony.PhoneStateListener; 37 | import android.telephony.TelephonyManager; 38 | 39 | 40 | class CallStateListener extends PhoneStateListener { 41 | 42 | Context context; 43 | 44 | public CallStateListener(Context ctx) { 45 | super(); 46 | context = ctx; 47 | } 48 | 49 | @Override 50 | public void onCallStateChanged(int state, String incomingNumber) { 51 | super.onCallStateChanged(state, incomingNumber); 52 | 53 | if (!MetaWatchService.Preferences.notifyCall) 54 | return; 55 | 56 | if (incomingNumber == null) 57 | incomingNumber = ""; 58 | 59 | switch (state) { 60 | case TelephonyManager.CALL_STATE_RINGING: 61 | //String name = Utils.getContactNameFromNumber(context, incomingNumber); 62 | //SendCommand.sendIncomingCallStart(incomingNumber, name, photo); 63 | Call.startCall(context, incomingNumber); 64 | break; 65 | case TelephonyManager.CALL_STATE_IDLE: 66 | Call.endCall(context); 67 | break; 68 | case TelephonyManager.CALL_STATE_OFFHOOK: 69 | Call.endCall(context); 70 | break; 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/MediaControl.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * MediaControl.java * 27 | * MediaControl * 28 | * Volume control and vanilla Android player control via intents * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import android.content.Context; 36 | import android.content.Intent; 37 | import android.media.AudioManager; 38 | 39 | public class MediaControl { 40 | 41 | final static byte VOLUME_UP = 10; 42 | final static byte VOLUME_DOWN = 11; 43 | final static byte NEXT = 15; 44 | final static byte PREVIOUS = 16; 45 | final static byte TOGGLE = 20; 46 | 47 | public static void next(Context context) { 48 | context.sendBroadcast(new Intent("com.android.music.musicservicecommand.next")); 49 | } 50 | 51 | public static void previous(Context context) { 52 | context.sendBroadcast(new Intent("com.android.music.musicservicecommand.previous")); 53 | } 54 | 55 | public static void togglePause(Context context) { 56 | context.sendBroadcast(new Intent("com.android.music.musicservicecommand.togglepause")); 57 | } 58 | 59 | public static void volumeDown(AudioManager audioManager) { 60 | audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0); 61 | } 62 | 63 | public static void volumeUp(AudioManager audioManager) { 64 | audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/Settings.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Settings.java * 27 | * Settings * 28 | * Preference activity * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import android.content.Context; 36 | import android.content.Intent; 37 | import android.os.Bundle; 38 | import android.preference.EditTextPreference; 39 | import android.preference.Preference; 40 | import android.preference.Preference.OnPreferenceClickListener; 41 | import android.preference.PreferenceActivity; 42 | import android.preference.PreferenceScreen; 43 | import android.util.Log; 44 | 45 | public class Settings extends PreferenceActivity { 46 | 47 | Context context; 48 | 49 | PreferenceScreen preferenceScreen; 50 | Preference discovery; 51 | 52 | EditTextPreference editTextMac; 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | context = this; 58 | 59 | setTitle(getString(R.string.app_name) + " - " + getString(R.string.activitiy_title_settings)); 60 | 61 | addPreferencesFromResource(R.layout.settings); 62 | 63 | preferenceScreen = getPreferenceScreen(); 64 | 65 | } 66 | 67 | @Override 68 | protected void onStart() { 69 | 70 | Log.d(MetaWatch.TAG, "set onstart"); 71 | 72 | editTextMac = (EditTextPreference) preferenceScreen.findPreference("MAC"); 73 | editTextMac.setText(MetaWatchService.Preferences.watchMacAddress); 74 | 75 | discovery = preferenceScreen.findPreference("Discovery"); 76 | discovery.setOnPreferenceClickListener(new OnPreferenceClickListener() { 77 | 78 | public boolean onPreferenceClick(Preference arg0) { 79 | 80 | Log.d(MetaWatch.TAG, "discovery click"); 81 | 82 | startActivity(new Intent(context, DeviceSelection.class)); 83 | 84 | return false; 85 | } 86 | }); 87 | 88 | super.onStart(); 89 | } 90 | 91 | 92 | 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/Call.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Call.java * 27 | * Call * 28 | * Call watch mode * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import org.metawatch.manager.MetaWatchService.WatchType; 36 | import org.metawatch.manager.Notification.VibratePattern; 37 | 38 | import android.content.Context; 39 | import android.graphics.Bitmap; 40 | 41 | public class Call { 42 | 43 | public static boolean isRinging = false; 44 | 45 | public static void startCall(Context context, String number) { 46 | toCall(); 47 | 48 | isRinging = true; 49 | 50 | Bitmap bitmap; 51 | String name = Utils.getContactNameFromNumber(context, number); 52 | 53 | if (name.equals(number)) 54 | bitmap = NotificationBuilder.smartLines(context, "phone.bmp", new String[] { number}); 55 | else 56 | bitmap = NotificationBuilder.smartLines(context, "phone.bmp", new String[] { number, name }); 57 | 58 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 59 | Protocol.sendLcdBitmap(bitmap, MetaWatchService.WatchBuffers.NOTIFICATION); 60 | Protocol.updateDisplay(2); 61 | } else { 62 | Notification.addOledNotification(context, Protocol.createOled1line(context, "phone.bmp", "Call from"), Protocol.createOled1line(context, null, name), null, 0, new VibratePattern(true, 500, 500, 3)); 63 | } 64 | 65 | Thread ringer = new Thread(new CallVibrate()); 66 | ringer.start(); 67 | } 68 | 69 | public static void endCall(Context context) { 70 | isRinging = false; 71 | exitCall(context); 72 | } 73 | 74 | static void toCall() { 75 | MetaWatchService.watchState = MetaWatchService.WatchStates.CALL; 76 | MetaWatchService.WatchModes.CALL = true; 77 | } 78 | 79 | static void exitCall(Context context) { 80 | 81 | MetaWatchService.WatchModes.CALL = false; 82 | 83 | if (MetaWatchService.WatchModes.NOTIFICATION == true) 84 | Notification.toNotification(context); 85 | else if (MetaWatchService.WatchModes.APPLICATION == true) 86 | Application.toApp(); 87 | else if (MetaWatchService.WatchModes.IDLE == true) 88 | Idle.toIdle(context); 89 | } 90 | 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /res/layout/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 14 | 15 | 16 | 17 | 20 | 26 | 32 | 38 | 44 | 50 | 56 | 57 | 58 | 61 | 67 | 72 | 73 | 74 | 75 | 78 | 84 | 90 | 100 | 106 | 112 | 119 | 125 | 131 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/ApiIntentReceiver.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * ApiIntentReceiver.java * 27 | * ApiIntentReceiver * 28 | * Intent receiver for 3rd party software * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import org.metawatch.manager.Notification.VibratePattern; 36 | 37 | import android.content.BroadcastReceiver; 38 | import android.content.Context; 39 | import android.content.Intent; 40 | import android.os.Bundle; 41 | 42 | public class ApiIntentReceiver extends BroadcastReceiver { 43 | 44 | @Override 45 | public void onReceive(Context context, Intent intent) { 46 | 47 | String action = intent.getAction(); 48 | 49 | // add digital watch check 50 | 51 | if (action.equals("org.metawatch.manager.APPLICATION_UPDATE")) { 52 | if (intent.hasExtra("array")) { 53 | int[] array = intent.getIntArrayExtra("array"); 54 | Application.updateAppMode(context, array); 55 | } else if (intent.hasExtra("buffer")) { 56 | byte[] buffer = intent.getByteArrayExtra("buffer"); 57 | Application.updateAppMode(context, buffer); 58 | } 59 | return; 60 | } 61 | 62 | if (action.equals("org.metawatch.manager.APPLICATION_START")) { 63 | Application.startAppMode(); 64 | return; 65 | } 66 | 67 | if (action.equals("org.metawatch.manager.APPLICATION_STOP")) { 68 | Application.startAppMode(); 69 | return; 70 | } 71 | 72 | if (action.equals("org.metawatch.manager.IDLE_BUTTONS_OVERRIDE")) { 73 | Bundle bundle = intent.getExtras(); 74 | if (bundle.containsKey("buttons")) { 75 | Idle.overridenButtons = bundle.getByteArray("buttons"); 76 | } else { 77 | Idle.overridenButtons = null; 78 | } 79 | return; 80 | } 81 | 82 | if (action.equals("org.metawatch.manager.NOTIFICATION")) { 83 | if (intent.hasExtra("array")) { 84 | int[] array = intent.getIntArrayExtra("array"); 85 | VibratePattern vibrate = null; 86 | if (intent.hasExtra("vibrate_on") && intent.hasExtra("vibrate_off") && intent.hasExtra("vibrate_cycles")) { 87 | int vibrateOn = intent.getIntExtra("vibrate_on", 500); 88 | int vibrateOff = intent.getIntExtra("vibrate_off", 500); 89 | int vibrateCycles = intent.getIntExtra("vibrate_cycles", 3); 90 | vibrate = new VibratePattern(true, vibrateOn, vibrateOff, vibrateCycles); 91 | } 92 | Notification.addArrayNotification(context, array, vibrate); 93 | } else if (intent.hasExtra("buffer")) { 94 | byte[] buffer = intent.getByteArrayExtra("buffer"); 95 | VibratePattern vibrate = null; 96 | if (intent.hasExtra("vibrate_on") && intent.hasExtra("vibrate_off") && intent.hasExtra("vibrate_cycles")) { 97 | int vibrateOn = intent.getIntExtra("vibrate_on", 500); 98 | int vibrateOff = intent.getIntExtra("vibrate_off", 500); 99 | int vibrateCycles = intent.getIntExtra("vibrate_cycles", 3); 100 | vibrate = new VibratePattern(true, vibrateOn, vibrateOff, vibrateCycles); 101 | } 102 | Notification.addBufferNotification(context, buffer, vibrate); 103 | } 104 | return; 105 | } 106 | 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/MetaWatch.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * MetaWatch.java * 27 | * MetaWatch * 28 | * Main activity with menu * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import org.metawatch.manager.MetaWatchService.Preferences; 36 | 37 | import android.app.Activity; 38 | import android.app.AlertDialog; 39 | import android.content.DialogInterface; 40 | import android.content.Intent; 41 | import android.os.Bundle; 42 | import android.view.Menu; 43 | import android.view.MenuInflater; 44 | import android.view.MenuItem; 45 | import android.webkit.WebView; 46 | 47 | public class MetaWatch extends Activity { 48 | 49 | public static final String TAG = "MetaWatch"; 50 | 51 | @Override 52 | public void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | setContentView(R.layout.main); 55 | setTitle(getString(R.string.app_name)); 56 | } 57 | 58 | @Override 59 | public boolean onCreateOptionsMenu(Menu menu) { 60 | MenuInflater inflater = getMenuInflater(); 61 | inflater.inflate(R.menu.menu, menu); 62 | return true; 63 | } 64 | 65 | @Override 66 | protected void onStart() { 67 | super.onStart(); 68 | 69 | MetaWatchService.loadPreferences(this); 70 | 71 | if (Preferences.idleMusicControls) 72 | Protocol.enableMediaButtons(); 73 | //else 74 | //Protocol.disableMediaButtons(); 75 | 76 | if (Preferences.idleReplay) 77 | Protocol.enableReplayButton(); 78 | //else 79 | //Protocol.disableReplayButton(); 80 | 81 | Protocol.configureMode(); 82 | } 83 | 84 | @Override 85 | public boolean onOptionsItemSelected(MenuItem item) { 86 | switch (item.getItemId()) { 87 | case R.id.start: 88 | startService(); 89 | return true; 90 | case R.id.stop: 91 | stopService(); 92 | return true; 93 | case R.id.test: 94 | startActivity(new Intent(this, Test.class)); 95 | return true; 96 | case R.id.settings: 97 | startActivity(new Intent(this, Settings.class)); 98 | return true; 99 | case R.id.about: 100 | showAbout(); 101 | return true; 102 | case R.id.exit: 103 | exit(); 104 | return true; 105 | default: 106 | return super.onOptionsItemSelected(item); 107 | } 108 | } 109 | 110 | void startService() { 111 | startService(new Intent(this, MetaWatchService.class)); 112 | } 113 | 114 | void stopService() { 115 | stopService(new Intent(this, MetaWatchService.class)); 116 | } 117 | 118 | void exit() { 119 | System.exit(0); 120 | } 121 | 122 | void showAbout() { 123 | 124 | WebView webView = new WebView(this); 125 | String html = "About" + 126 | "

MetaWatch

" + 127 | "

Version " + Utils.getVersion(this) + ".

" + 128 | "

© Copyright 2011 Meta Watch Ltd.

" + 129 | ""; 130 | webView.loadData(html, "text/html", "utf-8"); 131 | 132 | new AlertDialog.Builder(this).setView(webView).setCancelable(true).setPositiveButton("OK", new DialogInterface.OnClickListener() { 133 | //@Override 134 | public void onClick(DialogInterface dialog, int which) { 135 | dialog.dismiss(); 136 | } 137 | }).show(); 138 | } 139 | 140 | } -------------------------------------------------------------------------------- /src/org/metawatch/manager/Message.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright (c) 2011 Meta Watch Ltd. * 3 | * www.MetaWatch.org * 4 | * * 5 | ============================================================================= 6 | * * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); * 8 | * you may not use this file except in compliance with the License. * 9 | * You may obtain a copy of the License at * 10 | * * 11 | * http://www.apache.org/licenses/LICENSE-2.0 * 12 | * * 13 | * Unless required by applicable law or agreed to in writing, software * 14 | * distributed under the License is distributed on an "AS IS" BASIS, * 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 16 | * See the License for the specific language governing permissions and * 17 | * limitations under the License. * 18 | * * 19 | *****************************************************************************/ 20 | 21 | /***************************************************************************** 22 | * Message.java * 23 | * Message * 24 | * Message type constants * 25 | * * 26 | * * 27 | *****************************************************************************/ 28 | 29 | package org.metawatch.manager; 30 | 31 | public enum Message 32 | { 33 | InvalidMessage(0x00), 34 | 35 | GetDeviceType(0x01), 36 | GetDeviceTypeResponse(0x02), 37 | GetInfoString(0x03), 38 | GetInfoStringResponse(0x04), 39 | DiagnosticLoopback(0x05), 40 | EnterShippingModeMsg(0x06), 41 | SoftwareResetMsg(0x07), 42 | ConnectionTimeoutMsg(0x08), 43 | TurnRadioOnMsg(0x09), 44 | TurnRadioOffMsg(0x0a), 45 | SppReserved(0x0b), 46 | PariringControlMsg(0x0c), 47 | EnterSniffModeMsg(0x0d), 48 | xxReEnterSniffModeMsg(0x0e), 49 | LinkAlarmMsg(0x0f), 50 | 51 | /* 52 | * OLED display related commands 53 | */ 54 | OledWriteBufferMsg(0x10), 55 | OledConfigureModeMsg(0x11), 56 | OledChangeModeMsg(0x12), 57 | OledWriteScrollBufferMsg(0x13), 58 | OledScrollMsg(0x14), 59 | OledShowIdleBufferMsg(0x15), 60 | OledCrownMenuMsg(0x16), 61 | OledCrownMenuButtonMsg(0x17), 62 | 63 | /* 64 | * Status and control 65 | */ 66 | 67 | /* move the hands hours), mins and seconds */ 68 | AdvanceWatchHandsMsg(0x20), 69 | 70 | /* config and (dis)enable vibrate */ 71 | SetVibrateMode(0x23), 72 | 73 | /* Sets the RTC */ 74 | SetRealTimeClock(0x26), 75 | GetRealTimeClock(0x27), 76 | GetRealTimeClockResponse(0x28), 77 | 78 | /* osal nv */ 79 | NvalOperationMsg(0x30), 80 | NvalOperationResponseMsg(0x31), 81 | 82 | /* status of the current display operation */ 83 | StatusChangeEvent(0x33), 84 | 85 | ButtonEventMsg(0x34), 86 | 87 | GeneralPurposePhoneMsg(0x35), 88 | GeneralPurposeWatchMsg(0x36), 89 | /* 90 | * LCD display related commands 91 | */ 92 | WriteBuffer(0x40), 93 | ConfigureMode(0x41), 94 | ConfigureIdleBufferSize(0x42), 95 | UpdateDisplay(0x43), 96 | LoadTemplate(0x44), 97 | UpdateMyDisplaySram(0x45), 98 | EnableButtonMsg(0x46), 99 | DisableButtonMsg(0x47), 100 | ReadButtonConfigMsg(0x48), 101 | ReadButtonConfigResponse(0x49), 102 | UpdateMyDisplayLcd(0x4a), 103 | 104 | /* */ 105 | BatteryChargeControl(0x52), 106 | BatteryConfigMsg(0x53), 107 | LowBatteryWarningMsgHost(0x54), 108 | LowBatteryBtOffMsgHost(0x55), 109 | ReadBatteryVoltageMsg(0x56), 110 | ReadBatteryVoltageResponse(0x57), 111 | ReadLightSensorMsg(0x58), 112 | ReadLightSensorResponse(0x59), 113 | LowBatteryWarningMsg(0x5a), 114 | LowBatteryBtOffMsg(0x5b), 115 | 116 | /***************************************************************************** 117 | * 118 | * User Reserved 0x60-0x70-0x80-0x90 119 | * 120 | ****************************************************************************/ 121 | 122 | 123 | /***************************************************************************** 124 | * 125 | * Watch/Internal Use Only 126 | * 127 | ****************************************************************************/ 128 | IdleUpdate(0xa0), 129 | xxxInitialIdleUpdate(0xa1), 130 | WatchDrawnScreenTimeout(0xa2), 131 | ClearLcdSpecial(0xa3), 132 | WriteLcd(0xa4), 133 | ClearLcd(0xa5), 134 | ChangeModeMsg(0xa6), 135 | ModeTimeoutMsg(0xa7), 136 | WatchStatusMsg(0xa8), 137 | MenuModeMsg(0xa9), 138 | BarCode(0xaa), 139 | ListPairedDevicesMsg(0xab), 140 | ConnectionStateChangeMsg(0xac), 141 | ModifyTimeMsg(0xad), 142 | MenuButtonMsg(0xae), 143 | ToggleSecondsMsg(0xaf), 144 | SplashTimeoutMsg(0xb0), 145 | 146 | LedChange(0xc0), 147 | 148 | QueryMemoryMsg(0xd0), 149 | 150 | AccelerometerSteps(0xea), 151 | AccelerometerRawData(0xeb); 152 | public byte msg; 153 | static public final byte start = 0x01; 154 | //byte ID() 155 | //{ 156 | //return msg; 157 | //} 158 | Message(int msg) 159 | { 160 | this.msg = (byte)msg; 161 | } 162 | 163 | } ; -------------------------------------------------------------------------------- /src/org/metawatch/manager/Application.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Application.java * 27 | * Application * 28 | * Application watch mode * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import android.content.Context; 36 | import android.graphics.Bitmap; 37 | 38 | public class Application { 39 | 40 | public static void startAppMode() { 41 | MetaWatchService.WatchModes.APPLICATION = true; 42 | } 43 | 44 | public static void stopAppMode(Context context) { 45 | exitApp(context); 46 | } 47 | 48 | public static void updateAppMode(Context context) { 49 | MetaWatchService.WatchModes.APPLICATION = true; 50 | 51 | if (MetaWatchService.WatchModes.APPLICATION == true) { 52 | 53 | // enable app mode if there is no parent mode currently active 54 | if (MetaWatchService.watchState < MetaWatchService.WatchStates.APPLICATION) 55 | MetaWatchService.watchState = MetaWatchService.WatchStates.APPLICATION; 56 | 57 | if (MetaWatchService.watchState == MetaWatchService.WatchStates.APPLICATION) { 58 | //Bitmap bitmap = createLcdApp(context); 59 | Bitmap bitmap = Protocol.createTextBitmap(context, "Starting application mode ..."); 60 | Protocol.sendLcdBitmap(bitmap, MetaWatchService.WatchBuffers.APPLICATION); 61 | Protocol.updateDisplay(MetaWatchService.WatchBuffers.APPLICATION); 62 | } 63 | } 64 | } 65 | 66 | public static void updateAppMode(Context context, Bitmap bitmap) { 67 | MetaWatchService.WatchModes.APPLICATION = true; 68 | 69 | if (MetaWatchService.WatchModes.APPLICATION == true) { 70 | 71 | // enable app mode if there is no parent mode currently active 72 | if (MetaWatchService.watchState < MetaWatchService.WatchStates.APPLICATION) 73 | MetaWatchService.watchState = MetaWatchService.WatchStates.APPLICATION; 74 | 75 | if (MetaWatchService.watchState == MetaWatchService.WatchStates.APPLICATION) { 76 | Protocol.sendLcdBitmap(bitmap, MetaWatchService.WatchBuffers.APPLICATION); 77 | Protocol.updateDisplay(MetaWatchService.WatchBuffers.APPLICATION); 78 | } 79 | } 80 | } 81 | 82 | public static void updateAppMode(Context context, int[] array) { 83 | MetaWatchService.WatchModes.APPLICATION = true; 84 | 85 | if (MetaWatchService.WatchModes.APPLICATION == true) { 86 | 87 | // enable app mode if there is no parent mode currently active 88 | if (MetaWatchService.watchState < MetaWatchService.WatchStates.APPLICATION) 89 | MetaWatchService.watchState = MetaWatchService.WatchStates.APPLICATION; 90 | 91 | if (MetaWatchService.watchState == MetaWatchService.WatchStates.APPLICATION) { 92 | Protocol.sendLcdArray(array, MetaWatchService.WatchBuffers.APPLICATION); 93 | Protocol.updateDisplay(MetaWatchService.WatchBuffers.APPLICATION); 94 | } 95 | } 96 | } 97 | 98 | public static void updateAppMode(Context context, byte[] buffer) { 99 | MetaWatchService.WatchModes.APPLICATION = true; 100 | 101 | if (MetaWatchService.WatchModes.APPLICATION == true) { 102 | 103 | // enable app mode if there is no parent mode currently active 104 | if (MetaWatchService.watchState < MetaWatchService.WatchStates.APPLICATION) 105 | MetaWatchService.watchState = MetaWatchService.WatchStates.APPLICATION; 106 | 107 | if (MetaWatchService.watchState == MetaWatchService.WatchStates.APPLICATION) { 108 | Protocol.sendLcdBuffer(buffer, MetaWatchService.WatchBuffers.APPLICATION); 109 | Protocol.updateDisplay(MetaWatchService.WatchBuffers.APPLICATION); 110 | } 111 | } 112 | } 113 | 114 | 115 | 116 | public static void toApp() { 117 | MetaWatchService.watchState = MetaWatchService.WatchStates.APPLICATION; 118 | // update screen with cached buffer 119 | Protocol.updateDisplay(MetaWatchService.WatchBuffers.APPLICATION); 120 | } 121 | 122 | public static void exitApp(Context context) { 123 | MetaWatchService.WatchModes.APPLICATION = false; 124 | 125 | if (MetaWatchService.WatchModes.IDLE == true) { 126 | Idle.toIdle(context); 127 | } 128 | } 129 | 130 | 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/IntentReceiver.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * IntentReceiver.java * 27 | * IntentReceiver * 28 | * Notifications receiver * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import android.content.BroadcastReceiver; 36 | import android.content.Context; 37 | import android.content.Intent; 38 | import android.os.Bundle; 39 | import android.telephony.SmsMessage; 40 | import android.util.Log; 41 | 42 | public class IntentReceiver extends BroadcastReceiver { 43 | 44 | @Override 45 | public void onReceive(Context context, Intent intent) { 46 | 47 | String action = intent.getAction(); 48 | //Log.d(MetaWatch.TAG, action); 49 | 50 | /* 51 | Bundle b = intent.getExtras(); 52 | for (String key : b.keySet()) { 53 | Log.d(MetaWatch.TAG, "extra: " + key); 54 | } 55 | Log.d(MetaWatch.TAG, intent.getDataString()); 56 | */ 57 | 58 | if (action.equals("android.intent.action.PROVIDER_CHANGED")) { 59 | 60 | if (!MetaWatchService.Preferences.notifyGmail) 61 | return; 62 | 63 | if (!Utils.isGmailAccessSupported(context)) { 64 | String recipient = "You"; 65 | Bundle bundle = intent.getExtras(); 66 | 67 | if (bundle.containsKey("account")) 68 | recipient = bundle.getString("account"); 69 | Log.d(MetaWatch.TAG, "count for " + recipient + ": " + bundle.getInt("count")); 70 | int count = bundle.getInt("count"); 71 | Monitors.updateGmailUnreadCount(recipient, count); 72 | 73 | if (count > 0) 74 | NotificationBuilder.createGmailBlank(context, recipient); 75 | else 76 | Idle.updateLcdIdle(context); 77 | return; 78 | } 79 | } 80 | 81 | if (action.equals("android.provider.Telephony.SMS_RECEIVED")) { 82 | 83 | if (!MetaWatchService.Preferences.notifySMS) 84 | return; 85 | 86 | Bundle bundle = intent.getExtras(); 87 | if (bundle.containsKey("pdus")) { 88 | Object[] pdus = (Object[]) bundle.get("pdus"); 89 | SmsMessage[] smsMessage = new SmsMessage[pdus.length]; 90 | for (int i = 0; i < smsMessage.length; i++) { 91 | smsMessage[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); 92 | String number = smsMessage[i].getOriginatingAddress(); 93 | String body = smsMessage[i].getDisplayMessageBody(); 94 | 95 | NotificationBuilder.createSMS(context, number, body); 96 | } 97 | } 98 | return; 99 | } 100 | 101 | if (action.equals("com.fsck.k9.intent.action.EMAIL_RECEIVED")) { 102 | 103 | if (!MetaWatchService.Preferences.notifyK9) 104 | return; 105 | 106 | Bundle bundle = intent.getExtras(); 107 | String subject = bundle.getString("com.fsck.k9.intent.extra.SUBJECT"); 108 | String sender = bundle.getString("com.fsck.k9.intent.extra.FROM"); 109 | NotificationBuilder.createK9(context, sender, subject); 110 | return; 111 | } 112 | 113 | if (action.equals("com.android.alarmclock.ALARM_ALERT") || action.equals("com.htc.android.worldclock.ALARM_ALERT") || action.equals("com.android.deskclock.ALARM_ALERT") || action.equals("com.sonyericsson.alarm.ALARM_ALERT") ) { 114 | 115 | if (!MetaWatchService.Preferences.notifyAlarm) 116 | return; 117 | 118 | NotificationBuilder.createAlarm(context); 119 | return; 120 | } 121 | 122 | if (intent.getAction().equals("com.android.music.metachanged") || intent.getAction().equals("com.htc.music.metachanged")) 123 | //if (intent.getAction().equals("com.android.music.metachanged") || intent.getAction().equals("com.htc.music.metachanged") || intent.getAction().equals("com.android.music.playstatechanged") || intent.getAction().equals("com.htc.music.playstatechanged")) 124 | { 125 | if (!MetaWatchService.Preferences.notifyMusic) 126 | return; 127 | 128 | String artist = ""; 129 | String track = ""; 130 | 131 | if (intent.hasExtra("artist")) 132 | artist = intent.getStringExtra("artist"); 133 | if (intent.hasExtra("track")) 134 | track = intent.getStringExtra("track"); 135 | 136 | NotificationBuilder.createMusic(context, artist, track); 137 | return; 138 | } 139 | 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | 40 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 82 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 102 | 103 | 105 | 106 | 107 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/org/anddev/android/weatherforecast/weather/GoogleWeatherHandler.java: -------------------------------------------------------------------------------- 1 | package org.anddev.android.weatherforecast.weather; 2 | 3 | import org.xml.sax.Attributes; 4 | import org.xml.sax.SAXException; 5 | import org.xml.sax.helpers.DefaultHandler; 6 | 7 | /** 8 | * SAXHandler capable of extracting information out of the xml-data returned by 9 | * the Google Weather API. 10 | */ 11 | public class GoogleWeatherHandler extends DefaultHandler { 12 | 13 | // =========================================================== 14 | // Fields 15 | // =========================================================== 16 | 17 | @SuppressWarnings("unused") 18 | private String city = ""; 19 | 20 | private WeatherSet myWeatherSet = null; 21 | @SuppressWarnings("unused") 22 | private boolean in_forecast_information = false; 23 | private boolean in_current_conditions = false; 24 | private boolean in_forecast_conditions = false; 25 | 26 | private boolean usingSITemperature = false; // false means Fahrenheit 27 | 28 | // =========================================================== 29 | // Constructors 30 | // =========================================================== 31 | 32 | // =========================================================== 33 | // Getter & Setter 34 | // =========================================================== 35 | 36 | public WeatherSet getWeatherSet() { 37 | return this.myWeatherSet; 38 | } 39 | 40 | // =========================================================== 41 | // Methods 42 | // =========================================================== 43 | @Override 44 | public void startDocument() throws SAXException { 45 | this.myWeatherSet = new WeatherSet(); 46 | } 47 | 48 | @Override 49 | public void endDocument() throws SAXException { 50 | // Nothing 51 | } 52 | 53 | @Override 54 | public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 55 | // 'Outer' Tags 56 | if (localName.equals("forecast_information")) { 57 | this.in_forecast_information = true; 58 | } else if (localName.equals("current_conditions")) { 59 | this.myWeatherSet.setWeatherCurrentCondition(new WeatherCurrentCondition()); 60 | this.in_current_conditions = true; 61 | } else if (localName.equals("forecast_conditions")) { 62 | this.myWeatherSet.getWeatherForecastConditions().add(new WeatherForecastCondition()); 63 | this.in_forecast_conditions = true; 64 | } else { 65 | String dataAttribute = atts.getValue("data"); 66 | // 'Inner' Tags of "" 67 | if (localName.equals("city")) { 68 | this.city = dataAttribute; 69 | //Log.d("ow", "city detected"); 70 | } else if (localName.equals("postal_code")) { 71 | } else if (localName.equals("latitude_e6")) { 72 | /* One could use this to convert city-name to Lat/Long. */ 73 | } else if (localName.equals("longitude_e6")) { 74 | /* One could use this to convert city-name to Lat/Long. */ 75 | } else if (localName.equals("forecast_date")) { 76 | } else if (localName.equals("current_date_time")) { 77 | } else if (localName.equals("unit_system")) { 78 | if (dataAttribute.equals("SI")) 79 | this.usingSITemperature = true; 80 | } 81 | // SHARED(!) 'Inner' Tags within "" AND 82 | // "" 83 | else if (localName.equals("day_of_week")) { 84 | if (this.in_current_conditions) { 85 | this.myWeatherSet.getWeatherCurrentCondition().setDayofWeek(dataAttribute); 86 | } else if (this.in_forecast_conditions) { 87 | this.myWeatherSet.getLastWeatherForecastCondition().setDayofWeek(dataAttribute); 88 | } 89 | } else if (localName.equals("icon")) { 90 | if (this.in_current_conditions) { 91 | this.myWeatherSet.getWeatherCurrentCondition().setIconURL( 92 | dataAttribute); 93 | } else if (this.in_forecast_conditions) { 94 | this.myWeatherSet.getLastWeatherForecastCondition() 95 | .setIconURL(dataAttribute); 96 | } 97 | } else if (localName.equals("condition")) { 98 | if (this.in_current_conditions) { 99 | this.myWeatherSet.getWeatherCurrentCondition() 100 | .setCondition(dataAttribute); 101 | } else if (this.in_forecast_conditions) { 102 | this.myWeatherSet.getLastWeatherForecastCondition() 103 | .setCondition(dataAttribute); 104 | } 105 | } 106 | // 'Inner' Tags within "" 107 | else if (localName.equals("temp_f")) { 108 | this.myWeatherSet.getWeatherCurrentCondition() 109 | .setTempFahrenheit(Integer.parseInt(dataAttribute)); 110 | } else if (localName.equals("temp_c")) { 111 | this.myWeatherSet.getWeatherCurrentCondition().setTempCelcius( 112 | Integer.parseInt(dataAttribute)); 113 | } else if (localName.equals("humidity")) { 114 | this.myWeatherSet.getWeatherCurrentCondition().setHumidity( 115 | dataAttribute); 116 | } else if (localName.equals("wind_condition")) { 117 | this.myWeatherSet.getWeatherCurrentCondition() 118 | .setWindCondition(dataAttribute); 119 | } 120 | // 'Inner' Tags within "" 121 | else if (localName.equals("low")) { 122 | int temp = Integer.parseInt(dataAttribute); 123 | if (this.usingSITemperature) { 124 | this.myWeatherSet.getLastWeatherForecastCondition() 125 | .setTempMinCelsius(temp); 126 | } else { 127 | this.myWeatherSet.getLastWeatherForecastCondition() 128 | .setTempMinCelsius( 129 | WeatherUtils.fahrenheitToCelsius(temp)); 130 | } 131 | } else if (localName.equals("high")) { 132 | int temp = Integer.parseInt(dataAttribute); 133 | if (this.usingSITemperature) { 134 | this.myWeatherSet.getLastWeatherForecastCondition() 135 | .setTempMaxCelsius(temp); 136 | } else { 137 | this.myWeatherSet.getLastWeatherForecastCondition() 138 | .setTempMaxCelsius( 139 | WeatherUtils.fahrenheitToCelsius(temp)); 140 | } 141 | } 142 | } 143 | } 144 | 145 | @Override 146 | public void endElement(String namespaceURI, String localName, String qName) 147 | throws SAXException { 148 | if (localName.equals("forecast_information")) { 149 | this.in_forecast_information = false; 150 | } else if (localName.equals("current_conditions")) { 151 | this.in_current_conditions = false; 152 | } else if (localName.equals("forecast_conditions")) { 153 | this.in_forecast_conditions = false; 154 | } 155 | } 156 | 157 | @Override 158 | public void characters(char ch[], int start, int length) { 159 | /* 160 | * Would be called on the following structure: characters 161 | */ 162 | } 163 | } -------------------------------------------------------------------------------- /src/org/metawatch/manager/Test.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Test.java * 27 | * Test * 28 | * Activity for sending test commands * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import org.metawatch.manager.MetaWatchService.WatchType; 36 | import org.metawatch.manager.Notification.VibratePattern; 37 | 38 | import android.app.Activity; 39 | import android.content.Context; 40 | import android.os.Bundle; 41 | import android.view.Menu; 42 | import android.view.MenuInflater; 43 | import android.view.MenuItem; 44 | 45 | public class Test extends Activity { 46 | 47 | @Override 48 | protected void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setTitle(getString(R.string.app_name) + " - " + getString(R.string.activitiy_title_tests)); 51 | } 52 | 53 | @Override 54 | public boolean onCreateOptionsMenu(Menu menu) { 55 | MenuInflater inflater = getMenuInflater(); 56 | inflater.inflate(R.menu.test, menu); 57 | return true; 58 | } 59 | 60 | @Override 61 | public boolean onOptionsItemSelected(MenuItem item) { 62 | switch (item.getItemId()) { 63 | case R.id.notification: 64 | if (MetaWatchService.watchType == WatchType.DIGITAL) 65 | Notification.addTextNotification(this, "Notification", new VibratePattern(true, 500, 500, 3), Notification.notificationTimeout); 66 | else 67 | Notification.addOledNotification(this, Protocol.createOled2lines(this, "Display A, line 1", "Display A, line 2"), Protocol.createOled2lines(this, "Display B, line 1", "Display B, line 2"), null, 0, null); 68 | return true; 69 | case R.id.application_start: 70 | if (MetaWatchService.watchType == WatchType.DIGITAL) 71 | Application.startAppMode(); 72 | return true; 73 | case R.id.sms_start: 74 | startSmsTestLoop(this); 75 | return true; 76 | case R.id.sms_stop: 77 | stopSmsTestLoop(); 78 | return true; 79 | case R.id.application_update: 80 | if (MetaWatchService.watchType == WatchType.DIGITAL) 81 | Application.updateAppMode(this); 82 | return true; 83 | case R.id.application_stop: 84 | if (MetaWatchService.watchType == WatchType.DIGITAL) 85 | Application.stopAppMode(this); 86 | return true; 87 | case R.id.sms: 88 | NotificationBuilder.createSMS(this, "555-123-456", "Rights groups report systematic state violence is being unleashed on Bahrain's opposition movement."); 89 | //NotificationBuilder.createSMS(this, "123-456-789", "Test SMS #" + "x"); 90 | return true; 91 | case R.id.k9: 92 | NotificationBuilder.createK9(this, "e@mail.com", "Subject line"); 93 | return true; 94 | case R.id.alarm: 95 | NotificationBuilder.createAlarm(this); 96 | return true; 97 | case R.id.music: 98 | NotificationBuilder.createMusic(this, "Park", "Who is Aliandra"); 99 | return true; 100 | case R.id.call_start: 101 | Call.startCall(this, "555-123-4567"); 102 | return true; 103 | case R.id.call_stop: 104 | Call.endCall(this); 105 | return true; 106 | case R.id.vibrate: 107 | Protocol.vibrate(300, 500, 3); 108 | return true; 109 | case R.id.set_rtc: 110 | Protocol.sendRtcNow(this); 111 | return true; 112 | case R.id.load_template: 113 | if (MetaWatchService.watchType == WatchType.DIGITAL) 114 | Protocol.loadTemplate(0); 115 | return true; 116 | case R.id.activate_buffer: 117 | if (MetaWatchService.watchType == WatchType.DIGITAL) 118 | Protocol.activateBuffer(0); 119 | return true; 120 | case R.id.update_display: 121 | if (MetaWatchService.watchType == WatchType.DIGITAL) 122 | Protocol.updateDisplay(0); 123 | return true; 124 | case R.id.write_bufer: 125 | if (MetaWatchService.watchType == WatchType.DIGITAL) 126 | Protocol.writeBuffer(); 127 | return true; 128 | case R.id.test: { 129 | //Protocol.test(this); 130 | //NotificationBuilder.createSMS(this, "555-123-4567", "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20."); 131 | Protocol.setNvalTime(true); 132 | //Protocol.configureMode(); 133 | //Protocol.readButtonConfiguration(); 134 | //Protocol.enableMediaButtons(); 135 | //Protocol.queryNvalTime(); 136 | /* 137 | Log.d(MetaWatch.TAG, "sending notif test"); 138 | Protocol.loadTemplate(2); 139 | Protocol.sendLcdBitmap(Protocol.createTextBitmap(this, "abc"), true); 140 | Protocol.updateDisplay(2); 141 | */ 142 | } 143 | return true; 144 | default: 145 | return super.onOptionsItemSelected(item); 146 | } 147 | } 148 | 149 | void startSmsTestLoop(final Context context) { 150 | if (MetaWatchService.testSmsLoop != null) 151 | MetaWatchService.testSmsLoop.stop(); 152 | MetaWatchService.testSmsLoop = new TestSmsLoop(context); 153 | Thread thread = new Thread(MetaWatchService.testSmsLoop); 154 | thread.start(); 155 | } 156 | 157 | void stopSmsTestLoop() { 158 | MetaWatchService.testSmsLoop.stop(); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/Utils.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Utils.java * 27 | * Utils * 28 | * Different utils * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import java.io.IOException; 36 | import java.io.InputStream; 37 | 38 | import android.accounts.Account; 39 | import android.accounts.AccountManager; 40 | import android.content.Context; 41 | import android.content.pm.PackageInfo; 42 | import android.content.pm.PackageManager; 43 | import android.content.pm.PackageManager.NameNotFoundException; 44 | import android.database.Cursor; 45 | import android.graphics.Bitmap; 46 | import android.graphics.BitmapFactory; 47 | import android.net.Uri; 48 | import android.provider.CallLog; 49 | import android.provider.ContactsContract.PhoneLookup; 50 | import android.util.Log; 51 | 52 | public class Utils { 53 | 54 | public static String getContactNameFromNumber(Context context, String number) { 55 | 56 | if (number.equals("")) 57 | return "Private number"; 58 | 59 | String[] projection = new String[] { PhoneLookup.DISPLAY_NAME, PhoneLookup.NUMBER }; 60 | Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); 61 | Cursor c = context.getContentResolver().query(contactUri, projection, null, null, null); 62 | 63 | if (c.moveToFirst()) { 64 | String name = c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME)); 65 | 66 | if (name.length() > 0) 67 | return name; 68 | else 69 | return number; 70 | } 71 | 72 | return number; 73 | } 74 | 75 | public static int getUnreadSmsCount(Context context) { 76 | 77 | int count = 0; 78 | 79 | Cursor cursor = context.getContentResolver().query( 80 | Uri.withAppendedPath(Uri.parse("content://sms"), "inbox"), 81 | new String[] { "_id" }, 82 | "read=0", 83 | null, 84 | null 85 | ); 86 | 87 | if (cursor != null) { 88 | try { 89 | count = cursor.getCount(); 90 | } finally { 91 | cursor.close(); 92 | } 93 | } 94 | return count; 95 | } 96 | 97 | public static int getMissedCallsCount(Context context) { 98 | int missed = 0; 99 | try { 100 | Cursor cursor = context.getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, null, null, null, null); 101 | cursor.moveToFirst(); 102 | 103 | while (true) { 104 | if (cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)) == 3) 105 | missed += cursor.getInt(cursor.getColumnIndex(CallLog.Calls.NEW)); 106 | 107 | if (cursor.isLast()) 108 | break; 109 | 110 | cursor.moveToNext(); 111 | } 112 | 113 | } catch (Exception x) { 114 | } 115 | return missed; 116 | } 117 | 118 | public static int getUnreadGmailCount(Context context, String account, String label) { 119 | try { 120 | int nameColumn = 0; 121 | 122 | Cursor c = context.getContentResolver().query(Uri.parse("content://gmail-ls/labels/" + account), null, null, null, null); 123 | c.moveToFirst(); 124 | 125 | for (int i = 0; i < c.getColumnCount(); i++) 126 | if (c.getColumnName(i).equals("canonicalName")) { 127 | nameColumn = i; 128 | break; 129 | } 130 | 131 | while (true) { 132 | if (c.getString(nameColumn).equals(label)) 133 | for (int i = 0; i < c.getColumnCount(); i++) { 134 | if (c.getColumnName(i).equals("numUnreadConversations")) { 135 | return Integer.parseInt(c.getString(i)); 136 | } 137 | } 138 | 139 | c.moveToNext(); 140 | 141 | if (c.isLast()) { 142 | break; 143 | } 144 | } 145 | } catch (Exception x) { 146 | Log.d(MetaWatch.TAG, x.toString()); 147 | } 148 | 149 | return 0; 150 | } 151 | 152 | public static String getGoogleAccountName(Context context) { 153 | AccountManager accountManager = AccountManager.get(context); 154 | Account[] accounts = accountManager.getAccounts(); 155 | int count = accounts.length; 156 | Account account = null; 157 | 158 | for (int i = 0; i < count; i++) { 159 | account = accounts[i]; 160 | if (account.type.equals("com.google")) { 161 | return account.name; 162 | } 163 | } 164 | return ""; 165 | } 166 | 167 | public static Bitmap loadBitmapFromAssets(Context context, String path) { 168 | try { 169 | InputStream inputStream = context.getAssets().open(path); 170 | Bitmap bitmap = BitmapFactory.decodeStream(inputStream); 171 | inputStream.close(); 172 | //Log.d(MetaWatch.TAG, "ok"); 173 | return bitmap; 174 | } catch (IOException e) { 175 | //Log.d(MetaWatch.TAG, e.toString()); 176 | return null; 177 | } 178 | } 179 | /* 180 | public static Bitmap loadBitmapFromPath(Context context, String path) { 181 | return BitmapFactory.decodeFile(path); 182 | } 183 | */ 184 | 185 | public static String getVersion(Context context) { 186 | try { 187 | PackageManager packageManager = context.getPackageManager(); 188 | PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); 189 | return packageInfo.versionName; 190 | } catch (NameNotFoundException e) { 191 | } 192 | return "unknown"; 193 | } 194 | 195 | public static boolean isGmailAccessSupported(Context context) { 196 | 197 | 198 | try { 199 | PackageManager packageManager = context.getPackageManager(); 200 | PackageInfo packageInfo = packageManager.getPackageInfo("com.google.android.gm", 0); 201 | // check for Gmail version earlier than v2.3.5 (169) 202 | if (packageInfo.versionCode < 169) 203 | return true; 204 | 205 | } catch (NameNotFoundException e) { 206 | } 207 | 208 | 209 | return false; 210 | } 211 | 212 | 213 | } 214 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/Idle.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Idle.java * 27 | * Idle * 28 | * Idle watch mode * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import org.metawatch.manager.Monitors.WeatherData; 36 | 37 | import android.content.Context; 38 | import android.graphics.Bitmap; 39 | import android.graphics.Canvas; 40 | import android.graphics.Color; 41 | import android.graphics.Paint; 42 | import android.graphics.Typeface; 43 | import android.text.StaticLayout; 44 | import android.text.TextPaint; 45 | 46 | public class Idle { 47 | 48 | public static byte[] overridenButtons = null; 49 | 50 | static Bitmap createLcdIdle(Context context) { 51 | Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565); 52 | Canvas canvas = new Canvas(bitmap); 53 | 54 | Paint paintSmall = new Paint(); 55 | paintSmall.setColor(Color.BLACK); 56 | paintSmall.setTextSize(8); 57 | Typeface typefaceSmall = Typeface.createFromAsset(context.getAssets(), "metawatch_8pt_5pxl_CAPS.ttf"); 58 | paintSmall.setTypeface(typefaceSmall); 59 | 60 | Paint paintLarge = new Paint(); 61 | paintLarge.setColor(Color.BLACK); 62 | paintLarge.setTextSize(16); 63 | Typeface typefaceLarge = Typeface.createFromAsset(context.getAssets(), "metawatch_16pt_11pxl.ttf"); 64 | paintLarge.setTypeface(typefaceLarge); 65 | 66 | canvas.drawColor(Color.WHITE); 67 | 68 | canvas = drawLine(canvas, 32); 69 | 70 | if (WeatherData.received) { 71 | // condition 72 | canvas.save(); 73 | TextPaint paint = new TextPaint(paintSmall); 74 | StaticLayout layout = new StaticLayout(WeatherData.condition, paint, 36, android.text.Layout.Alignment.ALIGN_NORMAL, 1.3f, 0, false); 75 | canvas.translate(3, 40); //position the text 76 | layout.draw(canvas); 77 | 78 | canvas.restore(); 79 | 80 | // icon 81 | Bitmap image = Utils.loadBitmapFromAssets(context, WeatherData.icon); 82 | canvas.drawBitmap(image, 37, 35, null); 83 | 84 | // temperatures 85 | canvas.drawText(WeatherData.temp, 64, 46, paintLarge); 86 | canvas.drawText(WeatherData.tempHigh, 64, 54, paintSmall); 87 | canvas.drawText(WeatherData.tempLow, 64, 62, paintSmall); 88 | canvas.drawText(WeatherData.city, 3, 62, paintSmall); 89 | 90 | } else { 91 | canvas.drawText("no data", 34, 50, paintSmall); 92 | } 93 | 94 | canvas = drawLine(canvas, 64); 95 | 96 | // icons row 97 | //Bitmap imageI = Utils.loadBitmapFromAssets(context, "idle_icons_row.bmp"); 98 | //canvas.drawBitmap(imageI, 0, 66, null); 99 | 100 | int rows = 3; 101 | /* 102 | if (Utils.isGmailAccessSupported(context)) 103 | rows = 3; 104 | else 105 | rows = 2; 106 | */ 107 | 108 | // icons 109 | for (int i = 0; i < rows; i++) { 110 | int slotSpace = 96/rows; 111 | int slotX = slotSpace/2-12; 112 | int iconX = slotSpace*i + slotX; 113 | switch (i) { 114 | case 0: 115 | canvas.drawBitmap(Utils.loadBitmapFromAssets(context, "idle_call.bmp"), iconX, 67, null); 116 | break; 117 | case 1: 118 | canvas.drawBitmap(Utils.loadBitmapFromAssets(context, "idle_sms.bmp"), iconX, 67, null); 119 | break; 120 | case 2: 121 | canvas.drawBitmap(Utils.loadBitmapFromAssets(context, "idle_gmail.bmp"), iconX, 67, null); 122 | break; 123 | } 124 | } 125 | 126 | // unread counters 127 | for (int i = 0; i < rows; i++) { 128 | String count = ""; 129 | switch (i) { 130 | case 0: 131 | count = Integer.toString(Utils.getMissedCallsCount(context)); 132 | break; 133 | case 1: 134 | count = Integer.toString(Utils.getUnreadSmsCount(context)); 135 | break; 136 | case 2: 137 | if (Utils.isGmailAccessSupported(context)) 138 | count = Integer.toString(Utils.getUnreadGmailCount(context, Utils.getGoogleAccountName(context), "^i")); 139 | else 140 | count = Integer.toString(Monitors.getGmailUnreadCount()); 141 | break; 142 | } 143 | 144 | int slotSpace = 96/rows; 145 | int slotX = (int) (slotSpace/2-paintSmall.measureText(count)/2); 146 | int countX = slotSpace*i + slotX; 147 | 148 | canvas.drawText(count, countX, 92, paintSmall); 149 | } 150 | 151 | /* 152 | FileOutputStream fos = new FileOutputStream("/sdcard/test.png"); 153 | image.compress(Bitmap.CompressFormat.PNG, 100, fos); 154 | fos.close(); 155 | Log.d("ow", "bmp ok"); 156 | */ 157 | return bitmap; 158 | } 159 | 160 | public static Canvas drawLine(Canvas canvas, int y) { 161 | Paint paint = new Paint(); 162 | paint.setColor(Color.BLACK); 163 | 164 | int left = 3; 165 | 166 | for (int i = 0+left; i < 96-left; i += 3) 167 | canvas.drawLine(i, y, i+2, y, paint); 168 | 169 | return canvas; 170 | } 171 | 172 | public static void sendLcdIdle(Context context) { 173 | Bitmap bitmap = createLcdIdle(context); 174 | //Protocol.loadTemplate(0); 175 | Protocol.sendLcdBitmap(bitmap, MetaWatchService.WatchBuffers.IDLE); 176 | //Protocol.activateBuffer(); 177 | Protocol.updateDisplay(0); 178 | } 179 | 180 | public static boolean toIdle(Context context) { 181 | // check for parent modes 182 | 183 | MetaWatchService.WatchModes.IDLE = true; 184 | MetaWatchService.watchState = MetaWatchService.WatchStates.IDLE; 185 | 186 | sendLcdIdle(context); 187 | //Protocol.updateDisplay(0); 188 | 189 | return true; 190 | } 191 | 192 | public static void updateLcdIdle(Context context) { 193 | if (MetaWatchService.watchState == MetaWatchService.WatchStates.IDLE) 194 | sendLcdIdle(context); 195 | } 196 | 197 | public static boolean isIdleButtonOverriden(byte button) { 198 | if (overridenButtons != null) 199 | for (int i = 0; i < overridenButtons.length; i++) 200 | if (overridenButtons[i] == button) 201 | return true; 202 | return false; 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/DeviceSelection.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * DeviceSelection.java * 27 | * DeviceSelection * 28 | * Bluetooth device picker activity * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import java.util.ArrayList; 36 | import java.util.HashMap; 37 | import java.util.List; 38 | import java.util.Map; 39 | import java.util.Set; 40 | 41 | import android.app.Activity; 42 | import android.app.ProgressDialog; 43 | import android.bluetooth.BluetoothAdapter; 44 | import android.bluetooth.BluetoothDevice; 45 | import android.content.BroadcastReceiver; 46 | import android.content.Context; 47 | import android.content.DialogInterface; 48 | import android.content.DialogInterface.OnCancelListener; 49 | import android.content.Intent; 50 | import android.content.IntentFilter; 51 | import android.os.Bundle; 52 | import android.os.Handler; 53 | import android.os.Message; 54 | import android.util.Log; 55 | import android.view.View; 56 | import android.widget.AdapterView; 57 | import android.widget.AdapterView.OnItemClickListener; 58 | import android.widget.ListView; 59 | import android.widget.SimpleAdapter; 60 | import android.widget.Toast; 61 | 62 | public class DeviceSelection extends Activity { 63 | 64 | class Receiver extends BroadcastReceiver { 65 | @Override 66 | public void onReceive(Context context, Intent intent) { 67 | 68 | if (intent.getAction().equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { 69 | Log.d(MetaWatch.TAG, "discovery finished"); 70 | 71 | pdWait.dismiss(); 72 | 73 | if (list.size() == 0) { 74 | sendToast("No watch found"); 75 | finish(); 76 | } 77 | } 78 | 79 | if (intent.getAction().equals(BluetoothDevice.ACTION_FOUND)) { 80 | Log.d(MetaWatch.TAG, "device found"); 81 | 82 | BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 83 | 84 | if (device.getBondState() == BluetoothDevice.BOND_BONDED) 85 | return; 86 | 87 | String deviceName = device.getName(); 88 | String deviceMac = device.getAddress(); 89 | 90 | //int cl = device.getBluetoothClass().getMajorDeviceClass(); 91 | //Log.d(MetaWatch.TAG, "device class: " + cl); 92 | 93 | addToList(deviceMac, deviceName); 94 | } 95 | } 96 | } 97 | 98 | ProgressDialog pdWait = null; 99 | 100 | Context context; 101 | ListView listView; 102 | //static ArrayList menuList = new ArrayList(); 103 | List> list = new ArrayList>(); 104 | 105 | @Override 106 | protected void onCreate(Bundle savedInstanceState) { 107 | super.onCreate(savedInstanceState); 108 | context = this; 109 | 110 | pdWait = ProgressDialog.show(this, "Please wait", "Searching Bluetooth devices..."); 111 | pdWait.setCancelable(true); 112 | pdWait.setOnCancelListener(new OnCancelListener() { 113 | public void onCancel(DialogInterface dialog) { 114 | Log.d(MetaWatch.TAG, "canceled"); 115 | if (MetaWatchService.bluetoothAdapter.isDiscovering()) 116 | MetaWatchService.bluetoothAdapter.cancelDiscovery(); 117 | finish(); 118 | } 119 | }); 120 | pdWait.show(); 121 | 122 | setContentView(R.layout.device_selection); 123 | //constructMenuList(); 124 | listView = (ListView) findViewById(android.R.id.list); 125 | //listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, menuList)); 126 | 127 | listView.setOnItemClickListener(new OnItemClickListener() { 128 | 129 | public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { 130 | Log.d(MetaWatch.TAG, "device selected: " + arg2); 131 | 132 | Map map = list.get(arg2); 133 | String mac = map.get("mac"); 134 | 135 | Log.d(MetaWatch.TAG, "mac selected: " + mac); 136 | 137 | MetaWatchService.Preferences.watchMacAddress = mac; 138 | MetaWatchService.saveMac(context, mac); 139 | 140 | sendToast("Selected watch set"); 141 | finish(); 142 | } 143 | 144 | }); 145 | 146 | if (MetaWatchService.bluetoothAdapter == null) 147 | MetaWatchService.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 148 | 149 | Set pairedDevices = MetaWatchService.bluetoothAdapter.getBondedDevices(); 150 | if (pairedDevices.size() > 0) { 151 | for (BluetoothDevice device : pairedDevices) { 152 | addToList(device.getAddress(), device.getName()); 153 | } 154 | } 155 | 156 | Receiver receiver = new Receiver(); 157 | IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); 158 | intentFilter.addAction(BluetoothDevice.ACTION_FOUND); 159 | 160 | registerReceiver(receiver, intentFilter); 161 | 162 | MetaWatchService.bluetoothAdapter.startDiscovery(); 163 | 164 | } 165 | 166 | void addToList(String mac, String name) { 167 | Map map = new HashMap(); 168 | map.put("mac", mac); 169 | map.put("name", name); 170 | list.add(map); 171 | //menuList.add(mac); 172 | displayList(); 173 | } 174 | 175 | void displayList() { 176 | 177 | //listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, menuList)); 178 | listView.setAdapter(new SimpleAdapter(this, list, R.layout.list_item, new String[] { "name", "mac"}, new int[] { R.id.text1, R.id.text2} )); 179 | } 180 | 181 | public void sendToast(String text) { 182 | Message m = new Message(); 183 | m.what = 1; 184 | m.obj = text; 185 | messageHandler.sendMessage(m); 186 | } 187 | 188 | private Handler messageHandler = new Handler() { 189 | 190 | @Override 191 | public void handleMessage(Message msg) { 192 | switch (msg.what) { 193 | case 1: 194 | Toast.makeText(context, (CharSequence) msg.obj, Toast.LENGTH_SHORT).show(); 195 | break; 196 | } 197 | } 198 | 199 | }; 200 | 201 | 202 | @Override 203 | protected void onDestroy() { 204 | 205 | super.onDestroy(); 206 | } 207 | 208 | 209 | 210 | 211 | 212 | 213 | } 214 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/NotificationBuilder.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * NotificationBuilder.java * 27 | * NotificationBuilder * 28 | * Templates for different kinds of notification screens * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import org.metawatch.manager.MetaWatchService.Preferences; 36 | import org.metawatch.manager.MetaWatchService.WatchType; 37 | import org.metawatch.manager.Notification.VibratePattern; 38 | 39 | import android.content.Context; 40 | import android.graphics.Bitmap; 41 | import android.graphics.Canvas; 42 | import android.graphics.Color; 43 | import android.graphics.Paint; 44 | import android.graphics.Typeface; 45 | 46 | public class NotificationBuilder { 47 | 48 | public static final class FontSize { 49 | public static final int SMALL = 1; 50 | public static final int MEDIUM = 2; 51 | public static final int LARGE = 3; 52 | } 53 | 54 | public static void createSMS(Context context, String number, String text) { 55 | String name = Utils.getContactNameFromNumber(context, number); 56 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 57 | Bitmap bitmap = smartLines(context, "message.bmp", new String[] {"SMS from", name}); 58 | Notification.addBitmapNotification(context, bitmap, new VibratePattern(true, 500, 500, 3), 4000); 59 | Notification.addTextNotification(context, text, new VibratePattern(false, 0, 0, 0), Notification.notificationTimeout); 60 | } else { 61 | byte[] scroll = new byte[800]; 62 | int len = Protocol.createOled2linesLong(context, text, scroll); 63 | Notification.addOledNotification(context, Protocol.createOled1line(context, "message.bmp", "SMS from"), Protocol.createOled2lines(context, name, text), scroll, len, new VibratePattern(true, 500, 500, 3)); 64 | } 65 | } 66 | 67 | public static void createK9(Context context, String sender, String subject) { 68 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 69 | Bitmap bitmap = smartLines(context, "email.bmp", new String[] {"K9 mail from", sender, subject}); 70 | Notification.addBitmapNotification(context, bitmap, new VibratePattern(true, 500, 500, 3), Notification.notificationTimeout); 71 | } else { 72 | Notification.addOledNotification(context, Protocol.createOled1line(context, "email.bmp", "K9 mail from"), Protocol.createOled2lines(context, sender, subject), null, 0, new VibratePattern(true, 500, 500, 3)); 73 | } 74 | } 75 | 76 | public static void createGmail(Context context, String sender, String email, String subject, String snippet) { 77 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 78 | Bitmap bitmap = smartLines(context, "email.bmp", new String[] {"Gmail from", sender, email, subject}); 79 | Notification.addBitmapNotification(context, bitmap, new VibratePattern(true, 500, 500, 3), Notification.notificationTimeout); 80 | Notification.addTextNotification(context, snippet, new VibratePattern(false, 0, 0, 0), Notification.notificationTimeout); 81 | } else { 82 | Notification.addOledNotification(context, Protocol.createOled2lines(context, "Gmail from " + sender, email), Protocol.createOled2lines(context, subject, snippet), null, 0, new VibratePattern(true, 500, 500, 3)); 83 | } 84 | } 85 | 86 | public static void createGmailBlank(Context context, String recipient) { 87 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 88 | Bitmap bitmap = smartLines(context, "email.bmp", new String[] {"Gmail for", recipient}); 89 | Notification.addBitmapNotification(context, bitmap, new VibratePattern(true, 500, 500, 3), Notification.notificationTimeout); 90 | } else { 91 | Notification.addOledNotification(context, Protocol.createOled1line(context, "email.bmp", "SMS for"), Protocol.createOled1line(context, null, recipient), null, 0, new VibratePattern(true, 500, 500, 3)); 92 | } 93 | } 94 | 95 | public static void createAlarm(Context context) { 96 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 97 | Bitmap bitmap = smartLines(context, "timer.bmp", new String[] {"Alarm Clock"}); 98 | Notification.addBitmapNotification(context, bitmap, new VibratePattern(true, 500, 500, 3), Notification.notificationTimeout); 99 | } else { 100 | Notification.addOledNotification(context, Protocol.createOled1line(context, "timer.bmp", "Alarm clock"), Protocol.createOled1line(context, null, "Alarm"), null, 0, new VibratePattern(true, 500, 500, 3)); 101 | } 102 | } 103 | 104 | public static void createMusic(Context context, String artist, String track) { 105 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 106 | Bitmap bitmap = smartLines(context, "play.bmp", new String[] { track, artist}); 107 | Notification.addBitmapNotification(context, bitmap, new VibratePattern(true, 150, 0, 1), Notification.notificationTimeout); 108 | } else { 109 | Notification.addOledNotification(context, Protocol.createOled1line(context, "play.bmp", artist), Protocol.createOled1line(context, null, track), null, 0, new VibratePattern(true, 500, 500, 3)); 110 | } 111 | } 112 | 113 | 114 | static Bitmap smartLines(Context context, String iconPath, String[] lines) { 115 | 116 | String font = null; 117 | int size = 8; 118 | int realSize = 7; 119 | 120 | switch (Preferences.fontSize) { 121 | case FontSize.SMALL: 122 | font = "metawatch_8pt_5pxl_CAPS.ttf"; 123 | realSize = 5; 124 | break; 125 | case FontSize.MEDIUM: 126 | font = "metawatch_8pt_7pxl_CAPS.ttf"; 127 | realSize = 7; 128 | break; 129 | case FontSize.LARGE: 130 | font = "metawatch_16pt_11pxl.ttf"; 131 | realSize = 11; 132 | size = 16; 133 | break; 134 | } 135 | 136 | Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565); 137 | Canvas canvas = new Canvas(bitmap); 138 | Paint paint = new Paint(); 139 | paint.setColor(Color.BLACK); 140 | paint.setTextSize(size); 141 | Typeface typeface = Typeface.createFromAsset(context.getAssets(), font); 142 | paint.setTypeface(typeface); 143 | canvas.drawColor(Color.WHITE); 144 | 145 | Bitmap icon = Utils.loadBitmapFromAssets(context, iconPath); 146 | 147 | int spaceForItem = 96 / (1 + lines.length); 148 | 149 | canvas.drawBitmap(icon, 96/2-icon.getWidth()/2, spaceForItem/2-icon.getHeight()/2, paint); 150 | 151 | for (int i = 0; i < lines.length; i++) { 152 | int x = (int)(96/2-paint.measureText(lines[i])/2); 153 | if (x < 0) 154 | x = 0; 155 | int y = spaceForItem * (i + 1) + spaceForItem/2 + realSize/2 ; 156 | canvas.drawText(lines[i], x, y, paint); 157 | } 158 | 159 | return bitmap; 160 | } 161 | 162 | 163 | 164 | 165 | } 166 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/GmailMonitor.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * GmailMonitor.java * 27 | * GmailMonitor * 28 | * Watching for latest Gmail e-mails, working with Gmail version older than * 29 | * version 2.3.5 (excluded) * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import java.util.regex.Matcher; 36 | import java.util.regex.Pattern; 37 | 38 | import org.metawatch.manager.MetaWatchService.Preferences; 39 | 40 | 41 | import android.accounts.Account; 42 | import android.accounts.AccountManager; 43 | import android.content.ContentResolver; 44 | import android.content.Context; 45 | import android.database.ContentObserver; 46 | import android.database.Cursor; 47 | import android.net.Uri; 48 | import android.util.Log; 49 | 50 | public class GmailMonitor { 51 | 52 | Context context; 53 | 54 | MyContentObserver contentObserver = new MyContentObserver(); 55 | ContentResolver contentResolver; 56 | 57 | public static String account = ""; 58 | public static int lastUnreadGmailCount = 0; 59 | 60 | public GmailMonitor(Context ctx) { 61 | super(); 62 | context = ctx; 63 | } 64 | 65 | public void startMonitor() { 66 | try { 67 | AccountManager mgr = AccountManager.get(context); 68 | Account[] accts = mgr.getAccounts(); 69 | final int count = accts.length; 70 | Account acct = null; 71 | 72 | for (int i = 0; i < count; i++) { 73 | acct = accts[i]; 74 | if (acct.type.equals("com.google")) { 75 | account = acct.name; 76 | break; 77 | } 78 | // Log.d("ow", 79 | // "eclair account - name="+acct.name+", type="+acct.type); 80 | } 81 | 82 | Uri uri = Uri.parse("content://gmail-ls/conversations/" + account); 83 | contentResolver = context.getContentResolver(); 84 | contentResolver.registerContentObserver(uri, true, contentObserver); 85 | } catch (Exception x) { 86 | Log.d(MetaWatch.TAG, x.toString()); 87 | } 88 | } 89 | 90 | 91 | private class MyContentObserver extends ContentObserver { 92 | 93 | public MyContentObserver() { 94 | super(null); 95 | } 96 | 97 | @Override 98 | public void onChange(boolean selfChange) { 99 | super.onChange(selfChange); 100 | 101 | Log.d("ow", "onChange observer - unread"); 102 | 103 | if (Preferences.notifyGmail) 104 | { 105 | int currentGmailUnreadCount = getUnreadGmailCount(account, "^u"); 106 | 107 | //Log.d("ow", "current gmail unread count: " + Integer.toString(currentGmailUnreadCount)); 108 | 109 | if (currentGmailUnreadCount > lastUnreadGmailCount) 110 | { 111 | Log.d("ow", Integer.toString(currentGmailUnreadCount) + " > " + Integer.toString(lastUnreadGmailCount)); 112 | sendUnreadGmail(account); 113 | } 114 | 115 | lastUnreadGmailCount = currentGmailUnreadCount; 116 | } 117 | } 118 | } 119 | 120 | public int getUnreadGmailCount(String account, String label) { 121 | // label = "^u"; 122 | 123 | try { 124 | int nameColumn = 0; 125 | 126 | Cursor c = context.getContentResolver().query(Uri.parse("content://gmail-ls/labels/" + account), null, null, null, null); 127 | 128 | c.moveToFirst(); 129 | 130 | for (int i = 0; i < c.getColumnCount(); i++) 131 | if (c.getColumnName(i).equals("canonicalName")) { 132 | nameColumn = i; 133 | break; 134 | } 135 | 136 | while (true) { 137 | if (c.getString(nameColumn).equals(label)) 138 | // if (c.getString(nameColumn).equals("^i")) 139 | for (int i = 0; i < c.getColumnCount(); i++) { 140 | if (c.getColumnName(i).equals("numUnreadConversations")) { 141 | return Integer.parseInt(c.getString(i)); 142 | } 143 | } 144 | 145 | c.moveToNext(); 146 | 147 | if (c.isLast()) { 148 | break; 149 | } 150 | } 151 | } catch (Exception x) { 152 | } 153 | 154 | return 0; 155 | } 156 | 157 | 158 | void sendUnreadGmail(String account) { 159 | try { 160 | 161 | int nameColumn = 0; 162 | String id = ""; 163 | String convId = ""; 164 | 165 | double maxDate = 0; 166 | 167 | Cursor c = context.getContentResolver().query(Uri.parse("content://gmail-ls/labels/" + account), null, null, null, null); 168 | c.moveToFirst(); 169 | 170 | for (int i = 0; i < c.getColumnCount(); i++) 171 | if (c.getColumnName(i).equals("canonicalName")) 172 | nameColumn = i; 173 | 174 | while (true) { 175 | if (c.getString(nameColumn).equals("^u")) 176 | for (int i = 0; i < c.getColumnCount(); i++) { 177 | if (c.getColumnName(i).equals("_id")) { 178 | id = c.getString(i); 179 | } 180 | } 181 | 182 | if (c.isLast()) 183 | break; 184 | 185 | c.moveToNext(); 186 | } 187 | 188 | Cursor c2 = context.getContentResolver().query(Uri.parse("content://gmail-ls/conversations/" + account), null, null, null, null); 189 | c2.moveToLast(); 190 | 191 | for (int i = 0; i < c2.getColumnCount(); i++) 192 | if (c2.getColumnName(i).equals("labelIds")) 193 | nameColumn = i; 194 | 195 | while (true) { 196 | if (c2.getString(nameColumn).indexOf(id) >= 0) 197 | for (int i = 0; i < c2.getColumnCount(); i++) { 198 | if (c2.getColumnName(i).equals("conversation_id")) 199 | convId = c2.getString(i); 200 | } 201 | 202 | if (c2.isFirst()) 203 | break; 204 | 205 | c2.moveToPrevious(); 206 | } 207 | // /////////////// 208 | 209 | maxDate = 0; 210 | 211 | int colConvId = 0; 212 | int colSub = 0; 213 | int colFrom = 0; 214 | int colRcv = 0; 215 | 216 | String subject = ""; 217 | String sender = ""; 218 | String snippet = ""; 219 | 220 | Cursor c3 = context.getContentResolver().query(Uri.parse("content://gmail-ls/conversations/" + account + "/" + convId + "/messages"), null, null, null, null); 221 | // startManagingCursor(c3); 222 | c3.moveToFirst(); 223 | 224 | for (int i = 0; i < c3.getColumnCount(); i++) { 225 | if (c3.getColumnName(i).equals("conversation")) 226 | colConvId = i; 227 | if (c3.getColumnName(i).equals("subject")) 228 | colSub = i; 229 | if (c3.getColumnName(i).equals("fromAddress")) 230 | colFrom = i; 231 | if (c3.getColumnName(i).equals("dateReceivedMs")) 232 | colRcv = i; 233 | } 234 | 235 | while (true) { 236 | if (c3.getString(colConvId).indexOf(convId) >= 0) { 237 | double thisDate = Double.parseDouble(c3.getString(colRcv)); 238 | 239 | if (thisDate > maxDate) { 240 | subject = c3.getString(colSub); 241 | sender = c3.getString(colFrom); 242 | snippet = c3.getString(c3.getColumnIndex("snippet")); 243 | maxDate = thisDate; 244 | } 245 | } 246 | 247 | if (c3.isLast()) 248 | break; 249 | 250 | c3.moveToNext(); 251 | } 252 | 253 | Pattern pattern = Pattern.compile("(\"[^\"]*\") (<.*>)"); 254 | Matcher matcher = pattern.matcher(sender); 255 | matcher.find(); 256 | 257 | String senderName = matcher.group(1).replace("\"", ""); 258 | String senderMail = matcher.group(2).replace("<", "").replace(">", ""); 259 | 260 | NotificationBuilder.createGmail(context, senderName, senderMail, subject, snippet); 261 | 262 | } catch (Exception x) { 263 | } 264 | } 265 | 266 | } 267 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/Monitors.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Monitors.java * 27 | * Monitors * 28 | * Starting notifications and updates * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import java.net.URL; 36 | import java.util.Hashtable; 37 | 38 | import javax.xml.parsers.SAXParser; 39 | import javax.xml.parsers.SAXParserFactory; 40 | 41 | import org.anddev.android.weatherforecast.weather.GoogleWeatherHandler; 42 | import org.anddev.android.weatherforecast.weather.WeatherCurrentCondition; 43 | import org.anddev.android.weatherforecast.weather.WeatherForecastCondition; 44 | import org.anddev.android.weatherforecast.weather.WeatherSet; 45 | import org.anddev.android.weatherforecast.weather.WeatherUtils; 46 | import org.metawatch.manager.MetaWatchService.Preferences; 47 | import org.xml.sax.InputSource; 48 | import org.xml.sax.XMLReader; 49 | 50 | 51 | import android.app.AlarmManager; 52 | import android.app.PendingIntent; 53 | import android.content.ContentResolver; 54 | import android.content.Context; 55 | import android.content.Intent; 56 | import android.database.ContentObserver; 57 | import android.net.Uri; 58 | import android.telephony.PhoneStateListener; 59 | import android.telephony.TelephonyManager; 60 | import android.util.Log; 61 | 62 | 63 | public class Monitors { 64 | 65 | public static AlarmManager alarmManager; 66 | public static Intent intent; 67 | public static PendingIntent sender; 68 | 69 | static GmailMonitor gmailMonitor; 70 | 71 | private static ContentObserverMessages contentObserverMessages; 72 | static ContentResolver contentResolverMessages; 73 | 74 | private static ContentObserverCalls contentObserverCalls; 75 | static ContentResolver contentResolverCalls; 76 | 77 | //public static int gmailCount = 0; 78 | static Hashtable gmailUnreadCounts = new Hashtable(); 79 | 80 | 81 | public static class WeatherData { 82 | public static boolean received = false; 83 | public static String icon; 84 | public static String tempHigh; 85 | public static String tempLow; 86 | public static String temp; 87 | public static String condition; 88 | public static String city; 89 | } 90 | 91 | public static void updateGmailUnreadCount(String account, int count) { 92 | gmailUnreadCounts.put(account, count); 93 | } 94 | 95 | public static int getGmailUnreadCount() { 96 | int count = 0; 97 | for (int i : gmailUnreadCounts.values()) 98 | count += i; 99 | return count; 100 | } 101 | 102 | public static void start(Context context, TelephonyManager telephonyManager) { 103 | // start weather updater 104 | 105 | // temporary one time update 106 | updateWeatherData(context); 107 | 108 | CallStateListener phoneListener = new CallStateListener(context); 109 | 110 | telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 111 | int phoneEvents = PhoneStateListener.LISTEN_CALL_STATE; 112 | telephonyManager.listen(phoneListener, phoneEvents); 113 | 114 | if (Utils.isGmailAccessSupported(context)) { 115 | gmailMonitor = new GmailMonitor(context); 116 | gmailMonitor.startMonitor(); 117 | } 118 | 119 | try { 120 | contentObserverMessages = new ContentObserverMessages(context); 121 | Uri uri = Uri.parse("content://mms-sms/conversations/"); 122 | contentResolverMessages = context.getContentResolver(); 123 | contentResolverMessages.registerContentObserver(uri, true, contentObserverMessages); 124 | } catch (Exception x) { 125 | } 126 | 127 | try { 128 | contentObserverCalls = new ContentObserverCalls(context); 129 | //Uri uri = Uri.parse("content://mms-sms/conversations/"); 130 | contentResolverCalls = context.getContentResolver(); 131 | contentResolverCalls.registerContentObserver(android.provider.CallLog.Calls.CONTENT_URI, true, contentObserverCalls); 132 | } catch (Exception x) { 133 | } 134 | 135 | startAlarmTicker(context); 136 | } 137 | 138 | public static void stop() { 139 | contentResolverMessages.unregisterContentObserver(contentObserverMessages); 140 | stopAlarmTicker(); 141 | } 142 | 143 | public static void updateWeatherData(Context context) { 144 | try { 145 | 146 | URL url; 147 | String queryString = "http://www.google.com/ig/api?weather=" + Preferences.weatherCity; 148 | url = new URL(queryString.replace(" ", "%20")); 149 | 150 | SAXParserFactory spf = SAXParserFactory.newInstance(); 151 | SAXParser sp = spf.newSAXParser(); 152 | XMLReader xr = sp.getXMLReader(); 153 | 154 | GoogleWeatherHandler gwh = new GoogleWeatherHandler(); 155 | xr.setContentHandler(gwh); 156 | 157 | InputSource src = new InputSource(url.openStream()); 158 | src.setEncoding("ISO-8859-1"); 159 | xr.parse(src); 160 | 161 | WeatherSet ws = gwh.getWeatherSet(); 162 | WeatherCurrentCondition wcc = ws.getWeatherCurrentCondition(); 163 | 164 | // IndexOutOfBoundsException: Invalid index 0, size is 0 165 | WeatherForecastCondition wfc = ws.getWeatherForecastConditions().get(0); 166 | 167 | WeatherData.city = Preferences.weatherCity; 168 | 169 | String cond = wcc.getCondition(); 170 | String temp; 171 | if (Preferences.weatherCelsius) 172 | { 173 | WeatherData.tempHigh = "High " + Integer.toString(wfc.getTempMaxCelsius()); 174 | WeatherData.tempLow = "Low " + Integer.toString(wfc.getTempMinCelsius()); 175 | temp = Integer.toString(wcc.getTempCelcius()) + (char) 0x00B0 + "C"; 176 | } 177 | else 178 | { 179 | WeatherData.tempHigh = "High " + Integer.toString(WeatherUtils.celsiusToFahrenheit(wfc.getTempMaxCelsius())); 180 | WeatherData.tempLow = "Low " + Integer.toString(WeatherUtils.celsiusToFahrenheit(wfc.getTempMinCelsius())); 181 | temp = Integer.toString(wcc.getTempFahrenheit()) + (char) 0x00B0 + "F"; 182 | } 183 | //String place = gwh.city; 184 | 185 | WeatherData.condition = cond; 186 | WeatherData.temp = temp; 187 | 188 | cond = cond.toLowerCase(); 189 | 190 | if (cond.equals("clear") || cond.equals("mostly sunny") || cond.equals("partly sunny") || cond.equals("sunny")) 191 | WeatherData.icon = "weather_sunny.bmp"; 192 | else if (cond.equals("cloudy") || cond.equals("mostly cloudy") || cond.equals("overcast") || cond.equals("partly cloudy")) 193 | WeatherData.icon = "weather_cloudy.bmp"; 194 | else if (cond.equals("light rain") || cond.equals("rain") || cond.equals("rain showers") || cond.equals("showers") || cond.equals("chance of showers") || cond.equals("scattered showers") || cond.equals("freezing rain") || cond.equals("freezing drizzle") || cond.equals("rain and snow")) 195 | WeatherData.icon = "weather_rain.bmp"; 196 | else if (cond.equals("thunderstorm") || cond.equals("chance of storm") || cond.equals("isolated thunderstorms")) 197 | WeatherData.icon = "weather_thunderstorm.bmp"; 198 | else if (cond.equals("chance of snow") || cond.equals("snow showers") || cond.equals("ice/snow") || cond.equals("flurries")) 199 | WeatherData.icon = "weather_snow.bmp"; 200 | else 201 | WeatherData.icon = "weather_cloudy.bmp"; 202 | 203 | WeatherData.received = true; 204 | 205 | Idle.updateLcdIdle(context); 206 | 207 | } catch (Exception e) { 208 | Log.e(MetaWatch.TAG, e.toString()); 209 | } 210 | } 211 | 212 | static void startAlarmTicker(Context context) { 213 | alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 214 | intent = new Intent(context, AlarmReceiver.class); 215 | intent.putExtra("action_update", "update"); 216 | sender = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT); 217 | 218 | alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 0, 30 * 60 * 1000, sender); 219 | } 220 | 221 | static void stopAlarmTicker() { 222 | alarmManager.cancel(sender); 223 | } 224 | 225 | private static class ContentObserverMessages extends ContentObserver { 226 | 227 | Context context; 228 | 229 | public ContentObserverMessages(Context context) { 230 | super(null); 231 | this.context = context; 232 | } 233 | 234 | @Override 235 | public void onChange(boolean selfChange) { 236 | super.onChange(selfChange); 237 | // change in SMS/MMS database 238 | Idle.updateLcdIdle(context); 239 | } 240 | } 241 | 242 | private static class ContentObserverCalls extends ContentObserver { 243 | 244 | Context context; 245 | 246 | public ContentObserverCalls(Context context) { 247 | super(null); 248 | this.context = context; 249 | } 250 | 251 | @Override 252 | public void onChange(boolean selfChange) { 253 | super.onChange(selfChange); 254 | // change in call history database 255 | Log.d(MetaWatch.TAG, "call history change"); 256 | Idle.updateLcdIdle(context); 257 | } 258 | } 259 | 260 | 261 | } 262 | -------------------------------------------------------------------------------- /src/org/metawatch/manager/Notification.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * Notification.java * 27 | * Notification * 28 | * Notification watch mode * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import java.util.ArrayList; 36 | 37 | import org.metawatch.manager.MetaWatchService.WatchType; 38 | 39 | 40 | import android.content.Context; 41 | import android.graphics.Bitmap; 42 | import android.util.Log; 43 | 44 | public class Notification { 45 | 46 | static NotificationType lastNotification = null; 47 | 48 | public static ArrayList notificationQueue = new ArrayList(); 49 | public static boolean isSending = false; 50 | 51 | public static final int notificationTimeout = 5000; 52 | 53 | public static Object scrollRequest = new Object(); 54 | 55 | public static class NotificationType { 56 | Bitmap bitmap; 57 | int[] array; 58 | byte[] buffer; 59 | 60 | byte[] oledTop; 61 | byte[] oledBottom; 62 | byte[] oledScroll; 63 | 64 | int scrollLength; 65 | int timeout; 66 | 67 | VibratePattern vibratePattern; 68 | } 69 | 70 | public static class VibratePattern { 71 | boolean vibrate = false; 72 | int on; 73 | int off; 74 | int cycles; 75 | 76 | public VibratePattern(boolean vibrate, int on, int off, int cycles) { 77 | this.vibrate = vibrate; 78 | this.on = on; 79 | this.off = off; 80 | this.cycles = cycles; 81 | } 82 | } 83 | 84 | public static void processNotificationQueue(final Context context) { 85 | if (isSending) 86 | return; 87 | else 88 | isSending = true; 89 | 90 | Thread thread = new Thread() { 91 | public void run() { 92 | 93 | if (notificationQueue.size() > 0) { 94 | MetaWatchService.watchState = MetaWatchService.WatchStates.NOTIFICATION; 95 | MetaWatchService.WatchModes.NOTIFICATION = true; 96 | } 97 | 98 | while (notificationQueue.size() > 0) { 99 | NotificationType notification = notificationQueue.get(0); 100 | 101 | //Protocol.loadTemplate(2); 102 | 103 | if (MetaWatchService.watchType == WatchType.DIGITAL) { 104 | if (notification.bitmap != null) 105 | Protocol.sendLcdBitmap(notification.bitmap, MetaWatchService.WatchBuffers.NOTIFICATION); 106 | else if (notification.array != null) 107 | Protocol.sendLcdArray(notification.array, MetaWatchService.WatchBuffers.NOTIFICATION); 108 | else if (notification.buffer != null) 109 | Protocol.sendLcdBuffer(notification.buffer, MetaWatchService.WatchBuffers.NOTIFICATION); 110 | 111 | Protocol.updateDisplay(2); 112 | 113 | if (notification.vibratePattern.vibrate) 114 | Protocol.vibrate(notification.vibratePattern.on, notification.vibratePattern.off, notification.vibratePattern.cycles); 115 | 116 | Log.d(MetaWatch.TAG, "notif bitmap sent from thread"); 117 | } else { 118 | Protocol.sendOledDisplay(notification.oledTop, true, false); 119 | Protocol.sendOledDisplay(notification.oledBottom, false, false); 120 | 121 | if (notification.vibratePattern.vibrate) 122 | Protocol.vibrate(notification.vibratePattern.on, notification.vibratePattern.off, notification.vibratePattern.cycles); 123 | 124 | if (notification.oledScroll != null) { 125 | if (notification.scrollLength < 1) 126 | return; 127 | if (notification.scrollLength >= 240) { 128 | Protocol.sendOledBufferPart(notification.oledScroll, 0, 240, true, false); 129 | // wait continue with scroll 130 | 131 | for (int i = 240; i < notification.scrollLength; i += 80) { 132 | // wait for next request 133 | try { 134 | synchronized (Notification.scrollRequest) { 135 | Notification.scrollRequest.wait(60000); 136 | } 137 | } catch (InterruptedException e) { 138 | } 139 | 140 | if (i+80 >= notification.scrollLength) 141 | Protocol.sendOledBufferPart(notification.oledScroll, i, 80, false, true); 142 | else 143 | Protocol.sendOledBufferPart(notification.oledScroll, i, 80, false, false); 144 | } 145 | 146 | // wait for scroll to finish 147 | try { 148 | synchronized (Notification.scrollRequest) { 149 | Notification.scrollRequest.wait(60000); 150 | } 151 | } catch (InterruptedException e) { 152 | } 153 | 154 | } else { 155 | int len = notification.scrollLength / 20 + 1; 156 | Protocol.sendOledBufferPart(notification.oledScroll, 0, len*20, true, true); 157 | } 158 | } 159 | } 160 | 161 | 162 | MetaWatchService.nap(notification.timeout); 163 | 164 | if (MetaWatchService.WatchModes.CALL == true) { 165 | isSending = false; 166 | return; 167 | } 168 | 169 | notificationQueue.remove(0); 170 | } 171 | isSending = false; 172 | 173 | exitNotification(context); 174 | } 175 | }; 176 | thread.start(); 177 | } 178 | 179 | public static void addTextNotification(Context context, String text, VibratePattern vibratePattern, int timeout) { 180 | NotificationType notification = new NotificationType(); 181 | notification.bitmap = Protocol.createTextBitmap(context, text); 182 | notification.timeout = timeout; 183 | if (vibratePattern == null) 184 | notification.vibratePattern = new VibratePattern(false, 0, 0, 0); 185 | else 186 | notification.vibratePattern = vibratePattern; 187 | notificationQueue.add(notification); 188 | lastNotification = notification; 189 | processNotificationQueue(context); 190 | } 191 | 192 | public static void addBitmapNotification(Context context, Bitmap bitmap, VibratePattern vibratePattern, int timeout) { 193 | NotificationType notification = new NotificationType(); 194 | notification.bitmap = bitmap; 195 | notification.timeout = timeout; 196 | if (vibratePattern == null) 197 | notification.vibratePattern = new VibratePattern(false, 0, 0, 0); 198 | else 199 | notification.vibratePattern = vibratePattern; 200 | notificationQueue.add(notification); 201 | lastNotification = notification; 202 | processNotificationQueue(context); 203 | } 204 | 205 | public static void addArrayNotification(Context context, int[] array, VibratePattern vibratePattern) { 206 | NotificationType notification = new NotificationType(); 207 | notification.array = array; 208 | notification.timeout = notificationTimeout; 209 | if (vibratePattern == null) 210 | notification.vibratePattern = new VibratePattern(false, 0, 0, 0); 211 | else 212 | notification.vibratePattern = vibratePattern; 213 | notificationQueue.add(notification); 214 | lastNotification = notification; 215 | processNotificationQueue(context); 216 | } 217 | 218 | public static void addBufferNotification(Context context, byte[] buffer, VibratePattern vibratePattern) { 219 | NotificationType notification = new NotificationType(); 220 | notification.buffer = buffer; 221 | notification.timeout = notificationTimeout; 222 | if (vibratePattern == null) 223 | notification.vibratePattern = new VibratePattern(false, 0, 0, 0); 224 | else 225 | notification.vibratePattern = vibratePattern; 226 | notificationQueue.add(notification); 227 | lastNotification = notification; 228 | processNotificationQueue(context); 229 | } 230 | 231 | 232 | public static void addOledNotification(Context context, byte[] top, byte[] bottom, byte[] scroll, int scrollLength, VibratePattern vibratePattern) { 233 | NotificationType notification = new NotificationType(); 234 | notification.oledTop = top; 235 | notification.oledBottom = bottom; 236 | notification.oledScroll = scroll; 237 | notification.scrollLength = scrollLength; 238 | notification.timeout = notificationTimeout; 239 | if (vibratePattern == null) 240 | notification.vibratePattern = new VibratePattern(false, 0, 0, 0); 241 | else 242 | notification.vibratePattern = vibratePattern; 243 | notificationQueue.add(notification); 244 | lastNotification = notification; 245 | processNotificationQueue(context); 246 | } 247 | 248 | 249 | 250 | public static void toNotification(Context context) { 251 | MetaWatchService.watchState = MetaWatchService.WatchStates.NOTIFICATION; 252 | MetaWatchService.WatchModes.NOTIFICATION = true; 253 | 254 | processNotificationQueue(context); 255 | } 256 | 257 | public static void exitNotification(Context context) { 258 | // disable notification mode 259 | MetaWatchService.WatchModes.NOTIFICATION = false; 260 | 261 | if (MetaWatchService.WatchModes.CALL == true) 262 | return; 263 | else if (MetaWatchService.WatchModes.APPLICATION == true) 264 | Application.toApp(); 265 | else if (MetaWatchService.WatchModes.IDLE == true) 266 | Idle.toIdle(context); 267 | } 268 | 269 | public static void replay(Context context) { 270 | if (lastNotification != null) { 271 | lastNotification.vibratePattern.vibrate = false; 272 | notificationQueue.add(lastNotification); 273 | toNotification(context); 274 | } 275 | } 276 | 277 | } 278 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /src/org/metawatch/manager/MetaWatchService.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /***************************************************************************** 6 | * Copyright (c) 2011 Meta Watch Ltd. * 7 | * www.MetaWatch.org * 8 | * * 9 | ============================================================================= 10 | * * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); * 12 | * you may not use this file except in compliance with the License. * 13 | * You may obtain a copy of the License at * 14 | * * 15 | * http://www.apache.org/licenses/LICENSE-2.0 * 16 | * * 17 | * Unless required by applicable law or agreed to in writing, software * 18 | * distributed under the License is distributed on an "AS IS" BASIS, * 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 20 | * See the License for the specific language governing permissions and * 21 | * limitations under the License. * 22 | * * 23 | *****************************************************************************/ 24 | 25 | /***************************************************************************** 26 | * MetaWatchService.java * 27 | * MetaWatchService * 28 | * Always connected BT watch service * 29 | * * 30 | * * 31 | *****************************************************************************/ 32 | 33 | package org.metawatch.manager; 34 | 35 | import java.io.IOException; 36 | import java.io.InputStream; 37 | import java.io.OutputStream; 38 | import java.lang.reflect.InvocationTargetException; 39 | import java.lang.reflect.Method; 40 | import java.util.UUID; 41 | 42 | import android.app.NotificationManager; 43 | import android.app.PendingIntent; 44 | import android.app.Service; 45 | import android.bluetooth.BluetoothAdapter; 46 | import android.bluetooth.BluetoothDevice; 47 | import android.bluetooth.BluetoothSocket; 48 | import android.content.Context; 49 | import android.content.Intent; 50 | import android.content.SharedPreferences; 51 | import android.content.SharedPreferences.Editor; 52 | import android.media.AudioManager; 53 | import android.os.Handler; 54 | import android.os.IBinder; 55 | import android.os.Looper; 56 | import android.os.Message; 57 | import android.os.PowerManager; 58 | import android.preference.PreferenceManager; 59 | import android.telephony.TelephonyManager; 60 | import android.util.Log; 61 | import android.widget.RemoteViews; 62 | import android.widget.Toast; 63 | 64 | public class MetaWatchService extends Service { 65 | 66 | Context context; 67 | public static BluetoothAdapter bluetoothAdapter; 68 | //BluetoothServerSocket bluetoothServerSocket; 69 | BluetoothSocket bluetoothSocket; 70 | static InputStream inputStream; 71 | static OutputStream outputStream; 72 | 73 | TelephonyManager telephonyManager; 74 | AudioManager audioManager; 75 | NotificationManager notificationManager; 76 | RemoteViews remoteViews; 77 | android.app.Notification notification; 78 | 79 | public static PowerManager powerManger; 80 | public static PowerManager.WakeLock wakeLock; 81 | 82 | static int connectionState; 83 | public static int watchType; 84 | public static int watchState; 85 | 86 | public static TestSmsLoop testSmsLoop; 87 | 88 | 89 | final class ConnectionState { 90 | static final int DISCONNECTED = 0; 91 | static final int CONNECTING = 1; 92 | static final int CONNECTED = 2; 93 | static final int DISCONNECTING = 3; 94 | } 95 | 96 | final class WatchBuffers { 97 | static final int IDLE = 0; 98 | static final int APPLICATION = 1; 99 | static final int NOTIFICATION = 2; 100 | } 101 | 102 | final class WatchStates { 103 | static final int OFF = 0; 104 | static final int IDLE = 1; 105 | static final int APPLICATION = 2; 106 | static final int NOTIFICATION = 3; 107 | static final int CALL = 3; 108 | } 109 | 110 | static class WatchModes { 111 | public static boolean IDLE = false; 112 | public static boolean APPLICATION = false; 113 | public static boolean NOTIFICATION = false; 114 | public static boolean CALL = false; 115 | } 116 | 117 | static class Preferences { 118 | public static boolean startOnBoot = false; 119 | public static boolean notifyCall = true; 120 | public static boolean notifySMS = true; 121 | public static boolean notifyGmail = true; 122 | public static boolean notifyK9 = true; 123 | public static boolean notifyAlarm = true; 124 | public static boolean notifyMusic = true; 125 | public static String watchMacAddress = ""; 126 | public static int packetWait = 10; 127 | public static boolean skipSDP = false; 128 | public static boolean invertLCD = false; 129 | public static String weatherCity = "Dallas,US"; 130 | public static boolean weatherCelsius = false; 131 | public static int fontSize = 2; 132 | public static int smsLoopInterval = 15; 133 | public static boolean idleMusicControls = false; 134 | public static boolean idleReplay = false; 135 | } 136 | 137 | final class WatchType { 138 | static final int ANALOG = 1; 139 | static final int DIGITAL = 2; 140 | } 141 | 142 | @Override 143 | public IBinder onBind(Intent intent) { 144 | return null; 145 | } 146 | 147 | public static void loadPreferences(Context context) { 148 | SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); 149 | 150 | 151 | Preferences.startOnBoot = sharedPreferences.getBoolean("StartOnBoot", Preferences.startOnBoot); 152 | Preferences.notifyCall = sharedPreferences.getBoolean("NotifyCall", Preferences.notifyCall); 153 | Preferences.notifySMS = sharedPreferences.getBoolean("NotifySMS", Preferences.notifySMS); 154 | Preferences.notifyGmail = sharedPreferences.getBoolean("NotifyGmail", Preferences.notifyGmail); 155 | Preferences.notifyK9 = sharedPreferences.getBoolean("NotifyK9", Preferences.notifyK9); 156 | Preferences.notifyAlarm = sharedPreferences.getBoolean("NotifyAlarm", Preferences.notifyAlarm); 157 | Preferences.notifyMusic = sharedPreferences.getBoolean("NotifyMusic", Preferences.notifyMusic); 158 | Preferences.watchMacAddress = sharedPreferences.getString("MAC", Preferences.watchMacAddress); 159 | Preferences.skipSDP = sharedPreferences.getBoolean("SkipSDP", Preferences.skipSDP); 160 | Preferences.invertLCD = sharedPreferences.getBoolean("InvertLCD", Preferences.invertLCD); 161 | Preferences.weatherCity = sharedPreferences.getString("WeatherCity", Preferences.weatherCity); 162 | Preferences.weatherCelsius = sharedPreferences.getBoolean("WeatherCelsius", Preferences.weatherCelsius); 163 | Preferences.idleMusicControls = sharedPreferences.getBoolean("IdleMusicControls", Preferences.idleMusicControls); 164 | Preferences.idleReplay = sharedPreferences.getBoolean("IdleReplay", Preferences.idleReplay); 165 | 166 | try { 167 | Preferences.fontSize = Integer.valueOf(sharedPreferences.getString("FontSize", Integer.toString(Preferences.fontSize))); 168 | Preferences.packetWait = Integer.valueOf(sharedPreferences.getString("PacketWait", Integer.toString(Preferences.packetWait))); 169 | Preferences.smsLoopInterval = Integer.valueOf(sharedPreferences.getString("SmsLoopInterval", Integer.toString(Preferences.smsLoopInterval))); 170 | } catch (NumberFormatException e) { 171 | } 172 | 173 | } 174 | 175 | public static void saveMac(Context context, String mac) { 176 | SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); 177 | Editor editor = sharedPreferences.edit(); 178 | 179 | editor.putString("MAC", mac); 180 | editor.commit(); 181 | } 182 | 183 | public void createNotification() { 184 | notification = new android.app.Notification(R.drawable.disconnected_large, null, System.currentTimeMillis()); 185 | notification.flags |= android.app.Notification.FLAG_ONGOING_EVENT; 186 | 187 | remoteViews = new RemoteViews(getPackageName(), R.layout.notification); 188 | remoteViews.setImageViewResource(R.id.image, R.drawable.disconnected); 189 | remoteViews.setTextViewText(R.id.text, "MetaWatch service is running"); 190 | notification.contentView = remoteViews; 191 | 192 | Intent notificationIntent = new Intent(this, MetaWatch.class); 193 | PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 194 | notification.contentIntent = contentIntent; 195 | 196 | startForeground(1, notification); 197 | } 198 | 199 | public void updateNotification(boolean connected) { 200 | if (connected) { 201 | notification.icon = R.drawable.connected; 202 | remoteViews.setImageViewResource(R.id.image, R.drawable.connected_large); 203 | } else { 204 | notification.icon = R.drawable.disconnected; 205 | remoteViews.setImageViewResource(R.id.image, R.drawable.disconnected_large); 206 | } 207 | startForeground(1, notification); 208 | } 209 | 210 | public void removeNotification() { 211 | stopForeground(true); 212 | } 213 | 214 | @Override 215 | public void onCreate() { 216 | super.onCreate(); 217 | 218 | context = this; 219 | createNotification(); 220 | 221 | connectionState = ConnectionState.CONNECTING; 222 | watchState = WatchStates.OFF; 223 | watchType = WatchType.DIGITAL; 224 | 225 | if (bluetoothAdapter == null) 226 | bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 227 | 228 | powerManger = (PowerManager) getSystemService(Context.POWER_SERVICE); 229 | wakeLock = powerManger.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MetaWatch"); 230 | 231 | audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 232 | Monitors.start(this, telephonyManager); 233 | 234 | start(); 235 | 236 | } 237 | 238 | @Override 239 | public void onDestroy() { 240 | disconnectExit(); 241 | super.onDestroy(); 242 | 243 | Monitors.stop(); 244 | removeNotification(); 245 | } 246 | 247 | 248 | void connect(Context context) { 249 | 250 | try { 251 | 252 | Log.d(MetaWatch.TAG, "Remote device address: " + Preferences.watchMacAddress); 253 | if (Preferences.watchMacAddress.equals("")) 254 | loadPreferences(context); 255 | BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(Preferences.watchMacAddress); 256 | 257 | /* 258 | Log.d(MetaWatch.TAG, "remote device name: " + bluetoothDevice.getName()); 259 | int bondState = bluetoothDevice.getBondState(); 260 | String bond = ""; 261 | switch (bondState) { 262 | case BluetoothDevice.BOND_BONDED: 263 | bond = "bonded"; 264 | break; 265 | case BluetoothDevice.BOND_BONDING: 266 | bond = "bonding"; 267 | break; 268 | case BluetoothDevice.BOND_NONE: 269 | bond = "none"; 270 | break; 271 | } 272 | Log.d(MetaWatch.TAG, "bond state: " + bond); 273 | */ 274 | 275 | if (Preferences.skipSDP) { 276 | Method method = bluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); 277 | bluetoothSocket = (BluetoothSocket) method.invoke(bluetoothDevice, 1); 278 | } else { 279 | UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 280 | bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(uuid); 281 | } 282 | 283 | //Log.d(MetaWatch.TAG, "got Bluetooth socket"); 284 | //if (bluetoothSocket == null) 285 | //Log.d(MetaWatch.TAG, "Bluetooth socket is null"); 286 | 287 | bluetoothSocket.connect(); 288 | inputStream = bluetoothSocket.getInputStream(); 289 | outputStream = bluetoothSocket.getOutputStream(); 290 | 291 | connectionState = ConnectionState.CONNECTED; 292 | updateNotification(true); 293 | 294 | Protocol.sendRtcNow(context); 295 | Protocol.getDeviceType(); 296 | 297 | } catch (IOException ioexception) { 298 | Log.d(MetaWatch.TAG, ioexception.toString()); 299 | sendToast(ioexception.toString()); 300 | } catch (SecurityException e) { 301 | Log.d(MetaWatch.TAG, e.toString()); 302 | } catch (NoSuchMethodException e) { 303 | Log.d(MetaWatch.TAG, e.toString()); 304 | } catch (IllegalArgumentException e) { 305 | Log.d(MetaWatch.TAG, e.toString()); 306 | } catch (IllegalAccessException e) { 307 | Log.d(MetaWatch.TAG, e.toString()); 308 | } catch (InvocationTargetException e) { 309 | Log.d(MetaWatch.TAG, e.toString()); 310 | } 311 | 312 | 313 | } 314 | 315 | public void sendToast(String text) { 316 | Message m = new Message(); 317 | m.what = 1; 318 | m.obj = text; 319 | messageHandler.sendMessage(m); 320 | } 321 | 322 | private Handler messageHandler = new Handler() { 323 | 324 | @Override 325 | public void handleMessage(Message msg) { 326 | switch (msg.what) { 327 | case 1: 328 | Toast.makeText(context, (CharSequence) msg.obj, Toast.LENGTH_SHORT).show(); 329 | break; 330 | } 331 | } 332 | 333 | }; 334 | 335 | void disconnect() { 336 | try { 337 | if (outputStream != null) 338 | outputStream.close(); 339 | } catch (IOException e) { 340 | } 341 | try { 342 | if (inputStream != null) 343 | inputStream.close(); 344 | } catch (IOException e) { 345 | } 346 | try { 347 | if (bluetoothSocket != null) 348 | bluetoothSocket.close(); 349 | } catch (IOException e) { 350 | } 351 | } 352 | 353 | void disconnectExit() { 354 | connectionState = ConnectionState.DISCONNECTING; 355 | disconnect(); 356 | } 357 | 358 | public static void nap(long time) { 359 | try { 360 | Thread.sleep(time); 361 | } catch (InterruptedException e) { 362 | } 363 | } 364 | 365 | void start() { 366 | Thread thread = new Thread() { 367 | public void run() { 368 | boolean run = true; 369 | Looper.prepare(); 370 | 371 | while (run) { 372 | switch (connectionState) { 373 | case ConnectionState.DISCONNECTED: 374 | Log.d(MetaWatch.TAG, "state: disconnected"); 375 | break; 376 | case ConnectionState.CONNECTING: 377 | Log.d(MetaWatch.TAG, "state: connecting"); 378 | // create initial connection or reconnect 379 | updateNotification(false); 380 | connect(context); 381 | nap(2000); 382 | break; 383 | case ConnectionState.CONNECTED: 384 | Log.d(MetaWatch.TAG, "state: connected"); 385 | // read from input stream 386 | readFromDevice(); 387 | break; 388 | case ConnectionState.DISCONNECTING: 389 | Log.d(MetaWatch.TAG, "state: disconnecting"); 390 | // exit 391 | run = false; 392 | break; 393 | } 394 | } 395 | } 396 | }; 397 | thread.start(); 398 | } 399 | 400 | void readFromDevice() { 401 | 402 | try { 403 | byte[] bytes = new byte[256]; 404 | Log.d(MetaWatch.TAG, "before blocking read"); 405 | inputStream.read(bytes); 406 | wakeLock.acquire(5000); 407 | 408 | // print received 409 | String str = "received: "; 410 | int len = (bytes[1] & 0xFF); 411 | Log.d(MetaWatch.TAG, "packet length: " + len); 412 | 413 | for (int i = 0; i < len; i ++) { 414 | //str+= Byte.toString(bytes[i]) + ", "; 415 | str+= "0x" + Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1) + ", "; 416 | } 417 | Log.d(MetaWatch.TAG, str); 418 | 419 | switch (bytes[2]) { 420 | case 0x02: 421 | Log.d(MetaWatch.TAG, "received: device type response"); 422 | break; 423 | case 0x31: 424 | Log.d(MetaWatch.TAG, "received: nval response"); 425 | break; 426 | case 0x33: 427 | Log.d(MetaWatch.TAG, "received: status change event"); 428 | break; 429 | } 430 | /* 431 | if (bytes[2] == 0x31) { // nval response 432 | if (bytes[3] == 0x00) // success 433 | if (bytes[4] == 0x00) // set to 12 hour format 434 | Protocol.setNvalTime(true); 435 | } 436 | */ 437 | 438 | if (bytes[2] == 0x33) { // status change event 439 | if (bytes[4] == 0x11) { 440 | Log.d(MetaWatch.TAG, "notify scroll request"); 441 | 442 | synchronized (Notification.scrollRequest) { 443 | Notification.scrollRequest.notify(); 444 | } 445 | } 446 | 447 | if (bytes[4] == 0x10) { 448 | Log.d(MetaWatch.TAG, "scroll completed"); 449 | } 450 | } 451 | 452 | if (bytes[2] == 0x34) { // button press 453 | Log.d(MetaWatch.TAG, "button event"); 454 | pressedButton(bytes[3]); 455 | } 456 | 457 | if (bytes[2] == 0x02) { // device type 458 | if (bytes[4] == 1 || bytes[4] == 4) { 459 | watchType = WatchType.ANALOG; 460 | 461 | } 462 | else { 463 | watchType = WatchType.DIGITAL; 464 | 465 | 466 | if (Preferences.idleMusicControls) 467 | Protocol.enableMediaButtons(); 468 | //else 469 | //Protocol.disableMediaButtons(); 470 | 471 | if (Preferences.idleReplay) 472 | Protocol.enableReplayButton(); 473 | //else 474 | //Protocol.disableReplayButton(); 475 | 476 | Protocol.configureMode(); 477 | Idle.toIdle(this); 478 | Idle.updateLcdIdle(this); 479 | 480 | Protocol.queryNvalTime(); 481 | 482 | } 483 | } 484 | 485 | } catch (IOException e) { 486 | wakeLock.acquire(5000); 487 | if (connectionState != ConnectionState.DISCONNECTING) 488 | connectionState = ConnectionState.CONNECTING; 489 | } 490 | 491 | } 492 | 493 | void pressedButton(byte button) { 494 | Log.d(MetaWatch.TAG, "button code: " + Byte.toString(button)); 495 | 496 | switch (watchState) { 497 | case WatchStates.IDLE: { 498 | switch (button) { 499 | case MediaControl.VOLUME_UP: 500 | MediaControl.volumeUp(audioManager); 501 | break; 502 | case MediaControl.VOLUME_DOWN: 503 | MediaControl.volumeDown(audioManager); 504 | break; 505 | case MediaControl.NEXT: 506 | MediaControl.next(this); 507 | break; 508 | case MediaControl.PREVIOUS: 509 | MediaControl.previous(this); 510 | break; 511 | case MediaControl.TOGGLE: 512 | MediaControl.togglePause(this); 513 | break; 514 | case Protocol.REPLAY: 515 | Notification.replay(this); 516 | break; 517 | } 518 | /* 519 | if (Idle.isIdleButtonOverriden(button)) { 520 | Log.d(MetaWatch.TAG, "this button is overriden"); 521 | broadcastButton(button, watchState); 522 | } 523 | */ 524 | } 525 | break; 526 | case WatchStates.APPLICATION: 527 | broadcastButton(button, watchState); 528 | break; 529 | case WatchStates.NOTIFICATION: 530 | break; 531 | } 532 | 533 | } 534 | 535 | void broadcastButton(byte button, int state) { 536 | Intent intent = new Intent("org.metawatch.manager.BUTTON_PRESS"); 537 | intent.putExtra("button", button); 538 | switch (state) { 539 | case WatchStates.IDLE: 540 | intent.putExtra("mode", "idle"); 541 | break; 542 | case WatchStates.APPLICATION: 543 | intent.putExtra("mode", "application"); 544 | break; 545 | } 546 | sendBroadcast(intent); 547 | } 548 | 549 | 550 | } 551 | --------------------------------------------------------------------------------