Android Extensions: Allow LayoutContainers in inner/local classes and objects
This commit is contained in:
committed by
Yan Zhulanow
parent
07be1e9d10
commit
7b4e24a454
+40
@@ -0,0 +1,40 @@
|
||||
package test
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import kotlinx.android.synthetic.main.layout.*
|
||||
import kotlinx.android.extensions.*
|
||||
|
||||
class R {
|
||||
class id {
|
||||
companion object {
|
||||
const val login = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyActivity(): Activity() {
|
||||
val loginItem = Button(this)
|
||||
|
||||
val entity = MyEntity(object : FrameLayout(this) {
|
||||
override fun findViewById(id: Int) : View? = when(id) {
|
||||
R.id.login -> loginItem
|
||||
else -> null
|
||||
}
|
||||
})
|
||||
|
||||
val entity2: LayoutContainer = entity
|
||||
|
||||
public fun box(): String {
|
||||
val o = if (entity.login.toString() == "Button") "O" else ""
|
||||
val k = if (entity2.login.toString() == "Button") "K" else ""
|
||||
return o + k // "OK"
|
||||
}
|
||||
|
||||
inner class MyEntity(override val containerView: View) : LayoutContainer
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return MyActivity().box()
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package test
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import kotlinx.android.synthetic.main.layout.*
|
||||
import kotlinx.android.extensions.*
|
||||
|
||||
class R {
|
||||
class id {
|
||||
companion object {
|
||||
const val login = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyActivity(): Activity() {
|
||||
val loginItem = Button(this)
|
||||
val entity = MyEntity(loginItem)
|
||||
|
||||
init {
|
||||
entity.login
|
||||
}
|
||||
|
||||
inner class MyEntity(override val containerView: View) : LayoutContainer
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="test"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||
<uses-sdk
|
||||
android:minSdkVersion="18"
|
||||
android:targetSdkVersion="18" />
|
||||
<permission android:name="android"></permission>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Sample" >
|
||||
<activity
|
||||
android:name="com.example.android.basiccontactables.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop">
|
||||
<meta-data
|
||||
android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user