Pārlūkot izejas kodu

1.修改Android Apex Mobile KPI在从Search返回后手势识别不正确,以及数据为空。

Pen Li 8 gadi atpakaļ
vecāks
revīzija
9ba3e15989

+ 16 - 0
Apex Mobile/app/src/main/java/com/usai/apex/KPI/KPISwipeRefresh.java

@@ -34,4 +34,20 @@ public class KPISwipeRefresh extends SwipeRefreshLayout {
 
         return super.onInterceptTouchEvent(ev);
     }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+
+        Log.d("Refresh OnTouch", "onInterceptTouchEvent: " + ev.getY() + "and Action: " + ev.getAction());
+        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+            mFirstPointY = ev.getY();
+        }
+
+        // 防止下拉和ListView向上滑动冲突
+        if (mFirstPointY > 100) {
+            return false;
+        }
+
+        return super.onTouchEvent(ev);
+    }
 }

+ 28 - 27
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/HomeFragment.java

@@ -134,6 +134,8 @@ public class HomeFragment extends Fragment {
             fragment = fm.findFragmentByTag(tag);
             if(fragment==null)
                 fragment = recentFragment;
+            else
+                recentFragment = (RecentFragment) fragment;
 
         }
         else
@@ -142,9 +144,17 @@ public class HomeFragment extends Fragment {
             fragment = fm.findFragmentByTag(tag);
             if(fragment==null)
                 fragment = kpiFragment;
+            else
+                kpiFragment = (KPIFragment) fragment;
         }
         activeFragment = fragment;
 
+        if (activeFragment instanceof KPIFragment) {
+            kpiFragment.showTitle(getActivity(),true);
+        } else {
+            kpiFragment.showTitle(getActivity(),false);
+        }
+
         if (!fragment.isAdded()) {
             ft.add(R.id.container, fragment, tag);
         } else {
@@ -170,44 +180,35 @@ public class HomeFragment extends Fragment {
     @Override
     public void setUserVisibleHint(boolean isVisibleToUser) {
         super.setUserVisibleHint(isVisibleToUser);
-        if (isVisibleToUser) {
-            if (mode == 1) {
-                showTitlebar(true);
-            } else {
-                showTitlebar(false);
-            }
+        // 初始化的时候为null
+        if (getActivity() == null) {
+            return;
+        }
+        // 切换到History,再切回来
+        if (isVisibleToUser && activeFragment != null && activeFragment instanceof KPIFragment) {
+            ((KPIFragment) activeFragment).showTitle(getActivity(),true);
         } else {
-            showTitlebar(false);
+            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
+            ((Activity)getActivity()).setTitle(null);
         }
+
     }
 
     @Override
     public void onHiddenChanged(boolean hidden) {
         super.onHiddenChanged(hidden);
-        if (hidden) {
-           showTitlebar(false);
+        if (getActivity() == null) {
+            return;
+        }
+        // 切换到History,再切回来
+        if (!hidden && activeFragment != null && activeFragment instanceof KPIFragment) {
+            ((KPIFragment) activeFragment).showTitle(getActivity(),true);
         } else {
-            if (mode == 1) {
-                showTitlebar(true);
-            } else {
-                showTitlebar(false);
-            }
+            ((RootActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
+            ((Activity)getActivity()).setTitle(null);
         }
     }
 
-    private void showTitlebar(boolean show) {
-        RootActivity activity = (RootActivity)getActivity();
-        if (activity != null) {
-            android.support.v7.app.ActionBar bar = activity.getSupportActionBar();
-            if (bar != null) {
-                bar.setDisplayShowTitleEnabled(show);
-            }
-        }
-
-        if (kpiFragment != null && show && mode == 1) {
-            kpiFragment.showTitle(true);
-        }
-    }
 
     @Override
     public void onSaveInstanceState(Bundle outState) {

+ 43 - 23
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/KPIFragment.java

@@ -154,7 +154,7 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
                 } else  {
                     currentKPI = position;
                 }
-                showTitle(!isHidden());
+                showTitle(mContext,!isHidden());
 
             }
 
@@ -185,29 +185,36 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
         return root;
     }
 
-    @Override
-    public void setUserVisibleHint(boolean isVisibleToUser) {
-        super.setUserVisibleHint(isVisibleToUser);
-        showTitle(isVisibleToUser);
-    }
-
-    @Override
-    public void onHiddenChanged(boolean hidden) {
-        super.onHiddenChanged(hidden);
-        showTitle(!hidden);
-    }
+//    @Override
+//    public void setUserVisibleHint(boolean isVisibleToUser) {
+//        super.setUserVisibleHint(isVisibleToUser);
+//        showTitle(isVisibleToUser);
+//    }
+//
+//    @Override
+//    public void onHiddenChanged(boolean hidden) {
+//        super.onHiddenChanged(hidden);
+//        showTitle(!hidden);
+//    }
 
-    public void showTitle(boolean show) {
+    public void showTitle(Context ctx,boolean show) {
+        if (ctx == null) {
+            return;
+        }
+        android.support.v7.app.ActionBar bar = ((RootActivity)ctx).getSupportActionBar();
+        if (bar == null) {
+            return;
+        }
         if (show) {
-            ((RootActivity)mContext).getSupportActionBar().setDisplayShowTitleEnabled(true);
+            bar.setDisplayShowTitleEnabled(true);
             if (totalKPI > 0) {
-                ((Activity)mContext).setTitle(currentKPI + "/" + totalKPI);
+                ((Activity)ctx).setTitle(currentKPI + "/" + totalKPI);
             } else {
-                ((Activity)mContext).setTitle(null);
+                ((Activity)ctx).setTitle(null);
             }
         } else {
-            ((RootActivity)mContext).getSupportActionBar().setDisplayShowTitleEnabled(false);
-            ((Activity)mContext).setTitle(null);
+            bar.setDisplayShowTitleEnabled(false);
+            ((Activity)ctx).setTitle(null);
         }
     }
 
@@ -229,8 +236,8 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
             outState.putString("KPIData",mData.toString());
             outState.putInt("currentKPI",currentKPI);
         }
-        mKPIArr.clear();
-        mAdapter.notifyDataSetChanged();
+//        mKPIArr.clear();
+//        mAdapter.notifyDataSetChanged();
     }
 
     @Override
@@ -254,6 +261,16 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
         }
     }
 
+    @Override
+    public void setUserVisibleHint(boolean isVisibleToUser) {
+        super.setUserVisibleHint(isVisibleToUser);
+    }
+
+    @Override
+    public void onHiddenChanged(boolean hidden) {
+        super.onHiddenChanged(hidden);
+    }
+
     private boolean loading = false;
     private void loadKPIData() {
 
@@ -283,9 +300,9 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
                             mSwipeRefresh.setRefreshing(false);
                         }
                         prepareData();
-                        if (mKPIArr != null && mKPIArr.size() > 0) {
-                            mKPIPager.setCurrentItem(currentKPI,false);
-                        }
+//                        if (mKPIArr != null && mKPIArr.size() > 0) {
+//                            mKPIPager.setCurrentItem(currentKPI,false);
+//                        }
                         loading = false;
                     }
                 });
@@ -378,6 +395,9 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
             totalKPI = mKPIArr.size();
         }
         mAdapter.notifyDataSetChanged();
+        if (mKPIArr != null && mKPIArr.size() > 0) {
+            mKPIPager.setCurrentItem(currentKPI,false);
+        }
     }
 
     @Override