public void setStatusBarIconsTint(int iconTint) {
    if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !mKeyboardUp) {
      mNavigationBarIconTint = iconTint;
      setNavigationBarIconTint(iconTint, true);
    }

    if (mSettingsHelper.shouldForceWhiteTintWithOverlay()) {
      iconTint = Color.parseColor("#ccffffff");
    }

    mColorForStatusIcons = iconTint;
    try {
      if (mSystemIconViews != null) {
        for (ImageView view : mSystemIconViews) {
          if (view != null) {
            view.setColorFilter(iconTint, mSettingsHelper.getSystemIconCfType());
          } else {
            mSystemIconViews.remove(view);
          }
        }
      }

      if (mNotificationIconViews != null) {
        for (ImageView view : mNotificationIconViews) {
          if (view != null) {
            view.setColorFilter(iconTint, mSettingsHelper.getNotificationIconCfType());
          } else {
            mNotificationIconViews.remove(view);
          }
        }
      }

      if (mTextLabels != null) {
        for (TextView view : mTextLabels) {
          if (view != null) {
            view.setTextColor(iconTint);
          } else {
            mTextLabels.remove(view);
          }
        }
      }

      if (mStatusBarView != null) {
        Intent intent = new Intent("gravitybox.intent.action.STATUSBAR_COLOR_CHANGED");
        intent.putExtra("iconColorEnable", true);
        intent.putExtra("iconColor", iconTint);
        mStatusBarView.getContext().sendBroadcast(intent);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    setColorForLayout(mStatusIcons, iconTint, mSettingsHelper.getNotificationIconCfType());
    setKitKatBatteryColor(iconTint);
  }
  @SuppressLint("NewApi")
  private void setNavigationBarTint(final int tintColor, boolean force) {
    if (mNavigationBarView == null) return;

    if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !force) {
      log("Ignoring manual navigation bar color change cause we're linked");
      return;
    }

    log("Setting navigation bar color to " + tintColor);

    if (mSettingsHelper.animateStatusBarTintChange()) {
      if (tintColor != KITKAT_TRANSPARENT_COLOR) {
        ValueAnimator colorAnimation =
            ValueAnimator.ofObject(new ArgbEvaluator(), mLastSetNavBarTint, tintColor);
        colorAnimation.addUpdateListener(
            new AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animator) {
                mNavigationBarView.setBackgroundColor((Integer) animator.getAnimatedValue());
              }
            });
        colorAnimation.start();
      } else {
        mNavigationBarView.setBackgroundColor(KITKAT_TRANSPARENT_COLOR);
        Utils.setViewBackground(
            mNavigationBarView,
            new BarBackgroundDrawable(
                mStatusBarView.getContext(), mResources, R.drawable.nav_background));
      }
    } else {
      if (tintColor == KITKAT_TRANSPARENT_COLOR) {
        mNavigationBarView.setBackgroundColor(KITKAT_TRANSPARENT_COLOR);
        Utils.setViewBackground(
            mNavigationBarView,
            new BarBackgroundDrawable(
                mNavigationBarView.getContext(), mResources, R.drawable.nav_background));
      } else {
        mNavigationBarView.setBackgroundColor(tintColor);
      }
    }

    if (mNavigationBarView != null && tintColor != KITKAT_TRANSPARENT_COLOR) {
      Intent intent = new Intent("gravitybox.intent.action.ACTION_NAVBAR_CHANGED");
      intent.putExtra("navbarBgColor", tintColor);
      intent.putExtra("navbarColorEnable", true);
      mNavigationBarView.getContext().sendBroadcast(intent);
    }

    mLastSetNavBarTint = tintColor;
  }
  public void addSystemIconView(ImageView imageView, boolean applyColor) {
    if (!mSystemIconViews.contains(imageView)) mSystemIconViews.add(imageView);

    if (applyColor) {
      imageView.setColorFilter(mColorForStatusIcons, mSettingsHelper.getSystemIconCfType());
    }
  }
  public void onKeyboardVisible(boolean keyboardUp) {
    log("Keyboard visibility changed, isUp? " + keyboardUp);

    mKeyboardUp = keyboardUp;

    if (keyboardUp) {
      setNavigationBarTint(mSettingsHelper.getDefaultTint(Tint.NAV_BAR_IM), true);
      setNavigationBarIconTint(mSettingsHelper.getDefaultTint(Tint.NAV_BAR_ICON_IM), true);
    } else {
      if (mIgnoreNextKeyboardDownChange) {
        mIgnoreNextKeyboardDownChange = false;
        return;
      }
      setNavigationBarTint(mNavigationBarTint, true);
      setNavigationBarIconTint(mNavigationBarIconTint, true);
    }
  }
  public void setRendar(Context ctx, CoreLogic cl, int bgType) {
    int samples = SettingsHelper.getSamples(ctx);
    boolean hasAlpha = SettingsHelper.bgUsesGlAlpha(bgType);
    if (hasAlpha) getHolder().setFormat(PixelFormat.TRANSLUCENT);

    mGLES20IsAvailable = detectOpenGLES20(ctx);
    if (mGLES20IsAvailable) {
      setEGLContextClientVersion(2);
      setEGLConfigChooser(mConfigChooser = new MultisampleConfigChooser(samples, hasAlpha));
      mMikuRendarer = new MikuRendererGLES20(cl, bgType, mConfigChooser.usesCoverageAa());
    } else {
      if (hasAlpha) setEGLConfigChooser(8, 8, 8, 8, 24, 0);
      else setEGLConfigChooser(5, 6, 5, 0, 24, 0);
      mMikuRendarer = new MikuRenderer(cl);
    }
    setRenderer(mMikuRendarer);
  }
  @SuppressLint("NewApi")
  public void setStatusBarTint(final int tintColor) {
    if (mStatusBarView == null) return;

    log("Setting statusbar color to " + tintColor);

    if (mSettingsHelper.animateStatusBarTintChange()) {
      int animateFrom =
          mLastSetColor == KITKAT_TRANSPARENT_COLOR ? Color.TRANSPARENT : mLastSetColor;
      int animateTo = tintColor == KITKAT_TRANSPARENT_COLOR ? Color.TRANSPARENT : tintColor;
      ValueAnimator colorAnimation =
          ValueAnimator.ofObject(new ArgbEvaluator(), animateFrom, animateTo);
      colorAnimation.addUpdateListener(
          new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
              mGradientDrawable.setColor((Integer) animator.getAnimatedValue());
            }
          });
      Utils.setViewBackground(mStatusBarView, mGradientDrawable);
      mGradientDrawable.setMode(mSettingsHelper.getOverlayMode());
      colorAnimation.start();
    } else {
      mStatusBarView.setAlpha(1f);
      if (tintColor == KITKAT_TRANSPARENT_COLOR) {
        Utils.setViewBackground(mStatusBarView, mGradientDrawable);
        mGradientDrawable.setColor(Color.TRANSPARENT);
        mGradientDrawable.setMode(mSettingsHelper.getOverlayMode());
      } else {
        Utils.setViewBackground(mStatusBarView, mGradientDrawable);
        mGradientDrawable.setColor(tintColor);
        mGradientDrawable.setMode(mSettingsHelper.getOverlayMode());
      }
    }

    mLastSetColor = tintColor;

    if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !mKeyboardUp) {
      mNavigationBarTint = tintColor;
      setNavigationBarTint(tintColor, true);
    }
  }
  public static void sendColorChangeIntent(int statusBarTint, int iconColorTint, Context context) {
    Intent intent = new Intent(StatusBarTintApi.INTENT_CHANGE_COLOR_NAME);
    intent.putExtra(StatusBarTintApi.KEY_STATUS_BAR_TINT, statusBarTint);
    intent.putExtra(StatusBarTintApi.KEY_STATUS_BAR_ICON_TINT, iconColorTint);

    intent.putExtra("time", System.currentTimeMillis());
    intent.putExtra(
        "link_panels", mSettingsHelper.shouldLinkPanels(context.getPackageName(), null));

    context.sendBroadcast(intent);
  }
  private void setKitKatBatteryColor(int iconColor) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) return;

    if (mKitKatBatteryView == null) return;

    boolean debug = mSettingsHelper.isDebugMode();

    try {
      final int[] colors = (int[]) XposedHelpers.getObjectField(mKitKatBatteryView, "mColors");
      colors[colors.length - 1] = iconColor;
      XposedHelpers.setObjectField(mKitKatBatteryView, "mColors", colors);
    } catch (NoSuchFieldError e) {
      if (debug) e.printStackTrace();
    }

    try {
      final Paint framePaint =
          (Paint) XposedHelpers.getObjectField(mKitKatBatteryView, "mFramePaint");
      framePaint.setColor(iconColor);
      framePaint.setAlpha(100);
    } catch (NoSuchFieldError e) {
      if (debug) e.printStackTrace();
    }

    try {
      final Paint boltPaint =
          (Paint) XposedHelpers.getObjectField(mKitKatBatteryView, "mBoltPaint");
      boltPaint.setColor(Utils.getIconColorForColor(iconColor, Color.BLACK, Color.WHITE, 0.7f));
      boltPaint.setAlpha(100);
    } catch (NoSuchFieldError e) {
      if (debug) e.printStackTrace();
    }

    try {
      XposedHelpers.setIntField(mKitKatBatteryView, "mChargeColor", iconColor);
    } catch (NoSuchFieldError e) {
      /* Beanstalk, not sure why the ROM changed this */
      try {
        XposedHelpers.setIntField(mKitKatBatteryView, "mBatteryColor", iconColor);
      } catch (NoSuchFieldError e1) {
      }
      if (debug) e.printStackTrace();
    }

    mKitKatBatteryView.invalidate();
  }
  public void onLightsOutChanged(boolean lightsOut) {
    if (!mSettingsHelper.shouldReactToLightsOut()) return;

    log("Lights out changed, isOn? " + lightsOut);

    int transparent = Color.parseColor("#c3121212");
    if (lightsOut) {
      setStatusBarTint(transparent);
      setStatusBarIconsTint(Color.WHITE);

      setNavigationBarTint(transparent, true);
      setNavigationBarIconTint(Color.WHITE, true);
    } else {
      setStatusBarTint(mLastSetColor);
      setStatusBarIconsTint(mLastIconTint);

      setNavigationBarTint(mNavigationBarTint, true);
      setNavigationBarIconTint(mNavigationBarIconTint, true);
    }
  }
