OSDN Git Service

Remove the old network status intent.
authorPatrick Scott <phanna@android.com>
Wed, 16 Sep 2009 14:00:17 +0000 (10:00 -0400)
committerPatrick Scott <phanna@android.com>
Thu, 17 Sep 2009 12:38:56 +0000 (08:38 -0400)
Use NetworkInfo to see if we are connected to a network instead of the intent
extra. Update the network dialog text and refactor the alert dialog creation to
reuse code.

AndroidManifest.xml
res/values/strings.xml
src/com/android/browser/BrowserActivity.java

index b23f113..d25a2ac 100644 (file)
             </intent-filter>
             <meta-data android:name="android.app.searchable"
                     android:resource="@xml/searchable" />
-            <intent-filter>
-                <action android:name="android.net.http.NETWORK_STATE" />
-                <action android:name="android.intent.action.PROXY_CHANGE" />
-            </intent-filter>
         </activity>
 
         <activity android:name="CombinedBookmarkHistoryActivity" android:label=""
index 3555e86..407532a 100644 (file)
     <!-- Dialog box title -->
     <string name="loadSuspendedTitle">No network connection</string>
     <!-- Dialog box message -->
-    <string name="loadSuspended">The page will continue loading after connection has been restored.</string>
+    <string name="loadSuspended">The Browser cannot load this page because there
+      is no internet connection.</string>
     <!-- Menu item -->
     <string name="clear_history">Clear history</string>
     <!-- History screen title; appears in title bar -->
index bee8175..c8a717b 100644 (file)
@@ -56,6 +56,7 @@ import android.graphics.drawable.Drawable;
 import android.hardware.SensorListener;
 import android.hardware.SensorManager;
 import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
 import android.net.Uri;
 import android.net.WebAddress;
 import android.net.http.EventHandler;
@@ -356,9 +357,11 @@ public class BrowserActivity extends Activity
                 public void onReceive(Context context, Intent intent) {
                     if (intent.getAction().equals(
                             ConnectivityManager.CONNECTIVITY_ACTION)) {
-                        boolean down = intent.getBooleanExtra(
-                                ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
-                        onNetworkToggle(!down);
+                        NetworkInfo info =
+                                (NetworkInfo) intent.getParcelableExtra(
+                                        ConnectivityManager.EXTRA_NETWORK_INFO);
+                        onNetworkToggle(
+                                (info != null) ? info.isConnected() : false);
                     }
                 }
             };
@@ -2430,13 +2433,7 @@ public class BrowserActivity extends Activity
             }
             updateInLoadMenuItems();
             if (!mIsNetworkUp) {
-                if ( mAlertDialog == null) {
-                    mAlertDialog = new AlertDialog.Builder(BrowserActivity.this)
-                        .setTitle(R.string.loadSuspendedTitle)
-                        .setMessage(R.string.loadSuspended)
-                        .setPositiveButton(R.string.ok, null)
-                        .show();
-                }
+                createAndShowNetworkDialog();
                 if (view != null) {
                     view.setNetworkAvailable(false);
                 }
@@ -3956,13 +3953,9 @@ public class BrowserActivity extends Activity
             }
         } else {
             mIsNetworkUp = false;
-            if (mInLoad && mAlertDialog == null) {
-                mAlertDialog = new AlertDialog.Builder(this)
-                        .setTitle(R.string.loadSuspendedTitle)
-                        .setMessage(R.string.loadSuspended)
-                        .setPositiveButton(R.string.ok, null)
-                        .show();
-            }
+            if (mInLoad) {
+                createAndShowNetworkDialog();
+           }
         }
         WebView w = mTabControl.getCurrentWebView();
         if (w != null) {
@@ -3970,6 +3963,18 @@ public class BrowserActivity extends Activity
         }
     }
 
+    // This method shows the network dialog alerting the user that the net is
+    // down. It will only show the dialog if mAlertDialog is null.
+    private void createAndShowNetworkDialog() {
+        if (mAlertDialog == null) {
+            mAlertDialog = new AlertDialog.Builder(this)
+                    .setTitle(R.string.loadSuspendedTitle)
+                    .setMessage(R.string.loadSuspended)
+                    .setPositiveButton(R.string.ok, null)
+                    .show();
+        }
+    }
+
     @Override
     protected void onActivityResult(int requestCode, int resultCode,
                                     Intent intent) {