Example usage for android.graphics Color argb

List of usage examples for android.graphics Color argb

Introduction

In this page you can find the example usage for android.graphics Color argb.

Prototype

@ColorInt
public static int argb(float alpha, float red, float green, float blue) 

Source Link

Document

Return a color-int from alpha, red, green, blue float components in the range \([0..1]\).

Usage

From source file:org.mixare.data.Json.java

/**
 * returns a random color out of 6 predefined colors
 * //  w  ww .ja  va2 s .com
 * @return
 */
private static int getRandomGraffitiColor() {
    // random int
    Random randomGenerator = new Random((new Date()).getTime());
    int randomInt = randomGenerator.nextInt(6);

    // System.out.println("random int: " + randomInt);

    final int TRANSPARENCY = 180;
    int resultColor = Color.argb(TRANSPARENCY, 117, 12, 91);
    ;

    // select a random out of following colors
    switch (randomInt) {
    case 0:
        resultColor = Color.argb(TRANSPARENCY, 117, 12, 91);
        break;
    case 1:
        resultColor = Color.argb(TRANSPARENCY, 210, 26, 26);
        break;
    case 2:
        resultColor = Color.argb(TRANSPARENCY, 33, 152, 6);
        break;
    case 3:
        resultColor = Color.argb(TRANSPARENCY, 7, 81, 192);
        break;
    case 4:
        resultColor = Color.argb(TRANSPARENCY, 191, 111, 7);
        break;
    case 5:
        resultColor = Color.argb(TRANSPARENCY, 167, 173, 0);
        break;

    }
    return resultColor;
}

From source file:es.uma.lcc.tasks.DecryptionRequestTask.java

