Permalink
Browse files

Initial

  • Loading branch information...
morfeusys committed Feb 2, 2016
0 parents commit 47c915f50e2c43d3e5c28da309f6ec595e7ef836
Showing with 2,374 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +1 −0 app/.gitignore
  3. +28 −0 app/build.gradle
  4. BIN app/libs/BLNetwork.jar
  5. +17 −0 app/proguard-rules.pro
  6. +13 −0 app/src/androidTest/java/com/broadlink/control/ApplicationTest.java
  7. +42 −0 app/src/main/AndroidManifest.xml
  8. +22 −0 app/src/main/java/com/broadlink/control/BroadlinkReceiver.java
  9. +89 −0 app/src/main/java/com/broadlink/control/BroadlinkUtil.java
  10. +104 −0 app/src/main/java/com/broadlink/control/ButtonsActivity.java
  11. +208 −0 app/src/main/java/com/broadlink/control/ButtonsFragment.java
  12. +184 −0 app/src/main/java/com/broadlink/control/DbHelper.java
  13. +119 −0 app/src/main/java/com/broadlink/control/FunctionsFragment.java
  14. +160 −0 app/src/main/java/com/broadlink/control/MainActivity.java
  15. +468 −0 app/src/main/java/com/broadlink/control/api/BroadlinkAPI.java
  16. +111 −0 app/src/main/java/com/broadlink/control/api/BroadlinkConstants.java
  17. +176 −0 app/src/main/java/com/broadlink/control/api/DeviceInfo.java
  18. +56 −0 app/src/main/java/com/broadlink/control/api/JsonDevice.java
  19. +51 −0 app/src/main/java/com/broadlink/control/model/Code.java
  20. +27 −0 app/src/main/java/com/broadlink/control/model/Function.java
  21. +27 −0 app/src/main/java/com/broadlink/control/model/FunctionButton.java
  22. BIN app/src/main/jniLibs/armeabi-v7a/libBLNetwork.so
  23. BIN app/src/main/jniLibs/armeabi/libBLNetwork.so
  24. BIN app/src/main/res/drawable-hdpi/ic_add_white_36dp.png
  25. BIN app/src/main/res/drawable-hdpi/ic_mic_white_24dp.png
  26. BIN app/src/main/res/drawable-xhdpi/ic_add_white_36dp.png
  27. BIN app/src/main/res/drawable-xhdpi/ic_mic_white_24dp.png
  28. +9 −0 app/src/main/res/layout/activity_buttons.xml
  29. +51 −0 app/src/main/res/layout/activity_main.xml
  30. +16 −0 app/src/main/res/layout/fragment_main.xml
  31. +5 −0 app/src/main/res/menu/menu_context.xml
  32. +6 −0 app/src/main/res/menu/menu_function.xml
  33. +9 −0 app/src/main/res/menu/menu_main.xml
  34. BIN app/src/main/res/mipmap-hdpi/ic_launcher.png
  35. BIN app/src/main/res/mipmap-mdpi/ic_launcher.png
  36. BIN app/src/main/res/mipmap-xhdpi/ic_launcher.png
  37. BIN app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  38. +8 −0 app/src/main/res/values-v21/styles.xml
  39. +6 −0 app/src/main/res/values-w820dp/dimens.xml
  40. +6 −0 app/src/main/res/values/colors.xml
  41. +7 −0 app/src/main/res/values/dimens.xml
  42. +7 −0 app/src/main/res/values/strings.xml
  43. +17 −0 app/src/main/res/values/styles.xml
  44. +15 −0 app/src/test/java/com/broadlink/control/ExampleUnitTest.java
  45. +23 −0 build.gradle
  46. +18 −0 gradle.properties
  47. BIN gradle/wrapper/gradle-wrapper.jar
  48. +6 −0 gradle/wrapper/gradle-wrapper.properties
  49. +164 −0 gradlew
  50. +90 −0 gradlew.bat
  51. +1 −0 settings.gradle
