Bug 1366704 - Part 3: Support search suggestion visual refresh in private mode. r=sebastian,walkingice

MozReview-Commit-ID: 1Ccq1wDMxMX

--HG--
extra : rebase_source : 6e23de9f94ff39e6aed19367f469d7e123042a9b
This commit is contained in:
jwu 2017-07-06 16:54:44 +08:00
Родитель e67394ff6e
Коммит e5b6464756
10 изменённых файлов: 134 добавлений и 19 удалений

Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<item android:drawable="@android:color/transparent"/>
</selector>

Просмотреть файл

@ -19,7 +19,9 @@ import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.widget.FaviconView;
import org.mozilla.gecko.widget.FlowLayout;
import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
import org.mozilla.gecko.widget.themed.ThemedRelativeLayout;
import org.mozilla.gecko.widget.themed.ThemedTextView;
import android.content.Context;
import android.content.SharedPreferences;
@ -35,7 +37,6 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
@ -49,8 +50,8 @@ class SearchEngineRow extends ThemedRelativeLayout {
// Inner views
private final FlowLayout mSuggestionView;
private final FaviconView mIconView;
private final LinearLayout mUserEnteredView;
private final TextView mUserEnteredTextView;
private final ThemedLinearLayout mUserEnteredView;
private final ThemedTextView mUserEnteredTextView;
// Inflater used when updating from suggestions
private final LayoutInflater mInflater;
@ -139,10 +140,10 @@ class SearchEngineRow extends ThemedRelativeLayout {
mIconView = (FaviconView) findViewById(R.id.suggestion_icon);
// User-entered search term is first suggestion
mUserEnteredView = (LinearLayout) findViewById(R.id.suggestion_user_entered);
mUserEnteredView = (ThemedLinearLayout) findViewById(R.id.suggestion_user_entered);
mUserEnteredView.setOnClickListener(mClickListener);
mUserEnteredTextView = (TextView) findViewById(R.id.suggestion_text);
mUserEnteredTextView = (ThemedTextView) findViewById(R.id.suggestion_text);
mSearchHistorySuggestionIcon = DrawableUtil.tintDrawableWithColorRes(getContext(), R.drawable.icon_most_recent_empty, R.color.tabs_tray_icon_grey);
// Suggestion limits
@ -480,4 +481,20 @@ class SearchEngineRow extends ThemedRelativeLayout {
suggestion.setDuplicateParentStateEnabled(false);
suggestion.refreshDrawableState();
}
@Override
public void setPrivateMode(boolean isPrivate) {
super.setPrivateMode(isPrivate);
mUserEnteredView.setPrivateMode(isPrivate);
mUserEnteredTextView.setPrivateMode(isPrivate);
final int childCount = mSuggestionView.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = mSuggestionView.getChildAt(i);
if (child instanceof SuggestionItem) {
((SuggestionItem) child).setPrivateMode(isPrivate);
}
}
}
}

Просмотреть файл

@ -3,8 +3,12 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<item android:color="@color/photon_search_item_text" />
<item android:color="@color/photon_search_item_text_private"
gecko:state_private="true"/>
<item android:color="@color/photon_search_item_text"/>
</selector>

Просмотреть файл

@ -3,8 +3,14 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<!-- private browsing mode -->
<item android:color="@color/photon_text_main_private"
gecko:state_private="true"/>
<!-- normal mode -->
<item android:color="@color/photon_text_main"/>
</selector>

Просмотреть файл

@ -3,8 +3,14 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<!-- private browsing mode -->
<item android:color="@color/photon_text_secondary_private"
gecko:state_private="true"/>
<!-- normal mode -->
<item android:color="@color/photon_text_secondary"/>
</selector>

Просмотреть файл

@ -2,7 +2,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<item android:drawable="@color/photon_content_bg_private"
gecko:state_private="true"/>
<item android:drawable="@color/photon_content_bg"/>
</selector>

Просмотреть файл

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@color/photon_content_bg_private_pressed"/>
<item android:drawable="@color/photon_content_bg_private"/>
</selector>

Просмотреть файл

@ -2,10 +2,18 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<item android:state_pressed="true"
android:drawable="@color/photon_search_suggestion_box_pressed"/>
<item android:drawable="@color/photon_search_suggestion_box_private_pressed"
android:state_pressed="true"
gecko:state_private="true"/>
<item android:drawable="@color/photon_search_suggestion_box_private"
gecko:state_private="true"/>
<item android:drawable="@color/photon_search_suggestion_box_pressed"
android:state_pressed="true"/>
<item android:drawable="@color/photon_search_suggestion_box"/>
</selector>

Просмотреть файл

