diff --git a/res/layout/preference_batteryhistory.xml b/res/layout/preference_batteryhistory.xml
index c9403c6..86856d7 100644
--- a/res/layout/preference_batteryhistory.xml
+++ b/res/layout/preference_batteryhistory.xml
@@ -23,7 +23,7 @@
     android:gravity="center_vertical"
     android:id="@+android:id/battery_history_chart"
     android:paddingEnd="?android:attr/scrollbarSize"
-    android:textAppearance="?android:attr/textAppearanceMedium"
+    android:textAppearance="?android:attr/textAppearanceSmall"
     app:headerAppearance="?android:attr/textAppearanceMedium"
     android:shadowRadius="4"
     android:shadowColor="?android:attr/colorBackground"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 945dd3d..060ff54 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -185,14 +185,14 @@
 
     <!-- Battery Info screen. Value for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
     <string name="battery_info_status_unknown">Unknown</string>
-    <!-- Battery Info screen. Value for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
+    <!-- [CHAR_LIMIT=20] Battery use screen.  Battery status shown in chart label when charging from an unknown source.  -->
     <string name="battery_info_status_charging">Charging</string>
-    <!-- Battery Info screen. Units shown after a value.  Used for diagnostic info screens, precise translation isn't needed -->
-    <string name="battery_info_status_charging_ac">(AC)</string>
-    <!-- Battery Info screen. Units shown after a value.  Used for diagnostic info screens, precise translation isn't needed -->
-    <string name="battery_info_status_charging_usb">(USB)</string>
-    <!-- Battery Info screen. Units shown after a value.  Used for diagnostic info screens, precise translation isn't needed -->
-    <string name="battery_info_status_charging_wireless">(wireless)</string>
+    <!-- [CHAR_LIMIT=20] Battery use screen.  Battery status shown in chart label when charging on AC.  -->
+    <string name="battery_info_status_charging_ac">Charging on AC</string>
+    <!-- [CHAR_LIMIT=20] Battery use screen.  Battery status shown in chart label when charging over USB.  -->
+    <string name="battery_info_status_charging_usb">Charging over USB</string>
+    <!-- [CHAR_LIMIT=20] Battery use screen.  Battery status shown in chart label when charging over a wireless connection.  -->
+    <string name="battery_info_status_charging_wireless">Charging wirelessly</string>
     <!-- Battery Info screen. Value for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
     <string name="battery_info_status_discharging">Not charging</string>
     <!-- Battery Info screen. Value for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
@@ -2374,7 +2374,7 @@
     <string name="network_scorer_change_active_no_previous_dialog_text" translatable="false">Use <xliff:g id="new_app">%s</xliff:g> as your network scorer?</string>
 
     <!-- The SIM operator is not known [CHAR_ LIMIT=50]-->
-    <string name="mobile_unknown_sim_operator" translatable="true">Uknown SIM operator</string>
+    <string name="mobile_unknown_sim_operator" translatable="true">Unknown SIM operator</string>
 
     <!-- There is no mobile provisiong website for the operator which is the firat parameter [CHAR_ LIMIT=50]-->
     <string name="mobile_no_provisioning_url" translatable="true">%1$s has no known provisioning website</string>
@@ -3551,6 +3551,16 @@
     <string name="battery_stats_phone_signal_label">Mobile network signal</string>
     <!-- Battery usage during last unplugged period -->
     <string name="battery_stats_last_duration">@string/menu_stats_last_unplugged</string>
+    <!-- [CHAR_LIMIT=5] Label for an hour time when using 24 hour mode -->
+    <string name="battery_stats_hour_24_label"><xliff:g id="time">%1$d</xliff:g>:00</string>
+    <!-- [CHAR_LIMIT=5] Label for an hour time when using 12 hour mode in the AM -->
+    <string name="battery_stats_hour_am_label"><xliff:g id="time">%1$d</xliff:g> AM</string>
+    <!-- [CHAR_LIMIT=5] Label for an hour time when using 12 hour mode in the PM -->
+    <string name="battery_stats_hour_pm_label"><xliff:g id="time">%1$d</xliff:g> PM</string>
+    <!-- [CHAR_LIMIT=3] Label for date of day and month (not year) when the day is shown first -->
+    <string name="battery_stats_date_day_first_label"><xliff:g id="day">%1$d</xliff:g>/<xliff:g id="month">%2$d</xliff:g></string>
+    <!-- [CHAR_LIMIT=3] Label for date of day and month (not year) when the month is shown first -->
+    <string name="battery_stats_date_month_first_label"><xliff:g id="month">%2$d</xliff:g>/<xliff:g id="day">%1$d</xliff:g></string>
     <!-- CPU awake time title -->
     <string name="awake">Device awake time</string>
     <!-- Wifi on time -->
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 36e1904..1b64064 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -312,18 +312,17 @@
                 BatteryManager.BATTERY_STATUS_UNKNOWN);
         String statusString;
         if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
-            statusString = res.getString(R.string.battery_info_status_charging);
-            if (plugType > 0) {
-                int resId;
-                if (plugType == BatteryManager.BATTERY_PLUGGED_AC) {
-                    resId = R.string.battery_info_status_charging_ac;
-                } else if (plugType == BatteryManager.BATTERY_PLUGGED_USB) {
-                    resId = R.string.battery_info_status_charging_usb;
-                } else {
-                    resId = R.string.battery_info_status_charging_wireless;
-                }
-                statusString = statusString + " " + res.getString(resId);
+            int resId;
+            if (plugType == BatteryManager.BATTERY_PLUGGED_AC) {
+                resId = R.string.battery_info_status_charging_ac;
+            } else if (plugType == BatteryManager.BATTERY_PLUGGED_USB) {
+                resId = R.string.battery_info_status_charging_usb;
+            } else if (plugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
+                resId = R.string.battery_info_status_charging_wireless;
+            } else {
+                resId = R.string.battery_info_status_charging;
             }
+            statusString = res.getString(resId);
         } else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
             statusString = res.getString(R.string.battery_info_status_discharging);
         } else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
index da6729c..f718b42 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
@@ -17,8 +17,13 @@
 package com.android.settings.fuelgauge;
 
 import android.content.Intent;
+import android.graphics.DashPathEffect;
 import android.os.BatteryManager;
+import android.provider.Settings;
+import android.text.format.DateFormat;
 import android.text.format.Formatter;
+import android.util.Log;
+import android.util.TimeUtils;
 import com.android.settings.R;
 
 import android.content.Context;
@@ -36,8 +41,15 @@
 import android.util.AttributeSet;
 import android.util.TypedValue;
 import android.view.View;
