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 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## XX.XX.XX
* Improved content size management of content blocks.
* Mitigated an issue where, the action bar was overlapping with the content display.

## 24.7.8
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
return false;
}

public void registerWebViewUrlListeners(List<WebViewUrlListener> listener) {
this.listeners.addAll(listener);
public void registerWebViewUrlListener(WebViewUrlListener listener) {
this.listeners.add(listener);
}
}
61 changes: 28 additions & 33 deletions sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
Expand Down Expand Up @@ -44,9 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
Log.d(Countly.TAG, "[TransparentActivity] onCreate, content received, showing it");

// there is a stripe at the top of the screen for contents
// we eliminate it with no action bar full screen and this adds more smoothness
// the stripe is because of our transparency
//setTheme(android.R.style.Theme_DeviceDefault_NoActionBar_Fullscreen);
// we eliminate it with hiding the system ui
hideSystemUI();
super.onCreate(savedInstanceState);
overridePendingTransition(0, 0);
Expand Down Expand Up @@ -78,9 +75,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
};

configLandscape.listeners.add(listener);
configPortrait.listeners.add(listener);

// Configure window layout parameters
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.gravity = Gravity.TOP | Gravity.LEFT; // try out START
Expand Down Expand Up @@ -141,8 +135,8 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
return config;
}

private void changeOrientation(TransparentActivityConfig config) {
Log.d(Countly.TAG, "[TransparentActivity] changeOrientation, config x: [" + config.x + "] y: [" + config.y + "] width: [" + config.width + "] height: [" + config.height + "]");
private void resizeContent(TransparentActivityConfig config) {
Log.d(Countly.TAG, "[TransparentActivity] resizeContent, config x: [" + config.x + "] y: [" + config.y + "] width: [" + config.width + "] height: [" + config.height + "]");
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = config.x;
params.y = config.y;
Expand All @@ -165,34 +159,36 @@ private void changeOrientation(TransparentActivityConfig config) {
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);
resizeContent(configLandscape);
}
break;
case Configuration.ORIENTATION_PORTRAIT:
if (configPortrait != null) {
configPortrait = setupConfig(configPortrait);
// This is only needed for the portrait mode and
// after android 35 the function that gives height gives the full height of the screen
// so we need to subtract the height of the navigation bar
// this is implemented twice because in the future resize_me action will be able to change the height of the content
int navBarHeight = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
navBarHeight = getNavigationBarHeight();
}
changeOrientation(configPortrait);
resizeContent(configPortrait);
}
break;
default:
Expand Down Expand Up @@ -294,7 +290,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 Expand Up @@ -385,18 +381,17 @@ private WebView createWebView(TransparentActivityConfig config) {
webView.clearHistory();

CountlyWebViewClient client = new CountlyWebViewClient();
client.registerWebViewUrlListeners(config.listeners);
client.registerWebViewUrlListener(new WebViewUrlListener() {
@Override public boolean onUrl(String url, WebView webView) {
if (url.startsWith(URL_START)) {
return contentUrlAction(url, webView);
}
return false;
}
});

webView.setWebViewClient(client);
webView.loadUrl(config.url);
return webView;
}

private int getNavigationBarHeight() {
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return getResources().getDimensionPixelSize(resourceId);
}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package ly.count.android.sdk;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

class TransparentActivityConfig implements Serializable {
Integer x;
Integer y;
Integer width;
Integer height;
String url;
List<WebViewUrlListener> listeners;

TransparentActivityConfig(Integer x, Integer y, Integer width, Integer height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.listeners = new ArrayList<>();
}
}
Loading