Explorar o código

1.修改Android Apex Mobile KPI点击中心点后不响应Touch。
2.修改Android Apex Mobile KP显示时由于修改大小导致屏幕闪烁。

Pen Li %!s(int64=8) %!d(string=hai) anos
pai
achega
7b1f733921

+ 47 - 15
Apex Mobile/app/src/main/java/com/usai/apex/KPI/KPICell.java

@@ -47,8 +47,11 @@ public class KPICell extends RelativeLayout implements View.OnClickListener,KPIL
     private TextView mShipTV,mContainerTV,mTeuTV,mSelectionTV;
     private KPIListView mItemListView;
     private ValueAnimator mAnimation;
-    public void init() {
 
+    public void init(int w, int h) {
+
+        mWidth = w;
+        mHeight = h;
         mCell = this;
 
         mShipTV = findViewById(R.id.shipmentTV);
@@ -68,7 +71,6 @@ public class KPICell extends RelativeLayout implements View.OnClickListener,KPIL
 
         mChartView = findViewById(R.id.chart_view);
 
-
         if (mAnimation == null) {
             mAnimation = ValueAnimator.ofFloat(0f, 100f);
 
@@ -169,6 +171,28 @@ public class KPICell extends RelativeLayout implements View.OnClickListener,KPIL
 //        });
     }
 
+    private void resizePieChartView(int w) {
+
+        int leftInterval = dp2px(getContext(),60);
+        int rightInterval = dp2px(getContext(),60);
+
+        final int pieW = (w - leftInterval - rightInterval);
+
+
+        mChartView.post(new Runnable() {
+
+            @Override
+            public void run() {
+
+                LayoutParams layout = (LayoutParams)mChartView.getLayoutParams();
+                layout.width = (int)pieW;
+                layout.height = (int)pieW;
+                mChartView.setLayoutParams(layout);
+                mChartView.requestLayout();
+            }
+        });
+    }
+
     public void setMonthShipment(String shipment, int color) {
         mShipTV.setText("Shipment:" + shipment);
         mShipTV.setTextColor(color);
@@ -199,27 +223,35 @@ public class KPICell extends RelativeLayout implements View.OnClickListener,KPIL
 
         super.onSizeChanged(w, h, oldw, oldh);
 
-        int leftInterval = dp2px(getContext(),60);
-        int rightInterval = dp2px(getContext(),60);
+    }
 
-        final int pieW = (w - leftInterval - rightInterval);
+    private int mWidth = 0;
+    private int mHeight = 0;
 
+    public int getKPIWidth() {
+        return mWidth;
+    }
 
-        mChartView.post(new Runnable() {
+    public int getKPIHeight() {
+        return mHeight;
+    }
 
-            @Override
-            public void run() {
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
-                LayoutParams layout = (LayoutParams)mChartView.getLayoutParams();
-                layout.width = (int)pieW;
-                layout.height = (int)pieW;
-                mChartView.setLayoutParams(layout);
-                mChartView.requestLayout();
-            }
-        });
+        int w = getMeasuredWidth();
+        int h = getMeasuredHeight();
 
+        if (w != mWidth) {
+//            resizePieChartView(w);
+        }
+
+        mWidth = w;
+        mHeight = h;
     }
 
+
     float mTotal = 0;
     private ArrayList<PieChartView.ChartItem> preparePieChartItems() {
 

+ 30 - 10
Apex Mobile/app/src/main/java/com/usai/apex/KPI/PieChartView.java

@@ -16,6 +16,7 @@ import android.util.AttributeSet;
 import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewParent;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -460,17 +461,19 @@ public class PieChartView extends View {
         }
 
         // draw Pie
-        float r = radius();
-        if (item.select) {
-            r += detal * progress;
-        }
-        float x = (mWidth - r * 2) * 0.5f;
-        float y = (mHeight - r * 2) * 0.5f;
+        if (item.angle > 0) {
+            float r = radius();
+            if (item.select) {
+                r += detal * progress;
+            }
+            float x = (mWidth - r * 2) * 0.5f;
+            float y = (mHeight - r * 2) * 0.5f;
 
-        RectF rect = new RectF(x, y,x + 2 * r, y + 2 * r);
+            RectF rect = new RectF(x, y,x + 2 * r, y + 2 * r);
 
-        mBrush.setColor(item.getColor());
-        canvas.drawArc(rect,item.startAngle + 1,item.angle - 1,true,mBrush);
+            mBrush.setColor(item.getColor());
+            canvas.drawArc(rect,item.startAngle + 1,item.angle - 1,true,mBrush);
+        }
 
         if (minTitleAngle > item.angle) {
             return;
@@ -527,7 +530,7 @@ public class PieChartView extends View {
                 if (mPieChartItemClickListener != null) {
                     mPieChartItemClickListener.pieChartCenterClicked(this);
                 }
-                return super.onTouchEvent(event);
+                return true;
             }
 
             if (distance > radius()) {
@@ -651,4 +654,21 @@ public class PieChartView extends View {
 
         return new PointF(centerX + (float) Math.cos(rad) * r, centerY + (float) Math.sin(rad) * r);
     }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+
+        KPICell p = (KPICell) getParent();
+        int w = p.getKPIWidth();
+
+        int leftInterval = dp2px(getContext(),60);
+        int rightInterval = dp2px(getContext(),60);
+
+        int pieW = (w - leftInterval - rightInterval);
+
+        widthMeasureSpec = MeasureSpec.makeMeasureSpec(pieW, MeasureSpec.EXACTLY);
+        heightMeasureSpec = MeasureSpec.makeMeasureSpec(pieW, MeasureSpec.EXACTLY);
+
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
 }

+ 5 - 1
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/KPIFragment.java

@@ -106,12 +106,16 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
         super.onDestroyView();
     }
 
+    private int mWidth,mHeight;
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
         // Inflate the layout for this fragment
         View root = inflater.inflate(R.layout.fragment_kpi, container, false);
 
+        mWidth = container.getMeasuredWidth();
+        mHeight = container.getMeasuredHeight();
+
         mContext = getContext();
         self = this;
 
@@ -464,7 +468,7 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
             KPICell cell = null;
             if (mReusePool.isEmpty()) {
                 cell = (KPICell) LayoutInflater.from(mContext).inflate(R.layout.kpi_cell,null);
-                cell.init();
+                cell.init(mWidth,mHeight);
             } else {
                 cell = mReusePool.get(0);
                 mReusePool.remove(cell);

+ 7 - 0
Apex Mobile/app/src/main/res/layout/kpi_cell.xml

@@ -87,6 +87,13 @@
         <!--android:src="@drawable/next_item"-->
         <!--android:background="#00000000"-->
         <!--/>-->
+    <View
+        android:layout_width="match_parent"
+        android:layout_height=".5dp"
+        android:background="#aaaaaa"
+        android:layout_below="@id/chart_view"
+        android:layout_marginTop="2.5dp"
+        />
 
     <com.usai.apex.KPI.KPIListView
         android:id="@+id/item_list"