Skip to content

Commit c2d625e

Browse files
committed
Implement enough of edge-to-edge to work well on Android V
1 parent 291acb3 commit c2d625e

25 files changed

+460
-285
lines changed

main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.java

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2012-2015 Arne Schwabe
3+
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
4+
*/
5+
package de.blinkt.openvpn.activities
6+
7+
import android.app.UiModeManager
8+
import android.content.Context
9+
import android.content.res.Configuration
10+
import android.os.Bundle
11+
import android.view.View
12+
import android.view.ViewGroup
13+
import android.view.Window
14+
import androidx.activity.SystemBarStyle
15+
import androidx.activity.enableEdgeToEdge
16+
import androidx.appcompat.app.AppCompatActivity
17+
import androidx.core.view.ViewCompat
18+
import androidx.core.view.WindowInsetsCompat
19+
import androidx.core.view.updateLayoutParams
20+
import androidx.core.view.updatePadding
21+
import de.blinkt.openvpn.R
22+
import de.blinkt.openvpn.core.LocaleHelper
23+
24+
abstract class BaseActivity : AppCompatActivity() {
25+
val isAndroidTV: Boolean
26+
get() {
27+
val uiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager
28+
return uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION
29+
}
30+
31+
override fun onCreate(savedInstanceState: Bundle?) {
32+
if (isAndroidTV) {
33+
requestWindowFeature(Window.FEATURE_OPTIONS_PANEL)
34+
}
35+
this.enableEdgeToEdge(SystemBarStyle.dark(R.color.primary_dark))
36+
super.onCreate(savedInstanceState)
37+
}
38+
39+
fun setUpEdgeEdgeInsetsListener(
40+
rootView: View,
41+
contentViewId: Int = R.id.root_linear_layout,
42+
setupBottom: Boolean = true
43+
) {
44+
val contentView = rootView.findViewById<View>(contentViewId)
45+
46+
ViewCompat.setOnApplyWindowInsetsListener(contentView) { v, windowInsets ->
47+
val insets =
48+
windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
49+
val statusbarbg = findViewById<View>(R.id.statusbar_background);
50+
51+
val statusBarInsets = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars())
52+
53+
statusbarbg.layoutParams.height = statusBarInsets.top
54+
55+
56+
v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
57+
topMargin = insets.top
58+
}
59+
60+
v.updatePadding(
61+
left = insets.left,
62+
right = insets.right,
63+
)
64+
if (setupBottom) {
65+
v.updatePadding(bottom = insets.bottom)
66+
WindowInsetsCompat.CONSUMED
67+
} else {
68+
windowInsets
69+
}
70+
}
71+
}
72+
73+
override fun attachBaseContext(base: Context) {
74+
super.attachBaseContext(LocaleHelper.updateResources(base))
75+
}
76+
77+
override fun onConfigurationChanged(newConfig: Configuration) {
78+
super.onConfigurationChanged(newConfig)
79+
LocaleHelper.onConfigurationChange(this)
80+
}
81+
}

main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,9 @@ class ConfigConverter : BaseActivity(), FileSelectCallback, View.OnClickListener
618618

