use slidingmenu for sw600dp devices in portrait mode, misc menu-related

fixes
This commit is contained in:
Andrew Dolgov 2013-05-28 15:47:44 +04:00
parent 3fcdae62aa
commit e84345ce5a
8 changed files with 211 additions and 24 deletions

View File

@ -32,14 +32,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:baselineAligned="false" android:baselineAligned="false"
android:weightSum="1.3" android:weightSum="1.1"
android:orientation="horizontal" > android:orientation="horizontal" >
<FrameLayout <FrameLayout
android:id="@+id/feeds_fragment" android:id="@+id/feeds_fragment"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1.1" android:layout_weight="1"
android:background="?feedlistBackground" > android:background="?feedlistBackground" >
</FrameLayout> </FrameLayout>
@ -47,7 +47,7 @@
android:id="@+id/headlines_fragment" android:id="@+id/headlines_fragment"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1.9" android:layout_weight="2"
android:background="?headlinesBackground" > android:background="?headlinesBackground" >
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,35 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/headlines"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/sw600dp_port_anchor"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>
<LinearLayout
android:id="@+id/loading_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone" >
<TextView
android:id="@+id/loading_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<FrameLayout
android:id="@+id/headlines_fragment"
android:background="?smallScreenBackground"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>

View File

@ -0,0 +1,55 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="?headlinesBackgroundSolid"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/sw600dp_anchor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
</FrameLayout>
<LinearLayout
android:id="@+id/loading_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone" >
<TextView
android:id="@+id/loading_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:weightSum="1.1"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/feeds_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?feedlistBackground" >
</FrameLayout>
<FrameLayout
android:id="@+id/headlines_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="?headlinesBackground" >
</FrameLayout>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,49 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/headlines"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/loading_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?loadingBackground"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible" >
<TextView
android:id="@+id/loading_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/loading_message"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/headlines_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="?feedlistBackground" >
</FrameLayout>
<FrameLayout
android:id="@+id/article_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="?articleBackground" >
</FrameLayout>
</LinearLayout>
</LinearLayout>

View File

@ -7,6 +7,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.Point;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -151,7 +152,7 @@ public class CommonActivity extends SherlockFragmentActivity {
return width < height; return width < height;
} }
@SuppressLint("NewApi") @SuppressLint({ "NewApi", "ServiceCast" })
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void copyToClipboard(String str) { public void copyToClipboard(String str) {
if (android.os.Build.VERSION.SDK_INT < 11) { if (android.os.Build.VERSION.SDK_INT < 11) {
@ -186,4 +187,19 @@ public class CommonActivity extends SherlockFragmentActivity {
setTheme(R.style.LightTheme); setTheme(R.style.LightTheme);
} }
} }
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
protected int getScreenWidthInPixel() {
Display display = getWindowManager().getDefaultDisplay();
if (android.os.Build.VERSION.SDK_INT >= 13) {
Point size = new Point();
display.getSize(size);
int width = size.x;
return width;
} else {
return display.getWidth();
}
}
} }

View File

