-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: set up sample app test env with robolectric
- Loading branch information
Showing
10 changed files
with
269 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
sample/app/src/main/java/me/xx2bab/caliper/sample/MainActivity.kt
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
sample/app/src/main/kotlin/me/xx2bab/caliper/sample/BatteryOptimizationActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package me.xx2bab.caliper.sample | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
|
||
class BatteryOptimizationActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_battery_optimization) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
sample/app/src/main/kotlin/me/xx2bab/caliper/sample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.xx2bab.caliper.sample | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Button | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import me.xx2bab.caliper.sample.library.LibrarySampleClass | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
findViewById<Button>(R.id.navi_to_privacy).setOnClickListener { | ||
startActivity(Intent(this, PrivacyActivity::class.java)) | ||
} | ||
findViewById<Button>(R.id.navi_to_battery_optimization).setOnClickListener { | ||
startActivity(Intent(this, BatteryOptimizationActivity::class.java)) | ||
} | ||
|
||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
sample/app/src/main/kotlin/me/xx2bab/caliper/sample/PrivacyActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package me.xx2bab.caliper.sample | ||
|
||
import android.os.Build | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.provider.Settings | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import androidx.annotation.RequiresApi | ||
|
||
class PrivacyActivity : AppCompatActivity() { | ||
|
||
lateinit var outputTv: TextView | ||
lateinit var expectedTv: TextView | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
lateinit var triggerButtons: List<TriggerButton> | ||
|
||
override fun onRequestPermissionsResult( | ||
requestCode: Int, | ||
permissions: Array<out String>, | ||
grantResults: IntArray | ||
) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults) | ||
if(requestCode == 100) { | ||
outputTv.text = "true" | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_privacy) | ||
triggerButtons = listOf( | ||
TriggerButton( | ||
text = "getSerial()", | ||
id = 10001, | ||
expectedResult = "android/os/Build->getSerial", | ||
onClickListener = { | ||
outputTv.text = Build.getSerial() | ||
expectedTv.text = "" | ||
} | ||
), | ||
TriggerButton( | ||
text = "SERIAL", | ||
id = 10002, | ||
expectedResult = "android/os/Build->getSerialField", | ||
onClickListener = { | ||
outputTv.text = Build.SERIAL | ||
} | ||
), | ||
TriggerButton( | ||
text = "getString()", | ||
id = 10003, | ||
expectedResult = "android/provider/Settings\$Settings.Secure->getString", | ||
onClickListener = { | ||
outputTv.text = Settings.Secure.getString(this.application.contentResolver, | ||
Settings.Secure.ANDROID_ID) | ||
} | ||
), | ||
TriggerButton( | ||
text = "requestPermissions()", | ||
id = 10004, | ||
expectedResult = "android/app/Activity->requestPermissions", | ||
onClickListener = { | ||
requestPermissions(arrayOf("android.permission.READ_PHONE_STATE"), 100) | ||
} | ||
) | ||
) | ||
|
||
outputTv = findViewById(R.id.return_content) | ||
expectedTv = findViewById(R.id.expect_content) | ||
val buttonList = findViewById<LinearLayout>(R.id.button_list) | ||
|
||
triggerButtons.forEach { | ||
buttonList.addView(makeTriggerButton(this, it)) | ||
} | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
sample/app/src/main/kotlin/me/xx2bab/caliper/sample/TriggerButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.xx2bab.caliper.sample | ||
|
||
import android.content.Context | ||
import android.widget.Button | ||
|
||
data class TriggerButton( | ||
val text: String, | ||
val id: Int, | ||
val expectedResult: String, | ||
val onClickListener: () -> Unit | ||
) | ||
|
||
fun makeTriggerButton(context: Context, triggerButton: TriggerButton): Button { | ||
val button = Button(context) | ||
button.text = triggerButton.text | ||
button.id = triggerButton.id | ||
button.setOnClickListener { | ||
triggerButton.onClickListener() | ||
} | ||
return button | ||
} |
9 changes: 9 additions & 0 deletions
9
sample/app/src/main/res/layout/activity_battery_optimization.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?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=".BatteryOptimizationActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:padding="24dp" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
<!-- <TextView--> | ||
<!-- android:id="@+id/console_text"--> | ||
<!-- android:layout_width="wrap_content"--> | ||
<!-- android:layout_height="wrap_content"--> | ||
<!-- android:text="Hello Caliper."--> | ||
<!-- android:textSize="22sp"--> | ||
<!-- android:layout_centerInParent="true"/>--> | ||
|
||
|
||
<Button | ||
android:id="@+id/navi_to_privacy" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="PrivacyActivity" /> | ||
|
||
<Button | ||
android:id="@+id/navi_to_battery_optimization" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Hello Caliper." | ||
android:textSize="22sp" | ||
android:layout_centerInParent="true"/> | ||
android:text="BatteryOptimActivity" /> | ||
|
||
</RelativeLayout> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout 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" | ||
android:padding="24dp" | ||
tools:context=".PrivacyActivity"> | ||
|
||
<TextView | ||
android:id="@+id/return_title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="16dp" | ||
android:text="Return:" /> | ||
|
||
<TextView | ||
android:id="@+id/return_content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentEnd="true" | ||
android:layout_toEndOf="@id/return_title" | ||
android:text="" /> | ||
|
||
<TextView | ||
android:id="@+id/log_title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/return_content" | ||
android:layout_marginEnd="16dp" | ||
android:text="Log:" /> | ||
|
||
<TextView | ||
android:id="@+id/log_content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/return_content" | ||
android:layout_alignParentEnd="true" | ||
android:layout_toEndOf="@id/return_title" | ||
android:text="" /> | ||
|
||
<TextView | ||
android:id="@+id/expect_title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/log_content" | ||
android:layout_marginEnd="16dp" | ||
android:text="Expect:" /> | ||
|
||
<TextView | ||
android:id="@+id/expect_content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/return_content" | ||
android:layout_alignParentEnd="true" | ||
android:layout_toEndOf="@id/log_content" | ||
android:text="" /> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/expect_content" | ||
android:layout_alignParentBottom="true"> | ||
|
||
<LinearLayout | ||
android:id="@+id/button_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
</LinearLayout> | ||
</ScrollView> | ||
|
||
</RelativeLayout> |