Browse Source

fixed strange save state bug, which resulted in an fragment back stack bug

Alexander Brakowski 10 years ago
parent
commit
8300e331c6

+ 1 - 0
.gitignore

@@ -31,3 +31,4 @@ build/
 gen-external-apklibs/
 native/build
 native/build.o
+native/bind

BIN
native/bind.o


BIN
native/p


BIN
native/p.o


BIN
res/drawable-hdpi/ic_action_cancel_dark.png


BIN
res/drawable-mdpi/ic_action_cancel_dark.png


BIN
res/drawable-xhdpi/ic_action_cancel_dark.png


BIN
res/drawable-xxhdpi/ic_action_cancel_dark.png


+ 0 - 0
res/drawable/swipe_icon.png → res/drawable-xxxhdpi/swipe_icon.png


+ 19 - 0
res/drawable/panel_help_bg.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+	<!-- Bottom 3dp Shadow -->
+	<item>
+		<shape android:shape="rectangle">
+			<solid android:color="#C7C6C5" />
+		</shape>
+	</item>
+
+	<!-- White Top color -->
+	<item android:bottom="2px" android:top="2px">
+		<shape android:shape="rectangle">
+			<solid android:color="@color/bright_grey" />
+		</shape>
+
+	</item>
+
+</layer-list>

+ 17 - 4
res/layout/profile_manager_list_item_help.xml

@@ -5,7 +5,7 @@
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:id="@+id/swipelist_frontview"
-              android:background="@color/bright_grey"
+              android:background="@drawable/panel_help_bg"
               android:padding="10dp">
 
 	<TextView
@@ -16,21 +16,34 @@
 			android:id="@+id/textView"
 			android:layout_alignParentTop="true"
 			android:layout_toRightOf="@+id/imageView"
-			android:layout_marginLeft="10dp"/>
+			android:layout_marginLeft="15dp"
+			android:layout_toLeftOf="@+id/imageView2"/>
 
 	<ImageView
-			android:layout_width="wrap_content"
+			android:layout_width="50dp"
 			android:layout_height="wrap_content"
 			android:id="@+id/imageView"
 			android:src="@drawable/swipe_icon"
 			android:layout_alignParentTop="true"
 			android:layout_alignParentLeft="true"
 			android:layout_alignParentStart="true"
-			android:layout_alignBottom="@+id/textView"/>
+			android:layout_alignBottom="@+id/textView"
+			android:scaleType="fitCenter"/>
 
 	<FrameLayout
 			android:layout_width="wrap_content"
 			android:layout_height="wrap_content"
 			android:id="@+id/swipelist_backview">
 	</FrameLayout>
+
+	<ImageView
+			android:layout_width="wrap_content"
+			android:layout_height="wrap_content"
+			android:id="@+id/imageView2"
+			android:src="@drawable/ic_action_cancel_dark"
+			android:layout_alignParentTop="true"
+			android:layout_alignParentRight="true"
+			android:layout_alignParentEnd="true"
+			android:layout_alignBottom="@+id/textView"/>
+
 </RelativeLayout>

+ 5 - 0
src/de/tudarmstadt/informatik/hostage/Listener.java

@@ -222,4 +222,9 @@ public class Listener implements Runnable {
 		sslClient.setUseClientMode(false);
 		handlers.add(newInstance(service, this, protocol.getClass().newInstance(), sslClient));
 	}
+
+	@Override
+	public String toString() {
+		return protocol.toString() + ":" + port;
+	}
 }

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

