Exemple #1
0
 // изменение текста на кнопках
 private void showStationButtons() {
   Object button;
   Log.d(TAG, "showStationButtons");
   // если находимся в режиме поиска, то кнопки не переименовываем
   boolean mSearching = XposedHelpers.getBooleanField(radioService, "mSearching");
   if (mSearching) return;
   int mBand = XposedHelpers.getIntField(radioService, "mBand");
   int[][] freq = (int[][]) XposedHelpers.getObjectField(radioService, "freq");
   // цикл по кнопкам
   for (int i = 0; i < 6; i++) {
     // поиск кнопки
     button = XposedHelpers.callMethod(mUi, "getChannelButton", i);
     if (button == null) return;
     // выходим, если это не кнопка, а layout
     if (!(button instanceof Button)) return;
     // частота кнопки
     int buttonFreq = freq[mBand][i];
     // форматируем частоту
     String freqStr = getFrequencyString(buttonFreq);
     // короткое наименование
     String text = getShortStationName(freqStr);
     Log.d(TAG, "freq=" + freqStr + ", text=" + text);
     if (!text.isEmpty())
       // изменим текст на кнопке, если он задан
       ((Button) button).setText(text);
   }
 }
    @Override
    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
      try {
        String uuid =
            Common.byteArrayToHexString((byte[]) XposedHelpers.callMethod(param.args[0], "getUid"));

        Set<String> authorizedNfcTags =
            prefs.getStringSet(Common.PREF_NFC_KEYS, new HashSet<String>());
        Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
        if (mDebugMode) XposedBridge.log(uuid.trim());

        if (context != null) {
          if (authorizedNfcTags != null && authorizedNfcTags.contains(uuid.trim())) {
            if (mDebugMode) XposedBridge.log("Got matching NFC tag, unlocking device...");
            context.sendBroadcast(new Intent(Common.INTENT_UNLOCK_DEVICE));
          }

          if (!prefs.getBoolean(Common.PREF_TAGLOST, true)) return;

          XposedHelpers.setAdditionalInstanceField(param.args[0], "mContext", context);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  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();
  }
  @SuppressLint("SimpleDateFormat")
  @SuppressWarnings("deprecation")
  private static void setupSmartAlarm(MethodHookParam param, int timeout) {
    if (((Intent) param.args[0]).getBooleanExtra("alarmSet", false)) {
      Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
      String nextAlarm =
          Settings.System.getString(
              context.getContentResolver(), android.provider.Settings.System.NEXT_ALARM_FORMATTED);
      DateFormat sdf = new SimpleDateFormat("EEE hh:mm aa");
      Date alarmDate = null;
      try {
        alarmDate = sdf.parse(nextAlarm);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      int alarmDay = alarmDate.getDay();
      Calendar now = Calendar.getInstance();
      Date currentDate = now.getTime();
      int todayDay = currentDate.getDay();
      int daysDiff = 0;
      if (todayDay > alarmDay) {
        daysDiff = ((7 + (alarmDay - todayDay)) % 7) + 1;
      } else {
        daysDiff = ((7 + (alarmDay - todayDay)) % 7);
      }
      now.add(Calendar.DATE, daysDiff);
      Date alarmFulldate = now.getTime();
      alarmFulldate.setHours(alarmDate.getHours());
      alarmFulldate.setMinutes(alarmDate.getMinutes());
      alarmFulldate.setSeconds(0);
      long millis = alarmFulldate.getTime() - new Date().getTime();

      if (millis > (timeout * 60 * 1000)) {
        ((Intent) param.args[0]).putExtra("alarmSet", false);
      }
    }
  }