diff --git a/app/src/main/java/com/qhclh/ytzh/home/RpcUrl.java b/app/src/main/java/com/qhclh/ytzh/home/RpcUrl.java index 2aa0941..f9a30c9 100644 --- a/app/src/main/java/com/qhclh/ytzh/home/RpcUrl.java +++ b/app/src/main/java/com/qhclh/ytzh/home/RpcUrl.java @@ -8,4 +8,25 @@ public class RpcUrl { // public static String BaseAppUrl = ""; ///< 外网测试 public static String BaseAppUrl = "http://221.1.97.114:86/B3/"; + + public static String DayProductRpc_Query = "/MainSystem/B3_ZhongHui/Rpcs/DayProductRpc/Query"; + + public static String DayProductRpc_New = "/MainSystem/B3_ZhongHui/Rpcs/DayProductRpc/New"; + public static String DayProductRpc_Insert = "/MainSystem/B3_ZhongHui/Rpcs/DayProductRpc/Insert"; + + public static String DayProductRpc_Load = "/MainSystem/B3_ZhongHui/Rpcs/DayProductRpc/Load"; + public static String DayProductRpc_Update = "/MainSystem/B3_ZhongHui/Rpcs/DayProductRpc/Update"; + + ///< 通用数据源接口 + public static String GetChoiceBoxWords = "/MainSystem/System/UIRpcs/GetChoiceBoxWords"; +// [{Item1:string,Item2:String}] +// 参数:[dataKind:字符串,inputArgument:字符串,codeArgument:字符串] +// 其中 +// dataKind:数据源名称 +// inputArgument:用户输入参数 +// codeArgument:固定参数,通常为空字符串 +// 返回值:[{Item1:string,Item2:string}] +// 其中 +// Item1:主键值 +// Item2:显示名称 } diff --git a/app/src/main/java/com/qhclh/ytzh/ui/RefreshLayout.java b/app/src/main/java/com/qhclh/ytzh/ui/RefreshLayout.java new file mode 100644 index 0000000..2a38fd5 --- /dev/null +++ b/app/src/main/java/com/qhclh/ytzh/ui/RefreshLayout.java @@ -0,0 +1,244 @@ +package com.qhclh.ytzh.ui; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewConfiguration; +import android.widget.AbsListView; +import android.widget.AbsListView.OnScrollListener; +import android.widget.ListView; + + +import com.qhclh.ytzh.R; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * 继承自SwipeRefreshLayout,从而实现滑动到底部时上拉加载更多的功能. + */ +public class RefreshLayout extends SwipeRefreshLayout implements + OnScrollListener { + + /** + * 滑动到最下面时的上拉操作 + */ + + private int mTouchSlop; + /** + * listview实例 + */ + private ListView mListView; + + /** + * 上拉监听器, 到了最底部的上拉加载操作 + */ + private OnLoadListener mOnLoadListener; + + /** + * ListView的加载中footer + */ + private View mListViewFooter; + + /** + * 按下时的y坐标 + */ + private int mYDown; + /** + * 抬起时的y坐标, 与mYDown一起用于滑动到底部时判断是上拉还是下拉 + */ + private int mLastY; + /** + * 是否在加载中 ( 上拉加载更多 ) + */ + private boolean isLoading = false; + + /** + * @param context + */ + public RefreshLayout(Context context) { + this(context, null); + } + + @SuppressLint("InflateParams") + public RefreshLayout(Context context, AttributeSet attrs) { + super(context, attrs); + + mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); + + mListViewFooter = LayoutInflater.from(context).inflate( + R.layout.listview_footer, null, false); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, + int bottom) { + super.onLayout(changed, left, top, right, bottom); + // 初始化ListView对象 + if (mListView == null) { + getListView(); + } + } + + /** + * 获取ListView对象 + */ + private void getListView() { + int childs = getChildCount(); + if (childs > 0) { + View childView = getChildAt(0); + if (childView instanceof ListView) { + mListView = (ListView) childView; + // 设置滚动监听器给ListView, 使得滚动的情况下也可以自动加载 + mListView.setOnScrollListener(this); + Log.d(VIEW_LOG_TAG, "### 找到listview"); + } + } + } + + /* + * (non-Javadoc) + * + * @see android.view.ViewGroup#dispatchTouchEvent(android.view.MotionEvent) + */ + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + final int action = event.getAction(); + + switch (action) { + case MotionEvent.ACTION_DOWN: + // 按下 + mYDown = (int) event.getRawY(); + break; + + case MotionEvent.ACTION_MOVE: + // 移动 + mLastY = (int) event.getRawY(); + break; + + case MotionEvent.ACTION_UP: + // 抬起 + if (canLoad()) { + loadData(); + } + break; + default: + break; + } + + return super.dispatchTouchEvent(event); + } + + /** + * 是否可以加载更多, 条件是到了最底部, listview不在加载中, 且为上拉操作. + * + * @return + */ + private boolean canLoad() { + return isBottom() && !isLoading && isPullUp(); + } + + /** + * 判断是否到了最底部 + */ + private boolean isBottom() { + + if (mListView != null && mListView.getAdapter() != null) { + return mListView.getLastVisiblePosition() == (mListView + .getAdapter().getCount() - 1); + } + return false; + } + + /** + * 是否是上拉操作 + * + * @return + */ + private boolean isPullUp() { + return (mYDown - mLastY) >= mTouchSlop; + } + + /** + * 如果到了最底部,而且是上拉操作.那么执行onLoad方法 + */ + private void loadData() { + if (mOnLoadListener != null) { + // 设置状态 + setLoading(true); + // + mOnLoadListener.onLoad(); + } + } + + /** + * @param loading + */ + public void setLoading(boolean loading) { + isLoading = loading; + if (isLoading) { + mListView.addFooterView(mListViewFooter); + } else { + mListView.removeFooterView(mListViewFooter); + mYDown = 0; + mLastY = 0; + } + } + + /** + * @param loadListener + */ + public void setOnLoadListener(OnLoadListener loadListener) { + mOnLoadListener = loadListener; + } + + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + + } + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, + int visibleItemCount, int totalItemCount) { + // 滚动时到了最底部也可以加载更多 + if (canLoad()) { + loadData(); + } + } + + /** + * 设置刷新 + */ + public static void setRefreshing(SwipeRefreshLayout refreshLayout, + boolean refreshing, boolean notify) { + Class refreshLayoutClass = refreshLayout + .getClass(); + if (refreshLayoutClass != null) { + + try { + Method setRefreshing = refreshLayoutClass.getDeclaredMethod( + "setRefreshing", boolean.class, boolean.class); + setRefreshing.setAccessible(true); + setRefreshing.invoke(refreshLayout, refreshing, notify); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + } + + /** + * 加载更多的监听器 + */ + public static interface OnLoadListener { + public void onLoad(); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/act_productiondaily.xml b/app/src/main/res/layout/act_productiondaily.xml index 9f34c73..c32dcdd 100644 --- a/app/src/main/res/layout/act_productiondaily.xml +++ b/app/src/main/res/layout/act_productiondaily.xml @@ -1,17 +1,26 @@ - - + + + + - + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/listview_footer.xml b/app/src/main/res/layout/listview_footer.xml new file mode 100644 index 0000000..62393d4 --- /dev/null +++ b/app/src/main/res/layout/listview_footer.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file