+import libcore.icu.LocaleData;
+
+import java.util.ArrayList;
+import java.util.Calendar;
 
 public class BatteryHistoryChart extends View {
+    static final boolean DEBUG = false;
+    static final String TAG = "BatteryHistoryChart";
+
     static final int CHART_DATA_X_MASK = 0x0000ffff;
     static final int CHART_DATA_BIN_MASK = 0xffff0000;
     static final int CHART_DATA_BIN_SHIFT = 16;
@@ -116,28 +128,35 @@
     final Paint mBatteryGoodPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
     final Paint mBatteryWarnPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
     final Paint mBatteryCriticalPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+    final Paint mTimeRemainPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
     final Paint mChargingPaint = new Paint();
     final Paint mScreenOnPaint = new Paint();
     final Paint mGpsOnPaint = new Paint();
     final Paint mWifiRunningPaint = new Paint();
     final Paint mCpuRunningPaint = new Paint();
+    final Paint mDateLinePaint = new Paint();
     final ChartData mPhoneSignalChart = new ChartData();
     final TextPaint mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
     final TextPaint mHeaderTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
+    final Paint mDebugRectPaint = new Paint();
 
     final Path mBatLevelPath = new Path();
     final Path mBatGoodPath = new Path();
     final Path mBatWarnPath = new Path();
     final Path mBatCriticalPath = new Path();
+    final Path mTimeRemainPath = new Path();
     final Path mChargingPath = new Path();
     final Path mScreenOnPath = new Path();
     final Path mGpsOnPath = new Path();
     final Path mWifiRunningPath = new Path();
     final Path mCpuRunningPath = new Path();
+    final Path mDateLinePath = new Path();
     
     BatteryStats mStats;
     Intent mBatteryBroadcast;
     long mStatsPeriod;
+    String mMaxPercentLabelString;
+    String mMinPercentLabelString;
     String mDurationString;
     String mChargeLabelString;
     String mChargeDurationString;
@@ -153,6 +172,8 @@
     int mTextDescent;
     int mHeaderTextAscent;
     int mHeaderTextDescent;
+    int mMaxPercentLabelStringWidth;
+    int mMinPercentLabelStringWidth;
     int mDurationStringWidth;
     int mChargeLabelStringWidth;
     int mChargeDurationStringWidth;
@@ -160,6 +181,9 @@
 
     boolean mLargeMode;
 
+    int mLastWidth = -1;
+    int mLastHeight = -1;
+
     int mLineWidth;
     int mThinLineWidth;
     int mChargingOffset;
@@ -171,19 +195,29 @@
     int mLevelOffset;
     int mLevelTop;
     int mLevelBottom;
+    int mLevelLeft;
+    int mLevelRight;
     static final int PHONE_SIGNAL_X_MASK = CHART_DATA_X_MASK;
     static final int PHONE_SIGNAL_BIN_MASK = CHART_DATA_BIN_MASK;
     static final int PHONE_SIGNAL_BIN_SHIFT = CHART_DATA_BIN_SHIFT;
     
     int mNumHist;
     long mHistStart;
+    long mHistDataEnd;
     long mHistEnd;
+    long mStartWallTime;
+    long mEndDataWallTime;
+    long mEndWallTime;
+    boolean mDischarging;
     int mBatLow;
     int mBatHigh;
     boolean mHaveWifi;
     boolean mHaveGps;
     boolean mHavePhoneSignal;
 
+    final ArrayList<TimeLabel> mTimeLabels = new ArrayList<TimeLabel>();
+    final ArrayList<DateLabel> mDateLabels = new ArrayList<DateLabel>();
+
     static class TextAttrs {
         ColorStateList textColor = null;
         int textSize = 15;
@@ -273,10 +307,56 @@
         }
     }
 
+    static class TimeLabel {
+        final int x;
+        final String label;
+        final int width;
+
+        TimeLabel(Context context, TextPaint paint, int x, Calendar cal, boolean use24hr) {
+            this.x = x;
+            if (use24hr) {
+                label = context.getString(R.string.battery_stats_hour_24_label,
+                        cal.get(Calendar.HOUR_OF_DAY));
+            } else {
+                int hour = cal.get(Calendar.HOUR);
+                if (hour == 0) {
+                    hour = 12;
+                }
+                if (cal.get(Calendar.AM_PM) == Calendar.AM) {
+                    label = context.getString(R.string.battery_stats_hour_am_label, hour);
+                } else {
+                    label = context.getString(R.string.battery_stats_hour_pm_label, hour);
+                }
+            }
+            width = (int)paint.measureText(label);
+        }
+    }
+
+    static class DateLabel {
+        final int x;
+        final String label;
+        final int width;
+
+        DateLabel(Context context, TextPaint paint, int x, Calendar cal, boolean dayFirst) {
+            this.x = x;
+            if (dayFirst) {
+                label = context.getString(R.string.battery_stats_date_day_first_label,
+                        cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH));
+            } else {
+                label = context.getString(R.string.battery_stats_date_month_first_label,
+                        cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH));
+            }
+            width = (int)paint.measureText(label);
+        }
+    }
+
     public BatteryHistoryChart(Context context, AttributeSet attrs) {
         super(context, attrs);
         
-        mBatteryBackgroundPaint.setARGB(255, 128, 128, 128);
+        mThinLineWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+                2, getResources().getDisplayMetrics());
+
+        mBatteryBackgroundPaint.setColor(0xff263238);
         mBatteryBackgroundPaint.setStyle(Paint.Style.FILL);
         mBatteryGoodPaint.setARGB(128, 0, 255, 0);
         mBatteryGoodPaint.setStyle(Paint.Style.STROKE);
@@ -284,6 +364,8 @@
         mBatteryWarnPaint.setStyle(Paint.Style.STROKE);
         mBatteryCriticalPaint.setARGB(192, 255, 0, 0);
         mBatteryCriticalPaint.setStyle(Paint.Style.STROKE);
+        mTimeRemainPaint.setColor(0xffA5B1B7);
+        mTimeRemainPaint.setStyle(Paint.Style.FILL);
         mChargingPaint.setARGB(255, 0, 128, 0);
         mChargingPaint.setStyle(Paint.Style.STROKE);
         mScreenOnPaint.setStyle(Paint.Style.STROKE);
@@ -294,7 +376,9 @@
                 0x00000000, 0xffa00000, 0xffa07000, 0xffa0a000,
                 0xff80a000, 0xff409000, 0xff008000
         });
