diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml
index a706740..cee3b7a 100644
--- a/android/res/values/strings.xml
+++ b/android/res/values/strings.xml
@@ -10,7 +10,8 @@
Connecting...
Disconnecting...
Your phone is now connected to Chrome.
- Error! Unable to establish connection.
+ Error: Unable to connect.
+ Error: Google Apps accounts not supported.
Finish
Please set your link action preference:
Automatically launch links
@@ -18,7 +19,7 @@
Your phone is connected to Chrome using this account:
Link action preference:
Disconnect phone
- Error! Unable to disconnect.
+ Error: Unable to disconnect.
Help
Chrome to Phone lets you easily share links, maps, and selected phone numbers and text
diff --git a/android/src/com/google/android/apps/chrometophone/DeviceRegistrar.java b/android/src/com/google/android/apps/chrometophone/DeviceRegistrar.java
index a068cad..57da898 100644
--- a/android/src/com/google/android/apps/chrometophone/DeviceRegistrar.java
+++ b/android/src/com/google/android/apps/chrometophone/DeviceRegistrar.java
@@ -49,6 +49,12 @@ import android.util.Log;
* Will pass the registration id and user, authenticating with app engine.
*/
public class DeviceRegistrar {
+ public static final String STATUS_EXTRA = "Status";
+ public static final int REGISTERED_STATUS = 1;
+ public static final int AUTH_ERROR_STATUS = 2;
+ public static final int UNREGISTERED_STATUS = 3;
+ public static final int ERROR_STATUS = 4;
+
private static final String TAG = "DeviceRegistrar";
static final String SENDER_ID = "stp.chrome@gmail.com";
static final String BASE_URL = "https://chrometophone.appspot.com";
@@ -64,6 +70,7 @@ public class DeviceRegistrar {
final String deviceRegistrationID) {
new Thread(new Runnable() {
public void run() {
+ Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
try {
HttpResponse res = makeRequest(context, deviceRegistrationID, REGISTER_URL);
if (res.getStatusLine().getStatusCode() == 200) {
@@ -71,16 +78,21 @@ public class DeviceRegistrar {
SharedPreferences.Editor editor = settings.edit();
editor.putString("deviceRegistrationID", deviceRegistrationID);
editor.commit();
+ updateUIIntent.putExtra(STATUS_EXTRA, REGISTERED_STATUS);
+ } else if (res.getStatusLine().getStatusCode() == 400) {
+ updateUIIntent.putExtra(STATUS_EXTRA, AUTH_ERROR_STATUS);
} else {
Log.w(TAG, "Registration error " +
String.valueOf(res.getStatusLine().getStatusCode()));
+ updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
}
- context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI"));
+ context.sendBroadcast(updateUIIntent);
} catch (PendingAuthException e) {
// Ignore - we'll reregister later
} catch (Exception e) {
Log.w(TAG, "Registration error " + e.getMessage());
- context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI"));
+ updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
+ context.sendBroadcast(updateUIIntent);
}
}
}).start();
@@ -88,6 +100,7 @@ public class DeviceRegistrar {
public static void unregisterWithServer(final Context context,
final String deviceRegistrationID) {
+ Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
try {
HttpResponse res = makeRequest(context, deviceRegistrationID, UNREGISTER_URL);
if (res.getStatusLine().getStatusCode() == 200) {
@@ -95,16 +108,19 @@ public class DeviceRegistrar {
SharedPreferences.Editor editor = settings.edit();
editor.remove("deviceRegistrationID");
editor.commit();
+ updateUIIntent.putExtra(STATUS_EXTRA, UNREGISTERED_STATUS);
} else {
Log.w(TAG, "Unregistration error " +
String.valueOf(res.getStatusLine().getStatusCode()));
+ updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
}
} catch (Exception e) {
+ updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
Log.w(TAG, "Unegistration error " + e.getMessage());
}
// Update dialog activity
- context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI"));
+ context.sendBroadcast(updateUIIntent);
}
private static HttpResponse makeRequest(Context context, String deviceRegistrationID,
diff --git a/android/src/com/google/android/apps/chrometophone/MainActivity.java b/android/src/com/google/android/apps/chrometophone/MainActivity.java
index 62bcd83..2e5032f 100644
--- a/android/src/com/google/android/apps/chrometophone/MainActivity.java
+++ b/android/src/com/google/android/apps/chrometophone/MainActivity.java
@@ -289,34 +289,28 @@ public class MainActivity extends Activity {
return result;
}
- private void handleConnectingUpdate() {
- SharedPreferences prefs = Prefs.get(this);
- String deviceRegistrationID = prefs.getString("deviceRegistrationID", null);
-
- if (deviceRegistrationID == null) { // registration error
+ private void handleConnectingUpdate(int status) {
+ if (status == DeviceRegistrar.REGISTERED_STATUS) {
+ setScreenContent(R.layout.select_launch_mode);
+ } else {
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
progressBar.setVisibility(ProgressBar.INVISIBLE);
TextView textView = (TextView) findViewById(R.id.connecting_text);
- textView.setText(R.string.connect_error_text);
+ textView.setText(status == DeviceRegistrar.AUTH_ERROR_STATUS ? R.string.auth_error_text :
+ R.string.connect_error_text);
Button prevButton = (Button) findViewById(R.id.prev);
prevButton.setEnabled(true);
- Button nextButton = (Button) findViewById(R.id.prev);
+ Button nextButton = (Button) findViewById(R.id.next);
nextButton.setEnabled(true);
-
- } else { // registered successfully
- setScreenContent(R.layout.select_launch_mode);
}
}
- private void handleDisconnectingUpdate() {
- SharedPreferences prefs = Prefs.get(this);
- String deviceRegistrationID = prefs.getString("deviceRegistrationID", null);
-
- if (deviceRegistrationID == null) { // unregistered successfully
+ private void handleDisconnectingUpdate(int status) {
+ if (status == DeviceRegistrar.UNREGISTERED_STATUS) {
setScreenContent(R.layout.intro);
- } else { // unregistration error
+ } else {
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
progressBar.setVisibility(ProgressBar.INVISIBLE);
@@ -332,9 +326,11 @@ public class MainActivity extends Activity {
@Override
public void onReceive(Context context, Intent intent) {
if (mScreenId == R.layout.select_account) {
- handleConnectingUpdate();
+ handleConnectingUpdate(intent.getIntExtra(
+ DeviceRegistrar.STATUS_EXTRA, DeviceRegistrar.ERROR_STATUS));
} else if (mScreenId == R.layout.connected) {
- handleDisconnectingUpdate();
+ handleDisconnectingUpdate(intent.getIntExtra(
+ DeviceRegistrar.STATUS_EXTRA, DeviceRegistrar.ERROR_STATUS));
}
}
};