-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature / screen size π± #20
Open
yschermer
wants to merge
5
commits into
develop
Choose a base branch
from
feature/screen-size
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ import android.content.Context.ACCESSIBILITY_SERVICE | |
import android.content.Context.CAPTIONING_SERVICE | ||
import android.content.res.Configuration.ORIENTATION_LANDSCAPE | ||
import android.content.res.Configuration.ORIENTATION_PORTRAIT | ||
import android.graphics.Point | ||
import android.os.Build | ||
import android.provider.Settings | ||
import android.util.DisplayMetrics | ||
import android.view.WindowManager | ||
import android.view.accessibility.AccessibilityManager | ||
import android.view.accessibility.CaptioningManager | ||
import androidx.annotation.RequiresApi | ||
|
@@ -82,7 +84,7 @@ internal object AccessibilityCollector { | |
) | ||
} | ||
} | ||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){ | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
put( | ||
"isAnimationsDisabled", | ||
isAnimationsDisabled(context) | ||
|
@@ -101,6 +103,16 @@ internal object AccessibilityCollector { | |
} | ||
}) | ||
|
||
getScreenSize(context)?.let { | ||
put( | ||
"screenWidth", | ||
it.first | ||
) | ||
put( | ||
"screenHeight", | ||
it.second | ||
) | ||
} | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
getSystemIntAsBool( | ||
|
@@ -146,19 +158,19 @@ internal object AccessibilityCollector { | |
*/ | ||
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) | ||
private fun isMagnificationEnabled(context: Context, serviceNames: List<String>): Boolean? = try { | ||
val isMagnificationByTripleTapGesturesEnabled = getSystemIntAsBool(context,"accessibility_display_magnification_enabled") ?: false | ||
val isMagnificationByTripleTapGesturesEnabled = getSystemIntAsBool(context, "accessibility_display_magnification_enabled") ?: false | ||
val isMagnificationByVolumeButtonsEnabled = serviceNames.map { s -> s.lowercase() }.contains("com.example.android.apis.accessibility.magnificationservice") | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
val isMagnificationByNavigationButtonEnabled = | ||
Settings.Secure.getString(context.contentResolver, "accessibility_button_targets").lowercase().contains("com.android.server.accessibility.magnificationcontroller") | ||
|
||
isMagnificationByTripleTapGesturesEnabled || isMagnificationByVolumeButtonsEnabled || isMagnificationByNavigationButtonEnabled | ||
}else{ | ||
} else { | ||
isMagnificationByTripleTapGesturesEnabled || isMagnificationByVolumeButtonsEnabled | ||
} | ||
} catch (e: Throwable) { | ||
Q42StatsLogger.e(TAG, "Could not read magnification. Returning null", e) | ||
Q42StatsLogger.w(TAG, "Could not read magnification, user likely has never used magnification before. Returning null.") | ||
null | ||
} | ||
|
||
|
@@ -181,4 +193,45 @@ internal object AccessibilityCollector { | |
Q42StatsLogger.e(TAG, "Could not read system int $name. Returning null", e) | ||
null | ||
} | ||
|
||
/** | ||
* Gets the screen size in density independent pixels with portrait orientation. | ||
* | ||
* Note: calculates size given portrait mode. | ||
*/ | ||
private fun getScreenSize(context: Context): Pair<Int, Int>? { | ||
return try { | ||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager | ||
val resources = context.resources | ||
|
||
// get screen size in pixels | ||
val pixelScreenSize = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
val windowMetrics = windowManager.currentWindowMetrics | ||
with(windowMetrics.bounds) { | ||
Pair(right, bottom) | ||
} | ||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { | ||
val point = Point() | ||
@Suppress("DEPRECATION") | ||
windowManager.defaultDisplay.getRealSize(point) | ||
Pair(point.x, point.y) | ||
} else { | ||
with(resources.displayMetrics) { | ||
Pair(widthPixels, heightPixels) | ||
} | ||
} | ||
|
||
val portraitDpScreenSize = with(pixelScreenSize) { | ||
val density = resources.displayMetrics.density | ||
Pair( | ||
(first / density).toInt(), | ||
(second / density).toInt() | ||
) | ||
} | ||
portraitDpScreenSize | ||
} catch (e: Throwable) { | ||
Q42StatsLogger.e(TAG, "Could not read screen size. Returning null", e) | ||
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. error or warning? Warning seems most appropriate. |
||
null | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think all data types are strings, right? But I might remember incorrectly. As documentation, it would be more informative to list how the backend should parse the string. Reading this table does not answer the question of whether it is an int or float