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:com.yk.notification.util.BitmapUtil.java

/**
 * ??/*from ww w .j ava 2  s . c  om*/
 * 
 * @param delta
 *            ??(0,24)
 * @return
 */
public static Bitmap adjustTone(Bitmap src, int delta) {
    if (delta >= 24 || delta <= 0) {
        return null;
    }
    // 
    int[] gauss = new int[] { 1, 2, 1, 2, 4, 2, 1, 2, 1 };
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;
    int pixColor = 0;
    int newR = 0;
    int newG = 0;
    int newB = 0;
    int idx = 0;
    int[] pixels = new int[width * height];

    src.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            idx = 0;
            for (int m = -1; m <= 1; m++) {
                for (int n = -1; n <= 1; n++) {
                    pixColor = pixels[(i + m) * width + k + n];
                    pixR = Color.red(pixColor);
                    pixG = Color.green(pixColor);
                    pixB = Color.blue(pixColor);

                    newR += (pixR * gauss[idx]);
                    newG += (pixG * gauss[idx]);
                    newB += (pixB * gauss[idx]);
                    idx++;
                }
            }
            newR /= delta;
            newG /= delta;
            newB /= delta;
            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));
            pixels[i * width + k] = Color.argb(255, newR, newG, newB);
            newR = 0;
            newG = 0;
            newB = 0;
        }
    }
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

From source file:com.example.mego.adas.main.UserFragment.java

/**
 * method to get the data from the firebase and take action based on it
 *//*from  w ww . j  ava 2  s.com*/
