public CallThread( final Context context, final Speaker speaker, final Settings settings, final String text) { this.context = context; this.speaker = speaker; this.settings = settings; this.text = text; if (!settings.isStartSayCaller()) { return; } if (!text.equals(Contact.UNKNOWN) && !text.equals("")) { this.text = settings.getCallerFormat().replaceFirst("%", text); } start(); }
@Override public void run() { int counter = 0; while (((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getCallState() == TelephonyManager.CALL_STATE_RINGING && counter < settings.getCallerRepeatTimes()) { Log.v("SMN", "speak"); speaker.speak(text); try { sleep(settings.getCallerRepeatSeconds()); } catch (final InterruptedException e) { e.printStackTrace(); } counter++; } context.stopService(new Intent(context, ManagerService.class)); }