/** * Control whether the surface view's content should be treated as secure, preventing it from * appearing in screenshots or from being viewed on non-secure displays. * * <p>Note that this must be set before the surface view's containing window is attached to the * window manager. * * <p>See {@link android.view.Display#FLAG_SECURE} for details. * * @param isSecure True if the surface view is secure. */ public void setSecure(boolean isSecure) { if (isSecure) { mLayout.flags |= WindowManager.LayoutParams.FLAG_SECURE; } else { mLayout.flags &= ~WindowManager.LayoutParams.FLAG_SECURE; } }
public BaseUMBrowser(Context paramContext, int paramInt) { super(paramContext, paramInt); this.mContext = paramContext; WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes(); localLayoutParams.height = -1; localLayoutParams.width = -1; localLayoutParams.gravity = 17; getWindow().setAttributes(localLayoutParams); }
/** * Control whether the surface view's surface is placed on top of its window. Normally it is * placed behind the window, to allow it to (for the most part) appear to composite with the views * in the hierarchy. By setting this, you cause it to be placed above the window. This means that * none of the contents of the window this SurfaceView is in will be visible on top of its * surface. * * <p>Note that this must be set before the surface view's containing window is attached to the * window manager. * * <p>Calling this overrides any previous call to {@link #setZOrderMediaOverlay}. */ public void setZOrderOnTop(boolean onTop) { if (onTop) { mWindowType = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; // ensures the surface is placed below the IME mLayout.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; } else { mWindowType = WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; mLayout.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; } }
@TargetApi(19) private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
@Override protected void onDetachedFromWindow() { if (mGlobalListenersAdded) { ViewTreeObserver observer = getViewTreeObserver(); observer.removeOnScrollChangedListener(mScrollChangedListener); observer.removeOnPreDrawListener(mDrawListener); mGlobalListenersAdded = false; } mRequestedVisible = false; updateWindow(false, false); mHaveFrame = false; if (mWindow != null) { try { mSession.remove(mWindow); } catch (RemoteException ex) { // Not much we can do here... } mWindow = null; } mSession = null; mLayout.token = null; super.onDetachedFromWindow(); }
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); mParent.requestTransparentRegion(this); mSession = getWindowSession(); mLayout.token = getWindowToken(); mLayout.setTitle("SurfaceView"); mViewVisibility = getVisibility() == VISIBLE; if (!mGlobalListenersAdded) { ViewTreeObserver observer = getViewTreeObserver(); observer.addOnScrollChangedListener(mScrollChangedListener); observer.addOnPreDrawListener(mDrawListener); mGlobalListenersAdded = true; } }
private void showDeleteDialog() { Log.d(TAG, "showDeleteDialog() called"); final Dialog deleteDialog = new Dialog(NoteActivity.this); LinearLayout dialogLayout = (LinearLayout) View.inflate(NoteActivity.this, R.layout.delete_note_dialog, null); deleteDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); deleteDialog.setContentView(dialogLayout); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(deleteDialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; deleteDialog.show(); deleteDialog.getWindow().setAttributes(lp); TextView noteTitleTextView = (TextView) dialogLayout.findViewById(R.id.delete_note_dialog_delete_note_title_textview); noteTitleTextView.setText(note.getTitle()); Button confirmDeleteButton = (Button) dialogLayout.findViewById(R.id.delete_note_dialog_confirm_button); confirmDeleteButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "Delete dialog confirm button clicked"); noteProvider.deleteNote(note); finish(); } }); Button cancelDeleteButton = (Button) dialogLayout.findViewById(R.id.delete_note_dialog_cancel_button); cancelDeleteButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "Delete dialog cancel button clicked"); deleteDialog.dismiss(); } }); }
private void createFloatingWindow() { SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = shared.edit(); editor.putInt("float", 1); editor.commit(); windowManager = (WindowManager) getApplicationContext().getSystemService("window"); wmParams = ((ProfilerApplication) getApplication()).getMywmParams(); wmParams.type = 2002; wmParams.flags |= 8; wmParams.gravity = Gravity.LEFT | Gravity.TOP; wmParams.x = 0; wmParams.y = 0; wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.format = 1; windowManager.addView(floatingView, wmParams); floatingView.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { x = event.getRawX(); y = event.getRawY() - 25; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTouchStartX = event.getX(); mTouchStartY = event.getY(); break; case MotionEvent.ACTION_MOVE: updateViewPosition(); break; case MotionEvent.ACTION_UP: updateViewPosition(); mTouchStartX = mTouchStartY = 0; break; } return true; } }); }
private void updateWindow(boolean force, boolean redrawNeeded) { if (!mHaveFrame) { return; } ViewRootImpl viewRoot = getViewRootImpl(); if (viewRoot != null) { mTranslator = viewRoot.mTranslator; } if (mTranslator != null) { mSurface.setCompatibilityTranslator(mTranslator); } int myWidth = mRequestedWidth; if (myWidth <= 0) myWidth = getWidth(); int myHeight = mRequestedHeight; if (myHeight <= 0) myHeight = getHeight(); getLocationInWindow(mLocation); final boolean creating = mWindow == null; final boolean formatChanged = mFormat != mRequestedFormat; final boolean sizeChanged = mWidth != myWidth || mHeight != myHeight; final boolean visibleChanged = mVisible != mRequestedVisible; if (force || creating || formatChanged || sizeChanged || visibleChanged || mLeft != mLocation[0] || mTop != mLocation[1] || mUpdateWindowNeeded || mReportDrawNeeded || redrawNeeded) { if (DEBUG) Log.i( TAG, "Changes: creating=" + creating + " format=" + formatChanged + " size=" + sizeChanged + " visible=" + visibleChanged + " left=" + (mLeft != mLocation[0]) + " top=" + (mTop != mLocation[1])); try { final boolean visible = mVisible = mRequestedVisible; mLeft = mLocation[0]; mTop = mLocation[1]; mWidth = myWidth; mHeight = myHeight; mFormat = mRequestedFormat; // Scaling/Translate window's layout here because mLayout is not used elsewhere. // Places the window relative mLayout.x = mLeft; mLayout.y = mTop; mLayout.width = getWidth(); mLayout.height = getHeight(); if (mTranslator != null) { mTranslator.translateLayoutParamsInAppWindowToScreen(mLayout); } mLayout.format = mRequestedFormat; mLayout.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_SCALED | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; if (!getContext().getResources().getCompatibilityInfo().supportsScreen()) { mLayout.flags |= WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; } mLayout.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; if (mWindow == null) { Display display = getDisplay(); mWindow = new MyWindow(this); mLayout.type = mWindowType; mLayout.gravity = Gravity.START | Gravity.TOP; mSession.addToDisplayWithoutInputChannel( mWindow, mWindow.mSeq, mLayout, mVisible ? VISIBLE : GONE, display.getDisplayId(), mContentInsets); } boolean realSizeChanged; boolean reportDrawNeeded; int relayoutResult; mSurfaceLock.lock(); try { mUpdateWindowNeeded = false; reportDrawNeeded = mReportDrawNeeded; mReportDrawNeeded = false; mDrawingStopped = !visible; if (DEBUG) Log.i(TAG, "Cur surface: " + mSurface); relayoutResult = mSession.relayout( mWindow, mWindow.mSeq, mLayout, mWidth, mHeight, visible ? VISIBLE : GONE, WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY, mWinFrame, mOverscanInsets, mContentInsets, mVisibleInsets, mConfiguration, mNewSurface); if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { mReportDrawNeeded = true; } if (DEBUG) Log.i(TAG, "New surface: " + mNewSurface + ", vis=" + visible + ", frame=" + mWinFrame); mSurfaceFrame.left = 0; mSurfaceFrame.top = 0; if (mTranslator == null) { mSurfaceFrame.right = mWinFrame.width(); mSurfaceFrame.bottom = mWinFrame.height(); } else { float appInvertedScale = mTranslator.applicationInvertedScale; mSurfaceFrame.right = (int) (mWinFrame.width() * appInvertedScale + 0.5f); mSurfaceFrame.bottom = (int) (mWinFrame.height() * appInvertedScale + 0.5f); } final int surfaceWidth = mSurfaceFrame.right; final int surfaceHeight = mSurfaceFrame.bottom; realSizeChanged = mLastSurfaceWidth != surfaceWidth || mLastSurfaceHeight != surfaceHeight; mLastSurfaceWidth = surfaceWidth; mLastSurfaceHeight = surfaceHeight; } finally { mSurfaceLock.unlock(); } try { redrawNeeded |= creating | reportDrawNeeded; SurfaceHolder.Callback callbacks[] = null; final boolean surfaceChanged = (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED) != 0; if (mSurfaceCreated && (surfaceChanged || (!visible && visibleChanged))) { mSurfaceCreated = false; if (mSurface.isValid()) { if (DEBUG) Log.i(TAG, "visibleChanged -- surfaceDestroyed"); callbacks = getSurfaceCallbacks(); for (SurfaceHolder.Callback c : callbacks) { c.surfaceDestroyed(mSurfaceHolder); } } } mSurface.transferFrom(mNewSurface); if (visible && mSurface.isValid()) { if (!mSurfaceCreated && (surfaceChanged || visibleChanged)) { mSurfaceCreated = true; mIsCreating = true; if (DEBUG) Log.i(TAG, "visibleChanged -- surfaceCreated"); if (callbacks == null) { callbacks = getSurfaceCallbacks(); } for (SurfaceHolder.Callback c : callbacks) { c.surfaceCreated(mSurfaceHolder); } } if (creating || formatChanged || sizeChanged || visibleChanged || realSizeChanged) { if (DEBUG) Log.i( TAG, "surfaceChanged -- format=" + mFormat + " w=" + myWidth + " h=" + myHeight); if (callbacks == null) { callbacks = getSurfaceCallbacks(); } for (SurfaceHolder.Callback c : callbacks) { c.surfaceChanged(mSurfaceHolder, mFormat, myWidth, myHeight); } } if (redrawNeeded) { if (DEBUG) Log.i(TAG, "surfaceRedrawNeeded"); if (callbacks == null) { callbacks = getSurfaceCallbacks(); } for (SurfaceHolder.Callback c : callbacks) { if (c instanceof SurfaceHolder.Callback2) { ((SurfaceHolder.Callback2) c).surfaceRedrawNeeded(mSurfaceHolder); } } } } } finally { mIsCreating = false; if (redrawNeeded) { if (DEBUG) Log.i(TAG, "finishedDrawing"); mSession.finishDrawing(mWindow); } mSession.performDeferredDestroy(mWindow); } } catch (RemoteException ex) { } if (DEBUG) Log.v( TAG, "Layout: x=" + mLayout.x + " y=" + mLayout.y + " w=" + mLayout.width + " h=" + mLayout.height + ", frame=" + mSurfaceFrame); } }
/** update the position of floating window. */ private void updateViewPosition() { wmParams.x = (int) (x - mTouchStartX); wmParams.y = (int) (y - mTouchStartY); windowManager.updateViewLayout(floatingView, wmParams); }
public void onCreate() { int flags, screenLightVal = 1; Sensor mSensor; List<Sensor> sensors; if (scanData == null) return; // no ScanData, not possible to run correctly... PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); try { screenLightVal = Integer.parseInt(SP.getString("screenLight", "2")); } catch (NumberFormatException nfe) { } if (screenLightVal == 1) flags = PowerManager.PARTIAL_WAKE_LOCK; else if (screenLightVal == 3) flags = PowerManager.FULL_WAKE_LOCK; else flags = PowerManager.SCREEN_DIM_WAKE_LOCK; wl = pm.newWakeLock(flags, "OpenWLANMap"); wl.acquire(); while (myWLocate == null) { try { myWLocate = new MyWLocate(this); break; } catch (IllegalArgumentException iae) { myWLocate = null; } try { Thread.sleep(100); } catch (InterruptedException ie) { } } try { scanData.setUploadThres(Integer.parseInt(SP.getString("autoUpload", "0"))); } catch (NumberFormatException nfe) { } try { scanData.setNoGPSExitInterval( Integer.parseInt(SP.getString("noGPSExitInterval", "0")) * 60 * 1000); } catch (NumberFormatException nfe) { } Intent intent = new Intent(this, OWMapAtAndroid.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon) .setContentTitle(getResources().getText(R.string.app_name)) .setContentText("") .setContentIntent(pendIntent) .build(); notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(1703, notification); getScanData().setService(this); getScanData().setmView(new HUDView(this)); getScanData().getmView().setValue(getScanData().incStoredValues()); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.LEFT | Gravity.BOTTOM; params.setTitle("Load Average"); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(getScanData().getmView(), params); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME); sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); mSensor = sensors.get(0); getScanData().getTelemetryData().setAccelMax(mSensor.getMaximumRange()); telemetryDir = Environment.getExternalStorageDirectory().getPath() + "/telemetry/"; File dir = new File(telemetryDir); dir.mkdir(); connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); }