Search in sources :

Example 51 with WindowManager

use of android.view.WindowManager in project superCleanMaster by joyoyao.

the class QuickReturnUtils method px2dp.

public static int px2dp(Context context, int px) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics displaymetrics = new DisplayMetrics();
    display.getMetrics(displaymetrics);
    return (int) (px / displaymetrics.density + 0.5f);
}
Also used : DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 52 with WindowManager

use of android.view.WindowManager in project uk.co.jasonfry.android.tools by jsonfry.

the class SwipeView method initSwipeView.

private void initSwipeView() {
    Log.i("uk.co.jasonfry.android.tools.ui.SwipeView", "Initialising SwipeView");
    mLinearLayout = new LinearLayout(mContext);
    mLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    super.addView(mLinearLayout, -1, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    setSmoothScrollingEnabled(true);
    setHorizontalFadingEdgeEnabled(false);
    setHorizontalScrollBarEnabled(false);
    Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    SCREEN_WIDTH = (int) (display.getWidth());
    mPageWidth = SCREEN_WIDTH;
    mCurrentPage = 0;
    mSwipeOnTouchListener = new SwipeOnTouchListener();
    super.setOnTouchListener(mSwipeOnTouchListener);
}
Also used : LinearLayout(android.widget.LinearLayout) Display(android.view.Display) WindowManager(android.view.WindowManager)

Example 53 with WindowManager

use of android.view.WindowManager in project FloatingView by UFreedom.

the class UIUtils method getScreenHeight.

public static int getScreenHeight(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    return dm.heightPixels;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager)

Example 54 with WindowManager

use of android.view.WindowManager in project XPrivacy by M66B.

the class PrivacyService method onDemandDialog.

// Helper methods
private OnDemandResult onDemandDialog(final Hook hook, final PRestriction restriction, final PRestriction result) {
    final OnDemandResult oResult = new OnDemandResult();
    try {
        int userId = Util.getUserId(restriction.uid);
        // Check if application
        if (!PrivacyManager.isApplication(restriction.uid))
            if (!getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false))
                return oResult;
        // Check for exceptions
        if (hook != null && !hook.canOnDemand())
            return oResult;
        if (!PrivacyManager.canRestrict(restriction.uid, getXUid(), restriction.restrictionName, restriction.methodName, false))
            return oResult;
        // Check if enabled
        if (!getSettingBool(userId, PrivacyManager.cSettingOnDemand, true))
            return oResult;
        if (!getSettingBool(restriction.uid, PrivacyManager.cSettingOnDemand, false))
            return oResult;
        // Check version
        String version = getSetting(new PSetting(userId, "", PrivacyManager.cSettingVersion, "0.0")).value;
        if (new Version(version).compareTo(new Version("2.1.5")) < 0)
            return oResult;
        // Get activity manager context
        final Context context = getContext();
        if (context == null)
            return oResult;
        long token = 0;
        try {
            token = Binder.clearCallingIdentity();
            // Get application info
            final ApplicationInfoEx appInfo = new ApplicationInfoEx(context, restriction.uid);
            // Check for system application
            if (appInfo.isSystem())
                if (new Version(version).compareTo(new Version("2.0.38")) < 0)
                    return oResult;
            // Check if activity manager agrees
            if (!XActivityManagerService.canOnDemand())
                return oResult;
            // Check if activity manager locked
            if (isAMLocked(restriction.uid)) {
                Util.log(null, Log.WARN, "On demand locked " + restriction);
                return oResult;
            }
            // Go ask
            Util.log(null, Log.WARN, "On demand " + restriction);
            mOndemandSemaphore.acquireUninterruptibly();
            try {
                // Check if activity manager still agrees
                if (!XActivityManagerService.canOnDemand())
                    return oResult;
                // Check if activity manager locked now
                if (isAMLocked(restriction.uid)) {
                    Util.log(null, Log.WARN, "On demand acquired locked " + restriction);
                    return oResult;
                }
                Util.log(null, Log.WARN, "On demanding " + restriction);
                // Check if method not asked before
                CRestriction mkey = new CRestriction(restriction, null);
                synchronized (mRestrictionCache) {
                    if (mRestrictionCache.containsKey(mkey)) {
                        CRestriction mrestriction = mRestrictionCache.get(mkey);
                        if (mrestriction.asked) {
                            Util.log(null, Log.WARN, "Already asked " + restriction);
                            result.restricted = mrestriction.restricted;
                            result.asked = true;
                            return oResult;
                        }
                    }
                }
                // Check if category not asked before (once)
                CRestriction ckey = new CRestriction(restriction, null);
                ckey.setMethodName(null);
                synchronized (mAskedOnceCache) {
                    if (mAskedOnceCache.containsKey(ckey)) {
                        CRestriction carestriction = mAskedOnceCache.get(ckey);
                        if (!carestriction.isExpired()) {
                            Util.log(null, Log.WARN, "Already asked once category " + restriction);
                            result.restricted = carestriction.restricted;
                            result.asked = true;
                            return oResult;
                        }
                    }
                }
                // Check if method not asked before once
                synchronized (mAskedOnceCache) {
                    if (mAskedOnceCache.containsKey(mkey)) {
                        CRestriction marestriction = mAskedOnceCache.get(mkey);
                        if (!marestriction.isExpired()) {
                            Util.log(null, Log.WARN, "Already asked once method " + restriction);
                            result.restricted = marestriction.restricted;
                            result.asked = true;
                            return oResult;
                        }
                    }
                }
                // Check if whitelist not asked before
                if (restriction.extra != null && hook != null && hook.whitelist() != null) {
                    CSetting skey = new CSetting(restriction.uid, hook.whitelist(), restriction.extra);
                    synchronized (mSettingCache) {
                        if (mSettingCache.containsKey(skey)) {
                            String value = mSettingCache.get(skey).getValue();
                            if (value != null) {
                                Util.log(null, Log.WARN, "Already asked whitelist " + skey);
                                result.restricted = Boolean.parseBoolean(value);
                                result.asked = true;
                                return oResult;
                            }
                        }
                        for (String xextra : getXExtra(restriction, hook)) {
                            CSetting xkey = new CSetting(restriction.uid, hook.whitelist(), xextra);
                            if (mSettingCache.containsKey(xkey)) {
                                String value = mSettingCache.get(xkey).getValue();
                                if (value != null) {
                                    Util.log(null, Log.WARN, "Already asked whitelist " + xkey);
                                    result.restricted = Boolean.parseBoolean(value);
                                    result.asked = true;
                                    return oResult;
                                }
                            }
                        }
                    }
                }
                final OnDemandDialogHolder holder = new OnDemandDialogHolder();
                // Build dialog parameters
                final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
                params.type = WindowManager.LayoutParams.TYPE_PHONE;
                params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE;
                params.dimAmount = 0.85f;
                params.width = WindowManager.LayoutParams.WRAP_CONTENT;
                params.height = WindowManager.LayoutParams.WRAP_CONTENT;
                params.format = PixelFormat.TRANSLUCENT;
                params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
                params.gravity = Gravity.CENTER;
                // Get window manager
                final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                // Show dialog
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            // Build dialog
                            holder.dialog = getOnDemandView(restriction, hook, appInfo, result, context, holder, oResult);
                            // Handle reset button
                            ((Button) holder.dialog.findViewById(R.id.btnReset)).setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View view) {
                                    ((ProgressBar) holder.dialog.findViewById(R.id.pbProgress)).setProgress(cMaxOnDemandDialog * 20);
                                    holder.reset = true;
                                    holder.latch.countDown();
                                }
                            });
                            // Make dialog visible
                            wm.addView(holder.dialog, params);
                            // Update progress bar
                            Runnable runProgress = new Runnable() {

                                @Override
                                public void run() {
                                    if (holder.dialog != null && holder.dialog.isShown()) {
                                        // Update progress bar
                                        ProgressBar progressBar = (ProgressBar) holder.dialog.findViewById(R.id.pbProgress);
                                        if (progressBar.getProgress() > 0) {
                                            progressBar.incrementProgressBy(-1);
                                            mHandler.postDelayed(this, 50);
                                        }
                                        // Check if activity manager locked
                                        if (isAMLocked(restriction.uid)) {
                                            Util.log(null, Log.WARN, "On demand dialog locked " + restriction);
                                            ((Button) holder.dialog.findViewById(R.id.btnDontKnow)).callOnClick();
                                        }
                                    }
                                }
                            };
                            mHandler.postDelayed(runProgress, 50);
                            // Enabled buttons after one second
                            boolean repeat = (SystemClock.elapsedRealtime() - mOnDemandLastAnswer < 1000);
                            mHandler.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    if (holder.dialog != null && holder.dialog.isShown()) {
                                        holder.dialog.findViewById(R.id.btnAllow).setEnabled(true);
                                        holder.dialog.findViewById(R.id.btnDontKnow).setEnabled(true);
                                        holder.dialog.findViewById(R.id.btnDeny).setEnabled(true);
                                    }
                                }
                            }, repeat ? 0 : 1000);
                        } catch (NameNotFoundException ex) {
                            Util.log(null, Log.WARN, ex.toString());
                        } catch (Throwable ex) {
                            Util.bug(null, ex);
                        }
                    }
                });
                // Wait for choice, reset or timeout
                do {
                    holder.reset = false;
                    boolean choice = holder.latch.await(cMaxOnDemandDialog, TimeUnit.SECONDS);
                    if (holder.reset) {
                        holder.latch = new CountDownLatch(1);
                        Util.log(null, Log.WARN, "On demand reset " + restriction);
                    } else if (choice)
                        oResult.ondemand = true;
                    else
                        Util.log(null, Log.WARN, "On demand timeout " + restriction);
                } while (holder.reset);
                mOnDemandLastAnswer = SystemClock.elapsedRealtime();
                // Dismiss dialog
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        View dialog = holder.dialog;
                        if (dialog != null)
                            wm.removeView(dialog);
                    }
                });
            } finally {
                mOndemandSemaphore.release();
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    } catch (Throwable ex) {
        Util.bug(null, ex);
    }
    return oResult;
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) CountDownLatch(java.util.concurrent.CountDownLatch) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) WindowManager(android.view.WindowManager) ProgressBar(android.widget.ProgressBar)