-        
+        mDebugRectPaint.setARGB(255, 255, 0, 0);
+        mDebugRectPaint.setStyle(Paint.Style.STROKE);
+
         TypedArray a =
             context.obtainStyledAttributes(
                 attrs, R.styleable.BatteryHistoryChart, 0, 0);
@@ -355,12 +439,22 @@
         mainTextAttrs.apply(context, mTextPaint);
         headTextAttrs.apply(context, mHeaderTextPaint);
 
+        mDateLinePaint.set(mTextPaint);
+        mDateLinePaint.setStyle(Paint.Style.STROKE);
+        int hairlineWidth = mThinLineWidth/2;
+        if (hairlineWidth < 1) {
+            hairlineWidth = 1;
+        }
+        mDateLinePaint.setStrokeWidth(hairlineWidth);
+        mDateLinePaint.setPathEffect(new DashPathEffect(new float[] {
+                mThinLineWidth * 2, mThinLineWidth * 2 }, 0));
+
         if (shadowcolor != 0) {
             mTextPaint.setShadowLayer(r, dx, dy, shadowcolor);
             mHeaderTextPaint.setShadowLayer(r, dx, dy, shadowcolor);
         }
     }
-    
+
     void setStats(BatteryStats stats, Intent broadcast) {
         mStats = stats;
         mBatteryBroadcast = broadcast;
@@ -376,50 +470,21 @@
         mWifiRunningLabel = getContext().getString(R.string.battery_stats_wifi_running_label);
         mCpuRunningLabel = getContext().getString(R.string.battery_stats_wake_lock_label);
         mPhoneSignalLabel = getContext().getString(R.string.battery_stats_phone_signal_label);
-        
-        int pos = 0;
-        int lastInteresting = 0;
-        byte lastLevel = -1;
-        mBatLow = 0;
-        mBatHigh = 100;
-        int aggrStates = 0;
-        boolean first = true;
-        if (stats.startIteratingHistoryLocked()) {
-            final HistoryItem rec = new HistoryItem();
-            while (stats.getNextHistoryLocked(rec)) {
-                pos++;
-                if (rec.isDeltaData()) {
-                    if (first) {
-                        first = false;
-                        mHistStart = rec.time;
-                    }
-                    if (rec.batteryLevel != lastLevel || pos == 1) {
-                        lastLevel = rec.batteryLevel;
-                    }
-                    lastInteresting = pos;
-                    mHistEnd = rec.time;
-                    aggrStates |= rec.states;
-                }
-            }
-        }
-        mNumHist = lastInteresting;
-        mHaveGps = (aggrStates&HistoryItem.STATE_GPS_ON_FLAG) != 0;
-        mHaveWifi = (aggrStates&HistoryItem.STATE_WIFI_RUNNING_FLAG) != 0;
-        if (!com.android.settings.Utils.isWifiOnly(getContext())) {
-            mHavePhoneSignal = true;
-        }
-        if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1;
 
-        //String durationString = Utils.formatElapsedTime(getContext(), mStatsPeriod / 1000, true);
-        //mDurationString = getContext().getString(R.string.battery_stats_on_battery,
-        //        durationString);
-        mDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart, true);
+        mMaxPercentLabelString = getContext().getResources().getString(
+                R.string.percentage, 100);
+        mMinPercentLabelString = getContext().getResources().getString(
+                R.string.percentage, 0);
+
         int batteryLevel = com.android.settings.Utils.getBatteryLevel(mBatteryBroadcast);
         final int status = mBatteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS,
                 BatteryManager.BATTERY_STATUS_UNKNOWN);
+        long remainingTimeUs = 0;
+        mDischarging = true;
         if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
             final long drainTime = mStats.computeBatteryTimeRemaining(elapsedRealtimeUs);
             if (drainTime > 0) {
+                remainingTimeUs = drainTime;
                 String timeString = Formatter.formatShortElapsedTime(getContext(),
                         drainTime / 1000);
                 mChargeLabelString = getContext().getResources().getString(
@@ -433,6 +498,8 @@
             final String statusLabel = com.android.settings.Utils.getBatteryStatus(getResources(),
                     mBatteryBroadcast);
             if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
+                mDischarging = false;
+                remainingTimeUs = chargeTime;
                 String timeString = Formatter.formatShortElapsedTime(getContext(),
                         chargeTime / 1000);
                 mChargeLabelString = getContext().getResources().getString(
@@ -444,11 +511,69 @@
         }
         mDrainString = "";
         mChargeDurationString = "";
+
+        int pos = 0;
+        int lastInteresting = 0;
+        byte lastLevel = -1;
+        mBatLow = 0;
+        mBatHigh = 100;
+        mStartWallTime = 0;
+        mEndDataWallTime = 0;
+        mEndWallTime = 0;
+        mHistStart = 0;
+        mHistEnd = 0;
+        long lastWallTime = 0;
+        long lastRealtime = 0;
+        int aggrStates = 0;
+        boolean first = true;
+        if (stats.startIteratingHistoryLocked()) {
+            final HistoryItem rec = new HistoryItem();
+            while (stats.getNextHistoryLocked(rec)) {
+                pos++;
+                if (first) {
+                    first = false;
+                    mHistStart = rec.time;
+                }
+                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
+                        || rec.cmd == HistoryItem.CMD_RESET) {
+                    lastWallTime = rec.currentTime;
+                    lastRealtime = rec.time;
+                    if (mStartWallTime == 0) {
+                        mStartWallTime = lastWallTime;
+                    }
+                }
+                if (rec.isDeltaData()) {
+                    if (rec.batteryLevel != lastLevel || pos == 1) {
+                        lastLevel = rec.batteryLevel;
+                    }
+                    lastInteresting = pos;
+                    mHistDataEnd = rec.time;
+                    aggrStates |= rec.states;
+                }
+            }
+        }
+        mHistEnd = mHistDataEnd + (remainingTimeUs/1000);
+        mEndDataWallTime = lastWallTime + mHistDataEnd - lastRealtime;
+        mEndWallTime = mEndDataWallTime + (remainingTimeUs/1000);
+        mNumHist = lastInteresting;
+        mHaveGps = (aggrStates&HistoryItem.STATE_GPS_ON_FLAG) != 0;
+        mHaveWifi = (aggrStates&HistoryItem.STATE_WIFI_RUNNING_FLAG) != 0;
+        if (!com.android.settings.Utils.isWifiOnly(getContext())) {
+            mHavePhoneSignal = true;
+        }
+        if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1;
+
+        //String durationString = Utils.formatElapsedTime(getContext(), mStatsPeriod / 1000, true);
+        //mDurationString = getContext().getString(R.string.battery_stats_on_battery,
+        //        durationString);
+        mDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart, true);
     }
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+        mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
+        mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
         mDurationStringWidth = (int)mTextPaint.measureText(mDurationString);
         mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
         mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mChargeLabelString);
@@ -493,15 +618,51 @@
             mPhoneSignalChart.finish(w);
         }
     }
-    
+
+    private boolean is24Hour() {
+        return DateFormat.is24HourFormat(getContext());
+    }
+
+    private boolean isDayFirst() {
+        String value = Settings.System.getString(mContext.getContentResolver(),
+                Settings.System.DATE_FORMAT);
+        if (value == null) {
+            LocaleData d = LocaleData.get(mContext.getResources().getConfiguration().locale);
+            value = d.shortDateFormat4;
+        }
+        return value.indexOf('M') > value.indexOf('d');
+    }
+
+    /*
+    private void buildTime() {
+        java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(context);
+        final Calendar now = Calendar.getInstance();
+        mDummyDate.setTimeZone(now.getTimeZone());
+        // We use December 31st because it's unambiguous when demonstrating the date format.
+        // We use 13:00 so we can demonstrate the 12/24 hour options.
+        mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
+        Date dummyDate = mDummyDate.getTime();
+        mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now.getTime()));
+        mTimeZone.setSummary(getTimeZoneText(now.getTimeZone(), true));
+        mDatePref.setSummary(shortDateFormat.format(now.getTime()));
+        mDateFormat.setSummary(shortDateFormat.format(dummyDate));
+        mTime24Pref.setSummary(DateFormat.getTimeFormat(getActivity()).format(dummyDate));
+
+    }
+    */
+
     @Override
     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
         super.onSizeChanged(w, h, oldw, oldh);
-        
+
+        if (DEBUG) Log.d(TAG, "onSizeChanged: " + oldw + "x" + oldh + " to " + w + "x" + h);
+
+        if (mLastWidth == w && mLastHeight == h) {
+            return;
+        }
+
         int textHeight = mTextDescent - mTextAscent;
         int headerTextHeight = mHeaderTextDescent - mHeaderTextAscent;
-        mThinLineWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
-                2, getResources().getDisplayMetrics());
         if (h > (textHeight*12)) {
             mLargeMode = true;
             if (h > (textHeight*15)) {
@@ -511,7 +672,6 @@
                 // Compress lines to make more room for chart.
                 mLineWidth = textHeight/3;
             }
-            mLevelTop = headerTextHeight*2 + mLineWidth;
             mScreenOnPaint.setARGB(255, 32, 64, 255);
             mGpsOnPaint.setARGB(255, 32, 64, 255);
             mWifiRunningPaint.setARGB(255, 32, 64, 255);
@@ -519,13 +679,18 @@
         } else {
             mLargeMode = false;
             mLineWidth = mThinLineWidth;
-            mLevelTop = headerTextHeight*2 + mLineWidth;
             mScreenOnPaint.setARGB(255, 0, 0, 255);
             mGpsOnPaint.setARGB(255, 0, 0, 255);
             mWifiRunningPaint.setARGB(255, 0, 0, 255);
             mCpuRunningPaint.setARGB(255, 0, 0, 255);
         }
         if (mLineWidth <= 0) mLineWidth = 1;
+
+        mLevelTop = headerTextHeight*2 - mTextAscent;
+        mLevelLeft = mMaxPercentLabelStringWidth + mThinLineWidth*3;
+        mLevelRight = w;
+        int levelWidth = mLevelRight-mLevelLeft;
+
         mTextPaint.setStrokeWidth(mThinLineWidth);
         mBatteryGoodPaint.setStrokeWidth(mThinLineWidth);
         mBatteryWarnPaint.setStrokeWidth(mThinLineWidth);
@@ -535,26 +700,26 @@
         mGpsOnPaint.setStrokeWidth(mLineWidth);
         mWifiRunningPaint.setStrokeWidth(mLineWidth);
         mCpuRunningPaint.setStrokeWidth(mLineWidth);
