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.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.drawable.LevelListDrawable; | 9 import android.graphics.drawable.LevelListDrawable; |
10 import android.util.AttributeSet; | 10 import android.util.AttributeSet; |
11 import android.view.View; | 11 import android.view.View; |
12 import android.widget.ImageView; | 12 import android.widget.ImageView; |
13 import android.widget.RelativeLayout; | 13 import android.widget.RelativeLayout; |
14 import android.widget.TextView; | 14 import android.widget.TextView; |
15 | 15 |
16 import org.chromium.base.ApiCompatibilityUtils; | 16 import org.chromium.base.ApiCompatibilityUtils; |
17 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
18 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession; | 18 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession; |
19 import org.chromium.chrome.browser.widget.TintedDrawable; | 19 import org.chromium.chrome.browser.widget.TintedDrawable; |
20 import org.chromium.ui.base.DeviceFormFactor; | |
21 | 20 |
22 /** | 21 /** |
23 * Header view shown above each group of items on the Recent Tabs page. Shows th
e name of the | 22 * Header view shown above each group of items on the Recent Tabs page. Shows th
e name of the |
24 * group (e.g. "Recently closed" or "Jim's Laptop"), an icon, last synced time,
and a button to | 23 * group (e.g. "Recently closed" or "Jim's Laptop"), an icon, last synced time,
and a button to |
25 * expand or collapse the group. | 24 * expand or collapse the group. |
26 */ | 25 */ |
27 public class RecentTabsGroupView extends RelativeLayout { | 26 public class RecentTabsGroupView extends RelativeLayout { |
28 | 27 |
29 /** Drawable levels for the device type icon and the expand/collapse arrow.
*/ | 28 /** Drawable levels for the device type icon and the expand/collapse arrow.
*/ |
30 private static final int DRAWABLE_LEVEL_COLLAPSED = 0; | 29 private static final int DRAWABLE_LEVEL_COLLAPSED = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 TintedDrawable.constructTintedDrawable(getResources(), R.drawabl
e.ic_expanded)); | 70 TintedDrawable.constructTintedDrawable(getResources(), R.drawabl
e.ic_expanded)); |
72 TintedDrawable collapse = | 71 TintedDrawable collapse = |
73 TintedDrawable.constructTintedDrawable(getResources(), R.drawabl
e.ic_collapsed); | 72 TintedDrawable.constructTintedDrawable(getResources(), R.drawabl
e.ic_collapsed); |
74 collapse.setTint( | 73 collapse.setTint( |
75 ApiCompatibilityUtils.getColorStateList(getResources(), R.color.
blue_mode_tint)); | 74 ApiCompatibilityUtils.getColorStateList(getResources(), R.color.
blue_mode_tint)); |
76 collapseIcon.addLevel(DRAWABLE_LEVEL_EXPANDED, DRAWABLE_LEVEL_EXPANDED,
collapse); | 75 collapseIcon.addLevel(DRAWABLE_LEVEL_EXPANDED, DRAWABLE_LEVEL_EXPANDED,
collapse); |
77 mExpandCollapseIcon.setImageDrawable(collapseIcon); | 76 mExpandCollapseIcon.setImageDrawable(collapseIcon); |
78 } | 77 } |
79 | 78 |
80 /** | 79 /** |
81 * Configures the view for currently open tabs. | |
82 * | |
83 * @param isExpanded Whether the view is expanded or collapsed. | |
84 */ | |
85 public void configureForCurrentlyOpenTabs(boolean isExpanded) { | |
86 mDeviceIcon.setVisibility(View.VISIBLE); | |
87 mDeviceIcon.setImageResource(DeviceFormFactor.isTablet(getContext()) | |
88 ? R.drawable.recent_tablet : R.drawable.recent_phone); | |
89 String title = getResources().getString(R.string.recent_tabs_this_device
); | |
90 mDeviceLabel.setText(title); | |
91 setTimeLabelVisibility(View.GONE); | |
92 configureExpandedCollapsed(isExpanded); | |
93 } | |
94 | |
95 /** | |
96 * Configures the view for a foreign session. | 80 * Configures the view for a foreign session. |
97 * | 81 * |
98 * @param session The session to configure the view for. | 82 * @param session The session to configure the view for. |
99 * @param isExpanded Whether the view is expanded or collapsed. | 83 * @param isExpanded Whether the view is expanded or collapsed. |
100 */ | 84 */ |
101 public void configureForForeignSession(ForeignSession session, boolean isExp
anded) { | 85 public void configureForForeignSession(ForeignSession session, boolean isExp
anded) { |
102 mDeviceIcon.setVisibility(View.VISIBLE); | 86 mDeviceIcon.setVisibility(View.VISIBLE); |
103 mDeviceLabel.setText(session.name); | 87 mDeviceLabel.setText(session.name); |
104 setTimeLabelVisibility(View.VISIBLE); | 88 setTimeLabelVisibility(View.VISIBLE); |
105 mTimeLabel.setText(getTimeString(session)); | 89 mTimeLabel.setText(getTimeString(session)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 replaceRule(mDeviceLabel, CENTER_VERTICAL, ALIGN_PARENT_TOP); | 183 replaceRule(mDeviceLabel, CENTER_VERTICAL, ALIGN_PARENT_TOP); |
200 } | 184 } |
201 } | 185 } |
202 | 186 |
203 private static void replaceRule(View view, int oldRule, int newRule) { | 187 private static void replaceRule(View view, int oldRule, int newRule) { |
204 RelativeLayout.LayoutParams lp = ((RelativeLayout.LayoutParams) view.get
LayoutParams()); | 188 RelativeLayout.LayoutParams lp = ((RelativeLayout.LayoutParams) view.get
LayoutParams()); |
205 lp.addRule(oldRule, 0); | 189 lp.addRule(oldRule, 0); |
206 lp.addRule(newRule); | 190 lp.addRule(newRule); |
207 } | 191 } |
208 } | 192 } |
OLD | NEW |