Skip to content

Commit

Permalink
User defined colours for pie controls (2/2)
Browse files Browse the repository at this point in the history
This is the settings part of the commit.
For more information look at the framework/base commit.

Change-Id: Iaf486114db08cd6b002a3e5f25d6e4a9d915a7ae
  • Loading branch information
jdoll authored and Der-Schubi committed May 25, 2013
1 parent 97396c6 commit 225e789
Show file tree
Hide file tree
Showing 7 changed files with 552 additions and 5 deletions.
41 changes: 41 additions & 0 deletions res/layout/dialog_pie_colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<com.android.settings.notificationlight.ColorPickerView
android:id="@+id/color_picker_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp" />

<LinearLayout
android:id="@+id/color_panel_view"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignStart="@id/color_picker_view"
android:layout_alignEnd="@id/color_picker_view"
android:layout_below="@id/color_picker_view"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:orientation="horizontal" >

<EditText
android:id="@+id/hex_color_input"
android:layout_width="0px"
android:maxLength="6"
android:digits="0123456789ABCDEFabcdef"
android:inputType="textNoSuggestions"
android:layout_height="match_parent"
android:layout_weight="0.5" />

<com.android.settings.notificationlight.ColorPanelView
android:id="@+id/color_panel"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="0.5" />
</LinearLayout>

</RelativeLayout>
10 changes: 10 additions & 0 deletions res/layout/preference_widget_pie_color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout used by PieColorPreference. This is inflated
inside android.R.layout.preference. -->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pie_color"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center"
android:focusable="false"
android:clickable="false" />
8 changes: 8 additions & 0 deletions res/values/cm_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,14 @@ two in order to insert additional control points. \'Remove\' deletes the selecte
<string name="pie_control_trigger_right">Right screen border</string>
<string name="pie_control_trigger_top">Top screen border</string>
<string name="pie_control_trigger_top_summary">Only navigation will be displayed at top</string>
<string name="pie_control_color_settings">Pie Color Settings</string>
<string name="pie_control_color_normal">Normal background</string>
<string name="pie_control_color_selected">Selected background</string>
<string name="pie_control_color_longpressed">Long pressed background</string>
<string name="pie_control_color_icon">Icon color</string>
<string name="pie_control_outline">Show outline</string>
<string name="pie_control_color_title">Edit color setting</string>
<string name="pie_control_color_reset">Reset</string>

<!-- Stylus Gestures -->
<string name="gestures_settings_title">Stylus gestures</string>
Expand Down
37 changes: 36 additions & 1 deletion res/xml/pie_control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,40 @@
android:title="@string/pie_control_trigger_top"
android:summary="@string/pie_control_trigger_top_summary"
android:defaultValue="false" />
</PreferenceCategory>
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pie_control_color_settings">

<com.android.settings.cyanogenmod.PieColorPreference
android:key="pie_control_color_normal"
android:title="@string/pie_control_color_normal"
android:defaultValue="FFFFBF00"
android:persistent="false" />

<com.android.settings.cyanogenmod.PieColorPreference
android:key="pie_control_color_selected"
android:title="@string/pie_control_color_selected"
android:defaultValue="FFBFFF00"
android:persistent="false" />

<com.android.settings.cyanogenmod.PieColorPreference
android:key="pie_control_color_longpressed"
android:title="@string/pie_control_color_longpressed"
android:defaultValue="FF8A0808"
android:persistent="false" />

<com.android.settings.cyanogenmod.PieColorPreference
android:key="pie_control_color_icon"
android:title="@string/pie_control_color_icon"
android:defaultValue="FFFFFFFF"
android:persistent="false" />

<CheckBoxPreference
android:key="pie_control_outline"
android:title="@string/pie_control_outline"
android:defaultValue="false"
android:persistent="false" />
</PreferenceCategory>

</PreferenceScreen>
117 changes: 117 additions & 0 deletions src/com/android/settings/cyanogenmod/PieColorDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.android.settings.cyanogenmod;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;

import com.android.settings.R;
import com.android.settings.notificationlight.ColorPanelView;
import com.android.settings.notificationlight.ColorPickerView;
import com.android.settings.notificationlight.ColorPickerView.OnColorChangedListener;

import java.util.Locale;

public class PieColorDialog extends AlertDialog implements
ColorPickerView.OnColorChangedListener, TextWatcher, View.OnFocusChangeListener {

private ColorPickerView mColorPicker;
private EditText mHexColorInput;

private ColorPanelView mColorPanel;

protected PieColorDialog(Context context, int initialColor) {
super(context);

init(initialColor);
}

private void init(int color) {
// To fight color banding.
getWindow().setFormat(PixelFormat.RGBA_8888);
setup(color);
}

private void setup(int color) {
final LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog_pie_colors, null);

mColorPicker = (ColorPickerView) layout.findViewById(R.id.color_picker_view);
mColorPanel = (ColorPanelView) layout.findViewById(R.id.color_panel);
mHexColorInput = (EditText) layout.findViewById(R.id.hex_color_input);

mColorPanel.setColor(color);
mColorPicker.setOnColorChangedListener(this);
mColorPicker.setColor(color, true);
mHexColorInput.setOnFocusChangeListener(this);

setView(layout);
setTitle(R.string.pie_control_color_title);
}

@Override
public void onColorChanged(int color) {
final boolean hasAlpha = mColorPicker.isAlphaSliderVisible();
final String format = hasAlpha ? "%08x" : "%06x";
final int mask = hasAlpha ? 0xFFFFFFFF : 0x00FFFFFF;

mColorPanel.setColor(color);
mHexColorInput.setText(String.format(Locale.US, format, color & mask));
}

public void setAlphaSliderVisible(boolean visible) {
mColorPicker.setAlphaSliderVisible(visible);
}

public int getColor() {
return mColorPicker.getColor();
}

@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
mHexColorInput.removeTextChangedListener(this);
InputMethodManager inputMethodManager = (InputMethodManager) getContext()
.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
} else {
mHexColorInput.addTextChangedListener(this);
}
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}

@Override
public void afterTextChanged(Editable s) {
String hexColor = mHexColorInput.getText().toString();
if (!hexColor.isEmpty()) {
try {
int color = Color.parseColor(hexColor.indexOf('#') < 0 ? '#' + hexColor : hexColor);
if (!mColorPicker.isAlphaSliderVisible()) {
color |= 0xFF000000; // set opaque
}
mColorPicker.setColor(color);
mColorPanel.setColor(color);
} catch (IllegalArgumentException ex) {
// Number format is incorrect, ignore
}
}
}

}
Loading

0 comments on commit 225e789

Please sign in to comment.