diff --git a/.gitignore b/.gitignore index 5f1b992..17e193a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ ZBLibrary(ADT)/ZBLibraryDemoApp/gen ZBLibrary(AndroidStudio)/.idea ZBLibrary(AndroidStudio)/app/build ZBLibrary(AndroidStudio)/ZBLibrary/build +ZBLibrary(ADT)/recyclerview/bin diff --git a/ZBLibrary(ADT)/QRCodeLibrary/.settings/org.eclipse.jdt.core.prefs b/ZBLibrary(ADT)/QRCodeLibrary/.settings/org.eclipse.jdt.core.prefs index 8000cd6..7341ab1 100644 --- a/ZBLibrary(ADT)/QRCodeLibrary/.settings/org.eclipse.jdt.core.prefs +++ b/ZBLibrary(ADT)/QRCodeLibrary/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,11 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ZBLibrary(ADT)/ZBLibrary/.settings/org.eclipse.jdt.core.prefs b/ZBLibrary(ADT)/ZBLibrary/.settings/org.eclipse.jdt.core.prefs index 8000cd6..7341ab1 100644 --- a/ZBLibrary(ADT)/ZBLibrary/.settings/org.eclipse.jdt.core.prefs +++ b/ZBLibrary(ADT)/ZBLibrary/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,11 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ZBLibrary(ADT)/ZBLibrary/project.properties b/ZBLibrary(ADT)/ZBLibrary/project.properties index 93c8c3c..7f590e4 100755 --- a/ZBLibrary(ADT)/ZBLibrary/project.properties +++ b/ZBLibrary(ADT)/ZBLibrary/project.properties @@ -13,3 +13,4 @@ # Project target. target=android-21 android.library=true +android.library.reference.1=../recyclerview diff --git a/ZBLibrary(ADT)/ZBLibrary/res/layout/base_recycler_fragment.xml b/ZBLibrary(ADT)/ZBLibrary/res/layout/base_recycler_fragment.xml new file mode 100644 index 0000000..e4a12b5 --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibrary/res/layout/base_recycler_fragment.xml @@ -0,0 +1,4 @@ + + diff --git a/ZBLibrary(ADT)/ZBLibrary/res/values/ids.xml b/ZBLibrary(ADT)/ZBLibrary/res/values/ids.xml index 7c6d231..889a7c5 100644 --- a/ZBLibrary(ADT)/ZBLibrary/res/values/ids.xml +++ b/ZBLibrary(ADT)/ZBLibrary/res/values/ids.xml @@ -14,5 +14,7 @@ false false false - + false + false + \ No newline at end of file diff --git a/ZBLibrary(ADT)/ZBLibrary/res/values/strings.xml b/ZBLibrary(ADT)/ZBLibrary/res/values/strings.xml index 5aed677..2f82316 100755 --- a/ZBLibrary(ADT)/ZBLibrary/res/values/strings.xml +++ b/ZBLibrary(ADT)/ZBLibrary/res/values/strings.xml @@ -2,7 +2,7 @@ 坐标标准库 - 15.0 + 15.1 我发现了一款很好用的Android快速开发框架,叫 Android-ZBLibrary ,快去GitHub上看看吧~ 返回 提示 diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java index 032429f..7b46113 100644 --- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java +++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListActivity.java @@ -23,7 +23,6 @@ import zuo.biao.library.interfaces.CacheCallBack; import zuo.biao.library.interfaces.OnStopLoadListener; import zuo.biao.library.manager.CacheManager; -import zuo.biao.library.manager.HttpManager; import zuo.biao.library.util.Log; import zuo.biao.library.util.SettingUtil; import zuo.biao.library.util.StringUtil; diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java index c50ab17..c34f019 100644 --- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java +++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseListFragment.java @@ -23,7 +23,6 @@ import zuo.biao.library.interfaces.CacheCallBack; import zuo.biao.library.interfaces.OnStopLoadListener; import zuo.biao.library.manager.CacheManager; -import zuo.biao.library.manager.HttpManager; import zuo.biao.library.util.Log; import zuo.biao.library.util.SettingUtil; import zuo.biao.library.util.StringUtil; diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerActivity.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerActivity.java new file mode 100644 index 0000000..d13d5ab --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerActivity.java @@ -0,0 +1,461 @@ +/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package zuo.biao.library.base; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +import zuo.biao.library.R; +import zuo.biao.library.interfaces.CacheCallBack; +import zuo.biao.library.interfaces.OnStopLoadListener; +import zuo.biao.library.manager.CacheManager; +import zuo.biao.library.util.Log; +import zuo.biao.library.util.StringUtil; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +/**基础RecyclerView Activity + * @author Lemon + * @param 数据模型(model/JavaBean)类 + * @param ViewHolder或其子类 + * @param RecyclerView或其子类 + * @param 管理LV的Adapter + * @see #rvBaseRecycler + * @see #initCache + * @see #initView + * @see #getListAsync + * @see #onRefresh + * @use extends BaseRecyclerActivity 并在子类onCreate中调用onRefresh(...), 具体参考.DemoListActivity + * *缓存使用:在initData前调用initCache(...), 具体参考 .DemoListActivity(onCreate方法内) + */ +public abstract class BaseRecyclerActivity> extends BaseActivity { + private static final String TAG = "BaseRecyclerActivity"; + + public interface AdapterCallBack> { + /**创建一个Adapter + * @return new A(); + */ + A createAdapter(); + + /** + * BaseAdapter#notifyDataSetChanged()有时无效,有时因列表更新不及时而崩溃,所以需要在自定义adapter内自定义一个刷新方法。 + * 为什么不直接让自定义Adapter implement OnRefreshListener,从而直接 onRefreshListener.onRefresh(List list) ? + * 因为这样的话会不兼容部分 Android SDK 或 第三方库的Adapter + */ + void refreshAdapter(); + } + + + private OnStopLoadListener onStopLoadListener; + /**设置停止加载监听 + * @param onStopLoadListener + */ + protected void setOnStopLoadListener(OnStopLoadListener onStopLoadListener) { + this.onStopLoadListener = onStopLoadListener; + } + + private CacheCallBack cacheCallBack; + /**初始化缓存 + * @warn 在initData前使用才有效 + * @param cacheCallBack + */ + protected void initCache(CacheCallBack cacheCallBack) { + this.cacheCallBack = cacheCallBack; + } + + + + + // UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + /** + * 显示列表的RecyclerView + * @warn 只使用rvBaseRecycler为显示列表数据的RecyclerView,不要在子类中改变它 + */ + protected RV rvBaseRecycler; + /** + * 管理LV的Item的Adapter + */ + protected A adapter; + /** + * 如果在子类中调用(即super.initView());则view必须含有initView中初始化用到的id且id对应的View的类型全部相同; + * 否则必须在子类initView中重写这个类中initView内的代码(所有id替换成可用id) + */ + @Override + public void initView() {// 必须调用 + + rvBaseRecycler = findView(R.id.rvBaseRecycler); + rvBaseRecycler.setLayoutManager(new LinearLayoutManager(context)); + } + + /**设置adapter + * @param adapter + */ + public void setAdapter(A adapter) { + this.adapter = adapter; + rvBaseRecycler.setAdapter(adapter); + } + + /**显示列表(已在UI线程中),一般需求建议直接调用setList(List l, AdapterCallBack callBack) + * @param list + */ + public abstract void setList(List list); + + /**显示列表(已在UI线程中) + * @param callBack + */ + public void setList(AdapterCallBack callBack) { + if (adapter == null) { + setAdapter(callBack.createAdapter()); + } + callBack.refreshAdapter(); + } + + + // UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + + + // Data数据区(存在数据获取或处理代码,但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + private boolean isToSaveCache; + private boolean isToLoadCache; + @Override + public void initData() {// 必须调用 + + isToSaveCache = cacheCallBack != null && cacheCallBack.getCacheClass() != null; + isToLoadCache = isToSaveCache && StringUtil.isNotEmpty(cacheCallBack.getCacheGroup(), true); + } + + /** + * 获取列表,在非UI线程中 + * @must 获取成功后调用onLoadSucceed + * @param page 在onLoadSucceed中传回来保证一致性 + */ + public abstract void getListAsync(int page); + + + + public void loadData(int page) { + loadData(page, isToLoadCache); + } + + /** + * 起始页码 + */ + private static final int PAGE_NUM_0 = 1; + + /** + * 数据列表 + */ + private List list; + /** + * 正在加载 + */ + protected boolean isLoading = false; + /** + * 还有更多可加载数据 + */ + protected boolean isHaveMore = true; + /** + * 加载页码,每页对应一定数量的数据 + */ + private int page; + private int loadCacheStart; + /**加载数据,用getListAsync方法发请求获取数据 + * @param page_ + * @param isCache + */ + private void loadData(int page_, final boolean isCache) { + if (isLoading) { + Log.w(TAG, "loadData isLoading >> return;"); + return; + } + isLoading = true; + isSucceed = false; + + if (page_ <= PAGE_NUM_0) { + page_ = PAGE_NUM_0; + isHaveMore = true; + loadCacheStart = 0;//使用则可像网络正常情况下的重载,不使用则在网络异常情况下不重载(导致重载后加载数据下移) + } else { + if (isHaveMore == false) { + stopLoadData(page_); + return; + } + loadCacheStart = list == null ? 0 : list.size(); + } + this.page = page_; + Log.i(TAG, "loadData page_ = " + page_ + "; isCache = " + isCache + + "; isHaveMore = " + isHaveMore + "; loadCacheStart = " + loadCacheStart); + + runThread(TAG + "loadData", new Runnable() { + + @Override + public void run() { + if (isCache == false) {//从网络获取数据 + getListAsync(page); + } else {//从缓存获取数据 + onLoadSucceed(page, CacheManager.getInstance().getList(cacheCallBack.getCacheClass() + , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()), + true); + if (page <= PAGE_NUM_0) { + isLoading = false;//stopLoadeData在其它线程isLoading = false;后这个线程里还是true + loadData(page, false); + } + } + } + }); + } + + /**停止加载数据 + * isCache = false; + * @param page + */ + public synchronized void stopLoadData(int page) { + stopLoadData(page, false); + } + /**停止加载数据 + * @param page + * @param isCache + */ + private synchronized void stopLoadData(int page, boolean isCache) { + Log.i(TAG, "stopLoadData isCache = " + isCache); + isLoading = false; + dismissProgressDialog(); + + if (isCache) { + Log.d(TAG, "stopLoadData isCache >> return;"); + return; + } + + if (onStopLoadListener == null) { + Log.w(TAG, "stopLoadData onStopLoadListener == null >> return;"); + return; + } + onStopLoadListener.onStopRefresh(); + if (page > PAGE_NUM_0) { + onStopLoadListener.onStopLoadMore(isHaveMore); + } + } + + + + private boolean isSucceed = false; + /**处理列表 + * @param page + * @param newList 新数据列表 + * @param isCache + * @return + * @return + */ + public synchronized void handleList(int page, List newList, boolean isCache) { + if (newList == null) { + newList = new ArrayList(); + } + isSucceed = ! newList.isEmpty(); + Log.i(TAG, "\n\n<<<<<<<<<<<<<<<<<\n handleList newList.size = " + newList.size() + "; isCache = " + isCache + + "; page = " + page + "; isSucceed = " + isSucceed); + + if (page <= PAGE_NUM_0) { + Log.i(TAG, "handleList page <= PAGE_NUM_0 >>>> "); + saveCacheStart = 0; + list = new ArrayList(newList); + if (isCache == false && list.isEmpty() == false) { + Log.i(TAG, "handleList isCache == false && list.isEmpty() == false >> isToLoadCache = false;"); + isToLoadCache = false; + } + } else { + Log.i(TAG, "handleList page > PAGE_NUM_0 >>>> "); + if (list == null) { + list = new ArrayList(); + } + saveCacheStart = list.size(); + isHaveMore = ! newList.isEmpty(); + if (isHaveMore) { + list.addAll(newList); + } + } + + Log.i(TAG, "handleList list.size = " + list.size() + "; isHaveMore = " + isHaveMore + + "; isToLoadCache = " + isToLoadCache + "; saveCacheStart = " + saveCacheStart + + "\n>>>>>>>>>>>>>>>>>>\n\n"); + } + + + + /**加载成功 + * isCache = false; + * @param page + * @param newList + */ + public synchronized void onLoadSucceed(final int page, final List newList) { + onLoadSucceed(page, newList, false); + } + /**加载成功 + * @param page + * @param newList + * @param isCache newList是否为缓存 + */ + private synchronized void onLoadSucceed(final int page, final List newList, final boolean isCache) { + runThread(TAG + "onLoadSucceed", new Runnable() { + @Override + public void run() { + Log.i(TAG, "onLoadSucceed page = " + page + "; isCache = " + isCache + " >> handleList..."); + handleList(page, newList, isCache); + + runUiThread(new Runnable() { + + @Override + public void run() { + stopLoadData(page, isCache); + setList(list); + } + }); + + if (isToSaveCache && isCache == false) { + saveCache(newList); + } + } + }); + } + + /**加载失败 + * @param page + * @param e + */ + public synchronized void onLoadFailed(int page, Exception e) { + Log.e(TAG, "onLoadFailed page = " + page + "; e = " + (e == null ? null : e.getMessage())); + stopLoadData(page); + showShortToast(R.string.get_failed); + } + + + + + //缓存<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + // /** + // * 获取缓存每页数量 + // * @return > 0 ?缓存 : 不缓存 + // */ + // public int getCacheCount() { + // //让给服务器返回每页数量为count的数据,不行的话在子类重写 Math.max(10, newList == null ? 0 : newList.size()); + // return CacheManager.MAX_PAGE_SIZE; + // } + + private int saveCacheStart; + /**保存缓存 + * @param newList + */ + public synchronized void saveCache(List newList) { + if (cacheCallBack == null || newList == null || newList.isEmpty()) { + Log.e(TAG, "saveCache cacheCallBack == null || newList == null || newList.isEmpty() >> return;"); + return; + } + + LinkedHashMap map = new LinkedHashMap(); + for (T data : newList) { + if (data != null) { + map.put(cacheCallBack.getCacheId(data), data);//map.put(null, data);不会崩溃 + } + } + + CacheManager.getInstance().saveList(cacheCallBack.getCacheClass(), cacheCallBack.getCacheGroup() + , map, saveCacheStart, cacheCallBack.getCacheCount()); + } + //缓存>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + // Data数据区(存在数据获取或处理代码,但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + + + // Event事件区(只要存在事件监听代码就是)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + @Override + public void initEvent() { + + } + + + /**刷新(从头加载) + * @must 在子类onCreate中调用,建议放在最后 + */ + public void onRefresh() { + loadData(PAGE_NUM_0); + } + /**加载更多 + */ + public void onLoadMore() { + if (isSucceed == false && page <= PAGE_NUM_0) { + Log.w(TAG, "onLoadMore isSucceed == false && page <= PAGE_NUM_0 >> return;"); + return; + } + loadData(page + (isSucceed ? 1 : 0)); + } + + + // 系统自带监听方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + // 类相关监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + @Override + protected void onDestroy() { + isLoading = false; + isHaveMore = false; + isToSaveCache = false; + isToLoadCache = false; + + super.onDestroy(); + + rvBaseRecycler = null; + list = null; + + onStopLoadListener = null; + cacheCallBack = null; + } + + // 类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + // 系统自带监听方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + // Event事件区(只要存在事件监听代码就是)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + // 内部类,尽量少用<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + // 内部类,尽量少用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +} \ No newline at end of file diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerFragment.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerFragment.java new file mode 100644 index 0000000..c13c705 --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerFragment.java @@ -0,0 +1,527 @@ +/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package zuo.biao.library.base; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +import zuo.biao.library.R; +import zuo.biao.library.interfaces.CacheCallBack; +import zuo.biao.library.interfaces.OnStopLoadListener; +import zuo.biao.library.manager.CacheManager; +import zuo.biao.library.util.Log; +import zuo.biao.library.util.StringUtil; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; + +/**基础RecyclerView Fragment + * @author Lemon + * @param 数据模型(model/JavaBean)类 + * @param RecyclerView或其子类 + * @param ViewHolder或其子类 + * @param 管理LV的Adapter + * @see #rvBaseRecycler + * @see #initCache + * @see #initView + * @see #getListAsync + * @see #onRefresh + * @use extends BaseRecyclerFragment 并在子类onCreateView中调用onRefresh(...), 具体参考.DemoListFragment + * *缓存使用:在initData前调用initCache(...), 具体参考 .DemoListActivity(onCreate方法内) + */ +public abstract class BaseRecyclerFragment> extends BaseFragment { + private static final String TAG = "BaseRecyclerActivity"; + + public interface AdapterCallBack> { + /**创建一个Adapter + * @return new A(); + */ + A createAdapter(); + + /** + * BaseAdapter#notifyDataSetChanged()有时无效,有时因列表更新不及时而崩溃,所以需要在自定义adapter内自定义一个刷新方法。 + * 为什么不直接让自定义Adapter implement OnRefreshListener,从而直接 onRefreshListener.onRefresh(List list) ? + * 因为这样的话会不兼容部分 Android SDK 或 第三方库的Adapter + */ + void refreshAdapter(); + } + + + private OnStopLoadListener onStopLoadListener; + /**设置停止加载监听 + * @param onStopLoadListener + */ + protected void setOnStopLoadListener(OnStopLoadListener onStopLoadListener) { + this.onStopLoadListener = onStopLoadListener; + } + + private CacheCallBack cacheCallBack; + /**初始化缓存 + * @warn 在initData前使用才有效 + * @param cacheCallBack + */ + protected void initCache(CacheCallBack cacheCallBack) { + this.cacheCallBack = cacheCallBack; + } + + + + /** + * @param inflater + * @param container + * @param savedInstanceState + * @return + * @must 1.不要在子类重复这个类中onCreateView中的代码; + * 2.在子类onCreateView中super.onCreateView(inflater, container, savedInstanceState); + * initView();initData();initEvent(); return view; + */ + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return onCreateView(inflater, container, savedInstanceState, 0); + } + /** + * @param inflater + * @param container + * @param savedInstanceState + * @param layoutResID fragment全局视图view的布局资源id,默认值为R.layout.base_http_list_fragment + * @return + * @must 1.不要在子类重复这个类中onCreateView中的代码; + * 2.在子类onCreateView中super.onCreateView(inflater, container, savedInstanceState, layoutResID); + * initView();initData();initEvent(); return view; + */ + public final View onCreateView(LayoutInflater inflater, ViewGroup container + , Bundle savedInstanceState, int layoutResID) { + //类相关初始化,必须使用<<<<<<<<<<<<<<<<<< + super.onCreateView(inflater, container, savedInstanceState); + //调用这个类的setContentView而崩溃 super.setContentView(layoutResID <= 0 ? R.layout.base_recycler_fragment : layoutResID); + view = inflater.inflate(layoutResID <= 0 ? R.layout.base_recycler_fragment : layoutResID, container, false); + //类相关初始化,必须使用>>>>>>>>>>>>>>>> + + return view; + } + + + //防止子类中setContentView <<<<<<<<<<<<<<<<<<<<<<<< + /** + * @warn 不支持setContentView,传界面布局请使用onCreateView(Bundle savedInstanceState, int layoutResID)等方法 + */ + @Override + public final void setContentView(int layoutResID) { + setContentView(null); + } + /** + * @warn 不支持setContentView,传界面布局请使用onCreateView(Bundle savedInstanceState, int layoutResID)等方法 + */ + @Override + public final void setContentView(View view) { + setContentView(null, null); + } + /** + * @warn 不支持setContentView,传界面布局请使用onCreateView(Bundle savedInstanceState, int layoutResID)等方法 + */ + @Override + public final void setContentView(View view, LayoutParams params) { + throw new UnsupportedOperationException(TAG + "不支持setContentView,传界面布局请使用onCreateView(" + + "LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, int layoutResID)等方法"); + } + //防止子类中setContentView >>>>>>>>>>>>>>>>>>>>>>>>> + + + + // UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + /** + * 显示列表的RecyclerView + * @warn 只使用rvBaseRecycler为显示列表数据的RecyclerView,不要在子类中改变它 + */ + protected RV rvBaseRecycler; + /** + * 管理LV的Item的Adapter + */ + protected A adapter; + /** + * 如果在子类中调用(即super.initView());则view必须含有initView中初始化用到的id且id对应的View的类型全部相同; + * 否则必须在子类initView中重写这个类中initView内的代码(所有id替换成可用id) + */ + @Override + public void initView() {// 必须调用 + + rvBaseRecycler = findView(R.id.rvBaseRecycler); + rvBaseRecycler.setLayoutManager(new LinearLayoutManager(context)); + } + + /**设置adapter + * @param adapter + */ + public void setAdapter(A adapter) { + this.adapter = adapter; + rvBaseRecycler.setAdapter(adapter); + } + + /**显示列表(已在UI线程中),一般需求建议直接调用setList(List l, AdapterCallBack callBack) + * @param list + */ + public abstract void setList(List list); + + /**显示列表(已在UI线程中) + * @param callBack + */ + public void setList(AdapterCallBack callBack) { + if (adapter == null) { + setAdapter(callBack.createAdapter()); + } + callBack.refreshAdapter(); + } + + + // UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + + + // Data数据区(存在数据获取或处理代码,但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + private boolean isToSaveCache; + private boolean isToLoadCache; + @Override + public void initData() {// 必须调用 + + isToSaveCache = cacheCallBack != null && cacheCallBack.getCacheClass() != null; + isToLoadCache = isToSaveCache && StringUtil.isNotEmpty(cacheCallBack.getCacheGroup(), true); + } + + /** + * 获取列表,在非UI线程中 + * @must 获取成功后调用onLoadSucceed + * @param page 在onLoadSucceed中传回来保证一致性 + */ + public abstract void getListAsync(int page); + + + + public void loadData(int page) { + loadData(page, isToLoadCache); + } + + /** + * 起始页码 + */ + private static final int PAGE_NUM_0 = 1; + + /** + * 数据列表 + */ + private List list; + /** + * 正在加载 + */ + protected boolean isLoading = false; + /** + * 还有更多可加载数据 + */ + protected boolean isHaveMore = true; + /** + * 加载页码,每页对应一定数量的数据 + */ + private int page; + private int loadCacheStart; + /**加载数据,用getListAsync方法发请求获取数据 + * @param page_ + * @param isCache + */ + private void loadData(int page_, final boolean isCache) { + if (isLoading) { + Log.w(TAG, "loadData isLoading >> return;"); + return; + } + isLoading = true; + isSucceed = false; + + if (page_ <= PAGE_NUM_0) { + page_ = PAGE_NUM_0; + isHaveMore = true; + loadCacheStart = 0;//使用则可像网络正常情况下的重载,不使用则在网络异常情况下不重载(导致重载后加载数据下移) + } else { + if (isHaveMore == false) { + stopLoadData(page_); + return; + } + loadCacheStart = list == null ? 0 : list.size(); + } + this.page = page_; + Log.i(TAG, "loadData page_ = " + page_ + "; isCache = " + isCache + + "; isHaveMore = " + isHaveMore + "; loadCacheStart = " + loadCacheStart); + + runThread(TAG + "loadData", new Runnable() { + + @Override + public void run() { + if (isCache == false) {//从网络获取数据 + getListAsync(page); + } else {//从缓存获取数据 + onLoadSucceed(page, CacheManager.getInstance().getList(cacheCallBack.getCacheClass() + , cacheCallBack.getCacheGroup(), loadCacheStart, cacheCallBack.getCacheCount()), + true); + if (page <= PAGE_NUM_0) { + isLoading = false;//stopLoadeData在其它线程isLoading = false;后这个线程里还是true + loadData(page, false); + } + } + } + }); + } + + /**停止加载数据 + * isCache = false; + * @param page + */ + public synchronized void stopLoadData(int page) { + stopLoadData(page, false); + } + /**停止加载数据 + * @param page + * @param isCache + */ + private synchronized void stopLoadData(int page, boolean isCache) { + Log.i(TAG, "stopLoadData isCache = " + isCache); + isLoading = false; + dismissProgressDialog(); + + if (isCache) { + Log.d(TAG, "stopLoadData isCache >> return;"); + return; + } + + if (onStopLoadListener == null) { + Log.w(TAG, "stopLoadData onStopLoadListener == null >> return;"); + return; + } + onStopLoadListener.onStopRefresh(); + if (page > PAGE_NUM_0) { + onStopLoadListener.onStopLoadMore(isHaveMore); + } + } + + + + private boolean isSucceed = false; + /**处理列表 + * @param page + * @param newList 新数据列表 + * @param isCache + * @return + * @return + */ + public synchronized void handleList(int page, List newList, boolean isCache) { + if (newList == null) { + newList = new ArrayList(); + } + isSucceed = ! newList.isEmpty(); + Log.i(TAG, "\n\n<<<<<<<<<<<<<<<<<\n handleList newList.size = " + newList.size() + "; isCache = " + isCache + + "; page = " + page + "; isSucceed = " + isSucceed); + + if (page <= PAGE_NUM_0) { + Log.i(TAG, "handleList page <= PAGE_NUM_0 >>>> "); + saveCacheStart = 0; + list = new ArrayList(newList); + if (isCache == false && list.isEmpty() == false) { + Log.i(TAG, "handleList isCache == false && list.isEmpty() == false >> isToLoadCache = false;"); + isToLoadCache = false; + } + } else { + Log.i(TAG, "handleList page > PAGE_NUM_0 >>>> "); + if (list == null) { + list = new ArrayList(); + } + saveCacheStart = list.size(); + isHaveMore = ! newList.isEmpty(); + if (isHaveMore) { + list.addAll(newList); + } + } + + Log.i(TAG, "handleList list.size = " + list.size() + "; isHaveMore = " + isHaveMore + + "; isToLoadCache = " + isToLoadCache + "; saveCacheStart = " + saveCacheStart + + "\n>>>>>>>>>>>>>>>>>>\n\n"); + } + + + + /**加载成功 + * isCache = false; + * @param page + * @param newList + */ + public synchronized void onLoadSucceed(final int page, final List newList) { + onLoadSucceed(page, newList, false); + } + /**加载成功 + * @param page + * @param newList + * @param isCache newList是否为缓存 + */ + private synchronized void onLoadSucceed(final int page, final List newList, final boolean isCache) { + runThread(TAG + "onLoadSucceed", new Runnable() { + @Override + public void run() { + Log.i(TAG, "onLoadSucceed page = " + page + "; isCache = " + isCache + " >> handleList..."); + handleList(page, newList, isCache); + + runUiThread(new Runnable() { + + @Override + public void run() { + stopLoadData(page, isCache); + setList(list); + } + }); + + if (isToSaveCache && isCache == false) { + saveCache(newList); + } + } + }); + } + + /**加载失败 + * @param page + * @param e + */ + public synchronized void onLoadFailed(int page, Exception e) { + Log.e(TAG, "onLoadFailed page = " + page + "; e = " + (e == null ? null : e.getMessage())); + stopLoadData(page); + showShortToast(R.string.get_failed); + } + + + + + //缓存<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + // /** + // * 获取缓存每页数量 + // * @return > 0 ?缓存 : 不缓存 + // */ + // public int getCacheCount() { + // //让给服务器返回每页数量为count的数据,不行的话在子类重写 Math.max(10, newList == null ? 0 : newList.size()); + // return CacheManager.MAX_PAGE_SIZE; + // } + + private int saveCacheStart; + /**保存缓存 + * @param newList + */ + public synchronized void saveCache(List newList) { + if (cacheCallBack == null || newList == null || newList.isEmpty()) { + Log.e(TAG, "saveCache cacheCallBack == null || newList == null || newList.isEmpty() >> return;"); + return; + } + + LinkedHashMap map = new LinkedHashMap(); + for (T data : newList) { + if (data != null) { + map.put(cacheCallBack.getCacheId(data), data);//map.put(null, data);不会崩溃 + } + } + + CacheManager.getInstance().saveList(cacheCallBack.getCacheClass(), cacheCallBack.getCacheGroup() + , map, saveCacheStart, cacheCallBack.getCacheCount()); + } + //缓存>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + // Data数据区(存在数据获取或处理代码,但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + + + // Event事件区(只要存在事件监听代码就是)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + @Override + public void initEvent() { + + } + + + /**刷新(从头加载) + * @must 在子类onCreate中调用,建议放在最后 + */ + public void onRefresh() { + loadData(PAGE_NUM_0); + } + /**加载更多 + */ + public void onLoadMore() { + if (isSucceed == false && page <= PAGE_NUM_0) { + Log.w(TAG, "onLoadMore isSucceed == false && page <= PAGE_NUM_0 >> return;"); + return; + } + loadData(page + (isSucceed ? 1 : 0)); + } + + + // 系统自带监听方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + // 类相关监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + @Override + public void onDestroy() { + isLoading = false; + isHaveMore = false; + isToSaveCache = false; + isToLoadCache = false; + + super.onDestroy(); + + rvBaseRecycler = null; + list = null; + + onStopLoadListener = null; + cacheCallBack = null; + } + + // 类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + // 系统自带监听方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + // Event事件区(只要存在事件监听代码就是)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + // 内部类,尽量少用<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + // 内部类,尽量少用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +} \ No newline at end of file diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerView.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerView.java new file mode 100644 index 0000000..b15be48 --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseRecyclerView.java @@ -0,0 +1,75 @@ +package zuo.biao.library.base; + +import android.app.Activity; +import android.support.annotation.LayoutRes; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Tommy on 17/10/4. + */ + +public abstract class BaseRecyclerView extends RecyclerView.ViewHolder { + + public Activity context; + public BaseRecyclerView(Activity context, @LayoutRes int layoutResId) { + super(context.getLayoutInflater().inflate(layoutResId, null)); + this.context = context; + } + + protected List onClickViewList; + /**通过id查找并获取控件,使用时不需要强转 + * @param id + * @return + */ + @SuppressWarnings("unchecked") + public V findView(int id) { + return (V) itemView.findViewById(id); + } + /**通过id查找并获取控件,使用时不需要强转 + * @param id + * @return + */ + public V findViewById(int id) { + return findView(id); + } + /**通过id查找并获取控件,并setOnClickListener + * @param id + * @param listener + * @return + */ + public V findView(int id, View.OnClickListener listener) { + V v = findView(id); + v.setOnClickListener(listener); + if (onClickViewList == null) { + onClickViewList = new ArrayList(); + } + onClickViewList.add(v); + return v; + } + /**通过id查找并获取控件,并setOnClickListener + * @param id + * @param listener + * @return + */ + public V findViewById(int id, View.OnClickListener listener) { + return findView(id, listener); + } + + protected T data = null; + /**获取数据 + * @return + */ + public T getData() { + return data; + } + + + public abstract View createView(LayoutInflater inflater); + + public abstract void bindView(T data); +} diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseViewAdapter.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseViewAdapter.java index 163763a..a3068f4 100755 --- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseViewAdapter.java +++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/base/BaseViewAdapter.java @@ -30,7 +30,7 @@ * @use extends BaseViewAdapter, 具体参考 .DemoAdapter3 */ public abstract class BaseViewAdapter> extends BaseAdapter -implements AdapterViewPresenter { +implements AdapterViewPresenter { // private static final String TAG = "BaseViewAdapter"; @@ -44,17 +44,17 @@ public void setOnViewClickListener(OnViewClickListener listener) { } - private AdapterViewPresenter presenter; + private AdapterViewPresenter presenter; /**在子类构造方法内使用可重写AdapterViewPresenter里的方法 * @param presenter */ - protected final void setPresenter(AdapterViewPresenter presenter) { + protected final void setPresenter(AdapterViewPresenter presenter) { this.presenter = presenter; } /** * @return presenter == null ? this : presenter; */ - protected final AdapterViewPresenter getPresenter() { + protected final AdapterViewPresenter getPresenter() { return presenter == null ? this : presenter; } diff --git a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/interfaces/AdapterViewPresenter.java b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/interfaces/AdapterViewPresenter.java index 0b3fbd0..7ef8325 100644 --- a/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/interfaces/AdapterViewPresenter.java +++ b/ZBLibrary(ADT)/ZBLibrary/src/zuo/biao/library/interfaces/AdapterViewPresenter.java @@ -2,7 +2,7 @@ import android.view.ViewGroup; -public interface AdapterViewPresenter { +public interface AdapterViewPresenter { /**生成新的BV * @param position diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/.settings/org.eclipse.jdt.core.prefs b/ZBLibrary(ADT)/ZBLibraryDemoApp/.settings/org.eclipse.jdt.core.prefs index 8000cd6..7341ab1 100644 --- a/ZBLibrary(ADT)/ZBLibraryDemoApp/.settings/org.eclipse.jdt.core.prefs +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,11 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/AndroidManifest.xml b/ZBLibrary(ADT)/ZBLibraryDemoApp/AndroidManifest.xml index aee852e..d2f41fc 100755 --- a/ZBLibrary(ADT)/ZBLibraryDemoApp/AndroidManifest.xml +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/AndroidManifest.xml @@ -114,6 +114,10 @@ android:name="zblibrary.demo.DEMO.DemoListActivity" android:screenOrientation="portrait" android:windowSoftInputMode="stateAlwaysHidden" /> + + + + + + + + + + diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/res/layout/demo_recycler_activity.xml b/ZBLibrary(ADT)/ZBLibraryDemoApp/res/layout/demo_recycler_activity.xml new file mode 100755 index 0000000..c0306e4 --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/res/layout/demo_recycler_activity.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/res/layout/demo_view.xml b/ZBLibrary(ADT)/ZBLibraryDemoApp/res/layout/demo_view.xml index aff78e4..25317ad 100755 --- a/ZBLibrary(ADT)/ZBLibraryDemoApp/res/layout/demo_view.xml +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/res/layout/demo_view.xml @@ -9,8 +9,9 @@ diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/BaseRecyclerAdapter.java b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/BaseRecyclerAdapter.java new file mode 100644 index 0000000..f4b7b7e --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/BaseRecyclerAdapter.java @@ -0,0 +1,83 @@ +package zblibrary.demo.DEMO; + +import android.app.Activity; +import android.content.res.Resources; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.ViewGroup; + +import java.util.ArrayList; +import java.util.List; + +import zuo.biao.library.base.BaseRecyclerView; +import zuo.biao.library.interfaces.AdapterViewPresenter; + +public abstract class BaseRecyclerAdapter> extends RecyclerView.Adapter +implements AdapterViewPresenter { + + /** + * 管理整个界面的Activity实例 + */ + public Activity context; + /** + * 布局解释器,用来实例化列表的item的界面 + */ + public LayoutInflater inflater; + /** + * 资源获取器,用于获取res目录下的文件及文件中的内容等 + */ + public Resources resources; + public BaseRecyclerAdapter(Activity context) { + super(); + this.context = context; + + inflater = context.getLayoutInflater(); + resources = context.getResources(); + } + + /** + * 传进来的数据列表 + */ + public List list; + public List getList() { + return list; + } + + /**刷新列表 + */ + public synchronized void refresh(List list) { + this.list = list == null ? null : new ArrayList(list); + notifyDataSetChanged(); + } + + @Override + public int getItemCount() { + return list.size(); + } + + + public T getItem(int position) { + return list.get(position); + } + + + @Override + public BV onCreateViewHolder(ViewGroup parent, int position) { + BV bv = createView(position, parent); + bv.createView(inflater); + return bv; + } + + + @Override + public void onBindViewHolder(BV bv, int position) { + bindView(position, bv); + } + + @Override + public void bindView(int position, BV bv) { + bv.bindView(getItem(position)); + } + + +} diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoMainActivity.java b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoMainActivity.java index abb30c0..8e62097 100755 --- a/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoMainActivity.java +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoMainActivity.java @@ -14,6 +14,20 @@ package zblibrary.demo.DEMO; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.View.OnTouchListener; +import android.widget.ImageView; +import android.widget.ScrollView; +import android.widget.TextView; + import java.util.ArrayList; import zblibrary.demo.R; @@ -41,19 +55,6 @@ import zuo.biao.library.util.SettingUtil; import zuo.biao.library.util.StringUtil; import zuo.biao.library.util.TimeUtil; -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; -import android.view.MotionEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.View.OnTouchListener; -import android.widget.ImageView; -import android.widget.ScrollView; -import android.widget.TextView; /**demo主页 * @author Lemon @@ -73,7 +74,7 @@ public static Intent createIntent(Context context) { } //启动方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - + @Override public Activity getActivity() { @@ -95,7 +96,7 @@ protected void onCreate(Bundle savedInstanceState) { //UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - + private static final String[] TOPBAR_COLOR_NAMES = {"灰色", "蓝色", "黄色"}; private static final int[] TOPBAR_COLOR_RESIDS = {R.color.gray, R.color.blue,R.color.yellow}; @@ -197,7 +198,7 @@ private void editName(boolean toWindow) { @Override public void initData() {//必须调用 - + } @@ -214,20 +215,21 @@ public void initData() {//必须调用 @Override public void initEvent() {//必须调用 - + findView(R.id.llDemoMainItemDialog).setOnClickListener(this); findView(R.id.llDemoMainAlertDialog).setOnClickListener(this); - + findView(R.id.llDemoMainScanActivity).setOnClickListener(this); findView(R.id.llDemoMainSelectPictureActivity).setOnClickListener(this); findView(R.id.llDemoMainCutPictureActivity).setOnClickListener(this); findView(R.id.llDemoMainWebViewActivity).setOnClickListener(this); findView(R.id.llDemoMainEditTextInfoActivity).setOnClickListener(this); findView(R.id.llDemoMainServerSettingActivity).setOnTouchListener(this); - + findView(R.id.llDemoMainDemoActivity).setOnClickListener(this); findView(R.id.llDemoMainDemoListActivity).setOnClickListener(this); + findView(R.id.llDemoMainDemoRecyclerActivity).setOnClickListener(this); findView(R.id.llDemoMainDemoFragmentActivity).setOnClickListener(this); findView(R.id.llDemoMainDemoTabActivity).setOnClickListener(this); findView(R.id.llDemoMainDemoSQLActivity).setOnClickListener(this); @@ -235,7 +237,7 @@ public void initEvent() {//必须调用 findView(R.id.llDemoMainDemoBroadcastReceiverActivity).setOnClickListener(this); findView(R.id.llDemoMainDemoBottomWindow).setOnClickListener(this); - + findView(R.id.llDemoMainTopMenuWindow).setOnClickListener(this); findView(R.id.llDemoMainBottomMenuWindow).setOnClickListener(this); findView(R.id.llDemoMainEditTextInfoWindow).setOnClickListener(this); @@ -280,7 +282,7 @@ public void onDragBottom(boolean rightToLeft) { if (rightToLeft) { showTopMenu(); return; - } + } finish(); } @@ -327,83 +329,86 @@ public void onClick(View v) {//直接调用不会显示v被点击效果 switch (v.getId()) { case R.id.ivDemoMainHead: selectPicture(); - break; + break; case R.id.tvDemoMainHeadName: editName(true); - break; + break; + - case R.id.llDemoMainItemDialog: showItemDialog(); - break; + break; case R.id.llDemoMainAlertDialog: new AlertDialog(context, "更改颜色", "确定将导航栏颜色改为红色?", true, 0, this).show(); - break; + break; + - case R.id.llDemoMainScanActivity: toActivity(ScanActivity.createIntent(context), REQUEST_TO_CAMERA_SCAN); - break; + break; case R.id.llDemoMainSelectPictureActivity: selectPicture(); - break; + break; case R.id.llDemoMainCutPictureActivity: cutPicture(picturePath); - break; + break; case R.id.llDemoMainWebViewActivity: toActivity(WebViewActivity.createIntent(context, SettingUtil.isOnTestMode ? "测试服务器" : "正式服务器" , SettingUtil.getCurrentServerAddress())); - break; + break; case R.id.llDemoMainEditTextInfoActivity: editName(false); - break; - + break; + case R.id.llDemoMainDemoActivity: toActivity(DemoActivity.createIntent(context, 0)); - break; + break; case R.id.llDemoMainDemoListActivity: toActivity(DemoListActivity.createIntent(context, 0)); - break; + break; + case R.id.llDemoMainDemoRecyclerActivity: + toActivity(DemoRecyclerActivity.createIntent(context, 0)); + break; case R.id.llDemoMainDemoFragmentActivity: toActivity(DemoFragmentActivity.createIntent(context, 0)); - break; + break; case R.id.llDemoMainDemoTabActivity: toActivity(DemoTabActivity.createIntent(context)); - break; + break; case R.id.llDemoMainDemoSQLActivity: toActivity(DemoSQLActivity.createIntent(context)); - break; + break; case R.id.llDemoMainDemoTimeRefresherActivity: toActivity(DemoTimeRefresherActivity.createIntent(context)); - break; + break; case R.id.llDemoMainDemoBroadcastReceiverActivity: toActivity(DemoBroadcastReceiverActivity.createIntent(context)); - break; + break; case R.id.llDemoMainDemoBottomWindow: toActivity(DemoBottomWindow.createIntent(context, ""), REQUEST_TO_DEMO_BOTTOM_WINDOW, false); - break; + break; + - case R.id.llDemoMainTopMenuWindow: showTopMenu(); - break; + break; case R.id.llDemoMainBottomMenuWindow: toActivity(BottomMenuWindow.createIntent(context, TOPBAR_COLOR_NAMES) .putExtra(BottomMenuWindow.INTENT_TITLE, "选择颜色"), REQUEST_TO_BOTTOM_MENU, false); - break; + break; case R.id.llDemoMainEditTextInfoWindow: editName(true); - break; + break; case R.id.llDemoMainPlacePickerWindow: toActivity(PlacePickerWindow.createIntent(context, getPackageName(), 2), REQUEST_TO_PLACE_PICKER, false); break; case R.id.llDemoMainDatePickerWindow: toActivity(DatePickerWindow.createIntent(context, new int[]{1971, 0, 1} , TimeUtil.getDateDetail(System.currentTimeMillis())), REQUEST_TO_DATE_PICKER, false); - break; + break; case R.id.llDemoMainTimePickerWindow: toActivity(TimePickerWindow.createIntent(context, selectedTime), REQUEST_TO_TIME_PICKER, false); - break; + break; default: break; @@ -420,7 +425,7 @@ public void onClick(View v) {//直接调用不会显示v被点击效果 private static final int REQUEST_TO_EDIT_TEXT_INFO = 23; private static final int REQUEST_TO_SERVER_SETTING = 24; private static final int REQUEST_TO_DEMO_BOTTOM_WINDOW = 25; - + private static final int REQUEST_TO_TOP_MENU = 30; private static final int REQUEST_TO_BOTTOM_MENU = 31; private static final int REQUEST_TO_PLACE_PICKER = 32; @@ -468,7 +473,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { showShortToast(data.getStringExtra(DemoBottomWindow.RESULT_DATA)); } break; - + case REQUEST_TO_TOP_MENU: if (data != null) { switch (data.getIntExtra(TopMenuWindow.RESULT_POSITION, -1)) { @@ -491,7 +496,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } } break; - + case REQUEST_TO_PLACE_PICKER: if (data != null) { ArrayList placeList = data.getStringArrayListExtra(PlacePickerWindow.RESULT_PLACE_LIST); @@ -508,12 +513,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { ArrayList list = data.getIntegerArrayListExtra(DatePickerWindow.RESULT_DATE_DETAIL_LIST); if (list != null && list.size() >= 3) { - + selectedDate = new int[list.size()]; for (int i = 0; i < list.size(); i++) { selectedDate[i] = list.get(i); } - + showShortToast("选择的日期为" + selectedDate[0] + "-" + (selectedDate[1] + 1) + "-" + selectedDate[2]); } } @@ -522,12 +527,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { ArrayList list = data.getIntegerArrayListExtra(TimePickerWindow.RESULT_TIME_DETAIL_LIST); if (list != null && list.size() >= 2) { - + selectedTime = new int[list.size()]; for (int i = 0; i < list.size(); i++) { selectedTime[i] = list.get(i); } - + String minute = "" + selectedTime[1]; if (minute.length() < 2) { minute = "0" + minute; diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoRecyclerActivity.java b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoRecyclerActivity.java new file mode 100644 index 0000000..22915e5 --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoRecyclerActivity.java @@ -0,0 +1,238 @@ +/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package zblibrary.demo.DEMO; + +import java.util.ArrayList; +import java.util.List; + +import zblibrary.demo.R; +import zblibrary.demo.DEMO.DemoRecyclerAdapter.DemoRecyclerView; +import zblibrary.demo.util.TestUtil; +import zuo.biao.library.base.BaseRecyclerActivity; +import zuo.biao.library.interfaces.OnBottomDragListener; +import zuo.biao.library.model.Entry; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.widget.RecyclerView; + +/**使用方法:复制>粘贴>改名>改代码 */ +/**列表Activity示例 + * @author Lemon + * @warn 这里列表显示组件lvBaseList是GridView,如果是lvBaseList是ListView就改成ListView + * @use toActivity(DemoListActivity.createIntent(...)); + */ +public class DemoRecyclerActivity extends BaseRecyclerActivity, RecyclerView, DemoRecyclerView, DemoRecyclerAdapter> +implements OnBottomDragListener { + // private static final String TAG = "DemoListActivity"; + + //启动方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + public static final String INTENT_RANGE = "INTENT_RANGE"; + + public static final String RESULT_CLICKED_ITEM = "RESULT_CLICKED_ITEM"; + + /**启动这个Activity的Intent + * @param context + * @return + */ + public static Intent createIntent(Context context, int range) { + return new Intent(context, DemoRecyclerActivity.class).putExtra(INTENT_RANGE, range); + } + + //启动方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + @Override + public Activity getActivity() { + return this; + } + + private int range = 0; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + //TODO demo_list_activity改为你所需要的layout文件;传this是为了底部左右滑动手势 + setContentView(R.layout.demo_recycler_activity, this); + + intent = getIntent(); + range = intent.getIntExtra(INTENT_RANGE, range); + + // initCache(this);//初始化缓存,Entry替换成不带类型的类才可使用,原因看 .CacheCallBack + + //功能归类分区方法,必须调用<<<<<<<<<< + initView(); + initData(); + initEvent(); + //功能归类分区方法,必须调用>>>>>>>>>> + + onRefresh(); + } + + + //UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + @Override + public void initView() {//必须在onCreate方法内调用 + super.initView(); + + } + + @Override + public void setList(final List> list) { + //示例代码<<<<<<<<<<<<<<< + setList(new AdapterCallBack() { + + @Override + public DemoRecyclerAdapter createAdapter() { + return new DemoRecyclerAdapter(context); + } + + @Override + public void refreshAdapter() { + adapter.refresh(list); + } + }); + //示例代码>>>>>>>>>>>>>>> + } + + + //UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + + + //Data数据区(存在数据获取或处理代码,但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + @Override + public void initData() {//必须在onCreate方法内调用 + super.initData(); + //示例代码<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + tvBaseTitle.setText("" + rvBaseRecycler.getClass().getSimpleName()); + + showShortToast("range = " + range); + + //示例代码>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + } + + @Override + public void getListAsync(int page) { + showProgressDialog(R.string.loading); + + List> list = new ArrayList>(); + for (int i = 0; i < 6; i++) { + list.add(new Entry(getPictureUrl(i + 6*page), "联系人" + i + 6*page)); + } + + onLoadSucceed(page, list); + } + + /**获取图片地址,仅供测试用 + * @param userId + * @return + */ + private String getPictureUrl(int userId) { + return TestUtil.getPicture(userId % 6); + } + + //Data数据区(存在数据获取或处理代码,但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + //Event事件区(只要存在事件监听代码就是)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + @Override + public void initEvent() {//必须在onCreate方法内调用 + super.initEvent(); + //示例代码<<<<<<<<<<<<<<<<<<< + +// rvBaseRecycler.setOnItemClickListener(new OnItemClickListener() { +// @Override +// public void onItemClick(AdapterView parent, View view, int position, long id) { +// // //如果lvBaseList有headerView或footerView <<<<<<<<<<<<<<< +// // position -= lvBaseList.getHeaderViewsCount();//ListView的方法,GridView没有 +// // if (position < 0 || adapter == null || position >= adapter.getCount()) { +// // return; +// // } +// // //如果lvBaseList有headerView或footerView >>>>>>>>>>>>>>> +// +// showShortToast("选择了 " + adapter.getItem(position).getValue()); +// setResult(RESULT_OK, new Intent().putExtra(RESULT_CLICKED_ITEM, position)); +// finish(); +// } +// }); +// //示例代码>>>>>>>>>>>>>>>>>>> + } + + + + @Override + public void onDragBottom(boolean rightToLeft) { + if (rightToLeft) { + + return; + } + + finish(); + } + + + //系统自带监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + + + + + //类相关监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + + + + //类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + //系统自带监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + //Event事件区(只要存在事件监听代码就是)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + //内部类,尽量少用<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + + //内部类,尽量少用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +} \ No newline at end of file diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoRecyclerAdapter.java b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoRecyclerAdapter.java new file mode 100644 index 0000000..f2f20a3 --- /dev/null +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/DEMO/DemoRecyclerAdapter.java @@ -0,0 +1,67 @@ +package zblibrary.demo.DEMO; + +import android.app.Activity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import zblibrary.demo.DEMO.DemoRecyclerAdapter.DemoRecyclerView; +import zblibrary.demo.R; +import zuo.biao.library.base.BaseRecyclerView; +import zuo.biao.library.model.Entry; +import zuo.biao.library.util.ImageLoaderUtil; +import zuo.biao.library.util.StringUtil; + +public class DemoRecyclerAdapter extends BaseRecyclerAdapter, DemoRecyclerView> { + + public DemoRecyclerAdapter(Activity context) { + super(context); + } + + @Override + public DemoRecyclerView createView(int position, ViewGroup parent) { + return new DemoRecyclerView(context); + } + + + + public class DemoRecyclerView extends BaseRecyclerView> { + + public DemoRecyclerView(Activity context) { + super(context, R.layout.demo_view); + } + + //示例代码<<<<<<<<<<<<<<<< + public ImageView ivDemoViewHead; + public TextView tvDemoViewName; + public TextView tvDemoViewNumber; + //示例代码>>>>>>>>>>>>>>>> + @Override + public View createView(LayoutInflater inflater) { + + //示例代码<<<<<<<<<<<<<<<< + ivDemoViewHead = findView(R.id.ivDemoViewHead); + tvDemoViewName = findView(R.id.tvDemoViewName); + tvDemoViewNumber = findView(R.id.tvDemoViewNumber); + //示例代码>>>>>>>>>>>>>>>> + + return itemView; + } + + + @Override + public void bindView(Entry data){ + //示例代码<<<<<<<<<<<<<<<< + this.data = data;//这里data传进来的只有adapter内item数据,可不判空 + + ImageLoaderUtil.loadImage(ivDemoViewHead, data.getKey()); + tvDemoViewName.setText(StringUtil.getTrimedString(data.getValue())); + //示例代码>>>>>>>>>>>>>>>> + } + + } + + +} diff --git a/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/activity_fragment/AboutActivity.java b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/activity_fragment/AboutActivity.java index a96b996..21f2cda 100644 --- a/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/activity_fragment/AboutActivity.java +++ b/ZBLibrary(ADT)/ZBLibraryDemoApp/src/zblibrary/demo/activity_fragment/AboutActivity.java @@ -14,20 +14,6 @@ package zblibrary.demo.activity_fragment; -import java.io.File; - -import zblibrary.demo.R; -import zblibrary.demo.DEMO.DemoMainActivity; -import zblibrary.demo.application.DemoApplication; -import zblibrary.demo.util.Constant; -import zblibrary.demo.util.HttpRequest; -import zuo.biao.library.base.BaseActivity; -import zuo.biao.library.interfaces.OnBottomDragListener; -import zuo.biao.library.interfaces.OnHttpResponseListener; -import zuo.biao.library.ui.WebViewActivity; -import zuo.biao.library.util.CommonUtil; -import zuo.biao.library.util.DownloadUtil; -import zuo.biao.library.util.SettingUtil; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -44,6 +30,21 @@ import com.google.zxing.WriterException; import com.zxing.encoding.EncodingHandler; +import java.io.File; + +import zblibrary.demo.DEMO.DemoMainActivity; +import zblibrary.demo.R; +import zblibrary.demo.application.DemoApplication; +import zblibrary.demo.util.Constant; +import zblibrary.demo.util.HttpRequest; +import zuo.biao.library.base.BaseActivity; +import zuo.biao.library.interfaces.OnBottomDragListener; +import zuo.biao.library.interfaces.OnHttpResponseListener; +import zuo.biao.library.ui.WebViewActivity; +import zuo.biao.library.util.CommonUtil; +import zuo.biao.library.util.DownloadUtil; +import zuo.biao.library.util.SettingUtil; + /**关于界面 * @author Lemon */ @@ -83,17 +84,17 @@ protected void onCreate(Bundle savedInstanceState) { if (SettingUtil.isOnTestMode) { showShortToast("测试服务器\n" + HttpRequest.URL_BASE); } - - + + //仅测试用 HttpRequest.translate("library", 0, new OnHttpResponseListener() { - + @Override public void onHttpResponse(int requestCode, String resultJson, Exception e) { showShortToast("测试Http请求:翻译library结果为\n" + resultJson); } }); - + } //UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -105,7 +106,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) { private ImageView ivAboutQRCode; @Override public void initView() { - + ivAboutGesture = findView(R.id.ivAboutGesture); ivAboutGesture.setVisibility(SettingUtil.isFirstStart ? View.VISIBLE : View.GONE); if (SettingUtil.isFirstStart) { @@ -133,7 +134,7 @@ public void initView() { @Override public void initData() { - + tvAboutAppInfo.setText(DemoApplication.getInstance().getAppName() + "\n" + DemoApplication.getInstance().getAppVersion()); @@ -164,7 +165,7 @@ public void run() { public void run() { ivAboutQRCode.setImageBitmap(qRCodeBitmap); } - }); + }); } }); } @@ -196,7 +197,7 @@ public void run() { @Override public void initEvent() { - + findView(R.id.llAboutMainTabActivity).setOnClickListener(this); findView(R.id.llAboutZBLibraryMainActivity).setOnClickListener(this); @@ -239,7 +240,7 @@ public void onClick(View v) { case R.id.llAboutMainTabActivity: startActivity(MainTabActivity.createIntent(context).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); overridePendingTransition(R.anim.bottom_push_in, R.anim.hold); - + enterAnim = exitAnim = R.anim.null_anim; finish(); break; diff --git a/ZBLibrary(ADT)/recyclerview/.classpath b/ZBLibrary(ADT)/recyclerview/.classpath new file mode 100644 index 0000000..7bc01d9 --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ZBLibrary(ADT)/recyclerview/.project b/ZBLibrary(ADT)/recyclerview/.project new file mode 100644 index 0000000..67e61aa --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/.project @@ -0,0 +1,33 @@ + + + recyclerview + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/ZBLibrary(ADT)/recyclerview/.settings/org.eclipse.jdt.core.prefs b/ZBLibrary(ADT)/recyclerview/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ZBLibrary(ADT)/recyclerview/AndroidManifest.xml b/ZBLibrary(ADT)/recyclerview/AndroidManifest.xml new file mode 100644 index 0000000..421395f --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/ZBLibrary(ADT)/recyclerview/README.txt b/ZBLibrary(ADT)/recyclerview/README.txt new file mode 100644 index 0000000..3c9de34 --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/README.txt @@ -0,0 +1 @@ +Library Project including RecyclerView and associated utilities. diff --git a/ZBLibrary(ADT)/recyclerview/gen/android/support/v7/recyclerview/BuildConfig.java b/ZBLibrary(ADT)/recyclerview/gen/android/support/v7/recyclerview/BuildConfig.java new file mode 100644 index 0000000..e195efa --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/gen/android/support/v7/recyclerview/BuildConfig.java @@ -0,0 +1,6 @@ +/** Automatically generated file. DO NOT MODIFY */ +package android.support.v7.recyclerview; + +public final class BuildConfig { + public final static boolean DEBUG = true; +} \ No newline at end of file diff --git a/ZBLibrary(ADT)/recyclerview/gen/android/support/v7/recyclerview/R.java b/ZBLibrary(ADT)/recyclerview/gen/android/support/v7/recyclerview/R.java new file mode 100644 index 0000000..412e099 --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/gen/android/support/v7/recyclerview/R.java @@ -0,0 +1,163 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package android.support.v7.recyclerview; + +public final class R { + public static final class attr { + /** Class name of the Layout Manager to be used. +

