Code example for ViewFlipper

Methods: getDisplayedChild, getGlobalVisibleRect, setInAnimation, setOutAnimation, showNext, showPrevious

0
			else if(m_nPreTouchPosX - nTouchPosX > SWIPE_MIN_DISTANCE)
				moveNextView(); 
			//이미지의 이동 없는 것으로 상세페이지로 이동함 
			else 
			{ 
				int		nPosition = m_Flipper.getDisplayedChild();
				if(m_AdverData != null && nPosition < m_AdverData.size())
				{ 
//					String	sDetailType = m_AdverData.get(nPosition).m_sCONTENTTYPE; 
//					if(sDetailType.equals("BM")) 
//						goToDetailBM(nPosition); 
//					else if(sDetailType.equals("BLOGBM")) 
//						goToDetailBLOGBM(nPosition); 
//					else if(sDetailType.equals("THME")) 
//						goToDetailTHME(nPosition); 
//					else if(sDetailType.equals("NOTICE")) 
//						goToDetailNOTICE(nPosition); 
//					else if(sDetailType.equals("WEBSITE")) 
//						goToDetailWEBSITE(nPosition); 
				} 
			} 
			m_nPreTouchPosX = nTouchPosX;
			return true; 
		} 
 
		return false; 
	} 
 
	public void setClickEvent(){ 
    	OnClickListener	buttonClickListener = new OnClickListener() {
			@Override 
			public void onClick(View v) {
				int	nID = v.getId();
				switch (nID) {
//				case R.id.btn_Main_Adver_Left: 
//					movePreviousView(); 
//					break; 
//				case R.id.btn_Main_Adver_Right: 
//					moveNextView(); 
//					break; 
				} 
			} 
		}; 
		//Listener 연결 
//		m_Activity.findViewById(R.id.btn_Main_Adver_Left).setOnClickListener(buttonClickListener); 
//		m_Activity.findViewById(R.id.btn_Main_Adver_Right).setOnClickListener(buttonClickListener); 
	} 
 
	private final	Handler	m_Handler = new Handler(){
		@Override 
		public void handleMessage(android.os.Message msg) { 
			moveNextView(); 
			m_Handler.sendEmptyMessageDelayed(0, TIME_AUTOROLLING); 
		}; 
	}; 
 
	/*------------------------------------------------------------------------- 
	 * set Method define 
	-------------------------------------------------------------------------*/ 
	//List로 받은 Data중 이미지를 Flipper에 넣도록 설정한다. 
	public void setFlipperData(ArrayList<MainBannerData> flipperData){
		m_AdverData = flipperData;
		m_ivAdverChild = new ImageView[flipperData.size()];
 
		//ChildView를 초기화 한다. 
		for (int i = 0; i < m_ivAdverChild.length; i++) {
			m_ivAdverChild[i] = new ImageView(m_Activity);
			m_ivAdverChild[i].setImageResource(R.drawable.img_main_banner_default);
			m_ivAdverChild[i].setScaleType(ScaleType.FIT_XY);
		} 
		//서버로 부터 받은 이미지를 넣음 
		for (int i = 0; i < flipperData.size(); i++) {
			MainBannerData	data = flipperData.get(i);
			URL imageURL;
			try { 
				String	sURL = "";
				imageURL = new URL(sURL);
				HttpURLConnection conn = (HttpURLConnection)imageURL.openConnection();
				BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
				Bitmap bm = BitmapFactory.decodeStream(new FlushedInputStream(bis));
				bis.close();
				m_ivAdverChild[i].setImageBitmap(bm);
			} catch (Exception e) {
				e.printStackTrace();
			} 
		} 
	} 
 
	public void setFlipperImage(){ 
		m_Flipper.removeAllViews();
		for (int i = 0; i < m_ivAdverChild.length; i++) {
			m_Flipper.addView(m_ivAdverChild[i]);
		} 
		initAdverPosition(); 
		m_Handler.sendEmptyMessageDelayed(0, TIME_AUTOROLLING);
	} 
 
	private void setAdverPosition(){ 
		String	sMessage = "" + m_Flipper.getDisplayedChild();
		m_nAdverPosition = Integer.valueOf(sMessage);
		// 
		int			nOrangeDot = R.drawable.img_dot_orange;
		int			nWhiteDot = R.drawable.img_dot_white;
		for (int i = 0; i < m_ivDot.length; i++) {
			m_ivDot[i].setImageResource(nWhiteDot);
		} 
		try { 
			m_ivDot[m_nAdverPosition].setImageResource(nOrangeDot);
		} catch (Exception e) {
			m_Flipper.setDisplayedChild(0);
			setAdverPosition(); 
		} 
	} 
 
	/*------------------------------------------------------------------------- 
	 * get Method define 
	-------------------------------------------------------------------------*/ 
 
 
	/*------------------------------------------------------------------------- 
	 * ETC Method define 
	-------------------------------------------------------------------------*/ 
	private boolean compareAdverRect(MotionEvent event){
		Rect	outRect = new Rect();
		m_Flipper.getGlobalVisibleRect(outRect);	//전체 화면에서 해당하는 View,Layout의 좌표를 px단위로 출력해줌
		if(outRect.contains((int)event.getRawX(), (int)event.getRawY()))
			return true; 
		else 
			return false; 
	} 
 
	private void movePreviousView(){ 
		m_Flipper.setInAnimation(m_slideRightIn);
		m_Flipper.setOutAnimation(m_slideRightOut);
		m_Flipper.showPrevious();
		setAdverPosition(); 
	} 
 
	private void moveNextView(){ 
		m_Flipper.setInAnimation(m_slideLeftIn);
		m_Flipper.setOutAnimation(m_slideLeftOut);
		m_Flipper.showNext();
		setAdverPosition(); 
	} 
 
	/*------------------------------------------------------------------------- 
	 * goTo Method define