@Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.recents_panel_settings);

    PreferenceScreen prefSet = getPreferenceScreen();
    ContentResolver resolver = getActivity().getContentResolver();
    PackageManager pm = getPackageManager();

    mRecentsClearAll = (SwitchPreference) prefSet.findPreference(SHOW_CLEAR_ALL_RECENTS);
    mRecentsClearAll.setChecked(
        Settings.System.getIntForUser(
                resolver, Settings.System.SHOW_CLEAR_ALL_RECENTS, 1, UserHandle.USER_CURRENT)
            == 1);
    mRecentsClearAll.setOnPreferenceChangeListener(this);

    mRecentsClearAllLocation = (ListPreference) prefSet.findPreference(RECENTS_CLEAR_ALL_LOCATION);
    int location =
        Settings.System.getIntForUser(
            resolver, Settings.System.RECENTS_CLEAR_ALL_LOCATION, 3, UserHandle.USER_CURRENT);
    mRecentsClearAllLocation.setValue(String.valueOf(location));
    mRecentsClearAllLocation.setOnPreferenceChangeListener(this);
    updateRecentsLocation(location);

    mOmniSwitch = (Preference) prefSet.findPreference(KEY_OMNISWITCH);
    if (!Helpers.isPackageInstalled(OMNISWITCH_PACKAGE_NAME, pm)) {
      prefSet.removePreference(mOmniSwitch);
    }
  }
 private Drawable prepareBackIcon(Drawable d, boolean customIcon) {
   int customImageColorize =
       Settings.System.getIntForUser(
           mContext.getContentResolver(),
           Settings.System.PIE_ICON_COLOR_MODE,
           0,
           UserHandle.USER_CURRENT);
   int drawableColor =
       Settings.System.getIntForUser(
           mContext.getContentResolver(),
           Settings.System.PIE_ICON_COLOR,
           -2,
           UserHandle.USER_CURRENT);
   if (drawableColor == -2) {
     drawableColor = mContext.getResources().getColor(R.color.pie_foreground_color);
   }
   if (mIconResize && !customIcon) {
     d = resizeIcon(null, d, false);
   } else if (customIcon) {
     d = resizeIcon(null, d, true);
   }
   if ((customImageColorize != 1 || !customIcon) && customImageColorize != 3) {
     d =
         new BitmapDrawable(
             mContext.getResources(),
             ImageHelper.drawableToBitmap(ImageHelper.getColoredDrawable(d, drawableColor)));
   }
   return d;
 }
  private void setupListener() {
    ContentResolver resolver = mContext.getContentResolver();

    mPieTriggerSlots =
        Settings.System.getIntForUser(
            resolver,
            Settings.System.PIE_GRAVITY,
            EdgeGesturePosition.LEFT.FLAG,
            UserHandle.USER_CURRENT);

    int sensitivity = mContext.getResources().getInteger(R.integer.pie_gesture_sensivity);
    if (sensitivity < EdgeServiceConstants.SENSITIVITY_LOWEST
        || sensitivity > EdgeServiceConstants.SENSITIVITY_HIGHEST) {
      sensitivity = EdgeServiceConstants.SENSITIVITY_DEFAULT;
    }

    int flags = mPieTriggerSlots & mPieTriggerMask;

    if (Settings.System.getIntForUser(
            resolver, Settings.System.PIE_IME_CONTROL, 1, UserHandle.USER_CURRENT)
        == 1) {
      flags |= EdgeServiceConstants.IME_CONTROL;
    }

    mPieManager.updateEdgeGestureActivationListener(
        mPieActivationListener, sensitivity << EdgeServiceConstants.SENSITIVITY_SHIFT | flags);
  }
  @Override
  public void onSnap(EdgeGesturePosition position) {
    if (position == mPosition) {
      return;
    }

    doHapticTriggerFeedback();

    if (DEBUG) {
      Slog.d(TAG, "onSnap from " + position.name());
    }

    int triggerSlots =
        Settings.System.getIntForUser(
            mContext.getContentResolver(),
            Settings.System.PIE_GRAVITY,
            EdgeGesturePosition.LEFT.FLAG,
            UserHandle.USER_CURRENT);

    triggerSlots = triggerSlots & ~mPosition.FLAG | position.FLAG;

    Settings.System.putIntForUser(
        mContext.getContentResolver(),
        Settings.System.PIE_GRAVITY,
        triggerSlots,
        UserHandle.USER_CURRENT);
  }
 protected void setupQuickSettings() {
   shutdown();
   mReceiver = new QSBroadcastReceiver();
   mReceiverMap.clear();
   mObserver = new QuickSettingsObserver(mHandler);
   mObserverMap.clear();
   mTileStatusUris.clear();
   loadTiles();
   setupBroadcastReceiver();
   setupContentObserver();
   ContentResolver resolver = mContext.getContentResolver();
   boolean smallIcons =
       Settings.System.getIntForUser(
               resolver, Settings.System.QUICK_SETTINGS_SMALL_ICONS, 0, UserHandle.USER_CURRENT)
           == 1;
   if (mRibbonMode || smallIcons) {
     for (QuickSettingsTile t : mQuickSettingsTiles) {
       if (mRibbonMode) {
         t.switchToRibbonMode();
       } else {
         t.switchToSmallIcons();
       }
     }
   }
   updateResources();
 }
  private void updateTemperatureSummary() {
    int day =
        Settings.System.getIntForUser(
            getContentResolver(),
            Settings.System.DISPLAY_TEMPERATURE_DAY,
            mDefaultDayTemperature,
            UserHandle.USER_CURRENT);
    int night =
        Settings.System.getIntForUser(
            getContentResolver(),
            Settings.System.DISPLAY_TEMPERATURE_NIGHT,
            mDefaultNightTemperature,
            UserHandle.USER_CURRENT);

    mDisplayTemperature.setSummary(
        getResources().getString(R.string.live_display_color_temperature_summary, day, night));
  }
 public void update() {
   ContentResolver resolver = mContext.getContentResolver();
   mDoubleTapToSleepEnabled =
       Settings.System.getInt(resolver, Settings.System.DOUBLE_TAP_SLEEP_GESTURE, 1) == 1;
   mDoubleTapToSleepLockScreen =
       Settings.System.getIntForUser(
               resolver,
               Settings.System.DOUBLE_TAP_SLEEP_LOCK_SCREEN,
               0,
               UserHandle.USER_CURRENT)
           == 1;
 }
 private void vibrate() {
   final boolean hapticEnabled =
       Settings.System.getIntForUser(
               mContext.getContentResolver(),
               Settings.System.HAPTIC_FEEDBACK_ENABLED,
               1,
               UserHandle.USER_CURRENT)
           != 0;
   if (mVibrator != null && hapticEnabled) {
     mVibrator.vibrate(mVibrationDuration, VIBRATION_ATTRIBUTES);
   }
 }