Example 55 with WindowManager

use of android.view.WindowManager in project material-camera by afollestad.

the class Degrees method getDisplayRotation.

@DegreeUnits
public static int getDisplayRotation(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int rotation = windowManager.getDefaultDisplay().getRotation();
    switch(rotation) {
        case Surface.ROTATION_0:
            return DEGREES_0;
        case Surface.ROTATION_90:
            return DEGREES_90;
        case Surface.ROTATION_180:
            return DEGREES_180;
        case Surface.ROTATION_270:
            return DEGREES_270;
    }
    return DEGREES_0;
}
Also used : WindowManager(android.view.WindowManager)

Aggregations

WindowManager (android.view.WindowManager)409 Display (android.view.Display)185 Point (android.graphics.Point)129 DisplayMetrics (android.util.DisplayMetrics)103 View (android.view.View)43 IWindowManager (android.view.IWindowManager)37 Context (android.content.Context)36 Resources (android.content.res.Resources)25 ImageView (android.widget.ImageView)24 Configuration (android.content.res.Configuration)20 SuppressLint (android.annotation.SuppressLint)19 Camera (android.hardware.Camera)17 Intent (android.content.Intent)16 Rect (android.graphics.Rect)16 RemoteException (android.os.RemoteException)15 LayoutParams (android.view.WindowManager.LayoutParams)15 TextView (android.widget.TextView)15 Dialog (android.app.Dialog)14 Method (java.lang.reflect.Method)12 PackageManager (android.content.pm.PackageManager)11