Skip to content

Commit

Permalink
Merge pull request #1550 from cillyvms/window-insets
Browse files Browse the repository at this point in the history
Apply window insets to accommodate system UI.
  • Loading branch information
alexbakker authored Dec 4, 2024
2 parents 0eb1194 + 6039cfa commit a76f339
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.beemdevelopment.aegis.helpers;

import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.google.android.material.appbar.AppBarLayout;

public class ViewHelper {
private ViewHelper() {

}

public static void setupAppBarInsets(AppBarLayout appBar) {
ViewCompat.setOnApplyWindowInsetsListener(appBar, (targetView, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
targetView.setPadding(
insets.left,
insets.top,
insets.right,
0
);
return WindowInsetsCompat.CONSUMED;
});
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/beemdevelopment/aegis/ui/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@

import androidx.annotation.AttrRes;
import androidx.annotation.StringRes;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.beemdevelopment.aegis.BuildConfig;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.ui.dialogs.ChangelogDialog;
import com.beemdevelopment.aegis.ui.dialogs.LicenseDialog;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.google.android.material.color.MaterialColors;

public class AboutActivity extends AegisActivity {
Expand All @@ -39,6 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_about);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));

if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand Down Expand Up @@ -90,6 +95,17 @@ protected void onCreate(Bundle savedInstanceState) {
.setTheme(_themeHelper.getConfiguredTheme())
.show(getSupportFragmentManager(), null);
});

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.about_scroll_view), (targetView, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
targetView.setPadding(
0,
0,
0,
insets.bottom
);
return WindowInsetsCompat.CONSUMED;
});
}

private static String getCurrentAppVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.beemdevelopment.aegis.ui.views.AssignIconAdapter;
import com.beemdevelopment.aegis.ui.views.IconAdapter;
import com.beemdevelopment.aegis.util.IOUtils;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.beemdevelopment.aegis.vault.VaultEntry;
import com.beemdevelopment.aegis.vault.VaultEntryIcon;
import com.bumptech.glide.Glide;
Expand Down Expand Up @@ -61,6 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_assign_icons);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.beemdevelopment.aegis.ui.views.IconAdapter;
import com.beemdevelopment.aegis.util.Cloner;
import com.beemdevelopment.aegis.util.IOUtils;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.beemdevelopment.aegis.vault.VaultEntry;
import com.beemdevelopment.aegis.vault.VaultEntryIcon;
import com.beemdevelopment.aegis.vault.VaultGroup;
Expand Down Expand Up @@ -164,6 +165,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.activity_edit_entry);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));

_groups = _vaultManager.getVault().getGroups();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
import com.beemdevelopment.aegis.ui.views.GroupAdapter;
import com.beemdevelopment.aegis.util.Cloner;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.beemdevelopment.aegis.vault.VaultGroup;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

Expand All @@ -39,6 +40,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.activity_groups);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.beemdevelopment.aegis.ui.tasks.RootShellTask;
import com.beemdevelopment.aegis.ui.views.ImportEntriesAdapter;
import com.beemdevelopment.aegis.util.UUIDMap;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.beemdevelopment.aegis.vault.VaultEntry;
import com.beemdevelopment.aegis.vault.VaultGroup;
import com.beemdevelopment.aegis.vault.VaultRepository;
Expand Down Expand Up @@ -58,6 +59,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.activity_import_entries);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));

_view = findViewById(R.id.importEntriesRootView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.beemdevelopment.aegis.ui.views.EntryListView;
import com.beemdevelopment.aegis.util.TimeUtils;
import com.beemdevelopment.aegis.util.UUIDMap;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.beemdevelopment.aegis.vault.VaultEntry;
import com.beemdevelopment.aegis.vault.VaultFile;
import com.beemdevelopment.aegis.vault.VaultGroup;
Expand Down Expand Up @@ -183,6 +184,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));
_loaded = false;
_isDPadPressed = false;
_isDoingIntro = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.beemdevelopment.aegis.ui.fragments.preferences.AppearancePreferencesFragment;
import com.beemdevelopment.aegis.ui.fragments.preferences.MainPreferencesFragment;
import com.beemdevelopment.aegis.ui.fragments.preferences.PreferencesFragment;
import com.beemdevelopment.aegis.helpers.ViewHelper;

public class PreferencesActivity extends AegisActivity implements
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
Expand All @@ -27,6 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.activity_preferences);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));
getSupportFragmentManager()
.registerFragmentLifecycleCallbacks(new FragmentResumeListener(), true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
import com.beemdevelopment.aegis.otp.GoogleAuthInfoException;
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.beemdevelopment.aegis.vault.VaultEntry;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.zxing.Result;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.activity_scanner);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));