@@ -79,7 +79,7 @@ public class MainActivity extends Activity {
 	/**
 	 * Connection to bind the background service
 	 * 
-	 * @see HoneyService
+	 * @see de.tudarmstadt.informatik.hostage.Hostage
 	 */
 	private ServiceConnection mConnection = new ServiceConnection() {
 		/**
@@ -108,8 +108,6 @@ public class MainActivity extends Activity {
 
 	};
 
-	private boolean mInvalidMenuItem = false;
-
 	private HashMap<String, Boolean> mAttacksOnProtocol = new HashMap<String, Boolean>();
 
 	/**
@@ -400,9 +398,11 @@ public class MainActivity extends Activity {
 		}
 
 		if (fragment != null) {
+			boolean isFirst = getFragmentManager().getBackStackEntryCount() == 0;
+
 			getFragmentManager().popBackStackImmediate(HomeFragment.class.getName(), 0);
 			// update selected item and title, then close the drawer if needed
-			injectFragment(fragment);// , false, menuItemPosition);
+			if(!(fragment instanceof HomeFragment) || isFirst) injectFragment(fragment);// , false, menuItemPosition);
 
 			mDrawerList.setItemChecked(position, true);
 			mDrawerList.setSelection(position);

+ 39 - 24
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -42,28 +42,41 @@ import de.tudarmstadt.informatik.hostage.ui2.fragment.opengl.ThreatIndicatorGLRe
  */
 
 public class HomeFragment extends Fragment {
+
 	private Switch mHomeSwitchConnection;
+
 	private TextView mHomeTextName;
+
 	private TextView mHomeTextSecurity;
+
 	private TextView mHomeTextAttacks;
+
 	private TextView mHomeTextProfile;
+
 	private TextView mHomeTextProfileHeader;
+
 	private ImageView mHomeProfileImage;
+
 	private ImageView mHomeConnectionInfoButton;
 
 	private View mRootView;
+
 	private BroadcastReceiver mReceiver;
 
 	private CompoundButton.OnCheckedChangeListener mSwitchChangeListener = null;
 
 	private int mDefaultTextColor;
+
 	private ProfileManager mProfileManager;
 
 	private SharedPreferences mConnectionInfo;
+
 	private UglyDbHelper mDbHelper;
 
 	private boolean mReceiverRegistered;
 
+	private boolean mRestoredFromSaved = false;
+
 	private void assignViews() {
 		mHomeSwitchConnection = (Switch) mRootView.findViewById(R.id.home_switch_connection);
 		mHomeTextName = (TextView) mRootView.findViewById(R.id.home_text_name);
@@ -181,28 +194,28 @@ public class HomeFragment extends Fragment {
 			setStateActive(true);
 
 			switch (threatLevel) {
-			case NO_THREAT:
-				mHomeTextAttacks.setText(R.string.zero_attacks);
-				mHomeTextSecurity.setText(R.string.secure);
-				mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_dark_green));
-				mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_dark_green));
-				break;
-			case PAST_THREAT:
-				mHomeTextAttacks.setText(totalAttacks
-						+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
-						+ getResources().getString(R.string.recorded));
-				mHomeTextSecurity.setText(R.string.insecure);
-				mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_yellow));
-				mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_yellow));
-				break;
-			case LIVE_THREAT:
-				mHomeTextAttacks.setText(totalAttacks
-						+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
-						+ getResources().getString(R.string.recorded));
-				mHomeTextSecurity.setText(R.string.insecure);
-				mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_red));
-				mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_red));
-				break;
+				case NO_THREAT:
+					mHomeTextAttacks.setText(R.string.zero_attacks);
+					mHomeTextSecurity.setText(R.string.secure);
+					mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_dark_green));
+					mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_dark_green));
+					break;
+				case PAST_THREAT:
+					mHomeTextAttacks.setText(totalAttacks
+							+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
+							+ getResources().getString(R.string.recorded));
+					mHomeTextSecurity.setText(R.string.insecure);
+					mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_yellow));
+					mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_yellow));
+					break;
+				case LIVE_THREAT:
+					mHomeTextAttacks.setText(totalAttacks
+							+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
+							+ getResources().getString(R.string.recorded));
+					mHomeTextSecurity.setText(R.string.insecure);
+					mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_red));
+					mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_red));
+					break;
 			}
 
 			ThreatIndicatorGLRenderer.setThreatLevel(threatLevel);
@@ -218,6 +231,7 @@ public class HomeFragment extends Fragment {
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 		super.onCreateView(inflater, container, savedInstanceState);
+
 		setHasOptionsMenu(true);
 
 		final Activity activity = getActivity();
@@ -263,6 +277,7 @@ public class HomeFragment extends Fragment {
 		updateUI();
 
 		mHomeSwitchConnection = (Switch) mRootView.findViewById(R.id.home_switch_connection);
+		mHomeSwitchConnection.setSaveEnabled(false);
 
 		if (mSwitchChangeListener == null) {
 			mSwitchChangeListener = new CompoundButton.OnCheckedChangeListener() {
@@ -381,7 +396,7 @@ public class HomeFragment extends Fragment {
 
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
-		switch(item.getItemId()){
+		switch (item.getItemId()) {
 			case R.id.home_action_synchronize:
 				getActivity().startActivity(new Intent(this.getActivity(), BluetoothSync.class));
 				return true;
@@ -392,8 +407,8 @@ public class HomeFragment extends Fragment {
 
 	@Override
 	public void onStop() {
-		unregisterBroadcastReceiver();
 		super.onStop();
+		unregisterBroadcastReceiver();
 	}
 
 	@Override

+ 0 - 2
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -215,8 +215,6 @@ public class ServicesFragment extends Fragment {
 
     }
 
-    ;
-
     /**
      * called on start of this fragment.
      * registers broadcast receiver and binds change listener to main switch