Browse Source

fixed bugs in abstract popup
new time selection in records over view

Julien Clauter 10 years ago
parent
commit
39d132e033

+ 81 - 0
res/layout/split_popup_item.xml

@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="horizontal"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="top|center"
+    android:weightSum="1">
+
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:orientation="vertical"
+        android:layout_width="wrap_content"
+        android:layout_height="85dp"
+        android:layout_weight="0.5"
+        android:padding="2dp">
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="@color/dark_grey"
+        android:padding="2dp">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:text="Title"
+            android:id="@+id/left_title_text_view"
+            android:textColor="#ffffff"
+            android:layout_alignParentStart="true"
+            android:textAlignment="textStart"
+            android:textStyle="bold" />
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:text="Subtitle"
+            android:id="@+id/left_subtitle_text_view"
+            android:textColor="#ffffff"
+            android:layout_alignParentStart="true"
+            android:textAlignment="center"
+            android:textIsSelectable="false" />
+    </LinearLayout>
+    </LinearLayout>
+
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:orientation="vertical"
+        android:layout_width="wrap_content"
+        android:layout_height="85dp"
+        android:layout_weight="0.5"
+        android:padding="2dp">
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="@color/dark_grey"
+        android:padding="2dp">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:text="Title"
+            android:id="@+id/right_title_text_view"
+            android:textColor="#ffffff"
+            android:layout_alignParentStart="true"
+            android:textAlignment="textStart"
+            android:textStyle="bold" />
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:text="Subtitle"
+            android:id="@+id/right_subtitle_text_view"
+            android:textColor="#ffffff"
+            android:layout_alignParentStart="true"
+            android:textAlignment="center"
+            />
+    </LinearLayout>
+    </LinearLayout>
+</LinearLayout>

+ 62 - 31
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -41,6 +41,7 @@ import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
+import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
 
 public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
 	static final String SELECTED_KEY = "Selected";
@@ -49,11 +50,12 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	static final String FILTER_MENU_TITLE_BSSID = "BSSID";
 	static final String FILTER_MENU_TITLE_ESSID = "ESSID";
 	static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocol";
-	static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "Latest Time";
-	static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "Earliest Time";
+	static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "Latest";
+	static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "Earliest";
 	static final String FILTER_MENU_TITLE_SORTING = "Sort by";
 	static final String FILTER_MENU_TITLE_REMOVE = "Reset Filter";
     static final String FILTER_MENU_TITLE_GROUP = "Group by";
+    static final String FILTER_MENU_POPUP_TITLE = "Filter by";
 
     private boolean wasBelowTimePicker;
 
@@ -140,30 +142,42 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	}
 
 	public void onFilterMenuItemSelected(AbstractPopupItem item) {
-		String title = item.getTitle().toString();
+		String title = item.getTitle();
 
-		if(title.equals(FILTER_MENU_TITLE_BSSID)){
-			this.openBSSIDFilterDialog();
-		}
-		if(title.equals(FILTER_MENU_TITLE_ESSID)){
-			this.openESSIDFilterDialog();
-		}
-		if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
-			this.openProtocolsFilterDialog();
-		}
-		if(title.equals(FILTER_MENU_TITLE_SORTING)){
-			this.openSortingDialog();
-		}
-		if(title.equals(FILTER_MENU_TITLE_REMOVE)){
-			this.clearFilter();
-            this.populateListViewFromDB(this.expListView);
-		}
-		if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
-			this.openTimestampToFilterDialog();
-		}
-		if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
-			this.openTimestampFromFilterDialog();
-		}
+        if (item instanceof SplitPopupItem){
+            SplitPopupItem splitItem = (SplitPopupItem)item;
+            if (splitItem.wasRightTouch){
+                this.openTimestampToFilterDialog();
+            } else {
+                this.openTimestampFromFilterDialog();
+            }
+            return;
+        }
+
+        if (title != null){
+            if(title.equals(FILTER_MENU_TITLE_BSSID)){
+                this.openBSSIDFilterDialog();
+            }
+            if(title.equals(FILTER_MENU_TITLE_ESSID)){
+                this.openESSIDFilterDialog();
+            }
+            if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
+                this.openProtocolsFilterDialog();
+            }
+            if(title.equals(FILTER_MENU_TITLE_SORTING)){
+                this.openSortingDialog();
+            }
+            if(title.equals(FILTER_MENU_TITLE_REMOVE)){
+                this.clearFilter();
+                this.populateListViewFromDB(this.expListView);
+            }
+            if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
+                this.openTimestampToFilterDialog();
+            }
+            if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
+                this.openTimestampFromFilterDialog();
+            }
+        }
 		//return super.onOptionsItemSelected(item);
 	}
 
@@ -397,15 +411,32 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	private void openFilterPopupMenuOnView(View v){
 
         SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
-            public void onItemClick(AbstractPopupItem item) {
-                RecordOverviewFragment.this.onFilterMenuItemSelected(item);
+            public void onItemClick(Object ob) {
+                if (ob instanceof  AbstractPopupItem){
+                    AbstractPopupItem item = (AbstractPopupItem) ob;
+                    RecordOverviewFragment.this.onFilterMenuItemSelected(item);
+                }
             }
         });
