Jelajahi Sumber

Strange behaviour of the main menu FINALLY fixed.

seavenois 10 tahun lalu
induk
melakukan
2ade110de3

+ 2 - 2
app/src/main/AndroidManifest.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.ivalentin.margolariak"
-    android:versionCode="9"
-    android:versionName="2.0-alpha02" >
+    android:versionCode="10"
+    android:versionName="2.0-alpha03" >
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

+ 24 - 0
app/src/main/java/com/ivalentin/margolariak/MainActivity.java

@@ -19,6 +19,7 @@ import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.Gravity;
+import android.view.KeyEvent;
 import android.view.View;
 import android.view.Window;
 import android.view.View.OnClickListener;
@@ -200,6 +201,7 @@ public class MainActivity extends Activity{
 		menuItem[4] = (TextView) findViewById(R.id.menu_blog);
 		menuItem[5] = (TextView) findViewById(R.id.menu_gallery);
 		menuItem[6] = (TextView) findViewById(R.id.menu_settings);
+		TextView menuSpacer = (TextView) findViewById(R.id.menu_space);
 
 		//Assign buttons for la blanca submenu
 		TextView menuLablancaItem[] = new TextView[2];
@@ -260,6 +262,13 @@ public class MainActivity extends Activity{
 			}
 		}
 
+		menuSpacer.setOnClickListener(new OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				mLayout.toggleMenu();
+			}
+		});
+
 		//If the user code is not set, generate one
 		if (preferences.getString(GM.USER_CODE, "").length() == 0){
 			SecureRandom random = new SecureRandom();
@@ -565,5 +574,20 @@ public class MainActivity extends Activity{
 		}
 		
 	}
+
+	/**
+	 * Overrides onKeyUp().
+	 * Used to toggle the menu whent the key is pressed.
+	 *
+	 * @see android.app.Activity#onKeyUp(int, KeyEvent)
+	 */
+	@Override
+	public boolean onKeyUp(int keyCode, KeyEvent event) {
+		if (keyCode == KeyEvent.KEYCODE_MENU) {
+			mLayout.toggleMenu();
+			return true;
+		}
+		return super.onKeyUp(keyCode, event);
+	}
 	
 }

+ 8 - 4
app/src/main/java/com/ivalentin/margolariak/MainLayout.java

@@ -4,10 +4,12 @@ import android.annotation.SuppressLint;
 import android.content.Context;
 import android.os.Handler;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.animation.Interpolator;
 import android.widget.LinearLayout;
+import android.widget.ScrollView;
 import android.widget.Scroller;
 
 /**
@@ -206,7 +208,7 @@ public class MainLayout extends LinearLayout {
 			return false;
 		int curX = (int) event.getRawX();
 		int diffX;
-		
+
 		switch (event.getAction()) {
 			case MotionEvent.ACTION_DOWN:
 				prevX = curX;
@@ -238,12 +240,12 @@ public class MainLayout extends LinearLayout {
 				return true;
 			
 			case MotionEvent.ACTION_UP:
-				
-				if (lastDiffX > 0) {
+				if (currentMenuState == MenuState.HIDDEN) {
 					currentMenuState = MenuState.SHOWING;
 					menuScroller.startScroll(contentXOffset, 0,	menu.getLayoutParams().width - contentXOffset, 0, GM.MENU_SLIDING_DURATION);
 				}
-				else if (lastDiffX < 0) {
+				else if (currentMenuState == MenuState.SHOWN) {
+
 					currentMenuState = MenuState.HIDING;
 					menuScroller.startScroll(contentXOffset, 0, -contentXOffset, 0, GM.MENU_SLIDING_DURATION);
 				}
@@ -257,6 +259,8 @@ public class MainLayout extends LinearLayout {
 			default:
 				break;
 		}
+
+
 		
 		return false;
 	}

+ 35 - 22
app/src/main/res/layout/activity_main.xml

@@ -1,23 +1,26 @@
-<com.ivalentin.margolariak.MainLayout xmlns:android="http://schemas.android.com/apk/res/android"
-									  android:id="@+id/main_layout"
-									  android:layout_width="match_parent"
-									  android:layout_height="match_parent"
-									  android:background="@color/background_menu"
-									  android:fitsSystemWindows="true" >
+<com.ivalentin.margolariak.MainLayout
+	xmlns:android="http://schemas.android.com/apk/res/android"
+	android:id="@+id/main_layout"
+	android:layout_width="match_parent"
+	android:layout_height="match_parent"
+	android:fitsSystemWindows="true"
+	android:background="@color/background_menu">
     
 	
     <!-- Slider menu -->
 
     <ScrollView
-        android:layout_width="wrap_content"
-        android:layout_height="fill_parent" >
+		android:layout_width="wrap_content"
+		android:layout_height="fill_parent"
+		android:nestedScrollingEnabled="false">
 
         <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:divider="@drawable/divider"
-            android:orientation="vertical"
-            android:padding="10dp">
+			android:layout_width="match_parent"
+			android:layout_height="fill_parent"
+			android:divider="@drawable/divider"
+			android:orientation="vertical"
+			android:padding="10dp"
+			android:baselineAligned="false"	>
 
             <TextView
 				android:id="@+id/menu_home"
@@ -187,18 +190,26 @@
 				android:paddingBottom="4dp"
 				android:paddingTop="4dp"/>
 
-        </LinearLayout>
+			<TextView
+				android:layout_width="fill_parent"
+				android:layout_height="fill_parent"
+				android:textAppearance="?android:attr/textAppearanceMedium"
+				android:id="@+id/menu_space"
+				android:padding="5dp"/>
+
+		</LinearLayout>
 
     </ScrollView>
 
 	<!-- The visible screen -->
 
 	<LinearLayout
-	    xmlns:android="http://schemas.android.com/apk/res/android"
-	    android:layout_width="match_parent"
-	    android:layout_height="match_parent"
-	    android:background="@color/background_app"
-	    android:orientation="vertical" >
+		xmlns:android="http://schemas.android.com/apk/res/android"
+		android:layout_width="match_parent"
+		android:layout_height="match_parent"
+		android:background="@color/background_app"
+		android:orientation="vertical"
+		>
 
 		<!-- The action bar -->
 
@@ -269,9 +280,11 @@
 		<!-- The part where the fragments will be loaded -->
 
 		<FrameLayout
-		    android:id="@+id/activity_main_content_fragment"
-		    android:layout_width="match_parent"
-		    android:layout_height="match_parent" >
+			android:id="@+id/activity_main_content_fragment"
+			android:layout_width="match_parent"
+			android:layout_height="match_parent"
+			android:layout_marginLeft="9dp"
+			android:layout_marginRight="9dp">
 		
 		</FrameLayout>