commit 9b334ffd25e837f7d9068307ed0ddfcdaef517e7 Author: yova Date: Sat Feb 11 20:48:39 2023 +0100 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.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 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..d80a3f5 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..f3bbb26 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7766bbc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..2ad848a --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,53 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' + id 'kotlin-android-extensions' +} + +android { + compileSdk 33 + + defaultConfig { + applicationId "sgd.and04.layout" + minSdk 27 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled 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.7.0' + implementation 'androidx.appcompat:appcompat:1.6.0' + //noinspection GradleCompatible +// implementation 'com.android.support:appcompat-v7:28.0.0' + + + implementation 'com.google.android.material:material:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation fileTree(dir: 'libs', include: ['*.jar']) +// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7" +// +// implementation 'com.android.support.constraint:constraint-layout:1.1.2' + implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0' + 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 diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# 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 diff --git a/app/src/androidTest/java/sgd/and04/layout/ExampleInstrumentedTest.kt b/app/src/androidTest/java/sgd/and04/layout/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..79b009b --- /dev/null +++ b/app/src/androidTest/java/sgd/and04/layout/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package sgd.and04.layout + +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("sgd.and04.layout", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a43a6a1 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/sgd/and04/layout/DistanceActivity.kt b/app/src/main/java/sgd/and04/layout/DistanceActivity.kt new file mode 100644 index 0000000..f451bfc --- /dev/null +++ b/app/src/main/java/sgd/and04/layout/DistanceActivity.kt @@ -0,0 +1,94 @@ +package sgd.and04.layout + +import androidx.appcompat.app.AppCompatActivity +import android.os.Build +import android.os.Bundle +import android.widget.Button +import android.widget.SeekBar +import android.widget.TextView +import androidx.annotation.RequiresApi +import pavelsobolev.kotogl.Helpers.ZObjectsPos + +// activity for setting distances of the scene's objects +class DistanceActivity : AppCompatActivity() +{ + private var sbars: Array? = null + private var txts: Array? = null + private var txtids: IntArray? = null + private val MIN_DIST = 3 + + private var i = 0 + + @RequiresApi(api = Build.VERSION_CODES.N) + override fun onCreate(savedInstanceState: Bundle?) + { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_distance) + + setArraysOfControls() + + i = 0 + while (i < 5) + { + setDataToInterface(sbars!![i], i, txts!![i]) + sbars!![i].setOnSeekBarChangeListener( + object : SeekBar.OnSeekBarChangeListener { + var pos = i + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) + { + getDataFromInterface(sbars!![pos], pos, txts!![pos]) + } + override fun onStopTrackingTouch(seekBar: SeekBar) {} + override fun onStartTrackingTouch(seekBar: SeekBar) {} + }) + i++ + } + + (findViewById(R.id.buttonOk) as Button).setOnClickListener { view -> + setResult(AppCompatActivity.RESULT_OK) + finish() + } + + (findViewById(R.id.buttonCancel) as Button).setOnClickListener { view -> + setResult(AppCompatActivity.RESULT_CANCELED) + finish() + } + } + + private fun setArraysOfControls() + { + sbars = arrayOf( + findViewById(R.id.seekBarCentral) as SeekBar, + findViewById(R.id.seekBarLeft) as SeekBar, + findViewById(R.id.seekBarRight) as SeekBar, + findViewById(R.id.seekBarTop) as SeekBar, + findViewById(R.id.seekBarBottom) as SeekBar) + + txts = arrayOf( + findViewById(R.id.textViewCenter) as TextView, + findViewById(R.id.textViewLeft) as TextView, + findViewById(R.id.textViewRight) as TextView, + findViewById(R.id.textViewTop) as TextView, + findViewById(R.id.textViewBottom) as TextView) + + txtids = intArrayOf( + R.string.center_pos_txt, + R.string.left_pos_txt, + R.string.right_pos_txt, + R.string.top_pos_txt, + R.string.bottom_pos_txt) + } + + private fun getDataFromInterface(sb: SeekBar, i: Int, tv: TextView) + { + tv.text = String.format("%s is %d units", getString(txtids!![i]), sb.progress + MIN_DIST) + ZObjectsPos.setPosition(i, -(sb.progress + MIN_DIST)) + } + + @RequiresApi(api = Build.VERSION_CODES.N) + private fun setDataToInterface(sb: SeekBar, i: Int, tv: TextView) + { + tv.text = String.format("%s is %d units", getString(txtids!![i]), -ZObjectsPos.getPosition(i)) + sb.setProgress(-ZObjectsPos.getPosition(i) - MIN_DIST, true) + } +} diff --git a/app/src/main/java/sgd/and04/layout/FrameActivity.kt b/app/src/main/java/sgd/and04/layout/FrameActivity.kt new file mode 100644 index 0000000..e7b991f --- /dev/null +++ b/app/src/main/java/sgd/and04/layout/FrameActivity.kt @@ -0,0 +1,18 @@ +package sgd.and04.layout + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.view.View + +class FrameActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_frame) + } + + fun onLayoutClick(view: View) { + startActivity(Intent(this, MainActivity::class.java)) + } + +} \ No newline at end of file diff --git a/app/src/main/java/sgd/and04/layout/GridActivity.kt b/app/src/main/java/sgd/and04/layout/GridActivity.kt new file mode 100644 index 0000000..75de81b --- /dev/null +++ b/app/src/main/java/sgd/and04/layout/GridActivity.kt @@ -0,0 +1,29 @@ +package sgd.and04.layout + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.view.View + +class GridActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_grid) + } + + fun onButtonTableLayoutClick(view: View) { + startActivity(Intent(this, TableActivity::class.java)) + } + fun onButtonLinearLayoutClick(view: View) { + startActivity(Intent(this, MainActivity::class.java)) + } + + fun onButtonRelativeLayoutClick(view: View) { + startActivity(Intent(this, RelativeActivity::class.java)) + } + + fun onButtonFrameLayoutClick(view: View) { + startActivity(Intent(this, FrameActivity::class.java)) + } + +} \ No newline at end of file diff --git a/app/src/main/java/sgd/and04/layout/Helpers/TiltData.kt b/app/src/main/java/sgd/and04/layout/Helpers/TiltData.kt new file mode 100644 index 0000000..4253032 --- /dev/null +++ b/app/src/main/java/sgd/and04/layout/Helpers/TiltData.kt @@ -0,0 +1,61 @@ +package pavelsobolev.kotogl.Helpers + +import java.util.* + + +// the class calculates angle of tilt of a device (on the base of data from its accelerator) +object TiltData : Observable() +{ + private var xTilt : Float = 0.0f + private var yTilt : Float = 0.0f + private var tiltScale : Float = 1.5f + + init + { + setData(0.0f,0.0f) + tiltScale = 1.5f + } + + // sets new tilt data for current object + fun setData(x:Float, y:Float) + { + if (Math.abs(x)>10 || Math.abs(y)>10) return; + + xTilt = x + yTilt = y + setChanged() + notifyObservers() + } + + fun getDirection(): TiltDirections + { + return getDirection(xTilt, yTilt) + } + + fun getDirection(tiltX:Float, tiltY:Float) : TiltDirections + { + if (Math.abs(Math.abs(tiltX)-Math.abs(tiltY)) <= 3.0) + { + return TiltDirections.UNKNOWN + } + + if (Math.abs(tiltX) > Math.abs(tiltY)) + { + if (tiltX < 0) return TiltDirections.RIGHT + if (tiltX > 0) return TiltDirections.LEFT + } + else + { + if (tiltY < 0) return TiltDirections.UP + if (tiltY > 0) return TiltDirections.DOWN + } + + val threshold = 1.0f + if (tiltX > -threshold && tiltX < threshold && tiltY > -threshold && tiltY < threshold) + { + return TiltDirections.UNKNOWN + } + + return TiltDirections.UNKNOWN + } +} \ No newline at end of file diff --git a/app/src/main/java/sgd/and04/layout/Helpers/TiltDirections.kt b/app/src/main/java/sgd/and04/layout/Helpers/TiltDirections.kt new file mode 100644 index 0000000..97a8590 --- /dev/null +++ b/app/src/main/java/sgd/and04/layout/Helpers/TiltDirections.kt @@ -0,0 +1,11 @@ +package pavelsobolev.kotogl.Helpers + +/** + * enumeration describes the possible direction of tilts + * from device's accelerometer + */ +enum class TiltDirections +{ + UP, DOWN, LEFT, RIGHT, UNKNOWN + //UNKNOWN means that there is not now strong tilt to some specific direction +} diff --git a/app/src/main/java/sgd/and04/layout/Helpers/ZObjectsPos.kt b/app/src/main/java/sgd/and04/layout/Helpers/ZObjectsPos.kt new file mode 100644 index 0000000..e477e50 --- /dev/null +++ b/app/src/main/java/sgd/and04/layout/Helpers/ZObjectsPos.kt @@ -0,0 +1,30 @@ +package pavelsobolev.kotogl.Helpers + +// distances from point of view to objects of 3D scene +object ZObjectsPos +{ + /** + * 0=>central polyhedron z-position, 1=>left, 2=>right, 3=>top, 4=>bottom + */ + private var zPositions: IntArray + + init + { + zPositions = IntArray(5) + zPositions[0] = -6 + zPositions[1] = -7 + zPositions[2] = -6 + zPositions[3] = -7 + zPositions[4] = -7 + } + + fun setPosition(pos: Int, newVal: Int) + { + zPositions[pos] = newVal + } + + fun getPosition(pos: Int): Int + { + return zPositions[pos] + } +} diff --git a/app/src/main/java/sgd/and04/layout/ImageSwitcherActivity.kt b/app/src/main/java/sgd/and04/layout/ImageSwitcherActivity.kt new file mode 100644 index 0000000..66da2d4 --- /dev/null +++ b/app/src/main/java/sgd/and04/layout/ImageSwitcherActivity.kt @@ -0,0 +1,67 @@ +package sgd.and04.layout + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.view.View +import android.widget.FrameLayout +import android.widget.ImageSwitcher +import android.widget.ImageView +import android.view.animation.AnimationUtils +import android.widget.Button + +class ImageSwitcherActivity : AppCompatActivity() { + + private val flowers = intArrayOf(R.drawable.flower1, R.drawable.flower2, + R.drawable.flower4) + private var index = 0 + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_image_switcher) + // create the ImageSwitcher + val imgSwitcher = ImageSwitcher(this) + + imgSwitcher?.setFactory({ + val imgView = ImageView(applicationContext) + imgView.scaleType = ImageView.ScaleType.CENTER + imgView.setPadding(20, 20, 20, 20) + imgView.setAdjustViewBounds(true) + imgView.setMaxHeight(2400) + + imgView + }) + + val c_Layout = findViewById(R.id.scrollView) + //add ImageSwitcher in constraint layout + c_Layout?.addView(imgSwitcher) + + // set the method and pass array as a parameter + imgSwitcher?.setImageResource(flowers[index]) + + val imgIn = AnimationUtils.loadAnimation( + this, android.R.anim.slide_in_left) + imgSwitcher?.inAnimation = imgIn + + val imgOut = AnimationUtils.loadAnimation( + this, android.R.anim.slide_out_right) + imgSwitcher?.outAnimation = imgOut + + // previous button functionality + val prev = findViewById