99import org .mozilla .gecko .gfx .LayerView ;
1010import org .mozilla .gecko .util .HardwareUtils ;
1111
12+ import org .mozilla .gecko .util .ThreadUtils ;
13+ import org .mozilla .gecko .util .UiAsyncTask ;
14+
1215import android .content .Context ;
16+ import android .content .SharedPreferences ;
1317import android .content .res .Resources ;
1418import android .graphics .Bitmap ;
1519import android .graphics .Rect ;
5155public class BrowserToolbar implements ViewSwitcher .ViewFactory ,
5256 Tabs .OnTabsChangedListener ,
5357 GeckoMenu .ActionItemBarPresenter ,
54- Animation .AnimationListener {
58+ Animation .AnimationListener ,
59+ SharedPreferences .OnSharedPreferenceChangeListener {
5560 private static final String LOGTAG = "GeckoToolbar" ;
61+ public static final String PREFS_NAME = "BrowserToolbar" ;
62+ public static final String PREFS_SHOW_URL = "ShowUrl" ;
5663 private GeckoRelativeLayout mLayout ;
5764 private LayoutParams mAwesomeBarParams ;
5865 private View mAwesomeBarContent ;
@@ -115,6 +122,8 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
115122
116123 private static final int FORWARD_ANIMATION_DURATION = 450 ;
117124
125+ private boolean mShowUrl ;
126+
118127 public BrowserToolbar (BrowserApp activity ) {
119128 // BrowserToolbar is attached to BrowserApp only.
120129 mActivity = activity ;
@@ -125,6 +134,27 @@ public BrowserToolbar(BrowserApp activity) {
125134 mAnimateSiteSecurity = true ;
126135
127136 mAnimatingEntry = false ;
137+ mShowUrl = false ;
138+
139+ (new UiAsyncTask <Void , Void , Void >(ThreadUtils .getBackgroundHandler ()) {
140+ @ Override
141+ public synchronized Void doInBackground (Void ... params ) {
142+ SharedPreferences settings = mActivity .getSharedPreferences (PREFS_NAME , 0 );
143+ settings .registerOnSharedPreferenceChangeListener (BrowserToolbar .this );
144+ mShowUrl = settings .getBoolean (PREFS_SHOW_URL , false );
145+ return null ;
146+ }
147+
148+ @ Override
149+ public void onPostExecute (Void v ) {
150+ if (mShowUrl ) {
151+ Tab tab = Tabs .getInstance ().getSelectedTab ();
152+ if (tab != null ) {
153+ setTitle (tab .getURL ());
154+ }
155+ }
156+ }
157+ }).execute ();
128158 }
129159
130160 public void from (RelativeLayout layout ) {
@@ -431,7 +461,7 @@ public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
431461 switch (msg ) {
432462 case TITLE :
433463 if (Tabs .getInstance ().isSelectedTab (tab )) {
434- setTitle (tab .getDisplayTitle ());
464+ setTitle (mShowUrl ? tab . getURL () : tab .getDisplayTitle ());
435465 }
436466 break ;
437467 case START :
@@ -451,7 +481,7 @@ public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
451481 updateForwardButton (tab .canDoForward ());
452482 setProgressVisibility (false );
453483 // Reset the title in case we haven't navigated to a new page yet.
454- setTitle (tab .getDisplayTitle ());
484+ setTitle (mShowUrl ? tab . getURL () : tab .getDisplayTitle ());
455485 }
456486 break ;
457487 case RESTORED :
@@ -1189,7 +1219,7 @@ public void refresh() {
11891219 Tab tab = Tabs .getInstance ().getSelectedTab ();
11901220 if (tab != null ) {
11911221 String url = tab .getURL ();
1192- setTitle (tab .getDisplayTitle ());
1222+ setTitle (mShowUrl ? tab . getURL () : tab .getDisplayTitle ());
11931223 setFavicon (tab .getFavicon ());
11941224 setProgressVisibility (tab .getState () == Tab .STATE_LOADING );
11951225 setSecurityMode (tab .getSecurityMode ());
@@ -1237,4 +1267,14 @@ public boolean closeOptionsMenu() {
12371267
12381268 return true ;
12391269 }
1270+
1271+ public void onSharedPreferenceChanged (SharedPreferences sharedPreferences , String key ) {
1272+ if (key .equals (PREFS_SHOW_URL )) {
1273+ mShowUrl = sharedPreferences .getBoolean (key , false );
1274+ Tab tab = Tabs .getInstance ().getSelectedTab ();
1275+ if (tab != null ) {
1276+ setTitle (mShowUrl ? tab .getURL () : tab .getDisplayTitle ());
1277+ }
1278+ }
1279+ }
12401280}
0 commit comments