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_height="match_parent"
android:baselineAligned="false"
android:weightSum="1.3"
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.1"
android:layout_weight="1"
android:background="?feedlistBackground" >
</FrameLayout>
@ -47,7 +47,7 @@
android:id="@+id/headlines_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.9"
android:layout_weight="2"
android:background="?headlinesBackground" >
</FrameLayout>
</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.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
@ -151,7 +152,7 @@ public class CommonActivity extends SherlockFragmentActivity {
return width < height;
}
@SuppressLint("NewApi")
@SuppressLint({ "NewApi", "ServiceCast" })
@SuppressWarnings("deprecation")
public void copyToClipboard(String str) {
if (android.os.Build.VERSION.SDK_INT < 11) {
@ -186,4 +187,19 @@ public class CommonActivity extends SherlockFragmentActivity {
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 int m_actionbarRevertDepth = 0;
private SlidingMenu m_slidingMenu;
private boolean m_feedIsSelected = false;
@SuppressLint("NewApi")
@Override
@ -49,18 +50,23 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
super.onCreate(savedInstanceState);
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);
if (isSmallScreen()) {
if (isSmallScreen() || findViewById(R.id.sw600dp_port_anchor) != null) {
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.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
m_slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
m_slidingMenu.setSlidingEnabled(true);
m_slidingMenu.setMenu(R.layout.feeds);
m_slidingMenu.setSlidingEnabled(true);
m_slidingMenu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {
@Override
@ -94,13 +100,16 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
} else { // savedInstanceState != null
m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled");
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();
if (!isSmallScreen()) {
// temporary hack because FeedsActivity doesn't track whether active feed is open
LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container);
if (container != null)
container.setWeightSum(3f);
}
@ -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.feeds_fragment)).setLayoutTransition(new LayoutTransition());
}
} */
}
@ -156,6 +165,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
if (!isCompatMode() && !isSmallScreen()) {
LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container);
if (container != null) {
float wSum = container.getWeightSum();
if (wSum <= 2.0f) {
ObjectAnimator anim = ObjectAnimator.ofFloat(container, "weightSum", wSum, 3.0f);
@ -163,6 +173,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
anim.start();
}
}
}
final Feed fFeed = feed;
@ -178,6 +189,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
ft.commit();
m_feedIsSelected = true;
if (m_slidingMenu != null) {
m_slidingMenu.showContent();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -284,9 +297,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
out.putBoolean("feedIsSelected", m_feedIsSelected);
if (m_slidingMenu != null )
out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing());
//if (m_slidingMenu != null )
// out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing());
GlobalState.getInstance().save(out);
}

View File

@ -27,6 +27,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
private boolean m_actionbarUpEnabled = false;
private int m_actionbarRevertDepth = 0;
private SlidingMenu m_slidingMenu;
private boolean m_feedIsSelected = false;
@SuppressLint("NewApi")
@Override
@ -39,13 +40,18 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
super.onCreate(savedInstanceState);
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);
if (isSmallScreen()) {
if (isSmallScreen() || findViewById(R.id.sw600dp_port_anchor) != null) {
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.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
m_slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
@ -68,6 +74,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled");
m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth");
m_feedIsSelected = savedInstanceState.getBoolean("feedIsSelected");
if (!m_feedIsSelected && m_slidingMenu != null)
m_slidingMenu.showMenu();
if (m_actionbarUpEnabled) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -148,6 +158,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
out.putBoolean("feedIsSelected", m_feedIsSelected);
//if (m_slidingMenu != null )
// out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing());
GlobalState.getInstance().save(out);
}
@ -222,8 +236,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
if (open) {
if (!isSmallScreen()) {
LinearLayout container = (LinearLayout) findViewById(R.id.fragment_container);
if (container != null) {
container.setWeightSum(3f);
}
}
new Handler().postDelayed(new Runnable() {
@Override
@ -237,6 +253,8 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
ft.commit();
m_feedIsSelected = true;
if (m_slidingMenu != null) {
m_slidingMenu.showContent();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);