卷页从左到右的android

因此,我使用harism,https://github.com/harism/android_page_curl使用页面卷曲,并且已经成功实现了通过网络流式传输加载图像的功能。 但是,当我翻转回到之前的图像或页面时,由于图像没有以正确的索引进入,所以无法实现。 即他们没有适当的清爽。 我无法弄清楚这一点。

这是我将图片加载到PageProvider

private class PageProvider implements CurlView.PageProvider {


        @Override
        public int getPageCount() {
            return data1.size()-1;
        } 

        private Bitmap loadBitmap(int width, int height, final int index) throws MalformedURLException, IOException {
            Bitmap b = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
            b.eraseColor(0xFFFFFFFF);
            Canvas c = new Canvas(b);

            System.out.println("value of current page index "+mCurlView.getCurrentIndex()+" and index is "+index);

            System.out.println("url forward");
            aq.ajax(data1.get(index+1), Bitmap.class,0, new AjaxCallback<Bitmap>() {

                @Override
                public void callback(String url, Bitmap object, AjaxStatus status) {
                    if(object!=null)
                           try {
                                System.out.println("url image downloaded "+url);
                                y=object;

                                aq.ajax(data1.get(index).replace(".png", ".mp3"), File.class,0,new AjaxCallback<File>() {
                                    @Override
                                    public void callback(String url, File object, AjaxStatus status) {

                                        System.out.println("url sound downloaded "+url);
                                        try {
                                              if(object!=null)
                                               {    
                                                FileInputStream inputStream = new FileInputStream(object);

                                                if(index>0)
                                                 {  
                                                  mPlayer.stop();
                                                  mPlayer.reset();
                                                 }

                                                prepareMediaPlayer(inputStream.getFD());
                                                inputStream.close();
                                               }
                                            }
                                        catch (Exception e) {}
                                   }
                                });     
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                }
            }); 


            d = new BitmapDrawable(getResources(),y);

            if(y!=null)
            {   
            int margin = 7; 
            int border = 3;
            Rect r = new Rect(margin, margin, width - margin, height - margin);

            int imageWidth = r.width() - (border * 2);
            int imageHeight = imageWidth * d.getIntrinsicHeight()
                    / d.getIntrinsicWidth();
            if (imageHeight > r.height() - (border * 2)) {
                imageHeight = r.height() - (border * 2);
                imageWidth = imageHeight * d.getIntrinsicWidth()
                        / d.getIntrinsicHeight();
            }

            r.left += ((r.width() - imageWidth) / 2) - border;
            r.right = r.left + imageWidth + border + border;
            r.top += ((r.height() - imageHeight) / 2) - border;
            r.bottom = r.top + imageHeight + border + border;

            Paint p = new Paint();
            p.setColor(0xFFC0C0C0);
            c.drawRect(r, p);
            r.left += border;
            r.right -= border;
            r.top += border;
            r.bottom -= border;

            d.setBounds(r);
            d.draw(c);
            }
            //}
            if(y==null)
            return null;

            else
            return b;   
        }

        @Override
        public void updatePage(CurlPage page, final int width, final int height, final int index) {

                Bitmap front = null;

                System.out.println("motion / index value /countIteration / size of map "+motionDirection+"/"+index+"/"+countIteration+"/"+imageFilexxSm.size());

                try {


                     front=loadBitmap(width, height,index);

                    if(front!=null)
                    {
                    page.setTexture(front, CurlPage.SIDE_FRONT);
                    page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK);
                    }

                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }}}

另外我试图使用CurlView类中提供的getCurrentIndex方法设置索引,但它甚至不起作用。 已发现索引正确传递,但位图不会刷新。

更清楚的问题是:

当我向前移动即第1,2,3,4,5 ...时,图像和声音都能正常工作,但是当我做反向第5,第4,第3,第2,第1时,只有第5到第4个卷曲是正确的,但是,第三,第二和第一次出现故障。 这是为什么发生?


hm ... harism的curlpage具有加载图片时翻转页面的行为,例如,如果您将页面从0翻转为1,curlpage将为页面1和页面2加载图像,并且如果您翻转页面5,curlpage会加载图像对于第5页和第6页,但如果您翻回第4页,curlpage将为第4页,第3页和第2页加载图像。

当onTouch ACTION.MOVE时触发loadImage() ,因此在移动/翻页之前必须准备好图像,否则页面将变为空,必须通过调用CurlView类中的updatePage()方法手动加载。

对于getCurrentIndex()您可以在CurlView类的startCurl()updatePage()方法中检查它。


我希望如果使用具有harism页面卷曲的图像加载库,这将节省一些人的时间。