-        filterMenu.setTitle("Filter by");
+        filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
 		for(String title : RecordOverviewFragment.this.filterMenuTitles()){
-            SimplePopupItem item = new SimplePopupItem(this.getActivity());
-            item.setTitle(title);
-            item.setSelected(this.isFilterSetForTitle(title));
+            AbstractPopupItem item = null;
+            if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
+            if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
+                item = new SplitPopupItem(this.getActivity());
+                item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
+                item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
+                if (this.filter.hasBelowTimestamp()){
+                    item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
+                }
+                if (this.filter.hasAboveTimestamp()){
+                    item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
+                }
+            } else {
+                item = new SimplePopupItem(this.getActivity());
+                item.setTitle(title);
+                ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
+            }
 
             filterMenu.addItem(item);
 		}

+ 77 - 27
src/de/tudarmstadt/informatik/hostage/ui2/popup/AbstractPopup.java

@@ -5,6 +5,7 @@ import android.content.Context;
 import android.graphics.Rect;
 import android.view.Gravity;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
@@ -17,7 +18,7 @@ import android.widget.PopupWindow;
 public abstract class AbstractPopup {
 
     public interface OnPopupItemClickListener {
-        public void onItemClick(AbstractPopupItem item);
+        public void onItemClick(Object data);
     }
 
     private PopupWindow popupWindow;
@@ -44,16 +45,19 @@ public abstract class AbstractPopup {
         View view = item.getItemView();
 
         if (this.rootView == null){
-            this.rootView = (LinearLayout) lInf.inflate(this.getLayoutId(), null);
+            this.rootView = (LinearLayout) this.lInf.inflate(this.getLayoutId(), null);
             this.configureView(this.rootView);
         }
         if (this.rootView != null){
             this.rootView.addView(view);
-            view.setOnClickListener(new View.OnClickListener() {
+            view.setOnTouchListener(new View.OnTouchListener() {
                 @Override
-                public void onClick(View view) {
-                    onPopupItemClickListener.onItemClick(item);
-                    popupWindow.dismiss();
+                public boolean onTouch(View view, MotionEvent event) {
+                    if (event.getAction() == MotionEvent.ACTION_UP){
+                        AbstractPopup.this.onPopupItemClickListener.onItemClick(item.onClickedResult(event));
+                        AbstractPopup.this.popupWindow.dismiss();
+                    }
+                    return true;
                 }
             });
         }
@@ -61,43 +65,89 @@ public abstract class AbstractPopup {
     }
 
     public View getPopupView(){
-        return rootView;
+        if (this.rootView == null){
+            this.rootView = (LinearLayout) this.lInf.inflate(this.getLayoutId(), null);
+        }
+        return this.rootView;
     }
 
-    public void showOnView(View view)	{
+    public void showOnView(final View anchorView)	{
         if (this.rootView == null){
-            this.rootView = (LinearLayout) lInf.inflate(this.getLayoutId(), null);
+            this.rootView = (LinearLayout) this.lInf.inflate(this.getLayoutId(), null);
         }
+        if (this.rootView != null){
+            AbstractPopup.this.popupWindow.dismiss();
+
+            this.popupWindow.setContentView(this.rootView);
+
+            final Rect windowFrame= new Rect();
+            Window window = this.context.getWindow();
+            window.getDecorView().getWindowVisibleDisplayFrame(windowFrame);
+
+            final int[] position = new int[2];
+            anchorView.getLocationOnScreen(position);
+            final int anchorWidth = anchorView.getWidth();
+
+            this.rootView.measure(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
+            int width = this.rootView.getMeasuredWidth();
+            int height = this.rootView.getMeasuredHeight();
 
+            int x = position[0] + (anchorWidth / 2) - (width / 2);
+            int y = position[1] - height;
 
-        popupWindow.setContentView(rootView);
+            x = Math.min(0,x);
+            x = Math.max(windowFrame.width() - width, x);
 
-        Rect rectagle= new Rect();
-        Window window= this.context.getWindow();
-        window.getDecorView().getWindowVisibleDisplayFrame(rectagle);
+            y = Math.min(0,y);
+            y = Math.max(windowFrame.height() - height, y);
 
-        int[] position = new int[2];
-        view.getLocationOnScreen(position);
+            AbstractPopup.this.configureView(this.rootView);
 
-        rootView.measure(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
+            int smallBottomOffset = 10;
+            this.popupWindow.setWidth(width);
+            this.popupWindow.setHeight(height + smallBottomOffset);
+            this.popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, x, y-smallBottomOffset);
 
-        int x = position[0] + (view.getWidth() / 2) - (rootView.getMeasuredWidth() / 2);
-        int y = position[1] - rootView.getMeasuredHeight();
 
-        x = Math.min(0,x);
-        x = Math.max(rectagle.width()-rootView.getMeasuredWidth(), x);
 
-        y = Math.min(0,y);
-        y = Math.max(rectagle.height()-rootView.getMeasuredHeight(), y);
+            /*
+            // TO SET THE REAL SIZE
+            ViewTreeObserver viewTreeObserver = this.rootView.getViewTreeObserver();
+            if (viewTreeObserver != null &&  viewTreeObserver.isAlive()) {
+                viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+                    @Override
+                    public void onGlobalLayout() {
+                        ViewTreeObserver observer= AbstractPopup.this.rootView.getViewTreeObserver();
+                        if (observer != null)observer.removeOnGlobalLayoutListener(this);
 
-        this.configureView(rootView);
+                        View rootView = AbstractPopup.this.rootView;
 
-        int smallBottomOffset = 10;
+                        int width = rootView.getWidth();
+                        int height = rootView.getHeight();
 
-        popupWindow.setWidth(rootView.getMeasuredWidth());
-        popupWindow.setHeight(rootView.getMeasuredHeight() + smallBottomOffset);
+                        int x = position[0] + (anchorWidth / 2) - (width / 2);
+                        int y = position[1] - height;
 
-        popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, x, y);
+                        x = Math.min(0,x);
+                        x = Math.max(windowFrame.width() - width, x);
+
+                        y = Math.min(0,y);
+                        y = Math.max(windowFrame.height() - height, y);
+
+                        AbstractPopup.this.configureView(rootView);
+
+                        int smallBottomOffset = 10;
+                        AbstractPopup.this.popupWindow.dismiss();
+                        AbstractPopup.this.popupWindow.setWidth(width);
+                        AbstractPopup.this.popupWindow.setHeight(height + smallBottomOffset);
+                        AbstractPopup.this.popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, x, y-smallBottomOffset);
+
+                    }
+                });
+            }
+            */
+        }
     }
 
+
 }

+ 6 - 3
src/de/tudarmstadt/informatik/hostage/ui2/popup/AbstractPopupItem.java

@@ -2,6 +2,7 @@ package de.tudarmstadt.informatik.hostage.ui2.popup;
 
 import android.content.Context;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
 
 import java.util.HashMap;
@@ -57,20 +58,22 @@ public abstract class AbstractPopupItem {
 
     public AbstractPopupItem(Context context) {
         super();
-        lInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        this.lInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         this.data = new HashMap<Object, Object>();
     }
 
     public View getItemView(){
         if (this.itemView == null){
-            this.itemView = lInf.inflate(this.getLayoutId(), null);
+            this.itemView = this.lInf.inflate(this.getLayoutId(), null);
         }
         this.configureItemView(this.itemView);
 
         return this.itemView;
     }
 
-
+    public Object onClickedResult(MotionEvent event){
+        return this;
+    }
 
 
 }

+ 61 - 0
src/de/tudarmstadt/informatik/hostage/ui2/popup/SplitPopupItem.java

@@ -0,0 +1,61 @@
+package de.tudarmstadt.informatik.hostage.ui2.popup;
+
+import android.content.Context;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.TextView;
+
+import de.tudarmstadt.informatik.hostage.R;
+
+/**
+ * Created by Julien on 16.02.14.
+ */
+public class SplitPopupItem extends AbstractPopupItem {
+
+    public final static String LEFT_TITLE = "LEFT_TITLE";
+    public final static String RIGHT_TITLE = "RIGHT_TITLE";
+    public final static String LEFT_SUBTITLE = "LEFT_SUBTITLE";
+    public final static String RIGHT_SUBTITLE = "RIGHT_SUBTITLE";
+
+    public boolean wasRightTouch;
+
+    public SplitPopupItem(Context context){
+        super(context);
+    }
+
+    public int getLayoutId(){
+        return R.layout.split_popup_item;
+    }
+
+    public void configureItemView(View view){
+        String leftTitle = (String) this.data.get(LEFT_TITLE);
+        String rightTitle = (String) this.data.get(RIGHT_TITLE);
+
+        String leftSubtitle = (String) this.data.get(LEFT_SUBTITLE);
+        String rightSubtitle = (String) this.data.get(RIGHT_SUBTITLE);
+
+        TextView leftTitleView = (TextView)view.findViewById(R.id.left_title_text_view);
+        leftTitleView.setText(leftTitle);
+        TextView leftSubtitleView = (TextView)view.findViewById(R.id.left_subtitle_text_view);
+        if (leftSubtitle != null){
+            leftSubtitleView.setText(leftSubtitle);
+        } else {
+            leftSubtitleView.setText("-");
+        }
+
+        TextView rightTitleView = (TextView)view.findViewById(R.id.right_title_text_view);
+        rightTitleView.setText(rightTitle);
+        TextView rightSubtilteView = (TextView)view.findViewById(R.id.right_subtitle_text_view);
+        if (rightSubtitle != null){
+            rightSubtilteView.setText(rightSubtitle);
+        } else {
+            rightSubtilteView.setText("-");
+        }
+    }
+
+    public Object onClickedResult(MotionEvent event){
+        this.wasRightTouch = event.getX() > this.getItemView().getX() + (this.getItemView().getWidth() / 2);
+        return this;
+    }
+
+}