Permalink
Browse files

added display density

  • Loading branch information...
1 parent 76c9a1c commit cab353f97a1a062f67b2f64123bd30ad6b9fcea2 @codeanticode codeanticode committed Jan 10, 2017
@@ -34,6 +34,7 @@
public void initDimensions();
public int getDisplayWidth();
public int getDisplayHeight();
+ public float getDisplayDensity();
public int getKind();
public void setSketch(PApplet sketch);
public PApplet getSketch();
@@ -24,6 +24,7 @@
//import android.app.Fragment;
import android.support.v4.app.Fragment;
+import android.util.DisplayMetrics;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Point;
@@ -38,32 +39,23 @@
import processing.core.PApplet;
public class PFragment extends Fragment implements AppComponent {
-// private DisplayMetrics metrics;
+ private DisplayMetrics metrics;
protected Point size;
protected PApplet sketch;
public PFragment() {
}
public void initDimensions() {
- /*
- metrics = new DisplayMetrics();
-// getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
WindowManager wm = getActivity().getWindowManager();
Display display = wm.getDefaultDisplay();
- display.getRealMetrics(metrics);
- */
+ metrics = new DisplayMetrics();
+ display.getMetrics(metrics);
-// metrics = new DisplayMetrics();
-// getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
// display.getRealMetrics(metrics); // API 17 or higher
// display.getRealSize(size);
-// display.getMetrics(metrics);
-
size = new Point();
- WindowManager wm = getActivity().getWindowManager();
- Display display = wm.getDefaultDisplay();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
@@ -87,6 +79,10 @@ public int getDisplayHeight() {
// return metrics.heightPixels;
}
+ public float getDisplayDensity() {
+ return metrics.density;
+ }
+
public int getKind() {
return FRAGMENT;
}
@@ -28,6 +28,7 @@
import android.view.SurfaceHolder;
import android.view.WindowManager;
import processing.core.PApplet;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.os.Build;
//import android.view.WindowManager;
@@ -38,7 +39,7 @@
String TAG = "PWallpaper";
protected Point size;
-// private DisplayMetrics metrics;
+ private DisplayMetrics metrics;
protected PEngine engine;
public PWallpaper() {
@@ -48,15 +49,15 @@ public PWallpaper(PApplet sketch) {
}
public void initDimensions() {
-// metrics = new DisplayMetrics();
-// getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
+ WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ metrics = new DisplayMetrics();
+ display.getMetrics(metrics);
+
// display.getRealMetrics(metrics); // API 17 or higher
// display.getRealSize(size);
-// display.getMetrics(metrics);
size = new Point();
- WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
- Display display = wm.getDefaultDisplay();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
@@ -84,6 +85,10 @@ public int getDisplayHeight() {
// return metrics.heightPixels;
}
+ public float getDisplayDensity() {
+ return metrics.density;
+ }
+
public void setSketch(PApplet sketch) {
// engine.sketch = sketch;
}
@@ -31,6 +31,7 @@
import android.support.wearable.watchface.CanvasWatchFaceService;
import android.support.wearable.watchface.WatchFaceService;
import android.support.wearable.watchface.WatchFaceStyle;
+import android.util.DisplayMetrics;
//import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
@@ -45,19 +46,19 @@
public class PWatchFaceCanvas extends CanvasWatchFaceService implements AppComponent {
protected PApplet sketch;
protected Point size;
-// private DisplayMetrics metrics;
+ private DisplayMetrics metrics;
protected CEngine engine;
public void initDimensions() {
-// metrics = new DisplayMetrics();
-// WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
-// Display display = wm.getDefaultDisplay();
-// display.getRealMetrics(metrics); // only API level 17 o higher
-// display.getMetrics(metrics);
-
- size = new Point();
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
+ metrics = new DisplayMetrics();
+ display.getMetrics(metrics);
+
+// display.getRealMetrics(metrics); // API 17 or higher
+// display.getRealSize(size);
+
+ size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
@@ -81,6 +82,10 @@ public int getDisplayHeight() {
// return metrics.heightPixels;
}
+ public float getDisplayDensity() {
+ return metrics.density;
+ }
+
public int getKind() {
return WATCHFACE;
}
@@ -31,6 +31,7 @@
import android.support.wearable.watchface.Gles2WatchFaceService;
import android.support.wearable.watchface.WatchFaceService;
import android.support.wearable.watchface.WatchFaceStyle;
+import android.util.DisplayMetrics;
//import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
@@ -43,18 +44,19 @@
public class PWatchFaceGLES extends Gles2WatchFaceService implements AppComponent {
protected PApplet sketch;
protected Point size;
-// private DisplayMetrics metrics;
+ private DisplayMetrics metrics;
protected GLEngine engine;
public void initDimensions() {
-// metrics = new DisplayMetrics();
-// WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
-// Display display = wm.getDefaultDisplay();
-// display.getMetrics(metrics);
-
- size = new Point();
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
+ metrics = new DisplayMetrics();
+ display.getMetrics(metrics);
+
+// display.getRealMetrics(metrics); // API 17 or higher
+// display.getRealSize(size);
+
+ size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
@@ -78,6 +80,10 @@ public int getDisplayHeight() {
// return metrics.heightPixels;
}
+ public float getDisplayDensity() {
+ return metrics.density;
+ }
+
public int getKind() {
return WATCHFACE;
}
@@ -160,7 +160,15 @@
public int height = DEFAULT_HEIGHT;
// can't call this because causes an ex, but could set elsewhere
- //final float screenDensity = getResources().getDisplayMetrics().density;
+ /** The logical density of the display from getDisplayMetrics().density
+ * According to Android's documentation:
+ * This is a scaling factor for the Density Independent Pixel unit,
+ * where one DIP is one pixel on an approximately 160 dpi screen
+ * (for example a 240x320, 1.5"x2" screen), providing the baseline of the
+ * system's display. Thus on a 160dpi screen this density value will be 1;
+ * on a 120 dpi screen it would be .75; etc.
+ */
+ public float displayDensity = 1;
/** absolute x position of input on screen */
public int mouseX;
@@ -499,6 +507,8 @@ public void initSurface(LayoutInflater inflater, ViewGroup container,
component.initDimensions();
displayWidth = component.getDisplayWidth();
displayHeight = component.getDisplayHeight();
+ displayDensity = component.getDisplayDensity();
+
handleSettings();
if (fullScreen && parentLayout == -1) {
@@ -63,6 +63,10 @@ public int getDisplayWidth() {
public int getDisplayHeight() {
return metrics.heightPixels;
}
+
+ public float getDisplayDensity() {
+ return metrics.density;
+ }
public int getKind() {
return CARDBOARD;

0 comments on commit cab353f

Please sign in to comment.