小编Dan*_*ith的帖子

如何编码多点触控

所以我正在开发一个必须处理多点触控的应用程序.基本上我想要单点旋转(这没问题).用于滚动的多点触控.

我有基本的代码,但是当从单一触摸转换到多点触控和副verca时,我遇到了问题.基本上,由于多点触控(两个手指)的中间位置和单个手指的绝对位置处于一定距离,因此运动将摇晃.因此,如果我在屏幕上有两个手指,它们构成一个中间位置,然后抬起一根手指,这就像从中间位置到绝对单指位置的快速移动.这将是我不想要的运动.

这是我的代码:

@Override
public boolean onTouchEvent( MotionEvent event ) {
    float xEvent[] = new float[ 2 ];
    float yEvent[] = new float[ 2 ];
    switch( event.getPointerCount() ) {
        case 1:
            xEvent[ 0 ] = event.getX( 0 );
            yEvent[ 0 ] = event.getY( 0 );
            switch( event.getAction() ) {
                case MotionEvent.ACTION_DOWN:
                    camera.onTouchDown( xEvent[ 0 ], yEvent[ 0 ] );
                    return true;
                case MotionEvent.ACTION_MOVE:
                    camera.onTouchRotate( xEvent[ 0 ], yEvent[ 0 ] );
                    return true;
                default: return super.onTouchEvent( event );
            }
        case …
Run Code Online (Sandbox Code Playgroud)

android multi-touch touch

8
推荐指数
1
解决办法
5603
查看次数

如何只使用一个附加行扩展InboxStyle通知?

我通过以下方式构建通知:

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(title);
for (int position = 0; position < onlineCounter; position++) {
    inboxStyle.addLine(onlineName.get(position) + " is online now");
}

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext());
notificationBuilder.setStyle(inboxStyle);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(contentText);
notificationBuilder.setNumber(cursor.getCount());
notificationBuilder.setSmallIcon(R.drawable.ic_stat_notify);
notificationBuilder.setColor(getResources().getColor(R.color.notification_color));
notificationBuilder.setLargeIcon(icon);

notificationBuilder.setContentIntent(launchIntent);
notificationBuilder.setDeleteIntent(clearIntent);
notificationBuilder.setDefaults(property);
notificationBuilder.setAutoCancel(true);
Run Code Online (Sandbox Code Playgroud)

当两行或多行附加到inboxStyle时,通知将展开,并在打开通知抽屉时自动显示所有附加行.

附加2行

但是,如果仅添加一行,则不会展开通知并且该行不可见.如何使线条自动可见?

附加1行

notifications android android-notifications android-5.0-lollipop

6
推荐指数
1
解决办法
5334
查看次数

Nexus 4上的极端相机滞后

使用以下非常简单的相机预览活动(来自此处的google示例),Nexus 4相机明显比设备的标准相机应用程序慢:

public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
      private Camera mCamera;
      private TextureView mTextureView;

      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          mTextureView = new TextureView(this);
          mTextureView.setSurfaceTextureListener(this);

          setContentView(mTextureView);
      }

      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
          mCamera = Camera.open();

          try {
              mCamera.setPreviewTexture(surface);
              mCamera.startPreview();
          } catch (IOException ioe) {
              // Something bad happened
          }
      }

      public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
          // Ignored, Camera does all the work for us
      }

      public boolean onSurfaceTextureDestroyed(SurfaceTexture …
Run Code Online (Sandbox Code Playgroud)

android android-camera nexus-4

5
推荐指数
1
解决办法
5312
查看次数

我在哪里可以找到Activity和gradle脚本的Android Studio模板?

我正在使用新的appCompat v22.1,我想更改Android Studio使用的模板.

目前,Android Studio模板创建的扩展活动ActionBarActivity已在v22.1中弃用.我想切换到AppCompatActivity每次都不改变代码.

是否可以在不等待下一次Android Studio更新的情况下更改它们?

android android-appcompat android-activity android-studio

5
推荐指数
1
解决办法
356
查看次数

ViewPagers的隐式Z-Ordering

我正在尝试实现一个ViewPager.PageTransformer几乎与此处标记的示例相同的DepthPageTransformer(它位于页面底部).

然而,除了具有层次结构遵循其中的z-index由左到右(即欣赏到右边会出现在下面)降低的模式,我想的z-index从左至右(浏览次数增加至左侧会从下面出现).

作为第一次尝试,我基本上交换了代表从左侧和右侧进入的页面的示例中的代码,但我发现有一个隐式的z排序,左边的页面总是在右边的页面之上,当你滑动以查看右边的页面时,它会滑动不错,但消失的视图将在新输入的视图的"顶部"消失.

有没有办法调整由a服务的页面的z-indices ViewPager

我的第一直觉是以某种方式复制ViewPager支持库中的代码,并修改类来进行我的出价,但我不清楚该类中隐含排序的来源.

这是我的(主要被扯掉)PageTransformer:

public class DepthPageTransformer implements ViewPager.PageTransformer {
    private static float MIN_SCALE = 0.75f;

    public void transformPage(View view, float position) {

        int pageWidth = view.getWidth();

        if (position < -1) { // [-Infinity,-1)
            // This page is way off-screen to the left.
            view.setAlpha(0);

        } else if (position <= 0) { // [-1,0]  
            view.setAlpha(1 + position);

            // Counteract the default slide transition …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager android-support-library

4
推荐指数
1
解决办法
2760
查看次数

即使在匹配视频大小和预览大小宽高比时,MediaRecorder也会失败

根据Camera.Parameters#getPreferredSizeForVideoPreview文档:

我们建议您选择与要录制的视频分辨率具有相同宽高比的预览尺寸

我发现,在某些设备(Galaxy S3)上,选择具有不同宽高比的视频录制尺寸确实会导致录制视频(绿色/紫色视频)的问题.

当我遵循文档的建议并坚持相同的宽高比时,它大部分都有效,但在某些设备(Nexus S/Android 4.0.4)上,调用MediaRecorder.start()失败并显示以下消息:

E/MediaRecorder? start failed: -19
Run Code Online (Sandbox Code Playgroud)

在其他设备(HTCEVOV4G/Android 4.0.3)上调用MediaRecorder.stop失败并显示以下消息:

E/MediaRecorder? stop failed: -1007
Run Code Online (Sandbox Code Playgroud)

但是,我确实发现,如果我MediaRecorder#setVideoSize使用与相机预览尺寸完全相同的尺寸进行调用,则视频录制将起作用.

video android aspect-ratio android-camera mediarecorder

2
推荐指数
1
解决办法
1020
查看次数

使用AVSpeechSynthesizer注册文本到语音回调

我在iOS 7(AVSpeechUtterance)中使用Text to speech.

有没有办法注册一个将在完成语音后调用的回调?

我需要知道,以便我可以在语音运行时禁用播放按钮,并在语音完成时重新启用按钮.

speech ios

2
推荐指数
1
解决办法
623
查看次数