@ -37,6 +37,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
private boolean m_actionbarUpEnabled = false; private boolean m_actionbarUpEnabled = false;
private int m_actionbarRevertDepth = 0; private int m_actionbarRevertDepth = 0;
private SlidingMenu m_slidingMenu; private SlidingMenu m_slidingMenu;
private boolean m_feedIsSelected = false;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
@ -49,18 +50,23 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.headlines); setContentView(R.layout.headlines);
setSmallScreen(findViewById(R.id.sw600dp_anchor) == null); setSmallScreen(findViewById(R.id.sw600dp_anchor) == null &&
findViewById(R.id.sw600dp_port_anchor) == null);
GlobalState.getInstance().load(savedInstanceState); GlobalState.getInstance().load(savedInstanceState);
if (isSmallScreen()) { if (isSmallScreen() || findViewById(R.id.sw600dp_port_anchor) != null) {
m_slidingMenu = new SlidingMenu(this); m_slidingMenu = new SlidingMenu(this);
if (findViewById(R.id.sw600dp_port_anchor) != null) {
m_slidingMenu.setBehindWidth(getScreenWidthInPixel() * 2/3);
}
m_slidingMenu.setMode(SlidingMenu.LEFT); m_slidingMenu.setMode(SlidingMenu.LEFT);
m_slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); m_slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
m_slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); m_slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
m_slidingMenu.setSlidingEnabled(true);
m_slidingMenu.setMenu(R.layout.feeds); m_slidingMenu.setMenu(R.layout.feeds);
m_slidingMenu.setSlidingEnabled(true);
m_slidingMenu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() { m_slidingMenu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {
@Override @Override
@ -94,14 +100,17 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
} else { // savedInstanceState != null } else { // savedInstanceState != null
m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled"); m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled");
m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth"); m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth");
m_feedIsSelected = savedInstanceState.getBoolean("feedIsSelected");
if (m_slidingMenu != null && savedInstanceState.getBoolean("slidingMenuVisible")) if (m_slidingMenu != null && m_feedIsSelected == false)
m_slidingMenu.showMenu(); m_slidingMenu.showMenu();
if (!isSmallScreen()) { if (!isSmallScreen()) {
// temporary hack because FeedsActivity doesn't track whether active feed is open // temporary hack because FeedsActivity doesn't track whether active feed is open
LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container); LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container);
container.setWeightSum(3f);
if (container != null)
container.setWeightSum(3f);
} }
if (m_actionbarUpEnabled) { if (m_actionbarUpEnabled) {
@ -109,10 +118,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
} }
} }
if (!isCompatMode() && !isSmallScreen()) { /* if (!isCompatMode() && !isSmallScreen()) {
((ViewGroup)findViewById(R.id.headlines_fragment)).setLayoutTransition(new LayoutTransition()); ((ViewGroup)findViewById(R.id.headlines_fragment)).setLayoutTransition(new LayoutTransition());
((ViewGroup)findViewById(R.id.feeds_fragment)).setLayoutTransition(new LayoutTransition()); ((ViewGroup)findViewById(R.id.feeds_fragment)).setLayoutTransition(new LayoutTransition());
} } */
} }
@ -156,11 +165,13 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
if (!isCompatMode() && !isSmallScreen()) { if (!isCompatMode() && !isSmallScreen()) {
LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container); LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container);
float wSum = container.getWeightSum(); if (container != null) {
if (wSum <= 2.0f) { float wSum = container.getWeightSum();
ObjectAnimator anim = ObjectAnimator.ofFloat(container, "weightSum", wSum, 3.0f); if (wSum <= 2.0f) {
anim.setDuration(200); ObjectAnimator anim = ObjectAnimator.ofFloat(container, "weightSum", wSum, 3.0f);
anim.start(); anim.setDuration(200);
anim.start();
}
} }
} }
@ -177,6 +188,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ft.commit(); ft.commit();
m_feedIsSelected = true;
if (m_slidingMenu != null) { if (m_slidingMenu != null) {
m_slidingMenu.showContent(); m_slidingMenu.showContent();
@ -284,9 +297,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled); out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
out.putInt("actionbarRevertDepth", m_actionbarRevertDepth); out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
out.putBoolean("feedIsSelected", m_feedIsSelected);
if (m_slidingMenu != null ) //if (m_slidingMenu != null )
out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing()); // out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing());
GlobalState.getInstance().save(out); GlobalState.getInstance().save(out);
} }

View File

@ -27,6 +27,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
private boolean m_actionbarUpEnabled = false; private boolean m_actionbarUpEnabled = false;
private int m_actionbarRevertDepth = 0; private int m_actionbarRevertDepth = 0;
private SlidingMenu m_slidingMenu; private SlidingMenu m_slidingMenu;
private boolean m_feedIsSelected = false;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
@ -39,13 +40,18 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.headlines); setContentView(R.layout.headlines);
setSmallScreen(findViewById(R.id.sw600dp_anchor) == null); setSmallScreen(findViewById(R.id.sw600dp_anchor) == null &&
findViewById(R.id.sw600dp_port_anchor) == null);
GlobalState.getInstance().load(savedInstanceState); GlobalState.getInstance().load(savedInstanceState);
if (isSmallScreen()) { if (isSmallScreen() || findViewById(R.id.sw600dp_port_anchor) != null) {
m_slidingMenu = new SlidingMenu(this); m_slidingMenu = new SlidingMenu(this);
if (findViewById(R.id.sw600dp_port_anchor) != null) {
m_slidingMenu.setBehindWidth(getScreenWidthInPixel() * 2/3);
}
m_slidingMenu.setMode(SlidingMenu.LEFT); m_slidingMenu.setMode(SlidingMenu.LEFT);
m_slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); m_slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
m_slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); m_slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
@ -68,6 +74,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled"); m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled");
m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth"); m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth");
m_feedIsSelected = savedInstanceState.getBoolean("feedIsSelected");
if (!m_feedIsSelected && m_slidingMenu != null)
m_slidingMenu.showMenu();
if (m_actionbarUpEnabled) { if (m_actionbarUpEnabled) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -148,6 +158,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled); out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
out.putInt("actionbarRevertDepth", m_actionbarRevertDepth); out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
out.putBoolean("feedIsSelected", m_feedIsSelected);
//if (m_slidingMenu != null )
// out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing());
GlobalState.getInstance().save(out); GlobalState.getInstance().save(out);
} }
@ -222,7 +236,9 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
if (open) { if (open) {
if (!isSmallScreen()) { if (!isSmallScreen()) {
LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container); LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container);
container.setWeightSum(3f); if (container != null) {
container.setWeightSum(3f);
}
} }
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@ -236,7 +252,9 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ft.commit(); ft.commit();
m_feedIsSelected = true;
if (m_slidingMenu != null) { if (m_slidingMenu != null) {
m_slidingMenu.showContent(); m_slidingMenu.showContent();
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);