popupwindow.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="300dp"
    android:gravity="center"
    android:background="#E1000000"
    android:padding="10px">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="주의"
        android:textStyle="bold"
        android:textSize="30sp"
        android:textColor="#ABF106"/>
    <TextView
        android:layout_margin="30px"
        android:id="@+id/popup_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:textStyle="bold"
        android:textSize="38sp"
        android:textColor="#FCFCFC"/>

    <Button
        android:id="@+id/closePopupBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="확인"
        />
</LinearLayout>

메인 엑티비티의 레이아웃 id도 필요합니다. 

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mainLayout"
    tools:context=".activity.MainActivity">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

mainLayout 이라고 심플하게 만들어 줬습니다.

 

mainActivity.java 

public void checkWebRoadEvent(String data0, String data1, String data2) {

        ConstraintLayout linearLayout1 = (ConstraintLayout) findViewById(R.id.mainLayout);
        LayoutInflater layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        final View customView = layoutInflater.inflate(R.layout.popupwindow, null);
        Button closeBtn = (Button) customView.findViewById(R.id.closePopupBtn);
        TextView textview = (TextView) customView.findViewById(R.id.popup_text);
        textview.setText(Messages[0] + "지도를 확인하세요.");
        popupWindow = new PopupWindow(customView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        final Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
        customView.startAnimation(animation);
        popupWindow.showAtLocation(linearLayout1, Gravity.TOP, 0, 0);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());


        final Handler handler = new Handler() {
            public void handleMessage(Message msg) {
                // 원래 하려던 동작 (UI변경 작업 등)
                final Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.close);
                customView.startAnimation(animation);

                Handler mhandler = new Handler();
                mhandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (popupWindow != null) {
                            popupWindow.dismiss();
                            popupWindow = null;
                        }
                    }
                }, 500);
            }
        };

        final Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                TimerTask task = new TimerTask() {
                    @Override
                    public void run() {
                        Message msg = handler.obtainMessage();
                        handler.sendMessage(msg);
                        Log.d("lati", "check ");
                    }
                };

                Timer timer = new Timer();
                timer.schedule(task, 5000);
            }
        });


        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Message msg = handler.obtainMessage();
                handler.sendMessage(msg);
                Log.d("lati", "check ");

            }
        });
        thread.start();
        startSound();
        
        Log.d("dialogStart", "get Show Road Event");
    }

timer , runable , thread  사용은 다른곳 참고 부탁드릴게요~ 저도 완벽한 개념을 알고 쓴게 아니라서 ㅎㅎ 저장용입니다.
popupwindow 에서 타이머 사용시 뷰를 변경할 수 없다는 오류가 뜨는데 핸들러를 통하여 한번 돌아서 사용하시면 될것 같습니다. 

 

사운드

알람은 raw 패키지 폴더 생성하고 거기에 넣으셔야합니다.

기본 알람도 사용할 수 있습니다. 따로 안적을게요~

    public void startSound() {
        MediaPlayer player = MediaPlayer.create(this, R.raw.alarm1);
        player.start();
    }

애니메이션

anum 패키지 폴더 생성후

오픈시에는 위에서 밑으로 내려오게끔 
클로즈는 오른쪽으로 없어지게 만들었습니다.

 

open.xml

<?xml version="1.0" encoding="utf-8"?>

<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="-100%"
    android:toYDelta="0">
</translate>

 

close.xml

<?xml version="1.0" encoding="utf-8"?>

<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="0"
    android:toXDelta="100%">
</translate>

 

 

+ Recent posts