OSDN Git Service

When reverting the voice title bar, display the url.
[android-x86/packages-apps-Browser.git] / src / com / android / browser / BrowserActivity.java
index fc337f9..2469408 100644 (file)
@@ -73,6 +73,7 @@ import android.text.TextUtils;
 import android.text.format.DateFormat;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.util.Patterns;
 import android.view.ContextMenu;
 import android.view.Gravity;
 import android.view.KeyEvent;
@@ -110,12 +111,9 @@ import android.accounts.AuthenticatorException;
 import android.accounts.OperationCanceledException;
 import android.accounts.AccountManagerCallback;
 
-import com.android.common.Patterns;
 import com.android.common.Search;
 import com.android.common.speech.LoggingEvents;
 
-import com.google.android.gsf.GoogleLoginServiceConstants;
-
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
@@ -157,13 +155,20 @@ public class BrowserActivity extends Activity
     private Account[] mAccountsGoogle;
     private Account[] mAccountsPreferHosted;
 
+    // XXX: These constants should be exposed through some public api. Hardcode
+    // the values for now until some solution for gsf can be worked out.
+    // http://b/issue?id=2425179
+    private static final String ACCOUNT_TYPE = "com.google";
+    private static final String FEATURE_LEGACY_GOOGLE = "legacy_google";
+    private static final String FEATURE_LEGACY_HOSTED_OR_GOOGLE =
+            "legacy_hosted_or_google";
+
     private void startReadOfGoogleAccounts() {
         mAccountsGoogle = null;
         mAccountsPreferHosted = null;
 
         AccountManager.get(this).getAccountsByTypeAndFeatures(
-                GoogleLoginServiceConstants.ACCOUNT_TYPE,
-                new String[]{GoogleLoginServiceConstants.FEATURE_LEGACY_HOSTED_OR_GOOGLE},
+                ACCOUNT_TYPE, new String[]{ FEATURE_LEGACY_HOSTED_OR_GOOGLE },
                 this, null);
     }
 
