-
Notifications
You must be signed in to change notification settings - Fork 0
Request to Merge #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: parent7402e
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,74 @@ public static float getScreenDensity() { | |
public static int getScreenDensityDpi() { | ||
return Resources.getSystem().getDisplayMetrics().densityDpi; | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* Return X (width) of the screen expressed as dots-per-inch. | ||
* | ||
* @return the width of screen density expressed as dots-per-inch | ||
*/ | ||
public static int getScreenXDpi() { | ||
return Resources.getSystem().getDisplayMetrics().xdpi; | ||
} | ||
|
||
/** | ||
* Return Y (height) of the screen expressed as dots-per-inch. | ||
* | ||
* @return the height of screen density expressed as dots-per-inch | ||
*/ | ||
public static int getScreenYDpi() { | ||
return Resources.getSystem().getDisplayMetrics().ydpi; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Return the distance between the given View's X (start point of View's width) and the screen width. | ||
* | ||
* @return the distance between the given View's X (start point of View's width) and the screen width. | ||
*/ | ||
public float calculateDistanceByX(View view) { | ||
int[] point = new int[0]; | ||
view.getLocationOnScreen(point); | ||
return (getScreenWidth() - point[0]).toFloat(); | ||
} | ||
Comment on lines
+144
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize the 'point' array with a size of 2. Tell me moreIn the |
||
|
||
/** | ||
* Return the distance between the given View's Y (start point of View's height) and the screen height. | ||
* | ||
* @return the distance between the given View's Y (start point of View's height) and the screen height. | ||
*/ | ||
public float calculateDistanceByY(View view) { | ||
int[] point = new int[0]; | ||
view.getLocationOnScreen(point); | ||
return (getScreenHeight() - point[1]).toFloat(); | ||
} | ||
|
||
/** | ||
* Return the X coordinate of the given View on the screen. | ||
* | ||
* @return X coordinate of the given View on the screen. | ||
*/ | ||
public int getViewX(View view){ | ||
int[] point = new int[0]; | ||
view.getLocationOnScreen(point); | ||
return point[0]; | ||
} | ||
|
||
/** | ||
* Return the Y coordinate of the given View on the screen. | ||
* | ||
* @return Y coordinate of the given View on the screen. | ||
*/ | ||
public int getViewY(View view){ | ||
int[] point = new int[0]; | ||
view.getLocationOnScreen(point); | ||
return point[1]; | ||
} | ||
|
||
|
||
/** | ||
* Set full screen. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use cast to float instead of .toFloat() for int conversion.
Tell me more
In the
calculateDistanceByX
andcalculateDistanceByY
methods, you're using.toFloat()
to convert the result to a float. However, this method doesn't exist for int in Java. Instead, you should use a cast to float. Changereturn (getScreenWidth() - point[0]).toFloat();
toreturn (float)(getScreenWidth() - point[0]);
. Make the same change incalculateDistanceByY
.