Exemplo n.º 9
0
  private void updateTile() {
    int mode =
        Settings.System.getIntForUser(
            mContext.getContentResolver(),
            Settings.System.SCREEN_BRIGHTNESS_MODE,
            Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
            UserHandle.USER_CURRENT);
    boolean autoBrightness = mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;

    mDrawable =
        autoBrightness ? R.drawable.ic_qs_brightness_auto_on : R.drawable.ic_qs_brightness_auto_off;
    mLabel = mContext.getString(R.string.quick_settings_brightness_label);
  }
Exemplo n.º 10
0
  private void setupNavigationItems() {
    ContentResolver resolver = mContext.getContentResolver();
    // Get minimum allowed image size for layout
    int minimumImageSize = (int) mContext.getResources().getDimension(R.dimen.pie_item_size);

    mNavigationSlice.clear();

    // Reset mIconResizeFactor
    mIconResizeFactor = 1.0f;
    // Check the size set from the user and set resize values if needed
    float diff =
        PieView.PIE_ICON_START_SIZE_FACTOR
            - Settings.System.getFloatForUser(
                resolver,
                Settings.System.PIE_SIZE,
                PieView.PIE_CONTROL_SIZE_DEFAULT,
                UserHandle.USER_CURRENT);
    if (diff > 0.0f) {
      mIconResize = true;
      mIconResizeFactor = 1.0f - diff;
    } else {
      mIconResize = false;
    }

    // Prepare IME back icon
    mBackAltIcon = mContext.getResources().getDrawable(R.drawable.ic_sysbar_back_ime);
    mBackAltIcon = prepareBackIcon(mBackAltIcon, false);

    ArrayList<ActionConfig> buttonsConfig;

    // First we construct first buttons layer
    buttonsConfig = ActionHelper.getPieConfig(mContext);
    getCustomActionsAndConstruct(resolver, buttonsConfig, false, minimumImageSize);

    if (mSecondLayerActive) {
      // If second layer is active we construct second layer now
      mNavigationSliceSecondLayer.clear();
      buttonsConfig = ActionHelper.getPieSecondLayerConfig(mContext);
      getCustomActionsAndConstruct(resolver, buttonsConfig, true, minimumImageSize);
    }

    mShowMenuVisibility =
        Settings.System.getIntForUser(
            mContext.getContentResolver(),
            Settings.System.PIE_MENU,
            MENU_VISIBILITY_SYSTEM,
            UserHandle.USER_CURRENT);

    setNavigationIconHints(mNavigationIconHints, true);
    setMenuVisibility(mShowMenu);
  }
 public boolean onPreferenceChange(Preference preference, Object objValue) {
   if (preference == mVolumeKeyCursorControl) {
     String volumeKeyCursorControl = (String) objValue;
     int val = Integer.parseInt(volumeKeyCursorControl);
     Settings.System.putInt(getContentResolver(), Settings.System.VOLUME_KEY_CURSOR_CONTROL, val);
     int index = mVolumeKeyCursorControl.findIndexOfValue(volumeKeyCursorControl);
     mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntries()[index]);
     return true;
   } else if (preference == mDisableFullscreenKeyboard) {
     Settings.System.putInt(
         getContentResolver(),
         Settings.System.DISABLE_FULLSCREEN_KEYBOARD,
         (Boolean) objValue ? 1 : 0);
     return true;
   } else if (preference == mStatusBarImeSwitcher) {
     Settings.System.putInt(
         getContentResolver(),
         Settings.System.STATUS_BAR_IME_SWITCHER,
         (Boolean) objValue ? 1 : 0);
     return true;
   } else if (preference == mKeyboardRotationToggle) {
     boolean isAutoRotate =
         (Settings.System.getIntForUser(
                 getContentResolver(),
                 Settings.System.ACCELEROMETER_ROTATION,
                 0,
                 UserHandle.USER_CURRENT)
             == 1);
     if (isAutoRotate && (Boolean) objValue) {
       showDialogInner(DLG_KEYBOARD_ROTATION);
     }
     Settings.System.putInt(
         getContentResolver(),
         Settings.System.KEYBOARD_ROTATION_TIMEOUT,
         (Boolean) objValue ? KEYBOARD_ROTATION_TIMEOUT_DEFAULT : 0);
     updateRotationTimeout(KEYBOARD_ROTATION_TIMEOUT_DEFAULT);
     return true;
   } else if (preference == mShowEnterKey) {
     Settings.System.putInt(
         getContentResolver(), Settings.System.FORMAL_TEXT_INPUT, (Boolean) objValue ? 1 : 0);
     return true;
   } else if (preference == mKeyboardRotationTimeout) {
     int timeout = Integer.parseInt((String) objValue);
     Settings.System.putInt(
         getContentResolver(), Settings.System.KEYBOARD_ROTATION_TIMEOUT, timeout);
     updateRotationTimeout(timeout);
     return true;
   }
   return false;
 }
 /** Triggers haptic feedback. */
 private synchronized void vibrate(long duration) {
   final boolean hapticEnabled =
       Settings.System.getIntForUser(
               mContext.getContentResolver(),
               Settings.System.HAPTIC_FEEDBACK_ENABLED,
               1,
               UserHandle.USER_CURRENT)
           != 0;
   if (hapticEnabled) {
     if (mVibrator == null) {
       mVibrator = (android.os.Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
     }
     mVibrator.vibrate(duration, VIBRATION_ATTRIBUTES);
   }
 }
Exemplo n.º 13
0
  private void doHapticTriggerFeedback() {
    if (mVibrator == null || !mVibrator.hasVibrator()) {
      return;
    }

    int hapticSetting =
        Settings.System.getIntForUser(
            mContext.getContentResolver(),
            Settings.System.HAPTIC_FEEDBACK_ENABLED,
            1,
            UserHandle.USER_CURRENT);
    if (hapticSetting != 0) {
      mVibrator.vibrate(5);
    }
  }
  private void loadDockBatteryTile(final ContentResolver resolver, final LayoutInflater inflater) {
    if (!QSUtils.deviceSupportsDockBattery(mContext)) {
      return;
    }
    if (Settings.System.getIntForUser(
            resolver, Settings.System.QS_DYNAMIC_DOCK_BATTERY, 1, UserHandle.USER_CURRENT)
        == 0) {
      return;
    }

    QuickSettingsTile qs =
        new DockBatteryTile(mContext, this, mStatusBarService.mDockBatteryController);
    qs.setupQuickSettingsTile(inflater, mContainerView);
    mQuickSettingsTiles.add(qs);
  }
Exemplo n.º 15
0
  /** Assign the label to the view. */
  @Override
  public void setupInnerViewElements(ViewGroup parent, View view) {
    if (view == null || mLabel == null) {
      return;
    }

    // We use here a view holder to reduce expensive findViewById calls
    // when getView is called on the arrayadapter which calls setupInnerViewElements.
    // Simply just check if the given view was already tagged. If yes we know it has
    // the appIconView we want to have. If not we search it, give it to the viewholder
    // and tag the view for the next call to reuse the holded information later.
    ViewHolder holder;
    holder = (ViewHolder) view.getTag();

    if (holder == null) {
      holder = new ViewHolder();
      holder.textView = (TextView) view.findViewById(R.id.card_header_inner_simple_title);
      // Take scale factor into account if it is different then default or it has changed.
      if (mScaleFactor != RecentController.DEFAULT_SCALE_FACTOR || mScaleFactorChanged) {
        mScaleFactorChanged = false;
        int diff = 0;
        // We have on static element in the header (expanded icon button). Take this into
        // account to calculate the needed width.
        if (mScaleFactor < RecentController.DEFAULT_SCALE_FACTOR) {
          diff = (int) ((mExpandedButtonWidth - mExpandedButtonWidth * mScaleFactor) * 2);
        }
        final ViewGroup.LayoutParams layoutParams = holder.textView.getLayoutParams();
        layoutParams.width = mHeaderWidth - diff;
        layoutParams.height = mHeaderHeight;
        holder.textView.setLayoutParams(layoutParams);
        holder.textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mHeaderTextSize);
      }
      view.setTag(holder);
    }
    int defaultCardText = mContext.getResources().getColor(R.color.card_text_color_header);
    int textColor =
        Settings.System.getIntForUser(
            mContext.getContentResolver(),
            Settings.System.RECENT_CARD_TEXT_COLOR,
            defaultCardText,
            UserHandle.USER_CURRENT);
    holder.textView.setText(mLabel);
    if (textColor != 0x00ffffff) {
      holder.textView.setTextColor(textColor);
    } else {
      holder.textView.setTextColor(getDefaultTextColor());
    }
  }