private void actionResolver() {

    startStateEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                startState = (long) dataSnapshot.getValue();
                if (startState == 1) {
                    if (userFragments.isAdded()) {
                        //change the button color to the accent color when it's on
                        startButton.setBackgroundTintList(
                                ColorStateList.valueOf(getResources().getColor(R.color.off)));
                    }
                } else if (startState == 0) {
                    //change the button color to the accent color when it's on
                    if (userFragments.isAdded()) {
                        startButton.setBackgroundTintList(
                                ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
                    }
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };

    lockStateEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                lockState = (long) dataSnapshot.getValue();
                if (lockState == 1) {
                    if (userFragments.isAdded()) {
                        //change the button color to the accent color when it's on
                        lockButton.setBackgroundTintList(
                                ColorStateList.valueOf(getResources().getColor(R.color.off)));
                    }
                } else if (lockState == 0) {
                    //change the button color to the accent color when it's on
                    if (userFragments.isAdded()) {
                        lockButton.setBackgroundTintList(
                                ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
                    }
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };

    lightsStateEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                lightsState = (long) dataSnapshot.getValue();

                if (lightsState == 1) {
                    if (userFragments.isAdded()) {
                        //change the button color to the accent color when it's on
                        lightsButton.setBackgroundTintList(
                                ColorStateList.valueOf(getResources().getColor(R.color.off)));
                    }
                } else if (lightsState == 0) {
                    if (userFragments.isAdded()) {
                        //change the button color to the accent color when it's on
                        lightsButton.setBackgroundTintList(
                                ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
                    }
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };

    sensorsValueEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                SensorsValues sensorsValues = dataSnapshot.getValue(SensorsValues.class);

                //get the data from the firebase
                tempSensorValue = sensorsValues.getTemperatureSensorValue();
                tempPublishProcessor.onNext(tempSensorValue);

                //Temperature in Fahrenheit
                tempSensorInFahrenheit = (int) AdasUtils.celsiusToFahrenheit(tempSensorValue);

                ldrSensorValue = sensorsValues.getLdrSensorValue();
                ldrPublishProcessor.onNext(ldrSensorValue);

                potSensorValue = sensorsValues.getPotSensorValue();
                potPublishProcessor.onNext(potSensorValue);

                refreshUI();
            } else {
                showToast(getString(R.string.no_car_for_this_user));
                //progressDialog.dismiss();
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }

    };

    mappingServicesEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                MappingServices mappingServices = dataSnapshot.getValue(MappingServices.class);

                latitude = mappingServices.getLatitude();
                longitude = mappingServices.getLongitude();

                if (onConnectedFlag <= 1) {
                    onConnectedFlag = mappingServices.getOnConnectedFlag();
                }
                onLocationChangedFlag = mappingServices.getOnLocationChangedFlag();

                accidentPlace = new LatLng(latitude, longitude);

                cameraPosition = CameraPosition.builder().target(new LatLng(latitude, longitude)).zoom(zoom)
                        .bearing(bearing).tilt(tilt).build();

                //check for the map state if it's ready start
                if (mapReady) {

                    carPlace = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Car Place")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker));

                    if (onConnectedFlag == 1) {
                        marker = mMap.addMarker(carPlace);
                        flyTo(cameraPosition);

                    }

                    if (onLocationChangedFlag == 1) {
                        DirectionsApiUtilities.AnimateMarker(marker, accidentPlace, false, mMap);
                        cameraPosition = new CameraPosition.Builder().target(accidentPlace).zoom(zoom)
                                .bearing(bearing).tilt(tilt).build();
                        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
                    }
                    if (onConnectedFlag < 5) {
                        onConnectedFlag++;
                    }
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };

    accidentStateEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                Circle circle = null;
                accidentState = (long) dataSnapshot.getValue();
                if (accidentState == 1) {
                    accidentNotificationFlag++;
                    if (accidentNotificationFlag == 1) {
                        showAccidentHappenDialog();
                        circle = mMap.addCircle(new CircleOptions().center(accidentPlace).radius(50)
                                .strokeColor(getResources().getColor((R.color.red)))
                                .fillColor(Color.argb(64, 255, 0, 0)));
                        //NotificationUtils.showAccidentNotification(getContext());
                    }

                } else if (accidentState == 0) {
                    accidentNotificationFlag = 0;
                    if (circle != null) {
                        circle.remove();
                    }
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };

    connectionStateEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                connectionState = (long) dataSnapshot.getValue();
                if (connectionState == 0) {
                    if (userFragments.isAdded()) {
                        makeText(getContext(), R.string.car_not_connected, Toast.LENGTH_LONG).show();
                    }
                } else if (connectionState == 1) {
                    if (userFragments.isAdded()) {
                        makeText(getContext(), R.string.car_is_connected, Toast.LENGTH_LONG).show();
                    }
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };

    //add a listener to the reference
    mappingServicesDatabaseReference.addValueEventListener(mappingServicesEventListener);
    accidentStateDatabaseReference.addValueEventListener(accidentStateEventListener);
    sensorsValuesDatabaseReference.addValueEventListener(sensorsValueEventListener);
    startStateStateDatabaseReference.addValueEventListener(startStateEventListener);
    lockStateDatabaseReference.addValueEventListener(lockStateEventListener);
    lightsStateDatabaseReference.addValueEventListener(lightsStateEventListener);
    connectionStateDatabaseReference.addValueEventListener(connectionStateEventListener);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static int getUserHighlightColor(final Context context) {
    final int color = getUserLinkTextColor(context);
    final int red = Color.red(color), green = Color.green(color), blue = Color.blue(color);
    return Color.argb(0x66, red, green, blue);
}

From source file:com.cosmicsubspace.nerdyaudio.visuals.PlayControlsView.java

@Override
protected void onDraw(Canvas canvas) {

    //Log2.log(2,this,buttonFollower.getInfluence().getValue(),playBtnRestPosition.getInfluence().getValue());

    currentFrameTime = System.currentTimeMillis();

    pt.setColor(menuColor);//from w w  w .j av a 2s  .c  o m
    canvas.drawRect(0, h - barHeight.getValue(currentFrameTime).getValue("Height"), w, h, pt);

    titleAnimatable.draw(canvas, pt, currentFrameTime);

    artistAnimatable.draw(canvas, pt, currentFrameTime);

    filePath.draw(canvas, pt, currentFrameTime);
    if (albumArt != null) {
        pt.setAlpha(Math.round(albumArtColor.getValue(currentFrameTime).getValue("alpha")));
        canvas.drawBitmap(albumArt, null, artBoundsAnim.getRectF(currentFrameTime), pt);
        //Log2.log(1,this, "trying to draw..");
        pt.setAlpha(255);
    }

    waveform.draw(canvas, pt, currentFrameTime);

    pt.setColor(Color.argb(50, 0, 0, 0));

    pt.setColor(buttonColor);

    playBtn.draw(canvas, pt, currentFrameTime);

    pauseBtn.draw(canvas, pt, currentFrameTime);

    prevBtn.draw(canvas, pt, currentFrameTime);
    nextBtn.draw(canvas, pt, currentFrameTime);

    if (wf != null && ap != null && wf.isReady() && wf.getFilename().equals(ap.getSourceString())) {
        setCurrentPosition((float) (ap.getMusicCurrentFrame() / (double) wf.getNumOfFrames()));

        if (!dragMode) {
            timestampAnim.setText(wf.frameNumberToTimeStamp(ap.getMusicCurrentFrame()));
        }

        timestampAnim.draw(canvas, pt, currentFrameTime);

        buttonFollowerProgress.getBasis().setValue("X", w * currentPosition);
    }

    invalidate();

}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

protected void updateMessageDetail(final boolean isUpdate) {
    T.UI();//  www .j av a 2  s  . c om
    // Set sender avatar
    ImageView avatarImage = (ImageView) findViewById(R.id.avatar);
    String sender = mCurrentMessage.sender;
    setAvatar(avatarImage, sender);
    // Set sender name
    TextView senderView = (TextView) findViewById(R.id.sender);
    final String senderName = mFriendsPlugin.getName(sender);
    senderView.setText(senderName == null ? sender : senderName);
    // Set timestamp
    TextView timestampView = (TextView) findViewById(R.id.timestamp);
    timestampView.setText(TimeUtils.getDayTimeStr(this, mCurrentMessage.timestamp * 1000));

    // Set clickable region on top to go to friends detail
    final RelativeLayout messageHeader = (RelativeLayout) findViewById(R.id.message_header);
    messageHeader.setOnClickListener(getFriendDetailOnClickListener(mCurrentMessage.sender));
    messageHeader.setVisibility(View.VISIBLE);

    // Set message
    TextView messageView = (TextView) findViewById(R.id.message);
    WebView web = (WebView) findViewById(R.id.webview);
    FrameLayout flay = (FrameLayout) findViewById(R.id.message_details);
    Resources resources = getResources();
    flay.setBackgroundColor(resources.getColor(R.color.mc_background));
    boolean showBranded = false;

    int darkSchemeTextColor = resources.getColor(android.R.color.primary_text_dark);
    int lightSchemeTextColor = resources.getColor(android.R.color.primary_text_light);

    senderView.setTextColor(lightSchemeTextColor);
    timestampView.setTextColor(lightSchemeTextColor);

    BrandingResult br = null;
    if (!TextUtils.isEmptyOrWhitespace(mCurrentMessage.branding)) {
        boolean brandingAvailable = false;
        try {
            brandingAvailable = mMessagingPlugin.getBrandingMgr().isBrandingAvailable(mCurrentMessage.branding);
        } catch (BrandingFailureException e1) {
            L.d(e1);
        }
        try {
            if (brandingAvailable) {
                br = mMessagingPlugin.getBrandingMgr().prepareBranding(mCurrentMessage);
                WebSettings settings = web.getSettings();
                settings.setJavaScriptEnabled(false);
                settings.setBlockNetworkImage(false);
                web.loadUrl("file://" + br.file.getAbsolutePath());
                web.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
                if (br.color != null) {
                    flay.setBackgroundColor(br.color);
                }
                if (!br.showHeader) {
                    messageHeader.setVisibility(View.GONE);
                    MarginLayoutParams mlp = (MarginLayoutParams) web.getLayoutParams();
                    mlp.setMargins(0, 0, 0, mlp.bottomMargin);
                } else if (br.scheme == ColorScheme.dark) {
                    senderView.setTextColor(darkSchemeTextColor);
                    timestampView.setTextColor(darkSchemeTextColor);
                }

                showBranded = true;
            } else {
                mMessagingPlugin.getBrandingMgr().queueGenericBranding(mCurrentMessage.branding);
            }
        } catch (BrandingFailureException e) {
            L.bug("Could not display message with branding: branding is available, but prepareBranding failed",
                    e);
        }
    }

    if (showBranded) {
        web.setVisibility(View.VISIBLE);
        messageView.setVisibility(View.GONE);
    } else {
        web.setVisibility(View.GONE);
        messageView.setVisibility(View.VISIBLE);
        messageView.setText(mCurrentMessage.message);
    }

    // Add list of members who did not ack yet
    FlowLayout memberSummary = (FlowLayout) findViewById(R.id.member_summary);
    memberSummary.removeAllViews();
    SortedSet<MemberStatusTO> memberSummarySet = new TreeSet<MemberStatusTO>(getMemberstatusComparator());
    for (MemberStatusTO ms : mCurrentMessage.members) {
        if ((ms.status & MessagingPlugin.STATUS_ACKED) != MessagingPlugin.STATUS_ACKED
                && !ms.member.equals(mCurrentMessage.sender)) {
            memberSummarySet.add(ms);
        }
    }
    FlowLayout.LayoutParams flowLP = new FlowLayout.LayoutParams(2, 0);
    for (MemberStatusTO ms : memberSummarySet) {
        FrameLayout fl = new FrameLayout(this);
        fl.setLayoutParams(flowLP);
        memberSummary.addView(fl);
        fl.addView(createParticipantView(ms));
    }
    memberSummary.setVisibility(memberSummarySet.size() < 2 ? View.GONE : View.VISIBLE);

    // Add members statuses
    final LinearLayout members = (LinearLayout) findViewById(R.id.members);
    members.removeAllViews();
    final String myEmail = mService.getIdentityStore().getIdentity().getEmail();
    boolean isMember = false;
    mSomebodyAnswered = false;
    for (MemberStatusTO ms : mCurrentMessage.members) {
        boolean showMember = true;
        View view = getLayoutInflater().inflate(R.layout.message_member_detail, null);
        // Set receiver avatar
        RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.avatar);
        rl.addView(createParticipantView(ms));
        // Set receiver name
        TextView receiverView = (TextView) view.findViewById(R.id.receiver);
        final String memberName = mFriendsPlugin.getName(ms.member);
        receiverView.setText(memberName == null ? sender : memberName);
        // Set received timestamp
        TextView receivedView = (TextView) view.findViewById(R.id.received_timestamp);
        if ((ms.status & MessagingPlugin.STATUS_RECEIVED) == MessagingPlugin.STATUS_RECEIVED) {
            final String humanTime = TimeUtils.getDayTimeStr(this, ms.received_timestamp * 1000);
            if (ms.member.equals(mCurrentMessage.sender))
                receivedView.setText(getString(R.string.sent_at, humanTime));
            else
                receivedView.setText(getString(R.string.received_at, humanTime));
        } else {
            receivedView.setText(R.string.not_yet_received);
        }
        // Set replied timestamp
        TextView repliedView = (TextView) view.findViewById(R.id.acked_timestamp);
        if ((ms.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED) {
            mSomebodyAnswered = true;
            String acked_timestamp = TimeUtils.getDayTimeStr(this, ms.acked_timestamp * 1000);
            if (ms.button_id != null) {

                ButtonTO button = null;
                for (ButtonTO b : mCurrentMessage.buttons) {
                    if (b.id.equals(ms.button_id)) {
                        button = b;
                        break;
                    }
                }
                if (button == null) {
                    repliedView.setText(getString(R.string.dismissed_at, acked_timestamp));
                    // Do not show sender as member if he hasn't clicked a
                    // button
                    showMember = !ms.member.equals(mCurrentMessage.sender);
                } else {
                    repliedView.setText(getString(R.string.replied_at, button.caption, acked_timestamp));
                }
            } else {
                if (ms.custom_reply == null) {
                    // Do not show sender as member if he hasn't clicked a
                    // button
                    showMember = !ms.member.equals(mCurrentMessage.sender);
                    repliedView.setText(getString(R.string.dismissed_at, acked_timestamp));
                } else
                    repliedView.setText(getString(R.string.replied_at, ms.custom_reply, acked_timestamp));
            }
        } else {
            repliedView.setText(R.string.not_yet_replied);
            showMember = !ms.member.equals(mCurrentMessage.sender);
        }
        if (br != null && br.scheme == ColorScheme.dark) {
            receiverView.setTextColor(darkSchemeTextColor);
            receivedView.setTextColor(darkSchemeTextColor);
            repliedView.setTextColor(darkSchemeTextColor);
        } else {
            receiverView.setTextColor(lightSchemeTextColor);
            receivedView.setTextColor(lightSchemeTextColor);
            repliedView.setTextColor(lightSchemeTextColor);
        }

        if (showMember)
            members.addView(view);
        isMember |= ms.member.equals(myEmail);
    }

    boolean isLocked = (mCurrentMessage.flags & MessagingPlugin.FLAG_LOCKED) == MessagingPlugin.FLAG_LOCKED;
    boolean canEdit = isMember && !isLocked;

    // Add attachments
    LinearLayout attachmentLayout = (LinearLayout) findViewById(R.id.attachment_layout);
    attachmentLayout.removeAllViews();
    if (mCurrentMessage.attachments.length > 0) {
        attachmentLayout.setVisibility(View.VISIBLE);

        for (final AttachmentTO attachment : mCurrentMessage.attachments) {
            View v = getLayoutInflater().inflate(R.layout.attachment_item, null);

            ImageView attachment_image = (ImageView) v.findViewById(R.id.attachment_image);
            if (AttachmentViewerActivity.CONTENT_TYPE_JPEG.equalsIgnoreCase(attachment.content_type)
                    || AttachmentViewerActivity.CONTENT_TYPE_PNG.equalsIgnoreCase(attachment.content_type)) {
                attachment_image.setImageResource(R.drawable.attachment_img);
            } else if (AttachmentViewerActivity.CONTENT_TYPE_PDF.equalsIgnoreCase(attachment.content_type)) {
                attachment_image.setImageResource(R.drawable.attachment_pdf);
            } else if (AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4
                    .equalsIgnoreCase(attachment.content_type)) {
                attachment_image.setImageResource(R.drawable.attachment_video);
            } else {
                attachment_image.setImageResource(R.drawable.attachment_unknown);
                L.d("attachment.content_type not known: " + attachment.content_type);
            }

            TextView attachment_text = (TextView) v.findViewById(R.id.attachment_text);
            attachment_text.setText(attachment.name);

            v.setOnClickListener(new SafeViewOnClickListener() {

                @Override
                public void safeOnClick(View v) {
                    String downloadUrlHash = mMessagingPlugin
                            .attachmentDownloadUrlHash(attachment.download_url);

                    File attachmentsDir;
                    try {
                        attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), null);
                    } catch (IOException e) {
                        L.d("Unable to create attachment directory", e);
                        UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "",
                                R.string.unable_to_read_write_sd_card);
                        return;
                    }

                    boolean attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir,
                            downloadUrlHash);

                    if (!attachmentAvailable) {
                        try {
                            attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(),
                                    mCurrentMessage.key);
                        } catch (IOException e) {
                            L.d("Unable to create attachment directory", e);
                            UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "",
                                    R.string.unable_to_read_write_sd_card);
                            return;
                        }

                        attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir,
                                downloadUrlHash);
                    }

                    if (!mService.getNetworkConnectivityManager().isConnected() && !attachmentAvailable) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                ServiceMessageDetailActivity.this);
                        builder.setMessage(R.string.no_internet_connection_try_again);
                        builder.setPositiveButton(R.string.rogerthat, null);
                        AlertDialog dialog = builder.create();
                        dialog.show();
                        return;
                    }
                    if (IOUtils.shouldCheckExternalStorageAvailable()) {
                        String state = Environment.getExternalStorageState();
                        if (Environment.MEDIA_MOUNTED.equals(state)) {
                            // Its all oke
                        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
                            if (!attachmentAvailable) {
                                L.d("Unable to write to sd-card");
                                UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "",
                                        R.string.unable_to_read_write_sd_card);
                                return;
                            }
                        } else {
                            L.d("Unable to read or write to sd-card");
                            UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "",
                                    R.string.unable_to_read_write_sd_card);
                            return;
                        }
                    }

                    L.d("attachment.content_type: " + attachment.content_type);
                    L.d("attachment.download_url: " + attachment.download_url);
                    L.d("attachment.name: " + attachment.name);
                    L.d("attachment.size: " + attachment.size);

                    if (AttachmentViewerActivity.supportsContentType(attachment.content_type)) {
                        Intent i = new Intent(ServiceMessageDetailActivity.this,
                                AttachmentViewerActivity.class);
                        i.putExtra("thread_key", mCurrentMessage.getThreadKey());
                        i.putExtra("message", mCurrentMessage.key);
                        i.putExtra("content_type", attachment.content_type);
                        i.putExtra("download_url", attachment.download_url);
                        i.putExtra("name", attachment.name);
                        i.putExtra("download_url_hash", downloadUrlHash);

                        startActivity(i);
                    } else {
                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                ServiceMessageDetailActivity.this);
                        builder.setMessage(getString(R.string.attachment_can_not_be_displayed_in_your_version,
                                getString(R.string.app_name)));
                        builder.setPositiveButton(R.string.rogerthat, null);
                        AlertDialog dialog = builder.create();
                        dialog.show();
                    }
                }

            });

            attachmentLayout.addView(v);
        }

    } else {
        attachmentLayout.setVisibility(View.GONE);
    }

    LinearLayout widgetLayout = (LinearLayout) findViewById(R.id.widget_layout);
    if (mCurrentMessage.form == null) {
        widgetLayout.setVisibility(View.GONE);
    } else {
        widgetLayout.setVisibility(View.VISIBLE);
        widgetLayout.setEnabled(canEdit);
        displayWidget(widgetLayout, br);
    }

    // Add buttons
    TableLayout tableLayout = (TableLayout) findViewById(R.id.buttons);
    tableLayout.removeAllViews();

    for (final ButtonTO button : mCurrentMessage.buttons) {
        addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button);
    }
    if (mCurrentMessage.form == null && (mCurrentMessage.flags
            & MessagingPlugin.FLAG_ALLOW_DISMISS) == MessagingPlugin.FLAG_ALLOW_DISMISS) {
        ButtonTO button = new ButtonTO();
        button.caption = "Roger that!";
        addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button);
    }

    if (mCurrentMessage.broadcast_type != null) {
        L.d("Show broadcast spam control");
        final RelativeLayout broadcastSpamControl = (RelativeLayout) findViewById(R.id.broadcast_spam_control);
        View broadcastSpamControlBorder = findViewById(R.id.broadcast_spam_control_border);
        final View broadcastSpamControlDivider = findViewById(R.id.broadcast_spam_control_divider);

        final LinearLayout broadcastSpamControlTextContainer = (LinearLayout) findViewById(
                R.id.broadcast_spam_control_text_container);
        TextView broadcastSpamControlText = (TextView) findViewById(R.id.broadcast_spam_control_text);

        final LinearLayout broadcastSpamControlSettingsContainer = (LinearLayout) findViewById(
                R.id.broadcast_spam_control_settings_container);
        TextView broadcastSpamControlSettingsText = (TextView) findViewById(
                R.id.broadcast_spam_control_settings_text);
        TextView broadcastSpamControlIcon = (TextView) findViewById(R.id.broadcast_spam_control_icon);
        broadcastSpamControlIcon.setTypeface(mFontAwesomeTypeFace);
        broadcastSpamControlIcon.setText(R.string.fa_bell);

        final FriendBroadcastInfo fbi = mFriendsPlugin.getFriendBroadcastFlowForMfr(mCurrentMessage.sender);
        if (fbi == null) {
            L.bug("BroadcastData was null for: " + mCurrentMessage.sender);
            collapseDetails(DETAIL_SECTIONS);
            return;
        }
        broadcastSpamControl.setVisibility(View.VISIBLE);

        broadcastSpamControlSettingsContainer.setOnClickListener(new SafeViewOnClickListener() {

            @Override
            public void safeOnClick(View v) {
                L.d("goto broadcast settings");

                PressMenuIconRequestTO request = new PressMenuIconRequestTO();
                request.coords = fbi.coords;
                request.static_flow_hash = fbi.staticFlowHash;
                request.hashed_tag = fbi.hashedTag;
                request.generation = fbi.generation;
                request.service = mCurrentMessage.sender;
                mContext = "MENU_" + UUID.randomUUID().toString();
                request.context = mContext;
                request.timestamp = System.currentTimeMillis() / 1000;

                showTransmitting(null);
                Map<String, Object> userInput = new HashMap<String, Object>();
                userInput.put("request", request.toJSONMap());
                userInput.put("func", "com.mobicage.api.services.pressMenuItem");

                MessageFlowRun mfr = new MessageFlowRun();
                mfr.staticFlowHash = fbi.staticFlowHash;
                try {
                    JsMfr.executeMfr(mfr, userInput, mService, true);
                } catch (EmptyStaticFlowException ex) {
                    completeTransmit(null);
                    AlertDialog.Builder builder = new AlertDialog.Builder(ServiceMessageDetailActivity.this);
                    builder.setMessage(ex.getMessage());
                    builder.setPositiveButton(R.string.rogerthat, null);
                    AlertDialog dialog = builder.create();
                    dialog.show();
                    return;
                }
            }

        });

        UIUtils.showHint(this, mService, HINT_BROADCAST, R.string.hint_broadcast,
                mCurrentMessage.broadcast_type, mFriendsPlugin.getName(mCurrentMessage.sender));

        broadcastSpamControlText
                .setText(getString(R.string.broadcast_subscribed_to, mCurrentMessage.broadcast_type));
        broadcastSpamControlSettingsText.setText(fbi.label);
        int ligthAlpha = 180;
        int darkAlpha = 70;
        int alpha = ligthAlpha;
        if (br != null && br.scheme == ColorScheme.dark) {
            broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.black));
            broadcastSpamControlBorder.setBackgroundColor(darkSchemeTextColor);
            broadcastSpamControlDivider.setBackgroundColor(darkSchemeTextColor);
            activity.setBackgroundColor(darkSchemeTextColor);
            broadcastSpamControlText.setTextColor(lightSchemeTextColor);
            broadcastSpamControlSettingsText.setTextColor(lightSchemeTextColor);
            int alpacolor = Color.argb(darkAlpha, Color.red(lightSchemeTextColor),
                    Color.green(lightSchemeTextColor), Color.blue(lightSchemeTextColor));
            broadcastSpamControl.setBackgroundColor(alpacolor);

            alpha = darkAlpha;
        } else {
            broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.white));
            broadcastSpamControlBorder.setBackgroundColor(lightSchemeTextColor);
            broadcastSpamControlDivider.setBackgroundColor(lightSchemeTextColor);
            activity.setBackgroundColor(lightSchemeTextColor);
            broadcastSpamControlText.setTextColor(darkSchemeTextColor);
            broadcastSpamControlSettingsText.setTextColor(darkSchemeTextColor);
            int alpacolor = Color.argb(darkAlpha, Color.red(darkSchemeTextColor),
                    Color.green(darkSchemeTextColor), Color.blue(darkSchemeTextColor));
            broadcastSpamControl.setBackgroundColor(alpacolor);
        }

        if (br != null && br.color != null) {
            int alphaColor = Color.argb(alpha, Color.red(br.color), Color.green(br.color),
                    Color.blue(br.color));
            broadcastSpamControl.setBackgroundColor(alphaColor);
        }

        mService.postOnUIHandler(new SafeRunnable() {

            @Override
            protected void safeRun() throws Exception {
                int maxHeight = broadcastSpamControl.getHeight();
                broadcastSpamControlDivider.getLayoutParams().height = maxHeight;
                broadcastSpamControlDivider.requestLayout();

                broadcastSpamControlSettingsContainer.getLayoutParams().height = maxHeight;
                broadcastSpamControlSettingsContainer.requestLayout();

                broadcastSpamControlTextContainer.getLayoutParams().height = maxHeight;
                broadcastSpamControlTextContainer.requestLayout();

                int broadcastSpamControlWidth = broadcastSpamControl.getWidth();
                android.view.ViewGroup.LayoutParams lp = broadcastSpamControlSettingsContainer
                        .getLayoutParams();
                lp.width = broadcastSpamControlWidth / 4;
                broadcastSpamControlSettingsContainer.setLayoutParams(lp);
            }
        });
    }

    if (!isUpdate)
        collapseDetails(DETAIL_SECTIONS);
}

