Java Code Examples for android.util.DisplayMetrics#DENSITY_LOW

The following examples show how to use android.util.DisplayMetrics#DENSITY_LOW . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Theme.java    From YiBo with Apache License 2.0 6 votes vote down vote up
public String getResourcesPathInAssets(String resName) {
DisplayMetrics metrics = context.getApplicationContext().getResources().getDisplayMetrics();
      String drawableDpi;
      switch (metrics.densityDpi) {
      case DisplayMetrics.DENSITY_LOW:
      	drawableDpi = "drawable-ldpi";
      	break;
      case DisplayMetrics.DENSITY_MEDIUM:
      	drawableDpi = "drawable-mdpi";
      	break;
      case DisplayMetrics.DENSITY_HIGH:
      	drawableDpi = "drawable-hdpi";
      	break;
      case 320:
      	drawableDpi = "drawable-xhdpi";
      	break;
      default:
      	drawableDpi = "drawable-mdpi";
      }

      return currentPackageName + "/" + drawableDpi + "/" + resName + ".png";         
  }
 
Example 2
Source File: TopSlidWebView.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
private void initSize(WebSettings settings) {
    int   screenDensity   = getResources().getDisplayMetrics(). densityDpi ;
    WebSettings.ZoomDensity   zoomDensity   = WebSettings.ZoomDensity. MEDIUM ;
    switch (screenDensity){
        case   DisplayMetrics.DENSITY_LOW :
            zoomDensity = WebSettings.ZoomDensity.CLOSE;
            break ;
        case   DisplayMetrics.DENSITY_MEDIUM :
            zoomDensity = WebSettings.ZoomDensity.MEDIUM;
            break ;
        case   DisplayMetrics.DENSITY_HIGH :
            zoomDensity = WebSettings.ZoomDensity.FAR;
            break ;
    }
    settings.setDefaultZoom(zoomDensity) ;
}
 
Example 3
Source File: DeviceInfo.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
/**
 * 获取设备Densitydpi 类型
 *
 * @param context
 * @return
 */
public static String getDensityDpiStr(Context context) {
    switch (context.getResources().getDisplayMetrics().densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            return "LDPI";
        case DisplayMetrics.DENSITY_MEDIUM:
            return "MDPI";
        case DisplayMetrics.DENSITY_TV:
            return "TVDPI";
        case DisplayMetrics.DENSITY_HIGH:
            return "HDPI";
        case DisplayMetrics.DENSITY_XHIGH:
            return "XHDPI";
        case DisplayMetrics.DENSITY_XXHIGH:
            return "XXHDPI";
        case DisplayMetrics.DENSITY_XXXHIGH:
            return "XXXHDPI";
        default:
            return "";
    }
}
 
Example 4
Source File: BugReportLens.java    From u2020 with Apache License 2.0 6 votes vote down vote up
private static String getDensityString(DisplayMetrics displayMetrics) {
  switch (displayMetrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
      return "ldpi";
    case DisplayMetrics.DENSITY_MEDIUM:
      return "mdpi";
    case DisplayMetrics.DENSITY_HIGH:
      return "hdpi";
    case DisplayMetrics.DENSITY_XHIGH:
      return "xhdpi";
    case DisplayMetrics.DENSITY_XXHIGH:
      return "xxhdpi";
    case DisplayMetrics.DENSITY_XXXHIGH:
      return "xxxhdpi";
    case DisplayMetrics.DENSITY_TV:
      return "tvdpi";
    default:
      return String.valueOf(displayMetrics.densityDpi);
  }
}
 
Example 5
Source File: InvariantDeviceProfile.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
private int getLauncherIconDensity(int requiredSize) {
    // Densities typically defined by an app.
    int[] densityBuckets = new int[] {
            DisplayMetrics.DENSITY_LOW,
            DisplayMetrics.DENSITY_MEDIUM,
            DisplayMetrics.DENSITY_TV,
            DisplayMetrics.DENSITY_HIGH,
            DisplayMetrics.DENSITY_XHIGH,
            DisplayMetrics.DENSITY_XXHIGH,
            DisplayMetrics.DENSITY_XXXHIGH
    };

    int density = DisplayMetrics.DENSITY_XXXHIGH;
    for (int i = densityBuckets.length - 1; i >= 0; i--) {
        float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
                / DisplayMetrics.DENSITY_DEFAULT;
        if (expectedSize >= requiredSize) {
            density = densityBuckets[i];
        }
    }

    return density;
}
 
