List of usage examples for android.app Activity getWindow
public Window getWindow()
From source file:Main.java
/***************************************************** * ---------------- * Soft keyboard * -------------------- * * * ****************************************************/ public static void hideKeyboard(Activity activity) { if (activity != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0); }/* w w w . ja v a 2 s . co m*/ }
From source file:Main.java
public static void prepare(Activity activity, int id, int width) { if (sCoverBitmap != null) { sCoverBitmap.recycle();/*from w w w . j a va 2s .c o m*/ } Rect rectgle = new Rect(); Window window = activity.getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectgle); int statusBarHeight = rectgle.top; ViewGroup v1 = (ViewGroup) activity.findViewById(id).getRootView(); v1.setDrawingCacheEnabled(true); Bitmap source = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); if (statusBarHeight != 0) { sCoverBitmap = Bitmap.createBitmap(source, 0, statusBarHeight, source.getWidth(), source.getHeight() - statusBarHeight); source.recycle(); } else { sCoverBitmap = source; } sWidth = width; }
From source file:Main.java
/** * get a screen shot with size : width X height. *//* w w w .ja v a 2 s . co m*/ public static Bitmap getScreenShot(Activity activity, int width, int height) { if (activity == null || width < 1 || height < 1) { return null; } Window window = activity.getWindow(); if (window == null) { return null; } View decorView = window.getDecorView(); if (decorView == null) { return null; } decorView.setDrawingCacheEnabled(true); Bitmap screenShot = decorView.getDrawingCache(true); if (screenShot == null) { return null; } Matrix matrix = new Matrix(); matrix.postScale((float) width / screenShot.getWidth(), (float) height / screenShot.getHeight()); Bitmap drawingCache = Bitmap.createBitmap(screenShot, 0, 0, screenShot.getWidth(), screenShot.getHeight(), matrix, true); decorView.destroyDrawingCache(); screenShot.recycle(); return drawingCache; }
From source file:Main.java
public static void setKeepScreenOn(final Activity activity, final boolean keepScreenOn) { // WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED if (keepScreenOn) { activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } else {//from w w w . j a v a 2 s. co m activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }
From source file:Main.java
public static void setView(Activity activity, int id) { LayoutInflater layoutInflater = LayoutInflater.from(activity); setTranslucentStatus(activity);/*ww w. j av a2s . c om*/ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView().findViewById(android.R.id.content); int height = getStatusBarHeight(activity); ViewGroup linearLayout = (ViewGroup) layoutInflater.from(activity).inflate(id, null); linearLayout.setPadding(0, height, 0, 0); decorView.removeAllViews(); decorView.addView(linearLayout); }
From source file:com.android.mail.utils.ViewUtils.java
/** * Sets the status bar color of the provided activity. */// www. j a va 2 s. c o m @SuppressLint("NewApi") public static void setStatusBarColor(Activity activity, @ColorRes int colorId) { if (Utils.isRunningLOrLater() && activity != null) { final Window window = activity.getWindow(); if (window != null) { window.setStatusBarColor(activity.getResources().getColor(colorId)); } } }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackManager.java
public static void onPanelSlide(float slideOffset) { try {/*from ww w. ja v a 2s .co m*/ Activity activity = getInstance().getPenultimateActivity(); if (activity != null) { View decorView = activity.getWindow().getDecorView(); ViewCompat.setTranslationX(decorView, -(decorView.getMeasuredWidth() / 3.0f) * (1 - slideOffset)); } } catch (Exception e) { } }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackManager.java
public static void onPanelClosed() { try {// w w w . ja v a2 s. c om Activity activity = getInstance().getPenultimateActivity(); if (activity != null) { View decorView = activity.getWindow().getDecorView(); ViewCompat.setTranslationX(decorView, 0); } } catch (Exception e) { } }
From source file:Main.java
@TargetApi(VERSION_CODES.KITKAT) public static void hideSystemUI(Activity activity) { // Set the IMMERSIVE flag. // Set the content to appear under the system bars so that the content // doesn't resize when the system bars hideSelf and show. View decorView = activity.getWindow().getDecorView(); decorView.setSystemUiVisibility(// w ww .java2 s . c o m View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hideSelf nav bar | View.SYSTEM_UI_FLAG_FULLSCREEN // hideSelf status bar | View.SYSTEM_UI_FLAG_IMMERSIVE); }
From source file:Main.java
public static void closeInputMethod(Activity activity) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); if (imm != null) { if (imm.isActive()) { imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0); }//from w ww . j av a 2 s. c o m } }