Exemplo n.º 16
0
 private synchronized void updateTile() {
   mEnabled =
       Settings.System.getIntForUser(
               mContext.getContentResolver(),
               Settings.System.QUIET_HOURS_ENABLED,
               0,
               UserHandle.USER_CURRENT)
           == 1;
   if (mEnabled) {
     mDrawable = R.drawable.ic_qs_quiet_hours_on;
     mLabel = mContext.getString(R.string.quick_settings_quiethours);
   } else {
     mDrawable = R.drawable.ic_qs_quiet_hours_off;
     mLabel = mContext.getString(R.string.quick_settings_quiethours_off);
   }
 }
  private void updateModeSummary() {
    int mode =
        Settings.System.getIntForUser(
            getContentResolver(),
            Settings.System.DISPLAY_TEMPERATURE_MODE,
            MODE_OFF,
            UserHandle.USER_CURRENT);

    int index = ArrayUtils.indexOf(mModeValues, String.valueOf(mode));
    mLiveDisplay.setSummary(mModeSummaries[index]);

    if (mDisplayTemperature != null) {
      mDisplayTemperature.setEnabled(mode != MODE_OFF);
    }
    if (mOutdoorMode != null) {
      mOutdoorMode.setEnabled(mode != MODE_OFF);
    }
  }
