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 @@ |
|||||||
package org.transdroid.core.gui.settings; |
package org.transdroid.core.gui.settings; |
||||||
|
|
||||||
import android.content.res.Configuration; |
|
||||||
import android.os.Bundle; |
import android.os.Bundle; |
||||||
import android.preference.PreferenceActivity; |
|
||||||
import androidx.annotation.Nullable; |
import androidx.annotation.XmlRes; |
||||||
import androidx.appcompat.app.ActionBar; |
import androidx.appcompat.app.AppCompatActivity; |
||||||
import androidx.appcompat.app.AppCompatCallback; |
import androidx.appcompat.app.AppCompatCallback; |
||||||
import androidx.appcompat.app.AppCompatDelegate; |
import androidx.preference.Preference; |
||||||
import androidx.appcompat.view.ActionMode; |
import androidx.preference.PreferenceFragmentCompat; |
||||||
|
import androidx.preference.PreferenceManager; |
||||||
public class PreferenceCompatActivity extends PreferenceActivity implements AppCompatCallback { |
import androidx.preference.PreferenceScreen; |
||||||
|
|
||||||
private AppCompatDelegate acd; |
public class PreferenceCompatActivity extends AppCompatActivity implements AppCompatCallback, PreferenceFragmentCompat.OnPreferenceStartScreenCallback { |
||||||
|
|
||||||
@Override |
private PreferenceFragmentCompat fragment; |
||||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||||
super.onCreate(savedInstanceState); |
public void addPreferencesFromResource(@XmlRes int preferencesResId) { |
||||||
acd = AppCompatDelegate.create(this, this); |
fragment = new RootPreferencesFragment(preferencesResId); |
||||||
acd.onCreate(savedInstanceState); |
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commitNow(); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
public PreferenceManager getPreferenceManager() { |
||||||
protected void onPostCreate(Bundle savedInstanceState) { |
return fragment.getPreferenceManager(); |
||||||
super.onPostCreate(savedInstanceState); |
} |
||||||
acd.onPostCreate(savedInstanceState); |
|
||||||
} |
public PreferenceScreen getPreferenceScreen() { |
||||||
|
return fragment.getPreferenceScreen(); |
||||||
@Override |
} |
||||||
public void onConfigurationChanged(Configuration newConfig) { |
|
||||||
super.onConfigurationChanged(newConfig); |
public Preference findPreference(CharSequence key) { |
||||||
acd.onConfigurationChanged(newConfig); |
return fragment.findPreference(key); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
protected void onStop() { |
public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen pref) { |
||||||
super.onStop(); |
LowerPreferencesFragment lowerFragment = new LowerPreferencesFragment(pref); |
||||||
acd.onStop(); |
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, lowerFragment).addToBackStack("lower").commit(); |
||||||
} |
return true; |
||||||
|
} |
||||||
@Override |
|
||||||
protected void onDestroy() { |
public static class RootPreferencesFragment extends PreferenceFragmentCompat { |
||||||
super.onDestroy(); |
|
||||||
acd.onDestroy(); |
private int preferencesResId; |
||||||
} |
|
||||||
|
public RootPreferencesFragment(int preferencesResId) { |
||||||
public ActionBar getSupportActionBar() { |
this.preferencesResId = preferencesResId; |
||||||
return acd.getSupportActionBar(); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
@Override |
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { |
||||||
public void onSupportActionModeStarted(ActionMode actionMode) { |
addPreferencesFromResource(preferencesResId); |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
@Override |
public static class LowerPreferencesFragment extends PreferenceFragmentCompat { |
||||||
public void onSupportActionModeFinished(ActionMode actionMode) { |
|
||||||
|
private PreferenceScreen prefs; |
||||||
} |
|
||||||
|
public LowerPreferencesFragment() { |
||||||
@Nullable |
} |
||||||
@Override |
|
||||||
public ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback) { |
public LowerPreferencesFragment(PreferenceScreen prefs) { |
||||||
return acd.startSupportActionMode(callback); |
this.prefs = prefs; |
||||||
} |
} |
||||||
} |
|
||||||
|
@Override |
||||||
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { |
||||||
|
if (prefs != null) { |
||||||
|
setPreferenceScreen(prefs); |
||||||
|
prefs = null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
@ -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 @@ |
|||||||
<?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 @@ |
|||||||
<?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