Browse Source

did some java doc

Alexander Brakowski 10 years ago
parent
commit
7121208411

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

@@ -14,19 +14,38 @@ import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.ui2.model.DrawerListItem;
 
 /**
+ * Creates the item view for the navigation drawer listview
+ *
  * @author Alexander Brakowski
  * @created 13.01.14 16:35
  */
 public class DrawerListAdapter extends ArrayAdapter<DrawerListItem> {
+
+	/**
+	 * The context the adapter needs to retrieve resources
+	 */
     private final Context mContext;
+
+	/**
+	 * The list items
+	 */
     private final List<DrawerListItem> mValues;
 
+	/**
+	 * Create the list adapter
+	 *
+	 * @param context the context needed for resource retieval
+	 * @param objects all the items that should be displayed in the list
+	 */
     public DrawerListAdapter(Context context, List<DrawerListItem> objects) {
         super(context, R.layout.drawer_list_item, objects);
         this.mContext = context;
         this.mValues  = objects;
     }
 
+	/**
+	 * {@inheritDoc}
+	 */
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
         LayoutInflater inflater = (LayoutInflater) mContext

+ 87 - 50
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -28,43 +28,71 @@ import de.tudarmstadt.informatik.hostage.ui2.layouts.FlowLayout;
 import de.tudarmstadt.informatik.hostage.ui2.swipelist.SwipeListView;
 
 /**
+ * This adapter creates the item views for the profile manager by making use the viewholder pattern
+ *
  * @author Alexander Brakowski
  * @created 14.01.14 18:00
  */
 public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
+
+	/**
+	 * Holds our views, to reduce the number of view lookups immensly
+	 */
 	private class ViewHolder {
-		public TextView labelView;
-		public TextView textView;
-		public ImageView imageSelected;
-		public ImageView itemIcon;
-		public ImageButton buttonEdit;
-		public ImageButton buttonDelete;
-		public View seperator;
-		public FlowLayout badgesContainer;
+		public TextView mLabelView;
+		public TextView mTextView;
+		public ImageView mImageSelected;
+		public ImageView mItemIcon;
+		public ImageButton mButtonEdit;
+		public ImageButton mButtonDelete;
+		public View mSeperator;
+		public FlowLayout mBadgesContainer;
 	}
 
-    private final Context context;
-    private final List<Profile> values;
-	private SwipeListView list;
-
+	/**
+	 * The context nedded for resource lookups
+	 */
+    private final Context mContext;
+
+	/**
+	 * The profiles to display in the list
+	 */
+    private final List<Profile> mValues;
+
+	/**
+	 * A reference to the list view itself
+	 */
+	private SwipeListView mList;
+
+	/**
+	 * A simple constructor to propagate this object with neccessary references to needed objects
+	 *
+	 * @param context needed for resource lookups
+	 * @param objects the profiles to display
+	 * @param list a reference to the list view
+	 */
     public ProfileManagerListAdapter(Context context, List<Profile> objects, SwipeListView list) {
         super(context, R.layout.profile_manager_list_item, objects);
-        this.context = context;
-        this.values  = objects;
-	    this.list    = list;
+        this.mContext = context;
+        this.mValues = objects;
+	    this.mList = list;
     }
 
 
+	/**
+	 * {@inheritDoc}
+	 */
     @Override
     public View getView(final int position, View convertView, ViewGroup parent) {
-	    LayoutInflater inflater = (LayoutInflater) context
+	    LayoutInflater inflater = (LayoutInflater) mContext
 			    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
         View rowView = convertView;
 	    ViewHolder holder = null;
 
-	    final Profile item = values.get(position);
+	    final Profile item = mValues.get(position);
 
+	    // if the current item has the show tooltip flag set, render this item as an tooltip view
 	    if(item.mShowTooltip){
 		    rowView = inflater.inflate(R.layout.profile_manager_list_item_help, parent, false);
 		    rowView.findViewById(R.id.profile_manager_help_dismiss).setOnClickListener(new View.OnClickListener() {
@@ -72,59 +100,66 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 			    public void onClick(View v) {
 				    ProfileManagerListAdapter.this.remove(item);
 				    ProfileManagerListAdapter.this.notifyDataSetChanged();
-				    list.dismiss(position);
+				    mList.dismiss(position);
 
+				    // just show the tooltip as long as it was not dismissed
 				    MainActivity.getContext().getSharedPreferences(
 						    MainActivity.getContext().getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE
 				    ).edit().putBoolean("dismissedProfileSwipeHelp", true).commit();
 			    }
 		    });
 	    } else {
+		    // put our views into an view holder, if it is new
 		    if (rowView == null || rowView.getTag() == null) {
 			    rowView = inflater.inflate(R.layout.profile_manager_list_item, parent, false);
 
 			    holder = new ViewHolder();
-			    holder.labelView = (TextView) rowView.findViewById(R.id.profile_manager_item_label);
-			    holder.textView = (TextView) rowView.findViewById(R.id.profile_manager_item_text);
-			    holder.imageSelected = (ImageView) rowView.findViewById(R.id.profile_manager_item_activated);
-			    holder.itemIcon = (ImageView) rowView.findViewById(R.id.profile_manager_item_image);
-			    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);
+			    holder.mLabelView = (TextView) rowView.findViewById(R.id.profile_manager_item_label);
+			    holder.mTextView = (TextView) rowView.findViewById(R.id.profile_manager_item_text);
+			    holder.mImageSelected = (ImageView) rowView.findViewById(R.id.profile_manager_item_activated);
+			    holder.mItemIcon = (ImageView) rowView.findViewById(R.id.profile_manager_item_image);
+			    holder.mButtonEdit = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_edit);
+			    holder.mButtonDelete = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_delete);
+			    holder.mSeperator = rowView.findViewById(R.id.profile_manager_item_seperator);
+			    holder.mBadgesContainer = (FlowLayout) rowView.findViewById(R.id.badges_container);
 
 			    rowView.setTag(holder);
 		    } else {
+			    // save the viewholder to the tag of the view, so we can reuse it later
 			    holder = (ViewHolder) rowView.getTag();
 		    }
 
