Skip to content

Commit

Permalink
Merge pull request #54 from ricohapi/dev/1.6.0
Browse files Browse the repository at this point in the history
update to 1.6.0. formatted code.
  • Loading branch information
ywatanabe-dev authored Nov 21, 2023
2 parents e99decb + 7d58003 commit 0a84a53
Show file tree
Hide file tree
Showing 49 changed files with 566 additions and 576 deletions.
2 changes: 1 addition & 1 deletion demos/demo-android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies {
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation 'io.coil-kt:coil-compose:2.2.2'
implementation "io.ktor:ktor-client-cio:2.1.3"
implementation "com.ricoh360.thetaclient:theta-client:1.5.0"
implementation "com.ricoh360.thetaclient:theta-client:1.6.0"

testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.ricoh360.thetaclient.thetaClientDemo

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
25 changes: 13 additions & 12 deletions demos/demo-android/app/src/main/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html lang="en">

<head>
<meta charset="utf-8" />
<meta charset="utf-8"/>

<!-- In regard to the settings blow, see https://www.marzipano.net/reference/ -->
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui" />
<style>
<!-- In regard to the settings blow, see https://www.marzipano.net/reference/ -->
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui"/>
<style>
@-ms-viewport {
width: device-width;
}
Expand All @@ -21,16 +21,17 @@
-webkit-touch-callout: none;
-ms-content-zooming: none;
}
</style>

