From 93f63a8cfdfcd6c54dacfe79439627feb39b8930 Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 11:09:31 -0400 Subject: [PATCH 1/8] Initial commit: added init method and JNI cache struct --- Sources/LinearLayout.swift | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Sources/LinearLayout.swift diff --git a/Sources/LinearLayout.swift b/Sources/LinearLayout.swift new file mode 100644 index 0000000..8244cb7 --- /dev/null +++ b/Sources/LinearLayout.swift @@ -0,0 +1,60 @@ +// +// LinearLayout.swift +// Android +// +// Created by Killian Greene on 8/10/18. +// + +import Foundation +import java_swift +import java_lang +import JNI + +public extension AndroidViewGroup { + public typealias LinearLayout = AndroidLinearLayout +} + +open class AndroidLinearLayout: Android.View.ViewGroup { + // MARK: - Initialization + public convenience init(context: Android.Content.Context) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __object = JNIMethod.NewObject( + className: LinearLayoutJNICache.className, + classCache: &LinearLayoutJNICache.jniClass, + methodSig: "(Landroid/content/Context;)V)", + methodCache: &LinearLayoutJNICache.MethodID.init_method_1, + args: &__args, + locals: &__locals) + + self.init( javaObject: __object ) + + JNI.DeleteLocalRef( __object ) + } +} + + +// MARK: - Private +internal extension AndroidLinearLayout { + + /// JNI Cache + struct LinearLayoutJNICache { + + /// JNI Java class signature + static let classSignature = SwiftSupport.View.className(["LinearLayout"]) + + /// JNI Java class name + static let className = classSignature.rawValue + + /// JNI Java class + static var jniClass: jclass? + + /// JNI Method ID cache + struct MethodID { + static var init_method_1: jmethodID? + } + } +} From 78b2c13b7ab7fb5d2d61c1ff56894d0331bb3eaf Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 11:14:11 -0400 Subject: [PATCH 2/8] Added methods --- Sources/LinearLayout.swift | 456 +++++++++++++++++++++++++++++++++++++ 1 file changed, 456 insertions(+) diff --git a/Sources/LinearLayout.swift b/Sources/LinearLayout.swift index 8244cb7..cfb0625 100644 --- a/Sources/LinearLayout.swift +++ b/Sources/LinearLayout.swift @@ -36,6 +36,440 @@ open class AndroidLinearLayout: Android.View.ViewGroup { } } +// MARK: - Methods +public extension AndroidLinearLayout { + /** + * Return the offset of the widget's text baseline from the widget's top boundary. + */ + public func getBaseline() -> Int { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallIntMethod( + object: javaObject, + methodName: "getBaseline", + methodSig: "()I", + methodCache: &LinearLayoutJNICache.MethodID.getBaseline, + args: &__args, + locals: &__locals ) + + return Int(__return) + } + + + public func getBaselineAlignedChildIndex() -> Int { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallIntMethod( + object: javaObject, + methodName: "getBaselineAlignedChildIndex", + methodSig: "()I", + methodCache: &LinearLayoutJNICache.MethodID.getBaselineAlignedChildIndex, + args: &__args, + locals: &__locals ) + + return Int(__return) + } + + /** + * Get the padding size used to inset dividers in pixels + */ + public func getDividerPadding() -> Int { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallIntMethod( + object: javaObject, + methodName: "getDividerPadding", + methodSig: "()I", + methodCache: &LinearLayoutJNICache.MethodID.getDividerPadding, + args: &__args, + locals: &__locals ) + + return Int(__return) + } + + /** + * Returns the current gravity. + */ + public func getGravity() -> Int { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallIntMethod( + object: javaObject, + methodName: "getGravity", + methodSig: "()I", + methodCache: &LinearLayoutJNICache.MethodID.getGravity, + args: &__args, + locals: &__locals ) + + return Int(__return) + } + + /** + * Returns the current orientation. + */ + public func getOrientation() -> Int { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallIntMethod( + object: javaObject, + methodName: "getOrientation", + methodSig: "()I", + methodCache: &LinearLayoutJNICache.MethodID.getOrientation, + args: &__args, + locals: &__locals ) + + return Int(__return) + } + + + public func getShowDividers() -> Int { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallIntMethod( + object: javaObject, + methodName: "getShowDividers", + methodSig: "()I", + methodCache: &LinearLayoutJNICache.MethodID.getShowDividers, + args: &__args, + locals: &__locals ) + + return Int(__return) + } + + /** + * Returns the desired weights sum. + */ + public func getWeightSum() -> Float { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallFloatMethod( + object: javaObject, + methodName: "getWeightSum", + methodSig: "()F", + methodCache: &LinearLayoutJNICache.MethodID.getWeightSum, + args: &__args, + locals: &__locals ) + + return Float(__return) + } + + /** + * Indicates whether widgets contained within this layout are aligned on their baseline or not. + */ + public func isBaselineAligned() -> Bool { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallBooleanMethod( + object: javaObject, + methodName: "isBaselineAligned", + methodSig: "()Z", + methodCache: &LinearLayoutJNICache.MethodID.isBaselineAligned, + args: &__args, + locals: &__locals ) + + return __return != jboolean(JNI_FALSE) + } + + /** + * When true, all children with a weight will be considered having the minimum size of the largest child. + */ + public func isMeasureWithLargestChildEnabled() -> Bool { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallBooleanMethod( + object: javaObject, + methodName: "isMeasureWithLargestChildEnabled", + methodSig: "()Z", + methodCache: &LinearLayoutJNICache.MethodID.isMeasureWithLargestChildEnabled, + args: &__args, + locals: &__locals ) + + return __return != jboolean(JNI_FALSE) + } + + /** + * Called when any RTL property (layout direction or text direction or text alignment) has been changed. + */ + public func onRtlPropertiesChanged(layoutDirection: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(layoutDirection)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "onRtlPropertiesChanged", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.onRtlPropertiesChanged, + args: &__args, + locals: &__locals ) + } + + /** + * Defines whether widgets contained in this layout are baseline-aligned or not. + */ + public func setBaselineAligned(baselineAligned: Bool) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(z: jboolean(baselineAligned ? JNI_TRUE : JNI_FALSE)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setBaselineAligned", + methodSig: "(Z)V", + methodCache: &LinearLayoutJNICache.MethodID.setBaselineAligned, + args: &__args, + locals: &__locals ) + } + + + public func setBaselineAlignedChildIndex(i: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(i)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setBaselineAlignedChildIndex", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.setBaselineAlignedChildIndex, + args: &__args, + locals: &__locals ) + } + + /** + * Set a drawable to be used as a divider between items. + */ + public func setDividerDrawable(divider: JavaObject) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = JNIType.toJava(value: divider, locals: &__locals) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setDividerDrawable", + methodSig: "(Landroid/graphics/drawable/Drawable;)V", + methodCache: &LinearLayoutJNICache.MethodID.setDividerDrawable, + args: &__args, + locals: &__locals ) + } + + /** + * Set padding displayed on both ends of dividers. + */ + public func setDividerPadding(padding: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(padding)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setDividerPadding", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.setDividerPadding, + args: &__args, + locals: &__locals ) + } + + /** + * Describes how the child views are positioned. + */ + public func setGravity(gravity: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(gravity)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setGravity", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.setGravity, + args: &__args, + locals: &__locals ) + } + + + public func setHorizontalGravity(horizontalGravity: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(horizontalGravity)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setHorizontalGravity", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.setHorizontalGravity, + args: &__args, + locals: &__locals ) + } + + /** + * When set to true, all children with a weight will be considered having the minimum size of the largest child. + */ + public func setMeasureWithLargestChildEnabled(enabled: Bool) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(z: jboolean(enabled ? JNI_TRUE : JNI_FALSE)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setMeasureWithLargestChildEnabled", + methodSig: "(Z)V", + methodCache: &LinearLayoutJNICache.MethodID.setMeasureWithLargestChildEnabled, + args: &__args, + locals: &__locals ) + } + + /** + * Should the layout be a column or a row. + */ + public func setOrientation(orientation: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(orientation)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setOrientation", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.setOrientation, + args: &__args, + locals: &__locals ) + } + + /** + * Set how dividers should be shown between items in this layout + */ + public func setShowDividers(showDividers: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(showDividers)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setShowDividers", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.setShowDividers, + args: &__args, + locals: &__locals ) + } + + + public func setVerticalGravity(verticalGravity: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(verticalGravity)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setVerticalGravity", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.setVerticalGravity, + args: &__args, + locals: &__locals ) + } + + /** + * Defines the desired weights sum. + */ + public func setWeightSum(weightSum: Float) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(f: jfloat(weightSum)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "setWeightSum", + methodSig: "(F)V", + methodCache: &LinearLayoutJNICache.MethodID.setWeightSum, + args: &__args, + locals: &__locals ) + } + + /** + * Return true if the pressed state should be delayed for children or descendants of this ViewGroup. + */ + public func shouldDelayChildPressedState() -> Bool { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallBooleanMethod( + object: javaObject, + methodName: "shouldDelayChildPressedState", + methodSig: "()Z", + methodCache: &LinearLayoutJNICache.MethodID.shouldDelayChildPressedState, + args: &__args, + locals: &__locals ) + + return __return != jboolean(JNI_FALSE) + } + + +} // MARK: - Private internal extension AndroidLinearLayout { @@ -55,6 +489,28 @@ internal extension AndroidLinearLayout { /// JNI Method ID cache struct MethodID { static var init_method_1: jmethodID? + static var getBaseline: jmethodID? + static var getBaselineAlignedChildIndex: jmethodID? + static var getDividerPadding: jmethodID? + static var getGravity: jmethodID? + static var getOrientation: jmethodID? + static var getShowDividers: jmethodID? + static var getWeightSum: jmethodID? + static var isBaselineAligned: jmethodID? + static var isMeasureWithLargestChildEnabled: jmethodID? + static var onRtlPropertiesChanged: jmethodID? + static var setBaselineAligned: jmethodID? + static var setBaselineAlignedChildIndex: jmethodID? + static var setDividerDrawable: jmethodID? + static var setDividerPadding: jmethodID? + static var setGravity: jmethodID? + static var setHorizontalGravity: jmethodID? + static var setMeasureWithLargestChildEnabled: jmethodID? + static var setOrientation: jmethodID? + static var setShowDividers: jmethodID? + static var setVerticalGravity: jmethodID? + static var setWeightSum: jmethodID? + static var shouldDelayChildPressedState: jmethodID? } } } From 21b7626b9d3cee6fbd5eea5ec3e62d49b6aabbdc Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 11:23:46 -0400 Subject: [PATCH 3/8] Moved overriding funcs to main body --- Sources/LinearLayout.swift | 91 +++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/Sources/LinearLayout.swift b/Sources/LinearLayout.swift index cfb0625..b85a372 100644 --- a/Sources/LinearLayout.swift +++ b/Sources/LinearLayout.swift @@ -34,14 +34,11 @@ open class AndroidLinearLayout: Android.View.ViewGroup { JNI.DeleteLocalRef( __object ) } -} - -// MARK: - Methods -public extension AndroidLinearLayout { + /** * Return the offset of the widget's text baseline from the widget's top boundary. */ - public func getBaseline() -> Int { + open override func getBaseline() -> Int { var __locals = [jobject]() @@ -58,6 +55,49 @@ public extension AndroidLinearLayout { return Int(__return) } + /** + * Called when any RTL property (layout direction or text direction or text alignment) has been changed. + */ + open override func onRtlPropertiesChanged(layoutDirection: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(layoutDirection)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "onRtlPropertiesChanged", + methodSig: "(I)V", + methodCache: &LinearLayoutJNICache.MethodID.onRtlPropertiesChanged, + args: &__args, + locals: &__locals ) + } + + /** + * Return true if the pressed state should be delayed for children or descendants of this ViewGroup. + */ + open override func shouldDelayChildPressedState() -> Bool { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallBooleanMethod( + object: javaObject, + methodName: "shouldDelayChildPressedState", + methodSig: "()Z", + methodCache: &LinearLayoutJNICache.MethodID.shouldDelayChildPressedState, + args: &__args, + locals: &__locals ) + + return __return != jboolean(JNI_FALSE) + } +} + +// MARK: - Methods +public extension AndroidLinearLayout { public func getBaselineAlignedChildIndex() -> Int { @@ -214,26 +254,6 @@ public extension AndroidLinearLayout { return __return != jboolean(JNI_FALSE) } - /** - * Called when any RTL property (layout direction or text direction or text alignment) has been changed. - */ - public func onRtlPropertiesChanged(layoutDirection: Int) { - - var __locals = [jobject]() - - var __args = [jvalue]( repeating: jvalue(), count: 1 ) - - __args[0] = jvalue(i: jint(layoutDirection)) - - JNIMethod.CallVoidMethod( - object: javaObject, - methodName: "onRtlPropertiesChanged", - methodSig: "(I)V", - methodCache: &LinearLayoutJNICache.MethodID.onRtlPropertiesChanged, - args: &__args, - locals: &__locals ) - } - /** * Defines whether widgets contained in this layout are baseline-aligned or not. */ @@ -448,27 +468,6 @@ public extension AndroidLinearLayout { locals: &__locals ) } - /** - * Return true if the pressed state should be delayed for children or descendants of this ViewGroup. - */ - public func shouldDelayChildPressedState() -> Bool { - - var __locals = [jobject]() - - var __args = [jvalue]( repeating: jvalue(), count: 1 ) - - let __return = JNIMethod.CallBooleanMethod( - object: javaObject, - methodName: "shouldDelayChildPressedState", - methodSig: "()Z", - methodCache: &LinearLayoutJNICache.MethodID.shouldDelayChildPressedState, - args: &__args, - locals: &__locals ) - - return __return != jboolean(JNI_FALSE) - } - - } // MARK: - Private From 409b5513eb421bd39c4ab95ccbd9e27cd4f89a91 Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 11:24:21 -0400 Subject: [PATCH 4/8] Moved LinearLayout overridable funcs to main body --- Sources/View.swift | 78 ++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/Sources/View.swift b/Sources/View.swift index bc4713a..32c67aa 100644 --- a/Sources/View.swift +++ b/Sources/View.swift @@ -729,6 +729,43 @@ open class AndroidView: JavaObject { args: &__args, locals: &__locals ) } + + /** + * Return the offset of the widget's text baseline from the widget's top boundary. + */ + open func getBaseline() -> Int { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallIntMethod( + object: javaObject, + methodName: "getBaseline", + methodSig: "()I", + methodCache: &JNICache.MethodID.getBaseline, + args: &__args, + locals: &__locals ) + + return Int(__return) + } + + open func onRtlPropertiesChanged(layoutDirection: Int) { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + __args[0] = jvalue(i: jint(layoutDirection)) + + JNIMethod.CallVoidMethod( + object: javaObject, + methodName: "onRtlPropertiesChanged", + methodSig: "(I)V", + methodCache: &JNICache.MethodID.onRtlPropertiesChanged, + args: &__args, + locals: &__locals ) + } } // MARK: - Constants @@ -3689,26 +3726,6 @@ public extension Android.View.View { return Int(__return) } - /** - * Return the offset of the widget's text baseline from the widget's top boundary. - */ - public func getBaseline() -> Int { - - var __locals = [jobject]() - - var __args = [jvalue]( repeating: jvalue(), count: 1 ) - - let __return = JNIMethod.CallIntMethod( - object: javaObject, - methodName: "getBaseline", - methodSig: "()I", - methodCache: &JNICache.MethodID.getBaseline, - args: &__args, - locals: &__locals ) - - return Int(__return) - } - /** * Bottom position of this view relative to its parent. */ @@ -6247,27 +6264,6 @@ public extension Android.View.View { } - - public func onRtlPropertiesChanged(layoutDirection: Int) { - - var __locals = [jobject]() - - var __args = [jvalue]( repeating: jvalue(), count: 1 ) - - __args[0] = jvalue(i: jint(layoutDirection)) - - JNIMethod.CallVoidMethod( - object: javaObject, - methodName: "onRtlPropertiesChanged", - methodSig: "(I)V", - methodCache: &JNICache.MethodID.onRtlPropertiesChanged, - args: &__args, - locals: &__locals ) - - - } - - public func onScreenStateChanged(screenState: Int) { var __locals = [jobject]() From 88ad7c654734a3fab73b45dbe59de7a85d5837d8 Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 11:24:58 -0400 Subject: [PATCH 5/8] Moved LinearLayout overridable func to main body --- Sources/ViewGroup.swift | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Sources/ViewGroup.swift b/Sources/ViewGroup.swift index 3f90e66..3d2c516 100644 --- a/Sources/ViewGroup.swift +++ b/Sources/ViewGroup.swift @@ -591,6 +591,25 @@ open class AndroidViewGroup: AndroidView { args: &__args, locals: &__locals ) } + + open func shouldDelayChildPressedState() -> Bool { + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + + let __return = JNIMethod.CallBooleanMethod( + object: javaObject, + methodName: "shouldDelayChildPressedState", + methodSig: "()Z", + methodCache: &ViewGroupJNICache.MethodID.shouldDelayChildPressedState, + args: &__args, + locals: &__locals ) + + + + return __return != jboolean(JNI_FALSE) + } } public extension Android.View.ViewGroup { @@ -2069,27 +2088,6 @@ public extension Android.View.ViewGroup { } - - public func shouldDelayChildPressedState() -> Bool { - - var __locals = [jobject]() - - var __args = [jvalue]( repeating: jvalue(), count: 1 ) - - let __return = JNIMethod.CallBooleanMethod( - object: javaObject, - methodName: "shouldDelayChildPressedState", - methodSig: "()Z", - methodCache: &ViewGroupJNICache.MethodID.shouldDelayChildPressedState, - args: &__args, - locals: &__locals ) - - - - return __return != jboolean(JNI_FALSE) - } - - public func showContextMenuForChild(originalView: Android.View.View, x: Float, y: Float) -> Bool { var __locals = [jobject]() From 8f7d27edab07c673d13e2c6761d553079f609e88 Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 12:03:46 -0400 Subject: [PATCH 6/8] Fixed init --- Sources/LinearLayout.swift | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Sources/LinearLayout.swift b/Sources/LinearLayout.swift index b85a372..02b63c1 100644 --- a/Sources/LinearLayout.swift +++ b/Sources/LinearLayout.swift @@ -10,27 +10,47 @@ import java_swift import java_lang import JNI -public extension AndroidViewGroup { +public extension Android.Widget { public typealias LinearLayout = AndroidLinearLayout } open class AndroidLinearLayout: Android.View.ViewGroup { + // MARK: - Initialization - public convenience init(context: Android.Content.Context) { + public convenience init?( casting object: java_swift.JavaObject, + _ file: StaticString = #file, + _ line: Int = #line ) { + self.init(javaObject: nil) + object.withJavaObject { + self.javaObject = $0 + } + } + + public required init( javaObject: jobject? ) { + super.init(javaObject: javaObject) + } + + public convenience init(context: Android.Content.Context) { + self.init(javaObject: nil) + bindNewObject(context: context) + } + + public override func bindNewObject(context: Android.Content.Context) { var __locals = [jobject]() var __args = [jvalue]( repeating: jvalue(), count: 1 ) + __args[0] = JNIType.toJava(value: context, locals: &__locals) let __object = JNIMethod.NewObject( className: LinearLayoutJNICache.className, classCache: &LinearLayoutJNICache.jniClass, - methodSig: "(Landroid/content/Context;)V)", + methodSig: "(Landroid/content/Context;)V", methodCache: &LinearLayoutJNICache.MethodID.init_method_1, args: &__args, - locals: &__locals) + locals: &__locals ) - self.init( javaObject: __object ) + super.javaObject = __object JNI.DeleteLocalRef( __object ) } @@ -477,7 +497,7 @@ internal extension AndroidLinearLayout { struct LinearLayoutJNICache { /// JNI Java class signature - static let classSignature = SwiftSupport.View.className(["LinearLayout"]) + static let classSignature = Android.Widget.className(["LinearLayout"]) /// JNI Java class name static let className = classSignature.rawValue From 8d27ea34ff565fdc9031aae35ee319866fc6236f Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 12:11:25 -0400 Subject: [PATCH 7/8] Added constants --- Sources/LinearLayout.swift | 103 +++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/Sources/LinearLayout.swift b/Sources/LinearLayout.swift index 02b63c1..1286f1a 100644 --- a/Sources/LinearLayout.swift +++ b/Sources/LinearLayout.swift @@ -116,6 +116,100 @@ open class AndroidLinearLayout: Android.View.ViewGroup { } } +// MARK: - Constants +public extension AndroidLinearLayout { + + public static var HORIZONTAL: Int { + + get { + + let __value = JNIField.GetStaticIntField( + fieldName: "HORIZONTAL", + fieldType: "I", + fieldCache: &LinearLayoutJNICache.FieldID.HORIZONTAL, + className: LinearLayoutJNICache.className, + classCache: &LinearLayoutJNICache.jniClass ) + + return Int(__value) + } + } + + public static var VERTICAL: Int { + + get { + + let __value = JNIField.GetStaticIntField( + fieldName: "VERTICAL", + fieldType: "I", + fieldCache: &LinearLayoutJNICache.FieldID.VERTICAL, + className: LinearLayoutJNICache.className, + classCache: &LinearLayoutJNICache.jniClass ) + + return Int(__value) + } + } + + public static var SHOW_DIVIDER_BEGINNING: Int { + + get { + + let __value = JNIField.GetStaticIntField( + fieldName: "SHOW_DIVIDER_BEGINNING", + fieldType: "I", + fieldCache: &LinearLayoutJNICache.FieldID.SHOW_DIVIDER_BEGINNING, + className: LinearLayoutJNICache.className, + classCache: &LinearLayoutJNICache.jniClass ) + + return Int(__value) + } + } + + public static var SHOW_DIVIDER_END: Int { + + get { + + let __value = JNIField.GetStaticIntField( + fieldName: "SHOW_DIVIDER_END", + fieldType: "I", + fieldCache: &LinearLayoutJNICache.FieldID.SHOW_DIVIDER_END, + className: LinearLayoutJNICache.className, + classCache: &LinearLayoutJNICache.jniClass ) + + return Int(__value) + } + } + + public static var SHOW_DIVIDER_NONE: Int { + + get { + + let __value = JNIField.GetStaticIntField( + fieldName: "SHOW_DIVIDER_NONE", + fieldType: "I", + fieldCache: &LinearLayoutJNICache.FieldID.SHOW_DIVIDER_NONE, + className: LinearLayoutJNICache.className, + classCache: &LinearLayoutJNICache.jniClass ) + + return Int(__value) + } + } + + public static var SHOW_DIVIDER_MIDDLE: Int { + + get { + + let __value = JNIField.GetStaticIntField( + fieldName: "SHOW_DIVIDER_MIDDLE", + fieldType: "I", + fieldCache: &LinearLayoutJNICache.FieldID.SHOW_DIVIDER_MIDDLE, + className: LinearLayoutJNICache.className, + classCache: &LinearLayoutJNICache.jniClass ) + + return Int(__value) + } + } +} + // MARK: - Methods public extension AndroidLinearLayout { @@ -505,6 +599,15 @@ internal extension AndroidLinearLayout { /// JNI Java class static var jniClass: jclass? + struct FieldID { + static var HORIZONTAL: jfieldID? + static var VERTICAL: jfieldID? + static var SHOW_DIVIDER_BEGINNING: jfieldID? + static var SHOW_DIVIDER_END: jfieldID? + static var SHOW_DIVIDER_MIDDLE: jfieldID? + static var SHOW_DIVIDER_NONE: jfieldID? + } + /// JNI Method ID cache struct MethodID { static var init_method_1: jmethodID? From b0a43e4efb1ec6c79b7215fab26df56ac9349afc Mon Sep 17 00:00:00 2001 From: Killian Greene Date: Fri, 10 Aug 2018 15:47:24 -0400 Subject: [PATCH 8/8] Created LayoutParams for LinearLayout --- Sources/LinearLayoutLayoutParams.swift | 183 +++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 Sources/LinearLayoutLayoutParams.swift diff --git a/Sources/LinearLayoutLayoutParams.swift b/Sources/LinearLayoutLayoutParams.swift new file mode 100644 index 0000000..8e515e3 --- /dev/null +++ b/Sources/LinearLayoutLayoutParams.swift @@ -0,0 +1,183 @@ +// +// LinearLayoutLayoutParams.swift +// Android +// +// Created by Killian Greene on 8/10/18. +// + +import Foundation +import java_util +import java_swift +import JNI + +public extension AndroidLinearLayout { + public typealias LLayoutParams = AndroidLinearLayoutLayoutParams +} + +open class AndroidLinearLayoutLayoutParams: Android.View.ViewGroup.MarginLayoutParams { + + /** + * Creates a new set of layout parameters with the specified width, height and weight. + */ + public convenience init(width: Int, height: Int, weight: Float){ + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 3 ) + __args[0] = jvalue(i: jint(width)) + __args[1] = jvalue(i: jint(height)) + __args[2] = jvalue(f: jfloat(weight)) + + let __object = JNIMethod.NewObject( + className: LLayoutParamsJNICache.className, + classCache: &LLayoutParamsJNICache.jniClass, + methodSig: "(IIF)V", + methodCache: &LLayoutParamsJNICache.MethodID.init_method_1, + args: &__args, + locals: &__locals ) + + self.init( javaObject: __object ) + + JNI.DeleteLocalRef( __object ) + } + + public convenience init(source: Android.Widget.LinearLayout.LLayoutParams){ + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + __args[0] = JNIType.toJava(value: source, locals: &__locals) + + let __object = JNIMethod.NewObject( + className: LLayoutParamsJNICache.className, + classCache: &LLayoutParamsJNICache.jniClass, + methodSig: "(Landroid/widget/LinearLayout$LayoutParams;)V", + methodCache: &LLayoutParamsJNICache.MethodID.init_method_2, + args: &__args, + locals: &__locals ) + + self.init( javaObject: __object ) + + JNI.DeleteLocalRef( __object ) + } + + public convenience init(source: Android.View.ViewGroup.MarginLayoutParams){ + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + __args[0] = JNIType.toJava(value: source, locals: &__locals) + + let __object = JNIMethod.NewObject( + className: LLayoutParamsJNICache.className, + classCache: &LLayoutParamsJNICache.jniClass, + methodSig: "(Landroid/view/ViewGroup$MarginLayoutParams;)V", + methodCache: &LLayoutParamsJNICache.MethodID.init_method_3, + args: &__args, + locals: &__locals ) + + self.init( javaObject: __object ) + + JNI.DeleteLocalRef( __object ) + } + + /** + * Creates a new set of layout parameters with the specified width and height. + */ + public convenience init(width: Int, height: Int){ + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 2 ) + __args[0] = jvalue(i: jint(width)) + __args[1] = jvalue(i: jint(height)) + + let __object = JNIMethod.NewObject( + className: LLayoutParamsJNICache.className, + classCache: &LLayoutParamsJNICache.jniClass, + methodSig: "(II)V", + methodCache: &LLayoutParamsJNICache.MethodID.init_method_4, + args: &__args, + locals: &__locals ) + + self.init( javaObject: __object ) + + JNI.DeleteLocalRef( __object ) + } + + /** + * Copy constructor. + */ + public convenience init(source: Android.View.ViewGroup.LayoutParams){ + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 1 ) + __args[0] = JNIType.toJava(value: source, locals: &__locals) + + let __object = JNIMethod.NewObject( + className: LLayoutParamsJNICache.className, + classCache: &LLayoutParamsJNICache.jniClass, + methodSig: "(Landroid/view/ViewGroup$LayoutParams;)V", + methodCache: &LLayoutParamsJNICache.MethodID.init_method_5, + args: &__args, + locals: &__locals ) + + self.init( javaObject: __object ) + + JNI.DeleteLocalRef( __object ) + } + + public convenience init(context: Android.Content.Context, attrs: JavaObject){ + + var __locals = [jobject]() + + var __args = [jvalue]( repeating: jvalue(), count: 2 ) + __args[0] = JNIType.toJava(value: context, locals: &__locals) + __args[1] = JNIType.toJava(value: attrs, locals: &__locals) + + let __object = JNIMethod.NewObject( + className: LLayoutParamsJNICache.className, + classCache: &LLayoutParamsJNICache.jniClass, + methodSig: "(Landroid/content/Context;Landroid/util/AttributeSet;)V", + methodCache: &LLayoutParamsJNICache.MethodID.init_method_6, + args: &__args, + locals: &__locals ) + + self.init( javaObject: __object ) + + JNI.DeleteLocalRef( __object ) + } +} + +// MARK: - JNICache + +internal extension AndroidLinearLayoutLayoutParams { + + /// JNI Cache + struct LLayoutParamsJNICache { + + /// JNI Java class signature + static let classSignature = Android.Widget.className(["LinearLayout$LayoutParams"]) + + /// JNI Java class name + static let className = classSignature.rawValue + + /// JNI Java class + static var jniClass: jclass? + + /// JNI Field ID cache + struct FieldID { + } + + /// JNI Method ID cache + struct MethodID { + static var init_method_1: jmethodID? + static var init_method_2: jmethodID? + static var init_method_3: jmethodID? + static var init_method_4: jmethodID? + static var init_method_5: jmethodID? + static var init_method_6: jmethodID? + } + } +}