_entries = new ArrayList<>();
_lenses = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.beemdevelopment.aegis.otp.GoogleAuthInfoException;
import com.beemdevelopment.aegis.otp.Transferable;
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
import com.beemdevelopment.aegis.helpers.ViewHelper;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.zxing.WriterException;
Expand Down Expand Up @@ -55,6 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.activity_share_entry);
setSupportActionBar(findViewById(R.id.toolbar));
ViewHelper.setupAppBarInsets(findViewById(R.id.app_bar_layout));

_qrImage = findViewById(R.id.ivQrCode);
_description = findViewById(R.id.tvDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand Down Expand Up @@ -58,6 +61,17 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
_auditLogRecyclerView.setAdapter(_adapter);
_auditLogRecyclerView.setNestedScrollingEnabled(false);

ViewCompat.setOnApplyWindowInsetsListener(_auditLogRecyclerView, (targetView, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
targetView.setPadding(
0,
0,
0,
insets.bottom
);
return WindowInsetsCompat.CONSUMED;
});

entries.observe(getViewLifecycleOwner(), entries1 -> {
_noAuditLogsView.setVisibility(entries1.isEmpty() ? View.VISIBLE : View.GONE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.animation.Animation;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand All @@ -14,6 +15,9 @@
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -67,6 +71,19 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
fab.setOnClickListener(v -> startImportIconPack());
_fabScrollHelper = new FabScrollHelper(fab);

final MarginLayoutParams fabInitialMargin = (MarginLayoutParams) fab.getLayoutParams();
ViewCompat.setOnApplyWindowInsetsListener(fab, (targetView, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());

MarginLayoutParams marginParams = (MarginLayoutParams) targetView.getLayoutParams();
marginParams.leftMargin = fabInitialMargin.leftMargin + insets.left;
marginParams.bottomMargin = fabInitialMargin.bottomMargin + insets.bottom;
marginParams.rightMargin = fabInitialMargin.rightMargin + insets.right;
targetView.setLayoutParams(marginParams);

return WindowInsetsCompat.CONSUMED;
});

_noIconPacksView = view.findViewById(R.id.vEmptyList);
((TextView) view.findViewById(R.id.txt_no_icon_packs)).setMovementMethod(LinkMovementMethod.getInstance());
_adapter = new IconPackAdapter(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.beemdevelopment.aegis.ui.fragments.preferences;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.animation.Animation;

import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
Expand Down Expand Up @@ -61,6 +68,23 @@ public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
return super.onCreateAnimation(transit, enter, nextAnim);
}

@NonNull
@Override
public RecyclerView onCreateRecyclerView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @Nullable Bundle savedInstanceState) {
RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent, savedInstanceState);
ViewCompat.setOnApplyWindowInsetsListener(recyclerView, (targetView, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
targetView.setPadding(
0,
0,
0,
insets.bottom
);
return WindowInsetsCompat.CONSUMED;
});
return recyclerView;
}

protected boolean saveAndBackupVault() {
try {
_vaultManager.saveAndBackup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper;
Expand Down Expand Up @@ -149,6 +152,23 @@ public long getMillisTillNextRefresh() {
}
});

final int rvInitialPaddingLeft = _recyclerView.getPaddingLeft();
final int rvInitialPaddingTop = _recyclerView.getPaddingTop();
final int rvInitialPaddingRight = _recyclerView.getPaddingRight();
final int rvInitialPaddingBottom = _recyclerView.getPaddingBottom();

ViewCompat.setOnApplyWindowInsetsListener(_recyclerView, (targetView, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
// left and right padding seems to be handled by fitsSystemWindows="true" on the CoordinatorLayout in activity_main.xml
targetView.setPadding(
rvInitialPaddingLeft,
rvInitialPaddingTop,
rvInitialPaddingRight,
rvInitialPaddingBottom + insets.bottom
);
return WindowInsetsCompat.CONSUMED;
});

_emptyStateView = view.findViewById(R.id.vEmptyList);
return view;
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:id="@+id/about_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_audit_log.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarStyle="outsideOverlay"
android:clipToPadding="false"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_entry_list_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android:paddingHorizontal="8dp"
android:scrollbars="vertical"
android:scrollbarStyle="outsideOverlay"
android:clipToPadding="false"
android:id="@+id/rvKeyProfiles"
android:layout_weight="1"/>

Expand Down

0 comments on commit a76f339

Please sign in to comment.