Skip to content

Commit f013e0e

Browse files
committed
1.2
1 parent c54c82b commit f013e0e

File tree

7 files changed

+66
-53
lines changed

7 files changed

+66
-53
lines changed

.idea/libraries/multidex_1_0_1.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
②在lib目录下新建三个文件夹arm64-v8a armeabi x86并且把相对应的so文件复制过去。<br>
1212

1313
③新建一个与so文件对应的java文件里面加载库并且,声明那个native方法,注意方法名,包名什么的一定要相同,否则报错。<br>
14+
15+
#1.2
16+
1.已经修复了弹出窗口卡死的bug

lib/src/main/java/com/example/FF.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.example;
2+
3+
/**
4+
* Created by mr.cheng on 2016/12/3.
5+
*/
6+
public class FF {
7+
public static void main(String[] args) {
8+
FF ff = new FF();
9+
ff.method();
10+
}
11+
12+
private void method() {
13+
short[] myRecoed = new short[6000];
14+
15+
for (int i = 0; i < 6000; i++) {
16+
myRecoed[i]= (short) -32768;
17+
}
18+
int counter = 0;
19+
boolean startCount = true;
20+
for (int i = 0; i < myRecoed.length; i++) {
21+
if (Math.abs(myRecoed[i]) == 32768) {
22+
if (startCount) {
23+
counter++;
24+
if (counter==1000){
25+
System.out.printf("1111");
26+
System.out.printf("位置:"+i);
27+
System.out.println();
28+
counter=0;
29+
}
30+
} else {
31+
startCount = true;
32+
counter = 0;
33+
}
34+
35+
} else {
36+
startCount = false;
37+
}
38+
}
39+
}
40+
}

myapplication/build.gradle

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ android {
1010
targetSdkVersion 23
1111
versionCode 1
1212
versionName "1.0"
13-
multiDexEnabled true
14-
ndk {
15-
16-
moduleName"myNativeLib"
17-
18-
ldLibs "log", "z", "m"
19-
20-
abiFilters "arm64-v8a","x86"
21-
ldLibs "log"
22-
23-
}
2413

2514
}
2615
sourceSets {

myapplication/src/main/java/util/ReadFileThread.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ReadFileThread extends Thread {
5050
public ReadFileThread(Context context, String ip) {
5151
mContext = context;
5252
this.Ip = ip;
53-
ReadFile();
53+
5454
}
5555

5656
@Override
@@ -60,17 +60,8 @@ public void run() {
6060
serverSocket=new ServerSocket(Constant.TCP_PORT);
6161
mSocket=serverSocket.accept();
6262

63-
// InetSocketAddress socketAddress = new InetSocketAddress(Ip, Constant.TCP_PORT);
64-
// mSocket = new Socket();
65-
// while (!mSocket.isConnected()) {
66-
// try {
67-
// mSocket.connect(socketAddress, 5000);
68-
// } catch (IOException e) {
69-
// e.printStackTrace();
70-
// Thread.sleep(1000);
71-
// }
72-
// }
7363
EventBus.getDefault().post("已连接");
64+
ReadFile();
7465
mObjectOutputStream = new ObjectOutputStream(new BufferedOutputStream(mSocket.getOutputStream()));
7566
//注册广播接受者java代码
7667
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
@@ -96,7 +87,9 @@ public void run() {
9687
e.printStackTrace();
9788
}finally {
9889
try {
99-
serverSocket.close();
90+
if (serverSocket!=null) {
91+
serverSocket.close();
92+
}
10093
} catch (Exception e) {
10194
e.printStackTrace();
10295
}
@@ -118,7 +111,7 @@ private void ReadFile() {
118111
inputStream.close();
119112
is.close();
120113
mDatas.clear();
121-
for (int i = 0; i < 8192; i++) {
114+
for (int i = 0; i < 4000; i++) {
122115
mDatas.add((float) doubles[i]);
123116
}
124117
} catch (IOException e) {
@@ -146,8 +139,12 @@ public void SendDisimiss() {
146139
e.printStackTrace();
147140
}finally {
148141
try {
149-
mObjectOutputStream.close();
150-
mSocket.close();
142+
if (mObjectOutputStream!=null) {
143+
mObjectOutputStream.close();
144+
}
145+
if (mSocket!=null) {
146+
mSocket.close();
147+
}
151148
} catch (IOException e) {
152149
e.printStackTrace();
153150
}

myapplication/src/main/java/util/UpFileActivity.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.media.AudioRecord;
55
import android.media.MediaRecorder;
66
import android.os.Bundle;
7+
import android.os.Environment;
78
import android.os.Handler;
89
import android.os.Looper;
910
import android.support.v7.widget.LinearLayoutManager;
@@ -48,16 +49,10 @@ public class UpFileActivity extends BaseActivity implements Runnable {
4849
@InjectView(R.id.record)
4950
Button mRecord;
5051
private AudioRecord recorder;
51-
private String path;
5252
private Handler mHandler = new Handler(Looper.getMainLooper());
5353
private UpFileAdapter mAdapter;
5454
private List<OutLineFile> datas = new ArrayList<>();
5555

56-
static {
57-
System.loadLibrary("myNativeLib");
58-
}
59-
60-
6156
@Override
6257
protected void onCreate(Bundle savedInstanceState) {
6358
super.onCreate(savedInstanceState);
@@ -120,15 +115,20 @@ private void MyWriteFileMethod(final short[][] mydatas) {
120115
BufferedWriter writer = null;
121116
try {
122117
MyUser myUser = BmobUser.getCurrentUser(UpFileActivity.this, MyUser.class);
118+
String mPath = Environment.getExternalStorageDirectory().getPath() + File.separator +"bmob"+File.separator ;
119+
File file1 = new File(mPath);
120+
if (!file1.exists()) {
121+
file1.mkdirs();
122+
}
123123
StringBuilder builder = new StringBuilder();
124-
builder.append("/storage/sdcard0/bmob/");
124+
builder.append(mPath);
125125
builder.append(myUser.getUsername());
126126
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
127127
Date date = new Date(System.currentTimeMillis());
128128
String name = format.format(date);
129129
builder.append(name);
130130
builder.append(".txt");
131-
path = builder.toString();
131+
String path = builder.toString();
132132
File file = new File(path);
133133
if (file.exists()) {
134134
file.delete();
@@ -140,7 +140,7 @@ private void MyWriteFileMethod(final short[][] mydatas) {
140140
double[] doubles = new double[65536];
141141
for (int j = 0; j < mydatas.length; j++) {
142142
myThread.getStringFromNative(mydatas[j], doubles);
143-
for (int i = 0; i < 8192; i++) {
143+
for (int i = 0; i < 4000; i++) {
144144
writer.write(doubles[i] + "\r\n");
145145
writer.flush();
146146
}
@@ -165,6 +165,7 @@ public void run() {
165165
e.printStackTrace();
166166
} finally {
167167
try {
168+
if (writer!=null)
168169
writer.close();
169170
} catch (IOException e) {
170171
e.printStackTrace();

0 commit comments

Comments
 (0)