我有一个传感器管理器,它rotationMatrix根据设备Magnetometer和Accelerometer 返回一个.我一直试图计算用户设备的偏航俯仰和滚动,但我发现俯仰和滚动相互干扰并给出不准确的结果.有没有办法从rotationMatrix?提取设备的YAW PITCH和ROLL ?
编辑 试着解释下面的blender的答案,我感谢但还没到那里,我试图从这样的旋转矩阵中获得角度:
float R[] = phoneOri.getMatrix();
double rmYaw = Math.atan2(R[4], R[0]);
double rmPitch = Math.acos(-R[8]);
double rmRoll = Math.atan2(R[9], R[10]);
Run Code Online (Sandbox Code Playgroud)
我不知道我是否引用矩阵的错误部分,但我没有得到我想的结果.
我希望得到度数的价值,但我得到奇怪的整数.
我的矩阵来自我的sensorManager看起来像这样:
public void onSensorChanged(SensorEvent evt) {
int type=evt.sensor.getType();
if(type == Sensor.TYPE_ORIENTATION){
yaw = evt.values[0];
pitch = evt.values[1];
roll = evt.values[2];
}
if (type == Sensor.TYPE_MAGNETIC_FIELD) {
orientation[0]=(orientation[0]*1+evt.values[0])*0.5f;
orientation[1]=(orientation[1]*1+evt.values[1])*0.5f;
orientation[2]=(orientation[2]*1+evt.values[2])*0.5f;
} else if (type == Sensor.TYPE_ACCELEROMETER) {
acceleration[0]=(acceleration[0]*2+evt.values[0])*0.33334f;
acceleration[1]=(acceleration[1]*2+evt.values[1])*0.33334f;
acceleration[2]=(acceleration[2]*2+evt.values[2])*0.33334f;
}
if ((type==Sensor.TYPE_MAGNETIC_FIELD) || (type==Sensor.TYPE_ACCELEROMETER)) {
float newMat[]=new float[16]; …Run Code Online (Sandbox Code Playgroud) 下面是我在Android应用程序中的自定义编辑文本字段的屏幕截图.当您键入给定单词时,您当前键入的单词的文本以灰色突出显示,并将文本显示为黑色,直到您点击空格键,此时文本将按预期变为白色.有没有办法更改突出显示的颜色和突出显示的文本?

我的编辑文本xml看起来像这样
<EditText
android:id="@+id/searchField"
android:layout_width="160dp"
android:layout_height="44dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="60dp"
android:background="@null"
android:cursorVisible="true"
android:ems="10"
android:textColor="@color/white"
android:textColorHighlight ="#ff0000"
android:textCursorDrawable="@null" >
</EditText>
Run Code Online (Sandbox Code Playgroud)
整个布局
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!--
As the main content view, the view below consumes the entire
space available using match_parent in both dimensions.
-->
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff" >
<fragment
android:id="@+id/map"
android:name="com.sapientnitro.inhouse.drop.components.DRPCustomMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/btn_center_local"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="50dp"
android:layout_marginRight="15dp"
android:background="@drawable/btn_center_on_local_up" />
<RelativeLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#ddffffff" >
<ImageButton
android:id="@+id/btn_menu"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp" …Run Code Online (Sandbox Code Playgroud) 我试图获得当前wifi连接的信号强度 getRssi()
private void checkWifi(){
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo Info = cm.getActiveNetworkInfo();
if (Info == null || !Info.isConnectedOrConnecting()) {
Log.i("WIFI CONNECTION", "No connection");
} else {
int netType = Info.getType();
int netSubtype = Info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
wifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getLinkSpeed();
int rssi = wifiManager.getConnectionInfo().getRssi();
Log.i("WIFI CONNECTION", "Wifi connection speed: "+linkSpeed + " rssi: "+rssi);
//Need to get wifi strength
}
}
}
Run Code Online (Sandbox Code Playgroud)
事情是我得到像-35或-47等数字...我不明白他们的价值观..我已经看了android文档及其所有状态:
public int getRssi()
从以下版本开始:API Level 1返回当前802.11网络的接收信号强度指示符.
这不是规范化的,但应该是!
返回RSSI,范围是??? 至 …
我正在创建一个利用下面的DrawingSurfaceView类的绘图应用程序.在那个类中,我有一个Paint Called橡皮图画,用户可以打开和关闭..当在那个画面上假设橡皮擦的路径是什么.但它只是画了一条黑线..
当我将画布保存为透明png时,橡皮擦是正确的,但在屏幕上显示黑色..
用于在blob上写"Erik"的EraserPaint手机屏幕截图
从画布中保存了PNG

eraserPaint看起来像这样:
eraserPaint = new Paint();
eraserPaint.setAlpha(0);
eraserPaint.setColor(Color.TRANSPARENT);
eraserPaint.setStrokeWidth(60);
eraserPaint.setStyle(Style.STROKE);
eraserPaint.setMaskFilter(null);
eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
eraserPaint.setAntiAlias(true);
Run Code Online (Sandbox Code Playgroud)
整个班级
public KNDrawingSurfaceView(Context c, float width, float height, KNSketchBookActivity parent) {
super(c);
myWidth = width;
myHeight = height;
mBitmap = Bitmap.createBitmap((int) myWidth, (int) myHeight, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
_parent = parent;
mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
tile = new Paint();
tileImage = BitmapFactory.decodeResource(getResources(), R.drawable.checkerpattern);
shader = new BitmapShader(tileImage, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
tile.setShader(shader);
mPath = …Run Code Online (Sandbox Code Playgroud) 我写了一个非常简单的accessibilityService,我试图在Settings/accessibility /我的应用程序中显示该服务的描述.下面是我的所有代码,应将描述设置为"Hello!" 但设置仍显示"无可用说明"

我的服务:
public class IdleService extends AccessibilityService{
int interval = 100;
int maxIdleTime = 20000;
int idleTime = 0;
Handler mHandler;
String cProcess;
@Override
public void onServiceConnected(){
mHandler = new Handler();
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
// we are interested in all types of accessibility events
info.describeContents();
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
// we want to receive events in a certain interval
info.notificationTimeout = interval;
setServiceInfo(info);
Log.e("IdleService", " idle service connected!");
statusChecker.run();
} …Run Code Online (Sandbox Code Playgroud) 这里有趣的问题,想知道是否有人遇到过它.
我正在构建一个Android应用程序,它有一些特殊字符作为文本(主要是日文字符),我们的设计师需要一些战略性的软回报,因为较小的设备的宽度限制,文本需要包装.
问题是因为文本基本上是日语,所以单词之间没有空格.
我知道我们可以使用\u200b零宽度空间产生这样的字符串:
ABCDEF\u200bghijklmnop
当有足够的空间时,出现这样的情况:
abcdefghijklmnop
如果它需要换行,就像这样:
abcdef
ghijklmnop
问题是,如果不使用标准英文字符,我们使用日语字符似乎不起作用.我们根本没有软线.无论我们把它放在哪里,它总是会在空间不足的地方突破\u200b
ヘルプヘルプ\ u200bヘルプヘルプ
结果是:
ルヘプルヘプルヘプヘ
ルプ
有没有人以前处理过这个问题或有任何关于如何解决这个问题的想法?
我有一个cameraPreview类(见下文),它正在启动全屏和横向......但是图像变得拉伸/扭曲..有没有办法让这个预览保持全屏而不是扭曲?
camLayer:
public class CamLayer extends SurfaceView implements SurfaceHolder.Callback {
Camera camera;
SurfaceHolder previewHolder;
String camID;
private static final String TAG = "Cam Preview";
public CamLayer(Context context, String facing)
{
super(context);
camID = facing;
previewHolder = this.getHolder();
previewHolder.addCallback(this);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
startCamera();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
Parameters params = camera.getParameters();
//params.setPreviewSize(width, height);
//params.setPictureFormat(PixelFormat.JPEG);
camera.setParameters(params);
camera.startPreview();
}
public void surfaceDestroyed(SurfaceHolder arg0)
{
stopCamera();
}
public void onResume() { …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的android项目中创建一个用于我的图像按钮的形状,它基本上有左半边和右边的半圆.
我以为我可以使用半径为的形状XML.但是这只是围绕着我需要整个左右两侧的角落,如下图所示.
我当前形状的xml如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:color="@color/white">
<corners
android:radius="60dip"
/>
<stroke
android:width="0dp"
android:color="#000000" />
<solid
android:color="@color/white" />
</shape>
Run Code Online (Sandbox Code Playgroud)
但我想尝试这个效果:

我想知道是否有办法在不知道其名称的情况下获取JSONObject的第一个子节点的值:
我有一些JSON进来了一个名为的节点, this_guy
{"this_guy": {"some_name_i_wont_know":"the value i care about"}}
Run Code Online (Sandbox Code Playgroud)
使用JSONObject,如果我不知道孩子的名字,怎么能干净利落地得到"我关心的价值".我所知道的只是"this_guy",有人吗?
我正在使用mp4Parser isoviewer-1.0-RC-35.jar来组合使用android MediaRecorder录制的剪辑.通过聆听音轨,剪辑似乎正确组合,但视频保持在一帧上,时间码在播放时保持为零.
媒体记录器创建单个剪辑时的代码
mediaRecorder = new MediaRecorder();
myCamera.lock();
myCamera.unlock();
String clipLocation = file.getAbsolutePath();
_moviePaths.add(clipLocation);
// Please maintain sequence of following code.
// If you change sequence it will not work.
mediaRecorder.setCamera(myCamera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
if (facingBack) {
mediaRecorder.setOrientationHint(90);
} else {
mediaRecorder.setOrientationHint(270);
}
// Log.v("cam","supported vid sizes: "+
// myCamera.getParameters().getSupportedVideoSizes());
CamcorderProfile profile = CamcorderProfile
.get(CamcorderProfile.QUALITY_720P);
// mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
// mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setMaxDuration(g.kMaxVideoDurationInMiliseconds);// 15seconds
mediaRecorder.setProfile(profile);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.setOutputFile(path + filename);
mediaRecorder.prepare();
startTimer();
mediaRecorder.start();
}
Run Code Online (Sandbox Code Playgroud)
我用来组合剪辑的方法:
protected void combineClips() throws IOException{
for(int i=0; …Run Code Online (Sandbox Code Playgroud) android ×9
java ×2
android-a11y ×1
android-wifi ×1
android-xml ×1
jsonobject ×1
line-breaks ×1
mp4parser ×1
paint ×1
textview ×1