yoga1290

yoga1290 / Android QuickAction

Apr 8th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. //[email protected] Saturday, April 09 2011 01:32 AM
  2. import android.graphics.*;
  3. import android.graphics.drawable.BitmapDrawable;
  4. import android.graphics.drawable.Drawable;
  5. import android.app.Activity;
  6. import android.content.*;
  7. import android.os.Bundle;
  8. import android.view.*;
  9. import android.view.View.*;
  10. import android.widget.*;
  11.  
  12. public class yoga1290 extends Activity implements OnClickListener {
  13.     public Button b;
  14.     public void onCreate(Bundle savedInstanceState)
  15.     {
  16.         super.onCreate(savedInstanceState);
  17.         LinearLayout    fr=new LinearLayout(this);
  18.                         fr.setOrientation(LinearLayout.VERTICAL);
  19.         b=new Button(this);
  20.         b.setText("Click Me!");
  21.         b.setOnClickListener(this);
  22.         fr.addView(b);
  23.         setContentView(fr);
  24.     }
  25.     @Override
  26.     public void onClick(View v) {
  27.         b.setText("Click to hide/show!");
  28.         TextView    tv = new TextView(this);
  29.                     tv.setText("This is a Popup :)");
  30.         new yg(tv,b,200,200);
  31.     }
  32. }
  33.  
  34. class yg extends PopupWindow
  35. {
  36.     public yg(View v,View mv,int w,int h)
  37.     {
  38.         super(v,w,h,true);
  39.         //TODO Better Background may be,cuz this is empty transparent background
  40.         setBackgroundDrawable(new BitmapDrawable());
  41.         setOutsideTouchable(true);
  42.         setTouchable(true);
  43.        
  44.         setTouchInterceptor(new OnTouchListener() {
  45.            
  46.             public boolean onTouch(View v, MotionEvent event) {
  47.                         if(event.getAction() == MotionEvent.ACTION_OUTSIDE) {
  48.                             setFocusable(false);
  49.                             dismiss();
  50.                             return true;
  51.                         }
  52.             //your code when touched on the event
  53.             return false;
  54.             }
  55.            
  56.             });
  57.        
  58.         int loc[]=new int[2];
  59.         mv.getLocationOnScreen(loc);
  60.         showAtLocation(mv,Gravity.NO_GRAVITY,   0,  loc[1]+ mv.getMeasuredHeight()  );
  61.     }
  62. }
Add Comment
Please, Sign In to add comment