Skip to content

Commit

Permalink
Merge pull request #2 from ricohapi/feature/v1.0.1
Browse files Browse the repository at this point in the history
update
  • Loading branch information
KATSUYA2 authored May 20, 2022
2 parents ebfc372 + f03feb7 commit d990e56
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# THETA X Plug-in : Camera API Sample

Version: 1.0.0
Version: 1.0.1

This sample project shows how to implement a plug-in using Camera API for RICOH THETA X.
The program language is Kotlin, please checkout [java branch](https://github.com/ricohapi/theta-plugin-camera-api-sample-x/tree/java) to see Java code.

## Contents

Expand All @@ -27,6 +28,7 @@ This sample project shows how to implement a plug-in using Camera API for RICOH
> * ② Button to execute take picture
> * ③ Button to execute start / stop video recording
> * ④ Texture View to show preview picture
> * ⑨ Spinner to choose RIC_SHOOTING_MODE for preview mode
> * ⑤ Spinner to choose RIC_SHOOTING_MODE for image mode
> * ⑥ Spinner to choose RIC_SHOOTING_MODE for video mode
> * ⑦ Spinner to choose RIC_PROC_STITCHING
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.theta360.sample.camera"
minSdkVersion 25
targetSdkVersion 29
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.0.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
67 changes: 59 additions & 8 deletions app/src/main/java/com/theta360/sample/camera/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*

class MainActivity : PluginActivity() {
class MainActivity : PluginActivity(), MediaRecorder.OnInfoListener {
companion object {
private val RIC_SHOOTING_MODE = "RIC_SHOOTING_MODE"
private val RIC_PROC_STITCHING = "RIC_PROC_STITCHING"
Expand Down Expand Up @@ -53,6 +53,10 @@ class MainActivity : PluginActivity() {
private var isMultiShot: Boolean = false
private var isLongShutter: Boolean = false

private var mLcdBrightness: Int = 64
private var mLedPowerBrightness: IntArray = intArrayOf(0, 0, 0, 64) //(dummy,R,G,B)
private var mLedStatusBrightness: IntArray = intArrayOf(0, 0, 0, 64) //(dummy,R,G,B)

override fun onCreate(savedInstanceState: Bundle?) {
Log.i(TAG,"onCreate")
super.onCreate(savedInstanceState)
Expand All @@ -63,6 +67,7 @@ class MainActivity : PluginActivity() {
val switch_camera: Switch = findViewById<Switch>(R.id.switch_camera)
val button_image: Button = findViewById<Button>(R.id.button_image)
val button_video: Button = findViewById<Button>(R.id.button_video)
val spinner_ric_shooting_mode_preview: Spinner = findViewById<Spinner>(R.id.spinner_ric_shooting_mode_preview)
val spinner_ric_shooting_mode_image: Spinner = findViewById<Spinner>(R.id.spinner_ric_shooting_mode_image)
val spinner_ric_shooting_mode_video: Spinner = findViewById<Spinner>(R.id.spinner_ric_shooting_mode_video)
val spinner_ric_proc_stitching: Spinner = findViewById<Spinner>(R.id.spinner_ric_proc_stitching)
Expand Down Expand Up @@ -105,9 +110,11 @@ class MainActivity : PluginActivity() {
//Button : take picture
button_image.setEnabled(false)
button_image.setOnClickListener { _ ->
switch_camera.isClickable = false
enableAllButtons(false)
executeTakePicture()
if (button_image.isEnabled) {
switch_camera.isClickable = false
enableAllButtons(false)
executeTakePicture()
}
}

//Button : start and stop video recording
Expand All @@ -132,6 +139,7 @@ class MainActivity : PluginActivity() {
}

//Spinner : set Camera Parameters
spinner_ric_shooting_mode_preview.setSelection(0) //RicPreview1024
spinner_ric_shooting_mode_image.setSelection(0) //RicStillCaptureStd
spinner_ric_shooting_mode_video.setSelection(1) //RicMovieRecording3840
spinner_ric_proc_stitching.setSelection(2) //RicDynamicStitchingAuto
Expand Down Expand Up @@ -174,6 +182,13 @@ class MainActivity : PluginActivity() {
}
}

override fun onInfo(mr: MediaRecorder, what: Int, extra: Int) {
//Log.d(TAG, "onInfo() : what=" + what + ", extra=" + extra)
if (what == MediaRecorder.MEDIA_RECORDER_EVENT_RECORD_STOP) {
notificationAudioMovStop()
}
}

//
// folder path and file path related functions
//
Expand Down Expand Up @@ -288,6 +303,7 @@ class MainActivity : PluginActivity() {
fun executeTakePicture() {
Log.i(TAG,"executeTakePicture")
//executeStopPreview()
turnOnOffLcdLed(false)
notificationAudioSelf()
mCamera!!.apply {
setCameraParameters(MODE.IMAGE)
Expand Down Expand Up @@ -348,6 +364,7 @@ class MainActivity : PluginActivity() {
notificationAudioClose()
}
isLongShutter = false
turnOnOffLcdLed(true)
}
}

Expand All @@ -358,7 +375,9 @@ class MainActivity : PluginActivity() {
setCameraParameters(MODE.VIDEO)
}

mRecorder = MediaRecorder().apply {
mRecorder = MediaRecorder()
mRecorder?.setOnInfoListener(this)
mRecorder!!.apply {
//Context
setMediaRecorderContext(getApplicationContext())
//Audio Setting
Expand Down Expand Up @@ -425,7 +444,6 @@ class MainActivity : PluginActivity() {
fun stopVideoRecording() {
Log.i(TAG,"stopVideoRecording")
mRecorder!!.apply {
notificationAudioMovStop()
stop()
release()
}
Expand All @@ -437,6 +455,7 @@ class MainActivity : PluginActivity() {
fun releaseMediaRecorder() {
Log.i(TAG,"releaseMediaRecorder")
if (mRecorder != null) {
mRecorder?.setOnInfoListener(null)
mRecorder!!.release()
mRecorder = null
}
Expand All @@ -455,8 +474,13 @@ class MainActivity : PluginActivity() {

when (mode) {
MODE.PREVIEW -> {
p.set(RIC_SHOOTING_MODE, "RicPreview1024")
p.setPreviewSize(1024, 512)
val shooting_mode: String = findViewById<Spinner>(R.id.spinner_ric_shooting_mode_preview).selectedItem.toString()
when (shooting_mode) {
"RicPreview1024" -> { p.setPreviewSize(1024, 512) }
"RicPreview1920" -> { p.setPreviewSize(1920, 960) }
"RicPreview3840" -> { p.setPreviewSize(3840, 1920) }
"RicPreview5760" -> { p.setPreviewSize(5760, 2880) }
}
p.setPreviewFrameRate(30)
}
MODE.IMAGE -> {
Expand Down Expand Up @@ -484,6 +508,7 @@ class MainActivity : PluginActivity() {
// UI related functions
//
fun enableAllSpinners(flag: Boolean) {
findViewById<Spinner>(R.id.spinner_ric_shooting_mode_preview).isEnabled = flag
findViewById<Spinner>(R.id.spinner_ric_shooting_mode_image).isEnabled = flag
findViewById<Spinner>(R.id.spinner_ric_shooting_mode_video).isEnabled = flag
findViewById<Spinner>(R.id.spinner_ric_proc_stitching).isEnabled = flag
Expand All @@ -501,4 +526,30 @@ class MainActivity : PluginActivity() {
enableButton(button_image, flag)
enableButton(button_video, flag)
}

fun turnOnOffLcdLed(flag: Boolean) {
//turn on LCD and LED
if (flag) {
mCamera!!.apply {
ctrlLcdBrightness(mLcdBrightness)
for (i in 1..3) {
ctrlLedPowerBrightness(i, mLedPowerBrightness[i])
ctrlLedStatusBrightness(i, mLedStatusBrightness[i])
}
}
}
//turn off LCD and LED
else {
mCamera!!.apply{
mLcdBrightness = lcdBrightness
ctrlLcdBrightness(0)
for (i in 1..3) {
mLedPowerBrightness[i] = getLedPowerBrightness(i)
mLedStatusBrightness[i] = getLedStatusBrightness(i)
ctrlLedPowerBrightness(i, 0)
ctrlLedStatusBrightness(i, 0)
}
}
}
}
}
15 changes: 14 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner_ric_proc_zenith_correction" />

<Spinner
android:id="@+id/spinner_ric_shooting_mode_preview"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:entries="@array/RIC_SHOOTING_MODE_PREVIEW_ARRAY"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/texture_view" />

<Spinner
android:id="@+id/spinner_ric_shooting_mode_image"
android:layout_width="0dp"
Expand All @@ -67,7 +80,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/texture_view" />
app:layout_constraintTop_toBottomOf="@+id/spinner_ric_shooting_mode_preview" />

<Spinner
android:id="@+id/spinner_ric_shooting_mode_video"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<resources>
<string name="app_name">Camera API Sample</string>
<string-array name="RIC_SHOOTING_MODE_PREVIEW_ARRAY">
<item>RicPreview1024</item>
<item>RicPreview1920</item>
<item>RicPreview3840</item>
<item>RicPreview5760</item>
</string-array>
<string-array name="RIC_SHOOTING_MODE_IMAGE_ARRAY">
<item>RicStillCaptureStd</item>
<item>RicStillCaptureMultiRawNR</item>
Expand Down
Binary file modified ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d990e56

Please sign in to comment.