Просмотр исходного кода

statistics line & bar graph roation bug fixed, bug fix in abstract popup view

Julien Clauter 10 лет назад
Родитель
Сommit
6c2aeced36

+ 11 - 0
src/com/echo/holographlibrary/BarGraph.java

@@ -203,6 +203,16 @@ public class BarGraph extends View {
         this.popupImageID = id;
     }
 
+
+    @Override
+    protected void onLayout(boolean changed, int l, int t, int r, int b) {
+        super.onLayout(changed, l, t, r, b);
+        if(mFullImage != null)
+            mFullImage = null;
+        postInvalidate();
+    }
+
+
     @Override
     public boolean onTouchEvent(MotionEvent event) {
 
@@ -245,6 +255,7 @@ public class BarGraph extends View {
     		mFullImage.recycle();
     	
     	super.onDetachedFromWindow();
+        postInvalidate();
     }
     
     public void setOnBarClickedListener(OnBarClickedListener listener) {

+ 27 - 2
src/com/echo/holographlibrary/LineGraph.java

@@ -655,8 +655,33 @@ public class LineGraph extends View {
 
 	    return true;
 	}
-	
-	public void setOnPointClickedListener(OnPointClickedListener listener) {
+
+    @Override
+    protected void onDetachedFromWindow()
+    {
+        if(fullImage != null)
+            fullImage.recycle();
+
+        super.onDetachedFromWindow();
+        //postInvalidate();
+    }
+
+    @Override
+    protected void onSizeChanged (int w, int h, int oldw, int oldh){
+        super.onSizeChanged(w,h,oldw,oldh);
+        //postInvalidate();
+    }
+
+
+    @Override
+    protected void onLayout(boolean changed, int l, int t, int r, int b) {
+        super.onLayout(changed, l, t, r, b);
+        if(fullImage != null)
+            fullImage = null;
+        postInvalidate();
+    }
+
+    public void setOnPointClickedListener(OnPointClickedListener listener) {
 		this.listener = listener;
 	}
 	

+ 18 - 37
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -170,7 +170,6 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         if (this.filter == null){
             Intent intent = this.getActivity().getIntent();
             LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
-
             if(filter == null){
                 this.clearFilter();
             } else {
@@ -178,32 +177,18 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             }
         }
 
-        View rootView = inflater.inflate(this.getLayoutID(), container, false);
-
-        LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
-        plotLayout.setWillNotDraw(false);
-
-        container.setWillNotDraw(false);
-
-        this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
-        this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-            @Override
-            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
-                StatisticsFragment.this.userTappedOnLegendItem(i);
-            }
-        });
-        this.rootView = rootView;
-        rootView.setWillNotDraw(false);
+        this.rootView = inflater.inflate(this.getLayoutID(), container, false);
 
-        this.configureRootView(rootView);
+        this.configureRootView(this.rootView);
 
-        return rootView;
+        return this.rootView;
     }
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setHasOptionsMenu(true);
+        setRetainInstance(true);
     }
 
     @Override
@@ -213,24 +198,10 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
         ViewGroup container = (ViewGroup) this.getView();
         container.removeAllViewsInLayout();
-        View rootView = inflater.inflate(this.getLayoutID(), container, false);
-
-        container.addView(rootView);
+        this.rootView = inflater.inflate(this.getLayoutID(), container, false);
+        container.addView(this.rootView);
 
-        LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
-        plotLayout.setWillNotDraw(false);
-
-        this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
-        this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-            @Override
-            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
-                StatisticsFragment.this.userTappedOnLegendItem(i);
-            }
-        });
-        this.rootView = rootView;
-        rootView.setWillNotDraw(false);
-
-        this.configureRootView(rootView);
+        this.configureRootView(this.rootView);
     }
 
     private Context getBaseContext(){
@@ -244,9 +215,19 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     public void configureRootView(View rootView){
         LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
         plotLayout.setWillNotDraw(false);
-
         plotLayout.removeAllViews();
 
+        plotLayout.setWillNotDraw(false);
+
+        this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
+        this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+                StatisticsFragment.this.userTappedOnLegendItem(i);
+            }
+        });
+        rootView.setWillNotDraw(false);
+
         this.actualiseCurrentPlot();
 
         ImageButton visualButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);

+ 12 - 6
src/de/tudarmstadt/informatik/hostage/ui2/popup/AbstractPopup.java

@@ -3,7 +3,6 @@ package de.tudarmstadt.informatik.hostage.ui2.popup;
 import android.app.Activity;
 import android.content.Context;
 import android.graphics.Rect;
-import android.util.DisplayMetrics;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -13,13 +12,13 @@ import android.view.WindowManager;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
 
-import de.tudarmstadt.informatik.hostage.R;
-
 /**
  * Created by Julien on 13.02.14.
  */
 public abstract class AbstractPopup {
 
+    static final int ORIENTATION_LANDSCAPE = 2;
+
     public interface OnPopupItemClickListener {
         public void onItemClick(Object data);
     }
@@ -88,8 +87,12 @@ public abstract class AbstractPopup {
             this.popupWindow.setContentView(this.rootView);
 
             final Rect windowFrame= new Rect();
+
             Window window = this.context.getWindow();
             window.getDecorView().getWindowVisibleDisplayFrame(windowFrame);
+            int orientation = 1; //this.context.getResources().getConfiguration().orientation;
+            int windowWidth = orientation == ORIENTATION_LANDSCAPE ? windowFrame.height() : windowFrame.width();
+            int windowHeight = orientation == ORIENTATION_LANDSCAPE ? windowFrame.width() : windowFrame.height();
 
             final int[] position = new int[2];
             anchorView.getLocationOnScreen(position);
@@ -99,14 +102,17 @@ public abstract class AbstractPopup {
             int width = this.rootView.getMeasuredWidth();
             int height = this.rootView.getMeasuredHeight();
 
+            //int alh = (position[0] + width) - windowFrame.width();
+            //if (alh < 0) alh = 0;
+
             int x = position[0] + (anchorWidth / 2) - (width / 2);
             int y = position[1] - height;
 
-            x = Math.min(0,x);
-            x = Math.max(windowFrame.width() - width, x);
+            x = Math.max(0, x);
+            x = Math.min(windowWidth - width, x);
 
             y = Math.min(0,y);
-            y = Math.max(windowFrame.height() - height, y);
+            y = Math.max(windowHeight - height, y);
 
             AbstractPopup.this.configureView(this.rootView);