Skip to content

Commit

Permalink
Add task affinity sample
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwiz committed Apr 29, 2021
1 parent df36a2a commit 4d46c26
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 38 deletions.
16 changes: 0 additions & 16 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.5.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.android.material:material:1.3.0-alpha02'
implementation "androidx.biometric:biometric:1.0.1"
implementation 'androidx.core:core-ktx:1.6.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation "androidx.biometric:biometric:1.1.0"

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha07'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation 'androidx.activity:activity-ktx:1.2.0-alpha08'
implementation 'androidx.fragment:fragment-ktx:1.3.0-alpha08'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation 'androidx.activity:activity-ktx:1.3.0-alpha07'
implementation 'androidx.fragment:fragment-ktx:1.3.3'

implementation 'com.jakewharton.timber:timber:4.7.1'

testImplementation 'androidx.test:runner:1.3.0'
testImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation 'androidx.test.ext:junit:1.1.2'
testImplementation 'org.robolectric:robolectric:4.4'
testImplementation 'com.willowtreeapps.assertk:assertk-jvm:0.22'
testImplementation 'org.robolectric:robolectric:4.5.1'
testImplementation 'com.willowtreeapps.assertk:assertk-jvm:0.23.1'

androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".constracts.CustomPermissionActivity"></activity>
<activity
android:name=".task.affinity.TaskAffinityActivity"
android:taskAffinity=".TheOtherTask" />
<activity android:name=".constracts.CustomPermissionActivity" />
<activity android:name=".constracts.PermissionExampleActivity" />

<receiver
Expand Down Expand Up @@ -52,4 +55,4 @@
</activity>
</application>

</manifest>
</manifest>
4 changes: 3 additions & 1 deletion app/src/main/java/net/orgiu/tests/main/Functionalities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import net.orgiu.tests.lce.LceActivity
import net.orgiu.tests.networkrequest.NetworkRequestActivity
import net.orgiu.tests.nightmode.NightModeActivity
import net.orgiu.tests.snackbar.SnackbarActivity
import net.orgiu.tests.task.affinity.TaskAffinityActivity
import net.orgiu.tests.textscaling.TextScalingActivity
import net.orgiu.tests.textscaling.TextScalingDataBindingOnlyActivity

Expand All @@ -35,7 +36,8 @@ val functions = arrayOf(
Functionality(R.string.fragment_lifecycle, FragmentListenerActivity::class.java),
Functionality(R.string.lce, LceActivity::class.java),
Functionality(R.string.contracts, ContractsActivity::class.java),
Functionality(R.string.intent_sender, IntentSenderActivity::class.java)
Functionality(R.string.intent_sender, IntentSenderActivity::class.java),
Functionality(R.string.task_affinity, TaskAffinityActivity::class.java)
)

fun AppCompatActivity.launchBy(functionality: Functionality<*>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.orgiu.tests.task.affinity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import net.orgiu.tests.R
import net.orgiu.tests.databinding.ActivityTaskAffinityBinding
import kotlin.properties.Delegates
import kotlin.random.Random.Default.nextInt

class TaskAffinityActivity : AppCompatActivity() {

private var binding : ActivityTaskAffinityBinding by Delegates.notNull()
private val charPool : List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityTaskAffinityBinding.inflate(layoutInflater)

setContentView(binding.root)

binding.btnNewActivity.setOnClickListener {
startActivity(Intent(this, TaskAffinityActivity::class.java))
}

binding.btnCloseAffinity.setOnClickListener {
finishAffinity()
}

binding.textView.text = generateRandomText()
}

private fun generateRandomText(): CharSequence {
val length = nextInt(0, 1000)
return (1..length)
.map { nextInt(0, charPool.size) }
.map(charPool::get)
.joinToString("")
}
}
44 changes: 44 additions & 0 deletions app/src/main/res/layout/activity_task_affinity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".task.affinity.TaskAffinityActivity">

<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnNewActivity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:text="New Activity Of Same Task"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btnCloseAffinity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Close Affinity"
app:layout_constraintBottom_toTopOf="@+id/btnNewActivity"
app:layout_constraintEnd_toEndOf="@+id/btnNewActivity"
app:layout_constraintStart_toStartOf="@+id/btnNewActivity" />
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
<string name="lce">LCE</string>
<string name="contracts">Activity Results Contracts</string>
<string name="intent_sender">Intent Sender</string>
<string name="task_affinity">Task Affinity</string>
</resources>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.0'
ext.kotlin_version = '1.4.32'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-alpha11'
classpath 'com.android.tools.build:gradle:4.2.0-rc01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath 'com.novoda:gradle-build-properties-plugin:0.4.1'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.6.1-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':openoffline', ':weightwatcher', ':branchview'
include ':app'

0 comments on commit 4d46c26

Please sign in to comment.