From aaa143071a90af960d902e7fa05f9ca62abc0187 Mon Sep 17 00:00:00 2001 From: youth5201314 <1028729086@qq.com> Date: Mon, 13 Feb 2017 10:24:15 +0800 Subject: [PATCH] no message --- .gitignore | 7 + Readme.md | 89 + app/.gitignore | 1 + app/build.gradle | 27 + app/proguard-rules.pro | 17 + .../youth/xframe/ExampleInstrumentedTest.java | 26 + app/src/main/AndroidManifest.xml | 36 + app/src/main/java/com/youth/xf/App.java | 12 + .../main/java/com/youth/xf/BaseActivity.java | 49 + .../main/java/com/youth/xf/BaseFragment.java | 8 + app/src/main/java/com/youth/xf/bean/News.java | 73 + .../java/com/youth/xf/data/NewDataSource.java | 30 + .../com/youth/xf/loder/GlideImageLoader.java | 21 + .../java/com/youth/xf/ui/APIFragment.java | 26 + .../java/com/youth/xf/ui/DemoFragment.java | 68 + .../java/com/youth/xf/ui/MainActivity.java | 109 ++ .../xf/ui/adapter/MyFragmentPagerAdapter.java | 37 + .../xf/ui/adapter/StickyHeaderAdapter.java | 51 + .../xf/ui/demo/XLoadingDialogActivity.java | 55 + .../xf/ui/demo/XLoadingViewActivity.java | 78 + .../xf/ui/demo/XLoadingViewActivity2.java | 68 + .../youth/xf/ui/demo/XLogDemoActivity.java | 84 + .../xf/ui/demo/XMultiTypeAdapterActivity.java | 112 ++ .../xf/ui/demo/XPermissionDemoActivity.java | 134 ++ .../ui/demo/XRecyclerViewAdapterActivity.java | 171 ++ .../com/youth/xf/ui/demo/XToastActivity.java | 80 + .../youth/xf/view/GlideCircleTransform.java | 48 + .../youth/xf/view/GlideRoundTransform.java | 49 + .../xf/view/WrapContentHeightViewPager.java | 34 + app/src/main/res/drawable/selected_radius.xml | 6 + app/src/main/res/layout/activity_log_demo.xml | 71 + app/src/main/res/layout/activity_main.xml | 62 + .../res/layout/activity_xloading_dialog.xml | 31 + .../res/layout/activity_xloading_view.xml | 18 + .../res/layout/activity_xloading_view2.xml | 12 + .../res/layout/activity_xpermission_demo.xml | 39 + .../activity_xrecycler_view_adapter.xml | 17 + app/src/main/res/layout/activity_xtoast.xml | 50 + app/src/main/res/layout/api_fragment.xml | 11 + app/src/main/res/layout/demo_fragment.xml | 14 + app/src/main/res/layout/dome_image_item.xml | 44 + app/src/main/res/layout/dome_item.xml | 14 + app/src/main/res/layout/footer.xml | 15 + app/src/main/res/layout/header.xml | 16 + app/src/main/res/layout/header_item.xml | 8 + app/src/main/res/menu/loading.xml | 25 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes app/src/main/res/mipmap-xhdpi/currerror.png | Bin 0 -> 2082 bytes app/src/main/res/mipmap-xhdpi/error2.png | Bin 0 -> 3421 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/arrays.xml | 24 + app/src/main/res/values/colors.xml | 11 + app/src/main/res/values/dimens.xml | 6 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/values/styles.xml | 11 + .../com/youth/xframe/ExampleUnitTest.java | 17 + build.gradle | 24 + settings.gradle | 1 + xframe/.gitignore | 1 + xframe/build.gradle | 25 + xframe/proguard-rules.pro | 39 + .../youth/xframe/ExampleInstrumentedTest.java | 26 + xframe/src/main/AndroidManifest.xml | 8 + .../main/java/com/youth/xframe/XFrame.java | 93 ++ .../adapter/BaseRecyclerViewAdapter.java | 150 ++ .../xframe/adapter/XRecyclerViewAdapter.java | 293 ++++ .../com/youth/xframe/adapter/XViewHolder.java | 238 +++ .../adapter/decoration/DividerDecoration.java | 133 ++ .../adapter/decoration/SpaceDecoration.java | 107 ++ .../decoration/StickyHeaderDecoration.java | 289 ++++ .../java/com/youth/xframe/base/ICallback.java | 13 + .../java/com/youth/xframe/base/XActivity.java | 44 + .../com/youth/xframe/base/XApplication.java | 24 + .../java/com/youth/xframe/base/XFragment.java | 28 + .../com/youth/xframe/base/XImageLoader.java | 16 + .../xframe/common/NotObfuscateInterface.java | 6 + .../youth/xframe/common/XActivityStack.java | 139 ++ .../youth/xframe/entity/DateDifference.java | 54 + .../com/youth/xframe/utils/XAppUtils.java | 220 +++ .../com/youth/xframe/utils/XBitmapUtils.java | 1482 +++++++++++++++++ .../xframe/utils/XCrashHandlerUtils.java | 202 +++ .../com/youth/xframe/utils/XDateUtils.java | 719 ++++++++ .../com/youth/xframe/utils/XDensityUtils.java | 284 ++++ .../com/youth/xframe/utils/XEmptyUtils.java | 67 + .../com/youth/xframe/utils/XEncryptUtils.java | 42 + .../youth/xframe/utils/XFastBlurUtils.java | 257 +++ .../youth/xframe/utils/XFormatTimeUtils.java | 77 + .../youth/xframe/utils/XKeyboardUtils.java | 117 ++ .../com/youth/xframe/utils/XNetworkUtils.java | 357 ++++ .../youth/xframe/utils/XOutdatedUtils.java | 40 + .../youth/xframe/utils/XPreferencesUtils.java | 162 ++ .../com/youth/xframe/utils/XPrintUtils.java | 64 + .../com/youth/xframe/utils/XRegexUtils.java | 235 +++ .../youth/xframe/utils/XViewHolderUtils.java | 27 + .../youth/xframe/utils/handler/XHandler.java | 477 ++++++ .../youth/xframe/utils/log/LoggerPrinter.java | 291 ++++ .../com/youth/xframe/utils/log/Printer.java | 33 + .../java/com/youth/xframe/utils/log/XLog.java | 66 + .../youth/xframe/utils/log/XLogConfig.java | 44 + .../xframe/utils/permission/XPermission.java | 119 ++ .../xframe/utils/statusbar/XStatusBar.java | 606 +++++++ .../youth/xframe/widget/NoScrollGridView.java | 36 + .../youth/xframe/widget/NoScrollListView.java | 36 + .../youth/xframe/widget/XLoadingDialog.java | 61 + .../com/youth/xframe/widget/XLoadingView.java | 147 ++ .../com/youth/xframe/widget/XSplashView.java | 360 ++++ .../java/com/youth/xframe/widget/XToast.java | 178 ++ .../drawable-xhdpi/adapter_loading_error.png | Bin 0 -> 851 bytes .../adapter_loading_no_data.png | Bin 0 -> 1816 bytes .../res/drawable-xhdpi/xloading_empty.png | Bin 0 -> 3766 bytes .../res/drawable-xhdpi/xloading_error.png | Bin 0 -> 3988 bytes .../drawable-xhdpi/xloading_no_network.png | Bin 0 -> 3569 bytes .../main/res/drawable-xhdpi/xtoast_error.png | Bin 0 -> 436 bytes .../res/drawable-xhdpi/xtoast_frame.9.png | Bin 0 -> 2090 bytes .../main/res/drawable-xhdpi/xtoast_info.png | Bin 0 -> 1279 bytes .../res/drawable-xhdpi/xtoast_success.png | Bin 0 -> 308 bytes .../res/drawable-xhdpi/xtoast_warning.png | Bin 0 -> 1307 bytes .../main/res/drawable/loading_dialog_bg.xml | 6 + .../res/drawable/xloading_btn_selector.xml | 20 + .../src/main/res/layout/adapter_loading.xml | 33 + .../res/layout/adapter_loading_failed.xml | 32 + .../src/main/res/layout/adapter_no_more.xml | 31 + .../src/main/res/layout/xloading_dialog.xml | 29 + .../main/res/layout/xloading_empty_view.xml | 18 + .../main/res/layout/xloading_error_view.xml | 27 + .../main/res/layout/xloading_loading_view.xml | 11 + .../res/layout/xloading_no_network_view.xml | 27 + xframe/src/main/res/layout/xtoast_view.xml | 22 + xframe/src/main/res/values/attrs.xml | 10 + xframe/src/main/res/values/colors.xml | 9 + xframe/src/main/res/values/dimens.xml | 13 + xframe/src/main/res/values/ids.xml | 2 + xframe/src/main/res/values/strings.xml | 8 + xframe/src/main/res/values/styles.xml | 21 + .../com/youth/xframe/ExampleUnitTest.java | 17 + 139 files changed, 11025 insertions(+) create mode 100644 Readme.md create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/youth/xframe/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/youth/xf/App.java create mode 100644 app/src/main/java/com/youth/xf/BaseActivity.java create mode 100644 app/src/main/java/com/youth/xf/BaseFragment.java create mode 100644 app/src/main/java/com/youth/xf/bean/News.java create mode 100644 app/src/main/java/com/youth/xf/data/NewDataSource.java create mode 100644 app/src/main/java/com/youth/xf/loder/GlideImageLoader.java create mode 100644 app/src/main/java/com/youth/xf/ui/APIFragment.java create mode 100644 app/src/main/java/com/youth/xf/ui/DemoFragment.java create mode 100644 app/src/main/java/com/youth/xf/ui/MainActivity.java create mode 100644 app/src/main/java/com/youth/xf/ui/adapter/MyFragmentPagerAdapter.java create mode 100644 app/src/main/java/com/youth/xf/ui/adapter/StickyHeaderAdapter.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XLogDemoActivity.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java create mode 100644 app/src/main/java/com/youth/xf/ui/demo/XToastActivity.java create mode 100644 app/src/main/java/com/youth/xf/view/GlideCircleTransform.java create mode 100644 app/src/main/java/com/youth/xf/view/GlideRoundTransform.java create mode 100644 app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java create mode 100644 app/src/main/res/drawable/selected_radius.xml create mode 100644 app/src/main/res/layout/activity_log_demo.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/activity_xloading_dialog.xml create mode 100644 app/src/main/res/layout/activity_xloading_view.xml create mode 100644 app/src/main/res/layout/activity_xloading_view2.xml create mode 100644 app/src/main/res/layout/activity_xpermission_demo.xml create mode 100644 app/src/main/res/layout/activity_xrecycler_view_adapter.xml create mode 100644 app/src/main/res/layout/activity_xtoast.xml create mode 100644 app/src/main/res/layout/api_fragment.xml create mode 100644 app/src/main/res/layout/demo_fragment.xml create mode 100644 app/src/main/res/layout/dome_image_item.xml create mode 100644 app/src/main/res/layout/dome_item.xml create mode 100644 app/src/main/res/layout/footer.xml create mode 100644 app/src/main/res/layout/header.xml create mode 100644 app/src/main/res/layout/header_item.xml create mode 100644 app/src/main/res/menu/loading.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/currerror.png create mode 100644 app/src/main/res/mipmap-xhdpi/error2.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/values-w820dp/dimens.xml create mode 100644 app/src/main/res/values/arrays.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/youth/xframe/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 settings.gradle create mode 100644 xframe/.gitignore create mode 100644 xframe/build.gradle create mode 100644 xframe/proguard-rules.pro create mode 100644 xframe/src/androidTest/java/com/youth/xframe/ExampleInstrumentedTest.java create mode 100644 xframe/src/main/AndroidManifest.xml create mode 100644 xframe/src/main/java/com/youth/xframe/XFrame.java create mode 100644 xframe/src/main/java/com/youth/xframe/adapter/BaseRecyclerViewAdapter.java create mode 100644 xframe/src/main/java/com/youth/xframe/adapter/XRecyclerViewAdapter.java create mode 100644 xframe/src/main/java/com/youth/xframe/adapter/XViewHolder.java create mode 100644 xframe/src/main/java/com/youth/xframe/adapter/decoration/DividerDecoration.java create mode 100644 xframe/src/main/java/com/youth/xframe/adapter/decoration/SpaceDecoration.java create mode 100644 xframe/src/main/java/com/youth/xframe/adapter/decoration/StickyHeaderDecoration.java create mode 100644 xframe/src/main/java/com/youth/xframe/base/ICallback.java create mode 100644 xframe/src/main/java/com/youth/xframe/base/XActivity.java create mode 100644 xframe/src/main/java/com/youth/xframe/base/XApplication.java create mode 100644 xframe/src/main/java/com/youth/xframe/base/XFragment.java create mode 100644 xframe/src/main/java/com/youth/xframe/base/XImageLoader.java create mode 100644 xframe/src/main/java/com/youth/xframe/common/NotObfuscateInterface.java create mode 100644 xframe/src/main/java/com/youth/xframe/common/XActivityStack.java create mode 100644 xframe/src/main/java/com/youth/xframe/entity/DateDifference.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XAppUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XBitmapUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XCrashHandlerUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XDateUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XDensityUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XEmptyUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XEncryptUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XFastBlurUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XFormatTimeUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XKeyboardUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XNetworkUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XOutdatedUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XPreferencesUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XPrintUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XRegexUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/XViewHolderUtils.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/handler/XHandler.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/log/LoggerPrinter.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/log/Printer.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/log/XLog.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/log/XLogConfig.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/permission/XPermission.java create mode 100644 xframe/src/main/java/com/youth/xframe/utils/statusbar/XStatusBar.java create mode 100644 xframe/src/main/java/com/youth/xframe/widget/NoScrollGridView.java create mode 100644 xframe/src/main/java/com/youth/xframe/widget/NoScrollListView.java create mode 100644 xframe/src/main/java/com/youth/xframe/widget/XLoadingDialog.java create mode 100644 xframe/src/main/java/com/youth/xframe/widget/XLoadingView.java create mode 100644 xframe/src/main/java/com/youth/xframe/widget/XSplashView.java create mode 100644 xframe/src/main/java/com/youth/xframe/widget/XToast.java create mode 100644 xframe/src/main/res/drawable-xhdpi/adapter_loading_error.png create mode 100644 xframe/src/main/res/drawable-xhdpi/adapter_loading_no_data.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xloading_empty.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xloading_error.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xloading_no_network.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xtoast_error.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xtoast_frame.9.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xtoast_info.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xtoast_success.png create mode 100644 xframe/src/main/res/drawable-xhdpi/xtoast_warning.png create mode 100644 xframe/src/main/res/drawable/loading_dialog_bg.xml create mode 100644 xframe/src/main/res/drawable/xloading_btn_selector.xml create mode 100644 xframe/src/main/res/layout/adapter_loading.xml create mode 100644 xframe/src/main/res/layout/adapter_loading_failed.xml create mode 100644 xframe/src/main/res/layout/adapter_no_more.xml create mode 100644 xframe/src/main/res/layout/xloading_dialog.xml create mode 100644 xframe/src/main/res/layout/xloading_empty_view.xml create mode 100644 xframe/src/main/res/layout/xloading_error_view.xml create mode 100644 xframe/src/main/res/layout/xloading_loading_view.xml create mode 100644 xframe/src/main/res/layout/xloading_no_network_view.xml create mode 100644 xframe/src/main/res/layout/xtoast_view.xml create mode 100644 xframe/src/main/res/values/attrs.xml create mode 100644 xframe/src/main/res/values/colors.xml create mode 100644 xframe/src/main/res/values/dimens.xml create mode 100644 xframe/src/main/res/values/ids.xml create mode 100644 xframe/src/main/res/values/strings.xml create mode 100644 xframe/src/main/res/values/styles.xml create mode 100644 xframe/src/test/java/com/youth/xframe/ExampleUnitTest.java diff --git a/.gitignore b/.gitignore index f6b286c..fb5e46a 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,10 @@ captures/ # Keystore files *.jks +/.idea +/gradle +/gradle.properties +/gradlew +/gradlew.bat +/app/app.iml +/xframe/xframe.iml diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..0bfabaf --- /dev/null +++ b/Readme.md @@ -0,0 +1,89 @@ + +#XFrame Android快速开发框架 + +>从小的功能做起,只做必要的封装,让开发更加简单 ———— XFrame + +## XFrame简介 + +**XFrame**你可以理解成是一个Android开发的工具集合。我在写XFrame时就明确了方向,我不会去封装http、图片加载、ioc、orm 等这些听起来非常不错的想法。 +为什么呢?这些功能现在都有很强大的框架,我也做不到那么好,而且更新很快,隔段时间就有新的框架出现,每个人都有自己的选择,我不想使用者因为这个局限大家。 +我的本意是为了通过封装Android中一些的复杂操作而达到简化Android应用级开发的成本,用最少的代码实现更多的功能,我们只封装那些大部分应用必须用到但有总是增加我们繁琐的工作量。也许市面上单个功能模块有现成,而且很多!我们总是需要去挨着选择,但他们之间并不一定兼容,我们需要浪费在每个项目中的修改、拷贝、维护时间,而XFrame算是你还不错的选择对象! + +[详细文档请前往wiki](https://github.com/youth5201314/XFrame/wiki) + +## 特性 + +**XFrame**主要有这些功能: + +- [x] `XLog`:可输出漂亮容易查看的日志,支持Json、Xml、Map、List等格式输出,可全局配置 +- [x] `XLoadingView`:简单实用的页面状态统一管理 ,加载中、无网络、无数据、出错等状态的随意切换 +- [x] `XLoadingDialog`:简单实现加载等待对话框 +- [x] `XPermission`:简化Android 6.0 动态权限管理的操作 +- [x] `XRecyclerViewAdapter`:一个用于RecyclerView Adapter的开发库,包含添加Header,Footer,加载更多,加载失败,加载到底和支持多种布局 +* `XUpdateApp`:检测更新App,后台下载,应用自动安装 +* `XRouter`:组件化路由框架 +* `XCache`:缓存 +* `XCrash`:异常崩溃统一管理 +* `XTabPage`:Tab+Fragment快速实现 +* `XWebView`:WebView UI与常见的功能封装 +- [x] `XStatusBar`:实现沉浸式状态栏 +- [x] `XSplashView`:闪屏页或者广告页 +- [x] `XToast`:简单的吐司使用 +- [x] `Utils工具类集合`:内置常用工具类 +- [x] `自定义View`:内置常用自定义控件 + + +## Thanks + + 感谢以下开源项目的作者,本项目中有些功能受你们项目灵感的启发,有些功能也用到你们的代码完成。对此如果有什么意见请与我联系!再次感谢! + +- [orhanobut/logger](https://github.com/orhanobut/logger) +- [laobie/StatusBarUtil](https://github.com/laobie/StatusBarUtil) +- [GrenderG/Toasty](https://github.com/GrenderG/Toasty) +- [Blankj/AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode) +- [l123456789jy/Lazy](https://github.com/l123456789jy/Lazy) +- [Jude95/EasyRecyclerView](https://github.com/Jude95/EasyRecyclerView) +- [jkyeo/Android-SplashView](https://github.com/jkyeo/Android-SplashView) +- [czy1121/loadinglayout](https://github.com/czy1121/loadinglayout) + + + + + + + + + + + + + + + + + + + + + + + + + +## License + +``` +Copyright 2017 youth5201314 + +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. +``` \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..ea4a050 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "com.youth.xf" + minSdkVersion 14 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + compile project(':xframe') + compile 'com.android.support:design:25+' + compile 'com.youth.banner:banner:+' + compile 'com.github.bumptech.glide:glide:3.7.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..a8d49fd --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\android\android-sdk-windows/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/youth/xframe/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/youth/xframe/ExampleInstrumentedTest.java new file mode 100644 index 0000000..be894ba --- /dev/null +++ b/app/src/androidTest/java/com/youth/xframe/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.youth.xframe; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.youth.baseframe", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..51c0223 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/youth/xf/App.java b/app/src/main/java/com/youth/xf/App.java new file mode 100644 index 0000000..8b723ba --- /dev/null +++ b/app/src/main/java/com/youth/xf/App.java @@ -0,0 +1,12 @@ +package com.youth.xf; + +import com.youth.xframe.base.XApplication; +import com.youth.xframe.XFrame; + +public class App extends XApplication { + @Override + public void onCreate() { + super.onCreate(); + XFrame.initXLog().setTag("Test"); + } +} diff --git a/app/src/main/java/com/youth/xf/BaseActivity.java b/app/src/main/java/com/youth/xf/BaseActivity.java new file mode 100644 index 0000000..9e61f99 --- /dev/null +++ b/app/src/main/java/com/youth/xf/BaseActivity.java @@ -0,0 +1,49 @@ +package com.youth.xf; + +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.MenuItem; + +import com.youth.xframe.base.XActivity; +import com.youth.xframe.utils.statusbar.XStatusBar; + +/** + * 必须继承XActivity,你也可以每个都继承XActivity,这里进行再次封装是为了便于你维护和增加你需要的方法 + */ +public abstract class BaseActivity extends XActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + String title=getIntent().getStringExtra("title"); + if (TextUtils.isEmpty(title)) + title=getString(R.string.app_name); + ActionBar bar=getSupportActionBar(); + bar.setTitle(title); + if (!title.equals(getString(R.string.app_name))) + bar.setDisplayHomeAsUpEnabled(true); + } + + @Override + public void setContentView(int layoutResID) { + super.setContentView(layoutResID); + setStatusBar(); + } + + protected void setStatusBar() { + XStatusBar.setColor(this, getResources().getColor(R.color.colorPrimary)); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) + { + if(item.getItemId() == android.R.id.home) + { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/com/youth/xf/BaseFragment.java b/app/src/main/java/com/youth/xf/BaseFragment.java new file mode 100644 index 0000000..65c1e6e --- /dev/null +++ b/app/src/main/java/com/youth/xf/BaseFragment.java @@ -0,0 +1,8 @@ +package com.youth.xf; + + +import com.youth.xframe.base.XFragment; + + +public abstract class BaseFragment extends XFragment { +} diff --git a/app/src/main/java/com/youth/xf/bean/News.java b/app/src/main/java/com/youth/xf/bean/News.java new file mode 100644 index 0000000..d9da606 --- /dev/null +++ b/app/src/main/java/com/youth/xf/bean/News.java @@ -0,0 +1,73 @@ +package com.youth.xf.bean; + +/** + * Created by Administrator on 2017/1/17. + */ + +public class News { + /** 单图布局样式 */ + public static final int TYPE_SINGLE_PICTURE = 0; + /** 无图布局样式 */ + public static final int TYPE_NONE_PICTURE = 1; + + private int newsType; + private String title; + private String imageUrl; + private String author; + private String time; + + public News(int newsType, String title, String imageUrl, String author, String time) { + this.newsType = newsType; + this.title = title; + this.imageUrl = imageUrl; + this.author = author; + this.time = time; + } + + public News(int newsType, String title, String author, String time) { + this.newsType = newsType; + this.title = title; + this.author = author; + this.time = time; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public int getNewsType() { + return newsType; + } + + public void setNewsType(int newsType) { + this.newsType = newsType; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/app/src/main/java/com/youth/xf/data/NewDataSource.java b/app/src/main/java/com/youth/xf/data/NewDataSource.java new file mode 100644 index 0000000..3158974 --- /dev/null +++ b/app/src/main/java/com/youth/xf/data/NewDataSource.java @@ -0,0 +1,30 @@ +package com.youth.xf.data; + +import com.youth.xf.bean.News; + +import java.util.ArrayList; + +public class NewDataSource { + private static ArrayList newsList; + + //测试数据 + public static ArrayList getNewsList(){ + if(null==newsList || newsList.isEmpty()){ + newsList = new ArrayList<>(); + newsList.add(new News(News.TYPE_SINGLE_PICTURE,"智能手机行业正处于关键转折点,下一战场会在哪里?","https://pic.36krcnd.com/avatar/201701/17062818/1ucsedy4pdb4aqyu.jpg!heading","缪定纯•明星公司","58分钟前")); + newsList.add(new News(News.TYPE_NONE_PICTURE,"创始团队如何保持对公司的控制权?Snapchat这里可能有一份指南","36kr","2017.02.04")); + newsList.add(new News(News.TYPE_SINGLE_PICTURE,"创投机构回应上海政府风投补偿:返税意义更大","http://n.sinaimg.cn/tech/transform/20160126/KR43-fxnuvxc1994221.jpg","投资,职场","2017-01-16 10:36")); + newsList.add(new News(News.TYPE_NONE_PICTURE,"上海新规:天使投资有损失可获补偿 最高补六成","段旭","2017.02.04")); + newsList.add(new News(News.TYPE_SINGLE_PICTURE,"马云说新零售是在拯救线下 实业大佬会同意吗","https://pic.36krcnd.com/avatar/201701/12073251/vw1wo7bw0l73j8zp.jpg","早期项目","2017-01-16 10:36 ")); + newsList.add(new News(News.TYPE_NONE_PICTURE,"中国万吨巡洋舰开始下饺子,俄海军却至少还要等十年","译东西","2017.02.04")); + newsList.add(new News(News.TYPE_NONE_PICTURE,"高管集体离职致Twitter股价开盘跳水逾6%","社交媒体","2016.02.04")); + newsList.add(new News(News.TYPE_SINGLE_PICTURE,"传格力为推自家手机与门禁联动 员工不买难进门","http://p2.qhimg.com/t019db1294a2e7eb1db.jpg?size=600x400","前沿科技","2017-01-16 10:36")); + newsList.add(new News(News.TYPE_SINGLE_PICTURE,"安检繁琐无用?来看看这些缴获的违禁品","http://p9.qhimg.com/t01c2084745dc313fd1.jpg","投资,职场","2013.02.04")); + newsList.add(new News(News.TYPE_NONE_PICTURE,"清华控股将收购两家半导体制造公司","36kr","2017.02.04")); + newsList.add(new News(News.TYPE_SINGLE_PICTURE,"雷军称小米今年目标破千亿,是实力还是吹牛皮?","http://p7.qhimg.com/t0139528269ae1ac5a0.jpg","前沿科技","2017-01-16 10:36")); + newsList.add(new News(News.TYPE_NONE_PICTURE,"平安银行陷年终奖风波 最悲伤年终奖——1.5元","社交媒体","2017.01.04")); + newsList.add(new News(News.TYPE_SINGLE_PICTURE,"人工智能会取代人类?别担心,你想多了","http://p7.qhimg.com/t01e82f909e7c2c350c.jpg","36kr","2017.02.04")); + } + return newsList; + } +} diff --git a/app/src/main/java/com/youth/xf/loder/GlideImageLoader.java b/app/src/main/java/com/youth/xf/loder/GlideImageLoader.java new file mode 100644 index 0000000..7561f10 --- /dev/null +++ b/app/src/main/java/com/youth/xf/loder/GlideImageLoader.java @@ -0,0 +1,21 @@ +package com.youth.xf.loder; + +import android.content.Context; +import android.net.Uri; +import android.widget.ImageView; + +import com.bumptech.glide.Glide; +import com.youth.banner.loader.ImageLoader; +import com.youth.xframe.XFrame; + + +public class GlideImageLoader extends ImageLoader { + @Override + public void displayImage(Context context, Object path, ImageView imageView) { + //具体方法内容自己去选择,次方法是为了减少banner过多的依赖第三方包,所以将这个权限开放给使用者去选择 + Glide.with(XFrame.getContext()) + .load(path) + .crossFade() + .into(imageView); + } +} diff --git a/app/src/main/java/com/youth/xf/ui/APIFragment.java b/app/src/main/java/com/youth/xf/ui/APIFragment.java new file mode 100644 index 0000000..8a13897 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/APIFragment.java @@ -0,0 +1,26 @@ +package com.youth.xf.ui; + +import android.os.Bundle; +import android.widget.ListView; + +import com.youth.xf.BaseFragment; +import com.youth.xf.R; +import com.youth.xframe.widget.XLoadingView; + + +public class APIFragment extends BaseFragment { + + @Override + public int getLayoutId() { + return R.layout.api_fragment; + } + + @Override + public void initData(Bundle savedInstanceState) { + + } + + @Override + public void initView() { + } +} \ No newline at end of file diff --git a/app/src/main/java/com/youth/xf/ui/DemoFragment.java b/app/src/main/java/com/youth/xf/ui/DemoFragment.java new file mode 100644 index 0000000..a8a36d7 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/DemoFragment.java @@ -0,0 +1,68 @@ +package com.youth.xf.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; + +import com.youth.xf.BaseFragment; +import com.youth.xf.R; +import com.youth.xf.ui.demo.XLoadingDialogActivity; +import com.youth.xf.ui.demo.XLoadingViewActivity; +import com.youth.xf.ui.demo.XLogDemoActivity; +import com.youth.xf.ui.demo.XPermissionDemoActivity; +import com.youth.xf.ui.demo.XRecyclerViewAdapterActivity; +import com.youth.xf.ui.demo.XToastActivity; +import com.youth.xframe.widget.NoScrollListView; +import com.youth.xframe.widget.XToast; + + +public class DemoFragment extends BaseFragment implements AdapterView.OnItemClickListener { + NoScrollListView listView; + String[] demo; + + @Override + public int getLayoutId() { + return R.layout.demo_fragment; + } + + @Override + public void initData(Bundle savedInstanceState) { + demo=getResources().getStringArray(R.array.demo_list); + } + + @Override + public void initView() { + listView= (NoScrollListView) getView().findViewById(R.id.demoList); + listView.setOnItemClickListener(this); + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Intent intent=new Intent(); + switch (position){ + case 0: + intent.setClass(getActivity(),XLogDemoActivity.class); + break; + case 1: + intent.setClass(getActivity(),XPermissionDemoActivity.class); + break; + case 2: + intent.setClass(getActivity(),XRecyclerViewAdapterActivity.class); + break; + case 3: + intent.setClass(getActivity(),XLoadingDialogActivity.class); + break; + case 4: + intent.setClass(getActivity(),XToastActivity.class); + break; + case 5: + intent.setClass(getActivity(),XLoadingViewActivity.class); + break; + } + intent.putExtra("title",demo[position]); + startActivity(intent); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/youth/xf/ui/MainActivity.java b/app/src/main/java/com/youth/xf/ui/MainActivity.java new file mode 100644 index 0000000..be34e7b --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/MainActivity.java @@ -0,0 +1,109 @@ +package com.youth.xf.ui; + +import android.os.Bundle; +import android.os.Handler; +import android.support.design.widget.AppBarLayout; +import android.support.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.widget.SwipeRefreshLayout; + +import com.youth.banner.Banner; +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xf.loder.GlideImageLoader; +import com.youth.xf.ui.adapter.MyFragmentPagerAdapter; +import com.youth.xf.view.WrapContentHeightViewPager; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public class MainActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener { + static final int REFRESH_COMPLETE = 0X1112; + private List fragments; + private String[] titles = new String[]{"Demo", "API"}; + Banner banner; + AppBarLayout appBarLayout; + SwipeRefreshLayout mSwipeLayout; + TabLayout tabLayout; + MyFragmentPagerAdapter adapter; + WrapContentHeightViewPager viewPager; + static List urls; + private Handler mHandler = new Handler() { + public void handleMessage(android.os.Message msg) { + switch (msg.what) { + case REFRESH_COMPLETE: + String[] urls = getResources().getStringArray(R.array.url4); + List list = Arrays.asList(urls); + List arrayList = new ArrayList(list); + banner.update(arrayList); + mSwipeLayout.setRefreshing(false); + break; + } + } + }; + + @Override + public int getLayoutId() { + return R.layout.activity_main; + } + @Override + public void initData(Bundle savedInstanceState) { + String[] url=getResources().getStringArray(R.array.url); + List list= Arrays.asList(url); + urls=new ArrayList(list); + fragments=new ArrayList<>(); + fragments.add(new DemoFragment()); + fragments.add(new APIFragment()); + } + + @Override + public void initView() { + mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); + banner = (Banner) findViewById(R.id.banner); + appBarLayout = (AppBarLayout) findViewById(R.id.appbar); + tabLayout = (TabLayout) findViewById(R.id.tabLayout); + viewPager = (WrapContentHeightViewPager) findViewById(R.id.viewPager); + + banner.setImages(urls).setImageLoader(new GlideImageLoader()).start(); + + tabLayout.addTab(tabLayout.newTab().setText(titles[0])); + tabLayout.addTab(tabLayout.newTab().setText(titles[1])); + viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),fragments,titles)); + tabLayout.setupWithViewPager(viewPager); + + mSwipeLayout.setOnRefreshListener(this); + mSwipeLayout.setColorSchemeResources(R.color.main_color); + appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { + @Override + public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { + if (verticalOffset >= 0) { + mSwipeLayout.setEnabled(true); + } else { + mSwipeLayout.setEnabled(false); + } + } + }); + } + + @Override + public void onRefresh() { + mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000); + } + + @Override + protected void onStart() { + super.onStart(); + //开始轮播 + banner.startAutoPlay(); + } + + @Override + protected void onStop() { + super.onStop(); + //结束轮播 + banner.stopAutoPlay(); + } + +} diff --git a/app/src/main/java/com/youth/xf/ui/adapter/MyFragmentPagerAdapter.java b/app/src/main/java/com/youth/xf/ui/adapter/MyFragmentPagerAdapter.java new file mode 100644 index 0000000..f0e4620 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/adapter/MyFragmentPagerAdapter.java @@ -0,0 +1,37 @@ +package com.youth.xf.ui.adapter; + +import android.content.Context; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; + +import java.util.List; + + +public class MyFragmentPagerAdapter extends FragmentPagerAdapter { + private List fragments; + private String[] titles; + + public MyFragmentPagerAdapter(FragmentManager fm, List fragments,String[] titles) { + super(fm); + this.fragments = fragments; + this.titles = titles; + } + + @Override + public Fragment getItem(int position) { + return fragments.get(position); + } + + @Override + public int getCount() { + return titles.length; + } + + //此方法用来显示tab上的名字 + @Override + public CharSequence getPageTitle(int position) { + return titles[position % titles.length]; + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/youth/xf/ui/adapter/StickyHeaderAdapter.java b/app/src/main/java/com/youth/xf/ui/adapter/StickyHeaderAdapter.java new file mode 100644 index 0000000..e6b6b20 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/adapter/StickyHeaderAdapter.java @@ -0,0 +1,51 @@ + + +package com.youth.xf.ui.adapter; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.youth.xf.R; +import com.youth.xframe.adapter.decoration.StickyHeaderDecoration; + + +/** + * 悬浮headerAdapter + */ +public class StickyHeaderAdapter implements StickyHeaderDecoration.IStickyHeaderAdapter { + + private LayoutInflater mInflater; + + public StickyHeaderAdapter(Context context) { + mInflater = LayoutInflater.from(context); + } + + @Override + public long getHeaderId(int position) { + return position / 3; + } + + @Override + public HeaderHolder onCreateHeaderViewHolder(ViewGroup parent) { + final View view = mInflater.inflate(R.layout.header_item, parent, false); + return new HeaderHolder(view); + } + + @Override + public void onBindHeaderViewHolder(HeaderHolder viewholder, int position) { + viewholder.header.setText("第"+getHeaderId(position)+"组"); + } + + class HeaderHolder extends RecyclerView.ViewHolder { + public TextView header; + + public HeaderHolder(View itemView) { + super(itemView); + header = (TextView) itemView; + } + } +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java new file mode 100644 index 0000000..06dab83 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java @@ -0,0 +1,55 @@ +package com.youth.xf.ui.demo; + +import android.os.Handler; +import android.os.Message; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xframe.widget.XLoadingDialog; + +public class XLoadingDialogActivity extends BaseActivity { + private Handler handler=new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + XLoadingDialog.with(getApplicationContext()).dismiss(); + } + }; + + @Override + public int getLayoutId() { + return R.layout.activity_xloading_dialog; + } + + @Override + public void initData(Bundle savedInstanceState) { + + } + + @Override + public void initView() { + + } + + public void show(View view) { + switch (view.getId()){ + case R.id.loading1: + XLoadingDialog.with(this).show(); + break; + case R.id.loading2: + Toast.makeText(this,"3秒后自动取消",Toast.LENGTH_SHORT).show(); + XLoadingDialog.with(this).setCanceled(false).show(); + handler.sendEmptyMessageDelayed(1,3000); + break; + case R.id.loading3: + XLoadingDialog.with(this).setMessage("我正在加载中...").show(); + break; + } + + + } +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java new file mode 100644 index 0000000..577c9c6 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java @@ -0,0 +1,78 @@ +package com.youth.xf.ui.demo; + +import android.content.Intent; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Toast; + +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xframe.widget.XLoadingView; +import com.youth.xframe.widget.XToast; + +public class XLoadingViewActivity extends BaseActivity { + + + XLoadingView xLoadingView; + + @Override + public int getLayoutId() { + return R.layout.activity_xloading_view; + } + + @Override + public void initData(Bundle savedInstanceState) { + + } + + @Override + public void initView() { + //包裹并替换内容元素:这种方法不一定兼容各种场景,如果不行请用第二种方法 + xLoadingView = XLoadingView.wrap(this); + xLoadingView.setOnRetryClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + XToast.success("重新加载"); + xLoadingView.showLoading(); + } + }); + } + + public void show(View view){ + //第二种使用方法 + startActivity(new Intent(this,XLoadingViewActivity2.class)); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_empty: + xLoadingView.showEmpty(); + return true; + case R.id.action_loading: + xLoadingView.showLoading(); + return true; + case R.id.action_content: + xLoadingView.showContent(); + return true; + case R.id.action_error: + xLoadingView.showError(); + return true; + case R.id.action_network_error: + xLoadingView.showNoNetwork(); + return true; + case android.R.id.home: + finish(); + return true; + } + return false; + } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.loading, menu); + return true; + } + +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java new file mode 100644 index 0000000..848eea5 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java @@ -0,0 +1,68 @@ +package com.youth.xf.ui.demo; + +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xframe.widget.XLoadingView; +import com.youth.xframe.widget.XToast; + +public class XLoadingViewActivity2 extends BaseActivity { + + XLoadingView xLoadingView; + + @Override + public int getLayoutId() { + return R.layout.activity_xloading_view2; + } + + @Override + public void initData(Bundle savedInstanceState) { + + } + + @Override + public void initView() { + //第二种方法: + xLoadingView = (XLoadingView) findViewById(R.id.xloading_view); + xLoadingView.setOnRetryClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + XToast.success("重新加载"); + xLoadingView.showLoading(); + } + }); + } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_empty: + xLoadingView.showEmpty(); + return true; + case R.id.action_loading: + xLoadingView.showLoading(); + return true; + case R.id.action_content: + xLoadingView.showContent(); + return true; + case R.id.action_error: + xLoadingView.showError(); + return true; + case R.id.action_network_error: + xLoadingView.showNoNetwork(); + return true; + case android.R.id.home: + finish(); + return true; + } + return false; + } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.loading, menu); + return true; + } +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XLogDemoActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XLogDemoActivity.java new file mode 100644 index 0000000..53fd7b4 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XLogDemoActivity.java @@ -0,0 +1,84 @@ +package com.youth.xf.ui.demo; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xframe.utils.log.XLog; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class XLogDemoActivity extends BaseActivity implements View.OnClickListener { + String json="{ \"success\": true, \"reason\": \"\", \"data\": [ { \"time\": \"2016-04-26 00:21:26\", \"context\": \"到潍坊市【潍坊转运中心】\" }, { \"time\": \"2016-04-25 18:16:34\", \"context\": \"威海市【威海集散仓】,正发往【潍坊转运中心】\" }, { \"time\": \"2016-04-25 18:15:42\", \"context\": \"到威海市【威海集散仓】\" }, { \"time\": \"2016-04-25 15:16:00\", \"context\": \"威海市【荣成】,正发往【威海集散仓】\" }, { \"time\": \"2016-04-25 15:15:27\", \"context\": \"威海市【荣成】,【林波/13863000310】已揽收\" } ], \"status\": 3, \"exname\": \"huitongkuaidi\", \"ico\": \"http://www.kuaidi.com/data/upload/201407/htky_logo.gif\", \"phone\": \"400-956-5656\", \"url\": \"http://www.800bestex.com\", \"nu\": \"70186506140478\", \"company\": \"百世汇通\" }"; + String xml="穿衣较冷穿衣指数建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。洗车较适宜洗车指数较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。旅游适宜旅游指数天气较好,温度适宜,是个好天气哦。这样的天气适宜旅游,您可以尽情地享受大自然的风光。感冒易发感冒指数昼夜温差很大,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。运动较适宜运动指数天气较好,但考虑气温较低,推荐您进行室内运动,若户外适当增减衣物并注意防晒。紫外线强度中等紫外线强度指数属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。"; + List list=new ArrayList<>(); + Map map=new HashMap<>(); + Button button; + Button button2; + Button button3; + Button button5; + Button button4; + TextView textView; + + @Override + public int getLayoutId() { + return R.layout.activity_log_demo; + } + + @Override + public void initData(Bundle savedInstanceState) { + list.add("list数据 测试一"); + list.add("list数据 测试二"); + + map.put("name","王兴春"); + map.put("job","Android工程师"); + } + + @Override + public void initView() { + button = (Button) findViewById(R.id.button); + button2 = (Button) findViewById(R.id.button2); + button3 = (Button) findViewById(R.id.button3); + button5 = (Button) findViewById(R.id.button5); + button4 = (Button) findViewById(R.id.button4); + textView = (TextView) findViewById(R.id.textView); + button.setOnClickListener(this); + button2.setOnClickListener(this); + button3.setOnClickListener(this); + button4.setOnClickListener(this); + button5.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + switch (v.getId()){ + case R.id.button: + XLog.v("xlog用法展示"); + XLog.d("xlog用法展示"); + XLog.e("xlog用法展示"); + XLog.i("xlog用法展示"); + XLog.w("xlog用法展示"); + XLog.wtf("xlog用法展示"); + break; + case R.id.button2: + XLog.list(list); + break; + case R.id.button3: + XLog.map(map); + break; + case R.id.button4: + XLog.json(json); + break; + case R.id.button5: + XLog.xml(xml); + break; + } + textView.setText(XLog.getFormatLog()); + } +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java new file mode 100644 index 0000000..ba6dbf3 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java @@ -0,0 +1,112 @@ +package com.youth.xf.ui.demo; + +import android.graphics.Color; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.NonNull; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xf.bean.News; +import com.youth.xf.data.NewDataSource; +import com.youth.xf.ui.adapter.StickyHeaderAdapter; +import com.youth.xf.view.GlideCircleTransform; +import com.youth.xframe.XFrame; +import com.youth.xframe.adapter.XRecyclerViewAdapter; +import com.youth.xframe.adapter.XViewHolder; +import com.youth.xframe.adapter.decoration.DividerDecoration; +import com.youth.xframe.adapter.decoration.SpaceDecoration; +import com.youth.xframe.adapter.decoration.StickyHeaderDecoration; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class XMultiTypeAdapterActivity extends BaseActivity { + + @Override + public int getLayoutId() { + return R.layout.activity_xrecycler_view_adapter; + } + + @Override + public void initData(Bundle savedInstanceState) { + } + + @Override + public void initView() { + SwipeRefreshLayout mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); + mSwipeLayout.setEnabled(false); + RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); + recyclerView.addItemDecoration(new DividerDecoration(Color.parseColor("#f2f2f2"),15)); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + + final MultiTypeAdapter adapter = new MultiTypeAdapter(recyclerView, NewDataSource.getNewsList()); + recyclerView.setAdapter(adapter); + + // StickyHeader + StickyHeaderDecoration decoration = new StickyHeaderDecoration(new StickyHeaderAdapter(this)); + decoration.setIncludeHeader(false); + recyclerView.addItemDecoration(decoration); + + adapter.setOnItemClickListener(new XRecyclerViewAdapter.OnItemClickListener() { + @Override + public void onItemClick(View v, int position) { + //修改局部item的数据,点击那个修改哪个 + int random = new Random().nextInt(9); + News news=NewDataSource.getNewsList().get(random); + adapter.replace(position,news); + } + }); + } + + class MultiTypeAdapter extends XRecyclerViewAdapter { + + public MultiTypeAdapter(@NonNull RecyclerView mRecyclerView, List dataLists) { + super(mRecyclerView, dataLists); + } + + @Override + public int getItemLayoutResId(News data, int position) { + int layoutResId = -1; + switch (data.getNewsType()){ + case News.TYPE_NONE_PICTURE: + layoutResId = R.layout.dome_item; + break; + case News.TYPE_SINGLE_PICTURE: + layoutResId = R.layout.dome_image_item; + break; + } + return layoutResId; + } + + @Override + public void bindData(XViewHolder holder, News data, int position) { + switch (data.getNewsType()){ + case News.TYPE_NONE_PICTURE: + holder.setText(R.id.text, data.getTitle()); + break; + case News.TYPE_SINGLE_PICTURE: + holder.setText(R.id.newTitle, data.getTitle()) + .setText(R.id.newAuthor,data.getAuthor()) + .setText(R.id.newTime,data.getTime()); + ImageView view=holder.getView(R.id.newImage); + Glide.with(XFrame.getContext()) + .load(data.getImageUrl()) + .crossFade() + .transform(new GlideCircleTransform(XFrame.getContext())) + .into(view); + break; + } + } + } +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java new file mode 100644 index 0000000..471f791 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java @@ -0,0 +1,134 @@ +package com.youth.xf.ui.demo; + +import android.Manifest; +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.provider.MediaStore; +import android.provider.Settings; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xf.ui.MainActivity; +import com.youth.xframe.utils.permission.XPermission; + +import java.util.Calendar; + +/** + * 使用方法: + 以拨打电话为例 + 1、首先AndroidManifest中配置必要的权限 + + 2、继承XActivity + 3、调用工具类方法 + XPermission.requestPermissions(Context context, int requestCode, String[] permissions, OnPermissionListener listener) + 这里主要注意这个Context必需是一个Activity + 如果在Activity中可以传this; + 如果在Fragment中传getActivity(); + 如果在View中传getContext(); + */ +public class XPermissionDemoActivity extends BaseActivity implements View.OnClickListener { + private Button button1,button2,button3; + @Override + public int getLayoutId() { + return R.layout.activity_xpermission_demo; + } + + @Override + public void initData(Bundle savedInstanceState) { + } + + @Override + public void initView() { + button1 = (Button) findViewById(R.id.button1); + button2 = (Button) findViewById(R.id.button2); + button3 = (Button) findViewById(R.id.button3); + button1.setOnClickListener(this); + button2.setOnClickListener(this); + button3.setOnClickListener(this); + } + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.button1: + doCallPhone(); + break; + case R.id.button2: + doCamera(); + break; + case R.id.button3: + sendPermission(); + break; + + } + } + + /** + * 拨打电话 + */ + private void doCallPhone() { + XPermission.requestPermissions(this, 100, new String[]{Manifest.permission + .CALL_PHONE}, new XPermission.OnPermissionListener() { + @Override + public void onPermissionGranted() { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_CALL); + intent.setData(Uri.parse("tel:18682555854")); + startActivity(intent); + } + + @Override + public void onPermissionDenied() { + XPermission.showTipsDialog(XPermissionDemoActivity.this); + } + }); + } + + /** + * 照相 + */ + private void doCamera() { + XPermission.requestPermissions(this, 101, new String[]{Manifest.permission + .CAMERA}, new XPermission.OnPermissionListener() { + @Override + public void onPermissionGranted() { + Intent intent = new Intent(); + intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); + startActivity(intent); + } + + @Override + public void onPermissionDenied() { + XPermission.showTipsDialog(XPermissionDemoActivity.this); + } + }); + } + /** + * 多个权限 + */ + private void sendPermission() { + XPermission.requestPermissions(this, 102, new String[]{ + Manifest.permission.READ_CONTACTS, + Manifest.permission.RECEIVE_SMS, + Manifest.permission.WRITE_CONTACTS + }, new XPermission.OnPermissionListener() { + @Override + public void onPermissionGranted() { + Toast.makeText(getApplication(),"申请成功!",Toast.LENGTH_SHORT).show(); + } + + @Override + public void onPermissionDenied() { + XPermission.showTipsDialog(XPermissionDemoActivity.this); + } + }); + } +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java new file mode 100644 index 0000000..ccdbf0b --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java @@ -0,0 +1,171 @@ +package com.youth.xf.ui.demo; + +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.StaggeredGridLayoutManager; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.util.Util; +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xf.bean.News; +import com.youth.xframe.XFrame; +import com.youth.xframe.adapter.XRecyclerViewAdapter; +import com.youth.xframe.adapter.XViewHolder; +import com.youth.xframe.adapter.decoration.DividerDecoration; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Random; + +public class XRecyclerViewAdapterActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener { + + private List datas; + private TestAdapter adapter; + private RecyclerView recyclerView; + private SwipeRefreshLayout mSwipeLayout; + private Handler mHandler = new Handler(); + + @Override + public int getLayoutId() { + return R.layout.activity_xrecycler_view_adapter; + } + + @Override + public void initData(Bundle savedInstanceState) { + datas = new ArrayList<>(); + for (int i = 1; i <= 15; i++) { + datas.add("第 " + i + " 个"); + } + } + + @Override + public void initView() { + mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); + recyclerView = (RecyclerView) findViewById(R.id.recyclerView); + mSwipeLayout.setOnRefreshListener(this); + mSwipeLayout.setColorSchemeResources(R.color.main_color); + + //添加分割线 + recyclerView.addItemDecoration(new DividerDecoration(Color.parseColor("#C4C4C4"),1)); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); +// recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); +// recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); + + adapter = new TestAdapter(recyclerView, datas); + //添加header,footer + final View headerView = LayoutInflater.from(this).inflate(R.layout.header, recyclerView, false); + final View footerView = LayoutInflater.from(this).inflate(R.layout.footer, recyclerView, false); + adapter.addHeaderView(headerView); + adapter.addFooterView(footerView); + //点击事件 + adapter.setOnItemClickListener(new XRecyclerViewAdapter.OnItemClickListener() { + @Override + public void onItemClick(View v, int position) { + Toast.makeText(getApplication(), "position:" + position, Toast.LENGTH_SHORT).show(); + } + }); + headerView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(XRecyclerViewAdapterActivity.this,XMultiTypeAdapterActivity.class) + .putExtra("title","多布局使用+StickyHeader")); + + } + }); + footerView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(getApplication(), "移除footer", Toast.LENGTH_SHORT).show(); + adapter.removeFooterView(footerView); + } + }); + + adapter.isLoadMore(true);//开启加载更多功能,默认关闭 + + adapter.setOnLoadMoreListener(new XRecyclerViewAdapter.OnLoadMoreListener() { + @Override + public void onRetry() {//加载失败,重新加载回调方法 + load(); + } + + @Override + public void onLoadMore() {//加载更多回调方法 + load(); + } + }); + + recyclerView.setAdapter(adapter); + } + public void load() { + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + //模拟几种错误情况和正确情况 + int random = new Random().nextInt(10); + if (random <3 ) { + adapter.showLoadError();//显示加载错误 + } else if (random >=3 && random < 6) { + adapter.showLoadComplete();//没有更多数据了 + } else{ + adapter.addAll(getDatas("新增加"));//加载更多 + } +// adapter.addAll(getDatas("新增加"));//加载更多 + } + }, 2000); + } + + public List getDatas(String str) { + List datas = new ArrayList<>(); + int random = new Random().nextInt(10); + for (int i = 1; i <= random; i++) { + datas.add(str+" 第 " + i + " 个"); + } + Log.e("--",str+" "+datas.size()); + return datas; + } + + @Override + public void onRefresh() { + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + adapter.setDataLists(getDatas("刷新")); + mSwipeLayout.setRefreshing(false); + } + }, 2000); + } + + + //单一类型adapter + class TestAdapter extends XRecyclerViewAdapter { + + public TestAdapter(RecyclerView recyclerView, List datas) { + super(recyclerView, datas, R.layout.dome_item); + } + + @Override + public void bindData(XViewHolder holder, String data, int position) { + //方法一: + holder.setText(R.id.text, data); + //方法二: + //TextView textView = holder.getView(R.id.text); + //textView.setText(data); + } + } +} diff --git a/app/src/main/java/com/youth/xf/ui/demo/XToastActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XToastActivity.java new file mode 100644 index 0000000..436c070 --- /dev/null +++ b/app/src/main/java/com/youth/xf/ui/demo/XToastActivity.java @@ -0,0 +1,80 @@ +package com.youth.xf.ui.demo; + +import android.graphics.Color; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import com.youth.xf.BaseActivity; +import com.youth.xf.R; +import com.youth.xframe.utils.XOutdatedUtils; +import com.youth.xframe.widget.XToast; + +public class XToastActivity extends BaseActivity implements View.OnClickListener { + + + Button error; + Button success; + Button info; + Button warning; + Button normalNoIcon; + Button normalIcon; + Button custom; + + @Override + public int getLayoutId() { + return R.layout.activity_xtoast; + } + + @Override + public void initData(Bundle savedInstanceState) { + + } + + + @Override + public void initView() { + error = (Button) findViewById(R.id.button_error_toast); + success = (Button) findViewById(R.id.button_success_toast); + info = (Button) findViewById(R.id.button_info_toast); + warning = (Button) findViewById(R.id.button_warning_toast); + normalNoIcon = (Button) findViewById(R.id.button_normal_no_icon); + normalIcon = (Button) findViewById(R.id.button_normal_icon); + custom = (Button) findViewById(R.id.button_custom); + error.setOnClickListener(this); + success.setOnClickListener(this); + info.setOnClickListener(this); + warning.setOnClickListener(this); + normalNoIcon.setOnClickListener(this); + normalIcon.setOnClickListener(this); + custom.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + switch (v.getId()){ + case R.id.button_error_toast: + XToast.error("xloading_error!!"); + break; + case R.id.button_success_toast: + XToast.success("success!!"); + break; + case R.id.button_warning_toast: + XToast.warning("warning!!"); + break; + case R.id.button_info_toast: + XToast.info("info!!"); + break; + case R.id.button_normal_icon: + XToast.normal("success!!", XOutdatedUtils.getDrawable(R.mipmap.currerror)); + break; + case R.id.button_normal_no_icon: + XToast.normal("normal!!"); + break; + case R.id.button_custom: + XToast.custom("自定义!!!",R.mipmap.error2, Color.RED,Color.WHITE, Toast.LENGTH_SHORT); + break; + } + } +} diff --git a/app/src/main/java/com/youth/xf/view/GlideCircleTransform.java b/app/src/main/java/com/youth/xf/view/GlideCircleTransform.java new file mode 100644 index 0000000..da50b47 --- /dev/null +++ b/app/src/main/java/com/youth/xf/view/GlideCircleTransform.java @@ -0,0 +1,48 @@ +package com.youth.xf.view; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; + +/* +* glide 加载的圆形图片。如头像 +* */ +public class GlideCircleTransform extends BitmapTransformation { + public GlideCircleTransform(Context context) { + super(context); + } + + @Override + protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { + return circleCrop(pool, toTransform); + } + + private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { + if (source == null) return null; + int size = Math.min(source.getWidth(), source.getHeight()); + int x = (source.getWidth() - size) / 2; + int y = (source.getHeight() - size) / 2; + Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); + Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); + if (result == null) { + result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); + } + Canvas canvas = new Canvas(result); + Paint paint = new Paint(); + paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); + paint.setAntiAlias(true); + float r = size / 2f; + canvas.drawCircle(r, r, r, paint); + return result; + } + + @Override + public String getId() { + return getClass().getName(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/youth/xf/view/GlideRoundTransform.java b/app/src/main/java/com/youth/xf/view/GlideRoundTransform.java new file mode 100644 index 0000000..4503b5d --- /dev/null +++ b/app/src/main/java/com/youth/xf/view/GlideRoundTransform.java @@ -0,0 +1,49 @@ +package com.youth.xf.view; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +/* +* glide 下载图片加载的圆角大小 +* */ +public class GlideRoundTransform extends BitmapTransformation { + private static float radius = 0f; + public GlideRoundTransform(Context context) { + this(context,4); + } + public GlideRoundTransform(Context context, int dp) { + super(context); + this.radius = Resources.getSystem().getDisplayMetrics().density * dp; + } + @Override + protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { + return roundCrop(pool, toTransform); + } + private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { + if (source == null) return null; + + Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + if (result == null) { + result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + } + + Canvas canvas = new Canvas(result); + Paint paint = new Paint(); + paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); + paint.setAntiAlias(true); + RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); + canvas.drawRoundRect(rectF, radius, radius, paint); + return result; + } + @Override + public String getId() { + return getClass().getName() + Math.round(radius); + } +} diff --git a/app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java b/app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java new file mode 100644 index 0000000..9baf5b2 --- /dev/null +++ b/app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java @@ -0,0 +1,34 @@ +package com.youth.xf.view; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; + + +public class WrapContentHeightViewPager extends ViewPager { + public WrapContentHeightViewPager(Context context) { + super(context); + } + + public WrapContentHeightViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int height = 0; + for (int i = 0; i < getChildCount(); i++) { + View child = getChildAt(i); + child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + int h = child.getMeasuredHeight(); + if (h > height) height = h; + } + heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + +} diff --git a/app/src/main/res/drawable/selected_radius.xml b/app/src/main/res/drawable/selected_radius.xml new file mode 100644 index 0000000..b2869f4 --- /dev/null +++ b/app/src/main/res/drawable/selected_radius.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_log_demo.xml b/app/src/main/res/layout/activity_log_demo.xml new file mode 100644 index 0000000..a826eef --- /dev/null +++ b/app/src/main/res/layout/activity_log_demo.xml @@ -0,0 +1,71 @@ + + + +