├── .DS_Store ├── .gitignore ├── LICENSE ├── PlutoAndroidExample ├── .gitignore ├── .idea │ ├── codeStyles │ │ ├── Project.xml │ │ └── codeStyleConfig.xml │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── markdown-navigator.xml │ ├── markdown-navigator │ │ └── profiles_settings.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ └── vcs.xml ├── Pluto │ ├── build.gradle │ ├── dependencies.gradle │ ├── libs │ │ ├── commons-httpclient-3.1.jar │ │ └── httpmime-4.5.2.jar │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── minggo │ │ │ └── pluto │ │ │ ├── Pluto.java │ │ │ ├── activity │ │ │ ├── IActivity.java │ │ │ └── PlutoActivity.java │ │ │ ├── adapter │ │ │ └── PlutoPagerAdapter.java │ │ │ ├── annotation │ │ │ ├── AutoIncrement.java │ │ │ ├── Exclude.java │ │ │ └── Primarykey.java │ │ │ ├── api │ │ │ ├── ApiClient.java │ │ │ ├── ApiUrl.java │ │ │ └── PlutoApiEngine.java │ │ │ ├── bitmap │ │ │ ├── AsyncTask.java │ │ │ ├── BitmapCache.java │ │ │ ├── BitmapCommonUtils.java │ │ │ ├── BitmapDecoder.java │ │ │ ├── BitmapDisplayConfig.java │ │ │ ├── BitmapProcess.java │ │ │ ├── ChargeVersionUtils.java │ │ │ ├── DiskLruCache.java │ │ │ ├── Displayer.java │ │ │ ├── Downloader.java │ │ │ ├── FileNameGenerator.java │ │ │ ├── FinalBitmap.java │ │ │ ├── LruDiskCache.java │ │ │ ├── LruMemoryCache.java │ │ │ ├── RecyclingBitmapDrawable.java │ │ │ ├── RecyclingImageView.java │ │ │ ├── SimpleDisplayer.java │ │ │ ├── SimpleHttpDownloader.java │ │ │ └── Utils.java │ │ │ ├── common │ │ │ ├── AppContext.java │ │ │ ├── AppManager.java │ │ │ ├── AsyncTaskManager.java │ │ │ ├── CommonAsyncTask.java │ │ │ └── PlutoException.java │ │ │ ├── db │ │ │ ├── manager │ │ │ │ ├── DataManager.java │ │ │ │ ├── DataManagerProxy.java │ │ │ │ └── DataManagerStub.java │ │ │ └── orm │ │ │ │ ├── ClassUtils.java │ │ │ │ ├── CursorUtils.java │ │ │ │ ├── DaoUtils.java │ │ │ │ ├── DbException.java │ │ │ │ ├── DbModel.java │ │ │ │ ├── FieldUtils.java │ │ │ │ ├── FinalDb.java │ │ │ │ ├── Id.java │ │ │ │ ├── Id_A.java │ │ │ │ ├── KeyValue.java │ │ │ │ ├── ManyToOne.java │ │ │ │ ├── ManyToOneLazyLoader.java │ │ │ │ ├── ManyToOne_A.java │ │ │ │ ├── OneToMany.java │ │ │ │ ├── OneToManyLazyLoader.java │ │ │ │ ├── OneToMany_A.java │ │ │ │ ├── Property.java │ │ │ │ ├── Property_A.java │ │ │ │ ├── SQLHelper.java │ │ │ │ ├── SqlBuilder.java │ │ │ │ ├── SqlInfo.java │ │ │ │ ├── Table.java │ │ │ │ ├── TableInfo.java │ │ │ │ └── Transient.java │ │ │ ├── dialog │ │ │ └── PlutoDialog.java │ │ │ ├── fragment │ │ │ ├── FragmentUserVisibleController.java │ │ │ ├── IFragment.java │ │ │ ├── PlutoFragment.java │ │ │ └── ProgressFragment.java │ │ │ ├── logic │ │ │ ├── LogicManager.java │ │ │ └── LogicParam.java │ │ │ ├── model │ │ │ └── Result.java │ │ │ └── util │ │ │ ├── AnimationUtils.java │ │ │ ├── BitmapUtil.java │ │ │ ├── DateUtil.java │ │ │ ├── DisplayUtil.java │ │ │ ├── EncryptUtils.java │ │ │ ├── FastBlur.java │ │ │ ├── FileUtils.java │ │ │ ├── InjectedChromeClient.java │ │ │ ├── JsCallJava.java │ │ │ ├── JsCallback.java │ │ │ ├── LogUtils.java │ │ │ ├── MResource.java │ │ │ ├── NetworkUtils.java │ │ │ ├── PhotoUtil.java │ │ │ ├── PlutoFileCache.java │ │ │ ├── PollingUtils.java │ │ │ ├── SharePreferenceUtils.java │ │ │ ├── StringUtils.java │ │ │ └── ThreadPoolUtils.java │ │ └── res │ │ ├── anim │ │ ├── alpha_in.xml │ │ ├── alpha_out.xml │ │ ├── alpha_sllow_in.xml │ │ ├── alpha_sllow_out.xml │ │ ├── push_down_out.xml │ │ ├── push_left_in.xml │ │ ├── push_right_out.xml │ │ └── push_up_in.xml │ │ ├── layout │ │ ├── dialog_progress.xml │ │ ├── dialog_text.xml │ │ └── fragment_progress.xml │ │ └── values │ │ ├── strings.xml │ │ └── styles.xml ├── app │ ├── .gitignore │ ├── build.gradle │ ├── dependencies.gradle │ ├── libs │ │ └── Baidu_Mtj_3.7.5.4.jar │ ├── pluto_uml.png │ ├── pluto_uml.puml │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── minggo │ │ │ └── plutoandroidexample │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── minggo │ │ │ │ └── plutoandroidexample │ │ │ │ ├── activity │ │ │ │ ├── MainActivity.java │ │ │ │ ├── PlutoAPIEngineExample.java │ │ │ │ ├── PlutoActivityExample.java │ │ │ │ ├── PlutoDialogExample.java │ │ │ │ ├── PlutoFileCacheExample.java │ │ │ │ ├── PlutoFragmentExample.java │ │ │ │ ├── PlutoImageFrameworkExample.java │ │ │ │ ├── PlutoNetworkExample.java │ │ │ │ ├── PlutoORMDBFrameworkExample.java │ │ │ │ └── PlutoUtilsActivity.java │ │ │ │ ├── common │ │ │ │ └── PlutoApplication.java │ │ │ │ ├── fragment │ │ │ │ ├── BlogFragment.java │ │ │ │ └── ExampleFragment.java │ │ │ │ ├── logic │ │ │ │ ├── MyLogic.java │ │ │ │ └── MyParam.java │ │ │ │ ├── model │ │ │ │ ├── ServerURL.java │ │ │ │ └── User.java │ │ │ │ ├── neturl │ │ │ │ └── ExampleURL.java │ │ │ │ └── util │ │ │ │ └── FileUtil.java │ │ └── res │ │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── drawable-v21 │ │ │ ├── ic_menu_camera.xml │ │ │ ├── ic_menu_gallery.xml │ │ │ ├── ic_menu_manage.xml │ │ │ ├── ic_menu_send.xml │ │ │ ├── ic_menu_share.xml │ │ │ └── ic_menu_slideshow.xml │ │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── pluto.png │ │ │ └── pluto_corner.png │ │ │ ├── drawable-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── drawable │ │ │ ├── shap_bottom_line.xml │ │ │ └── side_nav_bar.xml │ │ │ ├── layout-w900dp │ │ │ └── item_list.xml │ │ │ ├── layout │ │ │ ├── activity_dialog_example.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_pluto_apiengine_example.xml │ │ │ ├── activity_pluto_example.xml │ │ │ ├── activity_pluto_file_cache_example.xml │ │ │ ├── activity_pluto_fragment_example.xml │ │ │ ├── activity_pluto_image_framework_example.xml │ │ │ ├── activity_pluto_network_example.xml │ │ │ ├── activity_pluto_ormdbframework_example.xml │ │ │ ├── activity_pluto_utils.xml │ │ │ ├── app_bar_main.xml │ │ │ ├── content_main.xml │ │ │ ├── fragment_blog.xml │ │ │ ├── fragment_example.xml │ │ │ └── nav_header_main.xml │ │ │ ├── menu │ │ │ ├── activity_main_drawer.xml │ │ │ ├── main.xml │ │ │ └── menu_pluto_activity_example.xml │ │ │ ├── values-v21 │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── drawables.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── minggo │ │ └── plutoandroidexample │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlutoArchitecture/Pluto-Android/836fb70f3a93c4b40e2ddf2bdd61c14018130d7a/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | 39 | # Keystore files 40 | *.jks 41 | PlutoAndroidExample/.idea/modules.xml 42 | PlutoAndroidExample/.idea/modules.xml 43 | PlutoAndroidExample/.idea/misc.xml 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 minggo 4 | email 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | /.idea 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 33 | 34 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 1.8 53 | 54 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /PlutoAndroidExample/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/dependencies.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | //Version 3 | supportLibrary = '25.0.1' 4 | 5 | //Support Libraries dependencies 6 | testDependencies = [ 7 | junit: "junit:junit:4.12", 8 | ] 9 | 10 | //Support Libraries dependencies 11 | supportDependencies = [ 12 | design : "com.android.support:design:${supportLibrary}", 13 | recyclerView : "com.android.support:recyclerview-v7:${supportLibrary}", 14 | cardView : "com.android.support:cardview-v7:${supportLibrary}", 15 | appCompat : "com.android.support:appcompat-v7:${supportLibrary}", 16 | supportAnnotation: "com.android.support:support-annotations:${supportLibrary}", 17 | ] 18 | 19 | //Third Libraries dependencies 20 | thirdDependencies = [ 21 | 22 | //View注解 代码地址-----> https://github.com/JakeWharton/butterknife 23 | butterKnife : "com.jakewharton:butterknife:8.4.0", 24 | butterknifeCompiler : "com.jakewharton:butterknife-compiler:8.4.0", 25 | //Bundle注解 代码地址-----> https://github.com/yatatsu/AutoBundle 26 | //autoBundle : "com.github.yatatsu:autobundle:3.1.1", 27 | //autoBundleProcessor : "com.github.yatatsu:autobundle-processor:3.1.1", 28 | //API网络请求注解库 代码地址-----> https://github.com/square/retrofit 29 | retrofit : "com.squareup.retrofit2:retrofit:2.0.1", 30 | converterGson: "com.squareup.retrofit2:converter-gson:2.0.1", 31 | //网络请求库 代码地址-----> https://github.com/square/okhttp 32 | okhttp : "com.squareup.okhttp3:okhttp:3.2.0", 33 | //EventBus 代码地址-----> https://github.com/greenrobot/EventBus 34 | eventBus : "org.greenrobot:eventbus:3.0.0", 35 | materialprogressbar : 'me.zhanghai.android.materialprogressbar:library:1.3.0', 36 | gson : 'com.google.code.gson:gson:2.5', 37 | commonlang : 'org.apache.commons:commons-lang3:3.4', 38 | glide : 'com.github.bumptech.glide:glide:3.7.0', 39 | glideTransformation : 'jp.wasabeef:glide-transformations:2.0.0' 40 | ] 41 | } -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/libs/commons-httpclient-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlutoArchitecture/Pluto-Android/836fb70f3a93c4b40e2ddf2bdd61c14018130d7a/PlutoAndroidExample/Pluto/libs/commons-httpclient-3.1.jar -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/libs/httpmime-4.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlutoArchitecture/Pluto-Android/836fb70f3a93c4b40e2ddf2bdd61c14018130d7a/PlutoAndroidExample/Pluto/libs/httpmime-4.5.2.jar -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/mmd_mac03/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | #用到反射及注解需要加上下面 19 | -keepattributes *Annotation*,EnclosingMethod 20 | #日志显示代码行数 21 | -keepattributes SourceFile,LineNumberTable 22 | #使代码不被压缩优化(点击事件的控件,被优化掉的原因就是因为用注解后,在代码中该控件的实例没有其他地方用到,所以程序就认为该代码没有被用到,就被注视掉了。) 23 | #用到afinal注解的项目代码混淆后某些控件view点击事件无效 - 七月流浪猫 - 博客频道 - CSDN.NET 24 | #http://blog.csdn.net/haibin80s/article/details/46965645 25 | -dontshrink 26 | -dontoptimize 27 | -dontwarn com.google.android.maps.** 28 | -dontwarn android.webkit.WebView 29 | -keepattributes Exceptions,InnerClasses,Signature 30 | 31 | #不混淆Serializable的子类 32 | # Explicitly preserve all serialization members. The Serializable interface 33 | # is only a marker interface, so it wouldn't save them. 34 | -keepclassmembers class * implements java.io.Serializable { 35 | static final long serialVersionUID; 36 | private static final java.io.ObjectStreamField[] serialPersistentFields; 37 | private void writeObject(java.io.ObjectOutputStream); 38 | private void readObject(java.io.ObjectInputStream); 39 | java.lang.Object writeReplace(); 40 | java.lang.Object readResolve(); 41 | } 42 | 43 | # Keep Butterknife stuff 44 | -keep class butterknife.** { *; } 45 | -dontwarn butterknife.internal.** 46 | -keep class **$$ViewBinder { *; } 47 | 48 | -keepclasseswithmembernames class * { 49 | @butterknife.* ; 50 | } 51 | 52 | -keepclasseswithmembernames class * { 53 | @butterknife.* ; 54 | } 55 | 56 | # Keep GSON stuff 57 | -keepattributes Signature 58 | -keep class sun.misc.Unsafe { *; } 59 | -keep class com.google.gson.** { *; } 60 | 61 | #排除指定Pluto的LogicParam混淆 62 | -keep class com.minggo.pluto.logic.LogicParam { *; } 63 | -keep class com.minggo.pluto.logic.LogicParam$* { *; } 64 | -keep class com.minggo.pluto.model.** { *; } 65 | 66 | 67 | #WebView 68 | -keepclassmembers class fqcn.of.javascript.interface.for.webview { 69 | public *; 70 | } 71 | #apache工具类mmons.** { *; } 72 | -dontwarn org.apache.commons.** 73 | #onClickXXX不混淆,防止FinalActivity无法调用 74 | -keepclassmembers class * { 75 | public void *(android.view.View); 76 | public void *(android.widget.AdapterView,android.view.View,int,long); 77 | public boolean *(android.widget.AdapterView,android.view.View,int,long); 78 | } 79 | 80 | #混淆Glide 81 | -keep public class * implements com.bumptech.glide.module.GlideModule 82 | -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { 83 | **[] $VALUES; 84 | public *; 85 | } -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/Pluto.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | 6 | import com.minggo.pluto.api.ApiUrl; 7 | import com.minggo.pluto.common.AppContext; 8 | import com.minggo.pluto.common.PlutoException; 9 | import com.minggo.pluto.util.LogUtils; 10 | 11 | /** 12 | * Pluto 框架配置 13 | * Created by minggo on 2017/1/3. 14 | */ 15 | public class Pluto { 16 | /** 17 | * 域名 18 | */ 19 | public static String URL_DOMAIN = "http://m8en.com:8877/"; 20 | //public static final String URL_DOMAIN = "http://10.10.2.14:8080/"; 21 | /** 22 | * 项目缓存目录 23 | */ 24 | public static String APP_CACHE_FILE = "com.minggo.pluto"; 25 | /** 26 | * 调试信息打印 27 | */ 28 | public static boolean LOG_SHOW = true; 29 | /** 30 | * 主程序SD卡目录 31 | */ 32 | public static String SDPATH = Environment.getExternalStorageDirectory().getPath() + "/" + APP_CACHE_FILE + "/"; 33 | /** 34 | * 便于统一finalbitmap修改保存路径 35 | */ 36 | public static String FINAL_BIMAP_SAVE_PATH = APP_CACHE_FILE + "/bookpic"; 37 | /** 38 | * 下载原图路径 便于统一finalbitmap修改保存路径 39 | */ 40 | public static String FINAL_ORIGINAL_BIMAP_SAVE_PATH = FINAL_BIMAP_SAVE_PATH + "/original"; 41 | 42 | /** 43 | * 数据库的配置 44 | */ 45 | public static class DBConfig { 46 | // 数据库名称 47 | public static String NAME = "com.minggo.pluto"; 48 | // 数据库版本 49 | public static int VERSION = 2; 50 | } 51 | 52 | /** 53 | * 加密key 54 | */ 55 | public static String MD5KEY = "minggo"; 56 | 57 | //必须在自己Application类中先初始化 58 | public static void initPluto(Context context) { 59 | AppContext.getInstance().context = context; 60 | ApiUrl.URL_DOMAIN = URL_DOMAIN; 61 | ApiUrl.MD5KEY=MD5KEY; 62 | SDPATH = Environment.getExternalStorageDirectory().getPath() + "/" + APP_CACHE_FILE + "/"; 63 | 64 | if (!BuildConfig.DEBUG) { 65 | LogUtils.info("plutoexception", ">>>>>init"); 66 | //PlutoException.getAppExceptionHandler(context); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/activity/IActivity.java: -------------------------------------------------------------------------------- 1 | 2 | package com.minggo.pluto.activity; 3 | 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Message; 7 | 8 | import java.util.ArrayList; 9 | 10 | /** 11 | * 描述:Activity抽象接口 12 | * 13 | * @author minggo 14 | * @since 2014-3-20 上午12:49:35 15 | */ 16 | public interface IActivity { 17 | 18 | /** 19 | * 设置广播action 20 | * 21 | * @return 22 | */ 23 | void setupActions(ArrayList actions); 24 | 25 | /** 26 | * 刷新界面 27 | * 28 | * @param msg 29 | */ 30 | void handleUiMessage(Message msg); 31 | 32 | /** 33 | * 处理广播 34 | * 35 | * @param context 36 | * @param intent 37 | */ 38 | void handleBroadcast(Context context, Intent intent); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/adapter/PlutoPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentStatePagerAdapter; 6 | import android.support.v4.view.PagerAdapter; 7 | import android.view.ViewGroup; 8 | 9 | import java.util.List; 10 | 11 | 12 | /** 13 | * 首页的viewpager适配器 14 | * @author minggo 15 | * @time 2015-3-16上午11:12:12 16 | */ 17 | public class PlutoPagerAdapter extends FragmentStatePagerAdapter { 18 | 19 | private List fragmentList; 20 | private List titleList; 21 | 22 | public PlutoPagerAdapter(FragmentManager fm, List fragmentList, List titleList) { 23 | super(fm); 24 | this.fragmentList = fragmentList; 25 | this.titleList = titleList; 26 | } 27 | 28 | /** 29 | * 得到每个页面 30 | */ 31 | @Override 32 | public Fragment getItem(int arg0) { 33 | return (fragmentList ==null || fragmentList.size() == 0) ? null: fragmentList.get(arg0); 34 | } 35 | 36 | 37 | /** 38 | * 页面的总个数 39 | */ 40 | @Override 41 | public int getCount() { 42 | return fragmentList == null ? 0 : fragmentList.size(); 43 | } 44 | 45 | 46 | @Override 47 | public int getItemPosition(Object object) { 48 | //return PagerAdapter.POSITION_NONE; 49 | return PagerAdapter.POSITION_NONE; 50 | } 51 | 52 | @Override 53 | public void destroyItem(ViewGroup container, int position, Object object) { 54 | super.destroyItem(container, position, object); 55 | //LogUtils.info("pager", "No." + position + "被删除了"); 56 | } 57 | 58 | @Override 59 | public CharSequence getPageTitle(int position) { 60 | //得到对应position的Fragment的title 61 | return titleList.get(position); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/annotation/AutoIncrement.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 数据库 递增注解 10 | * @author minggo 11 | * @time 2014-6-23 S下午9:32:16 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.FIELD) 15 | public @interface AutoIncrement { 16 | } 17 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/annotation/Exclude.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 排除字段注解,不持久化到数据库 10 | * @author minggo 11 | * @time 2014-6-23 S下午9:31:51 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.FIELD) 15 | public @interface Exclude { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/annotation/Primarykey.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 数据库 主键注解 10 | * @author minggo 11 | * @time 2014-6-23 S下午9:32:16 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.FIELD) 15 | public @interface Primarykey { 16 | } 17 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/api/ApiUrl.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.api; 2 | 3 | /** 4 | * 接口URL 5 | */ 6 | public class ApiUrl { 7 | 8 | //region 默认参数,每个请求都会有 9 | public final static String UID = "uid";//GG号(加密后) 10 | public final static String MID = "mid"; // 手机唯一识别码 11 | public final static String PID = "pid"; // 整型 手机渠道号id,用来区分推荐的渠道,如360, 百度 12 | public final static String IMEI = "imei"; //手机IMEI号 13 | public final static String M_VER = "m_ver"; //手机版本号 14 | public final static String S_VER = "s_ver";//手机系统版本 15 | public final static String IMEI_TIME = "imeiTime";//app安装后首次打开时间 16 | 17 | public final static String PASS = "pass"; // 参数加密结果 18 | public final static String VERSIONNAME = "versionName"; // 当前版本名称 19 | public final static String VERSIONCODE = "versionCode"; // 当前版本id 20 | public final static String TIMESTAMP = "timestamp"; // 请求时间戳 21 | public final static String FROM = "from"; // 源于 22 | //endregion 23 | 24 | //region 常用参数 25 | public final static String PN = "pn";//页码 26 | public final static String PS = "ps";//每页条数 27 | public final static int PN_V = 1;//页码 28 | public final static int PS_V = 10;//每页条数 29 | public final static String STATUS = "status";//状态 30 | public final static String TYPE_ID = "type_id";//类型 31 | public final static String ENCRYPT_ID = "encryptId";//加密用户Id 32 | public static final String ID = "id";//唯一标示 33 | public static final String BOOK_ID = "bookId";//书Id 34 | public static final String MENU_ID = "menuId";//章节Id 35 | /** 设备唯一识别码 */ 36 | public static final String UUID = "UUID"; 37 | //endregion 38 | 39 | public static String URL_DOMAIN = "";//正式服务器 40 | public static String MD5KEY = ""; // 加密key 41 | 42 | } 43 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/BitmapCommonUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | import android.content.Context; 19 | import android.graphics.Bitmap; 20 | import android.os.Environment; 21 | import android.os.StatFs; 22 | 23 | import java.io.File; 24 | 25 | public class BitmapCommonUtils { 26 | 27 | /** 28 | * 获取可以使用的缓存目录 29 | * @param context 30 | * @param uniqueName 目录名称 31 | * @return 32 | */ 33 | public static File getDiskCacheDir(Context context, String uniqueName) { 34 | final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ? 35 | getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); 36 | 37 | return new File(cachePath + File.separator + uniqueName); 38 | } 39 | 40 | 41 | 42 | /** 43 | * 获取bitmap的字节大小 44 | * @param bitmap 45 | * @return 46 | */ 47 | public static int getBitmapSize(Bitmap bitmap) { 48 | return bitmap.getRowBytes() * bitmap.getHeight(); 49 | } 50 | 51 | 52 | /** 53 | * 获取程序外部的缓存目录 54 | * @param context 55 | * @return 56 | */ 57 | public static File getExternalCacheDir(Context context) { 58 | // final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; 59 | return new File(Environment.getExternalStorageDirectory().getPath()); 60 | } 61 | 62 | /** 63 | * 获取文件路径空间大小 64 | * @param path 65 | * @return 66 | */ 67 | public static long getUsableSpace(File path) { 68 | final StatFs stats = new StatFs(Environment.getExternalStorageDirectory().getPath()); 69 | return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/BitmapDecoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | import android.content.res.Resources; 19 | import android.graphics.Bitmap; 20 | import android.graphics.BitmapFactory; 21 | 22 | import java.io.FileDescriptor; 23 | 24 | public class BitmapDecoder { 25 | private BitmapDecoder(){} 26 | 27 | public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,int reqWidth, int reqHeight) { 28 | 29 | final BitmapFactory.Options options = new BitmapFactory.Options(); 30 | options.inJustDecodeBounds = true; 31 | options.inPurgeable = true; 32 | BitmapFactory.decodeResource(res, resId, options); 33 | 34 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 35 | 36 | options.inJustDecodeBounds = false; 37 | return BitmapFactory.decodeResource(res, resId, options); 38 | } 39 | 40 | public static Bitmap decodeSampledBitmapFromFile(String filename,int reqWidth, int reqHeight) { 41 | 42 | final BitmapFactory.Options options = new BitmapFactory.Options(); 43 | options.inJustDecodeBounds = true; 44 | options.inPurgeable = true; 45 | BitmapFactory.decodeFile(filename, options); 46 | 47 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 48 | 49 | options.inJustDecodeBounds = false; 50 | return BitmapFactory.decodeFile(filename, options); 51 | } 52 | 53 | public static Bitmap decodeSampledBitmapFromDescriptor(FileDescriptor fileDescriptor, int reqWidth, int reqHeight) { 54 | 55 | final BitmapFactory.Options options = new BitmapFactory.Options(); 56 | options.inJustDecodeBounds = true; 57 | options.inPurgeable = true; 58 | BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); 59 | 60 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 61 | 62 | options.inJustDecodeBounds = false; 63 | return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); 64 | } 65 | 66 | public static int calculateInSampleSize(BitmapFactory.Options options,int reqWidth, int reqHeight) { 67 | final int height = options.outHeight; 68 | final int width = options.outWidth; 69 | int inSampleSize = 1; 70 | 71 | if (height > reqHeight || width > reqWidth) { 72 | if (width > height) { 73 | inSampleSize = Math.round((float) height / (float) reqHeight); 74 | } else { 75 | inSampleSize = Math.round((float) width / (float) reqWidth); 76 | } 77 | 78 | final float totalPixels = width * height; 79 | 80 | final float totalReqPixelsCap = reqWidth * reqHeight * 2; 81 | 82 | while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) { 83 | inSampleSize++; 84 | } 85 | } 86 | return inSampleSize; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/BitmapDisplayConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | import android.content.Context; 19 | import android.graphics.Bitmap; 20 | import android.graphics.BitmapFactory; 21 | import android.support.annotation.DimenRes; 22 | import android.view.animation.Animation; 23 | 24 | import com.minggo.pluto.util.DisplayUtil; 25 | 26 | 27 | public class BitmapDisplayConfig { 28 | 29 | 30 | private int bitmapWidth; 31 | private int bitmapHeight; 32 | 33 | private Animation animation; 34 | 35 | private int animationType; 36 | private Bitmap loadingBitmap; 37 | private Bitmap loadfailBitmap; 38 | 39 | 40 | public int getBitmapWidth() { 41 | return bitmapWidth; 42 | } 43 | 44 | public void setBitmapWidth(int bitmapWidth) { 45 | this.bitmapWidth = bitmapWidth; 46 | } 47 | 48 | public int getBitmapHeight() { 49 | return bitmapHeight; 50 | } 51 | 52 | public void setBitmapHeight(int bitmapHeight) { 53 | this.bitmapHeight = bitmapHeight; 54 | } 55 | 56 | public Animation getAnimation() { 57 | return animation; 58 | } 59 | 60 | public void setAnimation(Animation animation) { 61 | this.animation = animation; 62 | } 63 | 64 | public int getAnimationType() { 65 | return animationType; 66 | } 67 | 68 | public void setAnimationType(int animationType) { 69 | this.animationType = animationType; 70 | } 71 | 72 | public Bitmap getLoadingBitmap() { 73 | return loadingBitmap; 74 | } 75 | 76 | public void setLoadingBitmap(Bitmap loadingBitmap) { 77 | this.loadingBitmap = loadingBitmap; 78 | } 79 | 80 | public Bitmap getLoadfailBitmap() { 81 | return loadfailBitmap; 82 | } 83 | 84 | public void setLoadfailBitmap(Bitmap loadfailBitmap) { 85 | this.loadfailBitmap = loadfailBitmap; 86 | } 87 | 88 | 89 | public class AnimationType{ 90 | public static final int userDefined = 0; 91 | public static final int fadeIn = 1; 92 | } 93 | 94 | public static BitmapDisplayConfig getDefaultUserAvatarConfig(Context context, int bitmapPxSize) { 95 | BitmapDisplayConfig bitmapDisplayConfig = new BitmapDisplayConfig(); 96 | bitmapDisplayConfig.setAnimationType(BitmapDisplayConfig.AnimationType.fadeIn); 97 | 98 | if (bitmapPxSize > 0) { 99 | bitmapDisplayConfig.setBitmapWidth(bitmapPxSize); 100 | bitmapDisplayConfig.setBitmapHeight(bitmapPxSize); 101 | } 102 | return bitmapDisplayConfig; 103 | } 104 | 105 | public static BitmapDisplayConfig getDefaultUserAvatarConfigByDp(Context context, int dp) { 106 | int dp2px = DisplayUtil.dip2px(context, dp); 107 | return getDefaultUserAvatarConfig(context, dp2px); 108 | } 109 | 110 | public static BitmapDisplayConfig getDefaultUserAvatarConfigByDpRes(Context context, @DimenRes int dpRes) { 111 | int dp2px = context.getResources().getDimensionPixelSize(dpRes); 112 | return getDefaultUserAvatarConfig(context, dp2px); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/ChargeVersionUtils.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.bitmap; 2 | 3 | 4 | import android.os.Build; 5 | 6 | /** 7 | * 用于判断当前系统的版本 8 | * @author minggo 9 | * 在sdk4.1下编译才能通过 10 | */ 11 | public class ChargeVersionUtils { 12 | private ChargeVersionUtils() {}; 13 | 14 | public static boolean hasFroyo() { 15 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO; 16 | } 17 | 18 | public static boolean hasGingerbread() { 19 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; 20 | } 21 | 22 | public static boolean hasHoneycomb() { 23 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 24 | } 25 | 26 | public static boolean hasHoneycombMR1() { 27 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1; 28 | } 29 | 30 | public static boolean hasJellyBean() { 31 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/Displayer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | import android.graphics.Bitmap; 19 | import android.widget.ImageView; 20 | 21 | 22 | public interface Displayer { 23 | 24 | /** 25 | * 图片加载完成 回调的函数 26 | * @param imageView 27 | * @param bitmap 28 | * @param config 29 | */ 30 | public void loadCompletedisplay(ImageView imageView, Bitmap bitmap, BitmapDisplayConfig config); 31 | 32 | /** 33 | * 图片加载失败回调的函数 34 | * @param imageView 35 | * @param bitmap 36 | */ 37 | public void loadFailDisplay(ImageView imageView, Bitmap bitmap); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/Downloader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | import java.io.OutputStream; 19 | 20 | public interface Downloader { 21 | 22 | /** 23 | * 请求网络的inputStream填充outputStream 24 | * @param urlString 25 | * @param outputStream 26 | * @return 27 | */ 28 | public boolean downloadToLocalStreamByUrl(String urlString, OutputStream outputStream); 29 | } 30 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/FileNameGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | import java.security.MessageDigest; 19 | import java.security.NoSuchAlgorithmException; 20 | 21 | public class FileNameGenerator { 22 | 23 | 24 | public static String generator(String key) { 25 | String cacheKey; 26 | try { 27 | final MessageDigest mDigest = MessageDigest.getInstance("MD5"); 28 | mDigest.update(key.getBytes()); 29 | cacheKey = bytesToHexString(mDigest.digest()); 30 | } catch (NoSuchAlgorithmException e) { 31 | cacheKey = String.valueOf(key.hashCode()); 32 | } 33 | return cacheKey; 34 | } 35 | 36 | private static String bytesToHexString(byte[] bytes) { 37 | // http://stackoverflow.com/questions/332079 38 | StringBuilder sb = new StringBuilder(); 39 | for (int i = 0; i < bytes.length; i++) { 40 | String hex = Integer.toHexString(0xFF & bytes[i]); 41 | if (hex.length() == 1) { 42 | sb.append('0'); 43 | } 44 | sb.append(hex); 45 | } 46 | return sb.toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/RecyclingBitmapDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.minggo.pluto.bitmap; 18 | 19 | import android.content.res.Resources; 20 | import android.graphics.Bitmap; 21 | import android.graphics.drawable.BitmapDrawable; 22 | 23 | /** 24 | * A BitmapDrawable that keeps track of whether it is being displayed or cached. 25 | * When the drawable is no longer being displayed or cached, 26 | * {@link Bitmap#recycle() recycle()} will be called on this drawable's bitmap. 27 | */ 28 | public class RecyclingBitmapDrawable extends BitmapDrawable { 29 | 30 | static final String LOG_TAG = "CountingBitmapDrawable"; 31 | 32 | private int mCacheRefCount = 0; 33 | private int mDisplayRefCount = 0; 34 | 35 | private boolean mHasBeenDisplayed; 36 | 37 | public RecyclingBitmapDrawable(Resources res, Bitmap bitmap) { 38 | super(res, bitmap); 39 | } 40 | 41 | /** 42 | * Notify the drawable that the displayed state has changed. Internally a 43 | * count is kept so that the drawable knows when it is no longer being 44 | * displayed. 45 | * 46 | * @param isDisplayed - Whether the drawable is being displayed or not 47 | */ 48 | public void setIsDisplayed(boolean isDisplayed) { 49 | synchronized (this) { 50 | if (isDisplayed) { 51 | mDisplayRefCount++; 52 | mHasBeenDisplayed = true; 53 | } else { 54 | mDisplayRefCount--; 55 | } 56 | } 57 | 58 | // Check to see if recycle() can be called 59 | checkState(); 60 | } 61 | 62 | /** 63 | * Notify the drawable that the cache state has changed. Internally a count 64 | * is kept so that the drawable knows when it is no longer being cached. 65 | * 66 | * @param isCached - Whether the drawable is being cached or not 67 | */ 68 | public void setIsCached(boolean isCached) { 69 | synchronized (this) { 70 | if (isCached) { 71 | mCacheRefCount++; 72 | } else { 73 | mCacheRefCount--; 74 | } 75 | } 76 | 77 | // Check to see if recycle() can be called 78 | checkState(); 79 | } 80 | 81 | private synchronized void checkState() { 82 | // If the drawable cache and display ref counts = 0, and this drawable 83 | // has been displayed, then recycle 84 | if (mCacheRefCount <= 0 && mDisplayRefCount <= 0 && mHasBeenDisplayed 85 | && hasValidBitmap()) { 86 | getBitmap().recycle(); 87 | } 88 | } 89 | 90 | private synchronized boolean hasValidBitmap() { 91 | Bitmap bitmap = getBitmap(); 92 | return bitmap != null && !bitmap.isRecycled(); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/RecyclingImageView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.minggo.pluto.bitmap; 18 | 19 | import android.content.Context; 20 | import android.graphics.drawable.Drawable; 21 | import android.graphics.drawable.LayerDrawable; 22 | import android.util.AttributeSet; 23 | import android.widget.ImageView; 24 | 25 | /** 26 | * Sub-class of ImageView which automatically notifies the drawable when it is 27 | * being displayed. 28 | */ 29 | public class RecyclingImageView extends ImageView { 30 | 31 | public RecyclingImageView(Context context) { 32 | super(context); 33 | } 34 | 35 | public RecyclingImageView(Context context, AttributeSet attrs) { 36 | super(context, attrs); 37 | } 38 | 39 | /** 40 | * @see ImageView#onDetachedFromWindow() 41 | */ 42 | @Override 43 | protected void onDetachedFromWindow() { 44 | // This has been detached from Window, so clear the drawable 45 | setImageDrawable(null); 46 | 47 | super.onDetachedFromWindow(); 48 | } 49 | 50 | /** 51 | * @see ImageView#setImageDrawable(Drawable) 52 | */ 53 | @Override 54 | public void setImageDrawable(Drawable drawable) { 55 | // Keep hold of previous Drawable 56 | final Drawable previousDrawable = getDrawable(); 57 | 58 | // Call super to set new Drawable 59 | super.setImageDrawable(drawable); 60 | 61 | // Notify new Drawable that it is being displayed 62 | notifyDrawable(drawable, true); 63 | 64 | // Notify old Drawable so it is no longer being displayed 65 | notifyDrawable(previousDrawable, false); 66 | } 67 | 68 | /** 69 | * Notifies the drawable that it's displayed state has changed. 70 | * 71 | * @param drawable 72 | * @param isDisplayed 73 | */ 74 | private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) { 75 | if (drawable instanceof RecyclingBitmapDrawable) { 76 | // The drawable is a CountingBitmapDrawable, so notify it 77 | ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed); 78 | } else if (drawable instanceof LayerDrawable) { 79 | // The drawable is a LayerDrawable, so recurse on each layer 80 | LayerDrawable layerDrawable = (LayerDrawable) drawable; 81 | for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) { 82 | notifyDrawable(layerDrawable.getDrawable(i), isDisplayed); 83 | } 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/SimpleDisplayer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | import android.graphics.Bitmap; 19 | import android.graphics.drawable.BitmapDrawable; 20 | import android.graphics.drawable.ColorDrawable; 21 | import android.graphics.drawable.Drawable; 22 | import android.graphics.drawable.TransitionDrawable; 23 | import android.view.animation.Animation; 24 | import android.view.animation.AnimationUtils; 25 | import android.widget.ImageView; 26 | 27 | 28 | public class SimpleDisplayer implements Displayer{ 29 | 30 | public void loadCompletedisplay(ImageView imageView,Bitmap bitmap,BitmapDisplayConfig config){ 31 | switch (config.getAnimationType()) { 32 | case BitmapDisplayConfig.AnimationType.fadeIn: 33 | fadeInDisplay(imageView,bitmap); 34 | break; 35 | case BitmapDisplayConfig.AnimationType.userDefined: 36 | animationDisplay(imageView,bitmap,config.getAnimation()); 37 | break; 38 | default: 39 | break; 40 | } 41 | } 42 | 43 | 44 | public void loadFailDisplay(ImageView imageView,Bitmap bitmap){ 45 | imageView.setImageBitmap(bitmap); 46 | } 47 | 48 | 49 | 50 | private void fadeInDisplay(ImageView imageView,Bitmap bitmap){ 51 | final TransitionDrawable td = 52 | new TransitionDrawable(new Drawable[] { 53 | new ColorDrawable(android.R.color.transparent), 54 | new BitmapDrawable(imageView.getResources(), bitmap) 55 | }); 56 | imageView.setImageDrawable(td); 57 | td.startTransition(300); 58 | } 59 | 60 | 61 | private void animationDisplay(ImageView imageView,Bitmap bitmap,Animation animation){ 62 | animation.setStartTime(AnimationUtils.currentAnimationTimeMillis()); 63 | imageView.setImageBitmap(bitmap); 64 | imageView.startAnimation(animation); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/SimpleHttpDownloader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.bitmap; 17 | 18 | 19 | import com.minggo.pluto.util.LogUtils; 20 | 21 | import java.io.BufferedInputStream; 22 | import java.io.BufferedOutputStream; 23 | import java.io.FileInputStream; 24 | import java.io.FilterInputStream; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | import java.net.HttpURLConnection; 29 | import java.net.URL; 30 | 31 | 32 | public class SimpleHttpDownloader implements Downloader{ 33 | 34 | private static final String TAG = "BitmapDownloader"; 35 | 36 | private static final int IO_BUFFER_SIZE = 8 * 1024; //8k 37 | 38 | /** 39 | * 把网络图片转下载到文件的 outputStream 40 | * @param urlString 41 | * @param outputStream 42 | * @return 43 | */ 44 | public boolean downloadToLocalStreamByUrl(String urlString, OutputStream outputStream) { 45 | HttpURLConnection urlConnection = null; 46 | BufferedOutputStream out = null; 47 | FlushedInputStream in = null; 48 | 49 | try { 50 | if (urlString.contains("http")) {//获取网络图片 51 | final URL url = new URL(urlString); 52 | urlConnection = (HttpURLConnection) url.openConnection(); 53 | in = new FlushedInputStream(new BufferedInputStream(urlConnection.getInputStream(), IO_BUFFER_SIZE)); 54 | }else{//获取本地图片 55 | InputStream inputStream = new FileInputStream(urlString); 56 | in = new FlushedInputStream(new BufferedInputStream(inputStream, IO_BUFFER_SIZE)); 57 | } 58 | out = new BufferedOutputStream(outputStream, IO_BUFFER_SIZE); 59 | 60 | int b; 61 | while ((b = in.read()) != -1) { 62 | out.write(b); 63 | } 64 | return true; 65 | } catch (final IOException e) { 66 | LogUtils.error(TAG, "Error in downloadBitmap - " + urlString + " : " + e); 67 | } finally { 68 | if (urlConnection != null) { 69 | urlConnection.disconnect(); 70 | } 71 | try { 72 | if (out != null) { 73 | out.close(); 74 | } 75 | if (in != null) { 76 | in.close(); 77 | } 78 | } catch (final IOException e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | return false; 83 | } 84 | 85 | 86 | public class FlushedInputStream extends FilterInputStream { 87 | 88 | public FlushedInputStream(InputStream inputStream) { 89 | super(inputStream); 90 | } 91 | 92 | @Override 93 | public long skip(long n) throws IOException { 94 | long totalBytesSkipped = 0L; 95 | while (totalBytesSkipped < n) { 96 | long bytesSkipped = in.skip(n - totalBytesSkipped); 97 | if (bytesSkipped == 0L) { 98 | int by_te = read(); 99 | if (by_te < 0) { 100 | break; // we reached EOF 101 | } else { 102 | bytesSkipped = 1; // we read one byte 103 | } 104 | } 105 | totalBytesSkipped += bytesSkipped; 106 | } 107 | return totalBytesSkipped; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/bitmap/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.minggo.pluto.bitmap; 18 | 19 | import android.annotation.TargetApi; 20 | import android.os.Build; 21 | import android.os.StrictMode; 22 | 23 | /** 24 | * Class containing some static utility methods. 25 | */ 26 | public class Utils { 27 | private Utils() {}; 28 | /** 29 | * 需要设置哪个页面的限制缓存到VM中 30 | */ 31 | @TargetApi(11) 32 | public static void enableStrictMode(Class clazz) { 33 | if (Utils.hasGingerbread()) { 34 | StrictMode.ThreadPolicy.Builder threadPolicyBuilder = 35 | new StrictMode.ThreadPolicy.Builder() 36 | .detectAll() 37 | .penaltyLog(); 38 | StrictMode.VmPolicy.Builder vmPolicyBuilder = 39 | new StrictMode.VmPolicy.Builder() 40 | .detectAll() 41 | .penaltyLog(); 42 | 43 | if (Utils.hasHoneycomb()) { 44 | threadPolicyBuilder.penaltyFlashScreen(); 45 | vmPolicyBuilder.setClassInstanceLimit(clazz, 1); 46 | } 47 | StrictMode.setThreadPolicy(threadPolicyBuilder.build()); 48 | StrictMode.setVmPolicy(vmPolicyBuilder.build()); 49 | } 50 | } 51 | 52 | public static boolean hasFroyo() { 53 | // Can use static final constants like FROYO, declared in later versions 54 | // of the OS since they are inlined at compile time. This is guaranteed behavior. 55 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO; 56 | } 57 | 58 | public static boolean hasGingerbread() { 59 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; 60 | } 61 | 62 | public static boolean hasHoneycomb() { 63 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 64 | } 65 | 66 | public static boolean hasHoneycombMR1() { 67 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1; 68 | } 69 | 70 | public static boolean hasJellyBean() { 71 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/common/AppContext.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.common; 2 | 3 | import android.content.Context; 4 | import android.content.pm.ApplicationInfo; 5 | import android.content.pm.PackageInfo; 6 | import android.content.pm.PackageManager; 7 | import android.content.pm.PackageManager.NameNotFoundException; 8 | import android.provider.Settings.Secure; 9 | import android.telephony.TelephonyManager; 10 | import android.text.TextUtils; 11 | 12 | import com.minggo.pluto.util.LogUtils; 13 | import com.minggo.pluto.util.NetworkUtils; 14 | import com.minggo.pluto.util.StringUtils; 15 | 16 | 17 | /** 18 | * 应用上下文 19 | * 20 | * @author minggo 21 | * @time 2014-12-2下午2:09:33 22 | */ 23 | public class AppContext { 24 | 25 | private static AppContext appContext; 26 | 27 | 28 | private AsyncTaskManager asyncTaskManager; 29 | private String mPlatformId; 30 | public Context context; 31 | 32 | public AppContext() { 33 | } 34 | public static void initAppContent(Context context){ 35 | AppContext appContext = getInstance(); 36 | appContext.context = context; 37 | } 38 | public static AppContext getInstance() { 39 | if (null == appContext) { 40 | appContext = new AppContext(); 41 | 42 | 43 | } 44 | return appContext; 45 | } 46 | 47 | public AsyncTaskManager getAsyncTaskManager() { 48 | 49 | if (asyncTaskManager == null) { 50 | asyncTaskManager = new AsyncTaskManager(); 51 | } 52 | 53 | return asyncTaskManager; 54 | } 55 | 56 | /** 57 | * 检测网络是否可用 58 | */ 59 | public boolean isNetworkConnected() { 60 | return NetworkUtils.isNetworkConnected(context); 61 | } 62 | 63 | public static boolean isNetworkConnected(Context context) { 64 | return NetworkUtils.isNetworkConnected(context); 65 | } 66 | 67 | /** 68 | * 获取当前网络类型 69 | * 70 | * @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络 71 | */ 72 | public int getNetworkType() { 73 | return NetworkUtils.getNetworkType(context); 74 | } 75 | 76 | /** 77 | * 获取手机唯一识别码 78 | * 79 | * @return 80 | */ 81 | public String getAndroidId(int bookid) { 82 | // String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); 83 | // 84 | // if (android_id == null || android_id == "") { 85 | // android_id = android.os.Build.VERSION.RELEASE + android.os.Build.MODEL + bookid; 86 | // } 87 | // if (StringUtils.isEmpty(android_id)) { 88 | // android_id = ""; 89 | // } 90 | // return android_id; 91 | return "idonotneeddeviceid"; 92 | } 93 | 94 | /** 95 | * 获取手机的IMEI 96 | * 97 | * @return 98 | */ 99 | public String getAndroidIMEI() { 100 | //TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 101 | //String imei = telephonyManager.getDeviceId(); 102 | 103 | return "idonotneedimei"; 104 | } 105 | 106 | /** 107 | * 获取手机型号 108 | * 109 | * @return 110 | */ 111 | public String GetMobileVersion() { 112 | return android.os.Build.MODEL; 113 | } 114 | 115 | /** 116 | * 获取系统的版本号 117 | * 118 | * @return 119 | */ 120 | public String GetAndroidVersion() { 121 | return android.os.Build.VERSION.RELEASE; 122 | } 123 | 124 | /** 125 | * 获取App安装包信息 126 | * 127 | * @return 128 | */ 129 | public PackageInfo getPackageInfo() { 130 | PackageInfo info = null; 131 | try { 132 | info = context.getPackageManager() 133 | .getPackageInfo(context.getPackageName(), 0); 134 | } catch (NameNotFoundException e) { 135 | e.printStackTrace(System.err); 136 | } 137 | if (info == null) { 138 | info = new PackageInfo(); 139 | } 140 | return info; 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/common/AppManager.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.common; 2 | 3 | import android.app.Activity; 4 | import android.app.NotificationManager; 5 | import android.content.Context; 6 | import android.text.TextUtils; 7 | 8 | import java.util.Stack; 9 | 10 | /** 11 | * 应用程序Activity管理类:用于Activity管理和应用程序退出 12 | * @author minggo 13 | * @time 2014-12-2下午2:34:39 14 | */ 15 | public class AppManager { 16 | 17 | private static final String TAG = AppManager.class.getSimpleName(); 18 | private static Stack activityStack; 19 | private static AppManager instance; 20 | 21 | private AppManager() { 22 | } 23 | 24 | /** 25 | * 单一实例 26 | */ 27 | public static AppManager getAppManager() { 28 | if (instance == null) { 29 | instance = new AppManager(); 30 | } 31 | return instance; 32 | } 33 | 34 | /** 35 | * 添加Activity到堆栈 36 | */ 37 | public void addActivity(Activity activity) { 38 | if (activityStack == null) { 39 | activityStack = new Stack(); 40 | } 41 | activityStack.add(activity); 42 | } 43 | 44 | /** 45 | * 获取当前Activity(堆栈中最后一个压入的) 46 | */ 47 | public Activity currentActivity() { 48 | Activity activity = activityStack.lastElement(); 49 | return activity; 50 | } 51 | 52 | /** 53 | * 结束当前Activity(堆栈中最后一个压入的) 54 | */ 55 | public void finishActivity() { 56 | Activity activity = activityStack.lastElement(); 57 | finishActivity(activity); 58 | activityStack.remove(activity); 59 | } 60 | 61 | /** 62 | * 结束指定的Activity 63 | */ 64 | public void finishActivity(Activity activity) { 65 | if (activity != null) { 66 | activityStack.remove(activity); 67 | //activity.finish(); 68 | activity = null; 69 | } 70 | } 71 | 72 | /** 73 | *  从栈中取出activity 74 | * @param activity 75 | */ 76 | public void removeActivity(Activity activity){ 77 | if (activity !=null){ 78 | activityStack.remove(activity); 79 | } 80 | } 81 | 82 | /** 83 | * 结束指定类名的Activity 84 | */ 85 | public void finishActivity(Class cls) { 86 | for (Activity activity : activityStack) { 87 | if (activity.getClass().equals(cls)) { 88 | finishActivity(activity); 89 | } 90 | } 91 | } 92 | 93 | /** 94 | * 获取当前所有的Activity的总和 95 | * 96 | * @return 97 | */ 98 | public int getCountActivity() { 99 | return activityStack.size(); 100 | } 101 | 102 | /** 103 | * 结束所有Activity 104 | */ 105 | public void finishAllActivity() { 106 | for (int i = 0, size = activityStack.size(); i < size; i++) { 107 | if (null != activityStack.get(i)) { 108 | activityStack.get(i).finish(); 109 | } 110 | } 111 | activityStack.clear(); 112 | } 113 | 114 | /** 115 | * 清除所有通知 116 | */ 117 | private void cancelAllNotification(Context context) { 118 | NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 119 | notificationManager.cancelAll(); 120 | } 121 | 122 | } -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/common/AsyncTaskManager.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.common; 2 | 3 | 4 | import com.minggo.pluto.util.LogUtils; 5 | 6 | import java.util.Observable; 7 | import java.util.Observer; 8 | 9 | /** 10 | * 异步任务管理器 11 | * @author minggo 12 | * @time 2014-12-2下午2:12:23 13 | */ 14 | public class AsyncTaskManager extends Observable { 15 | 16 | private static final String TAG = "AsyncTaskManager"; 17 | 18 | public static final Integer CANCEL_ALL = 1; 19 | 20 | /** 21 | * 该方法不要写在onDestroy()方法中,以免引起下个Activity的异步任务中断 22 | */ 23 | public void cancelAll() { 24 | LogUtils.debug(TAG, "All asynctask will Cancell."); 25 | setChanged(); 26 | notifyObservers(CANCEL_ALL); 27 | } 28 | 29 | public void addTask(Observer task) { 30 | super.addObserver(task); 31 | } 32 | } -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/manager/DataManager.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.db.manager; 2 | 3 | /** 4 | * Created by minggo on 2017/2/21. 5 | */ 6 | 7 | public interface DataManager { 8 | 9 | void saveData(Object key,Object object); 10 | T queryData(Object key,Class clazz); 11 | void deleteData(Object key,Class clazz); 12 | void updateData(Object key,Object object); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/manager/DataManagerStub.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.db.manager; 2 | 3 | /** 4 | * Created by minggo on 2017/2/21. 5 | */ 6 | 7 | public class DataManagerStub implements DataManager { 8 | 9 | 10 | @Override 11 | public void saveData(Object key, Object object) { 12 | 13 | } 14 | 15 | @Override 16 | public T queryData(Object key, Class clazz) { 17 | return null; 18 | } 19 | 20 | @Override 21 | public void deleteData(Object key, Class clazz) { 22 | 23 | } 24 | 25 | @Override 26 | public void updateData(Object key, Object object) { 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/CursorUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import android.database.Cursor; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map.Entry; 22 | 23 | public class CursorUtils { 24 | 25 | public static T getEntity(Cursor cursor, Class clazz,FinalDb db){ 26 | try { 27 | if(cursor!=null ){ 28 | TableInfo table = TableInfo.get(clazz); 29 | int columnCount = cursor.getColumnCount(); 30 | if(columnCount>0){ 31 | T entity = (T) clazz.newInstance(); 32 | for(int i=0;i 0){ 79 | DbModel model = new DbModel(); 80 | int columnCount = cursor.getColumnCount(); 81 | for(int i=0;i T dbModel2Entity(DbModel dbModel,Class clazz){ 91 | if(dbModel!=null){ 92 | HashMap dataMap = dbModel.getDataMap(); 93 | try { 94 | @SuppressWarnings("unchecked") 95 | T entity = (T) clazz.newInstance(); 96 | for(Entry entry : dataMap.entrySet()){ 97 | String column = entry.getKey(); 98 | TableInfo table = TableInfo.get(clazz); 99 | Property property = table.propertyMap.get(column); 100 | if(property!=null){ 101 | property.setValue(entity, entry.getValue()==null?null:entry.getValue().toString()); 102 | }else{ 103 | if(table.getId().getColumn().equals(column)){ 104 | table.getId().setValue(entity, entry.getValue()==null?null:entry.getValue().toString()); 105 | } 106 | } 107 | 108 | } 109 | return entity; 110 | } catch (Exception e) { 111 | e.printStackTrace(); 112 | } 113 | } 114 | 115 | return null; 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/DbException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | public class DbException extends RuntimeException { 19 | private static final long serialVersionUID = 1L; 20 | 21 | public DbException() { 22 | super(); 23 | } 24 | 25 | public DbException(String msg) { 26 | super(msg); 27 | } 28 | 29 | public DbException(Throwable ex) { 30 | super(ex); 31 | } 32 | 33 | public DbException(String msg,Throwable ex) { 34 | super(msg,ex); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/DbModel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.util.HashMap; 19 | 20 | public class DbModel { 21 | 22 | private HashMap dataMap = new HashMap(); 23 | 24 | public Object get(String column){ 25 | return dataMap.get(column); 26 | } 27 | 28 | public String getString(String column){ 29 | return String.valueOf(get(column)); 30 | } 31 | 32 | public int getInt(String column){ 33 | return Integer.valueOf(getString(column)); 34 | } 35 | 36 | public boolean getBoolean(String column){ 37 | return Boolean.valueOf(getString(column)); 38 | } 39 | 40 | public double getDouble(String column){ 41 | return Double.valueOf(getString(column)); 42 | } 43 | 44 | public float getFloat(String column){ 45 | return Float.valueOf(getString(column)); 46 | } 47 | 48 | public long getLong(String column){ 49 | return Long.valueOf(getString(column)); 50 | } 51 | 52 | public void set(String key,Object value){ 53 | dataMap.put(key, value); 54 | } 55 | 56 | public HashMap getDataMap(){ 57 | return dataMap; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/Id.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | 19 | public class Id extends Property{ 20 | 21 | } 22 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/Id_A.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @title Id主键配置 25 | * @description 不配置的时候默认找类的id或_id字段作为主键,column不配置的是默认为字段名 26 | * @author michael Young (www.YangFuhai.com) 27 | * @version 1.0 28 | * @created 2012-10-31 29 | */ 30 | @Target(ElementType.FIELD) 31 | @Retention(RetentionPolicy.RUNTIME) 32 | public @interface Id_A { 33 | public String column() default ""; 34 | } 35 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/KeyValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | 19 | public class KeyValue { 20 | private String key; 21 | private Object value; 22 | 23 | public KeyValue(String key, Object value) { 24 | this.key = key; 25 | this.value = value; 26 | } 27 | 28 | 29 | public KeyValue() {} 30 | 31 | 32 | public String getKey() { 33 | return key; 34 | } 35 | public void setKey(String key) { 36 | this.key = key; 37 | } 38 | public Object getValue() { 39 | if(value instanceof java.util.Date || value instanceof java.sql.Date){ 40 | return FieldUtils.SDF.format(value); 41 | } 42 | return value; 43 | } 44 | public void setValue(Object value) { 45 | this.value = value; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/ManyToOne.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | 19 | public class ManyToOne extends Property{ 20 | 21 | private Class manyClass; 22 | 23 | public Class getManyClass() { 24 | return manyClass; 25 | } 26 | 27 | public void setManyClass(Class manyClass) { 28 | this.manyClass = manyClass; 29 | } 30 | 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/ManyToOneLazyLoader.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.db.orm; 2 | 3 | 4 | /** 5 | * 6 | * 一对多延迟加载类 7 | * Created by pwy on 13-7-25. 8 | * @param 宿主实体的class 9 | * @param 多放实体class 10 | */ 11 | public class ManyToOneLazyLoader { 12 | M manyEntity; 13 | Class manyClazz; 14 | Class oneClazz; 15 | FinalDb db; 16 | /** 17 | * 用于 18 | */ 19 | private Object fieldValue; 20 | public ManyToOneLazyLoader(M manyEntity, Class manyClazz, Class oneClazz, FinalDb db){ 21 | this.manyEntity = manyEntity; 22 | this.manyClazz = manyClazz; 23 | this.oneClazz = oneClazz; 24 | this.db = db; 25 | } 26 | O oneEntity; 27 | boolean hasLoaded = false; 28 | 29 | /** 30 | * 如果数据未加载,则调用loadManyToOne填充数据 31 | * @return 32 | */ 33 | public O get(){ 34 | if(oneEntity==null && !hasLoaded){ 35 | this.db.loadManyToOne(null,this.manyEntity,this.manyClazz,this.oneClazz); 36 | hasLoaded = true; 37 | } 38 | return oneEntity; 39 | } 40 | public void set(O value){ 41 | oneEntity = value; 42 | } 43 | 44 | public Object getFieldValue() { 45 | return fieldValue; 46 | } 47 | 48 | public void setFieldValue(Object fieldValue) { 49 | this.fieldValue = fieldValue; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/ManyToOne_A.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Target(ElementType.FIELD) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | public @interface ManyToOne_A { 26 | public String column() default ""; 27 | } 28 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/OneToMany.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | 19 | public class OneToMany extends Property{ 20 | 21 | private Class oneClass; 22 | 23 | public Class getOneClass() { 24 | return oneClass; 25 | } 26 | 27 | public void setOneClass(Class oneClass) { 28 | this.oneClass = oneClass; 29 | } 30 | 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/OneToManyLazyLoader.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.db.orm; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | 8 | /** 9 | * 10 | * 一对多延迟加载类 11 | * Created by pwy on 13-7-25. 12 | * @param 宿主实体的class 13 | * @param 多放实体class 14 | */ 15 | public class OneToManyLazyLoader { 16 | O ownerEntity; 17 | Class ownerClazz; 18 | Class listItemClazz; 19 | FinalDb db; 20 | public OneToManyLazyLoader(O ownerEntity,Class ownerClazz,Class listItemclazz,FinalDb db){ 21 | this.ownerEntity = ownerEntity; 22 | this.ownerClazz = ownerClazz; 23 | this.listItemClazz = listItemclazz; 24 | this.db = db; 25 | } 26 | List entities; 27 | 28 | /** 29 | * 如果数据未加载,则调用loadOneToMany填充数据 30 | * @return 31 | */ 32 | public List getList(){ 33 | if(entities==null){ 34 | this.db.loadOneToMany((O)this.ownerEntity,this.ownerClazz,this.listItemClazz); 35 | } 36 | if(entities==null){ 37 | entities =new ArrayList(); 38 | } 39 | return entities; 40 | } 41 | public void setList(List value){ 42 | entities = value; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/OneToMany_A.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Target(ElementType.FIELD) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | public @interface OneToMany_A { 26 | 27 | public String manyColumn(); 28 | } 29 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/Property.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.lang.reflect.Field; 19 | import java.lang.reflect.Method; 20 | import java.util.Date; 21 | 22 | 23 | /** 24 | * @title 属性 25 | * @description 【非主键】的【基本数据类型】 都是属性 26 | * @author michael Young (www.YangFuhai.com) 27 | * @version 1.0 28 | * @created 2012-10-10 29 | */ 30 | public class Property { 31 | 32 | private String fieldName; 33 | private String column; 34 | private String defaultValue; 35 | private Class dataType; 36 | private Field field; 37 | 38 | private Method get; 39 | private Method set; 40 | 41 | public void setValue(Object receiver , Object value){ 42 | if(set!=null && value!=null){ 43 | try { 44 | if (dataType == String.class) { 45 | set.invoke(receiver, value.toString()); 46 | } else if (dataType == int.class || dataType == Integer.class) { 47 | set.invoke(receiver, value == null ? (Integer) null : Integer.parseInt(value.toString())); 48 | } else if (dataType == float.class || dataType == Float.class) { 49 | set.invoke(receiver, value == null ? (Float) null: Float.parseFloat(value.toString())); 50 | } else if (dataType == double.class || dataType == Double.class) { 51 | set.invoke(receiver, value == null ? (Double) null: Double.parseDouble(value.toString())); 52 | } else if (dataType == long.class || dataType == Long.class) { 53 | set.invoke(receiver, value == null ? (Long) null: Long.parseLong(value.toString())); 54 | } else if (dataType == Date.class || dataType == java.sql.Date.class) { 55 | set.invoke(receiver, value == null ? (Date) null: FieldUtils.stringToDateTime(value.toString())); 56 | } else if (dataType == boolean.class || dataType == Boolean.class) { 57 | set.invoke(receiver, value == null ? (Boolean) null: "1".equals(value.toString())); 58 | } else { 59 | set.invoke(receiver, value); 60 | } 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | }else{ 65 | try { 66 | field.setAccessible(true); 67 | field.set(receiver, value); 68 | } catch (Exception e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | } 73 | 74 | /** 75 | * 获取某个实体执行某个方法的结果 76 | * @param obj 77 | * @param method 78 | * @return 79 | */ 80 | @SuppressWarnings("unchecked") 81 | public T getValue(Object obj){ 82 | if(obj != null && get != null) { 83 | try { 84 | return (T)get.invoke(obj); 85 | } catch (Exception e) { 86 | e.printStackTrace(); 87 | } 88 | } 89 | return null; 90 | } 91 | 92 | 93 | public String getFieldName() { 94 | return fieldName; 95 | } 96 | public void setFieldName(String fieldName) { 97 | this.fieldName = fieldName; 98 | } 99 | public String getColumn() { 100 | return column; 101 | } 102 | public void setColumn(String column) { 103 | this.column = column; 104 | } 105 | public String getDefaultValue() { 106 | return defaultValue; 107 | } 108 | public void setDefaultValue(String defaultValue) { 109 | this.defaultValue = defaultValue; 110 | } 111 | public Class getDataType() { 112 | return dataType; 113 | } 114 | public void setDataType(Class dataType) { 115 | this.dataType = dataType; 116 | } 117 | public Method getGet() { 118 | return get; 119 | } 120 | public void setGet(Method get) { 121 | this.get = get; 122 | } 123 | public Method getSet() { 124 | return set; 125 | } 126 | public void setSet(Method set) { 127 | this.set = set; 128 | } 129 | 130 | public Field getField() { 131 | return field; 132 | } 133 | 134 | public void setField(Field field) { 135 | this.field = field; 136 | } 137 | 138 | 139 | } 140 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/Property_A.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Target(ElementType.FIELD) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | public @interface Property_A { 26 | public String column() default ""; 27 | public String defaultValue() default ""; 28 | } 29 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/SQLHelper.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.db.orm; 2 | 3 | import com.minggo.pluto.annotation.AutoIncrement; 4 | import com.minggo.pluto.annotation.Exclude; 5 | import com.minggo.pluto.annotation.Primarykey; 6 | 7 | import java.lang.reflect.Field; 8 | import java.util.Date; 9 | 10 | 11 | /** 12 | * SQL语句拼装 13 | * 14 | * @author minggo 15 | * @time 2014-6-23 S下午9:43:33 16 | */ 17 | public class SQLHelper { 18 | 19 | /** 20 | * 获取创建表的SQL语句 21 | * 22 | * @param tableName 23 | * @param clazz 24 | * 要保存的实体 25 | * @return 26 | */ 27 | public static final String getCreateTable(String tableName, Class clazz) { 28 | StringBuilder sb = new StringBuilder(); 29 | sb.append("CREATE TABLE IF NOT EXISTS "); 30 | sb.append(tableName); 31 | sb.append("("); 32 | Field[] fields = clazz.getDeclaredFields(); 33 | for (Field field : fields) { 34 | field.setAccessible(true); 35 | // 排除字段 36 | if (field.getAnnotation(Exclude.class) != null) { 37 | continue; 38 | } 39 | 40 | if (field.getAnnotation(Primarykey.class) != null) { // 主键字段 41 | 42 | if (field.getAnnotation(AutoIncrement.class) == null) { 43 | sb.append(field.getName() + getTypeText(field) + "PRIMARY KEY NOT NULL,"); 44 | }else{ 45 | System.out.println("设置了数据库递增字段"); 46 | sb.append(field.getName() + getTypeText(field) + "PRIMARY KEY autoincrement NOT NULL ,"); 47 | } 48 | } else { 49 | if (field.getAnnotation(AutoIncrement.class) == null) { 50 | sb.append(field.getName() + getTypeText(field) + ","); 51 | }else{ 52 | sb.append(field.getName() + getTypeText(field) + "auto_increment,"); 53 | } 54 | } 55 | } 56 | 57 | // 处理掉最后一个逗号 58 | int indexOf = sb.lastIndexOf(","); 59 | if (indexOf != -1) { 60 | sb.deleteCharAt(indexOf); 61 | } 62 | 63 | sb.append(")"); 64 | 65 | return sb.toString(); 66 | } 67 | 68 | /** 69 | * 获得匹配的数据类型 70 | * 71 | * @param field 72 | * @return 73 | */ 74 | private static final String getTypeText(Field field) { 75 | Class type = field.getType(); 76 | field.setAccessible(true); 77 | if (type.equals(int.class) || type.equals(Integer.class)) { 78 | return " INTEGER "; 79 | } else if (type.equals(long.class) || type.equals(Long.class)) { 80 | return " LONG "; 81 | } else if (type.equals(double.class) || type.equals(Double.class)) { 82 | return " Double "; 83 | } else if (type.equals(Date.class)) { 84 | return " LONG "; 85 | } else { // 默认text类型 86 | return " TEXT "; 87 | } 88 | } 89 | 90 | /** 91 | * 获取删除表的SQL 92 | * 93 | * @return 94 | */ 95 | public static String getDrapTable(String tableName) { 96 | return "DROP TABLE IF EXISTS " + tableName; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/SqlInfo.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.db.orm; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class SqlInfo { 6 | 7 | private String sql; 8 | private LinkedList bindArgs; 9 | 10 | public String getSql() { 11 | return sql; 12 | } 13 | public void setSql(String sql) { 14 | this.sql = sql; 15 | } 16 | 17 | public LinkedList getBindArgs() { 18 | return bindArgs; 19 | } 20 | public void setBindArgs(LinkedList bindArgs) { 21 | this.bindArgs = bindArgs; 22 | } 23 | 24 | public Object[] getBindArgsAsArray() { 25 | if(bindArgs!=null) 26 | return bindArgs.toArray(); 27 | return null; 28 | } 29 | 30 | public String[] getBindArgsAsStringArray() { 31 | if(bindArgs!=null){ 32 | String[] strings = new String[bindArgs.size()]; 33 | for(int i = 0;i(); 44 | 45 | bindArgs.add(obj); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/Table.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Target(ElementType.TYPE) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | public @interface Table { 26 | public String name(); 27 | } -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/db/orm/Transient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.minggo.pluto.db.orm; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | 24 | @Target(ElementType.FIELD) 25 | @Retention(RetentionPolicy.RUNTIME) 26 | public @interface Transient { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/fragment/IFragment.java: -------------------------------------------------------------------------------- 1 | 2 | package com.minggo.pluto.fragment; 3 | 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Message; 7 | 8 | import java.util.ArrayList; 9 | 10 | /** 11 | * 描述:Fragment抽象接口 12 | */ 13 | public interface IFragment { 14 | 15 | /** 16 | * 设置广播action 17 | * 18 | * @return 19 | */ 20 | void setupActions(ArrayList actions); 21 | 22 | /** 23 | * 刷新界面 24 | * 25 | * @param msg 26 | */ 27 | void handleUiMessage(Message msg); 28 | 29 | /** 30 | * 处理广播 31 | * 32 | * @param context 33 | * @param intent 34 | */ 35 | void handleBroadcast(Context context, Intent intent); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/logic/LogicParam.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.logic; 2 | 3 | /** 4 | * Created by minggo on 2017/2/22. 5 | */ 6 | 7 | public abstract class LogicParam { 8 | 9 | public final class ParamName{ 10 | public static final String PN = "pn"; 11 | public static final String PS = "ps"; 12 | public static final String USERNAME = "username"; 13 | public static final String PASSWORD = "password"; 14 | public static final String EMAIL = "email"; 15 | } 16 | 17 | public final class ParamWhat{ 18 | public static final int LOGIN = 10000; 19 | public static final int REGIST = 10001; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/model/Result.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.model; 2 | 3 | import org.apache.commons.lang3.builder.ToStringBuilder; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 接口返回通用结果实体类 9 | * 10 | * @author minggo 11 | * @time 2014-12-2下午1:50:13 12 | */ 13 | public class Result implements Serializable { 14 | /** 15 | * 是否成功 16 | */ 17 | public boolean success; 18 | /** 19 | * 错误信息 20 | */ 21 | public String errorMsg; 22 | /** 23 | * 内容 24 | */ 25 | public T content; 26 | /** 27 | * 返回码 28 | */ 29 | public int code; 30 | 31 | @Override 32 | public String toString() { 33 | return ToStringBuilder.reflectionToString(this); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/AnimationUtils.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.util; 2 | 3 | import android.view.animation.AlphaAnimation; 4 | import android.view.animation.Animation; 5 | 6 | /** 7 | * 动画工具类 8 | * Created by zhengjinbin on 2016/8/11. 9 | */ 10 | public class AnimationUtils { 11 | public static final int DURATION_MILLIS_500 = 500; 12 | 13 | public static Animation getAlphaAnimation(float fromAlpha, float toAlpha, long durationMillis) { 14 | Animation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha); 15 | alphaAnimation.setDuration(durationMillis); 16 | return alphaAnimation; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/DisplayUtil.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.util; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.Locale; 6 | 7 | /** 8 | * 9 | */ 10 | public class DisplayUtil { 11 | public static final int SCREEN_WIDTH_PIXELS_480 = 480; 12 | public static final int SCREEN_WIDTH_PIXELS_720 = 720; 13 | public static final int SCREEN_WIDTH_PIXELS_1080 = 1080; 14 | 15 | /** 16 | * 将px值转换为dip或dp值,保证尺寸大小不变(有精度损失) 17 | */ 18 | public static int px2dip(Context context, float pxValue) { 19 | final float scale = context.getResources().getDisplayMetrics().density; 20 | return (int) (pxValue / scale + 0.5f); 21 | } 22 | 23 | /** 24 | * 将px值转换为dip或dp值,保证尺寸大小不变(无精度损失) 25 | */ 26 | public static float px2dipByFloat(Context context, float pxValue) { 27 | final float scale = context.getResources().getDisplayMetrics().density; 28 | return (pxValue / scale); 29 | } 30 | 31 | /** 32 | * 将dip或dp值转换为px值,保证尺寸大小不变(有精度损失),类似Context.getDimensionPixelSize方法(四舍五入) 33 | */ 34 | public static int dip2px(Context context, float dipValue) { 35 | final float scale = context.getResources().getDisplayMetrics().density; 36 | return (int) (dipValue * scale + 0.5f); 37 | } 38 | 39 | /** 40 | * 将dip或dp值转换为px值,保证尺寸大小不变(无精度损失),类似Context.getDimension方法 41 | */ 42 | public static float dip2pxByFloat(Context context, float dipValue) { 43 | final float scale = context.getResources().getDisplayMetrics().density; 44 | return (dipValue * scale); 45 | } 46 | 47 | /** 48 | * 将px值转换为sp值,保证文字大小不变 49 | */ 50 | public static int px2sp(Context context, float pxValue) { 51 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 52 | return (int) (pxValue / fontScale + 0.5f); 53 | } 54 | 55 | /** 56 | * 将sp值转换为px值,保证文字大小不变 57 | */ 58 | public static int sp2px(Context context, float spValue) { 59 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 60 | return (int) (spValue * fontScale + 0.5f); 61 | } 62 | 63 | /** 64 | * 屏幕宽度 65 | */ 66 | public static int getScreenWidthPixels(Context context) { 67 | return context.getResources().getDisplayMetrics().widthPixels; 68 | } 69 | 70 | /** 71 | * 屏幕高度 72 | */ 73 | public static int getScreenHeightPixels(Context context) { 74 | return context.getResources().getDisplayMetrics().heightPixels; 75 | } 76 | 77 | public static boolean isTargetScreenWidth(Context context, int targetPixels) { 78 | return getScreenWidthPixels(context) == targetPixels; 79 | } 80 | 81 | public static boolean isTargetScreenHeight(Context context, int targetPixels) { 82 | return getScreenHeightPixels(context) == targetPixels; 83 | } 84 | 85 | public static String getDisplayInfo(Context context) { 86 | String infoFormat = "宽:%s,高:%s 宽Dip:%s,高Dip:%s\ndpi:%s,1dip=%sPixels"; 87 | int screenWidthPixels = DisplayUtil.getScreenWidthPixels(context); 88 | int screenHeightPixels = DisplayUtil.getScreenHeightPixels(context); 89 | float density = context.getResources().getDisplayMetrics().density; 90 | Object[] infoFormatValue = { 91 | screenWidthPixels, screenHeightPixels, 92 | ((int) (screenWidthPixels / density)), ((int) (screenHeightPixels / density)), 93 | context.getResources().getDisplayMetrics().densityDpi, density 94 | }; 95 | return String.format(Locale.getDefault(), infoFormat, infoFormatValue); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/InjectedChromeClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Summary: 应用中使用的WebChromeClient基类 3 | * Version 1.0 4 | * Date: 13-11-8 5 | * Time: 下午2:31 6 | * Copyright: Copyright (c) 2013 7 | */ 8 | 9 | package com.minggo.pluto.util; 10 | 11 | import android.util.Log; 12 | import android.webkit.JsPromptResult; 13 | import android.webkit.JsResult; 14 | import android.webkit.WebChromeClient; 15 | import android.webkit.WebView; 16 | 17 | /** 18 | * 插入JS的Client 19 | * @author minggo 20 | * @time 2015-5-8上午10:49:43 21 | */ 22 | public class InjectedChromeClient extends WebChromeClient { 23 | 24 | private final String TAG = "InjectedChromeClient"; 25 | private JsCallJava mJsCallJava; 26 | private boolean mIsInjectedJS; 27 | 28 | public InjectedChromeClient(String injectedName, Class injectedCls) { 29 | mJsCallJava = new JsCallJava(injectedName, injectedCls); 30 | } 31 | 32 | public InjectedChromeClient(JsCallJava jsCallJava) { 33 | mJsCallJava = jsCallJava; 34 | } 35 | 36 | // 处理Alert事件 37 | @Override 38 | public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { 39 | result.confirm(); 40 | return true; 41 | } 42 | 43 | @Override 44 | public void onProgressChanged(WebView view, int newProgress) { 45 | // 为什么要在这里注入JS 46 | // 1 OnPageStarted中注入有可能全局注入不成功,导致页面脚本上所有接口任何时候都不可用 47 | // 2 OnPageFinished中注入,虽然最后都会全局注入成功,但是完成时间有可能太晚,当页面在初始化调用接口函数时会等待时间过长 48 | // 3 在进度变化时注入,刚好可以在上面两个问题中得到一个折中处理 49 | // 为什么是进度大于25%才进行注入,因为从测试看来只有进度大于这个数字页面才真正得到框架刷新加载,保证100%注入成功 50 | if (newProgress <= 25) { 51 | mIsInjectedJS = false; 52 | } else if (!mIsInjectedJS) { 53 | view.loadUrl(mJsCallJava.getPreloadInterfaceJS()); 54 | mIsInjectedJS = true; 55 | Log.d(TAG, " inject js interface completely on progress " + newProgress); 56 | 57 | } 58 | super.onProgressChanged(view, newProgress); 59 | } 60 | 61 | @Override 62 | public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { 63 | result.confirm(mJsCallJava.call(view, message)); 64 | return true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/JsCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Summary: 异步回调页面JS函数管理对象 3 | * Version 1.0 4 | * Date: 13-11-26 5 | * Time: 下午7:55 6 | * Copyright: Copyright (c) 2013 7 | */ 8 | 9 | package com.minggo.pluto.util; 10 | 11 | import android.util.Log; 12 | import android.webkit.WebView; 13 | 14 | import java.lang.ref.WeakReference; 15 | 16 | /** 17 | * JS回调 18 | * @author minggo 19 | * @time 2015-5-8上午10:50:59 20 | */ 21 | public class JsCallback { 22 | private static final String CALLBACK_JS_FORMAT = "javascript:%s.callback(%d, %d %s);"; 23 | private int mIndex; 24 | private boolean mCouldGoOn; 25 | private WeakReference mWebViewRef; 26 | private int mIsPermanent; 27 | private String mInjectedName; 28 | 29 | public JsCallback (WebView view, String injectedName, int index) { 30 | mCouldGoOn = true; 31 | mWebViewRef = new WeakReference(view); 32 | mInjectedName = injectedName; 33 | mIndex = index; 34 | } 35 | 36 | public void apply (Object... args) throws JsCallbackException { 37 | if (mWebViewRef.get() == null) { 38 | throw new JsCallbackException("the WebView related to the JsCallback has been recycled"); 39 | } 40 | if (!mCouldGoOn) { 41 | throw new JsCallbackException("the JsCallback isn't permanent,cannot be called more than once"); 42 | } 43 | StringBuilder sb = new StringBuilder(); 44 | for (Object arg : args){ 45 | sb.append(","); 46 | boolean isStrArg = arg instanceof String; 47 | if (isStrArg) { 48 | sb.append("\""); 49 | } 50 | sb.append(String.valueOf(arg)); 51 | if (isStrArg) { 52 | sb.append("\""); 53 | } 54 | } 55 | String execJs = String.format(CALLBACK_JS_FORMAT, mInjectedName, mIndex, mIsPermanent, sb.toString()); 56 | Log.d("JsCallBack", execJs); 57 | mWebViewRef.get().loadUrl(execJs); 58 | mCouldGoOn = mIsPermanent > 0; 59 | } 60 | 61 | public void setPermanent (boolean value) { 62 | mIsPermanent = value ? 1 : 0; 63 | } 64 | 65 | public static class JsCallbackException extends Exception { 66 | public JsCallbackException (String msg) { 67 | super(msg); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/MResource.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.util; 2 | 3 | import android.content.*; 4 | 5 | /** 6 | * Created by minggo on 2017/1/31. 7 | */ 8 | 9 | public class MResource { 10 | public static int getIdByName(Context context, String className, String name) { 11 | String packageName = context.getPackageName(); 12 | Class r = null; 13 | int id = 0; 14 | 15 | try { 16 | r = Class.forName(packageName + ".R"); 17 | Class[] classes = r.getClasses(); 18 | Class desireClass = null; 19 | 20 | for (int i = 0; i < classes.length; ++i) { 21 | if (classes[i].getName().split("\\$")[1].equals(className)) { 22 | desireClass = classes[i]; 23 | break; 24 | } 25 | } 26 | 27 | if (desireClass != null) { 28 | id = desireClass.getField(name).getInt(desireClass); 29 | } 30 | } catch (ClassNotFoundException e) { 31 | e.printStackTrace(); 32 | } catch (IllegalArgumentException e) { 33 | e.printStackTrace(); 34 | } catch (SecurityException e) { 35 | e.printStackTrace(); 36 | } catch (IllegalAccessException e) { 37 | e.printStackTrace(); 38 | } catch (NoSuchFieldException e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | return id; 43 | } 44 | 45 | public static int[] getIdsByName(Context context, String className, String name) { 46 | String packageName = context.getPackageName(); 47 | Class r = null; 48 | int[] ids = null; 49 | 50 | try { 51 | r = Class.forName(packageName + ".R"); 52 | 53 | Class[] classes = r.getClasses(); 54 | Class desireClass = null; 55 | 56 | for (int i = 0; i < classes.length; ++i) { 57 | if (classes[i].getName().split("\\$")[1].equals(className)) { 58 | desireClass = classes[i]; 59 | break; 60 | } 61 | } 62 | 63 | if ((desireClass != null) && (desireClass.getField(name).get(desireClass)) != null && (desireClass.getField(name).get(desireClass).getClass().isArray())) { 64 | ids = (int[]) desireClass.getField(name).get(desireClass); 65 | } 66 | } catch (ClassNotFoundException e) { 67 | e.printStackTrace(); 68 | } catch (IllegalArgumentException e) { 69 | e.printStackTrace(); 70 | } catch (SecurityException e) { 71 | e.printStackTrace(); 72 | } catch (IllegalAccessException e) { 73 | e.printStackTrace(); 74 | } catch (NoSuchFieldException e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | return ids; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/NetworkUtils.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | import java.util.Locale; 8 | 9 | /** 10 | * 11 | */ 12 | public class NetworkUtils { 13 | public static final int NET_TYPE_NOT = 0x00; 14 | public static final int NET_TYPE_WIFI = 0x01; 15 | public static final int NET_TYPE_CM_WAP = 0x02; 16 | public static final int NET_TYPE_CM_NET = 0x03; 17 | 18 | public static boolean isNetworkConnected(Context context) { 19 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 20 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); 21 | if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { 22 | if (networkInfo.getState() == NetworkInfo.State.CONNECTED) { 23 | return true; 24 | } 25 | } 26 | return false; 27 | } 28 | 29 | /** 30 | * 获取当前网络类型 31 | * 32 | * @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络 33 | */ 34 | public static int getNetworkType(Context context) { 35 | int netType = NetworkUtils.NET_TYPE_NOT; 36 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 37 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); 38 | if (networkInfo == null) { 39 | return netType; 40 | } 41 | int networkInfoType = networkInfo.getType(); 42 | if (networkInfoType == ConnectivityManager.TYPE_MOBILE) { 43 | String extraInfo = networkInfo.getExtraInfo(); 44 | if (!StringUtils.isEmpty(extraInfo)) { 45 | if (extraInfo.toLowerCase(Locale.getDefault()).equals("cmnet")) { 46 | netType = NetworkUtils.NET_TYPE_CM_NET; 47 | } else { 48 | netType = NetworkUtils.NET_TYPE_CM_WAP; 49 | } 50 | } 51 | } else if (networkInfoType == ConnectivityManager.TYPE_WIFI) { 52 | netType = NetworkUtils.NET_TYPE_WIFI; 53 | } 54 | return netType; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/PollingUtils.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.util; 2 | 3 | import android.app.AlarmManager; 4 | import android.app.PendingIntent; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.SystemClock; 8 | 9 | /** 10 | * 11 | */ 12 | public class PollingUtils { 13 | 14 | //开启轮询服务 15 | public static void startPollingService(Context context, int seconds, Class cls, String action) { 16 | LogUtils.info(String.format("cls:%s|action:%s|seconds:%d", cls + "", action, seconds)); 17 | //获取AlarmManager系统服务 18 | AlarmManager manager = (AlarmManager) context 19 | .getSystemService(Context.ALARM_SERVICE); 20 | 21 | //包装需要执行Service的Intent 22 | Intent intent = new Intent(context, cls); 23 | intent.setAction(action); 24 | PendingIntent pendingIntent = PendingIntent.getService(context, 0, 25 | intent, PendingIntent.FLAG_UPDATE_CURRENT); 26 | 27 | //触发服务的起始时间 28 | long triggerAtTime = SystemClock.elapsedRealtime(); 29 | 30 | //使用AlarmManger的setRepeating方法设置定期执行的时间间隔(seconds秒)和需要执行的Service 31 | manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, 32 | seconds * 1000, pendingIntent); 33 | } 34 | 35 | //停止轮询服务 36 | public static void stopPollingService(Context context, Class cls, String action) { 37 | LogUtils.info(String.format("cls:%s|action:%s", cls + "", action)); 38 | AlarmManager manager = (AlarmManager) context 39 | .getSystemService(Context.ALARM_SERVICE); 40 | Intent intent = new Intent(context, cls); 41 | intent.setAction(action); 42 | PendingIntent pendingIntent = PendingIntent.getService(context, 0, 43 | intent, PendingIntent.FLAG_UPDATE_CURRENT); 44 | //取消正在执行的服务 45 | manager.cancel(pendingIntent); 46 | } 47 | } -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/java/com/minggo/pluto/util/ThreadPoolUtils.java: -------------------------------------------------------------------------------- 1 | package com.minggo.pluto.util; 2 | 3 | 4 | import java.util.concurrent.ArrayBlockingQueue; 5 | import java.util.concurrent.BlockingQueue; 6 | import java.util.concurrent.ThreadFactory; 7 | import java.util.concurrent.ThreadPoolExecutor; 8 | import java.util.concurrent.TimeUnit; 9 | import java.util.concurrent.atomic.AtomicInteger; 10 | 11 | /** 12 | * 线程池辅助类,整个应用程序就只有一个线程池去管理线程。 可以设置核心线程数、最大线程数、额外线程空状态生存时间,阻塞队列长度来优化线程池。 13 | * 下面的数据都是参考Android的AsynTask里的数据。 14 | * @author minggo 15 | * @time 2014-12-29下午2:00:30 16 | */ 17 | public class ThreadPoolUtils { 18 | 19 | private ThreadPoolUtils() { 20 | 21 | } 22 | 23 | // 线程池核心线程数 24 | private static int CORE_POOL_SIZE = 5; 25 | 26 | // 线程池最大线程数 27 | private static int MAX_POOL_SIZE = 100; 28 | 29 | // 额外线程空状态生存时间 30 | private static int KEEP_ALIVE_TIME = 10000; 31 | 32 | // 阻塞队列。当核心线程都被占用,且阻塞队列已满的情况下,才会开启额外线程。 33 | private static BlockingQueue workQueue = new ArrayBlockingQueue( 34 | 10); 35 | 36 | // 线程工厂 37 | private static ThreadFactory threadFactory = new ThreadFactory() { 38 | private final AtomicInteger integer = new AtomicInteger(); 39 | 40 | @Override 41 | public Thread newThread(Runnable r) { 42 | return new Thread(r, "myThreadPool thread:" 43 | + integer.getAndIncrement()); 44 | } 45 | }; 46 | 47 | // 线程池 48 | private static ThreadPoolExecutor threadPool; 49 | 50 | static { 51 | threadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, 52 | KEEP_ALIVE_TIME, TimeUnit.SECONDS, workQueue, threadFactory); 53 | } 54 | 55 | /** 56 | * 从线程池中抽取线程,执行指定的Runnable对象 57 | * 58 | * @param runnable 59 | */ 60 | public static void execute(Runnable runnable) { 61 | threadPool.execute(runnable); 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/alpha_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 15 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/alpha_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/alpha_sllow_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/alpha_sllow_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/push_down_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/push_left_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/push_right_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/anim/push_up_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/layout/dialog_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 29 | 30 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/layout/dialog_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 13 | 20 | 21 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/layout/fragment_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 29 | 30 | 38 | 39 | 44 | 45 | 50 | 51 | 52 | 53 | 57 | 58 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Pluto 3 | 网络连接失败,请检查网络设置 4 | 数据解析异常 5 | 文件流异常 6 | 网络异常,错误码:%d 7 | 网络异常,请求超时 8 | 网络异常,读取数据超时 9 | 应用程序运行时异常 10 | 应用程序错误 11 | 很抱歉,应用程序出现错误,即将退出。\n请提交错误报告,我们会尽快修复这个问题! 12 | 请稍等... 13 | 退出提醒 14 | 取消 15 | 确定 16 | 您确定退出应用吗? 17 | 18 | 19 | -------------------------------------------------------------------------------- /PlutoAndroidExample/Pluto/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /PlutoAndroidExample/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /PlutoAndroidExample/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #30B900 7 | 8 | -------------------------------------------------------------------------------- /PlutoAndroidExample/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 160dp 5 | 6 | 16dp 7 | 16dp 8 | 16dp 9 | 76dp 10 | 200dp 11 | 8dp 12 | 13 | -------------------------------------------------------------------------------- /PlutoAndroidExample/app/src/main/res/values/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | @android:drawable/ic_menu_camera 3 | @android:drawable/ic_menu_gallery 4 | @android:drawable/ic_menu_slideshow 5 | @android:drawable/ic_menu_manage 6 | @android:drawable/ic_menu_share 7 | @android:drawable/ic_menu_send 8 | 9 | -------------------------------------------------------------------------------- /PlutoAndroidExample/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |