在这里,我们将给大家分享关于android–Rajawali旋转相机与Sensor.TYPE_ROTATION_VECTOR奇怪的行为的知识,让您更了解旋转相机app的本质,同时也会涉及到如何更有效地
在这里,我们将给大家分享关于android – Rajawali旋转相机与Sensor.TYPE_ROTATION_VECTOR奇怪的行为的知识,让您更了解旋转 相机app的本质,同时也会涉及到如何更有效地android Conflict with dependency 'com.android.support:support-annotations' in project ':app'.、android DialogFragment出现 Can not perform this action after onSaveInstanceState、Android getActiveNotifications抛出SecurityException、Android OnLongClickListener奇怪/不可靠的行为的内容。
本文目录一览:- android – Rajawali旋转相机与Sensor.TYPE_ROTATION_VECTOR奇怪的行为(旋转 相机app)
- android Conflict with dependency 'com.android.support:support-annotations' in project ':app'.
- android DialogFragment出现 Can not perform this action after onSaveInstanceState
- Android getActiveNotifications抛出SecurityException
- Android OnLongClickListener奇怪/不可靠的行为
android – Rajawali旋转相机与Sensor.TYPE_ROTATION_VECTOR奇怪的行为(旋转 相机app)
我正在创建一个全景视图,允许用户通过旋转智能手机环顾一下球形图像.我将Rajawali的SkyBox与TYPE_ROTATION_VECTOR传感器一起使用.
我得到了它的工作,但只有当我向前看时(它实际上是基于我的旋转(偏航))
这是行为:
>期待:yaw = yaw,pitch = pitch and roll = roll
>向左看:yaw = yaw,pitch = roll and roll = pitch
>向后看:yaw = yaw,pitch = pitch * -1和roll = roll * -1.
现在我确实有预感正在发生什么.似乎“相机对象”一直看着相同的方向,即使它看起来不是这样.这意味着俯仰似乎与滚动相同,但是它仍然在俯仰,因为物体没有旋转.我把它比作飞机上的四处看看.
我需要做些什么来解决这个问题?
我有一种感觉,我将不得不用lookAt()旋转相机,但我不知道如何.
public class SkyBoxFragment extends RajawaliFragment implements SensorEventListener {
public static final String TAG = "SkyBoxFragment";
private SensorManager mSensorManager;
private float[] orientationVals = new float[3];
private float[] mRotationMatrix = new float[16];
private Sensor mRotVectSensor;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
LinearLayout ll = new LinearLayout(getActivity());
ll.setorientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
mSensorManager = (SensorManager) getActivity().getSystemService(
Context.SENSOR_SERVICE);
mRotVectSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
mLayout.addView(ll);
mSensorManager.registerListener(this,
mRotVectSensor,
10000);
return mLayout;
}
@Override
public AExampleRenderer createRenderer() {
mRenderer = new SkyBoxRenderer(getActivity());
return ((SkyBoxRenderer) mRenderer);
}
@Override
public void onClick(View v) {
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, mRotationMatrix);
SensorManager.getorientation(mRotationMatrix, orientationVals);
orientationVals[0] = (float) Math.todegrees(orientationVals[0]);
orientationVals[1] = (float) Math.todegrees(orientationVals[1]) * -1;
orientationVals[2] = (float) Math.todegrees(orientationVals[2]) * -1;
//Log.d(TAG, "YAW:" + orientationVals[0] + " PITCH:" + orientationVals[1] + "ROLL:" + orientationVals[2]);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
private final class SkyBoxRenderer extends AExampleRenderer implements View.OnClickListener {
private final Vector3 mAccValues;
boolean odd = true;
public SkyBoxRenderer(Context context) {
super(context);
mAccValues = new Vector3();
}
@Override
protected void initScene() {
getCurrentCamera().setFarPlane(1000);
/**
* SkyBox images by Emil PeRSSon, aka Humus. http://www.humus.name humus@comhem.se
*/
try {
getCurrentScene().setSkyBox(R.drawable.posx, R.drawable.negx,
R.drawable.posy, R.drawable.negy, R.drawable.posz, R.drawable.negz);
} catch (ATexture.TextureException e) {
e.printstacktrace();
}
}
@Override
protected void onRender(long ellapsedRealtime, double deltaTime) {
super.onRender(ellapsedRealtime, deltaTime);
getCurrentCamera().setRotation(orientationVals[2], orientationVals[0], orientationVals[1]);
}
@Override
public void onClick(View v) {
try {
if (odd) {
/**
* SkyBox images by Emil PeRSSon, aka Humus. http://www.humus.name humus@comhem.se
*/
getCurrentScene().updateSkyBox(R.drawable.posx2, R.drawable.negx2,
R.drawable.posy2, R.drawable.negy2, R.drawable.posz2, R.drawable.negz2);
} else {
/**
* SkyBox images by Emil PeRSSon, aka Humus. http://www.humus.name humus@comhem.se
*/
getCurrentScene().updateSkyBox(R.drawable.posx, R.drawable.negx,
R.drawable.posy, R.drawable.negy, R.drawable.posz, R.drawable.negz);
}
} catch (Exception e) {
e.printstacktrace();
} finally {
odd = !odd;
}
}
public void setAccelerometerValues(float x, float y, float z) {
mAccValues.setAll(-x, -y, -z);
}
}
}
解决方法:
你有两个问题.首先是您要描述的问题,但另一个问题是TYPE_ROTATION_VECTOR的传感器会受到附近磁铁的影响,例如手机外壳中的磁铁.
解决磁铁问题
解决方案可以是使用加速度计和陀螺仪的组合.幸运的是,Google Cardboard SDK已经将其抽象了.
您可以通过使用HeadTracker.createFromContext(this.getActivity())实例化com.google.vrtoolkit.cardboard.sensors.HeadTracker的实例并在其上调用startTracking()来跟踪当前轮换.
现在你不再需要onSensorChanged了.相反,在你的onRender中,你可以这样做:
float[] R = new float[16];
headTracker.getLastHeadView(R, 0);
获得旋转矩阵.这解决了您未说明的磁场问题.
让相机正确环顾四周
使用此旋转矩阵将摄像机指向正确方向的最简单方法是将其转换为org.rajawali3d.math.Quaternion,然后调用getCurrentCamera().setCameraOrientation(quaternion);
从float [16]到四元数的转换可能很难正确,但Google Cardboard SDK再一次为您做到了.在这种情况下,它位于不再使用的旧类的源代码中:HeadTransform.
您可以轻松地调整该代码以返回新的Quaternion(w,x,y,z);.
现在,如果没有将orientationVals [1]和orientationVals [2]乘以-1,则会产生与当前代码相同的问题.
然而,通过反转旋转矩阵可以很容易地解决该问题.这将导致onRender中的以下代码(假设getQuaternion(R)返回org.rajawali3d.math.Quaternion):
@Override
protected void onRender(long ellapsedRealtime, double deltaTime) {
super.onRender(ellapsedRealtime, deltaTime);
float[] R = new float[16];
headTracker.getLastHeadView(R, 0);
android.opengl.Matrix.invertM(R, 0, R, 0);
Quaternion q = getQuaternion(R);
getCurrentCamera().setCameraOrientation(q);
}
android Conflict with dependency 'com.android.support:support-annotations' in project ':app'.
如题所示 只是新建了一个项目就报这个错了。
问题 以后解决了如下:
这样就可以了。但是原因了我还是不知道。我也没有修改或者升级什么东西。。知道原因的大佬请告知一下。
转载自:https://blog.csdn.net/qq_33313551/article/details/80240332
android DialogFragment出现 Can not perform this action after onSaveInstanceState
在使用android的DialogFragment的时候如果实在Activity在后台的时候调用dismiss函数的时候会出现Can not perform this action after onSaveInstanceState的异常,这个异常跟activity状态被保存之后又尝试提交一个 FragmentTransaction,原因是因为DialogFragment在调用dismiss函数的时候需要提交一个FragmentTransaction事务,但是在 onSaveInstanceState()函数调用之后,提交事务就会导致状态丢失,这样就会出现异常。不同的系统显示异常的方式不同。
为了避免这个问题就是在Activity在后台时或者onSaveInstanceState()和onStop()方法被调用后,就不直接调用dismiss函数改调用dismissAllowingStateLoss。还有一种方式是把这个DialogFragment状态记录下俩在Activity 启动 的时候在调用dismiss函数。
Android getActiveNotifications抛出SecurityException
我在NotificationService中使用AsyncTask来获取通知.代码如下.
private class AsyncProcessNotification extends AsyncTask<Void,Void,Void> { @Override protected Void doInBackground(Void... params) { int notificationType = MainApplication.settingNotificationType; MainApplication.clearNotificationItems(); if (MainApplication.settingNotificationType == Constants.KEY_NOTIFICATION_TYPE_disABLED) { Log.i(TAG,"Notifications disabled"); return null; } if (PermissionHelper.isNotificationPermissionGranted(getApplicationContext())) { if (getActiveNotifications() == null || getActiveNotifications().length == 0) { Log.i(TAG,"No notifications found"); return null; } Log.i(TAG,"Getting " + getActiveNotifications().length +" notifications"); Log.i(TAG,"Notification type " + notificationType); for (StatusBarNotification statusBarNotification : getActiveNotifications()) { // Process notifications } } else { // } return null; } @Override protected void onPostExecute(Void result) { Intent notify = new Intent(Constants.ACTION_NOTIFICATION_LISTENER); sendbroadcast(notify); } }
奇怪的是根据
Crashlytics,有时它在if(getActiveNotifications()== null || getActiveNotifications().length == 0)失败,有时它在Log.i失败(TAG,“获取”getActiveNotifications().length“notifications”);
要检查权限,我使用以下方法.
public static boolean isNotificationPermissionGranted(Context context) { Set<String> appList = notificationmanagerCompat.getEnabledListenerPackages(context); for (String l:appList) { if (l.equals(context.getPackageName())) { return true; } } return false; }
堆栈跟踪:
Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:309) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by java.lang.SecurityException: disallowed call from unkNown notification listener: android.service.notification.INotificationListener$Stub$Proxy@3e9880d at android.os.Parcel.readException(Parcel.java:1599) at android.os.Parcel.readException(Parcel.java:1552) at android.app.Inotificationmanager$Stub$Proxy.getActiveNotificationsFromListener(Inotificationmanager.java:1046) at android.service.notification.NotificationListenerService.getActiveNotifications(NotificationListenerService.java:467) at android.service.notification.NotificationListenerService.getActiveNotifications(NotificationListenerService.java:420) at com.afd.app.lockscreen.ios11.lib.service.NotificationService$AsyncProcessNotification.doInBackground(NotificationService.java:120) at com.afd.app.lockscreen.ios11.lib.service.NotificationService$AsyncProcessNotification.doInBackground(NotificationService.java:97) at android.os.AsyncTask$2.call(AsyncTask.java:295) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
我知道我必须做一些愚蠢但却无法弄清楚是什么.有人可以帮忙吗?谢谢!
解决方法
I hit the same error in my notification listener service. I was able
to solve it by waiting for the listener service to get connected to the
notification manager before calling any of the
NotificationListenerService methods.
@Override public void onListenerConnected() { Log.i(TAG,"Listener connected"); listenerConnected = true; } private class AsyncProcessNotification extends AsyncTask<Void,Void> { protected Void doInBackground(Void... params) { ... // wait until our notification listener service is connected // to the notification manager Log.i(TAG,"Waiting for listener to be connected..."); while(!listenerConnected); // Call getActiveNotifications after this for (StatusBarNotification sbn : getActiveNotifications()) { processNotifications(sbn); } } // rest of the AsyncTask here }
Android OnLongClickListener奇怪/不可靠的行为
我目前正在与Android Api Lvl 8上的OnLongClickListener作战.
拿这个代码:
this.webView.setonLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
System.out.println("long click");
return true;
}
});
它完美地运作.我可以按下WebView上的任意位置,每次都触发事件触发器.
现在来看看这个:
this.webView.setonLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final EditText editText = getUrlTextField();
switch (editText.getVisibility()) {
case View.VISIBLE:
editText.setVisibility(View.GONE);
return true;
case View.GONE:
editText.setVisibility(View.VISIBLE);
return true;
default:
return false;
}
}
});
假设URL EditText组件当前可见,它将从显示中消失,并在触发另一个长按事件时再次显示.
但是如果你运行它,当一个人在WebView上的任何一个位置上执行长按时,该事件只运行一次(!).为了使事情变得复杂,当在网站上的链接上执行时,长按会再次起作用…
任何人都可以解释它是否是sdk中的错误和/或我是否认为OnLongClickListener是如何工作的? :/
编辑:
我现在已经在Nexus One上运行了几个不同的场景,并得出以下结论:在运行时或多或少地更改布局会杀死OnLongClickListener ……我还没有找到让它可靠地工作的方法……
我真的很感激,如果有人能给我一个提示……我在我的智慧结束:(
解决方法:
个人而言,我最终在每次重播后重新设置了听众.
今天关于android – Rajawali旋转相机与Sensor.TYPE_ROTATION_VECTOR奇怪的行为和旋转 相机app的分享就到这里,希望大家有所收获,若想了解更多关于android Conflict with dependency 'com.android.support:support-annotations' in project ':app'.、android DialogFragment出现 Can not perform this action after onSaveInstanceState、Android getActiveNotifications抛出SecurityException、Android OnLongClickListener奇怪/不可靠的行为等相关知识,可以在本站进行查询。
本文标签: