List of usage examples for android.app Activity getWindow
public Window getWindow()
From source file:com.mark.quick.ui.view.swipebacklayout.SwipeBackLayout.java
/** * Activity //from www. jav a 2 s . co m * * @param activity */ void attachToActivity(Activity activity) { mActivity = activity; setSliderFadeColor(Color.TRANSPARENT); ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); //view mShadowView = new SwipeBackShadowView(activity); addView(mShadowView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); //??DecorViewchild ViewGroup contentView = (ViewGroup) decorView.getChildAt(0); decorView.removeView(contentView); addView(contentView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); //??DecorViewchild decorView.addView(this, 0); }
From source file:org.cryptsecure.Utility.java
/** * No screenshots. Call this in OnCreate BEFORE setting the layout! * /* ww w . j a va 2 s . com*/ * @param activity * the activity */ public static void noScreenshots(Activity activity) { // ON GINGERBREAD DEVICES (esp from SAMSUNG) there may be a bug // scrambling the view // if this is set. // See: // http://stackoverflow.com/questions/9822076/how-do-i-prevent-android-taking-a-screenshot-when-my-app-goes-to-the-background if (android.os.Build.VERSION.SDK_INT != android.os.Build.VERSION_CODES.GINGERBREAD && android.os.Build.VERSION.SDK_INT != android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); } }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
/** * Activity /*from ww w. j a v a 2s .c o m*/ * * @param activity */ public void attachToActivity(Activity activity) { mActivity = activity; setSliderFadeColor(Color.TRANSPARENT); mShadowView = new View(activity); setIsNeedShowShadow(mIsNeedShowShadow); addView(mShadowView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); mContentView = decorView.getChildAt(0); decorView.removeView(mContentView); decorView.addView(this); addView(mContentView, 1, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); }
From source file:com.ywesee.amiko.MainActivity.java
/** * Takes screenshot of the whole screen/*from w w w .j av a 2s . co m*/ * @param activity */ public void sendFeedbackScreenshot(final Activity activity, int mode) { try { // Get root windows final View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content) .getRootView(); rootView.setDrawingCacheEnabled(true); Bitmap bitmap = rootView.getDrawingCache(); // The file be saved to the download folder File outputFile = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/amiko_screenshot.png"); FileOutputStream fOutStream = new FileOutputStream(outputFile); // Picture is then compressed bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOutStream); rootView.setDrawingCacheEnabled(false); fOutStream.close(); // Start email activity if (mode == 1) startEmailActivity(activity, Uri.fromFile(outputFile), "", "AmiKo for Android"); else if (mode == 2) startEmailActivity(activity, Uri.fromFile(outputFile), "zdavatz@ywesee.com", "Interaction notification"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.example.ray.firstapp.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }/*from w ww . j a va2 s.c o m*/ if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }//from w ww .ja v a 2 s . c o m if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset, bottomBar.isShy(), bottomBar.mIsTabletMode)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:org.mariotaku.twidere.util.Utils.java
public static void restartActivity(final Activity activity) { if (activity == null) return;//from ww w.j a v a 2s . c o m final int enter_anim = android.R.anim.fade_in; final int exit_anim = android.R.anim.fade_out; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { ActivityAccessor.overridePendingTransition(activity, enter_anim, exit_anim); } else { activity.getWindow().setWindowAnimations(0); } activity.finish(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { ActivityAccessor.overridePendingTransition(activity, enter_anim, exit_anim); } else { activity.getWindow().setWindowAnimations(0); } activity.startActivity(activity.getIntent()); }
From source file:com.dwdesign.tweetings.util.Utils.java
public static void restartActivity(final Activity activity, final boolean animation) { if (activity == null) return;//w w w. ja v a2s . c o m final int enter_anim = animation ? android.R.anim.fade_in : 0; final int exit_anim = animation ? android.R.anim.fade_out : 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { OverridePendingTransitionAccessor.overridePendingTransition(activity, enter_anim, exit_anim); } else { activity.getWindow().setWindowAnimations(0); } activity.finish(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { OverridePendingTransitionAccessor.overridePendingTransition(activity, enter_anim, exit_anim); } else { activity.getWindow().setWindowAnimations(0); } activity.startActivity(activity.getIntent()); }
From source file:com.aliyun.homeshell.Folder.java
public void hideSoftInputMethod(Activity activity) { View v;/*from ww w. ja va2 s. c om*/ if (activity == null || activity.getWindow() == null) { v = mFolderName; } else { v = activity.getWindow().peekDecorView(); } // YUNOS END try { if (v != null && v.getWindowToken() != null) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); boolean result = imm.hideSoftInputFromWindow(v.getWindowToken(), 0); Log.d(TAG, "hideSoftInputMethod, ret:" + result); } } catch (RuntimeException e) { // add try catch block due to InputMethod throws // RuntimeException; // BugID:101639 Log.e(TAG, e.toString(), e); } }
From source file:de.vanita5.twittnuker.util.Utils.java
public static int inferStatusBarHeight(final Activity activity) { final Window w = activity.getWindow(); final View decorView = w.getDecorView(); final Rect rect = new Rect(); decorView.getWindowVisibleDisplayFrame(rect); return rect.top; }