@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "AlarmActivity"); mWakeLock.acquire(2 * 60 * 1000L); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); window.setStatusBarColor(Color.TRANSPARENT); } setContentView(R.layout.activity_alarm); if (getActivityComponent() != null) { getActivityComponent().inject(this); alarmPresenter.onAttach(this); } initViews(); bindEvents(); processIntent(); }
/** * 显示一个右上角弹出的menu * * @param activity * @param contentView * @param width * @param x * @param y * @return */ public static Dialog showTopRightMenu(Context activity, View contentView, int width, int x, int y) { Dialog dialog = new Dialog(activity, R.style.FullScreenDialog); dialog.setContentView(contentView); Window window = dialog.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.width = width == 0 ? UIUtils.dip2px(120) : width; lp.height = ViewGroup.LayoutParams.WRAP_CONTENT; lp.x = x == 0 ? UIUtils.dip2px(5) : x; lp.y = y == 0 ? UIUtils.dip2px(48) : y; lp.verticalMargin = 0; lp.horizontalMargin = 0; lp.dimAmount = 0.15f; window.setAttributes(lp); window.setWindowAnimations(R.style.topright_dialog); window.setGravity(Gravity.TOP | Gravity.RIGHT); // 此处可以设置dialog显示的位置 dialog.show(); return dialog; }
/** * 设置状态栏颜色 * * @param activity 需要设置的activity * @param color 状态栏颜色值 * @param statusBarAlpha 状态栏透明度 */ public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha)); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); View fakeStatusBarView = decorView.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG); if (fakeStatusBarView != null) { if (fakeStatusBarView.getVisibility() == View.GONE) { fakeStatusBarView.setVisibility(View.VISIBLE); } fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha)); } else { decorView.addView(createStatusBarView(activity, color, statusBarAlpha)); } setRootView(activity); } }
private void fixLayout() { ViewTreeObserver obs = fragmentView.getViewTreeObserver(); obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (fragmentView == null) { return true; } fragmentView.getViewTreeObserver().removeOnPreDrawListener(this); LinearLayout layout = (LinearLayout) fragmentView; WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE); int rotation = manager.getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { layout.setOrientation(LinearLayout.HORIZONTAL); } else { layout.setOrientation(LinearLayout.VERTICAL); } fragmentView.setPadding(fragmentView.getPaddingLeft(), 0, fragmentView.getPaddingRight(), fragmentView.getPaddingBottom()); return true; } }); }
public SDLSurface(Context context) { super(context); getHolder().addCallback(this); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); setOnKeyListener(this); setOnTouchListener(this); mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); if(Build.VERSION.SDK_INT >= 12) { setOnGenericMotionListener(new SDLGenericMotionListener_API12()); } // Some arbitrary defaults to avoid a potential division by zero mWidth = 1.0f; mHeight = 1.0f; }
/** * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用) * * @param activity 需要设置的activity * @param drawerLayout DrawerLayout * @param color 状态栏颜色值 */ @Deprecated public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // 生成一个状态栏大小的矩形 ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) { contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA)); } else { // 添加 statusBarView 到布局中 StatusBarView statusBarView = createStatusBarView(activity, color); contentLayout.addView(statusBarView, 0); } // 内容布局不是 LinearLayout 时,设置padding top if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0); } // 设置属性 ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1); drawerLayout.setFitsSystemWindows(false); contentLayout.setFitsSystemWindows(false); contentLayout.setClipToPadding(true); drawer.setFitsSystemWindows(false); } }
public void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point theScreenResolution = new Point(); theScreenResolution = getDisplaySize(display); screenResolution = theScreenResolution; Log.i(TAG, "Screen resolution: " + screenResolution); /** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */ Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera); Log.i(TAG, "Camera resolution x: " + cameraResolution.x); Log.i(TAG, "Camera resolution y: " + cameraResolution.y); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { // <3> super.onCreate(savedInstanceState); // Set full screen view <4> getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); // Create new instance of custom Rose and set it on the screen rose = new Rose(this); // <5> setContentView(rose); // <6> // Get sensor and sensor manager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); // <7> sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); // <8> Log.d("Compass", "onCreated"); }
private int getDeviceOrientation() { int orientation = 0; WindowManager wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE); switch (wm.getDefaultDisplay().getRotation()) { case Surface.ROTATION_90: orientation = 90; break; case Surface.ROTATION_180: orientation = 180; break; case Surface.ROTATION_270: orientation = 270; break; case Surface.ROTATION_0: default: orientation = 0; break; } return orientation; }
/** * apply the gravity for window params. * * @param expectGravity the expect gravity * @param applyWlp the window layout params. */ private static void applyGravity(Context context,int expectGravity, WindowManager.LayoutParams applyWlp) { if (Build.VERSION.SDK_INT >= 17) { final Configuration configuration = context.getResources().getConfiguration(); final int gravity = Gravity.getAbsoluteGravity(expectGravity, configuration.getLayoutDirection()); applyWlp.gravity = gravity; if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) { applyWlp.horizontalWeight = 1.0f; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) { applyWlp.verticalWeight = 1.0f; } } else { applyWlp.gravity = expectGravity; } }
@Override public void show() { if (!SettingsCompat.canDrawOverlays(mUiHandler.getContext())) { SettingsCompat.manageDrawOverlays(mUiHandler.getContext()); mUiHandler.toast(R.string.text_no_floating_window_permission); return; } startFloatyService(); mUiHandler.post(new Runnable() { @Override public void run() { try { FloatyService.addWindow(mFloatyWindow); // SecurityException: https://github.com/hyb1996-guest/AutoJsIssueReport/issues/4781 } catch (WindowManager.BadTokenException | SecurityException e) { e.printStackTrace(); mUiHandler.toast(R.string.text_no_floating_window_permission); } } }); mShown = true; }
@SuppressLint("DrawAllocation") private void onLayout(boolean changed, int left, int top, int right, int bottom) { if (changed) { scale = 1; translationX = 0; translationY = 0; updateMinMax(scale); if (checkImageView != null) { checkImageView.post(new Runnable() { @Override public void run() { FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) checkImageView.getLayoutParams(); WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE); int rotation = manager.getDefaultDisplay().getRotation(); layoutParams.topMargin = AndroidUtilities.dp(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68); checkImageView.setLayoutParams(layoutParams); } }); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_question2); et[0]= (EditText) findViewById(R.id.dogEt); et[1]= (EditText) findViewById(R.id.catEt); et[2]= (EditText) findViewById(R.id.ratEt); et[3]= (EditText) findViewById(R.id.coffeeEt); et[4]= (EditText) findViewById(R.id.seaEt); Button resetB= (Button) findViewById(R.id.resetB1); Button nextB= (Button) findViewById(R.id.nextB1); Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar); toolbar.setTitle(getResources().getString(R.string.question_2)); setSupportActionBar(toolbar); int pColor= Color.parseColor("#00c853"); resetB.getBackground().setColorFilter(pColor, PorterDuff.Mode.MULTIPLY); nextB.getBackground().setColorFilter(pColor, PorterDuff.Mode.MULTIPLY); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_EDITITEM: if (resultCode == RESULT_OK) { remoteNotifyAll(); updateItemList(); getWindow() .setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); } case REQUEST_PREFS: readPrefs(); break; } }
public void close() { if (parentActivity == null) { return; } showProgress = 1.0f; currentSticker = null; isVisible = false; AndroidUtilities.unlockOrientation(parentActivity); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { centerImage.setImageBitmap((Bitmap)null); } }); try { if (windowView.getParent() != null) { WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE); wm.removeView(windowView); } } catch (Exception e) { FileLog.e("tmessages", e); } }
public AlertDialog ActivateTipDialog(Activity activity, Context context){ final AlertDialog.Builder builder2 = new AlertDialog.Builder(activity); mTipDialog= builder2.create(); mTipDialog.getWindow().getAttributes().windowAnimations = R.style.Tip_Animation; WindowManager.LayoutParams params = mTipDialog.getWindow().getAttributes(); mTipDialog.getWindow().setAttributes(params); mTipDialog.show(); mTipDialog.setContentView(R.layout.tip_layout); TextView text = (TextView)mTipDialog.findViewById(R.id.textView3); SharedPreferences sharedPreferences = activity.getSharedPreferences("Data",Context.MODE_PRIVATE); if(sharedPreferences.getInt("Language",5)==0){ Typeface type = Typeface.createFromAsset(activity.getAssets(),"fonts/Catenary_Stamp.ttf"); text.setText("Πιέστε την επιλογή που θέλετε για μερικά δευτερόλεπτα για να εμφανιστούν περισσότερες πληροφορίες.Αλλιώς απλώς πιέστε για να πάτε στα προιόντα."); text.setTypeface(type); } return mTipDialog; }
public void initView(Context c) { windowManager = (WindowManager) c.getApplicationContext() .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = getResources().getDisplayMetrics(); screenWidth = dm.widthPixels; screenHeight = dm.heightPixels; this.setImageResource(imgId); windowManagerParams.type = WindowManager.LayoutParams.TYPE_PHONE; windowManagerParams.format = PixelFormat.RGBA_8888; // 背景透明 windowManagerParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; // 调整悬浮窗口至左上角,便于调整坐标 windowManagerParams.gravity = Gravity.LEFT | Gravity.TOP; // 以屏幕左上角为原点,设置x、y初始值 windowManagerParams.x = screenWidth; windowManagerParams.y = screenHeight * 2 / 3; // 设置悬浮窗口长宽数据 windowManagerParams.width = WindowManager.LayoutParams.WRAP_CONTENT; windowManagerParams.height = WindowManager.LayoutParams.WRAP_CONTENT; }
@SuppressLint("InflateParams") public WindowManager.LayoutParams setUpAllViews(){ final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.TOP | Gravity.START; //Initially view will be added to top-left corner params.x = 0; params.y = 100; //Add the view to the window mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); mWindowManager.addView(mFloatingView, params); return params; }
@Override public void alignCameraAndDisplayOrientation(WindowManager windowManager) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(id, info); int rotation = windowManager.getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }
/** * 获得屏幕宽度 * * @param context * @return */ public static int getScreenHeight(Context context) { WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.heightPixels; }
/** * @Description 初始化音量对话框 */ private void initSoundVolumeDlg() { soundVolumeDialog = new Dialog(this, R.style.SoundVolumeStyle); soundVolumeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); soundVolumeDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); soundVolumeDialog.setContentView(R.layout.tt_sound_volume_dialog); soundVolumeDialog.setCanceledOnTouchOutside(true); soundVolumeImg = (ImageView) soundVolumeDialog.findViewById(R.id.sound_volume_img); soundVolumeLayout = (LinearLayout) soundVolumeDialog.findViewById(R.id.sound_volume_bk); }
/** * 获得屏幕高度 * * @param context * @return */ public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.widthPixels; }
/** * Set the dim amount of the region outside this Dialog. * @param amount The dim amount in [0..1]. * @return The Dialog for chaining methods. */ public Dialog dimAmount(float amount){ Window window = getWindow(); if(amount > 0f){ window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); WindowManager.LayoutParams lp = window.getAttributes(); lp.dimAmount = amount; window.setAttributes(lp); } else window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); return this; }
private void showWindow() { WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); // layoutParams.type = WindowManager.LayoutParams.TYPE_TOAST; layoutParams.type = TYPE_SYSTEM_OVERLAY; layoutParams.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCHABLE | FLAG_NOT_TOUCH_MODAL; layoutParams.format = PixelFormat.RGBA_8888; try { windowManagermanager.addView(marquee, layoutParams); } catch (Exception e) { e.printStackTrace(); } }
/** * 进行初始化的一些操作 */ private void init(Context context) { //获取屏幕的宽高 WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displayMetrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(displayMetrics); int screenHeight = displayMetrics.heightPixels; int screenWidth = displayMetrics.widthPixels; //设置各点的位置 mStartXPoint = screenWidth / 4; mStartYPoint = screenHeight / 2; mEndXPoint = screenWidth * 3 / 4; mEndYPoint = screenHeight / 2; mConXPoint = screenWidth / 2; mConYPoint = screenHeight / 2 - 400; //路径,画笔设置 mPath = new Path(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setColor(Color.BLUE); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(8); //辅助线画笔 mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mLinePaint.setColor(Color.GRAY); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(3); //写字画笔 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setColor(Color.BLACK); mTextPaint.setStyle(Paint.Style.STROKE); mTextPaint.setTextSize(20); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.dialog_album_picker); ButterKnife.bind(this); realm = Realm.getDefaultInstance(); setCancelable(false); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); Window window = getWindow(); lp.copyFrom(window.getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(lp); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_48px); toolbar.setNavigationOnClickListener(this); toolbar.setTitle(R.string.select_album); adapter = new AlbumAdapter(getContext(), getResults()); recycler.setLayoutManager(new GridLayoutManager(getContext(),2)); recycler.setAdapter(adapter); adapter.getOnClickObservable().subscribe(this); }
void cancel() { getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (connectionHandler != null){ connectionHandler.cancel(); } if (getDialog() != null){ getDialog().cancel(); } }
private void initializeScreenshotSecurity() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && TextSecurePreferences.isScreenSecurityEnabled(this)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); } else { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); } }
void turnOff() { adapterInstance.unCheckSafe(false); isActivated = false; isColored = false; if (currentState.menuId != -1) { Menu menu = actionBar.getMenu(); actionBar.getMenu().clear(); actionBar.inflateMenu(currentState.origMenuId); actionBar.setOnMenuItemClickListener(origCallback); } actionBar.post(new Runnable() { @Override public void run() { actionBar.setNavigationIcon(prevState.navigationIcon); actionBar.setLogo(prevState.logo); if (prevState.statusBarColor != 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = activity.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(prevState.statusBarColor); } } actionBar.setBackgroundColor(prevState.toolbarColor); actionBar.setTitle(prevState.title); actionBar.setSubtitle(prevState.subTitle); } }); }
@Override public void onDestroy() { WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); if (wm != null) { wm.removeView(mRoot); } stopReadLogcat(); super.onDestroy(); }
public boolean checkHitXBorder(boolean changeState) { WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) getLayoutParams(); int y = layoutParams.y + (mIsUp ? -10 : 10); int endY = ScreenUtil.getScreenHeight(getContext()) - mInitHeight - ScreenUtil.getStatusBarHeight(getContext()); if (y >= endY) { layoutParams.y = endY; layoutParams.x = (mIsLeft ? (-mInitWidth / 2 + 30) : (ScreenUtil.getScreenWidth(getContext()) - mInitWidth / 2 - 30)); if (changeState) { setStatus(STAND); } else { setStatus(HIT_X_LOW_BORDER); } mPetViewEvent.reDraw(PetView.this, layoutParams); return false; } else if (y <= -ScreenUtil.getStatusBarHeight(getContext())) { layoutParams.y = -ScreenUtil.getStatusBarHeight(getContext()); layoutParams.x = (!mIsLeft) ? (ScreenUtil.getScreenWidth(getContext()) - mInitWidth / 2 - 10) : (-mInitWidth / 2 + 10); if (changeState) { mIsLeft = !mIsLeft; setStatus(FLY_PRE); } else { setStatus(HIT_X_HIGH_BORDER); } mPetViewEvent.reDraw(PetView.this, layoutParams); return false; } return true; }
/** * Making notification bar transparent */ private void changeStatusBarColor() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); } }
private void initFitsWindow() { getWindow().requestFeature(Window.FEATURE_NO_TITLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); } }
public static int getScreenHeight(Context context) { WindowManager windowManager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(dm); return dm.heightPixels; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); ApplicationController.initApp(new PlatformControllerImpl(this)); new MainMenuControllerImpl(); act = this; }
/** * 显示输入框 */ public static void showDialogEdit(Context context, final TextView textView) { final AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DialogTransBackGround); dialog = builder.create(); dialog.setCancelable(true); dialog.show(); Window window = dialog.getWindow(); window.setWindowAnimations(R.style.AnimBottom); window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); View view_dialog = LayoutInflater.from(context).inflate(R.layout.create_ac_input_layout, null); dialog.setContentView(view_dialog); final EditText et_content = (EditText) view_dialog.findViewById(R.id.edt_create_layout_input); TextView bt_yes = (TextView) view_dialog.findViewById(R.id.set); TextView bt_no = (TextView) view_dialog.findViewById(R.id.cancel); bt_yes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String content = et_content.getText().toString().trim(); AppUtils.hintKbTwo(et_content); if (!content.isEmpty()) { textView.setText(content); dialog.dismiss(); } } }); bt_no.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AppUtils.hintKbTwo(et_content); dialog.dismiss(); } }); }
/** * hide */ protected void hideKeyboard() { if (getActivity().getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
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); }
public static int getScreenHeight(Context context){ WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.heightPixels; }