Created
October 30, 2017 06:12
-
-
Save mksantoki/78b0dacc7726ac298b037c540cdf09c7 to your computer and use it in GitHub Desktop.
This class is use to get screen width and height.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.util.DisplayMetrics; | |
import android.view.WindowManager; | |
/** | |
* Created by maulik santoki on 17/10/17. | |
*/ | |
public class ScreenUtils { | |
/** | |
* This class is use to get screen width and height. | |
*/ | |
private ScreenUtils() { | |
// This utility class is not publicly instantiable | |
} | |
/** | |
* this method is use for get device screen width. | |
* | |
* @param context pass application context. | |
* @version V1.0 | |
*/ | |
public static int getScreenWidth(Context context) { | |
WindowManager windowManager = (WindowManager) context | |
.getSystemService(Context.WINDOW_SERVICE); | |
DisplayMetrics dm = new DisplayMetrics(); | |
windowManager.getDefaultDisplay().getMetrics(dm); | |
return dm.widthPixels; | |
} | |
/** | |
* this method is use for get device screen Height. | |
* | |
* @param context pass application context. | |
* @version V1.0 | |
*/ | |
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; | |
} | |
/** | |
* this method is use for get device StatusBar Height. | |
* | |
* @param context pass application context. | |
* @version V1.0 | |
*/ | |
public static int getStatusBarHeight(Context context) { | |
int result = 0; | |
int resourceId = context.getResources() | |
.getIdentifier("status_bar_height", "dimen", "android"); | |
if (resourceId > 0) { | |
result = context.getResources().getDimensionPixelSize(resourceId); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment