Java Code Examples for android.view.Display#getDisplayId()

The following examples show how to use android.view.Display#getDisplayId() . 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: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public Context createDisplayContext(Display display) {
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }

    int displayId = display.getDisplayId();

    ContextImpl context = new ContextImpl();
    context.init(mPackageInfo, null, mMainThread);
    context.mDisplay = display;
    DisplayAdjustments daj = getDisplayAdjustments(displayId);
    context.mResources = mResourcesManager.getTopLevelResources(mPackageInfo.getResDir(),
            displayId, null, daj.getCompatibilityInfo(), null);
    return context;
}
 
Example 2
Source File: DisplayManager.java    From libvlc-sdk-android with GNU General Public License v2.0 6 votes vote down vote up
private SecondaryDisplay createPresentation() {
    if (mMediaRouter == null) return null;
    final MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
    final Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;
    if (presentationDisplay != null) {
        if (BuildConfig.DEBUG)
            Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
        final SecondaryDisplay presentation = new SecondaryDisplay(mActivity, presentationDisplay);
        presentation.setOnDismissListener(mOnDismissListener);
        try {
            presentation.show();
            mPresentationId = presentationDisplay.getDisplayId();
            return presentation;
        } catch (WindowManager.InvalidDisplayException ex) {
            if (BuildConfig.DEBUG)
                Log.w(TAG, "Couldn't show presentation!  Display was removed in " + "the meantime.", ex);
            mPresentationId = -1;
        }
    } else if (BuildConfig.DEBUG) Log.i(TAG, "No secondary display detected");
    return null;
}
 
Example 3
Source File: SystemMediaRouteProvider.java    From cwac-mediarouter with Apache License 2.0 6 votes vote down vote up
@Override
public void onRoutePresentationDisplayChanged(Object routeObj) {
    int index = findSystemRouteRecord(routeObj);
    if (index >= 0) {
        SystemRouteRecord record = mSystemRouteRecords.get(index);
        Display newPresentationDisplay =
                MediaRouterJellybeanMr1.RouteInfo.getPresentationDisplay(routeObj);
        int newPresentationDisplayId = (newPresentationDisplay != null
                ? newPresentationDisplay.getDisplayId() : -1);
        if (newPresentationDisplayId
                != record.mRouteDescriptor.getPresentationDisplayId()) {
            record.mRouteDescriptor =
                    new MediaRouteDescriptor.Builder(record.mRouteDescriptor)
                    .setPresentationDisplayId(newPresentationDisplayId)
                    .build();
            publishRoutes();
        }
    }
}
 
Example 4
Source File: DisplayAndroidManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void initialize() {
    mIdMap = new SparseArray<>();
    Display display;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        mBackend = new DisplayListenerBackendImpl();
        // Make sure the display map contains the built-in primary display.
        // The primary display is never removed.
        display = getDisplayManager().getDisplay(Display.DEFAULT_DISPLAY);

        // Android documentation on Display.DEFAULT_DISPLAY suggests that the above
        // method might return null. In that case we retrieve the default display
        // from the application context and take it as the primary display.
        if (display == null) display = getDefaultDisplayForContext(getContext());
    } else {
        mBackend = new DisplayListenerAPI16();
        display = getDefaultDisplayForContext(getContext());
    }

    mMainSdkDisplayId = display.getDisplayId();
    addDisplay(display); // Note this display is never removed.

    mBackend.startListening();
}
 
Example 5
Source File: DisplayManagerCompat.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
@Override
public Display getDisplay(int displayId) {
    Display display = mWindowManager.getDefaultDisplay();
    if (display.getDisplayId() == displayId) {
        return display;
    }
    return null;
}
 
Example 6
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public Context createDisplayContext(Display display) {
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }

    ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mSplitName,
            mActivityToken, mUser, mFlags, mClassLoader);

    final int displayId = display.getDisplayId();
    context.setResources(createResources(mActivityToken, mPackageInfo, mSplitName, displayId,
            null, getDisplayAdjustments(displayId).getCompatibilityInfo()));
    context.mDisplay = display;
    return context;
}
 
Example 7
Source File: DisplayManagerCompat.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Display getDisplay(int displayId) {
    Display display = mWindowManager.getDefaultDisplay();
    if (display.getDisplayId() == displayId) {
        return display;
    }
    return null;
}
 
