mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2024-12-15 18:19:37 +01:00
added option to configure multi column mode
This commit is contained in:
parent
6d13d5dd7f
commit
966dd7dcc8
@ -65,6 +65,7 @@ import android.text.format.DateUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
@ -1215,10 +1216,27 @@ public final class Utils implements Constants {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether screen minimum width is not smaller than 600dp, regardless split screen mode
|
||||
*/
|
||||
public static boolean isDeviceTablet(@NonNull Context context) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.getDefaultDisplay().getMetrics(metrics);
|
||||
final Display defaultDisplay = wm.getDefaultDisplay();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
defaultDisplay.getMetrics(metrics);
|
||||
} else {
|
||||
defaultDisplay.getRealMetrics(metrics);
|
||||
}
|
||||
final float mw = Math.min(metrics.widthPixels / metrics.density, metrics.heightPixels / metrics.density);
|
||||
return mw >= 600;
|
||||
}
|
||||
|
||||
/*
|
||||
* May return false on tablets when using split window
|
||||
*/
|
||||
public static boolean isScreenTablet(@NonNull Context context) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
final float mw = Math.min(metrics.widthPixels / metrics.density, metrics.heightPixels / metrics.density);
|
||||
return mw >= 600;
|
||||
}
|
||||
|
@ -786,7 +786,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
||||
val hasNoTab = pagerAdapter.count == 0
|
||||
emptyTabHint.visibility = if (hasNoTab) View.VISIBLE else View.GONE
|
||||
mainPager.visibility = if (hasNoTab) View.GONE else View.VISIBLE
|
||||
if (pagerAdapter.count > 1 && resources.getBoolean(R.bool.home_tab_has_multiple_columns)) {
|
||||
if (pagerAdapter.count > 1 && hasMultiColumns()) {
|
||||
mainPager.pageMargin = resources.getDimensionPixelOffset(R.dimen.home_page_margin)
|
||||
mainPager.setPageMarginDrawable(ThemeUtils.getDrawableFromThemeAttribute(this, R.attr.dividerVertical))
|
||||
pagerAdapter.hasMultipleColumns = true
|
||||
@ -867,6 +867,16 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
||||
actionsButton.contentDescription = getString(title)
|
||||
}
|
||||
|
||||
|
||||
fun hasMultiColumns(): Boolean {
|
||||
if (!Utils.isScreenTablet(this)) return false
|
||||
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
return preferences.getBoolean("multi_column_tabs_landscape", resources.getBoolean(R.bool.default_multi_column_tabs_land))
|
||||
}
|
||||
return preferences.getBoolean("multi_column_tabs_portrait", resources.getBoolean(R.bool.default_multi_column_tabs_port))
|
||||
}
|
||||
|
||||
|
||||
private class AccountUpdatedListener(private val activity: HomeActivity) : OnAccountsUpdateListener {
|
||||
|
||||
override fun onAccountsUpdated(accounts: Array<out Account>?) {
|
||||
|
5
twidere/src/main/res/values-sw600dp/defaults.xml
Normal file
5
twidere/src/main/res/values-sw600dp/defaults.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<bool name="default_multi_column_tabs_land">true</bool>
|
||||
<bool name="default_multi_column_tabs_port">false</bool>
|
||||
</resources>
|
5
twidere/src/main/res/values-sw720dp/defaults.xml
Normal file
5
twidere/src/main/res/values-sw720dp/defaults.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<bool name="default_multi_column_tabs_land">true</bool>
|
||||
<bool name="default_multi_column_tabs_port">true</bool>
|
||||
</resources>
|
@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<resources>
|
||||
|
||||
<bool name="default_display_tab_label">false</bool>
|
||||
<bool name="support_new_document_intent">false</bool>
|
||||
|
||||
<bool name="has_font_family">false</bool>
|
||||
|
||||
<!-- Config for home screen -->
|
||||
<bool name="home_tab_has_multiple_columns">false</bool>
|
||||
|
||||
</resources>
|
||||
<bool name="support_new_document_intent">false</bool>
|
||||
</resources>
|
||||
|
@ -1,9 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="default_tab_display_option">icon</string>
|
||||
<string name="profile_image_size">normal</string>
|
||||
<bool name="default_multi_column_tabs_land">false</bool>
|
||||
<bool name="default_multi_column_tabs_port">false</bool>
|
||||
<string name="default_profile_image_style">round</string>
|
||||
<string name="default_tab_display_option">icon</string>
|
||||
|
||||
<integer name="min_database_item_limit">50</integer>
|
||||
|
||||
</resources>
|
||||
<string name="profile_image_size">normal</string>
|
||||
</resources>
|
||||
|
@ -1,15 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--suppress AndroidElementNotAllowed -->
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/preference_title_tablet_mode">
|
||||
|
||||
<org.mariotaku.twidere.preference.TintedPreferenceCategory android:title="@string/preference_title_multi_column_tabs">
|
||||
<org.mariotaku.twidere.preference.TintedPreferenceCategory
|
||||
android:title="@string/preference_title_multi_column_tabs">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:defaultValue="@bool/default_multi_column_tabs_port"
|
||||
android:key="multi_column_tabs_portrait"
|
||||
android:title="@string/preference_title_portrait"/>
|
||||
android:title="@string/preference_title_portrait">
|
||||
<extra
|
||||
android:name="should_recreate"
|
||||
android:value="true"/>
|
||||
</SwitchPreferenceCompat>
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:defaultValue="@bool/default_multi_column_tabs_land"
|
||||
android:key="multi_column_tabs_landscape"
|
||||
android:title="@string/preference_title_landscape"/>
|
||||
android:title="@string/preference_title_landscape">
|
||||
<extra
|
||||
android:name="should_recreate"
|
||||
android:value="true"/>
|
||||
</SwitchPreferenceCompat>
|
||||
</org.mariotaku.twidere.preference.TintedPreferenceCategory>
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user