Ok. Here's some more information about my App.
I'm going to create a keyboard app. Or rather an App where you can
define your own keyboard. Therefore I have two Activities A and B.

Activity A:
Here I want to create a single key. This is currently realized by
configuring a button.
The buttons size can be customized with a progress bar. One for height
and one for width. Also some letters/text can be added.
Then, height, width and the text of the button is send via an Intent
to Activity B.

Activity B:
On Activity B the current Button gets its properties out of the Intent
and via Gesture you can set it somewhere on the screen.
Afterwards the button get saved in an Arraylist.
Everytime I call Activity B the Arraylist is read and the buttons
should be shown on their position as before defined.
So the screen should be filled with buttons until the keyboard is
ready.

Then I want to create the keyboard (but I have no idea how yet ;) )

But as mentioned before, after reading the Arraylist the buttons loose
their position.

And here's the whole code of Activity B:

package example.com.fpa;

import java.util.ArrayList;
import java.util.Iterator;

import android.app.Activity;
import android.content.Intent;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class keyboard_view extends Activity implements
OnGesturePerformedListener {

        protected Button key_button;
        protected GestureLibrary mLibrary;
//      protected keys other_keys;
        protected int position;
        public static ArrayList<Button> keyList = new ArrayList<Button>();
        public Iterator iter;
        public static RelativeLayout rel_layout;

        /**
         * @param args
         */
         public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                setContentView(R.layout.keyboard_view);


                final Intent intent = new Intent(this, fpa.class);

                rel_layout = new RelativeLayout(this);

                final Button back_button = (Button)
findViewById(R.id.back_button);
                final Button accept_button = (Button)
findViewById(R.id.accept_button);
                key_button = (Button) findViewById(R.id.key_button);

                mLibrary = GestureLibraries.fromRawResource(this,
R.raw.gestures);
                if (!mLibrary.load()) {
                    finish();
                }

                GestureOverlayView gestures = (GestureOverlayView)
findViewById(R.id.gestures);
                gestures.addOnGesturePerformedListener(this);

        
key_button.setHeight(getIntent().getExtras().getInt("height"));
                key_button.setWidth(getIntent().getExtras().getInt("width"));
        
key_button.setText(getIntent().getExtras().getCharSequence("letter"));



                back_button.setOnClickListener(new OnClickListener(){
                        public void onClick(View v){
                                //Perform action on clicks

                                        intent.putExtra("height", 
key_button.getHeight());
                                        intent.putExtra("width", 
key_button.getWidth());
                                        startActivity(intent);
                        }
                });

                accept_button.setOnClickListener(new OnClickListener(){
                        public void onClick(View v){
                                //Perform action on clicks
                                keyList.add(key_button);
                                        intent.putExtra("height", 
key_button.getHeight());
                                        intent.putExtra("width", 
key_button.getWidth());
                                        startActivity(intent);
                        }
                });


                if(keyList.isEmpty() == false){
                        for (iter = keyList.iterator(); iter.hasNext();){


                                Button k =  (Button) iter.next();
                                Button ok = new Button(this);

                                ok.setHeight(k.getHeight());
                                Log.i("Button K", "Höhe: " + k.getHeight());
                                Log.i("Button OK", "Höhe: " + ok.getHeight());

                                ok.setWidth(k.getWidth());
                                Log.i("Button K", "Weite: " + k.getWidth());
                                Log.i("Button OK", "Weite: " + ok.getWidth());
                                ok.setText(k.getText());
                                ok.layout(k.getLeft(), k.getTop(), k.getRight(),
k.getBottom());
                                Log.i("Button OK", "Links: " + ok.getLeft());
                                Log.i("Button OK", "Oben: " + ok.getTop());
                                Log.i("Button OK", "Rechts: " + ok.getRight());
                                Log.i("Button OK", "Unten: " + ok.getBottom());
                                ok.setVisibility(1);

                                rel_layout.removeView(ok);

                                rel_layout.addView(ok);
                        }

                }

         }//endOnCreate

         protected void onSaveInstanceState(Bundle outState) {
                  super.onSaveInstanceState(outState);
//              outState.putStringArrayList("LISTE", keyList); // adding a
string in bundle
//              Toast.makeText(this, "Activity state saved",
Toast.LENGTH_LONG).show();
            }



         public void onResume(){
                 super.onResume();

                 if(keyList.isEmpty() == true || keyList == null)
                        Toast.makeText(keyboard_view.this, "leer",
Toast.LENGTH_SHORT).show();
                else
                        Toast.makeText(keyboard_view.this, "voll",
Toast.LENGTH_SHORT).show();



         }
        @Override
        public void onGesturePerformed(GestureOverlayView overlay, Gesture
gesture) {
                // TODO Auto-generated method stub
                ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
                int width = key_button.getWidth();
                int display_width =
getWindowManager().getDefaultDisplay().getWidth();
                int start_width = display_width - width;

                int height = key_button.getHeight();
                int display_height =
getWindowManager().getDefaultDisplay().getHeight();
                int start_height = display_height - 130 - height;
//              position = key_button.getLocationInWindow(FOCUSED_STATE_SET);

                // We want at least one prediction
                if (predictions.size() > 0) {
                        Prediction prediction = predictions.get(0);
                        // We want at least some confidence in the result
                        if (prediction.name.equals("add_key_left")) {
                                key_button.layout(10, 10, 10 + width, 10 + 
height);
                                Toast.makeText(keyboard_view.this, 
"Ausrichtung: " +
key_button.getLeft() + "Rechts: " + key_button.getRight() + "Oben: " +
key_button.getTop() + "Unten: " + key_button.getBottom(),
Toast.LENGTH_SHORT).show();
                        }
                        if(prediction.name.equals("add_key_downleft")){
                                key_button.layout(10, start_height, 10 + width, 
start_height +
height);
                                Toast.makeText(keyboard_view.this, 
"Ausrichtung: " +
key_button.getLeft() + "Rechts: " + key_button.getRight() + "Oben: " +
key_button.getTop() + "Unten: " + key_button.getBottom(),
Toast.LENGTH_SHORT).show();

                        }

                        if(prediction.name.equals("add_key_right")){

                                key_button.layout(start_width, 10, start_width 
+ width , 10 +
height);
                                Toast.makeText(keyboard_view.this, 
"Ausrichtung: " +
key_button.getLeft() + "Rechts: " + key_button.getRight() + "Oben: " +
key_button.getTop() + "Unten: " + key_button.getBottom(),
Toast.LENGTH_SHORT).show();

                        }
                        if(prediction.name.equals("add_key_downright")){
                                key_button.layout(start_width, start_height, 
start_width + width,
start_height + height);
                                Toast.makeText(keyboard_view.this, 
"Ausrichtung: " +
key_button.getLeft() + "Rechts: " + key_button.getRight() + "Oben: " +
key_button.getTop() + "Unten: " + key_button.getBottom(),
Toast.LENGTH_SHORT).show();

                        }

                }
        }//endGesturePerformed

}//endClass

