게시판 답변

10 글 보임 - 21 에서 30 까지 (총 58 중에서)
  • 글쓴이
  • mimoon
    키 마스터

      안정적인 fragment 리스너

      
      private static final String FRAGMENT_TAG = "FRAGMENT_TAG";
          private static final String KEY_NUMBER = "KEY_NUMBER";
          private int mNumber = 0;
          private FragmentManager.OnBackStackChangedListener mListener = new FragmentManager.OnBackStackChangedListener() {
              @Override
              public void onBackStackChanged() {
                  FragmentManager fragmentManager = getSupportFragmentManager();
                  int count = 0;
                  for (Fragment f: fragmentManager.getFragments()) {
                      if (f != null) {
                          count++;
                      }
                  }
                  mNumber = count;
                  Log.d("MainActivity", "onBackStackChanged mNumber=" + mNumber);
              }
          };
      
      mimoon
      키 마스터

        // 2021-05-05까지 Fragment_Blank.xml 디폴트

        
        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".BlankFragment">
        
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:isScrollContainer="false">
            <!-- TODO: Update blank fragment layout -->
            <TextView
                android:id="@+id/text_blank"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:background="#ffffff"
                android:text="@string/hello_blank_fragment" />
            </ScrollView>
        
            <Button
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        
            <!--WebView
                android:id="@+id/blank_wvLayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                tools:ignore="MissingConstraints" /-->
        
        </FrameLayout>
        
        mimoon
        키 마스터

          //2021-05-05까지 activity_crawl_main의 디폴트

          
          <androidx.drawerlayout.widget.DrawerLayout 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"
              tools:openDrawer="start"
              tools:context=".CrawlActivity">
          
              <FrameLayout
                  android:id="@+id/fl_activity_main"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">
                  <WebView
                      android:id="@+id/crawl_wvLayout"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      tools:ignore="MissingConstraints" />
              </FrameLayout>
              <com.google.android.material.navigation.NavigationView
                  android:id="@+id/nav_view"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:layout_gravity="start"
                  android:fitsSystemWindows="true"
                  app:headerLayout="@layout/nav_header_main"
                  app:menu="@menu/activity_main_drawer" />
          
          </androidx.drawerlayout.widget.DrawerLayout>
          
          mimoon
          키 마스터

            프로그레스를 위한 코드

            
            private class HelloWebViewClient extends WebViewClient {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.setVisibility(View.GONE);
                        mProgressDialog.setTitle("Loading");
                        mProgressDialog.show();
                        mProgressDialog.setMessage("페이지 자료를 모아오는 중입니다");
                        return false;
                    }
            
                    @Override
                    public void onPageFinished(WebView view, String url) {
                        mProgressDialog.dismiss();
                        animate(view);
                        view.setVisibility(View.VISIBLE);
                        super.onPageFinished(view,url);
                    }
                }
            
                private void animate(final WebView view) {
                    Animation anim = AnimationUtils.loadAnimation(getBaseContext(),
                            android.R.anim.slide_in_left);
                    view.startAnimation(anim);
                }
            

            후미 웹뷰에 다음까지 달아주어야 완성

            
            webView.setWebViewClient(new HelloWebViewClient());
            
            mimoon
            키 마스터

              Activity Default는 스택이 쌓이지 않음. 그러므로 Layout에서도 history true 기본이 적용되지 않음.
              다음 코드를 넣어야 함

              
              @Override
                  public boolean onKeyDown(int keyCode, KeyEvent event) {
                      WebView view = (WebView) findViewById(R.id.crawl_wvLayout);
                      if ((keyCode == KeyEvent.KEYCODE_BACK) && view.canGoBack()) {
                          view.goBack();
                          return true;
                      }
                      return super.onKeyDown(keyCode, event);
                  }
              
              mimoon
              키 마스터

                activity_crawl_main의 디폴트
                activity_main과 manifest와의 상관 관계
                균형 깨지면 error

                
                <RelativeLayout 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"
                    tools:context=".CrawlActivity">
                
                    <FrameLayout
                        android:id="@+id/fl_activity_main"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    <WebView
                        android:id="@+id/crawl_wvLayout"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        tools:ignore="MissingConstraints" />
                    </FrameLayout>
                
                </RelativeLayout>
                
                mimoon
                키 마스터

                  이상적인 Jsoup

                  
                   // 2021-4-31 Jsoup through Thread
                      // 2021-04-30
                      // 2nd
                      // URL Address
                  
                      String url = "https://www.biblegateway.com/verse/en/exodus%203%3A16";
                      //String url = "https://mimoonchurch.net/myday.html";
                  
                      Title AsyncTask;
                      // 2021-04-30
                      //@Override
                      private class Title extends android.os.AsyncTask<Void, Void, Void> {
                          String title;
                          String element;
                          @Override
                          protected Void doInBackground(Void... voids) {
                              try {
                                  // Connect to the web site
                                  Document document = Jsoup.connect(url).get();
                                  // Get the html document title
                                  // point line
                                   title = document.title();
                                  // document.body();
                                  // Elements status = document.select("#status"); //h1.id Exporting good
                                  // title = status.text(); // h1.id Exporting good
                                  //Elements Title = document.select("title");
                                  //title = document.select("h1");
                                  // 2021-4-31 gateway
                                 // Elements pList = document.select("div.singleverse > div.singleverse-text");
                                 // String tmp="";
                                 // for (Element li : pList) {
                                 //     tmp = tmp + li.text()+"\n";
                                 //     Log.i("test","ok:"+ tmp);
                                     // System.out.printIn(
                                      //        e.select("span.item_num").get(0).html() +
                                      //                e.select("span.item_title").get(0).html()
                                      //);
                                  //}
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
                              return null;
                          }
                          protected void onPreExecute() {
                              super.onPreExecute();
                              mProgressDialog = new ProgressDialog(CrawlActivity.this);
                              mProgressDialog.setTitle("Power Bible engine 3.5c1");
                              mProgressDialog.setMessage(url);
                              mProgressDialog.setIndeterminate(false);
                              mProgressDialog.show();
                          }
                          @Override
                          protected void onPostExecute(Void result) {
                              // Set title into TextView
                              TextView txttitle = (TextView) findViewById(R.id.text_blank);
                              txttitle.setText(title);
                              // txttitle.setText(title);
                              mProgressDialog.dismiss();
                          }
                      }
                  
                  
                  mimoon
                  키 마스터

                    창 전환 효과 부분:

                    
                      ProgressDialog mProgressDialog;
                    
                        private class HelloWebViewClient extends WebViewClient {
                            @Override
                            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                                view.setVisibility(View.GONE);
                                mProgressDialog.setTitle("Loading");
                                mProgressDialog.show();
                                mProgressDialog.setMessage("페이지를 불러옵니다");
                                return false;
                            }
                    
                            @Override
                            public void onPageFinished(WebView view, String url) {
                                mProgressDialog.dismiss();
                                animate(view);
                                view.setVisibility(View.VISIBLE);
                                super.onPageFinished(view,url);
                            }
                        }
                    
                        private void animate(final WebView view) {
                            Animation anim = AnimationUtils.loadAnimation(getBaseContext(),
                                    android.R.anim.slide_in_left);
                            view.startAnimation(anim);
                        }
                    
                    
                    mimoon
                    키 마스터
                      mimoon
                      키 마스터

                        이상적 소스 (그러나 느림)
                        activity_main.xml 내용

                        
                        <?xml version="1.0" encoding="utf-8"?>
                        <androidx.constraintlayout.widget.ConstraintLayout
                            xmlns:android="http://schemas.android.com/apk/res/android"
                            xmlns:tools="http://schemas.android.com/tools"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent" tools:context=".MainActivity">
                        
                            <WebView
                                android:id="@+id/wvLayout"
                                android:layout_width="fill_parent"
                                android:layout_height="fill_parent"
                                tools:ignore="MissingConstraints" />
                        </androidx.constraintlayout.widget.ConstraintLayout>
                        
                        

                        AndroidManifest.xml

                        
                        <?xml version="1.0" encoding="utf-8"?>
                        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                            package="com.mimoonchurch.powerbible">
                            <uses-permission android:name="android.permission.INTERNET"/>
                            <application
                                android:allowBackup="true"
                                android:icon="@mipmap/ic_launcher"
                                android:label="@string/app_name"
                                android:roundIcon="@mipmap/ic_launcher_round"
                                android:supportsRtl="true"
                                android:theme="@style/Theme.Powerbible">
                                <activity android:name=".MainActivity">
                                    <intent-filter>
                                        <action android:name="android.intent.action.MAIN" />
                        
                                        <category android:name="android.intent.category.LAUNCHER" />
                                    </intent-filter>
                                </activity>
                            </application>
                        
                        </manifest>
                        

                        strings.xml 내용에:

                        
                        <resources>
                            <string name="app_name">파워바이블</string>
                        </resources>
                        

                        themes.xml 내용에:

                        
                        <resources xmlns:tools="http://schemas.android.com/tools">
                            <!-- Base application theme. -->
                            <style name="Theme.Powerbible" parent="Theme.AppCompat.Light.NoActionBar">
                                <!-- Primary brand color. -->
                                <item name="colorPrimary">@color/purple_500</item>
                                <item name="colorPrimaryVariant">@color/purple_700</item>
                                <item name="colorOnPrimary">@color/white</item>
                                <!-- Secondary brand color. -->
                                <item name="colorSecondary">@color/teal_200</item>
                                <item name="colorSecondaryVariant">@color/teal_700</item>
                                <item name="colorOnSecondary">@color/black</item>
                                <!-- Status bar color. -->
                                <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
                                <!-- Customize your theme here. -->
                            </style>
                        </resources>
                        

                        MainActivity.java 내용에

                        
                        package com.mimoonchurch.powerbible;
                        import android.app.Activity;
                        import android.app.ProgressDialog;
                        import android.os.Bundle;
                        import android.view.KeyEvent;
                        import android.view.View;
                        import android.view.animation.Animation;
                        import android.view.animation.AnimationUtils;
                        import android.webkit.WebView;
                        import android.webkit.WebViewClient;
                        
                        public class MainActivity extends Activity {
                            ProgressDialog mProgressDialog;
                        
                            private class HelloWebViewClient extends WebViewClient {
                                @Override
                                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                                    view.setVisibility(View.GONE);
                                    mProgressDialog.setTitle("Loading");
                                    mProgressDialog.show();
                                    mProgressDialog.setMessage("Loading " + url);
                                    return false;
                                }
                        
                                @Override
                                public void onPageFinished(WebView view, String url) {
                                    mProgressDialog.dismiss();
                                    animate(view);
                                    view.setVisibility(View.VISIBLE);
                                    super.onPageFinished(view, url);
                                }
                            }
                        
                            private void animate(final WebView view) {
                                Animation anim = AnimationUtils.loadAnimation(getBaseContext(),
                                        android.R.anim.slide_in_left);
                                view.startAnimation(anim);
                            }
                        
                            @Override
                            public boolean onKeyDown(int keyCode, KeyEvent event) {
                                WebView view = (WebView) findViewById(R.id.wvLayout);
                                if ((keyCode == KeyEvent.KEYCODE_BACK) && view.canGoBack()) {
                                    view.goBack();
                                    return true;
                                }
                                return super.onKeyDown(keyCode, event);
                            }
                        
                            /** Called when the activity is first created. */
                            @Override
                            public void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_main);
                                mProgressDialog = new ProgressDialog(this);
                                WebView webView = (WebView) findViewById(R.id.wvLayout);
                                webView.setVerticalScrollBarEnabled(false);
                                webView.setHorizontalScrollBarEnabled(false);
                                webView.getSettings().setJavaScriptEnabled(true);
                                webView.loadUrl("https://mimoonchurch.net/");
                                webView.setWebViewClient(new HelloWebViewClient());
                            }
                        }
                        
                      10 글 보임 - 21 에서 30 까지 (총 58 중에서)