Ejemplo n.º 10
0
  private List<AppInfo> loadApps(ProgressDialog dialog) {
    PackageManager packageManager = getPackageManager();
    List<ApplicationInfo> packages =
        packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
    List<AppInfo> apps = new ArrayList<AppInfo>();

    dialog.setMax(packages.size());
    int i = 1;

    for (ApplicationInfo app : packages) {
      AppInfo appInfo = new AppInfo();
      appInfo.title = (String) app.loadLabel(packageManager);
      appInfo.summary = app.packageName;
      appInfo.icon = app.loadIcon(packageManager);
      appInfo.enabled = mSettingsHelper.isListed(app.packageName);
      apps.add(appInfo);
      dialog.setProgress(i++);
    }

    Collections.sort(
        apps,
        new Comparator<AppInfo>() {
          @Override
          public int compare(AppInfo appInfo1, AppInfo appInfo2) {
            boolean app1 = mSettingsHelper.isListed(appInfo1.summary);
            boolean app2 = mSettingsHelper.isListed(appInfo2.summary);

            if (app1 && app2 || !app1 && !app2) {
              return appInfo1.title.compareToIgnoreCase(appInfo2.title);
            } else if (app1) {
              return -1;
            } else if (app2) {
              return 1;
            }

            return 0;
          }
        });

    return apps;
  }
 public void refreshStatusIconColors() {
   if (mStatusIcons != null)
     setColorForLayout(
         mStatusIcons, mColorForStatusIcons, mSettingsHelper.getNotificationIconCfType());
 }
  private void setNavigationBarIconTint(final int tintColor, boolean force) {
    if (mNavigationBarView == null) return;

    if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !force) {
      return;
    }

    ImageView recentsButton = null;
    ImageView menuButton = null;
    ImageView backButton = null;
    ImageView homeButton = null;

    /* LG BUTTONS */
    ImageView qmemoButton = null;
    ImageView notificationButton = null;

    Class<?> NavbarEditor = null;

    try {
      NavbarEditor = getObjectField(mNavigationBarView, "mEditBar").getClass();
    } catch (NoSuchFieldError e) {
    }

    try {
      recentsButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getRecentsButton");
    } catch (NoSuchMethodError e) {
      try {
        if (NavbarEditor != null) {
          recentsButton =
              (ImageView)
                  mNavigationBarView.findViewWithTag(
                      getStaticObjectField(NavbarEditor, "NAVBAR_RECENT"));
        }
      } catch (NoSuchFieldError e1) {
        e1.printStackTrace();
      }
    }

    try {
      menuButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getMenuButton");
    } catch (NoSuchMethodError e) {
      try {
        if (NavbarEditor != null) {
          menuButton =
              (ImageView)
                  mNavigationBarView.findViewWithTag(
                      getStaticObjectField(NavbarEditor, "NAVBAR_ALWAYS_MENU"));
        }
      } catch (NoSuchFieldError e1) {
        e1.printStackTrace();
      }
    }

    try {
      backButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getBackButton");
    } catch (NoSuchMethodError e) {
      try {
        backButton =
            (ImageView)
                mNavigationBarView.findViewWithTag(
                    getStaticObjectField(NavbarEditor, "NAVBAR_BACK"));
      } catch (NoSuchFieldError e1) {
        e1.printStackTrace();
      }
    }

    try {
      homeButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getHomeButton");
    } catch (NoSuchMethodError e) {
      try {
        homeButton =
            (ImageView)
                mNavigationBarView.findViewWithTag(
                    getStaticObjectField(NavbarEditor, "NAVBAR_HOME"));
      } catch (NoSuchFieldError e1) {
        e1.printStackTrace();
      }
    }

    /* LG BUTTONS*/
    if (qmemoButtonRESID > 0)
      qmemoButton = (ImageView) mNavigationBarView.findViewById(qmemoButtonRESID);

    if (notificationButtonRESID > 0)
      notificationButton = (ImageView) mNavigationBarView.findViewById(notificationButtonRESID);

    if (recentsButton != null) recentsButton.setColorFilter(tintColor);
    if (menuButton != null) menuButton.setColorFilter(tintColor);
    if (backButton != null) backButton.setColorFilter(tintColor);
    if (homeButton != null) homeButton.setColorFilter(tintColor);
    if (qmemoButton != null) qmemoButton.setColorFilter(tintColor);
    if (notificationButton != null) notificationButton.setColorFilter(tintColor);

    if (mNavigationBarView != null) {
      Intent intent = new Intent("gravitybox.intent.action.ACTION_NAVBAR_CHANGED");
      intent.putExtra("navbarKeyColor", tintColor);
      intent.putExtra("navbarColorEnable", true);
      mNavigationBarView.getContext().sendBroadcast(intent);
    }
  }
        @Override
        public void onReceive(Context context, Intent intent) {
          if (StatusBarTintApi.INTENT_CHANGE_COLOR_NAME.equals(intent.getAction())) {
            boolean link = intent.getBooleanExtra("link_panels", false);

            if (intent.hasExtra("time")) {
              long time = intent.getLongExtra("time", -1);
              if (time != -1) {
                if (mLastReceivedTime == -1) {
                  mLastReceivedTime = time;
                } else {
                  if (time < mLastReceivedTime) {
                    log("Ignoring change request because of earlier request");
                    log("mLastReceivedTime: " + mLastReceivedTime + " time: " + time);
                    return;
                  } else {
                    mLastReceivedTime = time;
                  }
                }
              }
            }

            if (intent.hasExtra(Common.INTENT_SAVE_ACTIONBAR_COLOR_NAME))
              mActionBarColor = mLastTint;

            if (intent.hasExtra(StatusBarTintApi.KEY_STATUS_BAR_TINT)) {
              mLastTint = intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_TINT, -1);
              setStatusBarTint(mLastTint);
            }

            if (intent.hasExtra(StatusBarTintApi.KEY_STATUS_BAR_ICON_TINT)) {
              mLastIconTint = intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_ICON_TINT, -1);
              setStatusBarIconsTint(mLastIconTint);
            }

            if (intent.hasExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_TINT) && !link) {
              mNavigationBarTint = intent.getIntExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_TINT, -1);
              setNavigationBarTint(mNavigationBarTint, true);
            } else if (link) {
              mNavigationBarTint = intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_TINT, -1);
              setNavigationBarTint(mNavigationBarTint);
            }

            if (intent.hasExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_ICON_TINT) && !link) {
              mNavigationBarIconTint =
                  intent.getIntExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_ICON_TINT, -1);
              setNavigationBarIconTint(mNavigationBarIconTint, true);
            } else if (link) {
              mNavigationBarIconTint =
                  intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_ICON_TINT, -1);
              setNavigationBarIconTint(mNavigationBarIconTint);
            }
          } else if (Common.INTENT_RESET_ACTIONBAR_COLOR_NAME.equals(intent.getAction())) {
            mLastTint = mActionBarColor;
            setStatusBarTint(mActionBarColor);
          } else if (Common.INTENT_SETTINGS_UPDATED.equals(intent.getAction())) {
            Log.d("Xposed", "TintedStatusBar settings updated, reloading...");
            mSettingsHelper.reload();
            mSettingsHelper.reloadOverlayMode();
          } else if (Common.INTENT_KEYBOARD_VISIBLITY_CHANGED.equals(intent.getAction())) {
            if (intent.hasExtra(Common.EXTRA_KEY_KEYBOARD_UP))
              onKeyboardVisible(intent.getBooleanExtra(Common.EXTRA_KEY_KEYBOARD_UP, false));
          } else if (WindowManagerServiceHooks.INTENT_DIM_CHANGED.equals(intent.getAction())) {
            if (intent.hasExtra(WindowManagerServiceHooks.KEY_TARGET_ALPHA))
              onDimLayerChanged(
                  intent.getFloatExtra(WindowManagerServiceHooks.KEY_TARGET_ALPHA, -1));
          }
        }
 public void log(String text) {
   if (mSettingsHelper.isDebugMode()) XposedBridge.log("TintedStatusBar: " + text);
 }