public Void doInBackground(Void... parameters) {
    if (mPicId == null) {
        mDecodedBmp = BitmapFactory.decodeFile(mSrc);
    } else {//ww w.j  av a 2  s.  c  om
        DefaultHttpClient httpclient = new DefaultHttpClient();
        final HttpParams params = new BasicHttpParams();
        HttpClientParams.setRedirecting(params, false);
        httpclient.setParams(params);
        String target = SERVERURL + "?" + QUERYSTRING_ACTION + "=" + ACTION_READPERMISSIONS + "&"
                + QUERYSTRING_PICTUREID + "=" + mPicId;
        HttpGet httpget = new HttpGet(target);

        while (mCookie == null) // loop until authentication finishes, if necessary
            mCookie = mMainActivity.getCurrentCookie();

        httpget.setHeader("Cookie", mCookie.getName() + "=" + mMainActivity.getCurrentCookie().getValue());
        System.out.println("Cookie in header: " + mMainActivity.getCurrentCookie().getValue());
        try {
            HttpResponse response = httpclient.execute(httpget);

            StatusLine status = response.getStatusLine();
            if (status.getStatusCode() != 200) {
                mConnectionSucceeded = false;
                throw new IOException("Invalid response from server: " + status.toString());
            }

            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream inputStream = entity.getContent();
                ByteArrayOutputStream content = new ByteArrayOutputStream();

                // Read response into a buffered stream
                int readBytes = 0;
                byte[] sBuffer = new byte[256];
                while ((readBytes = inputStream.read(sBuffer)) != -1) {
                    content.write(sBuffer, 0, readBytes);
                }
                String result = new String(content.toByteArray());

                try {
                    JSONArray jsonArray = new JSONArray(result);
                    JSONObject jsonObj;
                    if (jsonArray.length() == 0) {
                        // should never happen
                        Log.e(APP_TAG, LOG_ERROR + ": Malformed response from server");
                    } else {
                        // Elements in a JSONArray keep their order
                        JSONObject successState = jsonArray.getJSONObject(0);
                        if (successState.get(JSON_RESULT).equals(JSON_RESULT_ERROR)) {
                            if (successState.getBoolean(JSON_ISAUTHERROR) && mIsFirstRun) {
                                mIsAuthError = true;
                                Log.e(APP_TAG, LOG_ERROR + ": Server found an auth error: "
                                        + successState.get(JSON_REASON));
                            } else {
                                Log.e(APP_TAG, LOG_ERROR + ": Server found an error: "
                                        + successState.get(JSON_REASON));
                            }
                        } else {
                            mSquareNum = jsonArray.length() - 1;
                            mHorizStarts = new int[mSquareNum];
                            mHorizEnds = new int[mSquareNum];
                            mVertStarts = new int[mSquareNum];
                            mVertEnds = new int[mSquareNum];
                            mKeys = new String[mSquareNum];
                            for (int i = 0; i < mSquareNum; i++) {
                                jsonObj = jsonArray.getJSONObject(i + 1);
                                mHorizStarts[i] = jsonObj.getInt(JSON_HSTART);
                                mHorizEnds[i] = jsonObj.getInt(JSON_HEND);
                                mVertStarts[i] = jsonObj.getInt(JSON_VSTART);
                                mVertEnds[i] = jsonObj.getInt(JSON_VEND);
                                mKeys[i] = jsonObj.getString(JSON_KEY);
                            }
                            publishProgress(10);
                            BitmapFactory.Options options = new BitmapFactory.Options();
                            options.inJustDecodeBounds = true; // get dimensions without reloading the image
                            BitmapFactory.decodeFile(mSrc, options);
                            mWidth = options.outWidth;
                            mHeight = options.outHeight;
                            mDecodedBmp = Bitmap.createBitmap(options.outWidth, options.outHeight,
                                    Config.ARGB_8888);

                            if (mSquareNum == 0) {
                                mDecodedBmp = BitmapFactory.decodeFile(mSrc);
                            } else {
                                mHasFoundKeys = true;
                                byte[] pixels = MainActivity.decodeWrapperRegions(mSrc, mSquareNum,
                                        mHorizStarts, mHorizEnds, mVertStarts, mVertEnds, mKeys, mPicId);

                                /* Native side returns each pixel as an RGBA quadruplet, with
                                 each a C unsigned byte ([0,255]). However, Java reads those
                                 as signed bytes ([-128, 127]) in two's complement.
                                 We mask them with 0xFF to ensure most significant bits set to 0,
                                 therefore interpreting them as their positive (unsigned) value.
                                 Furthermore, Java functions take pixels in ARGB (and not RGBA),
                                 so we manually re-order them */
                                int baseIndex;
                                for (int i = 0; i < mWidth; i++) {
                                    for (int j = 0; j < mHeight; j++) {
                                        baseIndex = 4 * (j * mWidth + i);
                                        mDecodedBmp.setPixel(i, j,
                                                Color.argb(pixels[baseIndex + 3] & 0xff,
                                                        pixels[baseIndex] & 0xff, pixels[baseIndex + 1] & 0xff,
                                                        pixels[baseIndex + 2] & 0xff));
                                    }
                                }
                            }
                        }
                    }
                } catch (JSONException jsonEx) {
                    Log.e(APP_TAG, LOG_ERROR + ": Malformed JSON response from server");
                    mSquareNum = 0;
                }
            }
        } catch (ClientProtocolException e) {
            mConnectionSucceeded = false;
            Log.e(APP_TAG, LOG_ERROR + ": " + e.getMessage());
        } catch (IOException e) {
            mConnectionSucceeded = false;
            Log.e(APP_TAG, LOG_ERROR + ": " + e.getMessage());
        }
    }
    return null;
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Return alpha color/*from ww  w.j  a v  a 2s  . c om*/
 *
 * @param color
 * @param ratio
 * @return
 */
public static int getColorWithAplha(int color, float ratio) {
    int transColor;
    int alpha = Math.round(Color.alpha(color) * ratio);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);
    transColor = Color.argb(alpha, r, g, b);
    return transColor;
}

From source file:com.saulcintero.moveon.fragments.Summary3.java

