Skip to content

Commit

Permalink
Merge pull request #11079 from t895/system-windows
Browse files Browse the repository at this point in the history
Android: Do not fit system windows
  • Loading branch information
JosJuice committed Oct 23, 2022
2 parents 9654d9a + 90d27be commit d442f3f
Show file tree
Hide file tree
Showing 27 changed files with 551 additions and 159 deletions.
Expand Up @@ -5,15 +5,19 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.WindowCompat;
import androidx.core.widget.NestedScrollView;

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

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.fragments.ConvertFragment;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;

public class ConvertActivity extends AppCompatActivity
Expand All @@ -36,6 +40,8 @@ protected void onCreate(Bundle savedInstanceState)

setContentView(R.layout.activity_convert);

WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

String path = getIntent().getStringExtra(ARG_GAME_PATH);

ConvertFragment fragment = (ConvertFragment) getSupportFragmentManager()
Expand All @@ -53,7 +59,10 @@ protected void onCreate(Bundle savedInstanceState)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

AppBarLayout appBarLayout = findViewById(R.id.appbar_convert);
ThemeHelper.enableScrollTint(tb, appBarLayout, this);
NestedScrollView scrollView = findViewById(R.id.scroll_view_convert);
View workaroundView = findViewById(R.id.workaround_view);
InsetsHelper.setUpAppBarWithScrollView(this, appBarLayout, scrollView, workaroundView);
ThemeHelper.enableScrollTint(this, tb, appBarLayout);
}

@Override
Expand Down
Expand Up @@ -15,14 +15,16 @@

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.WindowCompat;
import androidx.core.widget.NestedScrollView;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;
import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;
import org.dolphinemu.dolphinemu.utils.ThreadUtil;
Expand Down Expand Up @@ -61,6 +63,8 @@ protected void onCreate(Bundle savedInstanceState)

setContentView(R.layout.activity_user_data);

WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

TextView textType = findViewById(R.id.text_type);
TextView textPath = findViewById(R.id.text_path);
TextView textAndroid11 = findViewById(R.id.text_android_11);
Expand Down Expand Up @@ -92,7 +96,10 @@ protected void onCreate(Bundle savedInstanceState)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

AppBarLayout appBarLayout = findViewById(R.id.appbar_user_data);
ThemeHelper.enableScrollTint(tb, appBarLayout, this);
NestedScrollView scrollView = findViewById(R.id.scroll_view_user_data);
View workaroundView = findViewById(R.id.workaround_view);
InsetsHelper.setUpAppBarWithScrollView(this, appBarLayout, scrollView, workaroundView);
ThemeHelper.enableScrollTint(this, tb, appBarLayout);
}

@Override
Expand Down
Expand Up @@ -150,35 +150,12 @@ public void onClick(View view)
@Override
public boolean onLongClick(View view)
{
FragmentActivity activity = (FragmentActivity) view.getContext();
GameViewHolder holder = (GameViewHolder) view.getTag();
String gameId = holder.gameFile.getGameId();

GamePropertiesDialog fragment = GamePropertiesDialog.newInstance(holder.gameFile);
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction()
.add(fragment, GamePropertiesDialog.TAG).commit();

return true;
}

public static class SpacesItemDecoration extends RecyclerView.ItemDecoration
{
private int space;

public SpacesItemDecoration(int space)
{
this.space = space;
}

@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
@NonNull RecyclerView parent,
@NonNull RecyclerView.State state)
{
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
outRect.top = space;
}
}
}
Expand Up @@ -18,6 +18,7 @@

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;

public class CheatListFragment extends Fragment
{
Expand All @@ -44,5 +45,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
new MaterialDividerItemDecoration(requireActivity(), LinearLayoutManager.VERTICAL);
divider.setLastItemDecorated(false);
recyclerView.addItemDecoration(divider);

InsetsHelper.setUpList(getContext(), recyclerView);
}
}
Expand Up @@ -10,14 +10,18 @@
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.slidingpanelayout.widget.SlidingPaneLayout;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.dolphinemu.dolphinemu.R;
Expand All @@ -27,6 +31,7 @@
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.ui.TwoPaneOnBackPressedCallback;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;

public class CheatsActivity extends AppCompatActivity
Expand Down Expand Up @@ -83,6 +88,8 @@ protected void onCreate(Bundle savedInstanceState)

setContentView(R.layout.activity_cheats);

WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

mSlidingPaneLayout = findViewById(R.id.sliding_pane_layout);
mCheatList = findViewById(R.id.cheat_list);
mCheatDetails = findViewById(R.id.cheat_details);
Expand All @@ -100,9 +107,18 @@ protected void onCreate(Bundle savedInstanceState)

mViewModel.getOpenDetailsViewEvent().observe(this, this::openDetailsView);

Toolbar tb = findViewById(R.id.toolbar_cheats);
MaterialToolbar tb = findViewById(R.id.toolbar_cheats);
setSupportActionBar(tb);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

View workaroundView = findViewById(R.id.workaround_view);
AppBarLayout appBarLayout = findViewById(R.id.appbar_cheats);
InsetsHelper.setUpCheatsLayout(this, appBarLayout, mSlidingPaneLayout, mCheatDetails,
workaroundView);

@ColorInt int color = MaterialColors.getColor(tb, R.attr.colorSurfaceVariant);
tb.setBackgroundColor(color);
ThemeHelper.setStatusBarColor(this, color);
}

