Skip to content

Commit 5e052a6

Browse files
refactor: formatting
1 parent e442f6f commit 5e052a6

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed

sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,21 @@ protected void onCreate(Bundle savedInstanceState) {
5555
configLandscape = (TransparentActivityConfig) intent.getSerializableExtra(CONFIGURATION_LANDSCAPE);
5656
configPortrait = (TransparentActivityConfig) intent.getSerializableExtra(CONFIGURATION_PORTRAIT);
5757
Log.v(Countly.TAG, "[TransparentActivity] onCreate, orientation: " + currentOrientation);
58-
Log.v(Countly.TAG, "[TransparentActivity] onCreate, configLandscape x: [" + configLandscape.x + "] y: [" + configLandscape.y + "] width: [" + configLandscape.width + "] height: [" + configLandscape.height + "], topOffset: [" + configLandscape.topOffset + "], leftOffset: [" + configLandscape.leftOffset + "]");
59-
Log.v(Countly.TAG, "[TransparentActivity] onCreate, configPortrait x: [" + configPortrait.x + "] y: [" + configPortrait.y + "] width: [" + configPortrait.width + "] height: [" + configPortrait.height + "], topOffset: [" + configPortrait.topOffset + "], leftOffset: [" + configPortrait.leftOffset + "]");
58+
Log.v(Countly.TAG, "[TransparentActivity] onCreate, configLandscape x: ["
59+
+ configLandscape.x
60+
+ "] y: ["
61+
+ configLandscape.y
62+
+ "] width: ["
63+
+ configLandscape.width
64+
+ "] height: ["
65+
+ configLandscape.height
66+
+ "], topOffset: ["
67+
+ configLandscape.topOffset
68+
+ "], leftOffset: ["
69+
+ configLandscape.leftOffset
70+
+ "]");
71+
Log.v(Countly.TAG,
72+
"[TransparentActivity] onCreate, configPortrait x: [" + configPortrait.x + "] y: [" + configPortrait.y + "] width: [" + configPortrait.width + "] height: [" + configPortrait.height + "], topOffset: [" + configPortrait.topOffset + "], leftOffset: [" + configPortrait.leftOffset + "]");
6073

6174
TransparentActivityConfig config;
6275
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
@@ -70,10 +83,10 @@ protected void onCreate(Bundle savedInstanceState) {
7083
// Configure window layout parameters
7184
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
7285
params.gravity = Gravity.TOP | Gravity.START; // try out START
73-
86+
7487
int adjustedX = config.x;
7588
int adjustedY = config.y;
76-
89+
7790
if (config.useSafeArea) {
7891
if (config.leftOffset > 0) {
7992
adjustedX += config.leftOffset;
@@ -84,10 +97,10 @@ protected void onCreate(Bundle savedInstanceState) {
8497
Log.d(Countly.TAG, "[TransparentActivity] onCreate, using safe area mode, adjusting y from [" + config.y + "] to [" + adjustedY + "] (topOffset: " + config.topOffset + ")");
8598
}
8699
}
87-
100+
88101
params.x = adjustedX;
89102
params.y = adjustedY;
90-
103+
91104
params.height = config.height;
92105
params.width = config.width;
93106
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
@@ -119,32 +132,33 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
119132

120133
if (!config.useSafeArea) {
121134
final DisplayMetrics metrics = UtilsDevice.getDisplayMetrics(this);
122-
135+
123136
if (config.width < 1) {
124137
config.width = metrics.widthPixels;
125138
}
126139
if (config.height < 1) {
127140
config.height = metrics.heightPixels;
128141
}
129142
}
130-
143+
131144
if (config.x < 1) {
132145
config.x = 0;
133146
}
134147
if (config.y < 1) {
135148
config.y = 0;
136149
}
137-
150+
138151
Log.d(Countly.TAG, "[TransparentActivity] setupConfig, final config - x: [" + config.x + "], y: [" + config.y + "], width: [" + config.width + "], height: [" + config.height + "], useSafeArea: [" + config.useSafeArea + "]");
139152
return config;
140153
}
141154

142155
private void resizeContent(TransparentActivityConfig config) {
143-
Log.d(Countly.TAG, "[TransparentActivity] resizeContent(config), config dimensions (px): [" + config.width + "x" + config.height + "], x: [" + config.x + "], y: [" + config.y + "], useSafeArea: [" + config.useSafeArea + "], topOffset: [" + config.topOffset + "], leftOffset: [" + config.leftOffset + "]");
144-
156+
Log.d(Countly.TAG,
157+
"[TransparentActivity] resizeContent(config), config dimensions (px): [" + config.width + "x" + config.height + "], x: [" + config.x + "], y: [" + config.y + "], useSafeArea: [" + config.useSafeArea + "], topOffset: [" + config.topOffset + "], leftOffset: [" + config.leftOffset + "]");
158+
145159
int adjustedX = config.x;
146160
int adjustedY = config.y;
147-
161+
148162
if (config.useSafeArea) {
149163
if (config.leftOffset > 0) {
150164
adjustedX += config.leftOffset;
@@ -155,7 +169,7 @@ private void resizeContent(TransparentActivityConfig config) {
155169
Log.d(Countly.TAG, "[TransparentActivity] resizeContent(config), applying top offset, adjusted y: [" + adjustedY + "]");
156170
}
157171
}
158-
172+
159173
WindowManager.LayoutParams params = getWindow().getAttributes();
160174
Log.d(Countly.TAG, "[TransparentActivity] resizeContent(config), BEFORE - params.x: [" + params.x + "], params.y: [" + params.y + "], params.gravity: [" + params.gravity + "]");
161175
params.gravity = Gravity.TOP | Gravity.START; // safe?
@@ -164,7 +178,7 @@ private void resizeContent(TransparentActivityConfig config) {
164178
params.height = config.height;
165179
params.width = config.width;
166180
getWindow().setAttributes(params);
167-
181+
168182
WindowManager.LayoutParams verifyParams = getWindow().getAttributes();
169183
Log.d(Countly.TAG, "[TransparentActivity] resizeContent(config), AFTER - params.x: [" + verifyParams.x + "], params.y: [" + verifyParams.y + "], params.gravity: [" + verifyParams.gravity + "], width: [" + verifyParams.width + "], height: [" + verifyParams.height + "]");
170184

@@ -177,7 +191,7 @@ private void resizeContent(TransparentActivityConfig config) {
177191
webLayoutParams.width = config.width;
178192
webLayoutParams.height = config.height;
179193
webView.setLayoutParams(webLayoutParams);
180-
194+
181195
Log.d(Countly.TAG, "[TransparentActivity] resizeContent(config), layout params set - relativeLayout: [" + layoutParams.width + "x" + layoutParams.height + "], webView: [" + webLayoutParams.width + "x" + webLayoutParams.height + "]");
182196
}
183197

@@ -195,23 +209,23 @@ public void onConfigurationChanged(android.content.res.Configuration newConfig)
195209

196210
private void resizeContent() {
197211
TransparentActivityConfig currentConfig = (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) ? configLandscape : configPortrait;
198-
212+
199213
float density = getResources().getDisplayMetrics().density;
200214
int widthPx, heightPx;
201-
215+
202216
if (currentConfig != null && currentConfig.useSafeArea) {
203217
Log.d(Countly.TAG, "[TransparentActivity] resizeContent, recalculating safe area dimensions for orientation change");
204-
218+
205219
SafeAreaDimensions safeArea = SafeAreaCalculator.calculateSafeAreaDimensions(this, Countly.sharedInstance().L);
206-
220+
207221
configPortrait.topOffset = safeArea.portraitTopOffset;
208222
configPortrait.leftOffset = safeArea.portraitLeftOffset;
209223
configLandscape.topOffset = safeArea.landscapeTopOffset;
210224
configLandscape.leftOffset = safeArea.landscapeLeftOffset;
211-
225+
212226
Log.d(Countly.TAG, "[TransparentActivity] resizeContent, updated offsets - Portrait: topOffset=[" + configPortrait.topOffset + "], leftOffset=[" + configPortrait.leftOffset + "]");
213227
Log.d(Countly.TAG, "[TransparentActivity] resizeContent, updated offsets - Landscape: topOffset=[" + configLandscape.topOffset + "], leftOffset=[" + configLandscape.leftOffset + "]");
214-
228+
215229
int topOffset, leftOffset;
216230
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
217231
widthPx = safeArea.landscapeWidth;
@@ -224,16 +238,30 @@ private void resizeContent() {
224238
topOffset = safeArea.portraitTopOffset;
225239
leftOffset = safeArea.portraitLeftOffset;
226240
}
227-
228-
Log.d(Countly.TAG, "[TransparentActivity] resizeContent, safe area mode - sending dimensions to webview (px): [" + widthPx + "x" + heightPx + "], (dp): [" + Math.round(widthPx / density) + "x" + Math.round(heightPx / density) + "], density: [" + density + "], topOffset: [" + topOffset + "], leftOffset: [" + leftOffset + "]");
241+
242+
Log.d(Countly.TAG, "[TransparentActivity] resizeContent, safe area mode - sending dimensions to webview (px): ["
243+
+ widthPx
244+
+ "x"
245+
+ heightPx
246+
+ "], (dp): ["
247+
+ Math.round(widthPx / density)
248+
+ "x"
249+
+ Math.round(heightPx / density)
250+
+ "], density: ["
251+
+ density
252+
+ "], topOffset: ["
253+
+ topOffset
254+
+ "], leftOffset: ["
255+
+ leftOffset
256+
+ "]");
229257
} else {
230258
final DisplayMetrics metrics = UtilsDevice.getDisplayMetrics(this);
231259
widthPx = metrics.widthPixels;
232260
heightPx = metrics.heightPixels;
233-
261+
234262
Log.d(Countly.TAG, "[TransparentActivity] resizeContent, immersive mode - sending dimensions to webview (px): [" + widthPx + "x" + heightPx + "], (dp): [" + Math.round(widthPx / density) + "x" + Math.round(heightPx / density) + "], density: [" + density + "]");
235263
}
236-
264+
237265
int scaledWidth = Math.round(widthPx / density);
238266
int scaledHeight = Math.round(heightPx / density);
239267
webView.loadUrl("javascript:window.postMessage({type: 'resize', width: " + scaledWidth + ", height: " + scaledHeight + "}, '*');");
@@ -379,14 +407,14 @@ private void resizeMeAction(Map<String, Object> query) {
379407
Log.v(Countly.TAG, "[TransparentActivity] resizeMeAction, resize_me JSON: [" + resizeMeJson + "]");
380408
JSONObject portrait = resizeMeJson.getJSONObject("p");
381409
JSONObject landscape = resizeMeJson.getJSONObject("l");
382-
410+
383411
boolean portraitUseSafeArea = configPortrait.useSafeArea;
384412
boolean landscapeUseSafeArea = configLandscape.useSafeArea;
385413
int portraitTopOffset = configPortrait.topOffset;
386414
int landscapeTopOffset = configLandscape.topOffset;
387415
int portraitLeftOffset = configPortrait.leftOffset;
388416
int landscapeLeftOffset = configLandscape.leftOffset;
389-
417+
390418
configPortrait.x = (int) Math.ceil(portrait.getInt("x") * density);
391419
configPortrait.y = (int) Math.ceil(portrait.getInt("y") * density);
392420
configPortrait.width = (int) Math.ceil(portrait.getInt("w") * density);
@@ -402,7 +430,7 @@ private void resizeMeAction(Map<String, Object> query) {
402430
configLandscape.useSafeArea = landscapeUseSafeArea;
403431
configLandscape.topOffset = landscapeTopOffset;
404432
configLandscape.leftOffset = landscapeLeftOffset;
405-
433+
406434
Log.d(Countly.TAG, "[TransparentActivity] resizeMeAction, updated configs - Portrait: useSafeArea=[" + portraitUseSafeArea + "], topOffset=[" + portraitTopOffset + "], leftOffset=[" + portraitLeftOffset + "]");
407435
Log.d(Countly.TAG, "[TransparentActivity] resizeMeAction, updated configs - Landscape: useSafeArea=[" + landscapeUseSafeArea + "], topOffset=[" + landscapeTopOffset + "], leftOffset=[" + landscapeLeftOffset + "]");
408436

0 commit comments

Comments
 (0)