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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations