我的要求是像Google maps apps罗盘模式一样(点击时可以看到演示current location button twice):
compass模式下,地图始终旋转一个角度,以便bluedot arrow始终指向顶部屏幕.但我不知道如何计算正确的bearing距离azimuth, pitch, roll值.
public void onSensorChanged(SensorEvent sensorEvent) {
switch (sensorEvent.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
System.arraycopy(sensorEvent.values, 0, mAccelerometers, 0, 3);
break;
case Sensor.TYPE_MAGNETIC_FIELD:
System.arraycopy(sensorEvent.values, 0, mMagnetometers, 0, 3);
break;
default:
break;
}
float[] rotationMatrix = new float[9];
boolean success =
SensorManager.getRotationMatrix(rotationMatrix, null, mAccelerometers, mMagnetometers);
if (success) {
SensorManager.getOrientation(rotationMatrix, mOrientation);
float azimuth = Math.toDegrees(mOrientation[0]);
float pitch = Math.toDegrees(mOrientation[1]);
float roll = Math.toDegrees(mOrientation[2]);
} …Run Code Online (Sandbox Code Playgroud) 我正在使用GoogleFit HistoryAPI来获取用户的步骤数据.它运作良好.
但是,在我的情况下,我想区分不同设备之间的数据(使用相同的帐户),因为我不希望用户为2个或更多设备使用相同的帐户(这是一个基于步骤的游戏,所以我不想要用户在1台设备上玩,并在许多设备上取得成就).
我发现Device from DataSource#getDevice,Device#getLocalDevice可以帮助我区分不同设备之间的数据.以下是官方文档的信息:
要获取有关数据源的设备的信息,请使用DataSource.getDevice方法.设备信息可用于区分不同设备上的类似传感器,显示从传感器到用户的设备信息,或根据设备不同地处理数据.例如,您可能有兴趣专门从可穿戴设备上的传感器读取数据,而不是从手机上相同类型的传感器读取数据.
要为运行活动的设备获取Device实例,请使用Device.getLocalDevice静态方法.当您要检查数据源是否与运行应用程序的设备相同时,这非常有用.
所以,
// My idea is comparing the uid of local device and uid of device in datasource
// if it is same => step come from THIS device
// if not => step come from OTHER device
private void dumpDataSet(DataSet dataSet) {
for (DataPoint dp : dataSet.getDataPoints()) {
Log.i(Constant.TAG, "Origin type uid: " + dp.getOriginalDataSource().getDevice().getUid());
Log.i(Constant.TAG, "Local device uid: " + Device.getLocalDevice(getApplicationContext()).getUid());
...
}
}
Run Code Online (Sandbox Code Playgroud)
但是,仅来自 …
我正在为应用程序实现" Read Aloud"或" Talkback".一切都在使用contentDescription文本,但是通过选项菜单,我发现没有任何相关内容contentDescription,我希望系统读取"Menu "+ item's name.
EX:我的菜单有2个项目:" 创建新文件夹 "和" 删除当前文件夹 ",目前,当我关注菜单项(支持轨迹球和蓝牙键)时,系统可以准确地说出菜单的文本.但我希望它更像" 1:菜单创建新文件夹 "和" 2:菜单删除当前文件夹 ".
那么,我该如何更改阅读文本?menu item当蓝牙键盘UP/DOWN按键时,如何获得专注?
我有 3 个底部导航选项卡,称为Home, Dashboard, Profile.
Home,我有Fragment1和Fragment2,Dashboard,我有Fragment3和Fragment4Profile,我有MyProfile和EditProfile。现在,在 中Fragment2,一个按钮changeAvatar可以EditProfile在 stack 中打开Profile。因为EditProfile应该在 tab 中Profile,所以如果我不想包含EditProfile到navGraphof 中Home,我该如何实现这种行为?
navigation android android-architecture-navigation android-jetpack-navigation
我设置了锁定方向
并添加了2个简单类的示例代码,如下所示:
SplashLandscapeActivity.java
public class SplashLandscapeActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("start", "xxxx start Activity SplashLandscapeActivity");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashLandscapeActivity.this, TestActivity.class));
finish();
}
}, 500);
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("start", "xxxx onDestroy Activity SplashLandscapeActivity");
}
}
Run Code Online (Sandbox Code Playgroud)
TestActivity.java
public class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("start", "xxxx start Activity TestActivity "
+ getResources().getConfiguration().orientation);
}
@Override
protected void onDestroy() …Run Code Online (Sandbox Code Playgroud) 我想MapView通过sensor更改值进行旋转。但并没有Google Maps申请那么顺利。看来animate连续调用的方法会导致maps轴承不光滑。看来新的animateCamera调用会取消之前的调用animation,不是吗?我在下面的代码中做错了什么?我可以提高轴承性能吗?
mSensorManager.setOnDeviceRotationListener(bearing -> {
if (mCurrentLocation == null
|| Math.abs(mOldBearing - bearing) < ROTATION_THRESHOLD) { // atleast 5 degrees.
return;
}
mOldBearing = bearing;
LatLng target =
new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
CameraPosition oldCamera = mGoogleMap.getCameraPosition();
CameraPosition newCamera = CameraPosition.builder()
.zoom(Math.max(oldCamera.zoom, DEFAULT_MAP_COMPASS_ZOOM))
.target(target)
.tilt(DEFAULT_MAP_TILT)
.bearing(bearing)
.build();
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(newCamera));
}
Run Code Online (Sandbox Code Playgroud) android ×6
google-maps ×2
android-architecture-navigation ×1
animation ×1
google-fit ×1
menuitem ×1
navigation ×1
optionmenu ×1
talkback ×1