2013-12-17 3 views
0

안녕하세요 Android 용 RSS 리더를 프로그래밍했습니다. 때로는 피드에 jQuery 슬라이더 (RoyalSlider http://dimsemenov.com/plugins/royal-slider/)가 포함되어 있는데이 피드는 내 webview에 표시되지 않습니다.Android : WebView에 jQuery 슬라이더가 올바르게 표시되지 않았습니다.

내 웹보기는 다음과 같이 초기화 :

(단지 이미지에 대한 링크 교체)
@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 

    // Initialize views after the activity is created 
    TextView title = (TextView) getView().findViewById(R.id.title); 
    TextView author = (TextView) getView().findViewById(R.id.author); 
    TextView date = (TextView) getView().findViewById(R.id.date); 
    WebView wv = (WebView) getView().findViewById(R.id.desc); 

    // Enable the vertical fading edge (by default it is disabled) 
    ScrollView sv = (ScrollView) getView().findViewById(R.id.sv); 
    sv.setVerticalFadingEdgeEnabled(true); 


    // Set webview properties 
    WebSettings ws = wv.getSettings(); 
    //to show only one column, so that picture is always scaled correctly 
    ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); 
    ws.setJavaScriptEnabled(true); 
    ws.setAllowFileAccess(true); 
    ws.setAllowContentAccess(true); 

    wv.setWebChromeClient(new WebChromeClient()); 

    Log.d("debug","In ItemDetailFragment mit Position: "+fPos+"und Feed: "+fFeed); 

    //put in data 
    title.setText(fFeed.getItem(fPos).getTitle()); 
    author.setText(fFeed.getItem(fPos).getAuthor()); 
    date.setText(fFeed.getItem(fPos).getDate()); 
    wv.loadDataWithBaseURL("file:///android_asset/jquery-1.10.2.min.js", fFeed 
      .getItem(fPos).getDescription(), "text/html", "UTF-8", null); 

} 
RSS 피드의 슬라이더는 다음과 같습니다

:

<p><div id="royalslider-77" class="royalSlider default" style="width:620px; height:340px;"><ul class="royalSlidesContainer"><li data-src="http://www.test.de/1.jpg" class="royalSlide"></li><li data-src="http://www.test.de/2.jpg" class="royalSlide"></li><li data-src="http://www.test.de/3.jpg" class="royalSlide"></li><li data-src="http://www.test.de/4.jpg" class="royalSlide"></li><li data-src="http://www.test.de/5.jpg" class="royalSlide"></li></ul></div><script type="text/javascript">jQuery(document).ready(function() {jQuery("#royalslider-77").royalSlider({"width":620,"height":340,"skin":"default","preloadSkin":false,"lazyLoading":true,"preloadNearbyImages":true,"slideshowEnabled":false,"slideshowDelay":5000,"slideshowPauseOnHover":true,"slideshowAutoStart":true,"keyboardNavEnabled":false,"dragUsingMouse":true,"slideSpacing":0,"startSlideIndex":0,"imageAlignCenter":true,"imageScaleMode":"fit","autoScaleSlider":false,"autoScaleSliderWidth":620,"autoScaleSliderHeight":700,"slideTransitionType":"move","slideTransitionSpeed":400,"slideTransitionEasing":"easeInOutSine","directionNavEnabled":true,"directionNavAutoHide":false,"hideArrowOnLastSlide":true,"controlNavigationType":"none","auto-generate-images":false,"auto-generate-thumbs":false,"thumb-width":60,"thumb-height":60,"captionAnimationEnabled":true,"captionShowFadeEffect":true,"captionShowMoveEffect":"movetop","captionMoveOffset":20,"captionShowSpeed":400,"captionShowEasing":"easeInOutSine","captionShowDelay":200,"controlNavEnabled":false,"captionShowEffects":["fade","movetop"]});});</script><br /> 

이 글은 다음과 같습니다 내 webview의 경우 먼저 텍스트와 슬라이더는 다음 네 가지 점으로 표시됩니다.

enter image description here

내 실수는 누구나?

+0

사용중인 Android 버전은 무엇입니까? – ksasq

+0

@ksasq Android 4.1.2 –

+0

자바 스크립트 또는 CSS 슬라이더가 제대로로드되지 않는 것처럼 보입니다. loadDataWithBaseUrl에 대한 호출이 올바르게 표시되지 않습니다. js 파일이 기본 URL 인 이유는 무엇입니까? 데이터는 어떻게 생겼습니까? – ksasq

답변

0

http://www.test.de/1.jpg 링크가 깨진 - 다른 모든 참조 URL을 렌더링하는 경우 404

확인을 제공합니다.

URL이 작동하지 않는 한 예상대로받은 글 머리 기호 목록이 표시됩니다.

0
// set web chrome client by adding this in ur on create  
wv.setWebChromeClient(new CustomWebViewChromeClient()); 

    // this is web chrome client implemetation. it works. Any issues please put comments. i got working 
private class CustomWebViewClient extends WebViewClient 
{ 
    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    { 
    // TODO Auto-generated method stub 

     return false; 
    } 

    @Override 
    public void onPageStarted(WebView view, String url, Bitmap favicon) 
{ 
    // TODO Auto-generated method stub 
    super.onPageStarted(view, url, favicon); 
    } 

@Override 
public void onPageFinished(WebView view, String url) 
{ 
    // TODO Auto-generated method stub 
    super.onPageFinished(view, url); 
} 

    @TargetApi(11) 
    @Override 
    public WebResourceResponse shouldInterceptRequest(WebView view, String url) { 
    Log.d("shouldInterceptRequest", url); 

    InputStream stream = inputStreamForAndroidResource(url); 
    if (stream != null) { 
     return new WebResourceResponse("text/javascript", "utf-8", stream); 
    } 
    return super.shouldInterceptRequest(view, url); 
} 

private InputStream inputStreamForAndroidResource(String url) { 
    final String ANDROID_ASSET = "file:///android_asset/"; 

    if (url.contains(ANDROID_ASSET)) { 
     url = url.replaceFirst(ANDROID_ASSET, ""); 
     try { 
      AssetManager assets = getAssets(); 
      Uri uri = Uri.parse(url); 
      return assets 
        .open(uri.getPath(), AssetManager.ACCESS_STREAMING); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
    return null; 
} 
} 
관련 문제