@@ -174,8 +179,7 @@ public class BrowserActivity extends Activity
                 mAccountsGoogle = accountManagerFuture.getResult();
 
                 AccountManager.get(this).getAccountsByTypeAndFeatures(
-                        GoogleLoginServiceConstants.ACCOUNT_TYPE,
-                        new String[]{GoogleLoginServiceConstants.FEATURE_LEGACY_GOOGLE},
+                        ACCOUNT_TYPE, new String[]{ FEATURE_LEGACY_GOOGLE },
                         this, null);
             } else {
                 mAccountsPreferHosted = accountManagerFuture.getResult();
@@ -302,6 +306,14 @@ public class BrowserActivity extends Activity
         PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser");
 
+        // Find out if the network is currently up.
+        ConnectivityManager cm = (ConnectivityManager) getSystemService(
+                Context.CONNECTIVITY_SERVICE);
+        NetworkInfo info = cm.getActiveNetworkInfo();
+        if (info != null) {
+            mIsNetworkUp = info.isAvailable();
+        }
+
         /* enables registration for changes in network status from
            http stack */
         mNetworkStateChangedFilter = new IntentFilter();
@@ -718,11 +730,11 @@ public class BrowserActivity extends Activity
                 url = intent.getStringExtra(SearchManager.QUERY);
                 if (url != null) {
                     mLastEnteredUrl = url;
-                    Browser.updateVisitedHistory(mResolver, url, false);
                     // In general, we shouldn't modify URL from Intent.
                     // But currently, we get the user-typed URL from search box as well.
                     url = fixUrl(url);
                     url = smartUrlFilter(url);
+                    Browser.updateVisitedHistory(mResolver, url, false);
                     String searchSource = "&source=android-" + GOOGLE_SEARCH_SOURCE_SUGGEST + "&";
                     if (url.contains(searchSource)) {
                         String source = null;
@@ -751,8 +763,8 @@ public class BrowserActivity extends Activity
         mTitleBar.setInVoiceMode(false);
         mFakeTitleBar.setInVoiceMode(false);
 
-        mTitleBar.setDisplayTitle(mTitle);
-        mFakeTitleBar.setDisplayTitle(mTitle);
+        mTitleBar.setDisplayTitle(mUrl);
+        mFakeTitleBar.setDisplayTitle(mUrl);
     }
     /* package */ static String fixUrl(String inUrl) {
         // FIXME: Converting the url to lower case
@@ -1539,6 +1551,7 @@ public class BrowserActivity extends Activity
                 }
                 mFindDialog.setWebView(getTopWindow());
                 mFindDialog.show();
+                getTopWindow().setFindIsUp(true);
                 mMenuState = EMPTY_MENU;
                 break;
 
@@ -2149,7 +2162,7 @@ public class BrowserActivity extends Activity
         resetTitleIconAndProgress();
     }
 
-    private void goBackOnePageOrQuit() {
+    /* package */ void goBackOnePageOrQuit() {
         Tab current = mTabControl.getCurrentTab();
         if (current == null) {
             /*
@@ -2461,7 +2474,7 @@ public class BrowserActivity extends Activity
      * an {@link Intent} to launch the Activity chooser.
      * @param c Context used to launch a new Activity.
      * @param title Title of the page.  Stored in the Intent with
-     *          {@link Browser#EXTRA_SHARE_TITLE}
+     *          {@link Intent#EXTRA_SUBJECT}
      * @param url URL of the page.  Stored in the Intent with
      *          {@link Intent#EXTRA_TEXT}
      * @param favicon Bitmap of the favicon for the page.  Stored in the Intent
@@ -2474,7 +2487,7 @@ public class BrowserActivity extends Activity
         Intent send = new Intent(Intent.ACTION_SEND);
         send.setType("text/plain");
         send.putExtra(Intent.EXTRA_TEXT, url);
-        send.putExtra(Browser.EXTRA_SHARE_TITLE, title);
+        send.putExtra(Intent.EXTRA_SUBJECT, title);
         send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon);
         send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot);
         try {
@@ -2822,12 +2835,19 @@ public class BrowserActivity extends Activity
                     hideFakeTitleBar();
                 }
             }
-        } else if (!mInLoad) {
-            // onPageFinished may have already been called but a subframe is
-            // still loading and updating the progress. Reset mInLoad and update
-            // the menu items.
-            mInLoad = true;
-            updateInLoadMenuItems();
+        } else {
+            if (!mInLoad) {
+                // onPageFinished may have already been called but a subframe is
+                // still loading and updating the progress. Reset mInLoad and
+                // update the menu items.
+                mInLoad = true;
+                updateInLoadMenuItems();
+            }
+            // When the page first begins to load, the Activity may still be
+            // paused, in which case showFakeTitleBar will do nothing.  Call
+            // again as the page continues to load so that it will be shown.
+            // (Calling it will the fake title bar is already showing will also
+            // do nothing.
             if (!mOptionsMenuOpen || mIconView) {
                 // This page has begun to load, so show the title bar
                 showFakeTitleBar();
@@ -3405,14 +3425,14 @@ public class BrowserActivity extends Activity
         }
 
         // issued on:
-        String issuedOn = reformatCertificateDate(
-            certificate.getValidNotBefore());
+        String issuedOn = formatCertificateDate(
+            certificate.getValidNotBeforeDate());
         ((TextView) certificateView.findViewById(R.id.issued_on))
             .setText(issuedOn);
 
         // expires on:
-        String expiresOn = reformatCertificateDate(
-            certificate.getValidNotAfter());
+        String expiresOn = formatCertificateDate(
+            certificate.getValidNotAfterDate());
         ((TextView) certificateView.findViewById(R.id.expires_on))
             .setText(expiresOn);
 
@@ -3420,31 +3440,19 @@ public class BrowserActivity extends Activity
     }
 
     /**
-     * Re-formats the certificate date (Date.toString()) string to
-     * a properly localized date string.
+     * Formats the certificate date to a properly localized date string.
      * @return Properly localized version of the certificate date string and
-     * the original certificate date string if fails to localize.
-     * If the original string is null, returns an empty string "".
+     * the "" if it fails to localize.
      */
-    private String reformatCertificateDate(String certificateDate) {
-      String reformattedDate = null;
-
-      if (certificateDate != null) {
-          Date date = null;
-          try {
-              date = java.text.DateFormat.getInstance().parse(certificateDate);
-          } catch (ParseException e) {
-              date = null;
-          }
-
-          if (date != null) {
-              reformattedDate =
-                  DateFormat.getDateFormat(this).format(date);
-          }
+    private String formatCertificateDate(Date certificateDate) {
+      if (certificateDate == null) {
+          return "";
       }
-
-      return reformattedDate != null ? reformattedDate :
-          (certificateDate != null ? certificateDate : "");
+      String formattedDate = DateFormat.getDateFormat(this).format(certificateDate);
+      if (formattedDate == null) {
+          return "";
+      }
+      return formattedDate;
     }
 
     /**