@Override
Expand Down
Expand Up @@ -5,10 +5,13 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.WindowCompat;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

Expand All @@ -21,6 +24,7 @@
import org.dolphinemu.dolphinemu.features.riivolution.model.RiivolutionPatches;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;

public class RiivolutionBootActivity extends AppCompatActivity
Expand Down Expand Up @@ -52,6 +56,8 @@ protected void onCreate(Bundle savedInstanceState)

setContentView(R.layout.activity_riivolution_boot);

WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

Intent intent = getIntent();

String path = getIntent().getStringExtra(ARG_GAME_PATH);
Expand Down Expand Up @@ -89,7 +95,10 @@ protected void onCreate(Bundle savedInstanceState)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

AppBarLayout appBarLayout = findViewById(R.id.appbar_riivolution);
ThemeHelper.enableScrollTint(tb, appBarLayout, this);
NestedScrollView scrollView = findViewById(R.id.scroll_view_riivolution);
View workaroundView = findViewById(R.id.workaround_view);
InsetsHelper.setUpAppBarWithScrollView(this, appBarLayout, scrollView, workaroundView);
ThemeHelper.enableScrollTint(this, tb, appBarLayout);
}

@Override
Expand Down
Expand Up @@ -9,11 +9,15 @@
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

Expand All @@ -26,6 +30,7 @@
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;

import java.util.Set;
Expand Down Expand Up @@ -78,6 +83,8 @@ protected void onCreate(Bundle savedInstanceState)

setContentView(R.layout.activity_settings);

WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

Intent launcher = getIntent();
String gameID = launcher.getStringExtra(ARG_GAME_ID);
if (gameID == null)
Expand All @@ -95,7 +102,15 @@ protected void onCreate(Bundle savedInstanceState)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

AppBarLayout appBarLayout = findViewById(R.id.appbar_settings);
ThemeHelper.enableScrollTint(tb, appBarLayout, this);
FrameLayout frameLayout = findViewById(R.id.frame_content_settings);

// TODO: Remove this when CollapsingToolbarLayouts are fixed by Google
// https://github.com/material-components/material-components-android/issues/1310
ViewCompat.setOnApplyWindowInsetsListener(mToolbarLayout, null);

View workaroundView = findViewById(R.id.workaround_view);
InsetsHelper.setUpSettingsLayout(this, appBarLayout, frameLayout, workaroundView);
ThemeHelper.enableScrollTint(this, tb, appBarLayout);
}

@Override
Expand Down Expand Up @@ -162,8 +177,8 @@ public void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToSt

transaction.addToBackStack(null);
}
transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag, gameID, extras),
FRAGMENT_TAG);
transaction.replace(R.id.frame_content_settings,
SettingsFragment.newInstance(menuTag, gameID, extras), FRAGMENT_TAG);

transaction.commit();
}
Expand Down
Expand Up @@ -19,6 +19,8 @@
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;
import org.dolphinemu.dolphinemu.utils.Log;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -143,6 +145,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
divider.setLastItemDecorated(false);
recyclerView.addItemDecoration(divider);

InsetsHelper.setUpList(getContext(), recyclerView);

SettingsActivityView activity = (SettingsActivityView) getActivity();
mPresenter.onViewCreated(menuTag, activity.getSettings());
}
Expand Down
Expand Up @@ -9,15 +9,18 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.splashscreen.SplashScreen;
import androidx.core.view.WindowCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;

Expand All @@ -35,6 +38,7 @@
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
import org.dolphinemu.dolphinemu.utils.StartupHandler;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;
Expand All @@ -50,6 +54,7 @@ public final class MainActivity extends AppCompatActivity
private ViewPager mViewPager;
private Toolbar mToolbar;
private TabLayout mTabLayout;
private AppBarLayout mAppBarLayout;
private FloatingActionButton mFab;

private int mThemeId;
Expand All @@ -70,6 +75,11 @@ protected void onCreate(Bundle savedInstanceState)

findViews();

View workaroundView = findViewById(R.id.workaround_view);
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
InsetsHelper.setUpMainLayout(this, mAppBarLayout, mFab, mViewPager, workaroundView);
ThemeHelper.enableStatusBarScrollTint(this, mAppBarLayout);

setSupportActionBar(mToolbar);

// Set up the FAB.
Expand Down Expand Up @@ -147,6 +157,7 @@ else if (DirectoryInitialization.areDolphinDirectoriesReady())
// TODO: Replace with a ButterKnife injection.
private void findViews()
{
mAppBarLayout = findViewById(R.id.appbar_main);
mToolbar = findViewById(R.id.toolbar_main);
mViewPager = findViewById(R.id.pager_platforms);
mTabLayout = findViewById(R.id.tabs_platforms);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.adapters.GameAdapter;
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
import org.dolphinemu.dolphinemu.utils.InsetsHelper;

public final class PlatformGamesFragment extends Fragment implements PlatformGamesView
{
Expand Down Expand Up @@ -74,7 +75,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState)
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(mAdapter);

mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8));
InsetsHelper.setUpList(getContext(), mRecyclerView);

setRefreshing(GameFileCacheManager.isLoadingOrRescanning());

Expand Down

0 comments on commit d442f3f

Please sign in to comment.