Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/RecentTabsExpandableListView.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.ntp;
6
7 import android.content.Context;
8 import android.util.AttributeSet;
9 import android.view.View;
10 import android.widget.ExpandableListView;
11
12 import org.chromium.ui.base.DeviceFormFactor;
13
14 /**
15 * Customized ExpandableListView for the recent tabs page. This class handles ta blet-specific
16 * layout implementation.
17 */
18 public class RecentTabsExpandableListView extends ExpandableListView {
19 private static final int MAX_LIST_VIEW_WIDTH_DP = 550;
20
21 private int mMaxListViewWidth;
22 private int mSavedListPosition = 0;
23 private int mSavedListTop = 0;
24
25 /**
26 * Constructor for inflating from XML.
27 */
28 public RecentTabsExpandableListView(Context context, AttributeSet attrs) {
29 super(context, attrs);
30 }
31
32 @Override
33 protected void onFinishInflate() {
34 super.onFinishInflate();
35 float density = getResources().getDisplayMetrics().density;
36 mMaxListViewWidth = Math.round(MAX_LIST_VIEW_WIDTH_DP * density);
37 }
38
39 @Override
40 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
41 if (!DeviceFormFactor.isTablet(getContext())) {
42 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
43 return;
44 }
45
46 // Increase padding if needed to ensure children are no wider than mMaxL istViewWidth.
47 int childWidth = MeasureSpec.getSize(widthMeasureSpec);
48 int excessWidth = childWidth - mMaxListViewWidth;
49 int horizontalPadding = 0;
50 if (excessWidth > 0) {
51 horizontalPadding += excessWidth / 2;
52 }
53
54 setPadding(horizontalPadding, 0, horizontalPadding, 0);
55
56 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
57 }
58
59 @Override
60 protected void onAttachedToWindow() {
61 super.onAttachedToWindow();
62 setSelectionFromTop(mSavedListPosition, mSavedListTop);
63 }
64
65 @Override
66 protected void onDetachedFromWindow() {
67 mSavedListPosition = getFirstVisiblePosition();
68 View v = getChildAt(0);
69 mSavedListTop = (v == null) ? 0 : v.getTop();
70 super.onDetachedFromWindow();
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698