From 501a2661d767e836688669d180eaaf1c413eccc8 Mon Sep 17 00:00:00 2001 From: zjlong Date: Tue, 19 Apr 2016 14:27:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B2=A1=E7=94=A8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/encodings.xml | 2 + app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 1 + app/src/main/java/com/matto/App.java | 5 +- .../com/matto/model/config/ApiConstant.java | 10 + .../com/matto/model/http/ServiceFactory.java | 7 +- .../ui/activity/AndroidSwipActivity.java | 21 + .../com/matto/ui/activity/LoginActivity.java | 7 +- .../com/matto/ui/activity/MainActivity.java | 3 +- .../com/matto/ui/fragment/HomeFragment.java | 20 +- .../com/matto/ui/fragment/ShowMeFragment.java | 2 +- .../java/com/matto/ui/widget/TitleBar.java | 10 +- app/src/main/res/drawable-xxhdpi/app_logo.png | Bin 0 -> 3901 bytes app/src/main/res/layout/activity_common.xml | 15 + app/src/main/res/layout/activity_login.xml | 3 + .../main/res/layout/layout_nav_toolbar.xml | 0 .../src/main/res/layout/view_tool_bar.xml | 4 +- basic/build.gradle | 8 +- .../java/com/common/BasicApplication.java | 35 ++ .../main/java/com/common/EasyApplication.java | 49 -- .../java/com/common/model/basic/ToastTip.java | 4 +- .../com/common/model/control/LogicProxy.java | 2 - .../model/http/HttpCacheInterceptor.java | 9 +- .../com/common/model/http/HttpClient.java | 15 +- .../main/java/com/common/view/Constant.java | 10 - .../com/common/view/base/BaseActivity.java | 12 +- .../common/view/base/SwipBackActivity.java | 37 -- .../common/view/base/SwipeBackActivity.java | 60 +++ .../com/common/view/base/SwipeBackLayout.java | 468 ++++++++++++++++++ .../com/common/view/base/WebViewActivity.java | 134 ----- .../common/view/widget/SwipeBackLayout.java | 240 --------- .../main/res/drawable-xxhdpi/shadow_left.png | Bin 2865 -> 0 bytes .../src/main/res/layout/activity_hosting.xml | 16 - .../src/main/res/layout/activity_webview.xml | 26 - .../src/main/res/layout/base_swip_layout.xml | 5 - basic/src/main/res/layout/fragment_list.xml | 45 -- basic/src/main/res/values/colors.xml | 2 + 37 files changed, 676 insertions(+), 613 deletions(-) create mode 100644 app/src/main/java/com/matto/model/config/ApiConstant.java create mode 100644 app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java rename basic/src/main/java/com/common/view/base/EasyToolBar.java => app/src/main/java/com/matto/ui/widget/TitleBar.java (93%) create mode 100644 app/src/main/res/drawable-xxhdpi/app_logo.png create mode 100644 app/src/main/res/layout/activity_common.xml rename {basic => app}/src/main/res/layout/layout_nav_toolbar.xml (100%) rename {basic => app}/src/main/res/layout/view_tool_bar.xml (73%) create mode 100644 basic/src/main/java/com/common/BasicApplication.java delete mode 100644 basic/src/main/java/com/common/EasyApplication.java delete mode 100644 basic/src/main/java/com/common/view/Constant.java delete mode 100644 basic/src/main/java/com/common/view/base/SwipBackActivity.java create mode 100644 basic/src/main/java/com/common/view/base/SwipeBackActivity.java create mode 100644 basic/src/main/java/com/common/view/base/SwipeBackLayout.java delete mode 100644 basic/src/main/java/com/common/view/base/WebViewActivity.java delete mode 100644 basic/src/main/java/com/common/view/widget/SwipeBackLayout.java delete mode 100644 basic/src/main/res/drawable-xxhdpi/shadow_left.png delete mode 100644 basic/src/main/res/layout/activity_hosting.xml delete mode 100644 basic/src/main/res/layout/activity_webview.xml delete mode 100644 basic/src/main/res/layout/base_swip_layout.xml delete mode 100644 basic/src/main/res/layout/fragment_list.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 2ecf143..ada076f 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,8 @@ + + diff --git a/app/build.gradle b/app/build.gradle index c4411b9..9725a14 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,7 +20,7 @@ android { } repositories { - maven { url "https://jitpack.matto" } + maven { url "https://jitpack.io" } } dependencies { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f6e8ef3..e97d472 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ + diff --git a/app/src/main/java/com/matto/App.java b/app/src/main/java/com/matto/App.java index 063e667..7061fe3 100644 --- a/app/src/main/java/com/matto/App.java +++ b/app/src/main/java/com/matto/App.java @@ -1,6 +1,6 @@ package com.matto; -import com.common.EasyApplication; +import com.common.BasicApplication; import com.common.model.control.LogicProxy; import com.matto.model.LoginLogic; import com.matto.model.MainLogic; @@ -9,11 +9,12 @@ * author miekoz on 2016/3/17. * email meikoz@126.com */ -public class App extends EasyApplication { +public class App extends BasicApplication { @Override public void onCreate() { super.onCreate(); + LogicProxy.getInstance().init( LoginLogic.class, MainLogic.class ); diff --git a/app/src/main/java/com/matto/model/config/ApiConstant.java b/app/src/main/java/com/matto/model/config/ApiConstant.java new file mode 100644 index 0000000..1cadc12 --- /dev/null +++ b/app/src/main/java/com/matto/model/config/ApiConstant.java @@ -0,0 +1,10 @@ +package com.matto.model.config; + +/** + * author meikoz on 2016/4/19. + * email meikoz@126.com + */ +public interface ApiConstant { + + String BASE_URL = "http://gank.avosapps.com/api/"; +} diff --git a/app/src/main/java/com/matto/model/http/ServiceFactory.java b/app/src/main/java/com/matto/model/http/ServiceFactory.java index 5c66c32..56dec21 100644 --- a/app/src/main/java/com/matto/model/http/ServiceFactory.java +++ b/app/src/main/java/com/matto/model/http/ServiceFactory.java @@ -1,6 +1,7 @@ package com.matto.model.http; import com.common.model.http.HttpClient; +import com.matto.model.config.ApiConstant; import com.matto.pojo.Gank; import retrofit2.Call; @@ -16,13 +17,9 @@ public class ServiceFactory { public static MainService getMainIns(){ if (mService == null){ - mService = HttpClient.getIns().createService(MainService.class); + mService = HttpClient.getIns(ApiConstant.BASE_URL).createService(MainService.class); } return mService; } - public Call getBenefitsGoods(int size, int page){ - return mService.getMainAndroid(size,page); - } - } diff --git a/app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java b/app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java new file mode 100644 index 0000000..eb931d6 --- /dev/null +++ b/app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java @@ -0,0 +1,21 @@ +package com.matto.ui.activity; + +import android.os.Bundle; + +import com.common.view.base.SwipeBackActivity; +import com.common.view.base.SwipeBackLayout; +import com.matto.R; + +/** + * author meikoz on 2016/4/19. + * email meikoz@126.com + */ +public class AndroidSwipActivity extends SwipeBackActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_common); + setDragEdge(SwipeBackLayout.DragEdge.LEFT); + } +} diff --git a/app/src/main/java/com/matto/ui/activity/LoginActivity.java b/app/src/main/java/com/matto/ui/activity/LoginActivity.java index 908f5bb..52f688e 100644 --- a/app/src/main/java/com/matto/ui/activity/LoginActivity.java +++ b/app/src/main/java/com/matto/ui/activity/LoginActivity.java @@ -6,6 +6,7 @@ import com.common.model.basic.ToastTip; import com.common.view.base.BaseActivity; +import com.matto.ui.widget.TitleBar; import com.matto.R; import com.common.model.control.LogicProxy; import com.matto.model.LoginLogic; @@ -31,6 +32,9 @@ public static void start(Activity activity) { @Bind(R.id.edit_passwrod) EditText mEditPasswrod; + @Bind(R.id.title_bar) + TitleBar titlebar; + LoginLogic mLoginLogic; @Override @@ -40,18 +44,19 @@ protected int getLayoutResource() { @Override protected void onInitView() { + titlebar.setTitle("登录页面"); mLoginLogic = LogicProxy.getInstance().getBindViewProxy(LoginLogic.class, this); } @OnClick(R.id.btn_login) void login() { mLoginLogic.login("zhangsan", "123"); + startActivity(new Intent(LoginActivity.this, AndroidSwipActivity.class)); } @Override public void onLoginSuccess() { ToastTip.show("登录成功"); - MainActivity.start(LoginActivity.this); } @Override diff --git a/app/src/main/java/com/matto/ui/activity/MainActivity.java b/app/src/main/java/com/matto/ui/activity/MainActivity.java index 98b2367..bffdfcd 100644 --- a/app/src/main/java/com/matto/ui/activity/MainActivity.java +++ b/app/src/main/java/com/matto/ui/activity/MainActivity.java @@ -11,6 +11,7 @@ import com.matto.R; import com.matto.model.MainLogic; import com.matto.ui.fragment.DiscoveryFragment; +import com.matto.ui.fragment.HomeFragment; import com.matto.ui.fragment.ShowMeFragment; import com.matto.ui.view.MainView; @@ -42,7 +43,7 @@ protected void onInitView() { @Override public void switchHome() { - startFragment(new DiscoveryFragment()); + startFragment(new HomeFragment()); } @Override diff --git a/app/src/main/java/com/matto/ui/fragment/HomeFragment.java b/app/src/main/java/com/matto/ui/fragment/HomeFragment.java index 0e42d86..5241be4 100644 --- a/app/src/main/java/com/matto/ui/fragment/HomeFragment.java +++ b/app/src/main/java/com/matto/ui/fragment/HomeFragment.java @@ -1,13 +1,26 @@ package com.matto.ui.fragment; +import android.content.Intent; +import android.view.View; +import android.widget.ImageView; + import com.common.view.base.BaseFragment; +import com.common.view.widget.OnClickEvent; import com.matto.R; +import com.matto.ui.activity.AndroidSwipActivity; +import com.matto.ui.activity.LoginActivity; + +import butterknife.Bind; /** * author meikoz on 2016/4/19. * email meikoz@126.com */ public class HomeFragment extends BaseFragment { + + @Bind(R.id.splash_view) + ImageView splashView; + @Override protected int getLayoutResource() { return R.layout.activity_spalsh; @@ -15,6 +28,11 @@ protected int getLayoutResource() { @Override protected void onInitData() { - + splashView.setOnClickListener(new OnClickEvent() { + @Override + public void singleClick(View v) { + startActivity(new Intent(getActivity(), AndroidSwipActivity.class)); + } + }); } } diff --git a/app/src/main/java/com/matto/ui/fragment/ShowMeFragment.java b/app/src/main/java/com/matto/ui/fragment/ShowMeFragment.java index 882dab9..e52cbbd 100644 --- a/app/src/main/java/com/matto/ui/fragment/ShowMeFragment.java +++ b/app/src/main/java/com/matto/ui/fragment/ShowMeFragment.java @@ -10,7 +10,7 @@ public class ShowMeFragment extends BaseFragment { @Override protected int getLayoutResource() { - return R.layout.activity_hosting; + return R.layout.activity_listview; } @Override diff --git a/basic/src/main/java/com/common/view/base/EasyToolBar.java b/app/src/main/java/com/matto/ui/widget/TitleBar.java similarity index 93% rename from basic/src/main/java/com/common/view/base/EasyToolBar.java rename to app/src/main/java/com/matto/ui/widget/TitleBar.java index e6c2a8d..5695770 100644 --- a/basic/src/main/java/com/common/view/base/EasyToolBar.java +++ b/app/src/main/java/com/matto/ui/widget/TitleBar.java @@ -1,4 +1,4 @@ -package com.common.view.base; +package com.matto.ui.widget; import android.app.Activity; import android.content.Context; @@ -11,14 +11,14 @@ import android.widget.RelativeLayout; import android.widget.TextView; -import com.common.R; import com.common.utils.DisplayUtil; +import com.matto.R; /** * author miekoz on 2016/3/15. * email meikoz@126.com */ -public class EasyToolBar extends RelativeLayout implements View.OnClickListener { +public class TitleBar extends RelativeLayout implements View.OnClickListener { LinearLayout mlvTitleRight; TextView mTvTitle; @@ -27,12 +27,12 @@ public class EasyToolBar extends RelativeLayout implements View.OnClickListener private OnClickTitleBarBackCallback mCallBack; private TextView mTvRightText; - public EasyToolBar(Context context) { + public TitleBar(Context context) { super(context); onInit(); } - public EasyToolBar(Context context, AttributeSet attrs) { + public TitleBar(Context context, AttributeSet attrs) { super(context, attrs); onInit(); TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.titlebarview); diff --git a/app/src/main/res/drawable-xxhdpi/app_logo.png b/app/src/main/res/drawable-xxhdpi/app_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..100112a9fa67283c78d5183dc7a14753b1c2540c GIT binary patch literal 3901 zcmaJ^c{r5q+a7C_B|Bvq6CuoIpBl>;TMUx$+Q%3SW?{xIA!|t1Y}qPgFS3q}B3-{|-D{=PrHzUMfe=en=^xX$xh?(>iPNwhRK;y!%rFaQAHHZew9F|6ys z%fZh0&g2AXGK?6_z>apF>_H2{`r`q5?qoMS(1eKf#9QI9?je3p@Mi!37I}iT9nB77 zhQN`DVC+E*IG9LbpaFn0I>8hy&IeBey5T(uBqV6`Ea7Th{)i6*DMIY})Fb?&{ zpAR*+#)bOewA?{D+Q2ix2nGQW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)2pyk7XEwG}LB7_C~G5BuDHUrfS(X zKC2Dr=n%HA#sLkM6VJeT>V*hYL)~HnTc2ZJgD*(TJ>v40`%r6l3US70!aKT7)R8M% zfut^Qv07lg@s!96OMkYTo)D>NF7e4{xliJj#|xS>zn?U3PPI?&6SP8erkQp@1WvNi zrmo}-I@kGW2Uomp?erx)BUauHiqo;K^MrD{rI<07RT{FY+D1AEW!kqBe|-7ox7ulH z#>?AAp}QklW|<7Xe6%6D^Fs}8Onju)=Y?G8F|XUEG^CnT?y5K&?a_SvoL)1{wiXvM ziDZb{Iob{!W72d<$|uv<>^wI~TX}(N&rJ(H7sj+sZRk`Y=q^860~N)&+=!yWGlsX0 zUkQWL0$hrMs>YkngR}FJZFzz^r^LEghl{+MyV&1Ffs3|n{R_v(kLI$zc*FhTo@Hm2 z^`>k=!;kWJyPXz=i$9MqnWVCdULbp&;Uat4b{pvM$EeTjlx}SM)mNt9-(t#n@M?<2 z>}(P~U(yGznd0ahypC8e-bmz)c%OW6%v$h;3@6XPW|elVBR>Y`3%45=;eT|>lEd9q zx{yabhdOxMny}jr&S|Ze0o*mXBtD8KK-HUOXOtZ)wwqtCSdyx|x5Y@y8Yd#6ZOy$D zziXeQG<|26<+yLj1Vd>F1yI#Ed&HO$coTG7#KYJMuSk5ZEdV#z&*f?zG*2O*36?SW@NWulv2$r)>Js%dpC4o zuRQUA9^?)?$&M`G@(^16H3-MT*M1R6jt+*RBC~Au`&|u~X^cx6y9B@G<0WbLmMGSO z`K_by0z>An>!BQCUqMWEfi^=+(bVFhq-%g=mh8=)58@Tnctsw0;D$tD^}&1%wc|)^+MZ`3FC=CI;r{T9j+_{{Ta#!_WW# literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_common.xml b/app/src/main/res/layout/activity_common.xml new file mode 100644 index 0000000..4d4d9db --- /dev/null +++ b/app/src/main/res/layout/activity_common.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 682637c..2d30260 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -2,8 +2,11 @@ + + - diff --git a/basic/build.gradle b/basic/build.gradle index bdeaeed..3bfe319 100644 --- a/basic/build.gradle +++ b/basic/build.gradle @@ -1,7 +1,4 @@ apply plugin: 'com.android.library' -repositories { - maven { url "https://jitpack.matto" } -} android { compileSdkVersion 23 @@ -21,7 +18,9 @@ android { } } - +repositories { + maven { url "https://jitpack.io" } +} dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) @@ -34,6 +33,7 @@ dependencies { compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' compile 'com.squareup.okhttp3:logging-interceptor:3.1.2' + // Glide compile 'com.github.bumptech.glide:glide:3.7.0' compile files('libs/BaiduLBS_Android.jar') diff --git a/basic/src/main/java/com/common/BasicApplication.java b/basic/src/main/java/com/common/BasicApplication.java new file mode 100644 index 0000000..b15dc75 --- /dev/null +++ b/basic/src/main/java/com/common/BasicApplication.java @@ -0,0 +1,35 @@ +package com.common; + +import android.app.Application; +import android.content.Context; + +import com.common.model.basic.LocationTip; + +/** + * author miekoz on 2016/3/17. + * email meikoz@126.com + */ +public class BasicApplication extends Application { + + private static BasicApplication ourInstance = new BasicApplication(); + private static Context mContext; + + public static BasicApplication getInstance() { + return ourInstance; + } + + public static Context getContext() { + return mContext; + } + + @Override + public void onCreate() { + super.onCreate(); + ourInstance = this; + mContext = getApplicationContext(); + + new LocationTip(this).doStartLocation(); + } + + +} diff --git a/basic/src/main/java/com/common/EasyApplication.java b/basic/src/main/java/com/common/EasyApplication.java deleted file mode 100644 index b1dda9e..0000000 --- a/basic/src/main/java/com/common/EasyApplication.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.common; - -import android.app.Application; -import android.content.Context; - -import com.common.model.basic.LocationTip; -import com.common.view.Constant; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -/** - * author miekoz on 2016/3/17. - * email meikoz@126.com - */ -public class EasyApplication extends Application { - public Gson gson; - private static EasyApplication ourInstance = new EasyApplication(); - private static Context mContext; - - public static EasyApplication getInstance() { - return ourInstance; - } - - public static Context getContext() { - return mContext; - } - - @Override - public void onCreate() { - super.onCreate(); - ourInstance = this; - mContext = getApplicationContext(); - this.initGson(); - -// LogLevel logLevel; -// if (Config.DEBUG)logLevel =LogLevel.FULL; -// else logLevel=LogLevel.NONE; -// -// Logger.init().methodOffset(2).methodCount(2).logLevel(logLevel); - - new LocationTip(this).doStartLocation(); - } - - private void initGson() { - this.gson = new GsonBuilder() - .setDateFormat(Constant.GANK_DATA_FORMAT) - .create(); - } -} diff --git a/basic/src/main/java/com/common/model/basic/ToastTip.java b/basic/src/main/java/com/common/model/basic/ToastTip.java index 13f206e..dfaf997 100644 --- a/basic/src/main/java/com/common/model/basic/ToastTip.java +++ b/basic/src/main/java/com/common/model/basic/ToastTip.java @@ -2,7 +2,7 @@ import android.widget.Toast; -import com.common.EasyApplication; +import com.common.BasicApplication; /** * author meikoz on 2016/4/13. @@ -18,7 +18,7 @@ public static void show(CharSequence message) { if (message.length() > 10) { duration = Toast.LENGTH_LONG; } - mToast = Toast.makeText(EasyApplication.getInstance(), message, duration); + mToast = Toast.makeText(BasicApplication.getInstance(), message, duration); } else { mToast.setText(message); } diff --git a/basic/src/main/java/com/common/model/control/LogicProxy.java b/basic/src/main/java/com/common/model/control/LogicProxy.java index d73c07d..85e68c3 100644 --- a/basic/src/main/java/com/common/model/control/LogicProxy.java +++ b/basic/src/main/java/com/common/model/control/LogicProxy.java @@ -28,7 +28,6 @@ private LogicProxy() { //private Object m_proxy; public void init(Class... clss) { - Log.d("PROXY", "准备初始化Proxy"); List list = new LinkedList(); for (Class cls : clss) { if (cls.isAnnotationPresent(Implement.class)) { @@ -49,7 +48,6 @@ public void init(Class... clss) { } public T getProxy(Class cls) { - Log.d("PROXY", "获取Proxy"); //return (T) m_proxy; return (T) m_objects.get(cls); } diff --git a/basic/src/main/java/com/common/model/http/HttpCacheInterceptor.java b/basic/src/main/java/com/common/model/http/HttpCacheInterceptor.java index 3860707..9c772f6 100644 --- a/basic/src/main/java/com/common/model/http/HttpCacheInterceptor.java +++ b/basic/src/main/java/com/common/model/http/HttpCacheInterceptor.java @@ -1,11 +1,8 @@ package com.common.model.http; -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; import android.util.Log; -import com.common.EasyApplication; +import com.common.BasicApplication; import com.common.utils.NetWorkUtil; import java.io.IOException; @@ -24,7 +21,7 @@ public class HttpCacheInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); - if (!NetWorkUtil.isNetConnected(EasyApplication.getContext())) { + if (!NetWorkUtil.isNetConnected(BasicApplication.getContext())) { request = request.newBuilder() .cacheControl(CacheControl.FORCE_CACHE) .build(); @@ -32,7 +29,7 @@ public Response intercept(Chain chain) throws IOException { } Response originalResponse = chain.proceed(request); - if (NetWorkUtil.isNetConnected(EasyApplication.getContext())) { + if (NetWorkUtil.isNetConnected(BasicApplication.getContext())) { //有网的时候读接口上的@Headers里的配置,你可以在这里进行统一的设置 String cacheControl = request.cacheControl().toString(); return originalResponse.newBuilder() diff --git a/basic/src/main/java/com/common/model/http/HttpClient.java b/basic/src/main/java/com/common/model/http/HttpClient.java index a4ebf13..50c0b82 100644 --- a/basic/src/main/java/com/common/model/http/HttpClient.java +++ b/basic/src/main/java/com/common/model/http/HttpClient.java @@ -1,7 +1,6 @@ package com.common.model.http; -import com.common.view.Constant; -import com.common.EasyApplication; +import com.common.BasicApplication; import java.io.File; import java.util.concurrent.TimeUnit; @@ -22,21 +21,21 @@ public class HttpClient { private static HttpClient mInstance; private Retrofit retrofit; - public static HttpClient getIns() { + public static HttpClient getIns(String base_url) { if (mInstance == null) { synchronized (HttpClient.class) { - if (mInstance == null) mInstance = new HttpClient(); + if (mInstance == null) mInstance = new HttpClient(base_url); } } return mInstance; } - public HttpClient() { + public HttpClient(String BASE_URL) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); - File cacheFile = new File(EasyApplication.getInstance().getCacheDir(), "android"); + File cacheFile = new File(BasicApplication.getInstance().getCacheDir(), "android"); Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb OkHttpClient okHttpClient = new OkHttpClient.Builder() @@ -49,9 +48,9 @@ public HttpClient() { retrofit = new Retrofit.Builder() - .baseUrl(Constant.BASE_URL) + .baseUrl(BASE_URL) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) - .addConverterFactory(GsonConverterFactory.create(EasyApplication.getInstance().gson)) + .addConverterFactory(GsonConverterFactory.create()) .client(okHttpClient) .build(); } diff --git a/basic/src/main/java/com/common/view/Constant.java b/basic/src/main/java/com/common/view/Constant.java deleted file mode 100644 index 944c16f..0000000 --- a/basic/src/main/java/com/common/view/Constant.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.common.view; - -/** - * author miekoz on 2016/3/16. - * email meikoz@126.com - */ -public class Constant { - public static final String GANK_DATA_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; - public static final String BASE_URL = "http://gank.avosapps.com/api/"; -} diff --git a/basic/src/main/java/com/common/view/base/BaseActivity.java b/basic/src/main/java/com/common/view/base/BaseActivity.java index 7a3d91e..5bc0794 100644 --- a/basic/src/main/java/com/common/view/base/BaseActivity.java +++ b/basic/src/main/java/com/common/view/base/BaseActivity.java @@ -7,6 +7,8 @@ import com.common.R; +import java.util.logging.Logger; + import butterknife.ButterKnife; /** @@ -15,7 +17,6 @@ */ public abstract class BaseActivity extends FragmentActivity { - protected EasyToolBar mTitleBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -28,15 +29,6 @@ protected void onCreate(Bundle savedInstanceState) { protected abstract void onInitView(); - protected void initTitleBar(String title) { - findTitleBar(); - mTitleBar.setTitle(title); - } - - private void findTitleBar() { - mTitleBar = (EasyToolBar) findViewById(R.id.toolbar); - } - @Override protected void onDestroy() { super.onDestroy(); diff --git a/basic/src/main/java/com/common/view/base/SwipBackActivity.java b/basic/src/main/java/com/common/view/base/SwipBackActivity.java deleted file mode 100644 index 914059c..0000000 --- a/basic/src/main/java/com/common/view/base/SwipBackActivity.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.common.view.base; - -import android.content.Intent; -import android.os.Bundle; -import android.view.LayoutInflater; - -import com.common.R; -import com.common.view.widget.SwipeBackLayout; - -/** - * author meikoz on 2016/4/1. - * email meikoz@126.com - */ -public abstract class SwipBackActivity extends BaseActivity { - - protected SwipeBackLayout mSwipBack; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mSwipBack = (SwipeBackLayout) LayoutInflater.from(this).inflate( - R.layout.base_swip_layout, null); - mSwipBack.attachToActivity(this); - } - - @Override - public void startActivity(Intent intent) { - super.startActivity(intent); - overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain); - } - - // Press the back button in mobile phone - @Override - public void onBackPressed() { - super.onBackPressed(); - overridePendingTransition(0, R.anim.base_slide_right_out); - } -} diff --git a/basic/src/main/java/com/common/view/base/SwipeBackActivity.java b/basic/src/main/java/com/common/view/base/SwipeBackActivity.java new file mode 100644 index 0000000..718ac48 --- /dev/null +++ b/basic/src/main/java/com/common/view/base/SwipeBackActivity.java @@ -0,0 +1,60 @@ +package com.common.view.base; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.Window; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.RelativeLayout.LayoutParams; + +import com.common.R; + +/** + * Created by Eric on 15/3/3. + */ +public abstract class SwipeBackActivity extends AppCompatActivity implements SwipeBackLayout.SwipeBackListener { + + private SwipeBackLayout swipeBackLayout; + private ImageView ivShadow; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + } + + @Override + public void setContentView(int layoutResID) { + super.setContentView(getContainer()); + View view = LayoutInflater.from(this).inflate(layoutResID, null); + swipeBackLayout.addView(view); + } + + private View getContainer() { + RelativeLayout container = new RelativeLayout(this); + swipeBackLayout = new SwipeBackLayout(this); + swipeBackLayout.setOnSwipeBackListener(this); + ivShadow = new ImageView(this); + ivShadow.setBackgroundColor(getResources().getColor(R.color.black_p50)); + LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + container.addView(ivShadow, params); + container.addView(swipeBackLayout); + return container; + } + + public void setDragEdge(SwipeBackLayout.DragEdge dragEdge) { + swipeBackLayout.setDragEdge(dragEdge); + } + + public SwipeBackLayout getSwipeBackLayout() { + return swipeBackLayout; + } + + @Override + public void onViewPositionChanged(float fractionAnchor, float fractionScreen) { + ivShadow.setAlpha(1 - fractionScreen); + } + +} diff --git a/basic/src/main/java/com/common/view/base/SwipeBackLayout.java b/basic/src/main/java/com/common/view/base/SwipeBackLayout.java new file mode 100644 index 0000000..e03cb0c --- /dev/null +++ b/basic/src/main/java/com/common/view/base/SwipeBackLayout.java @@ -0,0 +1,468 @@ +/* + * Copyright 2015 Eric Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.common.view.base; + +import android.app.Activity; +import android.content.Context; +import android.support.v4.view.ViewCompat; +import android.support.v4.view.ViewPager; +import android.support.v4.widget.ViewDragHelper; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebView; +import android.widget.AbsListView; +import android.widget.ScrollView; + +/** + * Swipe or Pull to finish a Activity. + *

+ * This layout must be a root layout and contains only one direct child view. + *

+ * The activity must use a theme that with translucent style. + * + *

+ * Created by Eric on 15/1/8. + */ +public class SwipeBackLayout extends ViewGroup { + + private static final String TAG = "SwipeBackLayout"; + + public enum DragEdge { + LEFT, + + TOP, + + RIGHT, + + BOTTOM + } + + private DragEdge dragEdge = DragEdge.TOP; + + public void setDragEdge(DragEdge dragEdge) { + this.dragEdge = dragEdge; + } + + + private static final double AUTO_FINISHED_SPEED_LIMIT = 2000.0; + + private final ViewDragHelper viewDragHelper; + + private View target; + + private View scrollChild; + + private int verticalDragRange = 0; + + private int horizontalDragRange = 0; + + private int draggingState = 0; + + private int draggingOffset; + + /** + * Whether allow to pull this layout. + */ + private boolean enablePullToBack = true; + + private static final float BACK_FACTOR = 0.5f; + + /** + * the anchor of calling finish. + */ + private float finishAnchor = 0; + + /** + * Set the anchor of calling finish. + * + * @param offset + */ + public void setFinishAnchor(float offset) { + finishAnchor = offset; + } + + private boolean enableFlingBack = true; + + /** + * Whether allow to finish activity by fling the layout. + * + * @param b + */ + public void setEnableFlingBack(boolean b) { + enableFlingBack = b; + } + + private SwipeBackListener swipeBackListener; + + @Deprecated + public void setOnPullToBackListener(SwipeBackListener listener) { + swipeBackListener = listener; + } + + public void setOnSwipeBackListener(SwipeBackListener listener) { + swipeBackListener = listener; + } + + public SwipeBackLayout(Context context) { + this(context, null); + } + + public SwipeBackLayout(Context context, AttributeSet attrs) { + super(context, attrs); + + viewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallBack()); + } + + public void setScrollChild(View view) { + scrollChild = view; + } + + public void setEnablePullToBack(boolean b) { + enablePullToBack = b; + } + + private void ensureTarget() { + if (target == null) { + if (getChildCount() > 1) { + throw new IllegalStateException("SwipeBackLayout must contains only one direct child"); + } + target = getChildAt(0); + + if (scrollChild == null && target != null) { + if (target instanceof ViewGroup) { + findScrollView((ViewGroup) target); + } else { + scrollChild = target; + } + + } + } + } + + /** + * Find out the scrollable child view from a ViewGroup. + * + * @param viewGroup + */ + private void findScrollView(ViewGroup viewGroup) { + scrollChild = viewGroup; + if (viewGroup.getChildCount() > 0) { + int count = viewGroup.getChildCount(); + View child; + for (int i = 0; i < count; i++) { + child = viewGroup.getChildAt(i); + if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager || child instanceof WebView) { + scrollChild = child; + return; + } + } + } + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + int width = getMeasuredWidth(); + int height = getMeasuredHeight(); + if (getChildCount() == 0) return; + + View child = getChildAt(0); + + int childWidth = width - getPaddingLeft() - getPaddingRight(); + int childHeight = height - getPaddingTop() - getPaddingBottom(); + int childLeft = getPaddingLeft(); + int childTop = getPaddingTop(); + int childRight = childLeft + childWidth; + int childBottom = childTop + childHeight; + child.layout(childLeft, childTop, childRight, childBottom); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + if (getChildCount() > 1) { + throw new IllegalStateException("SwipeBackLayout must contains only one direct child."); + } + + if (getChildCount() > 0) { + int measureWidth = MeasureSpec.makeMeasureSpec(getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY); + int measureHeight = MeasureSpec.makeMeasureSpec(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY); + getChildAt(0).measure(measureWidth, measureHeight); + } + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + verticalDragRange = h; + horizontalDragRange = w; + + switch (dragEdge) { + case TOP: + case BOTTOM: + finishAnchor = finishAnchor > 0 ? finishAnchor : verticalDragRange * BACK_FACTOR; + break; + case LEFT: + case RIGHT: + finishAnchor = finishAnchor > 0 ? finishAnchor : horizontalDragRange * BACK_FACTOR; + break; + } + } + + private int getDragRange() { + switch (dragEdge) { + case TOP: + case BOTTOM: + return verticalDragRange; + case LEFT: + case RIGHT: + return horizontalDragRange; + default: + return verticalDragRange; + } + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + boolean handled = false; + ensureTarget(); + if (isEnabled()) { + handled = viewDragHelper.shouldInterceptTouchEvent(ev); + } else { + viewDragHelper.cancel(); + } + return !handled ? super.onInterceptTouchEvent(ev) : handled; + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + viewDragHelper.processTouchEvent(event); + return true; + } + + @Override + public void computeScroll() { + if (viewDragHelper.continueSettling(true)) { + ViewCompat.postInvalidateOnAnimation(this); + } + } + + public boolean canChildScrollUp() { + return ViewCompat.canScrollVertically(scrollChild, -1); + } + + public boolean canChildScrollDown() { + return ViewCompat.canScrollVertically(scrollChild, 1); + } + + private boolean canChildScrollRight() { + return ViewCompat.canScrollHorizontally(scrollChild, -1); + } + + private boolean canChildScrollLeft() { + return ViewCompat.canScrollHorizontally(scrollChild, 1); + } + + private void finish() { + Activity act = (Activity) getContext(); + act.finish(); + act.overridePendingTransition(0, android.R.anim.fade_out); + } + + private class ViewDragHelperCallBack extends ViewDragHelper.Callback { + + @Override + public boolean tryCaptureView(View child, int pointerId) { + return child == target && enablePullToBack; + } + + @Override + public int getViewVerticalDragRange(View child) { + return verticalDragRange; + } + + @Override + public int getViewHorizontalDragRange(View child) { + return horizontalDragRange; + } + + @Override + public int clampViewPositionVertical(View child, int top, int dy) { + + int result = 0; + + if (dragEdge == DragEdge.TOP && !canChildScrollUp() && top > 0) { + final int topBound = getPaddingTop(); + final int bottomBound = verticalDragRange; + result = Math.min(Math.max(top, topBound), bottomBound); + } else if (dragEdge == DragEdge.BOTTOM && !canChildScrollDown() && top < 0) { + final int topBound = -verticalDragRange; + final int bottomBound = getPaddingTop(); + result = Math.min(Math.max(top, topBound), bottomBound); + } + + return result; + } + + @Override + public int clampViewPositionHorizontal(View child, int left, int dx) { + + int result = 0; + + if (dragEdge == DragEdge.LEFT && !canChildScrollRight() && left > 0) { + final int leftBound = getPaddingLeft(); + final int rightBound = horizontalDragRange; + result = Math.min(Math.max(left, leftBound), rightBound); + } else if (dragEdge == DragEdge.RIGHT && !canChildScrollLeft() && left < 0) { + final int leftBound = -horizontalDragRange; + final int rightBound = getPaddingLeft(); + result = Math.min(Math.max(left, leftBound), rightBound); + } + + return result; + } + + @Override + public void onViewDragStateChanged(int state) { + if (state == draggingState) return; + + if ((draggingState == ViewDragHelper.STATE_DRAGGING || draggingState == ViewDragHelper.STATE_SETTLING) && + state == ViewDragHelper.STATE_IDLE) { + // the view stopped from moving. + if (draggingOffset == getDragRange()) { + finish(); + } + } + + draggingState = state; + } + + + @Override + public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { + switch (dragEdge) { + case TOP: + case BOTTOM: + draggingOffset = Math.abs(top); + break; + case LEFT: + case RIGHT: + draggingOffset = Math.abs(left); + break; + default: + break; + } + + //The proportion of the sliding. + float fractionAnchor = (float) draggingOffset / finishAnchor; + if (fractionAnchor >= 1) fractionAnchor = 1; + + float fractionScreen = (float) draggingOffset / (float) getDragRange(); + if (fractionScreen >= 1) fractionScreen = 1; + + if (swipeBackListener != null) { + swipeBackListener.onViewPositionChanged(fractionAnchor, fractionScreen); + } + } + + @Override + public void onViewReleased(View releasedChild, float xvel, float yvel) { + if (draggingOffset == 0) return; + + if (draggingOffset == getDragRange()) return; + + boolean isBack = false; + + if (enableFlingBack && backBySpeed(xvel, yvel)) { + isBack = !canChildScrollUp(); + } else if (draggingOffset >= finishAnchor) { + isBack = true; + } else if (draggingOffset < finishAnchor) { + isBack = false; + } + + int finalLeft; + int finalTop; + switch (dragEdge) { + case LEFT: + finalLeft = isBack ? horizontalDragRange : 0; + smoothScrollToX(finalLeft); + break; + case RIGHT: + finalLeft = isBack ? -horizontalDragRange : 0; + smoothScrollToX(finalLeft); + break; + case TOP: + finalTop = isBack ? verticalDragRange : 0; + smoothScrollToY(finalTop); + break; + case BOTTOM: + finalTop = isBack ? -verticalDragRange : 0; + smoothScrollToY(finalTop); + break; + } + + } + } + + private boolean backBySpeed(float xvel, float yvel) { + switch (dragEdge) { + case TOP: + case BOTTOM: + if (Math.abs(yvel) > Math.abs(xvel) && Math.abs(yvel) > AUTO_FINISHED_SPEED_LIMIT) { + return dragEdge == DragEdge.TOP ? !canChildScrollUp() : !canChildScrollDown(); + } + break; + case LEFT: + case RIGHT: + if (Math.abs(xvel) > Math.abs(yvel) && Math.abs(xvel) > AUTO_FINISHED_SPEED_LIMIT) { + return dragEdge == DragEdge.LEFT ? !canChildScrollLeft() : !canChildScrollRight(); + } + break; + } + return false; + } + + private void smoothScrollToX(int finalLeft) { + if (viewDragHelper.settleCapturedViewAt(finalLeft, 0)) { + ViewCompat.postInvalidateOnAnimation(SwipeBackLayout.this); + } + } + + private void smoothScrollToY(int finalTop) { + if (viewDragHelper.settleCapturedViewAt(0, finalTop)) { + ViewCompat.postInvalidateOnAnimation(SwipeBackLayout.this); + } + } + + public interface SwipeBackListener { + + /** + * Return scrolled fraction of the layout. + * + * @param fractionAnchor relative to the anchor. + * @param fractionScreen relative to the screen. + */ + void onViewPositionChanged(float fractionAnchor, float fractionScreen); + + } + +} diff --git a/basic/src/main/java/com/common/view/base/WebViewActivity.java b/basic/src/main/java/com/common/view/base/WebViewActivity.java deleted file mode 100644 index ef9ea95..0000000 --- a/basic/src/main/java/com/common/view/base/WebViewActivity.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.common.view.base; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.text.TextUtils; -import android.view.View; -import android.webkit.WebChromeClient; -import android.webkit.WebSettings; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import android.widget.ProgressBar; - -import com.common.R; -import com.common.utils.WebViewUtil; - -/** - * author miekoz on 2016/3/15. - * email meikoz@126.com - */ -public class WebViewActivity extends BaseActivity { - - private static final int PROGRESS_RATIO = 1000; - ProgressBar webviewPb; - WebView webview; - EasyToolBar toolbar; - - public static void start(Context context, String url, String title, boolean isShow) { - if (TextUtils.isEmpty(url)) throw new IllegalArgumentException("url must not be empty"); - Intent intent = new Intent(context, WebViewActivity.class); - intent.putExtra("url", url); - intent.putExtra("title", title); - context.startActivity(intent); - } - - public static void start(Context context, String url, String title) { - start(context, url, title, false); - } - - - @Override - protected int getLayoutResource() { - return R.layout.activity_webview; - } - - @Override - protected void onInitView() { - webviewPb = (ProgressBar) this.findViewById(R.id.webview_pb); - webview = (WebView) this.findViewById(R.id.webview); - toolbar = (EasyToolBar) this.findViewById(R.id.toolbar); - initTitleBar(TextUtils.isEmpty(getUrlTitle()) ? "" : getUrlTitle()); - this.enableJavascript(); - this.enableCaching(); - this.enableCustomClients(); - this.enableAdjust(); - this.zoomedOut(); - this.webview.loadUrl(this.getUrl()); - - } - - @SuppressLint("SetJavaScriptEnabled") - private void enableJavascript() { - this.webview.getSettings().setJavaScriptEnabled(true); - this.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); - } - - private void enableCaching() { - this.webview.getSettings().setAppCachePath(getFilesDir() + getPackageName() + "/cache"); - this.webview.getSettings().setAppCacheEnabled(true); - this.webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); - } - - private void enableAdjust() { - this.webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); - this.webview.getSettings().setLoadWithOverviewMode(true); - } - - private void zoomedOut() { - this.webview.getSettings().setLoadWithOverviewMode(true); - this.webview.getSettings().setUseWideViewPort(true); - this.webview.getSettings().setSupportZoom(true); - } - - private String getUrl() { - return this.getIntent().getStringExtra("url"); - } - - private String getUrlTitle() { - return this.getIntent().getStringExtra("title"); - } - - private void enableCustomClients() { - this.webview.setWebViewClient(new WebViewClient() { - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - view.loadUrl(url); - return true; - } - - /** - * @param view The WebView that is initiating the callback. - * @param url The url of the page. - */ - @Override - public void onPageFinished(WebView view, String url) { - super.onPageFinished(view, url); - if (url.contains("www.vmovier.com")) { - WebViewUtil.injectCss(WebViewActivity.this, WebViewActivity.this.webview, "vmovier.css"); - } else if (url.contains("video.weibo.com")) { - WebViewUtil.injectCss(WebViewActivity.this, WebViewActivity.this.webview, "weibo.css"); - } else if (url.contains("m.miaopai.com")) { - WebViewUtil.injectCss(WebViewActivity.this, WebViewActivity.this.webview, "miaopai.css"); - } - } - }); - this.webview.setWebChromeClient(new WebChromeClient() { - public void onProgressChanged(WebView view, int progress) { - WebViewActivity.this.webviewPb.setProgress(progress); - setProgress(progress * PROGRESS_RATIO); - if (progress >= 80) { - WebViewActivity.this.webviewPb.setVisibility(View.GONE); - } else { - WebViewActivity.this.webviewPb.setVisibility(View.VISIBLE); - } - } - }); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (this.webview != null) this.webview.destroy(); - } -} diff --git a/basic/src/main/java/com/common/view/widget/SwipeBackLayout.java b/basic/src/main/java/com/common/view/widget/SwipeBackLayout.java deleted file mode 100644 index 5d2fa78..0000000 --- a/basic/src/main/java/com/common/view/widget/SwipeBackLayout.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.common.view.widget; - -import android.app.Activity; -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.support.v4.view.ViewPager; -import android.util.AttributeSet; -import android.util.Log; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewConfiguration; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.Scroller; - -import com.common.R; - -import java.util.LinkedList; -import java.util.List; - -/** - * author meikoz on 2016/4/1. - * email meikoz@126.com - */ -public class SwipeBackLayout extends FrameLayout { - private static final String TAG = SwipeBackLayout.class.getSimpleName(); - private View mContentView; - private int mTouchSlop; - private int downX; - private int downY; - private int tempX; - private Scroller mScroller; - private int viewWidth; - private boolean isSilding; - private boolean isFinish; - private Drawable mShadowDrawable; - private Activity mActivity; - private List mViewPagers = new LinkedList(); - - public SwipeBackLayout(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - - mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); - mScroller = new Scroller(context); - - mShadowDrawable = getResources().getDrawable(R.drawable.shadow_left); - } - - - public void attachToActivity(Activity activity) { - mActivity = activity; - TypedArray a = activity.getTheme().obtainStyledAttributes( - new int[] { android.R.attr.windowBackground }); - int background = a.getResourceId(0, 0); - a.recycle(); - - ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); - ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); - decorChild.setBackgroundResource(background); - decor.removeView(decorChild); - addView(decorChild); - setContentView(decorChild); - decor.addView(this); - } - - private void setContentView(View decorChild) { - mContentView = (View) decorChild.getParent(); - } - - /** - * 事件拦截操作 - */ - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - //处理ViewPager冲突问题 - ViewPager mViewPager = getTouchViewPager(mViewPagers, ev); - Log.i(TAG, "mViewPager = " + mViewPager); - - if(mViewPager != null && mViewPager.getCurrentItem() != 0){ - return super.onInterceptTouchEvent(ev); - } - - switch (ev.getAction()) { - case MotionEvent.ACTION_DOWN: - downX = tempX = (int) ev.getRawX(); - downY = (int) ev.getRawY(); - break; - case MotionEvent.ACTION_MOVE: - int moveX = (int) ev.getRawX(); - // 满足此条件屏蔽SildingFinishLayout里面子类的touch事件 - if (moveX - downX > mTouchSlop - && Math.abs((int) ev.getRawY() - downY) < mTouchSlop) { - return true; - } - break; - } - - return super.onInterceptTouchEvent(ev); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - switch (event.getAction()) { - case MotionEvent.ACTION_MOVE: - int moveX = (int) event.getRawX(); - int deltaX = tempX - moveX; - tempX = moveX; - if (moveX - downX > mTouchSlop - && Math.abs((int) event.getRawY() - downY) < mTouchSlop) { - isSilding = true; - } - - if (moveX - downX >= 0 && isSilding) { - mContentView.scrollBy(deltaX, 0); - } - break; - case MotionEvent.ACTION_UP: - isSilding = false; - if (mContentView.getScrollX() <= -viewWidth / 2) { - isFinish = true; - scrollRight(); - } else { - scrollOrigin(); - isFinish = false; - } - break; - } - - return true; - } - - /** - * 获取SwipeBackLayout里面的ViewPager的集合 - * @param mViewPagers - * @param parent - */ - private void getAlLViewPager(List mViewPagers, ViewGroup parent){ - int childCount = parent.getChildCount(); - for(int i=0; i mViewPagers, MotionEvent ev){ - if(mViewPagers == null || mViewPagers.size() == 0){ - return null; - } - Rect mRect = new Rect(); - for(ViewPager v : mViewPagers){ - v.getHitRect(mRect); - - if(mRect.contains((int)ev.getX(), (int)ev.getY())){ - return v; - } - } - return null; - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - super.onLayout(changed, l, t, r, b); - if (changed) { - viewWidth = this.getWidth(); - - getAlLViewPager(mViewPagers, this); - Log.i(TAG, "ViewPager size = " + mViewPagers.size()); - } - } - - @Override - protected void dispatchDraw(Canvas canvas) { - super.dispatchDraw(canvas); - if (mShadowDrawable != null && mContentView != null) { - - int left = mContentView.getLeft() - - mShadowDrawable.getIntrinsicWidth(); - int right = left + mShadowDrawable.getIntrinsicWidth(); - int top = mContentView.getTop(); - int bottom = mContentView.getBottom(); - - mShadowDrawable.setBounds(left, top, right, bottom); - mShadowDrawable.draw(canvas); - } - - } - - - /** - * 滚动出界面 - */ - private void scrollRight() { - final int delta = (viewWidth + mContentView.getScrollX()); - // 调用startScroll方法来设置一些滚动的参数,我们在computeScroll()方法中调用scrollTo来滚动item - mScroller.startScroll(mContentView.getScrollX(), 0, -delta + 1, 0, - Math.abs(delta)); - postInvalidate(); - } - - /** - * 滚动到起始位置 - */ - private void scrollOrigin() { - int delta = mContentView.getScrollX(); - mScroller.startScroll(mContentView.getScrollX(), 0, -delta, 0, - Math.abs(delta)); - postInvalidate(); - } - - @Override - public void computeScroll() { - // 调用startScroll的时候scroller.computeScrollOffset()返回true, - if (mScroller.computeScrollOffset()) { - mContentView.scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); - postInvalidate(); - - if (mScroller.isFinished() && isFinish) { - mActivity.finish(); - } - } - } -} diff --git a/basic/src/main/res/drawable-xxhdpi/shadow_left.png b/basic/src/main/res/drawable-xxhdpi/shadow_left.png deleted file mode 100644 index 82c71c2f280955778b1b314eaa929a984152a921..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2865 zcmV-13(oY3P)KLZ*U+5Lu!Sk^o_Z5E4Meg@_7P6crJiNL9pw)e1;Xm069{HJUZAPk55R%$-RIA z6-eL&AQ0xu!e<4=008gy@A0LT~suv4>S3ILP<0Bm`DLLvaF4FK%)Nj?Pt*r}7;7Xa9z9H|HZjR63e zC`Tj$K)V27Re@400>HumpsYY5E(E}?0f1SyGDiY{y#)Yvj#!WnKwtoXnL;eg03bL5 z07D)V%>y7z1E4U{zu>7~aD})?0RX_umCct+(lZpemCzb@^6=o|A>zVpu|i=NDG+7} zl4`aK{0#b-!z=TL9Wt0BGO&T{GJWpjryhdijfaIQ&2!o}p04JRKYg3k&Tf zVxhe-O!X z{f;To;xw^bEES6JSc$k$B2CA6xl)ltA<32E66t?3@gJ7`36pmX0IY^jz)rRYwaaY4 ze(nJRiw;=Qb^t(r^DT@T3y}a2XEZW-_W%Hszxj_qD**t_m!#tW0KDiJT&R>6OvVTR z07RgHDzHHZ48atvzz&?j9lXF70$~P3Knx_nJP<+#`N z#-MZ2bTkiLfR>_b(HgWKJ%F~Nr_oF3b#wrIijHG|(J>BYjM-sajE6;FiC7vY#};Gd zST$CUHDeuEH+B^pz@B062qXfFfD`NpUW5?BY=V%GM_5c)L#QR}BeW8_2v-S%gfYS= zB9o|3v?Y2H`NVi)In3rTB8+ej^> zQ=~r95NVuDChL%G$=>7$vVg20myx%S50Foi`^m%Pw-h?Xh~i8Mq9jtJloCocWk2Nv zrJpiFnV_ms&8eQ$2&#xWpIS+6pmtC%Q-`S&GF4Q#^mhymh7E(qNMa}%YZ-ePrx>>xFPTiH1=E+A$W$=bG8>s^ zm=Bn5Rah$aDtr}@$`X}2l~$F0mFKEdRdZE8)p@E5RI61Ft6o-prbbn>P~)i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O-C z0A5K%K~#9!?9MR?z%UF0Kso9Ezw9m#sw9%V$4s zjC|lAARr(hARr(hARr(hARr(hARr(hARr(hARr(hARzvVxB&nF|NjF3ER+M?iLvGh P00000NkvXXu0mjfWSMC2 diff --git a/basic/src/main/res/layout/activity_hosting.xml b/basic/src/main/res/layout/activity_hosting.xml deleted file mode 100644 index ebb8e78..0000000 --- a/basic/src/main/res/layout/activity_hosting.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/basic/src/main/res/layout/activity_webview.xml b/basic/src/main/res/layout/activity_webview.xml deleted file mode 100644 index 5c0efd8..0000000 --- a/basic/src/main/res/layout/activity_webview.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - diff --git a/basic/src/main/res/layout/base_swip_layout.xml b/basic/src/main/res/layout/base_swip_layout.xml deleted file mode 100644 index 9f482c1..0000000 --- a/basic/src/main/res/layout/base_swip_layout.xml +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/basic/src/main/res/layout/fragment_list.xml b/basic/src/main/res/layout/fragment_list.xml deleted file mode 100644 index 82cf472..0000000 --- a/basic/src/main/res/layout/fragment_list.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/basic/src/main/res/values/colors.xml b/basic/src/main/res/values/colors.xml index 0213513..bc618d8 100644 --- a/basic/src/main/res/values/colors.xml +++ b/basic/src/main/res/values/colors.xml @@ -27,4 +27,6 @@ #12FFFFFF #e0e0e0 + + #7f000000