package
arabiannight.tistory.com.popupwindow;
import
android.app.Activity;
import
android.graphics.Matrix;
import
android.graphics.PointF;
import
android.os.Bundle;
import
android.view.MotionEvent;
import
android.view.View;
import
android.view.View.OnTouchListener;
import
android.view.WindowManager.LayoutParams;
import
android.widget.Button;
import
android.widget.ImageView;
import
android.widget.PopupWindow;
import
android.widget.Toast;
public
class
MainActivity
extends
Activity {
private
PopupWindow mPopupWindow;
private
Button btn_Popup;
int
offset_x =
50
;
int
offset_y =
50
;
int
filstY =
0
;
int
filstX =
0
;
int
imgX, imgY;
int
lastX, lastY;
int
thisX, thisY;
int
deltaX, deltaY;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_Popup = (Button) findViewById(R.id.btn_click);
}
public
void
onClick(View v) {
switch
(v.getId()) {
case
R.id.btn_click:
final
View popupView = getLayoutInflater().inflate(
R.layout.popup_window,
null
);
mPopupWindow =
new
PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mPopupWindow.setAnimationStyle(-
1
);
mPopupWindow.showAsDropDown(btn_Popup, offset_x, offset_y);
popupView.setOnTouchListener(
new
OnTouchListener() {
public
boolean
onTouch(View v, MotionEvent event) {
int
eventX = (
int
) event.getX();
int
eventY = (
int
) event.getY();
int
X = (
int
) event.getX();
int
Y = (
int
) event.getY();
int
eventaction = event.getAction();
switch
(eventaction) {
case
MotionEvent.ACTION_UP:
break
;
case
MotionEvent.ACTION_MOVE:
thisX = eventX;
thisY = eventY;
deltaX = thisX - lastX;
deltaY = thisY - lastY;
imgX += deltaX;
imgY += deltaY;
lastX = thisX;
lastY = thisY;
break
;
case
MotionEvent.ACTION_DOWN:
lastX = eventX;
lastY = eventY;
filstX = X;
filstY = Y;
break
;
}
mPopupWindow.update(btn_Popup, imgX, imgY,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
return
true
;
}
});
break
;
case
R.id.btn_close:
if
(mPopupWindow !=
null
&& mPopupWindow.isShowing()) {
mPopupWindow.dismiss();
}
break
;
case
R.id.btn_bottom:
Toast.makeText(MainActivity.
this
,
"Bottom UI 입니다."
,
Toast.LENGTH_SHORT).show();
break
;
default
:
break
;
}
}
}