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