Exemplo n.º 18
0
 /** Fetch the brightness mode from the system settings and update the icon */
 private void updateMode() {
   if (mAutomaticAvailable) {
     int automatic;
     automatic =
         Settings.System.getIntForUser(
             mContext.getContentResolver(),
             Settings.System.SCREEN_BRIGHTNESS_MODE,
             Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
             UserHandle.USER_CURRENT);
     mAutomatic = automatic != Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
     updateIcon(mAutomatic);
   } else {
     mControl.setChecked(false);
     updateIcon(false /*automatic*/);
     // M: [ALPS01748251] hide the Toggle slider
     mControl.hideToggle();
   }
 }
Exemplo n.º 19
0
 /** Fetch the brightness from the system settings and update the slider */
 private void updateSlider() {
   if (mAutomatic) {
     float value =
         Settings.System.getFloatForUser(
             mContext.getContentResolver(),
             Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ,
             0,
             UserHandle.USER_CURRENT);
     mControl.setMax((int) BRIGHTNESS_ADJ_RESOLUTION);
     mControl.setValue((int) ((value + 1) * BRIGHTNESS_ADJ_RESOLUTION / 2f));
   } else {
     int value;
     value =
         Settings.System.getIntForUser(
             mContext.getContentResolver(),
             Settings.System.SCREEN_BRIGHTNESS,
             mMaximumBacklight,
             UserHandle.USER_CURRENT);
     mControl.setMax(mMaximumBacklight - mMinimumBacklight);
     mControl.setValue(value - mMinimumBacklight);
   }
 }
