OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.ntp; | 5 package org.chromium.chrome.browser.ntp; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.drawable.BitmapDrawable; | 10 import android.graphics.drawable.BitmapDrawable; |
(...skipping 14 matching lines...) Expand all Loading... |
25 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | 25 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; |
26 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession; | 26 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession; |
27 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionTab; | 27 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionTab; |
28 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionWindow
; | 28 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionWindow
; |
29 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge.RecentlyClosedTab; | 29 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge.RecentlyClosedTab; |
30 import org.chromium.ui.WindowOpenDisposition; | 30 import org.chromium.ui.WindowOpenDisposition; |
31 import org.chromium.ui.base.DeviceFormFactor; | 31 import org.chromium.ui.base.DeviceFormFactor; |
32 | 32 |
33 import java.util.ArrayList; | 33 import java.util.ArrayList; |
34 import java.util.List; | 34 import java.util.List; |
35 import java.util.concurrent.TimeUnit; | |
36 | 35 |
37 /** | 36 /** |
38 * Row adapter for presenting recently closed tabs, synced tabs from other devic
es, the sync or | 37 * Row adapter for presenting recently closed tabs, synced tabs from other devic
es, the sync or |
39 * sign in promo, and currently open tabs (only in document mode) in a grouped l
ist view. | 38 * sign in promo, and currently open tabs (only in document mode) in a grouped l
ist view. |
40 */ | 39 */ |
41 public class RecentTabsRowAdapter extends BaseExpandableListAdapter { | 40 public class RecentTabsRowAdapter extends BaseExpandableListAdapter { |
42 private static final int MAX_NUM_FAVICONS_TO_CACHE = 256; | 41 private static final int MAX_NUM_FAVICONS_TO_CACHE = 256; |
43 | 42 |
44 private enum ChildType { | 43 private enum ChildType { |
45 NONE, DEFAULT_CONTENT, SYNC_PROMO | 44 NONE, DEFAULT_CONTENT, SYNC_PROMO |
46 } | 45 } |
47 | 46 |
48 private enum GroupType { | 47 private enum GroupType { |
49 CONTENT, VISIBLE_SEPARATOR, INVISIBLE_SEPARATOR | 48 CONTENT, VISIBLE_SEPARATOR, INVISIBLE_SEPARATOR |
50 } | 49 } |
51 | 50 |
52 private final Activity mActivity; | 51 private final Activity mActivity; |
53 private final ArrayList<Group> mGroups; | 52 private final ArrayList<Group> mGroups; |
54 private final Drawable mDefaultFavicon; | 53 private final Drawable mDefaultFavicon; |
55 private final RecentTabsManager mRecentTabsManager; | 54 private final RecentTabsManager mRecentTabsManager; |
56 private final RecentlyClosedTabsGroup mRecentlyClosedTabsGroup = new Recentl
yClosedTabsGroup(); | 55 private final RecentlyClosedTabsGroup mRecentlyClosedTabsGroup = new Recentl
yClosedTabsGroup(); |
57 private final SeparatorGroup mVisibleSeparatorGroup = new SeparatorGroup(tru
e); | 56 private final SeparatorGroup mVisibleSeparatorGroup = new SeparatorGroup(tru
e); |
58 private final SeparatorGroup mInvisibleSeparatorGroup = new SeparatorGroup(f
alse); | 57 private final SeparatorGroup mInvisibleSeparatorGroup = new SeparatorGroup(f
alse); |
59 private final long mInitializationTimestamp; // Seconds since Unix epoch. | |
60 private final FaviconCache mFaviconCache; | 58 private final FaviconCache mFaviconCache; |
61 private final int mFaviconSize; | 59 private final int mFaviconSize; |
62 | 60 |
63 /** | 61 /** |
64 * A generic group of objects to be shown in the RecentTabsRowAdapter, such
as the list of | 62 * A generic group of objects to be shown in the RecentTabsRowAdapter, such
as the list of |
65 * recently closed tabs. | 63 * recently closed tabs. |
66 */ | 64 */ |
67 abstract class Group { | 65 abstract class Group { |
68 /** | 66 /** |
69 * @return The type of group: GroupType.CONTENT or GroupType.SEPARATOR. | 67 * @return The type of group: GroupType.CONTENT or GroupType.SEPARATOR. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 * @param parent The parent view group. | 129 * @param parent The parent view group. |
132 * | 130 * |
133 * @return The view corresponding to the group. | 131 * @return The view corresponding to the group. |
134 */ | 132 */ |
135 public View getGroupView(boolean isExpanded, View convertView, ViewGroup
parent) { | 133 public View getGroupView(boolean isExpanded, View convertView, ViewGroup
parent) { |
136 assert convertView == null || convertView instanceof RecentTabsGroup
View; | 134 assert convertView == null || convertView instanceof RecentTabsGroup
View; |
137 RecentTabsGroupView groupView = (RecentTabsGroupView) convertView; | 135 RecentTabsGroupView groupView = (RecentTabsGroupView) convertView; |
138 if (groupView == null) { | 136 if (groupView == null) { |
139 groupView = (RecentTabsGroupView) LayoutInflater.from(mActivity)
.inflate( | 137 groupView = (RecentTabsGroupView) LayoutInflater.from(mActivity)
.inflate( |
140 R.layout.recent_tabs_group_item, parent, false); | 138 R.layout.recent_tabs_group_item, parent, false); |
141 groupView.initialize(mInitializationTimestamp); | |
142 } | 139 } |
143 configureGroupView(groupView, isExpanded); | 140 configureGroupView(groupView, isExpanded); |
144 return groupView; | 141 return groupView; |
145 } | 142 } |
146 | 143 |
147 /** | 144 /** |
148 * Configures an RecentTabsGroupView to display the header of this group
. | 145 * Configures an RecentTabsGroupView to display the header of this group
. |
149 * @param groupView The RecentTabsGroupView to configure. | 146 * @param groupView The RecentTabsGroupView to configure. |
150 * @param isExpanded Whether the view is currently expanded. | 147 * @param isExpanded Whether the view is currently expanded. |
151 */ | 148 */ |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 * Creates an RecentTabsRowAdapter used to populate an ExpandableList with o
ther | 652 * Creates an RecentTabsRowAdapter used to populate an ExpandableList with o
ther |
656 * devices and foreign tab cells. | 653 * devices and foreign tab cells. |
657 * | 654 * |
658 * @param activity The Android activity this adapter will work in. | 655 * @param activity The Android activity this adapter will work in. |
659 * @param recentTabsManager The RecentTabsManager that will act as the data
source. | 656 * @param recentTabsManager The RecentTabsManager that will act as the data
source. |
660 */ | 657 */ |
661 public RecentTabsRowAdapter(Activity activity, RecentTabsManager recentTabsM
anager) { | 658 public RecentTabsRowAdapter(Activity activity, RecentTabsManager recentTabsM
anager) { |
662 mActivity = activity; | 659 mActivity = activity; |
663 mRecentTabsManager = recentTabsManager; | 660 mRecentTabsManager = recentTabsManager; |
664 mGroups = new ArrayList<Group>(); | 661 mGroups = new ArrayList<Group>(); |
665 mInitializationTimestamp = | |
666 TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLIS
ECONDS); | |
667 mFaviconCache = buildFaviconCache(MAX_NUM_FAVICONS_TO_CACHE); | 662 mFaviconCache = buildFaviconCache(MAX_NUM_FAVICONS_TO_CACHE); |
668 | 663 |
669 Resources resources = activity.getResources(); | 664 Resources resources = activity.getResources(); |
670 mDefaultFavicon = ApiCompatibilityUtils.getDrawable(resources, R.drawabl
e.default_favicon); | 665 mDefaultFavicon = ApiCompatibilityUtils.getDrawable(resources, R.drawabl
e.default_favicon); |
671 mFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_s
ize); | 666 mFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_s
ize); |
672 } | 667 } |
673 | 668 |
674 private static FaviconCache buildFaviconCache(int size) { | 669 private static FaviconCache buildFaviconCache(int size) { |
675 return new FaviconCache(size); | 670 return new FaviconCache(size); |
676 } | 671 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 @Override | 834 @Override |
840 public int getChildType(int groupPosition, int childPosition) { | 835 public int getChildType(int groupPosition, int childPosition) { |
841 return mGroups.get(groupPosition).getChildType().ordinal(); | 836 return mGroups.get(groupPosition).getChildType().ordinal(); |
842 } | 837 } |
843 | 838 |
844 @Override | 839 @Override |
845 public int getChildTypeCount() { | 840 public int getChildTypeCount() { |
846 return ChildType.values().length; | 841 return ChildType.values().length; |
847 } | 842 } |
848 } | 843 } |
OLD | NEW |