Skip to content

Commit

Permalink
Merge branch 'develop' into develop_iOS16
Browse files Browse the repository at this point in the history
  • Loading branch information
ensan-hcl committed Nov 3, 2023
2 parents a185ac0 + 57c7a05 commit dd9a265
Show file tree
Hide file tree
Showing 51 changed files with 1,074 additions and 402 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ public enum AzooKeyKeyboardViewExtension: ApplicationSpecificKeyboardViewExtensi
HideResetButtonInOneHandedMode.value
}

public static var useSliderStyleCursorBar: Bool {
UseSliderStyleCursorBar.value
public static var useReflectStyleCursorBar: Bool {
UseReflectStyleCursorBar.value
}

public static var useShiftKey: Bool {
false
UseShiftKey.value
}

public static var displayCursorBarAutomatically: Bool {
DisplayCursorBarAutomatically.value
}

public static var canResetLearningForCandidate: Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,38 @@ public extension KeyboardSettingKey where Self == DisplayTabBarButton {
static var displayTabBarButton: Self { .init() }
}

public struct UseSliderStyleCursorBar: BoolKeyboardSettingKey {
public struct UseReflectStyleCursorBar: BoolKeyboardSettingKey {
public static let title: LocalizedStringKey = "新しいカーソルバーを使う"
public static let explanation: LocalizedStringKey = "操作性が向上した新しいカーソルバーを有効化します。"
public static let defaultValue = false
// MARK: This setting is originally introduced as 'beta cursor bar'
public static let key: String = "use_move_cursor_bar_beta"
}

public extension KeyboardSettingKey where Self == UseSliderStyleCursorBar {
static var useSliderStyleCursorBar: Self { .init() }
public extension KeyboardSettingKey where Self == UseReflectStyleCursorBar {
static var useReflectStyleCursorBar: Self { .init() }
}

public struct DisplayCursorBarAutomatically: BoolKeyboardSettingKey {
public static let title: LocalizedStringKey = "カーソルバーを自動表示"
public static let explanation: LocalizedStringKey = "カーソル移動の際にカーソルバーを自動表示します"
public static let defaultValue = false
public static let key: String = "display_cursor_bar_automatically"
}

public extension KeyboardSettingKey where Self == DisplayCursorBarAutomatically {
static var displayCursorBarAutomatically: Self { .init() }
}

public struct UseShiftKey: BoolKeyboardSettingKey {
public static let title: LocalizedStringKey = "シフトキーを使う"
public static let explanation: LocalizedStringKey = "QwertyキーボードでAaキーの代わりにシフトキーを利用します。"
public static let defaultValue = false
public static let key: String = "use_shift_key"
}

public extension KeyboardSettingKey where Self == UseShiftKey {
static var useShiftKey: Self { .init() }
}

public struct HideResetButtonInOneHandedMode: BoolKeyboardSettingKey {
Expand Down
2 changes: 1 addition & 1 deletion AzooKeyCore/Sources/KeyboardThemes/ThemeColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
@preconcurrency import SwiftUI
import SwiftUI

public enum ThemeColor<SystemColor: ApplicationSpecificColor>: Sendable {
case color(Color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ import Foundation
static var enableSound: Bool { get }
static var enableHaptics: Bool { get }
static var enablePasteButton: Bool { get }
static var displayTabBarButton: Bool { get }
static var hideResetButtonInOneHandedMode: Bool { get }
static var useSliderStyleCursorBar: Bool { get }
static var useShiftKey: Bool { get }

/// タブバーボタンを表示する
/// - note: このオプションは一度削除を決めたが、ユーザから強い要望があったので維持することにした。
static var displayTabBarButton: Bool { get }
/// 反射スタイルのカーソルバーを利用する
static var useReflectStyleCursorBar: Bool { get }
/// カーソルバーを自動表示する(実験的機能)
/// - note: この機能は実験的に導入しているが、仕様に議論がある。[#346](https://github.com/ensan-hcl/azooKey/issues/346)も参照。
static var displayCursorBarAutomatically: Bool { get }

static var canResetLearningForCandidate: Bool { get }

static func get(_: CustomizableFlickKey) -> KeyFlickSetting.SettingData
Expand Down
4 changes: 4 additions & 0 deletions AzooKeyCore/Sources/KeyboardViews/AzooKeyIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public struct AzooKeyIcon: View {
case king
case santaClaus
case strawHat
case fire
}
public enum Color {
case auto
Expand Down Expand Up @@ -88,6 +89,9 @@ public struct AzooKeyIcon: View {
Text("\u{EA22}")
.foregroundStyle(.red)
}
case .fire:
Text("δ")
.foregroundStyle(foregroundColor)
}
}

Expand Down
28 changes: 12 additions & 16 deletions AzooKeyCore/Sources/KeyboardViews/Design.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@ import SwiftUIUtils
public struct TabDependentDesign {
let horizontalKeyCount: CGFloat
let verticalKeyCount: CGFloat
let layout: KeyboardLayout
let orientation: KeyboardOrientation

private var interfaceWidth: CGFloat
private var interfaceHeight: CGFloat

public init(width: Int, height: Int, interfaceSize: CGSize, layout: KeyboardLayout, orientation: KeyboardOrientation) {
public init(width: Int, height: Int, interfaceSize: CGSize, orientation: KeyboardOrientation) {
self.horizontalKeyCount = CGFloat(width)
self.verticalKeyCount = CGFloat(height)
self.layout = layout
self.orientation = orientation
self.interfaceWidth = interfaceSize.width
self.interfaceHeight = interfaceSize.height
}

public init(width: CGFloat, height: CGFloat, interfaceSize: CGSize, layout: KeyboardLayout, orientation: KeyboardOrientation) {
public init(width: CGFloat, height: CGFloat, interfaceSize: CGSize, orientation: KeyboardOrientation) {
self.horizontalKeyCount = width
self.verticalKeyCount = height
self.layout = layout
self.orientation = orientation
self.interfaceWidth = interfaceSize.width
self.interfaceHeight = interfaceSize.height
Expand All @@ -42,10 +39,10 @@ public struct TabDependentDesign {
/// screenWidthとhorizontalKeyCountに依存
var keyViewWidth: CGFloat {
let coefficient: CGFloat
switch (layout, orientation) {
case (_, .vertical):
switch orientation {
case .vertical:
coefficient = 5 / (5.1 + horizontalKeyCount / 10)
case (_, .horizontal):
case .horizontal:
coefficient = 10 / (10.2 + horizontalKeyCount * 0.28)
}
return interfaceWidth / horizontalKeyCount * coefficient
Expand All @@ -72,15 +69,11 @@ public struct TabDependentDesign {
}

var verticalSpacing: CGFloat {
switch (layout, orientation) {
case (.flick, .vertical):
return interfaceWidth * 3 / 140
case (.flick, .horizontal):
switch orientation {
case .vertical:
return interfaceWidth / 50
case .horizontal:
return interfaceWidth / 107
case (.qwerty, .vertical):
return interfaceWidth / 36.6
case (.qwerty, .horizontal):
return interfaceWidth / 65
}
}

Expand Down Expand Up @@ -265,13 +258,16 @@ public enum Design {

enum LabelFontSizeStrategy {
case max
case xlarge
case large
case medium
case small
case xsmall

var scale: CGFloat {
switch self {
case .xlarge:
return 1.2
case .large, .max:
return 1
case .medium:
Expand Down
69 changes: 37 additions & 32 deletions AzooKeyCore/Sources/KeyboardViews/KeyboardFeedback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
//

import func AudioToolbox.AudioServicesPlaySystemSound
import Foundation
import typealias AudioToolbox.SystemSoundID
import class UIKit.UIImpactFeedbackGenerator

private enum UIImpactFeedbackGeneratorHolder {
@MainActor static let generator = UIImpactFeedbackGenerator(style: .light)
}
/// フィードバックを返すためのツールセット
@MainActor public enum KeyboardFeedback<Extension: ApplicationSpecificKeyboardViewExtension> {
public enum KeyboardFeedback<Extension: ApplicationSpecificKeyboardViewExtension> {
@MainActor
private static var enableSound: Bool {
Extension.SettingProvider.enableSound
}
@MainActor
private static var requestedHaptics: Bool {
Extension.SettingProvider.enableHaptics
}
@MainActor
private static var enableHaptics: Bool {
SemiStaticStates.shared.hapticsAvailable && SemiStaticStates.shared.hasFullAccess && requestedHaptics
}
// FIXME: possibly too heavy
private static var generator: UIImpactFeedbackGenerator { UIImpactFeedbackGenerator(style: .light) }

// 使えそうな音
/* i
Expand All @@ -42,53 +46,54 @@ import class UIKit.UIImpactFeedbackGenerator
/// 入力を伴う操作を行う際にフィードバックを返します。
/// - Note: 押しはじめに鳴らす方が反応が良く感じます。
public static func click() {
if enableSound {
AudioServicesPlaySystemSound(1104)
}
if enableHaptics {
generator.impactOccurred(intensity: 0.7)
}
playSystemSound(1104)
impactOnMainActor(intensity: 0.7)
}

/// タブの移動、入力の確定、小仮名濁点化、カーソル移動などを伴う操作を行う際にフィードバックを返します。
/// - Note: 押しはじめに鳴らす方が反応が良く感じます。
public static func tabOrOtherKey() {
if enableSound {
AudioServicesPlaySystemSound(1156)
}
if enableHaptics {
generator.impactOccurred(intensity: 0.75)
}
playSystemSound(1156)
impactOnMainActor(intensity: 0.75)
}

/// 文字の削除などを伴う操作を行う際に音を鳴らします。
/// - Note: 押しはじめに鳴らす方が反応が良く感じます。
public static func delete() {
if enableSound {
AudioServicesPlaySystemSound(1155)
}
if enableHaptics {
generator.impactOccurred(intensity: 0.75)
}
playSystemSound(1155)
impactOnMainActor(intensity: 0.75)
}

/// 文字の一括削除の操作を行う際にフィードバックを返します。
public static func smoothDelete() {
if enableSound {
AudioServicesPlaySystemSound(1105)
}
if enableHaptics {
generator.impactOccurred(intensity: 0.8)
}
playSystemSound(1105)
impactOnMainActor(intensity: 0.8)
}

/// 操作のリセットを行うときにフィードバックを返します。
public static func reset() {
if enableSound {
AudioServicesPlaySystemSound(1533)
playSystemSound(1533)
impactOnMainActor(intensity: 1)
}

/// systemSoundの再生のラッパー
/// - Note: `generator.impactOccurred`はMainActor上でのみ動作する
public static func impactOnMainActor(intensity: Double) {
Task { @MainActor in
if enableHaptics {
UIImpactFeedbackGeneratorHolder.generator.impactOccurred(intensity: intensity)
}
}
if enableHaptics {
generator.impactOccurred(intensity: 1)
}

/// systemSoundの再生のラッパー
/// - Note: `AudioServicesPlaySystemSound`は非同期で呼び出さないと爆音が鳴ることがある
public static func playSystemSound(_ id: SystemSoundID) {
Task {
if await enableSound {
// 再生自体は非同期で実行される
AudioServicesPlaySystemSound(id)
}
}
}
}
4 changes: 2 additions & 2 deletions AzooKeyCore/Sources/KeyboardViews/TemporalMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import struct SwiftUI.LocalizedStringKey

public enum TemporalMessage {
public enum TemporalMessage: Sendable {
case doneForgetCandidate
case doneReportWrongConversion
case failedReportWrongConversion
Expand All @@ -23,7 +23,7 @@ public enum TemporalMessage {
}
}

public enum DismissCondition {
public enum DismissCondition: Sendable {
case auto
case ok
}
Expand Down
Loading

0 comments on commit dd9a265

Please sign in to comment.