() {
263 | @Override
264 | public int compare(Device lhs, Device rhs) {
265 | String lhsName = lhs.name;
266 | String rhsName = rhs.name;
267 | int rssiDiff = rhs.rssi - lhs.rssi;
268 | if (isEmpty(lhsName)) {
269 | if (isEmpty(rhsName)) return rssiDiff;
270 | else return 1;
271 | } else if (isMynt(lhsName)) {
272 | if (isEmpty(rhsName)) return -1;
273 | else if (isMynt(rhsName)) return rssiDiff;
274 | else return -1;
275 | } else {
276 | if (isEmpty(rhsName)) return -1;
277 | else if (isMynt(rhsName)) return 1;
278 | else return rssiDiff;
279 | }
280 | }
281 |
282 | private boolean isEmpty(String s) {
283 | return s == null || s.length() <= 0;
284 | }
285 |
286 | private boolean isMynt(String s) {
287 | return s.startsWith(FILTER_NAME_PREFIX);
288 | }
289 | });
290 | }
291 |
292 | @Override
293 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
294 | Context context = parent.getContext();
295 | View v = LayoutInflater.from(context).inflate(R.layout.item_device, parent, false);
296 | v.setOnClickListener(this);
297 | return new ViewHolder(v);
298 | }
299 |
300 | @Override
301 | public void onBindViewHolder(ViewHolder holder, int position) {
302 | holder.itemView.setTag(position);
303 |
304 | final Device device = mDevices.get(position);
305 | holder.textName.setText(device.name + " " + device.sn);
306 | holder.textAddr.setText(device.address);
307 | holder.textRssi.setText(device.rssi + "dB");
308 | }
309 |
310 | @Override
311 | public int getItemCount() {
312 | return mDevices.size();
313 | }
314 |
315 | @Override
316 | public void onClick(View v) {
317 | if (mOnDeviceClickListener != null) {
318 | final int position = (int) v.getTag();
319 | mOnDeviceClickListener.onItemViewClick(v, position, mDevices.get(position));
320 | }
321 | }
322 |
323 | public interface OnDeviceClickListener {
324 | void onItemViewClick(View view, int position, Device device);
325 | }
326 | }
327 |
328 | //private final int REQ_ACCESS_LOCATION = 1;
329 |
330 | /**
331 | * Android 6.0 及以上蓝牙能够扫描到设备,需要蓝牙和定位都开启时才行,如果 targetSdkVersion >= 23。
332 | *
333 | *
http://stackoverflow.com/questions/32708374/bluetooth-le-scanfilters-dont-work-on-android-m
334 | *
335 | *
java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
336 | */
337 | /*private void requestPermissions() {
338 | if (!PermissionUtils.checkPermissionsGranted(this, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION)) {
339 | requestPermissions(new String[]{ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION},
340 | "Request ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION to get scan results for Bluetooth LE",
341 | REQ_ACCESS_LOCATION);
342 | }
343 | }
344 |
345 | private void requestPermissions(@NonNull final String[] permissions,
346 | @Nullable final String explanation,
347 | final int requestCode) {
348 | if (PermissionUtils.shouldPermissionsShowRationale(this, permissions)) {
349 | if (explanation == null) {
350 | return;
351 | }
352 | new AlertDialog.Builder(this)
353 | .setTitle("Request Permissions")
354 | .setMessage(explanation)
355 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
356 | @Override
357 | public void onClick(DialogInterface dialog, int which) {
358 | ActivityCompat.requestPermissions(SearchActivity.this,
359 | permissions, requestCode);
360 | }
361 | })
362 | .show();
363 | } else {
364 | ActivityCompat.requestPermissions(this, permissions, requestCode);
365 | }
366 | }
367 |
368 | @Override
369 | public void onRequestPermissionsResult(int requestCode,
370 | @NonNull String[] permissions,
371 | @NonNull int[] grantResults) {
372 | if (requestCode == REQ_ACCESS_LOCATION) {
373 | if (PermissionUtils.verifyPermission(grantResults)) {
374 | ToastUtils.show(this, "Permission was granted, yay!");
375 | } else {
376 | ToastUtils.show(this, "Permission denied, boo!");
377 | }
378 | } else {
379 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
380 | }
381 | }*/
382 | }
383 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/java/com/slightech/mynt/sdk/demo/ui/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo.ui.base;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 |
5 | public class BaseActivity extends AppCompatActivity {
6 | }
7 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/java/com/slightech/mynt/sdk/demo/ui/base/BaseDialogFragment.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo.ui.base;
2 |
3 | import android.support.v7.app.AppCompatDialogFragment;
4 |
5 | public abstract class BaseDialogFragment extends AppCompatDialogFragment {
6 | }
7 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/java/com/slightech/mynt/sdk/demo/ui/dialog/UpdateDialogFragment.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo.ui.dialog;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.app.AlertDialog;
6 | import android.app.Dialog;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.database.Cursor;
10 | import android.net.Uri;
11 | import android.os.Bundle;
12 | import android.support.annotation.NonNull;
13 | import android.view.View;
14 | import android.widget.AdapterView;
15 | import android.widget.ArrayAdapter;
16 | import android.widget.ListView;
17 |
18 | import com.slightech.mynt.sdk.demo.Firmware;
19 | import com.slightech.mynt.sdk.demo.R;
20 | import com.slightech.mynt.sdk.demo.ui.base.BaseActivity;
21 | import com.slightech.mynt.sdk.demo.ui.base.BaseDialogFragment;
22 | import com.slightech.mynt.sdk.demo.util.ToastUtils;
23 |
24 | import java.util.ArrayList;
25 | import java.util.Arrays;
26 |
27 | public class UpdateDialogFragment extends BaseDialogFragment implements
28 | ListView.OnItemClickListener {
29 |
30 | public static UpdateDialogFragment show(BaseActivity activity, String title) {
31 | UpdateDialogFragment dlg = new UpdateDialogFragment();
32 | Bundle args = new Bundle();
33 | args.putString("title", title);
34 | dlg.setArguments(args);
35 | dlg.show(activity.getSupportFragmentManager(), "dlg_update");
36 | return dlg;
37 | }
38 |
39 | private final String SELECT_BIN_FILE = "Select external bin file";
40 | private final int REQ_SELECT = 1;
41 |
42 | private ListView mListView;
43 |
44 | private String mTitle;
45 |
46 | private ArrayList mData;
47 |
48 | private OnUpdateSelectListener mListener;
49 |
50 | public UpdateDialogFragment setOnUpdateSelectListener(OnUpdateSelectListener l) {
51 | mListener = l;
52 | return this;
53 | }
54 |
55 | @Override
56 | public void onDetach() {
57 | super.onDetach();
58 | mListener = null;
59 | }
60 |
61 | @Override
62 | public void onCreate(Bundle savedInstanceState) {
63 | super.onCreate(savedInstanceState);
64 | Bundle args = getArguments();
65 | mTitle = args.getString("title");
66 | }
67 |
68 | @NonNull
69 | @Override
70 | public Dialog onCreateDialog(Bundle savedInstanceState) {
71 | Activity activity = getActivity();
72 | @SuppressLint("InflateParams")
73 | View v = activity.getLayoutInflater().inflate(R.layout.frag_dlg_update, null);
74 |
75 | ListView list = (ListView) v.findViewById(R.id.list);
76 | list.setOnItemClickListener(this);
77 | mListView = list;
78 |
79 | updateListView();
80 |
81 | AlertDialog.Builder b = new AlertDialog.Builder(activity)
82 | .setTitle(mTitle)
83 | .setView(v)
84 | .setNegativeButton(android.R.string.no, null);
85 | return b.create();
86 | }
87 |
88 | private void updateListView() {
89 | ArrayList data = new ArrayList<>();
90 | data.addAll(Arrays.asList(Firmware.FILES));
91 | data.add(SELECT_BIN_FILE);
92 | mData = data;
93 | mListView.setAdapter(new ArrayAdapter<>(getActivity(),
94 | android.R.layout.simple_list_item_1,
95 | android.R.id.text1, data));
96 | }
97 |
98 | @Override
99 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
100 | int end = mData.size() - 1;
101 | if (position == end) {
102 | showFileChooser();
103 | } else {
104 | onUpdateSelect(mData.get(position), true);
105 | }
106 | }
107 |
108 | private void showFileChooser() {
109 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
110 | intent.setType("*/*");
111 | intent.addCategory(Intent.CATEGORY_OPENABLE);
112 | try {
113 | startActivityForResult(Intent.createChooser(intent, SELECT_BIN_FILE), REQ_SELECT);
114 | } catch (android.content.ActivityNotFoundException ex) {
115 | ToastUtils.show(getActivity(), "Please install a File Manager.");
116 | }
117 | }
118 |
119 | @Override
120 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
121 | switch (requestCode) {
122 | case REQ_SELECT:
123 | if (resultCode == Activity.RESULT_OK) {
124 | Uri uri = data.getData();
125 | String path = getPath(getActivity(), uri);
126 | onUpdateSelect(path, false);
127 | }
128 | break;
129 | }
130 | }
131 |
132 | private String getPath(Context context, Uri uri) {
133 | if ("content".equalsIgnoreCase(uri.getScheme())) {
134 | String[] projection = {"_data"};
135 | try {
136 | Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
137 | if (cursor != null) {
138 | int index = cursor.getColumnIndexOrThrow("_data");
139 | if (cursor.moveToFirst()) {
140 | return cursor.getString(index);
141 | }
142 | cursor.close();
143 | }
144 | } catch (Exception e) {
145 | e.printStackTrace();
146 | }
147 | } else if ("file".equalsIgnoreCase(uri.getScheme())) {
148 | return uri.getPath();
149 | }
150 | return null;
151 | }
152 |
153 | private void onUpdateSelect(String path, boolean formAssets) {
154 | if (mListener != null && path != null) {
155 | mListener.onUpdateSelect(path, formAssets);
156 | }
157 | if (path != null) {
158 | dismiss();
159 | }
160 | }
161 |
162 | public interface OnUpdateSelectListener {
163 | void onUpdateSelect(String filepath, boolean formAssets);
164 | }
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/java/com/slightech/mynt/sdk/demo/util/KitUtils.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.view.View;
6 |
7 | public class KitUtils {
8 |
9 | @SuppressWarnings({ "unchecked", "UnusedDeclaration" })
10 | public static T findById(View view, int id) {
11 | return (T) view.findViewById(id);
12 | }
13 |
14 | @SuppressWarnings({ "unchecked", "UnusedDeclaration" })
15 | public static T findById(Activity activity, int id) {
16 | return (T) activity.findViewById(id);
17 | }
18 |
19 | /**
20 | * Return the handle to a system-level service by name.
21 | *
22 | * @see Context#getSystemService(String)
23 | */
24 | @SuppressWarnings({ "unchecked", "UnusedDeclaration" })
25 | public static T getService(Context context, String name) {
26 | return (T) context.getSystemService(name);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/java/com/slightech/mynt/sdk/demo/util/LogUtils.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo.util;
2 |
3 | import android.util.Log;
4 |
5 | import com.slightech.mynt.sdk.demo.BuildConfig;
6 |
7 | public class LogUtils {
8 |
9 | public static final boolean VISIBLE = BuildConfig.DEBUG;
10 |
11 | public static void v(String tag, String msg, Object... args) {
12 | println(Log.VERBOSE, tag, msg, args);
13 | }
14 |
15 | public static void d(String tag, String msg, Object... args) {
16 | println(Log.DEBUG, tag, msg, args);
17 | }
18 |
19 | public static void i(String tag, String msg, Object... args) {
20 | println(Log.INFO, tag, msg, args);
21 | }
22 |
23 | public static void w(String tag, String msg, Object... args) {
24 | println(Log.WARN, tag, msg, args);
25 | }
26 |
27 | public static void e(String tag, String msg, Object... args) {
28 | println(Log.ERROR, tag, msg, args);
29 | }
30 |
31 | public static void println(int priority, String tag, String msg, Object... args) {
32 | if (VISIBLE) Log.println(priority, tag, String.format(msg, args));
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/java/com/slightech/mynt/sdk/demo/util/PermissionUtils.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.pm.PackageManager;
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.app.ActivityCompat;
8 | import android.support.v4.content.ContextCompat;
9 |
10 | /**
11 | * Utility class that wraps access to the runtime permissions API in M and provides basic helper
12 | * methods.
13 | *
14 | * @see PermissionUtil.java
16 | * @see RxPermissions
17 | */
18 | public class PermissionUtils {
19 |
20 | /**
21 | * Check that the specific permission has been granted.
22 | */
23 | public static boolean checkPermissionGranted(@NonNull Context context,
24 | @NonNull String permission) {
25 | return ContextCompat.checkSelfPermission(context, permission)
26 | == PackageManager.PERMISSION_GRANTED;
27 | }
28 |
29 | /**
30 | * Check that all specific permissions have been granted.
31 | *
32 | * @see ContextCompat#checkSelfPermission(Context, String)
33 | */
34 | public static boolean checkPermissionsGranted(@NonNull Context context,
35 | @NonNull String... permissions) {
36 | for (String permission : permissions) {
37 | if (ContextCompat.checkSelfPermission(context, permission)
38 | != PackageManager.PERMISSION_GRANTED) {
39 | return false;
40 | }
41 | }
42 | return true;
43 | }
44 |
45 | /**
46 | * Check that should show request permission rationale.
47 | */
48 | public static boolean shouldPermissionShowRationale(@NonNull Activity activity,
49 | @NonNull String permission) {
50 | return ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
51 | }
52 |
53 | /**
54 | * Check that should show request permission rationale.
55 | *
56 | * @see ActivityCompat#shouldShowRequestPermissionRationale(Activity, String)
57 | */
58 | public static boolean shouldPermissionsShowRationale(@NonNull Activity activity,
59 | @NonNull String... permissions) {
60 | for (String permission : permissions) {
61 | if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
62 | return true;
63 | }
64 | }
65 | return false;
66 | }
67 |
68 | /**
69 | * Check that the given permission has been granted.
70 | */
71 | public static boolean verifyPermission(int[] grantResults) {
72 | return grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
73 | }
74 |
75 | /**
76 | * Check that all given permissions have been granted by verifying that each entry in the
77 | * given array is of the value {@link PackageManager#PERMISSION_GRANTED}.
78 | *
79 | * @see Activity#onRequestPermissionsResult(int, String[], int[])
80 | */
81 | public static boolean verifyPermissions(int[] grantResults) {
82 | // At least one result must be checked.
83 | if(grantResults.length < 1){
84 | return false;
85 | }
86 |
87 | // Verify that each required permission has been granted, otherwise return false.
88 | for (int result : grantResults) {
89 | if (result != PackageManager.PERMISSION_GRANTED) {
90 | return false;
91 | }
92 | }
93 | return true;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/java/com/slightech/mynt/sdk/demo/util/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo.util;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.StringRes;
5 |
6 | public class ToastUtils {
7 |
8 | public static void show(Context context, @StringRes int resId) {
9 | if (context == null) return;
10 | android.widget.Toast.makeText(context, resId, android.widget.Toast.LENGTH_SHORT).show();
11 | }
12 |
13 | public static void show(Context context, CharSequence text) {
14 | if (context == null) return;
15 | android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show();
16 | }
17 |
18 | public static void showLong(Context context, @StringRes int resId) {
19 | if (context == null) return;
20 | android.widget.Toast.makeText(context, resId, android.widget.Toast.LENGTH_LONG).show();
21 | }
22 |
23 | public static void showLong(Context context, CharSequence text) {
24 | if (context == null) return;
25 | android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_LONG).show();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/anim/slide_in_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/anim/slide_in_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/anim/slide_out_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/anim/slide_out_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/layout/activity_control.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
20 |
21 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/layout/activity_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
18 |
19 |
23 |
24 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/layout/frag_dlg_update.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/layout/item_device.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
22 |
25 |
30 |
33 |
38 |
41 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/layout/item_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/layout/toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/menu/control.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/menu/search.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/demo/mynt-sdk-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/demo/mynt-sdk-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/demo/mynt-sdk-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/demo/mynt-sdk-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/demo/mynt-sdk-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #ff33b5e5
8 | #ff99cc00
9 | #ffffbb33
10 | #ffff4444
11 |
12 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/values/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 300
4 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MYNT Demo
3 |
4 | Search MYNTs
5 | Control MYNTs
6 |
7 | Start
8 | Stop
9 |
10 | Connect
11 | Disconnect
12 |
13 | Toggle alarm
14 | Request rssi
15 | Request battery
16 | Request info
17 | Request control custom action
18 | Send control mode
19 | Send control custom clicks
20 | Update Firmware
21 | Setup BLE mode
22 | Setup HID mode
23 |
24 | Clear history
25 |
26 |
27 | - Music
28 | - Camera
29 | - PPT
30 | - Custom
31 | - Default
32 |
33 |
34 | Addr
35 | Rssi
36 |
37 | BLE not supported
38 | Bluetooth not supported
39 | Scan failed
40 | Address invalid
41 | Connect failed
42 | Discover failed
43 | Disconnect failed
44 |
45 | Click the button on MYNT device could wake it from sleep!
46 |
47 |
48 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/app/src/test/java/com/slightech/mynt/sdk/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.slightech.mynt.sdk.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/demo/mynt-sdk-demo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Aug 24 14:18:27 CST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/demo/mynt-sdk-demo/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/doc/how/how_to_update_firmware_en.md:
--------------------------------------------------------------------------------
1 |
2 | # How to update firmware
3 |
4 | **Step 1: run demo app, then connect the MYNT**
5 |
6 | **Step 2: select "Update Firmware" action**
7 |
8 | 
9 |
10 | **Step 3: select a bin file to send**
11 |
12 | 
13 |
14 | **Step 4: check the "software" info**
15 |
16 | 
17 |
--------------------------------------------------------------------------------
/doc/how/how_to_update_firmware_zh.md:
--------------------------------------------------------------------------------
1 |
2 | # 如何更新固件
3 |
4 | **Step 1: 运行 Demo, 连接 MYNT**
5 |
6 | **Step 2: 选择 "Update Firmware" 操作**
7 |
8 | 
9 |
10 | **Step 3: 选择一个 bin 固件文件**
11 |
12 | 
13 |
14 | **Step 4: 检查前后的 "software" 信息**
15 |
16 | 
17 |
--------------------------------------------------------------------------------
/doc/mynt-sdk-doc-deploy-v1.1.4_065b2c2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/doc/mynt-sdk-doc-deploy-v1.1.4_065b2c2.zip
--------------------------------------------------------------------------------
/doc/usage_en.md:
--------------------------------------------------------------------------------
1 |
2 | # The MYNT SDK Usage
3 |
4 | ## 1) Requirements
5 |
6 | **Permissions should be declared in `AndroidManifest.xml`:**
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | **`build.gradle` if target Android 6.0 (API level 23) or higher:**
19 |
20 | android {
21 |
22 | useLibrary 'org.apache.http.legacy'
23 |
24 |
25 | defaultConfig {
26 | targetSdkVersion 22
27 | }
28 | }
29 |
30 | Reference: [Android 6.0 Changes](http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html)
31 |
32 |
33 | ## 2) How to control the MYNTs
34 |
35 | Instantiate `MyntManager` class then using it to search and control MYNTs.
36 |
37 | * Call `startSearch` to search the MYNTs, and get the result from the `FoundCallback`.
38 | * Call `connect` to connect the MYNTs, then control them with `MyntManager`.
39 | - Set `PairCallback` to listen the connect process.
40 | - Set `EventCallback` to listen the device events.
41 |
42 |
43 | ## 3) How to contribute the anti-lost network
44 |
45 | Using `MyntManager` to start search in your `Application`:
46 |
47 | public class MyApplication extends Application {
48 |
49 | @Override
50 | public void onCreate() {
51 | super.onCreate();
52 | // Searching MYNTs here could help people who lost the things.
53 | new MyntManager(this).startSearch();
54 | }
55 |
56 | //...
57 | }
58 |
59 | Then will upload nearby MYNTs to the anti-lost network when the bluetooth is available.
60 |
61 | * Set the `MyntParams` to change the search internal etc.
62 | * Get the `Nearby` feature to bind location provider or upload by yourself.
63 |
64 |
65 | ## 4) About ProGuard rules
66 |
67 | -keep class com.slighetch.** { *; }
68 |
--------------------------------------------------------------------------------
/doc/usage_zh.md:
--------------------------------------------------------------------------------
1 |
2 | # MYNT SDK 使用手册
3 |
4 |
5 | ## 1) 要求
6 |
7 | **`AndroidManifest.xml`需要声明的权限:**
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | **`build.gradle`于 Android 6.0 (API level 23) 上:**
20 |
21 | android {
22 |
23 | useLibrary 'org.apache.http.legacy'
24 |
25 |
26 | defaultConfig {
27 | targetSdkVersion 22
28 | }
29 | }
30 |
31 | 参考: [Android 6.0 Changes](http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html)
32 |
33 |
34 | ## 2) 如何控制小觅设备
35 |
36 | 实例化`MyntManager`进行操作即可。分为搜索和控制两步:
37 |
38 | * `startSearch`进行搜索,通过`FoundCallback`获得搜索到的小觅设备。
39 | * `connect`进行连接,通过`PairCallback`监听连接配对、通过`EventCallback`监听设备事件。
40 |
41 |
42 | ## 3) 如何为防丢网络贡献一份力量
43 |
44 | 在`Application`中,启用搜索即可:
45 |
46 | public class MyApplication extends Application {
47 |
48 | @Override
49 | public void onCreate() {
50 | super.onCreate();
51 | // 搜索小觅,即会上报附近发现设备到防丢网络
52 | new MyntManager(this).startSearch();
53 | }
54 |
55 | //...
56 | }
57 |
58 | 然后,当蓝牙开启时,即会搜索附近的小觅并上报到防丢网络。
59 |
60 | `MyntParams`可设置搜索间隔等,`Nearby`功能则提供了更多支持。
61 |
62 |
63 | ## 4) ProGuard混淆规则
64 |
65 | -keep class com.slighetch.** { *; }
66 |
--------------------------------------------------------------------------------
/libs/mynt-sdk-deploy-v1.1.4_065b2c2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/libs/mynt-sdk-deploy-v1.1.4_065b2c2.jar
--------------------------------------------------------------------------------
/static/colorful.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/static/colorful.png
--------------------------------------------------------------------------------
/static/slide-ctr-photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/static/slide-ctr-photo.png
--------------------------------------------------------------------------------
/static/slide_mynt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/static/slide_mynt.png
--------------------------------------------------------------------------------
/static/update_firmware_check_software.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/static/update_firmware_check_software.png
--------------------------------------------------------------------------------
/static/update_firmware_select_action.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/static/update_firmware_select_action.png
--------------------------------------------------------------------------------
/static/update_firmware_select_bin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slightech/MYNT-SDK-Android/7c294d7d881bda54e19f21e899dc2bee02924fa3/static/update_firmware_select_bin.png
--------------------------------------------------------------------------------