/*
* This File(ColorPickerDialog.java) is a part of GlowNotifier Source Code
* which is maintained and copyrighted by Youngbin Han<sukso96100@gmail.com>
* and licensed under the GNU General Public License Version 3
* <http://www.gnu.org/licenses/>
*/
/*
* Copyright 2013 Piotr Adamus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hybdms.glownotifier;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
public class ColorPickerDialog extends AlertDialog {
private ColorPicker colorPickerView;
private final OnColorSelectedListener onColorSelectedListener;
public ColorPickerDialog(Context context, int initialColor, OnColorSelectedListener onColorSelectedListener) {
super(context);
this.onColorSelectedListener = onColorSelectedListener;
RelativeLayout relativeLayout = new RelativeLayout(context);
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
colorPickerView = new ColorPicker(context);
colorPickerView.setColor(initialColor);
relativeLayout.addView(colorPickerView, layoutParams);
setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), onClickListener);
setButton(BUTTON_NEGATIVE, context.getString(android.R.string.cancel), onClickListener);
setView(relativeLayout);
}
private OnClickListener onClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case BUTTON_POSITIVE:
int selectedColor = colorPickerView.getColor();
onColorSelectedListener.onColorSelected(selectedColor);
break;
case BUTTON_NEGATIVE:
dialog.dismiss();
break;
}
}
};
public interface OnColorSelectedListener {
public void onColorSelected(int color);
}
}