You could either set these drawables as the background drawables of
your views or create a custom view, similar to the one you already
have, to draw them in onDraw(). All you need to do is set their bounds
and then call myDrawable.draw(theCanvas).

On Thu, Jul 23, 2009 at 2:37 PM,
Erin<[email protected]> wrote:
>
> Ah - that would probably be a problem. I've added them originally to
> the main xml but I now see where that could be a problem. Do you have
> a suggestion on what the best way to add the drawables/drawing
> functionality - from what I can gather I should use a canvas, but how
> do I go about doing that?
>
> Thanks and sorry for the stupid/very basic questions.
>
> On Jul 23, 2:30 pm, Romain Guy <[email protected]> wrote:
>> Yes you do change their alpha but I don't see these drawables attached
>> to any view or even being drawn manually.
>>
>> On Thu, Jul 23, 2009 at 2:27 PM,
>>
>> Erin<[email protected]> wrote:
>>
>> > Supposedly I setAlpha of both of them to Transparent in my OnCreate
>> > menu after setting up the button clicks. The transparency is also
>> > supposed to change during the OnSeekBarChanged-->OnProgressChanged
>> > method.
>>
>> > On Jul 23, 2:18 pm, Romain Guy <[email protected]> wrote:
>> >> I don't see you do anything with rect1 and rect2??
>>
>> >> On Thu, Jul 23, 2009 at 2:14 PM,
>>
>> >> Erin<[email protected]> wrote:
>>
>> >> > Thanks for the speedy reply.
>>
>> >> > I copied all my code into a new project with the 1.5 SDK but, while
>> >> > I'm not getting any code errors, the rectangles don't change
>> >> > transparency. I've thrown in a bunch of log statements to prove that
>> >> > the code is actually getting to the setAlpha commands but when I run
>> >> > it in the emulator it just shows the rectangles as constantly opaque.
>>
>> >> > Any thoughts?
>>
>> >> > On Jul 23, 11:55 am, Romain Guy <[email protected]> wrote:
>> >> >> mutate() is available only in Android 1.5, it seems like you are
>> >> >> developing with an older SDK.
>>
>> >> >> On Thu, Jul 23, 2009 at 11:11 AM,
>>
>> >> >> Erin<[email protected]> wrote:
>>
>> >> >> > Hi,
>> >> >> > I'm sorry if I've missed something obvious but here goes.
>>
>> >> >> > I'm currently trying to make an android app where when one moves a
>> >> >> > seekbar past a certain value a blue rectangle goes from transparent 
>> >> >> > to
>> >> >> > opaque. This rectangle/value pairing will be repeated for roughly 10
>> >> >> > values in the seekbar. (Picture the AT&T bars being controlled by a
>> >> >> > seekbar). I understand that when I try to change the alpha of my
>> >> >> > rectangles (created from a resource in my drawable folder) I'm
>> >> >> > changing both of them at the same time. I also understand the 
>> >> >> > solution
>> >> >> > to this is by calling mutate on my rectangles. What I'm having 
>> >> >> > trouble
>> >> >> > with is actually accomplishing this.
>>
>> >> >> > The error I get is: The method mutate() is undefined for the type
>> >> >> > Drawable (lines 59 and 61).
>>
>> >> >> > I've tried changing my rectangles to ImageView and to ShapeDrawable.
>> >> >> > I've also tried modeling it off of the following from one of the
>> >> >> > previous posts but that didn't work either.
>> >> >> > Drawable star = context.getResources().getDrawable(R.drawable.star);
>> >> >> >            if (book.isFavorite()) {
>> >> >> >              star.mutate().setAlpha(255); // opaque
>> >> >> >            } else {
>> >> >> >              star.mutate().setAlpha(70); // translucent
>>
>> >> >> > Any help would be very, very appreciated.
>> >> >> > Thanks,
>> >> >> > Erin
>>
>> >> >> > Below is all of my code:
>>
>> >> >> > package com.artificialmuscle.controllers;
>>
>> >> >> > import android.app.Activity;
>> >> >> > import android.app.AlertDialog;
>> >> >> > import android.content.Context;
>> >> >> > import android.content.DialogInterface;
>> >> >> > import android.graphics.Canvas;
>> >> >> > import android.graphics.drawable.Drawable;
>> >> >> > import android.graphics.drawable.ShapeDrawable;
>> >> >> > import android.graphics.drawable.shapes.RectShape;
>> >> >> > import android.media.MediaPlayer;
>> >> >> > import android.os.Bundle;
>> >> >> > import android.util.AttributeSet;
>> >> >> > import android.util.Log;
>> >> >> > import android.view.View;
>> >> >> > import android.view.View.OnClickListener;
>> >> >> > import android.widget.Button;
>> >> >> > import android.widget.SeekBar;
>> >> >> > import android.widget.SeekBar.OnSeekBarChangeListener;
>>
>> >> >> > public class Controllers extends Activity {
>> >> >> >    /** Called when the activity is first created. */
>>
>> >> >> >        private final int OPAQUE = 255;
>> >> >> >        private final int TRANSPARENT = 75;
>>
>> >> >> >        private MediaPlayer mp = null;
>> >> >> >        Drawable rect1 = null;
>> >> >> >        Drawable rect2 = null;
>>
>> >> >> >   �...@override
>> >> >> >    public void onCreate(Bundle savedInstanceState) {
>> >> >> >        super.onCreate(savedInstanceState);
>> >> >> >        setContentView(R.layout.main);
>>
>> >> >> >        Button button1 = (Button)findViewById(R.id.button1);
>> >> >> >        Button button2 = (Button)findViewById(R.id.button2);
>> >> >> >        Button button3 = (Button)findViewById(R.id.button3);
>>
>> >> >> >        button1.setOnClickListener(new OnClickListener(){
>> >> >> >                public void onClick(View 
>> >> >> > viewParam){createDialogs(1);}});
>> >> >> >        button2.setOnClickListener(new OnClickListener(){
>> >> >> >                public void onClick(View 
>> >> >> > viewParam){createDialogs(2);}});
>> >> >> >                button3.setOnClickListener(new OnClickListener(){
>> >> >> >                        public void onClick(View 
>> >> >> > viewParam){createDialogs(3);}});
>>
>> >> >> >                rect1 = (ShapeDrawable)this.getResources().getDrawable
>> >> >> > (R.drawable.bluerect);
>> >> >> >                rect2 = this.getResources().getDrawable(R.id.rect2);
>>
>> >> >> >                // Ignore the different syntax I was only trying
>> >> >> > options
>> >> >> >                rect1.mutate();
>> >> >> >                rect1.setAlpha(TRANSPARENT);
>> >> >> >                rect2.mutate().setAlpha(TRANSPARENT);
>>
>> >> >> >            SeekBar mySeekBar = (SeekBar)findViewById(R.id.mySeekBar);
>> >> >> >            mySeekBar.setMax(100);
>>
>> >> >> >            OnSeekBarChangeListener myListener = new 
>> >> >> > OnSeekBarChangeListener()
>> >> >> > {
>>
>> >> >> >                public void onProgressChanged(SeekBar arg0, int arg1, 
>> >> >> > boolean
>> >> >> > arg2) {
>> >> >> >                                // TODO Auto-generated method stub
>>
>> >> >> >                                Log.i("seekbar","seekbar value 
>> >> >> > changed to "+arg1);
>>
>> >> >> >                                // play sounds on 10, 20.. 90
>> >> >> >                                if (arg1%10 == 0) {
>> >> >> >                                        if (mp != null) {
>> >> >> >                                                mp.stop();
>> >> >> >                                                mp.release();
>> >> >> >                                        }
>> >> >> >                                        mp = 
>> >> >> > MediaPlayer.create(Controllers.this, R.raw.sine25hz20ms);
>> >> >> >                                        mp.start();
>> >> >> >                                }
>>
>> >> >> >                                //if (arg1 == 10)Log.i("rectangle","I 
>> >> >> > am at 10!!!");
>>
>> >> >> >                                if (arg1 >= 10) 
>> >> >> > {rect1.setAlpha(OPAQUE);}// Log.i("rectangle","set
>> >> >> > rect 1");}
>> >> >> >                                else rect1.setAlpha(TRANSPARENT);
>>
>> >> >> >                                if (arg1 >= 20) 
>> >> >> > {rect2.setAlpha(OPAQUE);}//Log.i("rectangle","set
>> >> >> > rect 2");}
>> >> >> >                                else rect2.setAlpha(TRANSPARENT);
>> >> >> >                        }
>>
>> >> >> >                        public void onStartTrackingTouch(SeekBar 
>> >> >> > seekBar) {
>> >> >> >                                // TODO Auto-generated method stub
>>
>> >> >> >                        }
>>
>> >> >> >                        public void onStopTrackingTouch(SeekBar 
>> >> >> > seekBar) {
>> >> >> >                                // TODO Auto-generated method stub
>>
>> >> >> >                        }};
>>
>> >> >> >            mySeekBar.setOnSeekBarChangeListener(myListener);
>>
>> >> >> >    }
>>
>> >> >> >    public void createDialogs(int dialogID){
>> >> >> >        AlertDialog.Builder builder = new AlertDialog.Builder
>> >> >> > (Controllers.this);
>>
>> >> >> >        //if (dialogID == 1)
>> >> >> >        switch (dialogID)
>> >> >> >        {
>> >> >> >        case 1: builder.setMessage("You clicked Button"+dialogID)
>> >> >> >                           .setNeutralButton("DUH", new 
>> >> >> > DialogInterface.OnClickListener
>> >> >> > () {
>> >> >> >                                        public void 
>> >> >> > onClick(DialogInterface dialog, int id) {
>> >> >> >                                dialog.cancel();
>> >> >> >                           }// onClick
>> >> >> >                                })
>> >> >> >                           .show();
>> >> >> >                        break;
>> >> >> >        case 2:
>> >> >> >                builder.setMessage("You clicked me, I am 
>> >> >> > Button"+dialogID)
>> >> >> >                           .setNeutralButton("DUH", new 
>> >> >> > DialogInterface.OnClickListener() {
>> >> >> >                                public void onClick(DialogInterface 
>> >> >> > dialog, int id) {
>> >> >> >                        dialog.cancel();
>> >> >> >                   }// onClick
>> >> >> >                                })
>> >> >> >                           .show();
>> >> >> >                        break;
>> >> >> >        case 3:
>> >> >> >                builder.setMessage("You clicked me")
>> >> >> >                           .setNeutralButton("DUH", new 
>> >> >> > DialogInterface.OnClickListener() {
>> >> >> >                                public void onClick(DialogInterface 
>> >> >> > dialog, int id) {
>> >> >> >                        dialog.cancel();
>> >> >> >                   }// onClick
>> >> >> >
>>
>> ...
>>
>> read more »
> >
>



-- 
Romain Guy
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to