Skip to content

Commit 66a36bc

Browse files
fix: remove percantaged
1 parent 8b51e0b commit 66a36bc

File tree

5 files changed

+30
-103
lines changed

5 files changed

+30
-103
lines changed

app/src/main/java/ly/count/android/demo/ActivityExampleTransparentActivity.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,31 @@ public void onCreate(Bundle savedInstanceState) {
1717
}
1818

1919
public void onClickShowTransparentActivity(View v) {
20-
EditText editText1, editText2, editText3, editText4, editText5, editText6, editText7, editText8, editText9;
20+
EditText editText1, editText2, editText5, editText6, editText9;
2121

2222
editText1 = findViewById(R.id.buttonShowTransparent_text1);
2323
editText2 = findViewById(R.id.buttonShowTransparent_text2);
24-
editText3 = findViewById(R.id.buttonShowTransparent_text3);
25-
editText4 = findViewById(R.id.buttonShowTransparent_text4);
2624
editText5 = findViewById(R.id.buttonShowTransparent_text5);
2725
editText6 = findViewById(R.id.buttonShowTransparent_text6);
28-
editText7 = findViewById(R.id.buttonShowTransparent_text7);
29-
editText8 = findViewById(R.id.buttonShowTransparent_text8);
3026
editText9 = findViewById(R.id.buttonShowTransparent_text9);
3127

3228
Integer xCoordinate = getOptionalNullInt(editText1.getText().toString());
3329
Integer yCoordinate = getOptionalNullInt(editText2.getText().toString());
34-
Double xPercentage = getOptionalNullDouble(editText3.getText().toString());
35-
Double yPercentage = getOptionalNullDouble(editText4.getText().toString());
3630
Integer widthPx = getOptionalNullInt(editText5.getText().toString());
3731
Integer heightPx = getOptionalNullInt(editText6.getText().toString());
38-
Double widthPercentage = getOptionalNullDouble(editText7.getText().toString());
39-
Double heightPercentage = getOptionalNullDouble(editText8.getText().toString());
4032
String webviewURL = editText9.getText().toString();
4133
if (webviewURL.isEmpty()) {
4234
webviewURL = "https://countly.com/";
4335
}
4436

4537
Log.d("Countly", "ActivityExampleTransparentActivity, xCoordinate: " + xCoordinate);
4638
Log.d("Countly", "ActivityExampleTransparentActivity, yCoordinate: " + yCoordinate);
47-
Log.d("Countly", "ActivityExampleTransparentActivity, xPercentage: " + xPercentage);
48-
Log.d("Countly", "ActivityExampleTransparentActivity, yPercentage: " + yPercentage);
4939
Log.d("Countly", "ActivityExampleTransparentActivity, widthPx: " + widthPx);
5040
Log.d("Countly", "ActivityExampleTransparentActivity, heightPx: " + heightPx);
51-
Log.d("Countly", "ActivityExampleTransparentActivity, widthPercentage: " + widthPercentage);
52-
Log.d("Countly", "ActivityExampleTransparentActivity, heightPercentage: " + heightPercentage);
5341
Log.d("Countly", "ActivityExampleTransparentActivity, webviewURL: " + webviewURL);
5442

5543
TransparentActivityConfig config = new TransparentActivityConfig(xCoordinate, yCoordinate, widthPx, heightPx);
5644
config.setUrl(webviewURL);
57-
config.setPercents(xPercentage, yPercentage, widthPercentage, heightPercentage);
5845

5946
TransparentActivity.showActivity(this, config);
6047
}
@@ -66,12 +53,4 @@ private Integer getOptionalNullInt(String value) {
6653
return null;
6754
}
6855
}
69-
70-
private Double getOptionalNullDouble(String value) {
71-
try {
72-
return Double.parseDouble(value);
73-
} catch (Exception e) {
74-
return null;
75-
}
76-
}
7756
}

app/src/main/res/layout/activity_example_transparent_activity.xml

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,77 +8,57 @@
88
android:paddingRight="@dimen/activity_horizontal_margin"
99
android:paddingTop="@dimen/activity_vertical_margin"
1010
android:paddingBottom="@dimen/activity_vertical_margin"
11-
tools:context=".ActivityExampleCrashReporting"
11+
tools:context=".ActivityExampleTransparentActivity"
1212
android:gravity="center_vertical"
1313
>
1414

