├── .gitignore
├── .project
├── AndroidManifest.xml
├── README.md
├── libs
├── android-async-http-1.4.6.jar
├── android-support-v4.jar
├── androidannotations-api-3.1.jar
├── butterknife-4.0.1.jar
├── com.haarman.listviewanimations-2.6.0.jar
├── commons-codec-1.3.jar
├── core.jar
├── eventbus.jar
├── fastjson-1.1.43.android.jar
├── gson-2.2.1.jar
├── nineoldandroids-2.4.0.jar
├── pagerindicator.jar
├── picasso-2.3.1.jar
├── universal-image-loader-1.9.3.jar
├── viewpagertransformslibrary.jar
├── volley.jar
└── xUtils-2.6.14.jar
├── res
├── anim
│ ├── in_from_bottom.xml
│ ├── in_from_left.xml
│ ├── in_from_right.xml
│ ├── in_from_top.xml
│ ├── out_to_bottom.xml
│ ├── out_to_left.xml
│ ├── out_to_right.xml
│ ├── out_to_top.xml
│ ├── pop_enter.xml
│ ├── pop_exit.xml
│ └── update_loading_progressbar_anim.xml
├── color
│ └── tab_theme.xml
├── drawable-hdpi
│ ├── emotionstore_progresscancelbtn.png
│ ├── home_img_ratio.png
│ ├── home_img_ratio_selected.png
│ ├── ic_launcher.png
│ ├── me_share_return_press.png
│ ├── menu_btn_normal.png
│ ├── menu_btn_pressed.png
│ ├── news_tab_item_bg_select.9.png
│ ├── s_search_bg.png
│ ├── scan_icon_nor.png
│ ├── scan_top_bg2.png
│ ├── slip_ball.png
│ ├── slip_left.png
│ ├── slip_right.png
│ ├── topbar_right_normal.png
│ ├── topbar_right_press.png
│ ├── v1_7_back_blue_nor.png
│ ├── v1_7_back_hover.png
│ ├── xsearch_loading.png
│ └── xsearch_msg_pull_arrow_down.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── back_seletor.xml
│ ├── btn_bind_cancel.xml
│ ├── btn_bind_cancel_.xml
│ ├── me_share_return_normal.png
│ ├── progress_bar_states.xml
│ ├── progress_style.xml
│ ├── share_return.xml
│ ├── tab_indicator.xml
│ ├── text_blue.xml
│ ├── toast_bg.xml
│ └── top_right_selector.xml
├── layout
│ ├── activity_baseweb.xml
│ ├── ad_cycle_view.xml
│ ├── camera.xml
│ ├── popu_get_photo.xml
│ ├── progressdialog.xml
│ ├── pull_to_load_footer.xml
│ ├── pull_to_refresh_header.xml
│ ├── view_custom_toast.xml
│ ├── view_top_bar.xml
│ └── viewpager_item.xml
├── raw
│ └── qrcode_found.wav
└── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimen.xml
│ ├── drawables.xml
│ ├── ids.xml
│ ├── pull_picture_dimens.xml
│ ├── pull_refresh_strings.xml
│ ├── strings.xml
│ ├── styles.xml
│ ├── vpi__attrs.xml
│ └── vpi__styles.xml
└── src
└── com
├── android
└── pulltorefreshview
│ ├── FooterLoadingLayout.java
│ ├── HeaderLoadingLayout.java
│ ├── ILoadingLayout.java
│ ├── IPullToRefresh.java
│ ├── LoadingLayout.java
│ ├── PullToRefreshBase.java
│ └── PullToRefreshListView.java
├── finddreams
└── baselib
│ ├── activity
│ ├── CaptureActivity.java
│ └── DemoActivity.java
│ ├── app
│ ├── CrashHandler.java
│ └── MyApplication.java
│ ├── base
│ ├── BaseActivity.java
│ ├── BaseFragment.java
│ ├── BasePage.java
│ ├── BaseViewHolder.java
│ ├── BaseWebActivity.java
│ └── MyBaseAdapter.java
│ ├── http
│ ├── MyHttpClient.java
│ ├── MyHttpUtils.java
│ ├── NetStateUtil.java
│ └── URLUtils.java
│ ├── service
│ └── ServiceManager.java
│ ├── utils
│ ├── ActivityUtil.java
│ ├── AppHelper.java
│ ├── AppManager.java
│ ├── BitmapUtil.java
│ ├── BroadcastHelper.java
│ ├── CacheUtil.java
│ ├── CommonUtils.java
│ ├── ConstantsValue.java
│ ├── DateUtil.java
│ ├── DeviceInfoUtil.java
│ ├── DisplayUtil.java
│ ├── FileUtil.java
│ ├── GsonUtil.java
│ ├── InputMethodUtil.java
│ ├── InstallManager.java
│ ├── LogManager.java
│ ├── MD5Util.java
│ ├── PlaySoundUtil.java
│ ├── Screenshot.java
│ ├── SharePrefUtil.java
│ ├── StringUtil.java
│ └── ToastManager.java
│ └── view
│ ├── BounceScrollView.java
│ ├── CameraPreview.java
│ ├── CircleImageView.java
│ ├── ClearEditText.java
│ ├── CustomProgressDialog.java
│ ├── CustomToast.java
│ ├── CustomViewPager.java
│ ├── FlippingImageView.java
│ ├── ImageCycleView.java
│ ├── ImageTextView.java
│ ├── LazyViewPager.java
│ ├── ModelPopup.java
│ ├── MultiTouchImageView.java
│ ├── NoScrollGridView.java
│ ├── NoScrollListView.java
│ ├── ProgressWebView.java
│ ├── ProgressWheel.java
│ ├── RollViewPager.java
│ ├── RotateAnimation.java
│ ├── ScaleImageView.java
│ ├── ScrollListView.java
│ ├── SendValidateButton.java
│ ├── SlideButton.java
│ └── TopBarView.java
└── zxing
└── barcode
├── AutoFocusCallback.java
├── CameraConfigurationManager.java
├── CameraManager.java
├── CaptureActivityHandler.java
├── DecodeFormatManager.java
├── DecodeHandler.java
├── DecodeThread.java
├── EncodingHandler.java
├── FinishListener.java
├── FlashlightManager.java
├── InactivityTimer.java
├── Intents.java
├── PlanarYUVLuminanceSource.java
├── PreviewCallback.java
├── ViewfinderResultPointCallback.java
└── ViewfinderView.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /gen
3 | # Local configuration file (sdk path, etc)
4 | local.properties
5 |
6 | # Eclipse project files
7 | .classpath
8 | .project
9 |
10 | # Proguard folder generated by Eclipse
11 | proguard/
12 | /ic_launcher-web.png
13 | /.classpath
14 | /.settings
15 | /.classpath
16 | /proguard-project.txt
17 | /project.properties
18 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | BaseLib
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android_BaseLib
2 | ===============
3 |
4 | 这是一个可用于Android快速开发的框架,集成了很多项目中通用的东西,免去重复造轮子的麻烦,直接下载来了,修改一下就可以做为基础的框架进行开发,提高开发速度,适合当前移动互联网时代敏捷快速开发的节奏。
5 |
6 | 这是一个用于Android快速开发的框架,主要是在以往的项目开发中,收集到的常用的功能:
7 |
8 | 1.常用到的工具类;
9 | 2.BaseActivity,BaseFragment,还有BaseView的封装,以便于对ViewPage中的View进行分别的管理,符合Java的封 装思想。
10 |
11 | 3.对BaseAdapter进行封装成MyBaseAdapter,引入BaseViewHolder,是个万能的ViewHolder;
12 | 4.很多常用的自定义View,CustomToast,SlideButton(滑动按钮),RollViewPager(自动滚动的ViewPage广告)。。。。。
13 |
14 | 5.加入了很多项目中常用的开源项目,方便使用。比如:
15 |
16 |
17 | ViewPageIndicator, 导航栏,很多应用中都需要使用到
18 |
19 | Pulltorefreshview, 下拉刷新,支持各种ListView已经GridView的下拉
20 |
21 | Gson, 谷歌官方的解析json格式的库
22 |
23 | fastjson, 阿里巴巴公司出品的解析json格式的库
24 |
25 | android-async-http, 异步网络框架
26 |
27 | Zxing, 二维码扫描,项目中的名字是core
28 |
29 | Universal-image-loader, 强大的异步加载网络图片,防止OOM
30 |
31 | xUtils, 国内出名的快速开发框架
32 |
33 | nineoldandroids-2.4.0, 在Android2.X上兼容的动画库
34 |
35 | volley, 谷歌官方的访问网络的框架
36 |
37 | EventBus, 简化Android组件间通信库
38 |
39 | Butterknife 依赖注入框架,让你从findViewById中解放出来
40 |
41 | (一)、集成了项目常用到工具类
42 |
43 | AppManager, CommonUtils, 常用的工具类封装
44 |
45 | DeviceInfoUtil 获得设备相关的信息,IMEI,设备的蓝牙,和SD卡是否可用。
46 |
47 | LogManager 项目Log的统一管理
48 |
49 | Screenshot 可以用于截图
50 |
51 | ToastManager 项目中Toast的统一管理
52 |
53 | ServiceManager 管理手机的各种系统服务,比如LocationManager,TelephonyManager,InputMethodManager,Vibrator,ConnectivityManager
54 | 等等, .........................................
55 |
56 | (二)、封装了BaseActivity,BaseFragment,BasePage,对BaseAdapter进行封装,
57 | 把所有的公共点进行封装,子类只需要继承即可
58 |
59 | (三)万能的ViewHolder 可以省去每次都需要在Adapter类中写一个静态的ViewHolder问题,实现代码的重用性。
60 |
61 | (四)集成了很多的自定义View
62 |
63 | 比如项目常用到的顶部栏,直接封装成了TopBarView,只需要在布局文件中引入即可;
64 | RollViewPager 可以自动滚动的ViewPager,带有标题,和用于指示的小圆点。
65 | ProgressWheel 自定义的进度条,
66 | CustomToast 自定义的Toast
67 | CircleImageView 圆形的ImageView
68 | SlideButton 左右滑动的滑动开关
69 | ClearEditText 带有删除图标的EditText登录中常用到
70 | ScrollListView 解决ListView嵌套到ScrollView中只显示一行的问题
71 |
72 | (五)CrashHandler 用于异常崩溃处理
当程序发生未捕获异常时,由该类来接管程序并记录发送错误报告。把错误信息保存在sd卡中,然后上传异常信息到服务器,便于程序员对异常的处理。
73 |
74 | (六)集成了常用到的开源框架
75 |
76 | ViewPageIndicator 常用到滑动导航的开源框架,可以很方便的做到网易新闻客户端Tab标签滑动导航的功能;
77 |
78 | Pulltorefreshview 下拉刷新可以说是每个项目中都必须用到的吧,这个自然不用多说;
79 |
80 | Gson 可以用于对服务器端返回的json解析,在工具类中可以找到GsonUtil 帮助类,解析json非常的方便;
81 |
82 | android-async-http 非常成熟的异步请求网络的类,使用起来非常简单,从MyHttpClient中可以看到使用方法;当然你也可以不需要网络框架,自己封装httpclient做成MyHttpClient,不过开源框架毕竟是很成熟了的,可以解决在实际运行过程中的一些未知问题;
83 |
84 | Zxing 二维码/条形码识别的框架
项目中如果需要进行二维码的扫描,可以使用此框架,已经集成在项目中,只需要以startActivityForResult的方式调用本项目中的CaptureActivity类即可打开扫描界面,然后在返回结果中获得扫描到的结果;这个CaptureActivity已经实现了扫描成功时的震动和确认声音,提高用户的体验。当然还有从下而上的滑动滚动横杠,如果有特别的需求可以自己修改,比如说加上闪光灯也是个不错的想法。
85 |
86 | Universal-image-loader 对于图片的加载怎么少的了这个开源框架呢,全面解决你项目中ListView加载图片的各种问题。
87 |
88 | xUtils 很不错的快速开发框架,其中的ViewUtil模块可以省去我们在项目中的各种烦人的findViewById代码,以及setOnclickLister等,属于android中的ioc框架,完全注解方式就可以进行UI,资源和事件绑定;
89 |
--------------------------------------------------------------------------------
/libs/android-async-http-1.4.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/android-async-http-1.4.6.jar
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/androidannotations-api-3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/androidannotations-api-3.1.jar
--------------------------------------------------------------------------------
/libs/butterknife-4.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/butterknife-4.0.1.jar
--------------------------------------------------------------------------------
/libs/com.haarman.listviewanimations-2.6.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/com.haarman.listviewanimations-2.6.0.jar
--------------------------------------------------------------------------------
/libs/commons-codec-1.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/commons-codec-1.3.jar
--------------------------------------------------------------------------------
/libs/core.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/core.jar
--------------------------------------------------------------------------------
/libs/eventbus.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/eventbus.jar
--------------------------------------------------------------------------------
/libs/fastjson-1.1.43.android.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/fastjson-1.1.43.android.jar
--------------------------------------------------------------------------------
/libs/gson-2.2.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/gson-2.2.1.jar
--------------------------------------------------------------------------------
/libs/nineoldandroids-2.4.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/nineoldandroids-2.4.0.jar
--------------------------------------------------------------------------------
/libs/pagerindicator.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/pagerindicator.jar
--------------------------------------------------------------------------------
/libs/picasso-2.3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/picasso-2.3.1.jar
--------------------------------------------------------------------------------
/libs/universal-image-loader-1.9.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/universal-image-loader-1.9.3.jar
--------------------------------------------------------------------------------
/libs/viewpagertransformslibrary.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/viewpagertransformslibrary.jar
--------------------------------------------------------------------------------
/libs/volley.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/volley.jar
--------------------------------------------------------------------------------
/libs/xUtils-2.6.14.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/libs/xUtils-2.6.14.jar
--------------------------------------------------------------------------------
/res/anim/in_from_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/in_from_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/in_from_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/in_from_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/out_to_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/out_to_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/out_to_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/out_to_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/res/anim/pop_enter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/res/anim/pop_exit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/res/anim/update_loading_progressbar_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/res/color/tab_theme.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/emotionstore_progresscancelbtn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/emotionstore_progresscancelbtn.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/home_img_ratio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/home_img_ratio.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/home_img_ratio_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/home_img_ratio_selected.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/me_share_return_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/me_share_return_press.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/menu_btn_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/menu_btn_normal.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/menu_btn_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/menu_btn_pressed.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/news_tab_item_bg_select.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/news_tab_item_bg_select.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/s_search_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/s_search_bg.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/scan_icon_nor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/scan_icon_nor.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/scan_top_bg2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/scan_top_bg2.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/slip_ball.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/slip_ball.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/slip_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/slip_left.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/slip_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/slip_right.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/topbar_right_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/topbar_right_normal.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/topbar_right_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/topbar_right_press.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/v1_7_back_blue_nor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/v1_7_back_blue_nor.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/v1_7_back_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/v1_7_back_hover.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/xsearch_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/xsearch_loading.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/xsearch_msg_pull_arrow_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-hdpi/xsearch_msg_pull_arrow_down.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/back_seletor.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/drawable/btn_bind_cancel.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 | -
17 |
18 |
19 |
20 |
21 |
22 | -
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/res/drawable/btn_bind_cancel_.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 | -
17 |
18 |
19 |
20 |
21 |
22 | -
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/res/drawable/me_share_return_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/drawable/me_share_return_normal.png
--------------------------------------------------------------------------------
/res/drawable/progress_bar_states.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 |
9 |
14 |
15 |
16 | -
17 |
18 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/res/drawable/progress_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/share_return.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/tab_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/res/drawable/text_blue.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/toast_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/res/drawable/top_right_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/layout/activity_baseweb.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/res/layout/ad_cycle_view.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/res/layout/camera.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
16 |
17 |
22 |
23 |
28 |
29 |
36 |
37 |
47 |
48 |
58 |
59 |
60 |
66 |
67 |
71 |
72 |
78 |
79 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/res/layout/popu_get_photo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
25 |
26 |
37 |
48 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/res/layout/progressdialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
--------------------------------------------------------------------------------
/res/layout/pull_to_load_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
22 |
23 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/res/layout/pull_to_refresh_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
28 |
37 |
48 |
49 |
50 |
59 |
60 |
71 |
72 |
--------------------------------------------------------------------------------
/res/layout/view_custom_toast.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
--------------------------------------------------------------------------------
/res/layout/view_top_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
25 |
26 |
27 |
35 |
36 |
46 |
47 |
57 |
58 |
--------------------------------------------------------------------------------
/res/layout/viewpager_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
--------------------------------------------------------------------------------
/res/raw/qrcode_found.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/Android_BaseLib/b88ece62937cfb0cd539da88110db6675e6f381e/res/raw/qrcode_found.wav
--------------------------------------------------------------------------------
/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffffffff
4 |
5 | #ffd65284
6 | #ff7a7979
7 | #ff999999
8 | #ffef71a1
9 | #000000
10 | #60000000
11 | #b0000000
12 | #c0ffff00
13 | #aeff39
14 | #E60200
15 |
16 |
--------------------------------------------------------------------------------
/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16sp
4 |
5 |
--------------------------------------------------------------------------------
/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | - #00000000
4 |
5 |
--------------------------------------------------------------------------------
/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/res/values/pull_picture_dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 80dp
4 |
5 | 0dp
6 | 48dp
7 |
8 | 16dp
9 |
10 | 12dp
11 |
12 | 12dp
13 |
14 | 8dp
15 | 9dp
16 | 6dp
17 | 5dp
18 | 10dp
19 | 30dp
20 |
21 | 18dp
22 |
23 | 8dp
24 |
25 | 12dp
26 |
27 | 14dp
28 | 10dp
29 | 6dp
30 | 40dp
31 |
32 |
--------------------------------------------------------------------------------
/res/values/pull_refresh_strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 已经到底啦
5 | 松开加载更多
6 | 下拉可以刷新
7 | 松开获取更多
8 | 上次刷新时间 :
9 | 正在加载中
10 | 正在刷新…
11 |
12 |
13 | 点击屏幕,重新加载
14 |
15 | 正在加载…
16 |
17 |
18 | @string/pushmsg_center_pull_down_text
19 | 上拉可以刷新
20 | 松开后刷新
21 | @string/pushmsg_center_load_more_ongoing_text
22 | @string/pushmsg_center_pull_down_update_time
23 | 松开载入更多
24 | @string/pull_to_refresh_header_hint_loading
25 | @string/pushmsg_center_no_more_msg
26 | 网络不给力,请检查网络
27 |
28 |
29 | 图片已保存到相册
30 | 保存图片失败
31 | 下一组:
32 | 上一组:
33 |
34 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | BaseLib
4 | 返回
5 | 拍照
6 | 从手机相册选取
7 | 取消
8 | 模特
9 | 将二维码放入框内, 即可自动扫描
10 | 更多
11 | 扫描二维码
12 | 沒有网络
13 |
14 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
24 |
31 |
32 |
36 |
37 |
--------------------------------------------------------------------------------
/res/values/vpi__styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
38 |
39 |
40 |
43 |
44 |
48 |
49 |
--------------------------------------------------------------------------------
/src/com/android/pulltorefreshview/FooterLoadingLayout.java:
--------------------------------------------------------------------------------
1 | package com.android.pulltorefreshview;
2 |
3 |
4 |
5 | import android.content.Context;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.widget.ProgressBar;
11 | import android.widget.TextView;
12 |
13 | import com.finddreams.baselib.R;
14 |
15 | /**
16 | * 这个类封装了下拉刷新的布局
17 | *
18 | * @author Li Hong
19 | * @since 2013-7-30
20 | */
21 | public class FooterLoadingLayout extends LoadingLayout {
22 | /**进度条*/
23 | private ProgressBar mProgressBar;
24 | /** 显示的文本 */
25 | private TextView mHintView;
26 |
27 | /**
28 | * 构造方法
29 | *
30 | * @param context context
31 | */
32 | public FooterLoadingLayout(Context context) {
33 | super(context);
34 | init(context);
35 | }
36 |
37 | /**
38 | * 构造方法
39 | *
40 | * @param context context
41 | * @param attrs attrs
42 | */
43 | public FooterLoadingLayout(Context context, AttributeSet attrs) {
44 | super(context, attrs);
45 | init(context);
46 | }
47 |
48 | /**
49 | * 初始化
50 | *
51 | * @param context context
52 | */
53 | private void init(Context context) {
54 | mProgressBar = (ProgressBar) findViewById(R.id.pull_to_load_footer_progressbar);
55 | mHintView = (TextView) findViewById(R.id.pull_to_load_footer_hint_textview);
56 |
57 | setState(State.RESET);
58 | }
59 |
60 | @Override
61 | protected View createLoadingView(Context context, AttributeSet attrs) {
62 | View container = LayoutInflater.from(context).inflate(R.layout.pull_to_load_footer, null);
63 | return container;
64 | }
65 |
66 | @Override
67 | public void setLastUpdatedLabel(CharSequence label) {
68 | }
69 |
70 | @Override
71 | public int getContentSize() {
72 | View view = findViewById(R.id.pull_to_load_footer_content);
73 | if (null != view) {
74 | return view.getHeight();
75 | }
76 |
77 | return (int) (getResources().getDisplayMetrics().density * 40);
78 | }
79 |
80 | @Override
81 | protected void onStateChanged(State curState, State oldState) {
82 | show(true);
83 | // mProgressBar.setVisibility(View.GONE);
84 | // mHintView.setVisibility(View.INVISIBLE);
85 |
86 | super.onStateChanged(curState, oldState);
87 | }
88 |
89 | @Override
90 | protected void onReset() {
91 | show(false);
92 | mHintView.setText(R.string.pull_to_refresh_header_hint_loading);
93 | }
94 |
95 | @Override
96 | protected void onPullToRefresh() {
97 | show(true);
98 | mHintView.setVisibility(View.VISIBLE);
99 | mHintView.setText(R.string.pull_to_refresh_header_hint_normal2);
100 | }
101 |
102 | @Override
103 | protected void onReleaseToRefresh() {
104 | show(true);
105 | mHintView.setVisibility(View.VISIBLE);
106 | mHintView.setText(R.string.pull_to_refresh_header_hint_ready);
107 | }
108 |
109 | @Override
110 | protected void onRefreshing() {
111 | show(true);
112 | mProgressBar.setVisibility(View.VISIBLE);
113 | mHintView.setVisibility(View.VISIBLE);
114 | mHintView.setText(R.string.pull_to_refresh_header_hint_loading);
115 | }
116 |
117 | @Override
118 | protected void onNoMoreData() {
119 | show(false);
120 | mHintView.setText(R.string.pushmsg_center_no_more_msg);
121 | }
122 |
123 | @Override
124 | protected void onLoadingDrawableSet(Drawable imageDrawable) {
125 | // TODO Auto-generated method stub
126 |
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/com/android/pulltorefreshview/ILoadingLayout.java:
--------------------------------------------------------------------------------
1 | package com.android.pulltorefreshview;
2 |
3 | /**
4 | * 下拉刷新和上拉加载更多的界面接口
5 | *
6 | * @author Li Hong
7 | * @since 2013-7-29
8 | */
9 | public interface ILoadingLayout {
10 | /**
11 | * 当前的状态
12 | */
13 | public enum State {
14 |
15 | /**
16 | * Initial state
17 | */
18 | NONE,
19 |
20 | /**
21 | * When the UI is in a state which means that user is not interacting
22 | * with the Pull-to-Refresh function.
23 | */
24 | RESET,
25 |
26 | /**
27 | * When the UI is being pulled by the user, but has not been pulled far
28 | * enough so that it refreshes when released.
29 | */
30 | PULL_TO_REFRESH,
31 |
32 | /**
33 | * When the UI is being pulled by the user, and has
34 | * been pulled far enough so that it will refresh when released.
35 | */
36 | RELEASE_TO_REFRESH,
37 |
38 | /**
39 | * When the UI is currently refreshing, caused by a pull gesture.
40 | */
41 | REFRESHING,
42 |
43 | /**
44 | * When the UI is currently refreshing, caused by a pull gesture.
45 | */
46 | @Deprecated
47 | LOADING,
48 |
49 | /**
50 | * No more data
51 | */
52 | NO_MORE_DATA,
53 | }
54 |
55 | /**
56 | * 设置当前状态,派生类应该根据这个状态的变化来改变View的变化
57 | *
58 | * @param state 状态
59 | */
60 | public void setState(State state);
61 |
62 | /**
63 | * 得到当前的状态
64 | *
65 | * @return 状态
66 | */
67 | public State getState();
68 |
69 | /**
70 | * 得到当前Layout的内容大小,它将作为一个刷新的临界点
71 | *
72 | * @return 高度
73 | */
74 | public int getContentSize();
75 |
76 | /**
77 | * 在拉动时调用
78 | *
79 | * @param scale 拉动的比例
80 | */
81 | public void onPull(float scale);
82 | }
83 |
--------------------------------------------------------------------------------
/src/com/android/pulltorefreshview/IPullToRefresh.java:
--------------------------------------------------------------------------------
1 | package com.android.pulltorefreshview;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 | import com.android.pulltorefreshview.PullToRefreshBase.OnRefreshListener;
8 |
9 |
10 | /**
11 | * 定义了拉动刷新的接口
12 | *
13 | * @author Li Hong
14 | * @since 2013-8-22
15 | * @param
16 | */
17 | public interface IPullToRefresh {
18 |
19 | /**
20 | * 设置当前下拉刷新是否可用
21 | *
22 | * @param pullRefreshEnabled true表示可用,false表示不可用
23 | */
24 | public void setPullRefreshEnabled(boolean pullRefreshEnabled);
25 |
26 | /**
27 | * 设置当前上拉加载更多是否可用
28 | *
29 | * @param pullLoadEnabled true表示可用,false表示不可用
30 | */
31 | public void setPullLoadEnabled(boolean pullLoadEnabled);
32 |
33 | /**
34 | * 滑动到底部是否自动加载更多数据
35 | *
36 | * @param scrollLoadEnabled 如果这个值为true的话,那么上拉加载更多的功能将会禁用
37 | */
38 | public void setScrollLoadEnabled(boolean scrollLoadEnabled);
39 |
40 | /**
41 | * 判断当前下拉刷新是否可用
42 | *
43 | * @return true如果可用,false不可用
44 | */
45 | public boolean isPullRefreshEnabled();
46 |
47 | /**
48 | * 判断上拉加载是否可用
49 | *
50 | * @return true可用,false不可用
51 | */
52 | public boolean isPullLoadEnabled();
53 |
54 | /**
55 | * 滑动到底部加载是否可用
56 | *
57 | * @return true可用,否则不可用
58 | */
59 | public boolean isScrollLoadEnabled();
60 |
61 | /**
62 | * 设置刷新的监听器
63 | *
64 | * @param refreshListener 监听器对象
65 | */
66 | public void setOnRefreshListener(OnRefreshListener refreshListener);
67 |
68 | /**
69 | * 结束下拉刷新
70 | */
71 | public void onPullDownRefreshComplete();
72 |
73 | /**
74 | * 结束上拉加载更多
75 | */
76 | public void onPullUpRefreshComplete();
77 |
78 | /**
79 | * 得到可刷新的View对象
80 | *
81 | * @return 返回调用{@link #createRefreshableView(Context, AttributeSet)} 方法返回的对象
82 | */
83 | public T getRefreshableView();
84 |
85 | /**
86 | * 得到Header布局对象
87 | *
88 | * @return Header布局对象
89 | */
90 | public LoadingLayout getHeaderLoadingLayout();
91 |
92 | /**
93 | * 得到Footer布局对象
94 | *
95 | * @return Footer布局对象
96 | */
97 | public LoadingLayout getFooterLoadingLayout();
98 |
99 | /**
100 | * 设置最后更新的时间文本
101 | *
102 | * @param label 文本
103 | */
104 | public void setLastUpdatedLabel(CharSequence label);
105 | }
106 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/activity/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.activity;
2 |
3 | import com.finddreams.baselib.base.BaseActivity;
4 | /**
5 | * @Description: 例子,如何使用的实例
6 | * @author finddreams
7 | * @address https://github.com/finddreams
8 | */
9 | public class DemoActivity extends BaseActivity {
10 |
11 | @Override
12 | protected void initView() {
13 |
14 | }
15 |
16 | @Override
17 | protected void initData() {
18 |
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/app/CrashHandler.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.app;
2 |
3 | import java.io.File;
4 | import java.io.FileWriter;
5 | import java.io.IOException;
6 | import java.lang.Thread.UncaughtExceptionHandler;
7 |
8 | import android.os.Looper;
9 | import android.util.Log;
10 | import android.widget.Toast;
11 |
12 | import com.finddreams.baselib.utils.FileUtil;
13 | import com.finddreams.baselib.utils.StringUtil;
14 |
15 | /**
16 | * @Description: 异常崩溃处理类 当程序发生未捕获异常时,由该类来接管程序并记录发送错误报告。
17 | * @author http://blog.csdn.net/finddreams
18 | */
19 | public class CrashHandler implements UncaughtExceptionHandler {
20 |
21 | /** 错误日志文件名称 */
22 | static final String LOG_NAME = "/crash.txt";
23 |
24 | /** 系统默认的UncaughtException处理类 */
25 | private Thread.UncaughtExceptionHandler mDefaultHandler;
26 |
27 | MyApplication application;
28 |
29 | /**
30 | * @brief 构造函数
31 | * @details 获取系统默认的UncaughtException处理器,设置该CrashHandler为程序的默认处理器 。
32 | * @param context 上下文
33 | */
34 | public CrashHandler(MyApplication application) {
35 | mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
36 | Thread.setDefaultUncaughtExceptionHandler(this);
37 | this.application = application;
38 | }
39 |
40 | /**
41 | * @brief 当UncaughtException发生时会转入该函数来处理
42 | */
43 | @Override
44 | public void uncaughtException(Thread thread, Throwable ex) {
45 | // 如果用户没有处理则让系统默认的异常处理器来处理
46 | if (!handleException(ex) && mDefaultHandler != null) {
47 | mDefaultHandler.uncaughtException(thread, ex);
48 | } else {
49 | // 等待会后结束程序
50 | try {
51 | Log.i(LOG_NAME,"exit start");
52 | Thread.sleep(3000);
53 | android.os.Process.killProcess(android.os.Process.myPid());
54 | System.exit(10);
55 | // Intent intent = new Intent(application.getApplicationContext(), MainActivity.class);
56 | // PendingIntent restartIntent = PendingIntent.getActivity(
57 | // application.getApplicationContext(), 0, intent,
58 | // Intent.FLAG_ACTIVITY_NEW_TASK);
59 | // //退出程序
60 | // AlarmManager mgr = (AlarmManager)application.getSystemService(Context.ALARM_SERVICE);
61 | // mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
62 | // restartIntent); // 1秒钟后重启应用
63 | application.finishActivity();
64 | Log.i(LOG_NAME,"exit end");
65 | } catch (InterruptedException e) {
66 | e.printStackTrace();
67 | }
68 | }
69 |
70 | }
71 |
72 | /**
73 | * @brief 自定义错误处理,收集错误信息
74 | * @details 发送错误报告等操作均在此完成
75 | * @param ex 异常
76 | * @return true:如果处理了该异常信息;否则返回false。
77 | */
78 | private boolean handleException(final Throwable ex) {
79 | if (ex == null) {
80 | return true;
81 | }
82 | ex.printStackTrace();
83 | // 提示错误消息
84 | new Thread() {
85 | @Override
86 | public void run() {
87 | Looper.prepare();
88 | Toast.makeText(application.getApplicationContext(), "应用发生异常,即将退出!", Toast.LENGTH_LONG).show();
89 | Looper.loop();
90 | }
91 | }.start();
92 | // 保存错误报告文件
93 | saveCrashInfoToFile(ex);
94 | return true;
95 | }
96 |
97 | /**
98 | * @brief 保存错误信息到文件中
99 | * @param ex 异常
100 | */
101 | private void saveCrashInfoToFile(Throwable ex) {
102 | final StackTraceElement[] stack = ex.getStackTrace();
103 | final String message = ex.getMessage();
104 | /* 准备错误日志文件 */
105 | File logFile = new File(FileUtil.APP_LOG_PATH + LOG_NAME);
106 | if (!logFile.getParentFile().exists()) {
107 | logFile.getParentFile().mkdirs();
108 | }
109 | /* 写入错误日志 */
110 | FileWriter fw = null;
111 | final String lineFeed = "\r\n";
112 | try {
113 | fw = new FileWriter(logFile, true);
114 | fw.write(StringUtil.currentTime(StringUtil.FORMAT_YMDHMS).toString() + lineFeed
115 | + lineFeed);
116 | fw.write(message + lineFeed);
117 | for (int i = 0; i < stack.length; i++) {
118 | fw.write(stack[i].toString() + lineFeed);
119 | }
120 | fw.write(lineFeed);
121 | fw.flush();
122 | } catch (IOException e) {
123 | e.printStackTrace();
124 | } finally {
125 | try {
126 | if (null != fw)
127 | fw.close();
128 | } catch (IOException e) {
129 | e.printStackTrace();
130 | }
131 | }
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/app/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.app;
2 |
3 | import java.util.LinkedList;
4 |
5 | import android.app.Activity;
6 | import android.app.Application;
7 |
8 | import com.finddreams.baselib.utils.ConstantsValue;
9 |
10 | public class MyApplication extends Application {
11 | private static final String TAG = "InitApplication";
12 | private static boolean isLogged = false;
13 | private static MyApplication instance;
14 | private static LinkedList activityList;
15 | private Activity activity;
16 | @Override
17 | public void onCreate()
18 | {
19 | instance = this;
20 | super.onCreate();
21 | if (!ConstantsValue.DEBUG) {
22 | /* 全局异常崩溃处理 */
23 | CrashHandler catchExcep = new CrashHandler(this);
24 | Thread.setDefaultUncaughtExceptionHandler(catchExcep);
25 | }
26 | activityList = new LinkedList();
27 | super.onCreate();
28 | }
29 |
30 | public Activity getActivity() {
31 | return activity;
32 | }
33 | public void setActivity(Activity activity) {
34 | this.activity = activity;
35 | }
36 | public static MyApplication getInstance()
37 | {
38 | return instance;
39 | }
40 | /**
41 | * Activity关闭时,删除Activity列表中的Activity对象*/
42 | public void removeActivity(Activity a){
43 | activityList.remove(a);
44 | }
45 |
46 | /**
47 | * 向Activity列表中添加Activity对象*/
48 | public void addActivity(Activity a){
49 | activityList.add(a);
50 | }
51 |
52 | /**
53 | * 关闭Activity列表中的所有Activity*/
54 | public void finishActivity(){
55 | for (Activity activity : activityList) {
56 | if (null != activity) {
57 | activity.finish();
58 | }
59 | }
60 | activityList.clear();
61 | //杀死该应用进程
62 | android.os.Process.killProcess(android.os.Process.myPid());
63 | }
64 |
65 | public static boolean isLogged() {
66 | return isLogged;
67 | }
68 | public static void setLogged(boolean isLogged) {
69 | MyApplication.isLogged = isLogged;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.base;
2 |
3 |
4 | import com.finddreams.baselib.http.MyHttpClient;
5 | import com.finddreams.baselib.utils.AppManager;
6 | import com.loopj.android.http.AsyncHttpClient;
7 |
8 | import android.content.Context;
9 | import android.os.Bundle;
10 | import android.support.v4.app.FragmentActivity;
11 | import android.view.Window;
12 | /**
13 | * @Description:所有Activity的基类,是个抽象类,把整个项目中都需要用到的东西封装起来
14 | * @author http://blog.csdn.net/finddreams
15 | */
16 | public abstract class BaseActivity extends FragmentActivity {
17 |
18 | protected Context context;
19 | protected AsyncHttpClient httpClient;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | this.requestWindowFeature(Window.FEATURE_NO_TITLE);
25 | AppManager.getAppManager().addActivity(this);
26 | context = this;
27 | httpClient = MyHttpClient.getHttpClient();
28 | initView();
29 | initData();
30 | }
31 | /**
32 | * 抽象方法子类必须实现
33 | */
34 | protected abstract void initView();
35 |
36 | protected abstract void initData();
37 |
38 | @Override
39 | protected void onDestroy() {
40 | super.onDestroy();
41 | AppManager.getAppManager().finishActivity(this);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.base;
2 |
3 | import com.finddreams.baselib.app.MyApplication;
4 | import com.finddreams.baselib.http.MyHttpClient;
5 | import com.loopj.android.http.AsyncHttpClient;
6 |
7 | import android.app.Activity;
8 | import android.content.Context;
9 | import android.os.Bundle;
10 | import android.support.v4.app.Fragment;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.View.OnClickListener;
14 | import android.view.ViewGroup;
15 | /**
16 | * @Description:所有fragment的基类
17 | * @author http://blog.csdn.net/finddreams
18 | */
19 | public abstract class BaseFragment extends Fragment implements OnClickListener {
20 | protected Context context;
21 | public View rootView;
22 | protected MyApplication myApp;
23 | protected AsyncHttpClient httpClient;
24 | @Override
25 | public void onActivityCreated(Bundle savedInstanceState) {
26 |
27 | super.onActivityCreated(savedInstanceState);
28 | initData();
29 | }
30 |
31 | @Override
32 | public void onCreate(Bundle savedInstanceState) {
33 |
34 | super.onCreate(savedInstanceState);
35 | context = getActivity();
36 | myApp = (MyApplication) getActivity().getApplication();
37 | httpClient = MyHttpClient.getHttpClient();
38 | }
39 |
40 |
41 | @Override
42 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
43 | Bundle savedInstanceState) {
44 | rootView = initView(inflater);
45 | return rootView;
46 | }
47 | public View getRootView(){
48 | return rootView;
49 | }
50 | @Override
51 | public void onClick(View arg0) {
52 |
53 |
54 | }
55 | protected abstract View initView(LayoutInflater inflater);
56 |
57 | protected abstract void initData();
58 |
59 | protected abstract void processClick(View v);
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/base/BasePage.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.base;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 |
10 | import com.finddreams.baselib.http.MyHttpClient;
11 | import com.lidroid.xutils.ViewUtils;
12 | import com.loopj.android.http.AsyncHttpClient;
13 |
14 | /**
15 | * @Description:所有页面view的基类。
16 | * @author http://blog.csdn.net/finddreams
17 | */
18 | public abstract class BasePage implements OnClickListener {
19 |
20 | protected Context context;
21 | protected View contentView;
22 | protected AsyncHttpClient httpClient;
23 |
24 | public boolean isLoadSuccess=false;
25 |
26 | public BasePage(Context context) {
27 | this.context = context;
28 | contentView = initView((LayoutInflater) context
29 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE));
30 | ViewUtils.inject(contentView);
31 | httpClient = MyHttpClient.getHttpClient();
32 |
33 | }
34 | protected abstract View initView(LayoutInflater inflater);
35 |
36 | public abstract void initData();
37 |
38 | public View getContentView() {
39 | return contentView;
40 | }
41 | @Override
42 | public void onClick(View v) {
43 | }
44 |
45 | protected void startActivity(Activity activity) {
46 | Intent intent = new Intent(context, activity.getClass());
47 | context.startActivity(intent);
48 |
49 | // AppManager.getAppManager().finishActivity();
50 |
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/base/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.base;
2 |
3 | import android.util.SparseArray;
4 | import android.view.View;
5 | /**
6 | * @Description:万能的viewHolder
7 | * @author http://blog.csdn.net/finddreams
8 | */
9 | public class BaseViewHolder {
10 | @SuppressWarnings("unchecked")
11 | public static T get(View view, int id) {
12 | SparseArray viewHolder = (SparseArray) view.getTag();
13 | if (viewHolder == null) {
14 | viewHolder = new SparseArray();
15 | view.setTag(viewHolder);
16 | }
17 | View childView = viewHolder.get(id);
18 | if (childView == null) {
19 | childView = view.findViewById(id);
20 | viewHolder.put(id, childView);
21 | }
22 | return (T) childView;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/base/BaseWebActivity.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.base;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.widget.ProgressBar;
6 |
7 | import com.finddreams.baselib.R;
8 | import com.finddreams.baselib.utils.ConstantsValue;
9 | import com.finddreams.baselib.view.ProgressWebView;
10 | /**
11 | * WebView
12 | * @author liuxiang
13 | * @date 2015-1-30 下午6:07:05
14 | * @version V1.0
15 | */
16 | public class BaseWebActivity extends BaseActivity {
17 |
18 | // private View mLoadingView;
19 | protected ProgressWebView mWebView;
20 | private ProgressBar web_progressbar;
21 | @Override
22 | protected void initView() {
23 | setContentView(R.layout.activity_baseweb);
24 | // mLoadingView = findViewById(R.id.baseweb_loading_indicator);
25 | mWebView = (ProgressWebView) findViewById(R.id.baseweb_webview);
26 | mWebView.getSettings().setJavaScriptEnabled(true);
27 | }
28 |
29 | @Override
30 | protected void initData() {
31 | Intent intent = getIntent();
32 | Bundle bundle = intent.getExtras();
33 | String url = bundle.getString(ConstantsValue.INTENT_URL);
34 | String title = bundle.getString(ConstantsValue.INTENT_TITLE);
35 | // if(!TextUtils.isEmpty(url)&&TextUtils.isEmpty(title)){
36 | mWebView.loadUrl(url);
37 |
38 | // }
39 |
40 | }
41 | @Override
42 | protected void onDestroy() {
43 | // TODO Auto-generated method stub
44 | super.onDestroy();
45 | mWebView=null;
46 |
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/base/MyBaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.base;
2 |
3 | import java.util.List;
4 |
5 |
6 | import android.content.Context;
7 | import android.os.Bundle;
8 | import android.widget.BaseAdapter;
9 |
10 | /**
11 | * @Description:自定义的BaseAdapter,所有adapter的父类。
12 | * @author http://blog.csdn.net/finddreams
13 | */
14 | public abstract class MyBaseAdapter extends BaseAdapter {
15 |
16 | public Context context;
17 | public List list;//
18 | public Q view; // 这里不一定是ListView,比如GridView,CustomListView
19 |
20 |
21 | public MyBaseAdapter(Context context, List list, Q view) {
22 | this.context = context;
23 | this.list = list;
24 | this.view = view;
25 | }
26 |
27 | public MyBaseAdapter(Context context, List list) {
28 | this.context = context;
29 | this.list = list;
30 |
31 | }
32 | /**
33 | * update
34 | * @param list
35 | */
36 | public void updateListView(List list){
37 | this.list = list;
38 | notifyDataSetChanged();
39 | }
40 |
41 | @Override
42 | public int getCount() {
43 | return list.size();
44 | }
45 |
46 | @Override
47 | public Object getItem(int position) {
48 | return list.get(position);
49 | }
50 |
51 | @Override
52 | public long getItemId(int position) {
53 | return position;
54 | }
55 |
56 |
57 |
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/http/MyHttpClient.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.http;
2 |
3 | import java.util.HashMap;
4 |
5 | import com.loopj.android.http.AsyncHttpClient;
6 | import com.loopj.android.http.AsyncHttpResponseHandler;
7 | import com.loopj.android.http.RequestParams;
8 |
9 | /**
10 | * @Description:使用了android-async-http的网络帮助类
11 | * @author http://blog.csdn.net/finddreams
12 | */
13 | public class MyHttpClient {
14 |
15 | private static int CONNECTTIMEOUT = 15 * 1000; // 连接超时
16 | private static AsyncHttpClient client;
17 | private MyHttpClient(){
18 | }
19 | public static AsyncHttpClient getHttpClient(){
20 | if(client==null){
21 | client=new AsyncHttpClient();
22 | client.setTimeout(CONNECTTIMEOUT);
23 | }
24 | return client;
25 | }
26 | /**
27 | * 带参数的get请求
28 | * @param urlString
29 | * @param params
30 | * @param res
31 | */
32 | public void sendGet(String urlString, RequestParams params,
33 | AsyncHttpResponseHandler res){
34 |
35 | client.get(urlString, params, res);
36 |
37 | }
38 | public void sendGet(String url,AsyncHttpResponseHandler responseHandler){
39 | client.get(url, responseHandler);
40 | }
41 |
42 | public void sendPost(String url,RequestParams params,HashMap vaules,AsyncHttpResponseHandler responseHandler){
43 |
44 | client.post(url, params, responseHandler);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/http/MyHttpUtils.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.http;
2 |
3 | import java.io.IOException;
4 |
5 | import org.apache.http.HttpEntity;
6 |
7 | import android.content.Context;
8 |
9 | import com.finddreams.baselib.R;
10 | import com.finddreams.baselib.utils.StringUtil;
11 | import com.finddreams.baselib.utils.ToastManager;
12 | import com.lidroid.xutils.HttpUtils;
13 | import com.lidroid.xutils.http.RequestParams;
14 | import com.lidroid.xutils.http.callback.RequestCallBack;
15 | import com.lidroid.xutils.http.client.HttpRequest;
16 | import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
17 | import com.lidroid.xutils.util.LogUtils;
18 |
19 | /**
20 | * 自定义的HttpUtils
21 | *
22 | * @author liuxiang
23 | * @date 2015-2-5 下午3:46:48
24 | * @version V1.0
25 | */
26 | public class MyHttpUtils {
27 |
28 | private static final int CONNTIMEOUT = 1000 * 15;
29 | private static final int CACHE_TIME = 1000 * 20;
30 | private static HttpUtils http;
31 | private Context context;
32 |
33 | public MyHttpUtils(Context context) {
34 | this.context = context;
35 | http = new HttpUtils(CONNTIMEOUT);
36 |
37 | }
38 |
39 | public void setCache() {
40 | http.configCurrentHttpCacheExpiry(CACHE_TIME);
41 | }
42 |
43 | public void httpGet(String url, RequestCallBack callback) {
44 | http(HttpMethod.GET, url, null, callback);
45 | }
46 |
47 | public void httpPost(String url, RequestParams params,
48 | RequestCallBack callback) {
49 | http(HttpMethod.POST, url, params, callback);
50 | }
51 |
52 | protected void http(HttpRequest.HttpMethod method, String url,
53 | RequestParams params, RequestCallBack callback) {
54 | http.configCurrentHttpCacheExpiry(CACHE_TIME);
55 | LogUtils.allowD = true;
56 | if (params != null) {
57 | if (params.getQueryStringParams() != null)
58 | LogUtils.d(url + params.getQueryStringParams().toString());
59 | HttpEntity entity = params.getEntity();
60 | if (entity != null) {
61 |
62 | try {
63 | LogUtils.d(url + StringUtil.convertStreamToString(entity.getContent()));
64 | } catch (IOException e) {
65 |
66 | e.printStackTrace();
67 | }
68 | }
69 | } else {
70 | params = new RequestParams();
71 | }
72 |
73 | if (0 == NetStateUtil.isNetworkAvailable(context)) {
74 | showCustomToast(context.getString(R.string.no_net));
75 | http.send(method, url, params, callback);
76 | } else {
77 | http.send(method, url, params, callback);
78 | }
79 | }
80 |
81 | protected void showCustomToast(String str) {
82 | ToastManager.showShortText(context, str);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/http/NetStateUtil.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.http;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 | import android.telephony.TelephonyManager;
7 |
8 | import com.finddreams.baselib.service.ServiceManager;
9 | /**
10 | * @Description:检查网络状态的工具类
11 | * @author http://blog.csdn.net/finddreams
12 | */
13 | public class NetStateUtil {
14 |
15 | /**
16 | * Check current network whether available
17 | * @param context
18 | * @return
19 | */
20 | public static boolean checkNet(Context context) {
21 |
22 | ConnectivityManager manager = ServiceManager.getConnectivityManager(context);
23 | NetworkInfo info = manager.getActiveNetworkInfo();
24 | if (info != null && info.isAvailable() && info.isConnected()) {
25 | return true;
26 | }else {
27 | return false;
28 | }
29 | }
30 |
31 | /**
32 | * Judge network whether Wifi connectivity
33 | * @param context
34 | * @return
35 | */
36 | public static boolean isWifi(Context context) {
37 | ConnectivityManager manager = ServiceManager.getConnectivityManager(context);
38 | NetworkInfo networkInfo = manager.getActiveNetworkInfo();
39 | if (networkInfo != null) {
40 | int type = networkInfo.getType();
41 | if (networkInfo.isAvailable() && networkInfo.isConnected() && type == ConnectivityManager.TYPE_WIFI ) {
42 | return true;
43 | }
44 | }
45 | return false;
46 | }
47 | /**
48 | * 判断当前网络是否是移动流量连接
49 | * @param context
50 | * @return
51 | */
52 | public static boolean isMobile(Context context) {
53 | ConnectivityManager manager = ServiceManager.getConnectivityManager(context);
54 | NetworkInfo networkInfo = manager.getActiveNetworkInfo();
55 | if (networkInfo != null) {
56 | int type = networkInfo.getType();
57 | if (networkInfo.isAvailable() && networkInfo.isConnected() && type == ConnectivityManager.TYPE_MOBILE) {
58 | return true;
59 | }
60 | }
61 | return false;
62 | }
63 |
64 | /**
65 | * Whether open wifi
66 | * @param context
67 | * @return
68 | */
69 | public static boolean isWifiEnabled(Context context) {
70 | ConnectivityManager mgrConn = ServiceManager.getConnectivityManager(context);
71 | TelephonyManager mgrTel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
72 | return ((mgrConn.getActiveNetworkInfo() != null && mgrConn
73 | .getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel
74 | .getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
75 | }
76 | /**
77 | * 判断当前是否有可用的网络以及网络类型 0:无网络 1:WIFI 2:CMWAP 3:CMNET
78 | *
79 | * @param context
80 | * @return
81 | */
82 | public static int isNetworkAvailable(Context context) {
83 | ConnectivityManager connectivity = (ConnectivityManager) context
84 | .getSystemService(Context.CONNECTIVITY_SERVICE);
85 | if (connectivity == null) {
86 | return 0;
87 | } else {
88 | NetworkInfo[] info = connectivity.getAllNetworkInfo();
89 | if (info != null) {
90 | for (int i = 0; i < info.length; i++) {
91 | if (info[i].getState() == NetworkInfo.State.CONNECTED) {
92 | NetworkInfo netWorkInfo = info[i];
93 | if (netWorkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
94 | return 1;
95 | } else if (netWorkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
96 | String extraInfo = netWorkInfo.getExtraInfo();
97 | if ("cmwap".equalsIgnoreCase(extraInfo)
98 | || "cmwap:gsm".equalsIgnoreCase(extraInfo)) {
99 | return 2;
100 | }
101 | return 3;
102 | }
103 | }
104 | }
105 | }
106 | }
107 | return 0;
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/http/URLUtils.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.http;
2 |
3 | import java.net.URISyntaxException;
4 | import java.util.ArrayList;
5 | import java.util.Iterator;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | import org.apache.http.client.utils.URIUtils;
10 | import org.apache.http.client.utils.URLEncodedUtils;
11 | import org.apache.http.message.BasicNameValuePair;
12 |
13 | import com.lidroid.xutils.HttpUtils;
14 | import com.lidroid.xutils.util.LogUtils;
15 |
16 | /**
17 | * @Description:url的帮助类
18 | * @author http://blog.csdn.net/finddreams
19 | */
20 | public class URLUtils {
21 |
22 | public final static String HOST = "blog.csdn.net";
23 | public static final String PATH = "finddreams";
24 | public static final String SCHEME = "http";
25 | public static final String defaultEncoding = "UTF-8";
26 |
27 | public static String getUrl(String baseurl) {
28 | if (baseurl != null) {
29 | String url = SCHEME + "://" + HOST + "/" + PATH + baseurl;
30 | return url;
31 | }
32 | return null;
33 | }
34 | /**
35 | * 创建Url
36 | * @param resource
37 | * @return
38 | */
39 | public static String createURL(String resource) {
40 | try {
41 | String url = URIUtils.createURI(SCHEME, HOST, -1, PATH + resource,
42 | "", null).toString();
43 | LogUtils.d(url);
44 | return url;
45 | } catch (URISyntaxException e) {
46 | e.printStackTrace();
47 | }
48 | return null;
49 | }
50 |
51 | public static String createURL(String resource, Map params) {
52 | return createURL(resource, params, defaultEncoding);
53 | }
54 |
55 | public static String createURL(String resource, Map params,
56 | String encoding) {
57 | List parameters = new ArrayList();
58 | for (Iterator> it = params.entrySet()
59 | .iterator(); it.hasNext();) {
60 | Map.Entry entry = (Map.Entry) it
61 | .next();
62 | parameters.add(new BasicNameValuePair(entry.getKey(), entry
63 | .getValue()));
64 | }
65 |
66 | try {
67 | String url = URIUtils.createURI(SCHEME, HOST, -1, PATH + resource,
68 | URLEncodedUtils.format(parameters, encoding), null)
69 | .toString();
70 |
71 | LogUtils.d(url);
72 | return url;
73 | } catch (URISyntaxException e) {
74 | e.printStackTrace();
75 | }
76 | return null;
77 |
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/service/ServiceManager.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.service;
2 |
3 | import android.app.Service;
4 | import android.content.Context;
5 | import android.hardware.Sensor;
6 | import android.hardware.SensorManager;
7 | import android.location.LocationManager;
8 | import android.net.ConnectivityManager;
9 | import android.os.Vibrator;
10 | import android.telephony.TelephonyManager;
11 | import android.view.LayoutInflater;
12 | import android.view.inputmethod.InputMethodManager;
13 |
14 | /**
15 | * @Description:获得系统服务管理器
16 | * @author http://blog.csdn.net/finddreams
17 | */
18 | public class ServiceManager {
19 |
20 | private static ConnectivityManager cm;
21 | private static LocationManager locationManager;
22 | private static TelephonyManager telephonyManager;
23 | private static InputMethodManager inputMethodManager;
24 | private static Vibrator vibrator;
25 | private static SensorManager sensorManager;
26 | private static Sensor accelerometerSensor;
27 | private static Sensor lightSensor;//光线传感器引用
28 | private static LayoutInflater inflater;
29 |
30 | private ServiceManager(){};
31 |
32 | /**
33 | * 获得ConnectivityManager
34 | * @param context
35 | * @return
36 | */
37 | public static ConnectivityManager getConnectivityManager(Context context) {
38 |
39 | if (cm == null) {
40 | synchronized (ServiceManager.class) {
41 | if (cm == null) {
42 | cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
43 | }
44 | }
45 | }
46 | return cm;
47 | }
48 |
49 | /**
50 | * 获得LocationManager
51 | * @param context
52 | * @return
53 | */
54 | public static LocationManager getLocationManager(Context context) {
55 | if (locationManager == null) {
56 | synchronized (ServiceManager.class) {
57 | if (locationManager == null) {
58 | locationManager = ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE));
59 | }
60 | }
61 | }
62 | return locationManager;
63 | }
64 | /**
65 | * 获得TelephonyManager
66 | * @param context
67 | * @return
68 | */
69 | public static TelephonyManager getTelephonyManager(Context context) {
70 | if (telephonyManager == null) {
71 | synchronized(ServiceManager.class) {
72 | if (telephonyManager == null) {
73 | telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
74 | }
75 | }
76 | }
77 | return telephonyManager;
78 | }
79 | /**
80 | * 获得InputMethodManager
81 | * @param context
82 | * @return
83 | */
84 | public static InputMethodManager getInputMethodManager(Context context) {
85 | if (inputMethodManager == null) {
86 | synchronized(ServiceManager.class) {
87 | if (inputMethodManager == null) {
88 | inputMethodManager = ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE));
89 | }
90 | }
91 | }
92 | return inputMethodManager;
93 | }
94 |
95 | /**
96 | * 获得震动的控制器
97 | * @param context
98 | * @return
99 | */
100 | public static Vibrator getVibrator(Context context) {
101 | if (vibrator == null) {
102 | synchronized(ServiceManager.class) {
103 | if (vibrator == null) {
104 | vibrator = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
105 | }
106 | }
107 | }
108 | return vibrator;
109 | }
110 | /**
111 | * 获得传感器管理器
112 | * @param context
113 | * @return
114 | */
115 | public static SensorManager getSensorManager(Context context) {
116 | if (sensorManager == null) {
117 | synchronized(ServiceManager.class) {
118 | if (sensorManager == null) {
119 | sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
120 | }
121 | }
122 | }
123 | return sensorManager;
124 | }
125 | /**
126 | * 获得加速管理器
127 | * @param context
128 | * @return
129 | */
130 | public static Sensor getAccelerometerSensor(Context context) {
131 | if ( accelerometerSensor == null ){
132 | synchronized(ServiceManager.class) {
133 | if (accelerometerSensor == null) {
134 | accelerometerSensor = getSensorManager(context).getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
135 | }
136 | }
137 | }
138 | return accelerometerSensor;
139 | }
140 | public static Sensor getLightSensor(Context context) {
141 | if ( lightSensor == null ){
142 | synchronized(ServiceManager.class) {
143 | if (lightSensor == null) {
144 | lightSensor = getSensorManager(context).getDefaultSensor(Sensor.TYPE_LIGHT);
145 | }
146 | }
147 | }
148 | return lightSensor;
149 | }
150 |
151 | public static LayoutInflater getLayoutInflate(Context context) {
152 | if ( inflater == null ){
153 | synchronized(ServiceManager.class) {
154 | if (inflater == null) {
155 | inflater = LayoutInflater.from(context);
156 | }
157 | }
158 | }
159 | return inflater;
160 | }
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/ActivityUtil.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import java.io.File;
4 | import java.util.Timer;
5 | import java.util.TimerTask;
6 |
7 | import android.app.Activity;
8 | import android.content.ComponentName;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.net.Uri;
12 | import android.os.Bundle;
13 |
14 | import com.finddreams.baselib.R;
15 | /**
16 | * @Description: Activity的工具类
17 | * @author http://blog.csdn.net/finddreams
18 | */
19 | public class ActivityUtil {
20 |
21 | private static final String TAG = "ActivityUtil";
22 |
23 | /**
24 | * 延迟去往新的Activity
25 | * @param context
26 | * @param cls
27 | * @param delay
28 | */
29 | public static void delayToActivity(final Context context,final Class> cls,long delay) {
30 | Timer timer = new Timer();
31 | timer.schedule(new TimerTask() {
32 |
33 | @Override
34 | public void run() {
35 | context.startActivity(new Intent(context, cls));
36 | }
37 | }, delay);
38 | }
39 | /**
40 | * 跳转到另一个Activity,不携带数据,不设置flag
41 | * @param context
42 | * @param cls
43 | */
44 | public static void goToActivity(Context context,Class> cls) {
45 | Intent intent = new Intent();
46 | intent.setClass(context, cls);
47 | // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
48 | context.startActivity(intent);
49 | }
50 | /**
51 | * go to activity,use animation
52 | * @param context
53 | * @param cls
54 | * @param enterAnim
55 | * @param exitAnim
56 | */
57 | public static void goToActivity(Context context,Class> cls,int enterAnim,int exitAnim,Bundle bundle) {
58 | Activity activity = (Activity)context;
59 | Intent intent = new Intent();
60 | intent.setClass(activity, cls);
61 | intent.putExtras(bundle);
62 | activity.startActivity(intent);
63 | activity.overridePendingTransition(enterAnim,exitAnim);
64 | }
65 | /**
66 | * to new activity,use animation from right to left
67 | * @param context
68 | * @param cls
69 | */
70 | public static void goToActivityFromLeft2Right(Context context,Class> cls) {
71 | Activity activity = (Activity)context;
72 | Intent intent = new Intent();
73 | intent.setClass(activity, cls);
74 | activity.startActivity(intent);
75 | activity.overridePendingTransition(R.anim.in_from_right,R.anim.out_to_right);
76 | }
77 | /**
78 | * to new activity,use animation from right to left carry data
79 | * @param context
80 | * @param cls
81 | */
82 | public static void goToActivityFromLeft2Right(Context context,Class> cls,Bundle bundle) {
83 | Activity activity = (Activity)context;
84 | Intent intent = new Intent();
85 | intent.setClass(activity, cls);
86 | intent.putExtras(bundle);
87 | activity.startActivity(intent);
88 | activity.overridePendingTransition(R.anim.in_from_right,R.anim.out_to_right);
89 | }
90 | /**
91 | * to new activity,use animation from left to right
92 | * @param context
93 | * @param cls
94 | */
95 | public static void goToActivityFromRight2Left(Context context,Class> cls) {
96 | Activity activity = (Activity)context;
97 | Intent intent = new Intent();
98 | intent.setClass(activity, cls);
99 | activity.startActivity(intent);
100 | activity.overridePendingTransition(R.anim.in_from_left,R.anim.out_to_left);
101 | }
102 | /**
103 | * to new activity,use animation from left to right carry data
104 | * @param context
105 | * @param cls
106 | */
107 | public static void goToActivityFromRight2Left(Context context,Class> cls,Bundle bundle) {
108 | Activity activity = (Activity)context;
109 | Intent intent = new Intent();
110 | intent.setClass(activity, cls);
111 | intent.putExtras(bundle);
112 | activity.startActivity(intent);
113 | activity.overridePendingTransition(R.anim.in_from_left,R.anim.out_to_left);
114 | }
115 | /**
116 | * to new activity,use animation from bottom to top carry data
117 | * @param context
118 | * @param cls
119 | * @param bundle
120 | */
121 | public static void goToActivityFromBottom2Top(Context context,Class> cls,Bundle bundle) {
122 | Activity activity = (Activity)context;
123 | Intent intent = new Intent();
124 | intent.setClass(activity, cls);
125 | intent.putExtras(bundle);
126 | activity.startActivity(intent);
127 | activity.overridePendingTransition(R.anim.in_from_bottom,R.anim.out_to_top);
128 | }
129 | /**
130 | * to new activity,use animation from bottom to top
131 | * @param context
132 | * @param cls
133 | * @param bundle
134 | */
135 | public static void goToActivityFromBottom2Top(Context context,Class> cls) {
136 | Activity activity = (Activity)context;
137 | Intent intent = new Intent();
138 | intent.setClass(activity, cls);
139 | activity.startActivity(intent);
140 | activity.overridePendingTransition(R.anim.in_from_bottom,R.anim.out_to_top);
141 | }
142 | /**
143 | * to new activity,use animation form top to bottom
144 | * @param context
145 | * @param cls
146 | */
147 | public static void goToActivityFromTop2Bottom(Context context,Class> cls) {
148 | Activity activity = (Activity)context;
149 | Intent intent = new Intent();
150 | intent.setClass(activity, cls);
151 | activity.startActivity(intent);
152 | activity.overridePendingTransition(R.anim.in_from_top,R.anim.out_to_bottom);
153 | }
154 |
155 |
156 | /**
157 | * 跳转到另一个Activity,携带数据
158 | * @param context
159 | * @param cls
160 | */
161 | public static void goToActivity(Context context,Class> cls,Bundle bundle) {
162 | Intent intent = new Intent();
163 | intent.setClass(context, cls);
164 | intent.putExtras(bundle);
165 | context.startActivity(intent);
166 | }
167 |
168 |
169 | }
170 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/AppHelper.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.pm.PackageInfo;
7 | import android.content.pm.PackageManager;
8 | import android.content.pm.PackageManager.NameNotFoundException;
9 | import android.net.Uri;
10 | /**
11 | * @Description: app的帮助类
12 | * @author http://blog.csdn.net/finddreams
13 | */
14 | public class AppHelper {
15 |
16 | private static final String TAG = "AppHelper";
17 | /**
18 | * @param context
19 | * @return
20 | */
21 | public static String getAppVersion(Context context) {
22 | try {
23 | // 获取packagemanager的实例
24 | PackageManager packageManager = context.getPackageManager();
25 | // getPackageName()是你当前类的包名,0代表是获取版本信息
26 | PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(),0);
27 | String version = packInfo.versionName;
28 | return version;
29 | } catch (NameNotFoundException e) {
30 | e.printStackTrace();
31 | }
32 | return null;
33 | }
34 |
35 | /**
36 | * get android os version no
37 | * @return
38 | */
39 | public static float getAndroidVersion() {
40 | return Float.valueOf(android.os.Build.VERSION.RELEASE);
41 | }
42 |
43 | /**
44 | * get device model
45 | * @return
46 | */
47 | public String getDeviceModel () {
48 | return android.os.Build.MODEL;
49 | }
50 |
51 | /**
52 | * get android os sdk version 2.2 = 8,2.3 = 9,4.2.1 = 17
53 | * @return sdk version
54 | */
55 | public static int getSDKVersion(){
56 | return android.os.Build.VERSION.SDK_INT;
57 | }
58 | /**
59 | * 根据Uri安装apk
60 | * @param context
61 | * @param uri
62 | */
63 | public void installApk(Context context,Uri uri) {
64 | if (uri.toString().endsWith(".apk")) {
65 | Intent intent = new Intent();
66 | intent.setAction(Intent.ACTION_VIEW);
67 | // intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
68 | intent.setDataAndType(uri,"application/vnd.android.package-archive");
69 | context.startActivity(intent);
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/AppManager.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 |
4 | import java.util.Stack;
5 |
6 | import android.app.Activity;
7 | import android.app.ActivityManager;
8 | import android.content.Context;
9 | /**
10 | ****************************************
11 | * @author 刘祥
12 | * @Description: 这是一个管理Activity的类,可以对项目中Activity的生命周期进行管理,
13 | * 达到安全退出的目的;
14 | * @date 2014-7-7 下午3:30:52
15 | *****************************************
16 | */
17 | public class AppManager {
18 |
19 | private static Stack activityStack;
20 | private static AppManager instance;
21 |
22 | private AppManager(){}
23 | /**
24 | * 单一实例
25 | */
26 | public static AppManager getAppManager(){
27 | if(instance==null){
28 | instance=new AppManager();
29 | }
30 | return instance;
31 | }
32 | /**
33 | * 添加Activity到堆栈中
34 | */
35 | public void addActivity(Activity activity){
36 | if(activityStack==null){
37 | activityStack=new Stack();
38 | }
39 | activityStack.add(activity);
40 | }
41 | /**
42 | * 获取当前Activity(堆栈中最后压入的)
43 | */
44 | public Activity currentActivity(){
45 | Activity activity=activityStack.lastElement();
46 | return activity;
47 | }
48 | /**
49 | * 结束当前Activity(堆栈中最后压入的)
50 | */
51 | public void finishActivity(){
52 | Activity activity=activityStack.lastElement();
53 | finishActivity(activity);
54 | }
55 | /**
56 | * 结束指定的Activity
57 | */
58 | public void finishActivity(Activity activity){
59 | if(activity!=null){
60 | activityStack.remove(activity);
61 | activity.finish();
62 | activity=null;
63 | }
64 | }
65 | /**
66 | * 结束指定类名的Activity
67 | */
68 | public void finishActivity(Class> cls){
69 | for (Activity activity : activityStack) {
70 | if(activity.getClass().equals(cls) ){
71 | finishActivity(activity);
72 | }
73 | }
74 | }
75 | /**
76 | * 结束所有Activity
77 | */
78 | public void finishAllActivity(){
79 | for (int i = 0, size = activityStack.size(); i < size; i++){
80 | if (null != activityStack.get(i)){
81 | activityStack.get(i).finish();
82 | }
83 | }
84 | activityStack.clear();
85 | }
86 | /**
87 | * 彻底退出应用程序,安全退出
88 | */
89 | public void AppExit(Context context) {
90 | try {
91 | finishAllActivity();
92 | ActivityManager activityMgr= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
93 | activityMgr.restartPackage(context.getPackageName());
94 | System.exit(0);
95 | android.os.Process.killProcess(android.os.Process.myPid());
96 | } catch (Exception e) { }
97 | }
98 | }
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/BroadcastHelper.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | public class BroadcastHelper {
7 |
8 | public static void sendCommonBroadCast(Context context,String content) {
9 | Intent intent = new Intent();
10 | intent.setAction(ConstantsValue.COMMON_ACTION);
11 | intent.addCategory(Intent.CATEGORY_DEFAULT);
12 | intent.putExtra(ConstantsValue.COMMON_ACTION, content);
13 | context.sendBroadcast(intent);
14 | }
15 |
16 | public static void sendBroadCast(Context context,String action,String key,String value) {
17 | Intent intent = new Intent();
18 | intent.setAction(action);
19 | intent.addCategory(Intent.CATEGORY_DEFAULT);
20 | intent.putExtra(key, value);
21 | context.sendBroadcast(intent);
22 | }
23 |
24 | public static void sendBroadCast(Context context,String action,String key,int value) {
25 | Intent intent = new Intent();
26 | intent.setAction(action);
27 | intent.addCategory(Intent.CATEGORY_DEFAULT);
28 | intent.putExtra(key, value);
29 | context.sendBroadcast(intent);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/CacheUtil.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.ObjectInputStream;
7 | import java.io.ObjectOutputStream;
8 |
9 | import android.content.Context;
10 |
11 | /**
12 | * 缓存工具
13 | */
14 | public class CacheUtil {
15 | public final static int MAX_FAILCOUNT = 3; // 最大失败次数,超过即不再重新抓取
16 | public final static String TAG = "CacheTools";
17 |
18 | /**
19 | * 保存HTTP缓存
20 | *
21 | * @param cacheDir
22 | * @param cacheKey
23 | * @param cacheValue
24 | * @return
25 | */
26 | public static boolean saveHttpCache(String cacheDir, String cacheKey,
27 | Object cacheValue) {
28 | boolean flag = false;
29 | int cnt = 0;
30 | do {
31 | try {
32 | File destDir = new File(cacheDir);
33 | if (!destDir.exists()) {
34 | destDir.mkdirs();
35 | }
36 | ObjectOutputStream os = new ObjectOutputStream(
37 | new FileOutputStream(cacheDir + cacheKey));
38 | os.writeObject(cacheValue);
39 | os.close();
40 | flag = true;
41 | break;
42 | } catch (Exception e) {
43 | cnt++;
44 | LogManager.i(TAG, "写入缓存失败,正在尝试第" + cnt + "次重新写入");
45 | }
46 | } while (cnt < MAX_FAILCOUNT);
47 | return flag;
48 | }
49 |
50 | /**
51 | * 读取 HTTP 缓存
52 | *
53 | * @param cacheDir
54 | * @param cacheKey
55 | * @return
56 | */
57 |
58 | public static Object readHttpCache(String cacheDir, String cacheKey) {
59 | File file = new File(cacheDir + cacheKey);
60 | if (!file.exists()) {
61 | return null;
62 | }
63 | Object cacheObj = null;
64 | int cnt = 0;
65 | do {
66 | try {
67 | ObjectInputStream is = new ObjectInputStream(
68 | new FileInputStream(file));
69 | cacheObj = is.readObject();
70 | is.close();
71 | break;
72 | } catch (Exception e) {
73 | e.printStackTrace();
74 | cnt++;
75 | LogManager.i(TAG, "读取缓存失败,正在尝试第" + cnt + "次重新读取");
76 | }
77 | } while (cnt < MAX_FAILCOUNT);
78 | return cacheObj;
79 | }
80 |
81 | public static void clearAppCache(Context context) {
82 | context.deleteDatabase("webview.db");
83 | context.deleteDatabase("webview.db-shm");
84 | context.deleteDatabase("webview.db-wal");
85 | context.deleteDatabase("webviewCache.db");
86 | context.deleteDatabase("webviewCache.db-shm");
87 | context.deleteDatabase("webviewCache.db-wal");
88 | // 清除数据缓存
89 | clearFolder(context.getFilesDir(), System.currentTimeMillis());
90 | clearFolder(context.getCacheDir(), System.currentTimeMillis());
91 | }
92 |
93 | /**
94 | * 清除文件存目录
95 | *
96 | * @param dir
97 | * 目录
98 | * @param numDays
99 | * 当前系统时间
100 | * @return
101 | */
102 | public static int clearFolder(File dir, long curTime) {
103 | int cnt = 0;
104 | int deletedFiles = 0;
105 | do {
106 | if (dir != null && dir.isDirectory()) {
107 | try {
108 | for (File child : dir.listFiles()) {
109 | if (child.isDirectory()) {
110 | deletedFiles += clearFolder(child, curTime);
111 | }
112 | if (child.lastModified() < curTime) {
113 | if (child.delete()) {
114 | deletedFiles++;
115 | }
116 | }
117 | }
118 | } catch (Exception e) {
119 | cnt++;
120 | LogManager.i(TAG, "清除缓存失败,正在尝试第" + cnt + "清除缓存");
121 | }
122 | }
123 | return deletedFiles;
124 | } while (cnt < MAX_FAILCOUNT);
125 |
126 | }
127 |
128 | /**
129 | * 计算缓存大小
130 | *
131 | * @param context
132 | * @return
133 | */
134 | public static String getHttpCacheSize(Context context) {
135 | // 计算缓存大小
136 | long fileSize = 0;
137 | String cacheSize = "0KB";
138 | File filesDir = context.getFilesDir();
139 | File cacheDir = context.getCacheDir();
140 | fileSize += getDirSize(filesDir);
141 | fileSize += getDirSize(cacheDir);
142 | // fileSize += getDirSize(ImageLoader.getInstance().getDiscCache()
143 | // .getDirectory());
144 |
145 | if (fileSize > 0)
146 | cacheSize = formatFileSize(fileSize);
147 | return cacheSize;
148 | }
149 |
150 | /**
151 | * 获取目录文件大小
152 | *
153 | * @param dir
154 | * @return
155 | */
156 | public static long getDirSize(File dir) {
157 | if (dir == null) {
158 | return 0;
159 | }
160 | if (!dir.isDirectory()) {
161 | return 0;
162 | }
163 | long dirSize = 0;
164 | File[] files = dir.listFiles();
165 | for (File file : files) {
166 | if (file.isFile()) {
167 | dirSize += file.length();
168 | } else if (file.isDirectory()) {
169 | dirSize += file.length();
170 | dirSize += getDirSize(file); // 递归调用继续统计
171 | }
172 | }
173 | return dirSize;
174 | }
175 |
176 | /**
177 | * 转换文件大小
178 | *
179 | * @param fileS
180 | * @return B/KB/MB/GB
181 | */
182 | public static String formatFileSize(long fileS) {
183 | java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
184 | String fileSizeString = "";
185 | if (fileS < 1024) {
186 | fileSizeString = df.format((double) fileS) + "B";
187 | } else if (fileS < 1048576) {
188 | fileSizeString = df.format((double) fileS / 1024) + "KB";
189 | } else if (fileS < 1073741824) {
190 | fileSizeString = df.format((double) fileS / 1048576) + "MB";
191 | } else {
192 | fileSizeString = df.format((double) fileS / 1073741824) + "G";
193 | }
194 | return fileSizeString;
195 | }
196 | }
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/ConstantsValue.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import android.os.Environment;
4 |
5 | public class ConstantsValue {
6 |
7 | public static final String COMMON_ACTION = "finddreams";
8 | private static final String IMAGE_PATH_DIR = "/.finddreams/img/";
9 | private static final String IMAGE_APP_PATH_DIR = "/.finddreams/app_img/";
10 | private static final String APP_LOG_PATH_DIR = "/.finddreams/log/";
11 | public static final String IMAGE_APP_PATH = Environment.getExternalStorageDirectory() + IMAGE_APP_PATH_DIR;
12 |
13 | public static final boolean DEBUG = true;
14 | public static final String INTENT_URL = "url";
15 | public static final String INTENT_TITLE = "title";
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/DateUtil.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Calendar;
6 | import java.util.Date;
7 |
8 | import android.util.Log;
9 |
10 | public class DateUtil {
11 |
12 | private static final String TAG = "DateUtil";
13 |
14 | private static final String FORMAT1= "yyyy-MM-dd HH:mm:ss";
15 | private static final String FORMAT2 = "yyyyMMddHHmmss";
16 | private static SimpleDateFormat sdfNormal;
17 | private static SimpleDateFormat sdfStr;
18 |
19 | static {
20 | sdfNormal = new SimpleDateFormat(FORMAT1);
21 | sdfStr = new SimpleDateFormat(FORMAT2);
22 | }
23 |
24 | public static String formatDate(String date){
25 | String format = null;
26 | try {
27 | if (date == null || "".equals(date)) {
28 | return "";
29 | }
30 | format = sdfNormal.format(sdfNormal.parse(date));
31 | } catch (ParseException e) {
32 | LogManager.e(TAG, "formatDate", e);
33 | return date;
34 | }
35 | return format;
36 | }
37 | /**
38 | * get current date,date pattern : yyyy-MM-dd HH:mm:ss
39 | * @return
40 | */
41 | public static String getCurrentDate(){
42 | String format = null;
43 | format = sdfNormal.format(new Date());
44 | return format;
45 | }
46 |
47 | public static String formatDateStr(String date) {
48 | String format = null;
49 | try {
50 | Date parseDate = sdfStr.parse(date);
51 | format = sdfNormal.format(parseDate);
52 | } catch (ParseException e) {
53 | LogManager.e(TAG, "formatDateStr", e);
54 | return date;
55 | }
56 | return format;
57 | }
58 |
59 | /**
60 | * 获取当前时间的字符串
61 | */
62 | public static String getCurrentDateStr() {
63 | Date date = new Date();
64 | Calendar c = Calendar.getInstance();
65 | c.setTime(date);
66 | String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
67 | int w = c.get(Calendar.DAY_OF_WEEK) - 1;
68 | if (w < 0) {
69 | w = 0;
70 | }
71 | String mDate = c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1)
72 | + "月" + c.get(Calendar.DATE) + "日 " + weekDays[w];
73 | return mDate;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/DisplayUtil.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | import android.app.Activity;
6 | import android.content.Context;
7 | import android.graphics.Bitmap;
8 | import android.graphics.Rect;
9 | import android.util.DisplayMetrics;
10 | /**
11 | * @Description:屏幕显示的工具类
12 | * @author http://blog.csdn.net/finddreams
13 | */
14 | public class DisplayUtil {
15 |
16 | public static final String TAG = "DisplayUtil";
17 |
18 | /**
19 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
20 | */
21 | public static int dip2px(Context context, float dpValue) {
22 | final float scale = context.getResources().getDisplayMetrics().density;
23 | return (int) (dpValue * scale + 0.5f);
24 | }
25 |
26 | /**
27 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
28 | */
29 | public static int px2dip(Context context, float pxValue) {
30 | final float scale = context.getResources().getDisplayMetrics().density;
31 | return (int) (pxValue / scale + 0.5f);
32 | }
33 |
34 | public static int getScreenPicHeight(int screenWidth, Bitmap bitmap) {
35 | int picWidth = bitmap.getWidth();
36 | int picHeight = bitmap.getHeight();
37 | int picScreenHeight = 0;
38 | picScreenHeight = (screenWidth * picHeight) / picWidth;
39 | return picScreenHeight;
40 | }
41 | /**
42 | * 将px值转换为sp值,保证文字大小不变
43 | *
44 | * @param pxValue
45 | * @param fontScale
46 | * (DisplayMetrics类中属性scaledDensity)
47 | * @return
48 | */
49 | public static int px2sp(float pxValue, float fontScale) {
50 | return (int) (pxValue / fontScale + 0.5f);
51 | }
52 |
53 | /**
54 | * 将sp值转换为px值,保证文字大小不变
55 | *
56 | * @param spValue
57 | * @param fontScale
58 | * (DisplayMetrics类中属性scaledDensity)
59 | * @return
60 | */
61 | public static int sp2px(float spValue, float fontScale) {
62 | return (int) (spValue * fontScale + 0.5f);
63 | }
64 |
65 | public static int dp2px(Context context, float dpValue) {
66 | final float scale = context.getResources().getDisplayMetrics().density;
67 | return (int) (dpValue * scale + 0.5f);
68 | }
69 |
70 | public static int densityDPI(Context context){
71 | return context.getResources().getDisplayMetrics().densityDpi;
72 | }
73 | /**
74 | * 得到设备屏幕的宽度
75 | */
76 | public static int getScreenWidth(Context context) {
77 | return context.getResources().getDisplayMetrics().widthPixels;
78 | }
79 |
80 | /**
81 | * 得到设备屏幕的高度
82 | */
83 | public static int getScreenHeight(Context context) {
84 | return context.getResources().getDisplayMetrics().heightPixels;
85 | }
86 | /**
87 | * return system bar height
88 | * @param context
89 | * @return
90 | */
91 | public static int getStatuBarHeight(Context context) {
92 | try {
93 | Class> c = Class.forName("com.android.internal.R$dimen");
94 | Object obj;
95 | obj = c.newInstance();
96 | Field field = c.getField("status_bar_height");
97 | int width = Integer.parseInt(field.get(obj).toString());
98 | int height = context.getResources().getDimensionPixelSize(width);
99 | return height;
100 | } catch (Exception e) {
101 | e.printStackTrace();
102 | LogManager.e(TAG, "getStatuBarHeight",e);
103 | }
104 | return 0;
105 | }
106 |
107 | public static int getStatuBarHeight2(Context context) {
108 | Rect frame = new Rect();
109 | ((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
110 | int statusBarHeight = frame.top;
111 | return statusBarHeight;
112 | }
113 | /**
114 | * get screen height of this cellphone
115 | * @param context
116 | * @return
117 | */
118 | public static int getMobileHeight(Context context) {
119 | DisplayMetrics dm = new DisplayMetrics();
120 | ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
121 | int height = dm.heightPixels; //得到高度
122 | return height;
123 | }
124 | /**
125 | * get screen width of this cellphone
126 | * @param context
127 | * @return
128 | */
129 | public static int getMobileWidth(Context context) {
130 | DisplayMetrics dm = new DisplayMetrics();
131 | ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
132 | int width = dm.widthPixels; //得到宽度
133 | return width;
134 |
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | import android.os.Environment;
9 |
10 | public class FileUtil {
11 |
12 | public static final String ROOT = Environment.getExternalStorageDirectory().getPath() + "/nicehair/";
13 | public static final String CAMERA = Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/";
14 | public static final String CACHE_IMG ="/cache/images/";
15 | /**
16 | * 应用日志目录文件
17 | */
18 | public static String APP_LOG_PATH = ROOT + "log/";
19 |
20 | /**
21 | * 日志文件路径
22 | */
23 | public static String LOGFILE = APP_LOG_PATH + "log.txt";
24 |
25 | /**
26 | * 读取输入流数据
27 | *
28 | * @param inStream
29 | * @return
30 | */
31 | public static byte[] read(InputStream inStream) throws Exception {
32 | ByteArrayOutputStream outStream = new ByteArrayOutputStream();
33 | byte[] buffer = new byte[1024];
34 | int len = 0;
35 | while ((len = inStream.read(buffer)) != -1) {
36 | outStream.write(buffer, 0, len);
37 | }
38 | inStream.close();
39 | return outStream.toByteArray();
40 | }
41 | /**
42 | * 判断SD是否可以
43 | *
44 | * @return
45 | */
46 | public static boolean isSdcardExist() {
47 | if (Environment.getExternalStorageState().equals(
48 | Environment.MEDIA_MOUNTED)) {
49 | return true;
50 | }
51 | return false;
52 | }
53 |
54 | /**
55 | * 创建根目录
56 | *
57 | * @param path
58 | * 目录路径
59 | */
60 | public static void createDirFile(String path) {
61 | File dir = new File(path);
62 | if (!dir.exists()) {
63 | dir.mkdirs();
64 | }
65 | }
66 |
67 | /**
68 | * 创建文件
69 | *
70 | * @param path
71 | * 文件路径
72 | * @return 创建的文件
73 | */
74 | public static File createNewFile(String path) {
75 | File file = new File(path);
76 | if (!file.exists()) {
77 | try {
78 | file.createNewFile();
79 | } catch (IOException e) {
80 | return null;
81 | }
82 | }
83 | return file;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/com/finddreams/baselib/utils/GsonUtil.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.baselib.utils;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import com.google.gson.Gson;
7 | import com.google.gson.reflect.TypeToken;
8 | /**
9 | * @Description:谷歌的Gson解析工具类,官方推荐
10 | * @author http://blog.csdn.net/finddreams
11 | */
12 | public class GsonUtil {
13 |
14 | public GsonUtil() {
15 | // TODO Auto-generated constructor stub
16 | }
17 |
18 | public static String createGsonString(Object object) {
19 | Gson gson = new Gson();
20 | String gsonString = gson.toJson(object);
21 | return gsonString;
22 | }
23 |
24 | public static T changeGsonToBean(String gsonString, Class cls) {
25 | Gson gson = new Gson();
26 | T t = gson.fromJson(gsonString, cls);
27 | return t;
28 | }
29 |
30 | public static List changeGsonToList(String gsonString, Class cls) {
31 | Gson gson = new Gson();
32 | List list = gson.fromJson(gsonString, new TypeToken>() {}.getType());
33 | return list;
34 | }
35 |
36 |
37 |
38 | public static List