小编Gio*_*ano的帖子

为什么在Android模拟器中将相机预览旋转90度?

我已将网络摄像头连接到仿真器,并且总是看到摄像头旋转了90度。

条形码扫描仪演示应用

我所做的只是将“ Webcam0”设置为要在模拟器中用作后置摄像头的设备。

背景:我正在尝试解决正在开发的使用ZXing的应用程序的问题:它无法扫描某些设备上的某些QR代码,并且我想知道它是否与我在模拟器上看到的内容有关。

在我们用来测试图像的设备上,是否正确显示了图像,但是在模拟器上却旋转了图像。除了让我怀疑它是否会在实际设备上引起麻烦外,它还使测试QR码扫描变得非常困难(即,当您在应用程序上垂直移动QR码时,它会水平移动,反之亦然)。

你知道如何解决吗?

提前致谢

camera android qr-code zxing android-emulator

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

我可以使用 FileChannel 独立地从不同线程查找文件吗?

我创建了一个可处理 FLV 文件的 Web 应用程序。

该应用程序使用我创建的一个库来解析 flv 文件的内容。该库使用 FileChannel 来查找文件。

现在,我从不同的线程中寻找相同的 flv 文件,因此遇到了一种奇怪的行为。假设Thread_1Thread_2都同时寻找movie.flv(我的问题出现在示例之后)。

线程_1

// Thread_1 moves to position 200 to read something
FileChannel chan1 = new FileInputStream("movie.flv").getFileChannel();
chan1.position(200);
Run Code Online (Sandbox Code Playgroud)

Thread_2 (在Thread_1之后执行)

// Thread_2 moves to position 600 to read something else
FileChannel chan2 = new FileInputStream("movie.flv").getFileChannel();
chan2.position(600);
Run Code Online (Sandbox Code Playgroud)

最后Thread_1执行以下操作:

ByteBuffer bb = ByteBuffer.allocate(40);
chan1.read(bb);
Run Code Online (Sandbox Code Playgroud)

Thread_1是从位置 200 还是从位置 600 读取 40 个字节?更准确地说,chan1chan2是否独立(=可以独立寻找)通道?

文档中我读到 FileChannel 是 …

java file-io multithreading nio

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

在AngularJS中,当同一形式的另一个值发生变化时,如何强制重新验证表单中的字段?

我有一个包含很少字段的表单,但是select和input字段是耦合的:输入的验证取决于用户在select字段中选择的值.

我将尝试用一个例子来澄清.假设选择包含行星的名称:

<select id="planet" class="form-control" name="planet" ng-model="planet" ng-options="c.val as c.label for c in planets"></select>
Run Code Online (Sandbox Code Playgroud)

在输入中,我通过名为"input-validation"的自定义指令应用自定义验证:

<input id="city" input-validation iv-allow-if="planet==='earth'" class="form-control" name="city" ng-model="city" required>
Run Code Online (Sandbox Code Playgroud)

这是指令:

.directive('inputValidation', [function() {
  return {
    require: 'ngModel',
    restrict: 'A',
    scope: {
      ivAllowIf: '='
    },
    link: function(scope, elm, attrs, ctrl) {
      ctrl.$parsers.unshift(function(viewValue) {

        //input is allowed if the attribute is not present or the expression evaluates to true
        var inputAllowed = attrs.ivAllowIf === undefined || scope.$parent.$eval(attrs.ivAllowIf);

        if (inputAllowed) {
          ctrl.$setValidity('iv', true);
          return viewValue;
        } else {
          ctrl.$setValidity('iv', …
Run Code Online (Sandbox Code Playgroud)

forms validation angularjs angularjs-directive

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

IntentService中的ExecutorService.它会被Android杀死吗?

我写了一个IntentService,我将用它来从网上下载一些重量数据(大多数是大图).

这个类看起来像这样:

public class UpdateService extends IntentService {

    public UpdateService() {
        super(UpdateService.class.getCanonicalName());
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        final ExecutorService executorService = Executors.newFixedThreadPool(3);
        List<ListenableFuture> futures = new ArrayList<>();

        for(Runnable r : getRunnables()){
            executorService.execute(r);
            futures.add(r.getFuture());
        }

        Futures.addCallback(

                Futures.allAsList( futures ),

                new FutureCallback<List<Boolean>>() {
                    @Override
                    public void onSuccess(List<Boolean> result) {
                        // do some logic here
                        executorService.shutdown();
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        // do some error handling here
                        executorService.shutdown();
                    }
                }
        );      

    }
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,该onHandleIntent()方法返回非常快,因为大多数活动都是在ExecutorService 执行的Runnables中执行的. …

java multithreading android intentservice

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