This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Harsh Shandilya <[email protected]>
- Loading branch information
Showing
32 changed files
with
531 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright © 2019 Harsh Shandilya <[email protected]>. All Rights Reserved. | ||
* SPDX-License-Identifier: GPL-3.0-Only | ||
*/ | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
defaultConfig { | ||
applicationId "openpgpktx.sample" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation project(':library') | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'androidx.core:core-ktx:1.1.0' | ||
implementation 'androidx.preference:preference:1.1.0' | ||
} |
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 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="openpgpktx.sample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".SettingsActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
53 changes: 53 additions & 0 deletions
53
sample/src/main/kotlin/openpgpktx/sample/SettingsActivity.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,53 @@ | ||
/* | ||
* Copyright © 2019 Harsh Shandilya <[email protected]>. All Rights Reserved. | ||
* SPDX-License-Identifier: GPL-3.0-Only | ||
*/ | ||
package openpgpktx.sample | ||
|
||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.PreferenceManager | ||
import openpgpktx.sample.preference.OpenPgpAppPreference | ||
|
||
class SettingsActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.settings_activity) | ||
supportFragmentManager | ||
.beginTransaction() | ||
.replace(R.id.settings, SettingsFragment()) | ||
.commit() | ||
supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
return when (item.itemId) { | ||
android.R.id.home -> { | ||
finish() | ||
true | ||
} | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
|
||
class SettingsFragment : PreferenceFragmentCompat() { | ||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
setPreferencesFromResource(R.xml.root_preferences, rootKey) | ||
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext()) | ||
|
||
findPreference<OpenPgpAppPreference>("provider_app")?.apply { | ||
value = prefs.getString("provider_app", "None") | ||
summary = value | ||
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> | ||
prefs.edit().putString("provider_app", newValue as String).apply() | ||
summary = newValue | ||
true | ||
} | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
sample/src/main/kotlin/openpgpktx/sample/model/OpenPgpProviderEntry.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,12 @@ | ||
/* | ||
* Copyright © 2019 Harsh Shandilya <[email protected]>. All Rights Reserved. | ||
* SPDX-License-Identifier: GPL-3.0-Only | ||
*/ | ||
package openpgpktx.sample.model | ||
|
||
import android.content.Intent | ||
import android.graphics.drawable.Drawable | ||
|
||
data class OpenPgpProviderEntry(val packageName: String, val simpleName: String, val icon: Drawable? = null, val intent: Intent? = null) { | ||
override fun toString(): String = simpleName | ||
} |
29 changes: 29 additions & 0 deletions
29
sample/src/main/kotlin/openpgpktx/sample/preference/OpenPgpAppPreference.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,29 @@ | ||
/* | ||
* Copyright © 2019 Harsh Shandilya <[email protected]>. All Rights Reserved. | ||
* SPDX-License-Identifier: GPL-3.0-Only | ||
*/ | ||
package openpgpktx.sample.preference | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import androidx.preference.ListPreference | ||
import openpgpktx.sample.util.ProviderUtils | ||
import openpgpktx.sample.util.getAttr | ||
|
||
class OpenPgpAppPreference @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = getAttr(context, androidx.preference.R.attr.dialogPreferenceStyle, android.R.attr.dialogPreferenceStyle), | ||
defStyleRes: Int = 0 | ||
) : ListPreference(context, attrs, defStyleAttr, defStyleRes) { | ||
private val apps = ProviderUtils.getAppList(context) | ||
|
||
override fun getEntries(): Array<CharSequence> { | ||
return apps.map { it.simpleName }.toTypedArray() | ||
} | ||
|
||
override fun getEntryValues(): Array<CharSequence> { | ||
return apps.map { it.packageName }.toTypedArray() | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
sample/src/main/kotlin/openpgpktx/sample/util/ProviderUtils.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,71 @@ | ||
/* | ||
* Copyright © 2019 Harsh Shandilya <[email protected]>. All Rights Reserved. | ||
* SPDX-License-Identifier: GPL-3.0-Only | ||
*/ | ||
package openpgpktx.sample.util | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import openpgpktx.sample.R | ||
import openpgpktx.sample.model.OpenPgpProviderEntry | ||
|
||
object ProviderUtils { | ||
private const val OPENKEYCHAIN_PACKAGE = "org.sufficientlysecure.keychain" | ||
private const val MARKET_INTENT_URI_BASE = "market://details?id=%s" | ||
private const val PACKAGE_NAME_APG = "org.thialfihar.android.apg" | ||
private val PROVIDER_BLACKLIST = arrayOf(PACKAGE_NAME_APG) | ||
private val MARKET_INTENT = Intent(Intent.ACTION_VIEW, Uri.parse(String.format(MARKET_INTENT_URI_BASE, OPENKEYCHAIN_PACKAGE))) | ||
|
||
fun getAppList(context: Context): ArrayList<OpenPgpProviderEntry> { | ||
val apps = ArrayList<OpenPgpProviderEntry>() | ||
|
||
// Add the 'None' option | ||
apps.add(0, | ||
OpenPgpProviderEntry( | ||
"", | ||
"None", | ||
AppCompatResources.getDrawable(context, android.R.drawable.sym_def_app_icon) | ||
) | ||
) | ||
|
||
// Start searching for the real ones | ||
val intent = Intent("org.openintents.openpgp.IOpenPgpService2") | ||
var resInfo = context.packageManager.queryIntentServices(intent, 0) | ||
for (resolveInfo in resInfo) { | ||
resolveInfo.serviceInfo?.apply { | ||
if (packageName in PROVIDER_BLACKLIST) return@apply | ||
val simpleName = loadLabel(context.packageManager).toString() | ||
val icon = loadIcon(context.packageManager) | ||
apps.add( | ||
OpenPgpProviderEntry( | ||
packageName, simpleName, icon | ||
) | ||
) | ||
} ?: continue | ||
} | ||
if (apps.size == 1) { | ||
resInfo = context.packageManager | ||
.queryIntentActivities(MARKET_INTENT, 0) | ||
for (resolveInfo in resInfo) { | ||
resolveInfo.activityInfo?.apply { | ||
val marketIntent = Intent(MARKET_INTENT) | ||
marketIntent.setPackage(packageName) | ||
val icon = loadIcon(context.packageManager) | ||
val marketName = applicationInfo.loadLabel(context.packageManager).toString() | ||
val simpleName = String.format( | ||
context.getString(R.string.openpgp_install_openkeychain_via), | ||
marketName | ||
) | ||
apps.add( | ||
OpenPgpProviderEntry( | ||
OPENKEYCHAIN_PACKAGE, simpleName, icon, marketIntent | ||
) | ||
) | ||
} | ||
} | ||
} | ||
return apps | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
sample/src/main/kotlin/openpgpktx/sample/util/TypedArrayUtils.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,20 @@ | ||
/* | ||
* Copyright © 2019 Harsh Shandilya <[email protected]>. All Rights Reserved. | ||
* SPDX-License-Identifier: GPL-3.0-Only | ||
*/ | ||
package openpgpktx.sample.util | ||
|
||
import android.content.Context | ||
import android.util.TypedValue | ||
|
||
/** | ||
* @return The resource ID value in the `context` specified by `attr`. If it does | ||
* not exist, `fallbackAttr`. | ||
*/ | ||
fun getAttr(context: Context, attr: Int, fallbackAttr: Int): Int { | ||
val value = TypedValue() | ||
context.theme.resolveAttribute(attr, value, true) | ||
return if (value.resourceId != 0) { | ||
attr | ||
} else fallbackAttr | ||
} |
30 changes: 30 additions & 0 deletions
30
sample/src/main/res/drawable-v24/ic_launcher_foreground.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,30 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="85.84757" | ||
android:endY="92.4963" | ||
android:startX="42.9492" | ||
android:startY="49.59793" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
android:strokeWidth="1" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
Oops, something went wrong.