Skip to content

Commit d95c9a9

Browse files
committed
Show the connection status details when connected
1 parent 5ed139a commit d95c9a9

File tree

10 files changed

+238
-23
lines changed

10 files changed

+238
-23
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tech.httptoolkit.android
2+
3+
import android.content.Context
4+
import android.view.LayoutInflater
5+
import android.widget.LinearLayout
6+
import android.widget.TextView
7+
8+
class ConnectionStatusView(
9+
context: Context,
10+
proxyConfig: ProxyConfig
11+
) : LinearLayout(context) {
12+
13+
init {
14+
LayoutInflater.from(context).inflate(
15+
when (whereIsCertTrusted(proxyConfig)) {
16+
"user" -> R.layout.connection_status_basic
17+
"system" -> R.layout.connection_status_system
18+
else -> R.layout.connection_status_none
19+
},
20+
this, true)
21+
22+
val connectedToText = findViewById<TextView>(R.id.connectedTo)
23+
connectedToText.text = context.getString(
24+
R.string.connected_details,
25+
proxyConfig.ip,
26+
proxyConfig.port
27+
)
28+
}
29+
30+
}

app/src/main/java/tech/httptoolkit/android/MainActivity.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,10 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
225225
}
226226
MainState.CONNECTED -> {
227227
statusText.setText(R.string.connected_status)
228+
val proxyConfig = this.currentProxyConfig!!
228229

229230
detailContainer.addView(
230-
detailText(getString(
231-
R.string.connected_details,
232-
currentProxyConfig!!.ip,
233-
currentProxyConfig!!.port
234-
))
231+
ConnectionStatusView(this, proxyConfig)
235232
)
236233

237234
buttonContainer.visibility = View.VISIBLE
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="24sp"
4+
android:height="24sp"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
<path
8+
android:fillColor="@color/successColor"
9+
android:pathData="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
10+
/>
11+
</vector>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:width="576dp"
3-
android:height="512dp"
2+
android:width="24sp"
3+
android:height="24sp"
44
android:viewportWidth="576"
55
android:viewportHeight="512">
66
<path
77
android:pathData="M569.517,440.013C587.975,472.007 564.806,512 527.94,512L48.054,512c-36.937,0 -59.999,-40.055 -41.577,-71.987L246.423,23.985c18.467,-32.009 64.72,-31.951 83.154,0l239.94,416.028zM288,354c-25.405,0 -46,20.595 -46,46s20.595,46 46,46 46,-20.595 46,-46 -20.595,-46 -46,-46zM244.327,188.654l7.418,136c0.347,6.364 5.609,11.346 11.982,11.346h48.546c6.373,0 11.635,-4.982 11.982,-11.346l7.418,-136c0.375,-6.874 -5.098,-12.654 -11.982,-12.654h-63.383c-6.884,0 -12.356,5.78 -11.981,12.654z"
8-
android:fillColor="#f1971f"/>
8+
android:fillColor="@color/warningColor"/>
99
</vector>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.widget.LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
android:paddingStart="16sp"
8+
android:paddingEnd="16sp"
9+
android:paddingBottom="4sp"
10+
android:clipToPadding="false">
11+
12+
<TextView
13+
android:id="@+id/connectedTo"
14+
style="@style/ConnectedToText"
15+
android:text="to ?.?.?.?"
16+
android:layout_marginBottom="24sp" />
17+
18+
<com.google.android.material.card.MaterialCardView
19+
style="@style/ConnectionStatusCard"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content">
22+
23+
<LinearLayout
24+
android:layout_width="match_parent"
25+
android:layout_height="match_parent"
26+
android:orientation="vertical">
27+
28+
<TextView
29+
style="@style/ConnectionStatusHeading"
30+
android:drawableStart="@drawable/ic_check_circle"
31+
android:text="Basic interception enabled" />
32+
33+
<TextView
34+
style="@style/ConnectionStatusText"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:text="All plain HTTP traffic will be intercepted. HTTPS traffic will only be intercepted from apps with user certificate trust enabled." />
38+
</LinearLayout>
39+
40+
</com.google.android.material.card.MaterialCardView>
41+
42+
<com.google.android.material.card.MaterialCardView
43+
style="@style/ConnectionStatusCard"
44+
android:layout_width="match_parent"
45+
android:layout_height="wrap_content">
46+
47+
<TextView
48+
style="@style/ConnectionStatusHeading"
49+
android:drawableStart="@drawable/ic_exclamation_triangle"
50+
android:text="System interception disabled" />
51+
</com.google.android.material.card.MaterialCardView>
52+
53+
</android.widget.LinearLayout>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.widget.LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
android:paddingStart="16sp"
8+
android:paddingEnd="16sp"
9+
android:paddingBottom="4sp"
10+
android:clipToPadding="false">
11+
12+
<TextView
13+
android:id="@+id/connectedTo"
14+
style="@style/ConnectedToText"
15+
android:text="to ?.?.?.?"
16+
android:layout_marginBottom="24sp" />
17+
18+
<com.google.android.material.card.MaterialCardView
19+
style="@style/ConnectionStatusCard"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content">
22+
23+
<TextView
24+
style="@style/ConnectionStatusHeading"
25+
android:drawableStart="@drawable/ic_exclamation_triangle"
26+
android:text="HTTPS interception disabled" />
27+
28+
</com.google.android.material.card.MaterialCardView>
29+
30+
</android.widget.LinearLayout>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.widget.LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
android:paddingStart="16sp"
8+
android:paddingEnd="16sp"
9+
android:paddingBottom="4sp"
10+
android:clipToPadding="false">
11+
12+
<TextView
13+
android:id="@+id/connectedTo"
14+
style="@style/ConnectedToText"
15+
android:text="to ?.?.?.?"
16+
android:layout_marginBottom="24sp" />
17+
18+
<com.google.android.material.card.MaterialCardView
19+
style="@style/ConnectionStatusCard"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content">
22+
23+
<TextView
24+
style="@style/ConnectionStatusHeading"
25+
android:drawableStart="@drawable/ic_check_circle"
26+
android:text="Basic interception enabled" />
27+
28+
</com.google.android.material.card.MaterialCardView>
29+
30+
<com.google.android.material.card.MaterialCardView
31+
style="@style/ConnectionStatusCard"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content">
34+
35+
<LinearLayout
36+
android:layout_width="match_parent"
37+
android:layout_height="match_parent"
38+
android:orientation="vertical">
39+
40+
<TextView
41+
style="@style/ConnectionStatusHeading"
42+
android:drawableStart="@drawable/ic_check_circle"
43+
android:text="System interception enabled" />
44+
45+
<TextView
46+
style="@style/ConnectionStatusText"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:text="Traffic will be intercepted from all installed applications, except those using explicit certificate pinning." />
50+
51+
</LinearLayout>
52+
</com.google.android.material.card.MaterialCardView>
53+
54+
</android.widget.LinearLayout>

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
android:layout_height="match_parent"
77
tools:context=".MainActivity">
88

9-
109
<androidx.constraintlayout.widget.Guideline
1110
android:id="@+id/logoGuideline"
1211
android:layout_width="wrap_content"
1312
android:layout_height="wrap_content"
1413
android:orientation="horizontal"
15-
app:layout_constraintGuide_percent="0.2" />
14+
app:layout_constraintGuide_percent="0.15" />
1615

1716
<ImageView
1817
android:id="@+id/logoImage"
@@ -30,16 +29,15 @@
3029
android:layout_width="wrap_content"
3130
android:layout_height="wrap_content"
3231
android:orientation="horizontal"
33-
app:layout_constraintGuide_percent="0.4" />
32+
app:layout_constraintGuide_percent="0.3" />
3433

3534
<TextView
3635
android:id="@+id/statusText"
3736
style="@style/StatusText"
3837
android:layout_width="wrap_content"
3938
android:layout_height="wrap_content"
40-
android:layout_marginStart="8dp"
41-
android:layout_marginEnd="8dp"
42-
android:layout_marginBottom="8dp"
39+
android:layout_marginStart="8sp"
40+
android:layout_marginEnd="8sp"
4341
android:text="Not Connected"
4442
app:layout_constraintBottom_toBottomOf="@+id/statusGuideline"
4543
app:layout_constraintTop_toTopOf="@+id/statusGuideline"
@@ -50,9 +48,8 @@
5048
android:id="@+id/statusDetailContainer"
5149
android:layout_width="wrap_content"
5250
android:layout_height="wrap_content"
53-
android:layout_marginStart="32dp"
54-
android:layout_marginTop="16dp"
55-
android:layout_marginEnd="32dp"
51+
android:layout_marginStart="16sp"
52+
android:layout_marginEnd="16sp"
5653
app:layout_constrainedWidth="true"
5754
app:layout_constraintEnd_toEndOf="parent"
5855
app:layout_constraintStart_toStartOf="parent"
@@ -62,8 +59,8 @@
6259
<com.google.android.material.card.MaterialCardView
6360
android:layout_height="wrap_content"
6461
android:layout_width="match_parent"
65-
android:layout_marginStart="16dp"
66-
android:layout_marginEnd="16dp"
62+
android:layout_marginStart="16sp"
63+
android:layout_marginEnd="16sp"
6764
app:layout_constraintBottom_toBottomOf="parent"
6865
app:layout_constraintEnd_toEndOf="parent"
6966
app:layout_constraintStart_toStartOf="parent"
@@ -74,10 +71,11 @@
7471
android:layout_width="match_parent"
7572
android:layout_height="wrap_content"
7673
android:orientation="vertical"
77-
android:paddingStart="16dp"
78-
android:paddingEnd="16dp"
79-
android:paddingTop="12dp"
80-
android:paddingBottom="10dp">
74+
android:paddingStart="16sp"
75+
android:paddingEnd="16sp"
76+
android:paddingTop="12sp"
77+
android:paddingBottom="10sp"
78+
android:clipToPadding="false">
8179
</LinearLayout>
8280
</com.google.android.material.card.MaterialCardView>
8381

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<resources>
33
<color name="textColor">#222222</color>
44
<color name="popColor">#e1421f</color>
5+
<color name="lowLightColor">#808f8f</color>
6+
7+
<color name="successColor">#4caf7d</color>
8+
<color name="warningColor">#f1971f</color>
59

610
<color name="containerBackground">#d8e2e6</color>
711
<color name="mainBackground">#fafafa</color>

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
</style>
2020

2121
<style name="DetailText" parent="@android:style/Widget.TextView">
22+
<item name="android:layout_width">match_parent</item>
23+
<item name="android:layout_height">wrap_content</item>
24+
<item name="android:paddingTop">16sp</item>
25+
<item name="android:paddingStart">16sp</item>
26+
<item name="android:paddingEnd">16sp</item>
2227
<item name="android:textSize">20sp</item>
2328
<item name="android:gravity">center</item>
2429
</style>
@@ -67,4 +72,37 @@
6772
<item name="android:letterSpacing">0</item>
6873
</style>
6974

75+
<style name="ConnectionStatusCard" parent="@style/Widget.MaterialComponents.CardView">
76+
<item name="cardElevation">0sp</item>
77+
<item name="contentPadding">10sp</item>
78+
<item name="android:layout_marginBottom">10sp</item>
79+
</style>
80+
81+
<style name="ConnectedToText" parent="@android:style/Widget.TextView">
82+
<item name="android:layout_width">match_parent</item>
83+
<item name="android:layout_height">wrap_content</item>
84+
<item name="android:paddingStart">16sp</item>
85+
<item name="android:paddingEnd">16sp</item>
86+
<item name="android:textSize">16sp</item>
87+
<item name="android:gravity">center</item>
88+
</style>
89+
90+
<style name="ConnectionStatusHeading" parent="@android:style/Widget.TextView">
91+
<item name="android:layout_width">match_parent</item>
92+
<item name="android:layout_height">wrap_content</item>
93+
<item name="android:gravity">center</item>
94+
<item name="android:drawablePadding">10sp</item>
95+
<item name="android:textSize">14sp</item>
96+
<item name="android:fontFamily">@font/lato_bold</item>
97+
<item name="android:textAlignment">textStart</item>
98+
<item name="android:textAllCaps">true</item>
99+
<item name="android:textColor">@color/lowLightColor</item>
100+
</style>
101+
102+
<style name="ConnectionStatusText" parent="@android:style/Widget.TextView">
103+
<item name="android:textSize">16sp</item>
104+
<item name="android:layout_marginStart">34sp</item>
105+
<item name="android:layout_marginTop">5sp</item>
106+
</style>
107+
70108
</resources>

0 commit comments

Comments
 (0)