Skip to content
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

Resize me action for content zone Impl #445

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion sdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:exported="false"/>
<uses-library android:name="android.test.runner"/>
<activity android:name=".TransparentActivity"
android:configChanges="orientation|screenSize"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>
</application>
Expand Down
26 changes: 18 additions & 8 deletions sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,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 @@ -159,20 +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;
Log.i(Countly.TAG, "[TransparentActivity] onConfigurationChanged, orientation changed to currentOrientation: [" + currentOrientation + "]");
changeOrientationInternal();
}

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

int scaledWidth = (int) Math.ceil(metrics.widthPixels / metrics.density);
int scaledHeight = (int) Math.ceil(metrics.heightPixels / metrics.density);

// 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 @@ -186,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 @@ -288,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
Loading