Commit c4a2cca537070ca25b16b362e0e9b1f9ae51a489
1 parent
d2f4c819
swich basic control function,and simple demo
Showing
10 changed files
with
151 additions
and
7 deletions
| @@ -35,7 +35,9 @@ dependencies { | @@ -35,7 +35,9 @@ dependencies { | ||
| 35 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | 35 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { |
| 36 | exclude group: 'com.android.support', module: 'support-annotations' | 36 | exclude group: 'com.android.support', module: 'support-annotations' |
| 37 | }) | 37 | }) |
| 38 | - compile 'com.android.support:appcompat-v7:25.2.0' | ||
| 39 | compile group: 'com.google.code.gson', name: 'gson', version: '2.7' | 38 | compile group: 'com.google.code.gson', name: 'gson', version: '2.7' |
| 39 | + compile 'com.android.support:appcompat-v7:25.2.0' | ||
| 40 | + compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4' | ||
| 41 | + compile 'com.android.support:design:25.2.0' | ||
| 40 | testCompile 'junit:junit:4.12' | 42 | testCompile 'junit:junit:4.12' |
| 41 | } | 43 | } |
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | - package="com.qnbar.switchcontrol"> | 3 | + package="com.qnbar.switchcontrol"> |
| 4 | 4 | ||
| 5 | - <uses-permission android:name="android.permission.INTERNET" /> | 5 | + <uses-permission android:name="android.permission.INTERNET"/> |
| 6 | 6 | ||
| 7 | - <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" | ||
| 8 | - android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> | 7 | + <application |
| 8 | + android:allowBackup="true" | ||
| 9 | + android:icon="@mipmap/ic_launcher" | ||
| 10 | + android:label="@string/app_name" | ||
| 11 | + android:supportsRtl="true" | ||
| 12 | + android:theme="@style/AppTheme"> | ||
| 9 | <activity android:name=".MainActivity"> | 13 | <activity android:name=".MainActivity"> |
| 14 | + <!-- <intent-filter> | ||
| 15 | + <action android:name="android.intent.action.MAIN"/> | ||
| 16 | + | ||
| 17 | + <category android:name="android.intent.category.LAUNCHER"/> | ||
| 18 | + </intent-filter>--> | ||
| 19 | + </activity> | ||
| 20 | + <activity | ||
| 21 | + android:name=".SwitchControlActivity" | ||
| 22 | + android:theme="@style/AppTheme.NoActionBar"> | ||
| 10 | <intent-filter> | 23 | <intent-filter> |
| 11 | - <action android:name="android.intent.action.MAIN" /> | 24 | + <action android:name="android.intent.action.MAIN"/> |
| 12 | 25 | ||
| 13 | - <category android:name="android.intent.category.LAUNCHER" /> | 26 | + <category android:name="android.intent.category.LAUNCHER"/> |
| 14 | </intent-filter> | 27 | </intent-filter> |
| 15 | </activity> | 28 | </activity> |
| 16 | </application> | 29 | </application> |
| @@ -53,4 +53,12 @@ public class MainActivity extends AppCompatActivity { | @@ -53,4 +53,12 @@ public class MainActivity extends AppCompatActivity { | ||
| 53 | FistJni fistJni = FistJni.getInstance(); | 53 | FistJni fistJni = FistJni.getInstance(); |
| 54 | fistJni.query(); | 54 | fistJni.query(); |
| 55 | } | 55 | } |
| 56 | + public void normalC1(View view) { | ||
| 57 | + FistJni fistJni = FistJni.getInstance(); | ||
| 58 | + fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":1,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | ||
| 59 | + } | ||
| 60 | + public void normalC(View view) { | ||
| 61 | + FistJni fistJni = FistJni.getInstance(); | ||
| 62 | + fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":0,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | ||
| 63 | + } | ||
| 56 | } | 64 | } |
| 1 | +package com.qnbar.switchcontrol; | ||
| 2 | + | ||
| 3 | +import android.os.Bundle; | ||
| 4 | +import android.support.design.widget.FloatingActionButton; | ||
| 5 | +import android.support.design.widget.Snackbar; | ||
| 6 | +import android.support.v7.app.AppCompatActivity; | ||
| 7 | +import android.support.v7.widget.Toolbar; | ||
| 8 | +import android.view.View; | ||
| 9 | +import com.adroplat.fist_switch.jni.FistJni; | ||
| 10 | + | ||
| 11 | +public class SwitchControlActivity extends AppCompatActivity { | ||
| 12 | + | ||
| 13 | + @Override | ||
| 14 | + protected void onCreate(Bundle savedInstanceState) { | ||
| 15 | + super.onCreate(savedInstanceState); | ||
| 16 | + setContentView(R.layout.activity_switch_control); | ||
| 17 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
| 18 | + setSupportActionBar(toolbar); | ||
| 19 | + FistJni fistJni = FistJni.getInstance(); | ||
| 20 | + fistJni.startSdk(); | ||
| 21 | + searchLocalDevice(); | ||
| 22 | + if (getSupportActionBar() != null) { | ||
| 23 | + getSupportActionBar().setTitle("智能开关控制"); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | ||
| 27 | + fab.setOnClickListener(new View.OnClickListener() { | ||
| 28 | + @Override | ||
| 29 | + public void onClick(View view) { | ||
| 30 | + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | ||
| 31 | + .setAction("Action", null).show(); | ||
| 32 | + } | ||
| 33 | + }); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public void searchLocalDevice(){ | ||
| 37 | + FistJni fistJni = FistJni.getInstance(); | ||
| 38 | + fistJni.searchLocalDevice(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void startFist() { | ||
| 42 | + FistJni fistJni = FistJni.getInstance(); | ||
| 43 | + fistJni.query(); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public void normalC1() { | ||
| 47 | + FistJni fistJni = FistJni.getInstance(); | ||
| 48 | + fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":1,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void normalC() { | ||
| 52 | + FistJni fistJni = FistJni.getInstance(); | ||
| 53 | + fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":0,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | +} |
| @@ -31,4 +31,16 @@ | @@ -31,4 +31,16 @@ | ||
| 31 | android:onClick="searchLocalDevice" | 31 | android:onClick="searchLocalDevice" |
| 32 | android:text="searchLocalDevice"/> | 32 | android:text="searchLocalDevice"/> |
| 33 | 33 | ||
| 34 | + <Button | ||
| 35 | + android:layout_width="wrap_content" | ||
| 36 | + android:layout_height="wrap_content" | ||
| 37 | + android:onClick="normalC1" | ||
| 38 | + android:text="Open Connect Switch"/> | ||
| 39 | + | ||
| 40 | + <Button | ||
| 41 | + android:layout_width="wrap_content" | ||
| 42 | + android:layout_height="wrap_content" | ||
| 43 | + android:onClick="normalC" | ||
| 44 | + android:text="Close Connect Switch"/> | ||
| 45 | + | ||
| 34 | </LinearLayout> | 46 | </LinearLayout> |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<android.support.design.widget.CoordinatorLayout | ||
| 3 | + xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 4 | + xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| 5 | + xmlns:tools="http://schemas.android.com/tools" | ||
| 6 | + android:layout_width="match_parent" | ||
| 7 | + android:layout_height="match_parent" | ||
| 8 | + tools:context="com.qnbar.switchcontrol.SwitchControlActivity"> | ||
| 9 | + | ||
| 10 | + <android.support.design.widget.AppBarLayout | ||
| 11 | + android:layout_height="wrap_content" | ||
| 12 | + android:layout_width="match_parent" | ||
| 13 | + android:theme="@style/AppTheme.AppBarOverlay"> | ||
| 14 | + | ||
| 15 | + <android.support.v7.widget.Toolbar | ||
| 16 | + android:id="@+id/toolbar" | ||
| 17 | + android:layout_width="match_parent" | ||
| 18 | + android:layout_height="?attr/actionBarSize" | ||
| 19 | + android:background="?attr/colorPrimary" | ||
| 20 | + app:popupTheme="@style/AppTheme.PopupOverlay"/> | ||
| 21 | + | ||
| 22 | + </android.support.design.widget.AppBarLayout> | ||
| 23 | + | ||
| 24 | + <include layout="@layout/content_switch_control"/> | ||
| 25 | + | ||
| 26 | + <android.support.design.widget.FloatingActionButton | ||
| 27 | + android:id="@+id/fab" | ||
| 28 | + android:layout_width="wrap_content" | ||
| 29 | + android:layout_height="wrap_content" | ||
| 30 | + android:layout_gravity="bottom|end" | ||
| 31 | + android:layout_margin="@dimen/fab_margin" | ||
| 32 | + app:srcCompat="@android:drawable/ic_dialog_email"/> | ||
| 33 | + | ||
| 34 | +</android.support.design.widget.CoordinatorLayout> |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<android.support.constraint.ConstraintLayout | ||
| 3 | + xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 4 | + xmlns:tools="http://schemas.android.com/tools" | ||
| 5 | + xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| 6 | + android:layout_width="match_parent" | ||
| 7 | + android:layout_height="match_parent" | ||
| 8 | + app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
| 9 | + tools:showIn="@layout/activity_switch_control" | ||
| 10 | + tools:context="com.qnbar.switchcontrol.SwitchControlActivity"> | ||
| 11 | +</android.support.constraint.ConstraintLayout> |
| @@ -2,4 +2,5 @@ | @@ -2,4 +2,5 @@ | ||
| 2 | <!-- Default screen margins, per the Android Design guidelines. --> | 2 | <!-- Default screen margins, per the Android Design guidelines. --> |
| 3 | <dimen name="activity_horizontal_margin">16dp</dimen> | 3 | <dimen name="activity_horizontal_margin">16dp</dimen> |
| 4 | <dimen name="activity_vertical_margin">16dp</dimen> | 4 | <dimen name="activity_vertical_margin">16dp</dimen> |
| 5 | + <dimen name="fab_margin">16dp</dimen> | ||
| 5 | </resources> | 6 | </resources> |
| @@ -7,5 +7,11 @@ | @@ -7,5 +7,11 @@ | ||
| 7 | <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | 7 | <item name="colorPrimaryDark">@color/colorPrimaryDark</item> |
| 8 | <item name="colorAccent">@color/colorAccent</item> | 8 | <item name="colorAccent">@color/colorAccent</item> |
| 9 | </style> | 9 | </style> |
| 10 | + <style name="AppTheme.NoActionBar"> | ||
| 11 | + <item name="windowActionBar">false</item> | ||
| 12 | + <item name="windowNoTitle">true</item> | ||
| 13 | + </style> | ||
| 14 | + <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/> | ||
| 15 | + <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/> | ||
| 10 | 16 | ||
| 11 | </resources> | 17 | </resources> |
Please
register
or
login
to post a comment