mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 23:59:27 +01:00
Merge pull request #11064 from t895/tab-layout
Android: Remove TabLayout workaround
This commit is contained in:
commit
450b77a096
@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
package org.dolphinemu.dolphinemu.adapters;
|
package org.dolphinemu.dolphinemu.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.text.Spannable;
|
|
||||||
import android.text.SpannableString;
|
|
||||||
import android.text.style.ImageSpan;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
@ -20,21 +14,19 @@ import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesFragment;
|
|||||||
|
|
||||||
public class PlatformPagerAdapter extends FragmentPagerAdapter
|
public class PlatformPagerAdapter extends FragmentPagerAdapter
|
||||||
{
|
{
|
||||||
private Context mContext;
|
|
||||||
private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener;
|
private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener;
|
||||||
|
|
||||||
private final static int[] TAB_ICONS =
|
public final static int[] TAB_ICONS =
|
||||||
{
|
{
|
||||||
R.drawable.ic_gamecube,
|
R.drawable.ic_gamecube,
|
||||||
R.drawable.ic_wii,
|
R.drawable.ic_wii,
|
||||||
R.drawable.ic_folder
|
R.drawable.ic_folder
|
||||||
};
|
};
|
||||||
|
|
||||||
public PlatformPagerAdapter(FragmentManager fm, Context context,
|
public PlatformPagerAdapter(FragmentManager fm,
|
||||||
SwipeRefreshLayout.OnRefreshListener onRefreshListener)
|
SwipeRefreshLayout.OnRefreshListener onRefreshListener)
|
||||||
{
|
{
|
||||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||||
mContext = context;
|
|
||||||
mOnRefreshListener = onRefreshListener;
|
mOnRefreshListener = onRefreshListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,23 +46,4 @@ public class PlatformPagerAdapter extends FragmentPagerAdapter
|
|||||||
{
|
{
|
||||||
return TAB_ICONS.length;
|
return TAB_ICONS.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getPageTitle(int position)
|
|
||||||
{
|
|
||||||
// Hax from https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout#design-support-library
|
|
||||||
// Apparently a workaround for TabLayout not supporting icons.
|
|
||||||
// TODO: This workaround will eventually not be necessary; switch to more legit methods when that is the case
|
|
||||||
// TODO: Also remove additional hax from styles.xml
|
|
||||||
Drawable drawable =
|
|
||||||
mContext.getResources().getDrawable(TAB_ICONS[position], mContext.getTheme());
|
|
||||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
|
||||||
|
|
||||||
ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM);
|
|
||||||
|
|
||||||
SpannableString sb = new SpannableString(" ");
|
|
||||||
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
|
|
||||||
return sb;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ public final class MainActivity extends AppCompatActivity
|
|||||||
private void setPlatformTabsAndStartGameFileCacheService()
|
private void setPlatformTabsAndStartGameFileCacheService()
|
||||||
{
|
{
|
||||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||||
getSupportFragmentManager(), this, this);
|
getSupportFragmentManager(), this);
|
||||||
mViewPager.setAdapter(platformPagerAdapter);
|
mViewPager.setAdapter(platformPagerAdapter);
|
||||||
mViewPager.setOffscreenPageLimit(platformPagerAdapter.getCount());
|
mViewPager.setOffscreenPageLimit(platformPagerAdapter.getCount());
|
||||||
mTabLayout.setupWithViewPager(mViewPager);
|
mTabLayout.setupWithViewPager(mViewPager);
|
||||||
@ -360,6 +360,11 @@ public final class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (int i = 0; i < PlatformPagerAdapter.TAB_ICONS.length; i++)
|
||||||
|
{
|
||||||
|
mTabLayout.getTabAt(i).setIcon(PlatformPagerAdapter.TAB_ICONS[i]);
|
||||||
|
}
|
||||||
|
|
||||||
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getIntGlobal());
|
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getIntGlobal());
|
||||||
|
|
||||||
showGames();
|
showGames();
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<!-- Hax to make Tablayout render icons -->
|
|
||||||
<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
|
|
||||||
<item name="textAllCaps">false</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<!-- Custom button styles -->
|
<!-- Custom button styles -->
|
||||||
<style name="InGameMenuOption" parent="Widget.Material3.Button.TextButton">
|
<style name="InGameMenuOption" parent="Widget.Material3.Button.TextButton">
|
||||||
<item name="android:textColor">?attr/colorOnSurface</item>
|
<item name="android:textColor">?attr/colorOnSurface</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user