Ejemplo n.º 1
0
  @Override
  public void onReceive(Context context, Intent intent) {
    preferencesManager = PreferencesManager.getInstance(context);
    String action = intent.getAction();

    if (action.compareTo("android.provider.Telephony.SMS_RECEIVED") == 0) {
      // Check if the SMS trigger is enabled
      if (!preferencesManager.smsTriggerEnabled()) return;

      Bundle bundle = intent.getExtras();
      SmsMessage[] messages = null;
      String message = "";

      if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        messages = new SmsMessage[pdus.length];

        for (int i = 0; i < messages.length; i++) {
          messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
          message = messages[i].getMessageBody().toString();
          String source = messages[i].getOriginatingAddress();

          if (MessageHandler.processMessage(context, new SmsReceiver(), message, source))
            // Drop the SMS message so it doesn't go to the user's inbox
            this.abortBroadcast();
        }
      }
    } else {
      int resultCode = getResultCode();
      String message = getResultData();
      String source;

      if (intent.hasExtra("source")) source = intent.getStringExtra("source");
      else
        // If there is no source in the intent, there is no way to send a reply
        return;

      if (intent.getAction().compareTo("com.dririan.RingyDingyDingy.COMMAND_HELP") == 0)
        message = context.getString(R.string.sms_help);
      else if (message == null) {
        switch (resultCode) {
          case Activity.RESULT_OK:
            message = context.getString(R.string.sms_success);
            break;
          case ApiHandler.RESULT_UNKNOWN_COMMAND:
            message = context.getString(R.string.sms_unknown_command);
            break;
          default:
            message = context.getString(R.string.sms_unknown_error);
            break;
        }
      }

      sendSms(context, source, message.replace("<code>", preferencesManager.getCode()));
    }
  }
Ejemplo n.º 2
0
 /** Constructor */
 public TranslatorManager() {
   this.translatorProvider = TranslatorProvider.getInstance();
   this.preferencesManager = PreferencesManager.getInstance();
   this.translators = this.translatorProvider.getTranslators();
   this.preferencesManager.setDefaultTranslator(
       this.translators.get(Messages.TranslatorManager_0));
 }
Ejemplo n.º 3
0
  private void sendSms(Context context, String destination, String message) {
    if (preferencesManager.smsRepliesEnabled()) {
      PendingIntent sentIntent =
          PendingIntent.getBroadcast(
              context, 0, new Intent("com.dririan.RingyDingyDingy.SMS_SENT"), 0);

      SmsManager.getDefault().sendTextMessage(destination, null, message, sentIntent, null);
    }
  }
Ejemplo n.º 4
0
  /**
   * Translate the string passed as parameter
   *
   * @param string string to translate
   * @param fromLanguage language ID to translate from
   * @param toLanguage language ID to translate to
   * @return a TranslationResult object with information about the translation
   */
  public TranslationResult translate(String string, String fromLanguage, String toLanguage) {

    TranslationResult translationResults = null;

    ITranslator translator = preferencesManager.getDefaultTranslator();

    try {
      translationResults = translator.translate(string, fromLanguage, toLanguage);
    } catch (Exception e) {
      BasePlugin.logError(Messages.TranslatorManager_1);
    }

    return translationResults;
  }
Ejemplo n.º 5
0
  /**
   * Translate all strings passed as parameter
   *
   * @param strings strings to translate
   * @param fromLanguage language ID to translate from
   * @param toLanguage language ID to translate to
   * @return a TranslationResult object with information about the translation
   */
  public List<TranslationResult> translateAll(
      List<String> strings, String fromLanguage, String toLanguage) {

    List<TranslationResult> translationResults = null;

    ITranslator translator = preferencesManager.getDefaultTranslator();

    try {
      translationResults = translator.translateAll(strings, fromLanguage, toLanguage, null);
    } catch (Exception e) {
      BasePlugin.logError(Messages.TranslatorManager_2);
    }

    return translationResults;
  }
 public Object[] getElements(Object inputElement) {
   return inputManager.getJbpmInstallationMap().values().toArray();
 }