+		    // swipe listview needs some cleanup
 		    ((SwipeListView) parent).recycle(rowView, position);
 
-		    holder.textView.setText(item.mText);
-		    holder.labelView.setText(item.mLabel);
+		    // fill the item view with the correct data
+		    holder.mTextView.setText(item.mText);
+		    holder.mLabelView.setText(item.mLabel);
 
 		    if (item.getIconBitmap() != null) {
 			    //Bitmap bitmap = Bitmap.createScaledBitmap(item.getIconBitmap(), 32, 32, true);
-			    holder.itemIcon.setImageBitmap(item.getIconBitmap());
+			    holder.mItemIcon.setImageBitmap(item.getIconBitmap());
 		    } else {
-			    holder.itemIcon.setImageBitmap(BitmapFactory.decodeResource(MainActivity.context.getResources(), R.drawable.ic_launcher));
+			    holder.mItemIcon.setImageBitmap(BitmapFactory.decodeResource(MainActivity.context.getResources(), R.drawable.ic_launcher));
 		    }
 
-		    holder.buttonEdit.setOnClickListener(new View.OnClickListener() {
+		    // open the profile edit activity, if the edit button was pressed
+		    holder.mButtonEdit.setOnClickListener(new View.OnClickListener() {
 			    @Override
 			    public void onClick(View v) {
-				    Intent intent = new Intent(context, ProfileEditActivity.class);
+				    Intent intent = new Intent(mContext, ProfileEditActivity.class);
 				    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 				    intent.putExtra("profile_id", item.mId);
-				    //intent.putExtra("profile", item);
-				    context.startActivity(intent);
+
+				    mContext.startActivity(intent);
 			    }
 		    });
 
-		    holder.buttonDelete.setOnClickListener(new View.OnClickListener() {
+		    // delete the profile, if the delete button was pressed. But shows an confirm dialog first.
+		    holder.mButtonDelete.setOnClickListener(new View.OnClickListener() {
 			    @Override
 			    public void onClick(View v) {
-				    new AlertDialog.Builder(context)
+				    new AlertDialog.Builder(mContext)
 						    .setTitle(R.string.delete_profile)
 						    .setMessage(R.string.really_want_delete_profiel)
 						    .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@@ -139,7 +174,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 
 								    profileManager.deleteProfile(item);
 								    profileManager.getProfileListAdapter().notifyDataSetChanged();
-								    list.closeOpenedItems();
+								    mList.closeOpenedItems();
 							    }
 						    })
 						    .setIcon(android.R.drawable.ic_dialog_alert)
@@ -147,7 +182,8 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 			    }
 		    });
 
-		    holder.badgesContainer.removeAllViews();
+		    // show all the active protocols of an profile in form of badges at the bottom of an profile list item
+		    holder.mBadgesContainer.removeAllViews();
 		    boolean hasProtocols = false;
 
 		    List<String> profiles = new LinkedList<String>(item.getActiveProtocols());
@@ -158,35 +194,36 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 
 		    for (String protocol : profiles) {
 			    hasProtocols = true;
-			    TextView textView = new TextView(new ContextThemeWrapper(context, R.style.ProfileManagerListBadge));
+			    TextView textView = new TextView(new ContextThemeWrapper(mContext, R.style.ProfileManagerListBadge));
 			    textView.setText(protocol);
-			    holder.badgesContainer.addView(textView);
+			    holder.mBadgesContainer.addView(textView);
 		    }
 
 		    if (!hasProtocols) {
-			    holder.badgesContainer.setVisibility(View.INVISIBLE);
+			    holder.mBadgesContainer.setVisibility(View.INVISIBLE);
 		    } else {
-			    holder.badgesContainer.setVisibility(View.VISIBLE);
+			    holder.mBadgesContainer.setVisibility(View.VISIBLE);
 		    }
 
-		    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.textView.getLayoutParams();
+		    // do some styling when an profile is flagged as active
+		    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.mTextView.getLayoutParams();
 
 		    if (!item.mActivated) {
 			    lp.setMargins(0, 0, 0, 0);
 
-			    holder.textView.setLayoutParams(lp);
+			    holder.mTextView.setLayoutParams(lp);
 
-			    holder.imageSelected.setVisibility(View.GONE);
+			    holder.mImageSelected.setVisibility(View.GONE);
 		    } else {
-			    holder.imageSelected.setVisibility(View.VISIBLE);
+			    holder.mImageSelected.setVisibility(View.VISIBLE);
 		    }
 
 		    if (!item.isEditable()) {
-			    holder.buttonDelete.setVisibility(View.GONE);
-			    holder.seperator.setVisibility(View.GONE);
+			    holder.mButtonDelete.setVisibility(View.GONE);
+			    holder.mSeperator.setVisibility(View.GONE);
 		    } else {
-			    holder.buttonDelete.setVisibility(View.VISIBLE);
-			    holder.seperator.setVisibility(View.VISIBLE);
+			    holder.mButtonDelete.setVisibility(View.VISIBLE);
+			    holder.mSeperator.setVisibility(View.VISIBLE);
 		    }
 
 	    }

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

