Browse Source

changed behaviour of up navigation to return to old fragment state

Alexander Brakowski 10 years ago
parent
commit
54a036e64c

+ 1 - 1
res/drawable/profile_protocol_badge.xml

@@ -3,7 +3,7 @@
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 	<item android:bottom="4px">
 		<shape android:shape="rectangle">
-			<solid android:color="@color/light_grey" />
+			<solid android:color="@color/bright_grey" />
 			<corners android:radius="6dp" />
 		</shape>
 	</item>

+ 6 - 4
res/layout/profile_manager_list_item.xml

@@ -96,12 +96,12 @@
 	        android:layout_height="wrap_content"
 	        android:id="@+id/profile_manager_item_activated"
 	        android:src="@drawable/ic_action_accept"
-	        android:layout_centerVertical="true"
 	        android:layout_alignParentRight="true"
-	        android:layout_alignParentEnd="true"
+	        android:layout_alignParentEnd="false"
 	        android:layout_marginRight="20dp"
 	        android:visibility="visible"
-	        android:layout_marginLeft="20dp"/>
+	        android:layout_marginLeft="20dp"
+	        android:baselineAlignBottom="false" android:layout_above="@+id/badges_container" android:layout_alignTop="@+id/profile_manager_item_label"/>
 
 		<ImageView
 	        android:layout_width="48dp"
@@ -122,7 +122,9 @@
 				android:padding="10dp"
 				f:horizontalSpacing="10dip"
 				f:verticalSpacing="10dip"
-				android:layout_alignRight="@+id/profile_manager_item_text" android:layout_alignEnd="@+id/profile_manager_item_text">
+				android:layout_alignParentRight="true"
+				android:layout_alignParentEnd="true"
+				android:id="@+id/badges_container">
 			<TextView
 					android:layout_width="wrap_content"
 					android:layout_height="wrap_content"

+ 1 - 0
res/values/colors.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     	<color name="light_grey">#FFC0C0C0</color>
+		<color name="bright_grey">#ffeeeeee</color>
         <color name="dark_grey">#FF808080</color>
         <color name="holo_red">#FFF44444</color>
         <color name="holo_dark_green">#ff669900</color>

+ 1 - 1
res/values/styles.xml

@@ -49,6 +49,6 @@
 		<item name="android:paddingLeft">4dp</item>
 		<item name="android:paddingRight">4dp</item>
 		<item name="android:background">@drawable/profile_protocol_badge</item>
-		<item name="android:textColor">#FFFFFFFF</item>
+		<item name="android:textColor">@color/dark_grey</item>
 	</style>
 </resources>

+ 26 - 41
src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java

@@ -21,6 +21,8 @@ import android.support.v4.app.ActionBarDrawerToggle;
 import android.support.v4.content.LocalBroadcastManager;
 import android.support.v4.widget.DrawerLayout;
 import android.util.Log;
