Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 791
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

change bitmapfield on another

[ Edited ]
op = new BitmapField(getOverlappedBitmap(mMapBitmap, mIconBitmap),Field.FIELD_HCENTER
		         	                    | Field.FIELD_VCENTER | Field.FOCUSABLE)
		         	                    {
		         	   					int i = 1;
		         	   					
				         	           	 protected boolean navigationClick(int status, int time) 
				         	                { 	
				         	           		
				         	           		 	if(i == 1)
				         	           		 	{
				         	           		 		i = 2;
				         	           		 		
				         	           		 		if(GlobalValue.getX1() != null) 
{ GlobalValue.getX1().setBitmap(GlobalValue.getY());
 }
 GlobalValue.setX1(op); GlobalValue.setY(getOverlappedBitmap(mMapBitmap, mIconBitmap)); Bitmap m = getOverlappedBitmap(mMapBitmap, mIconBitmap2); setBitmap(m); GlobalValue.setX(m);
} else { i = 1; setBitmap(getOverlappedBitmap(mMapBitmap, mIconBitmap)); } return true; } };

 

 

  op2 = new BitmapField(getOverlappedBitmap(mMapBitmap, mIconBitmap),Field.FIELD_HCENTER
	         	                    | Field.FIELD_VCENTER | Field.FOCUSABLE)
	         	                    {
	         	   					int i = 1;
			         	           	 protected boolean navigationClick(int status, int time) 
			         	                { 	
			         	           		
			         	           		 	if(i == 1)
			         	           		 	{
			         	           		 		i = 2;
			         	           		 		
			         	           		 	if(GlobalValue.getX1() != null) { GlobalValue.getX1().setBitmap(GlobalValue.getY()); } GlobalValue.setX1(op2); GlobalValue.setY(getOverlappedBitmap(mMapBitmap, mIconBitmap)); Bitmap m = getOverlappedBitmap(mMapBitmap, mIconBitmap2); setBitmap(m); GlobalValue.setX(m);

			         	           		 	}
			         	           		 	else
			         	           		 	{
			         	           		 		i = 1;
			         	           		 		setBitmap(getOverlappedBitmap(mMapBitmap, mIconBitmap));
			         	           		 	}
				         	           		 
				         	           		
				         	                  return true;
				         	             }
			         	           	
	         	                    };

 

public static Bitmap x;
	public static Bitmap y;
	public static BitmapField x1;

	public static BitmapField getX1() {
		return x1;
	}

	public static void setX1(BitmapField x1) {
		GlobalValue.x1 = x1;
	}

	public static Bitmap getX() {
		return x;
	}

	public static void setX(Bitmap x) {
		GlobalValue.x = x;
	}

	public static Bitmap getY() {
		return y;
	}

	public static void setY(Bitmap y) {
		GlobalValue.y = y;
	}

	public static Vector getRecentAlbums() {
		return recentAlbums;
	}

 

 

 

 

As u see in bolded part when bitmap is clicked, i save it in globalvalue. when the next bitmapfield is clicked, i first revert the one clicked before..and store new one in globalvalue.

but its not working... it doesnt revert old one...

 

whats wrong? how do i update bitmapfield?

Developer
Posts: 16,643
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: change bitmapfield on another

why do you have public static fields and then write a setter and getter for them?

if you post code, could you remove the sections commented out? it makes it hard to read.

where is the bitmap field you are manipulating?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 791
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: change bitmapfield on another

Here is how am maniuplating things.

 

I have two bitmapfield, op and op2.

on cnavigationclick of op or op2  i do this

 

lets take example this is op...

 

if(GlobalValue.getX1() != null)
                                                     
                                                         {
                                                         

                                                             //mainpulate picture of op2 i if it was previously clicked, first time its null so doesnt enter here
                                                             GlobalValue.getX1().setBitmap(GlobalValue.getY());
                                                             
                                                         }
                                                         //since clicked  save the clicked one (op in this case) globally... so that next time