private void lineChartView_type1() {
    if (paintChartView) {
        check1.setVisibility(View.VISIBLE);
        check2.setVisibility(View.VISIBLE);
        txt1.setVisibility(View.GONE);

        TypedValue outValue1 = new TypedValue();
        TypedValue outValue2 = new TypedValue();
        TypedValue outValue3 = new TypedValue();
        TypedValue outValue4 = new TypedValue();
        mContext.getResources().getValue(R.dimen.line_axis_title_text_size_value, outValue1, true);
        mContext.getResources().getValue(R.dimen.line_chart_title_text_size_value, outValue2, true);
        mContext.getResources().getValue(R.dimen.line_labels_text_size_value, outValue3, true);
        mContext.getResources().getValue(R.dimen.line_legend_text_size_value, outValue4, true);
        float lineAxisTitleTextSizeValue = outValue1.getFloat();
        float lineCharTitleTextSizeValue = outValue2.getFloat();
        float lineLabelsTextSizeValue = outValue3.getFloat();
        float lineLegendTextSizeValue = outValue4.getFloat();

        XYMultipleSeriesDataset mDataset = getDataset_type1();
        XYMultipleSeriesRenderer mRenderer = getRenderer_type1();
        mRenderer.setApplyBackgroundColor(true);
        mRenderer.setBackgroundColor(Color.TRANSPARENT);
        mRenderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
        mRenderer.setAxisTitleTextSize(lineAxisTitleTextSizeValue);
        mRenderer.setChartTitleTextSize(lineCharTitleTextSizeValue);
        mRenderer.setLabelsTextSize(lineLabelsTextSizeValue);
        mRenderer.setLegendTextSize(lineLegendTextSizeValue);
        mRenderer.setMargins(new int[] { 12, 25, 12, 22 });
        mRenderer.setZoomButtonsVisible(true);
        mRenderer.setPointSize(10);/*from   ww w  . jav  a  2 s  .c om*/
        mRenderer.setClickEnabled(true);
        mChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer);

        mChartView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();

                if (seriesSelection != null) {
                    String units = "";
                    switch (seriesSelection.getSeriesIndex()) {
                    case 0:
                        units = " " + (isMetric ? getString(R.string.long_unit1_detail_4)
                                : getString(R.string.long_unit2_detail_4));
                        break;
                    case 1:
                        units = " " + (isMetric ? getString(R.string.long_unit1_detail_2)
                                : getString(R.string.long_unit2_detail_2));
                        break;
                    }
                    UIFunctionUtils.showMessage(mContext, true, (int) seriesSelection.getValue() + units);
                }
            }
        });

        chartLayout.addView(mChartView);
    } else {
        setCorrectText();
    }
}

From source file:foam.mongoose.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {/*from   ww  w . j  a va 2 s  .c o m*/
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });
            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(6);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                    spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = new StarwispCanvas(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.SetDrawList(arr.getJSONArray(3));
            parent.addView(v);
        }

        if (type.equals("camera-preview")) {
            PictureTaker pt = new PictureTaker();
            CameraPreview v = new CameraPreview(ctx, pt);
            final int wid = arr.getInt(1);
            v.setId(wid);

            //              LinearLayout.LayoutParams lp =
            //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            //                v.setLayoutParams(lp);
            parent.addView(v);
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:com.maxwen.wallpaper.board.adapters.WallpapersAdapterUnified.java

@Override
public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {
    if (h instanceof ImageHolder) {
        final ImageHolder holder = (ImageHolder) h;
        Wallpaper w = ((Wallpaper) mWallpapers.get(position));
        holder.name.setText(w.getName());
        holder.author.setText(w.getAuthor());
        holder.newWallpaper.setVisibility(mNewWallpapers.contains(w) ? View.VISIBLE : View.GONE);

        setFavorite(holder.favorite, ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary),
                position, false);//from ww w.j a v  a 2  s.co  m

        String url = w.getThumbUrl();

        ImageLoader.getInstance().displayImage(url, new ImageViewAware(holder.image), mOptions.build(),
                ImageConfig.getThumbnailSize(mContext), new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        super.onLoadingStarted(imageUri, view);
                        if (mIsAutoGeneratedColor) {
                            int vibrant = ColorHelper.getAttributeColor(mContext, R.attr.card_background);
                            holder.imageInfo.setBackgroundColor(vibrant);
                            int primary = ColorHelper.getAttributeColor(mContext,
                                    android.R.attr.textColorPrimary);
                            holder.name.setTextColor(primary);
                            holder.author.setTextColor(primary);
                        } else {
                            int color = mContext.getResources().getColor(R.color.image_info_text);
                            holder.imageInfo.setBackgroundColor(
                                    mContext.getResources().getColor(R.color.image_info_bg));
                            holder.name.setTextColor(color);
                            holder.author.setTextColor(color);
                        }
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        super.onLoadingComplete(imageUri, view, loadedImage);
                        if (mIsAutoGeneratedColor) {
                            if (loadedImage != null) {
                                Palette.from(loadedImage).generate(new Palette.PaletteAsyncListener() {
                                    @Override
                                    public void onGenerated(Palette palette) {
                                        int vibrant = ColorHelper.getAttributeColor(mContext,
                                                R.attr.card_background);
                                        int color = palette.getVibrantColor(vibrant);
                                        if (color == vibrant)
                                            color = palette.getMutedColor(vibrant);
                                        color = Color.argb(0x60, Color.red(color), Color.green(color),
                                                Color.blue(color));
                                        holder.imageInfo.setBackgroundColor(color);
                                        int text = ColorHelper.getTitleTextColor(color);
                                        holder.name.setTextColor(text);
                                        holder.author.setTextColor(text);
                                        setFavorite(holder.favorite, text, holder.getAdapterPosition(), false);
                                    }
                                });
                            }
                        } else {
                            int color = mContext.getResources().getColor(R.color.image_info_text);
                            holder.imageInfo.setBackgroundColor(
                                    mContext.getResources().getColor(R.color.image_info_bg));
                            holder.name.setTextColor(color);
                            holder.author.setTextColor(color);
                            setFavorite(holder.favorite, color, holder.getAdapterPosition(), false);
                        }
                    }
                }, null);

    } else if (h instanceof HeaderHolder) {
        HeaderHolder holder = (HeaderHolder) h;
        holder.mCatageory = (Category) mWallpapers.get(position);
        holder.category.setText(holder.mCatageory.getName());
        holder.count.setText(holder.mCatageory.getNumWallpapers() + " " + mCountString);
        holder.container.setClickable(mIsCategorySelectable);
        if (mIsCollapseMode) {
            holder.collapse.setRotation(!mCollapsedCategories.contains(holder.mCatageory.getName()) ? 180 : 0);
        }
        holder.newWallpaper
                .setVisibility(mNewCategories.contains(holder.mCatageory.getName()) ? View.VISIBLE : View.GONE);

        String url = holder.mCatageory.getThumbUrl();
        ImageLoader.getInstance().displayImage(url, new ImageViewAware(holder.image), mOptions.build(),
                ImageConfig.getThumbnailSize(mContext), new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        super.onLoadingStarted(imageUri, view);
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        super.onLoadingComplete(imageUri, view, loadedImage);
                    }
                }, null);

        int color = mContext.getResources().getColor(R.color.image_info_text);
        holder.imageInfo.setBackgroundColor(mContext.getResources().getColor(R.color.image_info_bg));
        holder.category.setTextColor(color);
        holder.count.setTextColor(color);
        holder.collapse
                .setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_expand, color));
    }
}

