2012년 11월 8일 목요일

센차터치2 + 폰갭 코믹뷰어 소스공개 3탄

다시 3탄으로 이어집니다....

자... 이제 상세화면을 살펴보겠습니다... 1탄의 이미지를 기억하세요... 상세화면은
파일목록에서 하나를 클릭해서 해당 폴더의 파일을 만화보듯이 손가락으로 넘겨서 만화를 보는 곳입니다.....

먼저 뷰를 살펴보겠습니다...

GalleryDetailView.js 파일입니다. ----------------------------
뭘를 가져왔나요.... 툴바, Carousel이 있죠.. Carousel을 잘 살펴보셔야 합니다.

Ext.define("Gallery.view.GalleryDetailView", {
extend: 'Ext.Panel',
xtype:'gallerydetailview',
requires:[
'Ext.Panel',
'Ext.Toolbar',
'Gallery.view.GalleryDetailCarousel'
],
config:{
fullscreen: true,
layout: {
type: 'vbox',
align: 'stretch',
},
items:[
{
name:'subjectToolbar',
xtype: 'toolbar',
height:40,
docked: 'top',
title:'Detail',
layout: {
type:'hbox',
align: 'stretch'
},
items:[
{
html:'<img src="./img/folder_black_open.png" height="30">',
name:'backList',
docked:'left',
},
{
xtype:'spacer',
},
{
html:'<img src="./img/search1.png" height="30">',
name:'chgSize',
docked:'right',
}]
},
{
xtype:'gallerydetailcarousel', //gallerydetail.carousel
name:'gallerydetailcarousel',
flex:1,
}],
}
});

GalleryDetailCarousel.js 파일입니다. ---------------------------
소스가 허전하죠... MVC로 하지 않았다면 소스가 엄청 있었을 겁니다.

Ext.define("Gallery.view.GalleryDetailCarousel", {
extend: 'Ext.Carousel',
xtype:'gallerydetailcarousel',
config:{
// 화면의 상하단 버튼을 확인
flex:1,
defaults: {
cls: 'card'
},
indicator:false,
items:[]
}
});


Carousel에 들어갈 화면이 필요하겠죠..... 그 안에서 돌아갈 화면입니다. 이미지를 담당하죠...
GalleryDetailCard.js 파일입니다. -------------------------------------

Ext.define("Gallery.view.GalleryDetailCard", {
extend:'Ext.Panel',
xtype:'gallerydetailcard',
galleryid:'0',
subject:'',
content:'',
img:'',
setImgCls:false,
config:{
height:'100%',
width:'100%',
scrollable:{
direction:'vertical',
directionLock:true,
},
layout:{
xtype:'vbox',
},
},
setPage:function(id, subject, content, img)
{
this.galleryid = id;
this.subject = subject;
this.content = content;
this.img = img;
this.setHtml('<img width="100%" src="' + this.img + '">');
this.setImgCls = true;
},

// 이미지 설정
setImg:function()
{
},
// 이미지 해제
releaseImg:function()
{
},

// 초기화
initialize:function(){
this.img='';
this.setImgCls = false;
this.flex = 1,
this.layout = {
type: 'vbox',
align:'stretch',
};
this.callParent();
}
});
확대창 보기입니다... 프로그램에 크게 중요하지 않으므로 무시하셔도 됩니다...
GalleryDetailCardPop.js 입니다. -------------------------------------------------------
Ext.define("Gallery.view.GalleryDetailCardPop", {
extend:'Ext.Panel',
xtype:'gallerydetailcardpop',
galleryid:'0',
subject:'',
content:'',
img:'',
popSize:'',
popRotate:'',
popState:0,
setImgCls:false,
config:{
fullscreen:true,
styleHtmlContent:true,
layout:{
xtype:'vbox',
},
scrollable:{
direction:'both',
directionLock:true
},
html:'',
items:[
{
xtype:'toolbar',
docked:'top',
height:40,
items:[
{
xtype:'button',
html:'<img src="./img/arrow_left.png" height="30">', // 방향전환
name:'popLeft'
},
{
xtype:'spacer'
},
{
xtype:'button',
html:'<img src="./img/delete.png" height="20">', // 나가기
name:'popClose'
},
{
xtype:'button',
html:'<img src="./img/minus1.png" height="20">', // 사이즈
name:'popSizeM'
},
{
xtype:'button',
html:'<img src="./img/add.png" height="20">', // 사이즈
name:'popSizeA'
},
{
xtype:'spacer'
},
{
xtype:'button',
html:'<img src="./img/arrow_right.png" height="30">', // 방향전환
name:'popRight'
}]
}],
},
setPage:function(id, subject, content, img, popSize, popRotate, panelWidth)
{
this.galleryid = id;
this.subject = subject;
this.content = content;
this.img = img;
this.popSize = popSize;
this.popRotate = popRotate;
var imgElement = document.createElement("img");
imgElement.src=this.img;
var tempWidth = imgElement.width;
var tempHeight = imgElement.height;
var tempCalc = tempHeight/tempWidth;
imgElement.width = window.screen.width * this.popSize * 0.01;
imgElement.height = imgElement.width * tempCalc;
this.setHtml('<font size=2>' + subject + '</font><BR><img height="' + imgElement.height + 'px" width="' + imgElement.width + 'px" src="' + this.img + '"> ');
this.setImgCls = true;
},

// 이미지 설정
setImg:function()
{
},
// 이미지 해제
releaseImg:function()
{
},
// 초기화
initialize:function(){
this.img='';
this.popSize='';
this.popRotate='';
this.setImgCls = false;
this.flex = 1,
this.layout = {
type: 'vbox',
align:'stretch',
};
this.callParent();
}
});



