从左至右机器人卷曲页 [英] Curl page from left to right android
问题描述
所以,我使用的页面卷曲由harism, https://github.com/harism/android_page_curl 并已成功实施它通过网络流媒体加载图像。但不能得到它,当我回头去看previous图片或网页的图像不与右手食指在下一个工作。即它们不是清爽正常。我不知道这一点。
这是我实现我的图像加载到 PageProvider
私有类PageProvider实现CurlView.PageProvider {
@覆盖
公众诠释getPageCount(){
返回data1.size() - 1;
}
私人位图loadBitmap(INT宽度,高度INT,最终诠释指数)抛出MalformedURLException的,IOException异常{
位图B = Bitmap.createBitmap(宽度,高度,Bitmap.Config.ARGB_8888);
b.eraseColor(0xFFFFFFFF的);
帆布C =新的Canvas(B);
的System.out.println(当前页索引值+ mCurlView.getCurrentIndex()+和索引是+指数);
的System.out.println(URL转发);
,新AjaxCallback&所述aq.ajax(data1.get(索引+1),Bitmap.class,0;位图>(){
@覆盖
公共无效回调(字符串URL,位图对象,AjaxStatus状态){
如果(对象!= NULL)
尝试 {
的System.out.println(URL图像下载的+网址);
Y =对象;
aq.ajax(data1.get(指数).replace(PNG,.MP3),File.class,0,新AjaxCallback<文件>(){
@覆盖
公共无效回调(字符串URL,文件对象,AjaxStatus状态){
的System.out.println(URL下载的声音+网址);
尝试 {
如果(对象!= NULL)
{
的FileInputStream的InputStream =新的FileInputStream(对象);
如果(指数大于0)
{
mPlayer.stop();
mPlayer.reset();
}
prepareMediaPlayer(inputStream.getFD());
inputStream.close();
}
}
赶上(例外五){}
}
});
}赶上(例外五){
// TODO自动生成的catch块
e.printStackTrace();
}
}
});
D =新BitmapDrawable(getResources(),Y);
如果(Y!= NULL)
{
廉政保证金= 7;
INT边界= 3;
矩形R =新的矩形(保证金,保证金,宽度 - 利润率,高 - 保证金);
INT ImageWidth等= r.width() - (境* 2);
INT imageHeight = ImageWidth等* d.getIntrinsicHeight()
/ d.getIntrinsicWidth();
如果(imageHeight> r.height() - (境* 2)){
imageHeight = r.height() - (境* 2);
ImageWidth等= imageHeight * d.getIntrinsicWidth()
/ d.getIntrinsicHeight();
}
r.left + =((r.width() - ImageWidth等)/ 2) - 边框;
r.right = r.left + ImageWidth等+边框+边框;
r.top + =((r.height() - imageHeight)/ 2) - 边框;
r.bottom = r.top + imageHeight +边框+边框;
涂料P =新的油漆();
p.setColor(0xFFC0C0C0);
c.drawRect(R,P);
r.left + =边界;
r.right - =边界;
r.top + =边界;
r.bottom - =边界;
d.setBounds(r)的;
d.draw(C);
}
//}
如果(Y == NULL)
返回null;
其他
返回b;
}
@覆盖
公共无效的updatePage(CurlPage页,最终诠释宽度,最终诠释高度,最终诠释指数){
位图前= NULL;
的System.out.println(地图的移动/指标值/ countIteration /大小+ motionDirection +/+指数+/+ countIteration +/+ imageFilexxSm.size());
尝试 {
前面= loadBitmap(宽度,高度,指数);
如果(前面!= NULL)
{
page.setTexture(前,CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(180,180,180),CurlPage.SIDE_BACK);
}
}赶上(MalformedURLException异常E){
e.printStackTrace();
}赶上(IOException异常E){
e.printStackTrace();
}}}
此外,我曾尝试使用 getCurrentIndex
这是CurlView类中提供的方法设置指标,但它甚至无法正常工作。已经发现,该指数被正确传递,但不对位图得到刷新。
更明确的问题是:
当我朝着前进的方向,即第一,第二,第三,第四,第五......图像和声音正常工作,但是当我做了相反的第五,第四,第三,第二,第一则只有5日至4日卷曲是正确的,但第3,第2和第1乱序。为什么会出现这种情况?
我希望这会如果使用imageloading库节省别人的时间 与harism页面卷曲。
于是,经过了大量的研究,我发现,我用的是imageloading库(aquery)
已得到方法,即 getCachedImage(字符串URL)
, getCachedFile(字符串URL)
不上线工作,并返回空
如果该文件是不是已经被缓存到任何存储(SD卡,缓存目录)。
这件作品的code,这是实际为我做的,
私有类PageProvider实现CurlView.PageProvider {
@覆盖
公众诠释getPageCount(){
返回data1.size() - 1;
}
私人位图loadBitmap(INT宽度,高度INT,最终诠释指数)抛出MalformedURLException的,IOException异常{
位图B = Bitmap.createBitmap(宽度,高度,Bitmap.Config.ARGB_8888);
b.eraseColor(0xFFFFFFFF的);
帆布C =新的Canvas(B);
的System.out.println(指数是:+指数+卷曲状态:+ CurlActivity.motionDirection);
如果(指数== data1.size())
{
末页= FALSE;
}
其他
{
末页= TRUE;
}
如果(CurlActivity.motionDirection == 11)
{
Y = aq.getCachedImage(data1.get(指数));
F = aq.getCachedFile(data1.get(索引+ 1).replace(PNG,.MP3));
如果(F!= NULL)
{
的FileInputStream的InputStream =新的FileInputStream(F);
如果(指数大于0)
{
mPlayer.stop();
mPlayer.reset();
}
prepareMediaPlayer(inputStream.getFD());
inputStream.close();
}
}
其他
{
Y = aq.getCachedImage(data1.get(指数));
如果(跳== 0)
{
F = aq.getCachedFile(data1.get(指数).replace(PNG,.MP3));
}
其他
{
F = aq.getCachedFile(data1.get(索引+ 1).replace(PNG,.MP3));
}
如果(Y = NULL和放大器;!&安培; F =空!)
{
的FileInputStream的InputStream =新的FileInputStream(F);
如果(指数大于0)
{
mPlayer.stop();
mPlayer.reset();
}
prepareMediaPlayer(inputStream.getFD());
inputStream.close();
}
否则,如果(Y = NULL和放大器;!&安培;˚F== NULL)
{
持续时间= 1000;
}
其他
{
,新AjaxCallback&所述aq.progress(R.id.progress)阿贾克斯(data1.get(索引+1),Bitmap.class,0;位图>(){
@覆盖
公共无效回调(最后弦乐urlimg,最终的位图object1,AjaxStatus状态){
如果(object1!= NULL)
尝试 {
Y = object1;
aq.ajax(data1.get(指数).replace(PNG,.MP3),File.class,0,新AjaxCallback<文件>(){
@覆盖
公共无效回调(字符串URL,文件对象,AjaxStatus状态){
的System.out.println(URL下载的声音+ URL + status.get code());
尝试 {
如果(对象!= NULL || status.get code()== 404)
{
的FileInputStream的InputStream =新的FileInputStream(对象);
如果(指数大于0)
{
mPlayer.stop();
mPlayer.reset();
}
prepareMediaPlayer(inputStream.getFD());
inputStream.close();
}
}
赶上(例外五){}
}
});
}赶上(例外五){
// TODO自动生成的catch块
e.printStackTrace();
}
}
});
}
}
D =新BitmapDrawable(getResources(),Y);
如果(Y!= NULL)
{
廉政保证金= 7;
INT边界= 3;
矩形R =新的矩形(保证金,保证金,宽度 - 利润率,高 - 保证金);
INT ImageWidth等= r.width() - (境* 2);
INT imageHeight = ImageWidth等* d.getIntrinsicHeight()
/ d.getIntrinsicWidth();
如果(imageHeight> r.height() - (境* 2)){
imageHeight = r.height() - (境* 2);
ImageWidth等= imageHeight * d.getIntrinsicWidth()
/ d.getIntrinsicHeight();
}
r.left + =((r.width() - ImageWidth等)/ 2) - 边框;
r.right = r.left + ImageWidth等+边框+边框;
r.top + =((r.height() - imageHeight)/ 2) - 边框;
r.bottom = r.top + imageHeight +边框+边框;
涂料P =新的油漆();
p.setColor(0xFFC0C0C0);
c.drawRect(R,P);
r.left + =边界;
r.right - =边界;
r.top + =边界;
r.bottom - =边界;
d.setBounds(r)的;
d.draw(C);
}
返回b;
}
@覆盖
公共无效的updatePage(CurlPage页,最终诠释宽度,最终诠释高度,最终诠释指数){
mPlayer.stop();
mPlayer.reset();
位图前= NULL;
尝试 {
前面= loadBitmap(宽度,高度,指数);
如果(前面!= NULL)
{
page.setTexture(前,CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(180,180,180),CurlPage.SIDE_BACK);
}
}赶上(MalformedURLException异常E){
e.printStackTrace();
}赶上(IOException异常E){
e.printStackTrace();
}
}
}
So , I am using page curl by harism , https://github.com/harism/android_page_curl and have successfully implemented it for loading images via web streaming. But can't get it work when I flip back to the previous images or pages as the images are not coming with the right index. i.e. they are not refreshing properly. I can't figure this out.
This is my implementation where I load images to the 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();
}}}
Also I have tried setting the index using getCurrentIndex
method that is provided inside the CurlView class , but it even doesn't work. Have found that the index gets passed correctly but the bitmaps are not getting refreshed.
More clearly the problem is:
When I move in forward direction i.e. 1st , 2nd , 3rd , 4th , 5th ... the images and sounds works correctly , but when I do the reverse 5th , 4th , 3rd , 2nd , 1st then only 5th to 4th curl is right but 3rd , 2nd and 1st are out of order. Why is this happening?
I hope this would save someone's time if using an imageloading library with harism page curl.
So, after a lot of research I found that the imageloading library I was using (aquery)
has got methods i.e. getCachedImage(String url)
, getCachedFile(String url)
which doesn't work on the threads and return null
if the file is not already cached into any storage (sdcard , cache directory).
The piece of code that was actual did it for me is ,
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();
}
}
}
这篇关于从左至右机器人卷曲页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!