android.hardware.display.DisplayManager#getDisplays ( )源码实例Demo

下面列出了android.hardware.display.DisplayManager#getDisplays ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Reader   文件: PdfMainPresenter.java
@Override
public Presentation initPresentation() {
    DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
    Display[] presentationDisplays = displayManager
            .getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
    if (presentationDisplays.length > 0) {
        Display presentationDisplay = presentationDisplays[0];
        mPresentation = new PdfPresentation(mContext, presentationDisplay);
        mPresentation.getWindow().setType(
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

        SystemPropertyUtils.setSystemProperty(mContext, "sys.eink.Appmode", "13");
        mPresentation.show();
        return mPresentation;
    }
    return null;
}
 
源代码2 项目: GLEXP-Team-onebillion   文件: OBSystemsManager.java
public boolean isScreenOn(Context context)
{
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
    {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        boolean screenOn = false;
        for (Display display : dm.getDisplays())
        {
            if (display.getState() != Display.STATE_OFF)
            {
                screenOn = true;
            }
        }
        return screenOn;
    } else
    {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        //noinspection deprecation
        return pm.isScreenOn();
    }
}
 
源代码3 项目: iGap-Android   文件: HelperNotificationAndBadge.java
/**
 * Is the screen of the device on.
 *
 * @param context the context
 * @return true when (at least one) screen is on
 */
public boolean isScreenOn(Context context) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        boolean screenOn = false;
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                screenOn = true;
            }
        }
        return screenOn;
    } else {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return pm.isScreenOn();
    }
}
 
源代码4 项目: SecondScreen   文件: U.java
public static boolean castScreenActive(Context context) {
    DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    for(Display display : displays) {
        try {
            if(Class.forName("android.view.Display")
                    .getMethod("getOwnerPackageName")
                    .invoke(display)
                    .equals("com.google.android.gms"))
                return true;
        } catch (Exception e) { /* Gracefully fail */ }
    }

    return false;
}
 
源代码5 项目: Reader   文件: ScreenUtils.java
private static DisplayMetrics getEPDDisplayMetrics() {
    Context context = AppUtils.getAppContext();
    DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    Display[] presentationDisplays = displayManager.getDisplays();
    Display display;
    if (presentationDisplays.length > 1) {
        display = presentationDisplays[1];
    } else {
        display = presentationDisplays[0];
    }
    DisplayMetrics metrics = new DisplayMetrics();
    display.getRealMetrics(metrics);
    LogUtils.d("widthPixels=" + metrics.widthPixels + " heightPixels=" + metrics.heightPixels);
    return metrics;
}
 
