오늘은 어디로 갈까...

Xlet 배경 이미지 본문

InteractiveTV

Xlet 배경 이미지

剛宇 2009. 9. 3. 18:08
 대충 따라서 구현하면 별로 어려운게 없지만, 원리를 알아내기 위해 오늘도 삽을 들었다. 여기서는 대부분 저수준(?)으로 일일이 그려낸다. 컴포넌트화해서 재사용하면 좋을거 같지만, 여러가지 걸림돌이 있는게 현실이다. havi UI에도 Text 같은 Wiget을 제공하는데, 여기서는 전혀 사용을 안한다. 뭔가 특별한 이유가 있을까...?
 오늘 배경 이미지를 설정하기 위해 피나는 노력을 했지만... 결과는 참혹했다. 영문으로 된 여러 자료들을 분석하여, 구현하였는데, XletView에서 이미지가 안나온다... 제대로 구현한거 같은데... 혹시나 해서 XleTView의 배경 이미지를 제거하고 했더니, 제대로 나온다. 본인의 구현이 잘못된것일까? 에뮬레이터에서 아직 지원을 안하는것일까? 모르는것이 많으니 정확한 판단을 내릴 수가 없다.
 여러 문서를 분석하는 중 찾아 낸 사이트.
http://www.interactivetvweb.org/

 ACAP 기반의 어플을 개발중인데, 포함되어진것 같은 라이브러리가 HAVi UI(Home Audio/Video Interoperability Architecture User Interface)과 JMF(Java Media Framework)

아래는 배경 이미지 바꾸는 소스

package kr.kangwoo.iptv.standard;

import java.util.HashMap;
import java.util.Map;

import org.davic.resources.ResourceClient;
import org.davic.resources.ResourceProxy;
import org.havi.ui.HBackgroundConfigTemplate;
import org.havi.ui.HBackgroundConfiguration;
import org.havi.ui.HBackgroundDevice;
import org.havi.ui.HBackgroundImage;
import org.havi.ui.HScreen;
import org.havi.ui.HStillImageBackgroundConfiguration;
import org.havi.ui.event.HBackgroundImageEvent;
import org.havi.ui.event.HBackgroundImageListener;

public class BackgroundImageManager implements ResourceClient, HBackgroundImageListener {

	private HBackgroundDevice device;
	private HStillImageBackgroundConfiguration imgBgConfig;
	
	private Map imageCache = new HashMap();
	

	public BackgroundImageManager() {
		HBackgroundConfigTemplate configTemplate = new HBackgroundConfigTemplate();
		configTemplate.setPreference(HBackgroundConfigTemplate.STILL_IMAGE, HBackgroundConfigTemplate.REQUIRED);
		
		device = HScreen.getDefaultHScreen().getDefaultHBackgroundDevice();
		
		HBackgroundConfiguration bgConfig = device.getBestConfiguration(configTemplate);
		if (bgConfig instanceof HStillImageBackgroundConfiguration) {
			imgBgConfig = (HStillImageBackgroundConfiguration)bgConfig;
		}
	}

	
	protected HBackgroundImage getHBackgroundImage(final String imgName) {
		HBackgroundImage bgImg = null;
//		bgImg = (HBackgroundImage)imageCache.get(imgName);
		if (bgImg == null) {
			bgImg = new HBackgroundImage(imgName);
			
			bgImg.load(this);

			System.out.println(bgImg + " ^^T");
			imageCache.put(imgName, bgImg);
		}
		return bgImg;
	}
	
	public void imageLoadFailed(
			HBackgroundImageEvent hbackgroundimageevent) {
		System.out.println(" : imageLoadFailed");
	}

	public void imageLoaded(
			HBackgroundImageEvent hbackgroundimageevent) {
		System.out.println(" : imageLoaded");
	}
	
	public void setBackgroundImage(String imgName) {
		device.reserveDevice(this);
		try {
			HBackgroundImage bgImg = getHBackgroundImage(imgName);
			
			if (imgBgConfig != null) {
				imgBgConfig.displayImage(bgImg);	
				System.out.println("imgBgConfig.displayImage(" + bgImg + ") : " + imgName);
			}
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			device.releaseDevice();
		}
	}
	public void notifyRelease(ResourceProxy resourceproxy) {
		device.releaseDevice();
		
	}
	public void release(ResourceProxy resourceproxy) {
		device.releaseDevice();
		
	}
	public boolean requestRelease(ResourceProxy resourceproxy, Object obj) {
		return false;
	}
}


이상한게 이미지를 재사용하면 정상작동을 안하는것 같은데, 이것도 에뮬레이터 버그인가....



위 소스는 잘못 되었다.
다른곳에 구현한것을 보니, getBestConfiguration()을 한다음, 자원 예약해서 setDefaultConfiguration()을 한다.
그리고 이미지를 변경할때는 자원 예약을 안하는것 같은데..
뭐가 맞는지는... 알 수가 없다. --;