Browse Source

show a small dialog if no data were available

Julien Clauter 10 years ago
parent
commit
68efe0a173

+ 4 - 0
res/values-de/strings.xml

@@ -89,6 +89,10 @@
     <string name="yes">Ja</string>
     <string name="no">Nein</string>
 
+    <string name="no_data_notification">Es sind keine Attacken vorhanden. Überprüfen Sie gegebenenfalls Ihre Filtereinstellungen.</string>
+    <string name="no_data_notification_no_filter">Es sind keine Attacken vorhanden.</string>
+
+
     <string name="ui_dev_by">UI Entwicklung</string>
     <string name="core_dev_by">Core Entwicklung</string>
     <string name="advanced_settings">Erweiterte Einstellungen</string>

+ 5 - 1
res/values/strings.xml

@@ -89,7 +89,11 @@
     <string name="yes">Yes</string>
     <string name="no">No</string>
 
-	<string name="hostage_with_url"><a href="http://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage">HosTaGe</a></string>
+    <string name="no_data_notification">No Attacks are recorded. Please check your filter option.</string>
+    <string name="no_data_notification_no_filter">No Attacks are recorded.</string>
+
+
+    <string name="hostage_with_url"><a href="http://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage">HosTaGe</a></string>
     <string name="ui_dev_by">UI developed by</string>
     <string name="core_dev_by">Core developed by</string>
     <string name="advanced_settings">Advanced Settings</string>

+ 25 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -92,7 +92,9 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
     private ExpandableListView expListView;
     private ProgressBar spinner;
 
-	HostageDBOpenHelper dbh;
+    private Toast noDataNotificationToast;
+
+    HostageDBOpenHelper dbh;
 
     private String sectionToOpen = "";
     private ArrayList<Integer> openSections;
@@ -112,6 +114,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
     }
 
 
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -236,6 +239,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
                             registerListClickCallback(RecordOverviewFragment.this.expListView);
                             RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
                             RecordOverviewFragment.this.actualiseFilterButton();
+                            RecordOverviewFragment.this.showEmptyDataNotification();
                         }
                     });
                 }
@@ -560,6 +564,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
                                 adapter.notifyDataSetChanged();
                                 RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
                             }
+                            RecordOverviewFragment.this.showEmptyDataNotification();
                         }
                     });
                 }
@@ -568,6 +573,25 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
         loader.start();
     }
 