@@ -103,6 +103,9 @@ public class HomeFragment extends Fragment {
 	 */
 	private boolean isConnected = false;
 
+	public HomeFragment() {
+	}
+
 	/**
 	 * Looks up all the neccessary views in the layout
 	 */
@@ -137,9 +140,6 @@ public class HomeFragment extends Fragment {
 		}
 	}
 
-	public HomeFragment() {
-	}
-
 	/**
 	 * Sets the view state to not active.
 	 * This means hiding and graying out all the informations in the view, that are not important, if the service is not active.

+ 16 - 1
src/de/tudarmstadt/informatik/hostage/ui2/swipelist/SwipeListView.java

@@ -4,30 +4,45 @@ import android.content.Context;
 import android.util.AttributeSet;
 
 /**
+ * Extends the SwipeListView with an mechanism to allow to open only one item at the same time.
+ *
  * @author Alexander Brakowski
  * @created 28.02.14 22:05
  */
 public class SwipeListView extends com.fortysevendeg.android.swipelistview.SwipeListView {
 
-
+	/**
+	 * {@inheritDoc}
+	 */
 	public SwipeListView(Context context, int swipeBackView, int swipeFrontView) {
 		super(context, swipeBackView, swipeFrontView);
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public SwipeListView(Context context, AttributeSet attrs) {
 		super(context, attrs);
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public SwipeListView(Context context, AttributeSet attrs, int defStyle) {
 		super(context, attrs, defStyle);
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
 	protected void onOpened(int position, boolean toRight) {
 		super.onOpened(position, toRight);
 
 		int start = getFirstVisiblePosition();
 		int end = getLastVisiblePosition();
 
+		// close all visible items other then the current one
 		for(int i=start; i<=end; i++){
 			if(i != position){
 				closeAnimate(i);