diff --git a/README.md b/README.md index ed4f3550ce..008188bce5 100755 --- a/README.md +++ b/README.md @@ -150,17 +150,8 @@ curl -X GET \ ## デバイスプラグイン | プロジェクト名|内容 | |:-----------|:---------| -|[dConnectDeviceAndroidWear](dConnectDevicePlugin/dConnectDeviceAndroidWear)|AndroidWearのデバイスプラグイン。| -|[dConnectDeviceChromeCast](dConnectDevicePlugin/dConnectDeviceChromeCast)|Chromecastのデバイスプラグイン。 | -|[dConnectDeviceFaBo](dConnectDevicePlugin/dConnectDeviceFaBo)|FaBoのデバイスプラグイン。| -|[dConnectDeviceHeartRate](dConnectDevicePlugin/dConnectDeviceHeartRate)|Mio AlphaなどのHeartRateのデバイスプラグイン。| -|[dConnectDeviceHOGP](dConnectDevicePlugin/dConnectDeviceHOGP)|HOGPのデバイスプラグイン。| |[dConnectDeviceHost](dConnectDevicePlugin/dConnectDeviceHost)|Androidのデバイスプラグイン。| -|[dConnectDeviceHue](dConnectDevicePlugin/dConnectDeviceHue)|Hueのデバイスプラグイン。| -|[dConnectDeviceIRKit](dConnectDevicePlugin/dConnectDeviceIRKit)|IRKitのデバイスプラグイン。| |[dConnectDeviceLinking](dConnectDevicePlugin/dConnectDeviceLinking)|Linkingのデバイスプラグイン。| -|[dConnectDeviceSwitchBot](dConnectDevicePlugin/dConnectDeviceSwitchBot)|SwitchBotのデバイスプラグイン。| -|[dConnectDeviceTheta](dConnectDevicePlugin/dConnectDeviceTheta)|THETAのデバイスプラグイン。| |[dConnectDeviceUVC](dConnectDevicePlugin/dConnectDeviceUVC)|UVCカメラのデバイスプラグイン。| |[dConnectDeviceTest](dConnectDevicePlugin/dConnectDeviceTest)|DeviceConnectのテスト用のデバイスプラグイン。| |[dConnectDevicePluginSDK](dConnectDevicePlugin/dConnectDevicePluginSDK)|DevicePluginを作成するためのSDK。
dConnectSDKForAndroidが必要。| diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/LICENSE.TXT b/dConnectDevicePlugin/dConnectDeviceAndroidWear/LICENSE.TXT deleted file mode 100755 index 9f0bfd2fe5..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/LICENSE.TXT +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 NTT DOCOMO, INC. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/README.md b/dConnectDevicePlugin/dConnectDeviceAndroidWear/README.md deleted file mode 100644 index 7f45ea3dd9..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Android Wear プラグイン - -このAndroid Wearプラグインでは、Android Wearに対応したスマートウォッチを操作する機能を提供します。 - -## 開発環境 -Android Studio 2.2.1以上 - -## ビルドマニュアル -- [Android Wearビルドマニュアル](https://github.com/DeviceConnect/DeviceConnect-Android/wiki/AndroidWear-Build) - -## サポートするプロファイル - -* canvas -* deviceOrientation -* keyEvent -* notification -* touch -* vibration diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/build.gradle b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/build.gradle deleted file mode 100644 index ac59734fd9..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/build.gradle +++ /dev/null @@ -1,89 +0,0 @@ -apply plugin: 'com.android.application' -// Create github.properties in root project folder file with -// gpr.usr=GITHUB_USER_ID -// gpr.key=PERSONAL_ACCESS_TOKEN -def githubPropertiesFile = rootProject.file("github.properties") -def githubProperties = new Properties() -if (githubPropertiesFile.exists()) { - githubProperties.load(new FileInputStream(githubPropertiesFile)) -} - -dependencies { - implementation fileTree(include: '*.jar', dir: 'libs') - implementation 'org.deviceconnect:dconnect-device-plugin-sdk:2.8.4' - implementation 'androidx.multidex:multidex:2.0.1' - implementation 'com.google.android.gms:play-services-wearable:17.0.0' - - wearApp project(':wear-app') -} - -android { - - compileSdkVersion 29 - - def getVersionName = { -> - def version - if (System.getProperty('os.name').toLowerCase().contains('windows')) { - version = ["cmd", "/c", "git describe --tags --long"].execute().in.text.trim() - } else { - version = ["sh", "-c", "git describe --tags --long"].execute().in.text.trim() - } - version = version.empty ? "2.1.0" : version - return "${version}" - } - - defaultConfig { - applicationId "org.deviceconnect.android.deviceplugin.wear" - minSdkVersion 23 - targetSdkVersion 29 - versionCode 1 - versionName getVersionName() - multiDexEnabled true - } - - signingConfigs { - releaseConfig { - storeFile=file(project.properties.storeFile) - storePassword=project.properties.storePassword - keyAlias=project.properties.keyAlias - keyPassword=project.properties.keyPassword - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - signingConfig signingConfigs.releaseConfig - } - } - - packagingOptions { - exclude 'LICENSE.txt' - exclude 'META-INF/DEPENDENCIES' - exclude 'META-INF/LICENSE' - exclude 'META-INF/NOTICE' - } - tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' - } - lintOptions { - checkReleaseBuilds false - abortOnError false - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - repositories { - maven { - name = "DeviceConnect-Android" - url = uri("https://maven.pkg.github.com/DeviceConnect/DeviceConnect-Android") - - credentials { - username = System.getenv("GPR_USER") ?: githubProperties['gpr.usr'] - password = System.getenv("GPR_API_KEY") ?: githubProperties['gpr.key'] - } - } - } -} \ No newline at end of file diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/AndroidManifest.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/AndroidManifest.xml deleted file mode 100755 index 76ac0caac4..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearDeviceProvider.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearDeviceProvider.java deleted file mode 100755 index 3071fef382..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearDeviceProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - WearServiceProvider.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear; - -import android.app.Service; - -import org.deviceconnect.android.message.DConnectMessageServiceProvider; - -/** - * Provider. - * - * @param Service class. - * @author NTT DOCOMO, INC. - */ -public class WearDeviceProvider extends DConnectMessageServiceProvider { - @SuppressWarnings("unchecked") - @Override - protected Class getServiceClass() { - Class clazz = WearDeviceService.class; - return (Class) clazz; - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearDeviceService.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearDeviceService.java deleted file mode 100755 index 921390b189..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearDeviceService.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - WearDeviceService.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear; - -import android.content.Intent; - -import com.google.android.gms.wearable.Node; - -import org.deviceconnect.android.deviceplugin.wear.profile.WearConst; -import org.deviceconnect.android.deviceplugin.wear.profile.WearNotificationProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearServiceDiscoveryProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearSystemProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearUtils; -import org.deviceconnect.android.deviceplugin.wear.service.WearService; -import org.deviceconnect.android.event.Event; -import org.deviceconnect.android.event.EventManager; -import org.deviceconnect.android.message.DConnectMessageService; -import org.deviceconnect.android.profile.SystemProfile; -import org.deviceconnect.android.service.DConnectService; - -import java.util.List; - -/** - * WearService. - * - * @author NTT DOCOMO, INC. - */ -public class WearDeviceService extends DConnectMessageService implements WearManager.NodeEventListener { - - /** - * Android Wearとの通信を管理するクラス. - */ - private WearManager mWearManager; - - @Override - public void onCreate() { - super.onCreate(); - mWearManager = new WearManager(this); - mWearManager.addNodeListener(this); - mWearManager.init(); - - addProfile(new WearServiceDiscoveryProfile(mWearManager, getServiceProvider())); - } - - @Override - public int onStartCommand(final Intent intent, final int flags, final int startId) { - if (intent != null) { - String action = intent.getAction(); - if (WearConst.DEVICE_TO_WEAR_NOTIFICATION_OPEN.equals(action)) { - String serviceId = intent.getStringExtra(WearConst.PARAM_DEVICEID); - int notificationId = intent.getIntExtra(WearConst.PARAM_NOTIFICATIONID, -1); - List events = EventManager.INSTANCE.getEventList(serviceId, - WearNotificationProfile.PROFILE_NAME, null, WearNotificationProfile.ATTRIBUTE_ON_CLICK); - synchronized (events) { - for (Event event : events) { - Intent msg = EventManager.createEventMessage(event); - msg.putExtra(WearNotificationProfile.PARAM_NOTIFICATION_ID, notificationId); - sendEvent(msg, event.getAccessToken()); - } - } - } else if (WearConst.DEVICE_TO_WEAR_NOTIFICATION_CLOSED.equals(action)) { - String serviceId = intent.getStringExtra(WearConst.PARAM_DEVICEID); - int notificationId = intent.getIntExtra(WearConst.PARAM_NOTIFICATIONID, -1); - List events = EventManager.INSTANCE.getEventList(serviceId, - WearNotificationProfile.PROFILE_NAME, null, WearNotificationProfile.ATTRIBUTE_ON_CLOSE); - synchronized (events) { - for (Event event : events) { - Intent msg = EventManager.createEventMessage(event); - msg.putExtra(WearNotificationProfile.PARAM_NOTIFICATION_ID, notificationId); - sendEvent(msg, event.getAccessToken()); - } - } - } - } - return super.onStartCommand(intent, flags, startId); - } - - @Override - public void onDestroy() { - super.onDestroy(); - if (mWearManager != null) { - mWearManager.destroy(); - mWearManager = null; - } - } - - @Override - protected SystemProfile getSystemProfile() { - return new WearSystemProfile(); - } - - @Override - public void onNodeConnected(final Node node) { - DConnectService service = WearService.getInstance(node, mWearManager); - service.setOnline(node.isNearby()); - getServiceProvider().addService(service); - getManager().sendWearData(); - } - - @Override - public void onNodeDisconnected(final Node node) { - String serviceId = WearUtils.createServiceId(node.getId()); - DConnectService service = getServiceProvider().getService(serviceId); - if (service != null) { - service.setOnline(false); - } else { - DConnectService addService = WearService.getInstance(node, mWearManager); - addService.setOnline(node.isNearby()); - getServiceProvider().addService(addService); - } - } - - /** - * Android Wear管理クラスを取得する. - * @return WearManagerのインスタンス - */ - public WearManager getManager() { - return mWearManager; - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearManager.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearManager.java deleted file mode 100644 index 379b492ecc..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearManager.java +++ /dev/null @@ -1,449 +0,0 @@ -package org.deviceconnect.android.deviceplugin.wear; - -import android.content.Context; -import android.net.Uri; -import androidx.annotation.NonNull; - -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.OnSuccessListener; -import com.google.android.gms.tasks.Task; -import com.google.android.gms.tasks.Tasks; -import com.google.android.gms.wearable.Asset; -import com.google.android.gms.wearable.CapabilityClient; -import com.google.android.gms.wearable.CapabilityInfo; -import com.google.android.gms.wearable.DataItem; -import com.google.android.gms.wearable.MessageClient; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.PutDataMapRequest; -import com.google.android.gms.wearable.PutDataRequest; -import com.google.android.gms.wearable.Wearable; - -import org.deviceconnect.android.deviceplugin.wear.profile.WearConst; - -import org.deviceconnect.android.logger.AndroidHandler; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.logging.SimpleFormatter; - -/** - * Android Wearを管理するクラス. - * - * @author NTT DOCOMO, INC. - */ -public class WearManager { - - private final Logger mLogger = Logger.getLogger("dconnect.wear"); - - - /** - * コンテキスト. - */ - private final Context mContext; - - /** - * スレッド管理用クラス. - */ - private final ExecutorService mExecutorService = Executors.newSingleThreadExecutor(); - - /** - * メッセージイベントリスナー一覧. - */ - private final Map mOnMessageEventListeners - = new HashMap<>(); - - /** - * ノード検知リスナー一覧. - */ - private final List mNodeEventListeners = new ArrayList<>(); - - /** - * ノード情報のキャッシュ. - */ - private final Map mNodeCache = new HashMap(); - - /** - * コンストラクタ. - * - * @param context このクラスが属するコンテキスト - */ - public WearManager(final Context context) { - mContext = context; - if (BuildConfig.DEBUG) { - AndroidHandler handler = new AndroidHandler(mLogger.getName()); - handler.setFormatter(new SimpleFormatter()); - handler.setLevel(Level.ALL); - mLogger.addHandler(handler); - mLogger.setLevel(Level.ALL); - } else { - mLogger.setLevel(Level.OFF); - } - } - - - /** - * このクラスを初期化する. - */ - public void init() { - setCapabilityListener(); - setMessageListener(); - getNodes((results) -> { - if (results == null) { - return; - } - synchronized (mNodeCache) { - for (Node node : results) { - if (!mNodeCache.containsKey(node.getId())) { - mNodeCache.put(node.getId(), node); - mLogger.info("getNodes: name = " + node.getDisplayName() - + ", id = " + node.getId()); - notifyOnNodeConnected(node); - } - } - } - }); - } - - /** - * 接続しているAndroidWearにIDを送る. - */ - public void sendWearData() { - new Thread(() -> { - getNodes((results) -> { - if (results == null) { - return; - } - synchronized (mNodeCache) { - for (Node node : results) { - if (!mNodeCache.containsKey(node.getId())) { - mNodeCache.put(node.getId(), node); - mLogger.info("getNode: name = " + node.getDisplayName() - + ", id = " + node.getId()); - notifyOnNodeConnected(node); - - } - } - } - }); - for (String key : mNodeCache.keySet()) { - Node node = mNodeCache.get(key); - sendMessageToWear(node.getId(), WearConst.DEVICE_TO_WEAR_SET_ID, node.getId(), null); - mLogger.info("sendMessage: name = " + node.getDisplayName() - + ", id = " + node.getId()); - } - }).start(); - } - /** - * 後始末処理を行う. - */ - public void destroy() { - mExecutorService.shutdown(); - mNodeEventListeners.clear(); - mOnMessageEventListeners.clear(); - mNodeCache.clear(); - } - - /** - * メッセージイベントリスナーを追加する. - * - * @param path パス - * @param listener リスナー - */ - public void addMessageEventListener(final String path, final OnMessageEventListener listener) { - mOnMessageEventListeners.put(path, listener); - } - - /** - * ノード検知リスナーを追加する. - */ - public void addNodeListener(final NodeEventListener listener) { - synchronized (mNodeEventListeners) { - mNodeEventListeners.add(listener); - } - } - - /** - * Wearとの接続状況を検知するリスナー. - */ - private void setCapabilityListener() { - Wearable.getCapabilityClient(mContext).addListener((capabilityInfo) -> { - for (Node node : capabilityInfo.getNodes()) { - if (node.isNearby()) { - mLogger.info("isNearby=true: name = " + node.getDisplayName() - + ", id = " + node.getId()); - mNodeCache.put(node.getId(), node); - notifyOnNodeConnected(node); - } else { - mLogger.info("onPeerDisconnected: name = " + node.getDisplayName() - + ", id = " + node.getId()); - mNodeCache.remove(node.getId()); - notifyOnNodeDisconnected(node); - } - } - }, Uri.parse("wear://"), CapabilityClient.FILTER_REACHABLE); - } - - private void notifyOnNodeConnected(final Node node) { - synchronized (mNodeEventListeners) { - for (NodeEventListener listener : mNodeEventListeners) { - listener.onNodeConnected(node); - } - } - } - - private void notifyOnNodeDisconnected(final Node node) { - synchronized (mNodeEventListeners) { - for (NodeEventListener listener : mNodeEventListeners) { - listener.onNodeDisconnected(node); - } - } - } - - /** - * Android Wearのリスナーを設定する. - */ - private void setMessageListener() { - Wearable.getMessageClient(mContext).addListener((messageEvent) -> { - final String data = new String(messageEvent.getData()); - final String path = messageEvent.getPath(); - final String nodeId = messageEvent.getSourceNodeId(); - OnMessageEventListener listener = mOnMessageEventListeners.get(path); - if (listener != null) { - listener.onEvent(nodeId, data); - } - }); - } - - /** - * Wear nodeを取得. - * - * @param listener Wear node取得を通知するリスナー - */ - public void getNodes(final OnNodeResultListener listener) { - sendMessageToWear(() -> { - Task> nodeListTask = Wearable.getNodeClient(mContext).getConnectedNodes(); - List nodes = null; - try { - nodes = Tasks.await(nodeListTask); - } catch (ExecutionException exception) { - mLogger.warning("Task failed: " + exception); - } catch (InterruptedException exception) { - mLogger.warning("Interrupt occurred: " + exception); - } - if (listener != null) { - listener.onResult(nodes); - } - }); - } - - /** - * メッセージをWearに送信する. - * - * @param dest 送信先のWearのnodeId - * @param action メッセージのアクション - * @param message メッセージ - * @param listener メッセージを送信した結果を通知するリスナー - */ - public void sendMessageToWear(final String dest, final String action, final String message, - final OnMessageResultListener listener) { - getNodes((results) -> { - for (Node node : results) { - if (node.getId().contains(dest)) { - Task sendMessageTask = - Wearable.getMessageClient(mContext).sendMessage(node.getId(), action, message.getBytes()); - sendMessageTask.addOnSuccessListener((integer) -> { - if (listener != null) { - listener.onResult(); - } - }); - - sendMessageTask.addOnFailureListener((e) -> { - if (listener != null) { - listener.onError(); - } - }); - } - } - }); - } - - /** - * PutDataRequestを作成する. - * - * @param nodeId ノードID - * @param requestId リクエストID - * @param data requestに格納する画像 - * @param x x座標 - * @param y y座標 - * @param mode 描画モード - * @return PutDataRequestのインスタンス - */ - private PutDataRequest createPutDataRequest(final String nodeId, final String requestId, final byte[] data, - final int x, final int y, final int mode) { - Asset asset = Asset.createFromBytes(data); - PutDataMapRequest dataMap = PutDataMapRequest.create(WearConst.PATH_CANVAS + "/" + nodeId + "/" + requestId); - dataMap.getDataMap().putAsset(WearConst.PARAM_BITMAP, asset); - dataMap.getDataMap().putInt(WearConst.PARAM_X, x); - dataMap.getDataMap().putInt(WearConst.PARAM_Y, y); - dataMap.getDataMap().putInt(WearConst.PARAM_MODE, mode); - dataMap.getDataMap().putLong(WearConst.TIMESTAMP, - System.currentTimeMillis()); - return dataMap.asPutDataRequest(); - } - - /** - * 画像データを送信する. - * - * @param nodeId ノードID - * @param requestId リクエストID - * @param data 画像データ - * @param x x座標 - * @param y y座標 - * @param mode 描画モード - * @param listener 送信結果を通知するリスナー - */ - public void sendImageData(final String nodeId, final String requestId, - final byte[] data, final int x, final int y, - final int mode, final OnDataItemResultListener listener) { - // リクエストIDとともに画像送信 - sendMessageToWear(() -> { - final PutDataRequest request = createPutDataRequest(nodeId, requestId, data, x, y, mode); - if (request == null) { - if (listener != null) { - listener.onError(); - } - } else { - request.setUrgent(); - Task dataItemTask = Wearable.getDataClient(mContext).putDataItem(request); - dataItemTask.addOnSuccessListener((dataItem) -> { - if (listener != null) { - listener.onResult(dataItem); - } - }); - dataItemTask.addOnFailureListener((e) -> { - if (listener != null) { - listener.onError(); - } - }); - } - }); - } - - /** - * Wearにメッセージを送ります. - * - * @param run 送るメッセージを実行するrunnable - */ - private void sendMessageToWear(final Runnable run) { - mExecutorService.execute(run); - } - - public void getLocalNodeId(final String serviceId, final OnLocalNodeListener listener) { - getNodes((results) -> { - for (Node node : results) { - if (node.getId().equals(serviceId)) { - if (listener != null) { - listener.onResult(node); - } - return; - } - } - if (listener != null) { - listener.onError(); - } - }); - } - - /** - * ノード検知イベントリスナー. - */ - public interface NodeEventListener { - - /** - * ノードとの接続イベント. - * @param node ノード - */ - void onNodeConnected(Node node); - - /** - * ノードとの接続の切断イベント. - * @param node ノード - */ - void onNodeDisconnected(Node node); - - } - - /** - * Nodeの検索結果を通知するリスナー. - */ - public interface OnNodeResultListener { - /** - * 結果を通知する. - * - * @param results 検索結果 - */ - void onResult(List results); - - } - - public interface OnLocalNodeListener { - - void onResult(Node localNode); - - void onError(); - } - - /** - * メッセージ送信の結果を通知するリスナー. - */ - public interface OnMessageResultListener { - /** - * メッセージ送信結果を通知する. - * - */ - void onResult(); - - /** - * エラーが発生したことを通知する. - */ - void onError(); - } - - /** - * データ送信の結果を通知するリスナー. - */ - public interface OnDataItemResultListener { - /** - * データ送信の結果を通知する. - * - * @param result 結果 - */ - void onResult(DataItem result); - - /** - * エラーが発生したことを通知する. - */ - void onError(); - } - - /** - * イベント受信を通知するリスナー. - */ - public interface OnMessageEventListener { - /** - * 受信したイベントを通知する. - * - * @param nodeId ノートID - * @param message イベントメッセージ - */ - void onEvent(String nodeId, String message); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/package-info.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/package-info.java deleted file mode 100644 index f3cf053010..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - org.deviceconnect.android.deviceplugin.wear - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ - -/** - * Android wear device plugin package. - */ -package org.deviceconnect.android.deviceplugin.wear; - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearCanvasProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearCanvasProfile.java deleted file mode 100644 index ce5246f34c..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearCanvasProfile.java +++ /dev/null @@ -1,325 +0,0 @@ -/* -WearCanvasProfile.java -Copyright (c) 2015 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; - -import com.google.android.gms.wearable.DataItem; -import com.google.android.gms.wearable.Node; - -import org.deviceconnect.android.deviceplugin.wear.WearDeviceService; -import org.deviceconnect.android.deviceplugin.wear.WearManager; -import org.deviceconnect.android.message.MessageUtils; -import org.deviceconnect.android.profile.CanvasProfile; -import org.deviceconnect.android.profile.api.DConnectApi; -import org.deviceconnect.android.profile.api.DeleteApi; -import org.deviceconnect.android.profile.api.PostApi; -import org.deviceconnect.message.DConnectMessage; - -import java.io.ByteArrayOutputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; - -/** - * Android Wear用のCanvasプロファイル. - * - * @author NTT DOCOMO, INC. - */ -public class WearCanvasProfile extends CanvasProfile { - - /** - * Android wearは1MB以上の画像は送信できない. - */ - private static final int LIMIT_DATA_SIZE = 1024 * 1024; - - private final Logger mLogger = Logger.getLogger("dconnect.wear"); - - private ExecutorService mImageService = Executors.newSingleThreadExecutor(); - - private static final Map mRequestMap = new HashMap<>(); - - private final WearManager mWearManager; - - public WearCanvasProfile(final WearManager mgr) { - mWearManager = mgr; - mgr.addMessageEventListener(WearConst.WEAR_TO_DEVICE_CANVAS_RESULT, - this::onCanvasResponse); - addApi(mPostDrawImage); - addApi(mDeleteDrawImage); - } - - private DConnectApi mPostDrawImage = new PostApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_DRAW_IMAGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - final String nodeId = WearUtils.getNodeId(getServiceID(request)); - final byte[] data = getData(request); - final double x = getX(request); - final double y = getY(request); - final String mode = getMode(request); - String mimeType = getMIMEType(request); - if (mimeType != null && !mimeType.contains("image")) { - MessageUtils.setInvalidRequestParameterError(response, - "Unsupported mimeType: " + mimeType); - return true; - } - - if (data == null) { - mImageService.execute(() -> { - String uri = getURI(request); - byte[] result = getData(uri); - if (result == null) { - MessageUtils.setInvalidRequestParameterError(response, "could not get image from uri."); - sendResponse(response); - return; - } - drawImage(response, nodeId, result, x, y, mode); - }); - return false; - } else { - drawImage(response, nodeId, data, x, y, mode); - return false; - } - } - }; - - private void drawImage(final Intent response, final String nodeId, - final byte[] data, final double x, final double y, final String mode) { - mWearManager.getLocalNodeId(nodeId, new WearManager.OnLocalNodeListener() { - - @Override - public void onResult(final Node localNode) { - final String localNodeId = localNode.getId(); - if (data.length > LIMIT_DATA_SIZE) { - MessageUtils.setInvalidRequestParameterError(response, "data size more than 1MB"); - sendResponse(response); - return; - } - Mode m = Mode.getInstance(mode); - if ((mode != null && mode.length() > 0) && m == null) { - MessageUtils.setInvalidRequestParameterError(response, "mode is invalid"); - sendResponse(response); - return; - } - - //for check binary - Bitmap bitmap; - try { - bitmap = getBitmap(data); - } catch (OutOfMemoryError e) { - MessageUtils.setInvalidRequestParameterError(response, "Too large bitmap for host device."); - sendResponse(response); - return; - } - if (bitmap == null) { - MessageUtils.setInvalidRequestParameterError(response, "format invalid"); - sendResponse(response); - return; - } - int mm = WearUtils.convertMode(m); - - //Adjust image format and compress - ByteArrayOutputStream o = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.PNG, 50, o); - final byte[] bitmapData = o.toByteArray(); - - final String requestId = UUID.randomUUID().toString(); - final DrawImageRequest wearRequest = createCanvasRequest(localNodeId, requestId); - getManager().sendImageData(localNodeId, requestId, bitmapData, (int) x, (int) y, mm, new WearManager.OnDataItemResultListener() { - @Override - public void onResult(final DataItem result) { - new Thread(() -> { - if (result != null) { - try { - DrawImageResponse wearResponse = wearRequest.await(); - if (wearResponse.isSuccess()) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - int errorCode = wearResponse.getErrorCode(); - String errorMessage = wearResponse.getErrorMessage(); - MessageUtils.setError(response, errorCode, errorMessage); - } - } catch (Exception e) { - MessageUtils.setUnknownError(response, e.getLocalizedMessage()); - } - } else { - MessageUtils.setIllegalDeviceStateError(response); - } - sendResponse(response); - }).start(); - } - - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - } - - @Override - public void onError() { - MessageUtils.setUnknownError(response, "Failed to get Local Node ID."); - } - }); - } - - private final DConnectApi mDeleteDrawImage = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_DRAW_IMAGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_CANCAS_DELETE_IMAGE, - "", new WearManager.OnMessageResultListener() { - @Override - public void onResult() { - setResult(response, DConnectMessage.RESULT_OK); - sendResponse(response); - } - - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - /** - * データを画像に変換します. - * - * @param data 画像データ - * @return Bitmap - */ - private Bitmap getBitmap(final byte[] data) { - return BitmapFactory.decodeByteArray(data, 0, data.length); - } - - /** - * Android Wear管理クラスを取得する. - * - * @return WearManager管理クラス - */ - private WearManager getManager() { - return ((WearDeviceService) getContext()).getManager(); - } - - private DrawImageRequest createCanvasRequest(final String nodeId, final String requestId) { - DrawImageRequest request = new DrawImageRequest(nodeId); - mRequestMap.put(requestId, request); - return request; - } - - private void onCanvasResponse(final String nodeId, final String message) { - String[] items = message.split(","); - String requestId = items[0]; - String result = items[1]; - DrawImageRequest request = mRequestMap.get(requestId); - if (request == null) { - mLogger.warning("onCanvasImageResponse: request is not found: nodeId = " + nodeId); - return; - } - if (!request.getNodeId().equals(nodeId)) { - mLogger.warning("onCanvasImageResponse: nodeId are not matched for request: requestId = " + requestId); - return; - } - request.receive(result); - mRequestMap.remove(requestId); - } - - private static class DrawImageRequest { - - private CountDownLatch mLock = new CountDownLatch(1); - - private DrawImageResponse mResponse; - - private final String mNodeId; - - public DrawImageRequest(final String nodeId) { - mNodeId = nodeId; - } - - public DrawImageResponse await() throws InterruptedException, ResponseTimeoutException { - mLock.await(30, TimeUnit.SECONDS); - if (!hasResponse()) { - throw new ResponseTimeoutException(); - } - return mResponse; - } - - public void receive(final String message) { - mResponse = new DrawImageResponse(message); - mLock.countDown(); - } - - public boolean hasResponse() { - return mResponse != null; - } - - public String getNodeId() { - return mNodeId; - } - } - - private static class DrawImageResponse { - - private final String mResult; - private final int mErrorCode; - private final String mErrorMessage; - - public DrawImageResponse(final String message) { - mResult = message; - if (WearConst.RESULT_ERROR_TOO_LARGE_BITMAP.equals(message)) { - mErrorCode = DConnectMessage.ErrorCode.INVALID_REQUEST_PARAMETER.getCode(); - mErrorMessage = "Too large bitmap for watch."; - } else if (WearConst.RESULT_ERROR_CONNECTION_FAILURE.equals(message)) { - mErrorCode = DConnectMessage.ErrorCode.ILLEGAL_DEVICE_STATE.getCode(); - mErrorMessage = "Connection failure."; - } else if (WearConst.RESULT_ERROR_NOT_SUPPORTED_FORMAT.equals(message)) { - mErrorCode = DConnectMessage.ErrorCode.INVALID_REQUEST_PARAMETER.getCode(); - mErrorMessage = "Not supported format."; - } else { - mErrorCode = 0; - mErrorMessage = ""; - } - } - - public boolean isSuccess() { - return WearConst.RESULT_SUCCESS.equals(mResult); - } - - public int getErrorCode() { - return mErrorCode; - } - - public String getErrorMessage() { - return mErrorMessage; - } - } - - private static class ResponseTimeoutException extends TimeoutException { - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearConst.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearConst.java deleted file mode 100755 index 502ec70057..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearConst.java +++ /dev/null @@ -1,260 +0,0 @@ -/* -WearConst.java -Copyright (c) 2014 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -/** - * Wear Const. - * - * @author NTT DOCOMO, INC. - */ -public final class WearConst { - - /** Vibration start. */ - public static final String DEVICE_TO_WEAR_VIBRATION_RUN - = "org.deviceconnect.wear.vibration.run"; - - /** Vibration stop. */ - public static final String DEVICE_TO_WEAR_VIBRATION_DEL - = "org.deviceconnect.wear.vibration.del"; - - /** When Action is opened. */ - public static final String DEVICE_TO_WEAR_NOTIFICATION_OPEN - = "org.deviceconnect.wear.notification.open"; - - /** When Action is closed. */ - public static final String DEVICE_TO_WEAR_NOTIFICATION_CLOSED - = "org.deviceconnect.wear.notification.closed"; - - /** When DeviceOrientation register is opened. */ - public static final String DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER - = "org.deviceconnect.wear.deivceorienatation.regist"; - - /** When DeviceOrientation unregister is opened. */ - public static final String DEVICE_TO_WEAR_DEIVCEORIENTATION_UNREGISTER - = "org.deviceconnect.wear.deivceorienatation.unregist"; - - /** When Canvas deleted. */ - public static final String DEVICE_TO_WEAR_CANCAS_DELETE_IMAGE - = "org.deviceconnect.wear.canvas.delete"; - - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_DEIVCEORIENTATION_DATA - = "org.deviceconnect.wear.deivceorienatation.data"; - - /** Register Key Event (ondown). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER - = "org.deviceconnect.wear.keyevent.ondown.regist"; - - /** Register Key Event (onup). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER = "org.deviceconnect.wear.keyevent.onup.regist"; - /** Register Key Event (onkeychange). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER - = "org.deviceconnect.wear.keyevent.onkeychange.regist"; - - /** Remove Key Event (ondown). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER - = "org.deviceconnect.wear.keyevent.ondown.unregist"; - - /** Remove Key Event (onup). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER - = "org.deviceconnect.wear.keyevent.onup.unregist"; - /** Remove Key Event (onkeychange). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER - = "org.deviceconnect.wear.keyevent.onkeychange.unregist"; - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_KEYEVENT_DATA = "org.deviceconnect.wear.keyevent.data"; - - /** Key Event (down). */ - public static final String PARAM_KEYEVENT_DOWN = "down"; - - /** Key Event (up). */ - public static final String PARAM_KEYEVENT_UP = "up"; - - /** ServiceId. */ - public static final String PARAM_DEVICEID = "serviceId"; - - /** NotificationId. */ - public static final String PARAM_NOTIFICATIONID = "notificationId"; - - /** - * サービスID. - */ - public static final String SERVICE_ID = "Wear"; - - /** - * デバイス名: {@value}. - */ - public static final String DEVICE_NAME = "Android Wear"; - - /** - * bitmapを受け渡しするためのキー. - */ - public static final String PARAM_BITMAP = "bitmap"; - - /** - * x座標を受け渡しするためのキー. - */ - public static final String PARAM_X = "x"; - - /** - * y座標を受け渡しするためのキー. - */ - public static final String PARAM_Y = "y"; - - /** - * 描画モードを受け渡しするためのキー. - */ - public static final String PARAM_MODE = "mode"; - - /** - * Timestamp. - */ - public static final String TIMESTAMP = "timestamp"; - /** - * 画像を送信するためのパスを定義する. - */ - public static final String PATH_CANVAS = "/canvas/profile"; - - /** - * 通常の描画モード. - */ - public static final int MODE_NORMAL = 0; - - /** - * 拡大の描画モード. - */ - public static final int MODE_SCALES = 1; - - /** - * リピート描画モード. - */ - public static final int MODE_FILLS = 2; - - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_CANVAS_RESULT = "org.deviceconnect.wear.canvas.result"; - - /** リクエストID. */ - public static final String PARAM_REQUEST_ID = "requestId"; - - /** データ変更イベントの送信元(Android端末)を特定するためのID. */ - public static final String PARAM_SOURCE_ID = "sourceId"; - - /** メッセージの送信先(Android端末)を特定するためのID. */ - public static final String PARAM_DESTINATION_ID = "destinationId"; - - /** 成功. */ - public static final String RESULT_SUCCESS = "success"; - - /** エラー: ビットマップサイズが大きすぎる. */ - public static final String RESULT_ERROR_TOO_LARGE_BITMAP = "errorTooLargeBitmap"; - - /** エラー: Android端末との接続に失敗. */ - public static final String RESULT_ERROR_CONNECTION_FAILURE = "errorConnectionFailure"; - - /** エラー: サポートしていない画像形式. */ - public static final String RESULT_ERROR_NOT_SUPPORTED_FORMAT = "errorNotSupportedFormat"; - - /** Register Touch (ontouch). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER - = "org.deviceconnect.wear.touch.ontouch.regist"; - - /** Register Touch (ontouchstart). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER - = "org.deviceconnect.wear.touch.ontouchstart.regist"; - - /** Register Touch (ontouchend). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER - = "org.deviceconnect.wear.touch.ontouchend.regist"; - - /** Register Touch (ondoubletap). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER - = "org.deviceconnect.wear.touch.ondoubletap.regist"; - - /** Register Touch (ontouchmove). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER - = "org.deviceconnect.wear.touch.ontouchmove.regist"; - - /** Register Touch (ontouchcancel). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER - = "org.deviceconnect.wear.touch.ontouchcancel.regist"; - /** Register Touch (ontouchchange). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER - = "org.deviceconnect.wear.touch.ontouchchange.regist"; - - /** Remove Touch (ontouch). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER - = "org.deviceconnect.wear.touch.ontouch.unregist"; - - /** Remove Touch (ontouchstart). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchstart.unregist"; - - /** Remove Touch (ontouchend). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchend.unregist"; - - /** Remove Touch (ondoubletap). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER - = "org.deviceconnect.wear.touch.ondoubletap.unregist"; - - /** Remove Touch (ontouchmove). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchmove.unregist"; - - /** Remove Touch (ontouchcancel). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchcancel.unregist"; - /** Remove Touch (ontouchchange). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchchange.unregist"; - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_TOUCH_DATA = "org.deviceconnect.wear.touch.data"; - /** Set wear id.. */ - public static final String DEVICE_TO_WEAR_SET_ID - = "org.deviceconnect.wear.id.set"; - - /** Touch (touch). */ - public static final String PARAM_TOUCH_TOUCH = "touch"; - - /** Touch (touchstart). */ - public static final String PARAM_TOUCH_TOUCHSTART = "touchstart"; - - /** Touch (touchend). */ - public static final String PARAM_TOUCH_TOUCHEND = "touchend"; - - /** Touch (doubletap). */ - public static final String PARAM_TOUCH_DOUBLETAP = "doubletap"; - - /** Touch (touchmove). */ - public static final String PARAM_TOUCH_TOUCHMOVE = "touchmove"; - - /** Touch (touchcancel). */ - public static final String PARAM_TOUCH_TOUCHCANCEL = "touchcancel"; - /** - * Attribute: {@value} . - */ - public static final String ATTRIBUTE_ON_TOUCH_CHANGE = "onTouchChange"; - /** Touch State start. */ - public static final String STATE_START = "start"; - /** Touch State end. */ - public static final String STATE_END = "end"; - /** Touch State double tap. */ - public static final String STATE_DOUBLE_TAP = "doubletap"; - /** Touch State move. */ - public static final String STATE_MOVE = "move"; - /** Touch State cancel. */ - public static final String STATE_CANCEL = "cancel"; - /** KeyEvent State move. */ - public static final String STATE_UP = "up"; - /** KeyEvent State cancel. */ - public static final String STATE_DOWN = "down"; - /** - * Constructor. - */ - private WearConst() { - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearDeviceOrientationProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearDeviceOrientationProfile.java deleted file mode 100755 index 83c1b08504..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearDeviceOrientationProfile.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - WearDeviceOrientationProfile.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.content.Intent; -import android.os.Bundle; - -import org.deviceconnect.android.deviceplugin.wear.WearDeviceService; -import org.deviceconnect.android.deviceplugin.wear.WearManager; -import org.deviceconnect.android.deviceplugin.wear.WearManager.OnMessageEventListener; -import org.deviceconnect.android.deviceplugin.wear.WearManager.OnMessageResultListener; -import org.deviceconnect.android.event.Event; -import org.deviceconnect.android.event.EventError; -import org.deviceconnect.android.event.EventManager; -import org.deviceconnect.android.message.MessageUtils; -import org.deviceconnect.android.profile.DeviceOrientationProfile; -import org.deviceconnect.android.profile.api.DConnectApi; -import org.deviceconnect.android.profile.api.DeleteApi; -import org.deviceconnect.android.profile.api.GetApi; -import org.deviceconnect.android.profile.api.PutApi; -import org.deviceconnect.message.DConnectMessage; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * DeviceOrientation Profile. - * - * @author NTT DOCOMO, INC. - */ -public class WearDeviceOrientationProfile extends DeviceOrientationProfile { - - /** - * 通知先のリスナーを保持するリスト. - */ - private final List mListeners = - Collections.synchronizedList(new ArrayList()); - - /** - * Android Wearからのイベントを受け取るリスナー. - */ - private OnMessageEventListener mListener = new OnMessageEventListener() { - @Override - public void onEvent(final String nodeId, final String message) { - synchronized (mListeners) { - for (OnMessageEventListener l : mListeners) { - l.onEvent(WearUtils.createServiceId(nodeId), message); - } - } - } - }; - - /** - * コンストラクタ. - * @param mgr Android Wear管理クラス - */ - public WearDeviceOrientationProfile(final WearManager mgr) { - mgr.addMessageEventListener(WearConst.WEAR_TO_DEVICE_DEIVCEORIENTATION_DATA, mListener); - mListeners.add(new OnMessageEventListener() { - @Override - public void onEvent(final String nodeId, final String message) { - sendMessageToEvent(nodeId, message); - } - }); - addApi(mGetOnDeviceOrientation); - addApi(mPutOnDeviceOrientation); - addApi(mDeleteOnDeviceOrientation); - } - - private final DConnectApi mGetOnDeviceOrientation = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DEVICE_ORIENTATION; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - final WearDeviceService service = (WearDeviceService) getContext(); - final String serviceId = WearUtils.getNodeId(getServiceID(request)); - final OnMessageEventListener l = new OnMessageEventListener() { - @Override - public void onEvent(final String nodeId, final String message) { - Bundle orientation = createOrientation(message); - setResult(response, DConnectMessage.RESULT_OK); - setOrientation(response, orientation); - service.sendResponse(response); - removeListener(this); - if (isEmptyEvent(serviceId)) { - stopSensor(serviceId); - } - } - }; - addListener(l); - - getManager().sendMessageToWear(serviceId, - WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - removeListener(l); - MessageUtils.setIllegalDeviceStateError(response); - service.sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mPutOnDeviceOrientation = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DEVICE_ORIENTATION; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mDeleteOnDeviceOrientation = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DEVICE_ORIENTATION; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - stopSensor(nodeId); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - /** - * イベントの配送先の空状態を取得する. - * @param nodeId wearのID - * @return 空の場合はtrue、それ以外はfalse - */ - private boolean isEmptyEvent(final String nodeId) { - List events = EventManager.INSTANCE.getEventList( - nodeId, PROFILE_NAME, null, ATTRIBUTE_ON_DEVICE_ORIENTATION); - return events == null || events.size() == 0; - } - - /** - * 指定されたWearのセンサーを停止する. - * @param nodeId wearのID - */ - private void stopSensor(final String nodeId) { - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - } - - /** - * リスナーを追加する. - * @param l 追加するリスナー - */ - private void addListener(final OnMessageEventListener l) { - if (!mListeners.contains(l)) { - mListeners.add(l); - } - } - - /** - * リスナーを削除する. - * @param l 削除するリスナー - */ - private void removeListener(final OnMessageEventListener l) { - mListeners.remove(l); - } - - /** - * Send a message to the registration event. - * - * @param nodeId node id - * @param data Received Strings. - */ - private void sendMessageToEvent(final String nodeId, final String data) { - Bundle orientation = createOrientation(data); - - List events = EventManager.INSTANCE.getEventList( - nodeId, PROFILE_NAME, null, ATTRIBUTE_ON_DEVICE_ORIENTATION); - synchronized (events) { - for (Event event : events) { - Intent intent = EventManager.createEventMessage(event); - intent.putExtra(DeviceOrientationProfile.PARAM_ORIENTATION, orientation); - ((WearDeviceService) getContext()).sendEvent(intent, event.getAccessToken()); - } - } - } - - /** - * 受信したデータからOrientationのデータを作成する. - * @param data 受信したデータ - * @return Orientationのデータ - */ - private Bundle createOrientation(final String data) { - String[] mDataArray = data.split(",", 0); - - Bundle orientation = new Bundle(); - Bundle a1 = new Bundle(); - a1.putDouble(DeviceOrientationProfile.PARAM_X, 0.0); - a1.putDouble(DeviceOrientationProfile.PARAM_Y, 0.0); - a1.putDouble(DeviceOrientationProfile.PARAM_Z, 0.0); - - Bundle a2 = new Bundle(); - a2.putDouble(DeviceOrientationProfile.PARAM_X, Double.parseDouble(mDataArray[0])); - a2.putDouble(DeviceOrientationProfile.PARAM_Y, Double.parseDouble(mDataArray[1])); - a2.putDouble(DeviceOrientationProfile.PARAM_Z, Double.parseDouble(mDataArray[2])); - - // Conversion the unit of angular speed from rad/s to degree/s. - double alpha = Math.toDegrees(Double.parseDouble(mDataArray[3])); - double beta = Math.toDegrees(Double.parseDouble(mDataArray[4])); - double gamma = Math.toDegrees(Double.parseDouble(mDataArray[5])); - Bundle r = new Bundle(); - r.putDouble(DeviceOrientationProfile.PARAM_ALPHA, alpha); - r.putDouble(DeviceOrientationProfile.PARAM_BETA, beta); - r.putDouble(DeviceOrientationProfile.PARAM_GAMMA, gamma); - orientation.putBundle(DeviceOrientationProfile.PARAM_ACCELERATION, a1); - orientation.putBundle(DeviceOrientationProfile.PARAM_ACCELERATION_INCLUDING_GRAVITY, a2); - orientation.putBundle(DeviceOrientationProfile.PARAM_ROTATION_RATE, r); - orientation.putLong(DeviceOrientationProfile.PARAM_INTERVAL, 0); - setInterval(orientation, Integer.parseInt(mDataArray[6])); - return orientation; - } - - /** - * Android Wear管理クラスを取得する. - * @return WearManager管理クラス - */ - private WearManager getManager() { - return ((WearDeviceService) getContext()).getManager(); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearKeyEventProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearKeyEventProfile.java deleted file mode 100644 index 8c2ccf7ff2..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearKeyEventProfile.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - WearKeyEventProfile.java - Copyright (c) 2015 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.content.Intent; -import android.os.Bundle; - -import org.deviceconnect.android.deviceplugin.wear.BuildConfig; -import org.deviceconnect.android.deviceplugin.wear.WearDeviceService; -import org.deviceconnect.android.deviceplugin.wear.WearManager; -import org.deviceconnect.android.deviceplugin.wear.WearManager.OnMessageEventListener; -import org.deviceconnect.android.deviceplugin.wear.WearManager.OnMessageResultListener; -import org.deviceconnect.android.event.Event; -import org.deviceconnect.android.event.EventError; -import org.deviceconnect.android.event.EventManager; -import org.deviceconnect.android.message.MessageUtils; -import org.deviceconnect.android.profile.KeyEventProfile; -import org.deviceconnect.android.profile.api.DConnectApi; -import org.deviceconnect.android.profile.api.DeleteApi; -import org.deviceconnect.android.profile.api.GetApi; -import org.deviceconnect.android.profile.api.PutApi; -import org.deviceconnect.message.DConnectMessage; - -import java.util.List; - -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.STATE_DOWN; -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.STATE_UP; - -/** - * Key Event Profile. - * - * @author NTT DOCOMO, INC. - */ -public class WearKeyEventProfile extends KeyEventProfile { - - /** Tag. */ - private static final String TAG = "WEAR"; - - /** KeyEvent profile onDown cache. */ - Bundle mOnDownCache = null; - - /** KeyEvent profile onDown cache time. */ - long mOnDownCacheTime = 0; - - /** KeyEvent profile onDown cache. */ - Bundle mOnUpCache = null; - - /** KeyEvent profile onUp cache time. */ - long mOnUpCacheTime = 0; - /** KeyEvent profile onKeyChange cache. */ - Bundle mOnKeyChangeCache = null; - /** KeyEvent profile onKeyChange cache time. */ - long mOnKeyChangeCacheTime = 0; - /** KeyEvent profile cache retention time (mSec). */ - static final long CACHE_RETENTION_TIME = 10000; - /** - * Attribute: {@value} . - */ - public static final String ATTRIBUTE_ON_KEY_CHANGE = "onKeyChange"; - /** - * Get KeyEvent cache data. - * - * @param attr Attribute. - * @return KeyEvent cache data. - */ - public Bundle getKeyEventCache(final String attr) { - long lCurrentTime = System.currentTimeMillis(); - if (attr.equalsIgnoreCase(KeyEventProfile.ATTRIBUTE_ON_DOWN)) { - if (lCurrentTime - mOnDownCacheTime <= CACHE_RETENTION_TIME) { - return mOnDownCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(KeyEventProfile.ATTRIBUTE_ON_UP)) { - if (lCurrentTime - mOnUpCacheTime <= CACHE_RETENTION_TIME) { - return mOnUpCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_KEY_CHANGE)) { - if (lCurrentTime - mOnKeyChangeCacheTime <= CACHE_RETENTION_TIME) { - return mOnKeyChangeCache; - } else { - return null; - } - } else { - return null; - } - } - - /** - * Set KeyEvent data to cache. - * - * @param attr Attribute. - * @param keyeventData Touch data. - */ - public void setKeyEventCache(final String attr, final Bundle keyeventData) { - long lCurrentTime = System.currentTimeMillis(); - if (attr.equalsIgnoreCase(KeyEventProfile.ATTRIBUTE_ON_DOWN)) { - mOnDownCache = keyeventData; - mOnDownCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(KeyEventProfile.ATTRIBUTE_ON_UP)) { - mOnUpCache = keyeventData; - mOnUpCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_KEY_CHANGE)) { - mOnKeyChangeCache = keyeventData; - mOnKeyChangeCacheTime = lCurrentTime; - } - } - - /** - * Receive event listener for Android Wear. - */ - private OnMessageEventListener mListener = new OnMessageEventListener() { - @Override - public void onEvent(final String nodeId, final String message) { - sendMessageToEvent(WearUtils.createServiceId(nodeId), message); - } - }; - - /** - * Constructor. - * - * @param mgr Android Wear management class. - */ - public WearKeyEventProfile(final WearManager mgr) { - mgr.addMessageEventListener(WearConst.WEAR_TO_DEVICE_KEYEVENT_DATA, mListener); - addApi(mGetOnKeyChange); - addApi(mGetOnDown); - addApi(mGetOnUp); - addApi(mPutOnKeyChange); - addApi(mPutOnDown); - addApi(mPutOnUp); - addApi(mDeleteOnKeyChange); - addApi(mDeleteOnDown); - addApi(mDeleteOnUp); - } - - private final DConnectApi mGetOnDown = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DOWN; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle keyevent = getKeyEventCache(KeyEventProfile.ATTRIBUTE_ON_DOWN); - if (keyevent == null) { - response.putExtra(KeyEventProfile.PARAM_KEYEVENT, ""); - } else { - response.putExtra(KeyEventProfile.PARAM_KEYEVENT, keyevent); - } - setResult(response, DConnectMessage.RESULT_OK); - return true; - } - }; - - private final DConnectApi mGetOnUp = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_UP; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle keyEvent = getKeyEventCache(KeyEventProfile.ATTRIBUTE_ON_UP); - if (keyEvent == null) { - response.putExtra(KeyEventProfile.PARAM_KEYEVENT, ""); - } else { - response.putExtra(KeyEventProfile.PARAM_KEYEVENT, keyEvent); - } - setResult(response, DConnectMessage.RESULT_OK); - return true; - } - }; - private final DConnectApi mGetOnKeyChange = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_KEY_CHANGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle keyevent = getKeyEventCache(ATTRIBUTE_ON_KEY_CHANGE); - if (keyevent == null) { - response.putExtra(KeyEventProfile.PARAM_KEYEVENT, ""); - } else { - response.putExtra(KeyEventProfile.PARAM_KEYEVENT, keyevent); - } - setResult(response, DConnectMessage.RESULT_OK); - return true; - } - }; - private final DConnectApi mPutOnDown = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DOWN; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER, "", - new OnMessageResultListener() { - @Override - public void onResult() { - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mPutOnUp = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_UP; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER, "", - new OnMessageResultListener() { - @Override - public void onResult() { - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - private final DConnectApi mPutOnKeyChange = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_KEY_CHANGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER, "", - new OnMessageResultListener() { - @Override - public void onResult() { - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - private final DConnectApi mDeleteOnDown = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DOWN; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER, "", - new OnMessageResultListener() { - @Override - public void onResult() { - } - - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - private final DConnectApi mDeleteOnUp = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_UP; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER, "", - new OnMessageResultListener() { - @Override - public void onResult() { - } - - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - private final DConnectApi mDeleteOnKeyChange = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_KEY_CHANGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER, "", - new OnMessageResultListener() { - @Override - public void onResult() { - } - - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - /** - * Send a message to the registration event. - * - * @param nodeId node id - * @param data Received Strings. - */ - private void sendMessageToEvent(final String nodeId, final String data) { - String[] mDataArray = data.split(",", 0); - String attr = null; - String state = null; - if (mDataArray[0].equals(WearConst.PARAM_KEYEVENT_DOWN)) { - attr = ATTRIBUTE_ON_DOWN; - state = STATE_DOWN; - } else if (mDataArray[0].equals(WearConst.PARAM_KEYEVENT_UP)) { - attr = ATTRIBUTE_ON_UP; - state = STATE_UP; - } else { - return; - } - - List events = EventManager.INSTANCE.getEventList(nodeId, PROFILE_NAME, null, attr); - List keyEvents = EventManager.INSTANCE.getEventList(nodeId, PROFILE_NAME, null, ATTRIBUTE_ON_KEY_CHANGE); - - Bundle keyevent = new Bundle(); - - keyevent.putInt(KeyEventProfile.PARAM_ID, Integer.parseInt(mDataArray[1])); - keyevent.putString(KeyEventProfile.PARAM_CONFIG, mDataArray[2]); - - synchronized (events) { - for (Event event : events) { - - String eventAttr = event.getAttribute(); - Intent intent = EventManager.createEventMessage(event); - intent.putExtra(KeyEventProfile.PARAM_KEYEVENT, keyevent); - ((WearDeviceService) getContext()).sendEvent(intent, event.getAccessToken()); - setKeyEventCache(eventAttr, keyevent); - } - } - synchronized (keyEvents) { - for (Event event : keyEvents) { - String eventAttr = event.getAttribute(); - keyevent.putString("state", state); - Intent intent = EventManager.createEventMessage(event); - intent.putExtra(KeyEventProfile.PARAM_KEYEVENT, keyevent); - ((WearDeviceService) getContext()).sendEvent(intent, event.getAccessToken()); - setKeyEventCache(eventAttr, keyevent); - } - } - - } - - /** - * Get Android Wear management class. - * - * @return WearManager management class. - */ - private WearManager getManager() { - return ((WearDeviceService) getContext()).getManager(); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearNotificationProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearNotificationProfile.java deleted file mode 100755 index 71de41ed66..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearNotificationProfile.java +++ /dev/null @@ -1,347 +0,0 @@ -/* - WearNotificationProfile.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.graphics.drawable.Icon; -import android.os.Build; -import androidx.core.app.NotificationCompat; - -import org.deviceconnect.android.deviceplugin.wear.R; -import org.deviceconnect.android.event.Event; -import org.deviceconnect.android.event.EventError; -import org.deviceconnect.android.event.EventManager; -import org.deviceconnect.android.message.DConnectMessageService; -import org.deviceconnect.android.message.MessageUtils; -import org.deviceconnect.android.profile.NotificationProfile; -import org.deviceconnect.android.profile.api.DConnectApi; -import org.deviceconnect.android.profile.api.DeleteApi; -import org.deviceconnect.android.profile.api.PostApi; -import org.deviceconnect.android.profile.api.PutApi; -import org.deviceconnect.message.DConnectMessage; -import org.deviceconnect.message.intent.message.IntentDConnectMessage; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.List; -import java.util.Random; - -/** - * Notification Profile. - * - * @author NTT DOCOMO, INC. - */ -public class WearNotificationProfile extends NotificationProfile { - - /** - * ランダムを生成するクラス. - */ - private final Random mRandom = new Random(System.currentTimeMillis()); - - public WearNotificationProfile() { - addApi(mPostNotify); - addApi(mDeleteNotify); - addApi(mDeleteOnClick); - addApi(mPutOnClick); - addApi(mDeleteOnClose); - addApi(mPutOnClose); - addApi(mDeleteOnShow); - addApi(mPutOnShow); - } - - private final DConnectApi mPostNotify = new PostApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_NOTIFY; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - final String serviceId = getServiceID(request); - final NotificationType type = getType(request); - final String body = getBody(request); - - int myNotificationId = mRandom.nextInt(Integer.MAX_VALUE); - - Intent clickIntent = new Intent(getContext(), - org.deviceconnect.android.deviceplugin.wear.WearDeviceService.class); - clickIntent.setAction(WearConst.DEVICE_TO_WEAR_NOTIFICATION_OPEN); - clickIntent.putExtra(WearConst.PARAM_DEVICEID, serviceId); - clickIntent.putExtra(WearConst.PARAM_NOTIFICATIONID, myNotificationId); - PendingIntent clickPendingIntent = PendingIntent.getService(getContext(), 0, clickIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - - Intent deleteIntent = new Intent(getContext(), - org.deviceconnect.android.deviceplugin.wear.WearDeviceService.class); - deleteIntent.setAction(WearConst.DEVICE_TO_WEAR_NOTIFICATION_CLOSED); - deleteIntent.putExtra(WearConst.PARAM_DEVICEID, serviceId); - deleteIntent.putExtra(WearConst.PARAM_NOTIFICATIONID, myNotificationId); - PendingIntent deletePendingIntent = PendingIntent.getService(getContext(), 0, deleteIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - - int iconType = 0; - String title = ""; - if (type == NotificationType.PHONE) { - iconType = R.drawable.notification_00_post_lollipop; - title = "PHONE"; - } else if (type == NotificationType.MAIL) { - iconType = R.drawable.notification_01_post_lollipop; - title = "MAIL"; - } else if (type == NotificationType.SMS) { - iconType = R.drawable.notification_02_post_lollipop; - title = "SMS"; - } else if (type == NotificationType.EVENT) { - iconType = R.drawable.notification_03_post_lollipop; - title = "EVENT"; - } else { - MessageUtils.setInvalidRequestParameterError(response, - "type is invalid."); - return true; - } - - String encodeBody = ""; - try { - if (body != null) { - encodeBody = URLDecoder.decode(body, "UTF-8"); - } - } catch (UnsupportedEncodingException e) { - MessageUtils.setInvalidRequestParameterError(response, - "body is invalid."); - return true; - } - - - Notification notification; - // Get an instance of the NotificationManager service - NotificationManager mNotification = (NotificationManager) getContext() - .getSystemService(Context.NOTIFICATION_SERVICE); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - NotificationCompat.Builder notificationBuilder = - new NotificationCompat.Builder(getContext()) - .setSmallIcon(iconType) - .setContentTitle("" + title) - .setContentText(encodeBody) - .setContentIntent(clickPendingIntent) - .setVibrate(new long[]{500}) - .setDeleteIntent(deletePendingIntent) - .extend(new NotificationCompat.WearableExtender()); - notification = notificationBuilder.build(); - } else { - Notification.Builder notificationBuilder = - new Notification.Builder(getContext()) - .setSmallIcon(Icon.createWithResource(getContext(), iconType)) - .setContentTitle("" + title) - .setContentText(encodeBody) - .setContentIntent(clickPendingIntent) - .setVibrate(new long[]{500}) - .setDeleteIntent(deletePendingIntent) - .extend(new Notification.WearableExtender()); - ; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - String channelId = getContext().getResources().getString(R.string.android_wear_notification_channel_id); - NotificationChannel channel = new NotificationChannel( - channelId, - getContext().getResources().getString(R.string.android_wear_notification_channel_title), - NotificationManager.IMPORTANCE_DEFAULT); - channel.setDescription(getContext().getResources().getString(R.string.android_wear_notification_channel_desc)); - mNotification.createNotificationChannel(channel); - notificationBuilder.setChannelId(channelId); - } - notification = notificationBuilder.build(); - } - // Build the notification and issues it with notification - // manager. - mNotification.notify(myNotificationId, notification); - - response.putExtra(NotificationProfile.PARAM_NOTIFICATION_ID, myNotificationId); - setResult(response, IntentDConnectMessage.RESULT_OK); - - List events = EventManager.INSTANCE.getEventList(serviceId, WearNotificationProfile.PROFILE_NAME, - null, WearNotificationProfile.ATTRIBUTE_ON_SHOW); - synchronized (events) { - for (Event event : events) { - Intent msg = EventManager.createEventMessage(event); - msg.putExtra(WearNotificationProfile.PARAM_NOTIFICATION_ID, myNotificationId); - ((DConnectMessageService) getContext()).sendEvent(msg, event.getAccessToken()); - } - } - return true; - } - }; - - private final DConnectApi mDeleteNotify = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_NOTIFY; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - NotificationManager manager = (NotificationManager) getContext() - .getSystemService(Context.NOTIFICATION_SERVICE); - try { - manager.cancel(Integer.parseInt(getNotificationId(request))); - setResult(response, DConnectMessage.RESULT_OK); - } catch (NumberFormatException e) { - MessageUtils.setInvalidRequestParameterError(response, - "notificationId is invalid."); - } - return true; - } - }; - - private final DConnectApi mDeleteOnClick = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_CLICK; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - return unregisterEvent(request, response, getServiceID(request), getSessionKey(request)); - } - }; - - private final DConnectApi mPutOnClick = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_CLICK; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - return registerEvent(request, response, getServiceID(request), getSessionKey(request)); - } - }; - - private final DConnectApi mDeleteOnClose = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_CLOSE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - return unregisterEvent(request, response, getServiceID(request), getSessionKey(request)); - } - }; - - private final DConnectApi mPutOnClose = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_CLOSE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - return registerEvent(request, response, getServiceID(request), getSessionKey(request)); - } - }; - - private final DConnectApi mDeleteOnShow = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_SHOW; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - return unregisterEvent(request, response, getServiceID(request), getSessionKey(request)); - } - }; - - private final DConnectApi mPutOnShow = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_SHOW; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - return registerEvent(request, response, getServiceID(request), getSessionKey(request)); - } - }; - - /** - * イベントを登録します. - * @param request リクエスト - * @param response レスポンス - * @param serviceId サービスID - * @param sessionKey セッションキー - * @return 同期なのでtrueを返却 - */ - private boolean registerEvent(final Intent request, final Intent response, final String serviceId, final String sessionKey) { - if (serviceId == null) { - MessageUtils.setEmptyServiceIdError(response); - } else if (!WearUtils.checkServiceId(serviceId)) { - MessageUtils.setNotFoundServiceError(response); - } else { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - switch (error) { - case NONE: - setResult(response, DConnectMessage.RESULT_OK); - break; - case FAILED: - MessageUtils.setUnknownError(response, "Do not register event."); - break; - case INVALID_PARAMETER: - MessageUtils.setInvalidRequestParameterError(response); - break; - case NOT_FOUND: - MessageUtils.setUnknownError(response, "Event not found."); - break; - default: - MessageUtils.setUnknownError(response); - break; - } - } - return true; - } - - /** - * イベントを解除します. - * @param request リクエスト - * @param response レスポンス - * @param serviceId サービスID - * @param sessionKey セッションキー - * @return 同期なのでtrueを返却 - */ - private boolean unregisterEvent(final Intent request, final Intent response, final String serviceId, final String sessionKey) { - if (serviceId == null) { - MessageUtils.setEmptyServiceIdError(response); - } else if (!WearUtils.checkServiceId(serviceId)) { - MessageUtils.setNotFoundServiceError(response); - } else { - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - switch (error) { - case NONE: - setResult(response, DConnectMessage.RESULT_OK); - break; - case FAILED: - MessageUtils.setUnknownError(response, "Do not unregister event."); - break; - case INVALID_PARAMETER: - MessageUtils.setInvalidRequestParameterError(response); - break; - case NOT_FOUND: - MessageUtils.setUnknownError(response, "Event not found."); - break; - default: - MessageUtils.setUnknownError(response); - break; - } - } - return true; - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearServiceDiscoveryProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearServiceDiscoveryProfile.java deleted file mode 100644 index 7839a8c599..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearServiceDiscoveryProfile.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - HeartRateServiceDiscoveryProfile - Copyright (c) 2015 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.content.Intent; - -import org.deviceconnect.android.deviceplugin.wear.WearManager; -import org.deviceconnect.android.profile.ServiceDiscoveryProfile; -import org.deviceconnect.android.profile.api.DConnectApi; -import org.deviceconnect.android.profile.api.GetApi; -import org.deviceconnect.android.service.DConnectServiceProvider; - -/** - * Implement ServiceDiscoveryProfile. - * @author NTT DOCOMO, INC. - */ -public class WearServiceDiscoveryProfile extends ServiceDiscoveryProfile { - - - private final DConnectApi mServiceDiscoveryApi = new GetApi() { - @Override - public boolean onRequest(final Intent request, final Intent response) { - mWearManager.sendWearData(); - appendServiceList(response); - return true; - } - }; - private WearManager mWearManager; - /** - * コンストラクタ. - * @param provider プロファイルプロバイダ - */ - public WearServiceDiscoveryProfile(final WearManager manager, final DConnectServiceProvider provider) { - super(provider); - mWearManager = manager; - addApi(mServiceDiscoveryApi); - } - -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearSystemProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearSystemProfile.java deleted file mode 100755 index c4f4a5d12a..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearSystemProfile.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - WearSystemProfile.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; - -import org.deviceconnect.android.deviceplugin.wear.setting.WearServiceListActivity; -import org.deviceconnect.android.profile.SystemProfile; - -/** - * System Profile. - * - * @author NTT DOCOMO, INC. - */ -public class WearSystemProfile extends SystemProfile { - - @Override - protected Class getSettingPageActivity(final Intent request, final Bundle param) { - return WearServiceListActivity.class; - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearTouchProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearTouchProfile.java deleted file mode 100644 index 8ca2e3082f..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearTouchProfile.java +++ /dev/null @@ -1,897 +0,0 @@ -/* - WearTouchProfile.java - Copyright (c) 2015 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; - - -import org.deviceconnect.android.deviceplugin.wear.BuildConfig; -import org.deviceconnect.android.deviceplugin.wear.WearDeviceService; -import org.deviceconnect.android.deviceplugin.wear.WearManager; -import org.deviceconnect.android.deviceplugin.wear.WearManager.OnMessageEventListener; -import org.deviceconnect.android.deviceplugin.wear.WearManager.OnMessageResultListener; -import org.deviceconnect.android.event.Event; -import org.deviceconnect.android.event.EventError; -import org.deviceconnect.android.event.EventManager; -import org.deviceconnect.android.message.MessageUtils; -import org.deviceconnect.android.profile.TouchProfile; -import org.deviceconnect.android.profile.api.DConnectApi; -import org.deviceconnect.android.profile.api.DeleteApi; -import org.deviceconnect.android.profile.api.GetApi; -import org.deviceconnect.android.profile.api.PutApi; -import org.deviceconnect.message.DConnectMessage; -import org.deviceconnect.message.intent.message.IntentDConnectMessage; - -import java.util.ArrayList; -import java.util.List; - -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.ATTRIBUTE_ON_TOUCH_CHANGE; -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.STATE_CANCEL; -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.STATE_DOUBLE_TAP; -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.STATE_END; -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.STATE_MOVE; -import static org.deviceconnect.android.deviceplugin.wear.profile.WearConst.STATE_START; - -/** - * Touch Profile. - * - * @author NTT DOCOMO, INC. - */ -public class WearTouchProfile extends TouchProfile { - - /** Tag. */ - private static final String TAG = "WEAR"; - - /** Touch profile onTouch cache. */ - Bundle mOnTouchCache = null; - - /** Touch profile onTouch cache time. */ - long mOnTouchCacheTime = 0; - - /** Touch profile onTouchStart cache. */ - Bundle mOnTouchStartCache = null; - - /** Touch profile onTouchStart cache time. */ - long mOnTouchStartCacheTime = 0; - - /** Touch profile onTouchEnd cache. */ - Bundle mOnTouchEndCache = null; - - /** Touch profile onTouchEnd cache time. */ - long mOnTouchEndCacheTime = 0; - - /** Touch profile onDoubleTap cache. */ - Bundle mOnDoubleTapCache = null; - - /** Touch profile onDoubleTap cache time. */ - long mOnDoubleTapCacheTime = 0; - - /** Touch profile onTouchMove cache. */ - Bundle mOnTouchMoveCache = null; - - /** Touch profile onTouchMove cache time. */ - long mOnTouchMoveCacheTime = 0; - - /** Touch profile onTouchCancel cache. */ - Bundle mOnTouchCancelCache = null; - - /** Touch profile onTouchCancel cache time. */ - long mOnTouchCancelCacheTime = 0; - /** Touch profile onTouchChange cache. */ - Bundle mOnTouchChangeCache = null; - - /** Touch profile onTouchChange cache time. */ - long mOnTouchChangeCacheTime = 0; - /** Touch profile cache retention time (mSec). */ - static final long CACHE_RETENTION_TIME = 10000; - - /** - * Get Touch cache data. - * - * @param attr Attribute. - * @return Touch cache data. - */ - public Bundle getTouchCache(final String attr) { - long lCurrentTime = System.currentTimeMillis(); - if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH)) { - if (lCurrentTime - mOnTouchCacheTime <= CACHE_RETENTION_TIME) { - return mOnTouchCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_START)) { - if (lCurrentTime - mOnTouchStartCacheTime <= CACHE_RETENTION_TIME) { - return mOnTouchStartCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_END)) { - if (lCurrentTime - mOnTouchEndCacheTime <= CACHE_RETENTION_TIME) { - return mOnTouchEndCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_DOUBLE_TAP)) { - if (lCurrentTime - mOnDoubleTapCacheTime <= CACHE_RETENTION_TIME) { - return mOnDoubleTapCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_MOVE)) { - if (lCurrentTime - mOnTouchMoveCacheTime <= CACHE_RETENTION_TIME) { - return mOnTouchMoveCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_CANCEL)) { - if (lCurrentTime - mOnTouchCancelCacheTime <= CACHE_RETENTION_TIME) { - return mOnTouchCancelCache; - } else { - return null; - } - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_CHANGE)) { - if (lCurrentTime - mOnTouchChangeCacheTime <= CACHE_RETENTION_TIME) { - return mOnTouchChangeCache; - } else { - return null; - } - } else { - return null; - } - } - - /** - * Set Touch data to cache. - * - * @param attr Attribute. - * @param touchData Touch data. - */ - public void setTouchCache(final String attr, final Bundle touchData) { - long lCurrentTime = System.currentTimeMillis(); - if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH)) { - mOnTouchCache = touchData; - mOnTouchCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_START)) { - mOnTouchStartCache = touchData; - mOnTouchStartCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_END)) { - mOnTouchEndCache = touchData; - mOnTouchEndCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_DOUBLE_TAP)) { - mOnDoubleTapCache = touchData; - mOnDoubleTapCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_MOVE)) { - mOnTouchMoveCache = touchData; - mOnTouchMoveCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_CANCEL)) { - mOnTouchCancelCache = touchData; - mOnTouchCancelCacheTime = lCurrentTime; - } else if (attr.equalsIgnoreCase(ATTRIBUTE_ON_TOUCH_CHANGE)) { - mOnTouchChangeCache = touchData; - mOnTouchChangeCacheTime = lCurrentTime; - } - } - - /** - * Event receive listener from Android Wear. - */ - private OnMessageEventListener mListener = new OnMessageEventListener() { - @Override - public void onEvent(final String nodeId, final String message) { - sendMessageToEvent(WearUtils.createServiceId(nodeId), message); - } - }; - - /** - * Constructor. - * @param mgr Android Wear管理クラス - */ - public WearTouchProfile(final WearManager mgr) { - mgr.addMessageEventListener(WearConst.WEAR_TO_DEVICE_TOUCH_DATA, mListener); - addApi(mGetOnTouch); - addApi(mGetOnTouchStart); - addApi(mGetOnTouchEnd); - addApi(mGetOnDoubleTap); - addApi(mGetOnTouchMove); - addApi(mGetOnTouchCancel); - addApi(mGetOnTouchChange); - addApi(mPutOnTouch); - addApi(mPutOnTouchStart); - addApi(mPutOnTouchEnd); - addApi(mPutOnDoubleTap); - addApi(mPutOnTouchMove); - addApi(mPutOnTouchCancel); - addApi(mPutOnTouchChange); - addApi(mDeleteOnTouch); - addApi(mDeleteOnTouchStart); - addApi(mDeleteOnTouchEnd); - addApi(mDeleteOnDoubleTap); - addApi(mDeleteOnTouchMove); - addApi(mDeleteOnTouchCancel); - addApi(mDeleteOnTouchChange); - } - private final DConnectApi mGetOnTouchChange = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_CHANGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle touches = getTouchCache(ATTRIBUTE_ON_TOUCH_CHANGE); - if (touches == null) { - response.putExtra(TouchProfile.PARAM_TOUCH, ""); - } else { - response.putExtra(TouchProfile.PARAM_TOUCH, touches); - } - setResult(response, IntentDConnectMessage.RESULT_OK); - return true; - } - }; - private final DConnectApi mGetOnTouch = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle touches = getTouchCache(TouchProfile.ATTRIBUTE_ON_TOUCH); - if (touches == null) { - response.putExtra(TouchProfile.PARAM_TOUCH, ""); - } else { - response.putExtra(TouchProfile.PARAM_TOUCH, touches); - } - setResult(response, IntentDConnectMessage.RESULT_OK); - return true; - } - }; - - private final DConnectApi mGetOnTouchStart = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_START; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle touches = getTouchCache(TouchProfile.ATTRIBUTE_ON_TOUCH_START); - if (touches == null) { - response.putExtra(TouchProfile.PARAM_TOUCH, ""); - } else { - response.putExtra(TouchProfile.PARAM_TOUCH, touches); - } - setResult(response, IntentDConnectMessage.RESULT_OK); - return true; - } - }; - - private final DConnectApi mGetOnTouchEnd = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_END; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle touches = getTouchCache(TouchProfile.ATTRIBUTE_ON_TOUCH_END); - if (touches == null) { - response.putExtra(TouchProfile.PARAM_TOUCH, ""); - } else { - response.putExtra(TouchProfile.PARAM_TOUCH, touches); - } - setResult(response, IntentDConnectMessage.RESULT_OK); - return true; - } - }; - - private final DConnectApi mGetOnDoubleTap = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DOUBLE_TAP; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle touches = getTouchCache(TouchProfile.ATTRIBUTE_ON_DOUBLE_TAP); - if (touches == null) { - response.putExtra(TouchProfile.PARAM_TOUCH, ""); - } else { - response.putExtra(TouchProfile.PARAM_TOUCH, touches); - } - setResult(response, IntentDConnectMessage.RESULT_OK); - return true; - } - }; - - private final DConnectApi mGetOnTouchMove = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_MOVE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle touches = getTouchCache(TouchProfile.ATTRIBUTE_ON_TOUCH_MOVE); - if (touches == null) { - response.putExtra(TouchProfile.PARAM_TOUCH, ""); - } else { - response.putExtra(TouchProfile.PARAM_TOUCH, touches); - } - setResult(response, IntentDConnectMessage.RESULT_OK); - return true; - } - }; - - private final DConnectApi mGetOnTouchCancel = new GetApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_CANCEL; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - Bundle touches = getTouchCache(TouchProfile.ATTRIBUTE_ON_TOUCH_CANCEL); - if (touches == null) { - response.putExtra(TouchProfile.PARAM_TOUCH, ""); - } else { - response.putExtra(TouchProfile.PARAM_TOUCH, touches); - } - setResult(response, IntentDConnectMessage.RESULT_OK); - return true; - } - }; - private final DConnectApi mPutOnTouchChange = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_CHANGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - private final DConnectApi mPutOnTouch = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mPutOnTouchStart = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_START; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mPutOnTouchEnd = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_END; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mPutOnDoubleTap = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DOUBLE_TAP; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mPutOnTouchMove = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_MOVE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mPutOnTouchCancel = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_CANCEL; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - // Event registration. - EventError error = EventManager.INSTANCE.addEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - private final DConnectApi mDeleteOnTouchChange = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_CHANGE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - private final DConnectApi mDeleteOnTouch = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - private final DConnectApi mDeleteOnTouchStart = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_START; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - private final DConnectApi mDeleteOnTouchEnd = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_END; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - private final DConnectApi mDeleteOnDoubleTap = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_DOUBLE_TAP; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - private final DConnectApi mDeleteOnTouchMove = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_MOVE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - private final DConnectApi mDeleteOnTouchCancel = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_ON_TOUCH_CANCEL; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, - WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER, - "", new OnMessageResultListener() { - @Override - public void onResult() { - } - @Override - public void onError() { - } - }); - - // Event release. - EventError error = EventManager.INSTANCE.removeEvent(request); - if (error == EventError.NONE) { - setResult(response, DConnectMessage.RESULT_OK); - } else { - setResult(response, DConnectMessage.RESULT_ERROR); - } - return true; - } - }; - - /** - * Send a message to the registration event. - * - * @param nodeId node id - * @param data Received Strings. - */ - private void sendMessageToEvent(final String nodeId, final String data) { - if (BuildConfig.DEBUG) { - Log.i(TAG, "@@@@@@SUCCESS"); - } - - String[] mDataArray = data.split(",", 0); - String attr; - String action = mDataArray[1]; - String state = null; - if (action.equals(WearConst.PARAM_TOUCH_TOUCH)) { - attr = ATTRIBUTE_ON_TOUCH; - } else if (action.equals(WearConst.PARAM_TOUCH_TOUCHSTART)) { - attr = ATTRIBUTE_ON_TOUCH_START; - state = STATE_START; - } else if (action.equals(WearConst.PARAM_TOUCH_TOUCHEND)) { - attr = ATTRIBUTE_ON_TOUCH_END; - state = STATE_END; - } else if (action.equals(WearConst.PARAM_TOUCH_TOUCHMOVE)) { - attr = ATTRIBUTE_ON_TOUCH_MOVE; - state = STATE_MOVE; - } else if (action.equals(WearConst.PARAM_TOUCH_TOUCHCANCEL)) { - attr = ATTRIBUTE_ON_TOUCH_CANCEL; - state = STATE_CANCEL; - } else if (action.equals(WearConst.PARAM_TOUCH_DOUBLETAP)) { - attr = ATTRIBUTE_ON_DOUBLE_TAP; - state = STATE_DOUBLE_TAP; - } else { - attr = null; - state = null; - } - - if (BuildConfig.DEBUG) { - Log.i(TAG, "action: " + action + " attr: " + attr); - } - - if (attr != null) { - List events = EventManager.INSTANCE.getEventList( - nodeId, PROFILE_NAME, null, attr); - List commonEvents = EventManager.INSTANCE.getEventList( - nodeId, PROFILE_NAME, null, ATTRIBUTE_ON_TOUCH_CHANGE); - Bundle touchdata = new Bundle(); - List touchlist = new ArrayList(); - Bundle touches = new Bundle(); - int count = Integer.parseInt(mDataArray[0]); - int index = 2; - for (int n = 0; n < count; n++) { - touchdata.putInt(TouchProfile.PARAM_ID, Integer.parseInt(mDataArray[index++])); - touchdata.putFloat(TouchProfile.PARAM_X, Float.parseFloat(mDataArray[index++])); - touchdata.putFloat(TouchProfile.PARAM_Y, Float.parseFloat(mDataArray[index++])); - touchlist.add((Bundle) touchdata.clone()); - } - touches.putParcelableArray(TouchProfile.PARAM_TOUCHES, - touchlist.toArray(new Bundle[touchlist.size()])); - synchronized (events) { - for (Event event : events) { - String eventAttr = event.getAttribute(); - Intent intent = EventManager.createEventMessage(event); - intent.putExtra(TouchProfile.PARAM_TOUCH, touches); - ((WearDeviceService) getContext()).sendEvent(intent, event.getAccessToken()); - setTouchCache(eventAttr, touches); - if (BuildConfig.DEBUG) { - Log.i(TAG, "event: " + event); - Log.i(TAG, "touches: " + touches); - Log.i(TAG, "intent: " + intent); - } - } - } - synchronized (commonEvents) { - for (Event event : commonEvents) { - String eventAttr = event.getAttribute(); - Intent intent = EventManager.createEventMessage(event); - if (state != null) { - touches.putString("state", state); - } - intent.putExtra(TouchProfile.PARAM_TOUCH, touches); - ((WearDeviceService) getContext()).sendEvent(intent, event.getAccessToken()); - setTouchCache(eventAttr, touches); - if (BuildConfig.DEBUG) { - Log.i(TAG, "event: " + event); - Log.i(TAG, "touches: " + touches); - Log.i(TAG, "intent: " + intent); - } - } - } - } - } - - /** - * Get Android Wear management class. - * @return WearManager management class. - */ - private WearManager getManager() { - return ((WearDeviceService) getContext()).getManager(); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearUtils.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearUtils.java deleted file mode 100755 index 3489716539..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearUtils.java +++ /dev/null @@ -1,75 +0,0 @@ -/* -WearUtil.java -Copyright (c) 2014 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import org.deviceconnect.profile.CanvasProfileConstants.Mode; - - -/** - * Wear Utils. - * - * @author NTT DOCOMO, INC. - */ -public final class WearUtils { - - /** - * Constructor. - */ - private WearUtils() { - } - - /** - * Android Wearに渡す描画モードに変換する. - * @param mode モード - * @return 変換後のモード - */ - public static int convertMode(final Mode mode) { - int mm = WearConst.MODE_NORMAL; - if (Mode.SCALES.equals(mode)) { - mm = WearConst.MODE_SCALES; - } else if (Mode.FILLS.equals(mode)) { - mm = WearConst.MODE_FILLS; - } else { - mm = WearConst.MODE_NORMAL; - } - return mm; - } - - /** - * サービスIDを確認する. - * @param serviceId サービスID - * @return 問題ない場合にはtrue、それ以外はfalse - */ - public static boolean checkServiceId(final String serviceId) { - if (serviceId == null) { - return false; - } - return serviceId.startsWith(WearConst.SERVICE_ID); - } - - /** - * nodeIdからサービスIDを作成する. - * @param nodeId ノードID - * @return サービスID - */ - public static String createServiceId(final String nodeId) { - String[] id = nodeId.split("-"); - return WearConst.SERVICE_ID + "-" + id[0]; - } - - /** - * Get node form Service ID. - * - * @param serviceId Service ID. - * @return nodeId Internal management Node ID. - */ - public static String getNodeId(final String serviceId) { - String[] mServiceIdArray = serviceId.split("-"); - return mServiceIdArray[1]; - } - -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearVibrationProfile.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearVibrationProfile.java deleted file mode 100755 index 09d0494d6d..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/WearVibrationProfile.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - WearVibrationProfile.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - -import android.content.Intent; - - -import org.deviceconnect.android.deviceplugin.wear.WearDeviceService; -import org.deviceconnect.android.deviceplugin.wear.WearManager; -import org.deviceconnect.android.deviceplugin.wear.WearManager.OnMessageResultListener; -import org.deviceconnect.android.message.MessageUtils; -import org.deviceconnect.android.profile.VibrationProfile; -import org.deviceconnect.android.profile.api.DConnectApi; -import org.deviceconnect.android.profile.api.DeleteApi; -import org.deviceconnect.android.profile.api.PutApi; -import org.deviceconnect.message.DConnectMessage; - -/** - * Vibration Profile. - * - * @author NTT DOCOMO, INC. - */ -public class WearVibrationProfile extends VibrationProfile { - - public WearVibrationProfile() { - addApi(mPutVibrate); - addApi(mDeleteVibrate); - } - - private final DConnectApi mPutVibrate = new PutApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_VIBRATE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String pattern = getPattern(request); - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_VIBRATION_RUN, - convertPatternToString(parsePattern(pattern)), new OnMessageResultListener() { - @Override - public void onResult() { - setResult(response, DConnectMessage.RESULT_OK); - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - private final DConnectApi mDeleteVibrate = new DeleteApi() { - @Override - public String getAttribute() { - return ATTRIBUTE_VIBRATE; - } - - @Override - public boolean onRequest(final Intent request, final Intent response) { - String nodeId = WearUtils.getNodeId(getServiceID(request)); - getManager().sendMessageToWear(nodeId, WearConst.DEVICE_TO_WEAR_VIBRATION_DEL, - "", new OnMessageResultListener() { - @Override - public void onResult() { - setResult(response, DConnectMessage.RESULT_OK); - sendResponse(response); - } - @Override - public void onError() { - MessageUtils.setIllegalDeviceStateError(response); - sendResponse(response); - } - }); - return false; - } - }; - - /** - * バイブレーションのパターンを文字列に変換する. - * @param pattern パターン - * @return 文字列に変換されたパターン - */ - private String convertPatternToString(final long[] pattern) { - // Convert pattern in string. - String patternStr = ""; - for (int i = 0; i < pattern.length; i++) { - if (i == 0) { - patternStr += pattern[i]; - } else { - patternStr += "," + pattern[i]; - } - } - return patternStr; - } - - /** - * Android Wear管理クラスを取得する. - * @return WearManager管理クラス - */ - private WearManager getManager() { - return ((WearDeviceService) getContext()).getManager(); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/package-info.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/package-info.java deleted file mode 100755 index ddd2193b6e..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/profile/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - org.deviceconnect.android.deviceplugin.wear.profile - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ - -/** - * Profile of wear. - */ -package org.deviceconnect.android.deviceplugin.wear.profile; - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/service/WearService.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/service/WearService.java deleted file mode 100644 index 5b69fd7b4d..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/service/WearService.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.deviceconnect.android.deviceplugin.wear.service; - - -import com.google.android.gms.wearable.Node; - -import org.deviceconnect.android.deviceplugin.wear.WearManager; -import org.deviceconnect.android.deviceplugin.wear.profile.WearCanvasProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearConst; -import org.deviceconnect.android.deviceplugin.wear.profile.WearDeviceOrientationProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearKeyEventProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearNotificationProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearTouchProfile; -import org.deviceconnect.android.deviceplugin.wear.profile.WearUtils; -import org.deviceconnect.android.deviceplugin.wear.profile.WearVibrationProfile; -import org.deviceconnect.android.service.DConnectService; - -public class WearService extends DConnectService { - - private WearService(final String id) { - super(id); - } - - public static WearService getInstance(final Node node, final WearManager mgr) { - String nodeId = node.getId(); - String[] serviceId = nodeId.split("-"); - - WearService service = new WearService(WearUtils.createServiceId(nodeId)); - service.setName(WearConst.DEVICE_NAME + "(" + serviceId[0] + ")"); - service.setNetworkType(NetworkType.BLE); - service.addProfile(new WearCanvasProfile(mgr)); - service.addProfile(new WearDeviceOrientationProfile(mgr)); - service.addProfile(new WearKeyEventProfile(mgr)); - service.addProfile(new WearNotificationProfile()); - service.addProfile(new WearTouchProfile(mgr)); - service.addProfile(new WearVibrationProfile()); - return service; - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearServiceListActivity.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearServiceListActivity.java deleted file mode 100644 index d483c53f17..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearServiceListActivity.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.deviceconnect.android.deviceplugin.wear.setting; - - -import android.app.Activity; - -import org.deviceconnect.android.deviceplugin.wear.WearDeviceService; -import org.deviceconnect.android.message.DConnectMessageService; -import org.deviceconnect.android.ui.activity.DConnectServiceListActivity; - -public class WearServiceListActivity extends DConnectServiceListActivity { - - @Override - protected Class getMessageServiceClass() { - return WearDeviceService.class; - } - - @Override - protected Class getSettingManualActivityClass() { - return WearSettingActivity.class; - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearSettingActivity.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearSettingActivity.java deleted file mode 100755 index b80d12cf4d..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearSettingActivity.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - WearSettingActivity.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.setting; - -import org.deviceconnect.android.ui.activity.DConnectSettingPageFragmentActivity; - -import android.os.Bundle; -import androidx.fragment.app.Fragment; - -/** - * Setting Activity. - * - * @author NTT DOCOMO, INC. - */ -public class WearSettingActivity extends DConnectSettingPageFragmentActivity { - - /** Service ID. */ - private String mServiceId; - - /** Page count. */ - private static final int PAGE_COUNT = 1; - - @Override - public Fragment createPage(final int position) { - Bundle mBundle = new Bundle(); - mBundle.putInt("position", position); - WearSettingFragment mFragment = new WearSettingFragment(); - mFragment.setArguments(mBundle); - return mFragment; - } - - /** - * Get Service ID. - * - * @return Service ID. - */ - public String getServiceId() { - return mServiceId; - } - - /** - * Set Service ID. - * - * @param serviceId Service ID. - */ - public void setServiceId(final String serviceId) { - mServiceId = serviceId; - } - - @Override - public int getPageCount() { - return PAGE_COUNT; - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearSettingFragment.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearSettingFragment.java deleted file mode 100755 index 83020ba21e..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/WearSettingFragment.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - WearSettingFragment.java - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.setting; - -import org.deviceconnect.android.deviceplugin.wear.R; - -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import androidx.fragment.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.ImageView; - -/** - * Setting screen Fragment. - * - * @author NTT DOCOMO, INC. - */ -public class WearSettingFragment extends Fragment implements OnClickListener { - - /** ImageView. */ - private ImageView mImageView; - - @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, - final Bundle savedInstanceState) { - // Get position. - Bundle mBundle = getArguments(); - int mPagePosition = mBundle.getInt("position", 0); - - int mPageLayoutId = this.getResources().getIdentifier("wear_setting_" + mPagePosition, "layout", - getActivity().getPackageName()); - - View mView = inflater.inflate(mPageLayoutId, container, false); - - if (mPagePosition == 0) { - mImageView = (ImageView) mView.findViewById(R.id.dconnect_settings_googleplay); - mImageView.setOnClickListener(this); - } - - return mView; - } - - @Override - public void onClick(final View v) { - if (v.equals(mImageView)) { - Uri uri = Uri.parse("market://details?id=com.google.android.wearable.app"); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(intent); - } - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/package-info.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/package-info.java deleted file mode 100755 index 82bc8407a1..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/java/org/deviceconnect/android/deviceplugin/wear/setting/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - org.deviceconnect.android.deviceplugin.wear.setting - Copyright (c) 2014 NTT DOCOMO,INC. - Released under the MIT license - http://opensource.org/licenses/mit-license.php - */ - -/** - * Setting activity of wear. - */ -package org.deviceconnect.android.deviceplugin.wear.setting; diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-hdpi/ic_launcher.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100755 index bff79fd34e..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/ic_launcher.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100755 index 6c47374bb1..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_00_post_lollipop.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_00_post_lollipop.png deleted file mode 100755 index c1d9e6f6b2..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_00_post_lollipop.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_01_post_lollipop.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_01_post_lollipop.png deleted file mode 100755 index bb0d1a28b0..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_01_post_lollipop.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_02_post_lollipop.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_02_post_lollipop.png deleted file mode 100755 index 450adce54d..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_02_post_lollipop.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_03_post_lollipop.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_03_post_lollipop.png deleted file mode 100755 index 502584f909..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_03_post_lollipop.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_04_post_lollipop.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_04_post_lollipop.png deleted file mode 100755 index ffd8c43d12..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-mdpi/notification_04_post_lollipop.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/dconnect_icon.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/dconnect_icon.png deleted file mode 100755 index a3a7f4794e..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/dconnect_icon.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/g_play_img.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/g_play_img.png deleted file mode 100755 index 9a50affda3..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/g_play_img.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/ic_launcher.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100755 index d6e3e95912..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_00.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_00.png deleted file mode 100755 index dd070b70ac..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_00.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_01.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_01.png deleted file mode 100755 index cc47b8c960..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_01.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_02.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_02.png deleted file mode 100755 index 99ed78f4ee..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_02.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_03.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_03.png deleted file mode 100755 index 5f06303212..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_03.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_04.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_04.png deleted file mode 100755 index cca2e553fd..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xhdpi/notification_04.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100755 index dec0b850ae..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/layout/wear_setting_0.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/layout/wear_setting_0.xml deleted file mode 100755 index b7491b59eb..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/layout/wear_setting_0.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values-v11/styles.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values-v11/styles.xml deleted file mode 100755 index cc7b3128b5..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values-v11/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values-v14/styles.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values-v14/styles.xml deleted file mode 100755 index d581045ffc..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values-v14/styles.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values/strings.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values/strings.xml deleted file mode 100755 index 20d28b27f4..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - Android Wear (Device Connect Device Plug-in) - org.deviceconnect.android.intent.action.notifiy.androidwear - Device Connect AndroidWear Notification - DeviceConnectのAndroidWearプラグインの通知 - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values/styles.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values/styles.xml deleted file mode 100755 index c1d5d9d7ef..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/network_security_config.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/network_security_config.xml deleted file mode 100644 index dca93c079e..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/network_security_config.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/org_deviceconnect_android_deviceplugin_wear.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/org_deviceconnect_android_deviceplugin_wear.xml deleted file mode 100755 index 0a48048e41..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/org_deviceconnect_android_deviceplugin_wear.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - デバイス検索 - 周辺のデバイスを検索する - Network Service Discovery - Searches near devices. - - - デバイス情報 - デバイス情報を取得する - Service Information - Gets service information. - - - システム - システム情報を取得する - System - Obtains system information. - - - 通知 - 通知管理機能にアクセスする - Notification - Accesses notification feature. - - - キャンバス - キャンバスにアクセスする - Canvas - Accesses canvas feature. - - - - バイブレーション - バイブレーション機能にアクセスする - Vibrarion - Accesses vibrarion feature. - - - - 加速度 - 加速度機能にアクセスする - Device Orientation - Accesses device orientation. - - - - 通知 - 通知管理機能にアクセスする - Notification - Accesses notification feature. - - - - タッチ - タッチ状態を取得する - Touch - Touch event. - - - - キーイベント - キーイベント状態を取得する - KeyEvent - Key Event. - - - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/wear.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/wear.xml deleted file mode 100644 index cde84b0e58..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/wear.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - wear_deviceconnect - - \ No newline at end of file diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/wearable_app_desc.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/wearable_app_desc.xml deleted file mode 100755 index 3291cf8994..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/app/src/main/res/xml/wearable_app_desc.xml +++ /dev/null @@ -1,5 +0,0 @@ - - 1 - 2.0.0 - wearable_app - \ No newline at end of file diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/build.gradle b/dConnectDevicePlugin/dConnectDeviceAndroidWear/build.gradle deleted file mode 100644 index 087ed2dd61..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ - -buildscript { - repositories { - google() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.6.2' - } -} - -allprojects { - repositories { - jcenter() - google() - } -} - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle.properties b/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle.properties deleted file mode 100644 index 0d089abc76..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle.properties +++ /dev/null @@ -1,6 +0,0 @@ -storeFile=キーストアのファイル名 -storePassword=キーストアのパスワード -keyAlias=エイリアス名 -keyPassword=エイリアスのパスワード -android.useAndroidX=true -android.enableJetifier=true diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle/wrapper/gradle-wrapper.jar b/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 13372aef5e..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle/wrapper/gradle-wrapper.properties b/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index ee31d1c5a8..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Tue Apr 14 15:43:39 JST 2020 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradlew b/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradlew deleted file mode 100755 index 9d82f78915..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradlew +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradlew.bat b/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradlew.bat deleted file mode 100644 index aec99730b4..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/lint.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/lint.xml deleted file mode 100644 index 715caf3d22..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/lint.xml +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/proguard-project.txt b/dConnectDevicePlugin/dConnectDeviceAndroidWear/proguard-project.txt deleted file mode 100755 index f2fe1559a2..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/settings.gradle b/dConnectDevicePlugin/dConnectDeviceAndroidWear/settings.gradle deleted file mode 100644 index 078b083939..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':app', ':wear-app' diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/build.gradle b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/build.gradle deleted file mode 100755 index 22c0a2ebc4..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/build.gradle +++ /dev/null @@ -1,50 +0,0 @@ -apply plugin: 'com.android.application' - - -android { - compileSdkVersion 29 - defaultConfig { - applicationId "org.deviceconnect.android.deviceplugin.wear" - minSdkVersion 23 - targetSdkVersion 29 - versionCode 1 - versionName '2.0.0' - } - signingConfigs { - releaseConfig { - storeFile=file(project.properties.storeFile) - storePassword=project.properties.storePassword - keyAlias=project.properties.keyAlias - keyPassword=project.properties.keyPassword - } - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - signingConfig signingConfigs.releaseConfig - } - } - productFlavors { - } - tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' - } - lintOptions { - checkReleaseBuilds false - abortOnError false - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.wear:wear:1.0.0' - implementation 'com.google.android.support:wearable:2.5.0' - compileOnly 'com.google.android.wearable:wearable:2.5.0' - - implementation 'com.google.android.gms:play-services-wearable:17.0.0' -} \ No newline at end of file diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/proguard-rules.pro b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/proguard-rules.pro deleted file mode 100755 index 1c560ab8e2..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Applications/android-sdk/android-sdk-macosx/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/AndroidManifest.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/AndroidManifest.xml deleted file mode 100755 index 22de2d9b83..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/DataLayerListenerService.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/DataLayerListenerService.java deleted file mode 100755 index 4fb882c213..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/DataLayerListenerService.java +++ /dev/null @@ -1,247 +0,0 @@ -/* -DataLayerListenerService.java -Copyright (c) 2014 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear; - -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.os.Vibrator; -import android.util.Log; - -import com.google.android.gms.wearable.Asset; -import com.google.android.gms.wearable.DataEvent; -import com.google.android.gms.wearable.DataEventBuffer; -import com.google.android.gms.wearable.DataMap; -import com.google.android.gms.wearable.DataMapItem; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.WearableListenerService; - -import org.deviceconnect.android.deviceplugin.wear.activity.CanvasActivity; -import org.deviceconnect.android.deviceplugin.wear.activity.WearKeyEventProfileActivity; -import org.deviceconnect.android.deviceplugin.wear.activity.WearTouchProfileActivity; - -import java.util.List; - -/** - * DataLayerListenerService. - * - * @author NTT DOCOMO, INC. - */ -public class DataLayerListenerService extends WearableListenerService { - - @Override - public void onCreate() { - super.onCreate(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - } - - @Override - public void onDataChanged(final DataEventBuffer dataEvents) { - super.onDataChanged(dataEvents); - for (DataEvent event : dataEvents) { - Uri uri = event.getDataItem().getUri(); - if (event.getType() == DataEvent.TYPE_CHANGED - && uri.getPath().startsWith(WearConst.PATH_CANVAS)) { - - DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); - DataMap map = dataMapItem.getDataMap(); - List segments = uri.getPathSegments(); - - String selfId = ((WearApplication) getApplication()).getSelfId(); - String wearId = segments.get(2); - if (selfId == null || !selfId.equals(wearId)) { - //WearのIDが違っていれば無視 - return; - } - String nodeId = uri.getHost(); - String requestId = segments.get(3); - Asset profileAsset = map.getAsset(WearConst.PARAM_BITMAP); - int x = map.getInt(WearConst.PARAM_X); - int y = map.getInt(WearConst.PARAM_Y); - int mode = map.getInt(WearConst.PARAM_MODE); - Intent intent = new Intent(); - intent.setClass(this, CanvasActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(WearConst.PARAM_SOURCE_ID, nodeId); - intent.putExtra(WearConst.PARAM_REQUEST_ID, requestId); - intent.putExtra(WearConst.PARAM_BITMAP, profileAsset); - intent.putExtra(WearConst.PARAM_X, x); - intent.putExtra(WearConst.PARAM_Y, y); - intent.putExtra(WearConst.PARAM_MODE, mode); - startActivity(intent); - } - } - } - - private void startSensorService(String id) { - Intent intent = new Intent(); - intent.setAction(WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER); - intent.setClass(this, WearAppService.class); - intent.putExtra(WearConst.PARAM_SENSOR_ID, id); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } - } - - private void stopSensorService(String id) { - Intent intent = new Intent(); - intent.setAction(WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_UNREGISTER); - intent.setClass(this, WearAppService.class); - intent.putExtra(WearConst.PARAM_SENSOR_ID, id); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } - } - - @Override - public void onMessageReceived(final MessageEvent messageEvent) { - // get id of wear device - String id = messageEvent.getSourceNodeId(); - String action = messageEvent.getPath(); - if (action.equals(WearConst.DEVICE_TO_WEAR_VIBRATION_RUN)) { - startVibration(messageEvent); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_VIBRATION_DEL)) { - stopVibration(); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_CANCAS_DELETE_IMAGE)) { - deleteCanvas(); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER)) { - startSensorService(id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_UNREGISTER)) { - stopSensorService(id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER)) { - startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER)) { - startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER)) { - startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER)) { - startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER)) { - startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER)) { - startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER)) { - startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER, id); - } else if (action.equals(WearConst.DEVICE_TO_WEAR_SET_ID)) { - String wearId = new String(messageEvent.getData()); - ((WearApplication) getApplication()).setSelfId(wearId); - } else { - if (BuildConfig.DEBUG) { - Log.e("Wear", "unknown event:" + action); - } - } - } - - @Override - public void onPeerConnected(final Node peer) { - } - - @Override - public void onPeerDisconnected(final Node peer) { - } - - /** - * バイブレーションを開始する. - * @param messageEvent メッセージ - */ - private void startVibration(final MessageEvent messageEvent) { - // get vibration pattern - String mPattern = new String(messageEvent.getData()); - - // Make array of pattern - String[] mPatternArray = mPattern.split(",", 0); - long[] mPatternLong = new long[mPatternArray.length + 1]; - mPatternLong[0] = 0; - for (int i = 1; i < mPatternLong.length; i++) { - mPatternLong[i] = Integer.parseInt(mPatternArray[i - 1]); - } - - Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); - vibrator.vibrate(mPatternLong, -1); - } - - /** - * バイブレーションを停止する. - */ - private void stopVibration() { - Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); - // 停止のパターンの時にバイブレーションを止めようとした時にcancelが効かないため、 - // バイブレーションが停止している時は、一度バイブレーションを鳴らしたのちに停止を行う。 - vibrator.vibrate(new long[]{100}, -1); - vibrator.cancel(); - } - - /** - * Canvasの画面を削除する. - */ - private void deleteCanvas() { - Intent intent = new Intent(); - intent.setClass(this, CanvasActivity.class); - intent.setAction(WearConst.ACTION_DELETE_CANVAS); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); - } - - /** - * Execute Key Event Activity. - * - * @param regist Register string. - */ - private void startKeyEventActivity(final String regist, String id) { - Intent i = new Intent(this, WearKeyEventProfileActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.putExtra(WearConst.PARAM_KEYEVENT_REGIST, regist); - i.putExtra(WearConst.PARAM_KEYEVENT_ID, id); - startActivity(i); - } - - /** - * Execute Touch Activity. - * - * @param regist Register string. - */ - private void startTouchActivity(final String regist, String id) { - Intent i = new Intent(this, WearTouchProfileActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.putExtra(WearConst.PARAM_TOUCH_REGIST, regist); - i.putExtra(WearConst.PARAM_TOUCH_ID, id); - startActivity(i); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearAppService.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearAppService.java deleted file mode 100644 index b8b0691432..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearAppService.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.deviceconnect.android.deviceplugin.wear; - -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.Service; -import android.content.Intent; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.os.Build; -import android.os.IBinder; -import androidx.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class WearAppService extends Service implements SensorEventListener { - /** radian. */ - private static final double RAD2DEG = 180 / Math.PI; - - /** Device NodeID . */ - private final List mIds = Collections.synchronizedList(new ArrayList()); - - /** SensorManager. */ - private SensorManager mSensorManager; - - /** Gyro x. */ - private float mGyroX; - - /** Gyro y. */ - private float mGyroY; - - /** Gyro z. */ - private float mGyroZ; - - /** The start time for measuring the interval. */ - private long mStartTime; - - /** GyroSensor. */ - private Sensor mGyroSensor; - - /** AcceleratorSensor. */ - private Sensor mAccelerometer; - - /** - * スレッド管理用クラス. - */ - private final ExecutorService mExecutorService = Executors.newSingleThreadExecutor(); - - @Override - public void onCreate() { - super.onCreate(); - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (intent != null) { - String action = intent.getAction(); - String id = intent.getStringExtra(WearConst.PARAM_SENSOR_ID); - if (WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER.equals(action)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - registerSensor(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - NotificationManager manager = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE); - String channelId = getString(R.string.android_wear_data_layer_channel_id); - NotificationChannel channel = new NotificationChannel( - channelId, - getString(R.string.android_wear_data_layer_channel_title), - NotificationManager.IMPORTANCE_LOW); - channel.setDescription(getResources().getString(R.string.android_wear_data_layer_channel_desc)); - manager.createNotificationChannel(channel); - Notification.Builder builder = new Notification.Builder(this, channelId); - builder.setContentTitle(getString(R.string.android_wear_data_layer_channel_id)); - builder.setContentText(getString(R.string.android_wear_data_layer_channel_desc)); - builder.setWhen(System.currentTimeMillis()); - builder.setAutoCancel(false); - startForeground(1, builder.build()); - } - } else if (WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_UNREGISTER.equals(action)) { - mIds.remove(id); - if (mIds.isEmpty()) { - unregisterSensor(); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - stopForeground(true); - } - } - } - return super.onStartCommand(intent, flags, startId); - } - - @Override - public void onDestroy() { - mIds.clear(); - unregisterSensor(); - super.onDestroy(); - } - - @Override - public void onSensorChanged(final SensorEvent sensorEvent) { - if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { - long time = System.currentTimeMillis(); - long interval = time - mStartTime; - mStartTime = time; - - float accelX = sensorEvent.values[0]; - float accelY = sensorEvent.values[1]; - float accelZ = sensorEvent.values[2]; - final String data = accelX + "," + accelY + "," + accelZ - + "," + mGyroX + "," + mGyroY + "," + mGyroZ + "," + interval; - mExecutorService.execute(() -> { - synchronized (mIds) { - for (String id : mIds) { - sendSensorEvent(data, id); - } - } - }); - } else if (sensorEvent.sensor.getType() == Sensor.TYPE_GYROSCOPE) { - mGyroX = (float) (sensorEvent.values[0] * RAD2DEG); - mGyroY = (float) (sensorEvent.values[1] * RAD2DEG); - mGyroZ = (float) (sensorEvent.values[2] * RAD2DEG); - } - } - - @Override - public void onAccuracyChanged(final Sensor sensor, final int accuracy) { - } - - - /** - * センサーイベントをスマホ側に送信する. - * @param data 送信するデータ - * @param id 送信先のID - */ - private void sendSensorEvent(final String data, final String id) { - WearApplication application = getWearApplication(); - application.sendMessage(id, WearConst.WEAR_TO_DEVICE_DEIVCEORIENTATION_DATA, data); - } - - /** - * センサーを登録する. - */ - private synchronized void registerSensor() { - if (mSensorManager != null) { - return; - } - new Thread(() -> { - mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); - List accelSensors = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); - if (accelSensors.size() > 0) { - mAccelerometer = accelSensors.get(0); - mSensorManager.registerListener(WearAppService.this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); - } - - List gyroSensors = mSensorManager.getSensorList(Sensor.TYPE_GYROSCOPE); - if (gyroSensors.size() > 0) { - mGyroSensor = gyroSensors.get(0); - mSensorManager.registerListener(WearAppService.this, mGyroSensor, SensorManager.SENSOR_DELAY_NORMAL); - } - - mStartTime = System.currentTimeMillis(); - }).start(); - } - - /** - * センサーを解除する. - */ - private synchronized void unregisterSensor() { - if (mSensorManager != null) { - mSensorManager.unregisterListener(this, mAccelerometer); - mSensorManager.unregisterListener(this, mGyroSensor); - mSensorManager.unregisterListener(this); - mSensorManager = null; - } - } - - /** - * GoogleApiClientを取得する. - * @return GoogleApiClient - */ - private WearApplication getWearApplication() { - return ((WearApplication) getApplication()); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearApplication.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearApplication.java deleted file mode 100644 index 02c9f702f4..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearApplication.java +++ /dev/null @@ -1,93 +0,0 @@ -/* -DataLayerListenerService.java -Copyright (c) 2015 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear; - -import android.app.Application; -import androidx.annotation.NonNull; -import android.util.Log; - -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.OnSuccessListener; -import com.google.android.gms.tasks.Task; -import com.google.android.gms.wearable.Wearable; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * このアプリで共有するGoogleApiClientを保持するアプリケーションクラス. - */ -public class WearApplication extends Application { - - /** - * WearのID. - */ - private String mSelfId; - /** - * スレッド管理用クラス. - */ - private final ExecutorService mExecutorService = Executors.newSingleThreadExecutor(); - - @Override - public void onCreate() { - super.onCreate(); - } - - @Override - public void onTerminate() { - super.onTerminate(); - destroy(); - } - - /** - * WearのIDを設定する. - * @param self WearのID - */ - public synchronized void setSelfId(final String self) { - mSelfId = self; - } - - /** - * WearのIDを返す. - * @return WearのID - */ - public synchronized String getSelfId() { - return mSelfId; - } - - /** - * 後始末を行う. - */ - public synchronized void destroy() { - mExecutorService.shutdown(); - } - - /** - * Phone側にメッセージを送る. - * @param destinationId phone側のID - * @param path メッセージのパス - * @param data メッセージのデータ - */ - public void sendMessage(final String destinationId, final String path, final String data) { - mExecutorService.execute(() -> { - Task sendMessageTask = - Wearable.getMessageClient(getApplicationContext()) - .sendMessage(destinationId, path, data.getBytes()); - sendMessageTask.addOnSuccessListener((integer) -> { - if (BuildConfig.DEBUG) { - Log.d("WEAR", "Sent result:" + integer); - } - }); - - sendMessageTask.addOnFailureListener((e) -> { - if (BuildConfig.DEBUG) { - Log.e("WEAR", "Sent result:" + e.getLocalizedMessage()); - } - }); - }); - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearConst.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearConst.java deleted file mode 100755 index 11c8f0d9d1..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/WearConst.java +++ /dev/null @@ -1,272 +0,0 @@ -/* -WearConst.java -Copyright (c) 2014 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear; - -/** - * Wear Const. - * - * @author NTT DOCOMO, INC. - */ -public final class WearConst { - - /** Broadcast Intent Key. */ - public static final String ACTION_WEAR_PING_SERVICE = "org.deviceconnect.wear.ping.service"; - - /** Vibration start. */ - public static final String DEVICE_TO_WEAR_VIBRATION_RUN = "org.deviceconnect.wear.vibration.run"; - - /** Vibration stop. */ - public static final String DEVICE_TO_WEAR_VIBRATION_DEL = "org.deviceconnect.wear.vibration.del"; - - /** when DeviceOrientation register is opened. */ - public static final String DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER - = "org.deviceconnect.wear.deivceorienatation.regist"; - - /** When Canvas deleted. */ - public static final String DEVICE_TO_WEAR_CANCAS_DELETE_IMAGE - = "org.deviceconnect.wear.canvas.delete"; - - /** when DeviceOrientation unregister is opened. */ - public static final String DEVICE_TO_WEAR_DEIVCEORIENTATION_UNREGISTER - = "org.deviceconnect.wear.deivceorienatation.unregist"; - - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_DEIVCEORIENTATION_DATA = "org.deviceconnect.wear.deivceorienatation.data"; - - /** Register Key Event (ondown). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER - = "org.deviceconnect.wear.keyevent.ondown.regist"; - - /** Register Key Event (onup). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER = "org.deviceconnect.wear.keyevent.onup.regist"; - /** Register Key Event (onkeychange). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER - = "org.deviceconnect.wear.keyevent.onkeychange.regist"; - /** Remove Key Event (ondown). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER - = "org.deviceconnect.wear.keyevent.ondown.unregist"; - - /** Remove Key Event (onup). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER - = "org.deviceconnect.wear.keyevent.onup.unregist"; - /** Remove Key Event (onkeychange). */ - public static final String DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER - = "org.deviceconnect.wear.keyevent.onkeychange.unregist"; - /** Set wear id.. */ - public static final String DEVICE_TO_WEAR_SET_ID - = "org.deviceconnect.wear.id.set"; - - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_KEYEVENT_DATA = "org.deviceconnect.wear.keyevent.data"; - - /** Broadcast Intent Key. */ - public static final String PARAM_DC_WEAR_KEYEVENT_SVC_TO_ACT = "DC_WEAR_KEYEVENT_SVC_TO_ACT"; - - /** Broadcast Intent Key. */ - public static final String PARAM_DC_WEAR_KEYEVENT_ACT_TO_SVC = "DC_WEAR_KEYEVENT_ACT_TO_SVC"; - - /** Key Event (down). */ - public static final String PARAM_KEYEVENT_DOWN = "down"; - - /** Key Event (up). */ - public static final String PARAM_KEYEVENT_UP = "up"; - - /** Broadcast Data Key (Regist). */ - public static final String PARAM_KEYEVENT_REGIST = "keyeventRegist"; - - /** Broadcast Data Key (Regist). */ - public static final String PARAM_KEYEVENT_ID = "keyeventId"; - - /** Broadcast Data Key (Data). */ - public static final String PARAM_KEYEVENT_DATA = "data"; - - /** Key Type (Standard Keyboard). */ - public static final int KEYTYPE_STD_KEY = 0x00000000; - - /** Key Type (Media Control). */ - public static final int KEYTYPE_MEDIA_CTRL = 0x00000200; - - /** Key Type (Directional Pad / Button). */ - public static final int KEYTYPE_DPAD_BUTTON = 0x00000400; - - /** Key Type (User Define). */ - public static final int KEYTYPE_USER = 0x00000800; - - /** Register Touch (ontouch). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER - = "org.deviceconnect.wear.touch.ontouch.regist"; - - /** Register Touch (ontouchstart). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER - = "org.deviceconnect.wear.touch.ontouchstart.regist"; - - /** Register Touch (ontouchend). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER - = "org.deviceconnect.wear.touch.ontouchend.regist"; - - /** Register Touch (ondoubletap). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER - = "org.deviceconnect.wear.touch.ondoubletap.regist"; - - /** Register Touch (ontouchmove). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER - = "org.deviceconnect.wear.touch.ontouchmove.regist"; - - /** Register Touch (ontouchcancel). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER - = "org.deviceconnect.wear.touch.ontouchcancel.regist"; - /** Register Touch (ontouchchange). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER - = "org.deviceconnect.wear.touch.ontouchchange.regist"; - - /** Remove Touch (ontouch). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER - = "org.deviceconnect.wear.touch.ontouch.unregist"; - - /** Remove Touch (ontouchstart). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchstart.unregist"; - - /** Remove Touch (ontouchend). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchend.unregist"; - - /** Remove Touch (ondoubletap). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER - = "org.deviceconnect.wear.touch.ondoubletap.unregist"; - - /** Remove Touch (ontouchmove). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchmove.unregist"; - - /** Remove Touch (ontouchcancel). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchcancel.unregist"; - /** Remove Touch (ontouchchange). */ - public static final String DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_UNREGISTER - = "org.deviceconnect.wear.touch.ontouchchange.unregist"; - - /** Broadcast Data Key (Regist). */ - public static final String PARAM_TOUCH_REGIST = "touchRegist"; - - public static final String PARAM_TOUCH_ID = "touchId"; - - /** Broadcast Data Key (Data). */ - public static final String PARAM_TOUCH_DATA = "data"; - - /** Broadcast Intent Key. */ - public static final String PARAM_DC_WEAR_TOUCH_SVC_TO_ACT = "DC_WEAR_TOUCH_SVC_TO_ACT"; - - /** Broadcast Intent Key. */ - public static final String PARAM_DC_WEAR_TOUCH_ACT_TO_SVC = "DC_WEAR_TOUCH_ACT_TO_SVC"; - - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_TOUCH_DATA = "org.deviceconnect.wear.touch.data"; - - /** Touch (touch). */ - public static final String PARAM_TOUCH_TOUCH = "touch"; - - /** Touch (touchstart). */ - public static final String PARAM_TOUCH_TOUCHSTART = "touchstart"; - - /** Touch (touchend). */ - public static final String PARAM_TOUCH_TOUCHEND = "touchend"; - - /** Touch (doubletap). */ - public static final String PARAM_TOUCH_DOUBLETAP = "doubletap"; - - /** Touch (touchmove). */ - public static final String PARAM_TOUCH_TOUCHMOVE = "touchmove"; - - /** Touch (touchcancel). */ - public static final String PARAM_TOUCH_TOUCHCANCEL = "touchcancel"; - - /** - * Canvas Profile Action. - */ - public static final String ACTION_DELETE_CANVAS = "org.devcieconnect.wear.canvas.delete"; - - /** Broadcast Intent Key. */ - public static final String PARAM_DC_WEAR_CANVAS_ACT_TO_SVC = "DC_WEAR_CANVAS_ACT_TO_SVC"; - - /** Wear to Android. */ - public static final String WEAR_TO_DEVICE_CANVAS_RESULT = "org.deviceconnect.wear.canvas.result"; - - /** リクエストID. */ - public static final String PARAM_REQUEST_ID = "requestId"; - - /** データ変更イベントの送信元(Android端末)を特定するためのID. */ - public static final String PARAM_SOURCE_ID = "sourceId"; - - /** メッセージの送信先(Android端末)を特定するためのID. */ - public static final String PARAM_DESTINATION_ID = "destinationId"; - - public static final String PARAM_SENSOR_ID = "sensorId"; - - /** - * bitmapを受け渡しするためのキー. - */ - public static final String PARAM_RESULT = "result"; - - /** 成功. */ - public static final String RESULT_SUCCESS = "success"; - - /** エラー: ビットマップサイズが大きすぎる. */ - public static final String RESULT_ERROR_TOO_LARGE_BITMAP = "errorTooLargeBitmap"; - - /** エラー: Android端末との接続に失敗. */ - public static final String RESULT_ERROR_CONNECTION_FAILURE = "errorConnectionFailure"; - - /** エラー: サポートしていない画像形式. */ - public static final String RESULT_ERROR_NOT_SUPPORTED_FORMAT = "errorNotSupportedFormat"; - - /** - * bitmapを受け渡しするためのキー. - */ - public static final String PARAM_BITMAP = "bitmap"; - - /** - * x座標を受け渡しするためのキー. - */ - public static final String PARAM_X = "x"; - - /** - * y座標を受け渡しするためのキー. - */ - public static final String PARAM_Y = "y"; - - /** - * 描画モードを受け渡しするためのキー. - */ - public static final String PARAM_MODE = "mode"; - - /** - * 画像を送信するためのパスを定義する. - */ - public static final String PATH_CANVAS = "/canvas/profile"; - - /** - * 通常の描画モード. - */ - public static final int MODE_NORMAL = 0; - - /** - * 拡大の描画モード. - */ - public static final int MODE_SCALES = 1; - - /** - * リピート描画モード. - */ - public static final int MODE_FILLS = 2; - - /** - * Constructor. - */ - private WearConst() { - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/CanvasActivity.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/CanvasActivity.java deleted file mode 100644 index 94c32abc10..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/CanvasActivity.java +++ /dev/null @@ -1,292 +0,0 @@ -/* -DataLayerListenerService.java -Copyright (c) 2015NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.activity; - -import android.app.Activity; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.graphics.Shader; -import android.graphics.drawable.BitmapDrawable; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.PowerManager; -import androidx.wear.widget.BoxInsetLayout; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.FrameLayout; -import android.widget.ImageView; - -import com.google.android.gms.tasks.Task; -import com.google.android.gms.tasks.Tasks; -import com.google.android.gms.wearable.Asset; -import com.google.android.gms.wearable.DataClient; -import com.google.android.gms.wearable.Wearable; - -import org.deviceconnect.android.deviceplugin.wear.R; -import org.deviceconnect.android.deviceplugin.wear.WearApplication; -import org.deviceconnect.android.deviceplugin.wear.WearConst; - -import java.io.InputStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import static androidx.wear.widget.BoxInsetLayout.LayoutParams.BOX_ALL; - -/** - * Canvas. - */ -public class CanvasActivity extends Activity { - /** - * Defines the timeout. - */ - private static final int TIMEOUT_MS = 10000; - - /** - * ImageView. - */ - private ImageView mImageView; - - /** - * Wakelock. - */ - private PowerManager.WakeLock mWakeLock; - /** - * Canvas Layout. - */ - private FrameLayout mFrameLayout; - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); - mWakeLock = powerManager.newWakeLock((PowerManager.PARTIAL_WAKE_LOCK - | PowerManager.ACQUIRE_CAUSES_WAKEUP), "DeviceConnect:CanvasWakelockTag"); - - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - setContentView(R.layout.activity_canvas); - if (!mWakeLock.isHeld()) { - mWakeLock.acquire(); - } - mImageView = (ImageView) findViewById(R.id.canvas_image); - mImageView.setVisibility(View.INVISIBLE); - mFrameLayout = findViewById(R.id.canvas_frame); - - Intent intent = getIntent(); - if (intent != null) { - refreshImage(intent); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mWakeLock.release(); - } - - @Override - protected void onNewIntent(final Intent intent) { - super.onNewIntent(intent); - if (intent != null) { - refreshImage(intent); - } - } - - /** - * Refresh image. - * @param intent Intent - */ - private void refreshImage(final Intent intent) { - String action = intent.getAction(); - if (WearConst.ACTION_DELETE_CANVAS.equals(action)) { - finish(); - return; - } - - (new AsyncTask() { - @Override - protected LoadingResult doInBackground(Void... params) { - Asset asset = intent.getParcelableExtra(WearConst.PARAM_BITMAP); - return loadBitmapFromAsset(asset); - } - @Override - protected void onPostExecute(LoadingResult result) { - String sourceId = intent.getStringExtra(WearConst.PARAM_SOURCE_ID); - String requestId = intent.getStringExtra(WearConst.PARAM_REQUEST_ID); - sendResultToHost(sourceId, requestId, result.getResultCode()); - if (!result.isSuccess()) { - finish(); - return; - } - - Bitmap bitmap = result.getBitmap(); - if (bitmap == null) { - return; - } - - int x = intent.getIntExtra(WearConst.PARAM_X, 0); - int y = intent.getIntExtra(WearConst.PARAM_Y, 0); - int mode = intent.getIntExtra(WearConst.PARAM_MODE, 0); - setImageBitmap(bitmap, mode, x, y); - } - }).execute(); - } - - private void sendResultToHost(final String destinationId, final String requestId, final String resultCode) { - String data = requestId + "," + resultCode; - String path = WearConst.WEAR_TO_DEVICE_CANVAS_RESULT; - ((WearApplication) getApplication()).sendMessage(destinationId, path, data); - } - - /** - * Sets a bitmap to ImageView. - * @param bitmap bitmap - * @param mode mode - * @param x x - * @param y y - */ - private synchronized void setImageBitmap(final Bitmap bitmap, final int mode, final int x, final int y) { - switch (mode) { - default: - case WearConst.MODE_NORMAL: - Matrix matrix = new Matrix(); - matrix.postTranslate((float) x, (float) y); - mImageView.setImageBitmap(bitmap); - mImageView.setScaleType(ImageView.ScaleType.MATRIX); - mImageView.setImageMatrix(matrix); - mImageView.setVisibility(View.VISIBLE); - BoxInsetLayout.LayoutParams normalLayoutParam = new BoxInsetLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER, BOX_ALL); - mFrameLayout.setLayoutParams(normalLayoutParam); - break; - case WearConst.MODE_SCALES: - mImageView.setImageBitmap(bitmap); - mImageView.setScaleType(ImageView.ScaleType.FIT_START); - mImageView.setTranslationX(x); - mImageView.setTranslationY(y); - mImageView.setVisibility(View.VISIBLE); - BoxInsetLayout.LayoutParams scaleLayoutParam = new BoxInsetLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT, Gravity.LEFT | Gravity.TOP); - mFrameLayout.setLayoutParams(scaleLayoutParam); - break; - case WearConst.MODE_FILLS: - BitmapDrawable bd = new BitmapDrawable(getResources(), bitmap); - bd.setTileModeX(Shader.TileMode.REPEAT); - bd.setTileModeY(Shader.TileMode.REPEAT); - mImageView.setImageDrawable(bd); - mImageView.setScaleType(ImageView.ScaleType.FIT_XY); - mImageView.setTranslationX(x); - mImageView.setTranslationY(y); - mImageView.setVisibility(View.VISIBLE); - BoxInsetLayout.LayoutParams fillLayoutParam = new BoxInsetLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT, Gravity.LEFT | Gravity.TOP); - mFrameLayout.setLayoutParams(fillLayoutParam); - break; - } - } - - /** - * Load a bitmap from Asset. - * @param asset asset - * @return result of loading - */ - private LoadingResult loadBitmapFromAsset(final Asset asset) { - InputStream in = getInputStream(asset); - if (in == null) { - return LoadingResult.errorOnConnection(); - } - try { - Bitmap bitmap = BitmapFactory.decodeStream(in); - if (bitmap == null) { - return LoadingResult.errorNotSupportedFormat(); - } - return LoadingResult.success(bitmap); - } catch (OutOfMemoryError e) { - return LoadingResult.errorTooLargeBitmap(); - } - } - - /** - * Get an input stream from Asset. - * @param asset input stream of asset - * @return input stream, null on error - */ - private InputStream getInputStream(final Asset asset) { - if (asset == null) { - return null; - } - Task getFdForAssetResponseTask = - Wearable.getDataClient(getApplicationContext()).getFdForAsset(asset); - - InputStream assetInputStream = null; - try { - DataClient.GetFdForAssetResponse getFdForAssetResponse = null; - getFdForAssetResponse = Tasks.await(getFdForAssetResponseTask, TIMEOUT_MS, TimeUnit.MILLISECONDS); - assetInputStream = getFdForAssetResponse.getInputStream(); - } catch (TimeoutException exception) { - Log.e("WEAR", "Failed retrieving asset, Timeout failed: " + exception); - } catch (ExecutionException exception) { - Log.e("WEAR", "Failed retrieving asset, Task failed: " + exception); - } catch (InterruptedException exception) { - Log.e("WEAR", "Failed retrieving asset, interrupt occurred: " + exception); - } - return assetInputStream; - } - - - private static class LoadingResult { - private Bitmap mBitmap; - private String mResultCode; - - private LoadingResult() { - } - - public Bitmap getBitmap() { - return mBitmap; - } - - public String getResultCode() { - return mResultCode; - } - - public boolean isSuccess() { - return WearConst.RESULT_SUCCESS.equals(mResultCode); - } - - static LoadingResult success(final Bitmap bitmap) { - if (bitmap == null) { - throw new IllegalArgumentException(); - } - LoadingResult result = new LoadingResult(); - result.mResultCode = WearConst.RESULT_SUCCESS; - result.mBitmap = bitmap; - return result; - } - - static LoadingResult errorTooLargeBitmap() { - LoadingResult result = new LoadingResult(); - result.mResultCode = WearConst.RESULT_ERROR_TOO_LARGE_BITMAP; - return result; - } - - static LoadingResult errorOnConnection() { - LoadingResult result = new LoadingResult(); - result.mResultCode = WearConst.RESULT_ERROR_CONNECTION_FAILURE; - return result; - } - - static LoadingResult errorNotSupportedFormat() { - LoadingResult result = new LoadingResult(); - result.mResultCode = WearConst.RESULT_ERROR_NOT_SUPPORTED_FORMAT; - return result; - } - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/WearKeyEventProfileActivity.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/WearKeyEventProfileActivity.java deleted file mode 100644 index 7b7f62c1ba..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/WearKeyEventProfileActivity.java +++ /dev/null @@ -1,314 +0,0 @@ -/* -WearKeyEventProfileActivity.java -Copyright (c) 2015 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.activity; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.os.PowerManager; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; - -import android.view.MotionEvent; -import android.view.View; -import android.view.WindowManager; -import android.widget.Button; - -import org.deviceconnect.android.deviceplugin.wear.R; -import org.deviceconnect.android.deviceplugin.wear.WearApplication; -import org.deviceconnect.android.deviceplugin.wear.WearConst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * WearKeyEventProfileActivity. - * - * @author NTT DOCOMO, INC. - */ -public class WearKeyEventProfileActivity extends Activity { - /** Device NodeID . */ - private final List mIds = Collections.synchronizedList(new ArrayList()); - - /** Event flag. */ - private int mRegisterEvent = 0; - /** Event flag define (down). */ - private static final int REGIST_FLAG_KEYEVENT_DOWN = 0x01; - /** Event flag define (up). */ - private static final int REGIST_FLAG_KEYEVENT_UP = 0x02; - /** Event flag define (keyChange). */ - private static final int REGIST_FLAG_KEYEVENT_KEYCHANGE = 0x04; - /** Button define. */ - private Button mBtnKeyMode, mBtnCancel, mBtnOk; - /** Key mode. */ - private int mKeyMode = 0; - - /** Key mode count. */ - private static final int KM_MAX_CNT = 4; - /** Key mode (Standard Keyboard). */ - private static final int KM_STD_KEY = 0; - /** Key mode (Media Control). */ - private static final int KM_MEDIA_CTRL = 1; - /** Key mode (Direction PAd / Button ). */ - private static final int KM_DPAD_BUTTON = 2; - /** Key mode (User Define). */ - private static final int KM_USER = 3; - - /** Key Code define(cancel). */ - private static final int KEYCODE_CANCEL = 0; - /** Key Code define(ok). */ - private static final int KEYCODE_OK = 1; - - /** Configure (Standard Keyboard). */ - private static final String[] CONFIG_STD_KEY = - {"Cancel", "OK"}; - /** Configure (Media Control). */ - private static final String[] CONFIG_MEDIA_CTRL = - {"stop", "play"}; - /** Configure (Directional Pad). */ - private static final String[] CONFIG_DPAD = - {"up", "down"}; - /** Configure (User defined). */ - private static final String[] CONFIG_USER = - {"USER_CANCEL", "USER_OK"}; - - /** - * Wakelock. - */ - private PowerManager.WakeLock mWakeLock; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); - mWakeLock = powerManager.newWakeLock((PowerManager.PARTIAL_WAKE_LOCK - | PowerManager.ACQUIRE_CAUSES_WAKEUP), "DeviceConnect:KeyEvent"); - - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - if (!mWakeLock.isHeld()) { - mWakeLock.acquire(); - } - setRegisterEvent(getIntent()); - setContentView(R.layout.activity_wear_keyevent_profile); - - mBtnKeyMode = findViewById(R.id.button_key_mode); - mBtnKeyMode.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - // Update Key Mode. - mKeyMode++; - if (mKeyMode >= KM_MAX_CNT) { - mKeyMode = KM_STD_KEY; - } - - String keyMode; - switch (mKeyMode) { - case KM_MEDIA_CTRL: - keyMode = getString(R.string.key_mode_media_ctrl); - break; - case KM_DPAD_BUTTON: - keyMode = getString(R.string.key_mode_dpad_button); - break; - case KM_USER: - keyMode = getString(R.string.key_mode_user); - break; - case KM_STD_KEY: - default: - keyMode = getString(R.string.key_mode_std_key); - break; - } - mBtnKeyMode.setText(keyMode); - } - }); - - mBtnCancel = findViewById(R.id.button_cancel); - mBtnCancel.setOnTouchListener((view, event) -> { - int action = event.getAction(); - switch (action) { - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_UP: - sendMessageData(action, KEYCODE_CANCEL); - break; - default: - break; - } - return false; - }); - - mBtnOk = findViewById(R.id.button_ok); - mBtnOk.setOnTouchListener((view, event) -> { - int action = event.getAction(); - switch (action) { - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_UP: - sendMessageData(action, KEYCODE_OK); - break; - default: - break; - } - return false; - }); - Intent i = new Intent(WearConst.ACTION_WEAR_PING_SERVICE); - LocalBroadcastManager.getInstance(this).sendBroadcast(i); - } - - @Override - protected void onNewIntent(Intent intent) { - setRegisterEvent(intent); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mWakeLock.release(); - } - - /** - * Get Configure string. - * - * @param keyMode Key Mode. - * @param keyId Key ID. - * @return config Configure string. - */ - private String getConfig(final int keyMode, final int keyId) { - String config; - int nIndex; - switch (keyId) { - case KEYCODE_CANCEL: - nIndex = 0; - break; - case KEYCODE_OK: - nIndex = 1; - break; - default: - nIndex = -1; - break; - } - - if (nIndex != -1) { - switch (keyMode) { - case KM_MEDIA_CTRL: - config = CONFIG_MEDIA_CTRL[nIndex]; - break; - case KM_DPAD_BUTTON: - config = CONFIG_DPAD[nIndex]; - break; - case KM_USER: - config = CONFIG_USER[nIndex]; - break; - case KM_STD_KEY: - default: - config = CONFIG_STD_KEY[nIndex]; - break; - } - } else { - config = ""; - } - - return config; - } - - /** - * Send message data. - * - * @param action MotionEvent action. - * @param keyId Key ID. - */ - private void sendMessageData(final int action, final int keyId) { - int keycode = keyId; - String keyConfig = getConfig(mKeyMode, keycode); - String keyAction; - if (action == MotionEvent.ACTION_DOWN) { - if ((mRegisterEvent & REGIST_FLAG_KEYEVENT_KEYCHANGE) == 0 - && (mRegisterEvent & REGIST_FLAG_KEYEVENT_DOWN) == 0) { - return; - } - keyAction = WearConst.PARAM_KEYEVENT_DOWN; - } else { - if ((mRegisterEvent & REGIST_FLAG_KEYEVENT_KEYCHANGE) == 0 - && (mRegisterEvent & REGIST_FLAG_KEYEVENT_UP) == 0) { - return; - } - keyAction = WearConst.PARAM_KEYEVENT_UP; - } - - switch (mKeyMode) { - case KM_MEDIA_CTRL: - keycode += WearConst.KEYTYPE_MEDIA_CTRL; - break; - case KM_DPAD_BUTTON: - keycode += WearConst.KEYTYPE_DPAD_BUTTON; - break; - case KM_USER: - keycode += WearConst.KEYTYPE_USER; - break; - case KM_STD_KEY: - default: - keycode += WearConst.KEYTYPE_STD_KEY; - break; - } - - String data = keyAction + "," + String.valueOf(keycode) + "," + keyConfig; - sendEvent(WearConst.WEAR_TO_DEVICE_KEYEVENT_DATA, data); - } - - private void sendEvent(final String path, final String data) { - synchronized (mIds) { - for (String id : mIds) { - ((WearApplication) getApplication()).sendMessage(id, path, data); - } - } - } - - private void setRegisterEvent(Intent intent) { - String type = intent.getStringExtra(WearConst.PARAM_KEYEVENT_REGIST); - String id = intent.getStringExtra(WearConst.PARAM_KEYEVENT_ID); - setRegisterEvent(type, id); - } - - /** - * Set register event. - * - * @param regist Request event. - */ - private void setRegisterEvent(final String regist, final String id) { - if (WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_KEYEVENT_DOWN; - } else if (WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_KEYEVENT_UP; - } else if (WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_KEYEVENT_KEYCHANGE; - } else if (WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_KEYEVENT_DOWN); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_KEYEVENT_UP); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_KEYEVENT_KEYCHANGE); - if (mRegisterEvent == 0) { - finish(); - } - } - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/WearTouchProfileActivity.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/WearTouchProfileActivity.java deleted file mode 100644 index 122ddc736e..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/activity/WearTouchProfileActivity.java +++ /dev/null @@ -1,287 +0,0 @@ -/* -WearTouchProfileActivity.java -Copyright (c) 2015 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -package org.deviceconnect.android.deviceplugin.wear.activity; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.os.PowerManager; -import androidx.annotation.NonNull; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import android.view.GestureDetector; -import android.view.GestureDetector.SimpleOnGestureListener; -import android.view.MotionEvent; -import android.view.WindowManager; - -import org.deviceconnect.android.deviceplugin.wear.R; -import org.deviceconnect.android.deviceplugin.wear.WearApplication; -import org.deviceconnect.android.deviceplugin.wear.WearConst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * WearTouchProfileActivity. - * - * @author NTT DOCOMO, INC. - */ -public class WearTouchProfileActivity extends Activity { - - /** Gesture detector. */ - private GestureDetector mGestureDetector; - - /** Device NodeID . */ - private final List mIds = Collections.synchronizedList(new ArrayList()); - - /** - * Wakelock. - */ - private PowerManager.WakeLock mWakeLock; - - /** Event flag. */ - private int mRegisterEvent = 0; - /** Event flag define (touch). */ - private static final int REGIST_FLAG_TOUCH_TOUCH = 0x01; - /** Event flag define (touchstart). */ - private static final int REGIST_FLAG_TOUCH_TOUCHSTART = 0x02; - /** Event flag define (touchend). */ - private static final int REGIST_FLAG_TOUCH_TOUCHEND = 0x04; - /** Event flag define (doubletap). */ - private static final int REGIST_FLAG_TOUCH_DOUBLETAP = 0x08; - /** Event flag define (touchmove). */ - private static final int REGIST_FLAG_TOUCH_TOUCHMOVE = 0x10; - /** Event flag define (touchcancel). */ - private static final int REGIST_FLAG_TOUCH_TOUCHCANCEL = 0x20; - /** Touch profile event flag. (ontouchchange). */ - private static final int REGIST_FLAG_TOUCH_TOUCHCHANGE = 0x0040; - /** - * Constructor. - */ - public WearTouchProfileActivity() { - } - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); - mWakeLock = powerManager.newWakeLock((PowerManager.PARTIAL_WAKE_LOCK - | PowerManager.ACQUIRE_CAUSES_WAKEUP), "DeviceConnect:TouchWakelockTag"); - - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - if (!mWakeLock.isHeld()) { - mWakeLock.acquire(); - } - - // Get intent data. - setRegisterEvent(getIntent()); - setContentView(R.layout.activity_wear_touch_profile); - mGestureDetector = new GestureDetector(this, mSimpleOnGestureListener); - - // For service destruction suppression. - Intent i = new Intent(WearConst.ACTION_WEAR_PING_SERVICE); - LocalBroadcastManager.getInstance(this).sendBroadcast(i); - } - - @Override - protected void onNewIntent(Intent intent) { - setRegisterEvent(intent); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mWakeLock.release(); - } - - @Override - public boolean dispatchTouchEvent(@NonNull final MotionEvent event) { - boolean execFlag = false; - int action = (event.getAction() & MotionEvent.ACTION_MASK); - String strAction = null; - switch (action) { - case MotionEvent.ACTION_DOWN: // 1st touch only. - case MotionEvent.ACTION_POINTER_DOWN: // Others touch. - // "ontouch" event processing. - if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCH) != 0) { - sendEventData(WearConst.PARAM_TOUCH_TOUCH, event); - } - - // "ontouchstart" event processing. - if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0 - || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHSTART) != 0) { - strAction = WearConst.PARAM_TOUCH_TOUCHSTART; - execFlag = true; - } - break; - case MotionEvent.ACTION_UP: // Last touch remove only. - case MotionEvent.ACTION_POINTER_UP: // Others touch move. - // "ontouchend" event processing. - if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0 - || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHEND) != 0) { - strAction = WearConst.PARAM_TOUCH_TOUCHEND; - execFlag = true; - } - break; - case MotionEvent.ACTION_MOVE: - // "ontouchmove" event processing. - if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0 - || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHMOVE) != 0) { - strAction = WearConst.PARAM_TOUCH_TOUCHMOVE; - execFlag = true; - } - break; - case MotionEvent.ACTION_CANCEL: - // "ontouchcancel" event processing. - if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0 - || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCANCEL) != 0) { - strAction = WearConst.PARAM_TOUCH_TOUCHCANCEL; - execFlag = true; - } - break; - default: - return mGestureDetector.onTouchEvent(event); - } - - if (execFlag) { - sendEventData(strAction, event); - } - return mGestureDetector.onTouchEvent(event) || super.dispatchTouchEvent(event); - } - - /** - * Gesture Listener. - */ - private final SimpleOnGestureListener mSimpleOnGestureListener = new SimpleOnGestureListener() { - @Override - public boolean onDoubleTap(final MotionEvent event) { - if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0 - || (mRegisterEvent & REGIST_FLAG_TOUCH_DOUBLETAP) != 0) { - sendEventData(WearConst.PARAM_TOUCH_DOUBLETAP, event); - } - return super.onDoubleTap(event); - } - }; - - /** - * Send event data. - * - * @param action Action. - * @param event MotionEvent. - */ - private void sendEventData(final String action, final MotionEvent event) { - int dataCount = event.getPointerCount(); - StringBuilder data = new StringBuilder(String.valueOf(dataCount)); - data.append(",").append(action); - for (int n = 0; n < dataCount; n++) { - int pointerId = event.getPointerId(n); - data.append(",").append(pointerId).append(",").append(event.getX(n)).append(",").append(event.getY(n)); - } - - sendEvent(WearConst.WEAR_TO_DEVICE_TOUCH_DATA, data.toString()); - } - - private void sendEvent(final String path, final String data) { - synchronized (mIds) { - for (String id : mIds) { - ((WearApplication) getApplication()).sendMessage(id, path, data); - } - } - } - - private void setRegisterEvent(Intent intent) { - String type = intent.getStringExtra(WearConst.PARAM_TOUCH_REGIST); - String id = intent.getStringExtra(WearConst.PARAM_TOUCH_ID); - setRegisterEvent(type, id); - } - - /** - * Set register event. - * - * @param regist Request event. - */ - private void setRegisterEvent(final String regist, String id) { - if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_TOUCH_TOUCH; - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_TOUCH_TOUCHSTART; - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_TOUCH_TOUCHEND; - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_TOUCH_DOUBLETAP; - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_TOUCH_TOUCHMOVE; - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_TOUCH_TOUCHCANCEL; - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER.equals(regist)) { - if (!mIds.contains(id)) { - mIds.add(id); - } - mRegisterEvent |= REGIST_FLAG_TOUCH_TOUCHCHANGE; - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_TOUCH_TOUCH); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_TOUCH_TOUCHSTART); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_TOUCH_TOUCHEND); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_TOUCH_DOUBLETAP); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_TOUCH_TOUCHMOVE); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_TOUCH_TOUCHCANCEL); - if (mRegisterEvent == 0) { - finish(); - } - } else if (WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_UNREGISTER.equals(regist)) { - mIds.remove(id); - mRegisterEvent &= ~(REGIST_FLAG_TOUCH_TOUCHCHANGE); - if (mRegisterEvent == 0) { - finish(); - } - } - } -} diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/package-info.java b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/package-info.java deleted file mode 100644 index eb89e6a5bd..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/java/org/deviceconnect/android/deviceplugin/wear/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/* -org.deviceconnect.android.deviceplugin.wear -Copyright (c) 2014 NTT DOCOMO,INC. -Released under the MIT license -http://opensource.org/licenses/mit-license.php - */ -/** - * Android Wear Device Plug-in package. - * @author NTT DOCOMO, INC. - */ -package org.deviceconnect.android.deviceplugin.wear; diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/res/drawable-xhdpi/dconnect_icon.png b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/res/drawable-xhdpi/dconnect_icon.png deleted file mode 100755 index a3a7f4794e..0000000000 Binary files a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/res/drawable-xhdpi/dconnect_icon.png and /dev/null differ diff --git a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/res/layout-notround/activity_wear_keyevent_profile.xml b/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/res/layout-notround/activity_wear_keyevent_profile.xml deleted file mode 100644 index 24f4eee90d..0000000000 --- a/dConnectDevicePlugin/dConnectDeviceAndroidWear/wear-app/src/main/res/layout-notround/activity_wear_keyevent_profile.xml +++ /dev/null @@ -1,36 +0,0 @@ - - -