728x90

콘솔 앱은 UI 전환없이 UI내에서 아이콘 배치를 효율적으로 해야 이용하는데 불편함이 적다.

화면 전환없이 정보를 보여주는 것을 처리하기 위해서 팝업 메뉴를 사용하고, 도움말 기능은 팝업 메뉴로는 해결할 수가 없어서 팝업 윈도우 기능을 이용하여 구현했다.


팝업 윈도우 기능은 활용하기에 따라 유용한 점이 많을 거 같다.

기본적으로 PopupWindow 자체적으로 show(), dismiss(), setFocusable() 등의 메서드를 제공해 준다.


popup_window.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ffffff">

    <WebView
        android:id="@+id/popupwebView"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:background="#eee9e9" />

    <ImageButton
        android:id="@+id/btn_close"
        android:layout_width="31dp"
        android:layout_height="31dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="15dp"
        android:layout_gravity="right"
        android:background="@android:color/transparent"
        android:src="@drawable/btn_close" />

</LinearLayout>


버튼을 클릭하면 팝업창이 뜨는 구조이므로 View view 에서 동작한다.

HTML 파일을 bootstrap 기반으로 만들었고, 이걸 가장 잘 보여줄 수 있는 것은 WebView 라서 WebView 기능의 일부를 구현하여 팝업창이 구현되도록 했다.

URL 만 변경하면 다른 내용도 보여줄 수 있도록 함수화를 했다.

팝업창 외부 터치시 팝업창이 사리지도록 옵션을 설정했다.


case R.id.btnHelp:
   // 설정방법 설명
   mPopupWindowShow(view,Value.IPADDRESS + "/help.html");
   break;


public void mPopupWindowShow(View view, String url) {
    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    //int width = LinearLayout.LayoutParams.MATCH_PARENT; // 100% 너비를 사용할 때
    int width = (int) (display.getWidth() * 0.9); //Display 사이즈의 90%
    int height = LinearLayout.LayoutParams.WRAP_CONTENT;
    // LayoutParams WRAP_CONTENT를 주면 inflate된 View의 사이즈 만큼의 PopupWinidow를 생성한다.

    // inflate the layout of the popup window
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.popup_window,null);
    mPopupView = layout.findViewById(R.id.linear_layout);

    WebView webView = (WebView) layout.findViewById(R.id.popupwebView);
    ImageButton btn_close = layout.findViewById(R.id.btn_close);

    // create the popup window
    boolean focusable = true; // lets taps outside the popup also dismiss it
    final PopupWindow popupWindow = new PopupWindow(mPopupView, width, height, focusable);

    WebSettings webSettings = webView.getSettings();
    webSettings.setDefaultFontSize(9);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.loadUrl(url);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

    popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0); // Parent View 로부터의 위치


    btn_close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popupWindow.dismiss();
        }
    });
}


 mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
 Display display = mWindowManager.getDefaultDisplay();

 Point point = new Point();
 display.getSize(point);
 int width = (int) (point.x * 0.9); // Display 사이즈의 90%
 //int width = LinearLayout.LayoutParams.MATCH_PARENT;
 //int height = (int) (point.y * 0.8);
 int height = LinearLayout.LayoutParams.WRAP_CONTENT;
      

'안드로이드 > Android Serial 통신' 카테고리의 다른 글

Geateway 파싱 처리  (0) 2020.05.23
AlertDialog EditText  (0) 2019.06.26
android handler 를 이용한 지연처리  (0) 2019.05.09
Serial Communication Key  (0) 2019.05.09
Spinner 기능을 이용한 세팅 코드 구현  (0) 2019.05.02
블로그 이미지

Link2Me

,