Small tablet support (< 8")

* Portrait mode
** feed list is now smaller and article list is bigger
* Landscape mode
** small tablets display always only two columns
This commit is contained in:
lpetrus 2012-09-02 15:10:57 +02:00 committed by Andrew Dolgov
parent d5c0f015e5
commit 416d155e85
4 changed files with 59 additions and 9 deletions

View File

@ -11,9 +11,9 @@
<FrameLayout
android:id="@+id/feeds_fragment"
android:layout_width="300dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0"
android:layout_weight="0.6"
android:background="?feedlistBackground" >
</FrameLayout>
@ -21,6 +21,7 @@
android:id="@+id/vertical_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:orientation="vertical" >
<FrameLayout

View File

@ -2,10 +2,11 @@ package org.fox.ttrss;
import org.fox.ttrss.util.DatabaseHelper;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.DisplayMetrics;
import android.util.FloatMath;
import android.util.Log;
import android.view.Display;
import android.widget.Toast;
@ -23,12 +24,30 @@ public class CommonActivity extends FragmentActivity {
private boolean m_smallScreenMode = true;
private boolean m_compatMode = false;
private boolean m_smallTablet = false;
protected void setSmallScreen(boolean smallScreen) {
Log.d(TAG, "m_smallScreenMode=" + smallScreen);
m_smallScreenMode = smallScreen;
}
protected void setupSmallTabletFlag() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
float inHeight = displayMetrics.heightPixels / displayMetrics.ydpi;
float inWidth = displayMetrics.widthPixels / displayMetrics.xdpi;
float inDiag = FloatMath.sqrt(inHeight * inHeight + inWidth * inWidth);
if (inDiag < 8) {
m_smallTablet = true;
}
Log.d(TAG, "m_smallTabletMode=" + m_smallTablet);
}
private void initDatabase() {
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
@ -67,6 +86,10 @@ public class CommonActivity extends FragmentActivity {
public boolean isSmallScreen() {
return m_smallScreenMode;
}
public boolean isSmallTablet() {
return m_smallTablet;
}
public boolean isCompatMode() {
return m_compatMode;

View File

@ -645,6 +645,8 @@ public class MainActivity extends CommonActivity implements OnlineServices {
setContentView(R.layout.main);
setSmallScreen(findViewById(R.id.headlines_fragment) == null);
setupSmallTabletFlag();
IntentFilter filter = new IntentFilter();
filter.addAction(OfflineDownloadService.INTENT_ACTION_SUCCESS);
@ -662,7 +664,7 @@ public class MainActivity extends CommonActivity implements OnlineServices {
if (!isCompatMode()) {
if (!isSmallScreen()) {
findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticle != null && isPortrait() ? View.GONE : View.VISIBLE);
findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticle != null && (isPortrait() || isSmallTablet()) ? View.GONE : View.VISIBLE);
findViewById(R.id.article_fragment).setVisibility(m_selectedArticle != null ? View.VISIBLE : View.GONE);
}
@ -998,8 +1000,8 @@ public class MainActivity extends CommonActivity implements OnlineServices {
if (m_selectedArticle != null) {
closeArticle();
refresh();
/* } else if (m_activeFeed != null) {
closeFeed(); */
} else if (m_activeFeed != null) {
closeFeed();
} else if (m_activeCategory != null) {
closeCategory();
} else if (allowQuit) {
@ -1008,6 +1010,28 @@ public class MainActivity extends CommonActivity implements OnlineServices {
}
}
private void closeFeed() {
if (m_activeFeed != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new DummyFragment(), "");
ft.commit();
if (m_activeFeed.is_cat) {
FeedCategoriesFragment cats = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS);
cats.setSelectedCategory(null);
} else {
FeedsFragment feeds = (FeedsFragment) getSupportFragmentManager().findFragmentByTag(FRAG_FEEDS);
feeds.setSelectedFeed(null);
}
m_activeFeed = null;
initMainMenu();
}
}
@SuppressWarnings("unchecked")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@ -1864,7 +1888,7 @@ public class MainActivity extends CommonActivity implements OnlineServices {
ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
ft.add(R.id.fragment_container, frag, FRAG_ARTICLE);
} else {
findViewById(R.id.feeds_fragment).setVisibility(isPortrait() ? View.GONE : View.VISIBLE);
findViewById(R.id.feeds_fragment).setVisibility(isPortrait() || isSmallTablet() ? View.GONE : View.VISIBLE);
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);

View File

@ -291,10 +291,12 @@ public class OfflineActivity extends CommonActivity implements
setContentView(R.layout.main);
setSmallScreen(findViewById(R.id.headlines_fragment) == null);
setupSmallTabletFlag();
if (!isCompatMode()) {
if (!isSmallScreen()) {
findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticleId != 0 && isPortrait() ? View.GONE : View.VISIBLE);
findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticleId != 0 && (isPortrait() || isSmallTablet()) ? View.GONE : View.VISIBLE);
findViewById(R.id.article_fragment).setVisibility(m_selectedArticleId != 0 ? View.VISIBLE : View.GONE);
}
@ -1399,7 +1401,7 @@ public class OfflineActivity extends CommonActivity implements
ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
ft.add(R.id.fragment_container, frag, FRAG_ARTICLE);
} else {
findViewById(R.id.feeds_fragment).setVisibility(isPortrait() ? View.GONE : View.VISIBLE);
findViewById(R.id.feeds_fragment).setVisibility(isPortrait() || isSmallTablet() ? View.GONE : View.VISIBLE);
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);