Bug 1055595 - Part 2: move code from layout to item view (r=lucasr)

This commit is contained in:
Martyn Haigh 2014-09-05 09:28:24 +01:00
Родитель 40ca757e3d
Коммит aae7fd2298
2 изменённых файлов: 28 добавлений и 27 удалений

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

@ -5,8 +5,10 @@
package org.mozilla.gecko.tabs;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.widget.TabThumbnailWrapper;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
@ -28,4 +30,23 @@ public class TabsLayoutItemView {
close = (ImageButton) view.findViewById(R.id.close);
thumbnailWrapper = (TabThumbnailWrapper) view.findViewById(R.id.wrapper);
}
}
protected void assignValues(Tab tab) {
if (tab == null)
return;
id = tab.getId();
Drawable thumbnailImage = tab.getThumbnail();
if (thumbnailImage != null) {
thumbnail.setImageDrawable(thumbnailImage);
} else {
thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
}
if (thumbnailWrapper != null) {
thumbnailWrapper.setRecording(tab.isRecording());
}
title.setText(tab.getDisplayTitle());
close.setTag(this);
}
}

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

@ -9,22 +9,21 @@ import java.util.ArrayList;
import java.util.List;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.animation.PropertyAnimator.Property;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.ViewHelper;
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.tabs.TabsPanel.TabsLayout;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.PropertyAnimator.Property;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.widget.TwoWayView;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -150,7 +149,7 @@ class TabsListLayout extends TwoWayView
return;
TabsLayoutItemView item = (TabsLayoutItemView) view.getTag();
assignValues(item, tab);
item.assignValues(tab);
break;
}
}
@ -269,31 +268,12 @@ class TabsListLayout extends TwoWayView
}
Tab tab = mTabs.get(position);
assignValues(item, tab);
item.assignValues(tab);
return convertView;
}
}
private void assignValues(TabsLayoutItemView item, Tab tab) {
if (item == null || tab == null)
return;
item.id = tab.getId();
Drawable thumbnailImage = tab.getThumbnail();
if (thumbnailImage != null) {
item.thumbnail.setImageDrawable(thumbnailImage);
} else {
item.thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
}
if (item.thumbnailWrapper != null) {
item.thumbnailWrapper.setRecording(tab.isRecording());
}
item.title.setText(tab.getDisplayTitle());
item.close.setTag(item);
}
private void resetTransforms(View view) {
ViewHelper.setAlpha(view, 1);