From source file:com.raulh82vlc.topratemovies.activities.CardFilmDetailsActivity.java

/**
 * Method getItsAlphaColor//from w  w  w . jav  a  2  s . co m
 * if API 21 then effects are settled
 *
 * @param iColor      alpha of a color
 * @param scrollRatio float variant
 */
private int getItsAlphaColor(int iColor, float scrollRatio) {
    return Color.argb((int) (scrollRatio * 255f), Color.red(iColor), Color.green(iColor), Color.blue(iColor));
}

From source file:com.readystatesoftware.ghostlog.ServerlessLogScreen.java

private void setSystemViewBackground(int v) {
    int level = 0;
    if (v > 0) {
        int a = (int) ((float) v / 100f * 255);
        mLogListView.setBackgroundColor(Color.argb(a, level, level, level));
    } else {/* www  . j a v a 2s .  co  m*/
        mLogListView.setBackgroundDrawable(null);
    }
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

private Bitmap createReflectionBitmap(Bitmap original) {
    final int w = original.getWidth();
    final int h = original.getHeight();
    final int rh = (int) (h * mReflectionHeight);
    final int gradientColor = Color.argb(mReflectionOpacity, 0xff, 0xff, 0xff);

    final Bitmap reflection = Bitmap.createBitmap(original, 0, rh, w, rh, mReflectionMatrix, false);

    final LinearGradient shader = new LinearGradient(0, 0, 0, reflection.getHeight(), gradientColor, 0x00ffffff,
            TileMode.CLAMP);//from   w w w  .j a v  a2s  . c om
    mPaint.reset();
    mPaint.setShader(shader);
    mPaint.setXfermode(mXfermode);

    mReflectionCanvas.setBitmap(reflection);
    mReflectionCanvas.drawRect(0, 0, reflection.getWidth(), reflection.getHeight(), mPaint);

    return reflection;
}

From source file:de.mdxdave.materialbreadcrumbsnavigation.MaterialBreadcrumbsNavigation.java

private static int modifyColor(int color, float factor) {
    int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0),
            Math.max((int) (b * factor), 0));
}