@@ -0,0 +1,7 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
@@ -0,0 +1 @@
/build
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.broadlink.control"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.code.gson:gson:2.3'
}
Binary file not shown.
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/morfeusys/Library/Android/sdk/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 *;
#}
@@ -0,0 +1,13 @@
package com.broadlink.control;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.broadlink.control" >
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<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"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ButtonsActivity"/>
<receiver android:name=".BroadlinkReceiver">
<intent-filter>
<action android:name="com.broadlink.control.action.QUERY"/>
<action android:name="com.broadlink.control.action.BUTTON"/>
</intent-filter>
</receiver>
</application>
</manifest>
@@ -0,0 +1,22 @@
package com.broadlink.control;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* Created by morfeusys on 01.02.16.
*/
public class BroadlinkReceiver extends BroadcastReceiver {
public static final String EXTRA_TEXT = "text";
@Override
public void onReceive(Context context, Intent intent) {
String text = intent.getStringExtra(EXTRA_TEXT);
if ("com.broadlink.control.action.QUERY".equals(intent.getAction())) {
BroadlinkUtil.processFunction(context, text);
} else {
BroadlinkUtil.processButton(context, text);
}
}
}
@@ -0,0 +1,89 @@
package com.broadlink.control;
import android.content.Context;
import com.broadlink.control.api.BroadlinkAPI;
import com.broadlink.control.api.DeviceInfo;
import com.broadlink.control.model.Code;
import com.broadlink.control.model.Function;
import com.broadlink.control.model.FunctionButton;
import java.util.ArrayList;
import java.util.List;
/**
* Created by morfeusys on 01.02.16.
*/
public class BroadlinkUtil {
public static void processFunction(Context context, long id) {
DbHelper helper = new DbHelper(context);
List<FunctionButton> list = helper.getButtons(id);
helper.close();
List<Code> codes = new ArrayList<>();
for (FunctionButton button : list) codes.add(button.getCode());
process(context, codes);
}
public static void processFunction(Context context, String query) {
if (query == null || query.isEmpty()) return;
DbHelper helper = new DbHelper(context);
List<Function> list = helper.queryFunctions(query);
List<Code> codes = new ArrayList<>();
for (Function function : list) {
List<FunctionButton> buttons = helper.getButtons(function.getId());
for (FunctionButton button : buttons) codes.add(button.getCode());
}
helper.close();
process(context, codes);
}
public static void processButton(Context context, String query) {
if (query == null || query.isEmpty()) return;
DbHelper helper = new DbHelper(context);
List<Code> list = helper.queryCodes(query);
helper.close();
process(context, list);
}
private static void process(final Context context, final List<Code> list) {
new Thread(new Runnable() {
@Override
public void run() {
BroadlinkAPI api = initAPI(context);
for (int i = 0; i < list.size(); i++) {
try {
if (i > 0) Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Code code = list.get(i);
if (code.isRm1()) {
api.RM1Send(code.getMac(), code.getData());
} else {
api.RM2Send(code.getMac(), code.getData());
}
}
}
}
}).start();
}
private static BroadlinkAPI initAPI(Context context) {
BroadlinkAPI api = BroadlinkAPI.getInstance(context);
ArrayList<DeviceInfo> devices = api.getProbeList();
if (devices == null) {
api.broadlinkInitNetwork();
try {
Thread.sleep(300);
devices = api.getProbeList();
if (devices != null) {
for (DeviceInfo info : devices) api.addDevice(info);
}
Thread.sleep(200);
} catch (InterruptedException e) {
}
}
return api;
}
}
@@ -0,0 +1,104 @@
package com.broadlink.control;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.broadlink.control.model.Code;
import com.broadlink.control.model.Function;
import com.broadlink.control.model.FunctionButton;
import java.util.List;
/**
* Created by morfeusys on 01.02.16.
*/
public class ButtonsActivity extends AppCompatActivity {
public static final String FUNCTION_ID = "id";
private DbHelper mDbHelper;
private ArrayAdapter<FunctionButton> mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buttons);
long fid = getIntent().getLongExtra(FUNCTION_ID, 0);
mDbHelper = new DbHelper(this);
Function function = mDbHelper.getFunction(fid);
setTitle(function.getName());
ListView listView = (ListView) findViewById(R.id.list);
List<FunctionButton> list = mDbHelper.getButtons(fid);
mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list);
listView.setAdapter(mAdapter);
registerForContextMenu(listView);
}
@Override
protected void onDestroy() {
super.onDestroy();
mDbHelper.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_add) {
addButton();
}
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
getMenuInflater().inflate(R.menu.menu_context, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
FunctionButton button = mAdapter.getItem(position);
if (item.getItemId() == R.id.remove) {
mAdapter.remove(button);
mAdapter.notifyDataSetChanged();
mDbHelper.removeButton(button.getId());
}
return true;
}
private void addButton() {
final List<Code> list = mDbHelper.getCodes();
CharSequence[] items = new CharSequence[list.size()];
for (int i = 0; i < items.length; i++) {
items[i] = list.get(i).getName();
}
new AlertDialog.Builder(this).setTitle("Выберите кнопку")
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
addButton(list.get(which));
}
}).show();
}
private void addButton(Code code) {
long fid = getIntent().getLongExtra(FUNCTION_ID, 0);
long id = mDbHelper.saveButton(new FunctionButton(0, code), fid);
mAdapter.add(new FunctionButton(id, code));
mAdapter.notifyDataSetChanged();
}
}
Oops, something went wrong.

0 comments on commit 47c915f

Please sign in to comment.