public void setMode(BatteryMeterMode mode) {
    if (mMeterMode == mode) {
      return;
    }

    mMeterMode = mode;
    BatteryTracker tracker = mDemoMode ? mDemoTracker : mTracker;
    if (mode == BatteryMeterMode.BATTERY_METER_GONE) {
      setVisibility(View.GONE);
      synchronized (mLock) {
        mBatteryMeterDrawable = null;
      }
    } else {
      synchronized (mLock) {
        if (mBatteryMeterDrawable != null) {
          mBatteryMeterDrawable.onDispose();
        }
        mBatteryMeterDrawable = createBatteryMeterDrawable(mode);
      }
      if (mMeterMode == BatteryMeterMode.BATTERY_METER_ICON_PORTRAIT
          || mMeterMode == BatteryMeterMode.BATTERY_METER_ICON_LANDSCAPE) {
        ((NormalBatteryMeterDrawable) mBatteryMeterDrawable)
            .loadBoltPoints(mContext.getResources());
      }
      if (tracker.present) {
        setVisibility(View.VISIBLE);
        postInvalidate();
        requestLayout();
      } else {
        setVisibility(View.GONE);
      }
    }
  }
 @SuppressLint("WrongCall")
 @Override
 public void draw(Canvas c) {
   synchronized (mLock) {
     if (mBatteryMeterDrawable != null) {
       BatteryTracker tracker = mDemoMode ? mDemoTracker : mTracker;
       mBatteryMeterDrawable.onDraw(c, tracker);
     }
   }
 }
 @Override
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
   mHeight = h;
   mWidth = w;
   synchronized (mLock) {
     if (mBatteryMeterDrawable != null) {
       mBatteryMeterDrawable.onSizeChanged(w, h, oldw, oldh);
     }
   }
 }