因此,大量的研究后,我发现,我用的是imageloading库(aquery)得到了方法,即getCachedImage(String url) getCachedFile(String url)不上线工作,并返回null ,如果该文件是不已经缓存到任何存储(SD卡,缓存目录)

这段代码实际上是为我做的,

private class PageProvider implements CurlView.PageProvider {


    @Override
    public int getPageCount() {
        return data1.size()-1;
    } 

    private Bitmap loadBitmap(int width, int height, final int index) throws MalformedURLException, IOException {
        Bitmap b = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
        b.eraseColor(0xFFFFFFFF);
        Canvas c = new Canvas(b);

        System.out.println(" Index is : "+index+" Curl state : "+CurlActivity.motionDirection);

        if(index==data1.size())
        {
        lastPage=false; 
        }

        else
        {
        lastPage=true;  
        }   

        if(CurlActivity.motionDirection==11)
             {
                y=aq.getCachedImage(data1.get(index));
                f=aq.getCachedFile(data1.get(index+1).replace(".png", ".mp3"));

                if(f!=null)
                {
                FileInputStream inputStream = new FileInputStream(f);

                if(index>0)
                     {  
                        mPlayer.stop();
                        mPlayer.reset();
                     }

                 prepareMediaPlayer(inputStream.getFD());
                 inputStream.close();
               }
            }

            else
            {
                y=aq.getCachedImage(data1.get(index));

                if(jump==0)
                 { 
                  f=aq.getCachedFile(data1.get(index).replace(".png", ".mp3"));
                 }

                else
                 {
                  f=aq.getCachedFile(data1.get(index+1).replace(".png", ".mp3"));
                 }


                if(y!=null&&f!=null)
                {
                FileInputStream inputStream = new FileInputStream(f);

                if(index>0)
                     {  
                        mPlayer.stop();
                        mPlayer.reset();
                     }
                 prepareMediaPlayer(inputStream.getFD());
                 inputStream.close();
                }

                else if(y!=null && f == null)
                {
                    duration=1000;
                }

                else
                {   
                aq.progress(R.id.progress).ajax(data1.get(index+1), Bitmap.class,0, new AjaxCallback<Bitmap>() {
                @Override
                public void callback(final String urlimg, final Bitmap object1, AjaxStatus status) {
                    if(object1!=null)
                           try {
                                y=object1;

                                aq.ajax(data1.get(index).replace(".png", ".mp3"), File.class,0,new AjaxCallback<File>() {
                                    @Override
                                    public void callback(String url, File object, AjaxStatus status) {

                                        System.out.println("url sound downloaded "+url+status.getCode());
                                        try {
                                              if(object!=null||status.getCode()==404)
                                               {
                                                FileInputStream inputStream = new FileInputStream(object);

                                                if(index>0)
                                                 {  
                                                  mPlayer.stop();
                                                  mPlayer.reset();
                                                 }

                                                prepareMediaPlayer(inputStream.getFD());
                                                inputStream.close();
                                               }
                                            }
                                        catch (Exception e) {}
                                   }
                                });     
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                }
            });
           }    
        }

        d = new BitmapDrawable(getResources(),y);

        if(y!=null)
        {   
        int margin = 7; 
        int border = 3;
        Rect r = new Rect(margin, margin, width - margin, height - margin);

        int imageWidth = r.width() - (border * 2);
        int imageHeight = imageWidth * d.getIntrinsicHeight()
                / d.getIntrinsicWidth();
        if (imageHeight > r.height() - (border * 2)) {
            imageHeight = r.height() - (border * 2);
            imageWidth = imageHeight * d.getIntrinsicWidth()
                    / d.getIntrinsicHeight();
        }

        r.left += ((r.width() - imageWidth) / 2) - border;
        r.right = r.left + imageWidth + border + border;
        r.top += ((r.height() - imageHeight) / 2) - border;
        r.bottom = r.top + imageHeight + border + border;

        Paint p = new Paint();
        p.setColor(0xFFC0C0C0);
        c.drawRect(r, p);
        r.left += border;
        r.right -= border;
        r.top += border;
        r.bottom -= border;

        d.setBounds(r);
        d.draw(c);
        }

        return b;   
    }

    @Override
    public void updatePage(CurlPage page, final int width, final int height, final int index) {
            mPlayer.stop();
            mPlayer.reset();

            Bitmap front = null;

            try {

                front=loadBitmap(width, height,index);

                if(front!=null)
                {
                page.setTexture(front, CurlPage.SIDE_FRONT);
                page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK);
                }

            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

      } 
}
链接地址: http://www.djcxy.com/p/71731.html

上一篇: Curl page from left to right android

下一篇: How to slide a view in and out in android