├── README.md
├── LBase
├── lint.xml
├── bin
│ ├── lbase.jar
│ ├── classes
│ │ └── com
│ │ │ └── leo
│ │ │ └── base
│ │ │ ├── util
│ │ │ ├── L.class
│ │ │ ├── MD5.class
│ │ │ ├── LBitmap.class
│ │ │ ├── LDate.class
│ │ │ ├── LFormat.class
│ │ │ ├── LDiscConn.class
│ │ │ ├── LMobileInfo.class
│ │ │ └── LSharePreference.class
│ │ │ ├── BuildConfig.class
│ │ │ ├── cache
│ │ │ └── LCache.class
│ │ │ ├── db
│ │ │ ├── LDBHelper.class
│ │ │ └── LDBManager.class
│ │ │ ├── net
│ │ │ ├── LCaller.class
│ │ │ ├── LNetwork.class
│ │ │ ├── ILNetwork.class
│ │ │ ├── ILNetworkCallback.class
│ │ │ ├── LNetwork$LReqState.class
│ │ │ └── ILNetwork$LReqResultState.class
│ │ │ ├── adapter
│ │ │ ├── LAdapters.class
│ │ │ ├── LBaseAdapter.class
│ │ │ └── LPagerAdapter.class
│ │ │ ├── entity
│ │ │ ├── LMessage$1.class
│ │ │ ├── LMessage.class
│ │ │ ├── LReqEncode.class
│ │ │ ├── LReqEntity.class
│ │ │ ├── LReqFile.class
│ │ │ ├── LReqMothed.class
│ │ │ └── LReqFileType.class
│ │ │ ├── handler
│ │ │ ├── LHandler.class
│ │ │ └── ILHandlerCallback.class
│ │ │ ├── activity
│ │ │ ├── LActivity.class
│ │ │ └── fragment
│ │ │ │ └── LFragment.class
│ │ │ ├── application
│ │ │ ├── LConfig.class
│ │ │ └── LApplication.class
│ │ │ ├── exception
│ │ │ ├── ILException.class
│ │ │ ├── LException.class
│ │ │ ├── LLoginException.class
│ │ │ └── ILException$LExcState.class
│ │ │ └── listener
│ │ │ ├── LViewPagerChangeListener.class
│ │ │ ├── LViewPagerChangeListener$State.class
│ │ │ ├── LViewPagerChangeListener$ILOnPageScrolled.class
│ │ │ ├── LViewPagerChangeListener$ILOnPageSelected.class
│ │ │ └── LViewPagerChangeListener$ILOnPageScrollStateChanged.class
│ ├── jarlist.cache
│ └── AndroidManifest.xml
├── libs
│ ├── android-support-v4.jar
│ ├── android-support-v7-appcompat.jar
│ └── universal-image-loader-1.9.2.jar
├── .settings
│ └── org.eclipse.core.resources.prefs
├── gen
│ └── com
│ │ └── leo
│ │ └── base
│ │ └── BuildConfig.java
├── AndroidManifest.xml
├── src
│ └── com
│ │ └── leo
│ │ └── base
│ │ ├── net
│ │ ├── ILNetworkProgress.java
│ │ ├── ILNetworkCallback.java
│ │ ├── ILNetwork.java
│ │ ├── LNetwork.java
│ │ ├── LDownload.java
│ │ └── LRequest.java
│ │ ├── handler
│ │ └── ILHandlerCallback.java
│ │ ├── application
│ │ └── LConfig.java
│ │ ├── entity
│ │ ├── LReqFileType.java
│ │ ├── LReqEncode.java
│ │ ├── LReqMothed.java
│ │ ├── LReqFile.java
│ │ ├── LMessage.java
│ │ └── LReqEntity.java
│ │ ├── exception
│ │ ├── LLoginException.java
│ │ ├── ILException.java
│ │ └── LException.java
│ │ ├── service
│ │ └── LService.java
│ │ ├── util
│ │ ├── MD5.java
│ │ ├── LMobileInfo.java
│ │ ├── LDiscConn.java
│ │ ├── LDate.java
│ │ ├── L.java
│ │ ├── LSharePreference.java
│ │ └── LFormat.java
│ │ ├── widget
│ │ ├── webview
│ │ │ └── LWebViewClient.java
│ │ ├── LWebView.java
│ │ └── T.java
│ │ ├── cache
│ │ └── LCache.java
│ │ ├── adapter
│ │ ├── LPagerAdapter.java
│ │ └── LBaseAdapter.java
│ │ ├── activity
│ │ ├── fragment
│ │ │ └── LFragment.java
│ │ └── LActivity.java
│ │ ├── db
│ │ ├── LDBManager.java
│ │ └── LDBHelper.java
│ │ ├── listener
│ │ └── LViewPagerChangeListener.java
│ │ └── dialog
│ │ └── LProgress.java
├── .classpath
├── .classpath.bak
├── project.properties
├── proguard-project.txt
├── .project
└── explain.txt
├── LBaseExample
├── lint.xml
├── bin
│ ├── classes.dex
│ ├── resources.ap_
│ ├── LBaseExample.apk
│ ├── jarlist.cache
│ ├── classes
│ │ └── com
│ │ │ └── example
│ │ │ └── lbaseexample
│ │ │ ├── R.class
│ │ │ ├── R$id.class
│ │ │ ├── R$array.class
│ │ │ ├── R$attr.class
│ │ │ ├── R$dimen.class
│ │ │ ├── R$layout.class
│ │ │ ├── R$menu.class
│ │ │ ├── R$string.class
│ │ │ ├── R$style.class
│ │ │ ├── R$drawable.class
│ │ │ ├── BuildConfig.class
│ │ │ ├── db
│ │ │ └── DBManager.class
│ │ │ ├── common
│ │ │ ├── MHandler.class
│ │ │ ├── MNetwork.class
│ │ │ └── MApplication.class
│ │ │ ├── entity
│ │ │ └── ListEntity.class
│ │ │ ├── activity
│ │ │ ├── AboutActivity.class
│ │ │ ├── MainActivity.class
│ │ │ ├── ListViewActivity.class
│ │ │ ├── ManyRequestActivity.class
│ │ │ ├── fragment
│ │ │ │ ├── Fragment1.class
│ │ │ │ └── Fragment2.class
│ │ │ ├── ManyRequestActivity$1.class
│ │ │ ├── FragmentViewPagerActivity.class
│ │ │ ├── FragmentViewPagerActivity$1.class
│ │ │ └── FragmentViewPagerActivity$OnPagerIndexListener.class
│ │ │ ├── adapter
│ │ │ ├── ListViewAdapter.class
│ │ │ ├── MyViewPagerAdapter.class
│ │ │ └── ListViewAdapter$ViewHolder.class
│ │ │ └── handler
│ │ │ ├── FragmentHandler.class
│ │ │ └── ListViewHandler.class
│ ├── res
│ │ └── crunch
│ │ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ └── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ ├── dexedLibs
│ │ ├── lbase-91b66b821b194224f337b776b36b3b92.jar
│ │ ├── android-support-v4-eba623b44905f85ee98f0f8b3b2058f2.jar
│ │ ├── android-support-v7-appcompat-d1bc06488aeaac3b3842504843229012.jar
│ │ └── universal-image-loader-1.9.2-de5d39a9c2ba6d9234e56e0758002c56.jar
│ ├── R.txt
│ └── AndroidManifest.xml
├── ic_launcher-web.png
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values
│ │ ├── dimens.xml
│ │ ├── dbs.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ ├── layout
│ │ ├── activity_listview.xml
│ │ ├── activity_webview.xml
│ │ ├── activity_fragment_viewpager.xml
│ │ ├── activity_about.xml
│ │ ├── view_pager_title.xml
│ │ ├── fragment_view1.xml
│ │ ├── item_listview.xml
│ │ ├── activity_many_request.xml
│ │ ├── activity_download.xml
│ │ └── activity_main.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── menu
│ │ └── main.xml
├── .settings
│ └── org.eclipse.core.resources.prefs
├── gen
│ └── com
│ │ └── example
│ │ └── lbaseexample
│ │ ├── BuildConfig.java
│ │ └── R.java
├── src
│ └── com
│ │ └── example
│ │ └── lbaseexample
│ │ ├── entity
│ │ └── ListEntity.java
│ │ ├── activity
│ │ ├── AboutActivity.java
│ │ ├── fragment
│ │ │ ├── Fragment1.java
│ │ │ └── Fragment2.java
│ │ ├── WebViewActivity.java
│ │ ├── FragmentViewPagerActivity.java
│ │ ├── DownloadActivity.java
│ │ ├── ListViewActivity.java
│ │ ├── MainActivity.java
│ │ └── ManyRequestActivity.java
│ │ ├── handler
│ │ ├── FragmentHandler.java
│ │ ├── DownloadHandler.java
│ │ └── ListViewHandler.java
│ │ ├── adapter
│ │ ├── MyViewPagerAdapter.java
│ │ └── ListViewAdapter.java
│ │ ├── common
│ │ ├── MNetwork.java
│ │ ├── MApplication.java
│ │ └── MHandler.java
│ │ └── db
│ │ └── DBManager.java
├── .classpath
├── project.properties
├── proguard-project.txt
├── .project
└── AndroidManifest.xml
└── .gitignore
/README.md:
--------------------------------------------------------------------------------
1 | # 此项目已不再维护,转至[MBase](https://github.com/MonchChen/mbase)
2 |
--------------------------------------------------------------------------------
/LBase/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/LBaseExample/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/LBase/bin/lbase.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/lbase.jar
--------------------------------------------------------------------------------
/LBaseExample/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes.dex
--------------------------------------------------------------------------------
/LBaseExample/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/resources.ap_
--------------------------------------------------------------------------------
/LBase/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/LBaseExample/bin/LBaseExample.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/LBaseExample.apk
--------------------------------------------------------------------------------
/LBaseExample/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/ic_launcher-web.png
--------------------------------------------------------------------------------
/LBase/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | #Tue Apr 01 15:28:12 CST 2014
2 | eclipse.preferences.version=1
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/L.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/L.class
--------------------------------------------------------------------------------
/LBase/libs/android-support-v7-appcompat.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/libs/android-support-v7-appcompat.jar
--------------------------------------------------------------------------------
/LBase/libs/universal-image-loader-1.9.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/libs/universal-image-loader-1.9.2.jar
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/MD5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/MD5.class
--------------------------------------------------------------------------------
/LBaseExample/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBaseExample/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/BuildConfig.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/cache/LCache.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/cache/LCache.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/db/LDBHelper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/db/LDBHelper.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/net/LCaller.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/net/LCaller.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/net/LNetwork.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/net/LNetwork.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/LBitmap.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/LBitmap.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/LDate.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/LDate.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/LFormat.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/LFormat.class
--------------------------------------------------------------------------------
/LBase/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/LBaseExample/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | #Fri Jul 04 10:15:29 CST 2014
2 | eclipse.preferences.version=1
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/LBaseExample/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBaseExample/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/db/LDBManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/db/LDBManager.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/net/ILNetwork.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/net/ILNetwork.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/LDiscConn.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/LDiscConn.class
--------------------------------------------------------------------------------
/LBaseExample/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/adapter/LAdapters.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/adapter/LAdapters.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/entity/LMessage$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/entity/LMessage$1.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/entity/LMessage.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/entity/LMessage.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/entity/LReqEncode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/entity/LReqEncode.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/entity/LReqEntity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/entity/LReqEntity.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/entity/LReqFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/entity/LReqFile.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/entity/LReqMothed.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/entity/LReqMothed.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/handler/LHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/handler/LHandler.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/LMobileInfo.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/LMobileInfo.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/activity/LActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/activity/LActivity.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/application/LConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/application/LConfig.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/entity/LReqFileType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/entity/LReqFileType.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/adapter/LBaseAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/adapter/LBaseAdapter.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/adapter/LPagerAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/adapter/LPagerAdapter.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/exception/ILException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/exception/ILException.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/exception/LException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/exception/LException.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/net/ILNetworkCallback.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/net/ILNetworkCallback.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/net/LNetwork$LReqState.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/net/LNetwork$LReqState.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/util/LSharePreference.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/util/LSharePreference.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R.class
--------------------------------------------------------------------------------
/LBaseExample/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBaseExample/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBaseExample/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBaseExample/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/application/LApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/application/LApplication.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$id.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/activity/fragment/LFragment.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/activity/fragment/LFragment.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/exception/LLoginException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/exception/LLoginException.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/handler/ILHandlerCallback.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/handler/ILHandlerCallback.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$array.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$array.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$attr.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$dimen.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$layout.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$menu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$menu.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$string.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$style.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/net/ILNetwork$LReqResultState.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/net/ILNetwork$LReqResultState.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/R$drawable.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/exception/ILException$LExcState.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/exception/ILException$LExcState.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/BuildConfig.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/db/DBManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/db/DBManager.class
--------------------------------------------------------------------------------
/LBaseExample/bin/dexedLibs/lbase-91b66b821b194224f337b776b36b3b92.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/dexedLibs/lbase-91b66b821b194224f337b776b36b3b92.jar
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/common/MHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/common/MHandler.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/common/MNetwork.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/common/MNetwork.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/entity/ListEntity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/entity/ListEntity.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$State.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$State.class
--------------------------------------------------------------------------------
/LBase/gen/com/leo/base/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.leo.base;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/common/MApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/common/MApplication.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/AboutActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/AboutActivity.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/MainActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/MainActivity.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/adapter/ListViewAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/adapter/ListViewAdapter.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/handler/FragmentHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/handler/FragmentHandler.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/handler/ListViewHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/handler/ListViewHandler.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/ListViewActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/ListViewActivity.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/ManyRequestActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/ManyRequestActivity.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/fragment/Fragment1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/fragment/Fragment1.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/fragment/Fragment2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/fragment/Fragment2.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/adapter/MyViewPagerAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/adapter/MyViewPagerAdapter.class
--------------------------------------------------------------------------------
/LBaseExample/bin/dexedLibs/android-support-v4-eba623b44905f85ee98f0f8b3b2058f2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/dexedLibs/android-support-v4-eba623b44905f85ee98f0f8b3b2058f2.jar
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/ManyRequestActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/ManyRequestActivity$1.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$ILOnPageScrolled.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$ILOnPageScrolled.class
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$ILOnPageSelected.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$ILOnPageSelected.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/FragmentViewPagerActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/FragmentViewPagerActivity.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/adapter/ListViewAdapter$ViewHolder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/adapter/ListViewAdapter$ViewHolder.class
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/FragmentViewPagerActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/FragmentViewPagerActivity$1.class
--------------------------------------------------------------------------------
/LBaseExample/bin/dexedLibs/android-support-v7-appcompat-d1bc06488aeaac3b3842504843229012.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/dexedLibs/android-support-v7-appcompat-d1bc06488aeaac3b3842504843229012.jar
--------------------------------------------------------------------------------
/LBaseExample/bin/dexedLibs/universal-image-loader-1.9.2-de5d39a9c2ba6d9234e56e0758002c56.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/dexedLibs/universal-image-loader-1.9.2-de5d39a9c2ba6d9234e56e0758002c56.jar
--------------------------------------------------------------------------------
/LBaseExample/gen/com/example/lbaseexample/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.example.lbaseexample;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/entity/ListEntity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.entity;
2 |
3 | public class ListEntity {
4 |
5 | public int id;
6 | public String url;
7 | public String content;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$ILOnPageScrollStateChanged.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBase/bin/classes/com/leo/base/listener/LViewPagerChangeListener$ILOnPageScrollStateChanged.class
--------------------------------------------------------------------------------
/LBase/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LBaseExample/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/LBase/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LBaseExample/bin/classes/com/example/lbaseexample/activity/FragmentViewPagerActivity$OnPagerIndexListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/object1991/LBase-Android/HEAD/LBaseExample/bin/classes/com/example/lbaseexample/activity/FragmentViewPagerActivity$OnPagerIndexListener.class
--------------------------------------------------------------------------------
/LBaseExample/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/activity_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/activity_webview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/activity_fragment_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/LBaseExample/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/LBaseExample/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/view_pager_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 |
19 | # Proguard folder generated by Eclipse
20 | proguard/
21 |
22 | # Intellij project files
23 | *.ipr
24 | *.iws
25 | .idea
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/net/ILNetworkProgress.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.net;
2 |
3 | /**
4 | *
5 | * @author Chen Lei
6 | * @version 1.3.5
7 | *
8 | */
9 | public interface ILNetworkProgress {
10 |
11 | /**
12 | * 上传/下载文件发送进度,运行在子线程,不可直接操控UI
13 | *
14 | * @param count
15 | * 总长度
16 | * @param current
17 | * 当前长度
18 | */
19 | void sendProgress(int count, int current);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/handler/ILHandlerCallback.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.handler;
2 |
3 | import com.leo.base.entity.LMessage;
4 |
5 | /**
6 | *
7 | * @author Chen Lei
8 | * @version 1.3.1
9 | *
10 | */
11 | public interface ILHandlerCallback {
12 |
13 | /**
14 | * 将结果返回,运行在UI线程
15 | * @param msg 请求结果处理后的实体封装
16 | * @param requestId 请求ID
17 | */
18 | void onResultHandler(LMessage msg, int requestId);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/LBaseExample/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/LBaseExample/res/values/dbs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - CREATE TABLE if not exists ListEntityTable(
6 | ID INTEGER,
7 | URL VARCHAR(30),
8 | CONTENT VARCHAR(100)
9 | )
10 |
11 |
12 |
13 |
14 | - drop table if exists ListEntityTable;
15 |
16 |
17 |
--------------------------------------------------------------------------------
/LBaseExample/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/LBase/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/application/LConfig.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.application;
2 |
3 | /**
4 | *
5 | * @author Chen Lei
6 | *
7 | */
8 | public class LConfig {
9 |
10 | /**
11 | * 默认的SessionKey值
12 | */
13 | public static final String SESSION_KEY = "SESSIONID";
14 |
15 | /**
16 | * 默认的等待数据超时时间
17 | */
18 | public static final int SO_TIMEOUT = 20 * 1000;
19 |
20 | /**
21 | * 默认的请求超时时间
22 | */
23 | public static final int REQUEST_TIMEOUT = 20 * 1000;
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/entity/LReqFileType.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.entity;
2 |
3 | /**
4 | * 此类为网络请求提交文件类型的类
5 | * 暂时只收录了jpeg格式
6 | * 如需其它类型,自行添加即可
7 | * 请见谅
8 | *
9 | * @author Chen Lei
10 | * @version 1.1.5
11 | *
12 | */
13 | public enum LReqFileType {
14 |
15 | JPEG("image/pjpeg");
16 |
17 | private String type;
18 |
19 | private LReqFileType(String str) {
20 | type = str;
21 | }
22 |
23 | public String getType() {
24 | return type;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/LBaseExample/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/fragment_view1.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/LBase/.classpath.bak:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/entity/LReqEncode.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.entity;
2 |
3 |
4 | /**
5 | *
6 | * @author Chen Lei
7 | * @version 1.3.1
8 | *
9 | */
10 | public enum LReqEncode {
11 |
12 | /**
13 | * 使用UTF-8编码请求网络连接
14 | */
15 | UTF8("UTF-8"),
16 |
17 | /**
18 | * 使用GBK编码请求网络连接
19 | */
20 | GBK("GBK");
21 |
22 | private String mEncoding;
23 |
24 | private LReqEncode(String encoding) {
25 | this.mEncoding = encoding;
26 | }
27 |
28 | public String getEncode() {
29 | return this.mEncoding;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/exception/LLoginException.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.exception;
2 |
3 | import com.nostra13.universalimageloader.utils.L;
4 |
5 | /**
6 | * 如网络请求时,需要后台登录,则抛出此异常
7 | * throw new LLoginException();
8 | *
9 | * @author Chen Lei
10 | * @version 1.3.1
11 | *
12 | */
13 | public class LLoginException extends LException {
14 |
15 | private static final long serialVersionUID = 1L;
16 |
17 | @Override
18 | public void captureException(Exception e) {
19 | L.w("用户未登录");
20 | }
21 |
22 | @Override
23 | public void handleAccomplish(LExcState state) {
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/LBaseExample/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LBaseExample
5 | http://127.0.0.1/
6 | ListViewExample
7 | About Me
8 | 多个请求并发
9 | 下载文件
10 | FragmentViewPagerExample
11 | Settings
12 | WebView保持session
13 |
14 |
--------------------------------------------------------------------------------
/LBase/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-8
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/service/LService.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.service;
2 |
3 | import com.leo.base.entity.LMessage;
4 | import com.leo.base.handler.ILHandlerCallback;
5 |
6 | import android.app.Service;
7 | import android.content.Intent;
8 | import android.os.IBinder;
9 |
10 | /**
11 | *
12 | * @author Chen Lei
13 | * @version 1.3.9
14 | *
15 | */
16 | public class LService extends Service implements ILHandlerCallback {
17 |
18 | @Override
19 | public IBinder onBind(Intent intent) {
20 | return null;
21 | }
22 |
23 | @Override
24 | public void onResultHandler(LMessage msg, int requestId) {
25 | // ... 写入你需要的代码
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/LBaseExample/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-18
15 | android.library.reference.1=../LBase
16 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/entity/LReqMothed.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.entity;
2 |
3 | /**
4 | *
5 | * @author Chen Lei
6 | * @version 1.1.5
7 | *
8 | */
9 | public enum LReqMothed {
10 |
11 | /**
12 | * 使用POST方式请求网络连接
13 | */
14 | POST("POST"),
15 |
16 | /**
17 | * 使用GET方式请求网络连接
18 | */
19 | GET("GET"),
20 |
21 | /**
22 | * 下载文件
23 | */
24 | DOWNLOAD("DOWNLOAD"),
25 |
26 | /**
27 | * 上传文件
28 | */
29 | UPLOAD("UPLOAD");
30 |
31 | private String mMothed;
32 |
33 | private LReqMothed(String mothed) {
34 | this.mMothed = mothed;
35 | }
36 |
37 | /**
38 | * 获取请求网络连接方式具体值
39 | *
40 | * @return
41 | */
42 | public String getMothed() {
43 | return this.mMothed;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/item_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/AboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.widget.TextView;
5 |
6 | import com.example.lbaseexample.R;
7 | import com.leo.base.activity.LActivity;
8 |
9 | public class AboutActivity extends LActivity {
10 |
11 | @Override
12 | protected void onLCreate(Bundle savedInstanceState) {
13 | setContentView(R.layout.activity_about);
14 | ((TextView) findViewById(R.id.about_textview)).setText(getAboutStr());
15 | }
16 |
17 | private String getAboutStr() {
18 | return "作者(Developer):陈磊 (Chen Lei)\n版本号(Version):1.1.8\nEMail:objectes@126.com\nQQ:75806772\n"
19 | + "制作时间(Time):2014.07.11\n状态(State):开源-未停止更新(Open Source - Not Stop Updating)";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/LBaseExample/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/exception/ILException.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.exception;
2 |
3 | /**
4 | * 此类暂未正式使用
5 | * @author Chen Lei
6 | * @version 1.1.5
7 | *
8 | */
9 | public interface ILException {
10 |
11 | /**
12 | * 处理状态
13 | *
14 | * @author leo
15 | *
16 | */
17 | public enum LExcState {
18 |
19 | /**
20 | * 异常处理成功
21 | */
22 | Success,
23 |
24 | /**
25 | * 异常处理失败
26 | */
27 | Error,
28 |
29 | /**
30 | * 异常未处理
31 | */
32 | None
33 | }
34 |
35 | /**
36 | * 捕获异常并处理方法
37 | *
38 | * @param e
39 | */
40 | void captureException(Exception e);
41 |
42 | /**
43 | * 异常处理后通知完成
44 | *
45 | * @param state
46 | * :完成状态
47 | */
48 | void handleAccomplish(LExcState state);
49 | }
50 |
--------------------------------------------------------------------------------
/LBase/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/LBaseExample/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/LBase/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | LBase
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 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/util/MD5.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.util;
2 |
3 | import java.security.MessageDigest;
4 |
5 | import com.leo.base.exception.LException;
6 |
7 |
8 | /**
9 | *
10 | * @author Chen Lei
11 | * @version 1.1.5
12 | *
13 | */
14 | public final class MD5 {
15 |
16 | private MD5() {
17 | }
18 |
19 | public static String getMD5(String content) {
20 | try {
21 | MessageDigest digest = MessageDigest.getInstance("MD5");
22 | digest.update(content.getBytes());
23 | return getHasnString(digest);
24 | } catch (Exception e) {
25 | L.e(LException.getStackMsg(e));
26 | }
27 | return null;
28 | }
29 |
30 | private static String getHasnString(MessageDigest digest) {
31 | StringBuilder builder = new StringBuilder();
32 | for (byte b : digest.digest()) {
33 | builder.append(Integer.toHexString((b >> 4) & 0xf));
34 | builder.append(Integer.toHexString(b & 0xf));
35 | }
36 | return builder.toString();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LBaseExample/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | LBaseExample
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 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/widget/webview/LWebViewClient.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.widget.webview;
2 |
3 | import android.webkit.CookieManager;
4 | import android.webkit.WebView;
5 | import android.webkit.WebViewClient;
6 |
7 | import com.leo.base.application.LApplication;
8 | import com.leo.base.util.L;
9 | import com.leo.base.util.LFormat;
10 |
11 | public class LWebViewClient extends WebViewClient {
12 |
13 | @Override
14 | public void onPageFinished(WebView view, String url) {
15 | super.onPageFinished(view, url);
16 | String cookie = CookieManager.getInstance().getCookie(url);
17 | if (!LFormat.isEmpty(cookie)) {
18 | String[] cookies = cookie.split(";");
19 | if (cookies != null && cookies.length > 0) {
20 | for (String str : cookies) {
21 | int index = str.indexOf(LApplication.getInstance()
22 | .getSessionKey());
23 | if (index != -1) {
24 | String sessionValue = str.substring(
25 | str.indexOf("=") + 1, str.length());
26 | LApplication.getInstance()
27 | .setSessionValue(sessionValue);
28 | L.e(sessionValue);
29 | }
30 | }
31 | }
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/activity_many_request.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
15 |
16 |
21 |
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/cache/LCache.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.cache;
2 |
3 | import java.util.HashMap;
4 | import java.util.LinkedList;
5 | import java.util.Map;
6 |
7 | import com.leo.base.application.LApplication;
8 |
9 | /**
10 | *
11 | * @author Chen Lei
12 | *
13 | * @param
14 | */
15 | public class LCache {
16 |
17 | private int cacheLimit = LApplication.getInstance().getCacheCount();
18 |
19 | private LinkedList cacheList;
20 |
21 | private Map cacheMap;
22 |
23 | public LCache() {
24 | cacheList = new LinkedList();
25 | cacheMap = new HashMap();
26 | }
27 |
28 | public void setCacheLimit(int num) {
29 | cacheLimit = num;
30 | }
31 |
32 | public void put(String key, E value) {
33 | cacheList.offer(key);
34 | if(cacheList.size() > cacheLimit) {
35 | String mKey = cacheList.poll();
36 | cacheMap.remove(mKey);
37 | }
38 | cacheMap.put(key, value);
39 | }
40 |
41 | public boolean isHaveCache(String key) {
42 | return cacheMap.containsKey(key);
43 | }
44 |
45 | public E get(String key) {
46 | return cacheMap.get(key);
47 | }
48 |
49 | public void remove(String key) {
50 | cacheMap.remove(key);
51 | }
52 |
53 | public void clearAll() {
54 | cacheList.clear();
55 | cacheMap.clear();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/activity_download.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
20 |
21 |
26 |
27 |
32 |
33 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/entity/LReqFile.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.entity;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | *
7 | * @author Chen Lei
8 | * @version 1.3.1
9 | *
10 | */
11 | public class LReqFile {
12 |
13 | private String name;
14 | private File file;
15 | private LReqFileType type;
16 |
17 | public LReqFile(String name, File file, LReqFileType type) {
18 | this.name = name;
19 | this.file = file;
20 | this.type = type;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 |
31 | public File getFile() {
32 | return file;
33 | }
34 |
35 | public void setFile(File file) {
36 | this.file = file;
37 | }
38 |
39 | public LReqFileType getType() {
40 | return type;
41 | }
42 |
43 | public void setType(LReqFileType type) {
44 | this.type = type;
45 | }
46 |
47 | public long getLength() {
48 | if (file.isFile() && file.exists()) {
49 | return file.length();
50 | }
51 | return 0;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | StringBuilder sb = new StringBuilder();
57 | sb.append("文件名:").append(name).append("<--->");
58 | sb.append("文件地址:").append(file.getPath()).append("<--->");
59 | sb.append("文件类型:").append(type.getType());
60 | return sb.toString();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/util/LMobileInfo.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.util;
2 |
3 | import com.leo.base.application.LApplication;
4 |
5 | import android.content.Context;
6 | import android.telephony.TelephonyManager;
7 |
8 | /**
9 | *
10 | * @author Chen Lei
11 | * @version 1.1.5
12 | *
13 | */
14 | public class LMobileInfo {
15 |
16 | /**
17 | * 获取IMEI码
18 | * @return
19 | */
20 | public static String getImei() {
21 | TelephonyManager mTm = (TelephonyManager) LApplication.getInstance()
22 | .getContext()
23 | .getSystemService(Context.TELEPHONY_SERVICE);
24 | return mTm.getDeviceId();
25 | }
26 |
27 | /**
28 | * 获取IMSI码
29 | * @return
30 | */
31 | public static String getImsi() {
32 | TelephonyManager mTm = (TelephonyManager) LApplication.getInstance()
33 | .getContext()
34 | .getSystemService(Context.TELEPHONY_SERVICE);
35 | return mTm.getSubscriberId();
36 | }
37 |
38 | /**
39 | * 获取手机型号
40 | * @return
41 | */
42 | public static String getMobileType() {
43 | return android.os.Build.MODEL; // 手机型号
44 | }
45 |
46 | /**
47 | * 获取系统发布版本号
48 | * @return
49 | */
50 |
51 | public static String getVersionRelease(){
52 | return android.os.Build.VERSION.RELEASE;
53 | }
54 |
55 | /**
56 | * 终端设备编码
57 | */
58 | public static final String TAG_END_FROM = "Android";
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/exception/LException.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.exception;
2 |
3 | import com.leo.base.application.LApplication;
4 | import com.leo.base.util.L;
5 |
6 | /**
7 | * 此类暂未正式使用
8 | *
9 | * @author Chen Lei
10 | * @version 1.3.1
11 | *
12 | */
13 | public abstract class LException extends Exception implements ILException {
14 |
15 | /**
16 | *
17 | */
18 | private static final long serialVersionUID = 1L;
19 |
20 | public void printException(Exception e) {
21 | if (LApplication.getInstance().getIsOpenDebugMode()) {
22 | L.e(LException.getStackMsg(e));
23 | }
24 | }
25 |
26 | public void printException(Exception e, boolean isCapture) {
27 | printException(e);
28 | if (isCapture) {
29 | captureException(e);
30 | }
31 | }
32 |
33 | @Override
34 | public abstract void captureException(Exception e);
35 |
36 | @Override
37 | public abstract void handleAccomplish(LExcState state);
38 |
39 | /**
40 | * 获取基本异常信息
41 | * @param e
42 | * @return
43 | */
44 | public static String getStackMsg(Throwable e) {
45 | StringBuffer sb = new StringBuffer();
46 | StackTraceElement[] stackArray = e.getStackTrace();
47 | for (int i = 0; i < stackArray.length; i++) {
48 | StackTraceElement element = stackArray[i];
49 | sb.append(element.toString() + "\n");
50 | }
51 | sb.append(e);
52 | return sb.toString();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/handler/FragmentHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.handler;
2 |
3 | import org.json.JSONException;
4 |
5 | import com.example.lbaseexample.common.MHandler;
6 | import com.leo.base.activity.fragment.LFragment;
7 | import com.leo.base.entity.LMessage;
8 | import com.leo.base.exception.LLoginException;
9 | import com.leo.base.util.L;
10 | import com.leo.base.widget.T;
11 |
12 | public class FragmentHandler extends MHandler {
13 |
14 | public FragmentHandler(LFragment fragment) {
15 | super(fragment);
16 | }
17 |
18 | @Override
19 | public LMessage onParse(String strs, int requestId) throws JSONException,
20 | LLoginException {
21 | LMessage msg = new LMessage();
22 | msg.setStr(strs);
23 | return msg;
24 | }
25 |
26 | @Override
27 | protected void onNetWorkExc(int requestId) {
28 | T.ss("网络请求发现异常");
29 | }
30 |
31 | @Override
32 | protected void onParseExc(int requestId) {
33 | T.ss("数据解析发现异常");
34 | }
35 |
36 | @Override
37 | protected void onLoginError(int requestId) {
38 | T.ss("自动登录错误异常");
39 | }
40 |
41 | @Override
42 | protected void onLoginNone(int requestId) {
43 | T.ss("用户并未存有登录帐号异常");
44 | }
45 |
46 | @Override
47 | protected void onOtherExc(int requestId) {
48 | T.ss("其它异常");
49 | }
50 |
51 | @Override
52 | protected void onStop(int requestId) {
53 | L.i("线程停止");
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/LBase/explain.txt:
--------------------------------------------------------------------------------
1 | 项目名称:LBase
2 | 项目类型:Library
3 | 项目所有人:陈磊(Chen Lei)
4 | 项目简介:
5 | 项目集合了开发中经常使用的工具类,并简化代码;
6 | 如:T类(Toast)、L类(Log)、LSharePreference类(SharedPreferences) 等;
7 | 并将代码层次划分,网络请求、结果解析、结果处理等繁琐并且常用的代码变得简单使用;
8 | Activity、Fragment、Adapter 只需处理 View 相关操作,Handler 处理请求数据解析等相关操作,使用者不需要再写着大量重复的代码去创建线程,只需几行便可解决;
9 | 常用的 BaseAdapter 也不需要再写着大量重复的代码,使用者只需要把工作重点放在 getView 上面就可以,处理好 Item 的数据,其它功能让 LBase 帮你解决
10 | 项目结构:
11 | com.leo.base
12 | .activity
13 | LActivity.java
14 | .fragment
15 | LFragment.java
16 | .adapter
17 | LAdapters.java
18 | LBaseAdapter.java
19 | LPagerAdapter.java
20 | .application
21 | LApplication.java
22 | LConfig.java
23 | .cache
24 | LCache.java
25 | .db
26 | LDBHelper.java
27 | LDBManager.java
28 | .entity
29 | LMessage.java
30 | .exception
31 | ILException.java
32 | ILException.java
33 | LLoginException.java
34 | .handler
35 | LHandler.java
36 | .listener
37 | LViewPagerChangeListener.java
38 | .net
39 | ILNetwork.java
40 | ILNetworkCallback.java
41 | LCaller.java
42 | LFileEntity.java
43 | LFileType.java
44 | LNetwork.java
45 | LReqEntity.java
46 | ReqEncode.java
47 | ReqMothed.java
48 | .util
49 | L.java
50 | LBitmap.java
51 | LDate.java
52 | LDiscConn.java
53 | LFormat.java
54 | LMobileInfo.java
55 | LSharePreference.java
56 | MD5.java
57 | T.java
58 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/net/ILNetworkCallback.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.net;
2 |
3 | import org.json.JSONException;
4 |
5 | import com.leo.base.entity.LMessage;
6 | import com.leo.base.exception.LLoginException;
7 | import com.leo.base.net.ILNetwork.LReqResultState;
8 |
9 | /**
10 | *
11 | * @author Chen Lei
12 | * @version 1.3.5
13 | *
14 | */
15 | public interface ILNetworkCallback {
16 |
17 | /**
18 | * 请求发现异常,运行于UI线程
19 | *
20 | * @param state
21 | * :请求异常状态
22 | * @param requestId
23 | * :请求ID
24 | */
25 | void onException(LReqResultState state, int requestId);
26 |
27 | /**
28 | * 网络请求结果返回,在此处解析返回结果,运行于子线程,不可操作UI
29 | *
30 | * @param result
31 | * :请求返回的值
32 | * @param requestId
33 | * :请求ID
34 | * @return:将解析好的数据存放到LMessage中封装
35 | * @throws JSONException
36 | * :如解析错误,向上抛出此异常
37 | * @throws LLoginException
38 | * :如发现用户在后台未登录,向上抛出此异常
39 | * @throws Exception
40 | * :其它异常
41 | */
42 | LMessage onParse(String strs, int requestId) throws LLoginException,
43 | JSONException, Exception;
44 |
45 | /**
46 | * 请求返回结果,运行于UI线程
47 | *
48 | * @param msg
49 | * :返回结果封装
50 | * @param requestId
51 | * :请求ID
52 | */
53 | void onHandlerUI(LMessage msg, int requestId);
54 |
55 | /**
56 | * 进度控制
57 | * @param count 总长度
58 | * @param current 当前长度
59 | */
60 | void onProgress(int count, int current, int requestId);
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/adapter/MyViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.adapter;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.example.lbaseexample.activity.FragmentViewPagerActivity;
7 | import com.example.lbaseexample.activity.FragmentViewPagerActivity.OnPagerIndexListener;
8 | import com.example.lbaseexample.activity.fragment.Fragment1;
9 | import com.example.lbaseexample.activity.fragment.Fragment2;
10 | import com.leo.base.activity.fragment.LFragment;
11 |
12 | import android.support.v4.app.Fragment;
13 | import android.support.v4.app.FragmentManager;
14 | import android.support.v4.app.FragmentPagerAdapter;
15 |
16 | public class MyViewPagerAdapter extends FragmentPagerAdapter implements
17 | OnPagerIndexListener {
18 |
19 | private List fragments;
20 |
21 | private Fragment1 f1;
22 | private Fragment2 f2;
23 |
24 | public MyViewPagerAdapter(FragmentViewPagerActivity activity,
25 | FragmentManager fm) {
26 | super(fm);
27 | activity.setOnPagerIndexListener(this);
28 | fragments = new ArrayList();
29 | f1 = new Fragment1();
30 | f2 = new Fragment2();
31 | fragments.add(f1);
32 | fragments.add(f2);
33 | }
34 |
35 | @Override
36 | public Fragment getItem(int arg0) {
37 | return fragments.get(arg0);
38 | }
39 |
40 | @Override
41 | public int getCount() {
42 | return fragments.size();
43 | }
44 |
45 | @Override
46 | public void onPagerIndex(int index) {
47 | if (index == 0) {
48 | f1.load();
49 | } else {
50 | f2.load();
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/common/MNetwork.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.common;
2 |
3 | import com.leo.base.net.LNetwork;
4 |
5 | public class MNetwork extends LNetwork {
6 |
7 | @Override
8 | public LLoginState doLogin() {
9 | // ... 你可以在这里操作登录
10 | // ... 当你请求服务器,服务器发现你的登录信息已失效,LBase会自动调用此方法,帮助你登录
11 | // ... 返回值有三种:
12 | // ... LoginState.SUCCESS 自动登录成功
13 | // ... LoginState.ERROR 自动登录失败
14 | // ... LoginState.NONE 未发现登录信息
15 | // ... 例如:
16 | /*
17 | * String username =
18 | * LSharePreference.getInstance(MApplication.get().getContext
19 | * ()).getString("username"); String password =
20 | * LSharePreference.getInstance
21 | * (MApplication.get().getContext()).getString("password");
22 | * if(TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
23 | * return LoginState.NONE; } String url =
24 | * MApplication.get().getAppServiceUrl() + "login"; Map
25 | * params = new HashMap(); params.put("username",
26 | * username); params.put("password", password); ReqEncode reqEncode =
27 | * ReqEncode.UTF8; ReqMothed reqMothed = ReqMothed.POST; String result =
28 | * null; try { result = LCaller.doConn(url, params, false, reqMothed,
29 | * reqEncode); } catch (Exception e) { e.printStackTrace(); return
30 | * LoginState.ERROR; } try { JSONObject jsonObject = new
31 | * JSONObject(result); if (jsonObject.optInt("error") > 0) { // ... //
32 | * 如果JSON返回错误信息大于0,则认为登录失败,否则登录成功 return LoginState.ERROR; } } catch
33 | * (JSONException e) { e.printStackTrace(); return LoginState.ERROR; }
34 | */
35 | return LLoginState.SUCCESS;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/fragment/Fragment1.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.example.lbaseexample.R;
10 | import com.example.lbaseexample.handler.FragmentHandler;
11 | import com.leo.base.activity.fragment.LFragment;
12 | import com.leo.base.entity.LMessage;
13 | import com.leo.base.entity.LReqEntity;
14 |
15 | public class Fragment1 extends LFragment {
16 |
17 | private TextView textview;
18 |
19 | private FragmentHandler handler;
20 |
21 | @Override
22 | public void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | handler = new FragmentHandler(this);
25 | }
26 |
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
29 | Bundle savedInstanceState) {
30 | ViewGroup mViewGroup = (ViewGroup) inflater.inflate(
31 | R.layout.fragment_view1, container, false);
32 | return mViewGroup;
33 | }
34 |
35 | @Override
36 | public void onActivityCreated(Bundle savedInstanceState) {
37 | // TODO Auto-generated method stub
38 | super.onActivityCreated(savedInstanceState);
39 | textview = (TextView) getView().findViewById(R.id.jsonstring);
40 | load();
41 | }
42 |
43 | @Override
44 | public void onResultHandler(LMessage msg, int requestId) {
45 | super.onResultHandler(msg, requestId);
46 | if (msg != null) {
47 | // textview.setText(msg.getStr());
48 | textview.setText("百度代码获取成功\n该页面未使用网络请求缓存!");
49 | }
50 | }
51 |
52 | public void load() {
53 | textview.setText("正在获取优酷网页代码...");
54 | String url = "http://www.youku.com";
55 | handler.request(new LReqEntity(url), 0);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/LBaseExample/bin/R.txt:
--------------------------------------------------------------------------------
1 | int array create_tables 0x7f040000
2 | int array drop_tables 0x7f040001
3 | int dimen activity_horizontal_margin 0x7f050000
4 | int dimen activity_vertical_margin 0x7f050001
5 | int drawable ic_launcher 0x7f020000
6 | int id about_textview 0x7f090000
7 | int id action_about_me 0x7f090013
8 | int id action_clear_all_data 0x7f090012
9 | int id download_button 0x7f090002
10 | int id download_imageview 0x7f090003
11 | int id download_progress 0x7f090001
12 | int id item_imageview 0x7f090010
13 | int id item_textview 0x7f090011
14 | int id jsonstring 0x7f09000f
15 | int id listview 0x7f090005
16 | int id main_download 0x7f09000a
17 | int id main_fragment_viewpager 0x7f090008
18 | int id main_infos 0x7f090006
19 | int id main_listview 0x7f090007
20 | int id main_many_request 0x7f090009
21 | int id main_webview 0x7f09000b
22 | int id many_infos 0x7f09000d
23 | int id many_request 0x7f09000c
24 | int id viewpager 0x7f090004
25 | int id webview_webview 0x7f09000e
26 | int layout activity_about 0x7f030000
27 | int layout activity_download 0x7f030001
28 | int layout activity_fragment_viewpager 0x7f030002
29 | int layout activity_listview 0x7f030003
30 | int layout activity_main 0x7f030004
31 | int layout activity_many_request 0x7f030005
32 | int layout activity_webview 0x7f030006
33 | int layout fragment_view1 0x7f030007
34 | int layout item_listview 0x7f030008
35 | int layout view_pager_title 0x7f030009
36 | int menu main 0x7f080000
37 | int string action_settings 0x7f060007
38 | int string app_about 0x7f060003
39 | int string app_download 0x7f060005
40 | int string app_fragmentviewpager 0x7f060006
41 | int string app_listview 0x7f060002
42 | int string app_many_request 0x7f060004
43 | int string app_name 0x7f060000
44 | int string app_service_url 0x7f060001
45 | int string app_webview 0x7f060008
46 | int style AppBaseTheme 0x7f070000
47 | int style AppTheme 0x7f070001
48 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/util/LDiscConn.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.util;
2 |
3 | import java.util.List;
4 |
5 | import com.leo.base.application.LApplication;
6 |
7 | import android.content.Context;
8 | import android.location.LocationManager;
9 | import android.net.ConnectivityManager;
10 | import android.net.NetworkInfo;
11 |
12 |
13 | /**
14 | *
15 | * @author Chen Lei
16 | * @version 1.1.5
17 | *
18 | */
19 | public class LDiscConn {
20 |
21 | private LDiscConn() {
22 | }
23 |
24 | /**
25 | * 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
26 | *
27 | * true已打开 false未打开
28 | */
29 | public static boolean IsConnNet() {
30 | boolean bisConnFlag = false;
31 | ConnectivityManager conManager = (ConnectivityManager) LApplication
32 | .getInstance().getContext()
33 | .getSystemService(Context.CONNECTIVITY_SERVICE);
34 | if (conManager != null) {
35 | NetworkInfo network = conManager.getActiveNetworkInfo();
36 | if (network != null) {
37 | bisConnFlag = conManager.getActiveNetworkInfo().isAvailable();
38 | }
39 | }
40 | return bisConnFlag;
41 | }
42 |
43 | /**
44 | * 判断GPS是否打开
45 | */
46 | public static boolean IsGPSEnabled() {
47 | LocationManager locationManager = (LocationManager) LApplication
48 | .getInstance().getContext()
49 | .getSystemService(Context.LOCATION_SERVICE);
50 | return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
51 | }
52 |
53 | /**
54 | * 判断所用机型是否有GPS设备模块
55 | */
56 | public static boolean HasGPSDevice() {
57 | LocationManager mgr = (LocationManager) LApplication.getInstance()
58 | .getContext().getSystemService(Context.LOCATION_SERVICE);
59 | if (mgr == null)
60 | return false;
61 | List providers = mgr.getAllProviders();
62 | if (providers == null)
63 | return false;
64 | return providers.contains(LocationManager.GPS_PROVIDER);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/WebViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.graphics.Bitmap;
5 | import android.os.Bundle;
6 | import android.webkit.WebView;
7 |
8 | import com.example.lbaseexample.R;
9 | import com.leo.base.activity.LActivity;
10 | import com.leo.base.widget.LWebView;
11 | import com.leo.base.widget.T;
12 | import com.leo.base.widget.webview.LWebViewClient;
13 |
14 | public class WebViewActivity extends LActivity {
15 |
16 | private LWebView mWebView;
17 |
18 | @Override
19 | protected void onLCreate(Bundle savedInstanceState) {
20 | setContentView(R.layout.activity_webview);
21 | mWebView = (LWebView) findViewById(R.id.webview_webview);
22 | init();
23 | }
24 |
25 | @SuppressLint("SetJavaScriptEnabled")
26 | private void init() {
27 | // 支持JavaScript
28 | mWebView.getSettings().setJavaScriptEnabled(true);
29 | // 支持缩放
30 | mWebView.getSettings().setBuiltInZoomControls(false);
31 | // 支持保存数据
32 | mWebView.getSettings().setSaveFormData(false);
33 |
34 | // 清除缓存
35 | mWebView.clearCache(true);
36 | // 清除历史记录
37 | mWebView.clearHistory();
38 | // LWebView会自动为您的请求填充session,使用者无需自主填充。
39 | // 如果需要设置WebViewClient回调,请在此处设置为LWebViewClient,不影响使用
40 | mWebView.setWebViewClient(new LWebViewClient() {
41 |
42 | @Override
43 | public void onPageFinished(WebView view, String url) {
44 | // TODO Auto-generated method stub
45 | super.onPageFinished(view, url);
46 | T.ss("加载完成...");
47 | }
48 |
49 | @Override
50 | public void onPageStarted(WebView view, String url, Bitmap favicon) {
51 | // TODO Auto-generated method stub
52 | super.onPageStarted(view, url, favicon);
53 | T.ss("加载开始...");
54 | }
55 |
56 | });
57 | // 联网载入
58 | mWebView.loadUrl("http://www.youku.com");
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/fragment/Fragment2.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.example.lbaseexample.R;
10 | import com.example.lbaseexample.handler.FragmentHandler;
11 | import com.leo.base.activity.fragment.LFragment;
12 | import com.leo.base.entity.LMessage;
13 | import com.leo.base.entity.LReqEntity;
14 |
15 | public class Fragment2 extends LFragment {
16 |
17 | private TextView textview;
18 |
19 | private FragmentHandler handler;
20 |
21 | @Override
22 | public void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | handler = new FragmentHandler(this);
25 | }
26 |
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
29 | Bundle savedInstanceState) {
30 | ViewGroup mViewGroup = (ViewGroup) inflater.inflate(
31 | R.layout.fragment_view1, container, false);
32 | return mViewGroup;
33 | }
34 |
35 | @Override
36 | public void onActivityCreated(Bundle savedInstanceState) {
37 | // TODO Auto-generated method stub
38 | super.onActivityCreated(savedInstanceState);
39 | textview = (TextView) getView().findViewById(R.id.jsonstring);
40 | }
41 |
42 | @Override
43 | public void onResultHandler(LMessage msg, int requestId) {
44 | super.onResultHandler(msg, requestId);
45 | if (msg != null) {
46 | // textview.setText(msg.getStr());
47 | textview.setText("搜搜代码获取成功\n该页面使用了网络请求缓存!");
48 | }
49 | }
50 |
51 | public void load() {
52 | textview.setText("正在获取搜搜网页代码...");
53 | String url = "http://www.soso.com/";
54 | LReqEntity entity = new LReqEntity();
55 | entity.setUrl(url);
56 | entity.setUseCache(true);
57 | handler.request(entity, 0);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/FragmentViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.ViewPager;
5 | import android.support.v7.app.ActionBar;
6 |
7 | import com.example.lbaseexample.R;
8 | import com.example.lbaseexample.adapter.MyViewPagerAdapter;
9 | import com.leo.base.activity.LActivity;
10 | import com.leo.base.listener.LViewPagerChangeListener;
11 | import com.leo.base.listener.LViewPagerChangeListener.ILOnPageSelected;
12 |
13 | public class FragmentViewPagerActivity extends LActivity implements
14 | ActionBar.OnNavigationListener {
15 |
16 | private ViewPager mViewPager;
17 | private MyViewPagerAdapter adapter;
18 |
19 | private int index;
20 |
21 | @Override
22 | protected void onLCreate(Bundle savedInstanceState) {
23 | setContentView(R.layout.activity_fragment_viewpager);
24 | mViewPager = (ViewPager) findViewById(R.id.viewpager);
25 | adapter = new MyViewPagerAdapter(this, this.getSupportFragmentManager());
26 | mViewPager.setAdapter(adapter);
27 | LViewPagerChangeListener listener = new LViewPagerChangeListener();
28 | listener.setILOnPageSelected(new ILOnPageSelected() {
29 |
30 | @Override
31 | public void onPageSelected(int position) {
32 | index = position;
33 | if (mOnPagerIndexListener != null) {
34 | mOnPagerIndexListener.onPagerIndex(index);
35 | }
36 | }
37 | });
38 | mViewPager.setOnPageChangeListener(listener);
39 | }
40 |
41 | private OnPagerIndexListener mOnPagerIndexListener;
42 |
43 | public void setOnPagerIndexListener(OnPagerIndexListener listener) {
44 | this.mOnPagerIndexListener = listener;
45 | }
46 |
47 | public interface OnPagerIndexListener {
48 | void onPagerIndex(int index);
49 | }
50 |
51 | @Override
52 | public boolean onNavigationItemSelected(int itemPosition, long itemId) {
53 | this.index = itemPosition;
54 | this.mViewPager.setCurrentItem(itemPosition);
55 | return true;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/LBaseExample/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
15 |
16 |
20 |
21 |
26 |
27 |
32 |
33 |
38 |
39 |
44 |
45 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/handler/DownloadHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.handler;
2 |
3 | import org.json.JSONException;
4 |
5 | import android.graphics.Bitmap;
6 |
7 | import com.example.lbaseexample.activity.DownloadActivity;
8 | import com.example.lbaseexample.common.MHandler;
9 | import com.leo.base.entity.LMessage;
10 | import com.leo.base.exception.LLoginException;
11 | import com.leo.base.util.L;
12 | import com.leo.base.util.LBitmap;
13 | import com.leo.base.util.LFormat;
14 | import com.leo.base.widget.T;
15 |
16 | public class DownloadHandler extends MHandler {
17 |
18 | private DownloadActivity mActivity;
19 |
20 | public DownloadHandler(DownloadActivity activity) {
21 | super(activity);
22 | this.mActivity = activity;
23 | }
24 |
25 | @Override
26 | public LMessage onParse(String strs, int requestId) throws LLoginException,
27 | JSONException, Exception {
28 | LMessage msg = new LMessage();
29 | if (!LFormat.isEmpty(strs)) {
30 | Bitmap mBitmap = LBitmap.getResizedImage(strs, 100);
31 | if (mBitmap != null) {
32 | msg.setObj(mBitmap);
33 | msg.setStr(strs);
34 | return msg;
35 | }
36 | }
37 | return null;
38 | }
39 |
40 | @Override
41 | public void onProgress(int size, int current, int requestId) {
42 | super.onProgress(size, current, requestId);
43 | L.i("图片大小:" + size + ",当前大小:" + current);
44 | mActivity.getProgressBar().setMax(size);
45 | mActivity.getProgressBar().setProgress(current);
46 | }
47 |
48 | @Override
49 | protected void onNetWorkExc(int requestId) {
50 | T.ss("图片加载失败");
51 | }
52 |
53 | @Override
54 | protected void onParseExc(int requestId) {
55 | // TODO Auto-generated method stub
56 |
57 | }
58 |
59 | @Override
60 | protected void onLoginError(int requestId) {
61 | // TODO Auto-generated method stub
62 |
63 | }
64 |
65 | @Override
66 | protected void onLoginNone(int requestId) {
67 | // TODO Auto-generated method stub
68 |
69 | }
70 |
71 | @Override
72 | protected void onStop(int requestId) {
73 | // TODO Auto-generated method stub
74 |
75 | }
76 |
77 | @Override
78 | protected void onOtherExc(int requestId) {
79 | // TODO Auto-generated method stub
80 |
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/adapter/ListViewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.adapter;
2 |
3 | import java.util.List;
4 |
5 | import android.content.Context;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.RelativeLayout;
11 | import android.widget.TextView;
12 |
13 | import com.example.lbaseexample.R;
14 | import com.example.lbaseexample.common.MApplication;
15 | import com.example.lbaseexample.entity.ListEntity;
16 | import com.leo.base.adapter.LBaseAdapter;
17 | import com.nostra13.universalimageloader.core.ImageLoader;
18 |
19 | public class ListViewAdapter extends LBaseAdapter {
20 |
21 | private static final String KEY = ListViewAdapter.class.getSimpleName();
22 |
23 | private ImageLoader imageLoader;
24 |
25 | private RelativeLayout.LayoutParams layoutParams;
26 |
27 | public ListViewAdapter(Context context, List list) {
28 | super(context, list, true);
29 | imageLoader = getAdapter().getImageLoader();
30 | int imgWidth = MApplication.get().getDiaplayWidth() / 3;
31 | int imgHeight = imgWidth;
32 | layoutParams = new RelativeLayout.LayoutParams(imgWidth, imgHeight);
33 | }
34 |
35 | @Override
36 | public View getView(int position, View convertView, ViewGroup parent) {
37 | ViewHolder holder = null;
38 | convertView = getConvertView(KEY + position);
39 | if(convertView != null) {
40 | return convertView;
41 | } else {
42 | final LayoutInflater inflater = getInflater();
43 | convertView = inflater.inflate(R.layout.item_listview, null);
44 | holder = new ViewHolder();
45 | holder.imageview = (ImageView) convertView.findViewById(R.id.item_imageview);
46 | holder.imageview.setLayoutParams(layoutParams);
47 | holder.textview = (TextView) convertView.findViewById(R.id.item_textview);
48 | addConvertView(KEY + position, convertView);
49 | }
50 | ListEntity entity = (ListEntity) getItem(position);
51 | holder.textview.setText(entity.content);
52 | imageLoader.displayImage(entity.url, holder.imageview);
53 | return convertView;
54 | }
55 |
56 | static class ViewHolder {
57 | ImageView imageview;
58 | TextView textview;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/common/MApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.common;
2 |
3 | import android.content.res.Resources;
4 |
5 | import com.example.lbaseexample.R;
6 | import com.leo.base.application.LApplication;
7 |
8 | public class MApplication extends LApplication {
9 |
10 | /**
11 | * 实例
12 | */
13 | private static MApplication instance;
14 |
15 | /**
16 | * 本地数据库名称
17 | */
18 | private static final String DB_NAME = "LBASE_EXAMPLE_DB_NAME";
19 |
20 | /**
21 | * 本地数据库版本
22 | */
23 | private static final int DB_VERSION = 3;
24 |
25 | /**
26 | * 本地数据库创建表集合
27 | */
28 | private static String[] DB_CREATE_TABLES;
29 |
30 | /**
31 | * 本地数据库删除表集合
32 | */
33 | private static String[] DB_DROP_TABLES;
34 |
35 | /**
36 | * 本地缓存数量
37 | */
38 | private static final int CACHE_COUNT = 30;
39 |
40 | @Override
41 | public void onCreate() {
42 | super.onCreate();
43 | Resources resources = getResources();
44 | // 设置实例
45 | setLApplication(this);
46 | // 设置数据库
47 | setDBInfo(DB_NAME, DB_VERSION, getDBCreateTables(), getDBDropTables());
48 | // 打开DEBUG模式
49 | setOpenDebugMode(true);
50 | // 设置APP名称
51 | setAppName(resources.getString(R.string.app_name));
52 | // 设置服务器路径
53 | setAppServiceUrl(resources.getString(R.string.app_service_url));
54 | // 设置缓存数量
55 | setCacheCount(CACHE_COUNT);
56 | // 设置默认图片
57 | setDefaultImage(R.drawable.ic_launcher);
58 | }
59 |
60 | /**
61 | * 获取一个Application对象
62 | *
63 | * @return
64 | */
65 | public static synchronized MApplication get() {
66 | if (instance == null) {
67 | instance = (MApplication) getInstance();
68 | }
69 | return instance;
70 | }
71 |
72 | /**
73 | * 获取创建数据库数组
74 | *
75 | * @return
76 | */
77 | private String[] getDBCreateTables() {
78 | if (DB_CREATE_TABLES == null) {
79 | DB_CREATE_TABLES = getResources().getStringArray(
80 | R.array.create_tables);
81 | }
82 | return DB_CREATE_TABLES;
83 | }
84 |
85 | /**
86 | * 获取删除数据库数组
87 | *
88 | * @return
89 | */
90 | private String[] getDBDropTables() {
91 | if (DB_DROP_TABLES == null) {
92 | DB_DROP_TABLES = getResources().getStringArray(R.array.drop_tables);
93 | }
94 | return DB_DROP_TABLES;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/common/MHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.common;
2 |
3 | import org.json.JSONException;
4 |
5 | import com.leo.base.activity.LActivity;
6 | import com.leo.base.activity.fragment.LFragment;
7 | import com.leo.base.adapter.LBaseAdapter;
8 | import com.leo.base.entity.LMessage;
9 | import com.leo.base.exception.LLoginException;
10 | import com.leo.base.handler.LHandler;
11 | import com.leo.base.net.ILNetwork.LReqResultState;
12 |
13 | public abstract class MHandler extends LHandler {
14 |
15 | public MHandler(LActivity activity) {
16 | super(activity);
17 | init();
18 | }
19 |
20 | public MHandler(LFragment fragment) {
21 | super(fragment);
22 | init();
23 | }
24 |
25 | public MHandler(LBaseAdapter baseAdapter) {
26 | super(baseAdapter);
27 | init();
28 | }
29 |
30 | /**
31 | * 初始化网络请求监听,非常重要
32 | */
33 | private void init() {
34 | initNetwork(new MNetwork());
35 | }
36 |
37 | @Override
38 | public void onException(LReqResultState state, int requestId) {
39 | switch (state) {
40 | case NETWORK_EXC:
41 | onNetWorkExc(requestId);
42 | break;
43 | case PARSE_EXC:
44 | onParseExc(requestId);
45 | break;
46 | case LOGIN_ERROR:
47 | onLoginError(requestId);
48 | break;
49 | case LOGIN_NONE:
50 | onLoginNone(requestId);
51 | break;
52 | case STOP:
53 | onStop(requestId);
54 | break;
55 | default:
56 | onOtherExc(requestId);
57 | break;
58 | }
59 | }
60 |
61 | @Override
62 | public abstract LMessage onParse(String strs, int requestId)
63 | throws LLoginException, JSONException, Exception;
64 |
65 | @Override
66 | public void onProgress(int size, int current, int requestId) {
67 | // ... 如果在上传文件/下载文件时需要进度控制,请重写此方法
68 | }
69 |
70 | /**
71 | * 网络请求异常
72 | */
73 | protected abstract void onNetWorkExc(int requestId);
74 |
75 | /**
76 | * 数据解析失败
77 | */
78 | protected abstract void onParseExc(int requestId);
79 |
80 | /**
81 | * 自动登录错误
82 | */
83 | protected abstract void onLoginError(int requestId);
84 |
85 | /**
86 | * 未登录用户
87 | */
88 | protected abstract void onLoginNone(int requestId);
89 |
90 | /**
91 | * 线程停止
92 | */
93 | protected abstract void onStop(int requestId);
94 |
95 | /**
96 | * 其它异常
97 | */
98 | protected abstract void onOtherExc(int requestId);
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/db/DBManager.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.db;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.database.SQLException;
7 | import android.database.sqlite.SQLiteCursor;
8 |
9 | import com.example.lbaseexample.common.MApplication;
10 | import com.example.lbaseexample.entity.ListEntity;
11 | import com.leo.base.db.LDBHelper;
12 | import com.leo.base.db.LDBManager;
13 | import com.leo.base.util.L;
14 |
15 | public class DBManager extends LDBManager {
16 |
17 | private static final String KEY = DBManager.class.getSimpleName();
18 |
19 | private LDBHelper db;
20 |
21 | private static DBManager instance;
22 |
23 | private DBManager() {
24 | db = MApplication.get().getDBHelper();
25 | }
26 |
27 | public synchronized static DBManager get() {
28 | if (instance == null) {
29 | instance = new DBManager();
30 | }
31 | return instance;
32 | }
33 |
34 | public void addListEntitys(List list) {
35 | for (ListEntity entity : list) {
36 | String SQL = insertSql("ListEntityTable", new String[] { "ID",
37 | "URL", "CONTENT" },
38 | new String[] { String.valueOf(entity.id), entity.url,
39 | entity.content });
40 | execute(SQL, "ID 为 " + entity.id + "的数据插入失败");
41 | }
42 | }
43 |
44 | public List getListEntitys() {
45 | List res = new ArrayList();
46 | SQLiteCursor cursor = null;
47 | try {
48 | cursor = db.getCursor("ListEntityTable", null, null, null, null,
49 | null, null);
50 | while (cursor.moveToNext()) {
51 | ListEntity entity = new ListEntity();
52 | entity.id = cursor.getInt(cursor.getColumnIndex("ID"));
53 | entity.url = cursor.getString(cursor.getColumnIndex("URL"));
54 | entity.content = cursor.getString(cursor
55 | .getColumnIndex("CONTENT"));
56 | res.add(entity);
57 | }
58 | } catch (Exception e) {
59 | res = null;
60 | } finally {
61 | if (cursor != null) {
62 | cursor.close();
63 | cursor = null;
64 | }
65 | }
66 | return res;
67 | }
68 |
69 | public boolean delListEntitys() {
70 | String SQL = deleteSql("ListEntityTable");
71 | return execute(SQL, "清空表内所有数据失败");
72 | }
73 |
74 | public boolean execute(String SQL, String error) {
75 | boolean res = true;
76 | try {
77 | db.Execute(SQL);
78 | } catch (SQLException e) {
79 | res = false;
80 | if (null != error && !"".equals(error)) {
81 | L.e(KEY, error);
82 | }
83 | e.printStackTrace();
84 | }
85 | return res;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/net/ILNetwork.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.net;
2 |
3 | import com.leo.base.entity.LReqEntity;
4 |
5 | /**
6 | *
7 | * @author Chen Lei
8 | * @version 1.3.5
9 | *
10 | */
11 | public interface ILNetwork {
12 |
13 | static final String TAG = ILNetwork.class.getSimpleName();
14 |
15 | /**
16 | * 开始执行网络请求
17 | *
18 | * @param reqEntity
19 | * 请求封装实体
20 | * @param requestId
21 | * 请求ID,用于相同实体之间区分不同请求
22 | * 如果两次或多次请求的requestId相同, 框架需要检查之前此requestId的请求是否已经结束
23 | * 如还未执行完成,则不再重复执行
24 | * 如已完成,则继承执行
25 | * @param callback
26 | * 执行回调接口
27 | */
28 | void request(LReqEntity reqEntity, int requestId, ILNetworkCallback callback);
29 |
30 | /**
31 | * 停止当前对象所有线程
32 | */
33 | void stopAllThread();
34 |
35 | /**
36 | * 根据请求ID停止相对应的请求线程
37 | *
38 | * @param requestId
39 | */
40 | void stopRequestThread(int requestId);
41 |
42 | /**
43 | * 根据请求ID停止相对应的下载线程
44 | * @param requestId
45 | */
46 | void stopDownloadThread(int requestId);
47 |
48 | /**
49 | * 执行下载文件请求
50 | * @param url
51 | * @param savePath
52 | * @param saveName
53 | * @param callback
54 | */
55 | void download(String url, String savePath, String saveName, int id, ILNetworkCallback callback);
56 |
57 | /**
58 | * 登录状态
59 | *
60 | * @author leo
61 | *
62 | */
63 | enum LLoginState {
64 | /**
65 | * 登录成功
66 | */
67 | SUCCESS,
68 |
69 | /**
70 | * 登录失败
71 | */
72 | ERROR,
73 |
74 | /**
75 | * 没有登录帐号
76 | */
77 | NONE;
78 | }
79 |
80 | /**
81 | * 此方法用于执行用户登录操作
82 | * 在请求网络时,由于SESSION可能为空,导致无法获取数据
83 | * 这时便需要在后台做登录操作
84 | *
85 | * @return {@link LoginState}结果对象
86 | */
87 | LLoginState doLogin();
88 |
89 | /**
90 | * 请求返回结果状态
91 | *
92 | * @author leo
93 | *
94 | */
95 | enum LReqResultState {
96 |
97 | /**
98 | * 网络请求返回结果成功
99 | */
100 | SUCCESS,
101 |
102 | /**
103 | * 网络请求返回结果失败
104 | */
105 | NETWORK_EXC,
106 |
107 | /**
108 | * 数据解析异常
109 | */
110 | PARSE_EXC,
111 |
112 | /**
113 | * 用户登录成功
114 | */
115 | LOGIN_SUCCESS,
116 |
117 | /**
118 | * 用户登录失败
119 | */
120 | LOGIN_ERROR,
121 |
122 | /**
123 | * 不存在登录帐号
124 | */
125 | LOGIN_NONE,
126 |
127 | /**
128 | * 登录未实现异常
129 | */
130 | LOGIN_EXC,
131 |
132 | /**
133 | * 其它异常
134 | */
135 | OTHER,
136 |
137 | /**
138 | * 线程停止
139 | */
140 | STOP;
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/LBaseExample/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
36 |
40 |
41 |
45 |
46 |
50 |
51 |
55 |
56 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/LBaseExample/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
36 |
40 |
41 |
45 |
46 |
50 |
51 |
55 |
56 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/DownloadActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity;
2 |
3 | import java.io.File;
4 |
5 | import android.graphics.Bitmap;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Button;
10 | import android.widget.ImageView;
11 | import android.widget.ProgressBar;
12 |
13 | import com.example.lbaseexample.R;
14 | import com.example.lbaseexample.common.MApplication;
15 | import com.example.lbaseexample.handler.DownloadHandler;
16 | import com.leo.base.activity.LActivity;
17 | import com.leo.base.entity.LMessage;
18 | import com.leo.base.util.LFormat;
19 |
20 | public class DownloadActivity extends LActivity implements OnClickListener {
21 |
22 | private ProgressBar progress;
23 | private Button button;
24 | private ImageView imageview;
25 |
26 | private boolean isDown = false;
27 |
28 | private DownloadHandler handler;
29 |
30 | private String fileUrl;
31 |
32 | @Override
33 | protected void onLCreate(Bundle savedInstanceState) {
34 | setContentView(R.layout.activity_download);
35 | progress = (ProgressBar) findViewById(R.id.download_progress);
36 | button = (Button) findViewById(R.id.download_button);
37 | imageview = (ImageView) findViewById(R.id.download_imageview);
38 | button.setOnClickListener(this);
39 | handler = new DownloadHandler(this);
40 | }
41 |
42 | @Override
43 | public void onResultHandler(LMessage msg, int requestId) {
44 | super.onResultHandler(msg, requestId);
45 | if (msg != null) {
46 | Bitmap bitmap = (Bitmap) msg.getObj();
47 | if (bitmap != null) {
48 | imageview.setImageBitmap(bitmap);
49 | imageview.setVisibility(View.VISIBLE);
50 | fileUrl = msg.getStr();
51 | button.setText("下载完成");
52 | isDown = false;
53 | }
54 | }
55 | }
56 |
57 | @Override
58 | protected void onDestroy() {
59 | super.onDestroy();
60 | if(handler != null) {
61 | handler.stopAllThread();
62 | }
63 | if (!LFormat.isEmpty(fileUrl)) {
64 | File file = new File(fileUrl);
65 | if (file.exists()) {
66 | file.delete();
67 | }
68 | }
69 | }
70 |
71 | public ProgressBar getProgressBar() {
72 | return progress;
73 | }
74 |
75 | @Override
76 | public void onClick(View v) {
77 | if (!isDown) {
78 | String url = "http://www.zhuoku.org/uploadfile/2013/0125/20130125102609585.jpg";
79 | handler.download(url, MApplication.getInstance().getCacheFile()
80 | .getPath(), LFormat.getMD5Url(url), 0);
81 | button.setText("正在下载");
82 | imageview.setVisibility(View.GONE);
83 | } else {
84 | handler.stopDownloadThread(0);
85 | button.setText("下载已取消,点击重新下载");
86 | }
87 | isDown = !isDown;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/handler/ListViewHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.handler;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.json.JSONArray;
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import com.example.lbaseexample.common.MHandler;
11 | import com.example.lbaseexample.db.DBManager;
12 | import com.example.lbaseexample.entity.ListEntity;
13 | import com.leo.base.activity.LActivity;
14 | import com.leo.base.entity.LMessage;
15 | import com.leo.base.exception.LLoginException;
16 | import com.leo.base.util.L;
17 | import com.leo.base.widget.T;
18 |
19 | public class ListViewHandler extends MHandler {
20 |
21 | public ListViewHandler(LActivity activity) {
22 | super(activity);
23 | }
24 |
25 | @Override
26 | public LMessage onParse(String strs, int requestId) throws JSONException,
27 | LLoginException {
28 | LMessage msg = parseJson(strs);
29 | if (msg.getWhat() == 1) {
30 | List list = msg.getList();
31 | // ... 清空本地数据库所有数据
32 | DBManager.get().delListEntitys();
33 | // ... 清加所有数据到本地数据库
34 | DBManager.get().addListEntitys(list);
35 | }
36 | return msg;
37 | }
38 |
39 | @Override
40 | protected void onNetWorkExc(int requestId) {
41 | T.ss("网络请求发现异常");
42 | }
43 |
44 | @Override
45 | protected void onParseExc(int requestId) {
46 | T.ss("数据解析发现异常");
47 | }
48 |
49 | @Override
50 | protected void onLoginError(int requestId) {
51 | T.ss("自动登录错误异常");
52 | }
53 |
54 | @Override
55 | protected void onLoginNone(int requestId) {
56 | T.ss("用户并未存有登录帐号异常");
57 | }
58 |
59 | @Override
60 | protected void onOtherExc(int requestId) {
61 | T.ss("其它异常");
62 | }
63 |
64 | @Override
65 | protected void onStop(int requestId) {
66 | L.i("线程停止");
67 | }
68 |
69 | private LMessage parseJson(String json) throws JSONException,
70 | LLoginException {
71 | LMessage msg = new LMessage();
72 | JSONObject newsObject = new JSONObject(json);
73 | /*
74 | * if (newsObject.optInt("is_login", 0) == 0) { // ... 例: // ...
75 | * 如果此次请求需要用户登录,而此处后台告诉前台, // ... 当前用户并未登录,可以在此处向上抛出未登录异常 throw new
76 | * LLoginException(); // ... 框架捕获到此异常之后,会自动调用 MNetwork.doLogin()方法自动登录,
77 | * // ... 登录成功后,自动重新请求 }
78 | */
79 | msg.setWhat(1);
80 | JSONObject jsonObject = newsObject.getJSONObject("data");
81 | JSONArray blogsJson = jsonObject.getJSONArray("blogs");
82 | List list = new ArrayList();
83 | for (int i = 0; i < blogsJson.length(); i++) {
84 | JSONObject newsInfoLeftObject = blogsJson.getJSONObject(i);
85 | ListEntity entity = new ListEntity();
86 | entity.id = newsInfoLeftObject.optInt("albid");
87 | entity.url = newsInfoLeftObject.optString("isrc");
88 | entity.content = newsInfoLeftObject.optString("msg");
89 | list.add(entity);
90 | }
91 | msg.setList(list);
92 | return msg;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/ListViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity;
2 |
3 | import java.util.List;
4 |
5 | import android.os.Bundle;
6 | import android.widget.ListView;
7 |
8 | import com.example.lbaseexample.R;
9 | import com.example.lbaseexample.adapter.ListViewAdapter;
10 | import com.example.lbaseexample.db.DBManager;
11 | import com.example.lbaseexample.entity.ListEntity;
12 | import com.example.lbaseexample.handler.ListViewHandler;
13 | import com.leo.base.activity.LActivity;
14 | import com.leo.base.entity.LMessage;
15 | import com.leo.base.entity.LReqEntity;
16 | import com.leo.base.util.L;
17 | import com.leo.base.widget.T;
18 |
19 | public class ListViewActivity extends LActivity {
20 |
21 | private ListView mListView;
22 | private ListViewAdapter adapter;
23 |
24 | private ListViewHandler handler;
25 |
26 | @Override
27 | protected void onLCreate(Bundle savedInstanceState) {
28 | setContentView(R.layout.activity_listview);
29 | mListView = (ListView) findViewById(R.id.listview);
30 | handler = new ListViewHandler(this);
31 | initData();
32 | }
33 |
34 | /**
35 | * 加载数据
36 | */
37 | private void initData() {
38 | List data = DBManager.get().getListEntitys();
39 | if (data != null && data.size() > 0) {
40 | setData(data);
41 | } else {
42 | sendRequest();
43 | showProgressDialog("正在加载数据...");
44 | }
45 | }
46 |
47 | @Override
48 | protected void onDestroy() {
49 | if (handler != null) {
50 | handler.stopAllThread();
51 | }
52 | super.onDestroy();
53 | }
54 |
55 | /**
56 | * 请求网络,当请求成功后,框架会调用resultHandler方法,
57 | */
58 | private void sendRequest() {
59 | // ... 网络请求地址,此URL来自于网络
60 | String url = "http://www.duitang.com/album/1733789/masn/p/2/24/";
61 | LReqEntity entity = new LReqEntity(url);
62 | handler.request(entity, 1);
63 | }
64 |
65 | @Override
66 | public void onKeyBackListener() {
67 | super.onKeyBackListener();
68 | L.i("停止线程!");
69 | if (handler != null) {
70 | handler.stopAllThread();
71 | }
72 | L.i("销毁Activity!");
73 | this.finish();
74 | }
75 |
76 | private void setData(List data) {
77 | if (adapter == null) {
78 | adapter = new ListViewAdapter(this, data);
79 | mListView.setAdapter(adapter);
80 | } else {
81 | adapter.getAdapter().setList(data);
82 | adapter.notifyDataSetChanged();
83 | }
84 | }
85 |
86 | @Override
87 | public void onResultHandler(LMessage msg, int requestId) {
88 | super.onResultHandler(msg, requestId);
89 | // ... 如果请求过程中发现异常,MHandler 会将清空,
90 | // ... 如需修改请自主到MHandler中修改
91 | if (msg != null) {
92 | if (msg.getWhat() == 1) {
93 | T.ss("获取数据成功");
94 | List data = msg.getList();
95 | setData(data);
96 | } else {
97 | T.ss("获取数据失败");
98 | }
99 | }
100 | dismissProgressDialog();
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/adapter/LPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.adapter;
2 |
3 | import java.util.List;
4 |
5 | import android.content.Context;
6 | import android.support.v4.view.PagerAdapter;
7 | import android.util.SparseArray;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | /**
12 | * 来源:
LPagerAdapter 继承自
13 | * {@linkplain android.support.v4.view.PagerAdapter PagerAdapter}
14 | *
15 | * @author Chen Lei
16 | * @version 1.1.5
17 | * @param
18 | * 传入此参数类型,以保证返回的数据为使用者需要的类型
19 | */
20 | public abstract class LPagerAdapter extends PagerAdapter {
21 |
22 | private LAdapters mAdapter;
23 |
24 | private SparseArray mViewList;
25 |
26 | public LPagerAdapter(Context context) {
27 | initAdapters(context, null, false);
28 | }
29 |
30 | public LPagerAdapter(Context context, List list) {
31 | initAdapters(context, list, false);
32 | }
33 |
34 | public LPagerAdapter(Context context, List list, boolean useImage) {
35 | initAdapters(context, list, useImage);
36 | }
37 |
38 | /**
39 | * 构造函数
40 | *
41 | * @param context
42 | * 传入上下文对象
43 | * @param list
44 | * 传入T类型的{@link List}
45 | * @param hasImage
46 | * 传入是否需要图片下载
47 | */
48 | private void initAdapters(Context context, List list, boolean useImage) {
49 | mAdapter = new LAdapters(context, list, useImage);
50 | this.mViewList = new SparseArray();
51 | }
52 |
53 | public LAdapters getAdapter() {
54 | return mAdapter;
55 | }
56 |
57 | @Override
58 | public int getCount() {
59 | int count = 0;
60 | if (mAdapter != null) {
61 | count = mAdapter.getCount();
62 | }
63 | return count;
64 | }
65 |
66 | @Override
67 | public void destroyItem(ViewGroup container, int position, Object object) {
68 | if (mViewList == null || mViewList.size() <= 0 || position < 0
69 | || mViewList.size() <= position) {
70 | return;
71 | }
72 | View view = mViewList.get(position);
73 | if (view == null) {
74 | return;
75 | }
76 | container.removeView(view);
77 | mViewList.remove(position);
78 | }
79 |
80 | /**
81 | * 添加页面样式
82 | */
83 | @Override
84 | public abstract Object instantiateItem(ViewGroup container, int position);
85 |
86 | @Override
87 | public boolean isViewFromObject(View view, Object object) {
88 | return view == object;
89 | }
90 |
91 | /**
92 | * 清除View
93 | */
94 | public void clearView() {
95 | if (mViewList != null) {
96 | mViewList.clear();
97 | }
98 | this.notifyDataSetChanged();
99 | }
100 |
101 | /**
102 | * 销毁方法
103 | */
104 | public void destroy() {
105 | clearView();
106 | mViewList = null;
107 | if (mAdapter != null) {
108 | mAdapter.destroyList();
109 | mAdapter.setList(null);
110 | }
111 | }
112 |
113 | public SparseArray getViewList() {
114 | return mViewList;
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/activity/fragment/LFragment.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.activity.fragment;
2 |
3 | import android.app.Activity;
4 | import android.support.v4.app.Fragment;
5 | import android.view.View;
6 |
7 | import com.leo.base.activity.LActivity;
8 | import com.leo.base.dialog.LProgress;
9 | import com.leo.base.dialog.LProgress.OnKeyBackListener;
10 | import com.leo.base.entity.LMessage;
11 | import com.leo.base.handler.ILHandlerCallback;
12 |
13 | /**
14 | * 来源:
LFragment 继承自 {@link android.support.v4.app.Fragment} 用途:
15 | * 所有 Fragment 需继承此类 说明:
当你使用了
16 | * {@linkplain com.leo.base.handler.LHandler#startLoadingData(com.leo.base.entity.LReqEntity)
17 | * LHandler.startLoadingData(LReqEntity)} 方法请求网络后,
18 | * {@linkplain com.leo.base.handler.LHandler LHandler} 会自动调用此类的
19 | * {@linkplain com.leo.base.activity.fragment.LFragment#resultHandler(com.leo.base.entity.LMessage)
20 | * LFragment.resultHandler(LMessage)} 方法,并将解析的结果
21 | * {@linkplain com.leo.base.entity.LMessage LMessage} 对象传回
22 | *
23 | * @author Chen Lei
24 | * @version 1.3.1
25 | *
26 | */
27 | public abstract class LFragment extends Fragment implements ILHandlerCallback, OnKeyBackListener {
28 |
29 | protected LActivity mActivity;
30 |
31 | protected View mView;
32 |
33 | /**
34 | * 进度提示框
35 | */
36 | private LProgress mProgressDialog;
37 |
38 | @Override
39 | public void onAttach(Activity activity) {
40 | super.onAttach(activity);
41 | this.mActivity = (LActivity) activity;
42 | }
43 |
44 | @Override
45 | public void onPause() {
46 | super.onPause();
47 | dismissProgressDialog();
48 | mProgressDialog = null;
49 | }
50 |
51 | @Override
52 | public void onDestroy() {
53 | super.onDestroy();
54 | }
55 |
56 | /**
57 | * 显示一个ProgressDialog,直接调用即可
58 | * 此ProgressDialog会在onPause方法内自动销毁
59 | *
60 | * @param text
61 | * 提示文字
62 | */
63 | protected void showProgressDialog(String text) {
64 | if (mProgressDialog == null) {
65 | mProgressDialog = new LProgress(this.getActivity());
66 | mProgressDialog.setOnKeyBackListener(this);
67 | }
68 | mProgressDialog.show(text);
69 | }
70 |
71 | /**
72 | * 销毁一个ProgressDialog
73 | */
74 | protected void dismissProgressDialog() {
75 | if (mProgressDialog != null && mProgressDialog.isShowing()) {
76 | mProgressDialog.dismiss();
77 | }
78 | }
79 |
80 | @Override
81 | public void onKeyBackListener() {
82 | // ... 如果ProgressDialog正在运行,使用者按下BACK键,销毁ProgressDialog的同时,还会调用此接口。
83 | // ... 使用者可以在这里finish(),也可以在这里停止线程
84 | }
85 |
86 | /**
87 | * 当你使用了
88 | * {@linkplain com.leo.base.handler.LHandler#startLoadingData(com.leo.base.net.LReqEntity)
89 | * LHandler.startLoadingData(LReqEntity)} 方法请求网络后,
90 | * {@linkplain com.leo.base.handler.LHandler LHandler} 会自动调用此方法,并将解析的结果
91 | * {@linkplain com.leo.base.entity.LMessage LMessage} 对象传回
92 | *
93 | * @param msg
94 | */
95 | @Override
96 | public void onResultHandler(LMessage msg, int requestId) {
97 | // ... 写入你需要的代码
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/net/LNetwork.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.net;
2 |
3 | import android.util.SparseArray;
4 |
5 | import com.leo.base.entity.LReqEntity;
6 | import com.leo.base.util.L;
7 |
8 | /**
9 | *
10 | * @author Chen Lei
11 | * @version 1.3.5
12 | *
13 | */
14 | public abstract class LNetwork implements ILNetwork {
15 |
16 | /**
17 | * 线程状态
18 | *
19 | * @author object
20 | *
21 | */
22 | enum LReqState {
23 |
24 | /**
25 | * 线程状态为等待执行
26 | */
27 | PENDING,
28 |
29 | /**
30 | * 线程状态为正在执行
31 | */
32 | RUNNING,
33 |
34 | /**
35 | * 线程状态为执行结束
36 | */
37 | FINISHED;
38 | }
39 |
40 | /**
41 | * 存放当前所有线程的集合
42 | */
43 | private SparseArray mRequestThreads;
44 |
45 | private SparseArray mDownloadThreads;
46 |
47 | /**
48 | * 构造函数
49 | */
50 | public LNetwork() {
51 | mRequestThreads = new SparseArray();
52 | mDownloadThreads = new SparseArray();
53 | }
54 |
55 | @Override
56 | public void request(LReqEntity reqEntity, int requestId,
57 | ILNetworkCallback callback) {
58 | if (reqEntity == null) {
59 | throw new NullPointerException(
60 | "The network requests the LReqEntity parameter cannot be empty!");
61 | }
62 | if (callback == null) {
63 | throw new NullPointerException(
64 | "This is an invalid request,because you did not realize the callback interface!");
65 | }
66 | LRequest task = mRequestThreads.get(requestId);
67 | if (task == null || task.getState() == LReqState.FINISHED) {
68 | task = new LRequest(reqEntity, requestId, callback, this);
69 | task.execute();
70 | mRequestThreads.put(requestId, task);
71 | } else {
72 | L.i(TAG, "requestId " + requestId + " thread is running!");
73 | }
74 | }
75 |
76 | @Override
77 | public void stopAllThread() {
78 | for (int index = 0, size = mRequestThreads.size(); index < size; index++) {
79 | int key = mRequestThreads.keyAt(index);
80 | stopRequestThread(key);
81 | }
82 | for (int index = 0, size = mDownloadThreads.size(); index < size; index++) {
83 | int key = mDownloadThreads.keyAt(index);
84 | stopDownloadThread(key);
85 | }
86 | }
87 |
88 | @Override
89 | public void stopRequestThread(int requestId) {
90 | LRequest task = mRequestThreads.get(requestId);
91 | if (task != null) {
92 | task.stop();
93 | }
94 | }
95 |
96 | @Override
97 | public void stopDownloadThread(int requestId) {
98 | LDownload task = mDownloadThreads.get(requestId);
99 | if (task != null) {
100 | task.stop();
101 | }
102 | }
103 |
104 | @Override
105 | public void download(String url, String savePath, String saveName,
106 | int requestId, ILNetworkCallback callback) {
107 | LDownload task = mDownloadThreads.get(requestId);
108 | if (task == null || task.getState() == LReqState.FINISHED) {
109 | task = new LDownload(url, savePath, saveName, requestId, callback,
110 | this);
111 | task.execute();
112 | mDownloadThreads.put(requestId, task);
113 | } else {
114 | L.i(TAG, "requestId " + requestId + " thread is running!");
115 | }
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/db/LDBManager.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.db;
2 |
3 | import android.text.TextUtils;
4 |
5 | /**
6 | *
7 | * @author Chen Lei
8 | *
9 | */
10 | public class LDBManager {
11 |
12 | /**
13 | * 生成插入语句
14 | *
15 | * @param table
16 | * 表名
17 | * @param names
18 | * 字段数组
19 | * @param values
20 | * 值数组
21 | * @return
22 | */
23 | protected String insertSql(String table, String[] names, String[] values) {
24 | if (TextUtils.isEmpty(table)) {
25 | throw new NullPointerException("表名不能为空");
26 | }
27 | if (names == null || names.length <= 0) {
28 | throw new NullPointerException("插入字段名不能为空");
29 | }
30 | if (values == null || values.length <= 0) {
31 | throw new NullPointerException("插入值不能为空");
32 | }
33 | if (names.length != values.length) {
34 | throw new IllegalArgumentException("参数不匹配错误");
35 | }
36 | StringBuilder sb = new StringBuilder();
37 | sb.append("INSERT INTO ").append(table).append(" (");
38 | for (String name : names) {
39 | sb.append(name).append(",");
40 | }
41 | sb.deleteCharAt(sb.length() - 1);
42 | sb.append(") VALUES (");
43 | for (String value : values) {
44 | sb.append("'").append(value).append("',");
45 | }
46 | sb.deleteCharAt(sb.length() - 1);
47 | sb.append(");");
48 | return sb.toString();
49 | }
50 |
51 | protected String deleteSql(String table) {
52 | if (TextUtils.isEmpty(table)) {
53 | throw new NullPointerException("表名不能为空");
54 | }
55 | return "DELETE FROM " + table;
56 | }
57 |
58 | protected String deleteSql(String table, String where) {
59 | if (TextUtils.isEmpty(table)) {
60 | throw new NullPointerException("表名不能为空");
61 | }
62 | StringBuilder sb = new StringBuilder();
63 | sb.append("DELETE FROM ").append(table);
64 | if (!TextUtils.isEmpty(where)) {
65 | sb.append(" WHERE ").append(where);
66 | }
67 | sb.append(";");
68 | return sb.toString();
69 | }
70 |
71 | protected String selectSql(String table) {
72 | if (TextUtils.isEmpty(table)) {
73 | throw new NullPointerException("表名不能为空");
74 | }
75 | return "SELETE * FROM " + table;
76 | }
77 |
78 | protected String selectSql(String table, String where) {
79 | if (TextUtils.isEmpty(table)) {
80 | throw new NullPointerException("表名不能为空");
81 | }
82 | StringBuilder sb = new StringBuilder();
83 | sb.append("SELETE * FROM ").append(table);
84 | if (!TextUtils.isEmpty(where)) {
85 | sb.append(" WHERE ").append(where);
86 | }
87 | sb.append(";");
88 | return sb.toString();
89 | }
90 |
91 | protected String selectSql(String table, String[] selectNames, String where) {
92 | if (TextUtils.isEmpty(table)) {
93 | throw new NullPointerException("表名不能为空");
94 | }
95 | if (selectNames == null || selectNames.length <= 0) {
96 | throw new NullPointerException("插入字段名不能为空");
97 | }
98 | StringBuilder sb = new StringBuilder();
99 | sb.append("SELETE ");
100 | for (String name : selectNames) {
101 | sb.append(name).append(",");
102 | }
103 | sb.deleteCharAt(sb.length() - 1);
104 | sb.append(" FROM").append(table);
105 | if (!TextUtils.isEmpty(where)) {
106 | sb.append(" WHERE ").append(where);
107 | }
108 | sb.append(";");
109 | return sb.toString();
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/util/LDate.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.util;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Calendar;
6 | import java.util.Date;
7 | import java.util.TimeZone;
8 |
9 |
10 | /**
11 | *
12 | * @author Chen Lei
13 | * @version 1.1.5
14 | *
15 | */
16 | public class LDate {
17 |
18 | private LDate() {
19 | }
20 |
21 | /**
22 | * 得到当前日期时间
23 | *
24 | * @return yyyy-MM-dd HH:mm:ss
25 | */
26 | public static String getDateTime() {
27 | return getCustomTime("yyyy-MM-dd HH:mm:ss");
28 | }
29 |
30 | /**
31 | * 得到当前日期
32 | *
33 | * @return yyyy-MM-dd
34 | */
35 | public static String getDate() {
36 | return getCustomTime("yyyy-MM-dd");
37 | }
38 |
39 | /**
40 | * 得到当前时间
41 | *
42 | * @return HH:mm:ss
43 | */
44 | public static String getTime() {
45 | return getCustomTime("HH:mm:ss");
46 | }
47 |
48 | /**
49 | * 获取自定义格式时间
50 | *
51 | * @param format
52 | * 格式:yyyy年、MM月、dd日、HH小时、mm分钟、ss秒
53 | * @return
54 | */
55 | public static String getCustomTime(String format) {
56 | Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
57 | SimpleDateFormat sdf = new SimpleDateFormat(format);
58 | return sdf.format(cal.getTime());
59 | }
60 |
61 | /**
62 | * 传入String,获得一个Date对象
63 | *
64 | * @param strDate
65 | * @return yyyy-MM-dd HH:mm:ss 返回null为字符串错误
66 | */
67 | public static Date getDateTime(String strDate) {
68 | return getDateByFormat(strDate, "yyyy-MM-dd HH:mm:ss");
69 | }
70 |
71 | /**
72 | * 传入String(例20130101210000),获得一个自定义格式的Date(yyyy-MM-dd HH:mm:ss)对象
73 | *
74 | * @param strDate
75 | * @param format
76 | * 格式
77 | * @return 返回null为字符串错误
78 | */
79 | public static Date getDateByFormat(String strDate, String format) {
80 | SimpleDateFormat sdf = new SimpleDateFormat(format);
81 | try {
82 | return (sdf.parse(strDate));
83 | } catch (ParseException e) {
84 | return null;
85 | }
86 | }
87 |
88 | /**
89 | * 传入一个时间,判断是星期几
90 | *
91 | * @param myDate
92 | * @return
93 | */
94 | public static String getWeekDay(Date myDate) {
95 | Calendar calendar = Calendar.getInstance();
96 | calendar.setTime(myDate);
97 | int x = calendar.get(Calendar.DAY_OF_WEEK);
98 | String[] days = new String[] { "星期天", "星期一", "星期二", "星期三", "星期四",
99 | "星期五", "星期六" };
100 | if (x > 7) {
101 | return "error";
102 | }
103 | return days[x - 1];
104 | }
105 |
106 | /**
107 | * 传入如yyyyMMddHHmmss格式字符串,计算与当前时间距离多久
108 | *
109 | * @param timer
110 | * yyyyMMddHHmmss 格式
111 | * @return 时间
112 | * @throws ParseException
113 | */
114 | public static String getComputeNowTimeStr(String timer, String format)
115 | throws ParseException {
116 | SimpleDateFormat sdf = new SimpleDateFormat(format);
117 | Date date = sdf.parse(timer);
118 | Date today = new Date();
119 | long interval = today.getTime() - date.getTime();
120 | today.setHours(23);
121 | today.setMinutes(59);
122 | today.setSeconds(59);
123 | boolean isSameDay = (interval / 86400000) == 0 ? true : false;
124 | if (isSameDay) {
125 | if (interval < 60 * 60 * 1000) {
126 | return (interval / (60 * 1000)) + "分钟前";
127 | } else {
128 | return (interval / (60 * 60 * 1000)) + "小时前";
129 | }
130 | } else {
131 | SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd hh:mm");
132 | return dateFormat.format(date);
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 |
12 | import com.example.lbaseexample.R;
13 | import com.example.lbaseexample.db.DBManager;
14 | import com.leo.base.activity.LActivity;
15 | import com.leo.base.util.L;
16 | import com.leo.base.util.LMobileInfo;
17 | import com.leo.base.util.LSharePreference;
18 | import com.leo.base.widget.T;
19 |
20 | public class MainActivity extends LActivity implements OnClickListener {
21 |
22 | private static final String KEY = MainActivity.class.getSimpleName();
23 |
24 | private TextView tvInfos;
25 |
26 | @Override
27 | protected void onLCreate(Bundle savedInstanceState) {
28 | setContentView(R.layout.activity_main);
29 | initLayout();
30 | // ... 添加用户信息到SharedPreferences存储
31 | LSharePreference.getInstance(this).setString("username", "admin");
32 | LSharePreference.getInstance(this).setString("password", "admin");
33 | }
34 |
35 | private void initLayout() {
36 | tvInfos = (TextView) findViewById(R.id.main_infos);
37 |
38 | ((Button) findViewById(R.id.main_listview)).setOnClickListener(this);
39 |
40 | ((Button) findViewById(R.id.main_fragment_viewpager))
41 | .setOnClickListener(this);
42 |
43 | ((Button) findViewById(R.id.main_many_request))
44 | .setOnClickListener(this);
45 |
46 | ((Button) findViewById(R.id.main_download)).setOnClickListener(this);
47 |
48 | ((Button) findViewById(R.id.main_webview)).setOnClickListener(this);
49 | }
50 |
51 | @Override
52 | protected void onResume() {
53 | super.onResume();
54 | String strs = "手机型号:" + LMobileInfo.getMobileType() + "\n" + "系统版本:"
55 | + LMobileInfo.getVersionRelease() + "\n" + "IMEI:"
56 | + LMobileInfo.getImei() + "\n" + "IMSI:"
57 | + LMobileInfo.getImsi();
58 | L.i(KEY, strs);
59 | tvInfos.setText(strs);
60 | }
61 |
62 | @Override
63 | public void onClick(View v) {
64 | switch (v.getId()) {
65 | case R.id.main_listview:
66 | L.i("进入 ListView 示例");
67 | getJumpIntent(ListViewActivity.class);
68 | break;
69 | case R.id.main_fragment_viewpager:
70 | L.i("进入 Fragment ViewPager 示例");
71 | getJumpIntent(FragmentViewPagerActivity.class);
72 | break;
73 | case R.id.main_many_request:
74 | getJumpIntent(ManyRequestActivity.class);
75 | break;
76 | case R.id.main_download:
77 | getJumpIntent(DownloadActivity.class);
78 | break;
79 | case R.id.main_webview:
80 | getJumpIntent(WebViewActivity.class);
81 | break;
82 | }
83 | }
84 |
85 | private void getJumpIntent(Class> cls) {
86 | Intent intent = new Intent(this, cls);
87 | this.startActivity(intent);
88 | }
89 |
90 | @Override
91 | public boolean onOptionsItemSelected(MenuItem item) {
92 | switch (item.getItemId()) {
93 | case R.id.action_clear_all_data:
94 | boolean b = DBManager.get().delListEntitys();
95 | if (b) {
96 | T.ss("清理完成!");
97 | } else {
98 | T.ss("清理失败");
99 | }
100 | break;
101 | case R.id.action_about_me:
102 | T.ss("关于我");
103 | getJumpIntent(AboutActivity.class);
104 | break;
105 | }
106 | return super.onOptionsItemSelected(item);
107 | }
108 |
109 | @Override
110 | public boolean onCreateOptionsMenu(Menu menu) {
111 | getMenuInflater().inflate(R.menu.main, menu);
112 | return true;
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/listener/LViewPagerChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.listener;
2 |
3 | import android.support.v4.view.ViewPager.OnPageChangeListener;
4 |
5 | /**
6 | *
7 | * @author Chen Lei
8 | * @version 1.1.5
9 | *
10 | */
11 | public class LViewPagerChangeListener implements OnPageChangeListener {
12 |
13 | public enum State {
14 | NONE, SCROLLING, SCROLL_SUCCESS
15 | }
16 |
17 | private ILOnPageScrollStateChanged mILOnPageScrollStateChanged;
18 |
19 | private ILOnPageScrolled mILOnPageScrolled;
20 |
21 | private ILOnPageSelected mILOnPageSelected;
22 |
23 | @Override
24 | public void onPageScrollStateChanged(int state) {
25 | if (mILOnPageScrollStateChanged == null)
26 | return;
27 | switch (state) {
28 | case 0:
29 | mILOnPageScrollStateChanged.onPageScrollStateChanged(State.NONE);
30 | break;
31 | case 1:
32 | mILOnPageScrollStateChanged
33 | .onPageScrollStateChanged(State.SCROLLING);
34 | break;
35 | case 2:
36 | mILOnPageScrollStateChanged
37 | .onPageScrollStateChanged(State.SCROLL_SUCCESS);
38 | break;
39 | }
40 | }
41 |
42 | @Override
43 | public void onPageScrolled(int position, float positionOffset,
44 | int positionOffsetPixels) {
45 | if (mILOnPageScrolled == null)
46 | return;
47 | mILOnPageScrolled.onPageScrolled(position, positionOffset,
48 | positionOffsetPixels);
49 | }
50 |
51 | @Override
52 | public void onPageSelected(int position) {
53 | if (mILOnPageSelected == null)
54 | return;
55 | mILOnPageSelected.onPageSelected(position);
56 | }
57 |
58 | /**
59 | * 设置ILOnPageScrollStateChanged实例
60 | *
61 | * @param onPageScrollStateChanged
62 | */
63 | public void setILOnPageScrollStateChanged(
64 | ILOnPageScrollStateChanged onPageScrollStateChanged) {
65 | this.mILOnPageScrollStateChanged = onPageScrollStateChanged;
66 | }
67 |
68 | /**
69 | * 设置ILOnPageScrolled实例
70 | *
71 | * @param onPageScrolled
72 | */
73 | public void setILOnPageScrolled(ILOnPageScrolled onPageScrolled) {
74 | this.mILOnPageScrolled = onPageScrolled;
75 | }
76 |
77 | /**
78 | * 设置ILOnPageSelected实例
79 | *
80 | * @param onPageSelected
81 | */
82 | public void setILOnPageSelected(ILOnPageSelected onPageSelected) {
83 | this.mILOnPageSelected = onPageSelected;
84 | }
85 |
86 | /**
87 | * 滑动状态接口
88 | *
89 | * @author leo
90 | *
91 | */
92 | public interface ILOnPageScrollStateChanged {
93 | /**
94 | * 滑动状态方法
95 | * 三种状态:
96 | * State.NONE表示未滑动
97 | * State.SCROLLING表示正在滑动
98 | * State. SCROLL_SUCCESS表示滑动完成
99 | *
100 | * @param state
101 | * :滑动状态,使用{@link com.leo.base.listener.LViewPagerChangeListener.State}
102 | */
103 | void onPageScrollStateChanged(State state);
104 | }
105 |
106 | /**
107 | * 滑动参数接口
108 | *
109 | * @author leo
110 | *
111 | */
112 | public interface ILOnPageScrolled {
113 | /**
114 | * 滑动参数方法
115 | *
116 | * @param position
117 | * :当前页面标识
118 | * @param positionOffset
119 | * :当前页面偏移的百分比
120 | * @param positionOffsetPixels
121 | * :当前页面偏移的像素值
122 | */
123 | void onPageScrolled(int position, float positionOffset,
124 | int positionOffsetPixels);
125 | }
126 |
127 | /**
128 | * 跳转完成接口
129 | *
130 | * @author leo
131 | *
132 | */
133 | public interface ILOnPageSelected {
134 | /**
135 | * 页面跳转完成接口
136 | *
137 | * @param position
138 | * :当前位置标识
139 | */
140 | void onPageSelected(int position);
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/entity/LMessage.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.entity;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import android.os.Parcel;
7 | import android.os.Parcelable;
8 |
9 | /**
10 | *
11 | * @author Chen Lei
12 | * @version 1.3.1
13 | *
14 | */
15 | @SuppressWarnings("unchecked")
16 | public class LMessage implements Parcelable {
17 |
18 | private int what;
19 |
20 | private int arg1;
21 |
22 | private int arg2;
23 |
24 | private String str;
25 |
26 | private Object obj;
27 |
28 | private List> list;
29 |
30 | private Map, ?> map;
31 |
32 | public int getWhat() {
33 | return what;
34 | }
35 |
36 | public void setWhat(int what) {
37 | this.what = what;
38 | }
39 |
40 | public int getArg1() {
41 | return arg1;
42 | }
43 |
44 | public void setArg1(int arg1) {
45 | this.arg1 = arg1;
46 | }
47 |
48 | public int getArg2() {
49 | return arg2;
50 | }
51 |
52 | public void setArg2(int arg2) {
53 | this.arg2 = arg2;
54 | }
55 |
56 | public String getStr() {
57 | return str;
58 | }
59 |
60 | public void setStr(String str) {
61 | this.str = str;
62 | }
63 |
64 | public Object getObj() {
65 | return obj;
66 | }
67 |
68 | public void setObj(Object obj) {
69 | this.obj = obj;
70 | }
71 |
72 | public List getList() {
73 | return (List) list;
74 | }
75 |
76 | public void setList(List list) {
77 | this.list = list;
78 | }
79 |
80 | public Map getMap() {
81 | return (Map) map;
82 | }
83 |
84 | public void setMap(Map map) {
85 | this.map = map;
86 | }
87 |
88 | @Override
89 | public int describeContents() {
90 | return 0;
91 | }
92 |
93 | @Override
94 | public void writeToParcel(Parcel dest, int flags) {
95 | dest.writeInt(what);
96 | dest.writeInt(arg1);
97 | dest.writeInt(arg2);
98 | if (null != str) {
99 | dest.writeInt(1);
100 | dest.writeString(str);
101 | } else {
102 | dest.writeInt(-1);
103 | }
104 | if (obj != null) {
105 | try {
106 | Parcelable pObj = (Parcelable) obj;
107 | dest.writeInt(2);
108 | dest.writeParcelable(pObj, flags);
109 | } catch (ClassCastException e) {
110 | throw new RuntimeException(
111 | "Can't marshal non-Parcelable objects across processes.");
112 | }
113 | } else {
114 | dest.writeInt(-2);
115 | }
116 | if (list != null) {
117 | dest.writeInt(3);
118 | dest.writeList(list);
119 | } else {
120 | dest.writeInt(-3);
121 | }
122 | if (map != null) {
123 | dest.writeInt(4);
124 | dest.writeMap(map);
125 | } else {
126 | dest.writeInt(-4);
127 | }
128 | }
129 |
130 | public static final Parcelable.Creator CREATOR = new Creator() {
131 |
132 | @Override
133 | public LMessage createFromParcel(Parcel source) {
134 | LMessage msg = new LMessage();
135 | msg.what = source.readInt();
136 | msg.arg1 = source.readInt();
137 | msg.arg2 = source.readInt();
138 | if (source.readInt() == 1) {
139 | msg.str = source.readString();
140 | }
141 | if (source.readInt() == 2) {
142 | msg.obj = source.readParcelable(getClass().getClassLoader());
143 | }
144 | if (source.readInt() == 3) {
145 | msg.list = source.readArrayList(getClass().getClassLoader());
146 | }
147 | if (source.readInt() == 4) {
148 | msg.map = source.readHashMap(getClass().getClassLoader());
149 | }
150 | return msg;
151 | }
152 |
153 | @Override
154 | public LMessage[] newArray(int size) {
155 | return new LMessage[size];
156 | }
157 |
158 | };
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/util/L.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.util;
2 |
3 | import com.leo.base.application.LApplication;
4 |
5 | import android.content.Context;
6 | import android.util.Log;
7 |
8 |
9 | /**
10 | *
11 | * @author Chen Lei
12 | * @version 1.1.5
13 | *
14 | */
15 | public class L {
16 |
17 | private static Context mContext;
18 |
19 | /**
20 | * 禁止实例化
21 | */
22 | private L(){}
23 |
24 | private static final String TAG = LApplication.getInstance().getAppName();
25 |
26 | /**
27 | * 打印消息类传入的字符串
28 | * @param msg
29 | */
30 | public static void i(String msg) {
31 | i(TAG, msg);
32 | }
33 |
34 | /**
35 | * 打印DEBUG类传入的字符串
36 | * @param msg
37 | */
38 | public static void d(String msg) {
39 | d(TAG, msg);
40 | }
41 |
42 | /**
43 | * 打印ERROR类传入的字符串
44 | * @param msg
45 | */
46 | public static void e(String msg) {
47 | e(TAG, msg);
48 | }
49 |
50 | /**
51 | * 打印详细类传入的字符串
52 | * @param msg
53 | */
54 | public static void v(String msg) {
55 | v(TAG, msg);
56 | }
57 |
58 | /**
59 | * 打印消息类传入的字符串
60 | * @param msg
61 | */
62 | public static void i(int msg) {
63 | i(TAG, msg);
64 | }
65 |
66 | /**
67 | * 打印DEBUG类传入的字符串
68 | * @param msg
69 | */
70 | public static void d(int msg) {
71 | d(TAG, msg);
72 | }
73 |
74 | /**
75 | * 打印ERROR类传入的字符串
76 | * @param msg
77 | */
78 | public static void e(int msg) {
79 | e(TAG, msg);
80 | }
81 |
82 | /**
83 | * 打印详细类传入的字符串
84 | * @param msg
85 | */
86 | public static void v(int msg) {
87 | v(TAG, msg);
88 | }
89 |
90 | /**
91 | * 打印消息类传入的字符串
92 | * @param tag
93 | * @param msg
94 | */
95 | public static void i(String tag, int message) {
96 | String str = getContext().getResources().getString(message);
97 | i(tag, str);
98 | }
99 |
100 | /**
101 | * 打印DEBUG类传入的字符串
102 | * @param tag
103 | * @param msg
104 | */
105 | public static void d(String tag, int message) {
106 | String str = getContext().getResources().getString(message);
107 | d(tag, str);
108 | }
109 |
110 | /**
111 | * 打印ERROR类传入的字符串
112 | * @param tag
113 | * @param msg
114 | */
115 | public static void e(String tag, int message) {
116 | String str = getContext().getResources().getString(message);
117 | e(tag, str);
118 | }
119 |
120 | /**
121 | * 打印详细类传入的字符串
122 | * @param tag
123 | * @param msg
124 | */
125 | public static void v(String tag, int message) {
126 | String str = getContext().getResources().getString(message);
127 | v(tag, str);
128 | }
129 |
130 | /**
131 | * 打印消息类传入的字符串
132 | * @param tag
133 | * @param msg
134 | */
135 | public static void i(String tag, String msg) {
136 | if (LApplication.getInstance().getIsOpenDebugMode())
137 | Log.i(tag, msg);
138 | }
139 |
140 | /**
141 | * 打印DEBUG类传入的字符串
142 | * @param tag
143 | * @param msg
144 | */
145 | public static void d(String tag, String msg) {
146 | if (LApplication.getInstance().getIsOpenDebugMode())
147 | Log.d(tag, msg);
148 | }
149 |
150 | /**
151 | * 打印ERROR类传入的字符串
152 | * @param tag
153 | * @param msg
154 | */
155 | public static void e(String tag, String msg) {
156 | if (LApplication.getInstance().getIsOpenDebugMode())
157 | Log.e(tag, msg);
158 | }
159 |
160 | /**
161 | * 打印详细类传入的字符串
162 | * @param tag
163 | * @param msg
164 | */
165 | public static void v(String tag, String msg) {
166 | if (LApplication.getInstance().getIsOpenDebugMode())
167 | Log.v(tag, msg);
168 | }
169 |
170 | private static Context getContext() {
171 | if(mContext == null)
172 | mContext = LApplication.getInstance().getContext();
173 | return mContext;
174 | }
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/LBaseExample/src/com/example/lbaseexample/activity/ManyRequestActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.lbaseexample.activity;
2 |
3 | import org.json.JSONException;
4 |
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.view.View.OnClickListener;
8 | import android.widget.Button;
9 | import android.widget.TextView;
10 |
11 | import com.example.lbaseexample.R;
12 | import com.example.lbaseexample.common.MNetwork;
13 | import com.leo.base.activity.LActivity;
14 | import com.leo.base.entity.LMessage;
15 | import com.leo.base.entity.LReqEntity;
16 | import com.leo.base.exception.LLoginException;
17 | import com.leo.base.net.ILNetwork;
18 | import com.leo.base.net.ILNetworkCallback;
19 | import com.leo.base.net.ILNetwork.LReqResultState;
20 |
21 | public class ManyRequestActivity extends LActivity implements OnClickListener {
22 |
23 | private Button button;
24 |
25 | private TextView textview;
26 |
27 | private boolean isStart = true;
28 |
29 | /**
30 | * 网络请求实例
31 | */
32 | private ILNetwork requestNetwork;
33 |
34 | private StringBuilder sb;
35 |
36 | @Override
37 | protected void onLCreate(Bundle savedInstanceState) {
38 | setContentView(R.layout.activity_many_request);
39 | button = (Button) findViewById(R.id.many_request);
40 | textview = (TextView) findViewById(R.id.many_infos);
41 | button.setOnClickListener(this);
42 | }
43 |
44 | @Override
45 | public void onClick(View v) {
46 | // ... 同时启动多个线程,使用不同的线程ID,启动之后,再次点击按钮,可以停止所有线程
47 | if (isStart) {
48 | button.setText("停止线程");
49 | sendRequest(30);
50 | } else {
51 | // 停止requestNetwork对象的所有线程
52 | requestNetwork.stopAllThread();
53 | // 指定线程的停止方法
54 | // requestNetwork.stopThread(9);
55 | // requestNetwork.stopThread(18);
56 | // requestNetwork.stopThread(27);
57 | button.setText("启动所有线程");
58 | }
59 | isStart = !isStart;
60 | }
61 |
62 | /**
63 | * 同时启动多个请求, 下面的请求方法可以正常使用,但LBase不建议使用此方法直接请求,建议使用ListViewActivity中处理方式
64 | * onParse方法运行在子线程,可以解析返回结果使用 onHandlerUI运行在UI线程,将返回的封装实体在此处更新UI
65 | * onException运行在UI线程,返回多种异常状态,可以相对不同的异常进行处理
66 | *
67 | * @param requestCount
68 | */
69 | private void sendRequest(int requestCount) {
70 | LReqEntity requestEntity = new LReqEntity();
71 | requestEntity.setUrl("http://www.baidu.com");
72 | if (requestNetwork == null) {
73 | requestNetwork = new MNetwork();
74 | }
75 | sb = new StringBuilder();
76 | for (int i = 0; i < requestCount; i++) {
77 | requestNetwork.request(requestEntity, i, new ILNetworkCallback() {
78 |
79 | @Override
80 | public LMessage onParse(String strs, int requestId)
81 | throws LLoginException, JSONException, Exception {
82 | // ... 运行在子线程
83 | LMessage msg = new LMessage();
84 | msg.setStr(strs);
85 | return msg;
86 | }
87 |
88 | @Override
89 | public void onHandlerUI(LMessage msg, int requestId) {
90 | // ... 运行在UI线程
91 | sb.append("请求requestId为:").append(requestId)
92 | .append("的请求,成功!\n");
93 | textview.setText(sb.toString());
94 | }
95 |
96 | @Override
97 | public void onException(LReqResultState state, int requestId) {
98 | // ... 运行在UI线程
99 | if (state == LReqResultState.STOP) {
100 | sb.append("请求requestId为:").append(requestId)
101 | .append("的请求,被停止!\n");
102 | } else {
103 | sb.append("请求requestId为:").append(requestId)
104 | .append("的请求,发现异常!\n");
105 | }
106 | textview.setText(sb.toString());
107 | }
108 |
109 | @Override
110 | public void onProgress(int count, int current, int requestId) {
111 | // ... 上传文件时,在此处可以回调进度
112 | }
113 | });
114 | }
115 | }
116 |
117 | @Override
118 | protected void onDestroy() {
119 | super.onDestroy();
120 | if (requestNetwork != null) {
121 | requestNetwork.stopAllThread();
122 | }
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/util/LSharePreference.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.util;
2 |
3 | import com.leo.base.application.LApplication;
4 |
5 | import android.content.Context;
6 | import android.content.SharedPreferences;
7 |
8 | /**
9 | *
10 | * @author Chen Lei
11 | * @version 1.1.5
12 | *
13 | */
14 | public class LSharePreference {
15 | private static String SP_NAME = LApplication.getInstance().getAppName();
16 |
17 | private SharedPreferences sp;
18 | private SharedPreferences.Editor editor;
19 |
20 | private static LSharePreference instance;
21 |
22 | public static synchronized LSharePreference getInstance(Context context) {
23 | if (instance == null) {
24 | instance = new LSharePreference(context);
25 | }
26 | return instance;
27 | }
28 |
29 | /**
30 | * 构造函数
31 | *
32 | * @param context
33 | */
34 | private LSharePreference(Context context) {
35 | init(context);
36 | }
37 |
38 | /**
39 | * 初使化
40 | */
41 | private void init(Context context) {
42 | if (context != null) {
43 | sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
44 | editor = sp.edit();
45 | }
46 | }
47 |
48 | /**
49 | * 添加String
50 | *
51 | * @param key
52 | * @param value
53 | */
54 | public void setString(String key, String value) {
55 | editor.putString(key, value);
56 | editor.commit();
57 | }
58 |
59 | /**
60 | * 获取String
61 | *
62 | * @param key
63 | * @return
64 | */
65 | public String getString(String key) {
66 | return getString(key, null);
67 | }
68 |
69 | /**
70 | * 获取String
71 | *
72 | * @param key
73 | * @param defValue
74 | * @return
75 | */
76 | public String getString(String key, String defValue) {
77 | return sp.getString(key, defValue);
78 | }
79 |
80 | /**
81 | * 添加Int
82 | *
83 | * @param key
84 | * @param value
85 | */
86 | public void setInt(String key, int value) {
87 | editor.putInt(key, value);
88 | editor.commit();
89 | }
90 |
91 | /**
92 | * 获取Int
93 | *
94 | * @param key
95 | * @return
96 | */
97 | public int getInt(String key) {
98 | return getInt(key, 0);
99 | }
100 |
101 | /**
102 | * 获取Int
103 | *
104 | * @param key
105 | * @param defValue
106 | * @return
107 | */
108 | public int getInt(String key, int defValue) {
109 | return sp.getInt(key, defValue);
110 | }
111 |
112 | /**
113 | * 添加float
114 | *
115 | * @param key
116 | * @param value
117 | */
118 | public void setFloat(String key, float value) {
119 | editor.putFloat(key, value);
120 | editor.commit();
121 | }
122 |
123 | /**
124 | * 获取float
125 | *
126 | * @param key
127 | * @return
128 | */
129 | public float getFloat(String key) {
130 | return getFloat(key, 0.0f);
131 | }
132 |
133 | /**
134 | * 获取float
135 | *
136 | * @param key
137 | * @param defValue
138 | * @return
139 | */
140 | public float getFloat(String key, float defValue) {
141 | return sp.getFloat(key, defValue);
142 | }
143 |
144 | /**
145 | * 添加boolean
146 | *
147 | * @param key
148 | * @param value
149 | */
150 | public void setBoolean(String key, boolean value) {
151 | editor.putBoolean(key, value);
152 | editor.commit();
153 | }
154 |
155 | /**
156 | * 获取boolean
157 | *
158 | * @param key
159 | * @return
160 | */
161 | public boolean getBoolean(String key) {
162 | return getBoolean(key, false);
163 | }
164 |
165 | /**
166 | * 获取boolean
167 | *
168 | * @param key
169 | * @param defValue
170 | * @return
171 | */
172 | public boolean getBoolean(String key, boolean defValue) {
173 | return sp.getBoolean(key, defValue);
174 | }
175 |
176 | /**
177 | * 删除
178 | *
179 | * @param key
180 | */
181 | public void delContent(String key) {
182 | editor.remove(key);
183 | editor.commit();
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/widget/LWebView.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.widget;
2 |
3 | import java.util.Map;
4 |
5 | import android.annotation.SuppressLint;
6 | import android.content.Context;
7 | import android.os.AsyncTask;
8 | import android.os.Build;
9 | import android.os.SystemClock;
10 | import android.util.AttributeSet;
11 | import android.webkit.CookieManager;
12 | import android.webkit.CookieSyncManager;
13 | import android.webkit.WebView;
14 | import android.webkit.WebViewClient;
15 |
16 | import com.leo.base.application.LApplication;
17 | import com.leo.base.widget.webview.LWebViewClient;
18 |
19 | /**
20 | *
21 | * LWebView 简单集成了Session控制
22 | * 如果需要使用{@linkplain android.webkit.WebView#setWebViewClient(WebViewClient)
23 | * setWebViewClient(WebViewClient)} 方法 ,请在实现
24 | * {@linkplain com.leo.base.widget.webview.LWebViewClient LWebViewClient}
25 | * 框架会在页面加载完成之后,自动填充session
26 | *
27 | * @author Chen Lei
28 | * @version 1.4.1
29 | *
30 | */
31 | public class LWebView extends WebView {
32 |
33 | /**
34 | * 上下文对象
35 | */
36 | private Context mContext;
37 |
38 | /**
39 | * 请求路径
40 | */
41 | private String mUrl;
42 |
43 | /**
44 | * 额外的标头
45 | */
46 | private Map mExtraHeaders;
47 |
48 | /**
49 | * WebViewClient子类
50 | */
51 | private LWebViewClient mWebViewClient;
52 |
53 | public LWebView(Context context) {
54 | super(context);
55 | init(context);
56 | }
57 |
58 | public LWebView(Context context, AttributeSet attrs) {
59 | super(context, attrs);
60 | init(context);
61 | }
62 |
63 | public LWebView(Context context, AttributeSet attrs, int defStyle) {
64 | super(context, attrs, defStyle);
65 | init(context);
66 | }
67 |
68 | private void init(Context context) {
69 | this.mContext = context;
70 | this.setWebViewClient(getWebViewClient());
71 | }
72 |
73 | @Override
74 | public void loadUrl(String url) {
75 | mUrl = url;
76 | mExtraHeaders = null;
77 | initCookie();
78 | new RequestAsyncTask().execute();
79 | }
80 |
81 | /**
82 | * 开始加载
83 | */
84 | public void loadUrl(String url, Map extraHeaders) {
85 | mUrl = url;
86 | mExtraHeaders = extraHeaders;
87 | initCookie();
88 | new RequestAsyncTask().execute();
89 |
90 | }
91 |
92 | @Override
93 | public void setWebViewClient(WebViewClient client) {
94 | mWebViewClient = (LWebViewClient) client;
95 | super.setWebViewClient(mWebViewClient);
96 | }
97 |
98 | /**
99 | * 初始化CookieManager
100 | */
101 | private void initCookie() {
102 | CookieSyncManager.createInstance(mContext);
103 | CookieManager.getInstance().setAcceptCookie(true);
104 | CookieManager.getInstance().removeSessionCookie();
105 | }
106 |
107 | /**
108 | * 同步CookieManager
109 | */
110 | private void syncCookie() {
111 | LApplication.getInstance().setSessionValue("123456789");
112 | CookieManager.getInstance().setCookie(
113 | mUrl,
114 | LApplication.getInstance().getSessionKey() + "="
115 | + LApplication.getInstance().getSessionValue());
116 | CookieSyncManager.getInstance().sync();
117 | }
118 |
119 | /**
120 | * 加载
121 | */
122 | @SuppressLint("NewApi")
123 | private void myLoadUrl() {
124 | if (Build.VERSION.SDK_INT >= 8) {
125 | super.loadUrl(mUrl, mExtraHeaders);
126 | } else {
127 | super.loadUrl(mUrl);
128 | }
129 | }
130 |
131 | private class RequestAsyncTask extends AsyncTask {
132 |
133 | @Override
134 | protected Void doInBackground(Void... params) {
135 | SystemClock.sleep(20);
136 | return null;
137 | }
138 |
139 | @Override
140 | protected void onPostExecute(Void result) {
141 | super.onPostExecute(result);
142 | syncCookie();
143 | myLoadUrl();
144 | }
145 | }
146 |
147 | private WebViewClient getWebViewClient() {
148 | if (mWebViewClient == null) {
149 | mWebViewClient = new LWebViewClient();
150 | }
151 | return mWebViewClient;
152 | }
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/util/LFormat.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.util;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | *
8 | * @author Chen Lei
9 | * @version 1.4.1
10 | *
11 | */
12 | public class LFormat {
13 |
14 | /**
15 | * 禁止实例化
16 | */
17 | private LFormat() {
18 | }
19 |
20 | /**
21 | * 判断字符串是否为空(包含null、""、NULL、" "等内容)
22 | *
23 | * @param str
24 | * @return true为空 false不为空
25 | */
26 | public static boolean isEmpty(String str) {
27 | if (null == str || "".equals(str) || "null".equalsIgnoreCase(str)
28 | || "".equals(str.trim()))
29 | return true;
30 | return false;
31 | }
32 |
33 | /**
34 | * 比较两个字符串是否相同
35 | *
36 | * @param str1
37 | * 第一个字符串
38 | * @param str2
39 | * 第二个字符串
40 | * @return true为相同,false为不同
41 | */
42 | public static boolean isEqual(String str1, String str2) {
43 | if (isEmpty(str1))
44 | return false;
45 | if (isEmpty(str2))
46 | return false;
47 | if (str1.equals(str2))
48 | return true;
49 | return false;
50 | }
51 |
52 | /**
53 | * 清理JSON无用字符
54 | *
55 | * @param json
56 | * json
57 | * @return
58 | */
59 | public static String JSONTokener(String json) {
60 | if (isEmpty(json))
61 | return null;
62 | String res = json.replaceAll("\n", "");
63 | if (res.startsWith("\ufeff")) {
64 | res = res.substring(1);
65 | }
66 | return res;
67 | }
68 |
69 | /**
70 | * 传入两个字符串比较,相同为true
71 | *
72 | * @param str1
73 | * @param str2
74 | * @return
75 | */
76 | public static boolean isSame(String str1, String str2) {
77 | if (isEmpty(str1))
78 | return false;
79 | if (isEmpty(str2))
80 | return false;
81 | if (str1.equals(str2))
82 | return true;
83 | return false;
84 | }
85 |
86 | /**
87 | * 判断是否为正确的邮件格式
88 | *
89 | * @param str
90 | * @return boolean
91 | */
92 | public static boolean isEmail(String str) {
93 | if (isEmpty(str))
94 | return false;
95 | return str.matches("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
96 | }
97 |
98 | /**
99 | * 判断字符串长度是否在此范围
100 | *
101 | * @param str
102 | * :需要比较的字符串
103 | * @param min
104 | * :最小值
105 | * @param max
106 | * :最大值
107 | * @return
108 | */
109 | public static boolean isLength(String str, int min, int max) {
110 | if (isEmpty(str))
111 | return false;
112 | if (str.length() >= min && str.length() <= max) {
113 | return true;
114 | }
115 | return false;
116 | }
117 |
118 | /**
119 | * 判断字符串是否为合法手机号 11位 13 14 15 18开头
120 | *
121 | * @param str
122 | * @return boolean
123 | */
124 | public static boolean isMobile(String str) {
125 | if (isEmpty(str))
126 | return false;
127 | return str.matches("^(13|14|15|18)\\d{9}$");
128 | }
129 |
130 | /**
131 | * 判断是否为数字
132 | *
133 | * @param str
134 | * @return
135 | */
136 | public static boolean isNumber(String str) {
137 | if (isEmpty(str))
138 | return false;
139 | try {
140 | Integer.parseInt(str);
141 | return true;
142 | } catch (Exception e) {
143 | return false;
144 | }
145 | }
146 |
147 | /**
148 | * 判断是否为浮点数或者整数
149 | *
150 | * @param str
151 | * @return true Or false
152 | */
153 | public static boolean isNumeric(String str) {
154 | if (isEmpty(str))
155 | return false;
156 | Pattern pattern = Pattern.compile("^(-?\\d+)(\\.\\d+)?$");
157 | Matcher isNum = pattern.matcher(str);
158 | if (!isNum.matches()) {
159 | return false;
160 | }
161 | return true;
162 | }
163 |
164 | /**
165 | * 将url转成MD5
166 | *
167 | * @param url
168 | * @return
169 | */
170 | public static String getMD5Url(String url) {
171 | return MD5.getMD5(url) + url.substring(url.lastIndexOf('.'));
172 | }
173 |
174 | /**
175 | * 传入两个数字,计算比例
176 | * @param arg1
177 | * @param arg2
178 | * @return
179 | */
180 | public static double getScale(double arg1, double arg2) {
181 | if (arg2 == 0) {
182 | throw new ArithmeticException("by arg2 is zero");
183 | }
184 | return arg1 / arg2;
185 | }
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/activity/LActivity.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.activity;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v4.app.FragmentActivity;
6 |
7 | import com.leo.base.application.LApplication;
8 | import com.leo.base.dialog.LProgress;
9 | import com.leo.base.dialog.LProgress.OnKeyBackListener;
10 | import com.leo.base.entity.LMessage;
11 | import com.leo.base.handler.ILHandlerCallback;
12 |
13 | /**
14 | * 来源:
LActivity 继承自 {@link android.support.v4.app.FragmentActivity}
15 | *
16 | * 用途:
所有 Activity 需继承此类
17 | *
18 | * 说明:
19 | * 继承 LActivity 类后,需要实现
20 | * {@linkplain com.leo.base.activity.LActivity#onLCreate(Bundle)
21 | * onLCreate(Bundle)} 方法,onLCreate 方法与
22 | * {@linkplain android.app.Activity#onCreate(Bundle savedInstanceState)
23 | * onCreate} 方法使用相同, 抽象出此方法是为了方便使用者继承之后,不需要再手动 Override
24 | * 当你使用了
25 | * {@linkplain com.leo.base.handler.LHandler#startLoadingData(com.leo.base.entity.LReqEntity)
26 | * LHandler.startLoadingData(LReqEntity)} 方法请求网络后,
27 | * {@linkplain com.leo.base.handler.LHandler LHandler} 会自动调用此类的
28 | * {@linkplain com.leo.base.activity.LActivity#resultHandler(com.leo.base.entity.LMessage)
29 | * LActivity.resultHandler(LMessage)} 方法,并将解析的结果
30 | * {@linkplain com.leo.base.entity.LMessage LMessage} 对象传回
31 | *
32 | * @author Chen Lei
33 | * @version 1.3.1
34 | *
35 | */
36 | public abstract class LActivity extends FragmentActivity implements
37 | ILHandlerCallback, OnKeyBackListener {
38 |
39 | /**
40 | * 全局的上下文对象
41 | */
42 | public Context mContext;
43 |
44 | /**
45 | * 全局的 {@linkplain com.leo.base.application.LApplication LApplication} 对象
46 | */
47 | public LApplication mLApplication;
48 |
49 | /**
50 | * 进度提示框
51 | */
52 | private LProgress mProgressDialog;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | // requestWindowFeature(Window.FEATURE_NO_TITLE);
58 | mContext = this;
59 | mLApplication = LApplication.getInstance();
60 | mLApplication.setContext(mContext);
61 | mLApplication.setDestroyActivitys(false);
62 | mLApplication.addActivity(this);
63 | mLApplication.setFragmentManager(this.getSupportFragmentManager());
64 | onLCreate(savedInstanceState);
65 | }
66 |
67 | @Override
68 | protected void onResume() {
69 | super.onResume();
70 | }
71 |
72 | @Override
73 | protected void onPause() {
74 | super.onPause();
75 | dismissProgressDialog();
76 | mProgressDialog = null;
77 | }
78 |
79 | @Override
80 | protected void onDestroy() {
81 | mLApplication.delActivity(this);
82 | super.onDestroy();
83 | }
84 |
85 | /**
86 | * 显示一个ProgressDialog,直接调用即可
87 | * 此ProgressDialog会在onPause方法内自动销毁
88 | *
89 | * @param text
90 | * 提示文字
91 | */
92 | protected void showProgressDialog(String text) {
93 | if (mProgressDialog == null) {
94 | mProgressDialog = new LProgress(this);
95 | mProgressDialog.setOnKeyBackListener(this);
96 | }
97 | mProgressDialog.show(text);
98 | }
99 |
100 | /**
101 | * 销毁一个ProgressDialog
102 | */
103 | protected void dismissProgressDialog() {
104 | if (mProgressDialog != null && mProgressDialog.isShowing()) {
105 | mProgressDialog.dismiss();
106 | }
107 | }
108 |
109 | @Override
110 | public void onKeyBackListener() {
111 | // ... 如果ProgressDialog正在运行,使用者按下BACK键,销毁ProgressDialog的同时,还会调用此接口。
112 | // ... 使用者可以在这里finish(),也可以在这里停止线程
113 | }
114 |
115 | /**
116 | * 继承LActivity类后,需要实现
117 | * {@linkplain com.leo.base.activity.LActivity#onLCreate(Bundle)
118 | * onLCreate(Bundle)} 方法,onLCreate 方法与
119 | * {@linkplain android.app.Activity#onCreate(Bundle savedInstanceState)
120 | * onCreate} 方法使用相同, 抽象出此方法是为了方便使用者继承之后,不需要再手动 Override
121 | *
122 | * @param savedInstanceState
123 | */
124 | protected abstract void onLCreate(Bundle savedInstanceState);
125 |
126 | /**
127 | * 当你使用了
128 | * {@linkplain com.leo.base.handler.LHandler#startLoadingData(com.leo.base.net.LReqEntity)
129 | * LHandler.startLoadingData(LReqEntity)} 方法请求网络后,
130 | * {@linkplain com.leo.base.handler.LHandler LHandler} 会自动调用此方法,并将解析的结果
131 | * {@linkplain com.leo.base.entity.LMessage LMessage} 对象传回
132 | *
133 | * @param msg
134 | */
135 | @Override
136 | public void onResultHandler(LMessage msg, int requestId) {
137 | // ... 写入你需要的代码
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/dialog/LProgress.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.dialog;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.GradientDrawable;
8 | import android.text.TextUtils.TruncateAt;
9 | import android.util.TypedValue;
10 | import android.view.Gravity;
11 | import android.view.KeyEvent;
12 | import android.view.ViewGroup;
13 | import android.view.Window;
14 | import android.widget.LinearLayout;
15 | import android.widget.ProgressBar;
16 | import android.widget.TextView;
17 |
18 | import com.leo.base.application.LApplication;
19 | import com.leo.base.util.LBitmap;
20 |
21 | public class LProgress extends Dialog implements DialogInterface.OnKeyListener {
22 |
23 | private static final int BACKGROUND_ALPHA = 230;
24 | private static final int BACKGROUND_COLOR = Color.rgb(255, 255, 255);
25 | private static final int TEXT_COLOR = Color.rgb(128, 128, 128);
26 |
27 | private Context mContext;
28 |
29 | private DialogView mDialogView;
30 |
31 | private static int width, height, padding10;
32 |
33 | private boolean mFlag = false;
34 |
35 | private OnKeyBackListener mOnKeyBackListener;
36 |
37 | public LProgress(Context context) {
38 | super(context);
39 | mContext = context;
40 | width = LApplication.getInstance().getDiaplayWidth() / 5 * 2;
41 | height = width;
42 | padding10 = LBitmap.dip2px(mContext, 10);
43 | requestWindowFeature(Window.FEATURE_NO_TITLE);
44 | mDialogView = new DialogView(mContext);
45 | getWindow().addContentView(mDialogView,
46 | new ViewGroup.LayoutParams(width, height));
47 | getWindow().getDecorView().setBackgroundDrawable(
48 | getViewGradientDrawable(padding10));
49 | getWindow().getDecorView().getBackground().setAlpha(BACKGROUND_ALPHA);
50 | setCancelable(mFlag);
51 | setOnKeyListener(this);
52 | }
53 |
54 | public void show(String text) {
55 | if (!isShowing()) {
56 | this.show();
57 | }
58 | mDialogView.setText(text);
59 | }
60 |
61 | public void setOnKeyBackListener(OnKeyBackListener keyBackListener) {
62 | this.mOnKeyBackListener = keyBackListener;
63 | }
64 |
65 | @Override
66 | public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
67 | if (keyCode == KeyEvent.KEYCODE_BACK) {
68 | dialog.dismiss();
69 | if (mOnKeyBackListener != null) {
70 | mOnKeyBackListener.onKeyBackListener();
71 | }
72 | return true;
73 | }
74 | return false;
75 | }
76 |
77 | class DialogView extends LinearLayout {
78 |
79 | private static final int INDEX0 = 0, INDEX1 = 1;
80 |
81 | private ProgressBar mProgressBar;
82 |
83 | private TextView mTextView;
84 |
85 | public DialogView(Context context) {
86 | super(context);
87 | initView();
88 | initProgressBar();
89 | initTextView();
90 | }
91 |
92 | private void initView() {
93 | this.setLayoutParams(new ViewGroup.LayoutParams(
94 | ViewGroup.LayoutParams.WRAP_CONTENT,
95 | ViewGroup.LayoutParams.WRAP_CONTENT));
96 | this.setPadding(padding10, padding10, padding10, padding10);
97 | this.setGravity(Gravity.CENTER);
98 | this.setOrientation(LinearLayout.VERTICAL);
99 | }
100 |
101 | private void initProgressBar() {
102 | if (mProgressBar == null) {
103 | mProgressBar = new ProgressBar(mContext);
104 | }
105 | if (this.getChildAt(INDEX0) == null) {
106 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
107 | LinearLayout.LayoutParams.WRAP_CONTENT,
108 | LinearLayout.LayoutParams.WRAP_CONTENT);
109 | params.gravity = Gravity.CENTER;
110 | this.addView(mProgressBar, INDEX0, params);
111 | }
112 | }
113 |
114 | private void initTextView() {
115 | if (mTextView == null) {
116 | mTextView = new TextView(mContext);
117 | }
118 | if (this.getChildAt(INDEX1) == null) {
119 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
120 | LinearLayout.LayoutParams.FILL_PARENT,
121 | LinearLayout.LayoutParams.WRAP_CONTENT);
122 | params.setMargins(0, LBitmap.dip2px(mContext, 10), 0, 0);
123 | mTextView.setGravity(Gravity.CENTER);
124 | mTextView.setTextColor(TEXT_COLOR);
125 | mTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
126 | mTextView.setSingleLine(true);
127 | mTextView.setEllipsize(TruncateAt.END);
128 | this.addView(mTextView, INDEX1, params);
129 | }
130 | }
131 |
132 | public void setText(String text) {
133 | if (mTextView == null) {
134 | initTextView();
135 | }
136 | mTextView.setText(text);
137 | }
138 |
139 | }
140 |
141 | private static GradientDrawable mGradientDrawable;
142 |
143 | private static GradientDrawable getViewGradientDrawable(int radius) {
144 | if (mGradientDrawable == null) {
145 | mGradientDrawable = new GradientDrawable();
146 | mGradientDrawable.setCornerRadius(radius);
147 | mGradientDrawable.setColor(BACKGROUND_COLOR);
148 | }
149 | return mGradientDrawable;
150 | }
151 |
152 | public interface OnKeyBackListener {
153 | void onKeyBackListener();
154 | }
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/LBaseExample/gen/com/example/lbaseexample/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.lbaseexample;
9 |
10 | public final class R {
11 | public static final class array {
12 | /** 创建数据库表集合
13 | */
14 | public static final int create_tables=0x7f040000;
15 | /** 删除数据库表集合
16 | */
17 | public static final int drop_tables=0x7f040001;
18 | }
19 | public static final class attr {
20 | }
21 | public static final class dimen {
22 | /** Default screen margins, per the Android Design guidelines.
23 |
24 | Customize dimensions originally defined in res/values/dimens.xml (such as
25 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
26 |
27 | */
28 | public static final int activity_horizontal_margin=0x7f050000;
29 | public static final int activity_vertical_margin=0x7f050001;
30 | }
31 | public static final class drawable {
32 | public static final int ic_launcher=0x7f020000;
33 | }
34 | public static final class id {
35 | public static final int about_textview=0x7f090000;
36 | public static final int action_about_me=0x7f090013;
37 | public static final int action_clear_all_data=0x7f090012;
38 | public static final int download_button=0x7f090002;
39 | public static final int download_imageview=0x7f090003;
40 | public static final int download_progress=0x7f090001;
41 | public static final int item_imageview=0x7f090010;
42 | public static final int item_textview=0x7f090011;
43 | public static final int jsonstring=0x7f09000f;
44 | public static final int listview=0x7f090005;
45 | public static final int main_download=0x7f09000a;
46 | public static final int main_fragment_viewpager=0x7f090008;
47 | public static final int main_infos=0x7f090006;
48 | public static final int main_listview=0x7f090007;
49 | public static final int main_many_request=0x7f090009;
50 | public static final int main_webview=0x7f09000b;
51 | public static final int many_infos=0x7f09000d;
52 | public static final int many_request=0x7f09000c;
53 | public static final int viewpager=0x7f090004;
54 | public static final int webview_webview=0x7f09000e;
55 | }
56 | public static final class layout {
57 | public static final int activity_about=0x7f030000;
58 | public static final int activity_download=0x7f030001;
59 | public static final int activity_fragment_viewpager=0x7f030002;
60 | public static final int activity_listview=0x7f030003;
61 | public static final int activity_main=0x7f030004;
62 | public static final int activity_many_request=0x7f030005;
63 | public static final int activity_webview=0x7f030006;
64 | public static final int fragment_view1=0x7f030007;
65 | public static final int item_listview=0x7f030008;
66 | public static final int view_pager_title=0x7f030009;
67 | }
68 | public static final class menu {
69 | public static final int main=0x7f080000;
70 | }
71 | public static final class string {
72 | public static final int action_settings=0x7f060007;
73 | public static final int app_about=0x7f060003;
74 | public static final int app_download=0x7f060005;
75 | public static final int app_fragmentviewpager=0x7f060006;
76 | public static final int app_listview=0x7f060002;
77 | public static final int app_many_request=0x7f060004;
78 | public static final int app_name=0x7f060000;
79 | public static final int app_service_url=0x7f060001;
80 | public static final int app_webview=0x7f060008;
81 | }
82 | public static final class style {
83 | /**
84 | Base application theme, dependent on API level. This theme is replaced
85 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
86 |
87 |
88 | Theme customizations available in newer API levels can go in
89 | res/values-vXX/styles.xml, while customizations related to
90 | backward-compatibility can go here.
91 |
92 |
93 | Base application theme for API 11+. This theme completely replaces
94 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
95 |
96 | API 11 theme customizations can go here.
97 |
98 | Base application theme for API 14+. This theme completely replaces
99 | AppBaseTheme from BOTH res/values/styles.xml and
100 | res/values-v11/styles.xml on API 14+ devices.
101 |
102 | API 14 theme customizations can go here.
103 | */
104 | public static final int AppBaseTheme=0x7f070000;
105 | /** Application theme.
106 | All customizations that are NOT specific to a particular API-level can go here.
107 | */
108 | public static final int AppTheme=0x7f070001;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/entity/LReqEntity.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.entity;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | /**
7 | *
8 | * @author Chen Lei
9 | * @version 1.3.1
10 | *
11 | */
12 | public class LReqEntity implements Cloneable {
13 |
14 | /**
15 | * 网络请求地址
16 | */
17 | private String mUrl;
18 |
19 | /**
20 | * 网络请求参数
21 | */
22 | private Map mParams;
23 |
24 | /**
25 | * 需要上传的文件集合
26 | */
27 | private List mFileParams;
28 |
29 | /**
30 | * 网络请求模式
31 | */
32 | private LReqMothed mReqMode;
33 |
34 | /**
35 | * 网络请求编码方式
36 | */
37 | private LReqEncode mReqEncode;
38 |
39 | /**
40 | * 网络请求是否启用缓存
41 | */
42 | private boolean mUseCache;
43 |
44 | public String getUrl() {
45 | return mUrl;
46 | }
47 |
48 | public void setUrl(String mUrl) {
49 | this.mUrl = mUrl;
50 | }
51 |
52 | public Map getParams() {
53 | return mParams;
54 | }
55 |
56 | public void setParams(Map params) {
57 | this.mParams = params;
58 | }
59 |
60 | public LReqMothed getReqMode() {
61 | return mReqMode;
62 | }
63 |
64 | public void setReqMode(LReqMothed mReqMode) {
65 | this.mReqMode = mReqMode;
66 | }
67 |
68 | public LReqEncode getReqEncode() {
69 | return mReqEncode;
70 | }
71 |
72 | public void setReqEncode(LReqEncode mReqEncode) {
73 | this.mReqEncode = mReqEncode;
74 | }
75 |
76 | public boolean getUseCache() {
77 | return mUseCache;
78 | }
79 |
80 | public void setUseCache(boolean mUseCache) {
81 | this.mUseCache = mUseCache;
82 | }
83 |
84 | public List getFileParams() {
85 | return mFileParams;
86 | }
87 |
88 | public void setFileParamsList(List list) {
89 | this.mFileParams = list;
90 | }
91 |
92 | public LReqEntity() {
93 | init(null, null, null, LReqMothed.GET, LReqEncode.UTF8, false);
94 | }
95 |
96 | /**
97 | * 网络请求封装实体
98 | * 无参,以GET方式请求,UTF-8编码,不启用缓存
99 | *
100 | * @param url
101 | * :地址
102 | */
103 | public LReqEntity(String url) {
104 | init(url, null, null, LReqMothed.GET, LReqEncode.UTF8, false);
105 | }
106 |
107 | /**
108 | * 网络请求封装实体
109 | * 以POST方式请求,UTF-8编码,不启用缓存
110 | *
111 | * @param url
112 | * :地址
113 | * @param params
114 | * :参数
115 | */
116 | public LReqEntity(String url, Map params) {
117 | init(url, params, null, LReqMothed.POST, LReqEncode.UTF8, false);
118 | }
119 |
120 | /**
121 | * 网络请求封装实体
122 | * UTF-8编码,不启用缓存
123 | *
124 | * @param url
125 | * :地址
126 | * @param params
127 | * :参数
128 | * @param mode
129 | * :请求模式
130 | */
131 | public LReqEntity(String url, Map params, LReqMothed mode) {
132 | init(url, params, null, mode, LReqEncode.UTF8, false);
133 | }
134 |
135 | /**
136 | * 网络请求封装实体
137 | * 不启用缓存
138 | *
139 | * @param url
140 | * :地址
141 | * @param params
142 | * :参数
143 | * @param mode
144 | * :请求模式
145 | * @param encoding
146 | * :请求编码
147 | */
148 | public LReqEntity(String url, Map params, LReqMothed mode,
149 | LReqEncode encoding) {
150 | init(url, params, null, mode, encoding, false);
151 | }
152 |
153 | /**
154 | * 网络请求封装实体
155 | *
156 | * @param url
157 | * :地址
158 | * @param params
159 | * :参数
160 | * @param list
161 | * :文件集合
162 | * @param mode
163 | * :请求模式
164 | * @param encoding
165 | * :请求编码
166 | * @param useCache
167 | * :启用缓存
168 | */
169 | public LReqEntity(String url, Map params, LReqMothed mode,
170 | LReqEncode encoding, boolean useCache) {
171 | init(url, params, null, mode, encoding, useCache);
172 | }
173 |
174 | /**
175 | * 网络请求封装实体
176 | *
177 | * @param url
178 | * :地址
179 | * @param params
180 | * :参数
181 | * @param list
182 | * :文件集合
183 | * @param encoding
184 | * :编码
185 | */
186 | public LReqEntity(String url, Map params,
187 | List list, LReqEncode encoding) {
188 | init(url, params, list, LReqMothed.POST, encoding, false);
189 | }
190 |
191 | private void init(String url, Map params,
192 | List list, LReqMothed mode, LReqEncode encoding,
193 | boolean useCache) {
194 | this.mUrl = url;
195 | this.mParams = params;
196 | this.mFileParams = list;
197 | this.mReqMode = mode;
198 | this.mReqEncode = encoding;
199 | this.mUseCache = useCache;
200 | }
201 |
202 | @Override
203 | public String toString() {
204 | StringBuilder sb = new StringBuilder();
205 | sb.append("地址:").append(this.mUrl);
206 | sb.append("<--->");
207 | sb.append("参数:").append(this.mParams);
208 | sb.append("<--->");
209 | sb.append("文件:").append(this.mFileParams);
210 | sb.append("<--->");
211 | sb.append("模式:").append(this.mReqMode.getMothed());
212 | sb.append("<--->");
213 | sb.append("编码:").append(this.mReqEncode.getEncode());
214 | sb.append("<--->");
215 | sb.append("缓存:").append(this.mUseCache ? "不启用" : "启用");
216 | return sb.toString();
217 | }
218 |
219 | }
220 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/widget/T.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.drawable.GradientDrawable;
6 | import android.util.TypedValue;
7 | import android.view.Gravity;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.leo.base.application.LApplication;
14 | import com.leo.base.util.LBitmap;
15 |
16 | /**
17 | *
18 | * @author Chen Lei
19 | * @version 1.1.5
20 | *
21 | */
22 | public class T {
23 |
24 | private static Context mContext;
25 |
26 | /**
27 | * 禁止实例化
28 | */
29 | private T() {
30 | }
31 |
32 | /**
33 | * 显示短Toast
34 | *
35 | * @param text
36 | */
37 | public static void ss(int text) {
38 | s(text, Toast.LENGTH_SHORT);
39 | }
40 |
41 | /**
42 | * 显示短Toast
43 | *
44 | * @param text
45 | */
46 | public static void ss(CharSequence text) {
47 | s(text, Toast.LENGTH_SHORT);
48 | }
49 |
50 | /**
51 | * 显示短Toast
52 | *
53 | * @param context
54 | * @param text
55 | */
56 | public static void ss(Context context, int text) {
57 | s(context, text, Toast.LENGTH_SHORT);
58 | }
59 |
60 | /**
61 | * 显示短Toast
62 | *
63 | * @param context
64 | * @param text
65 | */
66 | public static void ss(Context context, CharSequence text) {
67 | s(context, text, Toast.LENGTH_SHORT);
68 | }
69 |
70 | /**
71 | * 显示长Toast
72 | *
73 | * @param text
74 | */
75 | public static void sl(int text) {
76 | s(text, Toast.LENGTH_LONG);
77 | }
78 |
79 | /**
80 | * 显示长Toast
81 | *
82 | * @param text
83 | */
84 | public static void sl(CharSequence text) {
85 | s(text, Toast.LENGTH_LONG);
86 | }
87 |
88 | /**
89 | * 显示长Toast
90 | *
91 | * @param context
92 | * @param text
93 | */
94 | public static void sl(Context context, int text) {
95 | s(context, text, Toast.LENGTH_LONG);
96 | }
97 |
98 | /**
99 | * 显示长Toast
100 | *
101 | * @param context
102 | * @param text
103 | */
104 | public static void sl(Context context, CharSequence text) {
105 | s(context, text, Toast.LENGTH_LONG);
106 | }
107 |
108 | /**
109 | * 显示自定义时长Toast
110 | *
111 | * @param text
112 | * @param duration
113 | */
114 | public static void s(int text, int duration) {
115 | s(getContext(), text, duration);
116 | }
117 |
118 | /**
119 | * 显示自定义时长Toast
120 | *
121 | * @param text
122 | * @param duration
123 | */
124 | public static void s(CharSequence text, int duration) {
125 | s(getContext(), text, duration);
126 | }
127 |
128 | /**
129 | * 显示自定义时长Toast
130 | *
131 | * @param context
132 | * @param text
133 | * @param duration
134 | */
135 | public static void s(Context context, int text, int duration) {
136 | s(context, getText(text), duration);
137 | }
138 |
139 | /**
140 | * 显示自定义时长Toast
141 | *
142 | * @param context
143 | * @param text
144 | * @param duration
145 | */
146 | public static void s(Context context, CharSequence text, int duration) {
147 | mContext = context;
148 | makeToast(context, text, duration).show();
149 | }
150 |
151 | private static Context getContext() {
152 | if (mContext == null)
153 | mContext = LApplication.getInstance().getContext();
154 | return mContext;
155 | }
156 |
157 | private static String getText(int text) {
158 | return getContext().getResources().getString(text);
159 | }
160 |
161 | public static Toast makeToast(Context context, CharSequence text,
162 | int duration) {
163 | View mToastView = getToastView(context, text);
164 | Toast result = new Toast(context);
165 | result.setView(mToastView);
166 | result.setGravity(Gravity.CENTER, 0, 0);
167 | result.setDuration(duration);
168 | return result;
169 | }
170 |
171 | /**
172 | * Toast View 的 LayoutParams
173 | */
174 | private static final ViewGroup.LayoutParams M_LAYOUT_PARAMS = new ViewGroup.LayoutParams(
175 | ViewGroup.LayoutParams.WRAP_CONTENT,
176 | ViewGroup.LayoutParams.WRAP_CONTENT);
177 |
178 | /**
179 | * Toast View 的 TextColor
180 | */
181 | private static final int TEXT_COLOR = Color.rgb(250, 250, 250);
182 |
183 | /**
184 | * Toast View 的 TextSize;
185 | */
186 | private static final int TEXT_SIZE = 16;
187 |
188 | private static View getToastView(Context context, CharSequence text) {
189 | int padding = LBitmap.dip2px(context, 10);
190 | TextView mTextView = new TextView(context);
191 | mTextView.setLayoutParams(M_LAYOUT_PARAMS);
192 | mTextView.setPadding(padding, padding, padding, padding);
193 | mTextView.setBackgroundDrawable(getViewGradientDrawable(padding / 2));
194 | mTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
195 | mTextView.setTextColor(TEXT_COLOR);
196 | mTextView.setGravity(Gravity.CENTER);
197 | mTextView.setText(text);
198 | return mTextView;
199 | }
200 |
201 | private static GradientDrawable mGradientDrawable;
202 |
203 | private static GradientDrawable getViewGradientDrawable(int radius) {
204 | if (mGradientDrawable == null) {
205 | mGradientDrawable = new GradientDrawable();
206 | mGradientDrawable.setCornerRadius(radius);
207 | mGradientDrawable.setColor(Color.argb(160, 0, 0, 0));
208 | }
209 | return mGradientDrawable;
210 | }
211 |
212 | }
213 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/db/LDBHelper.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.db;
2 |
3 | import com.leo.base.exception.LException;
4 | import com.leo.base.util.L;
5 |
6 | import android.content.ContentValues;
7 | import android.content.Context;
8 | import android.database.SQLException;
9 | import android.database.sqlite.SQLiteCursor;
10 | import android.database.sqlite.SQLiteDatabase;
11 | import android.database.sqlite.SQLiteOpenHelper;
12 | import android.database.sqlite.SQLiteStatement;
13 |
14 | /**
15 | * 本地数据库管理类
16 | *
17 | * @author Chen Lei
18 | *
19 | */
20 | public final class LDBHelper extends SQLiteOpenHelper {
21 |
22 | private SQLiteDatabase myDataBase;
23 |
24 | private String[] mTableCreateText;
25 |
26 | private String[] mTableDropText;
27 |
28 | private static LDBHelper mDataProvider;
29 |
30 | private LDBHelper(Context context, String databaseName, int databaseVersion) {
31 | super(context, databaseName, null, databaseVersion);
32 | }
33 |
34 | /**
35 | * 创建一个DataProvider对象并返回
36 | *
37 | * @param context
38 | * :上下文对象
39 | * @param databaseName
40 | * :数据库名称
41 | * @param databaseVersion
42 | * :数据库版本
43 | * @return
44 | */
45 | public static synchronized LDBHelper Instance(Context context,
46 | String databaseName, int databaseVersion) {
47 | if (mDataProvider == null) {
48 | mDataProvider = new LDBHelper(context, databaseName,
49 | databaseVersion);
50 | }
51 | return mDataProvider;
52 | }
53 |
54 | /**
55 | * 写入创建表语句
56 | *
57 | * @param str
58 | */
59 | public void setTableCreateText(String[] tables) {
60 | this.mTableCreateText = tables;
61 | }
62 |
63 | /**
64 | * 写入删除表语句
65 | *
66 | * @param str
67 | */
68 | public void setTableDropText(String[] tables) {
69 | this.mTableDropText = tables;
70 | }
71 |
72 | /**
73 | * 打开数据库
74 | *
75 | * @throws SQLException
76 | */
77 | public void openDataBase() throws SQLException {
78 | this.myDataBase = this.getWritableDatabase();
79 | }
80 |
81 | /**
82 | * 关闭数据库
83 | *
84 | * @throws SQLException
85 | */
86 | public void closeDataBase() throws SQLException {
87 | if (this.myDataBase != null && this.myDataBase.isOpen())
88 | myDataBase.close();
89 | }
90 |
91 | /**
92 | * 传入SQL语句 返回查询结果
93 | */
94 | public android.database.sqlite.SQLiteCursor Query(String SQL) {
95 | if (myDataBase == null || !myDataBase.isOpen()) {
96 | openDataBase();
97 | }
98 | SQLiteCursor cursor = (android.database.sqlite.SQLiteCursor) myDataBase
99 | .rawQuery(SQL, null);
100 | return cursor;
101 | }
102 |
103 | /**
104 | * 执行SQL语句
105 | */
106 | public void Execute(String SQL) {
107 | if (myDataBase == null || !myDataBase.isOpen()) {
108 | openDataBase();
109 | }
110 | myDataBase.compileStatement(SQL);
111 | myDataBase.execSQL(SQL);
112 | }
113 |
114 | /**
115 | * 更新
116 | *
117 | * @param table
118 | * @param values
119 | * @param whereClause
120 | * @param whereArgs
121 | * @return
122 | */
123 | public int Update(String table, ContentValues values, String whereClause,
124 | String[] whereArgs) {
125 | if (myDataBase == null || !myDataBase.isOpen()) {
126 | openDataBase();
127 | }
128 | int num = myDataBase.update(table, values, whereClause, whereArgs);
129 | return num;
130 | }
131 |
132 | /**
133 | * 插入功能,如果使用此方法,建议在SDK2.2版本(8)或以上
134 | */
135 | public long Insert(String table, String nullColumnHack, ContentValues values) {
136 | SQLiteDatabase db = getWritableDatabase();
137 | long num = db.insert(table, nullColumnHack, values);
138 | return num;
139 | }
140 |
141 | /**
142 | * 执行SQL
143 | */
144 | public void Execute(String SQL, Object[] bindArgs) {
145 | if (myDataBase == null || !myDataBase.isOpen()) {
146 | openDataBase();
147 | }
148 | myDataBase.execSQL(SQL, bindArgs);
149 | }
150 |
151 | public SQLiteStatement CompileStatement(String SQL) {
152 | if (myDataBase == null || !myDataBase.isOpen()) {
153 | openDataBase();
154 | }
155 | return myDataBase.compileStatement(SQL);
156 | }
157 |
158 | /**
159 | * 查询
160 | */
161 | public android.database.sqlite.SQLiteCursor getCursor(String TableName,
162 | String[] columns, String selection, String[] selectionArgs,
163 | String groupBy, String having, String orderBy) {
164 |
165 | if (myDataBase == null || !myDataBase.isOpen()) {
166 | openDataBase();
167 | }
168 | return (android.database.sqlite.SQLiteCursor) myDataBase.query(
169 | TableName, columns, selection, selectionArgs, groupBy, having,
170 | orderBy);
171 | }
172 |
173 | @Override
174 | public void onCreate(SQLiteDatabase db) {
175 | if (mTableCreateText == null || mTableCreateText.length <= 0)
176 | return;
177 | String[] sql = mTableCreateText;
178 | db.beginTransaction();
179 | try {
180 | for (String s : sql) {
181 | if (s.trim().length() > 0) {
182 | db.execSQL(s);
183 | }
184 | }
185 | db.setTransactionSuccessful();
186 | } catch (Exception e) {
187 | L.e(LException.getStackMsg(e));
188 | } finally {
189 | db.endTransaction();
190 | }
191 | }
192 |
193 | @Override
194 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
195 | if (mTableDropText == null || mTableDropText.length <= 0)
196 | return;
197 | String[] sql = mTableDropText;
198 | db.beginTransaction();
199 | try {
200 | for (String s : sql) {
201 | if (s.trim().length() > 0) {
202 | db.execSQL(s);
203 | }
204 | }
205 | db.setTransactionSuccessful();
206 | } catch (Exception e) {
207 | L.e(LException.getStackMsg(e));
208 | } finally {
209 | db.endTransaction();
210 | }
211 | onCreate(db);
212 | }
213 |
214 | }
215 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/net/LDownload.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.net;
2 |
3 | import java.io.File;
4 |
5 | import org.json.JSONException;
6 |
7 | import android.annotation.SuppressLint;
8 | import android.os.AsyncTask;
9 | import android.os.Handler;
10 | import android.os.Message;
11 |
12 | import com.leo.base.entity.LMessage;
13 | import com.leo.base.exception.LException;
14 | import com.leo.base.exception.LLoginException;
15 | import com.leo.base.net.ILNetwork.LLoginState;
16 | import com.leo.base.net.ILNetwork.LReqResultState;
17 | import com.leo.base.net.LNetwork.LReqState;
18 | import com.leo.base.util.L;
19 |
20 | /**
21 | * 文件下载
22 | *
23 | * @author Chen Lei
24 | * @version 1.3.5
25 | */
26 | public class LDownload extends AsyncTask implements
27 | ILNetworkProgress {
28 |
29 | private static final String TAG = LDownload.class.getSimpleName();
30 |
31 | private String mUrl, mSavePath, mSaveName;
32 |
33 | private ILNetworkCallback mCallback;
34 |
35 | private LDownloadStoppingEntity mIsStopThread;
36 |
37 | private int mRequestId;
38 |
39 | private LMessage mMessage;
40 |
41 | /**
42 | * 网络请求接口
43 | */
44 | private ILNetwork mNetwork;
45 |
46 | /**
47 | * 线程状态
48 | */
49 | private LReqState mThreadState;
50 |
51 | public LDownload(String url, String savePath, String saveName,
52 | int requestId, ILNetworkCallback callback, ILNetwork network) {
53 | mThreadState = LReqState.PENDING;
54 | this.mUrl = url;
55 | this.mSavePath = savePath;
56 | this.mSaveName = saveName;
57 | this.mCallback = callback;
58 | this.mRequestId = requestId;
59 | this.mNetwork = network;
60 | mIsStopThread = new LDownloadStoppingEntity();
61 | mIsStopThread.isStopping = false;
62 | }
63 |
64 | @Override
65 | protected LReqResultState doInBackground(Void... params) {
66 | if (mIsStopThread.isStopping)
67 | return LReqResultState.STOP;
68 | mThreadState = LReqState.RUNNING;
69 | String fileUrl = null;
70 | try {
71 | fileUrl = LCaller.doDownloadFile(mUrl, mSavePath, mSaveName, this,
72 | mIsStopThread);
73 | } catch (Exception e) {
74 | L.e(LException.getStackMsg(e));
75 | return LReqResultState.NETWORK_EXC;
76 | }
77 | if (mCallback != null) {
78 | if (mIsStopThread.isStopping)
79 | return LReqResultState.STOP;
80 | File file = new File(fileUrl);
81 | if (file.exists()) {
82 | try {
83 | mMessage = mCallback.onParse(fileUrl, mRequestId);
84 | } catch (LLoginException e) {
85 | mMessage = null;
86 | // ... 登录处理
87 | LLoginState loginState = mNetwork.doLogin();
88 | if (loginState == LLoginState.SUCCESS) {
89 | return LReqResultState.LOGIN_SUCCESS;
90 | } else if (loginState == LLoginState.ERROR) {
91 | return LReqResultState.LOGIN_ERROR;
92 | } else if (loginState == LLoginState.NONE) {
93 | return LReqResultState.LOGIN_NONE;
94 | } else {
95 | return LReqResultState.LOGIN_EXC;
96 | }
97 | } catch (JSONException e) {
98 | mMessage = null;
99 | L.e(TAG, LException.getStackMsg(e));
100 | return LReqResultState.PARSE_EXC;
101 | } catch (Exception e) {
102 | mMessage = null;
103 | L.e(TAG, LException.getStackMsg(e));
104 | return LReqResultState.OTHER;
105 | }
106 | }
107 | } else {
108 | throw new NullPointerException(
109 | "This is an invalid request,because you did not realize the callback interface!");
110 | }
111 | return LReqResultState.SUCCESS;
112 | }
113 |
114 | @Override
115 | protected void onPostExecute(LReqResultState result) {
116 | super.onPostExecute(result);
117 | if (mIsStopThread.isStopping)
118 | result = LReqResultState.STOP;
119 | if (mCallback != null) {
120 | switch (result) {
121 | case SUCCESS:
122 | mCallback.onHandlerUI(mMessage, mRequestId);
123 | break;
124 | case NETWORK_EXC:
125 | mCallback.onException(LReqResultState.NETWORK_EXC, mRequestId);
126 | break;
127 | case PARSE_EXC:
128 | mCallback.onException(LReqResultState.PARSE_EXC, mRequestId);
129 | break;
130 | case LOGIN_SUCCESS:
131 | L.i(TAG, "用户自动登录成功");
132 | mThreadState = LReqState.FINISHED;
133 | mNetwork.download(mUrl, mSavePath, mSaveName, mRequestId,
134 | mCallback);
135 | break;
136 | case LOGIN_ERROR:
137 | mCallback.onException(LReqResultState.LOGIN_ERROR, mRequestId);
138 | break;
139 | case LOGIN_NONE:
140 | mCallback.onException(LReqResultState.LOGIN_NONE, mRequestId);
141 | break;
142 | case LOGIN_EXC:
143 | throw new RuntimeException("用户登录返回异常");
144 | case OTHER:
145 | mCallback.onException(LReqResultState.OTHER, mRequestId);
146 | break;
147 | case STOP:
148 | L.i(TAG, "线程ID为:" + mRequestId + "的线程已停止!");
149 | mCallback.onException(LReqResultState.STOP, mRequestId);
150 | break;
151 | default:
152 | throw new IllegalArgumentException("返回结果参数错误");
153 | }
154 | }
155 | mThreadState = LReqState.FINISHED;
156 | }
157 |
158 | @Override
159 | public void sendProgress(int size, int current) {
160 | Message msg = Message.obtain();
161 | msg.arg1 = size;
162 | msg.arg2 = current;
163 | mHandler.sendMessage(msg);
164 | }
165 |
166 | @SuppressLint("HandlerLeak")
167 | private Handler mHandler = new Handler() {
168 |
169 | @Override
170 | public void handleMessage(Message msg) {
171 | super.handleMessage(msg);
172 | if (mCallback != null) {
173 | int count = msg.arg1;
174 | int current = msg.arg2;
175 | mCallback.onProgress(count, current, mRequestId);
176 | }
177 | }
178 |
179 | };
180 |
181 | public void stop() {
182 | this.mIsStopThread.isStopping = true;
183 | }
184 |
185 | public LReqState getState() {
186 | return mThreadState;
187 | }
188 |
189 | class LDownloadStoppingEntity {
190 | boolean isStopping;
191 | }
192 |
193 | }
194 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/net/LRequest.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.net;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import org.json.JSONException;
7 |
8 | import android.annotation.SuppressLint;
9 | import android.os.AsyncTask;
10 | import android.os.Handler;
11 | import android.os.Message;
12 |
13 | import com.leo.base.entity.LMessage;
14 | import com.leo.base.entity.LReqEncode;
15 | import com.leo.base.entity.LReqEntity;
16 | import com.leo.base.entity.LReqFile;
17 | import com.leo.base.entity.LReqMothed;
18 | import com.leo.base.exception.LException;
19 | import com.leo.base.exception.LLoginException;
20 | import com.leo.base.net.ILNetwork.LLoginState;
21 | import com.leo.base.net.ILNetwork.LReqResultState;
22 | import com.leo.base.net.LNetwork.LReqState;
23 | import com.leo.base.util.L;
24 | import com.leo.base.util.LFormat;
25 |
26 | /**
27 | * 网络请求
28 | *
29 | * @author Chen Lei
30 | * @version 1.3.5
31 | *
32 | */
33 | public class LRequest extends AsyncTask implements
34 | ILNetworkProgress {
35 |
36 | private static final String TAG = LRequest.class.getSimpleName();
37 |
38 | /**
39 | * 请求封装实体
40 | */
41 | private LReqEntity mReqEntity;
42 |
43 | /**
44 | * 请求ID
45 | */
46 | private int mRequestId;
47 |
48 | /**
49 | * 请求回调接口
50 | */
51 | private ILNetworkCallback mCallback;
52 |
53 | /**
54 | * 网络请求接口
55 | */
56 | private ILNetwork mNetwork;
57 |
58 | /**
59 | * 请求返回值
60 | */
61 | private LMessage mMessage;
62 |
63 | /**
64 | * 线程状态
65 | */
66 | private LReqState mThreadState;
67 |
68 | /**
69 | * 是否停止线程,默认false
70 | */
71 | private boolean mIsStopThread;
72 |
73 | public LRequest(LReqEntity reqEntity, int reqId,
74 | ILNetworkCallback callback, ILNetwork network) {
75 | this.mReqEntity = reqEntity;
76 | this.mRequestId = reqId;
77 | this.mCallback = callback;
78 | this.mNetwork = network;
79 | mThreadState = LReqState.PENDING;
80 | mIsStopThread = false;
81 | }
82 |
83 | @Override
84 | protected LReqResultState doInBackground(Void... params) {
85 | mThreadState = LReqState.RUNNING;
86 | LReqEntity entity = mReqEntity;
87 | if (entity == null) {
88 | throw new NullPointerException(
89 | "The network requests the LReqEntity parameter cannot be empty!");
90 | }
91 | String netUrl = entity.getUrl();
92 | if (LFormat.isEmpty(netUrl)) {
93 | throw new NullPointerException(
94 | "The network requests the URL parameter cannot be empty!");
95 | }
96 | LReqEncode netEncode = entity.getReqEncode();
97 | LReqMothed netMothed = entity.getReqMode();
98 | Map netParams = entity.getParams();
99 | List netFiles = entity.getFileParams();
100 | boolean netUseCache = entity.getUseCache();
101 | if (mIsStopThread)
102 | return LReqResultState.STOP;
103 | String result = null;
104 | try {
105 | if (netFiles == null || netFiles.isEmpty()) {
106 | result = LCaller.doConn(netUrl, netParams, netUseCache,
107 | netMothed, netEncode);
108 | } else {
109 | result = LCaller.doUploadFile(netUrl, netParams, netFiles,
110 | netEncode, this);
111 | }
112 | } catch (Exception e) {
113 | L.e(TAG, LException.getStackMsg(e));
114 | return LReqResultState.NETWORK_EXC;
115 | }
116 | if (mCallback != null) {
117 | if (mIsStopThread)
118 | return LReqResultState.STOP;
119 | try {
120 | mMessage = mCallback.onParse(result, mRequestId);
121 | } catch (LLoginException e) {
122 | mMessage = null;
123 | // ... 登录处理
124 | LLoginState loginState = mNetwork.doLogin();
125 | if (loginState == LLoginState.SUCCESS) {
126 | return LReqResultState.LOGIN_SUCCESS;
127 | } else if (loginState == LLoginState.ERROR) {
128 | return LReqResultState.LOGIN_ERROR;
129 | } else if (loginState == LLoginState.NONE) {
130 | return LReqResultState.LOGIN_NONE;
131 | } else {
132 | return LReqResultState.LOGIN_EXC;
133 | }
134 | } catch (JSONException e) {
135 | mMessage = null;
136 | L.e(TAG, LException.getStackMsg(e));
137 | return LReqResultState.PARSE_EXC;
138 | } catch (Exception e) {
139 | mMessage = null;
140 | L.e(TAG, LException.getStackMsg(e));
141 | return LReqResultState.OTHER;
142 | }
143 | } else {
144 | throw new NullPointerException(
145 | "This is an invalid request,because you did not realize the callback interface!");
146 | }
147 | return LReqResultState.SUCCESS;
148 | }
149 |
150 | @Override
151 | protected void onPostExecute(LReqResultState result) {
152 | if (mIsStopThread)
153 | result = LReqResultState.STOP;
154 | super.onPostExecute(result);
155 | if (mCallback != null) {
156 | switch (result) {
157 | case SUCCESS:
158 | mCallback.onHandlerUI(mMessage, mRequestId);
159 | break;
160 | case NETWORK_EXC:
161 | mCallback.onException(LReqResultState.NETWORK_EXC, mRequestId);
162 | break;
163 | case PARSE_EXC:
164 | mCallback.onException(LReqResultState.PARSE_EXC, mRequestId);
165 | break;
166 | case LOGIN_SUCCESS:
167 | L.i(TAG, "用户自动登录成功");
168 | mThreadState = LReqState.FINISHED;
169 | mNetwork.request(mReqEntity, mRequestId, mCallback);
170 | break;
171 | case LOGIN_ERROR:
172 | mCallback.onException(LReqResultState.LOGIN_ERROR, mRequestId);
173 | break;
174 | case LOGIN_NONE:
175 | mCallback.onException(LReqResultState.LOGIN_NONE, mRequestId);
176 | break;
177 | case LOGIN_EXC:
178 | throw new RuntimeException("用户登录返回异常");
179 | case OTHER:
180 | mCallback.onException(LReqResultState.OTHER, mRequestId);
181 | break;
182 | case STOP:
183 | L.i(TAG, "线程ID为:" + mRequestId + "的线程已停止!");
184 | mCallback.onException(LReqResultState.STOP, mRequestId);
185 | break;
186 | default:
187 | throw new IllegalArgumentException("返回结果参数错误");
188 | }
189 | }
190 | mThreadState = LReqState.FINISHED;
191 | }
192 |
193 | /**
194 | * 发布进度
195 | *
196 | * @param count
197 | * @param current
198 | */
199 | @Override
200 | public void sendProgress(int count, int current) {
201 | Message msg = Message.obtain();
202 | msg.arg1 = count;
203 | msg.arg2 = current;
204 | mHandler.sendMessage(msg);
205 | }
206 |
207 | @SuppressLint("HandlerLeak")
208 | private Handler mHandler = new Handler() {
209 |
210 | @Override
211 | public void handleMessage(Message msg) {
212 | super.handleMessage(msg);
213 | if (mCallback != null) {
214 | int count = msg.arg1;
215 | int current = msg.arg2;
216 | mCallback.onProgress(count, current, mRequestId);
217 | }
218 | }
219 |
220 | };
221 |
222 | public LReqState getState() {
223 | return mThreadState;
224 | }
225 |
226 | public void stop() {
227 | this.mIsStopThread = true;
228 | L.i("下载是为停止为:" + mIsStopThread);
229 | }
230 |
231 | }
232 |
--------------------------------------------------------------------------------
/LBase/src/com/leo/base/adapter/LBaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.leo.base.adapter;
2 |
3 | import java.util.List;
4 |
5 | import com.leo.base.cache.LCache;
6 | import com.leo.base.entity.LMessage;
7 | import com.leo.base.handler.ILHandlerCallback;
8 |
9 | import android.content.Context;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.BaseAdapter;
14 |
15 | /**
16 | * 来源:
LBaseAdapter 继承自 {@linkplain android.widget.BaseAdapter
17 | * BaseAdapter} 用途:
所有需要继承 {@linkplain android.widget.BaseAdapter
18 | * BaseAdapter} 类的 Adapter,只需继承此类即可 说明:
属性
19 | * {@linkplain com.leo.base.cache.LCache LCache}:用作缓存View
20 | * {@linkplain com.leo.base.adapter.LAdapters LAdapters}:用作获取共有数据
21 | * {@linkplain android.view.LayoutInflater LayoutInflater} 对象
22 | * 方法 此类实现了 {@linkplain android.widget.BaseAdapter BaseAdapter} 所有的抽象方法, 并将
23 | * {@linkplain android.widget.BaseAdapter#getView(int, View, ViewGroup)
24 | * BaseAdapter.getView(int, View, ViewGroup)} 方法继承抽象,以便继承此类的 Adapter 构造自己的 Item。
25 | *
26 | * 继承此类后,使用者只需实现
27 | * {@linkplain android.widget.BaseAdapter#getView(int, View, ViewGroup)
28 | * BaseAdapter.getView(int, View, ViewGroup)} 方法便可,无需考虑其它
29 | * 此类还提供了多个操作缓存的方法 当你使用了
30 | * {@linkplain com.leo.base.handler.LHandler#startLoadingData(com.leo.base.entity.LReqEntity)
31 | * LHandler.startLoadingData(LReqEntity)} 方法请求网络后,
32 | * {@linkplain com.leo.base.handler.LHandler LHandler} 会自动调用此类的
33 | * {@linkplain com.leo.base.adapter.LBaseAdapter#resultHandler(com.leo.base.entity.LMessage)
34 | * LBaseAdapter.resultHandler(LMessage)} 方法,并将解析的结果
35 | * {@linkplain com.leo.base.entity.LMessage LMessage} 对象传回
36 | *
37 | * @author Chen Lei
38 | * @version 1.3.1
39 | * @param
40 | * 传入此参数类型,以保证返回的数据为使用者需要的类型
41 | */
42 | public abstract class LBaseAdapter extends BaseAdapter implements ILHandlerCallback {
43 |
44 | /**
45 | * 缓存View对象
46 | */
47 | private LCache cacheView = new LCache();
48 |
49 | private LAdapters mAdapter;
50 |
51 | private LayoutInflater mInflater;
52 |
53 | /**
54 | * 构造函数
55 | *
56 | * @param context
57 | * 传入上下文对象
58 | */
59 | public LBaseAdapter(Context context) {
60 | initAdapter(context, null, false);
61 | }
62 |
63 | /**
64 | * 构造函数
65 | *
66 | * @param context
67 | * 传入上下文对象
68 | * @param list
69 | * 数据集合
70 | */
71 | public LBaseAdapter(Context context, List list) {
72 | initAdapter(context, list, false);
73 | }
74 |
75 | /**
76 | * 构造函数
77 | *
78 | * @param context
79 | * 传入上下文对象
80 | * @param list
81 | * 数据集合
82 | * @param hasImage
83 | * 是否使用
84 | * {@linkplain com.nostra13.universalimageloader.core.ImageLoader
85 | * ImageLoader} 异步加载图片
86 | */
87 | public LBaseAdapter(Context context, List list, boolean useImage) {
88 | initAdapter(context, list, useImage);
89 | }
90 |
91 | /**
92 | * 初始化 {@linkplain com.leo.base.adapter.LAdapters.LAdapters LAdapters} 实例
93 | *
94 | * @param context
95 | * @param list
96 | * @param useImage
97 | */
98 | private void initAdapter(Context context, List list, boolean useImage) {
99 | mAdapter = new LAdapters(context, list, useImage);
100 | }
101 |
102 | /**
103 | *
104 | * @return 获取 {@linkplain com.leo.base.adapter.LAdapters.LAdapters
105 | * LAdapters} 实例
106 | */
107 | public LAdapters getAdapter() {
108 | return mAdapter;
109 | }
110 |
111 | @Override
112 | public int getCount() {
113 | int count = 0;
114 | if (mAdapter != null) {
115 | count = mAdapter.getCount();
116 | }
117 | return count;
118 | }
119 |
120 | @Override
121 | public Object getItem(int position) {
122 | Object o = null;
123 | if (mAdapter != null) {
124 | o = mAdapter.getItem(position);
125 | }
126 | return o;
127 | }
128 |
129 | @Override
130 | public long getItemId(int position) {
131 | long p = 0;
132 | if (mAdapter != null) {
133 | p = mAdapter.getItemId(position);
134 | }
135 | return p;
136 | }
137 |
138 | /**
139 | * 抽象的getView
140 | * 系统会自动调用getView方法来获取List数据的每一条显示内容
141 | * 需要手动实现此方法
142 | */
143 | @Override
144 | public abstract View getView(int position, View convertView,
145 | ViewGroup parent);
146 |
147 | /**
148 | * 获取一个LayoutInflater实例
149 | *
150 | * @return
151 | */
152 | public LayoutInflater getInflater() {
153 | if (mInflater == null) {
154 | mInflater = (LayoutInflater) this.getAdapter().getContext()
155 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
156 | }
157 | return mInflater;
158 | }
159 |
160 | /**
161 | * 清除缓存数据,并不刷新UI
162 | */
163 | public void destroyConvertView() {
164 | if (cacheView != null)
165 | cacheView.clearAll();
166 | }
167 |
168 | /**
169 | * 清除内存数据,并不刷新UI
170 | */
171 | public void Destroy() {
172 | destroyConvertView();
173 | cacheView = null;
174 | if (mAdapter != null) {
175 | mAdapter.destroyList();
176 | mAdapter.setList(null);
177 | }
178 | }
179 |
180 | /**
181 | * 添加缓存view
182 | *
183 | * @param key
184 | * @param value
185 | */
186 | public void addConvertView(String key, View value) {
187 | if (!cacheView.isHaveCache(key)) {
188 | cacheView.put(key, value);
189 | }
190 | }
191 |
192 | /**
193 | * 删除缓存view
194 | *
195 | * @param key
196 | */
197 | public void delConvertView(String key) {
198 | if (cacheView.isHaveCache(key)) {
199 | cacheView.remove(key);
200 | }
201 | }
202 |
203 | /**
204 | * 查询缓存view
205 | *
206 | * @param key
207 | * @return
208 | */
209 | public View getConvertView(String key) {
210 | View v = null;
211 | if (cacheView.isHaveCache(key)) {
212 | v = cacheView.get(key);
213 | }
214 | return v;
215 | }
216 |
217 | /**
218 | * 清除所有缓存并刷新UI
219 | */
220 | @Override
221 | public void notifyDataSetChanged() {
222 | destroyConvertView();
223 | super.notifyDataSetChanged();
224 | }
225 |
226 | /**
227 | * 清除指定KEY的缓存并刷新UI
228 | *
229 | * @param key
230 | * :需要重新生成UI的KEY
231 | */
232 | public void notifyDataSetChanged(String key) {
233 | delConvertView(key);
234 | super.notifyDataSetChanged();
235 | }
236 |
237 | /**
238 | * 当你使用了
239 | * {@linkplain com.leo.base.handler.LHandler#startLoadingData(com.leo.base.net.LReqEntity)
240 | * LHandler.startLoadingData(LReqEntity)} 方法请求网络后,
241 | * {@linkplain com.leo.base.handler.LHandler LHandler} 会自动调用此方法,并将解析的结果
242 | * {@linkplain com.leo.base.entity.LMessage LMessage} 对象传回
243 | *
244 | * @param msg
245 | */
246 | public void onResultHandler(LMessage msg, int requestId) {
247 | // ... 写入你需要的代码
248 | }
249 |
250 | }
251 |
--------------------------------------------------------------------------------