Browse Source
This brings proper theming to these screens (fixes #521) and finally solves the issue of the title base now showing up in sub-screens (#491 and many, many others)pull/565/head
Eric Kok
4 years ago
40 changed files with 991 additions and 817 deletions
@ -1,66 +1,74 @@
@@ -1,66 +1,74 @@
|
||||
package org.transdroid.core.gui.settings; |
||||
|
||||
import android.content.res.Configuration; |
||||
import android.os.Bundle; |
||||
import android.preference.PreferenceActivity; |
||||
import androidx.annotation.Nullable; |
||||
import androidx.appcompat.app.ActionBar; |
||||
|
||||
import androidx.annotation.XmlRes; |
||||
import androidx.appcompat.app.AppCompatActivity; |
||||
import androidx.appcompat.app.AppCompatCallback; |
||||
import androidx.appcompat.app.AppCompatDelegate; |
||||
import androidx.appcompat.view.ActionMode; |
||||
import androidx.preference.Preference; |
||||
import androidx.preference.PreferenceFragmentCompat; |
||||
import androidx.preference.PreferenceManager; |
||||
import androidx.preference.PreferenceScreen; |
||||
|
||||
public class PreferenceCompatActivity extends PreferenceActivity implements AppCompatCallback { |
||||
public class PreferenceCompatActivity extends AppCompatActivity implements AppCompatCallback, PreferenceFragmentCompat.OnPreferenceStartScreenCallback { |
||||
|
||||
private AppCompatDelegate acd; |
||||
private PreferenceFragmentCompat fragment; |
||||
|
||||
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
acd = AppCompatDelegate.create(this, this); |
||||
acd.onCreate(savedInstanceState); |
||||
public void addPreferencesFromResource(@XmlRes int preferencesResId) { |
||||
fragment = new RootPreferencesFragment(preferencesResId); |
||||
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commitNow(); |
||||
} |
||||
|
||||
@Override |
||||
protected void onPostCreate(Bundle savedInstanceState) { |
||||
super.onPostCreate(savedInstanceState); |
||||
acd.onPostCreate(savedInstanceState); |
||||
public PreferenceManager getPreferenceManager() { |
||||
return fragment.getPreferenceManager(); |
||||
} |
||||
|
||||
@Override |
||||
public void onConfigurationChanged(Configuration newConfig) { |
||||
super.onConfigurationChanged(newConfig); |
||||
acd.onConfigurationChanged(newConfig); |
||||
public PreferenceScreen getPreferenceScreen() { |
||||
return fragment.getPreferenceScreen(); |
||||
} |
||||
|
||||
@Override |
||||
protected void onStop() { |
||||
super.onStop(); |
||||
acd.onStop(); |
||||
public Preference findPreference(CharSequence key) { |
||||
return fragment.findPreference(key); |
||||
} |
||||
|
||||
@Override |
||||
protected void onDestroy() { |
||||
super.onDestroy(); |
||||
acd.onDestroy(); |
||||
public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen pref) { |
||||
LowerPreferencesFragment lowerFragment = new LowerPreferencesFragment(pref); |
||||
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, lowerFragment).addToBackStack("lower").commit(); |
||||
return true; |
||||
} |
||||
|
||||
public ActionBar getSupportActionBar() { |
||||
return acd.getSupportActionBar(); |
||||
} |
||||
public static class RootPreferencesFragment extends PreferenceFragmentCompat { |
||||
|
||||
@Override |
||||
public void onSupportActionModeStarted(ActionMode actionMode) { |
||||
private int preferencesResId; |
||||
|
||||
public RootPreferencesFragment(int preferencesResId) { |
||||
this.preferencesResId = preferencesResId; |
||||
} |
||||
|
||||
@Override |
||||
public void onSupportActionModeFinished(ActionMode actionMode) { |
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { |
||||
addPreferencesFromResource(preferencesResId); |
||||
} |
||||
} |
||||
|
||||
public static class LowerPreferencesFragment extends PreferenceFragmentCompat { |
||||
|
||||
private PreferenceScreen prefs; |
||||
|
||||
public LowerPreferencesFragment() { |
||||
} |
||||
|
||||
public LowerPreferencesFragment(PreferenceScreen prefs) { |
||||
this.prefs = prefs; |
||||
} |
||||
|
||||
@Nullable |
||||
@Override |
||||
public ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback) { |
||||
return acd.startSupportActionMode(callback); |
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { |
||||
if (prefs != null) { |
||||
setPreferenceScreen(prefs); |
||||
prefs = null; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
package org.transdroid.core.gui.settings; |
||||
|
||||
import android.app.Activity; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.media.RingtoneManager; |
||||
import android.net.Uri; |
||||
import android.provider.Settings; |
||||
import android.util.AttributeSet; |
||||
|
||||
import androidx.preference.Preference; |
||||
|
||||
@SuppressWarnings("unused") // Constructors for XML inflation
|
||||
public class RingtonePreference extends Preference { |
||||
|
||||
private static final int REQUEST_RINGTONE = 0; |
||||
|
||||
public RingtonePreference(Context context) { |
||||
super(context); |
||||
} |
||||
|
||||
public RingtonePreference(Context context, AttributeSet attrs) { |
||||
super(context, attrs); |
||||
} |
||||
|
||||
public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr) { |
||||
super(context, attrs, defStyleAttr); |
||||
} |
||||
|
||||
public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
||||
super(context, attrs, defStyleAttr, defStyleRes); |
||||
} |
||||
|
||||
@Override |
||||
protected void onClick() { |
||||
if (!(getContext() instanceof Activity)) { |
||||
return; |
||||
} |
||||
|
||||
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); |
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); |
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); |
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); |
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI); |
||||
|
||||
String existingValue = getSharedPreferences().getString(getKey(), null); |
||||
if (existingValue != null) { |
||||
if (existingValue.isEmpty()) { |
||||
// Select "Silent"
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null); |
||||
} else { |
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue)); |
||||
} |
||||
} else { |
||||
// No ringtone has been selected, set to the default
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI); |
||||
} |
||||
|
||||
((Activity) getContext()).startActivityForResult(intent, REQUEST_RINGTONE); |
||||
} |
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
||||
if (requestCode == REQUEST_RINGTONE && resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) { |
||||
Uri ringtone = (Uri) data.getExtras().get(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); |
||||
getSharedPreferences().edit().putString(getKey(), ringtone == null? "": ringtone.toString()).apply(); |
||||
} |
||||
} |
||||
} |
@ -1,37 +0,0 @@
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- File created by the Android Action Bar Style Generator |
||||
|
||||
Copyright (C) 2012 readyState Software Ltd |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
|
||||
<resources> |
||||
|
||||
<style name="Theme.Transdroid.Auto" parent="Theme.AppCompat.DayNight.NoActionBar"> |
||||
<item name="drawer_background">@color/transdroid_background</item> |
||||
<item name="activatable_background">@drawable/activatable_background</item> |
||||
|
||||
<item name="colorPrimary">@color/green</item> |
||||
<item name="colorPrimaryDark">@color/green_dark</item> |
||||
<item name="windowActionModeOverlay">true</item> |
||||
<item name="actionModeBackground">@color/grey</item> |
||||
<item name="android:textViewStyle">@style/DefaultTextView</item> |
||||
<item name="android:windowBackground">@color/transdroid_background</item> |
||||
<item name="loading_progress">@drawable/loading_progress</item> |
||||
<item name="text_bright">@color/transdroid_text_bright</item> |
||||
<item name="text_actionbar">@color/transdroid_text_actionbar</item> |
||||
<item name="text_actionbar_secondary">@color/transdroid_text_actionbar</item> |
||||
</style> |
||||
|
||||
</resources> |
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- File created by the Android Action Bar Style Generator |
||||
|
||||
Copyright (C) 2011 The Android Open Source Project |
||||
Copyright (C) 2012 readyState Software Ltd |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
||||
--> |
||||
|
||||
<resources> |
||||
|
||||
<style name="Theme.Transdroid.Auto" parent="Theme.AppCompat.DayNight.NoActionBar"> |
||||
<item name="drawer_background">@color/transdroid_background</item> |
||||
<item name="activatable_background">@drawable/activatable_background</item> |
||||
|
||||
<item name="colorPrimary">@color/green</item> |
||||
<item name="colorPrimaryDark">@color/green_dark</item> |
||||
<item name="colorControlHighlight">@color/green_light</item> |
||||
<item name="colorAccent">@color/green_light</item> |
||||
<item name="windowActionModeOverlay">true</item> |
||||
<item name="actionModeBackground">@color/grey</item> |
||||
<item name="android:textViewStyle">@style/DefaultTextView</item> |
||||
<item name="android:windowBackground">@color/transdroid_background</item> |
||||
<item name="loading_progress">@drawable/loading_progress</item> |
||||
<item name="text_bright">@color/transdroid_text_bright</item> |
||||
<item name="text_actionbar">@color/transdroid_text_actionbar</item> |
||||
<item name="text_actionbar_secondary">@color/transdroid_text_actionbar</item> |
||||
</style> |
||||
|
||||
</resources> |
Loading…
Reference in new issue