Skip to content

Commit 9309f1b

Browse files
committed
Tiny fixes
1 parent 8de5afa commit 9309f1b

6 files changed

Lines changed: 53 additions & 39 deletions

File tree

as/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.trik.gamepad"
4-
android:versionCode="19"
5-
android:versionName="1.11 beta" >
4+
android:versionCode="20"
5+
android:versionName="1.12 beta" >
66
<uses-permission android:name="android.permission.INTERNET" />
77
<!-- <uses-permission android:name="android.permission.VIBRATE" /> -->
88

as/app/src/main/java/com/demo/mjpeg/MjpegInputStream.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class MjpegInputStream extends DataInputStream {
1818
private final static int FRAME_MAX_LENGTH = 200000 + HEADER_MAX_LENGTH;
1919
private final byte[] SOI_MARKER = { (byte) 0xFF, (byte) 0xD8 };
2020
private final byte[] EOF_MARKER = { (byte) 0xFF, (byte) 0xD9 };
21-
private byte[] mHeader = new byte[100];
21+
//private byte[] mHeader = new byte[100];
2222

2323

2424
public MjpegInputStream(InputStream in) {
@@ -58,15 +58,18 @@ public InputStream readMjpegFrame() throws IOException {
5858
}
5959

6060
private int extractLength(int headerLen) throws IOException {
61+
InputStream headerIn = new BoundedInputStream(this,headerLen);
6162
try {
62-
InputStream headerIn = new BoundedInputStream(this,headerLen);
6363
Properties props = new Properties();
6464
props.load(headerIn);
6565
return Integer.parseInt(props.getProperty(CONTENT_LENGTH));
6666
} catch (NumberFormatException nfe) {
6767
nfe.getStackTrace();
6868
Log.d(TAG, "catch NumberFormatException hit", nfe);
6969
return getEndOfSequence(this, EOF_MARKER);
70+
} finally {
71+
headerIn.close();
7072
}
73+
7174
}
7275
}

as/app/src/main/java/com/demo/mjpeg/MjpegView.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.io.InputStream;
22+
import java.util.concurrent.ExecutionException;
2223

2324
public class MjpegView extends SurfaceView implements SurfaceHolder.Callback {
2425
public final static int POSITION_UPPER_LEFT = 9;
@@ -196,17 +197,14 @@ public void run() {
196197
if (surfaceDone) {
197198
Canvas c = null;
198199
try {
200+
extractNextFrameData();
201+
199202
if (mFrame == null)
200203
continue;
201204

202-
extractNextFrameDataAsync();
203-
204205
Bitmap bm;
205206
InputStream is;
206-
synchronized (extractor) {
207-
is = mFrame;
208-
}
209-
207+
is = mFrame;
210208

211209
bm = BitmapFactory.decodeStream(is);
212210

@@ -255,8 +253,14 @@ public void run() {
255253
};
256254
}
257255

258-
private void extractNextFrameDataAsync() {
259-
extractor.execute();
256+
private void extractNextFrameData() {
257+
try {
258+
extractor.execute().get();
259+
} catch (InterruptedException e) {
260+
e.printStackTrace();
261+
} catch (ExecutionException e) {
262+
e.printStackTrace();
263+
}
260264
}
261265

262266
public void join() {

as/app/src/main/java/com/trik/gamepad/MainActivity.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
5151
// @TargetApi(16)
5252
private void createPad(int id, String strId) {
5353
final SquareTouchPadLayout pad = (SquareTouchPadLayout) findViewById(id);
54-
pad.setPadName("pad " + strId);
55-
pad.setSender(mSender);
54+
if (pad != null) {
55+
pad.setPadName("pad " + strId);
56+
pad.setSender(mSender);
57+
}
5658
// if (android.os.Build.VERSION.SDK_INT >= 16) {
5759
// pad.setBackground(image);
5860
// } else {
@@ -90,8 +92,11 @@ protected void onCreate(final Bundle savedInstanceState) {
9092
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
9193
mSender = new SenderService(this);
9294

95+
mVideo = (MjpegView) findViewById(R.id.video);
96+
97+
if (mVideo != null)
9398
{
94-
mVideo = (MjpegView) findViewById(R.id.video);
99+
95100
mVideo.setOverlayPosition(MjpegView.POSITION_UPPER_RIGHT);
96101
mVideo.showFps(true);
97102
mVideo.setDisplayMode(MjpegView.SIZE_BEST_FIT);
@@ -121,21 +126,23 @@ public void onEvent(final String reason) {
121126

122127
{
123128
final Button btnSettings = (Button) findViewById(R.id.btnSettings);
124-
btnSettings.setOnClickListener(new View.OnClickListener() {
125-
126-
@Override
127-
public void onClick(final View v) {
128-
ActionBar a = getSupportActionBar();
129-
if (a != null)
130-
setSystemUiVisibility(!a.isShowing());
131-
}
132-
});
129+
if (btnSettings != null) {
130+
btnSettings.setOnClickListener(new View.OnClickListener() {
133131

132+
@Override
133+
public void onClick(final View v) {
134+
ActionBar a = getSupportActionBar();
135+
if (a != null)
136+
setSystemUiVisibility(!a.isShowing());
137+
}
138+
});
139+
}
134140
}
135141

136142
{
137143
final View controlsOverlay = findViewById(R.id.controlsOverlay);
138-
controlsOverlay.bringToFront();
144+
if (controlsOverlay != null)
145+
controlsOverlay.bringToFront();
139146
}
140147

141148
{
@@ -177,7 +184,8 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
177184

178185
// update video stream URI when target addr changed
179186
sharedPreferences.edit()
180-
.putString(SettingsActivity.SK_VIDEO_URI, "http://" + addr + ":8080/?action=stream")
187+
.putString(SettingsActivity.SK_VIDEO_URI, "http://" + addr.trim()
188+
+ ":8080/?action=stream")
181189
.apply();
182190
}
183191

@@ -197,8 +205,12 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
197205
mPrevAlpha = alpha;
198206
alphaUp.setFillAfter(true);
199207
alphaUp.setDuration(2000);
200-
findViewById(R.id.controlsOverlay).startAnimation(alphaUp);
201-
findViewById(R.id.buttons).startAnimation(alphaUp);
208+
final View co = findViewById(R.id.controlsOverlay);
209+
if (co != null)
210+
co.startAnimation(alphaUp);
211+
final View btns = findViewById(R.id.buttons);
212+
if (btns != null)
213+
btns.startAnimation(alphaUp);
202214
}
203215

204216
{
@@ -324,6 +336,8 @@ private void processSensor(final float[] values) {
324336

325337
private void recreateMagicButtons(final int count) {
326338
final ViewGroup buttonsView = (ViewGroup) findViewById(R.id.buttons);
339+
if (buttonsView == null)
340+
return;
327341
buttonsView.removeAllViews();
328342
for (int num = 1; num <= count; ++num) {
329343
final Button btn = new Button(MainActivity.this);
@@ -351,6 +365,8 @@ public void onClick(final View arg0) {
351365
private void setSystemUiVisibility(boolean show) {
352366
int flags = 0;
353367
final View mainView = findViewById(R.id.main);
368+
if (mainView == null)
369+
return;
354370

355371
final int sdk = Build.VERSION.SDK_INT;
356372

as/app/src/main/java/com/trik/gamepad/SquareTouchPadLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
101101
mMaxX = w;
102102
mMaxY = h;
103103
if (oldw == 0 && oldh == 0) {
104-
setAbsXY(w / 2, h / 2);
104+
setAbsXY(w / 2.0f, h / 2.0f);
105105
}
106106
}
107107

as/app/src/main/res/drawable/button_shape.xml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
android:color="@color/greenlight"/>
88
<corners
99
android:radius="6dp" />
10-
<padding
11-
android:left="15dp"
12-
android:top="10dp"
13-
android:right="15dp"
14-
android:bottom="10dp" />
10+
1511
</shape>
1612
</item>
1713
<item>
@@ -22,11 +18,6 @@
2218
android:color="@color/greendark" />
2319
<corners
2420
android:radius="6dp" />
25-
<padding
26-
android:left="10dp"
27-
android:top="10dp"
28-
android:right="10dp"
29-
android:bottom="10dp" />
3021
</shape>
3122
</item>
3223
</selector>

0 commit comments

Comments
 (0)