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 > }) > .show(); > break; > default: > builder.setMessage("I have no idea what you clicked") > .setNeutralButton("Shit", new > DialogInterface.OnClickListener() > { > public void onClick(DialogInterface dialog, > int id) { > dialog.cancel(); > }// onClick > }) > .show(); > break; > } // end of switch > } > > private class CustomDrawableView extends View { > private ShapeDrawable mDrawable; > > public CustomDrawableView(Context context, AttributeSet attrs) > { > super(context, attrs); > > int x = 10; > int y = 10; > int width = 300; > int height = 50; > > mDrawable = new ShapeDrawable(new RectShape()); > mDrawable.getPaint().setColor(0xff74AC23); > mDrawable.setBounds(x, y, x + width, y + height); > } > > protected void onDraw(Canvas canvas) { > mDrawable.draw(canvas); > } > } > > } > > And heres the XML: > <?xml version="1.0" encoding="utf-8"?> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ > android" > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > > > > <TextView android:id="@+id/txt" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:text="@string/intro"/> > > > > > <Button android:id="@+id/button1" > android:layout_width="90.0px" > android:layout_height="50.0px" > android:text="Effect 1" > android:layout_alignParentLeft="true" > android:layout_marginLeft="15.0px" > android:layout_marginTop="75.0px" > /> > > <Button android:id="@+id/button2" > android:layout_width="90.0px" > android:layout_height="50.0px" > android:text="Effect 2" > android:layout_marginLeft="115.0px" > android:layout_marginTop="75.0px" > /> > > <Button android:id="@+id/button3" > android:layout_width="90.0px" > android:layout_height="50.0px" > android:text="Effect 3" > android:layout_alignParentRight="true" > android:layout_marginRight="15.0px" > android:layout_marginTop="75.0px" > /> > > <SeekBar android:id="@+id/mySeekBar" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:layout_marginTop="350.0px" > /> > > <ImageView android:id="@+id/rect1" > android:layout_width="30.0px" > android:layout_height="50.0px" > android:src="@drawable/bluerect" > android:layout_marginTop="275.0px" > android:layout_marginLeft="15.0px" > /> > > <ImageView android:id="@+id/rect2" > android:layout_width="30.0px" > android:layout_height="60.0px" > android:src="@drawable/bluerect" > android:layout_marginTop="265.0px" > android:layout_marginLeft="50.0px" > /> > > > > > </RelativeLayout> > > > > > > -- 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 -~----------~----~----~----~------~----~------~--~---

