Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ dependencyResolutionManagement {
}

rootProject.name = "Andoid"
include(":app")
include(":testapp")
48 changes: 48 additions & 0 deletions testapp/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[versions]
coreVersion = "1.9.0"
ktxVersion = "2.8.3"
composeVersion = "1.9.0"
appcompatVersion = "1.7.0"
junitVersion = "4.13.2"
testExtJunitVersion = "1.2.1"
espressoCoreVersion = "3.6.1"
composeBomVersion = "2023.03.00"

[libraries]
androidx-core = {group = "androidx.core", name = "core-ktx",version.ref = "coreVersion"}
androidx-lifecycle = {group = "androidx.lifecycle", name = "lifecycle-runtime-ktx" , version.ref = "ktxVersion"}
androidx-activity = {group = "androidx.activity", name = "activity-compose" , version.ref = "composeVersion"}
androidx-appcompat = {group = "androidx.appcompat", name = "appcompat" , version.ref = "appcompatVersion"}
junit = {group = "junit", name = "junit" , version.ref = "junitVersion"}
androidx-test-ext = {group = "androidx.test.ext", name = "junit" , version.ref = "testExtJunitVersion"}
androidx-test-espresso = {group = "androidx.test.espresso", name = "espresso-core" , version.ref = "espressoCoreVersion"}
androidx-compose = {group = "androidx.compose", name = "compose-bom" , version.ref = "composeBomVersion"}


#implementation(libs.android.core)
#implementation(libs.androidx.lifecycle)
#implementation(libs.androidx.activity)
#
#implementation(platform(libs.androidx.compose))
#implementation("androidx.compose.ui:ui")
#implementation("androidx.compose.ui:ui-graphics")
#implementation("androidx.compose.ui:ui-tooling-preview")
#implementation("androidx.compose.material3:material3")
#
#implementation(libs.androidx.appcompat)
#testImplementation(libs.junit)
#androidTestImplementation(libs.androidx.test.ext)
#androidTestImplementation(libs.androidx.test.espresso)
#
#androidTestImplementation(platform(libs.androidx.compose))
#androidTestImplementation("androidx.compose.ui:ui-test-junit4")
#debugImplementation("androidx.compose.ui:ui-tooling")
#debugImplementation("androidx.compose.ui:ui-test-manifest")


[plugins]
kotlin-gradlePlugin = {id = "org.jetbrains.kotlin.android", version.ref ="kotlin"}
android-application = {id = "com.android.application", version.ref ="androidGradlePlugin"}

#alias(libs.plugins.kotlin.gradlePlugin)
#alias(libs.plugins.android.application)
117 changes: 95 additions & 22 deletions testapp/src/main/java/com/example/testapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.allViews

