Skip to content

Commit

Permalink
Implement enough of edge-to-edge to work well on Android V
Browse files Browse the repository at this point in the history
  • Loading branch information
schwabe authored and czdawid committed Sep 10, 2024
1 parent 455f9c0 commit ad680b7
Show file tree
Hide file tree
Showing 25 changed files with 460 additions and 285 deletions.
45 changes: 0 additions & 45 deletions main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.java

This file was deleted.

81 changes: 81 additions & 0 deletions main/src/ui/java/de/blinkt/openvpn/activities/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2012-2015 Arne Schwabe
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
*/
package de.blinkt.openvpn.activities

import android.app.UiModeManager
import android.content.Context
import android.content.res.Configuration
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import de.blinkt.openvpn.R
import de.blinkt.openvpn.core.LocaleHelper

abstract class BaseActivity : AppCompatActivity() {
val isAndroidTV: Boolean
get() {
val uiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager
return uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION
}

override fun onCreate(savedInstanceState: Bundle?) {
if (isAndroidTV) {
requestWindowFeature(Window.FEATURE_OPTIONS_PANEL)
}
this.enableEdgeToEdge(SystemBarStyle.dark(R.color.primary_dark))
super.onCreate(savedInstanceState)
}

fun setUpEdgeEdgeInsetsListener(
rootView: View,
contentViewId: Int = R.id.root_linear_layout,
setupBottom: Boolean = true
) {
val contentView = rootView.findViewById<View>(contentViewId)

ViewCompat.setOnApplyWindowInsetsListener(contentView) { v, windowInsets ->
val insets =
windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
val statusbarbg = findViewById<View>(R.id.statusbar_background);

val statusBarInsets = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars())

statusbarbg.layoutParams.height = statusBarInsets.top


v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
}

v.updatePadding(
left = insets.left,
right = insets.right,
)
if (setupBottom) {
v.updatePadding(bottom = insets.bottom)
WindowInsetsCompat.CONSUMED
} else {
windowInsets
}
}
}

override fun attachBaseContext(base: Context) {
super.attachBaseContext(LocaleHelper.updateResources(base))
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
LocaleHelper.onConfigurationChange(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,9 @@ class ConfigConverter : BaseActivity(), FileSelectCallback, View.OnClickListener

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.config_converter)
val v = layoutInflater.inflate(R.layout.config_converter, null)
setUpEdgeEdgeInsetsListener(v, R.id.root_layout_config_converter)
setContentView(v)

val fab_button = findViewById<ImageButton?>(R.id.fab_save)
if (fab_button != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import de.blinkt.openvpn.R
import de.blinkt.openvpn.VpnProfile
import org.json.JSONObject

class InternalWebView : AppCompatActivity() {
class InternalWebView : BaseActivity() {

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

super.onCreate(savedInstanceState)
setContentView(R.layout.webview_internal)
setUpEdgeEdgeInsetsListener(getWindow().getDecorView().getRootView(), R.id.container)


webView = findViewById(R.id.internal_webview)
urlTextView = findViewById(R.id.url_textview)
Expand Down
37 changes: 0 additions & 37 deletions main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.java

This file was deleted.

33 changes: 33 additions & 0 deletions main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2012-2016 Arne Schwabe
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
*/
package de.blinkt.openvpn.activities

import android.os.Bundle
import android.view.MenuItem
import de.blinkt.openvpn.R
import de.blinkt.openvpn.fragments.LogFragment

/**
* Created by arne on 13.10.13.setUpEdgeEdgeStuff
*/
class LogWindow : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.log_window)
supportActionBar?.setDisplayHomeAsUpEnabled(true)

if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.add(R.id.container, LogFragment())
.commit()
}

setUpEdgeEdgeInsetsListener(getWindow().getDecorView().getRootView(), R.id.container)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return super.onOptionsItemSelected(item)
}
}
11 changes: 7 additions & 4 deletions main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.viewpager.widget.ViewPager
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
Expand All @@ -22,13 +21,14 @@ import de.blinkt.openvpn.views.ScreenSlidePagerAdapter
class MainActivity : BaseActivity() {
private lateinit var mPager: ViewPager2
private lateinit var mPagerAdapter: ScreenSlidePagerAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
val view = layoutInflater.inflate(R.layout.main_activity, null)

// Instantiate a ViewPager and a PagerAdapter.
mPager = findViewById(R.id.pager)
val tablayout: TabLayout = findViewById(R.id.tab_layout)
mPager = view.findViewById(R.id.pager)
val tablayout: TabLayout = view.findViewById(R.id.tab_layout)

mPagerAdapter = ScreenSlidePagerAdapter(supportFragmentManager, lifecycle, this)

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

setUpEdgeEdgeInsetsListener(view, R.id.root_linear_layout)
setContentView(view)
}


private fun disableToolbarElevation() {
supportActionBar?.elevation = 0f
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class OpenSSLSpeed : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.openssl_speed)
setUpEdgeEdgeInsetsListener(getWindow().getDecorView().getRootView(), R.id.speed_root)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)

findViewById<View>(R.id.testSpecific).setOnClickListener { _ -> runAlgorithms(mCipher.text.toString()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ class VPNPreferences : BaseActivity() {
title = getString(R.string.edit_profile_title, mProfile!!.name)


setContentView(R.layout.main_activity)
val rootview = layoutInflater.inflate(R.layout.main_activity, null)
setUpEdgeEdgeInsetsListener(rootview, R.id.root_linear_layout)

disableToolbarElevation()

// Instantiate a ViewPager and a PagerAdapter.
mPager = findViewById(R.id.pager)
val tablayout: TabLayout = findViewById(R.id.tab_layout)
mPager = rootview.findViewById(R.id.pager)
val tablayout: TabLayout = rootview.findViewById(R.id.tab_layout)
mPagerAdapter = ScreenSlidePagerAdapter(supportFragmentManager, lifecycle, this)


Expand Down Expand Up @@ -143,6 +144,8 @@ class VPNPreferences : BaseActivity() {
TabLayoutMediator(tablayout, mPager) { tab, position ->
tab.text = mPagerAdapter.getPageTitle(position)
}.attach()

setContentView(rootview)
}


Expand Down
13 changes: 13 additions & 0 deletions main/src/ui/java/de/blinkt/openvpn/fragments/AboutFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

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

TextView wv = (TextView) v.findViewById(R.id.full_licenses);
wv.setText(Html.fromHtml(readHtmlFromAssets()));



ViewCompat.setOnApplyWindowInsetsListener(v, (view, windowInsets) ->
{
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), insets.bottom);
return WindowInsetsCompat.CONSUMED;
}
);
return v;
}

Expand Down
7 changes: 7 additions & 0 deletions main/src/ui/java/de/blinkt/openvpn/fragments/FaqFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import android.os.Build;
import android.os.Bundle;

import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
Expand Down Expand Up @@ -196,9 +199,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

mRecyclerView.setAdapter(new FaqViewAdapter(getActivity(), getFAQEntries()));

Utils.applyInsetListener(v);

return v;
}



private FAQEntry[] getFAQEntries() {
Vector<FAQEntry> faqItems = new Vector<>();

Expand Down
Loading

0 comments on commit ad680b7

Please sign in to comment.