From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java

private int convertColorOfPostion(float position, int color0, int color1) {
    int a0 = Color.alpha(color0);
    int r0 = Color.red(color0);
    int g0 = Color.green(color0);
    int b0 = Color.blue(color0);

    int a1 = Color.alpha(color1);
    int r1 = Color.red(color1);
    int g1 = Color.green(color1);
    int b1 = Color.blue(color1);
    int a = (int) (a0 + (a1 - a0) * position);
    int r = (int) (r0 + (r1 - r0) * position);
    int g = (int) (g0 + (g1 - g0) * position);
    int b = (int) (b0 + (b1 - b0) * position);
    return Color.argb(a, r, g, b);
}

From source file:com.skytree.epubtest.BookViewActivity.java

public int getColorWithAlpha(int color, int alpha) {
    int red, green, blue;
    red = Color.red(color);//  w w  w. j  a  v a2s.c om
    green = Color.green(color);
    blue = Color.blue(color);
    int newColor = Color.argb(alpha, red, green, blue);
    return newColor;
}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap bright(Bitmap bmImage, int brightness) {
    Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig());

    for (int i = 0; i < bmImage.getWidth(); i++) {
        for (int j = 0; j < bmImage.getHeight(); j++) {
            int p = bmImage.getPixel(i, j);
            int r = Color.red(p);
            int g = Color.green(p);
            int b = Color.blue(p);
            int alpha = Color.alpha(p);

            r += brightness;//  w  w w . j  a  va  2s . c o m
            g += brightness;
            b += brightness;
            alpha += brightness;
            r = r < 0 ? 0 : (r > 255 ? 255 : r);
            g = g < 0 ? 0 : (g > 255 ? 255 : g);
            b = b < 0 ? 0 : (b > 255 ? 255 : b);
            alpha = alpha < 0 ? 0 : (alpha > 255 ? 255 : alpha);

            bmTemp.setPixel(i, j, Color.argb(alpha, r, g, b));
        }
    }

    return bmTemp;
}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap tint(Bitmap bmImage, int degree) {
    Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig());

    double angle = (3.14159d * (double) degree) / 180.0d;
    int S = (int) (256.0d * Math.sin(angle));
    int C = (int) (256.0d * Math.cos(angle));

    for (int i = 0; i < bmImage.getWidth(); i++) {
        for (int j = 0; j < bmImage.getHeight(); j++) {
            int p = bmImage.getPixel(i, j);
            int r = Color.red(p);
            int g = Color.green(p);
            int b = Color.blue(p);
            // int alpha = Color.alpha(p);

            int RY = (70 * r - 59 * g - 11 * b) / 100;
            int BY = (-30 * r - 59 * g + 89 * b) / 100;
            int Y = (30 * r + 59 * g + 11 * b) / 100;
            int RYY = (S * BY + C * RY) / 256;
            int BYY = (C * BY - S * RY) / 256;
            int GYY = (-51 * RYY - 19 * BYY) / 100;
            r = Y + RYY;/*  www  .jav  a  2  s.  co m*/
            r = (r < 0) ? 0 : ((r > 255) ? 255 : r);
            g = Y + GYY;
            g = (g < 0) ? 0 : ((g > 255) ? 255 : g);
            b = Y + BYY;
            b = (b < 0) ? 0 : ((b > 255) ? 255 : b);
            bmTemp.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
        }
    }

    return bmTemp;
}

From source file:de.madvertise.android.sdk.MadvertiseView.java

/**
 * Draw the ad background for a text banner
 *
 * @param canvas//from w  w  w .  j a va  2  s .  com
 * @param rectangle
 * @param backgroundColor
 * @param mTextColor
 */
private void drawTextBannerBackground(final Canvas canvas, final Rect rectangle, final int backgroundColor,
        int shineColor) {
    Paint paint = new Paint();
    paint.setColor(backgroundColor);
    paint.setAntiAlias(true);
    canvas.drawRect(rectangle, paint);

    int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor),
            Color.blue(shineColor));
    int[] gradientColors = { upperColor, shineColor };
    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            gradientColors);

    int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top;
    gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop);
    gradientDrawable.draw(canvas);

    Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom);
    Paint shadowPaint = new Paint();
    shadowPaint.setColor(shineColor);
    canvas.drawRect(shadowRect, shadowPaint);
}