class MainActivity : AppCompatActivity() {

private lateinit var itemsList: MutableList<View>
private val textOnScreen = arrayListOf<String>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -27,29 +29,100 @@ class MainActivity : AppCompatActivity() {
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.getItemId()
val mainScreen = findViewById(R.id.scroll_main_layout) as LinearLayout
if (id == R.id.action_add_button) {
Log.d("myLogs","button created")
val v: View = LayoutInflater.from(this).inflate(
/* resource = */ R.layout.button,
/* root = */ mainScreen,
/* attachToRoot = */ false
)
val str: String = v.resources.getString(R.string.button_text)
val btn = v as Button
btn.text = str
mainScreen.addView(btn)
private fun showToast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}

private fun getTextById(stringId: Int): String {
return resources.getString(stringId)
}

private fun sendLogEvent(message: String) {
Log.d("Log",message)
}

private fun click() {
var countButton = 0
var countEditText = 0
val mainScreen = findViewById<LinearLayout>(R.id.scroll_main_layout)
mainScreen
.allViews
.filter { view -> view is EditText }
.map { view -> view as EditText }
.forEach { editText: EditText ->
textOnScreen.add(editText.text.toString())
}
val textEditText = getTextById(R.string.text)
val textEditButton = getTextById(R.string.button)
val textLog = getTextById(R.string.log)
val mistake = getTextById(R.string.mistake)
val zeroText = getTextById(R.string.zerotext)
if (textOnScreen.isEmpty()) {
showToast(zeroText)
} else {
for (element in textOnScreen) {
when (element) {
textEditText -> {
createEditView()
countEditText += 1
break
}
textEditButton -> {
createButton()
countButton +=1
break
}
else -> showToast(mistake)
}
}
sendLogEvent("$countEditText $textEditText $countButton $textEditButton $textLog")
}
if (id == R.id.action_add_text) {
Log.d("myLogs","text created")
val addText = EditText(this)
addText.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)
mainScreen.addView(addText)
mainScreen
.allViews
.filter { view -> view is EditText }
.map { view -> view as EditText }
.forEach { editText: EditText ->
editText.text.clear()
}
textOnScreen.clear()
}

private fun createButton() {
val mainScreen = findViewById<LinearLayout>(R.id.scroll_main_layout)
val buttonCreated = getTextById(R.string.button_created)
sendLogEvent(buttonCreated)
val v: View = LayoutInflater.from(this).inflate(
/* resource = */ R.layout.button,
/* root = */ mainScreen,
/* attachToRoot = */ false
)
val str: String = v.resources.getString(R.string.button_text)
val btn = v as Button
btn.text = str
mainScreen.addView(btn)
btn.setOnClickListener {
click()
}
if (id == R.id.action_clear) {
mainScreen.removeAllViews()
}

private fun createEditView() {
val mainScreen = findViewById<LinearLayout>(R.id.scroll_main_layout)
val textCreated = getTextById(R.string.text_created)
sendLogEvent(textCreated)
val addText = EditText(this)
addText.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)
mainScreen.addView(addText)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.itemId
val mainScreen = findViewById<LinearLayout>(R.id.scroll_main_layout)
when (id) {
R.id.action_add_button -> createButton()
R.id.action_add_text -> createEditView()
R.id.action_clear -> mainScreen.removeAllViews()
}
return super.onOptionsItemSelected(item)
}
Expand Down
4 changes: 2 additions & 2 deletions testapp/src/main/res/layout-land/button.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/new_button"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff0000"
android:id="@+id/new_button"
android:text="@string/button_text"
android:textColor="@color/black">

</Button>
12 changes: 6 additions & 6 deletions testapp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout"
android:orientation="vertical">
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
Expand All @@ -17,10 +17,10 @@
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scroll_main_layout"
android:orientation="vertical"
android:id="@+id/scroll_main_layout"/>
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>

</LinearLayout>
3 changes: 1 addition & 2 deletions testapp/src/main/res/layout/button.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/new_button"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#808080"
android:id="@+id/new_button"
android:text="@string/button_text"
android:textColor="@color/black">

</Button>
6 changes: 3 additions & 3 deletions testapp/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

<item
android:id="@+id/action_add_button"
android:title="Создать кнопку" />
android:title="@string/button_text" />

<item
android:id="@+id/action_add_text"
android:title="Создать поле" />
android:title="@string/create_text" />

<item
android:id="@+id/action_clear"
android:title="Очистить" />
android:title="@string/clear" />

</menu>
9 changes: 9 additions & 0 deletions testapp/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
<resources>
<string name="app_name">testApp</string>
<string name="button_text">Create elements</string>
<string name="create_text">Create text</string>
<string name="clear">Clear</string>
<string name="button_created">button created</string>
<string name="text_created">text created</string>
<string name="text">text</string>
<string name="button">button</string>
<string name="log">were created</string>
<string name="mistake">mistake</string>
<string name="zerotext">need 1 text</string>
</resources>
9 changes: 9 additions & 0 deletions testapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
<resources>
<string name="app_name">Тестовое приложение</string>
<string name="button_text">Создать кнопку</string>
<string name="create_text">Создать поле</string>
<string name="clear">Очистить</string>
<string name="button_created">кнопка создана</string>
<string name="text_created">текстовое поле создано</string>
<string name="text">текст</string>
<string name="button">кнопка</string>
<string name="log">было создано</string>
<string name="mistake">ошибка</string>
<string name="zerotext">нужно хотя бы 1 тексовое поле</string>
</resources>