public static String loadTextAssetAsString(Context context, String path) { AssetManager assetManager = context.getResources().getAssets(); BufferedReader reader = null; try { StringBuilder builder = new StringBuilder(); reader = new BufferedReader(new InputStreamReader(assetManager.open(path))); char[] buf = new char[READ_BUF_LEN]; int count = 0; while ((count = reader.read(buf, 0, READ_BUF_LEN)) != -1) { builder.append(buf, 0, count); } return builder.toString(); } catch (IOException e) { } finally { Util.ensureClosed(reader); } return null; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.email); final EditText messageText = (EditText) findViewById(R.id.message); final ApptentiveDialogButton declineButton = (ApptentiveDialogButton) findViewById(R.id.decline); final ApptentiveDialogButton submitButton = (ApptentiveDialogButton) findViewById(R.id.submit); // Pre-populate a list of possible emails based on those pulled from the phone. ArrayAdapter<String> emailAdapter = new ArrayAdapter<String>( getContext(), android.R.layout.simple_dropdown_item_1line, Util.getAllUserAccountEmailAddresses(getContext())); emailText.setAdapter(emailAdapter); emailText.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { emailText.showDropDown(); return false; } }); emailText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { email = charSequence; validateForm(submitButton); } @Override public void afterTextChanged(Editable editable) {} }); messageText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { message = charSequence; validateForm(submitButton); } @Override public void afterTextChanged(Editable editable) {} }); declineButton.setEnabled(true); declineButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { cancel(); } }); submitButton.setEnabled(false); submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (email != null && email.length() != 0 && !Util.isEmailValid(email.toString())) { EmailValidationFailedDialog dialog = new EmailValidationFailedDialog(getContext()); dialog.show(); return; } if (MessageCenterIntroDialog.this.onSendListener != null) { onSendListener.onSend( emailText.getText().toString(), messageText.getText().toString()); } } }); validateForm(submitButton); }
@Override public void show(final Activity activity) { super.show(activity); activity.setContentView(R.layout.apptentive_feedback_dialog_interaction); // Legacy support: We can remove this when we switch over to 100% interaction based Message // Center. SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); prefs .edit() .putBoolean(Constants.PREF_KEY_MESSAGE_CENTER_SHOULD_SHOW_INTRO_DIALOG, false) .commit(); if (!thankYouDialogVisible) { if (!feedbackDialogVisible) { EngagementModule.engageInternal(activity, interaction.getType().name(), CODE_POINT_LAUNCH); } String title = interaction.getTitle(); final AutoCompleteTextView emailView = (AutoCompleteTextView) activity.findViewById(R.id.email); EditText messageView = (EditText) activity.findViewById(R.id.message); Button noButton = (Button) activity.findViewById(R.id.decline); final Button sendButton = (Button) activity.findViewById(R.id.submit); // Title if (title != null) { TextView titleView = (TextView) activity.findViewById(R.id.title); titleView.setText(title); } // Body String body = interaction.getBody(activity); TextView bodyView = (TextView) activity.findViewById(R.id.body); bodyView.setText(body); // Email String personEnteredEmail = PersonManager.loadPersonEmail(activity); if (!interaction.isAskForEmail()) { emailView.setVisibility(View.GONE); } else if (!Util.isEmpty(personEnteredEmail)) { emailView.setVisibility(View.GONE); email = personEnteredEmail; } else { String personInitialEmail = PersonManager.loadInitialPersonEmail(activity); if (!Util.isEmpty(personInitialEmail)) { emailView.setText(personInitialEmail); email = personInitialEmail; } String emailHintText = interaction.getEmailHintText(); if (emailHintText != null) { emailView.setHint(emailHintText); } else if (interaction.isEmailRequired()) { emailView.setHint(R.string.apptentive_edittext_hint_email_required); } // Pre-populate a list of possible emails based on those pulled from the phone. ArrayAdapter<String> emailAdapter = new ArrayAdapter<String>( activity, android.R.layout.simple_dropdown_item_1line, Util.getAllUserAccountEmailAddresses(activity)); emailView.setAdapter(emailAdapter); emailView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { emailView.showDropDown(); return false; } }); emailView.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { email = charSequence; validateForm(sendButton); } @Override public void afterTextChanged(Editable editable) {} }); } // Message String messageHintText = interaction.getMessageHintText(); if (messageHintText != null) { messageView.setHint(messageHintText); } messageView.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { message = charSequence; validateForm(sendButton); } @Override public void afterTextChanged(Editable editable) {} }); // No String no = interaction.getDeclineText(); if (no != null) { noButton.setText(no); } noButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { cleanup(); EngagementModule.engageInternal( activity, interaction.getType().name(), CODE_POINT_DECLINE); activity.finish(); } }); // Send String send = interaction.getSubmitText(); if (send != null) { sendButton.setText(send); } sendButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (email != null && email.length() != 0 && !Util.isEmailValid(email.toString())) { EmailValidationFailedDialog dialog = new EmailValidationFailedDialog(activity); dialog.show(); return; } // Before we send this message, send an auto message. createMessageCenterAutoMessage(activity); sendMessage(activity); EngagementModule.engageInternal( activity, interaction.getType().name(), CODE_POINT_SUBMIT); thankYouDialogVisible = true; feedbackDialogVisible = false; activity.findViewById(R.id.feedback_dialog).setVisibility(View.GONE); activity.findViewById(R.id.thank_you_dialog).setVisibility(View.VISIBLE); } }); } else { activity.findViewById(R.id.feedback_dialog).setVisibility(View.GONE); activity.findViewById(R.id.thank_you_dialog).setVisibility(View.VISIBLE); } // Thank You Title TextView thankYouTitleView = (TextView) activity.findViewById(R.id.thank_you_title); String thankYouTitle = interaction.getThankYouTitle(); if (thankYouTitle != null) { thankYouTitleView.setText(thankYouTitle); } // Thank You Body TextView thankYouBodyView = (TextView) activity.findViewById(R.id.thank_you_body); String thankYouBody = interaction.getThankYouBody(); if (thankYouBody != null) { thankYouBodyView.setText(thankYouBody); } // Thank You Close Button Button thankYouCloseButton = (Button) activity.findViewById(R.id.thank_you_close); String thankYouCloseText = interaction.getThankYouCloseText(); if (thankYouCloseText != null) { thankYouCloseButton.setText(thankYouCloseText); } thankYouCloseButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { cleanup(); EngagementModule.engageInternal( activity, interaction.getType().name(), CODE_POINT_SKIP_VIEW_MESSAGES); activity.finish(); } }); // Thank You View Messages Button Button thankYouViewMessagesButton = (Button) activity.findViewById(R.id.thank_you_view_messages); String thankYouViewMessages = interaction.getThankYouViewMessagesText(); if (thankYouViewMessages != null) { thankYouViewMessagesButton.setText(thankYouViewMessages); } thankYouViewMessagesButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { cleanup(); EngagementModule.engageInternal( activity, interaction.getType().name(), CODE_POINT_VIEW_MESSAGES); activity.finish(); } }); feedbackDialogVisible = true; }