Skip to content

Commit

Permalink
add home screen shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyiso01 committed Feb 6, 2021
1 parent b3261bd commit 5c0ce93
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 29 deletions.
24 changes: 8 additions & 16 deletions .idea/codeStyles/Project.xml

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

5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
minSdkVersion 19
targetSdkVersion 30
multiDexEnabled true
versionCode 3
versionName "0.0.3"
versionCode 4
versionName "0.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -52,4 +52,5 @@ dependencies {
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import org.junit.Assert.*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
class ExampleInstrumentedTest
{
@Test
fun useAppContext() {
fun useAppContext()
{
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.island.filemanagerutils", appContext.packageName)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.island.filemanagerutils.action.CREATE_FILE_SHORTCUT" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity android:name=".sftp.SFTPAuthenticationActivity">
<intent-filter>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/island/filemanagerutils/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.google.android.material.switchmaterial.SwitchMaterial
class MainActivity : AppCompatActivity()
{
private val TAG="MainActivity"
private val ACTION_CREATE_FILE_SHORTCUT="com.island.filemanagerutils.action.CREATE_FILE_SHORTCUT"
private val CREATE_FILE_SHORTCUT=1
override fun onCreate(savedInstanceState: Bundle?)
{
Expand Down Expand Up @@ -60,11 +61,16 @@ class MainActivity : AppCompatActivity()
if(!resources.getBoolean(R.bool.enable_apk_documents_provider))apkSwitch.visibility=View.GONE
if(!(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O&&(getSystemService(ShortcutManager::class.java)).isRequestPinShortcutSupported))
findViewById<View>(R.id.create_file_shortcut).visibility=View.GONE
if (intent!!.action==ACTION_CREATE_FILE_SHORTCUT)createFileShortcut()
}

fun createFileShortcut(view:View)
{
Log.i(TAG,"CreateFileShortcut $view")
}

private fun createFileShortcut()
{
val intent=Intent(Intent.ACTION_OPEN_DOCUMENT).apply()
{
addCategory(Intent.CATEGORY_OPENABLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class SFTPAuthenticationActivity:AppCompatActivity(),CoroutineScope by MainScope
{
Log.i(TAG, "OnCreate")
super.onCreate(savedInstanceState)
if(intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)==null)
{
finish()
return
}
setContentView(R.layout.authentication_activity)
val uri=intent.data
if (uri != null)
Expand All @@ -55,7 +50,7 @@ class SFTPAuthenticationActivity:AppCompatActivity(),CoroutineScope by MainScope
val user = (findViewById<View>(R.id.username) as EditText).text.toString()
val password = (findViewById<View>(R.id.password) as EditText).text.toString()
if (ip.isEmpty() || port.isEmpty() || user.isEmpty() || password.isEmpty()) return
val accountType = intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)
val accountType = getString(R.string.account_type)
val username = "$user@$ip:$port"
val account = Account(username, accountType)
val accountManager = AccountManager.get(this)
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/xml-v25/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="add_sftp"
android:enabled="true"
android:icon="@mipmap/sftp"
android:shortcutShortLabel="@string/add_account"
android:shortcutLongLabel="@string/add_account">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.island.filemanagerutils"
android:targetClass="com.island.filemanagerutils.sftp.SFTPAuthenticationActivity" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>
26 changes: 26 additions & 0 deletions app/src/main/res/xml-v26/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="add_sftp"
android:enabled="true"
android:icon="@mipmap/sftp"
android:shortcutShortLabel="@string/add_account"
android:shortcutLongLabel="@string/add_account">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.island.filemanagerutils"
android:targetClass="com.island.filemanagerutils.sftp.SFTPAuthenticationActivity" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
<shortcut
android:shortcutId="add_file_shortcut"
android:enabled="true"
android:icon="@mipmap/generic_file"
android:shortcutShortLabel="@string/create_file_shortcut"
android:shortcutLongLabel="@string/create_file_shortcut">
<intent
android:action="com.island.filemanagerutils.action.CREATE_FILE_SHORTCUT"
android:targetPackage="com.island.filemanagerutils"
android:targetClass="com.island.filemanagerutils.MainActivity" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.21"
ext.kotlin_version = "1.4.30"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "com.android.tools.build:gradle:4.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
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.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

0 comments on commit 5c0ce93

Please sign in to comment.