kopia lustrzana https://github.com/sh123/codec2_talkie
rodzic
6c3700809a
commit
e6a05091d9
|
@ -53,7 +53,8 @@ public class MapActivity extends AppCompatActivity {
|
||||||
private boolean _rotateMap = false;
|
private boolean _rotateMap = false;
|
||||||
private boolean _shouldFollowLocation = false;
|
private boolean _shouldFollowLocation = false;
|
||||||
|
|
||||||
private String _info;
|
private String _positionInfo;
|
||||||
|
private double _prevBearing = 0.0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -66,11 +67,6 @@ public class MapActivity extends AppCompatActivity {
|
||||||
|
|
||||||
Context context = getApplicationContext();
|
Context context = getApplicationContext();
|
||||||
Configuration.getInstance().setUserAgentValue(Aprs.APRS_ID + " " + BuildConfig.VERSION_NAME);
|
Configuration.getInstance().setUserAgentValue(Aprs.APRS_ID + " " + BuildConfig.VERSION_NAME);
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
|
|
||||||
// my symbol
|
|
||||||
AprsSymbolTable aprsSymbolTable = AprsSymbolTable.getInstance(context);
|
|
||||||
String mySymbolCode = sharedPreferences.getString(PreferenceKeys.APRS_SYMBOL, "/[");
|
|
||||||
|
|
||||||
// map
|
// map
|
||||||
_mapView = findViewById(R.id.map);
|
_mapView = findViewById(R.id.map);
|
||||||
|
@ -100,7 +96,7 @@ public class MapActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location, IMyLocationProvider source) {
|
public void onLocationChanged(Location location, IMyLocationProvider source) {
|
||||||
super.onLocationChanged(location, source);
|
super.onLocationChanged(location, source);
|
||||||
_info = String.format(Locale.US, "%dkm/h, %d°, %dm, %s, %f, %f",
|
_positionInfo = String.format(Locale.US, "%dkm/h, %d°, %dm, %s, %f, %f",
|
||||||
UnitTools.metersPerSecondToKilometersPerHour((int)location.getSpeed()),
|
UnitTools.metersPerSecondToKilometersPerHour((int)location.getSpeed()),
|
||||||
(int)location.getBearing(),
|
(int)location.getBearing(),
|
||||||
(int)location.getAltitude(),
|
(int)location.getAltitude(),
|
||||||
|
@ -108,12 +104,21 @@ public class MapActivity extends AppCompatActivity {
|
||||||
location.getLatitude(),
|
location.getLatitude(),
|
||||||
location.getLongitude()
|
location.getLongitude()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
double currentBearing = location.getBearing();
|
||||||
|
|
||||||
|
if (_prevBearing > 180 && currentBearing <= 180)
|
||||||
|
updateMyIcon(false);
|
||||||
|
else if (_prevBearing <= 180 && currentBearing > 180)
|
||||||
|
updateMyIcon(true);
|
||||||
|
|
||||||
|
_prevBearing = currentBearing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas pCanvas, MapView pMapView, boolean pShadow) {
|
public void draw(Canvas pCanvas, MapView pMapView, boolean pShadow) {
|
||||||
super.draw(pCanvas, pMapView, pShadow);
|
super.draw(pCanvas, pMapView, pShadow);
|
||||||
if (_info == null || !_shouldFollowLocation) return;
|
if (_positionInfo == null || !_shouldFollowLocation) return;
|
||||||
|
|
||||||
// create paint
|
// create paint
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
|
@ -122,7 +127,7 @@ public class MapActivity extends AppCompatActivity {
|
||||||
|
|
||||||
// query bounds from text
|
// query bounds from text
|
||||||
Rect bounds = new Rect();
|
Rect bounds = new Rect();
|
||||||
paint.getTextBounds(_info, 0, _info.length(), bounds);
|
paint.getTextBounds(_positionInfo, 0, _positionInfo.length(), bounds);
|
||||||
|
|
||||||
// draw background
|
// draw background
|
||||||
paint.setColor(Color.WHITE);
|
paint.setColor(Color.WHITE);
|
||||||
|
@ -137,17 +142,12 @@ public class MapActivity extends AppCompatActivity {
|
||||||
paint.setColor(Color.BLACK);
|
paint.setColor(Color.BLACK);
|
||||||
paint.setAlpha(255);
|
paint.setAlpha(255);
|
||||||
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
||||||
pCanvas.drawText(_info, pCanvas.getWidth() - bounds.width(), bounds.height(), paint);
|
pCanvas.drawText(_positionInfo, pCanvas.getWidth() - bounds.width(), bounds.height(), paint);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Bitmap myBitmapIcon = aprsSymbolTable.bitmapFromSymbol(mySymbolCode, true);
|
|
||||||
if (AprsSymbolTable.needsRotation(mySymbolCode)) {
|
// set own icon
|
||||||
Matrix matrix = new Matrix();
|
updateMyIcon(false);
|
||||||
matrix.postRotate(-90);
|
|
||||||
myBitmapIcon = Bitmap.createBitmap(myBitmapIcon, 0, 0, myBitmapIcon.getWidth(), myBitmapIcon.getHeight(), matrix, true);
|
|
||||||
}
|
|
||||||
_myLocationNewOverlay.setDirectionIcon(myBitmapIcon);
|
|
||||||
_myLocationNewOverlay.setPersonIcon(myBitmapIcon);
|
|
||||||
|
|
||||||
// my location overlay
|
// my location overlay
|
||||||
_myLocationNewOverlay.enableMyLocation();
|
_myLocationNewOverlay.enableMyLocation();
|
||||||
|
@ -161,6 +161,28 @@ public class MapActivity extends AppCompatActivity {
|
||||||
_mapStations = new MapStations(context, _mapView, this);
|
_mapStations = new MapStations(context, _mapView, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateMyIcon(boolean shouldFlip) {
|
||||||
|
Context context = getApplicationContext();
|
||||||
|
Configuration.getInstance().setUserAgentValue(Aprs.APRS_ID + " " + BuildConfig.VERSION_NAME);
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
|
// my symbol
|
||||||
|
AprsSymbolTable aprsSymbolTable = AprsSymbolTable.getInstance(context);
|
||||||
|
String mySymbolCode = sharedPreferences.getString(PreferenceKeys.APRS_SYMBOL, "/[");
|
||||||
|
|
||||||
|
Bitmap myBitmapIcon = aprsSymbolTable.bitmapFromSymbol(mySymbolCode, true);
|
||||||
|
if (AprsSymbolTable.needsRotation(mySymbolCode)) {
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.postRotate(-90);
|
||||||
|
if (shouldFlip) {
|
||||||
|
matrix.postScale(-1, 1, myBitmapIcon.getWidth() / 2f, myBitmapIcon.getHeight() / 2f);
|
||||||
|
}
|
||||||
|
myBitmapIcon = Bitmap.createBitmap(myBitmapIcon, 0, 0, myBitmapIcon.getWidth(), myBitmapIcon.getHeight(), matrix, true);
|
||||||
|
}
|
||||||
|
_myLocationNewOverlay.setDirectionIcon(myBitmapIcon);
|
||||||
|
_myLocationNewOverlay.setPersonIcon(myBitmapIcon);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.map_menu, menu);
|
getMenuInflater().inflate(R.menu.map_menu, menu);
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class BitmapTools {
|
||||||
Rect bounds = new Rect();
|
Rect bounds = new Rect();
|
||||||
paint.getTextBounds(text, 0, text.length(), bounds);
|
paint.getTextBounds(text, 0, text.length(), bounds);
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
|
||||||
bitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
|
bitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
|
Ładowanie…
Reference in New Issue