From 9fb2ca5f0f793564b1d67ceeb30c537231de797a Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 1 Jun 2016 13:13:25 +0300 Subject: [PATCH 1/2] update scala, android sbt plugin, etc. --- .gitignore | 3 ++- AndroidManifest.xml | 4 +++- README.md | 10 ++++++---- build.sbt | 16 ++++++++-------- project/build.scala | 1 + project/plugins.sbt | 4 ++-- 6 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 project/build.scala diff --git a/.gitignore b/.gitignore index deab002..0c4705a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ gen/ .idea .idea_modules target/ -libmmcamera_imx179_mod/imx179_patch \ No newline at end of file +libmmcamera_imx179_mod/imx179_patch +project/build.properties diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 0a56969..ed16ea9 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -12,7 +13,8 @@ + android:allowBackup="true" + tools:replace="android:label"> diff --git a/README.md b/README.md index 165179f..b2c1d40 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Screenshot](screenshot.jpg?raw=true) -**L Camera** is an open-source experimental camera app for Android L devices using the new `android.hardware.camera2` API. Currently, the only supported device is Nexus 5 and Nexus 6 running Android 5.0 Lollipop. +**L Camera** is an open-source experimental camera app for Android L (and newer) devices using the new `android.hardware.camera2` API. Currently, supported devices include Nexus 5, 6, 5X and 6P running Android 5.0 Lollipop and 6.0 Marshmallow. *Please note that this app is intended to test and study new features of the camera API, it is not for general uses as it lacks many basic camera features (location tagging, white balance, photo review, flash control, etc).* @@ -116,15 +116,17 @@ The app is written in the [Scala](http://www.scala-lang.org/) programming langua ### How to build -You must have both **scala 2.11.5** and **sbt >= 0.13** installed. +You must have both **scala 2.11.8** and **sbt >= 0.13** installed. +Also, you must ensure that sbt runs with JDK 7, not 8. +For example, `sbt -java-home `/usr/libexec/java_home -v 1.7` on OS X. To build the app (the resulting APK will be placed in the `bin/` directory): - $ sbt package + $ sbt android:package To build and run the app on device (assuming you have `adb` and developer mode enabled): - $ sbt run + $ sbt android:run ### Debugging diff --git a/build.sbt b/build.sbt index e377c3f..66b15e7 100644 --- a/build.sbt +++ b/build.sbt @@ -1,11 +1,9 @@ import android.Keys._ import android.Dependencies.aar -android.Plugin.androidBuild - name := "lcamera" -scalaVersion := "2.11.5" +scalaVersion := "2.11.8" resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/" @@ -20,9 +18,9 @@ libraryDependencies ++= Seq( platformTarget in Android := "android-21" proguardCache in Android ++= - Seq ( ProguardCache("org.scaloid") % "org.scaloid" %% "scaloid" - , ProguardCache("rx") % "com.scalarx" %% "scalarx" - , ProguardCache("akka") % "com.typesafe.akka" %% "akka-actor" + Seq ( "org.scaloid.scaloid" + , "com.scalarx.scalarx" + , "com.typesafe.akka.akka-actor" ) proguardOptions in Android ++= @@ -33,10 +31,12 @@ proguardOptions in Android ++= , "-dontwarn sun.misc.Unsafe" ) -scalacOptions in Compile ++= Seq("-feature", "-deprecation", "-Xlint", "-Xfuture", "-Ywarn-dead-code", "-Ywarn-unused") +scalacOptions ++= Seq("-target:jvm-1.7", "-feature", "-deprecation", "-Xlint", "-Xfuture", "-Ywarn-dead-code", "-Ywarn-unused") + +javacOptions ++= Seq("-source", "1.7") run <<= run in Android install <<= install in Android -Keys.`package` <<= `packageT` in Android +//Keys.`package` <<= `packageT` in Android diff --git a/project/build.scala b/project/build.scala new file mode 100644 index 0000000..b30922a --- /dev/null +++ b/project/build.scala @@ -0,0 +1 @@ +object Build extends android.AutoBuild diff --git a/project/plugins.sbt b/project/plugins.sbt index 42e50a5..fc150d4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" -addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.3.5") +addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.3") addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT") -libraryDependencies += "net.sf.proguard" % "proguard-base" % "5.0" +libraryDependencies += "net.sf.proguard" % "proguard-base" % "5.2.1" From 7f5687d820cf48dec42d137c1cde5ee119d32d38 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 1 Jun 2016 14:02:34 +0300 Subject: [PATCH 2/2] Fix orientation calculation Take into account the sensor's base rotation instead of hardcoded values for Nexus 5/6. No more upside-down photos on 5X/6P! Thanks: https://stackoverflow.com/a/31881371 --- src/pkmx/lcamera/MainActivity.scala | 30 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/pkmx/lcamera/MainActivity.scala b/src/pkmx/lcamera/MainActivity.scala index 973f922..631a177 100644 --- a/src/pkmx/lcamera/MainActivity.scala +++ b/src/pkmx/lcamera/MainActivity.scala @@ -117,7 +117,7 @@ object Utils { setVideoSize(vc.width, vc.height) setVideoEncodingBitRate(vc.bitrate) setVideoFrameRate(vc.fps) - setOrientationHint(orientationToDegree(orientation)) + setOrientationHint(orientation) setOutputFile(tmpFilePath) setVideoEncoder(2) // H264 setAudioEncoder(3) // AAC @@ -130,14 +130,6 @@ object Utils { def renameFile(src: String, dst: String): Unit = { new File(src).renameTo(new File(dst)) } - def orientationToDegree(orientation: Int) = orientation match { - case Surface.ROTATION_0 => 90 - case Surface.ROTATION_90 => 0 - case Surface.ROTATION_180 => 270 - case Surface.ROTATION_270 => 180 - case _ => 0 - } - def createPathIfNotExist(path: String): String = { val file = new File(path) if (!file.exists()) { @@ -436,7 +428,7 @@ class LCamera (private[this] val camera: CameraDevice) (implicit cameraManager: setupRequest(request, focus, exposure) request.set_(LENS_OPTICAL_STABILIZATION_MODE, LENS_OPTICAL_STABILIZATION_MODE_ON) request.set_(JPEG_QUALITY, 100.toByte) - request.set_(JPEG_ORIENTATION, orientationToDegree(orientation)) + request.set_(JPEG_ORIENTATION, orientation) request.set_(STATISTICS_LENS_SHADING_MAP_MODE, STATISTICS_LENS_SHADING_MAP_MODE_ON) // Required for RAW capture List(previewSurface, jpegSurface, rawSurface) foreach request.addTarget @@ -727,7 +719,17 @@ class MainActivity extends SActivity with Observable { val userVideoConfiguration = Var(videoConfigurations(0)) val videoConfiguration = Rx { availableVideoConfigurations() find { _ == userVideoConfiguration() } orElse availableVideoConfigurations().lift(0) } - val orientationVar = Var(windowManager.getDefaultDisplay.getRotation) + def orientationToDegree(orientation: Int) = orientation match { + case Surface.ROTATION_0 => 0 + case Surface.ROTATION_90 => 90 + case Surface.ROTATION_180 => 180 + case Surface.ROTATION_270 => 270 + case _ => 0 + } + + val screenOrientationVar = Var(windowManager.getDefaultDisplay.getRotation) + val cameraOrientationVar: Rx[Integer] = Rx { lcamera().map(_.characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION)).getOrElse(0) } + val orientationVar: Rx[Integer] = Rx { (cameraOrientationVar() - orientationToDegree(screenOrientationVar()) + 360) % 360 } val orientationEventListener = new OrientationEventListener(this) { override def onOrientationChanged(deg: Int) = { @@ -739,8 +741,8 @@ class MainActivity extends SActivity with Observable { else Surface.ROTATION_0 debug(newOrientation.toString) - if (orientationVar() != newOrientation) { - orientationVar() = newOrientation // FIXME: Re-create video session + if (screenOrientationVar() != newOrientation) { + screenOrientationVar() = newOrientation // FIXME: Re-create video session } } } @@ -1324,4 +1326,4 @@ class MainActivity extends SActivity with Observable { ta.recycle() resId } -} \ No newline at end of file +}