+    /**
+     * Shows a small toast if the data to show is empty (no records).
+     */
+    private void showEmptyDataNotification(){
+        if (RecordOverviewFragment.this.noDataNotificationToast == null){
+            RecordOverviewFragment.this.noDataNotificationToast =  Toast.makeText(getApplicationContext(), R.string.no_data_notification, Toast.LENGTH_SHORT);
+        }
+        RecordListAdapter adapter = (RecordListAdapter) RecordOverviewFragment.this.expListView.getExpandableListAdapter();
+
+        if (this.getFilterButton().getVisibility() == View.VISIBLE && this.filter.isSet()){
+            this.noDataNotificationToast.setText(R.string.no_data_notification);
+        } else {
+            this.noDataNotificationToast.setText(R.string.no_data_notification_no_filter);
+        }
+        if (adapter == null || adapter.getData().isEmpty())
+            RecordOverviewFragment.this.noDataNotificationToast.show();
+
+    }
+
     /**This will open a section in the ExpandableListView with the same title as the parameter s.
     *
     * @param String s (the section title to open)

+ 21 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -19,6 +19,7 @@ import android.widget.ListView;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.echo.holographlibrary.Bar;
 import com.echo.holographlibrary.BarGraph;
@@ -128,6 +129,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
     private ListView legendListView;
 
+    private Toast noDataNotificationToast;
+
 
     private String selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
 
@@ -1232,6 +1235,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                              StatisticsFragment.this.currentPlotView.invalidate();
 
                              StatisticsFragment.this.spinner.setVisibility(View.GONE);
+
+                             StatisticsFragment.this.showEmptyDataNotification();
                          }
                      });
                  }
@@ -1241,6 +1246,22 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         this.loader.start();
      }
 
+    /**
+     * Shows a small toast if the data to show is empty (no records).
+     */
+    private void showEmptyDataNotification(){
+        if (this.noDataNotificationToast == null){
+            this.noDataNotificationToast =  Toast.makeText(getApplicationContext(), R.string.no_data_notification, Toast.LENGTH_SHORT);
+        }
+        if (this.getFilterButton().getVisibility() == View.VISIBLE){
+            this.noDataNotificationToast.setText(R.string.no_data_notification);
+        } else {
+            this.noDataNotificationToast.setText(R.string.no_data_notification_no_filter);
+        }
+        if (this.currentData == null || this.currentData.isEmpty())
+            this.noDataNotificationToast.show();
+    }
+
     /** Calculates and returns the data for the piegraph
      * @return ArrayList<PlotComparisonItem> data */
     public ArrayList<PlotComparisonItem> getPieData(){

+ 42 - 3
src/de/tudarmstadt/informatik/hostage/ui2/popup/AbstractPopup.java

@@ -19,8 +19,12 @@ import de.tudarmstadt.informatik.hostage.R;
  */
 public abstract class AbstractPopup {
 
-    static final int ORIENTATION_LANDSCAPE = 2;
+    //static final int ORIENTATION_LANDSCAPE = 2;
 
+    /**
+     * OnPopupItemClickListener
+     * The listener will be called if the user selects a table row
+     */
     public interface OnPopupItemClickListener {
         public void onItemClick(Object data);
     }
@@ -32,9 +36,23 @@ public abstract class AbstractPopup {
     private LayoutInflater lInf;
 	private View lastItemView;
 
+    /**
+     * Override to return the layout id.
+     * @return int layoutID
+     */
     abstract public int getLayoutId();
+
+    /**
+     * Override to make additional stuff with the rootview.
+     * @param View rootview
+     */
     abstract void configureView(View view);
 
+    /**
+     * Constructor
+     * @param Context context
+     * @param OnPopupItemClickListener listener
+     */
     public AbstractPopup(Context context, OnPopupItemClickListener listener) {
         super();
         this.context = (Activity) context;
@@ -46,14 +64,26 @@ public abstract class AbstractPopup {
 
     }
 
+    /**
+     * Override to return a linear layout to add a scrollview.
+     * @return LinearLayout
+     */
     public abstract LinearLayout getScrollableItemLayout();
 
+    /**
+     * Returns the root view
+     * @return View the rootview
+     */
     public View getRootView(){
         return this.rootView;
     }
 
+    /**
+     * Adds a table row item.
+     * @param AbstractPopupItem item
+     */
     public void addItem(final AbstractPopupItem item)	{
-        View view = item.getItemView();
+        View view = item.getRootView();
 
         if (this.rootView == null){
             this.rootView = (LinearLayout) this.lInf.inflate(this.getLayoutId(), null);
@@ -83,6 +113,11 @@ public abstract class AbstractPopup {
 
     }
 
+    /**
+     * Returns the rootview.
+     * If the root view is null, it initialises it with the layout id.
+     * @return View the root view
+     */
     public View getPopupView(){
         if (this.rootView == null){
             this.rootView = (LinearLayout) this.lInf.inflate(this.getLayoutId(), null);
@@ -90,6 +125,10 @@ public abstract class AbstractPopup {
         return this.rootView;
     }
 
+    /**
+     * Opens the Popup View on top of the given anchor.
+     * @param View anchorView
+     */
     public void showOnView(final View anchorView)	{
         if (this.rootView == null){
             this.rootView = (LinearLayout) this.lInf.inflate(this.getLayoutId(), null);
@@ -103,7 +142,7 @@ public abstract class AbstractPopup {
 
             Window window = this.context.getWindow();
             window.getDecorView().getWindowVisibleDisplayFrame(windowFrame);
-            int orientation = this.context.getResources().getConfiguration().orientation;
+            //int orientation = this.context.getResources().getConfiguration().orientation;
             int windowWidth = windowFrame.width();
             int windowHeight = windowFrame.height();
 

+ 56 - 11
src/de/tudarmstadt/informatik/hostage/ui2/popup/AbstractPopupItem.java

@@ -14,70 +14,115 @@ public abstract class AbstractPopupItem {
     private int itemId;
     private String title;
 
-    private View itemView;
+    private View rootView;
 
     private LayoutInflater lInf;
 
     public HashMap<Object, Object> data;
 
-
+    /**
+     * Override to return the layout id.
+     * @return int layoutID
+     */
     abstract public int getLayoutId();
 
+    /**
+     * Override to do additional stuff with the rootview.
+     *
+     * @param View rootview
+     */
     abstract public void configureItemView(View view);
 
 
     public void setValue(String key, Object value){
         if (key != null && value != null){
             this.data.put(key, value);
-            if (this.itemView != null) this.configureItemView(this.itemView);
+            if (this.rootView != null) this.configureItemView(this.rootView);
         }
     }
+
+    /**
+     * Add other data to the item.
+     * @param HashMap<Object, Object> data
+     */
     public void setMultipleData(HashMap<Object, Object> map){
         if (map != null){
             for(Object key : map.keySet()){
                 this.data.put(key, map.get(key));
             }
-            if (this.itemView != null) this.configureItemView(this.itemView);
+            if (this.rootView != null) this.configureItemView(this.rootView);
         }
     }
 
     public void setTitle(String title){
         this.title = title;
-        if (this.itemView != null) this.configureItemView(this.itemView);
+        if (this.rootView != null) this.configureItemView(this.rootView);
     }
     public String getTitle(){
         return this.title;
     }
+
+    /**
+     * Set a specific item ID to identify it.
+     * @param int id
+     */
     public void setItemId(int id){
         this.itemId = id;
-        if (this.itemView != null) this.configureItemView(this.itemView);
+        if (this.rootView != null) this.configureItemView(this.rootView);
     }
+
+    /**
+     * Returns the item ID.
+     * @return int ID
+     */
     public int getItemId() {
         return this.itemId;
     }
 
+    /**
+     * Constructor
+     * @param Context context
+     */
     public AbstractPopupItem(Context context) {
         super();
         this.lInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         this.data = new HashMap<Object, Object>();
     }
 
-    public View getItemView(){
-        if (this.itemView == null){
-            this.itemView = this.lInf.inflate(this.getLayoutId(), null);
+    /**
+     * Returns the rootview.
+     * This method calls everytime the ConfigureItemView methode.
+     * @return View rootview
+     */
+    public View getRootView(){
+        if (this.rootView == null){
+            this.rootView = this.lInf.inflate(this.getLayoutId(), null);
         }
-        this.configureItemView(this.itemView);
+        this.configureItemView(this.rootView);
 
-        return this.itemView;
+        return this.rootView;
     }
 
+    /**
+     * The method is called if the user clicks the rootview.
+     * @param  MotionEvent event
+     * @return Object object
+     */
     public Object onClickedResult(MotionEvent event){
         return this;
     }
 
+    /**
+     * Will be called if the user selected the view.
+     * @param MotionEvent event
+     */
 	public void onItemSelect(MotionEvent event){
 	}
 
+    /**
+     * Will be called if the user deselects the view.
+     * @param MotionEvent event
+     */
 	public void onItemDeselect(MotionEvent event){
 
 	}

+ 2 - 2
src/de/tudarmstadt/informatik/hostage/ui2/popup/SimplePopupItem.java

@@ -41,12 +41,12 @@ public class SimplePopupItem extends AbstractPopupItem {
 
     public void setSelected(boolean selected){
         this.selected = selected;
-        if (this.getItemView() != null) this.configureItemView(this.getItemView());
+        if (this.getRootView() != null) this.configureItemView(this.getRootView());
     }
 
 	private View getContainer(){
 		if(container == null){
-			container = this.getItemView().findViewById(R.id.popup_item_container);
+			container = this.getRootView().findViewById(R.id.popup_item_container);
 		}
 
 		return container;

+ 20 - 4
src/de/tudarmstadt/informatik/hostage/ui2/popup/SplitPopupItem.java

@@ -23,6 +23,11 @@ public class SplitPopupItem extends AbstractPopupItem {
 	private View left_container;
 	private View right_container;
 
+    /**
+     * Constructor
+     *
+     * @param Context context
+     */
     public SplitPopupItem(Context context){
         super(context);
 
@@ -64,22 +69,33 @@ public class SplitPopupItem extends AbstractPopupItem {
         return this;
     }
 
+    /**
+     * Returns true if the user touched the right side of the view.
+     * @return boolean isRightTouch
+     */
 	private boolean isRightTouch(MotionEvent event){
-		return event.getX() > this.getItemView().getX() + (this.getItemView().getWidth() / 2);
+		return event.getX() > this.getRootView().getX() + (this.getRootView().getWidth() / 2);
 	}
 
+    /**
+     * Returns the left view.
+     * @return View the left view
+     */
 	private View getLeftContainer(){
 		if(left_container == null){
-			left_container = this.getItemView().findViewById(R.id.popup_left_container);
+			left_container = this.getRootView().findViewById(R.id.popup_left_container);
 		}
 
 		return left_container;
 	}
 
-
+    /**
+     * Returns the right view.
+     * @return View the right view
+     */
 	private View getRightContainer(){
 		if(right_container == null){
-			right_container = this.getItemView().findViewById(R.id.popup_right_container);
+			right_container = this.getRootView().findViewById(R.id.popup_right_container);
 		}
 
 		return right_container;