public LockTaskNotify(Context context) {
   mContext = context;
   mAccessibilityManager =
       (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
   mHandler = new H();
   SettingsObserver observer = new SettingsObserver(mHandler);
   observer.observe();
   mHasNavigationBar = context.getResources().getBoolean(R.bool.config_showNavigationBar);
 }
  public HoloClock(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mHandler = new Handler();
    SettingsObserver settingsObserver = new SettingsObserver(mHandler);
    settingsObserver.observe();

    updateSettings();
  }
  NotificationManagerService(
      Context context, StatusBarManagerService statusBar, LightsService lights) {
    super();
    mContext = context;
    mAm = ActivityManagerNative.getDefault();
    mSound = new NotificationPlayer(TAG);
    mSound.setUsesWakeLock(context);
    mToastQueue = new ArrayList<ToastRecord>();
    mHandler = new WorkerHandler();

    mStatusBar = statusBar;
    statusBar.setNotificationCallbacks(mNotificationCallbacks);

    mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS);
    mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);

    Resources resources = mContext.getResources();
    mDefaultNotificationColor =
        resources.getColor(com.android.internal.R.color.config_defaultNotificationColor);
    mDefaultNotificationLedOn =
        resources.getInteger(com.android.internal.R.integer.config_defaultNotificationLedOn);
    mDefaultNotificationLedOff =
        resources.getInteger(com.android.internal.R.integer.config_defaultNotificationLedOff);

    // Don't start allowing notifications until the setup wizard has run once.
    // After that, including subsequent boots, init with notifications turned on.
    // This works on the first boot because the setup wizard will toggle this
    // flag at least once and we'll go back to 0 after that.
    if (0
        == Settings.Secure.getInt(
            mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0)) {
      mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
    }

    // register for various Intents
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    mContext.registerReceiver(mIntentReceiver, filter);
    IntentFilter pkgFilter = new IntentFilter();
    pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
    pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
    pkgFilter.addDataScheme("package");
    mContext.registerReceiver(mIntentReceiver, pkgFilter);
    IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mContext.registerReceiver(mIntentReceiver, sdFilter);

    SettingsObserver observer = new SettingsObserver(mHandler);
    observer.observe();
  }
  public DockBatteryController(Context context) {
    mContext = context;
    mHandler = new Handler();

    SettingsObserver settingsObserver = new SettingsObserver(mHandler);
    settingsObserver.observe();
    updateSettings();

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_BATTERY_CHANGED);
    context.registerReceiver(this, filter);
  }
  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    init();
    mBatteryGroup = (ViewGroup) findViewById(R.id.battery_combo);
    mBatteryIcon = (ImageView) findViewById(R.id.battery);
    mBatteryText = (TextView) findViewById(R.id.battery_text);
    mBatteryCenterText = (TextView) findViewById(R.id.battery_text_center);
    mBatteryTextOnly = (TextView) findViewById(R.id.battery_text_only);
    addIconView(mBatteryIcon);

    SettingsObserver settingsObserver = new SettingsObserver(new Handler());
    settingsObserver.observe();
    updateSettings(); // to initialize values
  }
  public BrightnessSlider(Context context) {
    mContext = context;
    mView = View.inflate(mContext, R.layout.brightness_slider, null);

    mControl = (ToggleSlider) mView.findViewById(R.id.brightness);

    mScreenBrightnessDim =
        mContext
            .getResources()
            .getInteger(com.android.internal.R.integer.config_screenBrightnessDim);

    boolean automaticAvailable =
        context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available);
    mPower = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));

    if (automaticAvailable) {
      int automatic;
      try {
        automatic =
            Settings.System.getInt(
                mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
      } catch (SettingNotFoundException snfe) {
        automatic = 0;
      }
      mControl.setChecked(automatic != 0);
    } else {
      mControl.setChecked(false);
      // control.hideToggle();
    }

    int value;
    try {
      value =
          Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
    } catch (SettingNotFoundException ex) {
      value = MAXIMUM_BACKLIGHT;
    }

    mControl.setMax(MAXIMUM_BACKLIGHT - mScreenBrightnessDim);
    mControl.setValue(value - mScreenBrightnessDim);

    mControl.setOnChangedListener(this);

    SettingsObserver so = new SettingsObserver(new Handler());
    so.observe();
  }
 @Override
 public void onResume() {
   super.onResume();
   updateModeSummary();
   updateTemperatureSummary();
   mObserver.register(true);
 }
  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    if (!mAttached) {
      mAttached = true;
      Log.e(TAG, "vertical bar: " + vertical);

      mBatteryBarLayout = new LinearLayout(mContext);
      addView(
          mBatteryBarLayout,
          new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

      mBatteryBar = new View(mContext);
      mBatteryBarLayout.addView(
          mBatteryBar,
          new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

      DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
      float dp = 4f;
      int pixels = (int) (metrics.density * dp + 0.5f);

      // charger
      mChargerLayout = new LinearLayout(mContext);

      if (vertical)
        addView(mChargerLayout, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, pixels));
      else
        addView(mChargerLayout, new RelativeLayout.LayoutParams(pixels, LayoutParams.MATCH_PARENT));

      mCharger = new View(mContext);
      mChargerLayout.setVisibility(View.GONE);
      mChargerLayout.addView(
          mCharger,
          new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

      IntentFilter filter = new IntentFilter();
      filter.addAction(Intent.ACTION_BATTERY_CHANGED);
      filter.addAction(Intent.ACTION_SCREEN_OFF);
      filter.addAction(Intent.ACTION_SCREEN_ON);
      getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());

      SettingsObserver observer = new SettingsObserver(mHandler);
      observer.observer();
      updateSettings();
    }
  }
 public void attachContainer() {
   if (!mAttached) {
     mAttached = true;
     setupContainer();
     refreshContainer();
     mSettingsObserver.observe();
   }
 }
  @Override
  public void onResume() {
    super.onResume();

    mSettingsObserver.resume();
    mIm.registerInputDeviceListener(this, null);

    if (!mIsOnlyImeSettings) {
      if (mLanguagePref != null) {
        Configuration conf = getResources().getConfiguration();
        String language = conf.locale.getLanguage();
        String localeString;
        // TODO: This is not an accurate way to display the locale, as it is
        // just working around the fact that we support limited dialects
        // and want to pretend that the language is valid for all locales.
        // We need a way to support languages that aren't tied to a particular
        // locale instead of hiding the locale qualifier.
        if (hasOnlyOneLanguageInstance(language, Resources.getSystem().getAssets().getLocales())) {
          localeString = conf.locale.getDisplayLanguage(conf.locale);
        } else {
          localeString = conf.locale.getDisplayName(conf.locale);
        }
        if (localeString.length() > 1) {
          localeString = Character.toUpperCase(localeString.charAt(0)) + localeString.substring(1);
          mLanguagePref.setSummary(localeString);
        }
      }

      updateUserDictionaryPreference(findPreference(KEY_USER_DICTIONARY_SETTINGS));
      if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
        mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this);
      }
    }

    if (mStatusBarImeSwitcher != null) {
      mStatusBarImeSwitcher.setChecked(
          Settings.System.getInt(
                  getActivity().getContentResolver(), Settings.System.STATUS_BAR_IME_SWITCHER, 1)
              != 0);
    }

    // Hard keyboard
    if (!mHardKeyboardPreferenceList.isEmpty()) {
      for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
        CheckBoxPreference chkPref =
            (CheckBoxPreference) mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i]);
        chkPref.setChecked(System.getInt(getContentResolver(), sSystemSettingNames[i], 1) > 0);
      }
    }

    updateInputDevices();

    // IME
    InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(this, getContentResolver(), mImis, null);
    updateActiveInputMethodsSummary();
  }
  @Override
  public void init(Context c, int style) {
    super.init(c, style);

    SharedPreferences shared =
        mContext.getSharedPreferences(KEY_USER_TIMEOUT, Context.MODE_PRIVATE);
    storedUserTimeout = shared.getInt("timeout", FALLBACK_SCREEN_TIMEOUT_VALUE);
    mObserver = new SettingsObserver(mHandler);
    mObserver.observe();
  }
 public void setListening(boolean listening) {
   if (mListening == listening) return;
   mListening = listening;
   for (TileRecord r : mRecords) {
     r.tile.setListening(mListening);
   }
   mFooter.setListening(mListening);
   if (mListening) {
     refreshAllTiles();
     mSettingsObserver.observe();
   } else {
     mSettingsObserver.unobserve();
   }
   if (listening && showBrightnessSlider()) {
     mBrightnessController.registerCallbacks();
   } else {
     mBrightnessController.unregisterCallbacks();
   }
 }
  @Override
  public void onPause() {
    super.onPause();

    mIm.unregisterInputDeviceListener(this);
    mSettingsObserver.pause();

    if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
      mShowInputMethodSelectorPref.setOnPreferenceChangeListener(null);
    }
    InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(
        this, getContentResolver(), mImis, !mHardKeyboardPreferenceList.isEmpty());
  }
  public KeyButtonView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.KeyButtonView, defStyle, 0);

    mCode = a.getInteger(R.styleable.KeyButtonView_keyCode, 0);

    mSupportsLongpress = a.getBoolean(R.styleable.KeyButtonView_keyRepeat, true);

    setDrawingAlpha(mQuiescentAlpha);

    a.recycle();

    setClickable(true);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    setBackground(new KeyButtonRipple(context, this));
    mPm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

    SettingsObserver settingsObserver = new SettingsObserver(new Handler());
    settingsObserver.observe();
  }
  /** Initialize the receivers and initiate the first NTP request */
  public void systemReady() {
    registerForTelephonyIntents();
    registerForAlarms();
    registerForConnectivityIntents();

    mThread = new HandlerThread(TAG);
    mThread.start();
    mHandler = new MyHandler(mThread.getLooper());
    // Check the network time on the new thread
    mHandler.obtainMessage(EVENT_POLL_NETWORK_TIME).sendToTarget();

    mSettingsObserver = new SettingsObserver(mHandler, EVENT_AUTO_TIME_CHANGED);
    mSettingsObserver.observe(mContext);
  }
  @Override
  protected void onDetachedFromWindow() {
    mObserver.unobserve();

    mWifiGroup = null;
    mWifi = null;
    mWifiActivity = null;
    mMobileGroup = null;
    mMobile = null;
    mMobileActivity = null;
    mMobileType = null;
    mSpacer = null;
    mAirplane = null;

    super.onDetachedFromWindow();
  }
  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    mObserver.observe();

    mWifiGroup = (ViewGroup) findViewById(R.id.wifi_combo);
    mWifi = (ImageView) findViewById(R.id.wifi_signal);
    mWifiActivity = (ImageView) findViewById(R.id.wifi_inout);
    mMobileGroup = (ViewGroup) findViewById(R.id.mobile_combo);
    mMobile = (ImageView) findViewById(R.id.mobile_signal);
    mMobileActivity = (ImageView) findViewById(R.id.mobile_inout);
    mMobileType = (ImageView) findViewById(R.id.mobile_type);
    mSpacer = findViewById(R.id.spacer);
    mAirplane = (ImageView) findViewById(R.id.airplane);

    apply();
  }
  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    mSettingsObserver.observe();
    mDoubleTapGesture =
        new GestureDetector(
            mContext,
            new GestureDetector.SimpleOnGestureListener() {
              @Override
              public boolean onDoubleTap(MotionEvent e) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                Log.d(TAG, "Gesture!!");
                if (pm != null) pm.goToSleep(e.getEventTime());
                else Log.d(TAG, "getSystemService returned null PowerManager");

                return true;
              }
            });

    // We really need to be able to animate while window animations are going on
    // so that activities may be started asynchronously from panel animations
    final ViewRootImpl root = getViewRootImpl();
    if (root != null) {
      root.setDrawDuringWindowsAnimating(true);
    }

    // We need to ensure that our window doesn't suffer from overdraw which would normally
    // occur if our window is translucent. Since we are drawing the whole window anyway with
    // the scrim, we don't need the window to be cleared in the beginning.
    if (mService.isScrimSrcModeEnabled()) {
      IBinder windowToken = getWindowToken();
      WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
      lp.token = windowToken;
      setLayoutParams(lp);
      WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
      setWillNotDraw(false);
    } else {
      setWillNotDraw(!DEBUG);
    }
  }
 public void updateResources() {
   final Resources res = mContext.getResources();
   final int columns = Math.max(1, useFourColumns());
   mCellHeight = res.getDimensionPixelSize(R.dimen.qs_tile_height);
   if (mUseFourColumns) {
     mCellWidth = (int) (mCellHeight * TILE_ASPECT_SMALL);
   } else {
     mCellWidth = (int) (mCellHeight * TILE_ASPECT);
   }
   mLargeCellHeight = res.getDimensionPixelSize(R.dimen.qs_dual_tile_height);
   mLargeCellWidth = (int) (mLargeCellHeight * TILE_ASPECT);
   mPanelPaddingBottom = res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom);
   mDualTileUnderlap = res.getDimensionPixelSize(R.dimen.qs_dual_tile_padding_vertical);
   mBrightnessPaddingTop = res.getDimensionPixelSize(R.dimen.qs_brightness_padding_top);
   if (mColumns != columns) {
     mColumns = columns;
     postInvalidate();
   }
   if (mListening) {
     refreshAllTiles();
     mSettingsObserver.observe();
   }
   updateDetailText();
 }
 @Override
 public void onPause() {
   super.onPause();
   mObserver.register(false);
 }
 @Override
 protected void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   mSettingsObserver.unobserve();
 }
 public void onBootPhaseAppsCanStart() {
   mSettingsObserver.observe();
 }