Skip to content

Commit

Permalink
feat: fully change to resize_me
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Jan 7, 2025
1 parent 4117176 commit 27f411f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## XX.XX.XX
* Improved content size management of content blocks.

## 24.7.8
* Added a config option to content (setZoneTimerInterval) to set content zone timer. (Experimental!)

Expand Down
37 changes: 13 additions & 24 deletions sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class TransparentActivity extends Activity {
WebView webView;
RelativeLayout relativeLayout;
static ContentCallback globalContentCallback;
private int lastWidth = -1;
private int lastHeight = -1;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -116,8 +114,6 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
final Display display = wm.getDefaultDisplay();
final DisplayMetrics metrics = new DisplayMetrics(); // this gets all
display.getMetrics(metrics);
lastWidth = metrics.widthPixels;
lastHeight = metrics.heightPixels;

if (config == null) {
Log.w(Countly.TAG, "[TransparentActivity] setupConfig, Config is null, using default values with full screen size");
Expand All @@ -139,7 +135,7 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
return config;
}

private void changeOrientation(TransparentActivityConfig config, int navBarHeight) {
private void resizeContent(TransparentActivityConfig config, int navBarHeight) {
Log.d(Countly.TAG, "[TransparentActivity] changeOrientation, config x: [" + config.x + "] y: [" + config.y + "] width: [" + config.width + "] height: [" + config.height + "]");
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = config.x;
Expand All @@ -163,37 +159,30 @@ private void changeOrientation(TransparentActivityConfig config, int navBarHeigh
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d(Countly.TAG, "[TransparentActivity] onConfigurationChanged orientation: [" + newConfig.orientation + "], currentOrientation: [" + currentOrientation + "]");
Log.v(Countly.TAG, "[TransparentActivity] onConfigurationChanged, Landscape: [" + Configuration.ORIENTATION_LANDSCAPE + "] Portrait: [" + Configuration.ORIENTATION_PORTRAIT + "]");

if (currentOrientation != newConfig.orientation) {
currentOrientation = newConfig.orientation;
}

// CHANGE SCREEN SIZE
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
final DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);

if (metrics.widthPixels != lastWidth || metrics.heightPixels != lastHeight) {
int scaledWidth = (int) Math.ceil(metrics.widthPixels / metrics.density);
int scaledHeight = (int) Math.ceil(metrics.heightPixels / metrics.density);

webView.loadUrl("javascript:window.postMessage({type: 'resize', width: " + scaledWidth + ", height: " + scaledHeight + "}, '*');");
int scaledWidth = (int) Math.ceil(metrics.widthPixels / metrics.density);
int scaledHeight = (int) Math.ceil(metrics.heightPixels / metrics.density);

lastWidth = metrics.widthPixels;
lastHeight = metrics.heightPixels;
}

if (currentOrientation != newConfig.orientation) {
currentOrientation = newConfig.orientation;
Log.i(Countly.TAG, "[TransparentActivity] onConfigurationChanged, orientation changed to currentOrientation: [" + currentOrientation + "]");
changeOrientationInternal();
}
// refactor in the future to use the resize_me action
webView.loadUrl("javascript:window.postMessage({type: 'resize', width: " + scaledWidth + ", height: " + scaledHeight + "}, '*');");
}

private void changeOrientationInternal() {
private void resizeContentInternal() {
switch (currentOrientation) {
case Configuration.ORIENTATION_LANDSCAPE:
if (configLandscape != null) {
configLandscape = setupConfig(configLandscape);
changeOrientation(configLandscape, 0);
resizeContent(configLandscape, 0);
}
break;
case Configuration.ORIENTATION_PORTRAIT:
Expand All @@ -207,7 +196,7 @@ private void changeOrientationInternal() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
navBarHeight = getNavigationBarHeight();
}
changeOrientation(configPortrait, navBarHeight);
resizeContent(configPortrait, navBarHeight);
}
break;
default:
Expand Down Expand Up @@ -309,7 +298,7 @@ private void resizeMeAction(Map<String, Object> query) {
configLandscape.width = (int) Math.ceil(landscape.getInt("w") * density);
configLandscape.height = (int) Math.ceil(landscape.getInt("h") * density);

changeOrientationInternal();
resizeContentInternal();
} catch (JSONException e) {
Log.e(Countly.TAG, "[TransparentActivity] resizeMeAction, Failed to parse resize JSON", e);
}
Expand Down

0 comments on commit 27f411f

Please sign in to comment.