mobile/android/base/prompts/ColorPickerInput.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/prompts/ColorPickerInput.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko.prompts;
    1.10 +
    1.11 +import org.json.JSONObject;
    1.12 +import org.mozilla.gecko.R;
    1.13 +import org.mozilla.gecko.widget.BasicColorPicker;
    1.14 +
    1.15 +import android.content.Context;
    1.16 +import android.graphics.Color;
    1.17 +import android.view.LayoutInflater;
    1.18 +import android.view.View;
    1.19 +
    1.20 +public class ColorPickerInput extends PromptInput {
    1.21 +    public static final String INPUT_TYPE = "color";
    1.22 +    public static final String LOGTAG = "GeckoColorPickerInput";
    1.23 +
    1.24 +    private boolean mShowAdvancedButton = true;
    1.25 +    private int mInitialColor;
    1.26 +
    1.27 +    public ColorPickerInput(JSONObject obj) {
    1.28 +        super(obj);
    1.29 +        String init = obj.optString("value");
    1.30 +        mInitialColor = Color.rgb(Integer.parseInt(init.substring(1,3), 16),
    1.31 +                                  Integer.parseInt(init.substring(3,5), 16),
    1.32 +                                  Integer.parseInt(init.substring(5,7), 16));
    1.33 +    }
    1.34 +
    1.35 +    @Override
    1.36 +    public View getView(Context context) throws UnsupportedOperationException {
    1.37 +        LayoutInflater inflater = LayoutInflater.from(context);
    1.38 +        mView = inflater.inflate(R.layout.basic_color_picker_dialog, null);
    1.39 +
    1.40 +        BasicColorPicker cp = (BasicColorPicker) mView.findViewById(R.id.colorpicker);
    1.41 +        cp.setColor(mInitialColor);
    1.42 +
    1.43 +        return mView;
    1.44 +    }
    1.45 +
    1.46 +    @Override
    1.47 +    public Object getValue() {
    1.48 +        BasicColorPicker cp = (BasicColorPicker) mView.findViewById(R.id.colorpicker);
    1.49 +        int color = cp.getColor();
    1.50 +        return "#" + Integer.toHexString(color).substring(2);
    1.51 +    }
    1.52 +
    1.53 +    @Override
    1.54 +    public boolean getScrollable() {
    1.55 +        return true;
    1.56 +    }
    1.57 +
    1.58 +    @Override
    1.59 +    public boolean canApplyInputStyle() {
    1.60 +	return false;
    1.61 +    }
    1.62 +}

mercurial