Example 8
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public Context createDisplayContext(Display display) {
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }

    ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mSplitName,
            mActivityToken, mUser, mFlags, mClassLoader);

    final int displayId = display.getDisplayId();
    context.setResources(createResources(mActivityToken, mPackageInfo, mSplitName, displayId,
            null, getDisplayAdjustments(displayId).getCompatibilityInfo()));
    context.mDisplay = display;
    return context;
}
 
Example 9
Source File: DisplayManagerCompat.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
public Display getDisplay(int displayId) {
    Display display = mWindowManager.getDefaultDisplay();
    if (display.getDisplayId() == displayId) {
        return display;
    }
    return null;
}
 
Example 10
Source File: DisplayAndroidManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
DisplayAndroid getDisplayAndroid(Display display) {
    int sdkDisplayId = display.getDisplayId();
    DisplayAndroid displayAndroid = mIdMap.get(sdkDisplayId);
    if (displayAndroid == null) {
        displayAndroid = addDisplay(display);
    }
    return displayAndroid;
}
 
Example 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public Context createDisplayContext(Display display) {
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }

    ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mSplitName,
            mActivityToken, mUser, mFlags, mClassLoader);

    final int displayId = display.getDisplayId();
    context.setResources(createResources(mActivityToken, mPackageInfo, mSplitName, displayId,
            null, getDisplayAdjustments(displayId).getCompatibilityInfo()));
    context.mDisplay = display;
    return context;
}
 
Example 12
Source File: DisplayManagerCompat.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override
public Display getDisplay(int displayId) {
    Display display = mWindowManager.getDefaultDisplay();
    if (display.getDisplayId() == displayId) {
        return display;
    }
    return null;
}
 
Example 13
Source File: DisplayManagerCompat.java    From guideshow with MIT License 5 votes vote down vote up
@Override
public Display getDisplay(int displayId) {
    Display display = mWindowManager.getDefaultDisplay();
    if (display.getDisplayId() == displayId) {
        return display;
    }
    return null;
}
 
Example 14
Source File: b.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public Display getDisplay(int i)
{
    Display display = a.getDefaultDisplay();
    if (display.getDisplayId() == i)
    {
        return display;
    } else
    {
        return null;
    }
}
 
Example 15
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public Context createDisplayContext(Display display) {
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }

    ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mSplitName,
            mActivityToken, mUser, mFlags, mClassLoader);

    final int displayId = display.getDisplayId();
    context.setResources(createResources(mActivityToken, mPackageInfo, mSplitName, displayId,
            null, getDisplayAdjustments(displayId).getCompatibilityInfo()));
    context.mDisplay = display;
    return context;
}
 
Example 16
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void createPresentation() {
    if (mMediaRouter == null || mEnableCloneMode)
        return;

    // Get the current route and its presentation display.
    MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(
        MediaRouter.ROUTE_TYPE_LIVE_VIDEO);

    Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;

    if (presentationDisplay != null) {
        // Show a new presentation if possible.
        Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
        mPresentation = new SecondaryDisplay(this, LibVLC(), presentationDisplay);
        mPresentation.setOnDismissListener(mOnDismissListener);
        try {
            mPresentation.show();
            mPresentationDisplayId = presentationDisplay.getDisplayId();
        } catch (WindowManager.InvalidDisplayException ex) {
            Log.w(TAG, "Couldn't show presentation!  Display was removed in "
                    + "the meantime.", ex);
            mPresentation = null;
        }
    } else
        Log.i(TAG, "No secondary display detected");
}
 