</style>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<p>Preparing to display a photo.</p>
<div id="root"></div>
<script src="bundle.js"></script>
<script src="rxjs.umd.js"></script>
<script src="index.js"></script>
<noscript>You need to enable JavaScript to run this app.</noscript>
<p>Preparing to display a photo.</p>
<div id="root"></div>
<script src="bundle.js"></script>
<script src="rxjs.umd.js"></script>
<script src="index.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.ricoh360.thetaclient.thetaClientDemo

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.Dp
Expand All @@ -26,7 +33,7 @@ fun PhotoListScreen(
toPhoto: (fileName: String, photoUrl: String) -> Unit,
viewModel: ThetaViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
) {
val oscInfo : ThetaRepository.ThetaInfo? by viewModel.thetaInfoState.collectAsState(initial = null)
val oscInfo: ThetaRepository.ThetaInfo? by viewModel.thetaInfoState.collectAsState(initial = null)
val thetaFiles: ThetaRepository.ThetaFiles? by viewModel.thetaFilesState.collectAsState(initial = null)

ThetaSimpleAndroidAppTheme {
Expand All @@ -40,9 +47,11 @@ fun PhotoListScreen(
thetaFiles?.also {
val thumbWidth = 100.dp
val pad = 24.dp
LazyColumn(modifier = Modifier
.fillMaxSize()
.padding(pad)) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(pad)
) {
items(it.fileList) { file ->
Row(horizontalArrangement = Arrangement.Center) {
ThumbnailImage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.ricoh360.thetaclient.thetaClientDemo
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import com.ricoh360.thetaclient.thetaClientDemo.ui.theme.ThetaSimpleAndroidAppTheme
import timber.log.Timber

Expand All @@ -19,7 +19,7 @@ fun PhotoScreen(fileName: String?, photoUrl: String?) {
ThetaSimpleAndroidAppTheme {
Scaffold(
topBar = {
TopAppBar(title = { Text(fileName?: "") })
TopAppBar(title = { Text(fileName ?: "") })
}
) {
photoUrl?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.FabPosition
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Scaffold
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
Expand All @@ -16,7 +19,10 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
import com.ricoh360.thetaclient.ThetaRepository
import com.ricoh360.thetaclient.capture.PhotoCapture
import com.ricoh360.thetaclient.thetaClientDemo.ui.theme.ThetaSimpleAndroidAppTheme
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import timber.log.Timber

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ricoh360.thetaclient.DigestAuth
import com.ricoh360.thetaclient.ThetaRepository
import com.ricoh360.thetaclient.capture.PhotoCapture
import io.ktor.client.utils.*
Expand All @@ -26,10 +25,10 @@ class ThetaViewModel(
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
) : ViewModel() {
private var thetaRepository: ThetaRepository
private val _thetaInfoState = MutableStateFlow<ThetaRepository.ThetaInfo?>(null)
private val _thetaInfoState = MutableStateFlow<ThetaRepository.ThetaInfo?>(null)
val thetaInfoState: StateFlow<ThetaRepository.ThetaInfo?> = _thetaInfoState
private val _thetaFilesState = MutableStateFlow<ThetaRepository.ThetaFiles?>(null)
val thetaFilesState: StateFlow<ThetaRepository.ThetaFiles?> = _thetaFilesState
val thetaFilesState: StateFlow<ThetaRepository.ThetaFiles?> = _thetaFilesState

private val _previewFlow = MutableStateFlow<Bitmap?>(null)
val previewFlow: StateFlow<Bitmap?> = _previewFlow
Expand Down Expand Up @@ -97,7 +96,7 @@ class ThetaViewModel(
previewJob = viewModelScope.launch(ioDispatcher) {
runCatching {
thetaRepository.getLivePreview { frame: Pair<ByteArray, Int> ->
if(!isActive) {
if (!isActive) {
Timber.d("Terminate preview")
return@getLivePreview false
}
Expand All @@ -112,7 +111,7 @@ class ThetaViewModel(
}
}

fun stopPreview () {
fun stopPreview() {
previewJob?.let {
it.cancel()
previewJob = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,33 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
import android.view.ViewGroup
import android.webkit.*
import android.webkit.JavascriptInterface
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebSettings
import android.webkit.WebView
import androidx.compose.foundation.layout.fillMaxSize
import androidx.webkit.WebViewClientCompat
import androidx.webkit.WebViewAssetLoader
import androidx.webkit.WebResourceErrorCompat
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView

import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.http.*
import androidx.webkit.WebResourceErrorCompat
import androidx.webkit.WebViewAssetLoader
import androidx.webkit.WebViewClientCompat
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.cio.CIO
import io.ktor.client.request.get
import io.ktor.http.isSuccess
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.io.ByteArrayOutputStream
import java.util.*
import java.util.Base64

/**
* Viewer for equirectangular image
Expand Down Expand Up @@ -70,7 +78,7 @@ fun Viewer360Core(photoDataUrl: String) {
/**
* Injecting object to WebView's JavaScript.
*/
class JsObject() {
class JsObject {
@JavascriptInterface
fun getPhotoUrl(): String {
Timber.d("called getPhotoUrl(): ${photoDataUrl.substring(0, 40)}...")
Expand Down Expand Up @@ -125,7 +133,7 @@ fun Viewer360Core(photoDataUrl: String) {
WebView(context).apply {
settings.allowFileAccess = true
settings.javaScriptEnabled = true
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE)
settings.mixedContentMode = WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
addJavascriptInterface(JsObject(), "injectedObject")
webViewClient = LocalContentWebViewClient(assetLoader)
layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
Expand Down Expand Up @@ -164,7 +172,7 @@ suspend fun getPhotoDataUrl(photoUrl: String): String? = withContext(Dispatchers
var dataUrl: String? = null
HttpClient(CIO).use { httpClient ->
val response = httpClient.get(photoUrl)
if(response.status.isSuccess()) {
if (response.status.isSuccess()) {
val byteArray: ByteArray = response.body()
dataUrl = DATA_URL_PREFIX + Base64.getEncoder().encodeToString(downSizeImage(byteArray))
} else {
Expand Down Expand Up @@ -201,7 +209,7 @@ fun downSizeImage(image: ByteArray): ByteArray {
}
BitmapFactory.decodeByteArray(image, 0, image.size, options)
Timber.d("Jpeg width; ${options.outWidth}")
if(options.outWidth > MAX_WIDTH) {
if (options.outWidth > MAX_WIDTH) {
val scaleFactor = MAX_WIDTH / options.outWidth.toFloat()
val scale = Matrix()
scale.postScale(scaleFactor, scaleFactor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.ricoh360.thetaclient.thetaClientDemo

import com.ricoh360.thetaclient.ThetaRepository
import com.ricoh360.thetaclient.capture.PhotoCapture
import com.ricoh360.thetaclient.thetaClientDemo.ThetaViewModel
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -34,15 +33,15 @@ internal class ThetaViewModelTest {
assertNotNull(files, "thetaFilesState")
}

/*
@Test
@kotlinx.coroutines.ExperimentalCoroutinesApi
fun previewTest() = runTest {
vm.startPreview()
val bitmap = vm.previewFlow.drop(1).first()
assertNotNull(bitmap, "preview")
vm.stopPreview()
} */
/*
@Test
@kotlinx.coroutines.ExperimentalCoroutinesApi
fun previewTest() = runTest {
vm.startPreview()
val bitmap = vm.previewFlow.drop(1).first()
assertNotNull(bitmap, "preview")
vm.stopPreview()
} */

@Test
fun shootingTest() = runTest {
Expand Down
16 changes: 8 additions & 8 deletions demos/demo-flutter/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import UIKit
import Flutter
import UIKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Loading

0 comments on commit 0a84a53

Please sign in to comment.