Bug 1203122 - Current tab is not selected in tab tray on gingerbread devices; r=mcomella

This commit is contained in:
Martyn Haigh 2015-09-22 15:01:59 +01:00
parent 614172ce7a
commit f9531b73f3
3 changed files with 25 additions and 14 deletions

View File

@ -11,6 +11,7 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import android.support.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;
@ -314,6 +315,7 @@ public class Tabs implements GeckoEventListener {
*
* @return the selected tab, or null if no tabs exist
*/
@Nullable
public Tab getSelectedTab() {
return mSelectedTab;
}

View File

@ -51,6 +51,7 @@ import java.util.List;
class TabsGridLayout extends GridView
implements TabsLayout,
Tabs.OnTabsChangedListener {
private static final String LOGTAG = "Gecko" + TabsGridLayout.class.getSimpleName();
public static final int ANIM_DELAY_MULTIPLE_MS = 20;
@ -266,15 +267,26 @@ class TabsGridLayout extends GridView
*
* @param selected position of the selected tab
*/
private void updateSelectedStyle(int selected) {
for (int i = 0; i < tabsAdapter.getCount(); i++) {
// setItemChecked doesn't exist until API 11, despite what the API docs say!
if (AppConstants.Versions.feature11Plus) {
setItemChecked(i, (i == selected));
} else {
setSelection(i);
private void updateSelectedStyle(final int selected) {
post(new Runnable() {
@Override
public void run() {
final int displayCount = getChildCount();
for (int i = getFirstVisiblePosition(); i <= getLastVisiblePosition(); i++) {
final Tab tab = tabsAdapter.getItem(i);
final boolean checked = displayCount == 1 || i == selected;
final View tabView = getViewForTab(tab);
if (tabView != null) {
((TabsLayoutItemView) tabView).setChecked(checked);
}
// setItemChecked doesn't exist until API 11, despite what the API docs say!
if (AppConstants.Versions.feature11Plus) {
setItemChecked(i, checked);
}
}
}
}
});
}
private void refreshTabsData() {

View File

@ -5,21 +5,16 @@
package org.mozilla.gecko.tabs;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.widget.TabThumbnailWrapper;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.TouchDelegate;
import android.view.View;
@ -136,6 +131,8 @@ public class TabsLayoutItemView extends LinearLayout
mTabId = tab.getId();
setChecked(Tabs.getInstance().isSelectedTab(tab));
Drawable thumbnailImage = tab.getThumbnail();
mThumbnail.setImageDrawable(thumbnailImage);