OLD | NEW |
(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.compositor.layouts; |
| 6 |
| 7 import android.content.res.Configuration; |
| 8 import android.content.res.Resources; |
| 9 import android.graphics.Color; |
| 10 import android.graphics.drawable.ColorDrawable; |
| 11 import android.graphics.drawable.Drawable; |
| 12 import android.test.mock.MockResources; |
| 13 import android.util.DisplayMetrics; |
| 14 import android.util.SparseArray; |
| 15 |
| 16 import com.google.android.apps.chrome.R; |
| 17 |
| 18 /** |
| 19 * This is the minimal {@link Resources} needed by the {@link LayoutManager} to
be working properly. |
| 20 * Values Come from the xml files (e.g. dimens.xml, values.xml, ...). |
| 21 * All the dimension values are in dp. |
| 22 * For internal structures, not based on xml configurations, a dummy {@link Reso
urces} instance is |
| 23 * provided. |
| 24 */ |
| 25 public class MockResourcesForLayout extends MockResources { |
| 26 private final Resources mValidResources; |
| 27 private final SparseArray<Float> mFloats = new SparseArray<Float>(); |
| 28 private final SparseArray<Integer> mIntegers = new SparseArray<Integer>(); |
| 29 private final SparseArray<Boolean> mBooleans = new SparseArray<Boolean>(); |
| 30 private final SparseArray<String> mStrings = new SparseArray<String>(); |
| 31 private final Drawable mDrawable = new ColorDrawable(Color.RED); |
| 32 |
| 33 public MockResourcesForLayout(Resources resources) { |
| 34 mValidResources = resources; |
| 35 mFloats.put(R.dimen.over_scroll_slide, 10.0f); |
| 36 mFloats.put(R.dimen.tabswitcher_border_frame_padding_left, 6.f); |
| 37 mFloats.put(R.dimen.tabswitcher_border_frame_padding_top, 50.f); |
| 38 mFloats.put(org.chromium.chrome.R.dimen.compositor_tab_title_text_size,
13.0f); |
| 39 mIntegers.put(R.color.tab_switcher_background, 0xFF111111); |
| 40 mFloats.put(R.dimen.over_scroll, 75.0f); |
| 41 mIntegers.put(R.integer.over_scroll_angle, 15); |
| 42 mFloats.put(R.dimen.even_out_scrolling, 400.0f); |
| 43 mFloats.put(R.dimen.min_spacing, 120.0f); |
| 44 mFloats.put(R.dimen.swipe_commit_distance, 120.0f); |
| 45 mFloats.put(R.dimen.toolbar_swipe_space_between_tabs, 30.0f); |
| 46 mFloats.put(R.dimen.toolbar_swipe_commit_distance, 90.0f); |
| 47 mIntegers.put( |
| 48 org.chromium.chrome.R.color.compositor_tab_title_bar_text_incogn
ito, 0xFFffFFff); |
| 49 mIntegers.put(org.chromium.chrome.R.color.compositor_tab_title_bar_text,
0xFF555555); |
| 50 mIntegers.put( |
| 51 org.chromium.chrome.R.color.compositor_tab_title_bar_shadow_inco
gnito, 0x88000000); |
| 52 mIntegers.put(org.chromium.chrome.R.color.compositor_tab_title_bar_shado
w, 0xAAffFFff); |
| 53 mFloats.put(org.chromium.chrome.R.dimen.compositor_tab_title_bar_shadow_
x_offset_incognito, |
| 54 -0.6667f); |
| 55 mFloats.put(org.chromium.chrome.R.dimen.compositor_tab_title_bar_shadow_
x_offset, 0.6667f); |
| 56 mFloats.put(org.chromium.chrome.R.dimen.compositor_tab_title_bar_shadow_
y_offset_incognito, |
| 57 -0.6667f); |
| 58 mFloats.put(org.chromium.chrome.R.dimen.compositor_tab_title_bar_shadow_
y_offset, 0.6667f); |
| 59 mFloats.put(R.dimen.tab_title_favicon_start_padding, 16.0f); |
| 60 mFloats.put(R.dimen.tab_title_favicon_end_padding, 7.0f); |
| 61 mFloats.put(org.chromium.chrome.R.dimen.compositor_tab_title_favicon_siz
e, 16.0f); |
| 62 mFloats.put(R.dimen.stacked_tab_visible_size, 4.0f); |
| 63 mFloats.put(R.dimen.stack_buffer_width, 5.0f); |
| 64 mFloats.put(R.dimen.stack_buffer_height, 5.0f); |
| 65 mFloats.put(org.chromium.chrome.R.dimen.compositor_button_slop, 20.0f); |
| 66 mFloats.put(R.dimen.accessibility_tab_height, 65.f); |
| 67 mFloats.put(R.dimen.tabswitcher_border_frame_padding_left, 6.f); |
| 68 mFloats.put(R.dimen.tabswitcher_border_frame_padding_top, 50.f); |
| 69 mFloats.put(R.dimen.tabswitcher_border_frame_transparent_top, 3.f); |
| 70 mFloats.put(R.dimen.tabswitcher_border_frame_transparent_side, 2.f); |
| 71 mBooleans.put(org.chromium.chrome.R.bool.compositor_tab_title_fake_bold_
text, true); |
| 72 mStrings.put(R.string.tab_loading_default_title, "Loading..."); |
| 73 mFloats.put(org.chromium.chrome.R.dimen.contextual_search_bar_height, 80
.f); |
| 74 } |
| 75 |
| 76 @Override |
| 77 public DisplayMetrics getDisplayMetrics() { |
| 78 return mValidResources.getDisplayMetrics(); |
| 79 } |
| 80 |
| 81 @Override |
| 82 public Configuration getConfiguration() { |
| 83 return mValidResources.getConfiguration(); |
| 84 } |
| 85 |
| 86 @Override |
| 87 public int getDimensionPixelSize(int id) { |
| 88 return Math.round(getDimension(id)); |
| 89 } |
| 90 |
| 91 @Override |
| 92 public int getDimensionPixelOffset(int id) { |
| 93 return getDimensionPixelSize(id); |
| 94 } |
| 95 |
| 96 @Override |
| 97 public float getDimension(int id) { |
| 98 final Float value = mFloats.get(id); |
| 99 return value != null ? value.floatValue() : mValidResources.getDimension
(id); |
| 100 } |
| 101 |
| 102 @Override |
| 103 public int getInteger(int id) { |
| 104 final Integer value = mIntegers.get(id); |
| 105 return value != null ? value.intValue() : mValidResources.getInteger(id)
; |
| 106 } |
| 107 |
| 108 @Override |
| 109 public boolean getBoolean(int id) { |
| 110 final Boolean value = mBooleans.get(id); |
| 111 return value != null ? value.booleanValue() : mValidResources.getBoolean
(id); |
| 112 } |
| 113 |
| 114 @Override |
| 115 public String getString(int id) { |
| 116 final String value = mStrings.get(id); |
| 117 return value != null ? value.toString() : mValidResources.getString(id); |
| 118 } |
| 119 |
| 120 @Override |
| 121 public int getColor(int id) { |
| 122 return getInteger(id); |
| 123 } |
| 124 |
| 125 @Override |
| 126 public Drawable getDrawable(int id) { |
| 127 return mDrawable; |
| 128 } |
| 129 |
| 130 @Override |
| 131 public Drawable getDrawable(int id, Resources.Theme theme) { |
| 132 return mDrawable; |
| 133 } |
| 134 } |
OLD | NEW |