michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.prompts; michael@0: michael@0: import org.json.JSONObject; michael@0: import org.mozilla.gecko.R; michael@0: import org.mozilla.gecko.widget.BasicColorPicker; michael@0: michael@0: import android.content.Context; michael@0: import android.graphics.Color; michael@0: import android.view.LayoutInflater; michael@0: import android.view.View; michael@0: michael@0: public class ColorPickerInput extends PromptInput { michael@0: public static final String INPUT_TYPE = "color"; michael@0: public static final String LOGTAG = "GeckoColorPickerInput"; michael@0: michael@0: private boolean mShowAdvancedButton = true; michael@0: private int mInitialColor; michael@0: michael@0: public ColorPickerInput(JSONObject obj) { michael@0: super(obj); michael@0: String init = obj.optString("value"); michael@0: mInitialColor = Color.rgb(Integer.parseInt(init.substring(1,3), 16), michael@0: Integer.parseInt(init.substring(3,5), 16), michael@0: Integer.parseInt(init.substring(5,7), 16)); michael@0: } michael@0: michael@0: @Override michael@0: public View getView(Context context) throws UnsupportedOperationException { michael@0: LayoutInflater inflater = LayoutInflater.from(context); michael@0: mView = inflater.inflate(R.layout.basic_color_picker_dialog, null); michael@0: michael@0: BasicColorPicker cp = (BasicColorPicker) mView.findViewById(R.id.colorpicker); michael@0: cp.setColor(mInitialColor); michael@0: michael@0: return mView; michael@0: } michael@0: michael@0: @Override michael@0: public Object getValue() { michael@0: BasicColorPicker cp = (BasicColorPicker) mView.findViewById(R.id.colorpicker); michael@0: int color = cp.getColor(); michael@0: return "#" + Integer.toHexString(color).substring(2); michael@0: } michael@0: michael@0: @Override michael@0: public boolean getScrollable() { michael@0: return true; michael@0: } michael@0: michael@0: @Override michael@0: public boolean canApplyInputStyle() { michael@0: return false; michael@0: } michael@0: }