1515
<EditText
1616
android:layout_width="match_parent"
1717
android:layout_height="wrap_content"
1818
android:id="@+id/buttonShowTransparent_text1"
19-
android:hint="X Coordinate"
20-
android:gravity="center"/>
19+
android:hint="@string/x_coordinate"
20+
android:gravity="center"
21+
android:autofillHints="number,coordinate"
22+
android:inputType="numberDecimal"/>
2123
<EditText
2224
android:layout_width="match_parent"
2325
android:layout_height="wrap_content"
2426
android:id="@+id/buttonShowTransparent_text2"
25-
android:hint="Y Coordinate"
26-
android:gravity="center"/>
27-
28-
<EditText
29-
android:layout_width="match_parent"
30-
android:layout_height="wrap_content"
31-
android:id="@+id/buttonShowTransparent_text3"
32-
android:hint="X Percentage"
33-
android:gravity="center"/>
34-
35-
<EditText
36-
android:layout_width="match_parent"
37-
android:layout_height="wrap_content"
38-
android:id="@+id/buttonShowTransparent_text4"
39-
android:hint="Y Percentage"
40-
android:gravity="center"/>
41-
27+
android:hint="@string/y_coordinate"
28+
android:gravity="center"
29+
android:autofillHints="number,coordinate"
30+
android:inputType="numberDecimal"/>
4231
<EditText
4332
android:layout_width="match_parent"
4433
android:layout_height="wrap_content"
4534
android:id="@+id/buttonShowTransparent_text5"
46-
android:hint="Width Px"
47-
android:gravity="center"/>
35+
android:hint="@string/width_px"
36+
android:gravity="center"
37+
android:autofillHints="number,coordinate"
38+
android:inputType="numberDecimal"/>
4839
<EditText
4940
android:layout_width="match_parent"
5041
android:layout_height="wrap_content"
5142
android:id="@+id/buttonShowTransparent_text6"
52-
android:hint="Height Px"
53-
android:gravity="center"/>
54-
55-
<EditText
56-
android:layout_width="match_parent"
57-
android:layout_height="wrap_content"
58-
android:id="@+id/buttonShowTransparent_text7"
59-
android:hint="Width Percentage"
60-
android:gravity="center"/>
61-
62-
<EditText
63-
android:layout_width="match_parent"
64-
android:layout_height="wrap_content"
65-
android:id="@+id/buttonShowTransparent_text8"
66-
android:hint="Height Percentage"
67-
android:gravity="center"/>
68-
43+
android:hint="@string/height_px"
44+
android:gravity="center"
45+
android:autofillHints="number,coordinate"
46+
android:inputType="numberDecimal"/>
6947
<EditText
7048
android:layout_width="match_parent"
7149
android:layout_height="wrap_content"
7250
android:id="@+id/buttonShowTransparent_text9"
73-
android:hint="Webview URL"
74-
android:gravity="center"/>
51+
android:hint="@string/webview_url"
52+
android:gravity="center"
53+
android:autofillHints="number,coordinate"
54+
android:inputType="textUri"/>
7555

7656
<Button
77-
android:text="Show Transparent Activity"
57+
android:text="@string/show_transparent_activity"
7858
android:layout_width="match_parent"
7959
android:layout_height="wrap_content"
8060
android:id="@+id/buttonShowTransparent"
8161
android:onClick="onClickShowTransparentActivity"
82-
/>
62+
tools:ignore="UsingOnClickInXml"/>
8363

8464
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,11 @@
6565
<string name="manual_report">manual report</string>
6666
<string name="add_a_breadcrumb">Add a breadcrumb</string>
6767
<string name="activity_name_feedback">Feedback examples</string>
68+
<string name="x_coordinate">X Coordinate</string>
69+
<string name="y_coordinate">Y Coordinate</string>
70+
<string name="width_px">Width Px</string>
71+
<string name="height_px">Height Px</string>
72+
<string name="webview_url">Webview URL</string>
73+
<string name="show_transparent_activity">Show Transparent Activity</string>
6874

6975
</resources>

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,9 @@ public static void showActivity(@NonNull Context context, @NonNull TransparentAc
9595
}
9696

9797
private static void calculateSize(int screenWidth, int screenHeight, TransparentActivityConfig config) {
98-
if (config.xPercent != null) {
99-
config.x = (int) (screenWidth * adjustPercent(config.xPercent));
100-
}
101-
if (config.yPercent != null) {
102-
config.y = (int) (screenHeight * adjustPercent(config.yPercent));
103-
}
104-
10598
int remainingWidth = screenWidth - (config.x != null ? config.x : 0);
10699
int remainingHeight = screenHeight - (config.y != null ? config.y : 0);
107100

108-
if (config.widthPercent != null) {
109-
config.width = (int) (remainingWidth * adjustPercent(config.widthPercent));
110-
config.width = Math.min(config.width, remainingWidth);
111-
}
112-
113-
if (config.heightPercent != null) {
114-
config.height = (int) (remainingHeight * adjustPercent(config.heightPercent));
115-
config.height = Math.min(config.height, remainingHeight);
116-
}
117-
118101
//fallback to remaining screen
119102
if (config.width == null) {
120103
config.width = remainingWidth;
@@ -131,14 +114,4 @@ private static void calculateSize(int screenWidth, int screenHeight, Transparent
131114
config.y = 0;
132115
}
133116
}
134-
135-
private static Double adjustPercent(Double percent) {
136-
if (percent > 1 || percent < -1) {
137-
percent = percent % 1;
138-
}
139-
if (percent < 0) {
140-
percent = 1 + percent;
141-
}
142-
return percent;
143-
}
144117
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ public class TransparentActivityConfig {
55
Integer y;
66
Integer width;
77
Integer height;
8-
Double widthPercent;
9-
Double heightPercent;
10-
Double xPercent;
11-
Double yPercent;
128
String url;
139

1410
public TransparentActivityConfig(Integer x, Integer y, Integer width, Integer height) {
@@ -21,11 +17,4 @@ public TransparentActivityConfig(Integer x, Integer y, Integer width, Integer he
2117
public void setUrl(String url) {
2218
this.url = url;
2319
}
24-
25-
public void setPercents(Double xPercent, Double yPercent, Double widthPercent, Double heightPercent) {
26-
this.xPercent = xPercent;
27-
this.yPercent = yPercent;
28-
this.widthPercent = widthPercent;
29-
this.heightPercent = heightPercent;
30-
}
3120
}

0 commit comments

Comments
 (0)