<commit_before>package com.rarepebble.colorpicker;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

public class ColorPreference extends DialogPreference {
	private final String selectNoneButtonText;
	private final Integer defaultColor;
	private final String noneSelectedSummaryText;
	private View thumbnail;

	public ColorPreference(Context context) {
		this(context, null);
	}
	public ColorPreference(Context context, AttributeSet attrs) {
		super(context, attrs);

		if (attrs != null) {
			TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ColorPreference, 0, 0);
			selectNoneButtonText = a.getString(R.styleable.ColorPreference_selectNoneButtonText);
			noneSelectedSummaryText = a.getString(R.styleable.ColorPreference_noneSelectedSummaryText);
			defaultColor = a.hasValue(R.styleable.ColorPreference_defaultColor)
					? a.getColor(R.styleable.ColorPreference_defaultColor, Color.GRAY)
					: null;
		}
		else {
			selectNoneButtonText = null;
			defaultColor = null;
			noneSelectedSummaryText = null;
		}
	}

	@Override
	protected void onBindView(View view) {
		thumbnail = addThumbnail(view);
		showColor(getPersistedIntDefaultOrNull());
		// Only call after showColor sets any summary text:
		super.onBindView(view);
	}

	private View addThumbnail(View view) {
		LinearLayout widgetFrameView = ((LinearLayout)view.findViewById(android.R.id.widget_frame));
		widgetFrameView.setVisibility(View.VISIBLE);
		widgetFrameView.removeAllViews();
		LayoutInflater.from(getContext()).inflate(R.layout.color_preference_thumbnail, widgetFrameView);
		return widgetFrameView.findViewById(R.id.thumbnail);
	}

	private Integer getPersistedIntDefaultOrNull() {
		return getSharedPreferences().contains(getKey())
				? new Integer(getPersistedInt(Color.GRAY))
				: defaultColor;
	}

	void showColor(Integer color) {
		if (thumbnail != null) {
			thumbnail.setVisibility(color == null ? View.GONE : View.VISIBLE);
			thumbnail.findViewById(R.id.colorPreview).setBackgroundColor(color == null ? 0x00000000 : color);
		}
		if (noneSelectedSummaryText != null) {
			setSummary(color == null ? noneSelectedSummaryText : null);
		}
	}

	@Override
	protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
		super.onPrepareDialogBuilder(builder);
		final ColorPickerView picker = new ColorPickerView(getContext());
		picker.setColor(getPersistedInt(defaultColor == null ? Color.GRAY : defaultColor));
		builder
				.setTitle(null)
				.setView(picker)
				.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						final int color = picker.getColor();
						persistInt(color);
						showColor(color);
					}
				});
		if (selectNoneButtonText != null) {
			builder.setNeutralButton(selectNoneButtonText, new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					removeSetting();
					showColor(null);
				}
			});
		}
	}

	private void removeSetting() {
		getSharedPreferences()
				.edit()
				.remove(getKey())
				.commit();
	}
}
<commit_msg>Background settings working. Using resources for preference keys.<commit_after>package com.rarepebble.colorpicker;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

public class ColorPreference extends DialogPreference {
	private final String selectNoneButtonText;
	private final Integer defaultColor;
	private final String noneSelectedSummaryText;
	private View thumbnail;

	public ColorPreference(Context context) {
		this(context, null);
	}
	public ColorPreference(Context context, AttributeSet attrs) {
		super(context, attrs);

		if (attrs != null) {
			TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ColorPreference, 0, 0);
			selectNoneButtonText = a.getString(R.styleable.ColorPreference_selectNoneButtonText);
			noneSelectedSummaryText = a.getString(R.styleable.ColorPreference_noneSelectedSummaryText);
			defaultColor = a.hasValue(R.styleable.ColorPreference_defaultColor)
					? a.getColor(R.styleable.ColorPreference_defaultColor, Color.GRAY)
					: null;
		}
		else {
			selectNoneButtonText = null;
			defaultColor = null;
			noneSelectedSummaryText = null;
		}
	}

	@Override
	protected void onBindView(View view) {
		thumbnail = addThumbnail(view);
		showColor(getPersistedIntDefaultOrNull());
		// Only call after showColor sets any summary text:
		super.onBindView(view);
	}

	private View addThumbnail(View view) {
		LinearLayout widgetFrameView = ((LinearLayout)view.findViewById(android.R.id.widget_frame));
		widgetFrameView.setVisibility(View.VISIBLE);
		widgetFrameView.removeAllViews();
		LayoutInflater.from(getContext()).inflate(R.layout.color_preference_thumbnail, widgetFrameView);
		return widgetFrameView.findViewById(R.id.thumbnail);
	}

	private Integer getPersistedIntDefaultOrNull() {
		return getSharedPreferences().contains(getKey())
				? new Integer(getPersistedInt(Color.GRAY))
				: defaultColor;
	}

	void showColor(Integer color) {
		if (thumbnail != null) {
			thumbnail.setVisibility(color == null ? View.GONE : View.VISIBLE);
			thumbnail.findViewById(R.id.colorPreview).setBackgroundColor(color == null ? 0 : color);
		}
		if (noneSelectedSummaryText != null) {
			setSummary(color == null ? noneSelectedSummaryText : null);
		}
	}

	@Override
	protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
		super.onPrepareDialogBuilder(builder);
		final ColorPickerView picker = new ColorPickerView(getContext());
		picker.setColor(getPersistedInt(defaultColor == null ? Color.GRAY : defaultColor));
		builder
				.setTitle(null)
				.setView(picker)
				.setPositiveButton(getPositiveButtonText(), new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						final int color = picker.getColor();
						persistInt(color);
						showColor(color);
					}
				});
		if (selectNoneButtonText != null) {
			builder.setNeutralButton(selectNoneButtonText, new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					removeSetting();
					showColor(null);
				}
			});
		}
	}

	private void removeSetting() {
		getSharedPreferences()
				.edit()
				.remove(getKey())
				.commit();
	}
}

{'fraction_non_alphanumeric': 0.09948230026584581, 'fraction_numerical': 0.0019588638589618022, 'mean_word_length': 4.275276752767527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5014033', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2026, 'n_words': 395}