이제 가장중요한 controller입니다......
GalleryDetailController.js 파일입니다... 소스에 간단한 설명을 해놓았으니 잘 살펴보시기 바랍니다.....


Ext.define('Gallery.controller.GalleryDetailController', {
extend: 'Ext.app.Controller',
xtype:'gallerydetailcontroller',
name:'GalleryDetailController',
requires:[
'Ext.Ajax',
'Ext.Anim',
'Gallery.view.GalleryDetailCard',
'Gallery.common.GalleryData'
],
config: {
// 참조개체를 정의한다.
refs: {
galleryListView: 'gallerylistview',
galleryDetailView: 'gallerydetailview',
galleryDetailCard: 'gallerydetailcard',
galleryDetailCardPop: 'gallerydetailcardpop',
galleryDetailCarousel: 'gallerydetailview [name=gallerydetailcarousel]',
subjectToolbar : 'gallerydetailview [name=subjectToolbar]',
backList : 'gallerydetailview [name=backList]',
chgSize: 'gallerydetailview [name=chgSize]',
popLeft: 'gallerydetailcardpop [name=popLeft]',
popClose: 'gallerydetailcardpop [name=popClose]',
popSizeA: 'gallerydetailcardpop [name=popSizeA]',
popSizeM: 'gallerydetailcardpop [name=popSizeM]',
popRotate: 'gallerydetailcardpop [name=popRotate]',
popRight: 'gallerydetailcardpop [name=popRight]',
},
// 참조개체의 이벤트를 정의함.
control: {
// viewport로부터 화면의 가로세로 변환을 감지하여 이벤트를 처리함.
viewport:{
orientationchange: 'onOrien'
},
galleryDetailCarousel: {
activeitemchange: 'onCarouselChange'
},
backList:{
tap:'onBackList'
},
chgSize:{
tap:'onChgSize'
},
popLeft:{
tap:'onPopLeft'
},
popClose:{
tap:'onPopClose'
},
popSizeA:{
tap:'onPopSizeA'
},
popSizeM:{
tap:'onPopSizeM'
},
popRotate:{
tap:'onPopRotate'
},
popRight:{
tap:'onPopRight'
},
}
},
// 멤버변수
currPageNum:0,
carouselAdded:0,
imgDraw:false,
panelPop:'',
popState:0,
launch: function() {
},
// 가로세로가 변경될 경우 시간을 지연한다.
onOrien:function(viewport, orientation, width, height){
if(orientation == 'portrait')
{
var strtTime = new Date().getTime();
for(var i=0;i<10000; i++)
{
var endTime= new Date().getTime();
if((endTime - strtTime) > 500)
{
break;
}
}
}
},
// 파일목록에서 상세화면이 호출될때 메소드
setPage:function(cpage){
this.currPageNum = cpage;
this.setDataPos('first');
},
// 폰갭플러그인을 통해 목록을 가져옴.
callServer:function(inputPage)
{
var tempThis= this;
var startNum = (inputPage-1)* 10;
var lastNum = startNum + 10;
if(startNum > Gallery.common.GalleryData.totData.length)
{
this.currPageNum = this.currPageNum - 1;
alert('더이상 데이터가 없습니다.');
return;
}
if( Gallery.common.GalleryData.totData.length < lastNum )
{
lastNum = Gallery.common.GalleryData.totData.length;
}
var tempArray = Array (lastNum-startNum);
var j=0;
for(i = startNum; i< lastNum; i++)
{
tempArray[j] = Gallery.common.GalleryData.totData[i];
j++;
}
this.addProxyData(tempArray);
},
// 상세화면관련====================================
// 앞화면(리스트 조회에서) 클릭하였을 경우 보여주는 현재 화면의 위치
setDataPos:function(val)
{
if(val=='first')
{
for(i= this.getGalleryDetailCarousel().getItems().length-1; i >= this.carouselAdded;i--)
{
this.getGalleryDetailCarousel().removeAt(i);
}
}
var start_i = Gallery.common.GalleryData.minDataPos;
if(start_i< 0)
start_i=0;
for(i = start_i; i< Gallery.common.GalleryData.maxDataPos;i++)
{
try{ this.addArt(Gallery.common.GalleryData.orgData[i]); }catch(e){ console.log('오류무시'); }
}
this.getGalleryDetailCarousel().setActiveItem( Gallery.common.GalleryData.curDataPos - start_i);
this.getGalleryDetailView().imgDraw = true;
// 첫번째 호출일경우
if(val=='first')
{
console.log('첫번째위치 ');
var firstPos = Gallery.common.GalleryData.curDataPos - Gallery.common.GalleryData.minDataPos;
if(firstPos < 0)
firstPos = 0;
var detailCard = this.getGalleryDetailCarousel().getAt(firstPos + this.carouselAdded);
this.getSubjectToolbar().setTitle(detailCard.subject);
try
{
Gallery.common.GalleryData.curId = detailCard.galleryid;
}
catch(e){}
}
},
// 가져온 데이터받기이벤트
addProxyData:function(result)
{
if(result == null){
}
else
{
if( Gallery.common.GalleryData.maxDataPos>= 30)
{
for(i=0;i<10;i++)
{
this.getGalleryDetailCarousel().removeAt(0 + this.carouselAdded);
}
}
this.addProxyDataSub(result);
}
},
// addProxyData로부터 호출됨
addProxyDataSub:function(result)
{
var temp = Gallery.common.GalleryData.maxDataPos;
for(i = 0; i< result.length; i++)
{
Gallery.common.GalleryData.orgData.push(result[i]);
}
Gallery.common.GalleryData.maxDataPos = Gallery.common.GalleryData.maxDataPos + 10;
Gallery.common.GalleryData.minDataPos = Gallery.common.GalleryData.maxDataPos - 30;
if(Gallery.common.GalleryData.maxDataPos > Gallery.common.GalleryData.totDataPos)
{
Gallery.common.GalleryData.totDataPos = Gallery.common.GalleryData.maxDataPos;
}
for(i = 0; i< result.length; i++)
{
this.addArt(result[i]);
}
if(temp >= 30)
{
this.getGalleryDetailCarousel().setActiveItem(19);
}
},
// 데이터를 추가함
addData:function(result)
{
for(i = 0; i< result.length; i++)
{
this.addArt(result[i]);
}
},
// 데이터를 삽입함
insertData:function(result)
{
for(i = 9; i>=0; i--)
{
this.insertArt(result[i]);
}
},
// 커로우절화면====================================
onCarouselChange:function( a, index1,index2){
console.log('움직였다.' + index1 + "." + index2);
if(this.getGalleryDetailView().imgDraw == true)
{
// 화면갱신
var curIndex = Number(this.getGalleryDetailCarousel().getActiveIndex());
{
{
// 페이지가 움직일때 Title설정
var detailCard =
this.getGalleryDetailCarousel().getAt(curIndex+this.carouselAdded);
Gallery.common.GalleryData.curId = detailCard.galleryid;
// 타이틀바 설정 (적절히 크기 등 수정요함)
this.getSubjectToolbar().setTitle(detailCard.subject);
}
}
// 오른쪽으로 이동
if(curIndex == this.getGalleryDetailCarousel().getItems().length-1-this.carouselAdded)
{
// 현재 MAX값보다 큰 값을 가져올 경우 서버로부터 데이터를 요청함.
if(Gallery.common.GalleryData.maxDataPos >= Gallery.common.GalleryData.totDataPos)
{
this.currPageNum = this.currPageNum+1;
this.callServer(this.currPageNum);
}
else
{
// 현재위치보다 작고 30건 이상일 경우 이미 불러온 10건을 리스트에 추가함.
if( Gallery.common.GalleryData.maxDataPos>= 30)
{
for(i=0;i<10;i++)
{
this.getGalleryDetailCarousel().removeAt(0 + this.carouselAdded);
}
var result = new Array(0);
for(i= Gallery.common.GalleryData.maxDataPos;
i< Gallery.common.GalleryData.maxDataPos+10;
i++)
{
result.push(Gallery.common.GalleryData.orgData[i]);
}
Gallery.common.GalleryData.maxDataPos = Gallery.common.GalleryData.maxDataPos+10;
Gallery.common.GalleryData.minDataPos = Gallery.common.GalleryData.maxDataPos-30;
this.addData(result);
}
}
}
else if(curIndex == 0)
{
// 맨 왼쪽으로 왔을 경우
console.log("왼쪽으로 이동");
if(Gallery.common.GalleryData.maxDataPos > 30)
{
// 30건 이상이 있을 경우 오른쪽 10건을 지우고 왼쪽 10건을 추가함.
for(i=9; i>=0;i--)
{
this.getGalleryDetailCarousel().removeAt(i + 20 + this.carouselAdded);
}
var result = new Array(0);
for(i= Gallery.common.GalleryData.maxDataPos-40;
i< Gallery.common.GalleryData.maxDataPos-30;
i++)
{
result.push(Gallery.common.GalleryData.orgData[i]);
}
Gallery.common.GalleryData.maxDataPos = Gallery.common.GalleryData.maxDataPos-10;
Gallery.common.GalleryData.minDataPos = Gallery.common.GalleryData.maxDataPos-30;
this.insertData(result);
this.getGalleryDetailCarousel().setActiveItem(10);
}
}
}
if(this.popState == 1)
{
this.pageRefresh();
}
},
// 앞화면(리스트 조회에서) 클릭하였을 경우 보여주는 현재 화면의 위치
setDetailDataPos:function(val)
{
if(val=='first')
{
for(i=this.getGalleryDetailCarousel().getItems().length-1; i>=this.carouselAdded;i--)
{
this.getGalleryDetailCarousel().removeAt(i);
}
}
var start_i = Gallery.common.GalleryData.minDataPos;
if(start_i< 0)
start_i=0;
for(i = start_i; i< Gallery.common.GalleryData.maxDataPos;i++)
{
try{ this.addArt(Gallery.common.GalleryData.orgData[i]); }catch(e){}
}
// 페이지를 이동시킨다.
this.getGalleryDetailCarousel().setActiveItem( Gallery.common.GalleryData.curDataPos - start_i);
this.getGalleryDetailView().imgDraw = true;
// 첫번째 호출일경우
if(val=='first')
{
var firstPos = Gallery.common.GalleryData.curDataPos - Gallery.common.GalleryData.minDataPos;
if(firstPos < 0)
firstPos = 0;
var detailCard = this.getGalleryDetailCarousel().getAt(firstPos+this.carouselAdded);
try
{
Gallery.common.GalleryData.curId = detailCard.galleryid;
}
catch(e){ console.log('에러무시' ); }
}
},
// GalleryDetailCard에 이미지를 넣은뒤 Carousel에 추가함
addArt:function(photodata){
var detailCard = new Ext.create('Gallery.view.GalleryDetailCard');
detailCard.setPage( photodata.id,
photodata.subject,
photodata.content,
photodata.img);
this.getGalleryDetailCarousel().add(detailCard);
},
// 앞쪽에 CardDetailCard를 추가함
insertArt:function(photodata) {
var detailCard = new Ext.create('Gallery.view.GalleryDetailCard');
detailCard.setPage( photodata.id,
photodata.subject,
photodata.content,
photodata.img);
this.getGalleryDetailCarousel().insert(0 + this.carouselAdded, detailCard);
},
// 파일목록으로 돌아감.
onBackList:function()
{
Gallery.common.GalleryData.curDataPos =
Number(this.getGalleryDetailCarousel().getActiveIndex()) +
Gallery.common.GalleryData.minDataPos;
this.getGalleryDetailView().hide();
this.getGalleryListView().show();
this.getApplication().getController('GalleryController').returnAddMsg(this.currPageNum);
},
// 상세확대창으로 이동
onChgSize:function()
{
this.getGalleryDetailView().hide();
this.getGalleryDetailCardPop().show();
this.popState = 1;
this.pageRefresh();
},
// 확대창에서 왼쪽이미지로 변경
onPopLeft:function()
{
this.getGalleryDetailCarousel().previous();
},
// 확대창을 닫음
onPopClose:function()
{
this.popState = 0;
this.getGalleryDetailCardPop().hide();
this.getGalleryDetailView().show();
},
// 확대창에서 크기를 늘림
onPopSizeA:function()
{
Gallery.common.GalleryData.curDataPos =
Number(this.getGalleryDetailCarousel().getActiveIndex()) +
Gallery.common.GalleryData.minDataPos;
Gallery.common.GalleryData.popSize = Gallery.common.GalleryData.popSize + 10;
this.pageRefresh();
},
// 확대창에서 크기를 줄임
onPopSizeM:function()
{
Gallery.common.GalleryData.curDataPos =
Number(this.getGalleryDetailCarousel().getActiveIndex()) +
Gallery.common.GalleryData.minDataPos;
Gallery.common.GalleryData.popSize = Gallery.common.GalleryData.popSize - 10;
this.pageRefresh();
},
// 확대창 이미지를 회전시킨 (미사용)
onPopRotate:function()
{
if(Gallery.common.GalleryData.popRotate == "rotate0")
Gallery.common.GalleryData.popRotate = "rotate90";
else if(Gallery.common.GalleryData.popRotate == "rotate90")
Gallery.common.GalleryData.popRotate = "rotate180";
else if(Gallery.common.GalleryData.popRotate == "rotate180")
Gallery.common.GalleryData.popRotate = "rotate270"
else if(Gallery.common.GalleryData.popRotate == "rotate270")
Gallery.common.GalleryData.popRotate = "rotate0";
this.pageRefresh();
},
// 확대창 이미지를 오른쪽 이미지로 대체
onPopRight:function()
{
this.getGalleryDetailCarousel().next();
},
// 확대창의 조작이 있은 후 화면을 갱신함
pageRefresh:function()
{
Gallery.common.GalleryData.curDataPos =
Number(this.getGalleryDetailCarousel().getActiveIndex()) +
Gallery.common.GalleryData.minDataPos;
this.getGalleryDetailCardPop().setPage(
Gallery.common.GalleryData.orgData[Gallery.common.GalleryData.curDataPos].id,
Gallery.common.GalleryData.orgData[Gallery.common.GalleryData.curDataPos].subject,
Gallery.common.GalleryData.orgData[Gallery.common.GalleryData.curDataPos].content,
Gallery.common.GalleryData.orgData[Gallery.common.GalleryData.curDataPos].img,
Gallery.common.GalleryData.popSize,
Gallery.common.GalleryData.popRotate,
window.screen.width);
}
});

센차터치쪽 소스는 다 보았습니다.... 어떠신지요..... Controller와 Controller간 호출도 살펴보세요...

다음은 폰갭 플러그인을 살펴봐야 할것 같네요.. 계속 4탄으로 이어집니다.

댓글 없음:

댓글 쓰기