Skip to content

Commit

Permalink
Merge pull request #42 from ricohapi/dev/1.4.0
Browse files Browse the repository at this point in the history
Dev/1.4.0
  • Loading branch information
simago authored Sep 13, 2023
2 parents d6a5426 + 9d3a220 commit e3f10b4
Show file tree
Hide file tree
Showing 353 changed files with 28,368 additions and 12,823 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/dummy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Dummy for test

on:
workflow_dispatch:

jobs:
dummy:
if: ${{ false }}
runs-on: ubuntu-latest
steps:
- run: ""
2 changes: 1 addition & 1 deletion demos/demo-android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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.3.1"
implementation "com.ricoh360.thetaclient:theta-client:1.4.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
Expand Up @@ -73,15 +73,17 @@ class ThetaViewModel(
kotlin.runCatching {
thetaRepository.getLivePreview()
.collect { byteReadPacket ->
if (isActive) {
byteReadPacket.inputStream().use {
_previewFlow.emit(BitmapFactory.decodeStream(it))
}
ensureActive()
byteReadPacket.inputStream().use {
_previewFlow.emit(BitmapFactory.decodeStream(it))
}
byteReadPacket.release()
}
}.onFailure {
Timber.e(it)
when (it) {
is CancellationException -> Timber.i(it) // Preview coroutine was cancelled. No need to do anything.
else -> Timber.e(it)
}
}
}
}
Expand Down
27 changes: 19 additions & 8 deletions demos/demo-flutter/lib/capture_video_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class _CaptureVideoScreen extends State<CaptureVideoScreen> with WidgetsBindingO
}

void startVideoCapture() {
if (videoCapture == null) {
return;
}
if (shooting) {
debugPrint('already shooting');
return;
Expand All @@ -195,27 +198,34 @@ class _CaptureVideoScreen extends State<CaptureVideoScreen> with WidgetsBindingO
// Stops while shooting is in progress
stopLivePreview();

videoCapturing = videoCapture!.startCapture((fileUrl) {

videoCapturing = videoCapture?.startCapture((fileUrl) {
setState(() {
shooting = false;
});
debugPrint('capture video: $fileUrl');
if (!mounted) return;

final uri = Uri.parse(fileUrl);
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => VideoScreen(
name: uri.pathSegments.last,
fileUrl: fileUrl,
if (fileUrl != null) {
final uri = Uri.parse(fileUrl);
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => VideoScreen(
name: uri.pathSegments.last,
fileUrl: fileUrl,
)
)
)
).then((value) => startLivePreview());
).then((value) => startLivePreview());
}
}, (exception) {
setState(() {
shooting = false;
});
startLivePreview();
debugPrint(exception.toString());

}, onStopFailed: (exception) {
debugPrint(exception.toString());
MessageBox.show(context, 'Error. stopCapture.\n$exception');
});
}

Expand All @@ -224,6 +234,7 @@ class _CaptureVideoScreen extends State<CaptureVideoScreen> with WidgetsBindingO
debugPrint('Not start capture.');
return;
}
debugPrint("stopVideoCapture");
videoCapturing!.stopCapture();
}
}
22 changes: 21 additions & 1 deletion demos/demo-flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MyApp extends StatefulWidget {
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
String _platformVersion = 'Unknown';
final _thetaClientFlutter = ThetaClientFlutter();
bool _isInitTheta = false;
Expand All @@ -31,10 +31,30 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
initPlatformState();
initTheta();
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.inactive:
setState(() {
_isInitTheta = false;
});
break;
default:
break;
}
}

