增加设置家和公司的ContentProvider
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
|
||||
<application>
|
||||
<activity android:name=".ui.NaviActivity"></activity>
|
||||
<provider
|
||||
android:name=".cp.AddressContentProvider"
|
||||
android:authorities="com.mogo.module.navi"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -22,10 +22,10 @@ public class DataConstants {
|
||||
public static final String POI_ID_HOME = "common_address_home";
|
||||
public static final String POI_ID_COMPANY = "common_address_company";
|
||||
|
||||
public static final String CP_AUTHORITY = "com.zhidao.amap";
|
||||
public static final String CP_AUTHORITY = "com.mogo.module.navi";
|
||||
|
||||
// 家的地址
|
||||
public static final Uri CONTENT_HOME_ADDRESS_URI = Uri.parse( "content://com.zhidao.amap/homeAddress" );
|
||||
public static final Uri CONTENT_HOME_ADDRESS_URI = Uri.parse( "content://com.mogo.module.navi/homeAddress" );
|
||||
public static final int HOME_ADDRESS_CODE = TYPE_HOME_ADDRESS;
|
||||
public static final String HOME_ADDRESS_PATH = "homeAddress";
|
||||
public static final String HOME_ADDRESS = "homeAddress";
|
||||
@@ -34,7 +34,7 @@ public class DataConstants {
|
||||
public static final String HOME_ADDRESS_LONGITUDE = "homeAddressLongitude";
|
||||
|
||||
// 公司地址
|
||||
public static final Uri CONTENT_COMPANY_ADDRESS_URI = Uri.parse( "content://com.zhidao.amap/companyAddress" );
|
||||
public static final Uri CONTENT_COMPANY_ADDRESS_URI = Uri.parse( "content://com.mogo.module.navi/companyAddress" );
|
||||
public static final int COMPANY_ADDRESS_CODE = TYPE_COMPANY_ADDRESS;
|
||||
public static final String COMPANY_ADDRESS_PATH = "companyAddress";
|
||||
public static final String COMPANY_ADDRESS = "companyAddress";
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mogo.map.search.geo.IMogoGeoSearch
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController
|
||||
import com.mogo.module.navi.manager.MogoSettingManager
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.analytics.IMogoAnalytics
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager
|
||||
import com.mogo.service.map.IMogoMapService
|
||||
@@ -41,6 +42,9 @@ object SearchServiceHolder{
|
||||
val statusManager: IMogoStatusManager = ARouter.getInstance().build(
|
||||
MogoServicePaths.PATH_STATUS_MANAGER
|
||||
).navigation() as IMogoStatusManager
|
||||
val analyticsManager: IMogoAnalytics = ARouter.getInstance().build(
|
||||
MogoServicePaths.PATH_UTILS_ANALYTICS
|
||||
).navigation() as IMogoAnalytics
|
||||
var geoSearch: IMogoGeoSearch? = null
|
||||
fun init(context: Context) {
|
||||
this.context = context
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.mogo.module.navi.cp;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
import com.mogo.module.navi.database.AppDataBase;
|
||||
import com.mogo.module.navi.manager.AddressManager;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-02
|
||||
* <p>
|
||||
* 外部应用设置家和公司的地址
|
||||
*/
|
||||
public class AddressContentProvider extends ContentProvider {
|
||||
|
||||
private static final String TAG = "data.AddressCP";
|
||||
|
||||
private static final UriMatcher mMatcher;
|
||||
|
||||
static {
|
||||
mMatcher = new UriMatcher( UriMatcher.NO_MATCH );
|
||||
mMatcher.addURI( DataConstants.CP_AUTHORITY, DataConstants.HOME_ADDRESS_PATH, DataConstants.HOME_ADDRESS_CODE );
|
||||
mMatcher.addURI( DataConstants.CP_AUTHORITY, DataConstants.COMPANY_ADDRESS_PATH, DataConstants.COMPANY_ADDRESS_CODE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Cursor query( @NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable
|
||||
String sortOrder ) {
|
||||
final int code = mMatcher.match( uri );
|
||||
Log.d( TAG, "query code: " + code );
|
||||
final SearchPoi poi = getPoi( code );
|
||||
MatrixCursor
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME, DataConstants.HOME_ADDRESS_LATITUDE, DataConstants.HOME_ADDRESS_LONGITUDE} );
|
||||
if ( code == DataConstants.HOME_ADDRESS_CODE ) {
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.HOME_ADDRESS_NAME, DataConstants.HOME_ADDRESS_LATITUDE, DataConstants.HOME_ADDRESS_LONGITUDE} );
|
||||
} else if ( code == DataConstants.COMPANY_ADDRESS_CODE ) {
|
||||
cursor = new MatrixCursor( new String[]{DataConstants.COMPANY_ADDRESS_NAME, DataConstants.COMPANY_ADDRESS_LATITUDE, DataConstants.COMPANY_ADDRESS_LONGITUDE} );
|
||||
}
|
||||
if ( cursor != null ) {
|
||||
if ( poi == null ) {
|
||||
cursor.addRow( new Object[]{"", 0, 0} );
|
||||
} else {
|
||||
cursor.addRow( new Object[]{poi.getName(), poi.getLat(), poi.getLng()} );
|
||||
}
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
private SearchPoi getPoi( int type ) {
|
||||
if ( type == DataConstants.HOME_ADDRESS_CODE ) {
|
||||
List< SearchPoi > homeAddressPoi = AppDataBase.getDatabase( getContext() ).poiDao().getHomeAddress().blockingGet();
|
||||
if ( homeAddressPoi != null && homeAddressPoi.size() > 0 ) {
|
||||
return homeAddressPoi.get( 0 );
|
||||
}
|
||||
} else if ( type == DataConstants.COMPANY_ADDRESS_CODE ) {
|
||||
List< SearchPoi > homeAddressPoi = AppDataBase.getDatabase( getContext()).poiDao().getCompanyAddress().blockingGet();
|
||||
if ( homeAddressPoi != null && homeAddressPoi.size() > 0 ) {
|
||||
return homeAddressPoi.get( 0 );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getType( @NonNull Uri uri ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Uri insert( @NonNull Uri uri, @Nullable ContentValues values ) {
|
||||
final int code = mMatcher.match( uri );
|
||||
Log.d( TAG, "insert code: " + code );
|
||||
if ( values.size() == 0 ) {
|
||||
return uri;
|
||||
}
|
||||
String poiName = "";
|
||||
String poiAddress = "";
|
||||
double lat = 0d;
|
||||
double lng = 0d;
|
||||
SearchPoi sp = null;
|
||||
if ( code == DataConstants.HOME_ADDRESS_CODE ) {
|
||||
poiName = values.getAsString( DataConstants.HOME_ADDRESS_NAME );
|
||||
poiAddress = values.getAsString( DataConstants.HOME_ADDRESS );
|
||||
Double dLat = values.getAsDouble( DataConstants.HOME_ADDRESS_LATITUDE );
|
||||
if ( dLat != null ) {
|
||||
lat = dLat;
|
||||
}
|
||||
Double dLng = values.getAsDouble( DataConstants.HOME_ADDRESS_LONGITUDE );
|
||||
if ( dLng != null ) {
|
||||
lng = dLng;
|
||||
}
|
||||
if ( validateLocation( lat, lng ) ) {
|
||||
sp = new SearchPoi( DataConstants.POI_ID_HOME, poiName, poiAddress, lat, lng, "", "", "" );
|
||||
}
|
||||
} else if ( code == DataConstants.COMPANY_ADDRESS_CODE ) {
|
||||
poiName = values.getAsString( DataConstants.COMPANY_ADDRESS_NAME );
|
||||
poiAddress = values.getAsString( DataConstants.COMPANY_ADDRESS );
|
||||
Double dLat = values.getAsDouble( DataConstants.COMPANY_ADDRESS_LATITUDE );
|
||||
if ( dLat != null ) {
|
||||
lat = dLat;
|
||||
}
|
||||
Double dLng = values.getAsDouble( DataConstants.COMPANY_ADDRESS_LONGITUDE );
|
||||
if ( dLng != null ) {
|
||||
lng = dLng;
|
||||
}
|
||||
if ( validateLocation( lat, lng ) ) {
|
||||
sp = new SearchPoi( DataConstants.POI_ID_COMPANY, poiName, poiAddress, lat, lng, "", "", "" );
|
||||
}
|
||||
}
|
||||
try {
|
||||
insertPoi( sp );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
private boolean validateLocation( double lat, double lng ) {
|
||||
if ( ( lat ) == 0D || ( lng ) == 0D ) {
|
||||
Log.e( TAG, "error location" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void insertPoi( SearchPoi poi ) {
|
||||
if ( poi == null ) {
|
||||
return;
|
||||
}
|
||||
List<Long> result = AppDataBase.getDatabase( getContext() ).poiDao().insert( poi );
|
||||
if ( result.get( 0 ).intValue() == -1 ) {
|
||||
Log.e( TAG, "insert error. " );
|
||||
}
|
||||
AddressManager.INSTANCE.insert(poi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete( @NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update( @NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -62,11 +62,11 @@ object AddressManager {
|
||||
}
|
||||
|
||||
fun hasHome(): Boolean {
|
||||
return homeAddress == null
|
||||
return homeAddress != null
|
||||
}
|
||||
|
||||
fun hasCompany(): Boolean {
|
||||
return companyAddress == null
|
||||
return companyAddress != null
|
||||
}
|
||||
|
||||
private fun pushSettingAddress(type: Int) {
|
||||
|
||||
@@ -116,7 +116,7 @@ public class SearchFragment extends BaseSearchFragment implements SearchView, Vi
|
||||
|
||||
mHistoryAdapter.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
AnalyticsUtils.track("Navigation_History_destination", new HashMap<String,Object>());
|
||||
SearchServiceHolder.INSTANCE.getAnalyticsManager().track("Navigation_History_destination", new HashMap<String,Object>());
|
||||
SearchPoi item = (SearchPoi) v.getTag(R.id.tag_item);
|
||||
MogoTip mogoTip = EntityConvertUtils.poi2MogoTip(item);
|
||||
SearchServiceHolder.INSTANCE.push(ChoosePathFragment.Companion.newInstance(mogoTip.getPoint()),
|
||||
@@ -142,7 +142,7 @@ public class SearchFragment extends BaseSearchFragment implements SearchView, Vi
|
||||
|
||||
findViewById(R.id.tv_navi_setting).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
AnalyticsUtils.track("Navigation_button_setting", new HashMap<String,Object>());
|
||||
SearchServiceHolder.INSTANCE.getAnalyticsManager().track("Navigation_button_setting", new HashMap<String,Object>());
|
||||
|
||||
push(new NaviSettingFragment(), MogoModulePaths.PATH_FRAGMENT_SETTING);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class SearchFragment extends BaseSearchFragment implements SearchView, Vi
|
||||
|
||||
findViewById(R.id.tv_navi_search).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
AnalyticsUtils.track("Navigation_button_search", new HashMap<String,Object>());
|
||||
SearchServiceHolder.INSTANCE.getAnalyticsManager().track("Navigation_button_search", new HashMap<String,Object>());
|
||||
|
||||
mSearchPresenter.startSearchPoiByInput(mSearchBox.getText().toString());
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import android.widget.SeekBar
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.commons.analytics.AnalyticsUtils
|
||||
import com.mogo.map.constants.BroadcastMode
|
||||
import com.mogo.map.uicontroller.EnumMapUI
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
@@ -84,7 +83,7 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
|
||||
}
|
||||
if (isChecked) {
|
||||
AnalyticsUtils.track("Navigation_preference", mapOf("type" to type))
|
||||
SearchServiceHolder.analyticsManager.track("Navigation_preference", mapOf("type" to type))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -194,9 +193,9 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
|
||||
|
||||
if (checkedId == R.id.rb_navi_detail) {
|
||||
AnalyticsUtils.track("Navigation_guide_type", mapOf("type" to 1))
|
||||
SearchServiceHolder.analyticsManager.track("Navigation_guide_type", mapOf("type" to 1))
|
||||
} else {
|
||||
AnalyticsUtils.track("Navigation_guide_type", mapOf("type" to 2))
|
||||
SearchServiceHolder.analyticsManager.track("Navigation_guide_type", mapOf("type" to 2))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,13 +213,13 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
|
||||
tv_navi_company_address.setOnClickListener {
|
||||
if (!AddressManager.hasCompany()) {
|
||||
AddressManager.goHome()
|
||||
AddressManager.goCompany()
|
||||
}
|
||||
}
|
||||
|
||||
tv_navi_home_address.setOnClickListener {
|
||||
if (!AddressManager.hasHome()) {
|
||||
AddressManager.goCompany()
|
||||
AddressManager.goHome()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +227,7 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
private fun updateHome() {
|
||||
|
||||
if (AddressManager.hasHome()) {
|
||||
tv_navi_home_address.text = AddressManager.homeAddress?.name
|
||||
tv_navi_home_address.text = AddressManager.homeAddress?.address
|
||||
tv_navi_clear_home_address.visibility = View.VISIBLE
|
||||
} else {
|
||||
tv_navi_clear_home_address.visibility = View.GONE
|
||||
@@ -237,7 +236,7 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
|
||||
private fun updateCompany() {
|
||||
if (AddressManager.hasCompany()) {
|
||||
tv_navi_company_address.text = AddressManager.companyAddress?.name
|
||||
tv_navi_company_address.text = AddressManager.companyAddress?.address
|
||||
tv_navi_clear_company_address.visibility = View.VISIBLE
|
||||
} else {
|
||||
tv_navi_clear_company_address.visibility = View.GONE
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.module.navi.ui.setting
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.map.MogoLatLng
|
||||
@@ -40,8 +41,8 @@ import kotlinx.android.synthetic.main.include_search_bar.iv_navi_back
|
||||
@Route(path = MogoModulePaths.PATH_FRAGMENT_SETTING_HOME)
|
||||
class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
override fun onRegeocodeSearched(regeocodeResult: MogoRegeocodeResult?) {
|
||||
|
||||
et_navi_search.setText(regeocodeResult?.regeocodeAddress?.formatAddress)
|
||||
selectPoi?.address=regeocodeResult?.regeocodeAddress?.formatAddress
|
||||
}
|
||||
|
||||
override fun onGeocodeSearched(geocodeResult: MogoGeocodeResult?) {
|
||||
@@ -52,7 +53,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
private var style: Int = DataConstants.TYPE_HOME_ADDRESS
|
||||
var addMarker: IMogoMarker? = null
|
||||
|
||||
private var selectPoi: MogoLatLng?=null
|
||||
private var selectPoi: SearchPoi?=null
|
||||
private var mapListener: IMogoMapListener = object : MogoMapListenerAdapter() {
|
||||
override fun onMapChanged(
|
||||
latLng: MogoLatLng?,
|
||||
@@ -61,7 +62,8 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
bearing: Float
|
||||
) {
|
||||
super.onMapChanged(latLng, zoom, tilt, bearing)
|
||||
selectPoi=latLng
|
||||
selectPoi=EntityConvertUtils.geoToPoi(latLng?.lat?:0.0,latLng?.lng?:0.0,style)
|
||||
|
||||
var mogoRegeocodeQuery = MogoRegeocodeQuery()
|
||||
mogoRegeocodeQuery.point = latLng
|
||||
SearchServiceHolder.getGeoSearcher().getFromLocationAsyn(mogoRegeocodeQuery)
|
||||
@@ -126,10 +128,11 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
}
|
||||
tv_set_as_home.setOnClickListener {
|
||||
|
||||
var geoToPoi =
|
||||
EntityConvertUtils.geoToPoi(selectPoi?.lat ?: 0.0, selectPoi?.lng ?: 0.0, style)
|
||||
insert(geoToPoi)
|
||||
if (selectPoi == null) {
|
||||
Toast.makeText(context,"请选择",Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
insert(selectPoi!!)
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
android:clickable="true"
|
||||
android:background="#2D2E3D"
|
||||
android:orientation="vertical"
|
||||
android:paddingRight="@dimen/dp_160"
|
||||
android:paddingLeft="@dimen/dp_160"
|
||||
|
||||
>
|
||||
<RelativeLayout
|
||||
android:id="@+id/rl_navi_setting_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_80"
|
||||
android:layout_marginLeft="@dimen/dp_60"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/dp_30"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
@@ -44,12 +44,15 @@
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:paddingRight="@dimen/dp_160"
|
||||
android:paddingLeft="@dimen/dp_160"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rl_navi_setting_title"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_height="0dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:paddingBottom="@dimen/dp_150"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
|
||||
Reference in New Issue
Block a user