@Override
  public void updatePreferences(final Preference preference, Object value) {
    final Resources r = getResources();

    if (r.getString(R.string.p_showNotes).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_showNotes_desc_disabled);
      else preference.setSummary(R.string.EPr_showNotes_desc_enabled);
      if ((Boolean) value != Preferences.getBoolean(preference.getKey(), false)) {
        taskService.clearDetails(Criterion.all);
        Flags.set(Flags.REFRESH);
      }
    } else if (r.getString(R.string.p_transparent).equals(preference.getKey())) {
      if (AndroidUtilities.getSdkVersion() < 5) {
        preference.setEnabled(false);
        preference.setSummary(R.string.EPr_transparent_desc_unsupported);
      } else if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_transparent_desc_disabled);
      else preference.setSummary(R.string.EPr_transparent_desc_enabled);
    }

    // statistics service
    else if (r.getString(R.string.p_statistics).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_statistics_desc_disabled);
      else preference.setSummary(R.string.EPr_statistics_desc_enabled);
    }

    // voice input and output
    if (!addOnService.hasPowerPack()) return;

    if (r.getString(R.string.p_voiceInputEnabled).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_voiceInputEnabled_desc_disabled);
      else preference.setSummary(R.string.EPr_voiceInputEnabled_desc_enabled);
      onVoiceInputStatusChanged(preference, (Boolean) value);
    } else if (r.getString(R.string.p_voiceRemindersEnabled).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_voiceRemindersEnabled_desc_disabled);
      else preference.setSummary(R.string.EPr_voiceRemindersEnabled_desc_enabled);
      onVoiceReminderStatusChanged(preference, (Boolean) value);
    } else if (r.getString(R.string.p_voiceInputCreatesTask).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_voiceInputCreatesTask_desc_disabled);
      else preference.setSummary(R.string.EPr_voiceInputCreatesTask_desc_enabled);
    }
  }
Esempio n. 2
0
  private void onVoiceInputStatusChanged(final Preference preference, boolean newValue) {
    if (!newValue) return;

    final Resources r = getResources();
    if (!VoiceRecognizer.voiceInputAvailable(this)) {
      if (AndroidUtilities.getSdkVersion() > 6) {
        DialogUtilities.okCancelDialog(
            this,
            r.getString(R.string.EPr_voiceInputInstall_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                voiceInputAssistant.showVoiceInputMarketSearch(
                    new OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog1, int which1) {
                        ((CheckBoxPreference) preference).setChecked(false);
                      }
                    });
              }
            },
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      } else {
        DialogUtilities.okDialog(
            this,
            r.getString(R.string.EPr_voiceInputUnavailable_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog1, int which1) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      }
    }
  }
Esempio n. 3
0
  public void showVoiceInputMarketSearch(DialogInterface.OnClickListener onFail) {
    String packageName;
    if (AndroidUtilities.getSdkVersion() <= 7) {
      packageName = "com.google.android.voicesearch.x";
    } else {
      packageName = "com.google.android.voicesearch";
    }

    // User wants to install voice search, take them to the market
    Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(packageName);
    if (activity != null) {
      try {
        if (marketIntent == null) {
          throw new ActivityNotFoundException("No market link supplied"); // $NON-NLS-1$
        }
        activity.startActivity(marketIntent);
      } catch (ActivityNotFoundException ane) {
        DialogUtilities.okDialog(
            activity, activity.getString(R.string.EPr_marketUnavailable_dlg), onFail);
      }
    }
  }
Esempio n. 4
0
 public static boolean speechRecordingAvailable(Context context) {
   return AndroidUtilities.getSdkVersion() >= 8
       && SpeechRecognizer.isRecognitionAvailable(context);
 }
