Skip to content

Commit

Permalink
Prepare for public release
Browse files Browse the repository at this point in the history
Change-Id: I0c2186bf2a8dddd2b695c06439d9dd3f4e49fba8
  • Loading branch information
owahltinez committed May 3, 2019
1 parent d512f9c commit 5d538ac
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CameraXBasic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CameraXbasic

CameraXbasic aims to demonstrate how to use CameraX APIs written in Kotlin
CameraXbasic aims to demonstrate how to use CameraX APIs written in Kotlin.

## Build

Expand Down
3 changes: 2 additions & 1 deletion CameraXBasic/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<activity
android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:icon="@mipmap/ic_launcher">

<!-- Main app intent filter -->
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.android.example.cameraxbasic.utils.FLAGS_FULLSCREEN

const val KEY_EVENT_ACTION = "key_event_action"
const val KEY_EVENT_EXTRA = "key_event_extra"
private const val IMMERSIVE_FLAG_TIMEOUT = 500L

/**
* Main entry point into our app. This app follows the single-activity pattern, and all
Expand All @@ -48,7 +49,7 @@ class MainActivity : AppCompatActivity() {
// be trying to set app to immersive mode before it's ready and the flags do not stick
container.postDelayed({
container.systemUiVisibility = FLAGS_FULLSCREEN
}, 500)
}, IMMERSIVE_FLAG_TIMEOUT)
}

/** When key down event is triggered, relay it via local broadcast so fragments can handle it */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ import com.android.example.cameraxbasic.KEY_EVENT_ACTION
import com.android.example.cameraxbasic.KEY_EVENT_EXTRA
import com.android.example.cameraxbasic.MainActivity
import com.android.example.cameraxbasic.R
import com.android.example.cameraxbasic.utils.*
import com.android.example.cameraxbasic.utils.ANIMATION_FAST_MILLIS
import com.android.example.cameraxbasic.utils.ANIMATION_SLOW_MILLIS
import com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder
import com.android.example.cameraxbasic.utils.ImageUtils
import com.android.example.cameraxbasic.utils.simulateClick
import com.bumptech.glide.Glide
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -221,13 +225,6 @@ class CameraFragment : Fragment(), CoroutineScope {
val filter = IntentFilter().apply { addAction(KEY_EVENT_ACTION) }
LocalBroadcastManager.getInstance(context!!).registerReceiver(volumeDownReceiver, filter)

// Setup view finder click listeners to enable auto-focus
viewFinder.setOnClickListener {

// Find coordinates of position on screen
// TODO: b/129455282
}

// Determine the output directory
outputDirectory = MainActivity.getOutputDirectory(requireContext())

Expand Down Expand Up @@ -306,7 +303,7 @@ class CameraFragment : Fragment(), CoroutineScope {
}

/** Method used to re-draw the camera UI controls, called every time configuration changes */
@SuppressLint("RestrictedApi") // TODO b/129910338: We shouldn't use restricted APIs
@SuppressLint("RestrictedApi")
private fun updateCameraUi() {

// Remove previous UI if any
Expand Down Expand Up @@ -334,8 +331,6 @@ class CameraFragment : Fragment(), CoroutineScope {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

// Display flash animation to indicate that photo was captured
// TODO b/129909364: This would be better done immediately after capture finishes
// TODO b/128249518: Play a sound to indicate capture succeeded
container.postDelayed({
container.foreground = ColorDrawable(Color.WHITE)
container.postDelayed({ container.foreground = null }, ANIMATION_FAST_MILLIS)
Expand All @@ -345,8 +340,11 @@ class CameraFragment : Fragment(), CoroutineScope {

// Listener for button used to switch cameras
controls.findViewById<ImageButton>(R.id.camera_switch_button).setOnClickListener {
lensFacing = if (CameraX.LensFacing.FRONT == lensFacing)
CameraX.LensFacing.BACK else CameraX.LensFacing.FRONT
lensFacing = if (CameraX.LensFacing.FRONT == lensFacing) {
CameraX.LensFacing.BACK
} else {
CameraX.LensFacing.FRONT
}
try {
// Only bind use cases if we can query a camera with this orientation
CameraX.getCameraWithLensFacing(lensFacing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.fragment.app.Fragment
import com.android.example.cameraxbasic.MainActivity
import com.android.example.cameraxbasic.utils.ImageUtils
import com.bumptech.glide.Glide
import java.io.File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.view.ViewGroup
import androidx.camera.core.Preview
import androidx.camera.core.PreviewConfig
import java.lang.IllegalArgumentException
import java.lang.RuntimeException
import java.lang.ref.WeakReference
import java.util.Objects

Expand Down Expand Up @@ -85,11 +84,11 @@ class AutoFitPreviewBuilder private constructor(config: PreviewConfig,
val viewFinder =
viewFinderRef.get() ?: return@OnPreviewOutputUpdateListener

// FIXME: Start workaround for b/129998710
// To update the SurfaceTexture, we have to remove it and re-add it
val parent = viewFinder.parent as ViewGroup
parent.removeView(viewFinder)
parent.addView(viewFinder, 0)
// FIXME: End workaround for b/129998710

viewFinder.surfaceTexture = it.surfaceTexture
bufferRotation = it.rotationDegrees
val rotation = getDisplaySurfaceRotation(viewFinder.display)
Expand Down

0 comments on commit 5d538ac

Please sign in to comment.