Example 6
Source File: DeviceInfoModule.java    From debugdrawer with Apache License 2.0 6 votes vote down vote up
private static String getDensityString(DisplayMetrics displayMetrics) {
    switch (displayMetrics.densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            return "ldpi";
        case DisplayMetrics.DENSITY_MEDIUM:
            return "mdpi";
        case DisplayMetrics.DENSITY_HIGH:
            return "hdpi";
        case DisplayMetrics.DENSITY_XHIGH:
            return "xhdpi";
        case DisplayMetrics.DENSITY_XXHIGH:
            return "xxhdpi";
        case DisplayMetrics.DENSITY_XXXHIGH:
            return "xxxhdpi";
        case DisplayMetrics.DENSITY_TV:
            return "tvdpi";
        default:
            return "unknown";
    }
}
 
Example 7
Source File: SystemInfo.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @return The height of the system status bar. This is
 * done by querying the system's resources, or if that fails
 * by using fallbacks for different screen densities.
 */
public static int getStatusBarHeight(Context context)
{
	if (mBarHeight > 0) return mBarHeight;

	// Get display metrics for window.
	final DisplayMetrics mMetrics = new DisplayMetrics();
	((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
		.getDefaultDisplay().getMetrics(mMetrics);

	int statusBarHeight;

	switch (mMetrics.densityDpi)
	{
		case DisplayMetrics.DENSITY_HIGH:
			statusBarHeight = HIGH_DPI_STATUS_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_MEDIUM:
			statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_LOW:
			statusBarHeight = LOW_DPI_STATUS_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_XHIGH:
			statusBarHeight = XHIGH_DPI_STATUS_BAR_HEIGHT;
			break;
		default:
			statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
	}

	return statusBarHeight;
}
 
Example 8
Source File: ImageInflationTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testScaleUpDueToDensity() {
    // Medium density device with low density target should result in image being scaled up
    // by a factor of 160/120 = 1.33
    int targetDensity = DisplayMetrics.DENSITY_LOW;
    testCorrectInflationWithDensity(targetDensity, mediumDensityDevice, boundingDimens_UNRESTRICTIVE, 133);
}
 
Example 9
Source File: EmailDeviceInfoLens.java    From telescope with Apache License 2.0 5 votes vote down vote up
public static String getDensityString(DisplayMetrics displayMetrics) {
  switch (displayMetrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
      return "ldpi";
    case DisplayMetrics.DENSITY_MEDIUM:
      return "mdpi";
    case DisplayMetrics.DENSITY_TV:
      return "tvdpi";
    case DisplayMetrics.DENSITY_HIGH:
      return "hdpi";
    case DisplayMetrics.DENSITY_260:
    case DisplayMetrics.DENSITY_280:
    case DisplayMetrics.DENSITY_300:
    case DisplayMetrics.DENSITY_XHIGH:
      return "xhdpi";
    case DisplayMetrics.DENSITY_340:
    case DisplayMetrics.DENSITY_360:
    case DisplayMetrics.DENSITY_400:
    case DisplayMetrics.DENSITY_420:
    case DisplayMetrics.DENSITY_XXHIGH:
      return "xxhdpi";
    case DisplayMetrics.DENSITY_560:
    case DisplayMetrics.DENSITY_XXXHIGH:
      return "xxxhdpi";
    default:
      return "unknown";
  }
}
 
Example 10
Source File: SystemInfo.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @return The height of the system bar. This is
 * done by querying the system's resources, or if that fails
 * by using fallbacks for different screen densities.
 */
public static int getSystemBarHeight(Context context)
{
	if (mBarHeight2 > 0) return mBarHeight2;

	// Get display metrics for window.
	final DisplayMetrics mMetrics = new DisplayMetrics();
	((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
		.getDefaultDisplay().getMetrics(mMetrics);

	int statusBarHeight;

	switch (mMetrics.densityDpi)
	{
		case DisplayMetrics.DENSITY_HIGH:
			statusBarHeight = HIGH_DPI_SYSTEM_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_MEDIUM:
			statusBarHeight = MEDIUM_DPI_SYSTEM_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_LOW:
			statusBarHeight = LOW_DPI_SYSTEM_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_XHIGH:
			statusBarHeight = XHIGH_DPI_SYSTEM_BAR_HEIGHT;
			break;
		default:
			statusBarHeight = MEDIUM_DPI_SYSTEM_BAR_HEIGHT;
	}

	return statusBarHeight;
}
 
Example 11
Source File: SystemInfo.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @return The height of the system status bar. This is
 * done by querying the system's resources, or if that fails
 * by using fallbacks for different screen densities.
 */
public static int getStatusBarHeight(Context context)
{
	if (mBarHeight > 0) return mBarHeight;

	// Get display metrics for window.
	final DisplayMetrics mMetrics = new DisplayMetrics();
	((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
		.getDefaultDisplay().getMetrics(mMetrics);

	int statusBarHeight;

	switch (mMetrics.densityDpi)
	{
		case DisplayMetrics.DENSITY_HIGH:
			statusBarHeight = HIGH_DPI_STATUS_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_MEDIUM:
			statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_LOW:
			statusBarHeight = LOW_DPI_STATUS_BAR_HEIGHT;
			break;
		case DisplayMetrics.DENSITY_XHIGH:
			statusBarHeight = XHIGH_DPI_STATUS_BAR_HEIGHT;
			break;
		default:
			statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
	}

	return statusBarHeight;
}
 
Example 12
Source File: MyApplication.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
private void initAvatarSize() {
	WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
	Display display = windowManager.getDefaultDisplay();
	// 要获取屏幕的宽和高等参数,首先需要声明一个DisplayMetrics对象,屏幕的宽高等属性存放在这个对象中
	DisplayMetrics DM = new DisplayMetrics();
	// 获取窗口管理器,获取当前的窗口,调用getDefaultDisplay()后,其将关于屏幕的一些信息写进DM对象中,最后通过getMetrics(DM)获取
	windowManager.getDefaultDisplay().getMetrics(DM);
	displayWidth = DM.widthPixels;
	displayHeight = DM.heightPixels;
	// 使用display.getOrientation() 判断横竖屏不准确
	if (displayWidth > displayHeight) {
		displayWidth = DM.heightPixels;
		displayHeight = DM.widthPixels;
	}
	DisplayMetrics metrics = new DisplayMetrics();
	display.getMetrics(metrics);
	density = metrics.density;
	densityDpi = metrics.densityDpi;
	if (densityDpi <= DisplayMetrics.DENSITY_LOW) {
	} else if (densityDpi <= DisplayMetrics.DENSITY_MEDIUM) {
	} else if (densityDpi <= DisplayMetrics.DENSITY_HIGH
			&& displayWidth <= Constants.DISPLAY_HDPI_WIDTH) {
	} else {
	}
	if (BuildConfig.DEBUG) {
		Log.v("Display Width: ", " " + displayWidth);
		Log.v("Display Height: ", " " + displayHeight);
		Log.v("Display Density: ", " " + densityDpi);
		Log.d(TAG, "initAvatarSize Finish : " + System.currentTimeMillis()
				/ 1000);
	}
}
 
Example 13
Source File: BaiduNewsDetailActivity.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);

	Intent intent = getIntent();
	mNewsTitle = intent.getStringExtra("news_title");
	mNewsUrl = intent.getStringExtra("news_url");

	setActionBarTitle(mNewsTitle);

	int screenDensity = getResources().getDisplayMetrics().densityDpi;
	WebSettings.ZoomDensity zoomDensity = WebSettings.ZoomDensity.MEDIUM;
	switch (screenDensity)
	{
		case DisplayMetrics.DENSITY_LOW:
		{
			zoomDensity = WebSettings.ZoomDensity.CLOSE;
			break;
		}
		case DisplayMetrics.DENSITY_MEDIUM:
		{
			zoomDensity = WebSettings.ZoomDensity.MEDIUM;
			break;
		}
		case DisplayMetrics.DENSITY_HIGH:
		{
			zoomDensity = WebSettings.ZoomDensity.FAR;
			break;
		}
	}
	// 设置默认缩放方式尺寸
	getWebview().getSettings().setDefaultZoom(zoomDensity);
	getWebview().getSettings().setBuiltInZoomControls(true);
	getWebview().loadUrl(mNewsUrl);
}
 
Example 14
Source File: StatsChart.java    From PressureNet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the chart text size based on screen metrics
 */
private void setTextSize() {
	try {
		DisplayMetrics displayMetrics = new DisplayMetrics(); 
		displayMetrics = context.getResources().getDisplayMetrics();
		log("setting text size, density is " + displayMetrics.densityDpi);
		switch(displayMetrics.densityDpi){
	     case DisplayMetrics.DENSITY_LOW:
	    	 textSize = 12;
	    	 pointSize = 1f;
	         break;
	     case DisplayMetrics.DENSITY_MEDIUM:
	    	 textSize = 16;
	    	 pointSize = 1f;
	    	 break;
	     case DisplayMetrics.DENSITY_HIGH:
	    	 textSize = 18;
	    	 pointSize = 1f;
	    	 break;
	     case DisplayMetrics.DENSITY_XHIGH:
	    	 textSize = 20;
	    	 pointSize = 1f;
                break;
	     case DisplayMetrics.DENSITY_XXHIGH:
	    	 textSize = 26;
	    	 pointSize = 1f;
                break;
	     default:
	    	 break;
		}
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
Example 15
Source File: Theme.java    From YiBo with Apache License 2.0 5 votes vote down vote up
public Uri getResourcesUri(String resName) {
	DisplayMetrics metrics = context.getApplicationContext().getResources().getDisplayMetrics();
    String drawableDpi;
    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
    	drawableDpi = "drawable-ldpi";
    	break;
    case DisplayMetrics.DENSITY_MEDIUM:
    	drawableDpi = "drawable-mdpi";
    	break;
    case DisplayMetrics.DENSITY_HIGH:
    	drawableDpi = "drawable-hdpi";
    	break;
    case 320:
    	drawableDpi = "drawable-xhdpi";
    	break;
    default:
    	drawableDpi = "drawable-mdpi";
    }

    File sdFolder = Environment.getExternalStorageDirectory();
    StringBuilder sb = new StringBuilder("/.sheJiaoMao/skins/");
    sb.append(drawableDpi);
    sb.append("/");
    sb.append(resName + ".png");
    File resFile = new File(sdFolder, sb.toString());
    Uri resUri = null;
    if (resFile.exists()) {
    	resUri = Uri.parse(resFile.getAbsolutePath());
    }
    
    return resUri;
}
 
Example 16
Source File: Chart.java    From PressureNet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the chart text size based on screen metrics
 */
private void setTextSize() {
	try {
		DisplayMetrics displayMetrics = new DisplayMetrics(); 
		displayMetrics = context.getResources().getDisplayMetrics();
		log("setting text size, density is " + displayMetrics.densityDpi);
		switch(displayMetrics.densityDpi){
	     case DisplayMetrics.DENSITY_LOW:
	    	 textSize = 12;
	    	 pointSize = 2f;
	         break;
	     case DisplayMetrics.DENSITY_MEDIUM:
	    	 textSize = 16;
	    	 pointSize = 3f;
	    	 break;
	     case DisplayMetrics.DENSITY_HIGH:
	    	 textSize = 18;
	    	 pointSize = 4f;
	    	 break;
	     case DisplayMetrics.DENSITY_XHIGH:
	    	 textSize = 20;
	    	 pointSize = 5f;
                break;
	     case DisplayMetrics.DENSITY_XXHIGH:
	    	 textSize = 26;
	    	 pointSize = 7f;
                break;
	     default:
	    	 break;
		}
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
Example 17
Source File: ActivityManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
static int getLauncherLargeIconSizeInner(Context context) {
    final Resources res = context.getResources();
    final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
    final int sw = res.getConfiguration().smallestScreenWidthDp;

    if (sw < 600) {
        // Smaller than approx 7" tablets, use the regular icon size.
        return size;
    }

    final int density = res.getDisplayMetrics().densityDpi;

    switch (density) {
        case DisplayMetrics.DENSITY_LOW:
            return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
        case DisplayMetrics.DENSITY_MEDIUM:
            return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
        case DisplayMetrics.DENSITY_TV:
            return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
        case DisplayMetrics.DENSITY_HIGH:
            return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
        case DisplayMetrics.DENSITY_XHIGH:
            return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
        case DisplayMetrics.DENSITY_XXHIGH:
            return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
        default:
            // The density is some abnormal value.  Return some other
            // abnormal value that is a reasonable scaling of it.
            return (int)((size*1.5f) + .5f);
    }
}
 
Example 18
Source File: ActivityManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Get the preferred density of icons for the launcher. This is used when
 * custom drawables are created (e.g., for shortcuts).
 *
 * @return density in terms of DPI
 */
public int getLauncherLargeIconDensity() {
    final Resources res = mContext.getResources();
    final int density = res.getDisplayMetrics().densityDpi;
    final int sw = res.getConfiguration().smallestScreenWidthDp;

    if (sw < 600) {
        // Smaller than approx 7" tablets, use the regular icon size.
        return density;
    }

    switch (density) {
        case DisplayMetrics.DENSITY_LOW:
            return DisplayMetrics.DENSITY_MEDIUM;
        case DisplayMetrics.DENSITY_MEDIUM:
            return DisplayMetrics.DENSITY_HIGH;
        case DisplayMetrics.DENSITY_TV:
            return DisplayMetrics.DENSITY_XHIGH;
        case DisplayMetrics.DENSITY_HIGH:
            return DisplayMetrics.DENSITY_XHIGH;
        case DisplayMetrics.DENSITY_XHIGH:
            return DisplayMetrics.DENSITY_XXHIGH;
        case DisplayMetrics.DENSITY_XXHIGH:
            return DisplayMetrics.DENSITY_XHIGH * 2;
        default:
            // The density is some abnormal value.  Return some other
            // abnormal value that is a reasonable scaling of it.
            return (int)((density*1.5f)+.5f);
    }
}
 
Example 19
Source File: BarometerNetworkActivity.java    From PressureNet with GNU General Public License v3.0 4 votes vote down vote up
private Bitmap drawableToBitmap(Drawable drawable, CbObservation obs) {
	/*
	 * if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable)
	 * drawable).getBitmap(); }
	 */
	if (obs == null) {
		return ((BitmapDrawable) drawable).getBitmap();
	}

	Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
			drawable.getIntrinsicHeight(), Config.ARGB_8888);

	Canvas canvas = new Canvas(bitmap);
	drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
			drawable.getIntrinsicHeight());

	String display = displayPressureValue(obs.getObservationValue(), obs.getLocation().getAltitude());
	if (display.contains(" ")) {
		display = display.split(" ")[0];
	}

	int x = 0;
	int y = canvas.getHeight();

	// Use the screen data to determine text size
	int defaultTextSize = 16;
	int defaultTextXOffset = 48;
	int defaultTextYOffset = 30;

	int textSize = defaultTextSize;
	int textXOffset = defaultTextXOffset;
	int textYOffset = defaultTextYOffset;

	// Check screen metrics
	DisplayMetrics metrics = new DisplayMetrics();
	getWindowManager().getDefaultDisplay().getMetrics(metrics);
	switch (metrics.densityDpi) {
	case DisplayMetrics.DENSITY_LOW:
		textSize = defaultTextSize - 10;
		textXOffset = defaultTextXOffset - 30;
		textYOffset = defaultTextYOffset - 25;
		break;
	case DisplayMetrics.DENSITY_MEDIUM:
		textSize = defaultTextSize - 8;
		textXOffset = defaultTextXOffset - 24;
		textYOffset = defaultTextYOffset - 15;
		break;
	case DisplayMetrics.DENSITY_HIGH:
		textSize = defaultTextSize - 4;
		textXOffset = defaultTextXOffset - 12;
		textYOffset = defaultTextYOffset - 8;

		break;
	case DisplayMetrics.DENSITY_XHIGH:
		textSize = defaultTextSize + 2;
		textXOffset = defaultTextXOffset + 3;
		textYOffset = defaultTextYOffset;
		break;
	case DisplayMetrics.DENSITY_XXHIGH:
		textSize = defaultTextSize + 16;
		textXOffset = defaultTextXOffset + 22;
		textYOffset = defaultTextYOffset + 14;
		break;
	default:
		break;

	}

	// Paint
	Paint paint = new Paint();
	paint.setTextAlign(Paint.Align.LEFT);
	paint.setTextSize(textSize);
	paint.setShadowLayer(15, 5, 5, 0);
	paint.setAntiAlias(true);
	paint.setColor(Color.BLACK);
	paint.setFlags(Paint.ANTI_ALIAS_FLAG);

	int xMax = canvas.getWidth();
	int yMax = canvas.getHeight();

	drawable.draw(canvas);

	canvas.drawText(display, textXOffset, textYOffset, paint);

	return bitmap;
}
 
Example 20
Source File: OverlayDisplayAdapter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void updateOverlayDisplayDevicesLocked() {
    String value = Settings.Global.getString(getContext().getContentResolver(),
            Settings.Global.OVERLAY_DISPLAY_DEVICES);
    if (value == null) {
        value = "";
    }

    if (value.equals(mCurrentOverlaySetting)) {
        return;
    }
    mCurrentOverlaySetting = value;

    if (!mOverlays.isEmpty()) {
        Slog.i(TAG, "Dismissing all overlay display devices.");
        for (OverlayDisplayHandle overlay : mOverlays) {
            overlay.dismissLocked();
        }
        mOverlays.clear();
    }

    int count = 0;
    for (String part : value.split(";")) {
        Matcher displayMatcher = DISPLAY_PATTERN.matcher(part);
        if (displayMatcher.matches()) {
            if (count >= 4) {
                Slog.w(TAG, "Too many overlay display devices specified: " + value);
                break;
            }
            String modeString = displayMatcher.group(1);
            String flagString = displayMatcher.group(2);
            ArrayList<OverlayMode> modes = new ArrayList<>();
            for (String mode : modeString.split("\\|")) {
                Matcher modeMatcher = MODE_PATTERN.matcher(mode);
                if (modeMatcher.matches()) {
                    try {
                        int width = Integer.parseInt(modeMatcher.group(1), 10);
                        int height = Integer.parseInt(modeMatcher.group(2), 10);
                        int densityDpi = Integer.parseInt(modeMatcher.group(3), 10);
                        if (width >= MIN_WIDTH && width <= MAX_WIDTH
                                && height >= MIN_HEIGHT && height <= MAX_HEIGHT
                                && densityDpi >= DisplayMetrics.DENSITY_LOW
                                && densityDpi <= DisplayMetrics.DENSITY_XXXHIGH) {
                            modes.add(new OverlayMode(width, height, densityDpi));
                            continue;
                        } else {
                            Slog.w(TAG, "Ignoring out-of-range overlay display mode: " + mode);
                        }
                    } catch (NumberFormatException ex) {
                    }
                } else if (mode.isEmpty()) {
                    continue;
                }
            }
            if (!modes.isEmpty()) {
                int number = ++count;
                String name = getContext().getResources().getString(
                        com.android.internal.R.string.display_manager_overlay_display_name,
                        number);
                int gravity = chooseOverlayGravity(number);
                boolean secure = flagString != null && flagString.contains(",secure");

                Slog.i(TAG, "Showing overlay display device #" + number
                        + ": name=" + name + ", modes=" + Arrays.toString(modes.toArray()));

                mOverlays.add(new OverlayDisplayHandle(name, modes, gravity, secure, number));
                continue;
            }
        }
        Slog.w(TAG, "Malformed overlay display devices setting: " + value);
    }
}