Esempio n. 5
0
  @Override
  public void updatePreferences(final Preference preference, Object value) {
    final Resources r = getResources();

    if (r.getString(R.string.p_showNotes).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_showNotes_desc_disabled);
      else preference.setSummary(R.string.EPr_showNotes_desc_enabled);
      if ((Boolean) value != Preferences.getBoolean(preference.getKey(), false)) {
        taskService.clearDetails(Criterion.all);
        Flags.set(Flags.REFRESH);
      }
    } else if (r.getString(R.string.p_fullTaskTitle).equals(preference.getKey())) {
      if (value != null && (Boolean) value)
        preference.setSummary(R.string.EPr_fullTask_desc_enabled);
      else preference.setSummary(R.string.EPr_fullTask_desc_disabled);
    } else if (r.getString(R.string.p_theme).equals(preference.getKey())) {
      if (AndroidUtilities.getSdkVersion() < 5) {
        preference.setEnabled(false);
        preference.setSummary(R.string.EPr_theme_desc_unsupported);
      } else {
        int index = 0;
        if (value instanceof String && !TextUtils.isEmpty((String) value))
          index =
              AndroidUtilities.indexOf(
                  r.getStringArray(R.array.EPr_theme_settings), (String) value);
        if (index < 0) index = 0;
        preference.setSummary(
            getString(R.string.EPr_theme_desc, r.getStringArray(R.array.EPr_themes)[index]));
      }
    } else if (r.getString(R.string.p_theme_widget).equals(preference.getKey())) {
      if (AndroidUtilities.getSdkVersion() < 5) {
        preference.setEnabled(false);
        preference.setSummary(R.string.EPr_theme_desc_unsupported);
      } else {
        int index = 0;
        if (value instanceof String && !TextUtils.isEmpty((String) value))
          index =
              AndroidUtilities.indexOf(
                  r.getStringArray(R.array.EPr_theme_widget_settings), (String) value);
        if (index < 0) index = 0;
        preference.setSummary(
            getString(R.string.EPr_theme_desc, r.getStringArray(R.array.EPr_themes_widget)[index]));
      }
    }

    // pp preferences
    else if (booleanPreference(
        preference,
        value,
        R.string.p_statistics,
        R.string.EPr_statistics_desc_disabled,
        R.string.EPr_statistics_desc_enabled)) ;
    else if (booleanPreference(
        preference,
        value,
        R.string.p_autoIdea,
        R.string.EPr_ideaAuto_desc_disabled,
        R.string.EPr_ideaAuto_desc_enabled)) ;

    // voice input and output
    if (!addOnService.hasPowerPack()) return;

    if (r.getString(R.string.p_voiceInputEnabled).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_voiceInputEnabled_desc_disabled);
      else preference.setSummary(R.string.EPr_voiceInputEnabled_desc_enabled);
      onVoiceInputStatusChanged(preference, (Boolean) value);
    } else if (r.getString(R.string.p_voiceRemindersEnabled).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_voiceRemindersEnabled_desc_disabled);
      else preference.setSummary(R.string.EPr_voiceRemindersEnabled_desc_enabled);
      onVoiceReminderStatusChanged(preference, (Boolean) value);
    } else if (r.getString(R.string.p_voiceInputCreatesTask).equals(preference.getKey())) {
      if (value != null && !(Boolean) value)
        preference.setSummary(R.string.EPr_voiceInputCreatesTask_desc_disabled);
      else preference.setSummary(R.string.EPr_voiceInputCreatesTask_desc_enabled);
    }
  }
Esempio n. 6
0
  private void showCalReminder(Context context, long eventId, boolean fromPostpone) {
    ContentResolver cr = context.getContentResolver();
    Uri eventUri = Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);

    if (AndroidUtilities.getSdkVersion() <= 7) return;

    String[] eventArg = new String[] {Long.toString(eventId)};
    Cursor event =
        cr.query(eventUri, EVENTS_PROJECTION, Calendars.ID_COLUMN_NAME + " = ?", eventArg, null);
    try {
      if (event.moveToFirst()) {
        int dtstartIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_DTSTART_COL);
        int dtendIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_DTEND_COL);
        int titleIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_NAME_COL);

        String title = event.getString(titleIndex);
        long startTime = event.getLong(dtstartIndex);
        long endTime = event.getLong(dtendIndex);

        boolean shouldShowReminder;
        if (fromPostpone) {
          long timeAfter = DateUtilities.now() - endTime;
          shouldShowReminder = (timeAfter > DateUtilities.ONE_MINUTE * 2);
        } else {
          long timeUntil = startTime - DateUtilities.now();
          shouldShowReminder = (timeUntil > 0 && timeUntil < DateUtilities.ONE_MINUTE * 20);
        }

        if (shouldShowReminder) {
          // Get attendees
          Cursor attendees =
              cr.query(
                  Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_ATTENDEES),
                  ATTENDEES_PROJECTION,
                  Calendars.ATTENDEES_EVENT_ID_COL + " = ? ",
                  eventArg,
                  null);
          try {
            // Do something with attendees
            int emailIndex = attendees.getColumnIndexOrThrow(Calendars.ATTENDEES_EMAIL_COL);
            int nameIndex = attendees.getColumnIndexOrThrow(Calendars.ATTENDEES_NAME_COL);

            ArrayList<String> names = new ArrayList<String>();
            ArrayList<String> emails = new ArrayList<String>();

            Account[] accountArray = AccountManager.get(context).getAccounts();
            Set<String> phoneAccounts = new HashSet<String>();
            for (Account a : accountArray) {
              phoneAccounts.add(a.name);
            }

            String astridUser = ActFmPreferenceService.thisUser().optString("email");
            if (!TextUtils.isEmpty(astridUser)) phoneAccounts.add(astridUser);

            boolean includesMe = false;
            for (attendees.moveToFirst(); !attendees.isAfterLast(); attendees.moveToNext()) {
              String name = attendees.getString(nameIndex);
              String email = attendees.getString(emailIndex);
              if (!TextUtils.isEmpty(email)) {
                if (phoneAccounts.contains(email)) {
                  includesMe = true;
                  continue;
                }
                if (Constants.DEBUG)
                  Log.w(CalendarAlarmScheduler.TAG, "Attendee: " + name + ", email: " + email);
                names.add(name);
                emails.add(email);
              }
            }

            if (emails.size() > 0 && includesMe) {
              Intent reminderActivity = new Intent(context, CalendarReminderActivity.class);
              reminderActivity.putStringArrayListExtra(CalendarReminderActivity.TOKEN_NAMES, names);
              reminderActivity.putStringArrayListExtra(
                  CalendarReminderActivity.TOKEN_EMAILS, emails);
              reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_ID, eventId);
              reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_NAME, title);
              reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_START_TIME, startTime);
              reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_END_TIME, endTime);
              reminderActivity.putExtra(CalendarReminderActivity.TOKEN_FROM_POSTPONE, fromPostpone);
              reminderActivity.setFlags(
                  Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
              context.startActivity(reminderActivity);
            }
          } finally {
            attendees.close();
          }
        }
      }
    } finally {
      event.close();
    }
  }