1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.cooliris.media; 18 19 import java.util.HashMap; 20 21 import com.cooliris.app.App; 22 23 // CR: this stuff needs comments really badly. 24 public final class DisplaySlot { 25 private MediaSet mSetRef; 26 private String mTitle; 27 private StringTexture mTitleImage; 28 private String mLocation; 29 private StringTexture mLocationImage; 30 31 private static final StringTexture.Config CAPTION_STYLE = new StringTexture.Config(); 32 private static final StringTexture.Config CLUSTER_STYLE = new StringTexture.Config(); 33 private static final StringTexture.Config LOCATION_STYLE = new StringTexture.Config(); 34 35 static { 36 CAPTION_STYLE.sizeMode = StringTexture.Config.SIZE_TEXT_TO_BOUNDS; 37 CAPTION_STYLE.fontSize = 16 * App.PIXEL_DENSITY; 38 CAPTION_STYLE.bold = true; 39 CAPTION_STYLE.width = (App.PIXEL_DENSITY < 1.5f) ? 128 : 256; 40 CAPTION_STYLE.height = (App.PIXEL_DENSITY < 1.5f) ? 32 : 64; 41 CAPTION_STYLE.yalignment = StringTexture.Config.ALIGN_TOP; 42 CAPTION_STYLE.xalignment = StringTexture.Config.ALIGN_HCENTER; 43 44 CLUSTER_STYLE.sizeMode = StringTexture.Config.SIZE_TEXT_TO_BOUNDS; 45 CLUSTER_STYLE.width = (App.PIXEL_DENSITY < 1.5f) ? 128 : 256; 46 CLUSTER_STYLE.height = (App.PIXEL_DENSITY < 1.5f) ? 32 : 64; 47 CLUSTER_STYLE.yalignment = StringTexture.Config.ALIGN_TOP; 48 CLUSTER_STYLE.fontSize = 16 * App.PIXEL_DENSITY; 49 CLUSTER_STYLE.bold = true; 50 CLUSTER_STYLE.xalignment = StringTexture.Config.ALIGN_HCENTER; 51 52 LOCATION_STYLE.sizeMode = StringTexture.Config.SIZE_TEXT_TO_BOUNDS; 53 LOCATION_STYLE.fontSize = 12 * App.PIXEL_DENSITY; 54 LOCATION_STYLE.width = (App.PIXEL_DENSITY < 1.5f) ? 128 : 256; 55 LOCATION_STYLE.height = (App.PIXEL_DENSITY < 1.5f) ? 32 : 64; 56 LOCATION_STYLE.fontSize = 12 * App.PIXEL_DENSITY; 57 LOCATION_STYLE.xalignment = StringTexture.Config.ALIGN_HCENTER; 58 } 59 60 public void setMediaSet(MediaSet set) { 61 mSetRef = set; 62 mTitle = null; 63 mTitleImage = null; 64 mLocationImage = null; 65 if (set.mReverseGeocodedLocation == null) { 66 set.mReverseGeocodedLocationRequestMade = false; 67 set.mReverseGeocodedLocationComputed = false; 68 } 69 } 70 71 public MediaSet getMediaSet() { 72 return mSetRef; 73 } 74 75 public boolean hasValidLocation() { 76 if (mSetRef != null) { 77 return (mSetRef.mReverseGeocodedLocation != null); 78 } else { 79 return false; 80 } 81 } 82 83 private StringTexture getTextureForString(String string, HashMap<String, StringTexture> textureTable, 84 StringTexture.Config config) { 85 StringTexture texture = null; 86 if (textureTable != null && textureTable.containsKey(string)) { 87 texture = textureTable.get(string); 88 } 89 if (texture == null) { 90 texture = new StringTexture(string, config); 91 if (textureTable != null) { 92 textureTable.put(string, texture); 93 } 94 } 95 return texture; 96 } 97 98 public StringTexture getTitleImage(HashMap<String, StringTexture> textureTable) { 99 if (mSetRef == null) { 100 return null; 101 } 102 StringTexture texture = mTitleImage; 103 String title = mSetRef.mTruncTitleString; 104 if (texture == null && title != null && !(title.equals(mTitle))) { 105 texture = getTextureForString(title, textureTable, ((mSetRef.mId != Shared.INVALID && mSetRef.mId != 0) ? CAPTION_STYLE 106 : CLUSTER_STYLE)); 107 mTitleImage = texture; 108 mTitle = title; 109 } 110 return texture; 111 } 112 113 public StringTexture getLocationImage(ReverseGeocoder reverseGeocoder, HashMap<String, StringTexture> textureTable) { 114 if (mSetRef == null || mSetRef.mTitleString == null) { 115 return null; 116 } 117 if (mLocationImage == null) { 118 if (!mSetRef.mReverseGeocodedLocationRequestMade && reverseGeocoder != null) { 119 reverseGeocoder.enqueue(mSetRef); 120 mSetRef.mReverseGeocodedLocationRequestMade = true; 121 } 122 if (mSetRef.mReverseGeocodedLocationComputed) { 123 String geocodedLocation = mSetRef.mReverseGeocodedLocation; 124 if (geocodedLocation != null) { 125 mLocation = geocodedLocation; 126 mLocationImage = getTextureForString(mLocation, textureTable, LOCATION_STYLE); 127 } 128 } 129 } 130 return mLocationImage; 131 } 132 } 133