| @@ -28,8 +28,8 @@ dependencies { | |||
| implementation 'com.android.support:appcompat-v7:26.0.2' | |||
| implementation 'com.android.support.constraint:constraint-layout:1.0.2' | |||
| testImplementation 'junit:junit:4.12' | |||
| androidTestImplementation ('com.android.support.test.espresso:espresso-core:3.0.1', { | |||
| androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', { | |||
| exclude group: 'com.android.support', module: 'support-annotations' | |||
| }) | |||
| implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | |||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | |||
| } | |||
| @@ -16,6 +16,7 @@ | |||
| <category android:name="android.intent.category.LAUNCHER" /> | |||
| </intent-filter> | |||
| </activity> | |||
| <activity android:name=".EditActivity"></activity> | |||
| </application> | |||
| </manifest> | |||
| @@ -0,0 +1,48 @@ | |||
| package de.mlte.soundboard | |||
| import android.app.Activity | |||
| import android.content.Intent | |||
| import android.net.Uri | |||
| import android.support.v7.app.AppCompatActivity | |||
| import android.os.Bundle | |||
| import android.widget.Button | |||
| import android.widget.EditText | |||
| class EditActivity : AppCompatActivity() { | |||
| override fun onCreate(savedInstanceState: Bundle?) { | |||
| super.onCreate(savedInstanceState) | |||
| setContentView(R.layout.activity_edit) | |||
| val captionEditText = findViewById<EditText>(R.id.captionEditText) | |||
| captionEditText.setText(intent.getStringExtra("caption")) | |||
| val okButton = findViewById<Button>(R.id.okButton) | |||
| okButton.setOnClickListener { | |||
| val intent = Intent() | |||
| intent.putExtra("caption", captionEditText.text.toString()) | |||
| intent.putExtra("uri", currentUri) | |||
| setResult(Activity.RESULT_OK, intent) | |||
| finish() | |||
| } | |||
| val selectButton = findViewById<Button>(R.id.selectButton) | |||
| selectButton.setOnClickListener { | |||
| val intent = Intent() | |||
| .setType("audio/*") | |||
| .setAction(Intent.ACTION_GET_CONTENT) | |||
| startActivityForResult(intent, 123) | |||
| } | |||
| } | |||
| var currentUri: Uri? = null | |||
| override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |||
| super.onActivityResult(requestCode, resultCode, data) | |||
| if (requestCode == 123 && resultCode == Activity.RESULT_OK && data != null) { | |||
| currentUri = data.data | |||
| } | |||
| } | |||
| } | |||
| @@ -64,11 +64,11 @@ class MainActivity : AppCompatActivity() { | |||
| } | |||
| btn.setOnLongClickListener { | |||
| val intent = Intent() | |||
| .setType("audio/*") | |||
| .setAction(Intent.ACTION_GET_CONTENT) | |||
| val intent = Intent(baseContext, EditActivity::class.java) | |||
| intent.putExtra("uri", currentUri) | |||
| intent.putExtra("caption", btn.text) | |||
| startActivityForResult(intent, 1234) | |||
| startActivityForResult(Intent.createChooser(intent, "Select a file"), 123) | |||
| true | |||
| } | |||
| } | |||
| @@ -78,8 +78,11 @@ class MainActivity : AppCompatActivity() { | |||
| override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |||
| super.onActivityResult(requestCode, resultCode, data) | |||
| if (requestCode == 123 && resultCode == Activity.RESULT_OK && data != null) { | |||
| currentUri = data.data | |||
| if (requestCode == 1234 && resultCode == Activity.RESULT_OK && data != null) { | |||
| val btn = findViewById<TextView>(R.id.text_view_button) | |||
| btn.setText(data.getStringExtra("caption")) | |||
| currentUri = data.getParcelableExtra<Uri>("uri") | |||
| grantUriPermission(getPackageName(), currentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION) | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,58 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
| xmlns:app="http://schemas.android.com/apk/res-auto" | |||
| xmlns:tools="http://schemas.android.com/tools" | |||
| android:layout_width="match_parent" | |||
| android:layout_height="match_parent" | |||
| tools:context="de.mlte.soundboard.EditActivity"> | |||
| <Button | |||
| android:id="@+id/okButton" | |||
| android:layout_width="wrap_content" | |||
| android:layout_height="wrap_content" | |||
| android:layout_marginBottom="0dp" | |||
| android:layout_marginEnd="0dp" | |||
| android:layout_marginStart="0dp" | |||
| android:layout_marginTop="0dp" | |||
| android:text="OK" | |||
| app:layout_constraintBottom_toBottomOf="parent" | |||
| app:layout_constraintEnd_toEndOf="parent" | |||
| app:layout_constraintStart_toStartOf="parent" | |||
| app:layout_constraintTop_toBottomOf="@+id/captionEditText" | |||
| tools:layout_editor_absoluteX="116dp" | |||
| tools:layout_editor_absoluteY="231dp" /> | |||
| <EditText | |||
| android:id="@+id/captionEditText" | |||
| android:layout_width="wrap_content" | |||
| android:layout_height="wrap_content" | |||
| android:layout_marginBottom="0dp" | |||
| android:layout_marginEnd="0dp" | |||
| android:layout_marginStart="0dp" | |||
| android:layout_marginTop="0dp" | |||
| android:ems="10" | |||
| android:inputType="textPersonName" | |||
| android:text="Name" | |||
| app:layout_constraintBottom_toTopOf="@+id/okButton" | |||
| app:layout_constraintEnd_toEndOf="parent" | |||
| app:layout_constraintStart_toStartOf="parent" | |||
| app:layout_constraintTop_toBottomOf="@+id/selectButton" | |||
| tools:layout_editor_absoluteX="76dp" | |||
| tools:layout_editor_absoluteY="121dp" /> | |||
| <Button | |||
| android:id="@+id/selectButton" | |||
| android:layout_width="wrap_content" | |||
| android:layout_height="wrap_content" | |||
| android:layout_marginBottom="0dp" | |||
| android:layout_marginEnd="0dp" | |||
| android:layout_marginStart="0dp" | |||
| android:layout_marginTop="0dp" | |||
| android:text="Select File ..." | |||
| app:layout_constraintBottom_toTopOf="@+id/captionEditText" | |||
| app:layout_constraintEnd_toEndOf="parent" | |||
| app:layout_constraintStart_toStartOf="parent" | |||
| app:layout_constraintTop_toTopOf="parent" | |||
| tools:layout_editor_absoluteX="94dp" | |||
| tools:layout_editor_absoluteY="42dp" /> | |||
| </android.support.constraint.ConstraintLayout> | |||