Exemplo n.º 20
0
 public void update() {
   ContentResolver resolver = mContext.getContentResolver();
   mBrightnessSliderEnabled =
       Settings.Secure.getIntForUser(
               mContext.getContentResolver(),
               Settings.Secure.QS_SHOW_BRIGHTNESS_SLIDER,
               1,
               UserHandle.USER_CURRENT)
           == 1;
   mVibrationEnabled =
       Settings.System.getIntForUser(
               mContext.getContentResolver(),
               Settings.System.QUICK_SETTINGS_TILES_VIBRATE,
               0,
               UserHandle.USER_CURRENT)
           == 1;
   mUseFourColumns =
       Settings.Secure.getIntForUser(
               mContext.getContentResolver(),
               Settings.Secure.QS_USE_FOUR_COLUMNS,
               0,
               UserHandle.USER_CURRENT)
           == 1;
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    final ContentResolver resolver = activity.getContentResolver();
    final Resources res = getResources();

    mDefaultDayTemperature =
        res.getInteger(com.android.internal.R.integer.config_dayColorTemperature);
    mDefaultNightTemperature =
        res.getInteger(com.android.internal.R.integer.config_nightColorTemperature);

    mCmHardwareManager = (CmHardwareManager) activity.getSystemService(Context.CMHW_SERVICE);

    addPreferencesFromResource(R.xml.livedisplay);

    PreferenceCategory liveDisplayPrefs =
        (PreferenceCategory) findPreference(KEY_CATEGORY_LIVE_DISPLAY);
    PreferenceCategory calibrationPrefs =
        (PreferenceCategory) findPreference(KEY_CATEGORY_CALIBRATION);

    int displayMode =
        Settings.System.getIntForUser(
            resolver, Settings.System.DISPLAY_TEMPERATURE_MODE, 0, UserHandle.USER_CURRENT);
    mLiveDisplay = (ListPreference) findPreference(KEY_LIVE_DISPLAY);
    mLiveDisplay.setValue(String.valueOf(displayMode));

    mModeEntries = res.getStringArray(com.android.internal.R.array.live_display_entries);
    mModeValues = res.getStringArray(com.android.internal.R.array.live_display_values);
    mModeSummaries = res.getStringArray(com.android.internal.R.array.live_display_summaries);

    // Remove outdoor mode from lists if there is no support
    if (!mCmHardwareManager.isSupported(FEATURE_SUNLIGHT_ENHANCEMENT)) {
      int idx = ArrayUtils.indexOf(mModeValues, String.valueOf(MODE_OUTDOOR));
      String[] entriesTemp = new String[mModeEntries.length - 1];
      String[] valuesTemp = new String[mModeValues.length - 1];
      String[] summariesTemp = new String[mModeSummaries.length - 1];
      int j = 0;
      for (int i = 0; i < mModeEntries.length; i++) {
        if (i == idx) {
          continue;
        }
        entriesTemp[j] = mModeEntries[i];
        valuesTemp[j] = mModeValues[i];
        summariesTemp[j] = mModeSummaries[i];
        j++;
      }
      mModeEntries = entriesTemp;
      mModeValues = valuesTemp;
      mModeSummaries = summariesTemp;
    }

    mLiveDisplay.setEntries(mModeEntries);
    mLiveDisplay.setEntryValues(mModeValues);
    mLiveDisplay.setOnPreferenceChangeListener(this);

    mDisplayTemperature = (DisplayTemperature) findPreference(KEY_LIVE_DISPLAY_TEMPERATURE);

    mLowPower = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_LOW_POWER);
    if (liveDisplayPrefs != null
        && mLowPower != null
        && !mCmHardwareManager.isSupported(FEATURE_ADAPTIVE_BACKLIGHT)) {
      liveDisplayPrefs.removePreference(mLowPower);
      mLowPower = null;
    }

    mOutdoorMode = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE);
    if (liveDisplayPrefs != null
        && mOutdoorMode != null
        && !mCmHardwareManager.isSupported(FEATURE_SUNLIGHT_ENHANCEMENT)) {
      liveDisplayPrefs.removePreference(mOutdoorMode);
      mOutdoorMode = null;
    }

    mColorEnhancement = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_COLOR_ENHANCE);
    if (liveDisplayPrefs != null
        && mColorEnhancement != null
        && !mCmHardwareManager.isSupported(FEATURE_COLOR_ENHANCEMENT)) {
      liveDisplayPrefs.removePreference(mColorEnhancement);
      mColorEnhancement = null;
    }

    if (calibrationPrefs != null
        && !mCmHardwareManager.isSupported(FEATURE_DISPLAY_GAMMA_CALIBRATION)) {
      Preference gammaPref = findPreference(KEY_DISPLAY_GAMMA);
      if (gammaPref != null) {
        calibrationPrefs.removePreference(gammaPref);
      }
    }

    mScreenColorSettings = (PreferenceScreen) findPreference(KEY_SCREEN_COLOR_SETTINGS);
    if (calibrationPrefs != null) {
      if (!isPostProcessingSupported(getActivity()) && mScreenColorSettings != null) {
        calibrationPrefs.removePreference(mScreenColorSettings);
      } else if ("user".equals(Build.TYPE)) {
        // Remove simple RGB controls if HSIC controls are available
        Preference displayColor = findPreference(KEY_DISPLAY_COLOR);
        if (displayColor != null) {
          calibrationPrefs.removePreference(displayColor);
        }
      }
    }
  }
  /** Constructor. Defines the LRU cache size and setup the broadcast receiver. */
  private CacheController(Context context) {
    mContext = context;

    final Resources res = context.getResources();

    int maxNumTasksToLoad =
        Settings.System.getIntForUser(
            mContext.getContentResolver(),
            Settings.System.RECENTS_MAX_APPS,
            ActivityManager.getMaxRecentTasksStatic(),
            UserHandle.USER_CURRENT);

    // Gets the dimensions of the device's screen
    DisplayMetrics dm = res.getDisplayMetrics();
    final int screenWidth = dm.widthPixels;
    final int screenHeight = dm.heightPixels;

    // We have ARGB_8888 pixel format, 4 bytes per pixel
    final int size = screenWidth * screenHeight * 4;

    // Calculate how much thumbnails we can put per screen page
    final int thumbnailWidth = res.getDimensionPixelSize(R.dimen.recent_thumbnail_width);
    final int thumbnailHeight = res.getDimensionPixelSize(R.dimen.recent_thumbnail_height);
    final float thumbnailsPerPage =
        (screenWidth / thumbnailWidth) * (screenHeight / thumbnailHeight);

    // Needed screen pages for max thumbnails we can get.
    float neededPages = maxNumTasksToLoad / thumbnailsPerPage;

    // Calculate how much app icons we can put per screen page
    final int iconSize = res.getDimensionPixelSize(R.dimen.recent_app_icon_size);
    final float iconsPerPage = (screenWidth / iconSize) * (screenHeight / iconSize);

    // Needed screen pages for max thumbnails and max app icons we can get.
    neededPages += maxNumTasksToLoad / iconsPerPage;

    // Calculate final cache size, stored in kilobytes.
    int cacheSize = (int) (size * neededPages / 1024);

    // Get max available VM memory, exceeding this amount will throw an
    // OutOfMemory exception. Stored in kilobytes as LruCache takes an
    // int in its constructor.
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // Do not allow more then 1/8 from max available memory.
    if (cacheSize > maxMemory / 8) {
      cacheSize = maxMemory / 8;
    }

    if (mMemoryCache == null) {
      mMemoryCache =
          new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
              return bitmap.getByteCount() / 1024;
            }

            @Override
            protected void entryRemoved(
                boolean evicted, String key, Bitmap oldBitmap, Bitmap newBitmap) {
              /**
               * For normal LRU cache designs this is not a valid approach. Well in our case it is
               * another case. The LRU cache control was designed in this way that we can be 100%
               * sure if a put(K, V) or a remove(V) was called that we do not have any reference to
               * this bitmap anymore. So it can be savely recycled. Cases are: 1. New bitmap was put
               * into the LRU cache. Shortly before the loaders assign the new bitmap to the
               * imageview. So old one has no reference. 2. Task entry was removed which removes as
               * well any reference to the bitmap. So we are save here as well. 3. The
               * CacheController broadcastreceiver removes the bitmap from the LRU cache. When this
               * happens we recycle only if the recent screen is not shown due that we may have a
               * valid reference. This scenario is realy realy rare. So we are save and can recycle
               * in most of the cases if an app was updated by the user. So we do not need to worry
               * to produce a memory leak here at all. 4. The case that the entry was evicted. Here
               * we do not recycle the old image. Well this case should never happen due that our
               * LRU cache is exactly meassured to keep all tasks in memory. Just in case we still
               * check for it.
               */
              if (!evicted) {
                if (key != null && key.equals(getKeyExcludeRecycle())) {
                  setKeyExcludeRecycle(null);
                  if (isRecentScreenShowing()) {
                    return;
                  }
                }
                oldBitmap.recycle();
                oldBitmap = null;
              }
            }
          };
    }

    // Receive broadcasts
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addDataScheme("package");
    mContext.registerReceiver(mBroadcastReceiver, filter);
  }
  void loadTiles() {
    // Reset reference tiles
    mIMETile = null;

    // Filter items not compatible with device
    boolean cameraSupported = QSUtils.deviceSupportsCamera();
    boolean bluetoothSupported = QSUtils.deviceSupportsBluetooth();
    boolean mobileDataSupported = QSUtils.deviceSupportsMobileData(mContext);
    boolean lteSupported = QSUtils.deviceSupportsLte(mContext);
    boolean gpsSupported = QSUtils.deviceSupportsGps(mContext);
    boolean torchSupported = QSUtils.deviceSupportsTorch(mContext);

    if (!bluetoothSupported) {
      TILES_DEFAULT.remove(TILE_BLUETOOTH);
    }

    if (!mobileDataSupported) {
      TILES_DEFAULT.remove(TILE_WIFIAP);
      TILES_DEFAULT.remove(TILE_MOBILEDATA);
      TILES_DEFAULT.remove(TILE_NETWORKMODE);
    }

    if (!lteSupported) {
      TILES_DEFAULT.remove(TILE_LTE);
    }

    if (!gpsSupported) {
      TILES_DEFAULT.remove(TILE_GPS);
    }

    if (!torchSupported) {
      TILES_DEFAULT.remove(TILE_TORCH);
    }

    // Read the stored list of tiles
    ContentResolver resolver = mContext.getContentResolver();
    LayoutInflater inflater = LayoutInflater.from(mContext);
    String tiles =
        Settings.System.getStringForUser(resolver, mSettingsKey, UserHandle.USER_CURRENT);
    if (tiles == null) {
      Log.i(TAG, "Default tiles being loaded");
      tiles = TextUtils.join(TILE_DELIMITER, TILES_DEFAULT);
    }

    Log.i(TAG, "Tiles list: " + tiles);

    // Split out the tile names and add to the list
    boolean dockBatteryLoaded = false;
    NetworkController networkController =
        MSimTelephonyManager.getDefault().isMultiSimEnabled()
            ? mStatusBarService.mMSimNetworkController
            : mStatusBarService.mNetworkController;

    for (String tile : tiles.split("\\|")) {
      QuickSettingsTile qs = null;
      if (tile.equals(TILE_USER)) {
        qs = new UserTile(mContext, this, mHandler);
      } else if (tile.equals(TILE_BATTERY)) {
        qs = new BatteryTile(mContext, this, mStatusBarService.mBatteryController);
      } else if (tile.equals(TILE_SETTINGS)) {
        qs = new PreferencesTile(mContext, this);
      } else if (tile.equals(TILE_WIFI)) {
        qs = new WiFiTile(mContext, this, networkController);
      } else if (tile.equals(TILE_GPS)) {
        qs = new GPSTile(mContext, this, mStatusBarService.mLocationController);
      } else if (tile.equals(TILE_BLUETOOTH) && bluetoothSupported) {
        qs = new BluetoothTile(mContext, this, mStatusBarService.mBluetoothController);
      } else if (tile.equals(TILE_BRIGHTNESS)) {
        qs = new BrightnessTile(mContext, this);
      } else if (tile.equals(TILE_CAMERA) && cameraSupported) {
        qs = new CameraTile(mContext, this, mHandler);
      } else if (tile.equals(TILE_RINGER)) {
        qs = new RingerModeTile(mContext, this);
      } else if (tile.equals(TILE_SYNC)) {
        qs = new SyncTile(mContext, this, mHandler);
      } else if (tile.equals(TILE_WIFIAP) && mobileDataSupported) {
        qs = new WifiAPTile(mContext, this);
      } else if (tile.equals(TILE_SCREENTIMEOUT)) {
        qs = new ScreenTimeoutTile(mContext, this);
      } else if (tile.equals(TILE_MOBILEDATA) && mobileDataSupported) {
        qs = new MobileNetworkTile(mContext, this, networkController);
      } else if (tile.equals(TILE_LOCKSCREEN)) {
        qs = new ToggleLockscreenTile(mContext, this);
      } else if (tile.equals(TILE_NETWORKMODE) && mobileDataSupported) {
        qs = new MobileNetworkTypeTile(mContext, this, networkController);
      } else if (tile.equals(TILE_AUTOROTATE)) {
        qs = new AutoRotateTile(mContext, this);
      } else if (tile.equals(TILE_AIRPLANE)) {
        qs = new AirplaneModeTile(mContext, this, networkController);
      } else if (tile.equals(TILE_TORCH)) {
        qs = new TorchTile(mContext, this);
      } else if (tile.equals(TILE_SLEEP)) {
        qs = new SleepScreenTile(mContext, this);
      } else if (tile.equals(TILE_PROFILE)) {
        mTileStatusUris.add(Settings.System.getUriFor(Settings.System.SYSTEM_PROFILES_ENABLED));
        if (QSUtils.systemProfilesEnabled(resolver)) {
          qs = new ProfileTile(mContext, this);
        }
      } else if (tile.equals(TILE_PERFORMANCE_PROFILE)) {
        if (QSUtils.deviceSupportsPerformanceProfiles(mContext)) {
          qs = new PerformanceProfileTile(mContext, this);
        }
      } else if (tile.equals(TILE_NFC)) {
        // User cannot add the NFC tile if the device does not support it
        // No need to check again here
        qs = new NfcTile(mContext, this);
      } else if (tile.equals(TILE_WIMAX)) {
        // Not available yet
      } else if (tile.equals(TILE_LTE)) {
        qs = new LteTile(mContext, this);
      } else if (tile.equals(TILE_QUIETHOURS)) {
        qs = new QuietHoursTile(mContext, this);
      } else if (tile.equals(TILE_VOLUME)) {
        qs = new VolumeTile(mContext, this);
      } else if (tile.equals(TILE_EXPANDEDDESKTOP)) {
        mTileStatusUris.add(Settings.System.getUriFor(Settings.System.EXPANDED_DESKTOP_STYLE));
        if (QSUtils.expandedDesktopEnabled(resolver)) {
          qs = new ExpandedDesktopTile(mContext, this);
        }
      } else if (tile.equals(TILE_NETWORKADB)) {
        mTileStatusUris.add(Settings.Global.getUriFor(Settings.Global.ADB_ENABLED));
        if (QSUtils.adbEnabled(resolver)) {
          qs = new NetworkAdbTile(mContext, this);
        }
      } else if (tile.equals(TILE_COMPASS)) {
        qs = new CompassTile(mContext, this);
      } else if (tile.equals(TILE_HEADS_UP)) {
        qs = new HeadsUpTile(mContext, this);
      } else if (tile.equals(TILE_THEMES)) {
        qs = new ThemesTile(mContext, this);
      }

      if (qs != null) {
        qs.setupQuickSettingsTile(inflater, mContainerView);
        mQuickSettingsTiles.add(qs);

        // Add dock battery beside main battery when possible
        if (qs instanceof BatteryTile) {
          loadDockBatteryTile(resolver, inflater);
          dockBatteryLoaded = true;
        }
      }
    }

    if (mRibbonMode) {
      return;
    }

    // Load the dynamic tiles
    // These toggles must be the last ones added to the view, as they will show
    // only when they are needed
    if (Settings.System.getIntForUser(
            resolver, Settings.System.QS_DYNAMIC_ALARM, 1, UserHandle.USER_CURRENT)
        == 1) {
      QuickSettingsTile qs = new AlarmTile(mContext, this);
      qs.setupQuickSettingsTile(inflater, mContainerView);
      mQuickSettingsTiles.add(qs);
    }
    if (Settings.System.getIntForUser(
            resolver, Settings.System.QS_DYNAMIC_BUGREPORT, 1, UserHandle.USER_CURRENT)
        == 1) {
      QuickSettingsTile qs = new BugReportTile(mContext, this, mHandler);
      qs.setupQuickSettingsTile(inflater, mContainerView);
      mQuickSettingsTiles.add(qs);
    }
    if (!dockBatteryLoaded) {
      loadDockBatteryTile(resolver, inflater);
    }
    if (Settings.System.getIntForUser(
            resolver, Settings.System.QS_DYNAMIC_WIFI, 1, UserHandle.USER_CURRENT)
        == 1) {
      QuickSettingsTile qs = new RemoteDisplayTile(mContext, this);
      qs.setupQuickSettingsTile(inflater, mContainerView);
      mQuickSettingsTiles.add(qs);
    }
    if (QSUtils.deviceSupportsImeSwitcher(mContext)
        && Settings.System.getIntForUser(
                resolver, Settings.System.QS_DYNAMIC_IME, 1, UserHandle.USER_CURRENT)
            == 1) {
      mIMETile = new InputMethodTile(mContext, this);
      mIMETile.setupQuickSettingsTile(inflater, mContainerView);
      mQuickSettingsTiles.add(mIMETile);
    }
    if (QSUtils.deviceSupportsUsbTether(mContext)
        && Settings.System.getIntForUser(
                resolver, Settings.System.QS_DYNAMIC_USBTETHER, 1, UserHandle.USER_CURRENT)
            == 1) {
      QuickSettingsTile qs = new UsbTetherTile(mContext, this);
      qs.setupQuickSettingsTile(inflater, mContainerView);
      mQuickSettingsTiles.add(qs);
    }
    if (Settings.System.getIntForUser(
            resolver, Settings.System.QS_DYNAMIC_EQUALIZER, 1, UserHandle.USER_CURRENT)
        == 1) {
      QuickSettingsTile qs = new EqualizerTile(mContext, this);
      qs.setupQuickSettingsTile(inflater, mContainerView);
      mQuickSettingsTiles.add(qs);
    }
  }
Exemplo n.º 24
0
 public static boolean expandedDesktopEnabled(ContentResolver resolver) {
   return Settings.System.getIntForUser(
           resolver, Settings.System.EXPANDED_DESKTOP_STYLE, 0, UserHandle.USER_CURRENT_OR_SELF)
       != 0;
 }