@@ -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
0 commit comments