1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

first implementation of color picker dialog

This commit is contained in:
Nikolay Pultsin 2010-11-26 03:41:05 +00:00
parent bec7794464
commit 225985bbcf
4 changed files with 143 additions and 13 deletions

View file

@ -320,10 +320,10 @@
<node name="colors" value="Colors">
<node name="summary" value="Color settings"/>
<node name="background" value="Background"/>
<node name="selectionBackground" value="Selection Background"/>
<node name="text" value="Regular Text"/>
<node name="hyperlink" value="Hyperlink Text"/>
<node name="highlighting" value="Search Results Background"/>
<node name="selectionBackground" value="Selection background"/>
<node name="text" value="Regular text"/>
<node name="hyperlink" value="Hyperlink text"/>
<node name="highlighting" value="Search results background"/>
</node>
<node name="margins" value="Margins">
<node name="summary" value="Text margins"/>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<View
android:layout_width="48dip"
android:layout_height="fill_parent"
android:layout_marginLeft="8dip"
android:layout_marginTop="8dip"
android:layout_marginBottom="8dip"
android:id="@+id/color_box"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dip"
>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/color_red"
android:max="255"
android:padding="4dip"
/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/color_green"
android:max="255"
android:padding="4dip"
/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/color_blue"
android:max="255"
android:padding="4dip"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -230,17 +230,18 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final Screen colorsScreen = optionsCategory.createPreferenceScreen("colors");
final Category colorsCategory = colorsScreen.createCategory(null);
final ColorProfile profile = fbReader.getColorProfile();
colorsCategory.addPreference(new ZLColorPreference(
this, colorsCategory.Resource, "background"
this, colorsCategory.Resource, "background", profile.BackgroundOption
));
colorsCategory.addPreference(new ZLColorPreference(
this, colorsCategory.Resource, "highlighting"
this, colorsCategory.Resource, "highlighting", profile.HighlightingOption
));
colorsCategory.addPreference(new ZLColorPreference(
this, colorsCategory.Resource, "text"
this, colorsCategory.Resource, "text", profile.RegularTextOption
));
colorsCategory.addPreference(new ZLColorPreference(
this, colorsCategory.Resource, "hyperlink"
this, colorsCategory.Resource, "hyperlink", profile.HyperlinkTextOption
));
final Screen marginsScreen = optionsCategory.createPreferenceScreen("margins");

View file

@ -20,27 +20,107 @@
package org.geometerplus.android.fbreader.preferences;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.*;
import android.preference.DialogPreference;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import org.geometerplus.zlibrary.core.util.ZLColor;
import org.geometerplus.zlibrary.core.options.ZLColorOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.ui.android.util.ZLAndroidColorUtil;
class ZLColorPreference extends DialogPreference implements ZLPreference {
ZLColorPreference(Context context, ZLResource resource, String resourceKey) {
private final ZLColorOption myOption;
private SeekBar myRedSlider;
private SeekBar myGreenSlider;
private SeekBar myBlueSlider;
private final GradientDrawable myPreviewDrawable = new GradientDrawable();
ZLColorPreference(Context context, ZLResource resource, String resourceKey, ZLColorOption option) {
super(context, null);
setWidgetLayoutResource(R.layout.color_preference_widget);
setTitle(resource.getResource(resourceKey).getValue());
myOption = option;
//setWidgetLayoutResource(R.layout.color_preference_widget);
final String title = resource.getResource(resourceKey).getValue();
setTitle(title);
setDialogTitle(title);
setDialogLayoutResource(R.layout.color_dialog);
}
@Override
protected void onBindDialogView(View view) {
final ZLColor color = myOption.getValue();
myRedSlider = (SeekBar)view.findViewById(R.id.color_red);
myRedSlider.setProgress(color.Red);
myGreenSlider = (SeekBar)view.findViewById(R.id.color_green);
myGreenSlider.setProgress(color.Green);
myBlueSlider = (SeekBar)view.findViewById(R.id.color_blue);
myBlueSlider.setProgress(color.Blue);
final View colorBox = view.findViewById(R.id.color_box);
colorBox.setBackgroundDrawable(myPreviewDrawable);
myPreviewDrawable.setCornerRadius(7);
myPreviewDrawable.setColor(ZLAndroidColorUtil.rgb(color));
final SeekBar.OnSeekBarChangeListener listener = new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
myPreviewDrawable.setColor(Color.rgb(
myRedSlider.getProgress(),
myGreenSlider.getProgress(),
myBlueSlider.getProgress()
));
myPreviewDrawable.invalidateSelf();
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
myPreviewDrawable.setColor(Color.rgb(
myRedSlider.getProgress(),
myGreenSlider.getProgress(),
myBlueSlider.getProgress()
));
myPreviewDrawable.invalidateSelf();
}
};
myRedSlider.setOnSeekBarChangeListener(listener);
myGreenSlider.setOnSeekBarChangeListener(listener);
myBlueSlider.setOnSeekBarChangeListener(listener);
super.onBindDialogView(view);
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
myOption.setValue(new ZLColor(
myRedSlider.getProgress(),
myGreenSlider.getProgress(),
myBlueSlider.getProgress()
));
}
}
/*
@Override
protected void onBindView(View view) {
final ImageView colorView = (ImageView)view.findViewById(R.id.color_preference_color);
colorView.setImageResource(R.drawable.fbreader);
//colorView.setImageResource(R.drawable.fbreader);
final Drawable drawable = new ColorDrawable(0x00FF00);
colorView.setImageDrawable(drawable);
super.onBindView(view);
}
*/
public void onAccept() {
}