Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. void show_alert(String title, String message) {
  2. Log.d("ipov","show_alert(+)");
  3. SMSDialogFragment smsDialogFragment = new SMSDialogFragment();
  4. smsDialogFragment.title = title;
  5. smsDialogFragment.message = message;
  6. smsDialogFragment.show(getFragmentManager(), "smsDialog");
  7. Log.d("ipov","show_alert(-)");
  8. }
  9.  
  10. public class SMSDialogFragment extends DialogFragment {
  11.  
  12. public String title;
  13. public String message;
  14. /* The activity that creates an instance of this dialog fragment must
  15. * implement this interface in order to receive event callbacks.
  16. * Each method passes the DialogFragment in case the host needs to query it. */
  17. public interface SMSDialogFragmentListener {
  18. public void onDialogPositiveClick(DialogFragment dialog);
  19. //public void onDialogNegativeClick(DialogFragment dialog);
  20. }
  21.  
  22. // Use this instance of the interface to deliver action events
  23. SMSDialogFragmentListener mListener;
  24.  
  25. // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
  26. @Override
  27. public void onAttach(Activity activity) {
  28. Log.d("ipov","dialog onAttach activity.getClass().getName()="+activity.getClass().getName());
  29. super.onAttach(activity);
  30.  
  31. // Verify that the host activity implements the callback interface
  32. try {
  33. // Instantiate the NoticeDialogListener so we can send events to the host
  34. mListener = (SMSDialogFragmentListener) activity;
  35. } catch (ClassCastException e) {
  36. // The activity doesn't implement the interface, throw exception
  37. throw new ClassCastException(activity.toString()
  38. + " must implement SMSDialogFragmentListener");
  39. }
  40. }
  41.  
  42.  
  43. @Override
  44. public Dialog onCreateDialog(Bundle savedInstanceState) {
  45. if(savedInstanceState != null)
  46. Log.d("ipov","dialog onCreateDialog savedInstanceState.toString()="+savedInstanceState.toString());
  47. Log.d("ipov","dialog onCreateDialog getActivity().getClass().getName()="+getActivity().getClass().getName());
  48.  
  49. // Use the Builder class for convenient dialog construction
  50. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  51. builder.setTitle(title)
  52. .setMessage(message)
  53. .setPositiveButton("button_1", new DialogInterface.OnClickListener() {
  54. public void onClick(DialogInterface dialog, int id) {
  55. //mListener.onDialogPositiveClick(SMSDialogFragment.this);
  56. }
  57. })
  58. .setNegativeButton("button_2", new DialogInterface.OnClickListener() {
  59. public void onClick(DialogInterface dialog, int id) {
  60. // User cancelled the dialog
  61. }
  62. });
  63. // Create the AlertDialog object and return it
  64. return builder.create();
  65. }
  66.  
  67. private class LoadSMSTask extends AsyncTask<Void, Void, String> {
  68.  
  69. public AsyncResponse delegate = null;
  70.  
  71. @Override
  72. protected String doInBackground(Void... params) {
  73. // получаем данные с внешнего ресурса
  74. processSmsForSender( account.getSMSSenderName() );
  75. return null;
  76. }
  77.  
  78. @Override
  79. protected void onPostExecute(String strJson) {
  80. Log.d("ipov","LoadSMSTask onPostExecute(+)");
  81. super.onPostExecute(strJson);
  82. JSONObject dataJsonObj = null;
  83. // выводим целиком полученную json-строку
  84. try {
  85. dataJsonObj = new JSONObject(
  86. "{n" +
  87. " "type": "smses_processed"n" +
  88. "}n"
  89. );
  90. } catch (JSONException e) {
  91. e.printStackTrace();
  92. }
  93. delegate.onJSONReceived(dataJsonObj,null);
  94. //RFin.initMainScreen();
  95. }
  96. }
  97.  
  98. public class AddAccount extends AppCompatActivity implements AsyncResponse, SMSDialogFragment.SMSDialogFragmentListener {
  99. ...
  100. @Override
  101. public void onJSONReceived(JSONObject jsonObject, String jsonErrorText){
  102. Log.d("ipov","onJSONReceived(+)");
  103. ...
  104. Log.d("ipov","onJSONReceived smses_processed show_alert");
  105. show_alert("sms processig error", parsingErrors[i]);
  106. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement