From 318be959b7ee2224d9ee7a7b8b308f2ef9eb2307 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 30 May 2018 20:55:06 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .idea/caches/build_file_checksums.ser | Bin 536 -> 536 bytes app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 25 +- .../activity/AppCompatPreferenceActivity.kt | 90 +++++++ .../activity/SettingsFeatureActivity.kt | 232 ++++++++++++++++++ .../main/res/drawable/ic_info_black_24dp.xml | 9 + .../drawable/ic_notifications_black_24dp.xml | 9 + .../main/res/drawable/ic_sync_black_24dp.xml | 9 + app/src/main/res/values/strings.xml | 76 ++++++ app/src/main/res/xml/pref_data_sync.xml | 21 ++ app/src/main/res/xml/pref_general.xml | 33 +++ app/src/main/res/xml/pref_headers.xml | 20 ++ app/src/main/res/xml/pref_notification.xml | 27 ++ 13 files changed, 534 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/com/tangem/presentation/activity/AppCompatPreferenceActivity.kt create mode 100644 app/src/main/java/com/tangem/presentation/activity/SettingsFeatureActivity.kt create mode 100644 app/src/main/res/drawable/ic_info_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_notifications_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_sync_black_24dp.xml create mode 100644 app/src/main/res/xml/pref_data_sync.xml create mode 100644 app/src/main/res/xml/pref_general.xml create mode 100644 app/src/main/res/xml/pref_headers.xml create mode 100644 app/src/main/res/xml/pref_notification.xml diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index a2693a62ff8c683e6bcce4fd190749df1bd27ecb..b5ad54e2299f50bc456983a37f0181424dd425ec 100644 GIT binary patch delta 33 pcmbQiGJ|Ep43khHM#EKeDgfR!4bT7p delta 33 rcmV++0N($Y1egSnm;|uHMj5f3YXK2>?d9SZ; - + - + + @@ -63,87 +64,75 @@ android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter"/> - - - - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/app/src/main/java/com/tangem/presentation/activity/AppCompatPreferenceActivity.kt b/app/src/main/java/com/tangem/presentation/activity/AppCompatPreferenceActivity.kt new file mode 100644 index 0000000000..a6bcab3e32 --- /dev/null +++ b/app/src/main/java/com/tangem/presentation/activity/AppCompatPreferenceActivity.kt @@ -0,0 +1,90 @@ +package com.tangem.presentation.activity + +import android.content.res.Configuration +import android.os.Bundle +import android.preference.PreferenceActivity +import android.support.annotation.LayoutRes +import android.support.v7.app.ActionBar +import android.support.v7.app.AppCompatDelegate +import android.support.v7.widget.Toolbar +import android.view.MenuInflater +import android.view.View +import android.view.ViewGroup + +/** + * A [android.preference.PreferenceActivity] which implements and proxies the necessary calls + * to be used with AppCompat. + */ +abstract class AppCompatPreferenceActivity : PreferenceActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + delegate.installViewFactory() + delegate.onCreate(savedInstanceState) + super.onCreate(savedInstanceState) + } + + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + delegate.onPostCreate(savedInstanceState) + } + + val supportActionBar: ActionBar? + get() = delegate.supportActionBar + + fun setSupportActionBar(toolbar: Toolbar?) { + delegate.setSupportActionBar(toolbar) + } + + override fun getMenuInflater(): MenuInflater { + return delegate.menuInflater + } + + override fun setContentView(@LayoutRes layoutResID: Int) { + delegate.setContentView(layoutResID) + } + + override fun setContentView(view: View) { + delegate.setContentView(view) + } + + override fun setContentView(view: View, params: ViewGroup.LayoutParams) { + delegate.setContentView(view, params) + } + + override fun addContentView(view: View, params: ViewGroup.LayoutParams) { + delegate.addContentView(view, params) + } + + override fun onPostResume() { + super.onPostResume() + delegate.onPostResume() + } + + override fun onTitleChanged(title: CharSequence, color: Int) { + super.onTitleChanged(title, color) + delegate.setTitle(title) + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + delegate.onConfigurationChanged(newConfig) + } + + override fun onStop() { + super.onStop() + delegate.onStop() + } + + override fun onDestroy() { + super.onDestroy() + delegate.onDestroy() + } + + override fun invalidateOptionsMenu() { + delegate.invalidateOptionsMenu() + } + + private val delegate: AppCompatDelegate by lazy { + AppCompatDelegate.create(this, null) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/presentation/activity/SettingsFeatureActivity.kt b/app/src/main/java/com/tangem/presentation/activity/SettingsFeatureActivity.kt new file mode 100644 index 0000000000..88bd55542b --- /dev/null +++ b/app/src/main/java/com/tangem/presentation/activity/SettingsFeatureActivity.kt @@ -0,0 +1,232 @@ +package com.tangem.presentation.activity + +import android.annotation.TargetApi +import android.content.Context +import android.content.Intent +import android.content.res.Configuration +import android.media.RingtoneManager +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.preference.* +import android.text.TextUtils +import android.view.MenuItem +import com.tangem.wallet.R + +/** + * A [PreferenceActivity] that presents a set of application settings. On + * handset devices, settings are presented as a single list. On tablets, + * settings are split by category, with category headers shown to the left of + * the list of settings. + * + * See [Android Design: Settings](http://developer.android.com/design/patterns/settings.html) + * for design guidelines and the [Settings API Guide](http://developer.android.com/guide/topics/ui/settings.html) + * for more information on developing a Settings UI. + */ +class SettingsFeatureActivity : AppCompatPreferenceActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setupActionBar() + } + + /** + * Set up the [android.app.ActionBar], if the API is available. + */ + private fun setupActionBar() { + supportActionBar?.setDisplayHomeAsUpEnabled(true) + } + + /** + * {@inheritDoc} + */ + override fun onIsMultiPane(): Boolean { + return isXLargeTablet(this) + } + + /** + * {@inheritDoc} + */ + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + override fun onBuildHeaders(target: List) { + loadHeadersFromResource(R.xml.pref_headers, target) + } + + /** + * This method stops fragment injection in malicious applications. + * Make sure to deny any unknown fragments here. + */ + override fun isValidFragment(fragmentName: String): Boolean { + return PreferenceFragment::class.java.name == fragmentName + || GeneralPreferenceFragment::class.java.name == fragmentName + || DataSyncPreferenceFragment::class.java.name == fragmentName + || NotificationPreferenceFragment::class.java.name == fragmentName + } + + /** + * This fragment shows general preferences only. It is used when the + * activity is showing a two-pane settings UI. + */ + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + class GeneralPreferenceFragment : PreferenceFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + addPreferencesFromResource(R.xml.pref_general) + setHasOptionsMenu(true) + + // Bind the summaries of EditText/List/Dialog/Ringtone preferences + // to their values. When their values change, their summaries are + // updated to reflect the new value, per the Android Design + // guidelines. + bindPreferenceSummaryToValue(findPreference("example_text")) + bindPreferenceSummaryToValue(findPreference("example_list")) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + if (id == android.R.id.home) { + startActivity(Intent(activity, SettingsFeatureActivity::class.java)) + return true + } + return super.onOptionsItemSelected(item) + } + } + + /** + * This fragment shows notification preferences only. It is used when the + * activity is showing a two-pane settings UI. + */ + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + class NotificationPreferenceFragment : PreferenceFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + addPreferencesFromResource(R.xml.pref_notification) + setHasOptionsMenu(true) + + // Bind the summaries of EditText/List/Dialog/Ringtone preferences + // to their values. When their values change, their summaries are + // updated to reflect the new value, per the Android Design + // guidelines. + bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone")) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + if (id == android.R.id.home) { + startActivity(Intent(activity, SettingsFeatureActivity::class.java)) + return true + } + return super.onOptionsItemSelected(item) + } + } + + /** + * This fragment shows data and sync preferences only. It is used when the + * activity is showing a two-pane settings UI. + */ + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + class DataSyncPreferenceFragment : PreferenceFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + addPreferencesFromResource(R.xml.pref_data_sync) + setHasOptionsMenu(true) + + // Bind the summaries of EditText/List/Dialog/Ringtone preferences + // to their values. When their values change, their summaries are + // updated to reflect the new value, per the Android Design + // guidelines. + bindPreferenceSummaryToValue(findPreference("sync_frequency")) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + if (id == android.R.id.home) { + startActivity(Intent(activity, SettingsFeatureActivity::class.java)) + return true + } + return super.onOptionsItemSelected(item) + } + } + + companion object { + + /** + * A preference value change listener that updates the preference's summary + * to reflect its new value. + */ + private val sBindPreferenceSummaryToValueListener = Preference.OnPreferenceChangeListener { preference, value -> + val stringValue = value.toString() + + if (preference is ListPreference) { + // For list preferences, look up the correct display value in + // the preference's 'entries' list. + val listPreference = preference + val index = listPreference.findIndexOfValue(stringValue) + + // Set the summary to reflect the new value. + preference.setSummary( + if (index >= 0) + listPreference.entries[index] + else + null) + + } else if (preference is RingtonePreference) { + // For ringtone preferences, look up the correct display value + // using RingtoneManager. + if (TextUtils.isEmpty(stringValue)) { + // Empty values correspond to 'silent' (no ringtone). + preference.setSummary(R.string.pref_ringtone_silent) + + } else { + val ringtone = RingtoneManager.getRingtone( + preference.getContext(), Uri.parse(stringValue)) + + if (ringtone == null) { + // Clear the summary if there was a lookup error. + preference.setSummary(null) + } else { + // Set the summary to reflect the new ringtone display + // name. + val name = ringtone.getTitle(preference.getContext()) + preference.setSummary(name) + } + } + + } else { + // For all other preferences, set the summary to the value's + // simple string representation. + preference.summary = stringValue + } + true + } + + /** + * Helper method to determine if the device has an extra-large screen. For + * example, 10" tablets are extra-large. + */ + private fun isXLargeTablet(context: Context): Boolean { + return context.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK >= Configuration.SCREENLAYOUT_SIZE_XLARGE + } + + /** + * Binds a preference's summary to its value. More specifically, when the + * preference's value is changed, its summary (line of text below the + * preference title) is updated to reflect the value. The summary is also + * immediately updated upon calling this method. The exact display format is + * dependent on the type of preference. + + * @see .sBindPreferenceSummaryToValueListener + */ + private fun bindPreferenceSummaryToValue(preference: Preference) { + // Set the listener to watch for value changes. + preference.onPreferenceChangeListener = sBindPreferenceSummaryToValueListener + + // Trigger the listener immediately with the preference's + // current value. + sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, + PreferenceManager + .getDefaultSharedPreferences(preference.context) + .getString(preference.key, "")) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info_black_24dp.xml b/app/src/main/res/drawable/ic_info_black_24dp.xml new file mode 100644 index 0000000000..d9c37038d2 --- /dev/null +++ b/app/src/main/res/drawable/ic_info_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_notifications_black_24dp.xml b/app/src/main/res/drawable/ic_notifications_black_24dp.xml new file mode 100644 index 0000000000..5ee298d0d2 --- /dev/null +++ b/app/src/main/res/drawable/ic_notifications_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_sync_black_24dp.xml b/app/src/main/res/drawable/ic_sync_black_24dp.xml new file mode 100644 index 0000000000..a3c73b9d92 --- /dev/null +++ b/app/src/main/res/drawable/ic_sync_black_24dp.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 599735ec71..b9ec10c47a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,5 +28,81 @@ @string/bcEtherium LoadedWalletActivity + Settings + + + + + + + + General + + Enable social recommendations + Recommendations for people to contact + based on your message history + + + Display name + John Smith + + Add friends to messages + + Always + When possible + Never + + + 1 + 0 + -1 + + + + Data & sync + + Sync frequency + + 15 minutes + 30 minutes + 1 hour + 3 hours + 6 hours + Never + + + 15 + 30 + 60 + 180 + 360 + -1 + + + + Entry 1 + Entry 2 + Entry 3 + + + + 1 + 2 + 3 + + + + + System sync settings + + + Notifications + + New message notifications + + Ringtone + Silent + + Vibrate diff --git a/app/src/main/res/xml/pref_data_sync.xml b/app/src/main/res/xml/pref_data_sync.xml new file mode 100644 index 0000000000..18cad67b51 --- /dev/null +++ b/app/src/main/res/xml/pref_data_sync.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml new file mode 100644 index 0000000000..51a5878260 --- /dev/null +++ b/app/src/main/res/xml/pref_general.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml new file mode 100644 index 0000000000..8e34f3d12c --- /dev/null +++ b/app/src/main/res/xml/pref_headers.xml @@ -0,0 +1,20 @@ + + + + +
+ +
+ +
+ + diff --git a/app/src/main/res/xml/pref_notification.xml b/app/src/main/res/xml/pref_notification.xml new file mode 100644 index 0000000000..6f7789bce5 --- /dev/null +++ b/app/src/main/res/xml/pref_notification.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + +