2013-04-30 3 views
0

참고 : Worklight 6.2에서는 네이티브/웹 관계를 훨씬 쉽게 제어 할 수 있으므로이 질문은 현재 사용되지 않습니다.작업 표시 줄 Android 플래쉬

작업등 스튜디오 5.0.6, 안드로이드 에뮬레이터 안드로이드 시작 화면에 대한 4.0.2

질문. 아래의 코드는 this question에 대한 답변에서 파생되었습니다. 정상적으로 작동하는 것 같습니다. 나의 첫번째 관심사는 10000 (10 초) 지연이 우리가 네이티브 시작 화면 및 첫 번째 웹 페이지 사이에 빈 화면을 볼 다음 생략하면 하드 코딩 지연

super.loadUrl(getWebMainFilePath(), 10000); 

입니다. 내 생각 엔 10 초를 조정할 수있는 장치의 CPU 속도에 따라 또는 느린 장치를 늘려야 할 수도 있습니다. 따라서 10 초 간 코딩 된 코드에 의존하기보다는 사용할 수있는 콜백이 다른지 궁금합니다.

둘째, 고정 소수점 이하의 초기 화면을 원한다고 가정하면 super32.loadUr()을 호출하기 전에 this article 코드를 추가하는 것으로 충분합니까? 자바 스크립트에서 네이티브 페이지를 호출하는 방법에 대해 잘 알고 있지만 여기에서는 네이티브 페이지에서 시작하여 이전에 초기화되지 않은 JavaScript 월드에 컨트롤을 전달하려고합니다.

import android.os.Bundle; 
import com.worklight.androidgap.WLDroidGap; 

public class App02 extends WLDroidGap { 

    @Override 
    public void onCreate(Bundle savedInstanceState){ 

      super.onCreate(savedInstanceState); 
      super.setIntegerProperty("splashscreen", R.drawable.splash); 
        // active code here?? 
      super.bindBrowser(appView); 
    } 

    /** 
    * onWLInitCompleted is called when the Worklight runtime framework initialization is complete 
    */ 
    @Override 
    public void onWLInitCompleted(Bundle savedInstanceState){ 
     super.loadUrl(getWebMainFilePath(), 10000); 
    } 
} 
+1

솔직히 현재 버전의 Worklight에서 Android 환경의 Worklight 응용 프로그램에 스플래시 화면을 처리하는 좋은 방법이 없다고 생각합니다 (관리 할 경우 - 공유, 공유!). 이것은 앞으로의 버전에서 더 잘 다루어 져야 할 /해야 할 일입니다 ... –

+0

고마워요 Idan, 알아두면 좋겠지. – djna

답변

4

그렇게 할 수 있습니다.

1). 이 코드를 기본 Android 클래스 java 클래스에 추가하십시오.

/* 
* Shows the splash screen over the full Activity 
*/ 
protected void showSplashScreen() { 
    mThisapp.runOnUiThread(new Runnable() { 
     public void run() { 
      // Get reference to display 
      final Display display = getWindowManager().getDefaultDisplay(); 

      // Get current orientation 
      final int rotation = display.getRotation(); 
      final String orientation; 
      switch (rotation) { 
      default: 
      case Surface.ROTATION_0: 
       orientation = "Portrait"; 
       break; 
      case Surface.ROTATION_90: 
       orientation = "Landscape"; 
       break; 
      case Surface.ROTATION_180: 
       orientation = "Reverse Portrait"; 
       break; 
      case Surface.ROTATION_270: 
       orientation = "Reverse Landscape"; 
       break; 
      } 
      Log.i(TAG, "Orientation :: " + orientation); 

      // Create the layout for the dialog 
      final LinearLayout root = new LinearLayout(mThisapp.getActivity()); 
      // This method was deprecated in API level 13: display.getHeight and display.getWidth 
      // Gets the size of the display, in pixels 
      final Point outSize = new Point(); 
      display.getSize(outSize); 
      root.setMinimumHeight(outSize.y); 
      root.setMinimumWidth(outSize.x); 
      root.setOrientation(LinearLayout.VERTICAL); 
      root.setBackgroundColor(mThisapp.getIntegerProperty("backgroundColor", 
        Color.WHITE)); 
      root.setLayoutParams(new LinearLayout.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT, 
        ViewGroup.LayoutParams.MATCH_PARENT, 0.0F)); 
      //root.setBackgroundResource(mThisapp.splashscreen); 

      // ImageView Setup 
      final ImageView imageView = new ImageView(mBaseContext); 
      // Setting image resource 
      imageView.setImageResource(mThisapp.splashscreen); 
      // Setting image position 
      imageView.setLayoutParams(new LayoutParams(
        LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
      root.addView(imageView); 

      // Create and show the dialog 
      splashDialog = new Dialog(mThisapp, 
        android.R.style.Theme_Translucent_NoTitleBar); 
      // Check to see if the splash screen should be full screen 
      if ((getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) { 
       splashDialog.getWindow().setFlags(
         WindowManager.LayoutParams.FLAG_FULLSCREEN, 
         WindowManager.LayoutParams.FLAG_FULLSCREEN); 
      } 
      splashDialog.setContentView(root); 
      splashDialog.setCancelable(false); 
      splashDialog.show(); 
     } 
    }); 
} 

2). 공공 무효에서 onCreate (최종 번들 savedInstanceState)에서 줄을 추가

super.onCreate(savedInstanceState); 
    mThisapp = this; 
    mBaseContext = getBaseContext(); 
    // Add splash screen 
    super.setIntegerProperty("splashscreen", R.drawable.splash); 
... 
    // Show the splash dialog 
    this.splashscreen = this.getIntegerProperty("splashscreen", 0); 
    showSplashScreen(); 
    // End of apache/cordova-android/DroidGap 
... 
} 

예, 당신은 고해상도 폴더 (.PNG에서) 스플래시 이미지를 가지고해야합니다.

3). onMessage 수정

@Override 
/** 
* Called when a message is sent to plugin. 
* 
* @param id   The message id 
* @param data   The message data 
* @return    Object or null 
*/ 
public Object onMessage(final String id, final Object data) { 
    Log.d(TAG, "onMessage(" + id + "," + data + ")"); 
    if ("splashscreen".equals(id)) { 
     if (data != null && "hide".equals(data.toString())) { 
      if (mThisapp.appView.getVisibility() != View.VISIBLE) { 
       mThisapp.runOnUiThread(new Runnable() { 
        public void run() { 
         final Animation animationIn = AnimationUtils 
           .loadAnimation(mBaseContext, R.anim.zoom_in);       animationIn.setAnimationListener(new Animation.AnimationListener() { 
          @Override 
          public void onAnimationEnd(
            final Animation animation) { 
          } 

          @Override 
          public void onAnimationRepeat(
            final Animation animation) { 
          } 

          @Override 
          public void onAnimationStart(
            final Animation animation) { 
           if (splashDialog != null) 
            mThisapp.removeSplashScreen(); 
          } 
         }); 
         mThisapp.appView.setVisibility(View.VISIBLE); 
         mThisapp.appView.requestFocus(); 
         mThisapp.appView.startAnimation(animationIn); 
        } 
       }); 
      } else { 
       this.removeSplashScreen(); 
      } 
     } 
     return null; 
    } else if ("spinner".equals(id)) { 
     if (data != null && "stop".equals(data.toString())) { 
      this.spinnerStop(); 
      return null; 
     } 
    } 
    return super.onMessage(id, data); 
} 

4). config.xnl에이 줄이 있는지 확인하십시오.

< plugin name="SplashScreen" value="org.apache.cordova.SplashScreen" /> 

5). Worklight 초기화 마무리 블록에서 다음과 같이 추가하십시오.

if (navigator && navigator.splashscreen) 
      navigator.splashscreen.hide(); 

그런 다음 백엔드가로드 된 전체 시작 화면이 있습니다. 준비가되면 첫 번째 화면을 표시하십시오.

관련 문제