Assorted error handling and messaging.
This commit is contained in:
@@ -45,5 +45,6 @@
|
|||||||
<string name="serv_wait">Por favor espere, buscando dispositivo de control</string>
|
<string name="serv_wait">Por favor espere, buscando dispositivo de control</string>
|
||||||
<string name="serv_connected">Conectado con el dispositivo de control</string>
|
<string name="serv_connected">Conectado con el dispositivo de control</string>
|
||||||
<string name="serv_fail">Falló la conexión con el dispositivo de control</string>
|
<string name="serv_fail">Falló la conexión con el dispositivo de control</string>
|
||||||
|
<string name="cam_fail">La cámara es null!</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -45,5 +45,6 @@
|
|||||||
<string name="serv_wait">Please wait, looking for control device</string>
|
<string name="serv_wait">Please wait, looking for control device</string>
|
||||||
<string name="serv_connected">Connected with the control device</string>
|
<string name="serv_connected">Connected with the control device</string>
|
||||||
<string name="serv_fail">Could no connect with the control device</string>
|
<string name="serv_fail">Could no connect with the control device</string>
|
||||||
|
<string name="cam_fail">Camera is null!</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@@ -19,6 +19,7 @@ import ve.ucv.ciens.ccg.nxtcam.camera.CameraPreview;
|
|||||||
import ve.ucv.ciens.ccg.nxtcam.network.ImageTransferThread;
|
import ve.ucv.ciens.ccg.nxtcam.network.ImageTransferThread;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.network.LCPThread;
|
import ve.ucv.ciens.ccg.nxtcam.network.LCPThread;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||||
|
import ve.ucv.ciens.ccg.nxtcam.utils.ProjectConstants;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
@@ -109,6 +110,13 @@ public class CamActivity extends Activity{
|
|||||||
// TODO: Destroy the network threads.
|
// TODO: Destroy the network threads.
|
||||||
imThread = null;
|
imThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed(){
|
||||||
|
Intent result = new Intent();
|
||||||
|
setResult(Activity.RESULT_OK, result);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
* My own methods *
|
* My own methods *
|
||||||
@@ -122,7 +130,9 @@ public class CamActivity extends Activity{
|
|||||||
Logger.log_d(TAG, CLASS_NAME + ".startCameraPreview() :: Camera and content view set.");
|
Logger.log_d(TAG, CLASS_NAME + ".startCameraPreview() :: Camera and content view set.");
|
||||||
}else{
|
}else{
|
||||||
Logger.log_wtf(TAG, CLASS_NAME + ".startCameraPreview() :: CAMERA IS NULL!");
|
Logger.log_wtf(TAG, CLASS_NAME + ".startCameraPreview() :: CAMERA IS NULL!");
|
||||||
System.exit(1);
|
Intent result = new Intent();
|
||||||
|
setResult(ProjectConstants.RESULT_CAMERA_FAILURE, result);
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,6 +60,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
private final String TAG = "NXTCAM_MAIN";
|
private final String TAG = "NXTCAM_MAIN";
|
||||||
private final String CLASS_NAME = MainActivity.class.getSimpleName();
|
private final String CLASS_NAME = MainActivity.class.getSimpleName();
|
||||||
private static final int REQUEST_ENABLE_BT = 1;
|
private static final int REQUEST_ENABLE_BT = 1;
|
||||||
|
private static final int REQUEST_CAM_ACTIVITY = 2;
|
||||||
|
|
||||||
// Gui components
|
// Gui components
|
||||||
private Button startButton;
|
private Button startButton;
|
||||||
@@ -73,6 +74,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
// Variables.
|
// Variables.
|
||||||
private boolean wifiOnByMe;
|
private boolean wifiOnByMe;
|
||||||
private boolean btOnByMe;
|
private boolean btOnByMe;
|
||||||
|
private boolean changingActivity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -82,6 +84,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
// Set up fields.
|
// Set up fields.
|
||||||
wifiOnByMe = false;
|
wifiOnByMe = false;
|
||||||
btOnByMe = false;
|
btOnByMe = false;
|
||||||
|
changingActivity = false;
|
||||||
|
|
||||||
// Set up gui components.
|
// Set up gui components.
|
||||||
startButton = (Button)findViewById(R.id.startButton);
|
startButton = (Button)findViewById(R.id.startButton);
|
||||||
@@ -115,11 +118,12 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
public void onPause(){
|
public void onPause(){
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
if(btManager.isBTEnabled() && btOnByMe)
|
if(!changingActivity){
|
||||||
btManager.disableBT();
|
if(btManager.isBTEnabled() && btOnByMe)
|
||||||
|
btManager.disableBT();
|
||||||
if(wifiManager.isWifiEnabled() && wifiOnByMe)
|
if(wifiManager.isWifiEnabled() && wifiOnByMe)
|
||||||
setWifi(false);
|
setWifi(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -142,11 +146,18 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onActivityResult(int request, int result, Intent data){
|
protected void onActivityResult(int request, int result, Intent data){
|
||||||
if(request == REQUEST_ENABLE_BT && result == RESULT_OK){
|
if(request == REQUEST_ENABLE_BT){
|
||||||
if(!wifiManager.isWifiEnabled())
|
if(result == RESULT_OK){
|
||||||
enableWifi();
|
if(!wifiManager.isWifiEnabled())
|
||||||
}else{
|
enableWifi();
|
||||||
Toast.makeText(this, R.string.bt_on_fail, Toast.LENGTH_LONG).show();
|
}else{
|
||||||
|
Toast.makeText(this, R.string.bt_on_fail, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}else if(request == REQUEST_CAM_ACTIVITY){
|
||||||
|
changingActivity = false;
|
||||||
|
if(result == ProjectConstants.RESULT_CAMERA_FAILURE){
|
||||||
|
Toast.makeText(this, R.string.cam_fail, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +171,9 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
if(serverFound){
|
if(serverFound){
|
||||||
Logger.log_d(TAG, CLASS_NAME + ".startCamActivity() :: Launching camera activity.");
|
Logger.log_d(TAG, CLASS_NAME + ".startCamActivity() :: Launching camera activity.");
|
||||||
Intent intent = new Intent(this, CamActivity.class);
|
Intent intent = new Intent(this, CamActivity.class);
|
||||||
|
changingActivity = true;
|
||||||
intent.putExtra("address", ipAddress);
|
intent.putExtra("address", ipAddress);
|
||||||
startActivity(intent);
|
startActivityForResult(intent, REQUEST_CAM_ACTIVITY);
|
||||||
}else{
|
}else{
|
||||||
Logger.log_d(TAG, CLASS_NAME + ".startCamActivity() :: Cannot launch camera activity.");
|
Logger.log_d(TAG, CLASS_NAME + ".startCamActivity() :: Cannot launch camera activity.");
|
||||||
Toast.makeText(this, R.string.badIpToast, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.badIpToast, Toast.LENGTH_SHORT).show();
|
||||||
|
@@ -17,7 +17,10 @@ package ve.ucv.ciens.ccg.nxtcam.utils;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
public abstract class ProjectConstants {
|
public abstract class ProjectConstants {
|
||||||
|
// Network related constants.
|
||||||
public static final int SERVER_UDP_PORT = 8889;
|
public static final int SERVER_UDP_PORT = 8889;
|
||||||
public static final int SERVER_TCP_PORT_1 = 9989;
|
public static final int SERVER_TCP_PORT_1 = 9989;
|
||||||
public static final int SERVER_TCP_PORT_2 = 9990;
|
public static final int SERVER_TCP_PORT_2 = 9990;
|
||||||
@@ -25,5 +28,8 @@ public abstract class ProjectConstants {
|
|||||||
public static final String OUI_LEGO = "00:16:53";
|
public static final String OUI_LEGO = "00:16:53";
|
||||||
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
||||||
|
|
||||||
|
// Activity results.
|
||||||
|
public static final int RESULT_CAMERA_FAILURE = Activity.RESULT_FIRST_USER + 1;
|
||||||
|
|
||||||
public static final boolean DEBUG = true;
|
public static final boolean DEBUG = true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user