Skip to content

Commit 5c0ce93

Browse files
committed
add home screen shortcut
1 parent b3261bd commit 5c0ce93

10 files changed

Lines changed: 70 additions & 29 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 8 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
minSdkVersion 19
1515
targetSdkVersion 30
1616
multiDexEnabled true
17-
versionCode 3
18-
versionName "0.0.3"
17+
versionCode 4
18+
versionName "0.1.0"
1919

2020
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2121
}
@@ -52,4 +52,5 @@ dependencies {
5252
testImplementation 'junit:junit:4.13.1'
5353
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
5454
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
55+
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
5556
}

app/src/androidTest/java/com/island/filemanagerutils/ExampleInstrumentedTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import org.junit.Assert.*
1414
* See [testing documentation](http://d.android.com/tools/testing).
1515
*/
1616
@RunWith(AndroidJUnit4::class)
17-
class ExampleInstrumentedTest {
17+
class ExampleInstrumentedTest
18+
{
1819
@Test
19-
fun useAppContext() {
20+
fun useAppContext()
21+
{
2022
// Context of the app under test.
2123
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
2224
assertEquals("com.island.filemanagerutils", appContext.packageName)

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636

3737
<category android:name="android.intent.category.LAUNCHER" />
3838
</intent-filter>
39+
<intent-filter>
40+
<action android:name="com.island.filemanagerutils.action.CREATE_FILE_SHORTCUT" />
41+
</intent-filter>
42+
<meta-data android:name="android.app.shortcuts"
43+
android:resource="@xml/shortcuts" />
3944
</activity>
4045
<activity android:name=".sftp.SFTPAuthenticationActivity">
4146
<intent-filter>

app/src/main/java/com/island/filemanagerutils/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.google.android.material.switchmaterial.SwitchMaterial
2727
class MainActivity : AppCompatActivity()
2828
{
2929
private val TAG="MainActivity"
30+
private val ACTION_CREATE_FILE_SHORTCUT="com.island.filemanagerutils.action.CREATE_FILE_SHORTCUT"
3031
private val CREATE_FILE_SHORTCUT=1
3132
override fun onCreate(savedInstanceState: Bundle?)
3233
{
@@ -60,11 +61,16 @@ class MainActivity : AppCompatActivity()
6061
if(!resources.getBoolean(R.bool.enable_apk_documents_provider))apkSwitch.visibility=View.GONE
6162
if(!(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O&&(getSystemService(ShortcutManager::class.java)).isRequestPinShortcutSupported))
6263
findViewById<View>(R.id.create_file_shortcut).visibility=View.GONE
64+
if (intent!!.action==ACTION_CREATE_FILE_SHORTCUT)createFileShortcut()
6365
}
6466

6567
fun createFileShortcut(view:View)
6668
{
6769
Log.i(TAG,"CreateFileShortcut $view")
70+
}
71+
72+
private fun createFileShortcut()
73+
{
6874
val intent=Intent(Intent.ACTION_OPEN_DOCUMENT).apply()
6975
{
7076
addCategory(Intent.CATEGORY_OPENABLE)

app/src/main/java/com/island/filemanagerutils/sftp/SFTPAuthenticationActivity.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class SFTPAuthenticationActivity:AppCompatActivity(),CoroutineScope by MainScope
2727
{
2828
Log.i(TAG, "OnCreate")
2929
super.onCreate(savedInstanceState)
30-
if(intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)==null)
31-
{
32-
finish()
33-
return
34-
}
3530
setContentView(R.layout.authentication_activity)
3631
val uri=intent.data
3732
if (uri != null)
@@ -55,7 +50,7 @@ class SFTPAuthenticationActivity:AppCompatActivity(),CoroutineScope by MainScope
5550
val user = (findViewById<View>(R.id.username) as EditText).text.toString()
5651
val password = (findViewById<View>(R.id.password) as EditText).text.toString()
5752
if (ip.isEmpty() || port.isEmpty() || user.isEmpty() || password.isEmpty()) return
58-
val accountType = intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)
53+
val accountType = getString(R.string.account_type)
5954
val username = "$user@$ip:$port"
6055
val account = Account(username, accountType)
6156
val accountManager = AccountManager.get(this)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
2+
<shortcut
3+
android:shortcutId="add_sftp"
4+
android:enabled="true"
5+
android:icon="@mipmap/sftp"
6+
android:shortcutShortLabel="@string/add_account"
7+
android:shortcutLongLabel="@string/add_account">
8+
<intent
9+
android:action="android.intent.action.VIEW"
10+
android:targetPackage="com.island.filemanagerutils"
11+
android:targetClass="com.island.filemanagerutils.sftp.SFTPAuthenticationActivity" />
12+
<categories android:name="android.shortcut.conversation" />
13+
</shortcut>
14+
</shortcuts>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
2+
<shortcut
3+
android:shortcutId="add_sftp"
4+
android:enabled="true"
5+
android:icon="@mipmap/sftp"
6+
android:shortcutShortLabel="@string/add_account"
7+
android:shortcutLongLabel="@string/add_account">
8+
<intent
9+
android:action="android.intent.action.VIEW"
10+
android:targetPackage="com.island.filemanagerutils"
11+
android:targetClass="com.island.filemanagerutils.sftp.SFTPAuthenticationActivity" />
12+
<categories android:name="android.shortcut.conversation" />
13+
</shortcut>
14+
<shortcut
15+
android:shortcutId="add_file_shortcut"
16+
android:enabled="true"
17+
android:icon="@mipmap/generic_file"
18+
android:shortcutShortLabel="@string/create_file_shortcut"
19+
android:shortcutLongLabel="@string/create_file_shortcut">
20+
<intent
21+
android:action="com.island.filemanagerutils.action.CREATE_FILE_SHORTCUT"
22+
android:targetPackage="com.island.filemanagerutils"
23+
android:targetClass="com.island.filemanagerutils.MainActivity" />
24+
<categories android:name="android.shortcut.conversation" />
25+
</shortcut>
26+
</shortcuts>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.4.21"
3+
ext.kotlin_version = "1.4.30"
44
repositories {
55
google()
66
jcenter()
77
}
88
dependencies {
9-
classpath "com.android.tools.build:gradle:4.1.2"
9+
classpath "com.android.tools.build:gradle:4.0.2"
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111

1212
// NOTE: Do not place your application dependencies here; they belong

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

0 commit comments

Comments
 (0)