@ -76,7 +76,8 @@ import android.widget.TextView;
*/
public class BrowserSearch extends HomeFragment
implements BundleEventListener,
SearchEngineBar.OnSearchBarClickListener {
SearchEngineBar.OnSearchBarClickListener,
Tabs.OnTabsChangedListener {
@RobocopTarget
public interface SuggestClientFactory {
@ -305,6 +306,7 @@ public class BrowserSearch extends HomeFragment
EventDispatcher.getInstance().unregisterUiThreadListener(this,
"SearchEngines:Data");
Tabs.unregisterOnTabsChangedListener(this);
mSearchEngineBar.setAdapter(null);
mSearchEngineBar = null;
@ -402,9 +404,14 @@ public class BrowserSearch extends HomeFragment
}
});
final Tab tab = Tabs.getInstance().getSelectedTab();
final boolean isPrivate = (tab != null && tab.isPrivate());
mList.setPrivateMode(isPrivate);
registerForContextMenu(mList);
EventDispatcher.getInstance().registerUiThreadListener(this,
"SearchEngines:Data");
Tabs.registerOnTabsChangedListener(this);
mSearchEngineBar.setOnSearchBarClickListener(this);
}
@ -471,6 +478,17 @@ public class BrowserSearch extends HomeFragment
}
}
@Override
public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
if (tab == null) {
return;
}
if (msg == Tabs.TabEvents.SELECTED) {
mList.setPrivateMode(tab.isPrivate());
}
}
@Override
protected void load() {
SearchLoader.init(getLoaderManager(), LOADER_ID_SEARCH, mCursorLoaderCallbacks, mSearchTerm);
@ -1152,6 +1170,9 @@ public class BrowserSearch extends HomeFragment
public void bindView(View view, Context context, int position) {
final int type = getItemViewType(position);
final Tab tab = Tabs.getInstance().getSelectedTab();
final boolean isPrivate = (tab != null && tab.isPrivate());
if (type == ROW_SEARCH || type == ROW_SUGGEST) {
final SearchEngineRow row = (SearchEngineRow) view;
row.setOnUrlOpenListener(mUrlOpenListener);
@ -1161,6 +1182,7 @@ public class BrowserSearch extends HomeFragment
final SearchEngine engine = mSearchEngines.get(position);
row.updateSuggestions(mSuggestionsEnabled, engine, mSearchHistorySuggestions);
row.setPrivateMode(isPrivate);
} else {
// Account for the search engines
position -= getPrimaryEngineCount();
@ -1168,6 +1190,7 @@ public class BrowserSearch extends HomeFragment
final Cursor c = getCursor(position);
final TwoLinePageRow row = (TwoLinePageRow) view;
row.updateFromCursor(c);
row.setPrivateMode(isPrivate);
}
}
}
@ -1291,6 +1314,10 @@ public class BrowserSearch extends HomeFragment
public HomeSearchListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final Tab tab = Tabs.getInstance().getSelectedTab();
final boolean isPrivate = (tab != null && tab.isPrivate());
setSelector(isPrivate);
}
@Override
@ -1302,5 +1329,19 @@ public class BrowserSearch extends HomeFragment
return super.onTouchEvent(event);
}
@Override
public void setPrivateMode(boolean isPrivate) {
final boolean modeChanged = isPrivateMode() != isPrivate;
if (modeChanged) {
setSelector(isPrivate);
}
super.setPrivateMode(isPrivate);
}
private void setSelector(boolean isPrivate) {
setSelector(isPrivate ? R.drawable.search_list_selector_private : R.drawable.search_list_selector);
}
}
}

Просмотреть файл

@ -17,7 +17,6 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
@ -33,14 +32,15 @@ import org.mozilla.gecko.reader.ReaderModeUtils;
import org.mozilla.gecko.reader.SavedReaderViewHelper;
import org.mozilla.gecko.widget.FaviconView;
import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
import org.mozilla.gecko.widget.themed.ThemedTextView;
public class TwoLinePageRow extends ThemedLinearLayout
implements Tabs.OnTabsChangedListener {
protected static final int NO_ICON = 0;
private final TextView mTitle;
private final TextView mUrl;
private final ThemedTextView mTitle;
private final ThemedTextView mUrl;
private final ImageView mStatusIcon;
private int mSwitchToTabIconId;
@ -68,8 +68,8 @@ public class TwoLinePageRow extends ThemedLinearLayout
// Merge layouts lose their padding, so set it dynamically.
ViewCompat.setPaddingRelative(this, 0, 0, (int) getResources().getDimension(R.dimen.page_row_edge_padding), 0);
mTitle = (TextView) findViewById(R.id.title);
mUrl = (TextView) findViewById(R.id.url);
mTitle = (ThemedTextView) findViewById(R.id.title);
mUrl = (ThemedTextView) findViewById(R.id.url);
mStatusIcon = (ImageView) findViewById(R.id.status_icon_bookmark);
mSwitchToTabIconId = NO_ICON;
@ -290,6 +290,14 @@ public class TwoLinePageRow extends ThemedLinearLayout
updateDisplayedUrl(url, hasReaderCacheItem);
}
@Override
public void setPrivateMode(boolean isPrivate) {
super.setPrivateMode(isPrivate);
mTitle.setPrivateMode(isPrivate);
mUrl.setPrivateMode(isPrivate);
}
/**
* Update the data displayed by this row.
* <p>