Java Code Examples for android.hardware.display.DisplayManager#registerDisplayListener()

The following examples show how to use android.hardware.display.DisplayManager#registerDisplayListener() . 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: DimScreenActivity.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tb_activity_hsl_config);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    TextView textView = findViewById(R.id.textView);
    textView.setText(R.string.tb_desktop_mode_is_active);

    DisplayManager manager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
    manager.registerDisplayListener(listener, null);

    U.registerReceiver(this, unDimScreenReceiver, ACTION_UNDIM_SCREEN);
    U.registerReceiver(this, finishReceiver,
            ACTION_FINISH_DIM_SCREEN_ACTIVITY, ACTION_KILL_HOME_ACTIVITY);

    if(getSupportActionBar() == null) return;

    // Make action bar invisible
    getSupportActionBar().setElevation(0);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0));

    setTitle(null);
}
 
Example 2
Source File: NotificationService.java    From SecondScreen with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onCreate() {
    // Register broadcast receivers for screen on and user present
    final IntentFilter filter1 = new IntentFilter();
    final IntentFilter filter2 = new IntentFilter();

    filter1.addAction(Intent.ACTION_SCREEN_ON);
    filter1.addAction(Intent.ACTION_DREAMING_STARTED);
    filter2.addAction(Intent.ACTION_USER_PRESENT);

    registerReceiver(screenOnReceiver, filter1);
    registerReceiver(userPresentReceiver, filter2);

    DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    manager.registerDisplayListener(listener, null);

    super.onCreate();
}
 
Example 3
Source File: CameraXView.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
  super.onAttachedToWindow();
  DisplayManager dpyMgr =
      (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
  dpyMgr.registerDisplayListener(mDisplayListener, new Handler(Looper.getMainLooper()));
}
 
Example 4
Source File: PreviewView.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    final DisplayManager displayManager =
            (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
    if (displayManager != null) {
        displayManager.registerDisplayListener(mDisplayListener, getHandler());
    }
}
 
Example 5
Source File: BurnInProtectionHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public BurnInProtectionHelper(Context context, int minHorizontalOffset,
        int maxHorizontalOffset, int minVerticalOffset, int maxVerticalOffset,
        int maxOffsetRadius) {
    mMinHorizontalBurnInOffset = minHorizontalOffset;
    mMaxHorizontalBurnInOffset = maxHorizontalOffset;
    mMinVerticalBurnInOffset = minVerticalOffset;
    mMaxVerticalBurnInOffset = maxVerticalOffset;
    if (maxOffsetRadius != BURN_IN_MAX_RADIUS_DEFAULT) {
        mBurnInRadiusMaxSquared = maxOffsetRadius * maxOffsetRadius;
    } else {
        mBurnInRadiusMaxSquared = BURN_IN_MAX_RADIUS_DEFAULT;
    }

    mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    context.registerReceiver(mBurnInProtectionReceiver,
            new IntentFilter(ACTION_BURN_IN_PROTECTION));
    Intent intent = new Intent(ACTION_BURN_IN_PROTECTION);
    intent.setPackage(context.getPackageName());
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    mBurnInProtectionIntent = PendingIntent.getBroadcast(context, 0,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    DisplayManager displayManager =
            (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    mDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    displayManager.registerDisplayListener(this, null /* handler */);

    mCenteringAnimator = ValueAnimator.ofFloat(1f, 0f);
    mCenteringAnimator.setDuration(CENTERING_ANIMATION_DURATION_MS);
    mCenteringAnimator.setInterpolator(new LinearInterpolator());
    mCenteringAnimator.addListener(this);
    mCenteringAnimator.addUpdateListener(this);
}
 
Example 6
Source File: WallpaperService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void attach(IWallpaperEngineWrapper wrapper) {
    if (DEBUG) Log.v(TAG, "attach: " + this + " wrapper=" + wrapper);
    if (mDestroyed) {
        return;
    }
    
    mIWallpaperEngine = wrapper;
    mCaller = wrapper.mCaller;
    mConnection = wrapper.mConnection;
    mWindowToken = wrapper.mWindowToken;
    mSurfaceHolder.setSizeFromLayout();
    mInitializing = true;
    mSession = WindowManagerGlobal.getWindowSession();
    
    mWindow.setSession(mSession);

    mLayout.packageName = getPackageName();

    mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE);
    mDisplayManager.registerDisplayListener(mDisplayListener, mCaller.getHandler());
    mDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
    mDisplayState = mDisplay.getState();

    if (DEBUG) Log.v(TAG, "onCreate(): " + this);
    onCreate(mSurfaceHolder);
    
    mInitializing = false;
    mReportedVisible = false;
    updateSurface(false, false, false);
}
 
Example 7
Source File: DesktopModeFragment.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadPrefs() {
    // Add preferences
    addPreferencesFromResource(R.xml.tb_pref_desktop_mode);

    // Set OnClickListeners for certain preferences
    findPreference(PREF_DESKTOP_MODE).setOnPreferenceClickListener(this);
    findPreference(PREF_SET_LAUNCHER_DEFAULT).setOnPreferenceClickListener(this);
    findPreference(PREF_PRIMARY_LAUNCHER).setOnPreferenceClickListener(this);
    findPreference(PREF_DIM_SCREEN).setOnPreferenceClickListener(this);
    findPreference(PREF_ENABLE_ADDITIONAL_SETTINGS).setOnPreferenceClickListener(this);

    if(!U.isShowHideNavbarSupported()) {
        PreferenceCategory category = (PreferenceCategory) findPreference(PREF_ADDITIONAL_SETTINGS);
        category.removePreference(findPreference(PREF_AUTO_HIDE_NAVBAR_DESKTOP_MODE));
    }

    SharedPreferences pref = U.getSharedPreferences(getActivity());
    if(pref.getBoolean(PREF_LAUNCHER, false)) {
        findPreference(PREF_DESKTOP_MODE).setEnabled(false);
        U.showToastLong(getActivity(), R.string.tb_disable_home_setting);
    } else
        bindPreferenceSummaryToValue(findPreference(PREF_DESKTOP_MODE));

    bindPreferenceSummaryToValue(findPreference(PREF_DISPLAY_DENSITY));

    DisplayManager manager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE);
    manager.registerDisplayListener(listener, null);

    updateAdditionalSettings();
}
 
Example 8
Source File: MiracastWidgetProvider.java    From miracast-widget with Apache License 2.0 4 votes vote down vote up
@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);
       }
   }
 
Example 9
Source File: DisplayConnectionService.java    From SecondScreen with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    manager.registerDisplayListener(listener, null);
}
 
Example 10
Source File: MiracastWidgetProvider.java    From miracast-widget with Apache License 2.0 4 votes vote down vote up
@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);
       }
   }