@Override
          public void onReceive(Context context, Intent intent) {
            boolean redraw = false;
            if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED))
              redraw = updateBatteryItems(intent);
            else if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
              redraw = updatePhoneInfo();
              redraw = updateDateTimeItems();
            } else if (intent.getAction().compareTo(Intent.ACTION_SCREEN_OFF) == 0) {
              mVisible = false;
              Phone.instance().screen().locked(true);
              redraw = true;
            } else if (intent.getAction().compareTo(Intent.ACTION_SCREEN_ON) == 0) {
              Phone.instance().screen().locked(true);
              mVisible = true;
              redraw = true;
            } else if (intent.getAction().compareTo(Intent.ACTION_USER_PRESENT) == 0) {
              updateWeatherAsync();
              Phone.instance().screen().locked(false);
              mVisible = true;
              redraw = true;
            } else if (intent.getAction().equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
              boolean activated = intent.getBooleanExtra("state", true);
              if (activated == false) mHandler.postDelayed(mWeatherUpdater, 30000);
            } else if (intent.getAction().equals("com.android.music.playbackcomplete")
                || intent.getAction().equals("com.android.music.playstatechanged")
                || intent.getAction().equals("com.android.music.metachanged")) {
              redraw = updateCurrentSong(intent);
            }

            if (redraw) {
              updateWallpaper();
            }
          }
    private void draw() {
      final SurfaceHolder surfaceHolder = getSurfaceHolder();
      Canvas canvas = null;

      try {
        canvas = surfaceHolder.lockCanvas();
        if (canvas != null) {
          canvas.save();

          mBackground.draw(canvas);

          if (Phone.instance().screen().isLocked() == false || mHide == false) {
            for (int i = 0; i < mInfoList.size(); ++i) {
              mInfoList.get(i).draw(canvas);
            }
          }

          canvas.restore();
        }
      } finally {
        if (canvas != null) {
          surfaceHolder.unlockCanvasAndPost(canvas);
          canvas = null;
        }
      }
    }
    @Override
    public void onSurfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height) {
      super.onSurfaceChanged(surfaceHolder, format, width, height);

      Phone.instance().screen().updateWindow(width, height, format);
      draw();
    }
    @Override
    public void onOffsetsChanged(
        float offsetX, float offsetY, float stepX, float stepY, int pixelsX, int pixelsY) {
      Phone.instance().screen().setOffset(offsetX, offsetY, stepX, stepY, pixelsX, pixelsY);

      if (mBackground.setOffset(offsetX) || mInfoOnAllScreens == false) {
        updateWallpaper();
      }
    }
    // Phone Info
    private boolean updatePhoneInfo() {
      Phone.instance().update(getBaseContext());

      boolean redraw = false;
      for (int i = 0; i < mInfoList.size(); ++i) {
        if (mInfoList.get(i).isType(InfoItem.TYPE_PHONESTATUS)) {
          redraw = true;
          mInfoList.get(i).update(InfoItem.TYPE_PHONESTATUS, null);
        }
      }

      return redraw;
    }
    public WallpaperEngine() {
      prepareUserAgent();

      mPrefs = LiveInfoWallpaper.this.getSharedPreferences(SHARED_PREFERENCES_NAME, 0);
      mPrefs.registerOnSharedPreferenceChangeListener(this);
      onSharedPreferenceChanged(mPrefs, null);

      IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
      filter.addAction(Intent.ACTION_SCREEN_OFF);
      filter.addAction(Intent.ACTION_SCREEN_ON);
      filter.addAction(Intent.ACTION_BATTERY_CHANGED);
      filter.addAction(Intent.ACTION_TIME_TICK);
      filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);

      registerReceiver(mReceiver, filter);

      TelephonyManager tm =
          (TelephonyManager)
              LiveInfoWallpaper.this.getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
      tm.listen(Phone.instance(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }