StatusBar.java revision d0546353a8ce2d9df5b390d0df967c0ee5eb7ca5
1/* 2 * Copyright (C) 2011 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 17package com.android.layoutlib.bridge.bars; 18 19import com.android.ide.common.rendering.api.LayoutLog; 20import com.android.layoutlib.bridge.Bridge; 21import com.android.layoutlib.bridge.android.BridgeContext; 22import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; 23import com.android.layoutlib.bridge.impl.ParserFactory; 24import com.android.resources.Density; 25 26import org.xmlpull.v1.XmlPullParserException; 27 28import android.graphics.drawable.Drawable; 29import android.view.Gravity; 30import android.view.View; 31import android.widget.ImageView; 32import android.widget.LinearLayout; 33import android.widget.TextView; 34 35import java.io.IOException; 36import java.io.InputStream; 37 38public class StatusBar extends CustomBar { 39 40 private final int mSimulatedPlatformVersion; 41 /** Status bar background color attribute name. */ 42 private static final String ATTR_COLOR = "statusBarColor"; 43 44 public StatusBar(BridgeContext context, Density density, int direction, boolean RtlEnabled, 45 int simulatedPlatformVersion) throws XmlPullParserException { 46 // FIXME: if direction is RTL but it's not enabled in application manifest, mirror this bar. 47 super(context, LinearLayout.HORIZONTAL, "/bars/status_bar.xml", "status_bar.xml", 48 simulatedPlatformVersion); 49 mSimulatedPlatformVersion = simulatedPlatformVersion; 50 51 // FIXME: use FILL_H? 52 setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT); 53 54 int color = getThemeAttrColor(ATTR_COLOR, true); 55 setBackgroundColor(color == 0 ? Config.getStatusBarColor(simulatedPlatformVersion) : color); 56 57 // Cannot access the inside items through id because no R.id values have been 58 // created for them. 59 // We do know the order though. 60 // 0 is the spacer 61 loadIcon(1, "stat_sys_wifi_signal_4_fully." 62 + Config.getWifiIconType(simulatedPlatformVersion), density); 63 loadIcon(2, "stat_sys_battery_100.png", density); 64 setText(3, Config.getTime(simulatedPlatformVersion), false) 65 .setTextColor(Config.getTimeColor(simulatedPlatformVersion)); 66 } 67 68 @Override 69 protected void loadIcon(int index, String iconName, Density density) { 70 if (!iconName.endsWith(".xml")) { 71 super.loadIcon(index, iconName, density); 72 return; 73 } 74 View child = getChildAt(index); 75 if (child instanceof ImageView) { 76 ImageView imageView = (ImageView) child; 77 // The xml is stored only in xhdpi. 78 IconLoader iconLoader = new IconLoader(iconName, Density.XHIGH, 79 mSimulatedPlatformVersion, null); 80 InputStream stream = iconLoader.getIcon(); 81 82 if (stream != null) { 83 try { 84 BridgeXmlBlockParser parser = new BridgeXmlBlockParser( 85 ParserFactory.create(stream, null), (BridgeContext) mContext, true); 86 imageView.setImageDrawable( 87 Drawable.createFromXml(mContext.getResources(), parser)); 88 } catch (XmlPullParserException e) { 89 Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e, 90 null); 91 } catch (IOException e) { 92 Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e, 93 null); 94 } 95 } 96 } 97 } 98 99 @Override 100 protected TextView getStyleableTextView() { 101 return null; 102 } 103} 104