+ The class must extend android.support.v7.widget.RecyclerView$LayoutManager + and have either a default constructor or constructor with the signature + (android.content.Context, android.util.AttributeSet, int, int). +

+ If the name starts with a '.', application package is prefixed. + Else, if the name contains a '.', the classname is assumed to be a full class name. + Else, the recycler view package name (android.support.v7.widget) is prefixed. +

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character. +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. + */ + public static int layoutManager=0x7f010000; + /**

Must be a boolean value, either "true" or "false". +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. + */ + public static int reverseLayout=0x7f010002; + /**

Must be an integer value, such as "100". +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. + */ + public static int spanCount=0x7f010001; + /**

Must be a boolean value, either "true" or "false". +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. + */ + public static int stackFromEnd=0x7f010003; + } + public static final class dimen { + /** The max amount of scroll ItemTouchHelper will trigger if dragged view is out of + RecyclerView's bounds. + */ + public static int item_touch_helper_max_drag_scroll_per_frame=0x7f020000; + public static int item_touch_helper_swipe_escape_max_velocity=0x7f020002; + public static int item_touch_helper_swipe_escape_velocity=0x7f020001; + } + public static final class id { + /** ItemTouchHelper uses this id to save a View's original elevation. + */ + public static int item_touch_helper_previous_elevation=0x7f030000; + } + public static final class styleable { + /** Attributes that can be used with a RecyclerView. +

Includes the following attributes:

+ + + + + + + + + +
AttributeDescription
{@link #RecyclerView_android_orientation android:orientation}
{@link #RecyclerView_layoutManager android.support.v7.recyclerview:layoutManager} Class name of the Layout Manager to be used.
{@link #RecyclerView_reverseLayout android.support.v7.recyclerview:reverseLayout}
{@link #RecyclerView_spanCount android.support.v7.recyclerview:spanCount}
{@link #RecyclerView_stackFromEnd android.support.v7.recyclerview:stackFromEnd}
+ @see #RecyclerView_android_orientation + @see #RecyclerView_layoutManager + @see #RecyclerView_reverseLayout + @see #RecyclerView_spanCount + @see #RecyclerView_stackFromEnd + */ + public static final int[] RecyclerView = { + 0x010100c4, 0x7f010000, 0x7f010001, 0x7f010002, + 0x7f010003 + }; + /** +

This symbol is the offset where the {@link android.R.attr#orientation} + attribute's value can be found in the {@link #RecyclerView} array. + @attr name android:orientation + */ + public static int RecyclerView_android_orientation = 0; + /** +

+ @attr description + Class name of the Layout Manager to be used. +

+ The class must extend android.support.v7.widget.RecyclerView$LayoutManager + and have either a default constructor or constructor with the signature + (android.content.Context, android.util.AttributeSet, int, int). +

+ If the name starts with a '.', application package is prefixed. + Else, if the name contains a '.', the classname is assumed to be a full class name. + Else, the recycler view package name (android.support.v7.widget) is prefixed. + + +

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character. +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. +

This is a private symbol. + @attr name android.support.v7.recyclerview:layoutManager + */ + public static int RecyclerView_layoutManager = 1; + /** +

This symbol is the offset where the {@link android.support.v7.recyclerview.R.attr#reverseLayout} + attribute's value can be found in the {@link #RecyclerView} array. + + +

Must be a boolean value, either "true" or "false". +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. + @attr name android.support.v7.recyclerview:reverseLayout + */ + public static int RecyclerView_reverseLayout = 3; + /** +

This symbol is the offset where the {@link android.support.v7.recyclerview.R.attr#spanCount} + attribute's value can be found in the {@link #RecyclerView} array. + + +

Must be an integer value, such as "100". +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. + @attr name android.support.v7.recyclerview:spanCount + */ + public static int RecyclerView_spanCount = 2; + /** +

This symbol is the offset where the {@link android.support.v7.recyclerview.R.attr#stackFromEnd} + attribute's value can be found in the {@link #RecyclerView} array. + + +

Must be a boolean value, either "true" or "false". +

This may also be a reference to a resource (in the form +"@[package:]type:name") or +theme attribute (in the form +"?[package:][type:]name") +containing a value of this type. + @attr name android.support.v7.recyclerview:stackFromEnd + */ + public static int RecyclerView_stackFromEnd = 4; + }; +} diff --git a/ZBLibrary(ADT)/recyclerview/libs/android-support-v7-recyclerview.jar b/ZBLibrary(ADT)/recyclerview/libs/android-support-v7-recyclerview.jar new file mode 100644 index 0000000..9d94070 Binary files /dev/null and b/ZBLibrary(ADT)/recyclerview/libs/android-support-v7-recyclerview.jar differ diff --git a/ZBLibrary(ADT)/recyclerview/project.properties b/ZBLibrary(ADT)/recyclerview/project.properties new file mode 100644 index 0000000..93c8c3c --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/project.properties @@ -0,0 +1,15 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-21 +android.library=true diff --git a/ZBLibrary(ADT)/recyclerview/res/values/attrs.xml b/ZBLibrary(ADT)/recyclerview/res/values/attrs.xml new file mode 100644 index 0000000..ad93ce6 --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/res/values/attrs.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZBLibrary(ADT)/recyclerview/res/values/dimens.xml b/ZBLibrary(ADT)/recyclerview/res/values/dimens.xml new file mode 100644 index 0000000..90c41b9 --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/res/values/dimens.xml @@ -0,0 +1,24 @@ + + + + + + 20dp + 120dp + 800dp + \ No newline at end of file diff --git a/ZBLibrary(ADT)/recyclerview/res/values/ids.xml b/ZBLibrary(ADT)/recyclerview/res/values/ids.xml new file mode 100644 index 0000000..fba1db4 --- /dev/null +++ b/ZBLibrary(ADT)/recyclerview/res/values/ids.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/res/values/strings.xml b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/res/values/strings.xml index 5aed677..2f82316 100755 --- a/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/res/values/strings.xml +++ b/ZBLibrary(AndroidStudio)/ZBLibrary/src/main/res/values/strings.xml @@ -2,7 +2,7 @@ 坐标标准库 - 15.0 + 15.1 我发现了一款很好用的Android快速开发框架,叫 Android-ZBLibrary ,快去GitHub上看看吧~ 返回 提示