-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
416 additions
and
34 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
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
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
78 changes: 78 additions & 0 deletions
78
manager/src/main/java/moe/shizuku/manager/cmd/TerminalTutorialActivity.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,78 @@ | ||
package moe.shizuku.manager.cmd | ||
|
||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.provider.DocumentsContract | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import moe.shizuku.manager.R | ||
import moe.shizuku.manager.app.AppBarActivity | ||
import moe.shizuku.manager.databinding.TerminalTutorialActivityBinding | ||
import moe.shizuku.manager.ktx.toHtml | ||
import rikka.widget.borderview.BorderView | ||
|
||
class TerminalTutorialActivity : AppBarActivity() { | ||
|
||
private val openDocumentsTree = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { tree: Uri? -> | ||
if (tree == null) return@registerForActivityResult | ||
|
||
val cr = contentResolver | ||
val doc = DocumentsContract.buildDocumentUriUsingTree(tree, DocumentsContract.getTreeDocumentId(tree)) | ||
val child = DocumentsContract.buildChildDocumentsUriUsingTree(tree, DocumentsContract.getTreeDocumentId(tree)) | ||
|
||
cr.query(child, arrayOf(DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME), null, null, null)?.use { | ||
while (it.moveToNext()) { | ||
val id = it.getString(0) | ||
val name = it.getString(1) | ||
if (name == "shizuku" || name == "shizuku.dex") { | ||
DocumentsContract.deleteDocument(cr, DocumentsContract.buildDocumentUriUsingTree(tree, id)) | ||
} | ||
} | ||
} | ||
|
||
fun writeToDocument(name: String) { | ||
DocumentsContract.createDocument(contentResolver, doc, "application/octet-stream", name)?.runCatching { | ||
cr.openOutputStream(this)?.let { assets.open(name).copyTo(it) } | ||
} | ||
} | ||
|
||
writeToDocument("shizuku") | ||
writeToDocument("shizuku.dex") | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
val binding = TerminalTutorialActivityBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
appBar?.setDisplayHomeAsUpEnabled(true) | ||
|
||
binding.apply { | ||
scrollView.borderVisibilityChangedListener = BorderView.OnBorderVisibilityChangedListener { top: Boolean, _: Boolean, _: Boolean, _: Boolean -> appBar?.setRaised(!top) } | ||
|
||
val shizukuName = "<font face=\"monospace\">shizuku</font>" | ||
val shizukuDexName = "<font face=\"monospace\">shizuku.dex</font>" | ||
|
||
text1.text = getString(R.string.terminal_tutorial_1, shizukuName, shizukuDexName).toHtml() | ||
|
||
text2.text = getString(R.string.terminal_tutorial_2, shizukuName).toHtml() | ||
summary2.text = getString( | ||
R.string.terminal_tutorial_2_description, | ||
"Termux", | ||
"<font face=\"monospace\">PKG</font>", | ||
"<font face=\"monospace\">com.termux</font>", | ||
"<font face=\"monospace\">com.termux</font>", | ||
).toHtml() | ||
|
||
text3.text = getString( | ||
R.string.terminal_tutorial_3, | ||
"<font face=\"monospace\">sh shizuku</font>", | ||
).toHtml() | ||
summary3.text = getString(R.string.terminal_tutorial_3_description, | ||
shizukuName, "<font face=\"monospace\">PATH</font>" | ||
).toHtml() | ||
|
||
button1.setOnClickListener { openDocumentsTree.launch(null) } | ||
} | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
manager/src/main/java/moe/shizuku/manager/home/TerminalViewHolder.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,40 @@ | ||
package moe.shizuku.manager.home | ||
|
||
import android.content.Intent | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import moe.shizuku.manager.R | ||
import moe.shizuku.manager.cmd.TerminalTutorialActivity | ||
import moe.shizuku.manager.databinding.HomeTerminalBinding | ||
import moe.shizuku.manager.model.ServiceStatus | ||
import rikka.recyclerview.BaseViewHolder | ||
import rikka.recyclerview.BaseViewHolder.Creator | ||
|
||
class TerminalViewHolder(private val binding: HomeTerminalBinding) : BaseViewHolder<ServiceStatus>(binding.root), View.OnClickListener { | ||
|
||
companion object { | ||
val CREATOR = Creator<ServiceStatus> { inflater: LayoutInflater, parent: ViewGroup? -> TerminalViewHolder(HomeTerminalBinding.inflate(inflater, parent, false)) } | ||
} | ||
|
||
init { | ||
itemView.setOnClickListener(this) | ||
} | ||
|
||
private inline val summary get() = binding.text2 | ||
|
||
override fun onBind() { | ||
val context = itemView.context | ||
if (!data.isRunning) { | ||
itemView.isEnabled = false | ||
summary.text = context.getString(R.string.home_status_service_not_running, context.getString(R.string.app_name)) | ||
} else { | ||
itemView.isEnabled = true | ||
summary.text = context.getString(R.string.home_terminal_description) | ||
} | ||
} | ||
|
||
override fun onClick(v: View) { | ||
v.context.startActivity(Intent(v.context, TerminalTutorialActivity::class.java)) | ||
} | ||
} |
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
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
8 changes: 8 additions & 0 deletions
8
manager/src/main/res/drawable/ic_numeric_1_circle_outline_24.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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:width="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path android:fillColor="#000" android:pathData="M10,7H14V17H12V9H10V7M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4Z" /> | ||
</vector> |
8 changes: 8 additions & 0 deletions
8
manager/src/main/res/drawable/ic_numeric_2_circle_outline_24.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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:width="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path android:fillColor="#000" android:pathData="M9,7H13A2,2 0 0,1 15,9V11A2,2 0 0,1 13,13H11V15H15V17H11L9,17V13A2,2 0 0,1 11,11H13V9H9V7M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4Z" /> | ||
</vector> |
8 changes: 8 additions & 0 deletions
8
manager/src/main/res/drawable/ic_numeric_3_circle_outline_24.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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:width="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path android:fillColor="#000" android:pathData="M15,15A2,2 0 0,1 13,17H9V15H13V13H11V11H13V9H9V7H13A2,2 0 0,1 15,9V10.5A1.5,1.5 0 0,1 13.5,12A1.5,1.5 0 0,1 15,13.5V15M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4Z" /> | ||
</vector> |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:width="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path android:fillColor="#000" android:pathData="M20,19V7H4V19H20M20,3A2,2 0 0,1 22,5V19A2,2 0 0,1 20,21H4A2,2 0 0,1 2,19V5C2,3.89 2.9,3 4,3H20M13,17V15H18V17H13M9.58,13L5.57,9H8.4L11.7,12.3C12.09,12.69 12.09,13.33 11.7,13.72L8.42,17H5.59L9.58,13Z" /> | ||
</vector> |
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,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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" | ||
style="?homeCardStyle" | ||
android:gravity="center_vertical" | ||
android:orientation="horizontal"> | ||
|
||
<moe.shizuku.manager.widget.MaterialCircleIconView | ||
android:id="@android:id/icon" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:duplicateParentState="true" | ||
android:importantForAccessibility="no" | ||
android:src="@drawable/ic_terminal_24" | ||
app:iconColorName="deep_purple" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="16dp" | ||
android:duplicateParentState="true" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@android:id/text1" | ||
style="@style/CardTitle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:duplicateParentState="true" | ||
android:text="@string/home_terminal_title" /> | ||
|
||
<TextView | ||
android:id="@android:id/text2" | ||
style="@style/CardSummary" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:duplicateParentState="true" | ||
tools:text="@string/home_terminal_description" /> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
Oops, something went wrong.