Example 17
Source File: DragState.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
InputInterceptor(Display display) {
    InputChannel[] channels = InputChannel.openInputChannelPair("drag");
    mServerChannel = channels[0];
    mClientChannel = channels[1];
    mService.mInputManager.registerInputChannel(mServerChannel, null);
    mInputEventReceiver = new DragInputEventReceiver(mClientChannel,
            mService.mH.getLooper(), mDragDropController);

    mDragApplicationHandle = new InputApplicationHandle(null);
    mDragApplicationHandle.name = "drag";
    mDragApplicationHandle.dispatchingTimeoutNanos =
            WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;

    mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, null,
            display.getDisplayId());
    mDragWindowHandle.name = "drag";
    mDragWindowHandle.inputChannel = mServerChannel;
    mDragWindowHandle.layer = getDragLayerLocked();
    mDragWindowHandle.layoutParamsFlags = 0;
    mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
    mDragWindowHandle.dispatchingTimeoutNanos =
            WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
    mDragWindowHandle.visible = true;
    mDragWindowHandle.canReceiveKeys = false;
    mDragWindowHandle.hasFocus = true;
    mDragWindowHandle.hasWallpaper = false;
    mDragWindowHandle.paused = false;
    mDragWindowHandle.ownerPid = Process.myPid();
    mDragWindowHandle.ownerUid = Process.myUid();
    mDragWindowHandle.inputFeatures = 0;
    mDragWindowHandle.scaleFactor = 1.0f;

    // The drag window cannot receive new touches.
    mDragWindowHandle.touchableRegion.setEmpty();

    // The drag window covers the entire display
    mDragWindowHandle.frameLeft = 0;
    mDragWindowHandle.frameTop = 0;
    mDragWindowHandle.frameRight = mDisplaySize.x;
    mDragWindowHandle.frameBottom = mDisplaySize.y;

    // Pause rotations before a drag.
    if (DEBUG_ORIENTATION) {
        Slog.d(TAG_WM, "Pausing rotation during drag");
    }
    mService.pauseRotationLocked();
}
 
Example 18
Source File: U.java    From Taskbar with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 19
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 20
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private ContextImpl(ContextImpl container, ActivityThread mainThread,
        LoadedApk packageInfo, IBinder activityToken, UserHandle user, boolean restricted,
        Display display, Configuration overrideConfiguration, int createDisplayWithId) {
    mOuterContext = this;

    mMainThread = mainThread;
    mActivityToken = activityToken;
    mRestricted = restricted;

    if (user == null) {
        user = Process.myUserHandle();
    }
    mUser = user;

    mPackageInfo = packageInfo;
    mResourcesManager = ResourcesManager.getInstance();

    final int displayId = (createDisplayWithId != Display.INVALID_DISPLAY)
            ? createDisplayWithId
            : (display != null) ? display.getDisplayId() : Display.DEFAULT_DISPLAY;

    CompatibilityInfo compatInfo = null;
    if (container != null) {
        compatInfo = container.getDisplayAdjustments(displayId).getCompatibilityInfo();
    }
    if (compatInfo == null) {
        compatInfo = (displayId == Display.DEFAULT_DISPLAY)
                ? packageInfo.getCompatibilityInfo()
                : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
    }
    mDisplayAdjustments.setCompatibilityInfo(compatInfo);
    mDisplayAdjustments.setConfiguration(overrideConfiguration);

    mDisplay = (createDisplayWithId == Display.INVALID_DISPLAY) ? display
            : ResourcesManager.getInstance().getAdjustedDisplay(displayId, mDisplayAdjustments);

    Resources resources = packageInfo.getResources(mainThread);
    if (resources != null) {
        if (displayId != Display.DEFAULT_DISPLAY
                || overrideConfiguration != null
                || (compatInfo != null && compatInfo.applicationScale
                        != resources.getCompatibilityInfo().applicationScale)) {
            resources = mResourcesManager.getTopLevelResources(packageInfo.getResDir(),
                    packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(),
                    packageInfo.getApplicationInfo().sharedLibraryFiles, displayId,
                    overrideConfiguration, compatInfo);
        }
    }
    mResources = resources;

    if (container != null) {
        mBasePackageName = container.mBasePackageName;
        mOpPackageName = container.mOpPackageName;
    } else {
        mBasePackageName = packageInfo.mPackageName;
        ApplicationInfo ainfo = packageInfo.getApplicationInfo();
        if (ainfo.uid == Process.SYSTEM_UID && ainfo.uid != Process.myUid()) {
            // Special case: system components allow themselves to be loaded in to other
            // processes.  For purposes of app ops, we must then consider the context as
            // belonging to the package of this process, not the system itself, otherwise
            // the package+uid verifications in app ops will fail.
            mOpPackageName = ActivityThread.currentPackageName();
        } else {
            mOpPackageName = mBasePackageName;
        }
    }

    mContentResolver = new ApplicationContentResolver(this, mainThread, user);
}