diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
| commit | 54b6cfa9a9e5b861a9930af873580d6dc20f773c (patch) | |
| tree | 35051494d2af230dce54d6b31c6af8fc24091316 /core/java/android/view/Display.java | |
Initial Contribution
Diffstat (limited to 'core/java/android/view/Display.java')
| -rw-r--r-- | core/java/android/view/Display.java | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java new file mode 100644 index 000000000000..09ebeed543e1 --- /dev/null +++ b/core/java/android/view/Display.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.view; + +import android.util.DisplayMetrics; + +public class Display +{ + /** + * Specify the default Display + */ + public static final int DEFAULT_DISPLAY = 0; + + + /** + * Use the WindowManager interface to create a Display object. + * Display gives you access to some information about a particular display + * connected to the device. + */ + Display(int display) { + // initalize the statics when this class is first instansiated. This is + // done here instead of in the static block because Zygote + synchronized (mStaticInit) { + if (!mInitialized) { + nativeClassInit(); + mInitialized = true; + } + } + mDisplay = display; + init(display); + } + + /** + * @return index of this display. + */ + public int getDisplayId() { + return mDisplay; + } + + /** + * @return the number of displays connected to the device. + */ + native static int getDisplayCount(); + + /** + * @return width of this display in pixels. + */ + native public int getWidth(); + + /** + * @return height of this display in pixels. + */ + native public int getHeight(); + + /** + * @return orientation of this display. + */ + native public int getOrientation(); + + /** + * @return pixel format of this display. + */ + public int getPixelFormat() { + return mPixelFormat; + } + + /** + * @return refresh rate of this display in frames per second. + */ + public float getRefreshRate() { + return mRefreshRate; + } + + /** + * Initialize a DisplayMetrics object from this display's data. + * + * @param outMetrics + */ + public void getMetrics(DisplayMetrics outMetrics) { + outMetrics.widthPixels = getWidth(); + outMetrics.heightPixels = getHeight(); + outMetrics.density = mDensity; + outMetrics.scaledDensity= outMetrics.density; + outMetrics.xdpi = mDpiX; + outMetrics.ydpi = mDpiY; + } + + /* + * We use a class initializer to allow the native code to cache some + * field offsets. + */ + native private static void nativeClassInit(); + + private native void init(int display); + + private int mDisplay; + // Following fields are initialized from native code + private int mPixelFormat; + private float mRefreshRate; + private float mDensity; + private float mDpiX; + private float mDpiY; + + private static final Object mStaticInit = new Object(); + private static boolean mInitialized = false; +} + |