Future<void> initPlatformState() async {
String platformVersion;
try {
Expand Down
2 changes: 1 addition & 1 deletion demos/demo-ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ target 'SdkSample' do
use_frameworks!

# Pods for SdkSample
pod 'THETAClient', '1.3.1'
pod 'THETAClient', '1.4.0'
end
28 changes: 17 additions & 11 deletions demos/demo-ios/SdkSample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let purple_700: UIColor = UIColor(hex: "6200EE")

struct ContentView: View {
@State var getInfoError: Bool = false
@Environment(\.scenePhase) var scenePhase

init() {
let appearance = UINavigationBarAppearance()
Expand Down Expand Up @@ -37,24 +38,29 @@ struct ContentView: View {
.background(Color(purple_700))
.cornerRadius(10)
}
.onAppear() {
Task {
do {
try await theta.info {info in
print(info)
}
} catch {
getInfoError = true
}
}
}
.navigationTitle("Theta SDK sample app")
.navigationBarTitleDisplayMode(.inline)
.alert("warning", isPresented: $getInfoError) {
} message: {
Text("Can not connect to Theta.")
}
}
.onChange(of: scenePhase) { newPhase in
if newPhase == .active {
print("ContentView Active")
theta.reset()
Task {
do {
try await theta.info {info in
print(info)
}
} catch {
getInfoError = true
}
}
}
}

}
}

Expand Down
14 changes: 12 additions & 2 deletions demos/demo-ios/SdkSample/PhotoSphereView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@ import SwiftUI
struct PhotoSphereView: View {
@Environment(\.presentationMode) var presentation
var item: FileItem
@State var isClose = false

init(_ item: FileItem = FileItem()) {
self.item = item
}
var body: some View {
VStack {
SphereView(urlString: item.url)
if isClose {
EmptyView()
} else {
SphereView(urlString: item.url)
}
}
.navigationBarBackButtonHidden(true)
.navigationTitle(item.name)
.navigationBarItems(
leading:
HStack {
Button(action: {
self.presentation.wrappedValue.dismiss()
isClose = true

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.presentation.wrappedValue.dismiss()
}
},
label: {
Image("chevron")
Expand Down
59 changes: 33 additions & 26 deletions demos/demo-ios/SdkSample/TakePhotoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ struct TakePhotoView: View {
.navigationBarBackButtonHidden(true)
.navigationTitle("Take Photo")
.navigationBarItems(
leading:
HStack {
Button(action: {
self.presentation.wrappedValue.dismiss()
},
label: {
Image("chevron")
.resizable()
.frame(width: 24, height: 24)
}
)
}
leading:
HStack {
Button(action: {
previewing = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.presentation.wrappedValue.dismiss()
}
},
label: {
Image("chevron")
.resizable()
.frame(width: 24, height: 24)
}
)
}
)
}
var hiddenLink: some View {
Expand Down Expand Up @@ -97,21 +100,25 @@ struct TakePhotoView: View {
}

func takePhoto() async {
do {
if (!previewing) {
return
}
previewing = false
try await theta.takePicture {photoUrl in
let parts = photoUrl.components(separatedBy: "/")
item = FileItem(
name: parts[parts.count - 1],
url: photoUrl
)
isActive = true
if (!previewing) {
return
}
previewing = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
Task {
do {
try await theta.takePicture {photoUrl in
let parts = photoUrl.components(separatedBy: "/")
item = FileItem(
name: parts[parts.count - 1],
url: photoUrl
)
isActive = true
}
} catch {
// TODO: handle error
}
}
} catch {
// TODO: handle error
}
}
}
Expand Down
24 changes: 14 additions & 10 deletions demos/demo-ios/SdkSample/ThetaSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Theta {
var thetaRepository: ThetaRepository? = nil
var lastInfo: ThetaInfo? = nil

func reset() {
thetaRepository = nil
}

func initialize() async throws {
if (thetaRepository != nil) {
return;
Expand Down Expand Up @@ -73,22 +77,22 @@ class Theta {
init(_ handler: @escaping ThetaFrameHandler) {
self.handler = handler
}
func invoke(
p1: Any?,
completionHandler: @escaping ThetaHandlerWithError<Any>
) {
func invoke(p1: Any?) async throws -> Any? {
let now = CACurrentMediaTime()
if (now - last > Self.FrameInterval) {
var result = false
autoreleasepool {
let nsData = PlatformKt.frameFrom(
packet: p1 as! KotlinPair<KotlinByteArray, KotlinInt>
)
let result = handler(nsData)
completionHandler(result, nil)
if let frameData = p1 as? KotlinPair<KotlinByteArray, KotlinInt> {
let nsData = PlatformKt.frameFrom(
packet: frameData
)
result = handler(nsData)
}
}
last = now
return result
} else {
completionHandler(true, nil)
return true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion demos/demo-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@react-navigation/native": "^6.1.0",
"@react-navigation/native-stack": "^6.9.5",
"theta-client-react-native": "1.3.1",
"theta-client-react-native": "1.4.0",
"react": "18.2.0",
"react-native": "0.70.6",
"react-native-safe-area-context": "^4.4.1",
Expand Down
Loading

0 comments on commit e3f10b4

Please sign in to comment.