619619
override fun onCreate(savedInstanceState: Bundle?) {
620620
super.onCreate(savedInstanceState)
621-
setContentView(R.layout.config_converter)
621+
val v = layoutInflater.inflate(R.layout.config_converter, null)
622+
setUpEdgeEdgeInsetsListener(v, R.id.root_layout_config_converter)
623+
setContentView(v)
622624

623625
val fab_button = findViewById<ImageButton?>(R.id.fab_save)
624626
if (fab_button != null) {

main/src/ui/java/de/blinkt/openvpn/activities/InternalWebView.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import de.blinkt.openvpn.R
2222
import de.blinkt.openvpn.VpnProfile
2323
import org.json.JSONObject
2424

25-
class InternalWebView : AppCompatActivity() {
25+
class InternalWebView : BaseActivity() {
2626

2727
lateinit var webView: WebView
2828
lateinit var urlTextView: TextView
@@ -32,6 +32,8 @@ class InternalWebView : AppCompatActivity() {
3232

3333
super.onCreate(savedInstanceState)
3434
setContentView(R.layout.webview_internal)
35+
setUpEdgeEdgeInsetsListener(getWindow().getDecorView().getRootView(), R.id.container)
36+
3537

3638
webView = findViewById(R.id.internal_webview)
3739
urlTextView = findViewById(R.id.url_textview)

main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.java

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2012-2016 Arne Schwabe
3+
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
4+
*/
5+
package de.blinkt.openvpn.activities
6+
7+
import android.os.Bundle
8+
import android.view.MenuItem
9+
import de.blinkt.openvpn.R
10+
import de.blinkt.openvpn.fragments.LogFragment
11+
12+
/**
13+
* Created by arne on 13.10.13.setUpEdgeEdgeStuff
14+
*/
15+
class LogWindow : BaseActivity() {
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
setContentView(R.layout.log_window)
19+
supportActionBar?.setDisplayHomeAsUpEnabled(true)
20+
21+
if (savedInstanceState == null) {
22+
supportFragmentManager.beginTransaction()
23+
.add(R.id.container, LogFragment())
24+
.commit()
25+
}
26+
27+
setUpEdgeEdgeInsetsListener(getWindow().getDecorView().getRootView(), R.id.container)
28+
}
29+
30+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
31+
return super.onOptionsItemSelected(item)
32+
}
33+
}

main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.os.Bundle
1010
import android.view.Menu
1111
import android.view.MenuItem
1212
import android.widget.Toast
13-
import androidx.viewpager.widget.ViewPager
1413
import androidx.viewpager2.widget.ViewPager2
1514
import com.google.android.material.tabs.TabLayout
1615
import com.google.android.material.tabs.TabLayoutMediator
@@ -22,13 +21,14 @@ import de.blinkt.openvpn.views.ScreenSlidePagerAdapter
2221
class MainActivity : BaseActivity() {
2322
private lateinit var mPager: ViewPager2
2423
private lateinit var mPagerAdapter: ScreenSlidePagerAdapter
24+
2525
override fun onCreate(savedInstanceState: Bundle?) {
2626
super.onCreate(savedInstanceState)
27-
setContentView(R.layout.main_activity)
27+
val view = layoutInflater.inflate(R.layout.main_activity, null)
2828

2929
// Instantiate a ViewPager and a PagerAdapter.
30-
mPager = findViewById(R.id.pager)
31-
val tablayout: TabLayout = findViewById(R.id.tab_layout)
30+
mPager = view.findViewById(R.id.pager)
31+
val tablayout: TabLayout = view.findViewById(R.id.tab_layout)
3232

3333
mPagerAdapter = ScreenSlidePagerAdapter(supportFragmentManager, lifecycle, this)
3434

@@ -49,8 +49,11 @@ class MainActivity : BaseActivity() {
4949
tab.text = mPagerAdapter.getPageTitle(position)
5050
}.attach()
5151

52+
setUpEdgeEdgeInsetsListener(view, R.id.root_linear_layout)
53+
setContentView(view)
5254
}
5355

56+
5457
private fun disableToolbarElevation() {
5558
supportActionBar?.elevation = 0f
5659
}

main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class OpenSSLSpeed : BaseActivity() {
105105
override fun onCreate(savedInstanceState: Bundle?) {
106106
super.onCreate(savedInstanceState)
107107
setContentView(R.layout.openssl_speed)
108+
setUpEdgeEdgeInsetsListener(getWindow().getDecorView().getRootView(), R.id.speed_root)
108109
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
109110

110111
findViewById<View>(R.id.testSpecific).setOnClickListener { _ -> runAlgorithms(mCipher.text.toString()) }

main/src/ui/java/de/blinkt/openvpn/activities/VPNPreferences.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ class VPNPreferences : BaseActivity() {
104104
title = getString(R.string.edit_profile_title, mProfile!!.name)
105105

106106

107-
setContentView(R.layout.main_activity)
107+
val rootview = layoutInflater.inflate(R.layout.main_activity, null)
108+
setUpEdgeEdgeInsetsListener(rootview, R.id.root_linear_layout)
108109

109110
disableToolbarElevation()
110111

111112
// Instantiate a ViewPager and a PagerAdapter.
112-
mPager = findViewById(R.id.pager)
113-
val tablayout: TabLayout = findViewById(R.id.tab_layout)
113+
mPager = rootview.findViewById(R.id.pager)
114+
val tablayout: TabLayout = rootview.findViewById(R.id.tab_layout)
114115
mPagerAdapter = ScreenSlidePagerAdapter(supportFragmentManager, lifecycle, this)
115116

116117

@@ -143,6 +144,8 @@ class VPNPreferences : BaseActivity() {
143144
TabLayoutMediator(tablayout, mPager) { tab, position ->
144145
tab.text = mPagerAdapter.getPageTitle(position)
145146
}.attach()
147+
148+
setContentView(rootview)
146149
}
147150

148151

main/src/ui/java/de/blinkt/openvpn/fragments/AboutFragment.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import android.view.ViewGroup;
2828
import android.widget.TextView;
2929

30+
import androidx.core.graphics.Insets;
31+
import androidx.core.view.ViewCompat;
32+
import androidx.core.view.WindowInsetsCompat;
3033
import androidx.fragment.app.Fragment;
3134

3235
import com.android.vending.billing.IInAppBillingService;
@@ -108,6 +111,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
108111

109112
TextView wv = (TextView) v.findViewById(R.id.full_licenses);
110113
wv.setText(Html.fromHtml(readHtmlFromAssets()));
114+
115+
116+
117+
ViewCompat.setOnApplyWindowInsetsListener(v, (view, windowInsets) ->
118+
{
119+
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
120+
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), insets.bottom);
121+
return WindowInsetsCompat.CONSUMED;
122+
}
123+
);
111124
return v;
112125
}
113126

0 commit comments

Comments
 (0)