Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efd109e

Browse files
committed
优化设备列表
1 parent 18e4864 commit efd109e

File tree

5 files changed

+182
-53
lines changed

5 files changed

+182
-53
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Listings/
44
App.bin/
55
JLinkLog.txt
66

7-
8-
7+
.idea
8+
app/release
99

1010
# Keil
1111
OBJ/

app/src/main/java/com/feasycom/feasybeacon/Activity/AdvertisingActivity.kt

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class AdvertisingActivity : BaseActivity() {
5050

5151
var number = 5;
5252
val timer = Timer()
53-
val timerTask = object : TimerTask(){
53+
val timerTask = object : TimerTask() {
5454
override fun run() {
55-
if(number > 0){
55+
if (number > 0) {
5656
runOnUiThread {
5757
to_main.text = "${number}s | Close"
5858
}
59-
number --
60-
}else{
59+
number--
60+
} else {
6161
this.cancel()
6262
}
6363
}
@@ -67,50 +67,56 @@ class AdvertisingActivity : BaseActivity() {
6767
private val handler = Handler(Handler.Callback {
6868
false
6969
})
70+
7071
override fun onCreate(savedInstanceState: Bundle?) {
7172
super.onCreate(savedInstanceState)
7273
setContentView(R.layout.activity_advertising)
73-
if (isFirstIn) {
74-
GuideActivity.actionStart(this)
75-
finish()
76-
} else {
77-
to_main.text = "${number}s | Close"
7874

79-
to_main.setOnClickListener {
80-
startActivity(Intent(this, MainActivity::class.java))
81-
finish()
82-
}
75+
startActivity(Intent(this, MainActivity::class.java))
76+
finish()
77+
8378

84-
timer.schedule(timerTask, 1000, 1000)
79+
if (isFirstIn) {
80+
GuideActivity.actionStart(this)
81+
finish()
82+
} else {
83+
to_main.text = "${number}s | Close"
8584

86-
lifecycleScope.launch {
87-
launch {
88-
try {
89-
api.getLauch(parameter).apply {
90-
sp.edit {
91-
putString("url", data.image)
92-
}
93-
Log.e(TAG, "onCreate: " + data.image )
94-
}
95-
}catch (e: Exception){
85+
to_main.setOnClickListener {
86+
startActivity(Intent(this, MainActivity::class.java))
87+
finish()
88+
}
9689

90+
timer.schedule(timerTask, 1000, 1000)
91+
92+
lifecycleScope.launch {
93+
launch {
94+
try {
95+
api.getLauch(parameter).apply {
96+
sp.edit {
97+
putString("url", data.image)
98+
}
99+
Log.e(TAG, "onCreate: " + data.image)
97100
}
98-
}
101+
} catch (e: Exception) {
99102

100-
launch {
101-
Glide.with(this@AdvertisingActivity)
102-
.load(sp.getString("url", "https://image.feasycom.com/lanchImage/beacon/lanch.png"))
103-
.diskCacheStrategy(DiskCacheStrategy.ALL)
104-
.into(lanch_img)
105103
}
104+
}
106105

107-
launch {
108-
delay(5000)
109-
startActivity(Intent(this@AdvertisingActivity, MainActivity::class.java))
110-
finish()
111-
}
106+
launch {
107+
Glide.with(this@AdvertisingActivity)
108+
.load(sp.getString("url", "https://image.feasycom.com/lanchImage/beacon/lanch.png"))
109+
.diskCacheStrategy(DiskCacheStrategy.ALL)
110+
.into(lanch_img)
111+
}
112+
113+
launch {
114+
delay(5000)
115+
startActivity(Intent(this@AdvertisingActivity, MainActivity::class.java))
116+
finish()
112117
}
113118
}
119+
}
114120
}
115121

116122
private val isFirstIn: Boolean
@@ -136,7 +142,7 @@ class AdvertisingActivity : BaseActivity() {
136142
override fun searchClick() {}
137143
override fun sensorClick() {}
138144

139-
companion object{
145+
companion object {
140146
private const val TAG = "AdvertisingActivity"
141147
}
142148
}

feasyblue/src/main/java/com/feasycom/feasyblue/activity/SplashScreenActivity.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ import com.feasycom.feasyblue.viewmodel.SplashViewModel
1313
import kotlinx.android.synthetic.main.activity_splash.*
1414
import java.util.*
1515

16-
class SplashScreenActivity: AppCompatActivity() {
16+
class SplashScreenActivity : AppCompatActivity() {
1717

18-
companion object{
18+
companion object {
1919
private const val TAG = "SplashActivity"
2020
}
2121

2222
private var number = 5;
2323
private val timer = Timer()
24-
private val timerTask = object : TimerTask(){
24+
private val timerTask = object : TimerTask() {
2525
override fun run() {
26-
if(number > 0){
26+
if (number > 0) {
2727
runOnUiThread {
2828
to_main.text = "${number}s | Close"
2929
}
30-
number --
31-
}else{
30+
number--
31+
} else {
3232
this.cancel()
3333
startActivity(Intent(this@SplashScreenActivity, SearchDeviceActivity::class.java))
3434
finish()
@@ -42,6 +42,8 @@ class SplashScreenActivity: AppCompatActivity() {
4242

4343
override fun onCreate(savedInstanceState: Bundle?) {
4444
super.onCreate(savedInstanceState)
45+
startActivity(Intent(this@SplashScreenActivity, SearchDeviceActivity::class.java))
46+
finish()
4547
/*this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
4648
WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
4749
//全屏设置

feasyblue/src/main/java/com/feasycom/feasyblue/adapter/SearchDeviceListAdapter.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,24 @@ public Object getItem(int position) {
5656
boolean filterRssiSwitch;
5757
boolean filterNameSwitch;
5858
int filterRssi;
59-
String filterName;
59+
String filterName = "fsc";
60+
6061
public void addDevice(BluetoothDeviceWrapper deviceDetail) {
61-
if (null == deviceDetail) return;
62-
if(filterNameSwitch){
63-
if(deviceDetail.getName() == null || !deviceDetail.getName().contains(filterName)){
62+
if (null == deviceDetail) {
63+
return;
64+
}
65+
66+
if (filterNameSwitch) {
67+
if (deviceDetail.getName() == null || !deviceDetail.getName().contains(filterName)) {
6468
return;
6569
}
6670
}
67-
if(filterRssiSwitch){
68-
if(deviceDetail.getRssi() < (filterRssi - 100)){
71+
72+
if (deviceDetail.getName() == null || !deviceDetail.getName().contains("FSC")) {
73+
return;
74+
}
75+
if (filterRssiSwitch) {
76+
if (deviceDetail.getRssi() < (filterRssi - 100)) {
6977
return;
7078
}
7179
}
@@ -84,17 +92,17 @@ public void addDevice(BluetoothDeviceWrapper deviceDetail) {
8492
mDevices.add(deviceDetail);
8593
notifyDataSetChanged();
8694
}, 100);
87-
}else {
95+
} else {
8896
mDevices.add(deviceDetail);
8997
notifyDataSetChanged();
9098
}
9199
}
92100
}
93101

94102
public void sort() {
95-
for (int i=0; i < mDevices.size() - 1; i++) {
103+
for (int i = 0; i < mDevices.size() - 1; i++) {
96104
for (int j = 0; j < mDevices.size() - 1 - i; j++) {
97-
if (mDevices.get(j).getRssi() < mDevices.get(j + 1).getRssi() && mDevices.get(j).getBondState() != BluetoothDevice.BOND_BONDED && mDevices.get(j+1).getBondState() != BluetoothDevice.BOND_BONDED) {
105+
if (mDevices.get(j).getRssi() < mDevices.get(j + 1).getRssi() && mDevices.get(j).getBondState() != BluetoothDevice.BOND_BONDED && mDevices.get(j + 1).getBondState() != BluetoothDevice.BOND_BONDED) {
98106
BluetoothDeviceWrapper bd = mDevices.get(j);
99107
mDevices.set(j, mDevices.get(j + 1));
100108
mDevices.set(j + 1, bd);
@@ -196,6 +204,7 @@ static class ViewHolder {
196204
ProgressBar pbRssi;
197205
@BindView(R.id.device_view)
198206
LinearLayout deviceView;
207+
199208
ViewHolder(View view) {
200209
ButterKnife.bind(this, view);
201210
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.feasycom.feasyblue.util;
2+
3+
import android.util.Log;
4+
5+
public class
6+
DebugLogUtil {
7+
8+
// 单例访问
9+
private static DebugLogUtil debugUtil;
10+
/**
11+
* 判断是否在进行Debug开发阶段, 默认false
12+
*/
13+
private boolean isDebug;
14+
/**
15+
* 打印日志过滤标示,默认'Application'
16+
*/
17+
private String Filter;
18+
19+
private DebugLogUtil() {
20+
isDebug = true;
21+
Filter = "DebugLogUtil";
22+
}
23+
24+
private static String commonMsg = "";
25+
26+
/**
27+
* 创建该类对象唯一的方法
28+
*
29+
* @return
30+
*/
31+
public static DebugLogUtil getInstance() {
32+
commonMsg = " -(,在" + getAutoJumpLogInfos()[2] + "->" + getAutoJumpLogInfos()[1];
33+
if (debugUtil == null) {
34+
synchronized (DebugLogUtil.class) {
35+
if (debugUtil == null) {
36+
debugUtil = new DebugLogUtil();
37+
}
38+
}
39+
}
40+
return debugUtil;
41+
}
42+
43+
44+
public boolean isDebug() {
45+
return isDebug;
46+
}
47+
48+
public void setDebug(boolean isDebug) {
49+
this.isDebug = isDebug;
50+
}
51+
52+
public String getFilter() {
53+
return Filter;
54+
}
55+
56+
public void setFilter(String filter) {
57+
Filter = filter;
58+
}
59+
60+
public void Verbose(String logCat) {
61+
if (isDebug) {
62+
Log.v(this.Filter, logCat + commonMsg);
63+
}
64+
}
65+
66+
public void Debug(String logCat) {
67+
if (isDebug) {
68+
Log.d(this.Filter, logCat + commonMsg);
69+
}
70+
}
71+
72+
public void Info(String logCat) {
73+
if (isDebug) {
74+
Log.i(this.Filter, logCat + commonMsg);
75+
}
76+
}
77+
78+
public void Warn(String logCat) {
79+
if (isDebug) {
80+
Log.w(this.Filter, logCat + commonMsg);
81+
}
82+
}
83+
84+
public void Error(String logCat) {
85+
if (isDebug) {
86+
Log.e(this.Filter, logCat + commonMsg);
87+
}
88+
}
89+
90+
91+
/**
92+
* 获取打印信息所在方法名,行号等信息
93+
*
94+
* @return
95+
*/
96+
private static String[] getAutoJumpLogInfos() {
97+
String[] infos = new String[]{"", "", ""};
98+
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
99+
if (elements.length < 5) {
100+
Log.e("MyLogger", "Stack is too shallow!!!");
101+
return infos;
102+
} else {
103+
infos[0] = elements[4].getClassName().substring(
104+
elements[4].getClassName().lastIndexOf(".") + 1);
105+
infos[1] = elements[4].getMethodName() + "()";
106+
infos[2] = " at (" + elements[4].getClassName() + ".java:"
107+
+ elements[4].getLineNumber() + ")";
108+
return infos;
109+
}
110+
111+
}
112+
}

0 commit comments

Comments
 (0)