源代码6 项目: KernelAdiutor   文件: Utils.java
public static boolean isScreenOn(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
源代码7 项目: MTweaks-KernelAdiutorMOD   文件: Utils.java
public static boolean isScreenOn(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
源代码8 项目: aosp_screen_stabilization   文件: Utils.java
public static boolean isScreenOn(Context context)
{
	DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
	for (Display display : dm.getDisplays())
	{
		if (display.getState() != Display.STATE_OFF)
			return true;
	}
	return false;
}
 
源代码9 项目: SecondScreen   文件: U.java
public static int getExternalDisplayID(Context context) {
    SharedPreferences prefCurrent = getPrefCurrent(context);
    int savedID = prefCurrent.getInt("external_display_id", -1);

    if(savedID != -1)
        return savedID;

    DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    return displays[displays.length - 1].getDisplayId();
}
 
源代码10 项目: always-on-amoled   文件: StarterService.java
boolean isScreenOn() {
    if (Utils.isAndroidNewerThanL()) {
        DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
源代码11 项目: SecondScreen   文件: NotificationService.java
@Override
public void onDisplayRemoved(int displayId) {
    DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    try {
        if(displays[displays.length - 1].getDisplayId() == Display.DEFAULT_DISPLAY) {
            Intent serviceIntent = new Intent(NotificationService.this, TempBacklightOnService.class);
            U.startService(NotificationService.this, serviceIntent);

            SharedPreferences prefMain = U.getPrefMain(NotificationService.this);
            ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            boolean displayConnectionServiceRunning = false;

            for(ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
                if(DisplayConnectionService.class.getName().equals(service.service.getClassName()))
                    displayConnectionServiceRunning = true;
            }

            if(prefMain.getBoolean("inactive", true) && !displayConnectionServiceRunning) {
                Intent turnOffIntent = new Intent(NotificationService.this, TurnOffActivity.class);
                turnOffIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(turnOffIntent);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) { /* Gracefully fail */ }
}
 
源代码12 项目: SecondScreen   文件: DisplayConnectionService.java
@Override
public void onDisplayAdded(int displayId) {
    SharedPreferences prefCurrent = U.getPrefCurrent(DisplayConnectionService.this);
    DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    try {
        if(displays[displays.length - 2].getDisplayId() == Display.DEFAULT_DISPLAY
                && prefCurrent.getBoolean("not_active", true)) {
            Intent hdmiIntent = new Intent(DisplayConnectionService.this, HdmiActivity.class);
            hdmiIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(hdmiIntent);
        }
    } catch (ArrayIndexOutOfBoundsException e) { /* Gracefully fail */ }
}
 
源代码13 项目: SecondScreen   文件: ScreenOnService.java
@Override
protected void onHandleIntent(Intent intent) {
    super.onHandleIntent(intent);

    // Turn the backlight back off after the device wakes up
    SharedPreferences prefCurrent = U.getPrefCurrent(this);
    SharedPreferences prefMain = U.getPrefMain(this);
    DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    if(!prefCurrent.getBoolean("not_active", true)
        && prefCurrent.getBoolean("backlight_off", false)
        && (displays[displays.length - 1].getDisplayId() != Display.DEFAULT_DISPLAY
        || prefMain.getBoolean("force_backlight_off", false))) {

        // Turn auto-brightness off so it doesn't mess with things
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

        // Attempt to set screen brightness to 0 first to avoid complications later
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0);

        // Run superuser command to blank screen again after device was turned off
        for(File backlightOff : U.backlightOff) {
            if(backlightOff.exists()) {
                U.runCommand(this, "sleep 2 && echo 0 > " + backlightOff.getAbsolutePath());
                break;
            }
        }
    }
}
 
源代码14 项目: an2linuxclient   文件: NotificationService.java
private boolean filter(StatusBarNotification sbn) {
    String packageName = sbn.getPackageName();
    if (!globalEnabled() || !appEnabled(packageName)) {
        return false;
    }
    boolean usingCustomSettings = isUsingCustomSettings(packageName);
    SharedPreferences sp;
    if (usingCustomSettings) {
        sp = getSharedPreferences(getString(R.string.notification_settings_custom), MODE_PRIVATE);
    } else {
        sp = getSharedPreferences(getString(R.string.notification_settings_global), MODE_PRIVATE);
    }

    boolean isAn2linuxTestNotification = packageName.startsWith("kiwi.root.an2linuxclient");
    if (dontSendIfScreenIsOn(sp, packageName, usingCustomSettings) && !isAn2linuxTestNotification) {
        boolean screenIsOn = false;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
            for (Display display : dm.getDisplays()) {
                if (display.getState() == Display.STATE_ON) {
                    // private as in samsung always-on feature, not sure if this is how it works
                    // https://stackoverflow.com/questions/2474367/how-can-i-tell-if-the-screen-is-on-in-android#comment71534994_17348755
                    boolean displayIsPrivate = (display.getFlags() & Display.FLAG_PRIVATE) == Display.FLAG_PRIVATE;
                    if (!displayIsPrivate) {
                        screenIsOn = true;
                        break;
                    }
                }
            }
        } else {
            PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
            if (powerManager.isScreenOn()){
                screenIsOn = true;
            }
        }

        if (screenIsOn) {
            return false;
        }
    }

    int flags = sbn.getNotification().flags;
    if (isOngoing(flags) && blockOngoing(sp, packageName, usingCustomSettings)){
        return false;
    }
    if (isForeground(flags) && blockForeground(sp, packageName, usingCustomSettings)){
        return false;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH){
        if (isGroupSummary(flags) && blockGroupSummary(sp, packageName, usingCustomSettings)){
            return false;
        }
        if (isLocalOnly(flags) && blockLocalOnly(sp, packageName, usingCustomSettings)){
            return false;
        }
    }
    return priorityAllowed(sp, packageName, usingCustomSettings, sbn.getNotification().priority);
}
 
源代码15 项目: SecondScreen   文件: BootService.java
@Override
protected void onHandleIntent(Intent intent) {
    super.onHandleIntent(intent);

    // Load preferences
    SharedPreferences prefCurrent = U.getPrefCurrent(this);
    SharedPreferences prefMain = U.getPrefMain(this);

    // Run superuser commands on boot
    final int safeModeDensityCommand = 0;
    final int safeModeSizeCommand = 1;
    final int rotationPreCommand = 2;
    final int rotationCommand = 3;
    final int rotationPostCommand = 4;
    final int vibrationCommand = 5;
    final int backlightCommand = 6;

    // Initialize su array
    String[] su = new String[backlightCommand + 1];
    Arrays.fill(su, "");

    if("auto-rotate".equals(prefCurrent.getString("rotation_lock_new", "do-nothing"))) {
        su[rotationCommand] = U.rotationCommand + Integer.toString(Intent.EXTRA_DOCK_STATE_DESK);
        if(Settings.Secure.getInt(getContentResolver(), "screensaver_enabled", 0) == 1
                && Settings.Secure.getInt(getContentResolver(), "screensaver_activate_on_dock", 0) == 1) {
            su[rotationPreCommand] = U.rotationPrePostCommands + "0";
            su[rotationPostCommand] = U.rotationPrePostCommands + "1";
        }
    }

    if(prefCurrent.getBoolean("vibration_off", false)) {
        // Set vibration command
        for(File vibrationOff : U.vibrationOff) {
            if(vibrationOff.exists()) {
                su[vibrationCommand] = "echo 0 > " + vibrationOff.getAbsolutePath();
                break;
            }
        }
    }

    DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    if(prefCurrent.getBoolean("backlight_off", false)
            && (displays[displays.length - 1].getDisplayId() != Display.DEFAULT_DISPLAY
            || prefMain.getBoolean("force_backlight_off", false))) {
        // Turn auto-brightness off so it doesn't mess with things
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

        // Attempt to set screen brightness to 0 first to avoid complications later
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0);

        // Set backlight command
        for(File backlightOff : U.backlightOff) {
            if(backlightOff.exists()) {
                su[backlightCommand] = "sleep 2 && echo 0 > " + backlightOff.getAbsolutePath();
                break;
            }
        }
    }

    if(prefMain.getBoolean("safe_mode", false) && "activity-manager".equals(prefCurrent.getString("ui_refresh", "do-nothing"))) {
        su[safeModeSizeCommand] = U.safeModeSizeCommand("null");
        su[safeModeDensityCommand] = U.safeModeDensityCommand("null");

        SharedPreferences.Editor editor = prefCurrent.edit();
        editor.putString("ui_refresh", "activity-manager-safe-mode");
        editor.commit();
    }

    // Run superuser commands
    U.runCommands(this, su, false);

    // Send broadcast to start Taskbar
    if(prefCurrent.getBoolean("taskbar", false)) {
        Intent taskbarIntent = new Intent("com.farmerbb.taskbar.START");
        taskbarIntent.putExtra("secondscreen", true);
        taskbarIntent.setPackage(U.getTaskbarPackageName(this));

        sendBroadcast(taskbarIntent);
    }
}
 
源代码16 项目: Taskbar   文件: U.java
public static DisplayInfo getDisplayInfo(Context context, boolean fromTaskbar) {
    context = getDisplayContext(context);
    int displayID = getTaskbarDisplayID(context);

    DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    Display currentDisplay = null;

    for(Display display : dm.getDisplays()) {
        if(display.getDisplayId() == displayID) {
            currentDisplay = display;
            break;
        }
    }

    if(currentDisplay == null)
        return new DisplayInfo(0, 0, 0, 0);

    DisplayMetrics metrics = new DisplayMetrics();
    currentDisplay.getMetrics(metrics);

    DisplayMetrics realMetrics = new DisplayMetrics();
    currentDisplay.getRealMetrics(realMetrics);

    DisplayInfo info = new DisplayInfo(metrics.widthPixels, metrics.heightPixels, metrics.densityDpi, 0);

    if(isChromeOs(context)) {
        SharedPreferences pref = getSharedPreferences(context);
        if(!pref.getBoolean(PREF_CHROME_OS_CONTEXT_MENU_FIX, true)) {
            info.width = realMetrics.widthPixels;
            info.height = realMetrics.heightPixels;
        }

        return info;
    }

    // Workaround for incorrect display size on devices with notches in landscape mode
    if(fromTaskbar && getDisplayOrientation(context) == Configuration.ORIENTATION_LANDSCAPE)
        return info;

    boolean sameWidth = metrics.widthPixels == realMetrics.widthPixels;
    boolean sameHeight = metrics.heightPixels == realMetrics.heightPixels;

    if(sameWidth && !sameHeight) {
        info.width = realMetrics.widthPixels;
        info.height = realMetrics.heightPixels - getNavbarHeight(context);
    }

    if(!sameWidth && sameHeight) {
        info.width = realMetrics.widthPixels - getNavbarHeight(context);
        info.height = realMetrics.heightPixels;
    }

    return info;
}
 
源代码17 项目: Taskbar   文件: U.java
private static Display getExternalDisplay(Context context) {
    DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    return displays[displays.length - 1];
}
 
源代码18 项目: SecondScreen   文件: HdmiActivity.java
@SuppressWarnings("deprecation")
private void showMenu() {
    setContentView(R.layout.activity_hdmi);
    setTitle(getResources().getString(R.string.hdmi_connected));
    menu = true;

    TextView header = findViewById(R.id.hdmi_header);
    header.setText(getString(R.string.hdmi_connected));

    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        header.setTypeface(Typeface.DEFAULT);

    // Close notification drawer
    Intent closeDrawer = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    sendBroadcast(closeDrawer);

    DisplayManager dm = (DisplayManager) getApplicationContext().getSystemService(DISPLAY_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();

    Display[] displays = dm.getDisplays();
    displays[displays.length - 1].getRealMetrics(metrics);

    String extScreenRes = metrics.widthPixels + "x" + metrics.heightPixels;

    switch(extScreenRes) {
        case "3840x2160":
            extScreenRes = getResources().getStringArray(R.array.pref_resolution_list)[1];
            break;
        case "1920x1080":
            extScreenRes = getResources().getStringArray(R.array.pref_resolution_list)[2];
            break;
        case "1280x720":
            extScreenRes = getResources().getStringArray(R.array.pref_resolution_list)[3];
            break;
        case "854x480":
            extScreenRes = getResources().getStringArray(R.array.pref_resolution_list)[4];
            break;
    }

    TextView textView = findViewById(R.id.hdmiTextView);
    textView.setText(extScreenRes);

    // Get array of profiles
    final String[][] profileList = U.listProfiles(this);

    // If there are no saved profiles, then show a toast message and exit
    if(profileList == null) {
        U.showToast(this, R.string.no_profiles_found);
        finish();
    } else {
        // Create ArrayList and populate with list of profiles
        ArrayList<String> arrayList = new ArrayList<>(profileList[1].length);
        arrayList.addAll(Arrays.asList(profileList[1]));

        // Create the custom adapter to bind the array to the ListView
        final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);

        // Display the ListView
        final ListView listView = findViewById(R.id.listView3);
        listView.setAdapter(adapter);
        listView.setClickable(true);
        listView.setOnItemClickListener((arg0, arg1, position, arg3) -> {
            U.loadProfile(this, profileList[0][position]);
            finish();
        });
    }
}
 
源代码19 项目: miracast-widget   文件: MiracastWidgetProvider.java
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
       final int length = appWidgetIds.length;

       for (int i = 0; i < length; i++) {
           int appWidgetId = appWidgetIds[i];

           Intent intent = new Intent(context, MainActivity.class);
           intent.putExtra(MainActivity.EXTRA_WIDGET_LAUNCH, true);
           PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                                                   intent, PendingIntent.FLAG_UPDATE_CURRENT);

           final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.miracast_widget);
           views.setOnClickPendingIntent(R.id.widget_layout_parent, pendingIntent);
           final DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);

           Display[] displays = displayManager.getDisplays();
           boolean displaySet = false;
           int currentDisplay = -1;
           for(int j = 0; j < displays.length; j++){
           	Display display = displays[j];
           	if(display.getDisplayId() != Display.DEFAULT_DISPLAY){
                   views.setTextViewText(R.id.widget_text, display.getName());
                   views.setTextColor(R.id.widget_text, context.getResources().getColor(android.R.color.holo_blue_bright));
                   currentDisplay = display.getDisplayId();
                   displaySet = true;

                   // Track this
                   MiracastApplication application
                           = (MiracastApplication) context.getApplicationContext();
                   Tracker tracker = application.getDefaultTracker();
                   sendEventDisplayFound(tracker);
           	}
           }
           
           if(!displaySet){
               views.setTextViewText(R.id.widget_text, "Cast Screen");
               views.setTextColor(R.id.widget_text, context.getResources().getColor(android.R.color.white));
           }

           MiracastDisplayListener displayListener = new MiracastDisplayListener(currentDisplay, views, displayManager, appWidgetManager, appWidgetId, context);
           displayManager.registerDisplayListener(displayListener, null);

           // Tell the AppWidgetManager to perform an update on the current app widget
           appWidgetManager.updateAppWidget(appWidgetId, views);
       }
   }
 
源代码20 项目: AcDisplay   文件: PowerUtils.java
@SuppressLint("NewApi")
public static boolean isScreenOn(@NonNull Context context) {
    display_api:
    if (Device.hasKitKatWatchApi()) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        Display[] displays = dm.getDisplays(null);
        Display display = null;
        if (displays == null || displays.length == 0) {
            break display_api;
        } else if (displays.length > 1) {
            Timber.tag(TAG).i("The number of logical displays is " + displays.length);
        }

        for (Display d : displays) {
            final boolean virtual = Operator.bitAnd(d.getFlags(), Display.FLAG_PRESENTATION);
            if (d.isValid() && !virtual) {
                display = d;

                final int type;
                try {
                    Method method = Display.class.getDeclaredMethod("getType");
                    method.setAccessible(true);
                    type = (int) method.invoke(d);
                } catch (Exception e) {
                    continue;
                }

                if (type == 1 /* built-in display */) {
                    break;
                }
            }
        }

        if (display == null) {
            return false;
        }

        Timber.tag(TAG).i("Display state=" + display.getState());
        return display.getState() == Display.STATE_ON;
    }
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    return isInteractive(pm);
}