+import android.view.Gravity;
+import android.view.KeyEvent;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.AdapterView;
@@ -258,7 +260,7 @@ public class MainActivity extends Activity {
 	}
 
 	public void stopAndUnbind() {
-		if(mServiceBound){
+		if(mHoneyService != null){
 			unbindService();
 		}
 
@@ -281,6 +283,7 @@ public class MainActivity extends Activity {
 
 	@Override
 	protected void onDestroy() {
+		super.onDestroy();
 		// Unregister Broadcast Receiver
 		unregisterReceiver();
 
@@ -288,7 +291,6 @@ public class MainActivity extends Activity {
 		if(!mHoneyService.hasRunningListeners()){
 			stopAndUnbind();
 		}
-		super.onDestroy();
 	}
 
 	@Override
@@ -307,8 +309,10 @@ public class MainActivity extends Activity {
 
 				UpNavigatible upNav = (UpNavigatible) this.mDisplayedFragment;
 
-				getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
-				Fragment frag = null;
+				getFragmentManager().popBackStackImmediate(upNav.getUpFragment().getName(), 0);
+				this.mDisplayedFragment = getFragmentManager().findFragmentById(R.id.content_frame);
+				configureFragment();
+				/*Fragment frag = null;
 
 				try{
 					frag = (Fragment) upNav.getUpFragment().newInstance();
@@ -318,7 +322,7 @@ public class MainActivity extends Activity {
 					Log.i(null, "Could not create new instance of fragment");
 				}
 
-				if(frag != null) this.injectFragment(frag);
+				if(frag != null) this.injectFragment(frag);*/
 
 				if(!(this.mDisplayedFragment instanceof UpNavigatible) || !((UpNavigatible) this.mDisplayedFragment).isUpNavigatible()){
 					mDrawerToggle.setDrawerIndicatorEnabled(true);
@@ -384,42 +388,6 @@ public class MainActivity extends Activity {
 			Log.i(menuItemPosition.getKlass().toString(), "Could not create new instance of fragment");
 		}
 
-		// update the main content by replacing fragments
-		/*switch (menuItemPosition) {
-			case HOME:
-				fragment = new HomeFragment();
-				break;
-			case THREAT_MAP:
-				fragment = new ThreatMapFragment();
-				break;
-			case RECORDS:{
-				Intent intent = this.getIntent();
-				intent.removeExtra(LogFilter.LOG_FILTER_INTENT_KEY);
-				fragment = new RecordOverviewFragment();
-				break;
-            }
-            case STATISTICS: {
-                Intent intent = this.getIntent();
-                intent.removeExtra(LogFilter.LOG_FILTER_INTENT_KEY);
-                fragment = new StatisticsFragment();
-                break;
-            }
-			case SERVICES:
-				fragment = new ServicesFragment();
-				break;
-			case PROFILE_MANAGER:
-				fragment = new ProfileManagerFragment();
-				break;
-			case SETTINGS:
-				fragment = new SettingsFragment();
-				break;
-			case APPLICATION_INFO:
-				fragment = new AboutFragment();
-				break;
-			default:
-				break;
-		}*/
-
 		if (fragment != null) {
 			// update selected item and title, then close the drawer if needed
             injectFragment(fragment);//, false, menuItemPosition);
@@ -500,6 +468,23 @@ public class MainActivity extends Activity {
 		}
 	}
 
+	@Override
+	public boolean onKeyDown(int keycode, KeyEvent e) {
+		switch(keycode) {
+			case KeyEvent.KEYCODE_MENU:
+				if(this.mDrawerToggle.isDrawerIndicatorEnabled()){
+					if(this.mDrawerLayout.isDrawerOpen(Gravity.LEFT)){
+						this.mDrawerLayout.closeDrawer(Gravity.LEFT);
+						return true;
+					}
+					this.mDrawerLayout.openDrawer(Gravity.LEFT);
+				}
+				return true;
+		}
+
+		return super.onKeyDown(keycode, e);
+	}
+
 	public static void displayBackStack(FragmentManager fm) {
 		int count = fm.getBackStackEntryCount();
 		Log.d("Backstack log", "There are " + count + " entries");

+ 19 - 0
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -5,6 +5,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.graphics.BitmapFactory;
+import android.view.ContextThemeWrapper;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -21,6 +22,7 @@ import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
 import de.tudarmstadt.informatik.hostage.model.Profile;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.activity.ProfileEditActivity;
+import de.tudarmstadt.informatik.hostage.ui2.layouts.FlowLayout;
 import de.tudarmstadt.informatik.hostage.ui2.swipelist.SwipeListView;
 
 /**
@@ -36,6 +38,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 		public ImageButton buttonEdit;
 		public ImageButton buttonDelete;
 		public View seperator;
+		public FlowLayout badgesContainer;
 	}
 
     private final Context context;
@@ -69,6 +72,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 		    holder.buttonEdit = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_edit);
 		    holder.buttonDelete = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_delete);
 			holder.seperator = rowView.findViewById(R.id.profile_manager_item_seperator);
+			holder.badgesContainer = (FlowLayout) rowView.findViewById(R.id.badges_container);
 
 		    rowView.setTag(holder);
 	    } else {
@@ -124,6 +128,21 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 			}
 		});
 
+	    holder.badgesContainer.removeAllViews();
+	    boolean hasProtocols = false;
+	    for(String protocol: item.getActiveProtocols()){
+		    hasProtocols = true;
+			TextView textView = new TextView(new ContextThemeWrapper(context, R.style.ProfileManagerListBadge));
+		    textView.setText(protocol);
+		    holder.badgesContainer.addView(textView);
+	    }
+
+	    if(!hasProtocols){
+		    holder.badgesContainer.setVisibility(View.INVISIBLE);
+	    } else {
+		    holder.badgesContainer.setVisibility(View.VISIBLE);
+	    }
+
 		RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.textView.getLayoutParams();
 
         if(!item.mActivated){

+ 3 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileManagerFragment.java

@@ -30,6 +30,7 @@ public class ProfileManagerFragment extends Fragment {
 
 	public ProfileManagerFragment(){}
 
+	private SwipeListView list;
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
@@ -39,7 +40,7 @@ public class ProfileManagerFragment extends Fragment {
 	    setHasOptionsMenu(true);
 
         View rootView = inflater.inflate(R.layout.fragment_profile_manager, container, false);
-	    SwipeListView list = (SwipeListView) rootView.findViewById(R.id.profile_manager_listview);
+	    list = (SwipeListView) rootView.findViewById(R.id.profile_manager_listview);
 
 		final ProfileManager pmanager = ProfileManager.getInstance();
 		pmanager.loadData();
@@ -67,6 +68,7 @@ public class ProfileManagerFragment extends Fragment {
 	@Override
 	public void onResume() {
 		super.onResume();
+		list.closeOpenedItems();
 		mAdapter.notifyDataSetChanged();
 	}