Skip to content
Snippets Groups Projects
Unverified Commit 7f5d63d3 authored by AC5636's avatar AC5636 :ghost:
Browse files

Done ex3

parent 74095ee6
No related branches found
No related tags found
No related merge requests found
Showing
with 270 additions and 0 deletions
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
# Default ignored files
/shelf/
/workspace.xml
E03 Build UI With Layout Editor 2
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State />
</entry>
</value>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveExternalAnnotations" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.10" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
/build
\ No newline at end of file
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "com.example.e03builduiwithlayouteditor2"
compileSdk = 34
defaultConfig {
applicationId = "com.example.e03builduiwithlayouteditor2"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.example.e03builduiwithlayouteditor2
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.e03builduiwithlayouteditor2", appContext.packageName)
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.E03BuildUIWithLayoutEditor2"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.example.e03builduiwithlayouteditor2
import android.graphics.Typeface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
class MainActivity : AppCompatActivity() {
private val firstnames = arrayOf("Renato", "Rosangela", "Tim", "Barton", "Jeannette", "Ali", "Becky", "Coco", "Ragnar")
private val lastnames = arrayOf("Ksenia", "MetLife", "Asuncion", "Zemfira", "Gang", "G", "G", "A", "B")
private val jobTitles = arrayOf("District Quality Coordinator","International Intranet Representative","District Intranet Administrator","Dynamic Research Manager","Central Infrastructure Consultant", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen")
// function displays employees data in UI
private fun showEmployeeData(index: Int) {
// find TextView's from the UI layout file
val firstNameTextview = findViewById<TextView>(R.id.first_name)
val lastNameTextView = findViewById<TextView>(R.id.last_name)
val jobTitleTextView = findViewById<TextView>(R.id.job_title)
val employeeInfoTextView = findViewById<TextView>(R.id.employee_info_text)
// Update TextView texts
firstNameTextview.text = firstnames[index]
lastNameTextView.text = lastnames[index]
jobTitleTextView.text = jobTitles[index]
// info is
employeeInfoTextView.text = getString(R.string.employee_info_text, lastnames[index], firstnames[index], jobTitles[index], getString(R.string.description))
// image
var id = 0
when(index) {
0 -> id = R.drawable.employee1
1 -> id = R.drawable.employee2
2 -> id = R.drawable.employee3
3 -> id = R.drawable.employee4
4 -> id = R.drawable.employee5
5 -> id = R.drawable.employee6
6 -> id = R.drawable.employee7
7 -> id = R.drawable.employee8
8 -> id = R.drawable.employee9
}
// find imageView and display correct employee image
val imageView = findViewById<ImageView>(R.id.employee_image)
imageView.setImageResource(id)
}
// function will be called from the UI
fun numberClicked(view: View?) {
// get clicked view as a textview and it text as a string
val text = (view as TextView).text.toString()
println(text)
// modify string to int and decrease by one (array's start position 0)
val int = text.toInt() - 1
// show selected employee data in UI, call earlier made function
showEmployeeData(int)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
showEmployeeData(0)
}
}
\ No newline at end of file
E03BuildUIWithLayoutEditor2/app/src/main/res/drawable/employee1.png

5.78 KiB

E03BuildUIWithLayoutEditor2/app/src/main/res/drawable/employee10.png

6.2 KiB

E03BuildUIWithLayoutEditor2/app/src/main/res/drawable/employee2.png

5.66 KiB

E03BuildUIWithLayoutEditor2/app/src/main/res/drawable/employee3.png

5.9 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment