This commit is contained in:
wangcongtao
2020-01-15 19:17:33 +08:00
parent 75f4d373a9
commit 6ddf294e7d
9 changed files with 117 additions and 40 deletions

View File

@@ -15,9 +15,16 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.logger.Logger;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
public class JSurfaceView extends SurfaceView implements Runnable, SurfaceHolder.Callback {
private static final String TAG = "JSurfaceView";
private SurfaceHolder mHolder;
/**
@@ -33,6 +40,15 @@ public class JSurfaceView extends SurfaceView implements Runnable, SurfaceHolder
*/
private int[] mFrames;
// 使用 BitmapFactory.Option.inBitmap 属性复用 bitmap 对象
private Bitmap mContainerBitmap = null;
// mContainerBitmap 是否生效
private boolean mContainerBitmapStatus = true;
// mContainerBitmapStatus 为 false 时,使用该缓存方案
private Map< Integer, WeakReference< Bitmap > > mBitmapRefMap = new HashMap<>();
public JSurfaceView( Context context ) {
super( context );
init();
@@ -87,28 +103,60 @@ public class JSurfaceView extends SurfaceView implements Runnable, SurfaceHolder
private void drawBitmap() {
//获取画布并锁定
Canvas mCanvas = mHolder.lockCanvas();
if ( mCanvas == null ) {
Canvas canvas = mHolder.lockCanvas();
if ( canvas == null ) {
return;
}
//绘制透明色
mCanvas.drawColor( Color.TRANSPARENT, PorterDuff.Mode.CLEAR );
Bitmap mBitmap = BitmapFactory.decodeResource( getResources(), mFrames[mCurrentPos % mFrames.length] );
canvas.drawColor( Color.TRANSPARENT, PorterDuff.Mode.CLEAR );
int factPosition = mCurrentPos % mFrames.length;
if ( mContainerBitmapStatus ) {
if ( mContainerBitmap == null ) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
mContainerBitmap = BitmapFactory.decodeResource( getResources(), mFrames[factPosition], options );
} else {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
options.inBitmap = mContainerBitmap;
try {
BitmapFactory.decodeResource( getResources(), mFrames[factPosition], options );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
mContainerBitmapStatus = false;
mContainerBitmap = null;
}
}
}
if ( !mContainerBitmapStatus ) {
WeakReference< Bitmap > ref = mBitmapRefMap.get( factPosition );
if ( ref != null && ref.get() != null && !ref.get().isRecycled() ) {
mContainerBitmap = ref.get();
} else {
mContainerBitmap = BitmapFactory.decodeResource( getResources(), mFrames[factPosition] );
mBitmapRefMap.put( factPosition, new WeakReference<>( mContainerBitmap ) );
}
}
if ( mContainerBitmap == null || mContainerBitmap.isRecycled() ) {
return;
}
Paint paint = new Paint();
Rect mSrcRect = new Rect( 0,
0,
mBitmap.getWidth(),
mBitmap.getHeight() ); // 图片绘制
mContainerBitmap.getWidth(),
mContainerBitmap.getHeight() ); // 图片绘制
Rect mDestRect = new Rect( 0,
0,
getWidth(),
getHeight() );// 图片绘制位置
mCanvas.drawBitmap( mBitmap, mSrcRect, mDestRect, paint );
canvas.drawBitmap( mContainerBitmap, mSrcRect, mDestRect, paint );
//解锁画布并展示bitmap到surface
mHolder.unlockCanvasAndPost( mCanvas );
mBitmap.recycle();
mHolder.unlockCanvasAndPost( canvas );
}
@Override

View File

@@ -1,7 +1,6 @@
package com.mogo.module.main;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.FrameLayout;
@@ -112,11 +111,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
}
}
@Override
public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels ) {
super.onPageScrolled( position, positionOffset, positionOffsetPixels );
}
@Override
public void onPageScrollStateChanged( int state ) {
super.onPageScrollStateChanged( state );
@@ -143,6 +137,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
properties.put( "appname", provider.getAppName() );
properties.put( "packagename", provider.getAppPackage() );
properties.put( "activeTime", System.currentTimeMillis() - mCardStartShowTime );
properties.put( "type", provider.getModuleName() );
mAnalytics.track( "Launcher_Card_Show", properties );
mCardStartShowTime = System.currentTimeMillis();
}
@@ -157,6 +152,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
Map< String, Object > properties = new HashMap<>();
properties.put( "appname", provider.getAppName() );
properties.put( "packagename", provider.getAppPackage() );
properties.put( "type", provider.getModuleName() );
mAnalytics.track( "Launcher_Card_Slide", properties );
}
} );

View File

