Skip to content

Commit

Permalink
Merge pull request #4 from Acegugu/develop
Browse files Browse the repository at this point in the history
RowIRSender를 구현한 내용에 대한 PR
  • Loading branch information
acious committed Oct 30, 2015
2 parents 493b205 + 7b20ecc commit b2b14f3
Show file tree
Hide file tree
Showing 18 changed files with 478 additions and 18 deletions.
1 change: 1 addition & 0 deletions RowClient/mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gdgssu.rowclient;

import android.content.Context;

public class ControlSendingThread implements Runnable {

private Context mContext;

public ControlSendingThread(Context mContext) {
this.mContext = mContext;
}

@Override
public void run() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public void onLayoutInflated(WatchViewStub stub) {
mTextView = (TextView) stub.findViewById(R.id.text);
}
});

new Thread(new ControlSendingThread(getApplicationContext())).start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gdgssu.rowclient;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;

public class RowClientReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {

} else {
throw new UnsupportedOperationException("Not yet implemented");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.gdgssu.rowclient;

import android.content.Context;

public class StateSyncThread extends Thread {

/**
* IRSender 애플리케이션과 소켓으로 연결하여 현재 가정에서 컨트롤할 디바이스의 종류를 받아와야한다
* 만약 30초동안 찾지 못한다면 본 Thread는 종료된다
*/

private int foundDeviceSecond = 0;
private Context mContext;

public StateSyncThread(Context mContext) {
this.mContext = mContext;
}

@Override
public void run() {
while(true){
try {

//Todo : 소켓을 IRSender측으로 보내는 로직 작성

Thread.sleep(1000);
foundDeviceSecond++;
} catch (InterruptedException e) {
e.printStackTrace();
}

if (foundDeviceSecond==30){
break;
}
}
}
}
3 changes: 2 additions & 1 deletion RowIRSender/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.gdgssu.rowirsender"
Expand All @@ -24,4 +24,5 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile files('libs/qremote.jar')
compile 'com.google.code.gson:gson:2.3'
}
18 changes: 17 additions & 1 deletion RowIRSender/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gdgssu.rowirsender" >

<uses-permission-sdk-23 android:name="android.permission.INTERNET" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission-sdk-23 android:name="android.permission.CHANGE_WIFI_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<receiver
android:name=".RowIRReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="gdgssu.com.rowirsender.getaction" />
</intent-filter>
</receiver>

<service android:name=".RowIRService" />

<activity android:name=".SettingActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.gdgssu.rowirsender;

import android.util.Log;

import com.lge.hardware.IRBlaster.Device;
import com.lge.hardware.IRBlaster.IRFunction;

import java.util.List;

public class DeviceControlInfo {

/**
* 웨어러블로부터 전송받은 데이터를 파싱하며, 일시적으로 인스턴스를 통해 저장하여 활용하는 모델 클래스입니다
*/
private final static String TAG = DeviceControlInfo.class.getSimpleName();

public int deviceId;
public String functionName;
public String deviceName;

public int getDeviceId() {
return deviceId;
}

public void setDeviceId(int deviceId) {
this.deviceId = deviceId;
}

public String getFunctionName() {
return functionName;
}

public void setFunctionName(String functionName) {
this.functionName = functionName;
}

public String getDeviceName() {
return deviceName;
}

public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}

/**
* String 형태의 funcLabel을 int형태의 Keycode로 변환합니다
* @param deviceList
* @param funcLabel
* @return function id
*/
public int getFunctionKeyCode(List<Device> deviceList, String funcLabel) {

if (deviceList.size() == 0) {
Log.e(TAG, "A device is not selected.");
return -1;
}
for (Device device : deviceList){
for (IRFunction function : device.KeyFunctions) {
if (function.Name.equalsIgnoreCase(funcLabel)) {
return function.Id;
}
}
}
Log.e(TAG, "[" + funcLabel + "] search function failed");

return -1;
}

// An example to use IR function labels.[E]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gdgssu.rowirsender;

import com.google.gson.Gson;

public class DeviceInfoParser {

/**
* 소켓을 통해서 전송된 json형태의 데이터를 파싱하는 클래스입니다
* @param jsonData
* @return DeviceControlInfo
*/

public static DeviceControlInfo parsedInfo(String jsonData){

Gson gson = new Gson();
return gson.fromJson(jsonData, DeviceControlInfo.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.gdgssu.rowirsender;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.lge.hardware.IRBlaster.Device;

import java.util.Arrays;
import java.util.List;

/**
* 유저가 컨트롤할 Device(AIRCON, TV, STB, DVD 등)을 저장하고 저장된 내용을 가져오는 PrefenceHelper 클래스
* mIR.getDevices()를 이용해 애플리케이션을 완전히 종료하고 다시 실행해도 디바이스 목록을 가져올수있다면 이 클래스는 효용성이 없습니다
*/

public class DevicePreferenceHelper {
private final static String PREF_NAME = "com.gdgssu.rowirsender.devicepref";
public final static String PREF_DEVICE_STORE = "PREF_DEVICE_STORE";

private Context mContext;

public DevicePreferenceHelper(Context mContext) {
this.mContext = mContext;
}

public void setDevicePref(String key, List<Device> deviceList){
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();

Gson gson = new Gson();
String devicesJsonData = gson.toJson(deviceList);

editor.putString(key, devicesJsonData);
editor.apply();
}

public List<Device> getDevicePref(String key){
List<Device> deviceList;
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);

if (pref.contains(PREF_DEVICE_STORE)){
String devicesJsonData = pref.getString(key, null);
Gson gson = new Gson();
Device[] deviceArray = gson.fromJson(devicesJsonData, Device[].class);
deviceList = Arrays.asList(deviceArray);
}else{
return null;
}

return deviceList;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gdgssu.rowirsender;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class RowIRReceiver extends BroadcastReceiver {

/**
* 스마트폰이 부팅되자마자 RowIRService를 구동하게끔하는 기능을 담당하는 Receiver입니다
* @param context
* @param intent
*/

@Override
public void onReceive(Context context, Intent intent) {

if (intent.getAction().equals("gdgssu.com.rowirsender.getaction")){
context.startService(new Intent(context, RowIRService.class));
}else{
throw new UnsupportedOperationException("Not yet implemented");
}
}
}
Loading

0 comments on commit b2b14f3

Please sign in to comment.