From 733ce0c55c882d10c25eed475eabf7ed72b387d1 Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Mon, 6 Jan 2020 14:59:03 +0800 Subject: [PATCH 1/2] fix: imageload download logic --- .idea/misc.xml | 2 +- config.gradle | 2 +- .../com/mogo/commons/AbsMogoApplication.java | 2 +- .../java/com/mogo/commons/network/Utils.java | 2 +- gradle.properties | 2 +- .../layout/module_ext_layout_extensions.xml | 36 +++--- .../res/layout/module_main_activity_main.xml | 8 +- .../drawable-xhdpi/module_map_ic_company.png | Bin 0 -> 737 bytes .../res/drawable-xhdpi/module_map_ic_home.png | Bin 0 -> 831 bytes .../module_map_ic_move2_current_location.png | Bin 0 -> 1550 bytes .../drawable-xhdpi/module_map_ic_search.png | Bin 0 -> 1038 bytes .../module_map_dw_common_corner_bkg.xml | 9 ++ ...odule_map_dw_upload_road_condition_bkg.xml | 9 ++ .../res/layout/module_map_fragment_map.xml | 118 ++++++++++++++++++ .../src/main/res/values/strings.xml | 2 + .../module/service/MogoServiceProvider.java | 21 ++-- .../service/network/RefreshApiService.java | 9 +- .../module/service/network/RefreshBody.java | 29 +++++ .../module/service/network/RefreshModel.java | 17 ++- .../imageloader/glide/GlideImageLoader.java | 33 +++-- 20 files changed, 250 insertions(+), 51 deletions(-) create mode 100644 modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_company.png create mode 100644 modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_home.png create mode 100644 modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_move2_current_location.png create mode 100644 modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_search.png create mode 100644 modules/mogo-module-map/src/main/res/drawable/module_map_dw_common_corner_bkg.xml create mode 100644 modules/mogo-module-map/src/main/res/drawable/module_map_dw_upload_road_condition_bkg.xml create mode 100644 modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 703e5d4b89..8a8f75bfe2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/config.gradle b/config.gradle index 1f7b20f715..a09c88791e 100644 --- a/config.gradle +++ b/config.gradle @@ -104,6 +104,6 @@ ext { jetbrainsannotationsjava5: "org.jetbrains:annotations-java5:15.0", // 统一登录 - accountsdk : "com.zhidao.accoutservice:account-sdk:1.0.0.1@aar", + accountsdk : "com.zhidao.accountservice:account-sdk:1.0.2", ] } \ No newline at end of file diff --git a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java index da9686570a..ba34b7889d 100644 --- a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java +++ b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java @@ -72,7 +72,7 @@ public class AbsMogoApplication extends Application { TipToast.init( sApp, null ); initNetConfig(); -// initAccountSdk(); + initAccountSdk(); } private static void initNetConfig() { diff --git a/foudations/mogo-commons/src/main/java/com/mogo/commons/network/Utils.java b/foudations/mogo-commons/src/main/java/com/mogo/commons/network/Utils.java index 7d6ec4242a..350234532b 100644 --- a/foudations/mogo-commons/src/main/java/com/mogo/commons/network/Utils.java +++ b/foudations/mogo-commons/src/main/java/com/mogo/commons/network/Utils.java @@ -15,7 +15,7 @@ import java.lang.reflect.Method; * Created by congtaowang on 2018/3/29. */ -class Utils { +public class Utils { public static String getCellId( Context context ) { TelephonyManager tm = ( TelephonyManager ) context.getSystemService( Context.TELEPHONY_SERVICE ); diff --git a/gradle.properties b/gradle.properties index 9db77184f3..832da15ccb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/ USERNAME=xintai PASSWORD=xintai2018 # 编译模式: false - 依赖本地版本, true - 依赖 maven 版本 -RELEASE=true +RELEASE=false # 模块版本 DEMO_MODULE_MAP_VERSION=1.0.0-SNAPSHOT DEMO_MODULE_MAP2_VERSION=1.0.0-SNAPSHOT diff --git a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml index e8e613ecd4..e7921e4e1a 100644 --- a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml +++ b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml @@ -3,10 +3,10 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="60dp" + android:layout_height="@dimen/dp_120" android:orientation="vertical" - android:paddingLeft="35dp" - android:paddingRight="35dp"> + android:paddingLeft="@dimen/dp_70" + android:paddingRight="@dimen/dp_70"> @@ -34,7 +34,7 @@ android:layout_height="wrap_content" android:gravity="center_vertical" android:textColor="#FFFFFF" - android:textSize="24dp" + android:textSize="@dimen/dp_48" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" @@ -44,10 +44,10 @@ android:id="@+id/module_ext_id_date" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="40dp" + android:layout_marginRight="@dimen/dp_80" android:gravity="center_vertical" android:textColor="#FFFFFF" - android:textSize="14dp" + android:textSize="@dimen/dp_28" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintRight_toLeftOf="@+id/module_ext_id_time" app:layout_constraintTop_toTopOf="parent" @@ -57,7 +57,7 @@ android:id="@+id/module_ext_id_weather_container" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="13dp" + android:layout_marginRight="@dimen/dp_26" android:gravity="center" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" @@ -66,26 +66,26 @@ @@ -100,7 +100,7 @@ android:id="@+id/module_ext_id_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="14dp" + android:layout_marginRight="@dimen/dp_28" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintRight_toLeftOf="@+id/module_ext_id_weather_container" app:layout_constraintTop_toTopOf="parent"> @@ -112,14 +112,14 @@ diff --git a/modules/mogo-module-main/src/main/res/layout/module_main_activity_main.xml b/modules/mogo-module-main/src/main/res/layout/module_main_activity_main.xml index 467245a03b..485feb099d 100644 --- a/modules/mogo-module-main/src/main/res/layout/module_main_activity_main.xml +++ b/modules/mogo-module-main/src/main/res/layout/module_main_activity_main.xml @@ -17,8 +17,8 @@ + android:layout_marginLeft="@dimen/dp_70" + android:layout_marginTop="@dimen/dp_10"> + android:paddingBottom="@dimen/dp_20" /> diff --git a/modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_company.png b/modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_company.png new file mode 100644 index 0000000000000000000000000000000000000000..47b1217f4a1a96306a2a3adaa3981f7303a738a0 GIT binary patch literal 737 zcmV<70v`Q|P);h!)}#LC9YaL_vrk3ThM*$irHQptTl(l(sfv zB_dkbS!t6Oq%#llC?ZCCAwdw7AY!o4Vw3edatE%%6?Pu??yQ^xKhDhTJu~M!b6;zLLd&I!{uMv&25*r_gl0Uf;^bN^?~K z4nT0y8zOu_Rw5I_5i)}qJh z-$s*wK1Ka#pLL8^w;emU!7kkcpqq@ZqhTa~#(HUpwmD`NKf&=E=0{iGjvf4yqnwK9 z37tVSj+T*Jm&Oj!xPe{)D%Y@=wGGf@3*-)3L}QE%p=U_$w0S#~@3^$v4wz3C$Sw4o zu@Uqj|C?_+DL?}OWRv!$>4*3v0YiZ7SOv5z(rNutpM%`qdniaBl4qTk5-8cN6DS$;0t8Acg7dc99rX<)*$8*?alxs(Ywel%s0m7(QEV;s2zL~W+&Q8 zQu&yd1PIi7pz<%ut;|!&F+mS{pdO<25I9cXJ7`IK8N@+=krKMeJO_~Y=#~PYIpvLy z3Yh|6R3LjY1+*(tLcfvCX?)ZrQrN*45dB2rqgyE#wo8^gV&ub!AaafECguoo{WJWFn0GucUE>H-(+X$>v;tZIt$L000004XF*Lt006O% z3;baP0008^NklzDEI*s4~hwj5tD-f zK@d@c3L%Fa0)pf&>d6Nff(J1|l8atM@Zcr!;3FUiBCfxZnWY#sGt<-EvZNaRbai!g z)xWBHdUm!}vt|{r3RnfK0#*U5fK|XMU=;{kfkvZo2=swXVI%z~?_1l1K^k<`3ZR_`z&I+8T~ELscc^%U&QvC(p46{CJONlFuDfzD`szz z2O<7Z>6#*I)-t#R4mXvx+I!^ltXWXHN}{(!AuO+oQLsxfnnu11;qOZKSCRGd-1e)< z&&X1s;5V|0xx5I;-QXEW-;vUv1*Hm!eGhmEQa>+{4=x`)(kw)dfEh(ji1xaMXRQ=% zO8JwdkGuLy*OjVxx=4D0%cXM;XcBVV`_i;kcWv;`bKvB!El{`I?3mZPx?wy62sRL-5Kym z#!2gyFNTq5 z8)uUkNB3VlsYw^H(e|a~7(1#-%`=!w6!Nhxf3-wuu@jx+S)7o}cy{~fq9q#R=tkMG zydainUWHn1-gdOrb}WzYirLZFub0l`wIUm!|Fq8AkjnFwKfEh5aBvXw!#n5?@SNP8 zV!J-043w4=X@eBX}002ov JPDHLkV1h>|fb;+W literal 0 HcmV?d00001 diff --git a/modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_move2_current_location.png b/modules/mogo-module-map/src/main/res/drawable-xhdpi/module_map_ic_move2_current_location.png new file mode 100644 index 0000000000000000000000000000000000000000..9d3d1e8b2a3910b09c4d73cdd22f805143704973 GIT binary patch literal 1550 zcmV+p2J!icP)0P43DCYJ&jB-SI0a;UDs_=J#)-D3ABUr zz%VcfIO>Pl33|c0TrRiUb)?y*o*;>xLV$C?6cA^HY{dRa68)4mHA*c(5>qm>!EL~8 zCN|Ikgx`Ven!#WYMDL({j6`KyGo_Ls$qgZrN5N&jh&Cgy1$|%-LI10M>^1LjFcEYB zEoGbVF62(^zoD&(YEF<~b!fi;Mw>{s!Y?7fEk+m0;^Q*u`G=nDaL0lk?B8-Tq7iNe9h81OD| zepkTT~M2Qn*wtLNt>j`Xy zk;_;Lk^{rRNDz5P@U;mCOO2B|8FRdmt7a1=$YeUWFY#tMM7tzxMr@lwC;i&~b%);o zz33K$Q{lsCB^`Ub&KBB4cQH|dOm>wwv6?rj__szbvLw)opg?Z{db4qKEX-ukgUxkL zX|)`e~q0Wljwjx%bVg)+6^A>Z?sXkfPR605VUh=bmyjl9YCa`>S6rqu9gtC`%&m+ zK_t5i@?4Bd3Fo*^PDbbw^RB_REn_NLfC&3Zy z8e~16B5hnj32Iq8nh7I_4l#Zne%>#L!Pjb*=#Rle^V+Zq4l!e*#@jwS#td%?`+uY2 zUTh76_=2e@G{JpFBj}kNP2&YT3u&;I>6+25Aw^2#^46&># z?T(hJO3>%xCuD8iS|Vo>XbY3>vo^?oqkj(FTuhaQX7o>GOG zjNLyaMiqo=Hklw7y+)~Bwu}hmKa}?a7hstUicMffP;#E}4Q9}Xag)>7q<3%xV_ySD z%L()VldmtZ+g=nXMbATR;@4-5-hH-%#6=U>#t2oC2Q5Uvr3v2_f1fb{2eY35C z58LJwMT5UZ#{cp}P8gJQiE6%=zyUGPD6o)#YVntMqzis-r@6YQ;BTAZW3hD4YVF%?2&TU<DHqmHxGy1V)01;8NgrO4vNT%5@RR$+jj+EkQ*=lC3mz zL7U_Rq&JnNB&J^*sZgp3x`;@$9ez4EA5^oEeT|*YyjMt0%R4oyOM)&s5*-RZ35*9< z0xeC^cJMja33^FtH|_tMNcM5yUJN=Kl}$Cvr%|!gWu7d-6w7MA@-3g@6y>f4m#gZg z(KqBDK!4)4)oqr{aaMt>0$ByJ3S{kW`ij)eJ3X}?z3X}?z3X}@$)C#ofOuXCe?gH-^+D4C}2ZPcKybroY+d)@bt=3Q4 zMx_>l5Zggy^@5KGEH>2|{j|sN?A2=;*&4-qOrL@=2n9Pq$=( z5R>mU^zxPn@3>w@pQCS3y_yoeu1C=0=n#4c^>Uw!yAbXAo4Ixp!9eZ~!B4paK48zI zOCXSJqNC^m*Woett-47%{Awl%j-e|~=dcH>d2jZT4=P`eHMZH~A6O(a zyd|Ltt~GiliG0z?EtvYQYmul|lq57-K0<9kd4@f~E0s0eizGO+=m}J!f#*E9*`sT0 z2DxO^L_$F_Yq@613%4QqVq59(!8}_Q|V}pR?DcF;B48%JwLSe`+=_ z_UPXGr&NO46*MIt+ZQz{UJSuC7eQN|ro?0Wm`U+s2zFeAAyygM^3*B;Q+q{|jv1+K z48c``=$JvG&8qfub&D`NzUd(VznLJgLMwv+lEcMf?kJY(x6idK}&|@^m^%-p^a*@s)e&Hp0%!&>ecI@ zfBokRI2v>&QIi)KbR00o>=Q*mQ3u>b%707*qo IM6N<$f*3345dZ)H literal 0 HcmV?d00001 diff --git a/modules/mogo-module-map/src/main/res/drawable/module_map_dw_common_corner_bkg.xml b/modules/mogo-module-map/src/main/res/drawable/module_map_dw_common_corner_bkg.xml new file mode 100644 index 0000000000..da35984c9d --- /dev/null +++ b/modules/mogo-module-map/src/main/res/drawable/module_map_dw_common_corner_bkg.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/modules/mogo-module-map/src/main/res/drawable/module_map_dw_upload_road_condition_bkg.xml b/modules/mogo-module-map/src/main/res/drawable/module_map_dw_upload_road_condition_bkg.xml new file mode 100644 index 0000000000..01523fc210 --- /dev/null +++ b/modules/mogo-module-map/src/main/res/drawable/module_map_dw_upload_road_condition_bkg.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/modules/mogo-module-map/src/main/res/layout/module_map_fragment_map.xml b/modules/mogo-module-map/src/main/res/layout/module_map_fragment_map.xml index 696bce61e8..038b269721 100644 --- a/modules/mogo-module-map/src/main/res/layout/module_map_fragment_map.xml +++ b/modules/mogo-module-map/src/main/res/layout/module_map_fragment_map.xml @@ -1,5 +1,6 @@ @@ -7,4 +8,121 @@ android:id="@+id/module_map_id_map" android:layout_width="match_parent" android:layout_height="match_parent" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/mogo-module-map/src/main/res/values/strings.xml b/modules/mogo-module-map/src/main/res/values/strings.xml index fab4c86972..344eed0558 100644 --- a/modules/mogo-module-map/src/main/res/values/strings.xml +++ b/modules/mogo-module-map/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ mogo-module-map + 搜索目的地 + 上报\n路况 diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java index 4f786c1ddd..2b916dfedd 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java @@ -101,7 +101,7 @@ public class MogoServiceProvider implements IMogoModuleProvider, case ServiceConst.MSG_TYPE_REFRESH_DECREASE: mRefreshRemainingTime -= ServiceConst.DECREASE_INTERVAL; if ( mRefreshRemainingTime == 0 ) { - notifyRefreshData( mAutoRefreshCallback ); + notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback ); } else { mHandler.sendEmptyMessageDelayed( msg.what, ServiceConst.DECREASE_INTERVAL ); } @@ -334,19 +334,26 @@ public class MogoServiceProvider implements IMogoModuleProvider, // 手动刷新触发 if ( mLastZoomLevel - zoom > mCustomRefreshStrategy.getZoomOutLevel() ) { // 缩放级别缩小 - notifyRefreshData( mCustomRefreshCallback ); + notifyRefreshData( latLng, getQueryRadius(), mCustomRefreshCallback ); mLastCustomRefreshCenterLocation = latLng; mLastZoomLevel = zoom; } else if ( mLastZoomLevel == zoom ) { // 手动平移 if ( invokeRefreshWhenTranslationByUser( latLng ) ) { - notifyRefreshData( mCustomRefreshCallback ); + notifyRefreshData( latLng, getQueryRadius(), mCustomRefreshCallback ); mLastCustomRefreshCenterLocation = latLng; } } Logger.d( TAG, "current map status: %s, zoom = %f, tilt = %f, bearing = %f", latLng, zoom, tilt, bearing ); } + private int getQueryRadius() { + if ( mIsVertical ) { + return ( ( int ) ( getMapCameraFactWidth() / 2 ) ); + } + return ( ( int ) ( getMapCameraFactHeight() / 2 ) ); + } + /** * 平移地图刷新策略 * @@ -379,11 +386,11 @@ public class MogoServiceProvider implements IMogoModuleProvider, // 自动刷新触发 if ( mLastAutoRefreshLocation == null ) { mLastAutoRefreshLocation = new MogoLatLng( location.getLatitude(), location.getLongitude() ); - notifyRefreshData( mAutoRefreshCallback ); + notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback ); } else { float distance = Utils.calculateLineDistance( mLastAutoRefreshLocation, new MogoLatLng( location.getLatitude(), location.getLongitude() ) ); if ( distance > mAutoRefreshStrategy.getDistance() ) { - notifyRefreshData( mAutoRefreshCallback ); + notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback ); } } } @@ -391,9 +398,9 @@ public class MogoServiceProvider implements IMogoModuleProvider, /** * 刷新数据 */ - private void notifyRefreshData( RefreshCallback callback ) { + private void notifyRefreshData( MogoLatLng latLng, int radius, RefreshCallback callback ) { Logger.d( TAG, mAutoRefreshCallback == callback ? "触发自动刷新" : "触发手动刷新" ); - mRefreshModel.refreshData( callback ); + mRefreshModel.refreshData( latLng, radius, callback ); } @Override diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshApiService.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshApiService.java index 875fa04b98..82497488e6 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshApiService.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshApiService.java @@ -6,7 +6,10 @@ import java.util.Map; import io.reactivex.Observable; import io.reactivex.Single; +import retrofit2.http.FieldMap; +import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; +import retrofit2.http.POST; import retrofit2.http.QueryMap; /** @@ -17,6 +20,8 @@ import retrofit2.http.QueryMap; */ public interface RefreshApiService { - @GET( "" ) - Observable< BaseData > refreshData( @QueryMap Map< String, Object > params ); + @FormUrlEncoded + @POST( "" ) + Observable< BaseData > refreshData( @QueryMap Map< String, Object > params, + @FieldMap Map< String, Object > parameters ); } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java new file mode 100644 index 0000000000..2200ed394a --- /dev/null +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java @@ -0,0 +1,29 @@ +package com.mogo.module.service.network; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author congtaowang + * @since 2020-01-06 + *

+ * 刷新地图信息接口 + */ +public class RefreshBody { + + public List< String > dataType = new ArrayList<>(); + public int limit = 50;// 请求数量 + public int radius = 2_000; // 地理围栏半径(米) + public LatLon location; + + public static class LatLon { + + private double lat; + private double lon; + + public LatLon( double lat, double lon ) { + this.lat = lat; + this.lon = lon; + } + } +} diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java index 5fdbce5600..1da0a385cb 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java @@ -6,10 +6,14 @@ import com.alibaba.android.arouter.launcher.ARouter; import com.mogo.commons.data.BaseData; import com.mogo.commons.network.ParamsProvider; import com.mogo.commons.network.SubscribeImpl; +import com.mogo.commons.network.Utils; +import com.mogo.map.MogoLatLng; import com.mogo.service.MogoServicePaths; import com.mogo.service.network.IMogoNetwork; import com.mogo.utils.network.RequestOptions; +import com.mogo.utils.network.utils.GsonUtil; +import java.util.HashMap; import java.util.Map; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -33,14 +37,21 @@ public class RefreshModel { this.mRefreshApiService = network.create( RefreshApiService.class, "http://www.baidu.com/" ); } - public void refreshData( final RefreshCallback callback ) { + public void refreshData( MogoLatLng latLng, int radius, final RefreshCallback callback ) { if ( callback != null ) { callback.onSuccess(); return; } if ( mRefreshApiService != null ) { - final Map< String, Object > params = new ParamsProvider.Builder( mContext ).build(); - mRefreshApiService.refreshData( params ) + final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build(); + final Map< String, Object > field = new HashMap<>(); + field.put( "sn", query.get( "sn" ) ); + final RefreshBody refreshBody = new RefreshBody(); + refreshBody.limit = 50; + refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng ); + refreshBody.radius = radius; + field.put( "data", GsonUtil.jsonFromObject( refreshBody ) ); + mRefreshApiService.refreshData( query, field ) .subscribeOn( Schedulers.io() ) .observeOn( AndroidSchedulers.mainThread() ) .subscribe( new SubscribeImpl< BaseData >( RequestOptions.create( mContext ) ) { diff --git a/services/mogo-service/src/main/java/com/mogo/service/impl/imageloader/glide/GlideImageLoader.java b/services/mogo-service/src/main/java/com/mogo/service/impl/imageloader/glide/GlideImageLoader.java index 2d577f3dc0..b1eaa394cb 100644 --- a/services/mogo-service/src/main/java/com/mogo/service/impl/imageloader/glide/GlideImageLoader.java +++ b/services/mogo-service/src/main/java/com/mogo/service/impl/imageloader/glide/GlideImageLoader.java @@ -2,7 +2,9 @@ package com.mogo.service.impl.imageloader.glide; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.alibaba.android.arouter.facade.annotation.Route; @@ -10,7 +12,10 @@ import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.ImageViewTarget; +import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.target.Target; +import com.bumptech.glide.request.transition.Transition; import com.mogo.service.MogoServicePaths; import com.mogo.service.imageloader.IMogoImageLoaderListener; import com.mogo.service.imageloader.IMogoImageloader; @@ -21,6 +26,8 @@ import com.mogo.service.impl.imageloader.glide.transform.GlideRoundBitmapTransfo import com.mogo.service.impl.imageloader.glide.utils.DiskLruCacheManager; import com.mogo.utils.glide.GlideApp; +import java.io.File; + /** * @author congtaowang * @since 2019-12-23 @@ -142,22 +149,24 @@ public class GlideImageLoader implements IMogoImageloader { GlideApp.with( context.getApplicationContext() ) .asBitmap() .load( url ) - .listener( new RequestListener< Bitmap >() { - + .into( new SimpleTarget< Bitmap >() { @Override - public boolean onLoadFailed( @Nullable GlideException e, Object model, Target< Bitmap > target, boolean isFirstResource ) { - if ( listener != null ) { - listener.onFailure( e ); - } - return false; - } - - @Override - public boolean onResourceReady( Bitmap resource, Object model, Target< Bitmap > target, DataSource dataSource, boolean isFirstResource ) { + public void onResourceReady( @NonNull Bitmap resource, @Nullable Transition< ? super Bitmap > transition ) { if ( listener != null ) { listener.onCompleted( resource ); } - return false; + } + + @Override + public void onLoadStarted( @Nullable Drawable placeholder ) { + super.onLoadStarted( placeholder ); + } + + @Override + public void onLoadFailed( @Nullable Drawable errorDrawable ) { + if ( listener != null ) { + listener.onFailure( new Exception( "download failed." ) ); + } } } ); } From 0fcf2a0e1dfa5a90e580f7f2f3de95f20d1d2c0c Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Mon, 6 Jan 2020 15:00:38 +0800 Subject: [PATCH 2/2] add autozoomimageview --- .../tanlu/fragment/TanluCardViewFragment.java | 46 +++- .../mogo/tanlu/view/AutoZoomInImageView.java | 259 ++++++++++++++++++ .../mogo/tanlu/view/AutoZoomInImageView.kt | 222 --------------- .../layout/tanlu_item_main_media_recycler.xml | 1 + 4 files changed, 302 insertions(+), 226 deletions(-) create mode 100644 modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.java delete mode 100644 modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.kt diff --git a/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/fragment/TanluCardViewFragment.java b/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/fragment/TanluCardViewFragment.java index 1b4781b8f0..e09dcdd482 100644 --- a/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/fragment/TanluCardViewFragment.java +++ b/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/fragment/TanluCardViewFragment.java @@ -1,5 +1,6 @@ package com.mogo.tanlu.fragment; +import android.graphics.Bitmap; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; @@ -25,6 +26,7 @@ import com.mogo.map.search.poisearch.IMogoPoiSearchListener; import com.mogo.map.search.poisearch.MogoPoiResult; import com.mogo.map.uicontroller.EnumMapUI; import com.mogo.service.MogoServicePaths; +import com.mogo.service.imageloader.IMogoImageLoaderListener; import com.mogo.service.imageloader.IMogoImageloader; import com.mogo.service.module.IMogoModuleLifecycle; import com.mogo.tanlu.R; @@ -144,10 +146,46 @@ public class TanluCardViewFragment extends MvpFragment> //图片显示 autoZoomInImageView.setVisibility(View.VISIBLE); simpleCoverVideoPlayer.setVisibility(View.GONE); - mogoImageloader.displayImage(imageUrl, autoZoomInImageView); +// mogoImageloader.displayImage(imageUrl, autoZoomInImageView); + mogoImageloader.downloadImage(getActivity(), imageUrl, new IMogoImageLoaderListener() { + @Override + public void onStart() { + Logger.d(TAG, "onStart ------>"); + } + + @Override + public void onCompleted(Bitmap bitmap) { + Logger.d(TAG, "onCompleted ------>"); + autoZoomInImageView.setImageBitmap(bitmap); + //动画 + handleImageAnimation(); + } + + @Override + public void onFailure(Exception e) { + Logger.e(TAG, "onFailure -----E->" + e); + } + }); + } } + /** + * 执行图片动画 + */ + private void handleImageAnimation() { + autoZoomInImageView.post(new Runnable() { + @Override + public void run() { + //放大增量是0.3,放大时间是1000毫秒,放大开始时间是1000毫秒以后 + autoZoomInImageView.init() + .startZoomInByScaleDeltaAndDuration(0.3f, 1000, 1500); + } + }); + + } + + /** * marker点击事件 TODO * @@ -171,14 +209,14 @@ public class TanluCardViewFragment extends MvpFragment> //TODO C位事件,如何获取数据,需要有默认数据 @Override public void onPerform() { - Logger.d(TAG, "卡片2有效"); + Logger.d(TAG, "tanlu卡片 有效"); } //TODO 离开C位事件 @Override public void onDisable() { - Logger.d(TAG, "卡片2无效"); + Logger.e(TAG, "tanlu卡片 无效"); } @Override @@ -226,7 +264,7 @@ public class TanluCardViewFragment extends MvpFragment> // } } - + @Override public void onMapClick(MogoLatLng latLng) { diff --git a/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.java b/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.java new file mode 100644 index 0000000000..102d772568 --- /dev/null +++ b/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.java @@ -0,0 +1,259 @@ +package com.mogo.tanlu.view; + +import com.mogo.service.imageloader.MogoImageView; + +import android.animation.Animator; +import android.animation.ValueAnimator; +import android.content.Context; +import android.graphics.Matrix; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.view.View; + + +/** + * @author lixiaopeng + * @description + * @since 2020-01-06 + */ +public class AutoZoomInImageView extends MogoImageView { + private int mDrawableW; + private int mDrawableH; + private int mImageViewW; + private int mImageViewH; + private long mDurationMillis = 700; + + private float[] mValues = new float[9]; + private float mScaleDelta = 0.2f; + + private Drawable mDrawable; + private Matrix mMatrix; + + public AutoZoomInImageView(Context context) { + super(context); + this.setScaleType(ScaleType.MATRIX); + } + + public AutoZoomInImageView(Context context, AttributeSet attrs) { + super(context, attrs); + this.setScaleType(ScaleType.MATRIX); + } + + public AutoZoomInImageView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + this.setScaleType(ScaleType.MATRIX); + } + + public AutoZoomInImageView init() { + initInternalValues(); + initPicturePosition(); + return this; + } + + public void init(Drawable drawable) { + initInternalValues(drawable); + initPicturePosition(); + } + + private void initInternalValues() { + mDrawable = getDrawable(); + + if (mDrawable == null) { + throw new IllegalArgumentException("please set the source of AutoZoomInImageView"); + } + + mDrawableW = mDrawable.getIntrinsicWidth(); + mDrawableH = mDrawable.getIntrinsicHeight(); + + mImageViewW = getMeasuredWidth(); + mImageViewH = getMeasuredHeight(); + + mMatrix = getImageMatrix(); + mMatrix.getValues(mValues); + } + + private void initInternalValues(Drawable drawable) { + mDrawable = drawable; + + if (mDrawable == null) { + throw new IllegalArgumentException("please set the source of AutoZoomInImageView"); + } + + mDrawableW = mDrawable.getIntrinsicWidth(); + mDrawableH = mDrawable.getIntrinsicHeight(); + + mImageViewW = getMeasuredWidth(); + mImageViewH = getMeasuredHeight(); + + mMatrix = getImageMatrix(); + mMatrix.getValues(mValues); + } + + private void initPicturePosition() { + updateMatrixValuesOrigin(mMatrix, mValues, mDrawableW, mDrawableH, mImageViewW, mImageViewH); + setImageMatrix(mMatrix); + } + + private void startZoomInByScaleDelta(final float scaleDelta, long duration) { + + final float oriScaleX = mValues[0]; + final float oriScaleY = mValues[4]; + + ValueAnimator va = ValueAnimator.ofFloat(0, scaleDelta); + va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + float value = (Float) animation.getAnimatedValue(); + if (mOnZoomListener != null) + mOnZoomListener.onUpdate(AutoZoomInImageView.this, value / scaleDelta); + updateMatrixValuesSpan(mValues, mDrawableW, mDrawableH, mImageViewW, mImageViewH, + oriScaleX, oriScaleY, value); + mMatrix.setValues(mValues); + setImageMatrix(mMatrix); + } + }); + va.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + if (mOnZoomListener != null) mOnZoomListener.onStart(AutoZoomInImageView.this); + } + + @Override + public void onAnimationEnd(Animator animation) { + if (mOnZoomListener != null) mOnZoomListener.onEnd(AutoZoomInImageView.this); + } + + @Override + public void onAnimationCancel(Animator animation) { + } + + @Override + public void onAnimationRepeat(Animator animation) { + } + }); + va.setDuration(duration); + va.start(); + } + + /** + * start zooming in + * + * @param scaleDelta the scale that the image will add to original scale + * @param durationMillis the duration of zoomin animation, in millisecond. + * @param delayMillis the delayed time of starting zoomin animation, in millisecond. + */ + public void startZoomInByScaleDeltaAndDuration(final float scaleDelta, final long durationMillis, long delayMillis) { + if (scaleDelta < 0) { + throw new IllegalArgumentException("scaleDelta should be larger than 0, now scaleDelta is " + scaleDelta); + } + if (durationMillis < 0) { + throw new IllegalArgumentException("durationMillis should not be less than 0, now durationMillis is " + durationMillis); + } + if (delayMillis < 0) { + throw new IllegalArgumentException("delayMillis should not be less than 0, now delayMillis is " + delayMillis); + } + postDelayed(new Runnable() { + @Override + public void run() { + startZoomInByScaleDelta(scaleDelta, durationMillis); + } + }, delayMillis); + } + + /** + * the scale that the image will add to original scale + * + * @param scaleDelta + * @return + */ + public AutoZoomInImageView setScaleDelta(float scaleDelta) { + mScaleDelta = scaleDelta; + return this; + } + + /** + * the duration of zoomin animation, in millisecond. + * + * @param durationMillis + * @return + */ + public AutoZoomInImageView setDurationMillis(long durationMillis) { + mDurationMillis = durationMillis; + return this; + } + + /** + * callback when zoomin animation finished + * + * @param onZoomListener + * @return + */ + public AutoZoomInImageView setOnZoomListener(OnZoomListener onZoomListener) { + mOnZoomListener = onZoomListener; + return this; + } + + /** + * start animation of zoomin + * + * @param delayMillis the delayed time of starting zoomin animation, in millisecond. + */ + public void start(long delayMillis) { + postDelayed(new Runnable() { + @Override + public void run() { + startZoomInByScaleDelta(mScaleDelta, mDurationMillis); + } + }, delayMillis); + } + + private void updateMatrixValuesOrigin(Matrix outMatrix, float[] outValues, float drawW, float drawH, float imageW, float imageH) { + if (outMatrix == null || outValues == null) { + throw new IllegalArgumentException("please set the source of AutoZoomInImageView's matrix and values"); + } + outMatrix.reset(); + if ((imageH * drawW > drawH * imageW)) { + float scale1 = (imageH) / (drawH); + float offset1 = (drawW * scale1 - imageW) / 2; + outMatrix.postScale(scale1, scale1); + outMatrix.postTranslate(-offset1, 0); + } else { + float scale2 = (imageW) / (drawW); + float offset2 = (drawH * scale2 - imageH) / 2; + outMatrix.postScale(scale2, scale2); + outMatrix.postTranslate(0, -offset2); + } + outMatrix.getValues(outValues); + } + + private void updateMatrixValuesSpan(float[] outValues, + float drawW, float drawH, + float imageW, float imageH, + float oriScaleX, float oriScaleY, + float scaleDelta) { + outValues[0] = oriScaleX * (1 + scaleDelta); + outValues[4] = oriScaleY * (1 + scaleDelta); + float offsetwidth = (drawW * outValues[0] - imageW) / 2; + outValues[2] = -offsetwidth; + float offsetHeight = (drawH * outValues[4] - imageH) / 2; + outValues[5] = -offsetHeight; + } + + private OnZoomListener mOnZoomListener; + + public interface OnZoomListener { + /** + * callback when zoom in animation is updating + * + * @param view AutoZoomInImageView + * @param progress return the progress of animation, scope is [0,1] + */ + void onUpdate(View view, float progress); + + void onEnd(View view); + + void onStart(View view); + } + +} diff --git a/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.kt b/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.kt deleted file mode 100644 index 391727aa8d..0000000000 --- a/modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/view/AutoZoomInImageView.kt +++ /dev/null @@ -1,222 +0,0 @@ -package com.mogo.tanlu.view - -import android.animation.Animator -import android.animation.ValueAnimator -import android.content.Context -import android.graphics.Matrix -import android.graphics.drawable.Drawable -import android.util.AttributeSet -import android.util.Log -import android.view.View -import android.widget.ImageView -import com.mogo.service.imageloader.MogoImageView - -class AutoZoomInImageView : MogoImageView { - - companion object { - const val TAG = "AutoZoomInImageView" - } - - private var mDrawableW: Int = 0 - private var mDrawableH: Int = 0 - private var mImageViewW: Int = 0 - private var mImageViewH: Int = 0 - private var mDurationMillis = 3000L - - private var mValues = FloatArray(9) - var isInit: Boolean = false - private var mScaleDelta = 0.2f - private var va: ValueAnimator = ValueAnimator.ofFloat(0f, mScaleDelta) - - private lateinit var mDrawable: Drawable - private lateinit var mMatrix: Matrix - - private var onStart: (View.() -> Unit)? = null - - private var onUpdate: ((view: View, progress: Float) -> Unit)? = null - - private var onEnd: (View.() -> Unit)? = null - - infix fun onStart(onStart: View.() -> Unit) :AutoZoomInImageView{ - this.onStart = onStart - return this - } - - infix fun onUpdate(onUpdate: (view: View, progress: Float) -> Unit) :AutoZoomInImageView{ - this.onUpdate = onUpdate - return this - } - - infix fun onEnd(onEnd: View.() -> Unit):AutoZoomInImageView { - this.onEnd = onEnd - return this - } - - constructor(context: Context?) : super(context) { - this.scaleType = ScaleType.MATRIX - } - - constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { - this.scaleType = ScaleType.MATRIX - } - - constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super( - context, - attrs, - defStyleAttr - ) { - this.scaleType = ScaleType.MATRIX - } - - - fun init(): AutoZoomInImageView { - initInternalValues() - initPicturePosition() - isInit = true - return this - } - - fun init(drawable: Drawable) { - initInternalValues(drawable) - initPicturePosition() - } - - private fun initInternalValues() { - mDrawable = drawable - - mDrawableW = mDrawable.intrinsicWidth - mDrawableH = mDrawable.intrinsicHeight - - mImageViewW = measuredWidth - mImageViewH = measuredHeight - - mMatrix = imageMatrix - mMatrix.getValues(mValues) - } - - private fun initInternalValues(drawable: Drawable) { - mDrawable = drawable - - mDrawableW = mDrawable.intrinsicWidth - mDrawableH = mDrawable.intrinsicHeight - - mImageViewW = measuredWidth - mImageViewH = measuredHeight - - mMatrix = imageMatrix - mMatrix.getValues(mValues) - } - - private fun initPicturePosition() { - updateMatrixValuesOrigin( - mMatrix, - mValues, - mDrawableW.toFloat(), - mDrawableH.toFloat(), - mImageViewW.toFloat(), - mImageViewH.toFloat() - ) - imageMatrix = mMatrix - } - - fun setDurationMillis(durationMillis: Long): AutoZoomInImageView { - mDurationMillis = durationMillis - return this - } - - fun startZoomInByScaleDelta(scaleDelta: Float = 0.2f, duration: Long = 3000) { - val oriScaleX = mValues[0] - val oriScaleY = mValues[4] - - va.addUpdateListener { animation -> - val value = animation.animatedValue as Float - onUpdate?.invoke(this@AutoZoomInImageView, value / scaleDelta) - updateMatrixValuesSpan( - mValues, - mDrawableW.toFloat(), - mDrawableH.toFloat(), - mImageViewW.toFloat(), - mImageViewH.toFloat(), - oriScaleX, - oriScaleY, - value - ) - mMatrix.setValues(mValues) - imageMatrix = mMatrix - } - va.addListener(object : Animator.AnimatorListener { - override fun onAnimationStart(animation: Animator) { - onStart?.invoke(this@AutoZoomInImageView) - } - - override fun onAnimationEnd(animation: Animator) { - onEnd?.invoke(this@AutoZoomInImageView) - } - - override fun onAnimationCancel(animation: Animator) {} - override fun onAnimationRepeat(animation: Animator) {} - }) - va.duration = duration - va.start() - } - - fun zoomPause() { - if (va.isRunning) { - Log.d(TAG, "pause") - va.pause() - } - } - - - fun zoomResume() { - if (va.isStarted && va.isPaused) { - Log.d(TAG, "resume") - va.resume() - } else { - Log.d(TAG, "restart") - va.start() - } - } - - private fun updateMatrixValuesOrigin( - outMatrix: Matrix?, - outValues: FloatArray?, - drawW: Float, - drawH: Float, - imageW: Float, - imageH: Float - ) { - if (outMatrix == null || outValues == null) { - throw IllegalArgumentException("please set the source of AutoZoomInImageView's matrix and values") - } - outMatrix.reset() - - if (imageH * drawW > drawH * imageW) { - val scale1 = imageH / drawH - val offset1 = (drawW * scale1 - imageW) / 2 - outMatrix.postScale(scale1, scale1) - outMatrix.postTranslate(-offset1, 0f) - } else { - val scale2 = imageW / drawW - val offset2 = (drawH * scale2 - imageH) / 2 - outMatrix.postScale(scale2, scale2) - outMatrix.postTranslate(0f, -offset2) - } - outMatrix.getValues(outValues) - } - - private fun updateMatrixValuesSpan( - outValues: FloatArray, - drawW: Float, drawH: Float, - imageW: Float, imageH: Float, - oriScaleX: Float, oriScaleY: Float, - scaleDelta: Float - ) { - outValues[0] = oriScaleX * (1 + scaleDelta) - outValues[4] = oriScaleY * (1 + scaleDelta) - val offsetwidth = (drawW * outValues[0] - imageW) / 2 - outValues[2] = -offsetwidth - val offsetHeight = (drawH * outValues[4] - imageH) / 2 - outValues[5] = -offsetHeight - } -} \ No newline at end of file diff --git a/modules/mogo-module-tanlu/src/main/res/layout/tanlu_item_main_media_recycler.xml b/modules/mogo-module-tanlu/src/main/res/layout/tanlu_item_main_media_recycler.xml index ccbb8d827b..81879ac41c 100644 --- a/modules/mogo-module-tanlu/src/main/res/layout/tanlu_item_main_media_recycler.xml +++ b/modules/mogo-module-tanlu/src/main/res/layout/tanlu_item_main_media_recycler.xml @@ -51,6 +51,7 @@