@@ -32,6 +32,10 @@ import com.mogo.service.map.IMogoMapService;
import com.mogo.service.statusmanager.IMogoStatusManager;
import com.mogo.utils.logger.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -263,6 +267,8 @@ public class MarkerServiceHandler {
lastMarker = null;
getMarkerManager().removeMarkers();
JSONArray array = new JSONArray();
// 解析不同的Marker类型然后对应的进行绘制
if (response != null && response.getResult() != null) {
MarkerCardResult markerCardResult = response.getResult();
@@ -301,7 +307,7 @@ public class MarkerServiceHandler {
drawMapMarker(markerShowEntity);
}
analyticData(3, onlineCarList.size());
fillNumberTrackEventBody(array, 3, onlineCarList.size());
}
if (exploreWayList != null) {
@@ -318,7 +324,7 @@ public class MarkerServiceHandler {
drawMapMarker(markerShowEntity);
}
}
analyticData(1, exploreWayList.size());
fillNumberTrackEventBody(array, 1, exploreWayList.size());
}
if (shareMusicList != null) {
@@ -334,7 +340,7 @@ public class MarkerServiceHandler {
drawMapMarker(markerShowEntity);
}
analyticData(4, shareMusicList.size());
fillNumberTrackEventBody(array, 4, shareMusicList.size());
}
if (noveltyInfoList != null) {
@@ -373,27 +379,42 @@ public class MarkerServiceHandler {
break;
}
}
analyticData(2, num_gas_station);
analyticData(6, num_road_closed);
analyticData(5, num_traffic_check);
analyticData(7, num_shop_discount);
analyticData(8, num_fours_shop);
fillNumberTrackEventBody(array,2, num_gas_station);
fillNumberTrackEventBody(array,6, num_road_closed);
fillNumberTrackEventBody(array,5, num_traffic_check);
fillNumberTrackEventBody(array,7, num_shop_discount);
fillNumberTrackEventBody(array,8, num_fours_shop);
}
analyticData(array);
}
}
private static void fillNumberTrackEventBody(JSONArray arr, int type, int size){
JSONObject object = new JSONObject( );
try {
object.put( "type", type );
object.put( "num", size);
if ( arr != null ) {
arr.put( object );
}
} catch ( JSONException e ) {
e.printStackTrace();
}
getMapUIController().changeZoom(12);
}
/**
* 统计地图内数据获取
*
* @param type 类型
* @param num marker数量
* @param array 埋点数据
*/
private static void analyticData(int type, int num) {
private static void analyticData(JSONArray array) {
try {
if ( array == null || array.length() == 0 ) {
return;
}
final Map<String, Object> properties = new HashMap<>();
properties.put("type", type);
properties.put("num", num);
properties.put("data", array.toString());
getMogoAnalytics().track("Launcher_Data_Get", properties);
} catch (Exception e) {
e.printStackTrace();
@@ -411,14 +432,14 @@ public class MarkerServiceHandler {
MogoMarkerOptions options = new MogoMarkerOptions()
.owner(markerShowEntity.getMarkerType())
.alpha( 0.7f )
.object( markerShowEntity )
.latitude(markerShowEntity.getMarkerLocation().getLat())
.longitude(markerShowEntity.getMarkerLocation().getLon());
options.icon(markerView);
IMogoMarker marker = getMarkerManager().addMarker(markerShowEntity.getMarkerType(), options);
marker.setOnMarkerClickListener(mogoMarkerClickListener);
marker.setObject(markerShowEntity);
marker.setAlpha(0.7f);
return marker;
} else {
Logger.e(TAG, "Location 必须进行初始化!!!!!");

View File

@@ -116,7 +116,7 @@ public class MogoServiceProvider implements IMogoModuleProvider,
case ServiceConst.MSG_TYPE_REFRESH_DECREASE:
mRefreshRemainingTime -= ServiceConst.DECREASE_INTERVAL;
if ( mRefreshRemainingTime == 0 ) {
notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback );
notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback );
} else {
mHandler.sendEmptyMessageDelayed( msg.what, ServiceConst.DECREASE_INTERVAL );
}
@@ -435,11 +435,11 @@ public class MogoServiceProvider implements IMogoModuleProvider,
// 自动刷新触发
if ( mLastAutoRefreshLocation == null ) {
mLastAutoRefreshLocation = new MogoLatLng( location.getLatitude(), location.getLongitude() );
notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback );
notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback );
} else {
float distance = Utils.calculateLineDistance( mLastAutoRefreshLocation, new MogoLatLng( location.getLatitude(), location.getLongitude() ) );
if ( distance > mAutoRefreshStrategy.getDistance() ) {
notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback );
notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback );
}
}
}

View File

@@ -30,7 +30,7 @@ public class MogoReceiver extends BroadcastReceiver {
/**
* ADAS
*/
public static final String ADAS_ACTION = "com.mogo.launcher.adas";
public static final String ADAS_ACTION = "com.zhidao.autopilot.adas";
// ADAS 状态 0 - 关闭 1 - 打开
public static final String PARAM_ADAS_STATUS = "adas_drawer_status";