├── .gitignore ├── AndJie ├── .classpath ├── .project ├── AndroidManifest.xml ├── assets │ └── problem_1 │ │ └── ListView ├── ic_launcher-web.png ├── libs │ ├── android-support-v4.jar │ ├── asynchttpclientlibrary.jar │ ├── gson-2.2.4.jar │ ├── ormlite-android-4.48.jar │ ├── ormlite-core-4.48.jar │ ├── photoview.jar │ ├── recyclerview-v7-21.0.0-rc1.jar │ ├── universal-image-loader-1.9.2-with-sources.jar │ ├── websocket.jar │ └── xutilslibrary.jar ├── proguard-project.txt ├── project.properties ├── res │ ├── anim │ │ ├── in_from_bootom.xml │ │ ├── in_from_top.xml │ │ ├── out_to_bootom.xml │ │ └── out_to_top.xml │ ├── drawable-hdpi │ │ ├── bg_add_picture.9.png │ │ ├── bg_item_list_2.9.png │ │ ├── bg_item_list_3.9.png │ │ ├── bg_loading_dialog.9.png │ │ ├── btn_delete_normal.png │ │ ├── btn_delete_selected.png │ │ ├── ic_launcher.png │ │ ├── icon_navigate.png │ │ ├── pop_add_img_default.png │ │ ├── pop_select_catory_bg.9.png │ │ └── title_navigation_other_bg.9.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── drawable │ │ └── btn_del.xml │ ├── layout │ │ ├── activity_and_base.xml │ │ ├── activity_photo_viewpager.xml │ │ ├── activity_recyclerview.xml │ │ ├── activity_scrollview_edittext.xml │ │ ├── activity_select_picture.xml │ │ ├── dialog_waiting.xml │ │ ├── item_account_adapter_item.xml │ │ ├── item_editext_del.xml │ │ ├── item_pop_add_picture.xml │ │ └── item_title_bar.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── attrs.xml │ │ ├── dimens.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── jwzhangjie │ └── andbase │ ├── AndBase.java │ ├── JieApp.java │ ├── doc │ ├── DBUsed.java │ ├── EditTextScrollUsed.java │ ├── GsonUsed.java │ ├── HttpRequestUsed.java │ ├── ImageLoaderUsed.java │ ├── NavigateUsed.java │ ├── PotoViewPagerUsed.java │ ├── RecyclerViewUsed.java │ ├── SelectPicUsed.java │ ├── WebSocketUsed.java │ ├── adapter │ │ └── AccountAdapter.java │ ├── bean │ │ ├── AffixForShowBean.java │ │ └── GsonBean.java │ └── db │ │ ├── DBHelper.java │ │ ├── DBUtils.java │ │ ├── Emails.java │ │ └── Users.java │ ├── interfaces │ ├── IActivity.java │ ├── IFragmentChange.java │ ├── ILayoutInit.java │ └── IParcelable.java │ ├── net │ ├── DefaultJsonResponseHandler.java │ ├── JieHttpClient.java │ └── JieWebSocket.java │ ├── popup │ └── AddPicturePopup.java │ ├── ui │ ├── base │ │ ├── ADBaseAdapter.java │ │ ├── BaseActivity.java │ │ ├── BaseChangeFragments.java │ │ ├── BaseFragment.java │ │ ├── BaseView.java │ │ └── JieBasePopup.java │ └── dialog │ │ ├── WaitingDialog.java │ │ └── WaitingFragmentDialog.java │ ├── util │ ├── AppLog.java │ ├── FileUtils.java │ ├── JieContant.java │ ├── MediaFile.java │ ├── SharePreferenceDelegate.java │ └── SharePreferenceKeeper.java │ └── widget │ ├── CircleImageView.java │ ├── HackyViewPager.java │ ├── InnerScrollView.java │ ├── JieEditTextDel.java │ ├── MarqueeTextView.java │ ├── TitleNavigate.java │ └── VerticalScrollTextView.java ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | -------------------------------------------------------------------------------- /AndJie/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /AndJie/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AndJie 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /AndJie/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /AndJie/assets/problem_1/ListView: -------------------------------------------------------------------------------- 1 | 问题一:ListView的setOnItemClickListener点击事件不起作用 2 | 解决方法:在Adapter的item的父布局中添加android:descendantFocusability="blocksDescendants" 3 | 例如: 4 | 9 | 15 | 16 | 21 | 22 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /AndJie/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/ic_launcher-web.png -------------------------------------------------------------------------------- /AndJie/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/android-support-v4.jar -------------------------------------------------------------------------------- /AndJie/libs/asynchttpclientlibrary.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/asynchttpclientlibrary.jar -------------------------------------------------------------------------------- /AndJie/libs/gson-2.2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/gson-2.2.4.jar -------------------------------------------------------------------------------- /AndJie/libs/ormlite-android-4.48.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/ormlite-android-4.48.jar -------------------------------------------------------------------------------- /AndJie/libs/ormlite-core-4.48.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/ormlite-core-4.48.jar -------------------------------------------------------------------------------- /AndJie/libs/photoview.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/photoview.jar -------------------------------------------------------------------------------- /AndJie/libs/recyclerview-v7-21.0.0-rc1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/recyclerview-v7-21.0.0-rc1.jar -------------------------------------------------------------------------------- /AndJie/libs/universal-image-loader-1.9.2-with-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/universal-image-loader-1.9.2-with-sources.jar -------------------------------------------------------------------------------- /AndJie/libs/websocket.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/websocket.jar -------------------------------------------------------------------------------- /AndJie/libs/xutilslibrary.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/libs/xutilslibrary.jar -------------------------------------------------------------------------------- /AndJie/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /AndJie/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /AndJie/res/anim/in_from_bootom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /AndJie/res/anim/in_from_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /AndJie/res/anim/out_to_bootom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /AndJie/res/anim/out_to_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/bg_add_picture.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/bg_add_picture.9.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/bg_item_list_2.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/bg_item_list_2.9.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/bg_item_list_3.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/bg_item_list_3.9.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/bg_loading_dialog.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/bg_loading_dialog.9.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/btn_delete_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/btn_delete_normal.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/btn_delete_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/btn_delete_selected.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/icon_navigate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/icon_navigate.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/pop_add_img_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/pop_add_img_default.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/pop_select_catory_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/pop_select_catory_bg.9.png -------------------------------------------------------------------------------- /AndJie/res/drawable-hdpi/title_navigation_other_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-hdpi/title_navigation_other_bg.9.png -------------------------------------------------------------------------------- /AndJie/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndJie/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndJie/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwzhangjie/AndJie/a6389f23731e8c0d637956f480ad24cb409d8760/AndJie/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndJie/res/drawable/btn_del.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /AndJie/res/layout/activity_and_base.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /AndJie/res/layout/activity_photo_viewpager.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 16 | 17 | -------------------------------------------------------------------------------- /AndJie/res/layout/activity_recyclerview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /AndJie/res/layout/activity_scrollview_edittext.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 32 | 36 | 37 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /AndJie/res/layout/activity_select_picture.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | -------------------------------------------------------------------------------- /AndJie/res/layout/dialog_waiting.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 26 | 27 | -------------------------------------------------------------------------------- /AndJie/res/layout/item_account_adapter_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 20 | 21 | 27 | 28 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /AndJie/res/layout/item_editext_del.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 25 | 26 | 35 | 36 | 44 | 45 | 46 | 59 | 60 | -------------------------------------------------------------------------------- /AndJie/res/layout/item_pop_add_picture.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 20 | 21 | 31 | 32 | 42 | 43 | -------------------------------------------------------------------------------- /AndJie/res/layout/item_title_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 19 | 20 | 28 | 29 | 38 | 39 | 49 | 50 | -------------------------------------------------------------------------------- /AndJie/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AndJie/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /AndJie/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AndJie/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12sp 5 | 16sp 6 | 18sp 7 | 20sp 8 | 9 | 4dip 10 | 10dip 11 | 20dip 12 | 30dip 13 | 14 | -------------------------------------------------------------------------------- /AndJie/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AndJie/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AndJie 5 | Hello world! 6 | 在ScrollView里面可以滑动的EditText 7 | 8 | 9 | 返回 10 | 取消 11 | 请稍等,数据加载中 12 | 13 | 从手机相册选择 14 | 拍照 15 | 16 | -------------------------------------------------------------------------------- /AndJie/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 24 | 25 | 29 | 30 | 42 | 43 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/AndBase.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase; 2 | 3 | import com.jwzhangjie.andbase.ui.base.BaseChangeFragments; 4 | 5 | import android.os.Bundle; 6 | 7 | public class AndBase extends BaseChangeFragments { 8 | 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.activity_and_base); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/JieApp.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase; 2 | 3 | import com.jwzhangjie.andbase.ui.base.BaseActivity; 4 | import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; 5 | import com.nostra13.universalimageloader.core.ImageLoader; 6 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 7 | import com.nostra13.universalimageloader.core.assist.QueueProcessingType; 8 | 9 | import android.app.Application; 10 | import android.content.Context; 11 | import android.view.LayoutInflater; 12 | 13 | public class JieApp extends Application { 14 | 15 | public static JieApp instance = null; 16 | private BaseActivity currentRunningActivity = null; 17 | private LayoutInflater mInflater; 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | instance = this; 23 | initImageLoader(instance); 24 | } 25 | 26 | public BaseActivity getCurrentRunningActivity() { 27 | return currentRunningActivity; 28 | } 29 | 30 | public void setCurrentRunningActivity(BaseActivity currentRunningActivity) { 31 | this.currentRunningActivity = currentRunningActivity; 32 | } 33 | 34 | public LayoutInflater getInflater() { 35 | if (mInflater == null) { 36 | mInflater = LayoutInflater.from(getApplicationContext()); 37 | } 38 | return mInflater; 39 | } 40 | 41 | public static void initImageLoader(Context context) { 42 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( 43 | context).threadPriority(Thread.NORM_PRIORITY - 2) 44 | .denyCacheImageMultipleSizesInMemory() 45 | .diskCacheFileNameGenerator(new Md5FileNameGenerator()) 46 | .tasksProcessingOrder(QueueProcessingType.LIFO) 47 | .writeDebugLogs() // Remove for release app 48 | .build(); 49 | // Initialize ImageLoader with configuration. 50 | ImageLoader.getInstance().init(config); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/DBUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import android.content.Context; 7 | 8 | import com.jwzhangjie.andbase.doc.db.DBUtils; 9 | import com.jwzhangjie.andbase.doc.db.Users; 10 | 11 | 12 | /** 13 | * title: DBUsed.java 14 | * @author jwzhangjie 15 | * Date: 2014年12月8日 下午12:48:21 16 | * version 1.0 17 | * {@link http://blog.csdn.net/jwzhangjie} 18 | * Description:关于ormlite的具体使用实例 19 | */ 20 | public class DBUsed { 21 | 22 | private DBUtils mDbUtils; 23 | public DBUsed(Context context){ 24 | mDbUtils = new DBUtils(context); 25 | } 26 | 27 | public void createUsers(){ 28 | List users = new ArrayList(); 29 | Users user1 = new Users(); 30 | user1.setEmail("jwzhangjie@163.com"); 31 | user1.setName("与狼共舞"); 32 | user1.setPwd("123456"); 33 | users.add(user1); 34 | Users user2 = new Users(); 35 | user2.setEmail("77777@qq.com"); 36 | user2.setName("海飘"); 37 | user2.setPwd("123456"); 38 | users.add(user2); 39 | mDbUtils.moreUserCreate(users); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/EditTextScrollUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import android.widget.ScrollView; 4 | 5 | import com.jwzhangjie.andbase.R; 6 | import com.jwzhangjie.andbase.ui.base.BaseActivity; 7 | import com.jwzhangjie.andbase.widget.InnerScrollView; 8 | import com.lidroid.xutils.view.annotation.ContentView; 9 | import com.lidroid.xutils.view.annotation.ViewInject; 10 | 11 | 12 | /** 13 | * title: EditTextScrollUsed.java 14 | * @author jwzhangjie 15 | * Date: 2014-12-7 上午11:03:58 16 | * version 1.0 17 | * {@link http://blog.csdn.net/jwzhangjie} 18 | * Description:测试在ScrollView下可以滑动的EditText,需要child_scroll.parentScrollView = parent_scroll; 19 | */ 20 | @ContentView(R.layout.activity_scrollview_edittext) 21 | public class EditTextScrollUsed extends BaseActivity { 22 | 23 | @ViewInject(R.id.parent_scroll) 24 | private ScrollView parent_scroll; 25 | @ViewInject(R.id.child_scroll) 26 | private InnerScrollView child_scroll; 27 | 28 | @Override 29 | protected void initView() { 30 | super.initView(); 31 | child_scroll.parentScrollView = parent_scroll; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/GsonUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import java.util.List; 4 | 5 | import com.google.gson.Gson; 6 | import com.google.gson.reflect.TypeToken; 7 | import com.jwzhangjie.andbase.doc.bean.GsonBean; 8 | import com.jwzhangjie.andbase.util.AppLog; 9 | 10 | /** 11 | * title: GsonUsed.java 12 | * @author jwzhangjie 13 | * Date: 2014-12-6 下午3:58:56 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description:Gson的基本使用 17 | */ 18 | public class GsonUsed { 19 | 20 | public GsonUsed(){ 21 | 22 | } 23 | 24 | /** 25 | * 26 | * Title: parseObject 27 | * Description:解析单个对象 28 | * @param json 29 | */ 30 | public void parseObject(String json){ 31 | Gson gson = new Gson(); 32 | GsonBean mGsonBean = gson.fromJson(json, GsonBean.class); 33 | //这样就把json字符串转化为对象了,直接使用mGsonBean就可以了 34 | AppLog.e(mGsonBean.getUser_name()); 35 | } 36 | 37 | /** 38 | * 39 | * Title: parseArray 40 | * Description:解析json数组 41 | * @param json 42 | */ 43 | public void parseArray(String json){ 44 | Gson gson = new Gson(); 45 | List list = gson.fromJson(json, new TypeToken>(){}.getType()); 46 | for (GsonBean gsonBean : list) { 47 | AppLog.e(gsonBean.getUser_name()); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/HttpRequestUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import org.apache.http.Header; 4 | 5 | import com.jwzhangjie.andbase.net.DefaultJsonResponseHandler; 6 | import com.jwzhangjie.andbase.net.JieHttpClient; 7 | import com.loopj.android.http.RequestParams; 8 | 9 | 10 | /** 11 | * title: HttpRequestUsed.java 12 | * @author jwzhangjie 13 | * Date: 2014-12-6 下午3:16:10 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description: 网络请求实例 17 | */ 18 | public class HttpRequestUsed { 19 | 20 | public HttpRequestUsed(){ 21 | RequestParams params = new RequestParams(); 22 | params.put("name", "jwzhangjie"); 23 | params.put("pwd", "****"); 24 | LoginRequest("/login", params); 25 | } 26 | 27 | /** 28 | * 29 | * Title: LoginRequest 30 | * Description: Post方式请求服务器数据 31 | * @param url 32 | * @param params 33 | */ 34 | public void LoginRequest(String url, RequestParams params){ 35 | JieHttpClient.postBase(url, params, new DefaultJsonResponseHandler(){ 36 | 37 | @Override 38 | public void onFailure(int statusCode, Header[] headers, 39 | String responseBody, Throwable throwable) { 40 | super.onFailure(statusCode, headers, responseBody, throwable); 41 | } 42 | 43 | @Override 44 | public void onSuccess(int statusCode, Header[] headers, 45 | String responseBody) { 46 | super.onSuccess(statusCode, headers, responseBody); 47 | } 48 | 49 | }); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/ImageLoaderUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import android.graphics.Bitmap; 4 | import android.widget.ImageView; 5 | 6 | import com.jwzhangjie.andbase.R; 7 | import com.nostra13.universalimageloader.core.DisplayImageOptions; 8 | import com.nostra13.universalimageloader.core.ImageLoader; 9 | 10 | /** 11 | * title: ImageLoaderUsed.java 12 | * @author jwzhangjie 13 | * Date: 2014-12-6 下午2:53:34 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description:String imageUri = "http://site.com/image.png"; // from Web 17 | * String imageUri = "file:///mnt/sdcard/image.png"; // from SD card 18 | * String imageUri = "content://media/external/audio/albumart/13"; // from content provider 19 | * String imageUri = "assets://image.png"; // from assets 20 | * String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch) 21 | */ 22 | public class ImageLoaderUsed { 23 | 24 | ImageLoader imageLoader = ImageLoader.getInstance(); 25 | DisplayImageOptions options; 26 | 27 | public ImageLoaderUsed() { 28 | options = new DisplayImageOptions.Builder() 29 | .showImageOnLoading(R.drawable.ic_launcher) 30 | .showImageForEmptyUri(R.drawable.ic_launcher) 31 | .showImageOnFail(R.drawable.ic_launcher).cacheInMemory(false) 32 | .cacheOnDisk(true).considerExifParams(true) 33 | .bitmapConfig(Bitmap.Config.RGB_565).build(); 34 | } 35 | 36 | /** 37 | * Title: loadImg 38 | * Description:显示网络图片 39 | * @param url 40 | * @param imageView 41 | */ 42 | public void loadImg(String url, ImageView imageView) { 43 | imageLoader.displayImage(url, imageView, options); 44 | } 45 | 46 | /** 47 | * Quick Setup 48 | 1. Include library 49 | Manual: 50 | 51 | •Download JAR 52 | •Put the JAR in the libs subfolder of your Android project 53 | or 54 | 55 | Maven dependency: 56 | 57 | 58 | com.nostra13.universalimageloader 59 | universal-image-loader 60 | 1.8.6 61 | 2. Android Manifest 62 | 63 | 64 | 65 | 66 | ... 67 | 68 | ... 69 | 70 | 3. Application class 71 | public class MyApplication extends Application { 72 | @Override 73 | public void onCreate() { 74 | super.onCreate(); 75 | 76 | // Create global configuration and initialize ImageLoader with this configuration 77 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) 78 | ... 79 | .build(); 80 | ImageLoader.getInstance().init(config); 81 | } 82 | }Configuration and Display Options 83 | •ImageLoader Configuration (ImageLoaderConfiguration) is global for application. 84 | •Display Options (DisplayImageOptions) are local for every display task (ImageLoader.displayImage(...)). 85 | Configuration 86 | All options in Configuration builder are optional. Use only those you really want to customize. 87 | See default values for config options in Java docs for every option. 88 | 89 | // DON'T COPY THIS CODE TO YOUR PROJECT! This is just example of ALL options using. 90 | File cacheDir = StorageUtils.getCacheDirectory(context); 91 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) 92 | .memoryCacheExtraOptions(480, 800) // default = device screen dimensions 93 | .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75, null) 94 | .taskExecutor(...) 95 | .taskExecutorForCachedImages(...) 96 | .threadPoolSize(3) // default 97 | .threadPriority(Thread.NORM_PRIORITY - 1) // default 98 | .tasksProcessingOrder(QueueProcessingType.FIFO) // default 99 | .denyCacheImageMultipleSizesInMemory() 100 | .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) 101 | .memoryCacheSize(2 * 1024 * 1024) 102 | .memoryCacheSizePercentage(13) // default 103 | .discCache(new UnlimitedDiscCache(cacheDir)) // default 104 | .discCacheSize(50 * 1024 * 1024) 105 | .discCacheFileCount(100) 106 | .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default 107 | .imageDownloader(new BaseImageDownloader(context)) // default 108 | .imageDecoder(new BaseImageDecoder()) // default 109 | .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default 110 | .writeDebugLogs() 111 | .build();Display Options 112 | Display Options can be applied to every display task (ImageLoader.displayImage(...) call). 113 | 114 | Note: If Display Options wasn't passed to ImageLoader.displayImage(...)method then default Display Options from configuration (ImageLoaderConfiguration.defaultDisplayImageOptions(...)) will be used. 115 | 116 | // DON'T COPY THIS CODE TO YOUR PROJECT! This is just example of ALL options using. 117 | DisplayImageOptions options = new DisplayImageOptions.Builder() 118 | .showImageOnLoading(R.drawable.ic_stub) // resource or drawable 119 | .showImageForEmptyUri(R.drawable.ic_empty) // resource or drawable 120 | .showImageOnFail(R.drawable.ic_error) // resource or drawable 121 | .resetViewBeforeLoading(false) // default 122 | .delayBeforeLoading(1000) 123 | .cacheInMemory(false) // default 124 | .cacheOnDisc(false) // default 125 | .preProcessor(...) 126 | .postProcessor(...) 127 | .extraForDownloader(...) 128 | .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default 129 | .bitmapConfig(Bitmap.Config.ARGB_8888) // default 130 | .decodingOptions(...) 131 | .displayer(new SimpleBitmapDisplayer()) // default 132 | .handler(new Handler()) // default 133 | .build();Usage 134 | Acceptable URIs examples 135 | String imageUri = "http://site.com/image.png"; // from Web 136 | String imageUri = "file:///mnt/sdcard/image.png"; // from SD card 137 | String imageUri = "content://media/external/audio/albumart/13"; // from content provider 138 | String imageUri = "assets://image.png"; // from assets 139 | String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)NOTE: Use drawable:// only if you really need it! Always consider the native way to load drawables - ImageView.setImageResource(...) instead of using of ImageLoader. 140 | 141 | Simple 142 | // Load image, decode it to Bitmap and display Bitmap in ImageView 143 | imageLoader.displayImage(imageUri, imageView);// Load image, decode it to Bitmap and return Bitmap to callback 144 | imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() { 145 | @Override 146 | public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 147 | // Do whatever you want with Bitmap 148 | } 149 | });Complete 150 | // Load image, decode it to Bitmap and display Bitmap in ImageView 151 | imageLoader.displayImage(imageUri, imageView, displayOptions, new ImageLoadingListener() { 152 | @Override 153 | public void onLoadingStarted(String imageUri, View view) { 154 | ... 155 | } 156 | @Override 157 | public void onLoadingFailed(String imageUri, View view, FailReason failReason) { 158 | ... 159 | } 160 | @Override 161 | public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 162 | ... 163 | } 164 | @Override 165 | public void onLoadingCancelled(String imageUri, View view) { 166 | ... 167 | } 168 | });// Load image, decode it to Bitmap and return Bitmap to callback 169 | ImageSize targetSize = new ImageSize(120, 80); // result Bitmap will be fit to this size 170 | imageLoader.loadImage(imageUri, targetSize, displayOptions, new SimpleImageLoadingListener() { 171 | @Override 172 | public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 173 | // Do whatever you want with Bitmap 174 | } 175 | });ImageLoader Helpers 176 | Other useful methods and classes to consider. 177 | 178 | ImageLoader | 179 | | - getMemoryCache() 180 | | - clearMemoryCache() 181 | | - getDiscCache() 182 | | - clearDiscCache() 183 | | - denyNetworkDownloads(boolean) 184 | | - handleSlowNetwork(boolean) 185 | | - pause() 186 | | - resume() 187 | | - stop() 188 | | - destroy() 189 | | - getLoadingUriForView(ImageView) 190 | | - cancelDisplayTask(ImageView) 191 | 192 | MemoryCacheUtil | 193 | | - findCachedBitmapsForImageUri(...) 194 | | - findCacheKeysForImageUri(...) 195 | | - removeFromCache(...) 196 | 197 | DiscCacheUtil | 198 | | - findInCache(...) 199 | | - removeFromCache(...) 200 | 201 | StorageUtils | 202 | | - getCacheDirectory(Context) 203 | | - getIndividualCacheDirectory(Context) 204 | | - getOwnCacheDirectory(Context, String) 205 | 206 | PauseOnScrollListener 207 | Also look into more detailed Library Map 208 | 209 | Useful Info 210 | 1.Caching is NOT enabled by default. If you want loaded images will be cached in memory and/or on disc then you should enable caching in DisplayImageOptions this way: 211 | // Create default options which will be used for every 212 | // displayImage(...) call if no options will be passed to this method 213 | DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() 214 | ... 215 | .cacheInMemory(true) 216 | .cacheOnDisc(true) 217 | ... 218 | .build(); 219 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) 220 | ... 221 | .defaultDisplayImageOptions(defaultOptions) 222 | ... 223 | .build(); 224 | ImageLoader.getInstance().init(config); // Do it on Application start// Then later, when you want to display image 225 | ImageLoader.getInstance().displayImage(imageUrl, imageView); // Default options will be usedor this way: 226 | 227 | DisplayImageOptions options = new DisplayImageOptions.Builder() 228 | ... 229 | .cacheInMemory(true) 230 | .cacheOnDisc(true) 231 | ... 232 | .build(); 233 | ImageLoader.getInstance().displayImage(imageUrl, imageView, options); // Incoming options will be used1.If you enabled disc caching then UIL try to cache images on external storage (/sdcard/Android/data/[package_name]/cache). If external storage is not available then images are cached on device's filesytem. To provide caching on external storage (SD card) add following permission to AndroidManifest.xml: 234 | 1.How UIL define Bitmap size needed for exact ImageView? It searches defined parameters: 235 | 236 | ◦Get actual measured width and height of ImageView 237 | ◦Get android:layout_width and android:layout_height parameters 238 | ◦Get android:maxWidth and/or android:maxHeight parameters 239 | ◦Get maximum width and/or height parameters from configuration (memoryCacheExtraOptions(int, int) option) 240 | ◦Get width and/or height of device screen 241 | So try to set android:layout_width|android:layout_height or android:maxWidth|android:maxHeight parameters for ImageView if you know approximate maximum size of it. It will help correctly compute Bitmap size needed for this view and save memory. 242 | 243 | 2.If you often got OutOfMemoryError in your app using Universal Image Loader then try next (all of them or several): 244 | 245 | ◦Reduce thread pool size in configuration (.threadPoolSize(...)). 1 - 5 is recommended. 246 | ◦Use .bitmapConfig(Bitmap.Config.RGB_565) in display options. Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. 247 | ◦Use .memoryCache(new WeakMemoryCache()) in configuration or disable caching in memory at all in display options (don't call .cacheInMemory()). 248 | ◦Use .imageScaleType(ImageScaleType.IN_SAMPLE_INT) in display options. Or try .imageScaleType(ImageScaleType.EXACTLY). 249 | ◦Avoid using RoundedBitmapDisplayer. It creates new Bitmap object with ARGB_8888 config for displaying during work. 250 | 3.For memory cache configuration (ImageLoaderConfiguration.memoryCache(...)) you can use already prepared implementations. 251 | 252 | ◦Cache using only strong references: 253 | ■LruMemoryCache (Least recently used bitmap is deleted when cache size limit is exceeded) - Used by default for API >= 9 254 | ◦Caches using weak and strong references: 255 | ■UsingFreqLimitedMemoryCache (Least frequently used bitmap is deleted when cache size limit is exceeded) 256 | ■LRULimitedMemoryCache (Least recently used bitmap is deleted when cache size limit is exceeded) - Used by default for API < 9 257 | ■FIFOLimitedMemoryCache (FIFO rule is used for deletion when cache size limit is exceeded) 258 | ■LargestLimitedMemoryCache (The largest bitmap is deleted when cache size limit is exceeded) 259 | ■LimitedAgeMemoryCache (Decorator. Cached object is deleted when its age exceeds defined value) 260 | ◦Cache using only weak references: 261 | ■WeakMemoryCache (Unlimited cache) 262 | 4.For disc cache configuration (ImageLoaderConfiguration.discCache(...)) you can use already prepared implementations: 263 | 264 | ◦UnlimitedDiscCache (The fastest cache, doesn't limit cache size) - Used by default 265 | ◦TotalSizeLimitedDiscCache (Cache limited by total cache size. If cache size exceeds specified limit then file with the most oldest last usage date will be deleted) 266 | ◦FileCountLimitedDiscCache (Cache limited by file count. If file count in cache directory exceeds specified limit then file with the most oldest last usage date will be deleted. Use it if your cached files are of about the same size.) 267 | ◦LimitedAgeDiscCache (Size-unlimited cache with limited files' lifetime. If age of cached file exceeds defined limit then it will be deleted from cache.) 268 | NOTE: UnlimitedDiscCache is 30%-faster than other limited disc cache implementations. 269 | 270 | 5.To display bitmap (DisplayImageOptions.displayer(...)) you can use already prepared implementations: 271 | 272 | ◦RoundedBitmapDisplayer (Displays bitmap with rounded corners) 273 | ◦FadeInBitmapDisplayer (Displays image with "fade in" animation) 274 | 6.To avoid list (grid, ...) scrolling lags you can use PauseOnScrollListener: 275 | 276 | boolean pauseOnScroll = false; // or true 277 | boolean pauseOnFling = true; // or false 278 | PauseOnScrollListener listener = new PauseOnScrollListener(imageLoader, pauseOnScroll, pauseOnFling); 279 | listView.setOnScrollListener(listener); 280 | */ 281 | 282 | } 283 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/NavigateUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import android.view.View; 4 | 5 | import com.jwzhangjie.andbase.R; 6 | import com.jwzhangjie.andbase.ui.base.BaseActivity; 7 | import com.jwzhangjie.andbase.widget.TitleNavigate; 8 | import com.jwzhangjie.andbase.widget.TitleNavigate.NavigateListener; 9 | import com.lidroid.xutils.view.annotation.ContentView; 10 | import com.lidroid.xutils.view.annotation.ViewInject; 11 | 12 | 13 | /** 14 | * title: NavigateUsed.java 15 | * @author jwzhangjie 16 | * Date: 2014-12-7 上午11:22:26 17 | * version 1.0 18 | * {@link http://blog.csdn.net/jwzhangjie} 19 | * Description:演示标题栏的基本使用 20 | */ 21 | @ContentView(R.layout.activity_scrollview_edittext) 22 | public class NavigateUsed extends BaseActivity{ 23 | 24 | @ViewInject(R.id.nav_title_bar) 25 | private TitleNavigate nav_title_bar; 26 | 27 | @Override 28 | protected void initData() { 29 | super.initData(); 30 | nav_title_bar.setMiddleText("自定义通用标题栏"); 31 | nav_title_bar.setLeftImg(R.drawable.icon_navigate, 0); 32 | } 33 | 34 | @Override 35 | protected void initListener() { 36 | super.initListener(); 37 | nav_title_bar.setNavigateListener(new NavigateListener() { 38 | 39 | @Override 40 | public void navigateOnClick(View view) { 41 | if (nav_title_bar.getLeftView() == view) { 42 | showInfo("你点击了返回"); 43 | }else if (nav_title_bar.getRightView() == view) { 44 | showInfo("你点击了右边按钮"); 45 | } 46 | } 47 | }); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/PotoViewPagerUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import java.util.List; 4 | 5 | import uk.co.senab.photoview.PhotoView; 6 | import android.graphics.Bitmap; 7 | import android.os.Bundle; 8 | import android.support.v4.view.PagerAdapter; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.ViewGroup.LayoutParams; 12 | 13 | import com.jwzhangjie.andbase.R; 14 | import com.jwzhangjie.andbase.doc.bean.AffixForShowBean; 15 | import com.jwzhangjie.andbase.ui.base.BaseActivity; 16 | import com.jwzhangjie.andbase.util.JieContant; 17 | import com.jwzhangjie.andbase.widget.HackyViewPager; 18 | import com.jwzhangjie.andbase.widget.TitleNavigate; 19 | import com.jwzhangjie.andbase.widget.TitleNavigate.NavigateListener; 20 | import com.lidroid.xutils.view.annotation.ContentView; 21 | import com.lidroid.xutils.view.annotation.ViewInject; 22 | import com.nostra13.universalimageloader.core.DisplayImageOptions; 23 | import com.nostra13.universalimageloader.core.ImageLoader; 24 | 25 | 26 | /** 27 | * title: PotoViewPagerUsed.java 28 | * @author jwzhangjie 29 | * Date: 2014年12月9日 上午11:13:22 30 | * version 1.0 31 | * {@link http://blog.csdn.net/jwzhangjie} 32 | * Description:点击显示大图,缩放功能,需要从其他界面接收点击图片的位置,以及图片列表 33 | */ 34 | @ContentView(R.layout.activity_photo_viewpager) 35 | public class PotoViewPagerUsed extends BaseActivity implements NavigateListener{ 36 | 37 | @ViewInject(R.id.view_pager) 38 | private HackyViewPager mViewPager; 39 | @ViewInject(R.id.title_navigate) 40 | private TitleNavigate titleNavigate; 41 | 42 | private List imgList; 43 | private int firstPosition = 0; 44 | private String title = "图片详情"; 45 | 46 | DisplayImageOptions options; 47 | ImageLoader imageLoader = ImageLoader.getInstance(); 48 | 49 | @Override 50 | protected void beforeCreate() { 51 | super.beforeCreate(); 52 | Bundle bundle = getIntent().getExtras(); 53 | title = bundle.getString("title"); 54 | firstPosition = bundle.getInt("firstPosition", 0); 55 | imgList = bundle.getParcelableArrayList("imgList"); 56 | } 57 | 58 | @Override 59 | protected void initListener() { 60 | super.initListener(); 61 | titleNavigate.setNavigateListener(this); 62 | } 63 | 64 | 65 | @Override 66 | protected void initData() { 67 | super.initData(); 68 | options = new DisplayImageOptions.Builder() 69 | .showImageOnLoading(R.drawable.ic_launcher) 70 | .showImageForEmptyUri(R.drawable.ic_launcher) 71 | .showImageOnFail(R.drawable.ic_launcher) 72 | .cacheInMemory(false).cacheOnDisk(true) 73 | .considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565) 74 | .build(); 75 | titleNavigate.setMiddleText(title); 76 | mViewPager.setAdapter(new PhotoPagerAdapter()); 77 | mViewPager.setCurrentItem(firstPosition); 78 | } 79 | 80 | class PhotoPagerAdapter extends PagerAdapter { 81 | 82 | @Override 83 | public int getCount() { 84 | return imgList == null ? 0 : imgList.size(); 85 | } 86 | 87 | @Override 88 | public View instantiateItem(ViewGroup container, int position) { 89 | PhotoView photoView = new PhotoView(container.getContext()); 90 | AffixForShowBean bean = imgList.get(position); 91 | imageLoader.displayImage( 92 | JieContant.URL_Img_Base + bean.getAffixFolder(), photoView, 93 | options); 94 | // Now just add PhotoView to ViewPager and return it 95 | container.addView(photoView, LayoutParams.MATCH_PARENT, 96 | LayoutParams.MATCH_PARENT); 97 | return photoView; 98 | } 99 | 100 | @Override 101 | public void destroyItem(ViewGroup container, int position, Object object) { 102 | container.removeView((View) object); 103 | } 104 | 105 | @Override 106 | public boolean isViewFromObject(View view, Object object) { 107 | return view == object; 108 | } 109 | 110 | } 111 | 112 | @Override 113 | public void navigateOnClick(View view) { 114 | if (view == titleNavigate.getLeftView()) { 115 | finish(); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/RecyclerViewUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.http.Header; 6 | 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.support.v7.widget.RecyclerView.OnItemClickListener; 10 | import android.view.View; 11 | 12 | import com.google.gson.Gson; 13 | import com.google.gson.reflect.TypeToken; 14 | import com.jwzhangjie.andbase.R; 15 | import com.jwzhangjie.andbase.doc.adapter.AccountAdapter; 16 | import com.jwzhangjie.andbase.doc.bean.GsonBean; 17 | import com.jwzhangjie.andbase.net.DefaultJsonResponseHandler; 18 | import com.jwzhangjie.andbase.net.JieHttpClient; 19 | import com.jwzhangjie.andbase.ui.base.BaseActivity; 20 | import com.lidroid.xutils.view.annotation.ContentView; 21 | import com.lidroid.xutils.view.annotation.ViewInject; 22 | import com.loopj.android.http.RequestParams; 23 | 24 | 25 | /** 26 | * title: RecyclerViewUsed.java 27 | * @author jwzhangjie 28 | * Date: 2014-12-6 下午4:48:20 29 | * version 1.0 30 | * {@link http://blog.csdn.net/jwzhangjie} 31 | * Description:综合演示了RecyclerView的基本使用,Gson解析,数据请求的综合实例 32 | */ 33 | @ContentView(R.layout.activity_recyclerview) 34 | public class RecyclerViewUsed extends BaseActivity{ 35 | 36 | @ViewInject(R.id.recyclerViewId) 37 | private RecyclerView mRecyclerView; 38 | 39 | private AccountAdapter mAccountAdapter; 40 | 41 | private List listAccounts; 42 | 43 | @Override 44 | protected void initView() { 45 | super.initView(); 46 | //这个是必须的 47 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 48 | // 设置布局管理器 49 | mRecyclerView.setLayoutManager(layoutManager); 50 | } 51 | 52 | 53 | @Override 54 | protected void initListener() { 55 | super.initListener(); 56 | //这个功能是我额外添加的 57 | mRecyclerView.setOnItemClickListener(new OnItemClickListener() { 58 | 59 | @Override 60 | public void onItemClick(View view, int position) { 61 | 62 | } 63 | }); 64 | } 65 | 66 | 67 | 68 | @Override 69 | protected void initData() { 70 | super.initData(); 71 | mAccountAdapter = new AccountAdapter(); 72 | mRecyclerView.setAdapter(mAccountAdapter); 73 | getAcccountInfo("url"); 74 | } 75 | 76 | private void getAcccountInfo(String url){ 77 | RequestParams params = new RequestParams(); 78 | params.put("name", "jwzhangjie"); 79 | params.put("pwd", "****"); 80 | JieHttpClient.postBase(url, params, new DefaultJsonResponseHandler(){ 81 | 82 | @Override 83 | public void onFailure(int statusCode, Header[] headers, 84 | String responseBody, Throwable throwable) { 85 | super.onFailure(statusCode, headers, responseBody, throwable); 86 | } 87 | 88 | @Override 89 | public void onSuccess(int statusCode, Header[] headers, 90 | String responseBody) { 91 | super.onSuccess(statusCode, headers, responseBody); 92 | Gson gson = new Gson(); 93 | listAccounts = gson.fromJson(responseBody, new TypeToken>(){}.getType()); 94 | mAccountAdapter.setContent(listAccounts); 95 | } 96 | 97 | }); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/SelectPicUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import java.io.File; 4 | 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Environment; 8 | import android.view.View; 9 | import android.widget.ImageView; 10 | 11 | import com.jwzhangjie.andbase.R; 12 | import com.jwzhangjie.andbase.popup.AddPicturePopup; 13 | import com.jwzhangjie.andbase.ui.base.BaseActivity; 14 | import com.jwzhangjie.andbase.util.FileUtils; 15 | import com.jwzhangjie.andbase.util.JieContant; 16 | import com.lidroid.xutils.view.annotation.ContentView; 17 | import com.lidroid.xutils.view.annotation.ViewInject; 18 | import com.lidroid.xutils.view.annotation.event.OnClick; 19 | import com.nostra13.universalimageloader.core.ImageLoader; 20 | 21 | 22 | /** 23 | * title: SelectPicUsed.java 24 | * @author jwzhangjie 25 | * Date: 2014-12-7 下午10:00:59 26 | * version 1.0 27 | * {@link http://blog.csdn.net/jwzhangjie} 28 | * Description:演示添加本地图片和摄像头拍照 29 | */ 30 | @ContentView(R.layout.activity_select_picture) 31 | public class SelectPicUsed extends BaseActivity { 32 | 33 | @ViewInject(R.id.select_pic) 34 | private ImageView selectPic; 35 | 36 | ImageLoader imageLoader = ImageLoader.getInstance(); 37 | 38 | @OnClick(R.id.select_pic) 39 | public void onClick(View view) { 40 | int id = view.getId(); 41 | switch (id) { 42 | case R.id.select_pic: 43 | AddPicturePopup mPicturePopup = new AddPicturePopup(this); 44 | mPicturePopup.initPopView(view); 45 | break; 46 | 47 | default: 48 | break; 49 | } 50 | } 51 | 52 | @Override 53 | public void onActivityResult(int requestCode, int resultCode, Intent intent) { 54 | super.onActivityResult(requestCode, resultCode, intent); 55 | if (resultCode == JieContant.RESULT_OK) { 56 | switch (requestCode) { 57 | case JieContant.POP_ADD_PICTURE_FROM_CAMERA: 58 | // 这个拍照也是一张 59 | File f = new File(Environment.getExternalStorageDirectory() 60 | + "/localTempImgDir/pickImg.jpg"); 61 | try { 62 | Uri u = Uri.parse(android.provider.MediaStore.Images.Media 63 | .insertImage(getContentResolver(), 64 | f.getAbsolutePath(), null, null)); 65 | if (u != null) { 66 | String filename = FileUtils.getPath(u, this); 67 | imageLoader.displayImage("file:///"+filename, selectPic); 68 | } 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | } 72 | break; 73 | case JieContant.POP_ADD_PICTURE_FROM_PHOTO: 74 | // 这个是最近照片,选择一张 75 | Uri uri = intent.getData(); 76 | if (uri != null) { 77 | String filename = FileUtils.getPath(uri, this); 78 | imageLoader.displayImage("file:///"+filename, selectPic); 79 | } 80 | break; 81 | default: 82 | break; 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/WebSocketUsed.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc; 2 | 3 | import java.net.URI; 4 | import java.net.URISyntaxException; 5 | 6 | import org.java_websocket.drafts.Draft_17; 7 | 8 | import com.jwzhangjie.andbase.net.JieWebSocket; 9 | 10 | /** 11 | * title: WebSocketUsed.java 12 | * @author jwzhangjie 13 | * Date: 2014-12-6 下午3:37:12 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description: JieWebSocket的简单使用,主要还是在JieWebSocket内容处理相关内容 17 | */ 18 | public class WebSocketUsed { 19 | 20 | private JieWebSocket mJieWebSocket; 21 | 22 | public WebSocketUsed() { 23 | try { 24 | mJieWebSocket = new JieWebSocket(new URI("url"), new Draft_17()); 25 | mJieWebSocket.connect(); 26 | } catch (URISyntaxException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/adapter/AccountAdapter.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc.adapter; 2 | 3 | import java.util.List; 4 | 5 | import com.jwzhangjie.andbase.R; 6 | import com.jwzhangjie.andbase.doc.bean.GsonBean; 7 | 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | 15 | 16 | /** 17 | * title: AccountAdapter.java 18 | * @author jwzhangjie 19 | * Date: 2014-12-6 下午4:50:10 20 | * version 1.0 21 | * {@link http://blog.csdn.net/jwzhangjie} 22 | * Description:RecyclerView的适配器 23 | */ 24 | public class AccountAdapter extends 25 | RecyclerView.Adapter { 26 | 27 | private List listDatas; 28 | 29 | public void setContent(List listDatas) { 30 | this.listDatas = listDatas; 31 | notifyDataSetChanged(); 32 | } 33 | 34 | @Override 35 | public int getItemCount() { 36 | return listDatas == null ? 0 : listDatas.size(); 37 | } 38 | 39 | @Override 40 | public void onBindViewHolder(ViewHolder holder, int position) { 41 | GsonBean bean = listDatas.get(position); 42 | holder.accountName.setText(bean.getUser_name()); 43 | holder.accountPwd.setText(bean.getUser_pwd()); 44 | } 45 | 46 | @Override 47 | public ViewHolder onCreateViewHolder(ViewGroup viweGroup, int arg1) { 48 | View view = LayoutInflater.from(viweGroup.getContext()).inflate( 49 | R.layout.item_account_adapter_item, null); 50 | ViewHolder holder = new ViewHolder(view); 51 | return holder; 52 | } 53 | 54 | public static class ViewHolder extends RecyclerView.ViewHolder { 55 | 56 | private ImageView accountImg; 57 | private TextView accountName; 58 | private TextView accountPwd; 59 | 60 | public ViewHolder(View itemView) { 61 | super(itemView); 62 | accountImg = (ImageView) itemView.findViewById(R.id.accountImgId); 63 | accountName = (TextView) itemView.findViewById(R.id.account_name); 64 | accountPwd = (TextView) itemView.findViewById(R.id.account_pwd); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/bean/AffixForShowBean.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc.bean; 2 | 3 | import com.jwzhangjie.andbase.interfaces.IParcelable; 4 | 5 | import android.os.Parcel; 6 | 7 | /** 8 | * title: AffixForShowBean.java 9 | * @author jwzhangjie 10 | * Date: 2014年12月9日 上午11:10:09 11 | * version 1.0 12 | * {@link http://blog.csdn.net/jwzhangjie} 13 | * Description:图片的实体类 14 | */ 15 | public class AffixForShowBean implements IParcelable { 16 | 17 | @Override 18 | public int describeContents() { 19 | return 0; 20 | } 21 | 22 | public AffixForShowBean() { 23 | 24 | } 25 | 26 | private AffixForShowBean(Parcel source) { 27 | readFromParcel(source); 28 | } 29 | 30 | private int id; 31 | private String sysNumber; 32 | //图片存放文件夹 - 原图 33 | private String affixFolder; 34 | //图片名称(系统生成) - 上传的原图 35 | private String affixName; 36 | //图片名称 - 根据上传的图片生成的小图片,用于列表显示时使用 37 | private String affixNameSmall; 38 | //图片名称(原名) - 上传的原图 39 | private String affixOldName; 40 | 41 | @Override 42 | public void writeToParcel(Parcel dest, int flags) { 43 | dest.writeInt(id); 44 | dest.writeString(sysNumber); 45 | dest.writeString(affixFolder); 46 | dest.writeString(affixName); 47 | dest.writeString(affixNameSmall); 48 | dest.writeString(affixOldName); 49 | } 50 | 51 | @Override 52 | public void readFromParcel(Parcel source) { 53 | id = source.readInt(); 54 | sysNumber = source.readString(); 55 | affixFolder = source.readString(); 56 | affixName = source.readString(); 57 | affixNameSmall = source.readString(); 58 | affixOldName = source.readString(); 59 | } 60 | 61 | public static Creator CREATOR = new Creator() { 62 | 63 | @Override 64 | public AffixForShowBean createFromParcel(Parcel source) { 65 | return new AffixForShowBean(source); 66 | } 67 | 68 | @Override 69 | public AffixForShowBean[] newArray(int size) { 70 | return new AffixForShowBean[size]; 71 | } 72 | }; 73 | 74 | public int getId() { 75 | return id; 76 | } 77 | 78 | public void setId(int id) { 79 | this.id = id; 80 | } 81 | 82 | public String getSysNumber() { 83 | return sysNumber; 84 | } 85 | 86 | public void setSysNumber(String sysNumber) { 87 | this.sysNumber = sysNumber; 88 | } 89 | 90 | public String getAffixFolder() { 91 | return affixFolder; 92 | } 93 | 94 | public void setAffixFolder(String affixFolder) { 95 | this.affixFolder = affixFolder; 96 | } 97 | 98 | public String getAffixName() { 99 | return affixName; 100 | } 101 | 102 | public void setAffixName(String affixName) { 103 | this.affixName = affixName; 104 | } 105 | 106 | public String getAffixNameSmall() { 107 | return affixNameSmall; 108 | } 109 | 110 | public void setAffixNameSmall(String affixNameSmall) { 111 | this.affixNameSmall = affixNameSmall; 112 | } 113 | 114 | public String getAffixOldName() { 115 | return affixOldName; 116 | } 117 | 118 | public void setAffixOldName(String affixOldName) { 119 | this.affixOldName = affixOldName; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/bean/GsonBean.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc.bean; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import android.os.Parcel; 7 | 8 | import com.jwzhangjie.andbase.interfaces.IParcelable; 9 | 10 | /** 11 | * title: GsonBean.java 12 | * @author jwzhangjie 13 | * Date: 2014-12-6 下午3:52:52 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description:这个类来测试Gson解析的,同时推荐使用Parcelable而不是Serializable 17 | */ 18 | public class GsonBean implements IParcelable{ 19 | 20 | @Override 21 | public int describeContents() { 22 | return 0; 23 | } 24 | 25 | public GsonBean(){ 26 | 27 | } 28 | 29 | public GsonBean(Parcel source){ 30 | readFromParcel(source); 31 | } 32 | 33 | //用户登录账号 34 | private String user_name; 35 | //用户登录密码 36 | private String user_pwd; 37 | //其他信息,一定要先初始化 38 | private List other = new ArrayList(); 39 | 40 | @Override 41 | public void writeToParcel(Parcel dest, int flags) { 42 | dest.writeString(user_name); 43 | dest.writeString(user_pwd); 44 | dest.writeList(other); 45 | } 46 | 47 | @Override 48 | public void readFromParcel(Parcel source) { 49 | user_name = source.readString(); 50 | user_pwd = source.readString(); 51 | source.readList(other, String.class.getClassLoader()); 52 | } 53 | 54 | public static Creator CREATOR = new Creator() { 55 | 56 | @Override 57 | public GsonBean createFromParcel(Parcel source) { 58 | return new GsonBean(source); 59 | } 60 | 61 | @Override 62 | public GsonBean[] newArray(int size) { 63 | return new GsonBean[size]; 64 | } 65 | 66 | }; 67 | 68 | public String getUser_name() { 69 | return user_name; 70 | } 71 | 72 | public void setUser_name(String user_name) { 73 | this.user_name = user_name; 74 | } 75 | 76 | public String getUser_pwd() { 77 | return user_pwd; 78 | } 79 | 80 | public void setUser_pwd(String user_pwd) { 81 | this.user_pwd = user_pwd; 82 | } 83 | 84 | public List getOther() { 85 | return other; 86 | } 87 | 88 | public void setOther(List other) { 89 | this.other = other; 90 | } 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/db/DBHelper.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc.db; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | 6 | import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; 7 | import com.j256.ormlite.support.ConnectionSource; 8 | import com.j256.ormlite.table.TableUtils; 9 | 10 | 11 | /** 12 | * title: DBHelper.java 13 | * @author jwzhangjie 14 | * Date: 2014年12月8日 下午12:44:37 15 | * version 1.0 16 | * {@link http://blog.csdn.net/jwzhangjie} 17 | * Description:数据库的一个帮助类 18 | */ 19 | public class DBHelper extends OrmLiteSqliteOpenHelper { 20 | 21 | private static final String DATABASE_NAME = "jwzhangjie.db"; 22 | private static final int DATABASE_VERSION = 1; 23 | 24 | public DBHelper(Context context){ 25 | super(context, DATABASE_NAME, null, DATABASE_VERSION); 26 | } 27 | 28 | @Override 29 | public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) { 30 | try { 31 | TableUtils.createTable(connectionSource, Users.class); 32 | TableUtils.createTable(connectionSource, Emails.class); 33 | } catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | 38 | @Override 39 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int oldVer, 40 | int newVer) { 41 | try { 42 | TableUtils.dropTable(connectionSource, Users.class, true); 43 | TableUtils.dropTable(connectionSource, Emails.class, true); 44 | onCreate(sqLiteDatabase, connectionSource); 45 | } catch (Exception e) { 46 | e.printStackTrace(); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/db/DBUtils.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc.db; 2 | 3 | import java.sql.SQLException; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | 8 | import android.content.Context; 9 | 10 | import com.j256.ormlite.dao.Dao; 11 | 12 | /** 13 | * title: DBUtils.java 14 | * @author jwzhangjie 15 | * Date: 2014年12月8日 下午12:44:52 16 | * version 1.0 17 | * {@link http://blog.csdn.net/jwzhangjie} 18 | * Description:数据库操作类 19 | */ 20 | public class DBUtils { 21 | 22 | public static Dao usersDao = null; 23 | public static Dao emailDao = null; 24 | 25 | public DBUtils(Context context) { 26 | if (usersDao == null || emailDao == null) { 27 | DBHelper dbHelper = new DBHelper(context); 28 | try { 29 | if (usersDao == null) { 30 | usersDao = dbHelper.getDao(Users.class); 31 | } 32 | if (emailDao == null) { 33 | emailDao = dbHelper.getDao(Emails.class); 34 | } 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | 41 | /** 42 | * 插入一个用户 43 | */ 44 | public void oneUserCreate(Users user) { 45 | try { 46 | usersDao.createOrUpdate(user); 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | /** 53 | * 连续插入多个用户 54 | */ 55 | 56 | public void moreUserCreate(List users) { 57 | try { 58 | for (Users user : users) { 59 | usersDao.createOrUpdate(user); 60 | } 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | } 65 | 66 | /** 67 | * 查询所有的用户 68 | */ 69 | public List getAllUsers() { 70 | List users = new ArrayList(); 71 | try { 72 | users = usersDao.queryForAll(); 73 | users.remove(0); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | return users; 78 | } 79 | 80 | /** 81 | * 插入一封邮件 82 | */ 83 | public void oneEmailCreate(Emails email) { 84 | try { 85 | emailDao.create(email); 86 | } catch (Exception e) { 87 | e.printStackTrace(); 88 | } 89 | } 90 | 91 | /** 92 | * 插入多封邮件 93 | */ 94 | public void moreEmailCreate(List emails) { 95 | try { 96 | for (Emails email : emails) { 97 | emailDao.create(email); 98 | } 99 | } catch (Exception e) { 100 | e.printStackTrace(); 101 | } 102 | } 103 | 104 | /** 105 | * 更新一封邮件状态 106 | */ 107 | public void updateEmail(Emails email) { 108 | try { 109 | emailDao.update(email); 110 | } catch (SQLException e) { 111 | e.printStackTrace(); 112 | } 113 | } 114 | 115 | /** 116 | * 删除一个邮件 117 | */ 118 | public void deleOneEmail(Emails email) { 119 | try { 120 | emailDao.update(email); 121 | } catch (Exception e) { 122 | e.printStackTrace(); 123 | } 124 | } 125 | 126 | /** 127 | * 查询对应邮箱的用户 128 | */ 129 | public Users getUsersFromEmail(String email) { 130 | Users users = new Users(); 131 | try { 132 | List uList = usersDao.queryForEq("email", email); 133 | if (uList != null && uList.size() > 0) { 134 | users = uList.get(0); 135 | } 136 | } catch (Exception e) { 137 | e.printStackTrace(); 138 | } 139 | return users; 140 | } 141 | 142 | /** 143 | * 查询所有收件人邮件 144 | */ 145 | public List getAllInBoxEmails(String receiverId) { 146 | List emails = new ArrayList(); 147 | try { 148 | emails = emailDao.queryBuilder().orderBy("id", false).where() 149 | .eq("receiverId", receiverId) 150 | .and().eq("state_receiver", "0").query(); 151 | } catch (Exception e) { 152 | e.printStackTrace(); 153 | } 154 | return emails; 155 | } 156 | 157 | /** 158 | * 删除所有的收件箱 159 | */ 160 | public void deleteAllInBoxEmails(int type, String id){ 161 | List emails = null; 162 | try { 163 | switch (type) { 164 | case 1://收件箱 165 | emails = getAllInBoxEmails(id); 166 | for (Emails email : emails) { 167 | email.setState_receiver("1"); 168 | emailDao.update(email); 169 | } 170 | break; 171 | case 2://发件箱 172 | emails = getAllSendEmals(id); 173 | for (Emails email : emails) { 174 | email.setState_send("1"); 175 | emailDao.update(email); 176 | } 177 | break; 178 | case 3://删除箱 179 | emails = getAllDeleteEmals(id); 180 | for (Emails email : emails) { 181 | email.setState_receiver("-1"); 182 | email.setState_send("-1"); 183 | emailDao.update(email); 184 | } 185 | break; 186 | default: 187 | break; 188 | } 189 | } catch (Exception e) { 190 | e.printStackTrace(); 191 | } 192 | } 193 | 194 | /** 195 | * 查询未读收件邮件个数 196 | */ 197 | public int getUnReadInBoxEmail(String receiverId) { 198 | int count = 0; 199 | try { 200 | HashMap params = new HashMap(); 201 | params.put("receiverId", receiverId); 202 | params.put("state_receiver", 0);// 正常 203 | params.put("unRead", 0);// 未读 204 | count = emailDao.queryForFieldValues(params).size(); 205 | } catch (Exception e) { 206 | e.printStackTrace(); 207 | } 208 | return count; 209 | } 210 | 211 | /** 212 | * 查询所有发件人邮件 213 | */ 214 | public List getAllSendEmals(String sendId) { 215 | List emails = new ArrayList(); 216 | try { 217 | emails = emailDao.queryBuilder().orderBy("id", false).where() 218 | .eq("sendId", sendId) 219 | .and().eq("state_send", "0").query(); 220 | } catch (Exception e) { 221 | e.printStackTrace(); 222 | } 223 | return emails; 224 | } 225 | 226 | /** 227 | * 查询所有已删除邮件 228 | * 229 | * @email 收件人和发件人 230 | */ 231 | public List getAllDeleteEmals(String email) { 232 | List emails = new ArrayList(); 233 | List emails_send = new ArrayList(); 234 | try { 235 | HashMap params = new HashMap(); 236 | params.put("sendId", email); 237 | params.put("state_send", 1); 238 | emails_send = emailDao.queryForFieldValues(params); 239 | params.remove("sendId"); 240 | params.remove("state_send"); 241 | params.put("receiverId", email); 242 | params.put("state_receiver", 1); 243 | emails = emailDao.queryForFieldValues(params); 244 | emails.addAll(emails_send); 245 | } catch (Exception e) { 246 | e.printStackTrace(); 247 | } 248 | return emails; 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/db/Emails.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc.db; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.j256.ormlite.field.DatabaseField; 6 | 7 | 8 | /** 9 | * title: Emails.java 10 | * @author jwzhangjie 11 | * Date: 2014年12月8日 下午12:42:40 12 | * version 1.0 13 | * {@link http://blog.csdn.net/jwzhangjie} 14 | * Description:使用ormlite创建表 15 | */ 16 | public class Emails implements Serializable{ 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public Emails(){ 21 | 22 | } 23 | 24 | @DatabaseField(generatedId = true) 25 | private int id; 26 | //发件人邮箱 27 | @DatabaseField 28 | private String sendId; 29 | //收件人邮箱 30 | @DatabaseField 31 | private String receiverId; 32 | //邮件标题 33 | @DatabaseField 34 | private String title; 35 | //邮件内容 36 | @DatabaseField 37 | private String content; 38 | //转账金额 39 | @DatabaseField 40 | private double money_num; 41 | //转账详情 42 | @DatabaseField 43 | private String money_detail; 44 | //创建日期 45 | @DatabaseField 46 | private String createTime; 47 | //转/收账 48 | @DatabaseField 49 | private int money_type; 50 | //邮箱状态 0:正常 1:删除 发件人删除 51 | @DatabaseField 52 | private String state_send; 53 | //邮箱状态 0:正常 1:删除 收件人删除 54 | @DatabaseField 55 | private String state_receiver; 56 | //是否读取 0:未读 1:已读 57 | @DatabaseField 58 | private int unRead; 59 | 60 | public int getId() { 61 | return id; 62 | } 63 | public void setId(int id) { 64 | this.id = id; 65 | } 66 | 67 | public String getSendId() { 68 | return sendId; 69 | } 70 | public void setSendId(String sendId) { 71 | this.sendId = sendId; 72 | } 73 | public String getReceiverId() { 74 | return receiverId; 75 | } 76 | public void setReceiverId(String receiverId) { 77 | this.receiverId = receiverId; 78 | } 79 | public String getTitle() { 80 | return title; 81 | } 82 | public void setTitle(String title) { 83 | this.title = title; 84 | } 85 | public String getContent() { 86 | return content; 87 | } 88 | public void setContent(String content) { 89 | this.content = content; 90 | } 91 | public double getMoney_num() { 92 | return money_num; 93 | } 94 | public void setMoney_num(double money_num) { 95 | this.money_num = money_num; 96 | } 97 | public String getMoney_detail() { 98 | return money_detail; 99 | } 100 | public void setMoney_detail(String money_detail) { 101 | this.money_detail = money_detail; 102 | } 103 | 104 | public String getCreateTime() { 105 | return createTime; 106 | } 107 | public void setCreateTime(String createTime) { 108 | this.createTime = createTime; 109 | } 110 | public int getMoney_type() { 111 | return money_type; 112 | } 113 | public void setMoney_type(int money_type) { 114 | this.money_type = money_type; 115 | } 116 | 117 | public String getState_send() { 118 | return state_send; 119 | } 120 | public void setState_send(String state_send) { 121 | this.state_send = state_send; 122 | } 123 | public String getState_receiver() { 124 | return state_receiver; 125 | } 126 | public void setState_receiver(String state_receiver) { 127 | this.state_receiver = state_receiver; 128 | } 129 | public int getUnRead() { 130 | return unRead; 131 | } 132 | public void setUnRead(int unRead) { 133 | this.unRead = unRead; 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/doc/db/Users.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.doc.db; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | import com.j256.ormlite.field.DatabaseField; 7 | import com.j256.ormlite.table.DatabaseTable; 8 | 9 | 10 | /** 11 | * title: Users.java 12 | * @author jwzhangjie 13 | * Date: 2014年12月8日 下午12:43:49 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description:使用ormlite创建表 17 | */ 18 | @DatabaseTable(tableName = "users") 19 | public class Users implements Serializable{ 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | @DatabaseField(generatedId = true) 24 | private int id; 25 | 26 | @DatabaseField(unique = true) 27 | private String email; 28 | 29 | @DatabaseField 30 | private String pwd; 31 | 32 | @DatabaseField 33 | private String name; 34 | 35 | @DatabaseField 36 | private Date createTime; 37 | 38 | public Users() { 39 | } 40 | 41 | public int getId() { 42 | return id; 43 | } 44 | 45 | public void setId(int id) { 46 | this.id = id; 47 | } 48 | 49 | public String getEmail() { 50 | return email; 51 | } 52 | 53 | public void setEmail(String email) { 54 | this.email = email; 55 | } 56 | 57 | public String getPwd() { 58 | return pwd; 59 | } 60 | 61 | public void setPwd(String pwd) { 62 | this.pwd = pwd; 63 | } 64 | 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | public void setName(String name) { 70 | this.name = name; 71 | } 72 | 73 | public Date getCreateTime() { 74 | return createTime; 75 | } 76 | 77 | public void setCreateTime(Date createTime) { 78 | this.createTime = createTime; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/interfaces/IActivity.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.interfaces; 2 | 3 | import android.os.Bundle; 4 | 5 | public interface IActivity { 6 | 7 | void startActivity(Class cls, boolean isClose); 8 | 9 | void startActivity(Class cls); 10 | 11 | void startActivity(Class cls, Bundle bundle, boolean isClose); 12 | 13 | void startActivityForResult(int request); 14 | 15 | void startActivityForResult(int request, Class cls, boolean isClose); 16 | 17 | void startActivityForResult(int request, Class cls); 18 | 19 | void startActivityForResult(int request, Class cls, Bundle bundle); 20 | } 21 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/interfaces/IFragmentChange.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.interfaces; 2 | 3 | import android.os.Bundle; 4 | 5 | public interface IFragmentChange { 6 | void setId(String id, Bundle bundle); 7 | } 8 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/interfaces/ILayoutInit.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.interfaces; 2 | 3 | public interface ILayoutInit { 4 | void initLayout(); 5 | } 6 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/interfaces/IParcelable.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.interfaces; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | public interface IParcelable extends Parcelable { 7 | void readFromParcel(Parcel source); 8 | } 9 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/net/DefaultJsonResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.net; 2 | 3 | import org.apache.http.Header; 4 | 5 | import com.loopj.android.http.TextHttpResponseHandler; 6 | 7 | /** 8 | * title: DefaultJsonResponseHandler.java 9 | * @author jwzhangjie 10 | * Date: 2014-12-6 下午3:03:51 11 | * version 1.0 12 | * {@link http://blog.csdn.net/jwzhangjie} 13 | * Description:处理服务器回调接口 14 | */ 15 | public class DefaultJsonResponseHandler extends TextHttpResponseHandler { 16 | 17 | public DefaultJsonResponseHandler() { 18 | 19 | } 20 | 21 | @Override 22 | public void onFailure(int statusCode, Header[] headers, 23 | String responseBody, Throwable throwable) { 24 | 25 | } 26 | 27 | @Override 28 | public void onSuccess(int statusCode, Header[] headers, String responseBody) { 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/net/JieHttpClient.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.net; 2 | 3 | import java.io.File; 4 | import java.io.UnsupportedEncodingException; 5 | import java.util.List; 6 | 7 | import org.apache.http.entity.StringEntity; 8 | 9 | import android.content.Context; 10 | 11 | import com.jwzhangjie.andbase.util.JieContant; 12 | import com.loopj.android.http.AsyncHttpClient; 13 | import com.loopj.android.http.RequestParams; 14 | 15 | /** 16 | * title: UEHttpClient.java 17 | * @author jwzhangjie 18 | * Date: 2014-12-6 下午3:07:32 19 | * version 1.0 20 | * {@link http://blog.csdn.net/jwzhangjie} 21 | * Description:使用android-async-http-1.4.4实现以后后台请求 22 | */ 23 | public class JieHttpClient { 24 | 25 | private static final String BASE_URL = JieContant.URL_Base; 26 | private static AsyncHttpClient client = new AsyncHttpClient(); 27 | 28 | static { 29 | client.setTimeout(30000); 30 | } 31 | 32 | public static void get(String url, RequestParams params, 33 | DefaultJsonResponseHandler responseHandler) { 34 | client.get(getAbsUrl(url), params, responseHandler); 35 | } 36 | 37 | /** 38 | * Title: postJson 39 | * Description:上传参数采用json格式 40 | * @param context 41 | * @param url 42 | * @param data 43 | * @param responseHandler 44 | */ 45 | public static void postJson(Context context, String url, String data, 46 | DefaultJsonResponseHandler responseHandler) { 47 | StringEntity entity = null; 48 | if (data != null) { 49 | try { 50 | entity = new StringEntity(data); 51 | } catch (UnsupportedEncodingException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | client.post(context, url, entity, "application/json", responseHandler); 56 | } 57 | 58 | public static void postBase(String url, RequestParams params, 59 | DefaultJsonResponseHandler responseHandler) { 60 | client.post(getAbsUrl(url), params, responseHandler); 61 | } 62 | 63 | public static void post(String url, RequestParams params, 64 | DefaultJsonResponseHandler responseHandler) { 65 | client.post(url, params, responseHandler); 66 | } 67 | 68 | /** 69 | * 70 | * Title: postFiles 71 | * Description:上传文件 72 | * @param url 73 | * @param params 74 | * @param listFile 75 | * @param fileKey 76 | * @param responseHandler 77 | */ 78 | public static void postFiles(String url, RequestParams params, 79 | List listFile, String fileKey, 80 | DefaultJsonResponseHandler responseHandler) { 81 | client.post(getAbsUrl(url), params, listFile, fileKey, responseHandler); 82 | } 83 | 84 | public static String getAbsUrl(String string) { 85 | return BASE_URL + string; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/net/JieWebSocket.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.net; 2 | 3 | import java.net.URI; 4 | import java.util.Map; 5 | 6 | import org.java_websocket.client.WebSocketClient; 7 | import org.java_websocket.drafts.Draft; 8 | import org.java_websocket.handshake.ServerHandshake; 9 | 10 | /** 11 | * title: JieWebSocket.java 12 | * @author jwzhangjie 13 | * Date: 2014-12-6 下午3:34:22 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description:与后台通过WebSocket通信的封装 17 | */ 18 | public class JieWebSocket extends WebSocketClient { 19 | 20 | public JieWebSocket(URI serverUri, Draft draft) { 21 | super(serverUri, draft); 22 | } 23 | 24 | public JieWebSocket(URI serverUri, Draft protocolDraft, 25 | Map httpHeaders, int connectTimeout) { 26 | super(serverUri, protocolDraft, httpHeaders, connectTimeout); 27 | } 28 | 29 | public JieWebSocket(URI serverURI) { 30 | super(serverURI); 31 | } 32 | 33 | @Override 34 | public void onClose(int arg0, String arg1, boolean o) { 35 | 36 | } 37 | 38 | @Override 39 | public void onError(Exception exception) { 40 | exception.printStackTrace(); 41 | } 42 | 43 | /** 44 | * 接收后台发送的信息,格式自己定义 45 | */ 46 | @Override 47 | public void onMessage(String msg) { 48 | 49 | } 50 | 51 | @Override 52 | public void onOpen(ServerHandshake server) { 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/popup/AddPicturePopup.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.popup; 2 | 3 | import java.io.File; 4 | 5 | import com.jwzhangjie.andbase.JieApp; 6 | import com.jwzhangjie.andbase.R; 7 | import com.jwzhangjie.andbase.ui.base.JieBasePopup; 8 | import com.jwzhangjie.andbase.util.JieContant; 9 | import com.lidroid.xutils.ViewUtils; 10 | import com.lidroid.xutils.view.annotation.ViewInject; 11 | import com.lidroid.xutils.view.annotation.event.OnClick; 12 | 13 | import android.app.Activity; 14 | import android.content.Intent; 15 | import android.net.Uri; 16 | import android.os.Environment; 17 | import android.provider.MediaStore; 18 | import android.support.v4.app.Fragment; 19 | import android.view.Gravity; 20 | import android.view.View; 21 | import android.view.View.OnClickListener; 22 | import android.view.ViewGroup.LayoutParams; 23 | import android.widget.TextView; 24 | 25 | /** 26 | * title: AddPicturePopup.java 27 | * @author jwzhangjie 28 | * Date: 2014-12-7 下午9:45:15 29 | * version 1.0 30 | * {@link http://blog.csdn.net/jwzhangjie} 31 | * Description:作为添加图片弹出框 32 | */ 33 | public class AddPicturePopup extends JieBasePopup implements OnClickListener { 34 | 35 | @ViewInject(R.id.pop_add_pic_from_camera) 36 | private TextView addCamera; 37 | @ViewInject(R.id.pop_add_pic_from_photo) 38 | private TextView addPhoto; 39 | @ViewInject(R.id.pop_add_pic_cancel) 40 | private TextView addCancel; 41 | private Fragment fragment; 42 | private Activity activity; 43 | 44 | public AddPicturePopup(Fragment fragment) { 45 | super(); 46 | this.fragment = fragment; 47 | } 48 | 49 | public AddPicturePopup(Activity activity) { 50 | super(); 51 | this.activity = activity; 52 | } 53 | 54 | @Override 55 | public void initPopView(View parent) { 56 | super.initPopView(parent); 57 | view = (View) JieApp.instance.getInflater().inflate( 58 | R.layout.item_pop_add_picture, null); 59 | ViewUtils.inject(this, view); 60 | initPopWindow(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 61 | startPop(Gravity.BOTTOM, 0, 0); 62 | } 63 | 64 | @OnClick({ R.id.pop_add_pic_from_camera, R.id.pop_add_pic_from_photo, 65 | R.id.pop_add_pic_cancel }) 66 | @Override 67 | public void onClick(View v) { 68 | int id = v.getId(); 69 | switch (id) { 70 | case R.id.pop_add_pic_from_camera: 71 | String status = Environment.getExternalStorageState(); 72 | if (status.equals(Environment.MEDIA_MOUNTED)) { 73 | try { 74 | File dir = new File( 75 | Environment.getExternalStorageDirectory() 76 | + "/localTempImgDir"); 77 | if (!dir.exists()) 78 | dir.mkdirs(); 79 | File f = new File(dir, "pickImg.jpg"); 80 | Uri u = Uri.fromFile(f); 81 | Intent intent1 = new Intent(); 82 | intent1 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 83 | intent1.setAction(MediaStore.ACTION_IMAGE_CAPTURE); 84 | intent1.putExtra(MediaStore.Images.Media.ORIENTATION, 0); 85 | intent1.putExtra(MediaStore.EXTRA_OUTPUT, u); 86 | if (fragment != null) { 87 | fragment.startActivityForResult(intent1, 88 | JieContant.POP_ADD_PICTURE_FROM_CAMERA); 89 | } else if (activity != null) { 90 | activity.startActivityForResult(intent1, 91 | JieContant.POP_ADD_PICTURE_FROM_CAMERA); 92 | } 93 | } catch (Exception e) { 94 | e.printStackTrace(); 95 | } 96 | } 97 | mPopupWindow.dismiss(); 98 | break; 99 | case R.id.pop_add_pic_from_photo: 100 | Intent intent = new Intent( 101 | Intent.ACTION_PICK, 102 | android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 103 | if (fragment != null) { 104 | fragment.startActivityForResult(intent, 105 | JieContant.POP_ADD_PICTURE_FROM_PHOTO); 106 | } else if (activity != null) { 107 | activity.startActivityForResult(intent, 108 | JieContant.POP_ADD_PICTURE_FROM_PHOTO); 109 | } 110 | mPopupWindow.dismiss(); 111 | break; 112 | case R.id.pop_add_pic_cancel: 113 | mPopupWindow.dismiss(); 114 | break; 115 | default: 116 | break; 117 | } 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/base/ADBaseAdapter.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.base; 2 | 3 | import java.util.List; 4 | 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | 9 | /** 10 | * title: ADBaseAdapter.java 11 | * @author jwzhangjie 12 | * Date: 2014-12-6-下午1:38:42 13 | * version 1.0 14 | * {@link http://blog.csdn.net/jwzhangjie} 15 | * Description:自定义适配器基础类,采用泛型 16 | */ 17 | public abstract class ADBaseAdapter extends BaseAdapter { 18 | 19 | public List listDatas; 20 | 21 | public void setData(List listDatas) { 22 | this.listDatas = listDatas; 23 | notifyDataSetChanged(); 24 | } 25 | 26 | @Override 27 | public int getCount() { 28 | return listDatas == null ? 0 : listDatas.size(); 29 | } 30 | 31 | @Override 32 | public Object getItem(int position) { 33 | return listDatas.get(position); 34 | } 35 | 36 | @Override 37 | public long getItemId(int position) { 38 | return position; 39 | } 40 | 41 | @Override 42 | public View getView(int position, View convertView, ViewGroup parent) { 43 | return null; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.base; 2 | 3 | import com.jwzhangjie.andbase.interfaces.IActivity; 4 | import com.lidroid.xutils.ViewUtils; 5 | import com.lidroid.xutils.util.LogUtils; 6 | 7 | import android.annotation.SuppressLint; 8 | import android.content.Intent; 9 | import android.os.Bundle; 10 | import android.os.Handler; 11 | import android.os.Message; 12 | import android.support.v4.app.FragmentActivity; 13 | import android.view.Gravity; 14 | import android.widget.Toast; 15 | 16 | 17 | /** 18 | * title: BaseActivity.java 19 | * @author jwzhangjie 20 | * Date: 2014-12-6 下午1:45:21 21 | * version 1.0 22 | * {@link http://blog.csdn.net/jwzhangjie} 23 | * Description:基础类 24 | */ 25 | public class BaseActivity extends FragmentActivity implements IActivity { 26 | 27 | protected Intent startIntent; 28 | private Toast mToast; 29 | protected int PULL_FINISH = 0; 30 | public String ISREFRESH = "isReFresh"; 31 | 32 | @SuppressLint("HandlerLeak") 33 | public Handler handlerMain = new Handler() { 34 | 35 | @Override 36 | public void handleMessage(Message msg) { 37 | super.handleMessage(msg); 38 | Msg(msg); 39 | } 40 | }; 41 | 42 | public void Msg(Message msg) { 43 | 44 | } 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | startIntent = new Intent(); 50 | beforeCreate(); 51 | LogUtils.customTagPrefix = "jwzhangjie"; 52 | initView(); 53 | initListener(); 54 | initData(); 55 | } 56 | 57 | protected void beforeCreate() { 58 | ViewUtils.inject(this); 59 | } 60 | 61 | protected void initView() { 62 | } 63 | 64 | protected void initListener() { 65 | 66 | } 67 | 68 | protected void initData() { 69 | 70 | } 71 | 72 | protected void showInfo(String text) { 73 | if (mToast == null) { 74 | mToast = Toast.makeText(this, text, Toast.LENGTH_SHORT); 75 | mToast.setGravity(Gravity.CENTER, 0, 0); 76 | } else { 77 | mToast.setText(text); 78 | mToast.setDuration(Toast.LENGTH_SHORT); 79 | } 80 | mToast.show(); 81 | } 82 | 83 | protected void showInfo(int text) { 84 | if (mToast == null) { 85 | mToast = Toast.makeText(this, text, Toast.LENGTH_SHORT); 86 | mToast.setGravity(Gravity.CENTER, 0, 0); 87 | } else { 88 | mToast.setText(text); 89 | mToast.setDuration(Toast.LENGTH_SHORT); 90 | } 91 | mToast.show(); 92 | } 93 | 94 | @Override 95 | public void startActivity(Class cls, boolean isClose) { 96 | startIntent.setClass(this, cls); 97 | startActivity(startIntent); 98 | if (isClose) { 99 | this.finish(); 100 | } 101 | } 102 | 103 | @Override 104 | public void startActivity(Class cls) { 105 | startIntent.setClass(this, cls); 106 | startActivity(startIntent); 107 | } 108 | 109 | @Override 110 | public void startActivity(Class cls, Bundle bundle, boolean isClose) { 111 | startIntent.setClass(this, cls); 112 | startIntent.putExtras(bundle); 113 | startActivity(startIntent); 114 | if (isClose) { 115 | this.finish(); 116 | } 117 | } 118 | 119 | @Override 120 | public void startActivityForResult(int request) { 121 | } 122 | 123 | @Override 124 | public void startActivityForResult(int request, Class cls, 125 | boolean isClose) { 126 | startIntent.setClass(this, cls); 127 | super.startActivityForResult(startIntent, request); 128 | if (isClose) { 129 | this.finish(); 130 | } 131 | } 132 | 133 | @Override 134 | public void startActivityForResult(int request, Class cls) { 135 | startIntent.setClass(this, cls); 136 | super.startActivityForResult(startIntent, request); 137 | } 138 | 139 | @Override 140 | public void startActivityForResult(int request, Class cls, Bundle bundle) { 141 | startIntent.setClass(this, cls); 142 | startIntent.putExtras(bundle); 143 | super.startActivityForResult(startIntent, request); 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/base/BaseChangeFragments.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.base; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jwzhangjie.andbase.R; 7 | 8 | import android.os.Bundle; 9 | import android.support.v4.app.Fragment; 10 | import android.support.v4.app.FragmentManager; 11 | import android.support.v4.app.FragmentTransaction; 12 | import android.text.TextUtils; 13 | 14 | 15 | /** 16 | * title: BaseChangeFragments.java 17 | * @author jwzhangjie 18 | * Date: 2014-12-6 下午1:46:58 19 | * version 1.0 20 | * {@link http://blog.csdn.net/jwzhangjie} 21 | * Description:管理Fragment切换使用 22 | */ 23 | public class BaseChangeFragments extends BaseActivity { 24 | 25 | protected FragmentManager mFragmentManager; 26 | protected FragmentTransaction mFragmentTransaction; 27 | 28 | protected String mCurrentFragmentTag; 29 | protected Map mapFragments = new HashMap(); 30 | 31 | @Override 32 | protected void beforeCreate() { 33 | super.beforeCreate(); 34 | mFragmentManager = getSupportFragmentManager(); 35 | } 36 | 37 | protected FragmentTransaction ensureTransaction() { 38 | if (mFragmentTransaction == null) { 39 | mFragmentTransaction = mFragmentManager.beginTransaction(); 40 | // mFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 41 | // mFragmentTransaction.addToBackStack(null); 42 | mFragmentTransaction 43 | .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 44 | } 45 | 46 | return mFragmentTransaction; 47 | } 48 | 49 | protected BaseFragment getFragment(String tag) { 50 | BaseFragment f = (BaseFragment) (mFragmentManager 51 | .findFragmentByTag(tag)); 52 | if (f == null) { 53 | // 在这里判断tag,不同则实例化对应的fragment 54 | f = mapFragments.get(tag); 55 | } 56 | return f; 57 | } 58 | 59 | protected void attachFragment(int layout, Fragment f, String tag) { 60 | if (f != null) { 61 | if (f.isDetached()) { 62 | ensureTransaction(); 63 | mFragmentTransaction.attach(f); 64 | } else if (!f.isAdded()) { 65 | ensureTransaction(); 66 | mFragmentTransaction.add(layout, f, tag); 67 | } 68 | } 69 | } 70 | 71 | protected void detachFragment(Fragment f) { 72 | if (f != null && !f.isDetached()) { 73 | ensureTransaction(); 74 | mFragmentTransaction.detach(f); 75 | } 76 | } 77 | 78 | /** 79 | * @param layout 80 | * @param f 81 | * @param tag 82 | */ 83 | protected void showFragment(int layout, BaseFragment f, String tag) { 84 | if (f != null) { 85 | if (!f.isAdded()) { 86 | ensureTransaction(); 87 | f.updateNet(); 88 | mFragmentTransaction.add(layout, f, tag); 89 | } else { 90 | ensureTransaction(); 91 | f.updateNet(); 92 | mFragmentTransaction.show(f); 93 | } 94 | } 95 | } 96 | 97 | /** 98 | * 进行传值 99 | * 100 | * @param layout 101 | * @param f 102 | * @param tag 103 | * @param bundle 104 | */ 105 | protected void showFragment(int layout, BaseFragment f, String tag, 106 | Bundle bundle) { 107 | if (f != null) { 108 | if (!f.isAdded()) { 109 | ensureTransaction(); 110 | f.updateNet(bundle); 111 | mFragmentTransaction.add(layout, f, tag); 112 | } else { 113 | ensureTransaction(); 114 | f.updateNet(bundle); 115 | mFragmentTransaction.show(f); 116 | } 117 | } 118 | } 119 | 120 | protected void hideFragment(Fragment f) { 121 | if (f != null) { 122 | if (f.isAdded()) { 123 | ensureTransaction(); 124 | mFragmentTransaction.hide(f); 125 | } 126 | } 127 | } 128 | 129 | protected void commitTransactions() { 130 | if (mFragmentTransaction != null && !mFragmentTransaction.isEmpty()) { 131 | mFragmentTransaction.commit(); 132 | mFragmentTransaction = null; 133 | } 134 | } 135 | 136 | /** 137 | * 采用attach和detach来实现fragment的切换,每一次都会进入onCreateView 138 | * 139 | * @param tag 140 | */ 141 | protected void switchFragmenCreate(String tag) { 142 | if (TextUtils.equals(mCurrentFragmentTag, tag)) 143 | return; 144 | if (mCurrentFragmentTag != null) 145 | detachFragment(getFragment(mCurrentFragmentTag)); 146 | attachFragment(R.id.container, getFragment(tag), tag); 147 | mCurrentFragmentTag = tag; 148 | commitTransactions(); 149 | } 150 | 151 | /** 152 | * 采用show和hide来实现fragment的切换,只有第一次都会进入onCreateView 153 | * 154 | * @param tag 155 | */ 156 | protected void switchFragmen(String tag) { 157 | if (TextUtils.equals(mCurrentFragmentTag, tag)) 158 | return; 159 | if (mCurrentFragmentTag != null) 160 | hideFragment(getFragment(mCurrentFragmentTag)); 161 | showFragment(R.id.container, getFragment(tag), tag); 162 | mCurrentFragmentTag = tag; 163 | commitTransactions(); 164 | } 165 | 166 | protected void switchFragmen(String tag, Bundle bundle) { 167 | if (TextUtils.equals(mCurrentFragmentTag, tag)) 168 | return; 169 | if (mCurrentFragmentTag != null) { 170 | BaseFragment preFragment = getFragment(mCurrentFragmentTag); 171 | preFragment.onPause(); 172 | hideFragment(preFragment); 173 | } 174 | showFragment(R.id.container, getFragment(tag), tag, bundle); 175 | mCurrentFragmentTag = tag; 176 | commitTransactions(); 177 | } 178 | 179 | } 180 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/base/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.base; 2 | 3 | import com.jwzhangjie.andbase.interfaces.IActivity; 4 | import com.jwzhangjie.andbase.util.JieContant; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v4.app.Fragment; 9 | import android.support.v4.app.FragmentActivity; 10 | import android.view.Gravity; 11 | import android.view.View; 12 | import android.widget.Toast; 13 | 14 | 15 | /** 16 | * title: BaseFragment.java 17 | * @author jwzhangjie 18 | * Date: 2014-12-6 下午1:51:19 19 | * version 1.0 20 | * {@link http://blog.csdn.net/jwzhangjie} 21 | * Description:Fagment基础类 22 | */ 23 | public class BaseFragment extends Fragment implements IActivity { 24 | 25 | protected View view; 26 | protected FragmentActivity activity; 27 | protected Intent startIntent; 28 | public int PULL_FINISH = 0; 29 | public boolean refresh = false; 30 | public String ISREFRESH = "isReFresh"; 31 | private Toast mToast; 32 | 33 | @Override 34 | public void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | activity = getActivity(); 37 | startIntent = new Intent(); 38 | } 39 | 40 | @Override 41 | public void onViewCreated(View view, Bundle savedInstanceState) { 42 | super.onViewCreated(view, savedInstanceState); 43 | initView(); 44 | initListener(); 45 | initData(); 46 | } 47 | 48 | protected View findViewById(int id) { 49 | return view.findViewById(id); 50 | } 51 | 52 | protected void initView() { 53 | 54 | } 55 | 56 | protected void initListener() { 57 | 58 | } 59 | 60 | protected void initData() { 61 | 62 | } 63 | 64 | /** 65 | * Title: updateNet 66 | * Description: Fragment切换时调用 67 | * @param bundle 切换时传递参数用的 68 | */ 69 | public void updateNet(Bundle bundle) { 70 | 71 | } 72 | 73 | public void updateNet() { 74 | 75 | } 76 | 77 | protected void finish() { 78 | activity.finish(); 79 | } 80 | 81 | protected void finish(Intent intent) { 82 | activity.setResult(JieContant.RESULT_OK, intent); 83 | activity.finish(); 84 | } 85 | 86 | protected void showInfo(String text) { 87 | if (mToast == null) { 88 | mToast = Toast.makeText(activity, text, Toast.LENGTH_SHORT); 89 | mToast.setGravity(Gravity.CENTER, 0, 0); 90 | } else { 91 | mToast.setText(text); 92 | mToast.setDuration(Toast.LENGTH_SHORT); 93 | } 94 | mToast.show(); 95 | } 96 | 97 | protected void showInfo(int text) { 98 | if (mToast == null) { 99 | mToast = Toast.makeText(activity, text, Toast.LENGTH_SHORT); 100 | mToast.setGravity(Gravity.CENTER, 0, 0); 101 | } else { 102 | mToast.setText(text); 103 | mToast.setDuration(Toast.LENGTH_SHORT); 104 | } 105 | mToast.show(); 106 | } 107 | 108 | @Override 109 | public void startActivity(Class cls, boolean isClose) { 110 | 111 | } 112 | 113 | @Override 114 | public void startActivity(Class cls) { 115 | startIntent.setClass(activity, cls); 116 | startActivity(startIntent); 117 | } 118 | 119 | @Override 120 | public void startActivity(Class cls, Bundle bundle, boolean isClose) { 121 | startIntent.setClass(activity, cls); 122 | startIntent.putExtras(bundle); 123 | startActivity(startIntent); 124 | if (isClose) { 125 | activity.finish(); 126 | } 127 | } 128 | 129 | @Override 130 | public void startActivityForResult(int request) { 131 | 132 | } 133 | 134 | @Override 135 | public void startActivityForResult(int request, Class cls, 136 | boolean isClose) { 137 | 138 | } 139 | 140 | @Override 141 | public void startActivityForResult(int request, Class cls) { 142 | 143 | } 144 | 145 | @Override 146 | public void startActivityForResult(int request, Class cls, Bundle bundle) { 147 | startIntent.setClass(activity, cls); 148 | startIntent.putExtras(bundle); 149 | super.startActivityForResult(startIntent, request); 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/base/BaseView.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.base; 2 | 3 | import com.jwzhangjie.andbase.JieApp; 4 | 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | 9 | /** 10 | * title: BaseView.java 11 | * @author jwzhangjie 12 | * Date: 2014-12-7 下午10:34:35 13 | * version 1.0 14 | * {@link http://blog.csdn.net/jwzhangjie} 15 | * Description: 16 | */ 17 | public class BaseView { 18 | protected View view; 19 | protected Toast mToast; 20 | 21 | public BaseView() { 22 | } 23 | 24 | public View findViewById(int id) { 25 | return view.findViewById(id); 26 | } 27 | 28 | protected void showInfo(int text) { 29 | if (mToast == null) { 30 | mToast = Toast.makeText(JieApp.instance, text, Toast.LENGTH_SHORT); 31 | } else { 32 | mToast.setText(text); 33 | mToast.setDuration(Toast.LENGTH_SHORT); 34 | } 35 | mToast.show(); 36 | } 37 | 38 | protected void showInfo(String text) { 39 | if (mToast == null) { 40 | mToast = Toast.makeText(JieApp.instance, text, Toast.LENGTH_SHORT); 41 | } else { 42 | mToast.setText(text); 43 | mToast.setDuration(Toast.LENGTH_SHORT); 44 | } 45 | mToast.show(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/base/JieBasePopup.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.base; 2 | 3 | import com.jwzhangjie.andbase.JieApp; 4 | import com.jwzhangjie.andbase.R; 5 | 6 | import android.graphics.drawable.BitmapDrawable; 7 | import android.graphics.drawable.Drawable; 8 | import android.view.View; 9 | import android.widget.PopupWindow; 10 | 11 | 12 | /** 13 | * title: JieBasePopup.java 14 | * @author jwzhangjie 15 | * Date: 2014-12-7 下午9:09:10 16 | * version 1.0 17 | * {@link http://blog.csdn.net/jwzhangjie} 18 | * Description:封装基础的弹出框 19 | */ 20 | public abstract class JieBasePopup extends BaseView { 21 | 22 | protected PopupWindow mPopupWindow; 23 | private View parentView; 24 | 25 | public JieBasePopup() { 26 | super(); 27 | } 28 | 29 | public void initPopView(View parent) { 30 | parentView = parent; 31 | } 32 | 33 | public void initPopView(View parent, int viewId) { 34 | parentView = parent; 35 | } 36 | 37 | public void initPopWindow(int width, int height) { 38 | if (mPopupWindow == null) { 39 | mPopupWindow = new PopupWindow(view, width, height); 40 | /* 设置触摸外面时消失 */ 41 | mPopupWindow.setOutsideTouchable(true); 42 | mPopupWindow.setBackgroundDrawable(JieApp.instance 43 | .getResources() 44 | .getDrawable(R.drawable.pop_select_catory_bg)); 45 | /* 设置系统动画 */ 46 | mPopupWindow.setAnimationStyle(R.style.popupAnimation); 47 | mPopupWindow.setTouchable(true); 48 | /* 设置点击menu以外其他地方以及返回键退出 */ 49 | mPopupWindow.setFocusable(true); 50 | } 51 | } 52 | 53 | @SuppressWarnings("deprecation") 54 | public void initPopWindow(int width, int height, int anim) { 55 | if (mPopupWindow == null) { 56 | mPopupWindow = new PopupWindow(view, width, height); 57 | mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); 58 | /* 设置触摸外面时消失 */ 59 | mPopupWindow.setOutsideTouchable(true); 60 | /* 设置系统动画 */ 61 | if (anim != -1) { 62 | mPopupWindow.setAnimationStyle(anim); 63 | } 64 | mPopupWindow.setTouchable(true); 65 | /* 设置点击menu以外其他地方以及返回键退出 */ 66 | mPopupWindow.setFocusable(true); 67 | } 68 | } 69 | 70 | public void initPopWindow(Drawable popBg, int width, int height) { 71 | if (mPopupWindow == null) { 72 | mPopupWindow = new PopupWindow(view, width, height); 73 | /* 设置背景显示 */ 74 | if (popBg != null) { 75 | mPopupWindow.setBackgroundDrawable(popBg); 76 | } 77 | /* 设置触摸外面时消失 */ 78 | mPopupWindow.setOutsideTouchable(true); 79 | /* 设置系统动画 */ 80 | mPopupWindow.setAnimationStyle(R.style.popupAnimation); 81 | mPopupWindow.setTouchable(true); 82 | /* 设置点击menu以外其他地方以及返回键退出 */ 83 | mPopupWindow.setFocusable(true); 84 | } 85 | } 86 | 87 | public void startPop(int gravity, int x, int y) { 88 | mPopupWindow.update(); 89 | mPopupWindow.showAtLocation(parentView, gravity, x, y); 90 | } 91 | 92 | public void startPopDown() { 93 | mPopupWindow.update(); 94 | mPopupWindow.showAsDropDown(parentView); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/dialog/WaitingDialog.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.dialog; 2 | 3 | import com.jwzhangjie.andbase.R; 4 | 5 | import android.app.Dialog; 6 | import android.content.Context; 7 | import android.os.Bundle; 8 | import android.widget.ProgressBar; 9 | import android.widget.TextView; 10 | 11 | /** 12 | * title: WaitingDialog.java 13 | * @author jwzhangjie 14 | * Date: 2014-12-8 下午8:14:51 15 | * version 1.0 16 | * {@link http://blog.csdn.net/jwzhangjie} 17 | * Description:使用Dialog实现的,用于网络请求或者耗时操作显示 18 | */ 19 | public class WaitingDialog extends Dialog{ 20 | 21 | private TextView waitingInfo; 22 | private ProgressBar waitingDialog; 23 | 24 | public WaitingDialog(Context context) { 25 | super(context, R.style.waiting_dialog); 26 | } 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.dialog_waiting); 32 | // setCancelable(false); 33 | setCanceledOnTouchOutside(false); 34 | waitingDialog = (ProgressBar)findViewById(R.id.waitingDialogId); 35 | waitingInfo = (TextView)findViewById(R.id.waitingInfoId); 36 | } 37 | 38 | 39 | public void showInfo(String str){ 40 | waitingInfo.setText(str); 41 | } 42 | 43 | public void showInfo(int str){ 44 | waitingInfo.setText(str); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/ui/dialog/WaitingFragmentDialog.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.ui.dialog; 2 | 3 | import com.jwzhangjie.andbase.R; 4 | 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.DialogFragment; 8 | import android.support.v4.app.FragmentManager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | /** 14 | * title: WaitingFragmentDialog.java 15 | * 16 | * @author jwzhangjie 17 | * Date: 2014-12-9 下午9:16:04 version 1.0 18 | * {@link http://blog.csdn.net/jwzhangjie} 19 | * Description:FragmentDialog主要用在FragmentActivity 20 | */ 21 | public class WaitingFragmentDialog extends DialogFragment { 22 | 23 | public WaitingFragmentDialog() { 24 | setStyle(-1, R.style.waiting_dialog); 25 | } 26 | 27 | @Override 28 | public void onActivityCreated(Bundle bundle) { 29 | super.onActivityCreated(bundle); 30 | } 31 | 32 | @Override 33 | public View onCreateView(LayoutInflater inflater, 34 | @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 35 | View view = inflater.inflate(R.layout.dialog_waiting, container, false); 36 | return view; 37 | } 38 | 39 | @Override 40 | public void show(FragmentManager manager, String tag) { 41 | super.show(manager, tag); 42 | } 43 | 44 | /** 45 | * Title: show 46 | * Description:android.support.v4.app.FragmentManager.getSupportFragmentManager() 47 | * @param manager 48 | */ 49 | public void show(FragmentManager manager){ 50 | show(manager, "waitingDialog"); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/util/AppLog.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.util; 2 | 3 | import com.jwzhangjie.andbase.BuildConfig; 4 | 5 | /** 6 | * title: AppLog.java 7 | * @author jwzhangjie 8 | * Date: 2014-12-6 下午3:22:57 9 | * version 1.0 10 | * {@link http://blog.csdn.net/jwzhangjie} 11 | * Description: Wrapper API for sending log output. 12 | */ 13 | public class AppLog { 14 | protected static final String TAG = "jwzhangjie"; 15 | 16 | private AppLog() { 17 | } 18 | 19 | /** 20 | * Send a VERBOSE log message. 21 | * 22 | * @param msg 23 | * The message you would like logged. 24 | */ 25 | public static void v(String msg) { 26 | if (BuildConfig.DEBUG) 27 | android.util.Log.v(TAG, buildMessage(msg)); 28 | } 29 | 30 | /** 31 | * Send a VERBOSE log message and log the exception. 32 | * 33 | * @param msg 34 | * The message you would like logged. 35 | * @param thr 36 | * An exception to log 37 | */ 38 | public static void v(String msg, Throwable thr) { 39 | if (BuildConfig.DEBUG) 40 | android.util.Log.v(TAG, buildMessage(msg), thr); 41 | } 42 | 43 | /** 44 | * Send a DEBUG log message. 45 | * 46 | * @param msg 47 | */ 48 | public static void d(String msg) { 49 | if (BuildConfig.DEBUG) 50 | android.util.Log.d(TAG, buildMessage(msg)); 51 | } 52 | 53 | /** 54 | * Send a DEBUG log message and log the exception. 55 | * 56 | * @param msg 57 | * The message you would like logged. 58 | * @param thr 59 | * An exception to log 60 | */ 61 | public static void d(String msg, Throwable thr) { 62 | if (BuildConfig.DEBUG) 63 | android.util.Log.d(TAG, buildMessage(msg), thr); 64 | } 65 | 66 | /** 67 | * Send an INFO log message. 68 | * 69 | * @param msg 70 | * The message you would like logged. 71 | */ 72 | public static void i(String msg) { 73 | if (BuildConfig.DEBUG) 74 | android.util.Log.i(TAG, buildMessage(msg)); 75 | } 76 | 77 | /** 78 | * Send a INFO log message and log the exception. 79 | * 80 | * @param msg 81 | * The message you would like logged. 82 | * @param thr 83 | * An exception to log 84 | */ 85 | public static void i(String msg, Throwable thr) { 86 | if (BuildConfig.DEBUG) 87 | android.util.Log.i(TAG, buildMessage(msg), thr); 88 | } 89 | 90 | /** 91 | * Send an ERROR log message. 92 | * 93 | * @param msg 94 | * The message you would like logged. 95 | */ 96 | public static void e(String msg) { 97 | if (BuildConfig.DEBUG) 98 | android.util.Log.e(TAG, buildMessage(msg)); 99 | } 100 | 101 | /** 102 | * Send a WARN log message 103 | * 104 | * @param msg 105 | * The message you would like logged. 106 | */ 107 | public static void w(String msg) { 108 | if (BuildConfig.DEBUG) 109 | android.util.Log.w(TAG, buildMessage(msg)); 110 | } 111 | 112 | /** 113 | * Send a WARN log message and log the exception. 114 | * 115 | * @param msg 116 | * The message you would like logged. 117 | * @param thr 118 | * An exception to log 119 | */ 120 | public static void w(String msg, Throwable thr) { 121 | if (BuildConfig.DEBUG) 122 | android.util.Log.w(TAG, buildMessage(msg), thr); 123 | } 124 | 125 | /** 126 | * Send an empty WARN log message and log the exception. 127 | * 128 | * @param thr 129 | * An exception to log 130 | */ 131 | public static void w(Throwable thr) { 132 | if (BuildConfig.DEBUG) 133 | android.util.Log.w(TAG, buildMessage(""), thr); 134 | } 135 | 136 | /** 137 | * Send an ERROR log message and log the exception. 138 | * 139 | * @param msg 140 | * The message you would like logged. 141 | * @param thr 142 | * An exception to log 143 | */ 144 | public static void e(String msg, Throwable thr) { 145 | if (BuildConfig.DEBUG) 146 | android.util.Log.e(TAG, buildMessage(msg), thr); 147 | } 148 | 149 | /** 150 | * Building Message 151 | * 152 | * @param msg 153 | * The message you would like logged. 154 | * @return Message String 155 | */ 156 | protected static String buildMessage(String msg) { 157 | StackTraceElement caller = new Throwable().fillInStackTrace() 158 | .getStackTrace()[2]; 159 | 160 | return caller.getClassName() + "." + caller.getMethodName() + "(): " 161 | + msg; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.util; 2 | 3 | import java.io.File; 4 | import java.io.FileFilter; 5 | import java.net.URISyntaxException; 6 | import java.text.DecimalFormat; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.Comparator; 10 | import java.util.List; 11 | 12 | import android.content.ContentResolver; 13 | import android.content.Context; 14 | import android.content.Intent; 15 | import android.database.Cursor; 16 | import android.graphics.Bitmap; 17 | import android.net.Uri; 18 | import android.provider.MediaStore; 19 | import android.provider.MediaStore.Audio; 20 | import android.provider.MediaStore.Video; 21 | import android.util.Log; 22 | 23 | /** 24 | * title: FileUtils.java 25 | * @author jwzhangjie 26 | * Date: 2014-12-7 下午10:34:51 27 | * version 1.0 28 | * {@link http://blog.csdn.net/jwzhangjie} 29 | * Description: 30 | */ 31 | public class FileUtils { 32 | /** TAG for log messages. */ 33 | static final String TAG = "FileUtils"; 34 | private static final boolean DEBUG = false; // Set to true to enable logging 35 | 36 | public static final String MIME_TYPE_AUDIO = "audio/*"; 37 | public static final String MIME_TYPE_TEXT = "text/*"; 38 | public static final String MIME_TYPE_IMAGE = "image/*"; 39 | public static final String MIME_TYPE_VIDEO = "video/*"; 40 | public static final String MIME_TYPE_APP = "application/*"; 41 | 42 | /** 43 | * Whether the filename is a video file. 44 | * 45 | * @param filename 46 | * @return 47 | */ 48 | /* 49 | * public static boolean isVideo(String filename) { String mimeType = 50 | * getMimeType(filename); if (mimeType != null && 51 | * mimeType.startsWith("video/")) { return true; } else { return false; } } 52 | */ 53 | 54 | /** 55 | * Whether the URI is a local one. 56 | * 57 | * @param uri 58 | * @return 59 | */ 60 | public static boolean isLocal(String uri) { 61 | if (uri != null && !uri.startsWith("http://")) { 62 | return true; 63 | } 64 | return false; 65 | } 66 | 67 | /** 68 | * Gets the extension of a file name, like ".png" or ".jpg". 69 | * 70 | * @param uri 71 | * @return Extension including the dot("."); "" if there is no extension; 72 | * null if uri was null. 73 | */ 74 | public static String getExtension(String uri) { 75 | if (uri == null) { 76 | return null; 77 | } 78 | 79 | int dot = uri.lastIndexOf("."); 80 | if (dot >= 0) { 81 | return uri.substring(dot); 82 | } else { 83 | // No extension. 84 | return ""; 85 | } 86 | } 87 | 88 | /** 89 | * Returns true if uri is a media uri. 90 | * 91 | * @param uri 92 | * @return 93 | */ 94 | public static boolean isMediaUri(Uri uri) { 95 | String uriString = uri.toString(); 96 | if (uriString.startsWith(Audio.Media.INTERNAL_CONTENT_URI.toString()) 97 | || uriString.startsWith(Audio.Media.EXTERNAL_CONTENT_URI 98 | .toString()) 99 | || uriString.startsWith(Video.Media.INTERNAL_CONTENT_URI 100 | .toString()) 101 | || uriString.startsWith(Video.Media.EXTERNAL_CONTENT_URI 102 | .toString())) { 103 | return true; 104 | } else { 105 | return false; 106 | } 107 | } 108 | 109 | /** 110 | * Convert File into Uri. 111 | * 112 | * @param file 113 | * @return uri 114 | */ 115 | public static Uri getUri(File file) { 116 | if (file != null) { 117 | return Uri.fromFile(file); 118 | } 119 | return null; 120 | } 121 | 122 | /** 123 | * Convert Uri into File. 124 | * 125 | * @param uri 126 | * @return file 127 | */ 128 | public static File getFile(Uri uri) { 129 | if (uri != null) { 130 | String filepath = uri.getPath(); 131 | if (filepath != null) { 132 | return new File(filepath); 133 | } 134 | } 135 | return null; 136 | } 137 | 138 | /** 139 | * Returns the path only (without file name). 140 | * 141 | * @param file 142 | * @return 143 | */ 144 | public static File getPathWithoutFilename(File file) { 145 | if (file != null) { 146 | if (file.isDirectory()) { 147 | // no file to be split off. Return everything 148 | return file; 149 | } else { 150 | String filename = file.getName(); 151 | String filepath = file.getAbsolutePath(); 152 | 153 | // Construct path without file name. 154 | String pathwithoutname = filepath.substring(0, 155 | filepath.length() - filename.length()); 156 | if (pathwithoutname.endsWith("/")) { 157 | pathwithoutname = pathwithoutname.substring(0, 158 | pathwithoutname.length() - 1); 159 | } 160 | return new File(pathwithoutname); 161 | } 162 | } 163 | return null; 164 | } 165 | 166 | /** 167 | * Constructs a file from a path and file name. 168 | * 169 | * @param curdir 170 | * @param file 171 | * @return 172 | */ 173 | public static File getFile(String curdir, String file) { 174 | String separator = "/"; 175 | if (curdir.endsWith("/")) { 176 | separator = ""; 177 | } 178 | File clickedFile = new File(curdir + separator + file); 179 | return clickedFile; 180 | } 181 | 182 | public static File getFile(File curdir, String file) { 183 | return getFile(curdir.getAbsolutePath(), file); 184 | } 185 | 186 | /** 187 | * Get a file path from a Uri. 188 | * 189 | * @param context 190 | * @param uri 191 | * @return 192 | * @throws java.net.URISyntaxException 193 | * 194 | * @author paulburke 195 | */ 196 | public static String getPath(Context context, Uri uri) 197 | throws URISyntaxException { 198 | 199 | if (DEBUG) 200 | Log.d(TAG + " File -", 201 | "Authority: " + uri.getAuthority() + ", Fragment: " 202 | + uri.getFragment() + ", Port: " + uri.getPort() 203 | + ", Query: " + uri.getQuery() + ", Scheme: " 204 | + uri.getScheme() + ", Host: " + uri.getHost() 205 | + ", Segments: " + uri.getPathSegments().toString()); 206 | 207 | if ("content".equalsIgnoreCase(uri.getScheme())) { 208 | String[] projection = { "_data" }; 209 | Cursor cursor = null; 210 | 211 | try { 212 | cursor = context.getContentResolver().query(uri, projection, 213 | null, null, null); 214 | int column_index = cursor.getColumnIndexOrThrow("_data"); 215 | if (cursor.moveToFirst()) { 216 | return cursor.getString(column_index); 217 | } 218 | } catch (Exception e) { 219 | // Eat it 220 | } 221 | } 222 | 223 | else if ("file".equalsIgnoreCase(uri.getScheme())) { 224 | return uri.getPath(); 225 | } 226 | 227 | return null; 228 | } 229 | 230 | public static String getFilenameFromUri(Context context, Uri uri) { 231 | String fileName = ""; 232 | String scheme = uri.getScheme(); 233 | if (scheme.equals("file")) { 234 | fileName = uri.getLastPathSegment(); 235 | } else if (scheme.equals("content")) { 236 | String[] proj = { MediaStore.Images.Media.DATA, 237 | MediaStore.Images.Media.DISPLAY_NAME }; 238 | Cursor cursor = context.getContentResolver().query(uri, proj, null, 239 | null, null); 240 | if (cursor != null && cursor.getCount() != 0) { 241 | // http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html 242 | int columnIndex = 0; 243 | cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 244 | cursor.moveToFirst(); 245 | fileName = cursor.getString(columnIndex); 246 | 247 | cursor.close(); 248 | } 249 | } 250 | return fileName; 251 | } 252 | 253 | /** 254 | * Get the file size in a human-readable string. 255 | * 256 | * @param size 257 | * @return 258 | * 259 | * @author paulburke 260 | */ 261 | public static String getReadableFileSize(int size) { 262 | final int BYTES_IN_KILOBYTES = 1024; 263 | final DecimalFormat dec = new DecimalFormat("###.#"); 264 | final String KILOBYTES = " KB"; 265 | final String MEGABYTES = " MB"; 266 | final String GIGABYTES = " GB"; 267 | float fileSize = 0; 268 | String suffix = KILOBYTES; 269 | 270 | if (size > BYTES_IN_KILOBYTES) { 271 | fileSize = size / BYTES_IN_KILOBYTES; 272 | if (fileSize > BYTES_IN_KILOBYTES) { 273 | fileSize = fileSize / BYTES_IN_KILOBYTES; 274 | if (fileSize > BYTES_IN_KILOBYTES) { 275 | fileSize = fileSize / BYTES_IN_KILOBYTES; 276 | suffix = GIGABYTES; 277 | } else { 278 | suffix = MEGABYTES; 279 | } 280 | } 281 | } 282 | return String.valueOf(dec.format(fileSize) + suffix); 283 | } 284 | 285 | /** 286 | * Attempt to retrieve the thumbnail of given Uri from the MediaStore. 287 | * 288 | * This should not be called on the UI thread. 289 | * 290 | * @param context 291 | * @param uri 292 | * @param mimeType 293 | * @return 294 | * 295 | * @author paulburke 296 | */ 297 | public static Bitmap getThumbnail(Context context, Uri uri, String mimeType) { 298 | if (DEBUG) 299 | Log.d(TAG, "Attempting to get thumbnail"); 300 | 301 | if (isMediaUri(uri)) { 302 | Log.e(TAG, 303 | "You can only retrieve thumbnails for images and videos."); 304 | return null; 305 | } 306 | 307 | Bitmap bm = null; 308 | if (uri != null) { 309 | final ContentResolver resolver = context.getContentResolver(); 310 | Cursor cursor = null; 311 | try { 312 | cursor = resolver.query(uri, null, null, null, null); 313 | if (cursor.moveToFirst()) { 314 | final int id = cursor.getInt(0); 315 | if (DEBUG) 316 | Log.d(TAG, "Got thumb ID: " + id); 317 | 318 | if (mimeType.contains("video")) { 319 | bm = Video.Thumbnails.getThumbnail(resolver, id, 320 | Video.Thumbnails.MINI_KIND, null); 321 | } else if (mimeType.contains(FileUtils.MIME_TYPE_IMAGE)) { 322 | bm = MediaStore.Images.Thumbnails.getThumbnail( 323 | resolver, id, 324 | MediaStore.Images.Thumbnails.MINI_KIND, null); 325 | } 326 | } 327 | } catch (Exception e) { 328 | if (DEBUG) 329 | Log.e(TAG, "getThumbnail", e); 330 | } finally { 331 | if (cursor != null) 332 | cursor.close(); 333 | } 334 | } 335 | return bm; 336 | } 337 | 338 | private static final String HIDDEN_PREFIX = "."; 339 | 340 | /** 341 | * File and folder comparator. Expose sorting option method 342 | * 343 | * @author paulburke 344 | */ 345 | private static Comparator mComparator = new Comparator() { 346 | public int compare(File f1, File f2) { 347 | // Sort alphabetically by lower case, which is much cleaner 348 | return f1.getName().toLowerCase() 349 | .compareTo(f2.getName().toLowerCase()); 350 | } 351 | }; 352 | 353 | /** 354 | * File (not directories) filter. 355 | * 356 | * @author paulburke 357 | */ 358 | private static FileFilter mFileFilter = new FileFilter() { 359 | public boolean accept(File file) { 360 | final String fileName = file.getName(); 361 | // Return files only (not directories) and skip hidden files 362 | return file.isFile() && !fileName.startsWith(HIDDEN_PREFIX); 363 | } 364 | }; 365 | 366 | /** 367 | * Folder (directories) filter. 368 | * 369 | * @author paulburke 370 | */ 371 | private static FileFilter mDirFilter = new FileFilter() { 372 | public boolean accept(File file) { 373 | final String fileName = file.getName(); 374 | // Return directories only and skip hidden directories 375 | return file.isDirectory() && !fileName.startsWith(HIDDEN_PREFIX); 376 | } 377 | }; 378 | 379 | /** 380 | * Get a list of Files in the give path 381 | * 382 | * @param path 383 | * @return Collection of files in give directory 384 | * 385 | * @author paulburke 386 | */ 387 | public static List getFileList(String path) { 388 | ArrayList list = new ArrayList(); 389 | 390 | // Current directory File instance 391 | final File pathDir = new File(path); 392 | 393 | // List file in this directory with the directory filter 394 | final File[] dirs = pathDir.listFiles(mDirFilter); 395 | if (dirs != null) { 396 | // Sort the folders alphabetically 397 | Arrays.sort(dirs, mComparator); 398 | // Add each folder to the File list for the list adapter 399 | for (File dir : dirs) 400 | list.add(dir); 401 | } 402 | 403 | // List file in this directory with the file filter 404 | final File[] files = pathDir.listFiles(mFileFilter); 405 | if (files != null) { 406 | // Sort the files alphabetically 407 | Arrays.sort(files, mComparator); 408 | // Add each file to the File list for the list adapter 409 | for (File file : files) 410 | list.add(file); 411 | } 412 | 413 | return list; 414 | } 415 | 416 | /** 417 | * Get the Intent for selecting content to be used in an Intent Chooser. 418 | * 419 | * @return The intent for opening a file with Intent.createChooser() 420 | * 421 | * @author paulburke 422 | */ 423 | public static Intent createGetContentIntent() { 424 | // Implicitly allow the user to select a particular kind of data 425 | final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 426 | // The MIME data type filter 427 | intent.setType("*/*"); 428 | // Only return URIs that can be opened with ContentResolver 429 | intent.addCategory(Intent.CATEGORY_OPENABLE); 430 | return intent; 431 | } 432 | 433 | public static String getPath(Uri uri, Context context) { 434 | String[] proj = { MediaStore.Images.Media.DATA }; 435 | ContentResolver cr = context.getContentResolver(); 436 | Cursor cursor = cr.query(uri, proj, null, null, null); 437 | cursor.moveToFirst(); 438 | int actual_image_column_index = cursor 439 | .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 440 | return cursor.getString(actual_image_column_index); 441 | } 442 | } 443 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/util/JieContant.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.util; 2 | 3 | /** 4 | * title: JieContant.java 5 | * 6 | * @author jwzhangjie 7 | * Date: 2014-12-6 下午1:52:25 8 | * version 1.0 9 | * {@link http://blog.csdn.net/jwzhangjie} 10 | * Description:常亮类 11 | */ 12 | 13 | public class JieContant { 14 | 15 | public static final int RESULT_OK = -1; 16 | 17 | public static final String URL_Base = "";// 项目的基础地址 18 | public static final String URL_Img_Base = "";//服务器图片的地址 19 | 20 | // Request Code 21 | public static final int POP_ADD_PICTURE_FROM_CAMERA = 6666; 22 | public static final int POP_ADD_PICTURE_FROM_PHOTO = 6667; 23 | } 24 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/util/MediaFile.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.util; 2 | 3 | import android.annotation.SuppressLint; 4 | import java.util.HashMap; 5 | import java.util.Iterator; 6 | import java.util.Locale; 7 | 8 | /** 9 | * title: MediaFile.java 10 | * @author jwzhangjie 11 | * Date: 2014-12-6 下午3:26:02 12 | * version 1.0 13 | * {@link http://blog.csdn.net/jwzhangjie} 14 | * Description: 媒体类型检测 15 | */ 16 | public class MediaFile { 17 | // comma separated list of all file extensions supported by the media 18 | // scanner 19 | public static String sFileExtensions; 20 | 21 | // Audio file types 22 | public static final int FILE_TYPE_MP3 = 1; 23 | public static final int FILE_TYPE_M4A = 2; 24 | public static final int FILE_TYPE_WAV = 3; 25 | public static final int FILE_TYPE_AMR = 4; 26 | public static final int FILE_TYPE_AWB = 5; 27 | public static final int FILE_TYPE_WMA = 6; 28 | public static final int FILE_TYPE_OGG = 7; 29 | private static final int FIRST_AUDIO_FILE_TYPE = FILE_TYPE_MP3; 30 | private static final int LAST_AUDIO_FILE_TYPE = FILE_TYPE_OGG; 31 | 32 | // MIDI file types 33 | public static final int FILE_TYPE_MID = 11; 34 | public static final int FILE_TYPE_SMF = 12; 35 | public static final int FILE_TYPE_IMY = 13; 36 | private static final int FIRST_MIDI_FILE_TYPE = FILE_TYPE_MID; 37 | private static final int LAST_MIDI_FILE_TYPE = FILE_TYPE_IMY; 38 | 39 | // Video file types 40 | public static final int FILE_TYPE_MP4 = 21; 41 | public static final int FILE_TYPE_M4V = 22; 42 | public static final int FILE_TYPE_3GPP = 23; 43 | public static final int FILE_TYPE_3GPP2 = 24; 44 | public static final int FILE_TYPE_WMV = 25; 45 | private static final int FIRST_VIDEO_FILE_TYPE = FILE_TYPE_MP4; 46 | private static final int LAST_VIDEO_FILE_TYPE = FILE_TYPE_WMV; 47 | 48 | // Image file types 49 | public static final int FILE_TYPE_JPEG = 31; 50 | public static final int FILE_TYPE_GIF = 32; 51 | public static final int FILE_TYPE_PNG = 33; 52 | public static final int FILE_TYPE_BMP = 34; 53 | public static final int FILE_TYPE_WBMP = 35; 54 | private static final int FIRST_IMAGE_FILE_TYPE = FILE_TYPE_JPEG; 55 | private static final int LAST_IMAGE_FILE_TYPE = FILE_TYPE_WBMP; 56 | 57 | // Playlist file types 58 | public static final int FILE_TYPE_M3U = 41; 59 | public static final int FILE_TYPE_PLS = 42; 60 | public static final int FILE_TYPE_WPL = 43; 61 | private static final int FIRST_PLAYLIST_FILE_TYPE = FILE_TYPE_M3U; 62 | private static final int LAST_PLAYLIST_FILE_TYPE = FILE_TYPE_WPL; 63 | 64 | // 静态内部类 65 | static class MediaFileType { 66 | 67 | int fileType; 68 | String mimeType; 69 | 70 | MediaFileType(int fileType, String mimeType) { 71 | this.fileType = fileType; 72 | this.mimeType = mimeType; 73 | } 74 | } 75 | 76 | private static HashMap sFileTypeMap = new HashMap(); 77 | private static HashMap sMimeTypeMap = new HashMap(); 78 | 79 | @SuppressLint("UseValueOf") 80 | static void addFileType(String extension, int fileType, String mimeType) { 81 | sFileTypeMap.put(extension, new MediaFileType(fileType, mimeType)); 82 | sMimeTypeMap.put(mimeType, new Integer(fileType)); 83 | } 84 | 85 | static { 86 | addFileType("M4A", FILE_TYPE_M4A, "audio/mp4"); 87 | addFileType("MP3", FILE_TYPE_MP3, "audio/mpeg"); 88 | addFileType("WAV", FILE_TYPE_WAV, "audio/x-wav"); 89 | addFileType("AMR", FILE_TYPE_AMR, "audio/amr"); 90 | addFileType("AWB", FILE_TYPE_AWB, "audio/amr-wb"); 91 | addFileType("WMA", FILE_TYPE_WMA, "audio/x-ms-wma"); 92 | addFileType("OGG", FILE_TYPE_OGG, "application/ogg"); 93 | 94 | addFileType("MID", FILE_TYPE_MID, "audio/midi"); 95 | addFileType("XMF", FILE_TYPE_MID, "audio/midi"); 96 | addFileType("RTTTL", FILE_TYPE_MID, "audio/midi"); 97 | addFileType("SMF", FILE_TYPE_SMF, "audio/sp-midi"); 98 | addFileType("IMY", FILE_TYPE_IMY, "audio/imelody"); 99 | 100 | addFileType("MP4", FILE_TYPE_MP4, "video/mp4"); 101 | addFileType("M4V", FILE_TYPE_M4V, "video/mp4"); 102 | addFileType("3GP", FILE_TYPE_3GPP, "video/3gpp"); 103 | addFileType("3GPP", FILE_TYPE_3GPP, "video/3gpp"); 104 | addFileType("3G2", FILE_TYPE_3GPP2, "video/3gpp2"); 105 | addFileType("3GPP2", FILE_TYPE_3GPP2, "video/3gpp2"); 106 | addFileType("WMV", FILE_TYPE_WMV, "video/x-ms-wmv"); 107 | 108 | addFileType("PNG", FILE_TYPE_PNG, "image/png"); 109 | addFileType("JPG", FILE_TYPE_JPEG, "image/jpeg"); 110 | addFileType("JPEG", FILE_TYPE_JPEG, "image/jpeg"); 111 | addFileType("GIF", FILE_TYPE_GIF, "image/gif"); 112 | addFileType("BMP", FILE_TYPE_BMP, "image/x-ms-bmp"); 113 | addFileType("WBMP", FILE_TYPE_WBMP, "image/vnd.wap.wbmp"); 114 | 115 | addFileType("M3U", FILE_TYPE_M3U, "audio/x-mpegurl"); 116 | addFileType("PLS", FILE_TYPE_PLS, "audio/x-scpls"); 117 | addFileType("WPL", FILE_TYPE_WPL, "application/vnd.ms-wpl"); 118 | 119 | // compute file extensions list for native Media Scanner 120 | StringBuilder builder = new StringBuilder(); 121 | Iterator iterator = sFileTypeMap.keySet().iterator(); 122 | 123 | while (iterator.hasNext()) { 124 | if (builder.length() > 0) { 125 | builder.append(','); 126 | } 127 | builder.append(iterator.next()); 128 | } 129 | sFileExtensions = builder.toString(); 130 | } 131 | 132 | public static final String UNKNOWN_STRING = ""; 133 | 134 | public static boolean isAudioFileType(int fileType) { 135 | return ((fileType >= FIRST_AUDIO_FILE_TYPE && fileType <= LAST_AUDIO_FILE_TYPE) || (fileType >= FIRST_MIDI_FILE_TYPE && fileType <= LAST_MIDI_FILE_TYPE)); 136 | } 137 | 138 | public static boolean isVideoFileType(int fileType) { 139 | return (fileType >= FIRST_VIDEO_FILE_TYPE && fileType <= LAST_VIDEO_FILE_TYPE); 140 | } 141 | 142 | public static boolean isImageFileType(int fileType) { 143 | return (fileType >= FIRST_IMAGE_FILE_TYPE && fileType <= LAST_IMAGE_FILE_TYPE); 144 | } 145 | 146 | public static boolean isPlayListFileType(int fileType) { 147 | return (fileType >= FIRST_PLAYLIST_FILE_TYPE && fileType <= LAST_PLAYLIST_FILE_TYPE); 148 | } 149 | 150 | public static MediaFileType getFileType(String path) { 151 | int lastDot = path.lastIndexOf("."); 152 | if (lastDot < 0) 153 | return null; 154 | return sFileTypeMap.get(path.substring(lastDot + 1).toUpperCase( 155 | Locale.getDefault())); 156 | } 157 | 158 | // 根据图片文件路径判断文件类型 159 | public static boolean isImageFileType(String path) { 160 | MediaFileType type = getFileType(path); 161 | if (null != type) { 162 | return isImageFileType(type.fileType); 163 | } 164 | return false; 165 | } 166 | 167 | // 根据视频文件路径判断文件类型 168 | public static boolean isVideoFileType(String path) { // 自己增加 169 | MediaFileType type = getFileType(path); 170 | if (null != type) { 171 | return isVideoFileType(type.fileType); 172 | } 173 | return false; 174 | } 175 | 176 | // 根据音频文件路径判断文件类型 177 | public static boolean isAudioFileType(String path) { // 自己增加 178 | MediaFileType type = getFileType(path); 179 | if (null != type) { 180 | return isAudioFileType(type.fileType); 181 | } 182 | return false; 183 | } 184 | 185 | // 根据mime类型查看文件类型 186 | public static int getFileTypeForMimeType(String mimeType) { 187 | Integer value = sMimeTypeMap.get(mimeType); 188 | return (value == null ? 0 : value.intValue()); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/util/SharePreferenceDelegate.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.util; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.SharedPreferences.Editor; 5 | 6 | 7 | /** 8 | * title: SharePreferenceDelegate.java 9 | * @author jwzhangjie 10 | * Date: 2014-12-6 下午3:22:22 11 | * version 1.0 12 | * {@link http://blog.csdn.net/jwzhangjie} 13 | * Description: 14 | */ 15 | public class SharePreferenceDelegate { 16 | 17 | @SuppressLint("NewApi") 18 | public static final void commit(Editor editor) { 19 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.GINGERBREAD) { 20 | editor.commit(); 21 | } else { 22 | editor.apply(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/util/SharePreferenceKeeper.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.util; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.content.SharedPreferences.Editor; 6 | 7 | /** 8 | * title: SharePreferenceKeeper.java 9 | * @author jwzhangjie 10 | * Date: 2014-12-6 下午3:22:27 11 | * version 1.0 12 | * {@link http://blog.csdn.net/jwzhangjie} 13 | * Description: Share preference utils, used for reading and saving share preference conveniently. 14 | */ 15 | public class SharePreferenceKeeper { 16 | private static final String PREFERENCES_NAME = "preference"; 17 | private static final String PREFERENCES_PERSONAL_NAME = "preference_per"; 18 | 19 | // private static final String PREFERENCES_OBJ_NAME = "preference_obj"; 20 | 21 | public static final void keepStringValue(Context context, String key, 22 | String value) { 23 | keepStringValue(context, key, value, true); 24 | } 25 | 26 | public static final void keepStringValue(Context context, String key, 27 | String value, boolean isPersonal) { 28 | SharedPreferences pref = getSharedPreferences(context, isPersonal); 29 | Editor editor = pref.edit(); 30 | editor.putString(key, value); 31 | SharePreferenceDelegate.commit(editor); 32 | } 33 | 34 | public static final void keepIntValue(Context context, String key, int value) { 35 | keepIntValue(context, key, value, true); 36 | } 37 | 38 | public static final void keepIntValue(Context context, String key, 39 | int value, boolean isPersonal) { 40 | SharedPreferences pref = getSharedPreferences(context, isPersonal); 41 | Editor editor = pref.edit(); 42 | editor.putInt(key, value); 43 | SharePreferenceDelegate.commit(editor); 44 | } 45 | 46 | public static final void keepBooleanValue(Context context, String key, 47 | boolean value) { 48 | keepBooleanValue(context, key, value, true); 49 | } 50 | 51 | public static final void keepBooleanValue(Context context, String key, 52 | boolean value, boolean isPersonal) { 53 | SharedPreferences pref = getSharedPreferences(context, isPersonal); 54 | Editor editor = pref.edit(); 55 | editor.putBoolean(key, value); 56 | SharePreferenceDelegate.commit(editor); 57 | } 58 | 59 | public static final String getStringValue(Context context, String key) { 60 | return getStringValue(context, key, null); 61 | } 62 | 63 | public static final String getStringValue(Context context, String key, 64 | boolean isPersonal) { 65 | return getStringValue(context, key, null, isPersonal); 66 | } 67 | 68 | public static final String getStringValue(Context context, String key, 69 | String defValue) { 70 | return getStringValue(context, key, defValue, true); 71 | } 72 | 73 | public static final String getStringValue(Context context, String key, 74 | String defValue, boolean isPersonal) { 75 | SharedPreferences pref = getSharedPreferences(context, isPersonal); 76 | return pref.getString(key, defValue); 77 | } 78 | 79 | public static final int getIntValue(Context context, String key) { 80 | return getIntValue(context, key, 0); 81 | } 82 | 83 | public static final int getIntValue(Context context, String key, 84 | boolean isPersonal) { 85 | return getIntValue(context, key, 0, isPersonal); 86 | } 87 | 88 | public static final int getIntValue(Context context, String key, 89 | int defValue) { 90 | return getIntValue(context, key, defValue, true); 91 | } 92 | 93 | public static final int getIntValue(Context context, String key, 94 | int defValue, boolean isPersonal) { 95 | SharedPreferences pref = getSharedPreferences(context, isPersonal); 96 | return pref.getInt(key, defValue); 97 | } 98 | 99 | public static final boolean getBooleanValue(Context context, String key) { 100 | return getBooleanValue(context, key, false, true); 101 | } 102 | 103 | public static final boolean getBooleanValue(Context context, String key, 104 | boolean defValue, boolean isPersonal) { 105 | SharedPreferences pref = getSharedPreferences(context, isPersonal); 106 | return pref.getBoolean(key, defValue); 107 | } 108 | 109 | public static void removeKey(Context context, String key) { 110 | removeKey(context, key, true); 111 | } 112 | 113 | public static void removeKey(Context context, String key, boolean isPersonal) { 114 | SharedPreferences pref = getSharedPreferences(context, isPersonal); 115 | Editor editor = pref.edit(); 116 | editor.remove(key); 117 | SharePreferenceDelegate.commit(editor); 118 | } 119 | 120 | public static void clearAll(Context context) { 121 | clearPersonal(context); 122 | 123 | SharedPreferences pref = getSharedPreferences(context, false); 124 | Editor editor = pref.edit(); 125 | editor.clear(); 126 | SharePreferenceDelegate.commit(editor); 127 | } 128 | 129 | public static void clearPersonal(Context context) { 130 | SharedPreferences pref = getSharedPreferences(context, true); 131 | Editor editor = pref.edit(); 132 | editor.clear(); 133 | SharePreferenceDelegate.commit(editor); 134 | } 135 | 136 | private static SharedPreferences getSharedPreferences(Context context, 137 | boolean isPersonal) { 138 | if (isPersonal) { 139 | return context.getSharedPreferences(PREFERENCES_PERSONAL_NAME, 140 | Context.MODE_PRIVATE); 141 | } else { 142 | return context.getSharedPreferences(PREFERENCES_NAME, 143 | Context.MODE_PRIVATE); 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/widget/CircleImageView.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.widget; 2 | 3 | import com.jwzhangjie.andbase.R; 4 | 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.graphics.Bitmap; 8 | import android.graphics.BitmapShader; 9 | import android.graphics.Canvas; 10 | import android.graphics.Color; 11 | import android.graphics.Matrix; 12 | import android.graphics.Paint; 13 | import android.graphics.RectF; 14 | import android.graphics.Shader; 15 | import android.graphics.drawable.BitmapDrawable; 16 | import android.graphics.drawable.ColorDrawable; 17 | import android.graphics.drawable.Drawable; 18 | import android.util.AttributeSet; 19 | import android.widget.ImageView; 20 | 21 | 22 | /** 23 | * title: CircleImageView.java 24 | * @author jwzhangjie 25 | * Date: 2014-12-6 下午4:58:38 26 | * version 1.0 27 | * {@link http://blog.csdn.net/jwzhangjie} 28 | * Description:圆角图片控件 29 | * 37 | */ 38 | public class CircleImageView extends ImageView { 39 | 40 | private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP; 41 | 42 | private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; 43 | private static final int COLORDRAWABLE_DIMENSION = 1; 44 | 45 | private static final int DEFAULT_BORDER_WIDTH = 0; 46 | private static final int DEFAULT_BORDER_COLOR = Color.BLACK; 47 | 48 | private final RectF mDrawableRect = new RectF(); 49 | private final RectF mBorderRect = new RectF(); 50 | 51 | private final Matrix mShaderMatrix = new Matrix(); 52 | private final Paint mBitmapPaint = new Paint(); 53 | private final Paint mBorderPaint = new Paint(); 54 | 55 | private int mBorderColor = DEFAULT_BORDER_COLOR; 56 | private int mBorderWidth = DEFAULT_BORDER_WIDTH; 57 | 58 | private Bitmap mBitmap; 59 | private BitmapShader mBitmapShader; 60 | private int mBitmapWidth; 61 | private int mBitmapHeight; 62 | 63 | private float mDrawableRadius; 64 | private float mBorderRadius; 65 | 66 | private boolean mReady; 67 | private boolean mSetupPending; 68 | 69 | public CircleImageView(Context context) { 70 | super(context); 71 | } 72 | 73 | public CircleImageView(Context context, AttributeSet attrs) { 74 | this(context, attrs, 0); 75 | } 76 | 77 | public CircleImageView(Context context, AttributeSet attrs, int defStyle) { 78 | super(context, attrs, defStyle); 79 | super.setScaleType(SCALE_TYPE); 80 | 81 | TypedArray a = context.obtainStyledAttributes(attrs, 82 | R.styleable.CircleImageView, defStyle, 0); 83 | 84 | mBorderWidth = a.getDimensionPixelSize( 85 | R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH); 86 | mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, 87 | DEFAULT_BORDER_COLOR); 88 | 89 | a.recycle(); 90 | 91 | mReady = true; 92 | 93 | if (mSetupPending) { 94 | setup(); 95 | mSetupPending = false; 96 | } 97 | } 98 | 99 | @Override 100 | public ScaleType getScaleType() { 101 | return SCALE_TYPE; 102 | } 103 | 104 | @Override 105 | public void setScaleType(ScaleType scaleType) { 106 | if (scaleType != SCALE_TYPE) { 107 | throw new IllegalArgumentException(String.format( 108 | "ScaleType %s not supported.", scaleType)); 109 | } 110 | } 111 | 112 | @Override 113 | protected void onDraw(Canvas canvas) { 114 | if (getDrawable() == null) { 115 | return; 116 | } 117 | 118 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius, 119 | mBitmapPaint); 120 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius, 121 | mBorderPaint); 122 | } 123 | 124 | @Override 125 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 126 | super.onSizeChanged(w, h, oldw, oldh); 127 | setup(); 128 | } 129 | 130 | public int getBorderColor() { 131 | return mBorderColor; 132 | } 133 | 134 | public void setBorderColor(int borderColor) { 135 | if (borderColor == mBorderColor) { 136 | return; 137 | } 138 | 139 | mBorderColor = borderColor; 140 | mBorderPaint.setColor(mBorderColor); 141 | invalidate(); 142 | } 143 | 144 | public int getBorderWidth() { 145 | return mBorderWidth; 146 | } 147 | 148 | public void setBorderWidth(int borderWidth) { 149 | if (borderWidth == mBorderWidth) { 150 | return; 151 | } 152 | 153 | mBorderWidth = borderWidth; 154 | setup(); 155 | } 156 | 157 | @Override 158 | public void setImageBitmap(Bitmap bm) { 159 | super.setImageBitmap(bm); 160 | mBitmap = bm; 161 | setup(); 162 | } 163 | 164 | @Override 165 | public void setImageDrawable(Drawable drawable) { 166 | super.setImageDrawable(drawable); 167 | mBitmap = getBitmapFromDrawable(drawable); 168 | setup(); 169 | } 170 | 171 | @Override 172 | public void setImageResource(int resId) { 173 | super.setImageResource(resId); 174 | mBitmap = getBitmapFromDrawable(getDrawable()); 175 | setup(); 176 | } 177 | 178 | private Bitmap getBitmapFromDrawable(Drawable drawable) { 179 | if (drawable == null) { 180 | return null; 181 | } 182 | 183 | if (drawable instanceof BitmapDrawable) { 184 | return ((BitmapDrawable) drawable).getBitmap(); 185 | } 186 | 187 | try { 188 | Bitmap bitmap; 189 | 190 | if (drawable instanceof ColorDrawable) { 191 | bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, 192 | COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); 193 | } else { 194 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), 195 | drawable.getIntrinsicHeight(), BITMAP_CONFIG); 196 | } 197 | 198 | Canvas canvas = new Canvas(bitmap); 199 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 200 | drawable.draw(canvas); 201 | return bitmap; 202 | } catch (OutOfMemoryError e) { 203 | return null; 204 | } 205 | } 206 | 207 | private void setup() { 208 | if (!mReady) { 209 | mSetupPending = true; 210 | return; 211 | } 212 | 213 | if (mBitmap == null) { 214 | return; 215 | } 216 | 217 | mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, 218 | Shader.TileMode.CLAMP); 219 | 220 | mBitmapPaint.setAntiAlias(true); 221 | mBitmapPaint.setShader(mBitmapShader); 222 | 223 | mBorderPaint.setStyle(Paint.Style.STROKE); 224 | mBorderPaint.setAntiAlias(true); 225 | mBorderPaint.setColor(mBorderColor); 226 | mBorderPaint.setStrokeWidth(mBorderWidth); 227 | 228 | mBitmapHeight = mBitmap.getHeight(); 229 | mBitmapWidth = mBitmap.getWidth(); 230 | 231 | mBorderRect.set(0, 0, getWidth(), getHeight()); 232 | mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, 233 | (mBorderRect.width() - mBorderWidth) / 2); 234 | 235 | mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() 236 | - mBorderWidth, mBorderRect.height() - mBorderWidth); 237 | mDrawableRadius = Math.min(mDrawableRect.height() / 2, 238 | mDrawableRect.width() / 2); 239 | 240 | updateShaderMatrix(); 241 | invalidate(); 242 | } 243 | 244 | private void updateShaderMatrix() { 245 | float scale; 246 | float dx = 0; 247 | float dy = 0; 248 | 249 | mShaderMatrix.set(null); 250 | 251 | if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() 252 | * mBitmapHeight) { 253 | scale = mDrawableRect.height() / (float) mBitmapHeight; 254 | dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f; 255 | } else { 256 | scale = mDrawableRect.width() / (float) mBitmapWidth; 257 | dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f; 258 | } 259 | 260 | mShaderMatrix.setScale(scale, scale); 261 | mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, 262 | (int) (dy + 0.5f) + mBorderWidth); 263 | 264 | mBitmapShader.setLocalMatrix(mShaderMatrix); 265 | } 266 | 267 | } -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/widget/HackyViewPager.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.widget; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | 9 | /** 10 | * title: HackyViewPager.java 11 | * @author jwzhangjie 12 | * Date: 2014年12月9日 上午11:07:46 13 | * version 1.0 14 | * {@link http://blog.csdn.net/jwzhangjie} 15 | * Description:图片浏览的ViewPager 16 | */ 17 | public class HackyViewPager extends ViewPager { 18 | 19 | private boolean isLocked; 20 | 21 | public HackyViewPager(Context context) { 22 | super(context); 23 | isLocked = false; 24 | } 25 | 26 | public HackyViewPager(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | isLocked = false; 29 | } 30 | 31 | @Override 32 | public boolean onInterceptTouchEvent(MotionEvent ev) { 33 | if (!isLocked) { 34 | try { 35 | return super.onInterceptTouchEvent(ev); 36 | } catch (IllegalArgumentException e) { 37 | e.printStackTrace(); 38 | return false; 39 | } 40 | } 41 | return false; 42 | } 43 | 44 | @SuppressLint("ClickableViewAccessibility") 45 | @Override 46 | public boolean onTouchEvent(MotionEvent event) { 47 | if (!isLocked) { 48 | return super.onTouchEvent(event); 49 | } 50 | return false; 51 | } 52 | 53 | public void toggleLock() { 54 | isLocked = !isLocked; 55 | } 56 | 57 | public void setLocked(boolean isLocked) { 58 | this.isLocked = isLocked; 59 | } 60 | 61 | public boolean isLocked() { 62 | return isLocked; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/widget/InnerScrollView.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.widget; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.widget.ScrollView; 9 | 10 | /** 11 | * title: InnerScrollView.java 12 | * @author jwzhangjie 13 | * Date: 2014-12-7 上午10:51:25 14 | * version 1.0 15 | * {@link http://blog.csdn.net/jwzhangjie} 16 | * Description:ScrollView与EditText滚动冲突问题 17 | */ 18 | public class InnerScrollView extends ScrollView { 19 | 20 | Handler handler; 21 | 22 | /** 23 | */ 24 | public ScrollView parentScrollView; 25 | 26 | public InnerScrollView(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | handler = new Handler(); 29 | 30 | } 31 | 32 | private int lastScrollDelta = 0; 33 | 34 | public void resume() { 35 | overScrollBy(0, -lastScrollDelta, 0, getScrollY(), 0, getScrollRange(), 0, 0, true); 36 | lastScrollDelta = 0; 37 | } 38 | 39 | int mTop = 10; 40 | 41 | /** 42 | * 将targetView滚到最顶端 43 | */ 44 | public void scrollTo(final View targetView) { 45 | 46 | handler.postDelayed(new Runnable() { 47 | 48 | @Override 49 | public void run() { 50 | int oldScrollY = getScrollY(); 51 | int top = targetView.getTop() - mTop; 52 | final int delatY = top - oldScrollY; 53 | lastScrollDelta = delatY; 54 | smoothScrollTo(0, top); 55 | } 56 | }, 50); 57 | 58 | } 59 | 60 | private int getScrollRange() { 61 | int scrollRange = 0; 62 | if (getChildCount() > 0) { 63 | View child = getChildAt(0); 64 | scrollRange = Math.max(0, child.getHeight() - (getHeight())); 65 | } 66 | return scrollRange; 67 | } 68 | 69 | int currentY; 70 | 71 | @Override 72 | public boolean onInterceptTouchEvent(MotionEvent ev) { 73 | if (parentScrollView == null) { 74 | return super.onInterceptTouchEvent(ev); 75 | } else { 76 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { 77 | // 将父scrollview的滚动事件拦截 78 | currentY = (int)ev.getY(); 79 | setParentScrollAble(false); 80 | return super.onInterceptTouchEvent(ev); 81 | } else if (ev.getAction() == MotionEvent.ACTION_UP) { 82 | // 把滚动事件恢复给父Scrollview 83 | setParentScrollAble(true); 84 | } else if (ev.getAction() == MotionEvent.ACTION_MOVE) { 85 | } 86 | } 87 | return super.onInterceptTouchEvent(ev); 88 | 89 | } 90 | 91 | @Override 92 | public boolean onTouchEvent(MotionEvent ev) { 93 | View child = getChildAt(0); 94 | if (parentScrollView != null) { 95 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 96 | int height = child.getMeasuredHeight(); 97 | height = height - getMeasuredHeight(); 98 | 99 | // System.out.println("height=" + height); 100 | int scrollY = getScrollY(); 101 | // System.out.println("scrollY" + scrollY); 102 | int y = (int)ev.getY(); 103 | 104 | // 手指向下滑动 105 | if (currentY < y) { 106 | if (scrollY <= 0) { 107 | // 如果向下滑动到头,就把滚动交给父Scrollview 108 | setParentScrollAble(true); 109 | return false; 110 | } else { 111 | setParentScrollAble(false); 112 | 113 | } 114 | } else if (currentY > y) { 115 | if (scrollY >= height) { 116 | // 如果向上滑动到头,就把滚动交给父Scrollview 117 | setParentScrollAble(true); 118 | return false; 119 | } else { 120 | setParentScrollAble(false); 121 | 122 | } 123 | 124 | } 125 | currentY = y; 126 | } 127 | } 128 | 129 | return super.onTouchEvent(ev); 130 | } 131 | 132 | /** 133 | * 是否把滚动事件交给父scrollview 134 | * 135 | * @param flag 136 | */ 137 | private void setParentScrollAble(boolean flag) { 138 | 139 | parentScrollView.requestDisallowInterceptTouchEvent(!flag); 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/widget/JieEditTextDel.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.widget; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.jwzhangjie.andbase.R; 6 | 7 | import android.content.Context; 8 | import android.graphics.drawable.Drawable; 9 | import android.text.Editable; 10 | import android.text.InputFilter; 11 | import android.text.InputType; 12 | import android.text.TextUtils; 13 | import android.text.TextUtils.TruncateAt; 14 | import android.text.TextWatcher; 15 | import android.util.AttributeSet; 16 | import android.view.KeyEvent; 17 | import android.view.LayoutInflater; 18 | import android.view.View; 19 | import android.view.inputmethod.EditorInfo; 20 | import android.widget.EditText; 21 | import android.widget.ImageView; 22 | import android.widget.LinearLayout; 23 | import android.widget.TextView; 24 | import android.widget.TextView.OnEditorActionListener; 25 | 26 | /** 27 | * title: JieEditTextDel.java 28 | * @author jwzhangjie 29 | * Date: 2014-12-7 上午11:29:32 30 | * version 1.0 31 | * {@link http://blog.csdn.net/jwzhangjie} 32 | * Description:自定义组合框,分为左,中, 右 左边:一个TextView 中间:一个EditText 右边:一个ImageView,一个TextView 33 | * 自动检测内容,如果有则出现删除图标 34 | */ 35 | public class JieEditTextDel extends LinearLayout { 36 | 37 | protected TextView lefText; 38 | protected EditText middleText; 39 | protected TextView rightText; 40 | protected ImageView rightImg; 41 | private Context context; 42 | protected int maxLen = 999; 43 | 44 | private boolean isDelEnable = true; 45 | 46 | private ArrayList mFocusListeners = new ArrayList(); 47 | private ArrayList mTextWatchers = new ArrayList(); 48 | private ArrayList mClickListeners = new ArrayList(); 49 | private ArrayList mOnClearTextListeners = new ArrayList(); 50 | private ArrayList mOnEditorActionListener = new ArrayList(); 51 | 52 | private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() { 53 | 54 | @Override 55 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 56 | for (OnEditorActionListener l : mOnEditorActionListener) { 57 | l.onEditorAction(v, actionId, event); 58 | return true; 59 | } 60 | return false; 61 | } 62 | }; 63 | 64 | private OnFocusChangeListener mFocusListener = new OnFocusChangeListener() { 65 | @Override 66 | public void onFocusChange(View v, boolean hasFocus) { 67 | for (OnFocusChangeListener listener : mFocusListeners) { 68 | listener.onFocusChange(v, hasFocus); 69 | } 70 | 71 | if (hasFocus && getText().length() > 0 && isDelEnable) { 72 | rightImg.setVisibility(View.VISIBLE); 73 | } else if (isDelEnable) { 74 | rightImg.setVisibility(View.INVISIBLE); 75 | } else { 76 | rightImg.setVisibility(View.GONE); 77 | } 78 | invalidate(); 79 | } 80 | }; 81 | 82 | private TextWatcher mTextWatcher = new TextWatcher() { 83 | 84 | @Override 85 | public void onTextChanged(CharSequence s, int start, int before, 86 | int count) { 87 | for (TextWatcher watch : mTextWatchers) { 88 | watch.onTextChanged(s, start, before, count); 89 | } 90 | 91 | if (s.length() > 0 && isDelEnable) { 92 | rightImg.setVisibility(View.VISIBLE); 93 | } else if (isDelEnable) { 94 | rightImg.setVisibility(View.INVISIBLE); 95 | } else { 96 | rightImg.setVisibility(View.GONE); 97 | } 98 | } 99 | 100 | @Override 101 | public void beforeTextChanged(CharSequence s, int start, int count, 102 | int after) { 103 | for (TextWatcher watch : mTextWatchers) { 104 | watch.beforeTextChanged(s, start, count, after); 105 | } 106 | } 107 | 108 | @Override 109 | public void afterTextChanged(Editable s) { 110 | for (TextWatcher watch : mTextWatchers) { 111 | watch.afterTextChanged(s); 112 | } 113 | } 114 | }; 115 | 116 | private OnClickListener mEditTextClickListener = new OnClickListener() { 117 | 118 | @Override 119 | public void onClick(View v) { 120 | for (OnClickListener l : mClickListeners) { 121 | l.onClick(v); 122 | } 123 | } 124 | }; 125 | 126 | private OnClickListener mDelClickListener = new OnClickListener() { 127 | 128 | @Override 129 | public void onClick(View v) { 130 | middleText.setText(""); 131 | for (OnClearTextListener l : mOnClearTextListeners) { 132 | l.onClearText(); 133 | } 134 | } 135 | }; 136 | 137 | public interface OnClearTextListener { 138 | public void onClearText(); 139 | } 140 | 141 | public JieEditTextDel(Context context) { 142 | super(context); 143 | initLayout(); 144 | 145 | } 146 | 147 | public JieEditTextDel(Context context, AttributeSet attrs) { 148 | super(context, attrs); 149 | initLayout(); 150 | } 151 | 152 | private View view; 153 | 154 | protected void initLayout() { 155 | context = getContext(); 156 | view = LayoutInflater.from(context).inflate(R.layout.item_editext_del, 157 | null); 158 | lefText = (TextView) view.findViewById(R.id.leftText); 159 | middleText = (EditText) view.findViewById(R.id.middleText); 160 | rightText = (TextView) view.findViewById(R.id.rightText); 161 | rightImg = (ImageView) view.findViewById(R.id.right_img); 162 | middleText.setSingleLine(true); 163 | middleText.setEllipsize(TruncateAt.END); 164 | middleText.setClickable(true); 165 | addListener(); 166 | addView(view); 167 | } 168 | 169 | protected void addListener() { 170 | rightImg.setOnClickListener(mDelClickListener); 171 | middleText.setOnClickListener(mEditTextClickListener); 172 | } 173 | 174 | @Override 175 | protected void onAttachedToWindow() { 176 | super.onAttachedToWindow(); 177 | middleText.setOnFocusChangeListener(mFocusListener); 178 | middleText.addTextChangedListener(mTextWatcher); 179 | middleText.setOnEditorActionListener(mEditorActionListener); 180 | } 181 | 182 | @Override 183 | protected void onDetachedFromWindow() { 184 | middleText.setOnFocusChangeListener(null); 185 | middleText.removeTextChangedListener(mTextWatcher); 186 | middleText.setOnEditorActionListener(null); 187 | super.onDetachedFromWindow(); 188 | } 189 | 190 | public void setError(CharSequence text) { 191 | middleText.setError(text); 192 | } 193 | 194 | public void setHint(int resId) { 195 | middleText.setHint(resId); 196 | } 197 | 198 | public void setHint(CharSequence text) { 199 | middleText.setHint(text); 200 | } 201 | 202 | public void setHintColor(int color) { 203 | middleText.setHintTextColor(color); 204 | } 205 | 206 | public CharSequence getHint() { 207 | return middleText.getHint(); 208 | } 209 | 210 | public String getContent() { 211 | return getText().toString().trim(); 212 | } 213 | 214 | public boolean isEmpty() { 215 | return TextUtils.isEmpty(getContent()); 216 | } 217 | 218 | public void addOnFocusChangeListener(OnFocusChangeListener l) { 219 | mFocusListeners.add(l); 220 | } 221 | 222 | public boolean removeOnFocusChangeListener(OnFocusChangeListener l) { 223 | return mFocusListeners.remove(l); 224 | } 225 | 226 | public void addOnClearTextListener(OnClearTextListener l) { 227 | mOnClearTextListeners.add(l); 228 | } 229 | 230 | public void addOnEditorActionListener(OnEditorActionListener l) { 231 | mOnEditorActionListener.add(l); 232 | } 233 | 234 | public boolean removeOnClearTextListener(OnClearTextListener l) { 235 | return mOnClearTextListeners.remove(l); 236 | } 237 | 238 | public void addOnClickListener(OnClickListener l) { 239 | mClickListeners.add(l); 240 | } 241 | 242 | public boolean removeOnClickListener(OnClickListener l) { 243 | return mClickListeners.remove(l); 244 | } 245 | 246 | public void addTextChangedListener(TextWatcher watcher) { 247 | mTextWatchers.add(watcher); 248 | } 249 | 250 | public boolean removeTextChangedListener(TextWatcher watcher) { 251 | return mTextWatchers.remove(watcher); 252 | } 253 | 254 | public boolean isEditTextFocused() { 255 | return middleText.hasFocus(); 256 | } 257 | 258 | public void setText(int resId) { 259 | middleText.setText(resId); 260 | } 261 | 262 | public void setText(CharSequence text) { 263 | middleText.setText(text); 264 | } 265 | 266 | public void setPassword() { 267 | middleText.setInputType(InputType.TYPE_CLASS_TEXT 268 | | InputType.TYPE_TEXT_VARIATION_PASSWORD); 269 | } 270 | 271 | public void setOnlyNumber() { 272 | middleText.setInputType(InputType.TYPE_CLASS_NUMBER); 273 | } 274 | 275 | public void setNumber(){ 276 | middleText.setInputType(EditorInfo.TYPE_CLASS_PHONE|InputType.TYPE_CLASS_TEXT); 277 | } 278 | 279 | public void setNumberPwd() { 280 | middleText.setInputType(InputType.TYPE_CLASS_TEXT 281 | | InputType.TYPE_TEXT_VARIATION_PASSWORD); 282 | } 283 | 284 | public void setMaxLen(int len) { 285 | maxLen = len; 286 | middleText.setFilters(new InputFilter[] { new InputFilter.LengthFilter( 287 | len) }); 288 | } 289 | 290 | public void setSelection(int index) { 291 | middleText.setSelection(index); 292 | } 293 | 294 | public void setFilters(InputFilter[] filters) { 295 | middleText.setFilters(filters); 296 | } 297 | 298 | public void setInputType(int type) { 299 | middleText.setInputType(type); 300 | } 301 | 302 | public void setEditTextTag(Object tag) { 303 | middleText.setTag(tag); 304 | } 305 | 306 | public void setTextSize(float size) { 307 | middleText.setTextSize(size); 308 | } 309 | 310 | // 设置文本显示的方向 311 | public void setTextLocal(int local) { 312 | middleText.setGravity(local); 313 | } 314 | 315 | public void setTextSize(int unit, float size) { 316 | middleText.setTextSize(unit, size); 317 | } 318 | 319 | public Editable getText() { 320 | return middleText.getText(); 321 | } 322 | 323 | public void setLines(int lines) { 324 | middleText.setLines(lines); 325 | } 326 | 327 | public void setMaxLines(int lines){ 328 | middleText.setMaxLines(lines); 329 | } 330 | 331 | public void setLeftText(String text) { 332 | lefText.setText(text); 333 | } 334 | 335 | public void setLeftMinEms(int minEms) { 336 | lefText.setMinEms(minEms); 337 | } 338 | 339 | public void setLeftText(int text) { 340 | lefText.setText(text); 341 | } 342 | 343 | /** 344 | * @param drawable 345 | * @param orientation 346 | * left:0 top:1 right:2 bottom:3 347 | */ 348 | public void setLeftImg(int drawable, int orientation) { 349 | Drawable img = getResources().getDrawable(drawable); 350 | // 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示 351 | img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight()); 352 | switch (orientation) { 353 | case 0: 354 | lefText.setCompoundDrawables(img, null, null, null); 355 | break; 356 | case 1: 357 | lefText.setCompoundDrawables(null, img, null, null); 358 | break; 359 | case 2: 360 | lefText.setCompoundDrawables(null, null, img, null); 361 | break; 362 | case 3: 363 | lefText.setCompoundDrawables(null, null, null, img); 364 | break; 365 | } 366 | } 367 | 368 | public void setRightText(String text) { 369 | if (rightText.getVisibility() == View.GONE) { 370 | rightText.setVisibility(View.VISIBLE); 371 | } 372 | rightText.setText(text); 373 | } 374 | 375 | public void setMiddleTextGravity(int gravity) { 376 | middleText.setGravity(gravity); 377 | } 378 | 379 | public void setRightText(int text) { 380 | if (rightText.getVisibility() == View.GONE) { 381 | rightText.setVisibility(View.VISIBLE); 382 | } 383 | rightText.setText(text); 384 | } 385 | 386 | public void setRightImg(int drawable) { 387 | if (rightImg.getVisibility() == View.GONE) { 388 | rightImg.setVisibility(View.VISIBLE); 389 | } 390 | rightImg.setImageResource(drawable); 391 | } 392 | 393 | public void RightImgStatus(boolean opt) { 394 | isDelEnable = opt; 395 | if (opt) 396 | rightImg.setVisibility(View.VISIBLE); 397 | else 398 | rightImg.setVisibility(View.GONE); 399 | } 400 | 401 | public void setReadOnly() { 402 | middleText.setKeyListener(null); 403 | middleText.setFocusable(false); 404 | } 405 | 406 | public void getFocus() { 407 | middleText.setFocusable(true); 408 | middleText.setFocusableInTouchMode(true); 409 | middleText.requestFocus(); 410 | } 411 | 412 | public void setLeftHide() { 413 | lefText.setVisibility(View.GONE); 414 | } 415 | 416 | public void setRightTextColor(int color) { 417 | rightText.setTextColor(color); 418 | } 419 | 420 | public void setLeftTextColor(int color) { 421 | lefText.setTextColor(color); 422 | } 423 | 424 | public void setMiddleTextColor(int color) { 425 | middleText.setTextColor(color); 426 | } 427 | 428 | public void setEditEnable(boolean opt) { 429 | middleText.setEnabled(false); 430 | } 431 | 432 | public void setVisibility(int opt) { 433 | middleText.setVisibility(opt); 434 | } 435 | 436 | public void setHide(int opt) { 437 | setVisibility(opt); 438 | } 439 | 440 | public void setRightTextImg(int drawable) { 441 | if (rightText.getVisibility() == View.GONE) { 442 | rightText.setVisibility(View.VISIBLE); 443 | } 444 | rightText.setBackgroundResource(drawable); 445 | } 446 | 447 | public void setBg(int bg) { 448 | view.setBackgroundResource(bg); 449 | } 450 | } 451 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/widget/MarqueeTextView.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.TextView; 6 | 7 | 8 | /** 9 | * title: MarqueeTextView.java 10 | * @author jwzhangjie 11 | * Date: 2014-12-7 上午10:45:23 12 | * version 1.0 13 | * {@link http://blog.csdn.net/jwzhangjie} 14 | * Description:跑马灯效果 15 | * android:singleLine="true" 16 | * android:ellipsize="marquee" 17 | * android:focusable="true" 18 | * android:focusableInTouchMode="true" 19 | * android:scrollHorizontally="true" 20 | * android:marqueeRepeatLimit="marquee_forever" 21 | */ 22 | public class MarqueeTextView extends TextView { 23 | 24 | public MarqueeTextView(Context context) { 25 | super(context); 26 | } 27 | 28 | public MarqueeTextView(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | } 31 | 32 | @Override 33 | public boolean isFocused() { 34 | return true; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/widget/TitleNavigate.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.widget; 2 | 3 | import com.lidroid.xutils.ViewUtils; 4 | import com.lidroid.xutils.view.annotation.ViewInject; 5 | import com.lidroid.xutils.view.annotation.event.OnClick; 6 | 7 | import com.jwzhangjie.andbase.R; 8 | 9 | import android.content.Context; 10 | import android.graphics.drawable.Drawable; 11 | import android.util.AttributeSet; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.widget.RelativeLayout; 15 | import android.widget.TextView; 16 | 17 | 18 | /** 19 | * title: TitleNavigate.java 20 | * @author jwzhangjie 21 | * Date: 2014-12-7 上午11:15:23 22 | * version 1.0 23 | * {@link http://blog.csdn.net/jwzhangjie} 24 | * Description: 自定义通用的标题栏 25 | */ 26 | public class TitleNavigate extends RelativeLayout { 27 | 28 | @ViewInject(R.id.leftView) 29 | private TextView leftView; 30 | @ViewInject(R.id.middleView) 31 | private TextView middleView; 32 | @ViewInject(R.id.rightView) 33 | private TextView rightView; 34 | @ViewInject(R.id.rightView_1) 35 | private TextView rightView_1; 36 | private Context context; 37 | private View view; 38 | 39 | public interface NavigateListener { 40 | public void navigateOnClick(View view); 41 | } 42 | 43 | public NavigateListener navigateListener; 44 | 45 | public void setNavigateListener(NavigateListener navigateListener) { 46 | this.navigateListener = navigateListener; 47 | } 48 | 49 | public TitleNavigate(Context context) { 50 | this(context, null); 51 | } 52 | 53 | public TitleNavigate(Context context, AttributeSet attrs) { 54 | super(context, attrs); 55 | initLayout(); 56 | } 57 | 58 | private void initLayout() { 59 | context = getContext(); 60 | view = LayoutInflater.from(context).inflate(R.layout.item_title_bar, null); 61 | ViewUtils.inject(this, view); 62 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( 63 | RelativeLayout.LayoutParams.MATCH_PARENT, 64 | RelativeLayout.LayoutParams.WRAP_CONTENT); 65 | addView(view, params); 66 | } 67 | 68 | public void setBg(int bg) { 69 | view.setBackgroundResource(bg); 70 | } 71 | 72 | @OnClick({ R.id.leftView, R.id.rightView, R.id.rightView_1 }) 73 | public void onClick(View view) { 74 | if (navigateListener != null) { 75 | navigateListener.navigateOnClick(view); 76 | } 77 | } 78 | 79 | class leftClick implements View.OnClickListener { 80 | @Override 81 | public void onClick(View v) { 82 | if (navigateListener != null) { 83 | navigateListener.navigateOnClick(v); 84 | } 85 | } 86 | } 87 | 88 | class rightClick implements View.OnClickListener { 89 | @Override 90 | public void onClick(View v) { 91 | if (navigateListener != null) { 92 | navigateListener.navigateOnClick(v); 93 | } 94 | } 95 | 96 | } 97 | 98 | public TextView getLeftView() { 99 | return this.leftView; 100 | } 101 | 102 | public void setLeftText(String text) { 103 | leftView.setText(text); 104 | } 105 | 106 | public void setLeftText(int text) { 107 | leftView.setText(text); 108 | } 109 | 110 | /** 111 | * @param drawable 112 | * @param orientation 113 | * left:0 top:1 right:2 bottom:3 114 | */ 115 | public void setLeftImg(int drawable, int orientation) { 116 | Drawable img = getResources().getDrawable(drawable); 117 | // 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示 118 | img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight()); 119 | switch (orientation) { 120 | case 0: 121 | leftView.setCompoundDrawables(img, null, null, null); 122 | break; 123 | case 1: 124 | leftView.setCompoundDrawables(null, img, null, null); 125 | break; 126 | case 2: 127 | leftView.setCompoundDrawables(null, null, img, null); 128 | break; 129 | case 3: 130 | leftView.setCompoundDrawables(null, null, null, img); 131 | break; 132 | } 133 | } 134 | 135 | public void setMiddleText(String text) { 136 | middleView.setText(text); 137 | } 138 | 139 | public void setMiddleText(int text) { 140 | middleView.setText(text); 141 | } 142 | 143 | /** 144 | * @param drawable 145 | * @param orientation 146 | * left:0 top:1 right:2 bottom:3 147 | */ 148 | public void setMiddleImg(int drawable, int orientation) { 149 | Drawable img = getResources().getDrawable(drawable); 150 | // 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示 151 | img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight()); 152 | switch (orientation) { 153 | case 0: 154 | middleView.setCompoundDrawables(img, null, null, null); 155 | break; 156 | case 1: 157 | middleView.setCompoundDrawables(null, img, null, null); 158 | break; 159 | case 2: 160 | middleView.setCompoundDrawables(null, null, img, null); 161 | break; 162 | case 3: 163 | middleView.setCompoundDrawables(null, null, null, img); 164 | break; 165 | } 166 | } 167 | 168 | public void setLeftVisiable(int invisible) { 169 | leftView.setVisibility(invisible); 170 | } 171 | 172 | public void setRightText(int resid) { 173 | rightView.setText(resid); 174 | } 175 | 176 | public void setRightText(String text) { 177 | rightView.setText(text); 178 | } 179 | 180 | public TextView getRightView() { 181 | return this.rightView; 182 | } 183 | 184 | public void setRightImg(int drawable, int orientation) { 185 | Drawable img = getResources().getDrawable(drawable); 186 | // 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示 187 | img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight()); 188 | switch (orientation) { 189 | case 0: 190 | rightView.setCompoundDrawables(img, null, null, null); 191 | break; 192 | case 1: 193 | rightView.setCompoundDrawables(null, img, null, null); 194 | break; 195 | case 2: 196 | rightView.setCompoundDrawables(null, null, img, null); 197 | break; 198 | case 3: 199 | rightView.setCompoundDrawables(null, null, null, img); 200 | break; 201 | } 202 | } 203 | 204 | public View getRightView1() { 205 | return rightView_1; 206 | } 207 | 208 | public void setRightView1(int drawable, int orientation) { 209 | Drawable img = getResources().getDrawable(drawable); 210 | // 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示 211 | img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight()); 212 | switch (orientation) { 213 | case 0: 214 | rightView_1.setCompoundDrawables(img, null, null, null); 215 | break; 216 | case 1: 217 | rightView_1.setCompoundDrawables(null, img, null, null); 218 | break; 219 | case 2: 220 | rightView_1.setCompoundDrawables(null, null, img, null); 221 | break; 222 | case 3: 223 | rightView_1.setCompoundDrawables(null, null, null, img); 224 | break; 225 | } 226 | } 227 | 228 | public void setRightView1Show(boolean opt) { 229 | if (opt) { 230 | rightView_1.setVisibility(View.VISIBLE); 231 | } else { 232 | rightView_1.setVisibility(View.GONE); 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /AndJie/src/com/jwzhangjie/andbase/widget/VerticalScrollTextView.java: -------------------------------------------------------------------------------- 1 | package com.jwzhangjie.andbase.widget; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import android.content.Context; 7 | import android.graphics.Canvas; 8 | import android.graphics.Paint; 9 | import android.util.AttributeSet; 10 | import android.widget.TextView; 11 | 12 | /** 13 | * title: VerticalScrollTextView.java 14 | * @author jwzhangjie 15 | * Date: 2014-12-6 下午3:28:28 16 | * version 1.0 17 | * {@link http://blog.csdn.net/jwzhangjie} 18 | * Description:文本内容垂直滚动,最好在xml里面设置一个初始文本 19 | */ 20 | public class VerticalScrollTextView extends TextView { 21 | 22 | private float step = 0f; 23 | private Paint mPaint; 24 | private String text; 25 | private float width; 26 | private List textList = new ArrayList(); // 分行保存textview的显示信息。 27 | StringBuilder builder = new StringBuilder(); 28 | 29 | public VerticalScrollTextView(Context context, AttributeSet attrs) { 30 | super(context, attrs); 31 | text = getText().toString(); 32 | mPaint = new Paint(); 33 | mPaint.setTextSize(34); 34 | } 35 | 36 | public VerticalScrollTextView(Context context) { 37 | super(context); 38 | } 39 | 40 | /** 41 | * Title: setText 42 | * Description:动态设置滚动的文本内容 43 | * @param text 44 | */ 45 | public void setText(String text) { 46 | this.text = text; 47 | requestLayout(); 48 | invalidate(); 49 | } 50 | 51 | @Override 52 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 53 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 54 | width = getMeasuredWidth(); 55 | final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 56 | if (widthMode != MeasureSpec.EXACTLY) { 57 | throw new IllegalStateException( 58 | "ScrollLayout only canmCurScreen run at EXACTLY mode!"); 59 | } 60 | 61 | float length = 0; 62 | int count = text.length(); 63 | if (text == null || count == 0) { 64 | return; 65 | } 66 | 67 | // 下面的代码是根据宽度和字体大小,来计算textview显示的行数。 68 | textList.clear(); 69 | builder.delete(0, builder.length()); 70 | for (int i = 0; i < count; i++) { 71 | if (length < width) { 72 | builder.append(text.charAt(i)); 73 | length += mPaint.measureText(text.substring(i, i + 1)); 74 | if (i == text.length() - 1) { 75 | textList.add(builder.toString()); 76 | } 77 | } else { 78 | textList.add(builder.toString().substring(0, 79 | builder.toString().length() - 1)); 80 | builder.delete(0, builder.length() - 1); 81 | length = mPaint.measureText(text.substring(i, i + 1)); 82 | i--; 83 | } 84 | } 85 | } 86 | 87 | // 下面代码是利用上面计算的显示行数,将文字画在画布上,实时更新。 88 | @Override 89 | public void onDraw(Canvas canvas) { 90 | if (textList.size() == 0) 91 | return; 92 | for (int i = 0; i < textList.size(); i++) { 93 | canvas.drawText(textList.get(i), 5, this.getHeight() + (i + 1) 94 | * mPaint.getTextSize() - step, getPaint()); 95 | } 96 | 97 | invalidate(); 98 | step = step + 0.2f; 99 | if (step >= this.getHeight() + textList.size() * mPaint.getTextSize()) { 100 | step = 0; 101 | } 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AndJie 2 | ====== 3 | 4 | 安卓框架一步一步搭建,项目搭建规则、基础库添加 5 | --------------------------------------------------------------------------------