forked from Quarx2k/android_packages_apps_Settings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User defined colours for pie controls (2/2)
This is the settings part of the commit. For more information look at the framework/base commit. Change-Id: Iaf486114db08cd6b002a3e5f25d6e4a9d915a7ae
- Loading branch information
1 parent
97396c6
commit 225e789
Showing
7 changed files
with
552 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/com/android/settings/cyanogenmod/PieColorDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.