it enters the above if and maniuplates picture
                                                   GlobalValue.setX1(op);    

                                                        //save the bitmap its being modified into  in globalvalue x, and previous picture in y.once op2 is clicked, in it  GlobalValue.getX1().setBitmap(GlobalValue.getY()); will change the picture back to its old one
                                                         GlobalValue.setY(getOverlappedBitmap(mMapBitmap, mIconBitmap));
                                                         Bitmap m = getOverlappedBitmap(mMapBitmap, mIconBitmap2);
                                                         setBitmap(m);
                                                         GlobalValue.setX(m);

Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: change bitmapfield on another

I'm still confused.

 

How about you explain, in words, what you are trying to do and why.  For example, why do you need to save the old value.  Why does it have to be global (is it tested by other parts of your processing for example).  Where are these bitmaps coming from? 

 

Then we can suggest an approach to doing what you need to do. 

 

This will save us having to decipher your code and means we can suggest the best solution rather than just trying to rework your current code which might not be appropriate for your real requirements anyway.

 

Just a thought..

Developer
Posts: 791
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: change bitmapfield on another

Okey.

 

Lets assume I  have a list , in those lists there is play button. When it clicks play button, I will replace it with pause button.

Now in the list, lets say he clicks first row...the pause buttong appears there. Now when he clicks play on row 5 button, I want to appear pause button on row 5...and move row 1 button back to play.

 

What am trying to do and failing, is move back row 1 button back to play.This is why am trying to store row 1 in globalvalue ( its old and new value)...

Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: change bitmapfield on another

[ Edited ]

OK, let us look at the logic here a bit.  In my opinion, you are putting logic into your Bitmap that I don't think should be there.

 

For me, your bitmap has two states

a) playing - in which case it needs to display one image (the Pause image) and

b) stopped, in which case it displays the 'Play' image. 

So what your BitmapField needs to do is be told whether it is playing or not (add a setPlaying(boolean) method perhaps), and display the appropriate image.  Initially it will be in the stopped state. 

 

It also needs to be a Button, but there are numerous posts and examples of using a BitmapField as a Button so we don't need to discuss that. 

 

And then you will have a single change Listener that will listen to all the Bitmaps.  This Listener will remember the last clicked Bitmap (if any).  When another Bitmap is clicked, the Listener will turn the original BitmapField (if any) state to stopped (which the Birtmap will interpret as meaning it must display the Play image), turn the new BitmapField's state to playing (which the Bitmap will interpret as meaning it must display the Pause image) and then organize the playing. 

 

So nothing global, or static or funny required here.  Just implement the standard facilities with a simpler design and job done.  At least I think so.  Do you agree?

Developer
Posts: 791
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: change bitmapfield on another

how can i do a single change lsitener to listen to all biutmapfiel together?
and how on click can i change inform of last clicked bitmapfield.
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: change bitmapfield on another

1) "how can i do a single change listener to listen to all biutmapfiel together?"

 

Very quick sample code.  Not demonstrating best practice, just demonstrating a single Change Listener.  Please do not cut and paste this code and expect it to work.  It is just demonstrating the principle and I have not had time to create a real working example.  Anyway I figure you can pick out the key messages from this code and implement it yourself. 

 

// -- Sample Listener code

 

class MyFieldChangeListener extends Object implements FieldChangeListener {

 

BitmapField lastBitmapClicked = null;

 

public MyFieldChangeListener() {

}

 

public void fieldChanged(Field f, int context) {

if ( f instanceof BitmapField ) {

if f != lastBitmapClicked ) {

if ( lastBitmapClicked != null ) {

// set Bitmap to Play

}

lastBitmapClicked = (BitmapField) f;

// set the Bitmap f to Pause

} else {

// same, so must be pausing the current button

// set lastBitmapClicked to Play

}

}

 

// ----- Sample using code

 

BitmapField bmf = new BitmapField(...);

MyFieldChangeListener myfcl = new MyFieldChangeListener ();

bfm.setChangeListener(myfcl);

BitmapField bmf2 = new BitmapField(...);

bfm2.setChangeListener(myfcl);

 

// ------

 

2) " how on click can i change inform of last clicked bitmapfield. "

 

I think the code sample explains that.