dev
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -5,7 +5,7 @@
|
|||||||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
|
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
|
||||||
</configurations>
|
</configurations>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -10,10 +10,35 @@ android {
|
|||||||
versionCode rootProject.ext.android.versionCode
|
versionCode rootProject.ext.android.versionCode
|
||||||
versionName rootProject.ext.android.versionName
|
versionName rootProject.ext.android.versionName
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
javaCompileOptions {
|
||||||
|
annotationProcessorOptions {
|
||||||
|
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
externalNativeBuild {
|
||||||
|
ndk {
|
||||||
|
// 设置支持的SO库架构
|
||||||
|
abiFilters 'armeabi'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
signingConfigs {
|
||||||
|
release {
|
||||||
|
keyAlias = 'CarLauncher'
|
||||||
|
storeFile file('../keystore/car_launcher.jks')
|
||||||
|
storePassword 'ZDauto123456'
|
||||||
|
keyPassword 'ZDauto123456'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
debug {
|
||||||
|
signingConfig signingConfigs.release
|
||||||
|
debuggable = true
|
||||||
|
}
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
|
signingConfig signingConfigs.release
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,9 +46,11 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation rootProject.ext.dependencies.androidxappcompat
|
|
||||||
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
api rootProject.ext.dependencies.androidxappcompat
|
||||||
testImplementation rootProject.ext.dependencies.junit
|
debugImplementation rootProject.ext.dependencies.leakcanary
|
||||||
androidTestImplementation rootProject.ext.dependencies.androidxjunit
|
testImplementation rootProject.ext.dependencies.leakcanary
|
||||||
androidTestImplementation rootProject.ext.dependencies.androidxespressocore
|
releaseImplementation rootProject.ext.dependencies.leakcanarynoop
|
||||||
|
implementation project(':modules:mogo-module-main')
|
||||||
|
implementation project(':foudations:mogo-commons')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme.App">
|
android:theme="@style/AppTheme.App">
|
||||||
|
|
||||||
|
<!-- 高德地图 -->
|
||||||
|
<meta-data
|
||||||
|
android:name="com.amap.api.v2.apikey"
|
||||||
|
android:value="a36b9f7b086fa3951bb35338a5a06dd3" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -2,13 +2,15 @@ package com.mogo.launcher;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import com.mogo.commons.AbsMogoApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author congtaowang
|
* @author congtaowang
|
||||||
* @since 2019-12-18
|
* @since 2019-12-18
|
||||||
* <p>
|
* <p>
|
||||||
* Launcher application
|
* Launcher application
|
||||||
*/
|
*/
|
||||||
public class MogoApplication extends Application {
|
public class MogoApplication extends AbsMogoApplication {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.2'
|
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
classpath "com.alibaba:arouter-register:1.0.2"
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,17 @@ ext {
|
|||||||
fresco : 'com.facebook.fresco:fresco:1.1.0',
|
fresco : 'com.facebook.fresco:fresco:1.1.0',
|
||||||
// 公司服务 - 语音
|
// 公司服务 - 语音
|
||||||
aiassist : "com.zhidaoauto.common:service:1.0.4",
|
aiassist : "com.zhidaoauto.common:service:1.0.4",
|
||||||
|
// 公司服务 - 埋点
|
||||||
|
analytics : "com.elegant.analytics:analytics:1.1.19",
|
||||||
|
|
||||||
// retrofit
|
// retrofit
|
||||||
retrofit : "com.squareup.retrofit2:retrofit:2.3.0",
|
retrofit : "com.squareup.retrofit2:retrofit:2.3.0",
|
||||||
retrofitadapter : "com.squareup.retrofit2:adapter-rxjava:2.1.0",
|
retrofitadapter : "com.squareup.retrofit2:adapter-rxjava:2.1.0",
|
||||||
retrofitconvertergson : "com.squareup.retrofit2:converter-gson:2.3.0",
|
retrofitconvertergson : "com.squareup.retrofit2:converter-gson:2.3.0",
|
||||||
retrofitconverterscalars: "com.squareup.retrofit2:converter-scalars:2.1.0",
|
retrofitconverterscalars: "com.squareup.retrofit2:converter-scalars:2.1.0",
|
||||||
|
|
||||||
|
// leakcanary
|
||||||
|
leakcanary : 'com.squareup.leakcanary:leakcanary-android:1.5.4',
|
||||||
|
leakcanarynoop : 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
1
demo/demo-module-map/.gitignore
vendored
Normal file
1
demo/demo-module-map/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
46
demo/demo-module-map/build.gradle
Normal file
46
demo/demo-module-map/build.gradle
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'com.alibaba.arouter'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 29
|
||||||
|
buildToolsVersion "29.0.2"
|
||||||
|
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 19
|
||||||
|
targetSdkVersion 29
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
consumerProguardFiles 'consumer-rules.pro'
|
||||||
|
|
||||||
|
javaCompileOptions {
|
||||||
|
annotationProcessorOptions {
|
||||||
|
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
|
||||||
|
implementation project(":libraries:mogo-map")
|
||||||
|
implementation project(":foudations:mogo-utils")
|
||||||
|
api project(":foudations:mogo-commons")
|
||||||
|
implementation project(':services:mogo-service-api')
|
||||||
|
implementation project(':modules:mogo-module-common')
|
||||||
|
implementation rootProject.ext.dependencies.androidxappcompat
|
||||||
|
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
||||||
|
implementation rootProject.ext.dependencies.arouter
|
||||||
|
annotationProcessor rootProject.ext.dependencies.aroutercompiler
|
||||||
|
}
|
||||||
0
demo/demo-module-map/consumer-rules.pro
Normal file
0
demo/demo-module-map/consumer-rules.pro
Normal file
21
demo/demo-module-map/proguard-rules.pro
vendored
Normal file
21
demo/demo-module-map/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
2
demo/demo-module-map/src/main/AndroidManifest.xml
Normal file
2
demo/demo-module-map/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.mogo.demo.module.map" />
|
||||||
@@ -0,0 +1,226 @@
|
|||||||
|
package com.mogo.demo.module.map;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.alibaba.android.arouter.launcher.ARouter;
|
||||||
|
import com.mogo.commons.mvp.IView;
|
||||||
|
import com.mogo.commons.mvp.MvpFragment;
|
||||||
|
import com.mogo.commons.mvp.Presenter;
|
||||||
|
import com.mogo.map.listener.IMogoMapListener;
|
||||||
|
import com.mogo.map.location.ILocationListener;
|
||||||
|
import com.mogo.map.location.IMogoLocationClient;
|
||||||
|
import com.mogo.map.location.MogoLocation;
|
||||||
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
|
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||||
|
import com.mogo.map.marker.MogoMarkerOptions;
|
||||||
|
import com.mogo.map.model.MogoPoi;
|
||||||
|
import com.mogo.map.search.geo.MogoPoiItem;
|
||||||
|
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||||
|
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||||
|
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||||
|
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||||
|
import com.mogo.service.MogoServicePaths;
|
||||||
|
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||||
|
import com.mogo.service.map.IMogoMapService;
|
||||||
|
import com.mogo.utils.TipToast;
|
||||||
|
import com.mogo.utils.logger.Logger;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > >
|
||||||
|
implements IView,
|
||||||
|
IMogoMarkerClickListener,
|
||||||
|
IMogoModuleLifecycle,
|
||||||
|
IMogoMapListener,
|
||||||
|
IMogoPoiSearchListener,
|
||||||
|
ILocationListener {
|
||||||
|
|
||||||
|
private static final String TAG = "demo.DemoCardViewProvider";
|
||||||
|
|
||||||
|
private Button mAddMarker;
|
||||||
|
private Button mAddMarkers;
|
||||||
|
|
||||||
|
private Bitmap mMarkerIcon;
|
||||||
|
private Bitmap mClickedMarkerIcon;
|
||||||
|
private TextView mLoc;
|
||||||
|
|
||||||
|
private IMogoMarker mLastClickedMarker;
|
||||||
|
|
||||||
|
private IMogoMapService mMapService;
|
||||||
|
private IMogoPoiSearch mPoiSearch;
|
||||||
|
private IMogoLocationClient mLocationClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getLayoutId() {
|
||||||
|
return R.layout.demo_module_card_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews() {
|
||||||
|
|
||||||
|
mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( getContext() );
|
||||||
|
mPoiSearch = mMapService.getPoiSearch( getContext(), new MogoPoiSearchQuery() );
|
||||||
|
mPoiSearch.setPoiSearchListener( this );
|
||||||
|
mLocationClient = mMapService.getSingletonLocationClient( getContext() );
|
||||||
|
mLocationClient.addLocationListener( this );
|
||||||
|
mLocationClient.start( 1_000L );
|
||||||
|
|
||||||
|
mLoc = findViewById( R.id.demo_module_id_loc );
|
||||||
|
|
||||||
|
mMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher );
|
||||||
|
mClickedMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher_round );
|
||||||
|
mAddMarker = findViewById( R.id.demo_module_id_add_marker );
|
||||||
|
mAddMarker.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
IMogoMapService ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
||||||
|
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||||
|
.icon( mMarkerIcon )
|
||||||
|
.latitude( 39.974525d )
|
||||||
|
.longitude( 116.41733d );
|
||||||
|
IMogoMarker marker = ims.addMarker( options );
|
||||||
|
marker.setOnMarkerClickListener( DemoCardViewFragment.this );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
mAddMarkers = findViewById( R.id.demo_module_id_add_markers );
|
||||||
|
mAddMarkers.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
IMogoMapService ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
||||||
|
|
||||||
|
for ( int i = 0; i < 10; i++ ) {
|
||||||
|
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||||
|
.icon( mMarkerIcon )
|
||||||
|
.latitude( 39.974525d + new Random().nextDouble() )
|
||||||
|
.longitude( 116.41733d + new Random().nextDouble() );
|
||||||
|
List< IMogoMarker > iMogoMarkers = ims.addMarkers( new ArrayList<>( Arrays.asList( options ) ), true );
|
||||||
|
for ( IMogoMarker iMogoMarker : iMogoMarkers ) {
|
||||||
|
iMogoMarker.setOnMarkerClickListener( DemoCardViewFragment.this );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated( @Nullable Bundle savedInstanceState ) {
|
||||||
|
super.onActivityCreated( savedInstanceState );
|
||||||
|
getViewLifecycleOwner().getLifecycle().addObserver( mPresenter );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMarkerClicked( IMogoMarker marker ) {
|
||||||
|
if ( mLastClickedMarker != null ) {
|
||||||
|
mLastClickedMarker.setIcon( this.mMarkerIcon );
|
||||||
|
}
|
||||||
|
marker.setIcon( mClickedMarkerIcon );
|
||||||
|
mLastClickedMarker = marker;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected Presenter createPresenter() {
|
||||||
|
return new Presenter( this ) {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPerform() {
|
||||||
|
TipToast.shortTip( "卡片有效" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
TipToast.shortTip( "卡片无效" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMapLoaded() {
|
||||||
|
Logger.d( TAG, "地图加载事件" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTouch( MotionEvent motionEvent ) {
|
||||||
|
Logger.d( TAG, "地图触摸事件" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPOIClick( MogoPoi poi ) {
|
||||||
|
if ( poi != null ) {
|
||||||
|
TipToast.shortTip( poi.getName() );
|
||||||
|
}
|
||||||
|
mPoiSearch.searchPOIIdAsyn( poi.getPoiId() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPoiSearched( MogoPoiResult result, int errorCode ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPoiItemSearched( MogoPoiItem item, int errorCode ) {
|
||||||
|
if ( item == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new AlertDialog.Builder( getContext() )
|
||||||
|
.setTitle( item.getTitle() )
|
||||||
|
.setMessage(
|
||||||
|
new StringBuilder()
|
||||||
|
.append( "adCode:" ).append( item.getAdCode() ).append( "\n" )
|
||||||
|
.append( "cityCode:" ).append( item.getCityCode() ).append( "\n" )
|
||||||
|
.append( "email:" ).append( item.getEmail() ).append( "\n" )
|
||||||
|
.append( "tel:" ).append( item.getTel() ).append( "\n" )
|
||||||
|
)
|
||||||
|
.setNegativeButton( "知道了", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( DialogInterface dialog, int which ) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLocationChanged( MogoLocation location ) {
|
||||||
|
Logger.i( TAG, location.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
getViewLifecycleOwner().getLifecycle().removeObserver( mPresenter );
|
||||||
|
mLocationClient.removeLocationListener( this );
|
||||||
|
if ( mLastClickedMarker != null ) {
|
||||||
|
mLastClickedMarker.destroy();
|
||||||
|
mLastClickedMarker = null;
|
||||||
|
}
|
||||||
|
mMapService = null;
|
||||||
|
mPoiSearch = null;
|
||||||
|
mLocationClient = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.mogo.demo.module.map;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||||
|
import com.mogo.map.listener.IMogoMapListener;
|
||||||
|
import com.mogo.module.common.MogoModulePaths;
|
||||||
|
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||||
|
import com.mogo.service.module.IMogoModuleProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
@Route( path = MogoModulePaths.PATH_MODULE_DEMO )
|
||||||
|
public class DemoCardViewProvider implements IMogoModuleProvider {
|
||||||
|
|
||||||
|
private DemoCardViewFragment fragment;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment createFragment( Context context, Bundle data ) {
|
||||||
|
fragment = new DemoCardViewFragment();
|
||||||
|
fragment.setArguments( data );
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init( Context context ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModuleName() {
|
||||||
|
return MogoModulePaths.PATH_MODULE_DEMO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMogoModuleLifecycle getCardLifecycle() {
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View createView( Context context ) {
|
||||||
|
// don't
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMogoMapListener getMapListener() {
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getType() {
|
||||||
|
return IMogoModuleProvider.TYPE_FRAGMENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
demo/demo-module-map/src/main/res/drawable/ic_launcher.png
Normal file
BIN
demo/demo-module-map/src/main/res/drawable/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
demo/demo-module-map/src/main/res/drawable/ic_launcher_round.png
Normal file
BIN
demo/demo-module-map/src/main/res/drawable/ic_launcher_round.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="300dp"
|
||||||
|
android:background="#ff0000">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/demo_module_id_loc"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/demo_module_id_add_marker"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="添加一个覆盖物"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/demo_module_id_add_markers"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="75dp"
|
||||||
|
android:text="添加多个覆盖物"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
3
demo/demo-module-map/src/main/res/values/strings.xml
Normal file
3
demo/demo-module-map/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">demo_module_map</string>
|
||||||
|
</resources>
|
||||||
@@ -13,6 +13,13 @@ android {
|
|||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
consumerProguardFiles 'consumer-rules.pro'
|
consumerProguardFiles 'consumer-rules.pro'
|
||||||
|
|
||||||
|
javaCompileOptions {
|
||||||
|
annotationProcessorOptions {
|
||||||
|
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -27,5 +34,9 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
api rootProject.ext.dependencies.aiassist
|
api rootProject.ext.dependencies.aiassist
|
||||||
|
api rootProject.ext.dependencies.androidxappcompat
|
||||||
|
api rootProject.ext.dependencies.analytics
|
||||||
implementation project(":foudations:mogo-utils")
|
implementation project(":foudations:mogo-utils")
|
||||||
|
implementation rootProject.ext.dependencies.arouter
|
||||||
|
annotationProcessor rootProject.ext.dependencies.aroutercompiler
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ package com.mogo.commons;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import com.alibaba.android.arouter.launcher.ARouter;
|
||||||
|
import com.elegant.analytics.Analytics;
|
||||||
|
import com.elegant.analytics.AnalyticsConfig;
|
||||||
|
import com.mogo.commons.debug.DebugConfig;
|
||||||
|
import com.mogo.utils.TipToast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author congtaowang
|
* @author congtaowang
|
||||||
* @since 2019-12-23
|
* @since 2019-12-23
|
||||||
@@ -12,13 +18,36 @@ public class AbsMogoApplication extends Application {
|
|||||||
|
|
||||||
private static Application sApp;
|
private static Application sApp;
|
||||||
|
|
||||||
|
public static Application getApp() {
|
||||||
|
return sApp;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
sApp = this;
|
sApp = this;
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Application getApp() {
|
protected void init() {
|
||||||
return sApp;
|
|
||||||
|
// 初始化埋点
|
||||||
|
Analytics.getInstance().start( sApp );
|
||||||
|
// 0 - debug 近实时上报,积累一条埋点上报,或者积累3秒上报一次。
|
||||||
|
// 2 - 本地缓存,聚合上报,积累30条埋点上报,或者积累60秒上报一次。
|
||||||
|
Analytics.getInstance().start( sApp );
|
||||||
|
AnalyticsConfig.getInstance( sApp ).setMode( DebugConfig.isDebug() ? 0 : 2 );
|
||||||
|
AnalyticsConfig.getInstance( sApp ).shouldLog( DebugConfig.isDebug() );
|
||||||
|
|
||||||
|
// 初始化 arouter
|
||||||
|
if ( DebugConfig.isDebug() ) {
|
||||||
|
ARouter.openDebug();
|
||||||
|
ARouter.openLog();
|
||||||
|
}
|
||||||
|
ARouter.init( sApp );
|
||||||
|
|
||||||
|
// 初始化toast
|
||||||
|
TipToast.init( sApp, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.mogo.commons.analytics;
|
||||||
|
|
||||||
|
import com.elegant.analytics.Analytics;
|
||||||
|
import com.mogo.commons.network.ParamUtils;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 埋点
|
||||||
|
*/
|
||||||
|
public class AnalyticsUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 埋点
|
||||||
|
*
|
||||||
|
* @param event 事件名称
|
||||||
|
* @param properties 事件参数
|
||||||
|
*/
|
||||||
|
public static void track( String event, Map< String, Object > properties ) {
|
||||||
|
Analytics.getInstance().setCustomParams( ParamUtils.getAnalyticsParameters() );
|
||||||
|
Analytics.getInstance().track( event, properties );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.mogo.commons.debug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 各个莫快递调试信息控制接口
|
||||||
|
*/
|
||||||
|
public class DebugConfig {
|
||||||
|
|
||||||
|
private static boolean sDebug = true;
|
||||||
|
|
||||||
|
public static boolean isDebug() {
|
||||||
|
return sDebug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDebug( boolean sDebug ) {
|
||||||
|
DebugConfig.sDebug = sDebug;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.mogo.commons.mvp;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* mvp的view接口
|
||||||
|
*/
|
||||||
|
public interface IView {
|
||||||
|
|
||||||
|
Context getContext();
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.mogo.commons.mvp;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* mvp 的 activity
|
||||||
|
*/
|
||||||
|
public abstract class MvpActivity< V extends IView, P extends Presenter< V > >
|
||||||
|
extends AppCompatActivity implements IView {
|
||||||
|
|
||||||
|
protected P mPresenter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate( @Nullable Bundle savedInstanceState ) {
|
||||||
|
super.onCreate( savedInstanceState );
|
||||||
|
setContentView( getLayoutId() );
|
||||||
|
initViews();
|
||||||
|
mPresenter = createPresenter();
|
||||||
|
getLifecycle().addObserver( mPresenter );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 布局资源
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract int getLayoutId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化控件,必须在初始化完成之后才可以实例化presenter,避免
|
||||||
|
* presenter 生命周期错乱
|
||||||
|
*/
|
||||||
|
protected abstract void initViews();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 presenter 实例
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
protected abstract P createPresenter();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Context getContext() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
getLifecycle().removeObserver( mPresenter );
|
||||||
|
if ( mPresenter != null ) {
|
||||||
|
getLifecycle().removeObserver( mPresenter );
|
||||||
|
}
|
||||||
|
mPresenter = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package com.mogo.commons.mvp;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* mvp fragment
|
||||||
|
*/
|
||||||
|
public abstract class MvpFragment< V extends IView, P extends Presenter< V > > extends Fragment implements IView {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
protected P mPresenter;
|
||||||
|
private View mRootView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach( Context context ) {
|
||||||
|
super.onAttach( context );
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView( @NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState ) {
|
||||||
|
return inflater.inflate( getLayoutId(), container, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated( @NonNull View view, @Nullable Bundle savedInstanceState ) {
|
||||||
|
super.onViewCreated( view, savedInstanceState );
|
||||||
|
mRootView = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 布局资源
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract int getLayoutId();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated( @Nullable Bundle savedInstanceState ) {
|
||||||
|
super.onActivityCreated( savedInstanceState );
|
||||||
|
initViews();
|
||||||
|
mPresenter = createPresenter();
|
||||||
|
getViewLifecycleOwner().getLifecycle().addObserver( mPresenter );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化控件,必须在初始化完成之后才可以实例化presenter,避免
|
||||||
|
* presenter 生命周期错乱
|
||||||
|
*/
|
||||||
|
protected abstract void initViews();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 presenter 实例
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
protected abstract P createPresenter();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected < T extends View > T findViewById( int id ) {
|
||||||
|
if ( mRootView != null ) {
|
||||||
|
return ( T ) mRootView.findViewById( id );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Context getContext() {
|
||||||
|
return mContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
if ( mPresenter != null ) {
|
||||||
|
getViewLifecycleOwner().getLifecycle().removeObserver( mPresenter );
|
||||||
|
}
|
||||||
|
mPresenter = null;
|
||||||
|
mRootView = null;
|
||||||
|
mContext = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.mogo.commons.mvp;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* mvp 的 presenter
|
||||||
|
*/
|
||||||
|
public abstract class Presenter< V extends IView > implements LifecycleObserver {
|
||||||
|
|
||||||
|
private V mView;
|
||||||
|
|
||||||
|
public Presenter( V view ) {
|
||||||
|
this.mView = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent( Lifecycle.Event.ON_CREATE )
|
||||||
|
public void onCreate( @NonNull LifecycleOwner owner ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent( Lifecycle.Event.ON_START )
|
||||||
|
public void onStart( @NonNull LifecycleOwner owner ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent( Lifecycle.Event.ON_RESUME )
|
||||||
|
public void onResume( @NonNull LifecycleOwner owner ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent( Lifecycle.Event.ON_PAUSE )
|
||||||
|
public void onPause( @NonNull LifecycleOwner owner ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent( Lifecycle.Event.ON_STOP )
|
||||||
|
public void onStop( @NonNull LifecycleOwner owner ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent( Lifecycle.Event.ON_DESTROY )
|
||||||
|
public void onDestroy( @NonNull LifecycleOwner owner ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent( Lifecycle.Event.ON_ANY )
|
||||||
|
public void onLifecycleChanged(
|
||||||
|
@NonNull LifecycleOwner owner,
|
||||||
|
@NonNull Lifecycle.Event event ) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.mogo.commons.network;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
public class ParamUtils {
|
||||||
|
|
||||||
|
public static Map< String, Object > getAnalyticsParameters() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,63 +10,72 @@ import android.util.DisplayMetrics;
|
|||||||
|
|
||||||
public class ResourcesHelper {
|
public class ResourcesHelper {
|
||||||
|
|
||||||
public static Resources getResources( Context context){
|
public static Resources getResources( Context context ) {
|
||||||
return context.getResources();
|
return context.getResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getColor( Context context, int rid) {
|
public static int getColor( Context context, int rid ) {
|
||||||
return getResources(context).getColor(rid);
|
return getResources( context ).getColor( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ColorStateList getColorStateList( Context context, int rid) {
|
public static ColorStateList getColorStateList( Context context, int rid ) {
|
||||||
return getResources(context).getColorStateList(rid);
|
return getResources( context ).getColorStateList( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getString( Context context, int rid) {
|
public static String getString( Context context, int rid ) {
|
||||||
return getResources(context).getString(rid);
|
return getResources( context ).getString( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getString( Context context, int rid, int param1, int param2) {
|
public static String getString( Context context, int rid, int param1, int param2 ) {
|
||||||
return getResources(context).getString(rid, param1, param2);
|
return getResources( context ).getString( rid, param1, param2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getString( Context context, int rid, String str) {
|
public static String getString( Context context, int rid, String str ) {
|
||||||
return getResources(context).getString(rid, str);
|
return getResources( context ).getString( rid, str );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getStringArray( Context context, int rid) {
|
public static String[] getStringArray( Context context, int rid ) {
|
||||||
return getResources(context).getStringArray(rid);
|
return getResources( context ).getStringArray( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Drawable getDrawable( Context context, int rid) {
|
public static Drawable getDrawable( Context context, int rid ) {
|
||||||
return getResources(context).getDrawable(rid);
|
return getResources( context ).getDrawable( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getDimension( Context context, int rid) {
|
public static float getDimension( Context context, int rid ) {
|
||||||
return getResources(context).getDimension(rid);
|
return getResources( context ).getDimension( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DisplayMetrics getDisplayMetrics( Context context) {
|
public static DisplayMetrics getDisplayMetrics( Context context ) {
|
||||||
return getResources(context).getDisplayMetrics();
|
return getResources( context ).getDisplayMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDisplayMetrics( Context context, int x) {
|
public static int getDisplayMetrics( Context context, int x ) {
|
||||||
return getResources(context).getDimensionPixelSize(x);
|
return getResources( context ).getDimensionPixelSize( x );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDimensionPixelSize( Context context, int x) {
|
public static int getDimensionPixelSize( Context context, int x ) {
|
||||||
return getResources(context).getDimensionPixelSize(x);
|
return getResources( context ).getDimensionPixelSize( x );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getInteger( Context context, int rid) {
|
public static int getInteger( Context context, int rid ) {
|
||||||
return getResources(context).getInteger(rid);
|
return getResources( context ).getInteger( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XmlResourceParser getXml( Context context, int rid) {
|
public static XmlResourceParser getXml( Context context, int rid ) {
|
||||||
return getResources(context).getXml(rid);
|
return getResources( context ).getXml( rid );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Configuration getConfiguration( Context context) {
|
public static Configuration getConfiguration( Context context ) {
|
||||||
return getResources(context).getConfiguration();
|
return getResources( context ).getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getResNameById( Context context, int id ) {
|
||||||
|
try {
|
||||||
|
return context.getResources().getResourceName( id );
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return String.valueOf( id );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package com.mogo.utils;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
public class SoftKeyBoardJobber {
|
||||||
|
|
||||||
|
public static boolean hideIfNecessary( Activity context, MotionEvent ev ) {
|
||||||
|
if ( ev.getAction() == MotionEvent.ACTION_DOWN ) {
|
||||||
|
View v = context.getCurrentFocus();
|
||||||
|
if ( isShouldHideInput( v, ev ) ) {
|
||||||
|
InputMethodManager imm = ( InputMethodManager ) context.getSystemService( Context.INPUT_METHOD_SERVICE );
|
||||||
|
if ( imm != null ) {
|
||||||
|
imm.hideSoftInputFromWindow( v.getWindowToken(), 0 );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isShouldHideInput( View v, MotionEvent event ) {
|
||||||
|
if ( v != null && ( v instanceof EditText ) ) {
|
||||||
|
int[] leftTop = {0, 0};
|
||||||
|
// 获取输入框当前的location位置
|
||||||
|
v.getLocationInWindow( leftTop );
|
||||||
|
int left = leftTop[0];
|
||||||
|
int top = leftTop[1];
|
||||||
|
int bottom = top + v.getHeight();
|
||||||
|
int right = left + v.getWidth();
|
||||||
|
return !( event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void hide( Context context, View v ) {
|
||||||
|
InputMethodManager imm = getInputMethodManager( context );
|
||||||
|
if ( imm != null ) {
|
||||||
|
imm.hideSoftInputFromWindow( v.getWindowToken(), 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void show( Context context ) {
|
||||||
|
InputMethodManager imm = getInputMethodManager( context );
|
||||||
|
if ( imm != null ) {
|
||||||
|
imm.toggleSoftInput( 0, InputMethodManager.HIDE_NOT_ALWAYS );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InputMethodManager imm = null;
|
||||||
|
|
||||||
|
private static InputMethodManager getInputMethodManager( Context context ) {
|
||||||
|
if ( imm == null ) {
|
||||||
|
imm = ( InputMethodManager ) context.getSystemService( Context.INPUT_METHOD_SERVICE );
|
||||||
|
}
|
||||||
|
return imm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnSoftKeyboardChangeListener {
|
||||||
|
void onSoftKeyBoardChange( int softKeyboardHeight, boolean visible );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViewTreeObserver.OnGlobalLayoutListener observeSoftKeyboard( Activity activity, final OnSoftKeyboardChangeListener listener ) {
|
||||||
|
if ( !isAliveActivity( activity ) || listener == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final View decorView = activity.getWindow().getDecorView();
|
||||||
|
ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
|
||||||
|
int previousKeyboardHeight = -1;
|
||||||
|
Rect rect = new Rect();
|
||||||
|
boolean lastVisibleState = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
rect.setEmpty();
|
||||||
|
decorView.getWindowVisibleDisplayFrame( rect );
|
||||||
|
int displayHeight = rect.bottom - rect.top;
|
||||||
|
int height = decorView.getHeight() - rect.top;
|
||||||
|
int keyboardHeight = height - displayHeight;
|
||||||
|
if ( previousKeyboardHeight != keyboardHeight ) {
|
||||||
|
boolean hide = ( double ) displayHeight / height > 0.8;
|
||||||
|
if ( hide != lastVisibleState ) {
|
||||||
|
listener.onSoftKeyBoardChange( keyboardHeight, !hide );
|
||||||
|
lastVisibleState = hide;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previousKeyboardHeight = height;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
decorView.getViewTreeObserver().addOnGlobalLayoutListener( onGlobalLayoutListener );
|
||||||
|
return onGlobalLayoutListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeSoftKeyboardObserver( Activity activity, ViewTreeObserver.OnGlobalLayoutListener listener ) {
|
||||||
|
if ( !isAliveActivity( activity ) || listener == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final View decorView = activity.getWindow().getDecorView();
|
||||||
|
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN ) {
|
||||||
|
decorView.getViewTreeObserver().removeOnGlobalLayoutListener( listener );
|
||||||
|
} else {
|
||||||
|
decorView.getViewTreeObserver().removeGlobalOnLayoutListener( listener );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAliveActivity( Activity activity ) {
|
||||||
|
return activity != null
|
||||||
|
&& activity.getWindow() != null
|
||||||
|
&& activity.getWindow().getDecorView() != null
|
||||||
|
&& activity.getWindow().getDecorView().getViewTreeObserver() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.mogo.utils;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by congtaowang on 2018/12/20.
|
|
||||||
*/
|
|
||||||
public class SoftKeyboardUtils {
|
|
||||||
|
|
||||||
public static void show( Context context ) {
|
|
||||||
try {
|
|
||||||
InputMethodManager imm = ( InputMethodManager ) context.getSystemService( Context.INPUT_METHOD_SERVICE );
|
|
||||||
if ( imm != null ) {
|
|
||||||
imm.toggleSoftInput( 0, InputMethodManager.HIDE_NOT_ALWAYS );
|
|
||||||
}
|
|
||||||
} catch ( Exception e ) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void hidden( Context context, EditText editText ) {
|
|
||||||
try {
|
|
||||||
InputMethodManager imm = ( InputMethodManager ) context.getSystemService( Context.INPUT_METHOD_SERVICE );
|
|
||||||
if ( imm != null ) {
|
|
||||||
imm.hideSoftInputFromWindow( editText.getWindowToken(), 0 );
|
|
||||||
}
|
|
||||||
} catch ( Exception e ) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.mogo.utils.storage.lrucache;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/** Junk drawer of utility methods. */
|
||||||
|
final class CacheUtil {
|
||||||
|
static final Charset US_ASCII = Charset.forName("US-ASCII");
|
||||||
|
static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
|
private CacheUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static String readFully( Reader reader) throws IOException {
|
||||||
|
try {
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
char[] buffer = new char[1024];
|
||||||
|
int count;
|
||||||
|
while ((count = reader.read(buffer)) != -1) {
|
||||||
|
writer.write(buffer, 0, count);
|
||||||
|
}
|
||||||
|
return writer.toString();
|
||||||
|
} finally {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the imageContent of {@code dir}. Throws an IOException if any file
|
||||||
|
* could not be deleted, or if {@code dir} is not a readable directory.
|
||||||
|
*/
|
||||||
|
static void deleteContents( File dir) throws IOException {
|
||||||
|
File[] files = dir.listFiles();
|
||||||
|
if (files == null) {
|
||||||
|
throw new IOException("not a readable directory: " + dir);
|
||||||
|
}
|
||||||
|
for ( File file : files) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
deleteContents(file);
|
||||||
|
}
|
||||||
|
if (!file.delete()) {
|
||||||
|
throw new IOException("failed to delete file: " + file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void closeQuietly(/*Auto*/Closeable closeable) {
|
||||||
|
if (closeable != null) {
|
||||||
|
try {
|
||||||
|
closeable.close();
|
||||||
|
} catch ( RuntimeException rethrown) {
|
||||||
|
throw rethrown;
|
||||||
|
} catch ( Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,374 @@
|
|||||||
|
package com.mogo.utils.storage.lrucache;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class DiskCacheManager {
|
||||||
|
|
||||||
|
private static DiskLruCache mDiskLruCache = null;
|
||||||
|
private DiskLruCache.Editor mEditor = null;
|
||||||
|
private DiskLruCache.Snapshot mSnapshot = null;
|
||||||
|
public static final long CACHE_MAXSIZE = 10 * 1024 * 1024;
|
||||||
|
|
||||||
|
public DiskCacheManager( Context context, String uniqueName) {
|
||||||
|
try {
|
||||||
|
if (mDiskLruCache != null) {
|
||||||
|
mDiskLruCache.close();
|
||||||
|
mDiskLruCache = null;
|
||||||
|
}
|
||||||
|
File cacheFile = getCacheFile(context, uniqueName);
|
||||||
|
mDiskLruCache = DiskLruCache.open(cacheFile, 1, 1, CACHE_MAXSIZE);
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存的路径 两个路径在卸载程序时都会删除,因此不会在卸载后还保留乱七八糟的缓存
|
||||||
|
* 有SD卡时获取 /sdcard/Android/data/<application package>/cache
|
||||||
|
* 无SD卡时获取 /data/labelList/<application package>/cache
|
||||||
|
*
|
||||||
|
* @param context 上下文
|
||||||
|
* @param uniqueName 缓存目录下的细分目录,用于存放不同类型的缓存
|
||||||
|
* @return 缓存目录 File
|
||||||
|
*/
|
||||||
|
private File getCacheFile( Context context, String uniqueName) {
|
||||||
|
String cachePath = null;
|
||||||
|
try {
|
||||||
|
cachePath = context.getCacheDir().getPath();
|
||||||
|
}catch ( Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new File(cachePath + File.separator + uniqueName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存 editor
|
||||||
|
*
|
||||||
|
* @param key 缓存的key
|
||||||
|
* @return editor
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private DiskLruCache.Editor edit( String key) throws IOException {
|
||||||
|
key = SecretUtil.getMD5Result(key); //存取的 key
|
||||||
|
if (mDiskLruCache != null) {
|
||||||
|
mEditor = mDiskLruCache.edit(key);
|
||||||
|
}
|
||||||
|
return mEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 key 获取缓存缩略
|
||||||
|
*
|
||||||
|
* @param key 缓存的key
|
||||||
|
* @return Snapshot
|
||||||
|
*/
|
||||||
|
private DiskLruCache.Snapshot snapshot( String key) {
|
||||||
|
if (mDiskLruCache != null) {
|
||||||
|
try {
|
||||||
|
mSnapshot = mDiskLruCache.get(key);
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mSnapshot;
|
||||||
|
}
|
||||||
|
/*************************
|
||||||
|
* 字符串读写
|
||||||
|
*************************/
|
||||||
|
/**
|
||||||
|
* 缓存 String
|
||||||
|
*
|
||||||
|
* @param key 缓存文件键值(MD5加密结果作为缓存文件名)
|
||||||
|
* @param value 缓存内容
|
||||||
|
*/
|
||||||
|
public void put( String key, String value) {
|
||||||
|
DiskLruCache.Editor editor = null;
|
||||||
|
BufferedWriter writer = null;
|
||||||
|
try {
|
||||||
|
editor = edit(key);
|
||||||
|
if (editor == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OutputStream os = editor.newOutputStream(0);
|
||||||
|
writer = new BufferedWriter(new OutputStreamWriter(os));
|
||||||
|
writer.write(value);
|
||||||
|
editor.commit();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
try {
|
||||||
|
if (editor != null)
|
||||||
|
editor.abort();
|
||||||
|
} catch ( IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (writer != null) {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字符串缓存
|
||||||
|
*
|
||||||
|
* @param key cache'key
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public String getString( String key) {
|
||||||
|
InputStream inputStream = getCacheInputStream(key);
|
||||||
|
if (inputStream == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return inputStream2String(inputStream);
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch ( IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************
|
||||||
|
* Json对象读写
|
||||||
|
*************************/
|
||||||
|
//Json 数据转换成 String 存储
|
||||||
|
public void put( String key, JSONObject value) {
|
||||||
|
put(key, value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
//取得 json 字符串再转为 Json对象
|
||||||
|
public JSONObject getJsonObject( String key) {
|
||||||
|
String json = getString(key);
|
||||||
|
try {
|
||||||
|
return new JSONObject(json);
|
||||||
|
} catch ( JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************
|
||||||
|
* Json数组对象读写
|
||||||
|
*************************/
|
||||||
|
|
||||||
|
public void put( String key, JSONArray array) {
|
||||||
|
put(key, array.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONArray getJsonArray( String key) {
|
||||||
|
try {
|
||||||
|
return new JSONArray(getString(key));
|
||||||
|
} catch ( JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************
|
||||||
|
* byte 数据读写
|
||||||
|
*************************/
|
||||||
|
/**
|
||||||
|
* 存入byte数组
|
||||||
|
*
|
||||||
|
* @param key cache'key
|
||||||
|
* @param bytes bytes to save
|
||||||
|
*/
|
||||||
|
public void put( String key, byte[] bytes) {
|
||||||
|
OutputStream out = null;
|
||||||
|
DiskLruCache.Editor editor = null;
|
||||||
|
try {
|
||||||
|
editor = edit(key);
|
||||||
|
if (editor == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
out = editor.newOutputStream(0);
|
||||||
|
out.write(bytes);
|
||||||
|
out.flush();
|
||||||
|
editor.commit();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
try {
|
||||||
|
if (editor != null) {
|
||||||
|
editor.abort();
|
||||||
|
}
|
||||||
|
} catch ( IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存的 byte 数组
|
||||||
|
*
|
||||||
|
* @param key cache'key
|
||||||
|
* @return bytes
|
||||||
|
*/
|
||||||
|
public byte[] getBytes( String key) {
|
||||||
|
byte[] bytes = null;
|
||||||
|
InputStream inputStream = getCacheInputStream(key);
|
||||||
|
if (inputStream == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
byte[] buf = new byte[256];
|
||||||
|
int len = 0;
|
||||||
|
try {
|
||||||
|
while ((len = inputStream.read(buf)) != -1) {
|
||||||
|
bos.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
bytes = bos.toByteArray();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************
|
||||||
|
* 序列化对象数据读写
|
||||||
|
*************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 序列化对象写入
|
||||||
|
*
|
||||||
|
* @param key cache'key
|
||||||
|
* @param object 待缓存的序列化对象
|
||||||
|
*/
|
||||||
|
public void put( String key, Serializable object) {
|
||||||
|
ObjectOutputStream oos = null;
|
||||||
|
DiskLruCache.Editor editor = null;
|
||||||
|
try {
|
||||||
|
editor = edit(key);
|
||||||
|
if (editor == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
oos = new ObjectOutputStream(editor.newOutputStream(0));
|
||||||
|
oos.writeObject(object);
|
||||||
|
oos.flush();
|
||||||
|
editor.commit();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
try {
|
||||||
|
if (editor != null)
|
||||||
|
editor.abort();
|
||||||
|
} catch ( IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (oos != null) {
|
||||||
|
oos.close();
|
||||||
|
}
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 序列化对象
|
||||||
|
*
|
||||||
|
* @param key cache'key
|
||||||
|
* @param <T> 对象类型
|
||||||
|
* @return 读取到的序列化对象
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T getSerializable( String key) {
|
||||||
|
T object = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
InputStream in = getCacheInputStream(key);
|
||||||
|
if (in == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ois = new ObjectInputStream(in);
|
||||||
|
object = (T) ois.readObject();
|
||||||
|
} catch ( IOException | ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
********************** 辅助工具方法 分割线 ****************************
|
||||||
|
************************************************************************/
|
||||||
|
/**
|
||||||
|
* inputStream 转 String
|
||||||
|
*
|
||||||
|
* @param is 输入流
|
||||||
|
* @return 结果字符串
|
||||||
|
*/
|
||||||
|
private String inputStream2String( InputStream is) throws IOException {
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
buffer.append(line);
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 缓存数据的 InputStream
|
||||||
|
*
|
||||||
|
* @param key cache'key
|
||||||
|
* @return InputStream
|
||||||
|
*/
|
||||||
|
private InputStream getCacheInputStream( String key) {
|
||||||
|
key = SecretUtil.getMD5Result(key);
|
||||||
|
InputStream in;
|
||||||
|
DiskLruCache.Snapshot snapshot = snapshot(key);
|
||||||
|
if (snapshot == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
in = snapshot.getInputStream(0);
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步记录文件
|
||||||
|
*/
|
||||||
|
public static void flush() {
|
||||||
|
if (mDiskLruCache != null) {
|
||||||
|
try {
|
||||||
|
mDiskLruCache.flush();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,947 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.mogo.utils.storage.lrucache;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FilterOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A cache that uses a bounded amount of space on a filesystem. Each cache
|
||||||
|
* entry has a string key and a fixed number of values. Each key must match
|
||||||
|
* the regex <strong>[a-z0-9_-]{1,120}</strong>. Values are byte sequences,
|
||||||
|
* accessible as streams or files. Each value must be between {@code 0} and
|
||||||
|
* {@code Integer.MAX_VALUE} bytes in length.
|
||||||
|
*
|
||||||
|
* <p>The cache stores its data in a directory on the filesystem. This
|
||||||
|
* directory must be exclusive to the cache; the cache may delete or overwrite
|
||||||
|
* files from its directory. It is an error for multiple processes to use the
|
||||||
|
* same cache directory at the same time.
|
||||||
|
*
|
||||||
|
* <p>This cache limits the number of bytes that it will store on the
|
||||||
|
* filesystem. When the number of stored bytes exceeds the limit, the cache will
|
||||||
|
* remove entries in the background until the limit is satisfied. The limit is
|
||||||
|
* not strict: the cache may temporarily exceed it while waiting for files to be
|
||||||
|
* deleted. The limit does not include filesystem overhead or the cache
|
||||||
|
* journal so space-sensitive applications should set a conservative limit.
|
||||||
|
*
|
||||||
|
* <p>Clients call {@link #edit} to create or update the values of an entry. An
|
||||||
|
* entry may have only one editor at one time; if a value is not available to be
|
||||||
|
* edited then {@link #edit} will return null.
|
||||||
|
* <ul>
|
||||||
|
* <li>When an entry is being <strong>created</strong> it is necessary to
|
||||||
|
* supply a full set of values; the empty value should be used as a
|
||||||
|
* placeholder if necessary.
|
||||||
|
* <li>When an entry is being <strong>edited</strong>, it is not necessary
|
||||||
|
* to supply data for every value; values default to their previous
|
||||||
|
* value.
|
||||||
|
* </ul>
|
||||||
|
* Every {@link #edit} call must be matched by a call to {@link Editor#commit}
|
||||||
|
* or {@link Editor#abort}. Committing is atomic: a read observes the full set
|
||||||
|
* of values as they were before or after the commit, but never a mix of values.
|
||||||
|
*
|
||||||
|
* <p>Clients call {@link #get} to read a snapshot of an entry. The read will
|
||||||
|
* observe the value at the time that {@link #get} was called. Updates and
|
||||||
|
* removals after the call do not impact ongoing reads.
|
||||||
|
*
|
||||||
|
* <p>This class is tolerant of some I/O errors. If files are missing from the
|
||||||
|
* filesystem, the corresponding entries will be dropped from the cache. If
|
||||||
|
* an error occurs while writing a cache value, the edit will fail silently.
|
||||||
|
* Callers should handle other problems by catching {@code IOException} and
|
||||||
|
* responding appropriately.
|
||||||
|
*/
|
||||||
|
public final class DiskLruCache implements Closeable {
|
||||||
|
static final String JOURNAL_FILE = "journal";
|
||||||
|
static final String JOURNAL_FILE_TEMP = "journal.tmp";
|
||||||
|
static final String JOURNAL_FILE_BACKUP = "journal.bkp";
|
||||||
|
static final String MAGIC = "libcore.io.DiskLruCache";
|
||||||
|
static final String VERSION_1 = "1";
|
||||||
|
static final long ANY_SEQUENCE_NUMBER = -1;
|
||||||
|
static final String STRING_KEY_PATTERN = "[a-z0-9_-]{1,120}";
|
||||||
|
static final Pattern LEGAL_KEY_PATTERN = Pattern.compile(STRING_KEY_PATTERN);
|
||||||
|
private static final String CLEAN = "CLEAN";
|
||||||
|
private static final String DIRTY = "DIRTY";
|
||||||
|
private static final String REMOVE = "REMOVE";
|
||||||
|
private static final String READ = "READ";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This cache uses a journal file named "journal". A typical journal file
|
||||||
|
* looks like this:
|
||||||
|
* libcore.io.DiskLruCache
|
||||||
|
* 1
|
||||||
|
* 100
|
||||||
|
* 2
|
||||||
|
*
|
||||||
|
* CLEAN 3400330d1dfc7f3f7f4b8d4d803dfcf6 832 21054
|
||||||
|
* DIRTY 335c4c6028171cfddfbaae1a9c313c52
|
||||||
|
* CLEAN 335c4c6028171cfddfbaae1a9c313c52 3934 2342
|
||||||
|
* REMOVE 335c4c6028171cfddfbaae1a9c313c52
|
||||||
|
* DIRTY 1ab96a171faeeee38496d8b330771a7a
|
||||||
|
* CLEAN 1ab96a171faeeee38496d8b330771a7a 1600 234
|
||||||
|
* READ 335c4c6028171cfddfbaae1a9c313c52
|
||||||
|
* READ 3400330d1dfc7f3f7f4b8d4d803dfcf6
|
||||||
|
*
|
||||||
|
* The first five lines of the journal form its header. They are the
|
||||||
|
* constant string "libcore.io.DiskLruCache", the disk cache's version,
|
||||||
|
* the application's version, the value count, and a blank line.
|
||||||
|
*
|
||||||
|
* Each of the subsequent lines in the file is a record of the state of a
|
||||||
|
* cache entry. Each line contains space-separated values: a state, a key,
|
||||||
|
* and optional state-specific values.
|
||||||
|
* o DIRTY lines track that an entry is actively being created or updated.
|
||||||
|
* Every successful DIRTY action should be followed by a CLEAN or REMOVE
|
||||||
|
* action. DIRTY lines without a matching CLEAN or REMOVE indicate that
|
||||||
|
* temporary files may need to be deleted.
|
||||||
|
* o CLEAN lines track a cache entry that has been successfully published
|
||||||
|
* and may be read. A publish line is followed by the lengths of each of
|
||||||
|
* its values.
|
||||||
|
* o READ lines track accesses for LRU.
|
||||||
|
* o REMOVE lines track entries that have been deleted.
|
||||||
|
*
|
||||||
|
* The journal file is appended to as cache operations occur. The journal may
|
||||||
|
* occasionally be compacted by dropping redundant lines. A temporary file named
|
||||||
|
* "journal.tmp" will be used during compaction; that file should be deleted if
|
||||||
|
* it exists when the cache is opened.
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final File directory;
|
||||||
|
private final File journalFile;
|
||||||
|
private final File journalFileTmp;
|
||||||
|
private final File journalFileBackup;
|
||||||
|
private final int appVersion;
|
||||||
|
private long maxSize;
|
||||||
|
private final int valueCount;
|
||||||
|
private long size = 0;
|
||||||
|
private Writer journalWriter;
|
||||||
|
private final LinkedHashMap< String, Entry> lruEntries =
|
||||||
|
new LinkedHashMap< String, Entry>(0, 0.75f, true);
|
||||||
|
private int redundantOpCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To differentiate between old and current snapshots, each entry is given
|
||||||
|
* a sequence number each time an edit is committed. A snapshot is stale if
|
||||||
|
* its sequence number is not equal to its entry's sequence number.
|
||||||
|
*/
|
||||||
|
private long nextSequenceNumber = 0;
|
||||||
|
|
||||||
|
/** This cache uses a single background thread to evict entries. */
|
||||||
|
final ThreadPoolExecutor executorService =
|
||||||
|
new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue< Runnable >());
|
||||||
|
private final Callable< Void > cleanupCallable = new Callable< Void >() {
|
||||||
|
public Void call() throws Exception {
|
||||||
|
synchronized (DiskLruCache.this) {
|
||||||
|
if (journalWriter == null) {
|
||||||
|
return null; // Closed.
|
||||||
|
}
|
||||||
|
trimToSize();
|
||||||
|
if (journalRebuildRequired()) {
|
||||||
|
rebuildJournal();
|
||||||
|
redundantOpCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private DiskLruCache( File directory, int appVersion, int valueCount, long maxSize) {
|
||||||
|
this.directory = directory;
|
||||||
|
this.appVersion = appVersion;
|
||||||
|
this.journalFile = new File(directory, JOURNAL_FILE);
|
||||||
|
this.journalFileTmp = new File(directory, JOURNAL_FILE_TEMP);
|
||||||
|
this.journalFileBackup = new File(directory, JOURNAL_FILE_BACKUP);
|
||||||
|
this.valueCount = valueCount;
|
||||||
|
this.maxSize = maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the cache in {@code directory}, creating a cache if none exists
|
||||||
|
* there.
|
||||||
|
*
|
||||||
|
* @param directory a writable directory
|
||||||
|
* @param valueCount the number of values per cache entry. Must be positive.
|
||||||
|
* @param maxSize the maximum number of bytes this cache should use to store
|
||||||
|
* @throws IOException if reading or writing the cache directory fails
|
||||||
|
*/
|
||||||
|
public static DiskLruCache open( File directory, int appVersion, int valueCount, long maxSize)
|
||||||
|
throws IOException {
|
||||||
|
if (maxSize <= 0) {
|
||||||
|
throw new IllegalArgumentException("maxSize <= 0");
|
||||||
|
}
|
||||||
|
if (valueCount <= 0) {
|
||||||
|
throw new IllegalArgumentException("valueCount <= 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a bkp file exists, use it instead.
|
||||||
|
File backupFile = new File(directory, JOURNAL_FILE_BACKUP);
|
||||||
|
if (backupFile.exists()) {
|
||||||
|
File journalFile = new File(directory, JOURNAL_FILE);
|
||||||
|
// If journal file also exists just delete backup file.
|
||||||
|
if (journalFile.exists()) {
|
||||||
|
backupFile.delete();
|
||||||
|
} else {
|
||||||
|
renameTo(backupFile, journalFile, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer to pick up where we left off.
|
||||||
|
DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
|
||||||
|
if (cache.journalFile.exists()) {
|
||||||
|
try {
|
||||||
|
cache.readJournal();
|
||||||
|
cache.processJournal();
|
||||||
|
return cache;
|
||||||
|
} catch ( IOException journalIsCorrupt) {
|
||||||
|
System.out
|
||||||
|
.println("DiskLruCache "
|
||||||
|
+ directory
|
||||||
|
+ " is corrupt: "
|
||||||
|
+ journalIsCorrupt.getMessage()
|
||||||
|
+ ", removing");
|
||||||
|
cache.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new empty cache.
|
||||||
|
directory.mkdirs();
|
||||||
|
cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
|
||||||
|
cache.rebuildJournal();
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readJournal() throws IOException {
|
||||||
|
StrictLineReader reader = new StrictLineReader(new FileInputStream(journalFile), CacheUtil.US_ASCII);
|
||||||
|
try {
|
||||||
|
String magic = reader.readLine();
|
||||||
|
String version = reader.readLine();
|
||||||
|
String appVersionString = reader.readLine();
|
||||||
|
String valueCountString = reader.readLine();
|
||||||
|
String blank = reader.readLine();
|
||||||
|
if (!MAGIC.equals(magic)
|
||||||
|
|| !VERSION_1.equals(version)
|
||||||
|
|| !Integer.toString(appVersion).equals(appVersionString)
|
||||||
|
|| !Integer.toString(valueCount).equals(valueCountString)
|
||||||
|
|| !"".equals(blank)) {
|
||||||
|
throw new IOException("unexpected journal header: [" + magic + ", " + version + ", "
|
||||||
|
+ valueCountString + ", " + blank + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineCount = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
readJournalLine(reader.readLine());
|
||||||
|
lineCount++;
|
||||||
|
} catch ( EOFException endOfJournal) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
redundantOpCount = lineCount - lruEntries.size();
|
||||||
|
|
||||||
|
// If we ended on a truncated line, rebuild the journal before appending to it.
|
||||||
|
if (reader.hasUnterminatedLine()) {
|
||||||
|
rebuildJournal();
|
||||||
|
} else {
|
||||||
|
journalWriter = new BufferedWriter(new OutputStreamWriter(
|
||||||
|
new FileOutputStream(journalFile, true), CacheUtil.US_ASCII));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
CacheUtil.closeQuietly(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readJournalLine( String line) throws IOException {
|
||||||
|
int firstSpace = line.indexOf(' ');
|
||||||
|
if (firstSpace == -1) {
|
||||||
|
throw new IOException("unexpected journal line: " + line);
|
||||||
|
}
|
||||||
|
|
||||||
|
int keyBegin = firstSpace + 1;
|
||||||
|
int secondSpace = line.indexOf(' ', keyBegin);
|
||||||
|
final String key;
|
||||||
|
if (secondSpace == -1) {
|
||||||
|
key = line.substring(keyBegin);
|
||||||
|
if (firstSpace == REMOVE.length() && line.startsWith(REMOVE)) {
|
||||||
|
lruEntries.remove(key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
key = line.substring(keyBegin, secondSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry entry = lruEntries.get(key);
|
||||||
|
if (entry == null) {
|
||||||
|
entry = new Entry(key);
|
||||||
|
lruEntries.put(key, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secondSpace != -1 && firstSpace == CLEAN.length() && line.startsWith(CLEAN)) {
|
||||||
|
String[] parts = line.substring(secondSpace + 1).split(" ");
|
||||||
|
entry.readable = true;
|
||||||
|
entry.currentEditor = null;
|
||||||
|
entry.setLengths(parts);
|
||||||
|
} else if (secondSpace == -1 && firstSpace == DIRTY.length() && line.startsWith(DIRTY)) {
|
||||||
|
entry.currentEditor = new Editor(entry);
|
||||||
|
} else if (secondSpace == -1 && firstSpace == READ.length() && line.startsWith(READ)) {
|
||||||
|
// This work was already done by calling lruEntries.get().
|
||||||
|
} else {
|
||||||
|
throw new IOException("unexpected journal line: " + line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the initial size and collects garbage as a part of opening the
|
||||||
|
* cache. Dirty entries are assumed to be inconsistent and will be deleted.
|
||||||
|
*/
|
||||||
|
private void processJournal() throws IOException {
|
||||||
|
deleteIfExists(journalFileTmp);
|
||||||
|
for ( Iterator<Entry> i = lruEntries.values().iterator(); i.hasNext(); ) {
|
||||||
|
Entry entry = i.next();
|
||||||
|
if (entry.currentEditor == null) {
|
||||||
|
for (int t = 0; t < valueCount; t++) {
|
||||||
|
size += entry.lengths[t];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
entry.currentEditor = null;
|
||||||
|
for (int t = 0; t < valueCount; t++) {
|
||||||
|
deleteIfExists(entry.getCleanFile(t));
|
||||||
|
deleteIfExists(entry.getDirtyFile(t));
|
||||||
|
}
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new journal that omits redundant information. This replaces the
|
||||||
|
* current journal if it exists.
|
||||||
|
*/
|
||||||
|
private synchronized void rebuildJournal() throws IOException {
|
||||||
|
if (journalWriter != null) {
|
||||||
|
journalWriter.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Writer writer = new BufferedWriter(
|
||||||
|
new OutputStreamWriter(new FileOutputStream(journalFileTmp), CacheUtil.US_ASCII));
|
||||||
|
try {
|
||||||
|
writer.write(MAGIC);
|
||||||
|
writer.write("\n");
|
||||||
|
writer.write(VERSION_1);
|
||||||
|
writer.write("\n");
|
||||||
|
writer.write( Integer.toString(appVersion));
|
||||||
|
writer.write("\n");
|
||||||
|
writer.write( Integer.toString(valueCount));
|
||||||
|
writer.write("\n");
|
||||||
|
writer.write("\n");
|
||||||
|
|
||||||
|
for (Entry entry : lruEntries.values()) {
|
||||||
|
if (entry.currentEditor != null) {
|
||||||
|
writer.write(DIRTY + ' ' + entry.key + '\n');
|
||||||
|
} else {
|
||||||
|
writer.write(CLEAN + ' ' + entry.key + entry.getLengths() + '\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (journalFile.exists()) {
|
||||||
|
renameTo(journalFile, journalFileBackup, true);
|
||||||
|
}
|
||||||
|
renameTo(journalFileTmp, journalFile, false);
|
||||||
|
journalFileBackup.delete();
|
||||||
|
|
||||||
|
journalWriter = new BufferedWriter(
|
||||||
|
new OutputStreamWriter(new FileOutputStream(journalFile, true), CacheUtil.US_ASCII));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deleteIfExists( File file) throws IOException {
|
||||||
|
if (file.exists() && !file.delete()) {
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renameTo( File from, File to, boolean deleteDestination) throws IOException {
|
||||||
|
if (deleteDestination) {
|
||||||
|
deleteIfExists(to);
|
||||||
|
}
|
||||||
|
if (!from.renameTo(to)) {
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a snapshot of the entry named {@code key}, or null if it doesn't
|
||||||
|
* exist is not currently readable. If a value is returned, it is moved to
|
||||||
|
* the head of the LRU queue.
|
||||||
|
*/
|
||||||
|
public synchronized Snapshot get( String key) throws IOException {
|
||||||
|
checkNotClosed();
|
||||||
|
validateKey(key);
|
||||||
|
Entry entry = lruEntries.get(key);
|
||||||
|
if (entry == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entry.readable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open all streams eagerly to guarantee that we see a single published
|
||||||
|
// snapshot. If we opened streams lazily then the streams could come
|
||||||
|
// from different edits.
|
||||||
|
InputStream[] ins = new InputStream[valueCount];
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < valueCount; i++) {
|
||||||
|
ins[i] = new FileInputStream(entry.getCleanFile(i));
|
||||||
|
}
|
||||||
|
} catch ( FileNotFoundException e) {
|
||||||
|
// A file must have been deleted manually!
|
||||||
|
for (int i = 0; i < valueCount; i++) {
|
||||||
|
if (ins[i] != null) {
|
||||||
|
CacheUtil.closeQuietly(ins[i]);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
redundantOpCount++;
|
||||||
|
journalWriter.append(READ + ' ' + key + '\n');
|
||||||
|
if (journalRebuildRequired()) {
|
||||||
|
executorService.submit(cleanupCallable);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Snapshot(key, entry.sequenceNumber, ins, entry.lengths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an editor for the entry named {@code key}, or null if another
|
||||||
|
* edit is in progress.
|
||||||
|
*/
|
||||||
|
public Editor edit( String key) throws IOException {
|
||||||
|
return edit(key, ANY_SEQUENCE_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized Editor edit( String key, long expectedSequenceNumber) throws IOException {
|
||||||
|
checkNotClosed();
|
||||||
|
validateKey(key);
|
||||||
|
Entry entry = lruEntries.get(key);
|
||||||
|
if (expectedSequenceNumber != ANY_SEQUENCE_NUMBER && (entry == null
|
||||||
|
|| entry.sequenceNumber != expectedSequenceNumber)) {
|
||||||
|
return null; // Snapshot is stale.
|
||||||
|
}
|
||||||
|
if (entry == null) {
|
||||||
|
entry = new Entry(key);
|
||||||
|
lruEntries.put(key, entry);
|
||||||
|
} else if (entry.currentEditor != null) {
|
||||||
|
return null; // Another edit is in progress.
|
||||||
|
}
|
||||||
|
|
||||||
|
Editor editor = new Editor(entry);
|
||||||
|
entry.currentEditor = editor;
|
||||||
|
|
||||||
|
// Flush the journal before creating files to prevent file leaks.
|
||||||
|
journalWriter.write(DIRTY + ' ' + key + '\n');
|
||||||
|
journalWriter.flush();
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the directory where this cache stores its data. */
|
||||||
|
public File getDirectory() {
|
||||||
|
return directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the maximum number of bytes that this cache should use to store
|
||||||
|
* its data.
|
||||||
|
*/
|
||||||
|
public synchronized long getMaxSize() {
|
||||||
|
return maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the maximum number of bytes the cache can store and queues a job
|
||||||
|
* to trim the existing store, if necessary.
|
||||||
|
*/
|
||||||
|
public synchronized void setMaxSize(long maxSize) {
|
||||||
|
this.maxSize = maxSize;
|
||||||
|
executorService.submit(cleanupCallable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of bytes currently being used to store the values in
|
||||||
|
* this cache. This may be greater than the max size if a background
|
||||||
|
* deletion is pending.
|
||||||
|
*/
|
||||||
|
public synchronized long size() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void completeEdit(Editor editor, boolean success) throws IOException {
|
||||||
|
Entry entry = editor.entry;
|
||||||
|
if (entry.currentEditor != editor) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this edit is creating the entry for the first time, every index must have a value.
|
||||||
|
if (success && !entry.readable) {
|
||||||
|
for (int i = 0; i < valueCount; i++) {
|
||||||
|
if (!editor.written[i]) {
|
||||||
|
editor.abort();
|
||||||
|
throw new IllegalStateException("Newly created entry didn't create value for index " + i);
|
||||||
|
}
|
||||||
|
if (!entry.getDirtyFile(i).exists()) {
|
||||||
|
editor.abort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < valueCount; i++) {
|
||||||
|
File dirty = entry.getDirtyFile(i);
|
||||||
|
if (success) {
|
||||||
|
if (dirty.exists()) {
|
||||||
|
File clean = entry.getCleanFile(i);
|
||||||
|
dirty.renameTo(clean);
|
||||||
|
long oldLength = entry.lengths[i];
|
||||||
|
long newLength = clean.length();
|
||||||
|
entry.lengths[i] = newLength;
|
||||||
|
size = size - oldLength + newLength;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deleteIfExists(dirty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redundantOpCount++;
|
||||||
|
entry.currentEditor = null;
|
||||||
|
if (entry.readable | success) {
|
||||||
|
entry.readable = true;
|
||||||
|
journalWriter.write(CLEAN + ' ' + entry.key + entry.getLengths() + '\n');
|
||||||
|
if (success) {
|
||||||
|
entry.sequenceNumber = nextSequenceNumber++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lruEntries.remove(entry.key);
|
||||||
|
journalWriter.write(REMOVE + ' ' + entry.key + '\n');
|
||||||
|
}
|
||||||
|
journalWriter.flush();
|
||||||
|
|
||||||
|
if (size > maxSize || journalRebuildRequired()) {
|
||||||
|
executorService.submit(cleanupCallable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We only rebuild the journal when it will halve the size of the journal
|
||||||
|
* and eliminate at least 2000 ops.
|
||||||
|
*/
|
||||||
|
private boolean journalRebuildRequired() {
|
||||||
|
final int redundantOpCompactThreshold = 2000;
|
||||||
|
return redundantOpCount >= redundantOpCompactThreshold //
|
||||||
|
&& redundantOpCount >= lruEntries.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drops the entry for {@code key} if it exists and can be removed. Entries
|
||||||
|
* actively being edited cannot be removed.
|
||||||
|
*
|
||||||
|
* @return true if an entry was removed.
|
||||||
|
*/
|
||||||
|
public synchronized boolean remove( String key) throws IOException {
|
||||||
|
checkNotClosed();
|
||||||
|
validateKey(key);
|
||||||
|
Entry entry = lruEntries.get(key);
|
||||||
|
if (entry == null || entry.currentEditor != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < valueCount; i++) {
|
||||||
|
File file = entry.getCleanFile(i);
|
||||||
|
if (file.exists() && !file.delete()) {
|
||||||
|
throw new IOException("failed to delete " + file);
|
||||||
|
}
|
||||||
|
size -= entry.lengths[i];
|
||||||
|
entry.lengths[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
redundantOpCount++;
|
||||||
|
journalWriter.append(REMOVE + ' ' + key + '\n');
|
||||||
|
lruEntries.remove(key);
|
||||||
|
|
||||||
|
if (journalRebuildRequired()) {
|
||||||
|
executorService.submit(cleanupCallable);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if this cache has been closed. */
|
||||||
|
public synchronized boolean isClosed() {
|
||||||
|
return journalWriter == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkNotClosed() {
|
||||||
|
if (journalWriter == null) {
|
||||||
|
throw new IllegalStateException("cache is closed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Force buffered operations to the filesystem. */
|
||||||
|
public synchronized void flush() throws IOException {
|
||||||
|
checkNotClosed();
|
||||||
|
trimToSize();
|
||||||
|
journalWriter.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Closes this cache. Stored values will remain on the filesystem. */
|
||||||
|
public synchronized void close() throws IOException {
|
||||||
|
if (journalWriter == null) {
|
||||||
|
return; // Already closed.
|
||||||
|
}
|
||||||
|
for (Entry entry : new ArrayList<Entry>(lruEntries.values())) {
|
||||||
|
if (entry.currentEditor != null) {
|
||||||
|
entry.currentEditor.abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trimToSize();
|
||||||
|
journalWriter.close();
|
||||||
|
journalWriter = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void trimToSize() throws IOException {
|
||||||
|
while (size > maxSize) {
|
||||||
|
Map.Entry< String, Entry> toEvict = lruEntries.entrySet().iterator().next();
|
||||||
|
remove(toEvict.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the cache and deletes all of its stored values. This will delete
|
||||||
|
* all files in the cache directory including files that weren't created by
|
||||||
|
* the cache.
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
close();
|
||||||
|
CacheUtil.deleteContents(directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateKey( String key) {
|
||||||
|
Matcher matcher = LEGAL_KEY_PATTERN.matcher(key);
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
throw new IllegalArgumentException("keys must match regex "
|
||||||
|
+ STRING_KEY_PATTERN + ": \"" + key + "\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String inputStreamToString( InputStream in) throws IOException {
|
||||||
|
return CacheUtil.readFully(new InputStreamReader(in, CacheUtil.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A snapshot of the values for an entry. */
|
||||||
|
public final class Snapshot implements Closeable {
|
||||||
|
private final String key;
|
||||||
|
private final long sequenceNumber;
|
||||||
|
private final InputStream[] ins;
|
||||||
|
private final long[] lengths;
|
||||||
|
|
||||||
|
private Snapshot( String key, long sequenceNumber, InputStream[] ins, long[] lengths) {
|
||||||
|
this.key = key;
|
||||||
|
this.sequenceNumber = sequenceNumber;
|
||||||
|
this.ins = ins;
|
||||||
|
this.lengths = lengths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an editor for this snapshot's entry, or null if either the
|
||||||
|
* entry has changed since this snapshot was created or if another edit
|
||||||
|
* is in progress.
|
||||||
|
*/
|
||||||
|
public Editor edit() throws IOException {
|
||||||
|
return DiskLruCache.this.edit(key, sequenceNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the unbuffered stream with the value for {@code index}. */
|
||||||
|
public InputStream getInputStream( int index) {
|
||||||
|
return ins[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the string value for {@code index}. */
|
||||||
|
public String getString( int index) throws IOException {
|
||||||
|
return inputStreamToString(getInputStream(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the byte length of the value for {@code index}. */
|
||||||
|
public long getLength(int index) {
|
||||||
|
return lengths[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
for ( InputStream in : ins) {
|
||||||
|
CacheUtil.closeQuietly(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final OutputStream NULL_OUTPUT_STREAM = new OutputStream() {
|
||||||
|
@Override
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
// Eat all writes silently. Nom nom.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Edits the values for an entry. */
|
||||||
|
public final class Editor {
|
||||||
|
private final Entry entry;
|
||||||
|
private final boolean[] written;
|
||||||
|
private boolean hasErrors;
|
||||||
|
private boolean committed;
|
||||||
|
|
||||||
|
private Editor(Entry entry) {
|
||||||
|
this.entry = entry;
|
||||||
|
this.written = (entry.readable) ? null : new boolean[valueCount];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an unbuffered input stream to read the last committed value,
|
||||||
|
* or null if no value has been committed.
|
||||||
|
*/
|
||||||
|
public InputStream newInputStream( int index) throws IOException {
|
||||||
|
synchronized (DiskLruCache.this) {
|
||||||
|
if (entry.currentEditor != this) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
if (!entry.readable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new FileInputStream(entry.getCleanFile(index));
|
||||||
|
} catch ( FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last committed value as a string, or null if no value
|
||||||
|
* has been committed.
|
||||||
|
*/
|
||||||
|
public String getString( int index) throws IOException {
|
||||||
|
InputStream in = newInputStream(index);
|
||||||
|
return in != null ? inputStreamToString(in) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new unbuffered output stream to write the value at
|
||||||
|
* {@code index}. If the underlying output stream encounters errors
|
||||||
|
* when writing to the filesystem, this edit will be aborted when
|
||||||
|
* {@link #commit} is called. The returned output stream does not throw
|
||||||
|
* IOExceptions.
|
||||||
|
*/
|
||||||
|
public OutputStream newOutputStream( int index) throws IOException {
|
||||||
|
if (index < 0 || index >= valueCount) {
|
||||||
|
throw new IllegalArgumentException("Expected index " + index + " to "
|
||||||
|
+ "be greater than 0 and less than the maximum value count "
|
||||||
|
+ "of " + valueCount);
|
||||||
|
}
|
||||||
|
synchronized (DiskLruCache.this) {
|
||||||
|
if (entry.currentEditor != this) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
if (!entry.readable) {
|
||||||
|
written[index] = true;
|
||||||
|
}
|
||||||
|
File dirtyFile = entry.getDirtyFile(index);
|
||||||
|
FileOutputStream outputStream;
|
||||||
|
try {
|
||||||
|
outputStream = new FileOutputStream(dirtyFile);
|
||||||
|
} catch ( FileNotFoundException e) {
|
||||||
|
// Attempt to recreate the cache directory.
|
||||||
|
directory.mkdirs();
|
||||||
|
try {
|
||||||
|
outputStream = new FileOutputStream(dirtyFile);
|
||||||
|
} catch ( FileNotFoundException e2) {
|
||||||
|
// We are unable to recover. Silently eat the writes.
|
||||||
|
return NULL_OUTPUT_STREAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new FaultHidingOutputStream(outputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the value at {@code index} to {@code value}. */
|
||||||
|
public void set(int index, String value) throws IOException {
|
||||||
|
Writer writer = null;
|
||||||
|
try {
|
||||||
|
writer = new OutputStreamWriter(newOutputStream(index), CacheUtil.UTF_8);
|
||||||
|
writer.write(value);
|
||||||
|
} finally {
|
||||||
|
CacheUtil.closeQuietly(writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commits this edit so it is visible to readers. This releases the
|
||||||
|
* edit lock so another edit may be started on the same key.
|
||||||
|
*/
|
||||||
|
public void commit() throws IOException {
|
||||||
|
if (hasErrors) {
|
||||||
|
completeEdit(this, false);
|
||||||
|
remove(entry.key); // The previous entry is stale.
|
||||||
|
} else {
|
||||||
|
completeEdit(this, true);
|
||||||
|
}
|
||||||
|
committed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aborts this edit. This releases the edit lock so another edit may be
|
||||||
|
* started on the same key.
|
||||||
|
*/
|
||||||
|
public void abort() throws IOException {
|
||||||
|
completeEdit(this, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abortUnlessCommitted() {
|
||||||
|
if (!committed) {
|
||||||
|
try {
|
||||||
|
abort();
|
||||||
|
} catch ( IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class FaultHidingOutputStream extends FilterOutputStream {
|
||||||
|
private FaultHidingOutputStream( OutputStream out) {
|
||||||
|
super(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write( int oneByte) {
|
||||||
|
try {
|
||||||
|
out.write(oneByte);
|
||||||
|
} catch ( IOException e) {
|
||||||
|
hasErrors = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write( byte[] buffer, int offset, int length) {
|
||||||
|
try {
|
||||||
|
out.write(buffer, offset, length);
|
||||||
|
} catch ( IOException e) {
|
||||||
|
hasErrors = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
hasErrors = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
try {
|
||||||
|
out.flush();
|
||||||
|
} catch ( IOException e) {
|
||||||
|
hasErrors = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class Entry {
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
/** Lengths of this entry's files. */
|
||||||
|
private final long[] lengths;
|
||||||
|
|
||||||
|
/** True if this entry has ever been published. */
|
||||||
|
private boolean readable;
|
||||||
|
|
||||||
|
/** The ongoing edit or null if this entry is not being edited. */
|
||||||
|
private Editor currentEditor;
|
||||||
|
|
||||||
|
/** The sequence number of the most recently committed edit to this entry. */
|
||||||
|
private long sequenceNumber;
|
||||||
|
|
||||||
|
private Entry( String key) {
|
||||||
|
this.key = key;
|
||||||
|
this.lengths = new long[valueCount];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLengths() throws IOException {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (long size : lengths) {
|
||||||
|
result.append(' ').append(size);
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set lengths using decimal numbers like "10123". */
|
||||||
|
private void setLengths( String[] strings) throws IOException {
|
||||||
|
if (strings.length != valueCount) {
|
||||||
|
throw invalidLengths(strings);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < strings.length; i++) {
|
||||||
|
lengths[i] = Long.parseLong(strings[i]);
|
||||||
|
}
|
||||||
|
} catch ( NumberFormatException e) {
|
||||||
|
throw invalidLengths(strings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IOException invalidLengths( String[] strings) throws IOException {
|
||||||
|
throw new IOException("unexpected journal line: " + java.util.Arrays.toString(strings));
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getCleanFile( int i) {
|
||||||
|
return new File(directory, key + "." + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getDirtyFile( int i) {
|
||||||
|
return new File(directory, key + "." + i + ".tmp");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.mogo.utils.storage.lrucache;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
public class SecretUtil {
|
||||||
|
|
||||||
|
public static String getMD5Result( String value) {
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
md.update(value.getBytes("UTF-8"));
|
||||||
|
byte[] result = md.digest();
|
||||||
|
return getString(result);
|
||||||
|
} catch ( NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
|
} catch ( UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getString( byte[] result) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte b : result) {
|
||||||
|
int i = b & 0xff;
|
||||||
|
if (i <= 0xf) {
|
||||||
|
sb.append(0);
|
||||||
|
}
|
||||||
|
sb.append( Integer.toHexString(i));
|
||||||
|
}
|
||||||
|
return sb.toString().toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.mogo.utils.storage.lrucache;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buffers input from an {@link InputStream} for reading lines.
|
||||||
|
*
|
||||||
|
* <p>This class is used for buffered reading of lines. For purposes of this class, a line ends
|
||||||
|
* with "\n" or "\r\n". End of input is reported by throwing {@code EOFException}. Unterminated
|
||||||
|
* line at end of input is invalid and will be ignored, the caller may use {@code
|
||||||
|
* hasUnterminatedLine()} to detect it after catching the {@code EOFException}.
|
||||||
|
*
|
||||||
|
* <p>This class is intended for reading input that strictly consists of lines, such as line-based
|
||||||
|
* cache entries or cache journal. Unlike the {@link java.io.BufferedReader} which in conjunction
|
||||||
|
* with {@link java.io.InputStreamReader} provides similar functionality, this class uses different
|
||||||
|
* end-of-input reporting and a more restrictive definition of a line.
|
||||||
|
*
|
||||||
|
* <p>This class supports only charsets that encode '\r' and '\n' as a single byte with value 13
|
||||||
|
* and 10, respectively, and the representation of no other character contains these values.
|
||||||
|
* We currently check in constructor that the charset is one of US-ASCII, UTF-8 and ISO-8859-1.
|
||||||
|
* The default charset is US_ASCII.
|
||||||
|
*/
|
||||||
|
class StrictLineReader implements Closeable {
|
||||||
|
private static final byte CR = (byte) '\r';
|
||||||
|
private static final byte LF = (byte) '\n';
|
||||||
|
|
||||||
|
private final InputStream in;
|
||||||
|
private final Charset charset;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Buffered data is stored in {@code buf}. As long as no exception occurs, 0 <= pos <= end
|
||||||
|
* and the data in the range [pos, end) is buffered for reading. At end of input, if there is
|
||||||
|
* an unterminated line, we set end == -1, otherwise end == pos. If the underlying
|
||||||
|
* {@code InputStream} throws an {@code IOException}, end may remain as either pos or -1.
|
||||||
|
*/
|
||||||
|
private byte[] buf;
|
||||||
|
private int pos;
|
||||||
|
private int end;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new {@code LineReader} with the specified charset and the default capacity.
|
||||||
|
*
|
||||||
|
* @param in the {@code InputStream} to read data from.
|
||||||
|
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
|
||||||
|
* supported.
|
||||||
|
* @throws NullPointerException if {@code in} or {@code charset} is null.
|
||||||
|
* @throws IllegalArgumentException if the specified charset is not supported.
|
||||||
|
*/
|
||||||
|
public StrictLineReader( InputStream in, Charset charset) {
|
||||||
|
this(in, 8192, charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new {@code LineReader} with the specified capacity and charset.
|
||||||
|
*
|
||||||
|
* @param in the {@code InputStream} to read data from.
|
||||||
|
* @param capacity the capacity of the buffer.
|
||||||
|
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
|
||||||
|
* supported.
|
||||||
|
* @throws NullPointerException if {@code in} or {@code charset} is null.
|
||||||
|
* @throws IllegalArgumentException if {@code capacity} is negative or zero
|
||||||
|
* or the specified charset is not supported.
|
||||||
|
*/
|
||||||
|
public StrictLineReader( InputStream in, int capacity, Charset charset) {
|
||||||
|
if (in == null || charset == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
if (capacity < 0) {
|
||||||
|
throw new IllegalArgumentException("capacity <= 0");
|
||||||
|
}
|
||||||
|
if (!(charset.equals(CacheUtil.US_ASCII))) {
|
||||||
|
throw new IllegalArgumentException("Unsupported encoding");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.in = in;
|
||||||
|
this.charset = charset;
|
||||||
|
buf = new byte[capacity];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the reader by closing the underlying {@code InputStream} and
|
||||||
|
* marking this reader as closed.
|
||||||
|
*
|
||||||
|
* @throws IOException for errors when closing the underlying {@code InputStream}.
|
||||||
|
*/
|
||||||
|
public void close() throws IOException {
|
||||||
|
synchronized (in) {
|
||||||
|
if (buf != null) {
|
||||||
|
buf = null;
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the next line. A line ends with {@code "\n"} or {@code "\r\n"},
|
||||||
|
* this end of line marker is not included in the result.
|
||||||
|
*
|
||||||
|
* @return the next line from the input.
|
||||||
|
* @throws IOException for underlying {@code InputStream} errors.
|
||||||
|
* @throws EOFException for the end of source stream.
|
||||||
|
*/
|
||||||
|
public String readLine() throws IOException {
|
||||||
|
synchronized (in) {
|
||||||
|
if (buf == null) {
|
||||||
|
throw new IOException("LineReader is closed");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read more data if we are at the end of the buffered labelList.
|
||||||
|
// Though it's an error to read after an exception, we will let {@code fillBuf()}
|
||||||
|
// throw again if that happens; thus we need to handle end == -1 as well as end == pos.
|
||||||
|
if (pos >= end) {
|
||||||
|
fillBuf();
|
||||||
|
}
|
||||||
|
// Try to find LF in the buffered data and return the line if successful.
|
||||||
|
for (int i = pos; i != end; ++i) {
|
||||||
|
if (buf[i] == LF) {
|
||||||
|
int lineEnd = (i != pos && buf[i - 1] == CR) ? i - 1 : i;
|
||||||
|
String res = new String(buf, pos, lineEnd - pos, charset.name());
|
||||||
|
pos = i + 1;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let's anticipate up to 80 characters on top of those already read.
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream(end - pos + 80) {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
int length = (count > 0 && buf[count - 1] == CR) ? count - 1 : count;
|
||||||
|
try {
|
||||||
|
return new String(buf, 0, length, charset.name());
|
||||||
|
} catch ( UnsupportedEncodingException e) {
|
||||||
|
throw new AssertionError(e); // Since we control the charset this will never happen.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
out.write(buf, pos, end - pos);
|
||||||
|
// Mark unterminated line in case fillBuf throws EOFException or IOException.
|
||||||
|
end = -1;
|
||||||
|
fillBuf();
|
||||||
|
// Try to find LF in the buffered data and return the line if successful.
|
||||||
|
for (int i = pos; i != end; ++i) {
|
||||||
|
if (buf[i] == LF) {
|
||||||
|
if (i != pos) {
|
||||||
|
out.write(buf, pos, i - pos);
|
||||||
|
}
|
||||||
|
pos = i + 1;
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasUnterminatedLine() {
|
||||||
|
return end == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads new input data into the buffer. Call only with pos == end or end == -1,
|
||||||
|
* depending on the desired outcome if the function throws.
|
||||||
|
*/
|
||||||
|
private void fillBuf() throws IOException {
|
||||||
|
int result = in.read(buf, 0, buf.length);
|
||||||
|
if (result == -1) {
|
||||||
|
throw new EOFException();
|
||||||
|
}
|
||||||
|
pos = 0;
|
||||||
|
end = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BIN
keystore/car_launcher.jks
Normal file
BIN
keystore/car_launcher.jks
Normal file
Binary file not shown.
@@ -21,7 +21,6 @@ android {
|
|||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -41,7 +42,7 @@ public abstract class MogoBaseMapView extends FrameLayout implements ILifeCycle
|
|||||||
if ( mMapView != null ) {
|
if ( mMapView != null ) {
|
||||||
final View mapView = mMapView.getMapView();
|
final View mapView = mMapView.getMapView();
|
||||||
if ( mapView != null ) {
|
if ( mapView != null ) {
|
||||||
addView( mapView );
|
addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) );
|
||||||
MogoMap.getInstance().init( context, getMap() );
|
MogoMap.getInstance().init( context, getMap() );
|
||||||
} else {
|
} else {
|
||||||
Logger.e( TAG, "create MapView instance failed." );
|
Logger.e( TAG, "create MapView instance failed." );
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.mogo.map.amap;
|
||||||
|
|
||||||
|
import com.amap.api.maps.model.Marker;
|
||||||
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
|
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* marker 点击事件处理
|
||||||
|
*/
|
||||||
|
public class AMapMarkerClickHandler {
|
||||||
|
|
||||||
|
public boolean handleMarkerClicked( Marker marker ) {
|
||||||
|
if ( marker == null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( marker.getObject() instanceof IMogoMarker ) {
|
||||||
|
final IMogoMarkerClickListener listener = ( ( IMogoMarker ) marker.getObject() ).getOnMarkerClickListener();
|
||||||
|
if ( listener != null ) {
|
||||||
|
return listener.onMarkerClicked( ( ( IMogoMarker ) marker.getObject() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
package com.mogo.map.amap;
|
package com.mogo.map.amap;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.amap.api.maps.AMap;
|
||||||
|
import com.amap.api.maps.model.Marker;
|
||||||
|
import com.amap.api.maps.model.Poi;
|
||||||
import com.amap.api.navi.AMapNaviView;
|
import com.amap.api.navi.AMapNaviView;
|
||||||
import com.mogo.map.IMogoMap;
|
import com.mogo.map.IMogoMap;
|
||||||
import com.mogo.map.IMogoMapView;
|
import com.mogo.map.IMogoMapView;
|
||||||
|
import com.mogo.map.amap.utils.ObjectUtils;
|
||||||
|
import com.mogo.map.listener.MogoMapListenerHandler;
|
||||||
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
|
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author congtaowang
|
* @author congtaowang
|
||||||
@@ -13,13 +21,26 @@ import com.mogo.map.IMogoMapView;
|
|||||||
* <p>
|
* <p>
|
||||||
* 代理高德导航地图
|
* 代理高德导航地图
|
||||||
*/
|
*/
|
||||||
public class AMapNaviViewWrapper implements IMogoMapView {
|
public class AMapNaviViewWrapper implements IMogoMapView,
|
||||||
|
AMap.OnMarkerClickListener,
|
||||||
|
AMap.OnMapLoadedListener,
|
||||||
|
AMap.OnMapTouchListener,
|
||||||
|
AMap.OnPOIClickListener {
|
||||||
|
|
||||||
private final AMapNaviView mMapView;
|
private final AMapNaviView mMapView;
|
||||||
private IMogoMap mIMap;
|
private IMogoMap mIMap;
|
||||||
|
|
||||||
|
private AMapMarkerClickHandler mMarkerClickHandler;
|
||||||
|
|
||||||
public AMapNaviViewWrapper( AMapNaviView mapView ) {
|
public AMapNaviViewWrapper( AMapNaviView mapView ) {
|
||||||
this.mMapView = mapView;
|
this.mMapView = mapView;
|
||||||
|
mMapView.setOnMarkerClickListener( this );
|
||||||
|
mMarkerClickHandler = new AMapMarkerClickHandler();
|
||||||
|
mMapView.setOnMapLoadedListener( this );
|
||||||
|
mMapView.setOnMapTouchListener( this );
|
||||||
|
if ( mMapView.getMap() != null ) {
|
||||||
|
mMapView.getMap().setOnPOIClickListener( this );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,4 +96,44 @@ public class AMapNaviViewWrapper implements IMogoMapView {
|
|||||||
@Override
|
@Override
|
||||||
public void onLowMemory() {
|
public void onLowMemory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地图marker点击
|
||||||
|
*
|
||||||
|
* @param marker
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onMarkerClick( Marker marker ) {
|
||||||
|
return mMarkerClickHandler.handleMarkerClicked( marker );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地图加载完毕
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onMapLoaded() {
|
||||||
|
MogoMapListenerHandler.getInstance().onMapLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地图点击回调
|
||||||
|
*
|
||||||
|
* @param motionEvent
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onTouch( MotionEvent motionEvent ) {
|
||||||
|
MogoMapListenerHandler.getInstance().onTouch( motionEvent );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POI 点击
|
||||||
|
*
|
||||||
|
* @param poi
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onPOIClick( Poi poi ) {
|
||||||
|
MogoMapListenerHandler.getInstance().onPOIClick( ObjectUtils.fromAMap( poi ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package com.mogo.map.amap;
|
|||||||
import com.amap.api.maps.AMap;
|
import com.amap.api.maps.AMap;
|
||||||
import com.amap.api.maps.model.Marker;
|
import com.amap.api.maps.model.Marker;
|
||||||
import com.amap.api.maps.model.MarkerOptions;
|
import com.amap.api.maps.model.MarkerOptions;
|
||||||
|
import com.amap.api.maps.model.Poi;
|
||||||
import com.mogo.map.IMogoMap;
|
import com.mogo.map.IMogoMap;
|
||||||
import com.mogo.map.marker.IMogoMarker;
|
|
||||||
import com.mogo.map.IUiSettings;
|
import com.mogo.map.IUiSettings;
|
||||||
import com.mogo.map.marker.MogoMarkerOptions;
|
|
||||||
import com.mogo.map.amap.marker.AMapMarkerWrapper;
|
import com.mogo.map.amap.marker.AMapMarkerWrapper;
|
||||||
import com.mogo.map.amap.utils.ObjectUtils;
|
import com.mogo.map.amap.utils.ObjectUtils;
|
||||||
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
|
import com.mogo.map.marker.MogoMarkerOptions;
|
||||||
|
import com.mogo.utils.TipToast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import com.amap.api.maps.model.BitmapDescriptorFactory;
|
|||||||
import com.amap.api.maps.model.LatLng;
|
import com.amap.api.maps.model.LatLng;
|
||||||
import com.amap.api.maps.model.Marker;
|
import com.amap.api.maps.model.Marker;
|
||||||
import com.amap.api.maps.model.MarkerOptions;
|
import com.amap.api.maps.model.MarkerOptions;
|
||||||
|
import com.mogo.map.MogoLatLng;
|
||||||
import com.mogo.map.marker.IMogoMarker;
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
|
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||||
import com.mogo.map.marker.MogoMarkerOptions;
|
import com.mogo.map.marker.MogoMarkerOptions;
|
||||||
import com.mogo.map.amap.utils.ObjectUtils;
|
import com.mogo.map.amap.utils.ObjectUtils;
|
||||||
|
|
||||||
@@ -22,9 +24,14 @@ import java.util.ArrayList;
|
|||||||
public class AMapMarkerWrapper implements IMogoMarker {
|
public class AMapMarkerWrapper implements IMogoMarker {
|
||||||
|
|
||||||
private Marker mMarker;
|
private Marker mMarker;
|
||||||
|
private Object mObject;
|
||||||
|
private IMogoMarkerClickListener mMogoMarkerClickListener;
|
||||||
|
|
||||||
public AMapMarkerWrapper( Marker mMarker ) {
|
public AMapMarkerWrapper( Marker mMarker ) {
|
||||||
this.mMarker = mMarker;
|
this.mMarker = mMarker;
|
||||||
|
if ( mMarker != null ) {
|
||||||
|
mMarker.setObject( this );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,9 +127,12 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setObject( Object object ) {
|
public void setObject( Object object ) {
|
||||||
if ( mMarker != null ) {
|
mObject = object;
|
||||||
mMarker.setObject( object );
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public Object getObject() {
|
||||||
|
return mObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,6 +149,15 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoLatLng getPosition() {
|
||||||
|
if ( mMarker != null ) {
|
||||||
|
final LatLng latLng = mMarker.getPosition();
|
||||||
|
return ObjectUtils.fromAMap( latLng );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRotateAngle( float rotate ) {
|
public void setRotateAngle( float rotate ) {
|
||||||
if ( mMarker != null ) {
|
if ( mMarker != null ) {
|
||||||
@@ -187,4 +206,14 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
|||||||
mMarker.showInfoWindow();
|
mMarker.showInfoWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOnMarkerClickListener( IMogoMarkerClickListener listener ) {
|
||||||
|
mMogoMarkerClickListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMogoMarkerClickListener getOnMarkerClickListener() {
|
||||||
|
return mMogoMarkerClickListener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import com.amap.api.services.geocoder.RegeocodeAddress;
|
|||||||
import com.amap.api.services.geocoder.RegeocodeResult;
|
import com.amap.api.services.geocoder.RegeocodeResult;
|
||||||
import com.mogo.map.amap.utils.ObjectUtils;
|
import com.mogo.map.amap.utils.ObjectUtils;
|
||||||
import com.mogo.map.exception.MogoMapException;
|
import com.mogo.map.exception.MogoMapException;
|
||||||
import com.mogo.map.search.IMogoGeoSearch;
|
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||||
import com.mogo.map.search.IMogoGeoSearchListener;
|
import com.mogo.map.search.geo.IMogoGeoSearchListener;
|
||||||
import com.mogo.map.search.MogoGeocodeAddress;
|
import com.mogo.map.search.geo.MogoGeocodeAddress;
|
||||||
import com.mogo.map.search.MogoRegeocodeAddress;
|
import com.mogo.map.search.geo.MogoRegeocodeAddress;
|
||||||
import com.mogo.map.search.query.MogoGeocodeQuery;
|
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
|
||||||
import com.mogo.map.search.query.MogoRegeocodeQuery;
|
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import com.amap.api.services.help.InputtipsQuery;
|
|||||||
import com.amap.api.services.help.Tip;
|
import com.amap.api.services.help.Tip;
|
||||||
import com.mogo.map.amap.utils.ObjectUtils;
|
import com.mogo.map.amap.utils.ObjectUtils;
|
||||||
import com.mogo.map.exception.MogoMapException;
|
import com.mogo.map.exception.MogoMapException;
|
||||||
import com.mogo.map.search.IMogoInputtipsListener;
|
import com.mogo.map.search.inputtips.IMogoInputtipsListener;
|
||||||
import com.mogo.map.search.IMogoInputtipsSearch;
|
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||||
import com.mogo.map.search.MogoTip;
|
import com.mogo.map.search.inputtips.MogoTip;
|
||||||
import com.mogo.map.search.query.MogoInputtipsQuery;
|
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package com.mogo.map.amap.search;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.amap.api.services.core.AMapException;
|
||||||
|
import com.amap.api.services.core.PoiItem;
|
||||||
|
import com.amap.api.services.poisearch.PoiResult;
|
||||||
|
import com.amap.api.services.poisearch.PoiSearch;
|
||||||
|
import com.mogo.map.amap.utils.ObjectUtils;
|
||||||
|
import com.mogo.map.exception.MogoMapException;
|
||||||
|
import com.mogo.map.search.geo.MogoPoiItem;
|
||||||
|
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||||
|
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||||
|
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||||
|
import com.mogo.map.search.poisearch.MogoSearchBound;
|
||||||
|
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||||
|
import com.mogo.utils.logger.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* poi搜索高德实现
|
||||||
|
* <p>
|
||||||
|
* 错误码对照表:https://lbs.amap.com/api/android-sdk/guide/map-tools/error-code
|
||||||
|
*/
|
||||||
|
public class PoiSearchClient implements IMogoPoiSearch, PoiSearch.OnPoiSearchListener {
|
||||||
|
|
||||||
|
private static final String TAG = "PoiSearchClient";
|
||||||
|
|
||||||
|
private MogoPoiSearchQuery mQuery;
|
||||||
|
private PoiSearch mClient;
|
||||||
|
private IMogoPoiSearchListener mListener;
|
||||||
|
private MogoSearchBound mBound;
|
||||||
|
|
||||||
|
public PoiSearchClient( Context context, MogoPoiSearchQuery query ) {
|
||||||
|
mQuery = query;
|
||||||
|
mClient = new PoiSearch( context, ObjectUtils.fromMogo( mQuery ) );
|
||||||
|
mClient.setOnPoiSearchListener( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPoiSearchListener( IMogoPoiSearchListener listener ) {
|
||||||
|
mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void searchPOIAsyn() {
|
||||||
|
if ( mClient != null ) {
|
||||||
|
mClient.searchPOIAsyn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoPoiResult searchPOI() throws MogoMapException {
|
||||||
|
if ( mClient != null ) {
|
||||||
|
try {
|
||||||
|
PoiResult search = mClient.searchPOI();
|
||||||
|
return ObjectUtils.fromAMap( search );
|
||||||
|
} catch ( AMapException e ) {
|
||||||
|
throw new MogoMapException( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setQuery( MogoPoiSearchQuery query ) {
|
||||||
|
mQuery = query;
|
||||||
|
if ( mClient != null ) {
|
||||||
|
mClient.setQuery( ObjectUtils.fromMogo( mQuery ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoPoiItem searchPOIId( String poiId ) throws MogoMapException {
|
||||||
|
if ( mClient != null ) {
|
||||||
|
try {
|
||||||
|
PoiItem poiItem = mClient.searchPOIId( poiId );
|
||||||
|
return ObjectUtils.fromAMap( poiItem );
|
||||||
|
} catch ( AMapException e ) {
|
||||||
|
throw new MogoMapException( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void searchPOIIdAsyn( String poiId ) {
|
||||||
|
if ( mClient != null ) {
|
||||||
|
mClient.searchPOIIdAsyn( poiId );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBound( MogoSearchBound bound ) {
|
||||||
|
mBound = bound;
|
||||||
|
if ( mClient != null ) {
|
||||||
|
mClient.setBound( ObjectUtils.fromMogo( bound ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPoiSearched( PoiResult poiResult, int errorCode ) {
|
||||||
|
if ( errorCode != 1000 ) {
|
||||||
|
Logger.e( TAG, "errorcode is %d", errorCode );
|
||||||
|
}
|
||||||
|
if ( mListener != null ) {
|
||||||
|
mListener.onPoiSearched( ObjectUtils.fromAMap( poiResult ), errorCode );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPoiItemSearched( PoiItem poiItem, int errorCode ) {
|
||||||
|
if ( errorCode != 1000 ) {
|
||||||
|
Logger.e( TAG, "errorcode is %d", errorCode );
|
||||||
|
}
|
||||||
|
if ( mListener != null ) {
|
||||||
|
mListener.onPoiItemSearched( ObjectUtils.fromAMap( poiItem ), errorCode );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import com.amap.api.maps.model.BitmapDescriptor;
|
|||||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||||
import com.amap.api.maps.model.LatLng;
|
import com.amap.api.maps.model.LatLng;
|
||||||
import com.amap.api.maps.model.MarkerOptions;
|
import com.amap.api.maps.model.MarkerOptions;
|
||||||
|
import com.amap.api.maps.model.Poi;
|
||||||
import com.amap.api.services.core.LatLonPoint;
|
import com.amap.api.services.core.LatLonPoint;
|
||||||
import com.amap.api.services.core.PoiItem;
|
import com.amap.api.services.core.PoiItem;
|
||||||
import com.amap.api.services.geocoder.AoiItem;
|
import com.amap.api.services.geocoder.AoiItem;
|
||||||
@@ -24,29 +25,35 @@ import com.amap.api.services.help.Tip;
|
|||||||
import com.amap.api.services.poisearch.IndoorData;
|
import com.amap.api.services.poisearch.IndoorData;
|
||||||
import com.amap.api.services.poisearch.Photo;
|
import com.amap.api.services.poisearch.Photo;
|
||||||
import com.amap.api.services.poisearch.PoiItemExtension;
|
import com.amap.api.services.poisearch.PoiItemExtension;
|
||||||
|
import com.amap.api.services.poisearch.PoiResult;
|
||||||
|
import com.amap.api.services.poisearch.PoiSearch;
|
||||||
import com.amap.api.services.poisearch.SubPoiItem;
|
import com.amap.api.services.poisearch.SubPoiItem;
|
||||||
import com.amap.api.services.road.Crossroad;
|
import com.amap.api.services.road.Crossroad;
|
||||||
import com.mogo.map.MogoLatLng;
|
import com.mogo.map.MogoLatLng;
|
||||||
import com.mogo.map.location.MogoLocation;
|
import com.mogo.map.location.MogoLocation;
|
||||||
import com.mogo.map.marker.MogoMarkerOptions;
|
import com.mogo.map.marker.MogoMarkerOptions;
|
||||||
import com.mogo.map.search.MogoAoiItem;
|
import com.mogo.map.model.MogoPoi;
|
||||||
import com.mogo.map.search.MogoBusinessArea;
|
import com.mogo.map.search.geo.MogoAoiItem;
|
||||||
import com.mogo.map.search.MogoCrossroad;
|
import com.mogo.map.search.geo.MogoBusinessArea;
|
||||||
import com.mogo.map.search.MogoGeocodeAddress;
|
import com.mogo.map.search.geo.MogoCrossroad;
|
||||||
import com.mogo.map.search.MogoGeocodeResult;
|
import com.mogo.map.search.geo.MogoGeocodeAddress;
|
||||||
import com.mogo.map.search.MogoIndoorData;
|
import com.mogo.map.search.geo.MogoGeocodeResult;
|
||||||
import com.mogo.map.search.MogoPhoto;
|
import com.mogo.map.search.geo.MogoIndoorData;
|
||||||
import com.mogo.map.search.MogoPoiItem;
|
import com.mogo.map.search.geo.MogoPhoto;
|
||||||
import com.mogo.map.search.MogoPoiItemExtension;
|
import com.mogo.map.search.geo.MogoPoiItem;
|
||||||
import com.mogo.map.search.MogoRegeocodeAddress;
|
import com.mogo.map.search.geo.MogoPoiItemExtension;
|
||||||
import com.mogo.map.search.MogoRegeocodeResult;
|
import com.mogo.map.search.geo.MogoRegeocodeAddress;
|
||||||
import com.mogo.map.search.MogoRegeocodeRoad;
|
import com.mogo.map.search.geo.MogoRegeocodeResult;
|
||||||
import com.mogo.map.search.MogoStreetNumber;
|
import com.mogo.map.search.geo.MogoRegeocodeRoad;
|
||||||
import com.mogo.map.search.MogoSubPoiItem;
|
import com.mogo.map.search.geo.MogoStreetNumber;
|
||||||
import com.mogo.map.search.MogoTip;
|
import com.mogo.map.search.geo.MogoSubPoiItem;
|
||||||
import com.mogo.map.search.query.MogoGeocodeQuery;
|
import com.mogo.map.search.inputtips.MogoTip;
|
||||||
import com.mogo.map.search.query.MogoInputtipsQuery;
|
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
|
||||||
import com.mogo.map.search.query.MogoRegeocodeQuery;
|
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||||
|
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||||
|
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||||
|
import com.mogo.map.search.poisearch.MogoSearchBound;
|
||||||
|
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -136,6 +143,13 @@ public class ObjectUtils {
|
|||||||
return new LatLonPoint( latLng.lat, latLng.lng );
|
return new LatLonPoint( latLng.lat, latLng.lng );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LatLng fromMogo2( MogoLatLng latLng ) {
|
||||||
|
if ( latLng == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new LatLng( latLng.lat, latLng.lng );
|
||||||
|
}
|
||||||
|
|
||||||
public static MogoLatLng fromAMap( LatLonPoint point ) {
|
public static MogoLatLng fromAMap( LatLonPoint point ) {
|
||||||
if ( point == null ) {
|
if ( point == null ) {
|
||||||
return null;
|
return null;
|
||||||
@@ -143,6 +157,13 @@ public class ObjectUtils {
|
|||||||
return new MogoLatLng( point.getLatitude(), point.getLongitude() );
|
return new MogoLatLng( point.getLatitude(), point.getLongitude() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MogoLatLng fromAMap( LatLng point ) {
|
||||||
|
if ( point == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new MogoLatLng( point.latitude, point.longitude );
|
||||||
|
}
|
||||||
|
|
||||||
public static GeocodeQuery fromMogo( MogoGeocodeQuery query ) {
|
public static GeocodeQuery fromMogo( MogoGeocodeQuery query ) {
|
||||||
if ( query == null ) {
|
if ( query == null ) {
|
||||||
return null;
|
return null;
|
||||||
@@ -463,4 +484,111 @@ public class ObjectUtils {
|
|||||||
mogoTip.setTypeCode( tip.getTypeCode() );
|
mogoTip.setTypeCode( tip.getTypeCode() );
|
||||||
return mogoTip;
|
return mogoTip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MogoPoi fromAMap( Poi poi ) {
|
||||||
|
if ( poi == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MogoPoi mogoPoi = new MogoPoi();
|
||||||
|
mogoPoi.setCoordinate( fromAMap( poi.getCoordinate() ) );
|
||||||
|
mogoPoi.setName( poi.getName() );
|
||||||
|
mogoPoi.setPoiId( poi.getPoiId() );
|
||||||
|
return mogoPoi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MogoPoiSearchQuery fromAMap( PoiSearch.Query query ) {
|
||||||
|
if ( query == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MogoPoiSearchQuery mogoPoiSearchQuery = new MogoPoiSearchQuery( query.getQueryString(), query.getCategory(), query.getCity() );
|
||||||
|
mogoPoiSearchQuery.setBuilding( query.getBuilding() );
|
||||||
|
mogoPoiSearchQuery.setCityLimit( query.getCityLimit() );
|
||||||
|
mogoPoiSearchQuery.setDistanceSort( query.isDistanceSort() );
|
||||||
|
mogoPoiSearchQuery.setLocation( fromAMap( query.getLocation() ) );
|
||||||
|
mogoPoiSearchQuery.setPageNum( query.getPageNum() );
|
||||||
|
mogoPoiSearchQuery.setPageSize( query.getPageSize() );
|
||||||
|
return mogoPoiSearchQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PoiSearch.Query fromMogo( MogoPoiSearchQuery query ) {
|
||||||
|
if ( query == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
PoiSearch.Query psq = new PoiSearch.Query( query.getQuery(), query.getCategory(), query.getCity() );
|
||||||
|
psq.setBuilding( query.getBuilding() );
|
||||||
|
psq.setCityLimit( query.isCityLimit() );
|
||||||
|
psq.setDistanceSort( query.isDistanceSort() );
|
||||||
|
psq.setLocation( fromMogo( query.getLocation() ) );
|
||||||
|
psq.setPageNum( query.getPageNum() );
|
||||||
|
psq.setPageSize( query.getPageSize() );
|
||||||
|
return psq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MogoSearchBound fromAMap( PoiSearch.SearchBound bound ) {
|
||||||
|
if ( bound == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ( bound.getShape() == PoiSearch.SearchBound.BOUND_SHAPE ) {
|
||||||
|
return new MogoSearchBound( fromAMap( bound.getCenter() ), bound.getRange(), bound.isDistanceSort() );
|
||||||
|
} else if ( bound.getShape() == PoiSearch.SearchBound.POLYGON_SHAPE ) {
|
||||||
|
return new MogoSearchBound( fromAMap( bound.getPolyGonList() ) );
|
||||||
|
} else if ( bound.getShape() == PoiSearch.SearchBound.RECTANGLE_SHAPE ) {
|
||||||
|
return new MogoSearchBound( fromAMap( bound.getLowerLeft() ), fromAMap( bound.getUpperRight() ) );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List< MogoLatLng > fromAMap( List< LatLonPoint > latLngs ) {
|
||||||
|
if ( latLngs == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List< MogoLatLng > result = new ArrayList<>( latLngs.size() );
|
||||||
|
for ( LatLonPoint latLng : latLngs ) {
|
||||||
|
result.add( fromAMap( latLng ) );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List< LatLonPoint > fromMogo( List< MogoLatLng > latLngs ) {
|
||||||
|
if ( latLngs == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List< LatLonPoint > result = new ArrayList<>( latLngs.size() );
|
||||||
|
for ( MogoLatLng latLng : latLngs ) {
|
||||||
|
result.add( fromMogo( latLng ) );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static PoiSearch.SearchBound fromMogo( MogoSearchBound bound ) {
|
||||||
|
if ( bound == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ( bound.getShape() == MogoSearchBound.SHAPE_BOUND ) {
|
||||||
|
return new PoiSearch.SearchBound( fromMogo( bound.getCenterPoint() ), bound.getRadiusInMeters(), bound.isDistanceSort() );
|
||||||
|
} else if ( bound.getShape() == MogoSearchBound.SHAPE_POLYGON ) {
|
||||||
|
return new PoiSearch.SearchBound( fromMogo( bound.getPolyGonList() ) );
|
||||||
|
} else if ( bound.getShape() == MogoSearchBound.SHAPE_RECTANGLE ) {
|
||||||
|
return new PoiSearch.SearchBound( fromMogo( bound.getLowerLeft() ), fromMogo( bound.getUpperRight() ) );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MogoPoiResult fromAMap( PoiResult result ) {
|
||||||
|
if ( result == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MogoPoiResult mogoPoiResult = new MogoPoiResult();
|
||||||
|
if ( result.getPois() != null ) {
|
||||||
|
final List< PoiItem > poiItems = result.getPois();
|
||||||
|
final ArrayList< MogoPoiItem > mogoPoiItems = new ArrayList<>( poiItems.size() );
|
||||||
|
for ( PoiItem poiItem : poiItems ) {
|
||||||
|
mogoPoiItems.add( fromAMap( poiItem ) );
|
||||||
|
}
|
||||||
|
mogoPoiResult.setPois( mogoPoiItems );
|
||||||
|
}
|
||||||
|
return mogoPoiResult;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.mogo.map.listener;
|
||||||
|
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import com.mogo.map.model.MogoPoi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 地图操作回调
|
||||||
|
*/
|
||||||
|
public interface IMogoMapListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地图加载完毕
|
||||||
|
*/
|
||||||
|
void onMapLoaded();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地图点击
|
||||||
|
*
|
||||||
|
* @param motionEvent
|
||||||
|
*/
|
||||||
|
void onTouch( MotionEvent motionEvent );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地图上的任意poi点击
|
||||||
|
*
|
||||||
|
* @param poi
|
||||||
|
*/
|
||||||
|
void onPOIClick( MogoPoi poi );
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.mogo.map.listener;
|
||||||
|
|
||||||
|
import com.mogo.map.exception.MogoMapException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 地图操作回调
|
||||||
|
*/
|
||||||
|
public interface IMogoMapListenerRegister {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册地图事件
|
||||||
|
*
|
||||||
|
* @param listener 回调事件
|
||||||
|
*/
|
||||||
|
void registerHostMapListener( IMogoMapListener listener );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反注册注册地图事件
|
||||||
|
*/
|
||||||
|
void unregisterHostMapListener();
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.mogo.map.listener;
|
||||||
|
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import com.mogo.map.model.MogoPoi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 地图监听注册管理
|
||||||
|
*/
|
||||||
|
public class MogoMapListenerHandler implements IMogoMapListener, IMogoMapListenerRegister {
|
||||||
|
|
||||||
|
private static volatile MogoMapListenerHandler sInstance;
|
||||||
|
|
||||||
|
private MogoMapListenerHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MogoMapListenerHandler getInstance() {
|
||||||
|
if ( sInstance == null ) {
|
||||||
|
synchronized ( MogoMapListenerHandler.class ) {
|
||||||
|
if ( sInstance == null ) {
|
||||||
|
sInstance = new MogoMapListenerHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void release() {
|
||||||
|
sInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上层模块代理对象
|
||||||
|
*/
|
||||||
|
private IMogoMapListener mDelegateListener = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerHostMapListener( IMogoMapListener listener ) {
|
||||||
|
mDelegateListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unregisterHostMapListener() {
|
||||||
|
mDelegateListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMapLoaded() {
|
||||||
|
if ( mDelegateListener != null ) {
|
||||||
|
synchronized ( mDelegateListener ) {
|
||||||
|
mDelegateListener.onMapLoaded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTouch( MotionEvent motionEvent ) {
|
||||||
|
if ( mDelegateListener != null ) {
|
||||||
|
synchronized ( mDelegateListener ) {
|
||||||
|
mDelegateListener.onTouch( motionEvent );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPOIClick( MogoPoi poi ) {
|
||||||
|
if ( mDelegateListener != null ) {
|
||||||
|
synchronized ( mDelegateListener ) {
|
||||||
|
mDelegateListener.onPOIClick( poi );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@ package com.mogo.map.marker;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
import com.mogo.map.MogoLatLng;
|
||||||
|
import com.mogo.map.location.IMogoLocationClient;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,6 +83,8 @@ public interface IMogoMarker {
|
|||||||
|
|
||||||
void setObject( Object object );
|
void setObject( Object object );
|
||||||
|
|
||||||
|
Object getObject();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置多少帧刷新一次图片资源,Marker动画的间隔时间,值越小动画越快。
|
* 设置多少帧刷新一次图片资源,Marker动画的间隔时间,值越小动画越快。
|
||||||
*
|
*
|
||||||
@@ -87,8 +92,16 @@ public interface IMogoMarker {
|
|||||||
*/
|
*/
|
||||||
void setPeriod( int period );
|
void setPeriod( int period );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置位置
|
||||||
|
*
|
||||||
|
* @param lat
|
||||||
|
* @param lng
|
||||||
|
*/
|
||||||
void setPosition( double lat, double lng );
|
void setPosition( double lat, double lng );
|
||||||
|
|
||||||
|
MogoLatLng getPosition();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置Marker覆盖物图片旋转的角度,从正北开始,逆时针计算。
|
* 设置Marker覆盖物图片旋转的角度,从正北开始,逆时针计算。
|
||||||
*
|
*
|
||||||
@@ -133,4 +146,18 @@ public interface IMogoMarker {
|
|||||||
* 显示 Marker 覆盖物的信息窗口。
|
* 显示 Marker 覆盖物的信息窗口。
|
||||||
*/
|
*/
|
||||||
void showInfoWindow();
|
void showInfoWindow();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置点击事件
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
void setOnMarkerClickListener( IMogoMarkerClickListener listener );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取点击事件
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IMogoMarkerClickListener getOnMarkerClickListener();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.mogo.map.marker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* marker 点击事件
|
||||||
|
*/
|
||||||
|
public interface IMogoMarkerClickListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件是否继续往下传递
|
||||||
|
*
|
||||||
|
* @param marker
|
||||||
|
* @return true - 时间已经处理完毕不继续往下传,否则继续往下传
|
||||||
|
*/
|
||||||
|
boolean onMarkerClicked( IMogoMarker marker );
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.mogo.map.model;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.mogo.map.MogoLatLng;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 地图上的poi
|
||||||
|
*/
|
||||||
|
public class MogoPoi implements Parcelable {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private MogoLatLng coordinate;
|
||||||
|
private String poiId;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName( String name ) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoLatLng getCoordinate() {
|
||||||
|
return coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordinate( MogoLatLng coordinate ) {
|
||||||
|
this.coordinate = coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPoiId() {
|
||||||
|
return poiId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoiId( String poiId ) {
|
||||||
|
this.poiId = poiId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel( Parcel dest, int flags ) {
|
||||||
|
dest.writeString( this.name );
|
||||||
|
dest.writeParcelable( this.coordinate, flags );
|
||||||
|
dest.writeString( this.poiId );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoPoi() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MogoPoi( Parcel in ) {
|
||||||
|
this.name = in.readString();
|
||||||
|
this.coordinate = in.readParcelable( MogoLatLng.class.getClassLoader() );
|
||||||
|
this.poiId = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator< MogoPoi > CREATOR = new Parcelable.Creator< MogoPoi >() {
|
||||||
|
@Override
|
||||||
|
public MogoPoi createFromParcel( Parcel source ) {
|
||||||
|
return new MogoPoi( source );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoPoi[] newArray( int size ) {
|
||||||
|
return new MogoPoi[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import com.mogo.map.exception.MogoMapException;
|
import com.mogo.map.exception.MogoMapException;
|
||||||
import com.mogo.map.search.query.MogoGeocodeQuery;
|
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
|
||||||
import com.mogo.map.search.query.MogoRegeocodeQuery;
|
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author congtaowang
|
* @author congtaowang
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.mogo.map.amap.search.GeocodeSearchClient;
|
import com.mogo.map.amap.search.GeocodeSearchClient;
|
||||||
import com.mogo.map.exception.MogoMapException;
|
import com.mogo.map.exception.MogoMapException;
|
||||||
import com.mogo.map.search.query.MogoGeocodeQuery;
|
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
|
||||||
import com.mogo.map.search.query.MogoRegeocodeQuery;
|
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import com.mogo.map.MogoLatLng;
|
import com.mogo.map.MogoLatLng;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.geo;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search.query;
|
package com.mogo.map.search.geo.query;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search.query;
|
package com.mogo.map.search.geo.query;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.inputtips;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.inputtips;
|
||||||
|
|
||||||
import com.mogo.map.exception.MogoMapException;
|
import com.mogo.map.exception.MogoMapException;
|
||||||
import com.mogo.map.search.query.MogoInputtipsQuery;
|
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.inputtips;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.mogo.map.amap.search.InputtipsSearch;
|
import com.mogo.map.amap.search.InputtipsSearch;
|
||||||
import com.mogo.map.exception.MogoMapException;
|
import com.mogo.map.exception.MogoMapException;
|
||||||
import com.mogo.map.search.query.MogoInputtipsQuery;
|
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search;
|
package com.mogo.map.search.inputtips;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.map.search.query;
|
package com.mogo.map.search.inputtips.query;
|
||||||
|
|
||||||
import com.mogo.map.MogoLatLng;
|
import com.mogo.map.MogoLatLng;
|
||||||
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.mogo.map.search.poisearch;
|
||||||
|
|
||||||
|
import com.mogo.map.exception.MogoMapException;
|
||||||
|
import com.mogo.map.search.geo.MogoPoiItem;
|
||||||
|
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* poi 搜索
|
||||||
|
*/
|
||||||
|
public interface IMogoPoiSearch {
|
||||||
|
|
||||||
|
void setPoiSearchListener( IMogoPoiSearchListener listener );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步搜索poi信息
|
||||||
|
*/
|
||||||
|
void searchPOIAsyn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步搜索poi信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MogoPoiResult searchPOI() throws MogoMapException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置查询条件
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
void setQuery( MogoPoiSearchQuery query );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据poiId搜索详情,同步
|
||||||
|
*
|
||||||
|
* @param poiId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MogoPoiItem searchPOIId( String poiId ) throws MogoMapException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据poiId搜索详情,异步
|
||||||
|
*
|
||||||
|
* @param poiId
|
||||||
|
*/
|
||||||
|
void searchPOIIdAsyn( String poiId );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 周边检索POI
|
||||||
|
*
|
||||||
|
* @param bound
|
||||||
|
*/
|
||||||
|
void setBound( MogoSearchBound bound );
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.mogo.map.search.poisearch;
|
||||||
|
|
||||||
|
import com.mogo.map.search.geo.MogoPoiItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* poi 检索结果回调
|
||||||
|
*/
|
||||||
|
public interface IMogoPoiSearchListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回POI搜索异步处理的结果。
|
||||||
|
*/
|
||||||
|
void onPoiSearched( MogoPoiResult result, int errorCode );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* poi ID 检索结果回调方法
|
||||||
|
*/
|
||||||
|
void onPoiItemSearched( MogoPoiItem item, int errorCode );
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.mogo.map.search.poisearch;
|
||||||
|
|
||||||
|
import com.mogo.map.search.geo.MogoPoiItem;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* poi搜索结果集
|
||||||
|
*/
|
||||||
|
public class MogoPoiResult {
|
||||||
|
|
||||||
|
private ArrayList< MogoPoiItem > pois;
|
||||||
|
|
||||||
|
public ArrayList< MogoPoiItem > getPois() {
|
||||||
|
return pois;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPois( ArrayList< MogoPoiItem > pois ) {
|
||||||
|
this.pois = pois;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.mogo.map.search.poisearch;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.mogo.map.amap.search.PoiSearchClient;
|
||||||
|
import com.mogo.map.exception.MogoMapException;
|
||||||
|
import com.mogo.map.search.geo.MogoPoiItem;
|
||||||
|
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
public class MogoPoiSearch implements IMogoPoiSearch {
|
||||||
|
|
||||||
|
private IMogoPoiSearch mDelegate;
|
||||||
|
|
||||||
|
public MogoPoiSearch( Context context, MogoPoiSearchQuery query ) {
|
||||||
|
mDelegate = new PoiSearchClient( context, query );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPoiSearchListener( IMogoPoiSearchListener listener ) {
|
||||||
|
if ( mDelegate != null ) {
|
||||||
|
mDelegate.setPoiSearchListener( listener );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void searchPOIAsyn() {
|
||||||
|
if ( mDelegate != null ) {
|
||||||
|
mDelegate.searchPOIAsyn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoPoiResult searchPOI() throws MogoMapException {
|
||||||
|
if ( mDelegate != null ) {
|
||||||
|
return mDelegate.searchPOI();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setQuery( MogoPoiSearchQuery query ) {
|
||||||
|
if ( mDelegate != null ) {
|
||||||
|
mDelegate.setQuery( query );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoPoiItem searchPOIId( String poiId ) throws MogoMapException {
|
||||||
|
if ( mDelegate != null ) {
|
||||||
|
return mDelegate.searchPOIId( poiId );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void searchPOIIdAsyn( String poiId ) {
|
||||||
|
if ( mDelegate != null ) {
|
||||||
|
mDelegate.searchPOIIdAsyn( poiId );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBound( MogoSearchBound bound ) {
|
||||||
|
if ( mDelegate != null ) {
|
||||||
|
mDelegate.setBound( bound );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package com.mogo.map.search.poisearch;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.mogo.map.MogoLatLng;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 周边搜索范围
|
||||||
|
*/
|
||||||
|
public class MogoSearchBound implements Parcelable {
|
||||||
|
|
||||||
|
public static final String SHAPE_BOUND = "Bound";
|
||||||
|
public static final String SHAPE_RECTANGLE = "Rectangle";
|
||||||
|
public static final String SHAPE_POLYGON = "Polygon";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 中心点
|
||||||
|
*/
|
||||||
|
private MogoLatLng centerPoint;
|
||||||
|
/**
|
||||||
|
* 半径:米
|
||||||
|
*/
|
||||||
|
private int radiusInMeters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索范围的形状
|
||||||
|
*/
|
||||||
|
private String shape;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按距离排序
|
||||||
|
*/
|
||||||
|
private boolean isDistanceSort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 左下角
|
||||||
|
*/
|
||||||
|
private MogoLatLng lowerLeft;
|
||||||
|
/**
|
||||||
|
* 右上角
|
||||||
|
*/
|
||||||
|
private MogoLatLng upperRight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 范围搜索地点列表
|
||||||
|
*/
|
||||||
|
private List< MogoLatLng > polyGonList;
|
||||||
|
|
||||||
|
public MogoSearchBound( MogoLatLng centerPoint, int radiusInMeters ) {
|
||||||
|
this( centerPoint, radiusInMeters, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoSearchBound( MogoLatLng centerPoint, int radiusInMeters, boolean isDistanceSort ) {
|
||||||
|
this.centerPoint = centerPoint;
|
||||||
|
this.radiusInMeters = radiusInMeters;
|
||||||
|
this.isDistanceSort = isDistanceSort;
|
||||||
|
this.shape = SHAPE_BOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoSearchBound( MogoLatLng lowerLeft, MogoLatLng upperRight ) {
|
||||||
|
this.lowerLeft = lowerLeft;
|
||||||
|
this.upperRight = upperRight;
|
||||||
|
this.shape = SHAPE_RECTANGLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoSearchBound( List< MogoLatLng > polyGonList ) {
|
||||||
|
this.polyGonList = polyGonList;
|
||||||
|
this.shape = SHAPE_POLYGON;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoLatLng getCenterPoint() {
|
||||||
|
return centerPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRadiusInMeters() {
|
||||||
|
return radiusInMeters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShape() {
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDistanceSort() {
|
||||||
|
return isDistanceSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoLatLng getLowerLeft() {
|
||||||
|
return lowerLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoLatLng getUpperRight() {
|
||||||
|
return upperRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List< MogoLatLng > getPolyGonList() {
|
||||||
|
return polyGonList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel( Parcel dest, int flags ) {
|
||||||
|
dest.writeParcelable( this.centerPoint, flags );
|
||||||
|
dest.writeInt( this.radiusInMeters );
|
||||||
|
dest.writeString( this.shape );
|
||||||
|
dest.writeByte( this.isDistanceSort ? ( byte ) 1 : ( byte ) 0 );
|
||||||
|
dest.writeParcelable( this.lowerLeft, flags );
|
||||||
|
dest.writeParcelable( this.upperRight, flags );
|
||||||
|
dest.writeTypedList( this.polyGonList );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MogoSearchBound( Parcel in ) {
|
||||||
|
this.centerPoint = in.readParcelable( MogoLatLng.class.getClassLoader() );
|
||||||
|
this.radiusInMeters = in.readInt();
|
||||||
|
this.shape = in.readString();
|
||||||
|
this.isDistanceSort = in.readByte() != 0;
|
||||||
|
this.lowerLeft = in.readParcelable( MogoLatLng.class.getClassLoader() );
|
||||||
|
this.upperRight = in.readParcelable( MogoLatLng.class.getClassLoader() );
|
||||||
|
this.polyGonList = in.createTypedArrayList( MogoLatLng.CREATOR );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator< MogoSearchBound > CREATOR = new Parcelable.Creator< MogoSearchBound >() {
|
||||||
|
@Override
|
||||||
|
public MogoSearchBound createFromParcel( Parcel source ) {
|
||||||
|
return new MogoSearchBound( source );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoSearchBound[] newArray( int size ) {
|
||||||
|
return new MogoSearchBound[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
package com.mogo.map.search.poisearch.query;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.mogo.map.MogoLatLng;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* poi 搜索查询条件
|
||||||
|
*/
|
||||||
|
public class MogoPoiSearchQuery implements Parcelable {
|
||||||
|
|
||||||
|
private String query;
|
||||||
|
private String category;
|
||||||
|
private String city;
|
||||||
|
private String building;
|
||||||
|
private int pageNum;
|
||||||
|
private int pageSize;
|
||||||
|
private boolean isCityLimit;
|
||||||
|
private boolean isSubPois;
|
||||||
|
private boolean isDistanceSort;
|
||||||
|
private MogoLatLng location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param query 查询字符串,多个关键字用“|”分割
|
||||||
|
* @param category 类型的组合,比如定义如下组合:餐馆|电影院|景点
|
||||||
|
*/
|
||||||
|
public MogoPoiSearchQuery( String query, String category ) {
|
||||||
|
this.query = query;
|
||||||
|
this.category = category;
|
||||||
|
this.city = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param query 查询字符串,多个关键字用“|”分割
|
||||||
|
* @param category 类型的组合,比如定义如下组合:餐馆|电影院|景点
|
||||||
|
*/
|
||||||
|
public MogoPoiSearchQuery( String query, String category, String city ) {
|
||||||
|
this.query = query;
|
||||||
|
this.category = category;
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBuilding() {
|
||||||
|
return building;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuilding( String building ) {
|
||||||
|
this.building = building;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQuery() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCity() {
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPageNum() {
|
||||||
|
return pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageNum( int pageNum ) {
|
||||||
|
this.pageNum = pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageSize( int pageSize ) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCityLimit() {
|
||||||
|
return isCityLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCityLimit( boolean cityLimit ) {
|
||||||
|
isCityLimit = cityLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSubPois() {
|
||||||
|
return isSubPois;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubPois( boolean subPois ) {
|
||||||
|
isSubPois = subPois;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDistanceSort() {
|
||||||
|
return isDistanceSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDistanceSort( boolean distanceSort ) {
|
||||||
|
isDistanceSort = distanceSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoLatLng getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation( MogoLatLng location ) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel( Parcel dest, int flags ) {
|
||||||
|
dest.writeString( this.building );
|
||||||
|
dest.writeString( this.category );
|
||||||
|
dest.writeString( this.city );
|
||||||
|
dest.writeInt( this.pageNum );
|
||||||
|
dest.writeInt( this.pageSize );
|
||||||
|
dest.writeByte( this.isCityLimit ? ( byte ) 1 : ( byte ) 0 );
|
||||||
|
dest.writeByte( this.isSubPois ? ( byte ) 1 : ( byte ) 0 );
|
||||||
|
dest.writeByte( this.isDistanceSort ? ( byte ) 1 : ( byte ) 0 );
|
||||||
|
dest.writeParcelable( this.location, flags );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoPoiSearchQuery() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MogoPoiSearchQuery( Parcel in ) {
|
||||||
|
this.building = in.readString();
|
||||||
|
this.category = in.readString();
|
||||||
|
this.city = in.readString();
|
||||||
|
this.pageNum = in.readInt();
|
||||||
|
this.pageSize = in.readInt();
|
||||||
|
this.isCityLimit = in.readByte() != 0;
|
||||||
|
this.isSubPois = in.readByte() != 0;
|
||||||
|
this.isDistanceSort = in.readByte() != 0;
|
||||||
|
this.location = in.readParcelable( MogoLatLng.class.getClassLoader() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator< MogoPoiSearchQuery > CREATOR = new Parcelable.Creator< MogoPoiSearchQuery >() {
|
||||||
|
@Override
|
||||||
|
public MogoPoiSearchQuery createFromParcel( Parcel source ) {
|
||||||
|
return new MogoPoiSearchQuery( source );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoPoiSearchQuery[] newArray( int size ) {
|
||||||
|
return new MogoPoiSearchQuery[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
1
modules/mogo-module-common/.gitignore
vendored
Normal file
1
modules/mogo-module-common/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
34
modules/mogo-module-common/build.gradle
Normal file
34
modules/mogo-module-common/build.gradle
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 29
|
||||||
|
buildToolsVersion "29.0.2"
|
||||||
|
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 19
|
||||||
|
targetSdkVersion 29
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
consumerProguardFiles 'consumer-rules.pro'
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||||
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||||
|
}
|
||||||
0
modules/mogo-module-common/consumer-rules.pro
Normal file
0
modules/mogo-module-common/consumer-rules.pro
Normal file
21
modules/mogo-module-common/proguard-rules.pro
vendored
Normal file
21
modules/mogo-module-common/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.mogo.module.common;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
@RunWith( AndroidJUnit4.class )
|
||||||
|
public class ExampleInstrumentedTest {
|
||||||
|
@Test
|
||||||
|
public void useAppContext() {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
|
|
||||||
|
assertEquals( "com.mogo.module.common.test", appContext.getPackageName() );
|
||||||
|
}
|
||||||
|
}
|
||||||
2
modules/mogo-module-common/src/main/AndroidManifest.xml
Normal file
2
modules/mogo-module-common/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.mogo.module.common" />
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.mogo.module.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 模块路由路径
|
||||||
|
*/
|
||||||
|
public class MogoModulePaths {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地图模块 fragment 路径
|
||||||
|
*/
|
||||||
|
public static final String PATH_MODULE_MAP = "/module/map";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试模块
|
||||||
|
*/
|
||||||
|
public static final String PATH_MODULE_DEMO = "/demo/module/demo";
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">mogo-module-common</string>
|
||||||
|
</resources>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.mogo.module.common;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
public class ExampleUnitTest {
|
||||||
|
@Test
|
||||||
|
public void addition_isCorrect() {
|
||||||
|
assertEquals( 4, 2 + 2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
1
modules/mogo-module-main/.gitignore
vendored
Normal file
1
modules/mogo-module-main/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
47
modules/mogo-module-main/build.gradle
Normal file
47
modules/mogo-module-main/build.gradle
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 29
|
||||||
|
buildToolsVersion "29.0.2"
|
||||||
|
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 19
|
||||||
|
targetSdkVersion 29
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
consumerProguardFiles 'consumer-rules.pro'
|
||||||
|
|
||||||
|
javaCompileOptions {
|
||||||
|
annotationProcessorOptions {
|
||||||
|
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
|
||||||
|
implementation project(":foudations:mogo-utils")
|
||||||
|
implementation project(":foudations:mogo-commons")
|
||||||
|
implementation project(':modules:mogo-module-common')
|
||||||
|
implementation project(':modules:mogo-module-map')
|
||||||
|
implementation project(':services:mogo-service-api')
|
||||||
|
implementation project(':services:mogo-service')
|
||||||
|
implementation project(':demo:demo-module-map')
|
||||||
|
implementation rootProject.ext.dependencies.androidxappcompat
|
||||||
|
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
||||||
|
implementation rootProject.ext.dependencies.arouter
|
||||||
|
annotationProcessor rootProject.ext.dependencies.aroutercompiler
|
||||||
|
}
|
||||||
0
modules/mogo-module-main/consumer-rules.pro
Normal file
0
modules/mogo-module-main/consumer-rules.pro
Normal file
21
modules/mogo-module-main/proguard-rules.pro
vendored
Normal file
21
modules/mogo-module-main/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.mogo.service.map;
|
package com.mogo.module.main;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
@@ -22,6 +22,6 @@ public class ExampleInstrumentedTest {
|
|||||||
// Context of the app under test.
|
// Context of the app under test.
|
||||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
|
|
||||||
assertEquals( "com.mogo.service.amap.test", appContext.getPackageName() );
|
assertEquals( "com.mogo.module.main.test", appContext.getPackageName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
27
modules/mogo-module-main/src/main/AndroidManifest.xml
Normal file
27
modules/mogo-module-main/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.mogo.module.main">
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<activity
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:clearTaskOnLaunch="true"
|
||||||
|
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|mcc|mnc|keyboard|navigation"
|
||||||
|
android:enabled="true"
|
||||||
|
android:launchMode="singleInstance"
|
||||||
|
android:resizeableActivity="true"
|
||||||
|
android:resumeWhilePausing="true"
|
||||||
|
android:screenOrientation="nosensor"
|
||||||
|
android:stateNotNeeded="true"
|
||||||
|
android:taskAffinity=""
|
||||||
|
android:windowSoftInputMode="adjustPan">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<!--调试用,暂时开启LAUNCHER这个属性-->
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER_APP" />
|
||||||
|
<category android:name="android.intent.category.HOME" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.mogo.module.main;
|
||||||
|
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.alibaba.android.arouter.launcher.ARouter;
|
||||||
|
import com.mogo.commons.mvp.MvpActivity;
|
||||||
|
import com.mogo.map.listener.IMogoMapListener;
|
||||||
|
import com.mogo.map.model.MogoPoi;
|
||||||
|
import com.mogo.module.main.cards.MogoModulesHandler;
|
||||||
|
import com.mogo.module.main.cards.MogoModulesManager;
|
||||||
|
import com.mogo.service.MogoServicePaths;
|
||||||
|
import com.mogo.service.map.IMogoMapService;
|
||||||
|
import com.mogo.service.module.IMogoModuleProvider;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
public class MainActivity extends MvpActivity< MainView, MainPresenter > implements MainView {
|
||||||
|
|
||||||
|
IMogoMapService ims;
|
||||||
|
MogoModulesHandler handler;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getLayoutId() {
|
||||||
|
return R.layout.module_main_activity_main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews() {
|
||||||
|
|
||||||
|
handler = new MogoModulesManager( this );
|
||||||
|
ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
||||||
|
if ( ims != null ) {
|
||||||
|
ims.registerHostMapListener( handler );
|
||||||
|
}
|
||||||
|
handler.loadMap( R.id.module_main_id_fragment_container );
|
||||||
|
|
||||||
|
Collection< IMogoModuleProvider > providers = handler.loadCards();
|
||||||
|
for ( IMogoModuleProvider provider : providers ) {
|
||||||
|
if ( provider == null ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( provider.getType() == IMogoModuleProvider.TYPE_FRAGMENT ) {
|
||||||
|
final Fragment fragment = provider.createFragment( this, null );
|
||||||
|
if ( fragment != null ) {
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.add( R.id.module_main_id_fragment_container, fragment )
|
||||||
|
.commitAllowingStateLoss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handler.setEnable( providers.iterator().next().getModuleName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected MainPresenter createPresenter() {
|
||||||
|
return new MainPresenter( this );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.mogo.module.main;
|
||||||
|
|
||||||
|
import com.mogo.commons.mvp.Presenter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
public class MainPresenter extends Presenter< MainView > {
|
||||||
|
|
||||||
|
public MainPresenter( MainView view ) {
|
||||||
|
super( view );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.mogo.module.main;
|
||||||
|
|
||||||
|
import com.mogo.commons.mvp.IView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-23
|
||||||
|
* <p>
|
||||||
|
* 主页 view 接口
|
||||||
|
*/
|
||||||
|
public interface MainView extends IView {
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user