MasterSwitchPreference

This commit is contained in:
ByteHamster 2018-04-22 18:41:43 +02:00
parent a64c996e9c
commit bb42ddbd56
5 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,45 @@
package de.danoeh.antennapod.preferences;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
import de.danoeh.antennapod.R;
public class MasterSwitchPreference extends SwitchCompatPreference {
public MasterSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public MasterSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public MasterSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MasterSwitchPreference(Context context) {
super(context);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
TypedValue typedValue = new TypedValue();
getContext().getTheme().resolveAttribute(R.attr.master_switch_background, typedValue, true);
view.setBackgroundColor(typedValue.data);
TextView title = (TextView) view.findViewById(android.R.id.title);
if (title != null) {
title.setTypeface(title.getTypeface(), Typeface.BOLD);
}
}
}

View File

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<de.danoeh.antennapod.preferences.SwitchCompatPreference
<de.danoeh.antennapod.preferences.MasterSwitchPreference
android:key="prefEnableAutoDl"
android:title="@string/pref_automatic_download_title"
android:defaultValue="false"/>

View File

@ -54,6 +54,7 @@
<attr name="ic_sd_storage" format="reference"/>
<attr name="ic_create_new_folder" format="reference"/>
<attr name="ic_cast_disconnect" format="reference"/>
<attr name="master_switch_background" format="color"/>
<!-- Used in itemdescription -->
<attr name="non_transparent_background" format="reference"/>

View File

@ -33,4 +33,7 @@
<color name="antennapod_blue">#147BAF</color>
<color name="master_switch_background_light">#DDDDDD</color>
<color name="master_switch_background_dark">#191919</color>
</resources>

View File

@ -65,6 +65,7 @@
<item type="attr" name="ic_sd_storage">@drawable/ic_sd_storage_grey600_36dp</item>
<item type="attr" name="ic_create_new_folder">@drawable/ic_create_new_folder_grey600_24dp</item>
<item type="attr" name="ic_cast_disconnect">@drawable/ic_cast_disconnect_grey600_36dp</item>
<item type="attr" name="master_switch_background">@color/master_switch_background_light</item>
</style>
<style name="Theme.AntennaPod.Dark" parent="Theme.Base.AntennaPod.Dark">
@ -130,6 +131,7 @@
<item type="attr" name="ic_sd_storage">@drawable/ic_sd_storage_white_36dp</item>
<item type="attr" name="ic_create_new_folder">@drawable/ic_create_new_folder_white_24dp</item>
<item type="attr" name="ic_cast_disconnect">@drawable/ic_cast_disconnect_white_36dp</item>
<item type="attr" name="master_switch_background">@color/master_switch_background_dark</item>
</style>
<style name="Theme.AntennaPod.Light.NoTitle" parent="Theme.Base.AntennaPod.Light.NoTitle">
@ -197,6 +199,7 @@
<item type="attr" name="ic_sd_storage">@drawable/ic_sd_storage_grey600_36dp</item>
<item type="attr" name="ic_create_new_folder">@drawable/ic_create_new_folder_grey600_24dp</item>
<item type="attr" name="ic_cast_disconnect">@drawable/ic_cast_disconnect_grey600_36dp</item>
<item type="attr" name="master_switch_background">@color/master_switch_background_light</item>
</style>
<style name="Theme.AntennaPod.Dark.NoTitle" parent="Theme.Base.AntennaPod.Dark.NoTitle">
@ -264,6 +267,7 @@
<item type="attr" name="ic_sd_storage">@drawable/ic_sd_storage_white_36dp</item>
<item type="attr" name="ic_create_new_folder">@drawable/ic_create_new_folder_white_24dp</item>
<item type="attr" name="ic_cast_disconnect">@drawable/ic_cast_disconnect_white_36dp</item>
<item type="attr" name="master_switch_background">@color/master_switch_background_dark</item>
</style>
<style name="Theme.AntennaPod.Dark.Splash" parent="Theme.AppCompat.NoActionBar">