Hope this helps ^^"
Any kind of help is appreciated !


On 8 Feb., 20:25, Kritzli <[email protected]> wrote:
> > You cannot pass a Button via an Intent.
>
> You're right. I only pass the height, width and text of the button I
> customized in Activity A.
>
> > Activity B cannot modify the UI of Activity A. Activity B cannot safely
> > reuse the widgets of Activity A.
>
> I don't want to modify the UI of Activity A. Activity B has its own UI
> or rather Activity B's Ui is made of those buttons.  Therefore I want
> to move and show the buttons on Activity B.
>
> Maybe I schould post some more code for clarification ?
>
> On 8 Feb., 14:14, "Mark Murphy" <[email protected]> wrote:
>
> > > There are two Activities (Activity A and B). At Activity A I customize
> > > a button and pass it on Activity B via an intent.
>
> > You cannot pass a Button via an Intent.
>
> > > On Activity B I move
> > > the button somewhere on the screen.
>
> > Activity B cannot modify the UI of Activity A. Activity B cannot safely
> > reuse the widgets of Activity A.
>
> > > Any suggestion and hints how this could be solved would be
> > > appreciated !
>
> > Give Activity B its own widgets, independent of those from Activity A,
> > positioned where they are supposed to be from the outset.
>
> > --
> > Mark Murphy (a Commons Guy)http://commonsware.com
> > Android App Developer Books:http://commonsware.com/books.html

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en

Reply via email to