OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.ui.gfx; | 5 package org.chromium.ui.gfx; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.ComponentCallbacks; | |
9 import android.content.res.Configuration; | |
8 import android.graphics.PixelFormat; | 10 import android.graphics.PixelFormat; |
9 import android.os.Build; | 11 import android.os.Build; |
10 import android.util.DisplayMetrics; | 12 import android.util.DisplayMetrics; |
11 import android.view.Display; | 13 import android.view.Display; |
12 import android.view.WindowManager; | 14 import android.view.WindowManager; |
13 | 15 |
14 import org.chromium.base.CalledByNative; | 16 import org.chromium.base.CalledByNative; |
15 import org.chromium.base.JNINamespace; | 17 import org.chromium.base.JNINamespace; |
16 | 18 |
17 /** | 19 /** |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 | 110 |
109 /** | 111 /** |
110 * @return A scaling factor for the Density Independent Pixel unit. | 112 * @return A scaling factor for the Density Independent Pixel unit. |
111 * 1.0 is 160dpi, 0.75 is 120dpi, 2.0 is 320dpi. | 113 * 1.0 is 160dpi, 0.75 is 120dpi, 2.0 is 320dpi. |
112 */ | 114 */ |
113 @CalledByNative | 115 @CalledByNative |
114 public double getDIPScale() { | 116 public double getDIPScale() { |
115 return getMetrics().density; | 117 return getMetrics().density; |
116 } | 118 } |
117 | 119 |
120 public void registerListener() { | |
Yaron
2013/10/11 10:18:14
private
| |
121 mAppContext.registerComponentCallbacks( | |
122 new ComponentCallbacks() { | |
123 @Override | |
124 public void onConfigurationChanged(Configuration configuration) { | |
125 updateNativeSharedDisplayInfo(); | |
Yaron
2013/10/11 10:18:14
indent 4 for block-level (other places below too).
| |
126 } | |
127 | |
128 @Override | |
129 public void onLowMemory() { | |
130 } | |
131 }); | |
132 } | |
133 | |
134 private void updateNativeSharedDisplayInfo() { | |
135 nativeUpdateSharedDeviceDisplayInfo(getDisplayHeight(), getDisplayWidth(), | |
136 getBitsPerPixel(), getBitsPerComponent(), getDIPScale()); | |
137 } | |
138 | |
118 private Display getDisplay() { | 139 private Display getDisplay() { |
119 return mWinManager.getDefaultDisplay(); | 140 return mWinManager.getDefaultDisplay(); |
120 } | 141 } |
121 | 142 |
122 private DisplayMetrics getMetrics() { | 143 private DisplayMetrics getMetrics() { |
123 return mAppContext.getResources().getDisplayMetrics(); | 144 return mAppContext.getResources().getDisplayMetrics(); |
124 } | 145 } |
125 | 146 |
126 /** | 147 /** |
127 * Creates DeviceDisplayInfo for a given Context. | 148 * Creates DeviceDisplayInfo for a given Context. |
128 * @param context A context to use. | 149 * @param context A context to use. |
129 * @return DeviceDisplayInfo associated with a given Context. | 150 * @return DeviceDisplayInfo associated with a given Context. |
130 */ | 151 */ |
131 @CalledByNative | |
132 public static DeviceDisplayInfo create(Context context) { | 152 public static DeviceDisplayInfo create(Context context) { |
133 return new DeviceDisplayInfo(context); | 153 return new DeviceDisplayInfo(context); |
134 } | 154 } |
155 | |
156 @CalledByNative | |
157 public static DeviceDisplayInfo createWithListener(Context context) { | |
Yaron
2013/10/11 10:18:14
Make private. This is unneeded from the java layer
| |
158 DeviceDisplayInfo deviceDisplayInfo = new DeviceDisplayInfo(context); | |
159 deviceDisplayInfo.registerListener(); | |
160 return deviceDisplayInfo; | |
161 } | |
162 | |
163 private native void nativeUpdateSharedDeviceDisplayInfo(int displayHeight, | |
164 int displayWidth, int bitsPerPixel, | |
165 int bitsPerComponent, double dipScale); | |
166 | |
135 } | 167 } |
OLD | NEW |