|
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 package org.mozilla.gecko.prompts; |
|
7 |
|
8 import org.json.JSONObject; |
|
9 import org.mozilla.gecko.R; |
|
10 import org.mozilla.gecko.widget.BasicColorPicker; |
|
11 |
|
12 import android.content.Context; |
|
13 import android.graphics.Color; |
|
14 import android.view.LayoutInflater; |
|
15 import android.view.View; |
|
16 |
|
17 public class ColorPickerInput extends PromptInput { |
|
18 public static final String INPUT_TYPE = "color"; |
|
19 public static final String LOGTAG = "GeckoColorPickerInput"; |
|
20 |
|
21 private boolean mShowAdvancedButton = true; |
|
22 private int mInitialColor; |
|
23 |
|
24 public ColorPickerInput(JSONObject obj) { |
|
25 super(obj); |
|
26 String init = obj.optString("value"); |
|
27 mInitialColor = Color.rgb(Integer.parseInt(init.substring(1,3), 16), |
|
28 Integer.parseInt(init.substring(3,5), 16), |
|
29 Integer.parseInt(init.substring(5,7), 16)); |
|
30 } |
|
31 |
|
32 @Override |
|
33 public View getView(Context context) throws UnsupportedOperationException { |
|
34 LayoutInflater inflater = LayoutInflater.from(context); |
|
35 mView = inflater.inflate(R.layout.basic_color_picker_dialog, null); |
|
36 |
|
37 BasicColorPicker cp = (BasicColorPicker) mView.findViewById(R.id.colorpicker); |
|
38 cp.setColor(mInitialColor); |
|
39 |
|
40 return mView; |
|
41 } |
|
42 |
|
43 @Override |
|
44 public Object getValue() { |
|
45 BasicColorPicker cp = (BasicColorPicker) mView.findViewById(R.id.colorpicker); |
|
46 int color = cp.getColor(); |
|
47 return "#" + Integer.toHexString(color).substring(2); |
|
48 } |
|
49 |
|
50 @Override |
|
51 public boolean getScrollable() { |
|
52 return true; |
|
53 } |
|
54 |
|
55 @Override |
|
56 public boolean canApplyInputStyle() { |
|
57 return false; |
|
58 } |
|
59 } |