Skip to content

Commit

Permalink
Merge pull request #396 from Countly/missing_contents
Browse files Browse the repository at this point in the history
fix: missing density calc
  • Loading branch information
turtledreams authored Oct 1, 2024
2 parents 72e471a + 97aa7fa commit 96497cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* Mitigated an issue where content fetching was enabled after initialization of the SDK.

* Fixed an issue where the validation of the parameters during content retrieval was improper.
* Mitigated an issue that density calculation was missing while resizing content.

## 24.7.3
* Automatic view pause/resumes are changed with stop/start for better data consistency.
* Added the config interface 'experimental' to group experimental features.
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/ly/count/android/sdk/ModuleContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private String prepareContentFetchRequest(@NonNull DisplayMetrics displayMetrics
}

boolean validateResponse(@NonNull JSONObject response) {
boolean success = response.optBoolean("result", false);
boolean success = response.optString("result", "error").equals("success");
JSONArray content = response.optJSONArray("content");
return success && content != null && content.length() > 0;
}
Expand Down
25 changes: 16 additions & 9 deletions sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,26 @@ private void resizeMeAction(Map<String, Object> query) {
return;
}
try {
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
final DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);

float density = metrics.density;

JSONObject resizeMeJson = (JSONObject) resizeMe;
Log.v(Countly.TAG, "[TransparentActivity] resizeMeAction, resize_me JSON: [" + resizeMeJson + "]");
JSONObject portrait = resizeMeJson.getJSONObject("p");
JSONObject landscape = resizeMeJson.getJSONObject("l");
configPortrait.x = portrait.getInt("x");
configPortrait.y = portrait.getInt("y");
configPortrait.width = portrait.getInt("w");
configPortrait.height = portrait.getInt("h");

configLandscape.x = landscape.getInt("x");
configLandscape.y = landscape.getInt("y");
configLandscape.width = landscape.getInt("w");
configLandscape.height = landscape.getInt("h");
configPortrait.x = (int) Math.ceil(portrait.getInt("x") * density);
configPortrait.y = (int) Math.ceil(portrait.getInt("y") * density);
configPortrait.width = (int) Math.ceil(portrait.getInt("w") * density);
configPortrait.height = (int) Math.ceil(portrait.getInt("h") * density);

configLandscape.x = (int) Math.ceil(landscape.getInt("x") * density);
configLandscape.y = (int) Math.ceil(landscape.getInt("y") * density);
configLandscape.width = (int) Math.ceil(landscape.getInt("w") * density);
configLandscape.height = (int) Math.ceil(landscape.getInt("h") * density);

changeOrientationInternal();
} catch (JSONException e) {
Expand Down

0 comments on commit 96497cf

Please sign in to comment.