+        mDebugRectPaint.setStrokeWidth(1);
+
+        int fullBarOffset = textHeight + mLineWidth;
 
         if (mLargeMode) {
-            int barOffset = textHeight + mLineWidth;
             mChargingOffset = mLineWidth;
-            mScreenOnOffset = mChargingOffset + barOffset;
-            mCpuRunningOffset = mScreenOnOffset + barOffset;
-            mWifiRunningOffset = mCpuRunningOffset + barOffset;
-            mGpsOnOffset = mWifiRunningOffset + (mHaveWifi ? barOffset : 0);
-            mPhoneSignalOffset = mGpsOnOffset + (mHaveGps ? barOffset : 0);
-            mLevelOffset = mPhoneSignalOffset + (mHavePhoneSignal ? barOffset : 0)
-                    + ((mLineWidth*3)/2);
+            mScreenOnOffset = mChargingOffset + fullBarOffset;
+            mCpuRunningOffset = mScreenOnOffset + fullBarOffset;
+            mWifiRunningOffset = mCpuRunningOffset + fullBarOffset;
+            mGpsOnOffset = mWifiRunningOffset + (mHaveWifi ? fullBarOffset : 0);
+            mPhoneSignalOffset = mGpsOnOffset + (mHaveGps ? fullBarOffset : 0);
+            mLevelOffset = mPhoneSignalOffset + (mHavePhoneSignal ? fullBarOffset : 0)
+                    + mLineWidth*2 + mLineWidth/2;
             if (mHavePhoneSignal) {
                 mPhoneSignalChart.init(w);
             }
         } else {
             mScreenOnOffset = mGpsOnOffset = mWifiRunningOffset
-                    = mCpuRunningOffset = mLineWidth;
-            mChargingOffset = mLineWidth*2;
-            mPhoneSignalOffset = 0;
-            mLevelOffset = mLineWidth*3;
+                    = mCpuRunningOffset = mChargingOffset = mPhoneSignalOffset = 0;
+            mLevelOffset = fullBarOffset + mThinLineWidth*4;
             if (mHavePhoneSignal) {
                 mPhoneSignalChart.init(0);
             }
@@ -563,23 +728,26 @@
         mBatLevelPath.reset();
         mBatGoodPath.reset();
         mBatWarnPath.reset();
+        mTimeRemainPath.reset();
         mBatCriticalPath.reset();
         mScreenOnPath.reset();
         mGpsOnPath.reset();
         mWifiRunningPath.reset();
         mCpuRunningPath.reset();
         mChargingPath.reset();
-        
-        final long timeStart = mHistStart;
-        final long timeChange = mHistEnd-mHistStart;
-        
+
+        final long walltimeStart = mStartWallTime;
+        final long walltimeChange = mEndWallTime-walltimeStart;
+        long curWalltime = 0;
+        long lastRealtime = 0;
+
         final int batLow = mBatLow;
         final int batChange = mBatHigh-mBatLow;
-        
+
         final int levelh = h - mLevelOffset - mLevelTop;
         mLevelBottom = mLevelTop + levelh;
-        
-        int x = 0, y = 0, startX = 0, lastX = -1, lastY = -1;
+
+        int x = mLevelLeft, y = 0, startX = mLevelLeft, lastX = -1, lastY = -1;
         int i = 0;
         Path curLevelPath = null;
         Path lastLinePath = null;
@@ -589,8 +757,25 @@
         if (mStats.startIteratingHistoryLocked()) {
             final HistoryItem rec = new HistoryItem();
             while (mStats.getNextHistoryLocked(rec) && i < N) {
-                if (rec.isDeltaData()) {
-                    x = (int)(((rec.time-timeStart)*w)/timeChange);
+                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
+                    curWalltime = rec.currentTime;
+                    lastRealtime = rec.time;
+                } else if (curWalltime != 0) {
+                    curWalltime += rec.time-lastRealtime;
+                    lastRealtime = rec.time;
+                }
+                if (curWalltime != 0 && rec.isDeltaData()) {
+                    x = mLevelLeft + (int)(((curWalltime-walltimeStart)*levelWidth)/walltimeChange);
+                    if (false) {
+                        StringBuilder sb = new StringBuilder(128);
+                        sb.append("walloff=");
+                        TimeUtils.formatDuration(curWalltime - walltimeStart, sb);
+                        sb.append(" wallchange=");
+                        TimeUtils.formatDuration(walltimeChange, sb);
+                        sb.append(" x=");
+                        sb.append(x);
+                        Log.d("foo", sb.toString());
+                    }
                     y = mLevelTop + levelh - ((rec.batteryLevel-batLow)*(levelh-1))/batChange;
 
                     if (lastX != x) {
@@ -625,78 +810,81 @@
                         }
                     }
 
-                    final boolean charging =
-                        (rec.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) != 0;
-                    if (charging != lastCharging) {
-                        if (charging) {
-                            mChargingPath.moveTo(x, h-mChargingOffset);
-                        } else {
-                            mChargingPath.lineTo(x, h-mChargingOffset);
+                    if (mLargeMode) {
+                        final boolean charging =
+                            (rec.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) != 0;
+                        if (charging != lastCharging) {
+                            if (charging) {
+                                mChargingPath.moveTo(x, h-mChargingOffset);
+                            } else {
+                                mChargingPath.lineTo(x, h-mChargingOffset);
+                            }
+                            lastCharging = charging;
                         }
-                        lastCharging = charging;
+
+                        final boolean screenOn =
+                            (rec.states&HistoryItem.STATE_SCREEN_ON_FLAG) != 0;
+                        if (screenOn != lastScreenOn) {
+                            if (screenOn) {
+                                mScreenOnPath.moveTo(x, h-mScreenOnOffset);
+                            } else {
+                                mScreenOnPath.lineTo(x, h-mScreenOnOffset);
+                            }
+                            lastScreenOn = screenOn;
+                        }
+
+                        final boolean gpsOn =
+                            (rec.states&HistoryItem.STATE_GPS_ON_FLAG) != 0;
+                        if (gpsOn != lastGpsOn) {
+                            if (gpsOn) {
+                                mGpsOnPath.moveTo(x, h-mGpsOnOffset);
+                            } else {
+                                mGpsOnPath.lineTo(x, h-mGpsOnOffset);
+                            }
+                            lastGpsOn = gpsOn;
+                        }
+
+                        final boolean wifiRunning =
+                            (rec.states&HistoryItem.STATE_WIFI_RUNNING_FLAG) != 0;
+                        if (wifiRunning != lastWifiRunning) {
+                            if (wifiRunning) {
+                                mWifiRunningPath.moveTo(x, h-mWifiRunningOffset);
+                            } else {
+                                mWifiRunningPath.lineTo(x, h-mWifiRunningOffset);
+                            }
+                            lastWifiRunning = wifiRunning;
+                        }
+
+                        final boolean cpuRunning =
+                            (rec.states&HistoryItem.STATE_CPU_RUNNING_FLAG) != 0;
+                        if (cpuRunning != lastCpuRunning) {
+                            if (cpuRunning) {
+                                mCpuRunningPath.moveTo(x, h - mCpuRunningOffset);
+                            } else {
+                                mCpuRunningPath.lineTo(x, h - mCpuRunningOffset);
+                            }
+                            lastCpuRunning = cpuRunning;
+                        }
+
+                        if (mLargeMode && mHavePhoneSignal) {
+                            int bin;
+                            if (((rec.states&HistoryItem.STATE_PHONE_STATE_MASK)
+                                    >> HistoryItem.STATE_PHONE_STATE_SHIFT)
+                                    == ServiceState.STATE_POWER_OFF) {
+                                bin = 0;
+                            } else if ((rec.states&HistoryItem.STATE_PHONE_SCANNING_FLAG) != 0) {
+                                bin = 1;
+                            } else {
+                                bin = (rec.states&HistoryItem.STATE_SIGNAL_STRENGTH_MASK)
+                                        >> HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT;
+                                bin += 2;
+                            }
+                            mPhoneSignalChart.addTick(x, bin);
+                        }
                     }
 
-                    final boolean screenOn =
-                        (rec.states&HistoryItem.STATE_SCREEN_ON_FLAG) != 0;
-                    if (screenOn != lastScreenOn) {
-                        if (screenOn) {
-                            mScreenOnPath.moveTo(x, h-mScreenOnOffset);
-                        } else {
-                            mScreenOnPath.lineTo(x, h-mScreenOnOffset);
-                        }
-                        lastScreenOn = screenOn;
-                    }
-
-                    final boolean gpsOn =
-                        (rec.states&HistoryItem.STATE_GPS_ON_FLAG) != 0;
-                    if (gpsOn != lastGpsOn) {
-                        if (gpsOn) {
-                            mGpsOnPath.moveTo(x, h-mGpsOnOffset);
-                        } else {
-                            mGpsOnPath.lineTo(x, h-mGpsOnOffset);
-                        }
-                        lastGpsOn = gpsOn;
-                    }
-
-                    final boolean wifiRunning =
-                        (rec.states&HistoryItem.STATE_WIFI_RUNNING_FLAG) != 0;
-                    if (wifiRunning != lastWifiRunning) {
-                        if (wifiRunning) {
-                            mWifiRunningPath.moveTo(x, h-mWifiRunningOffset);
-                        } else {
-                            mWifiRunningPath.lineTo(x, h-mWifiRunningOffset);
-                        }
-                        lastWifiRunning = wifiRunning;
-                    }
-
-                    final boolean cpuRunning =
-                        (rec.states&HistoryItem.STATE_CPU_RUNNING_FLAG) != 0;
-                    if (cpuRunning != lastCpuRunning) {
-                        if (cpuRunning) {
-                            mCpuRunningPath.moveTo(x, h - mCpuRunningOffset);
-                        } else {
-                            mCpuRunningPath.lineTo(x, h - mCpuRunningOffset);
-                        }
-                        lastCpuRunning = cpuRunning;
-                    }
-
-                    if (mLargeMode && mHavePhoneSignal) {
-                        int bin;
-                        if (((rec.states&HistoryItem.STATE_PHONE_STATE_MASK)
-                                >> HistoryItem.STATE_PHONE_STATE_SHIFT)
-                                == ServiceState.STATE_POWER_OFF) {
-                            bin = 0;
-                        } else if ((rec.states&HistoryItem.STATE_PHONE_SCANNING_FLAG) != 0) {
-                            bin = 1;
-                        } else {
-                            bin = (rec.states&HistoryItem.STATE_SIGNAL_STRENGTH_MASK)
-                                    >> HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT;
-                            bin += 2;
-                        }
-                        mPhoneSignalChart.addTick(x, bin);
-                    }
-
-                } else if (rec.cmd != BatteryStats.HistoryItem.CMD_OVERFLOW) {
+                } else if (rec.cmd != HistoryItem.CMD_OVERFLOW
+                        && rec.cmd != HistoryItem.CMD_CURRENT_TIME) {
                     if (curLevelPath != null) {
                         finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX,
                                 lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning,
@@ -711,83 +899,241 @@
                 i++;
             }
         }
-        
-        finishPaths(w, h, levelh, startX, lastY, curLevelPath, lastX,
+
+        // Figure out where the actual data ends on the screen.
+        x = mLevelLeft + (int)(((mEndDataWallTime-walltimeStart)*levelWidth)/walltimeChange);
+
+        finishPaths(x, h, levelh, startX, lastY, curLevelPath, lastX,
                 lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning,
                 lastCpuRunning, lastLinePath);
+
+        if (x < w) {
+            // If we reserved room for the remaining time, create a final path to draw
+            // that part of the UI.
+            mTimeRemainPath.moveTo(x, lastY);
+            int fullY = mLevelTop + levelh - ((100-batLow)*(levelh-1))/batChange;
+            int emptyY = mLevelTop + levelh - ((0-batLow)*(levelh-1))/batChange;
+            if (mDischarging) {
+                mTimeRemainPath.lineTo(mLevelRight, emptyY);
+            } else {
+                mTimeRemainPath.lineTo(mLevelRight, fullY);
+                mTimeRemainPath.lineTo(mLevelRight, emptyY);
+            }
+            mTimeRemainPath.lineTo(x, emptyY);
+            mTimeRemainPath.close();
+        }
+
+        // Create the time labels at the bottom.
+        mTimeLabels.clear();
+        boolean is24hr = is24Hour();
+        Calendar calStart = Calendar.getInstance();
+        calStart.setTimeInMillis(mStartWallTime);
+        calStart.set(Calendar.MILLISECOND, 0);
+        calStart.set(Calendar.SECOND, 0);
+        calStart.set(Calendar.MINUTE, 0);
+        long startRoundTime = calStart.getTimeInMillis();
+        if (startRoundTime < mStartWallTime) {
+            calStart.set(Calendar.HOUR_OF_DAY, calStart.get(Calendar.HOUR_OF_DAY)+1);
+            startRoundTime = calStart.getTimeInMillis();
+        }
+        Calendar calEnd = Calendar.getInstance();
+        calEnd.setTimeInMillis(mEndWallTime);
+        calEnd.set(Calendar.MILLISECOND, 0);
+        calEnd.set(Calendar.SECOND, 0);
+        calEnd.set(Calendar.MINUTE, 0);
+        long endRoundTime = calEnd.getTimeInMillis();
+        if (startRoundTime < endRoundTime) {
+            addTimeLabel(calStart, mLevelLeft, mLevelRight, is24hr);
+            Calendar calMid = Calendar.getInstance();
+            calMid.setTimeInMillis(mStartWallTime+((mEndWallTime-mStartWallTime)/2));
+            calMid.set(Calendar.MILLISECOND, 0);
+            calMid.set(Calendar.SECOND, 0);
+            calMid.set(Calendar.MINUTE, 0);
+            long calMidMillis = calMid.getTimeInMillis();
+            if (calMidMillis > startRoundTime && calMidMillis < endRoundTime) {
+                addTimeLabel(calMid, mLevelLeft, mLevelRight, is24hr);
+            }
+            addTimeLabel(calEnd, mLevelLeft, mLevelRight, is24hr);
+        }
+
+        // Create the date labels if the chart includes multiple days
+        mDateLabels.clear();
+        if (calStart.get(Calendar.DAY_OF_YEAR) != calEnd.get(Calendar.DAY_OF_YEAR) ||
+                calStart.get(Calendar.YEAR) != calEnd.get(Calendar.YEAR)) {
+            boolean isDayFirst = isDayFirst();
+            calStart.set(Calendar.HOUR_OF_DAY, 0);
+            startRoundTime = calStart.getTimeInMillis();
+            if (startRoundTime < mStartWallTime) {
+                calStart.set(Calendar.DAY_OF_YEAR, calStart.get(Calendar.DAY_OF_YEAR) + 1);
+                startRoundTime = calStart.getTimeInMillis();
+            }
+            calEnd.set(Calendar.HOUR_OF_DAY, 0);
+            endRoundTime = calEnd.getTimeInMillis();
+            if (startRoundTime < endRoundTime) {
+                addDateLabel(calStart, mLevelLeft, mLevelRight, isDayFirst);
+            }
+            addDateLabel(calEnd, mLevelLeft, mLevelRight, isDayFirst);
+        }
     }
-    
+
+    void addTimeLabel(Calendar cal, int levelLeft, int levelRight, boolean is24hr) {
+        final long walltimeStart = mStartWallTime;
+        final long walltimeChange = mEndWallTime-walltimeStart;
+        mTimeLabels.add(new TimeLabel(getContext(), mTextPaint,
+                levelLeft + (int)(((cal.getTimeInMillis()-walltimeStart)*(levelRight-levelLeft))
+                        / walltimeChange),
+                cal, is24hr));
+    }
+
+    void addDateLabel(Calendar cal, int levelLeft, int levelRight, boolean isDayFirst) {
+        final long walltimeStart = mStartWallTime;
+        final long walltimeChange = mEndWallTime-walltimeStart;
+        mDateLabels.add(new DateLabel(getContext(), mTextPaint,
+                levelLeft + (int)(((cal.getTimeInMillis()-walltimeStart)*(levelRight-levelLeft))
+                        / walltimeChange),
+                cal, isDayFirst));
+    }
+
     @Override
     protected void onDraw(Canvas canvas) {
         super.onDraw(canvas);
 
         final int width = getWidth();
         final int height = getHeight();
+
+        if (DEBUG) Log.d(TAG, "onDraw: " + width + "x" + height);
+
         final boolean layoutRtl = isLayoutRtl();
         final int textStartX = layoutRtl ? width : 0;
         final int textEndX = layoutRtl ? 0 : width;
         final Paint.Align textAlignLeft = layoutRtl ? Paint.Align.RIGHT : Paint.Align.LEFT;
         final Paint.Align textAlignRight = layoutRtl ? Paint.Align.LEFT : Paint.Align.RIGHT;
-        mTextPaint.setTextAlign(textAlignLeft);
 
-        canvas.drawPath(mBatLevelPath, mBatteryBackgroundPaint);
-        int durationHalfWidth = mDurationStringWidth / 2;
-        if (layoutRtl) durationHalfWidth = -durationHalfWidth;
-        if (mLargeMode) {
-            canvas.drawText(mDurationString, (width / 2) - durationHalfWidth,
-                    mLevelBottom - mTextAscent + mThinLineWidth, mTextPaint);
-        } else {
-            canvas.drawText(mDurationString, (width / 2) - durationHalfWidth,
-                    mLevelTop + ((height-mLevelTop) / 2) - ((mTextDescent - mTextAscent) / 2)
-                            - mTextAscent, mTextPaint);
+        if (DEBUG) {
+            canvas.drawRect(1, 1, width, height, mDebugRectPaint);
         }
 
-        int headerTop = mLevelTop/2 + (mHeaderTextDescent-mHeaderTextAscent)/2;
+        if (DEBUG) Log.d(TAG, "Drawing level path.");
+        canvas.drawPath(mBatLevelPath, mBatteryBackgroundPaint);
+        if (!mTimeRemainPath.isEmpty()) {
+            if (DEBUG) Log.d(TAG, "Drawing time remain path.");
+            canvas.drawPath(mTimeRemainPath, mTimeRemainPaint);
+        }
+        int durationHalfWidth = mDurationStringWidth / 2;
+        if (layoutRtl) durationHalfWidth = -durationHalfWidth;
+        if (mTimeLabels.size() > 0) {
+            int y = mLevelBottom - mTextAscent + (mThinLineWidth*4);
+            int ytick = mLevelBottom+mThinLineWidth+(mThinLineWidth/2);
+            mTextPaint.setTextAlign(Paint.Align.LEFT);
+            int lastX = 0;
+            for (int i=0; i<mTimeLabels.size(); i++) {
+                TimeLabel label = mTimeLabels.get(i);
+                if (i == 0) {
+                    int x = label.x - label.width/2;
+                    if (x < 0) {
+                        x = 0;
+                    }
+                    if (DEBUG) Log.d(TAG, "Drawing left label: " + label.label + " @ " + x);
+                    canvas.drawText(label.label, x, y, mTextPaint);
+                    canvas.drawLine(label.x, ytick, label.x, ytick+mThinLineWidth, mTextPaint);
+                    lastX = x + label.width;
+                } else if (i < (mTimeLabels.size()-1)) {
+                    int x = label.x - label.width/2;
+                    if (x < (lastX+mTextAscent)) {
+                        continue;
+                    }
+                    TimeLabel nextLabel = mTimeLabels.get(i+1);
+                    if (x > (width-nextLabel.width-mTextAscent)) {
+                        continue;
+                    }
+                    if (DEBUG) Log.d(TAG, "Drawing middle label: " + label.label + " @ " + x);
+                    canvas.drawText(label.label, x, y, mTextPaint);
+                    canvas.drawLine(label.x, ytick, label.x, ytick + mThinLineWidth, mTextPaint);
+                    lastX = x + label.width;
+                } else {
+                    int x = label.x - label.width/2;
+                    if ((x+label.width) >= width) {
+                        x = width-1-label.width;
+                    }
+                    if (DEBUG) Log.d(TAG, "Drawing right label: " + label.label + " @ " + x);
+                    canvas.drawText(label.label, x, y, mTextPaint);
+                    canvas.drawLine(label.x, ytick, label.x, ytick+mThinLineWidth, mTextPaint);
+                }
+            }
+        }
+
+        if (false) {
+            // Old code for printing label.
+            mTextPaint.setTextAlign(textAlignLeft);
+            if (mLargeMode) {
+                canvas.drawText(mDurationString, (width / 2) - durationHalfWidth,
+                        mLevelBottom - mTextAscent + mThinLineWidth, mTextPaint);
+            } else {
+                canvas.drawText(mDurationString, (width / 2) - durationHalfWidth,
+                        mLevelTop + ((height-mLevelTop) / 2) - ((mTextDescent - mTextAscent) / 2)
+                                - mTextAscent, mTextPaint);
+            }
+        }
+
+        int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
         mHeaderTextPaint.setTextAlign(textAlignLeft);
+        if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mChargeLabelString);
         canvas.drawText(mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
         durationHalfWidth = mChargeDurationStringWidth / 2;
         if (layoutRtl) durationHalfWidth = -durationHalfWidth;
         int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
                 + (layoutRtl ? mDrainStringWidth : mChargeLabelStringWidth);
+        if (DEBUG) Log.d(TAG, "Drawing charge duration string: " + mChargeDurationString);
         canvas.drawText(mChargeDurationString, headerCenter - durationHalfWidth, headerTop,
                 mHeaderTextPaint);
         mHeaderTextPaint.setTextAlign(textAlignRight);
+        if (DEBUG) Log.d(TAG, "Drawing drain string: " + mDrainString);
         canvas.drawText(mDrainString, textEndX, headerTop, mHeaderTextPaint);
 
         if (!mBatGoodPath.isEmpty()) {
+            if (DEBUG) Log.d(TAG, "Drawing good battery path");
             canvas.drawPath(mBatGoodPath, mBatteryGoodPaint);
         }
         if (!mBatWarnPath.isEmpty()) {
+            if (DEBUG) Log.d(TAG, "Drawing warn battery path");
             canvas.drawPath(mBatWarnPath, mBatteryWarnPaint);
         }
         if (!mBatCriticalPath.isEmpty()) {
+            if (DEBUG) Log.d(TAG, "Drawing critical battery path");
             canvas.drawPath(mBatCriticalPath, mBatteryCriticalPaint);
         }
         if (mHavePhoneSignal) {
+            if (DEBUG) Log.d(TAG, "Drawing phone signal path");
             int top = height-mPhoneSignalOffset - (mLineWidth/2);
             mPhoneSignalChart.draw(canvas, top, mLineWidth);
         }
         if (!mScreenOnPath.isEmpty()) {
+            if (DEBUG) Log.d(TAG, "Drawing screen on path");
             canvas.drawPath(mScreenOnPath, mScreenOnPaint);
         }
         if (!mChargingPath.isEmpty()) {
+            if (DEBUG) Log.d(TAG, "Drawing charging path");
             canvas.drawPath(mChargingPath, mChargingPaint);
         }
         if (mHaveGps) {
             if (!mGpsOnPath.isEmpty()) {
+                if (DEBUG) Log.d(TAG, "Drawing gps path");
                 canvas.drawPath(mGpsOnPath, mGpsOnPaint);
             }
         }
         if (mHaveWifi) {
             if (!mWifiRunningPath.isEmpty()) {
+                if (DEBUG) Log.d(TAG, "Drawing wifi path");
                 canvas.drawPath(mWifiRunningPath, mWifiRunningPaint);
             }
         }
         if (!mCpuRunningPath.isEmpty()) {
+            if (DEBUG) Log.d(TAG, "Drawing running path");
             canvas.drawPath(mCpuRunningPath, mCpuRunningPaint);
         }
 
         if (mLargeMode) {
+            if (DEBUG) Log.d(TAG, "Drawing large mode labels");
             if (mHavePhoneSignal) {
                 canvas.drawText(mPhoneSignalLabel, textStartX,
                         height - mPhoneSignalOffset - mTextDescent, mTextPaint);
@@ -806,13 +1152,52 @@
                     height - mChargingOffset - mTextDescent, mTextPaint);
             canvas.drawText(mScreenOnLabel, textStartX,
                     height - mScreenOnOffset - mTextDescent, mTextPaint);
-            canvas.drawLine(0, mLevelBottom+(mThinLineWidth/2), width,
-                    mLevelBottom+(mThinLineWidth/2), mTextPaint);
-            canvas.drawLine(0, mLevelTop, 0,
-                    mLevelBottom+(mThinLineWidth/2), mTextPaint);
+        }
+
+        canvas.drawLine(mLevelLeft-mThinLineWidth, mLevelTop, mLevelLeft-mThinLineWidth,
+                mLevelBottom+(mThinLineWidth/2), mTextPaint);
+        if (mLargeMode) {
             for (int i=0; i<10; i++) {
-                int y = mLevelTop + ((mLevelBottom-mLevelTop)*i)/10;
-                canvas.drawLine(0, y, mThinLineWidth*2, y, mTextPaint);
+                int y = mLevelTop + mThinLineWidth/2 + ((mLevelBottom-mLevelTop)*i)/10;
+                canvas.drawLine(mLevelLeft-mThinLineWidth*2-mThinLineWidth/2, y,
+                        mLevelLeft-mThinLineWidth-mThinLineWidth/2, y, mTextPaint);
+            }
+        }
+        if (DEBUG) Log.d(TAG, "Drawing max percent, origw=" + mMaxPercentLabelStringWidth
+                + ", noww=" + (int)mTextPaint.measureText(mMaxPercentLabelString));
+        canvas.drawText(mMaxPercentLabelString, 0, mLevelTop, mTextPaint);
+        canvas.drawText(mMinPercentLabelString,
+                mMaxPercentLabelStringWidth-mMinPercentLabelStringWidth,
+                mLevelBottom - mThinLineWidth, mTextPaint);
+        canvas.drawLine(0, mLevelBottom+mThinLineWidth, width,
+                mLevelBottom+mThinLineWidth, mTextPaint);
+
+        if (mDateLabels.size() > 0) {
+            int ytop = mLevelTop + mTextAscent;
+            int ybottom = mLevelBottom;
+            int lastLeft = mLevelRight;
+            mTextPaint.setTextAlign(Paint.Align.LEFT);
+            for (int i=mDateLabels.size()-1; i>=0; i--) {
+                DateLabel label = mDateLabels.get(i);
+                int left = label.x - mThinLineWidth;
+                int x = label.x + mThinLineWidth*2;
+                if ((x+label.width) >= lastLeft) {
+                    x = label.x - mThinLineWidth*2 - label.width;
+                    left = x - mThinLineWidth;
+                    if (left >= lastLeft) {
+                        // okay we give up.
+                        continue;
+                    }
+                }
+                if (left < mLevelLeft) {
+                    // Won't fit on left, give up.
+                    continue;
+                }
+                mDateLinePath.reset();
+                mDateLinePath.moveTo(label.x, ytop);
+                mDateLinePath.lineTo(label.x, ybottom);
+                canvas.drawPath(mDateLinePath, mDateLinePaint);
+                canvas.drawText(label.label, x, ytop - mTextAscent, mTextPaint);
             }
         }
     }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 87e5d76..e6c2c96 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -21,7 +21,6 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.os.BatteryManager;
 import android.os.BatteryStats;
 import android.os.Bundle;
 import android.os.Handler;
diff --git a/src/com/android/settings/notification/NotificationStation.java b/src/com/android/settings/notification/NotificationStation.java
index 3f37f6d..2471801 100644
--- a/src/com/android/settings/notification/NotificationStation.java
+++ b/src/com/android/settings/notification/NotificationStation.java
@@ -74,10 +74,6 @@
 
     private NotificationListenerService mListener = new NotificationListenerService() {
         @Override
-        public void onListenerConnected(String[] notificationKeys) {
-            // noop
-        }
-        @Override
         public void onNotificationPosted(StatusBarNotification notification) {
             Log.v(TAG, "onNotificationPosted: " + notification);
             final Handler h = getListView().getHandler();
