Skip to content

Commit

Permalink
feat: call js function
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Jan 6, 2025
1 parent f1d25a5 commit 56a6cbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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: 26 additions & 0 deletions sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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 @@ -114,6 +116,8 @@ 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 Down Expand Up @@ -160,6 +164,28 @@ 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 + "]");

// CHANGE SCREEN SIZE
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
final DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
boolean portrait = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT;

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);

int portraitWidth = portrait ? scaledWidth : scaledHeight;
int portraitHeight = portrait ? scaledHeight : scaledWidth;
int landscapeWidth = portrait ? scaledHeight : scaledWidth;
int landscapeHeight = portrait ? scaledWidth : scaledHeight;
webView.loadUrl("javascript:resizeContent(" + portraitWidth + "," + portraitHeight + "," + landscapeWidth + "," + landscapeHeight + ");");

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

if (currentOrientation != newConfig.orientation) {
currentOrientation = newConfig.orientation;
Log.i(Countly.TAG, "[TransparentActivity] onConfigurationChanged, orientation changed to currentOrientation: [" + currentOrientation + "]");
Expand Down

0 comments on commit 56a6cbf

Please sign in to comment.