Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. public class RoundedDialog {
  2.  
  3. private Activity activity;
  4. private Context c;
  5. private TextView titleTextView;
  6. private TextView msgTextView;
  7. private Button btn;
  8. private int theme;
  9. private int layout;
  10. private String dialogTitle;
  11. private String dialogMsg;
  12.  
  13.  
  14. public RoundedDialog(Context context, Activity activity , int themeID, int layoutID, TextView titleTextView, TextView msgTextView, Button button, String title, String message) {
  15. c = context;
  16. this. activity = activity;
  17. theme = themeID;
  18. layout = layoutID;
  19. this.titleTextView = titleTextView;
  20. this.msgTextView = msgTextView;
  21. btn = button;
  22. dialogTitle = title;
  23. dialogMsg = message;
  24. }
  25.  
  26. /**
  27. * Generates a dialog based on the parameters of the class.
  28. * Don't forget to call .show()
  29. * @return A custom AlertDialog
  30. **/
  31. public AlertDialog generateDialog() {
  32. final AlertDialog.Builder builder = new AlertDialog.Builder(c,theme);
  33. ViewGroup viewGroup = activity.findViewById(android.R.id.content);
  34. View dialogView = LayoutInflater.from(c).inflate(layout,viewGroup,false);
  35. titleTextView.setText(dialogTitle);
  36. msgTextView.setText(dialogMsg);
  37. builder.setView(dialogView);
  38. final AlertDialog alertDialog = builder.create();
  39. btn.setOnClickListener(new View.OnClickListener() {
  40.  
  41. @Override
  42. public void onClick(View view) {
  43. alertDialog.dismiss();
  44. }
  45. });
  46. return alertDialog;
  47. }
  48. }
  49.  
  50. public class MainActivity extends AppCompatActivity {
  51.  
  52. @Override
  53. protected void onCreate(Bundle savedInstanceState) {
  54. super.onCreate(savedInstanceState);
  55. setContentView(R.layout.activity_main);
  56.  
  57. BottomNavigationView navbar = findViewById(R.id.bottom_nav_bar);
  58. navbar.setSelectedItemId(R.id.home);
  59.  
  60. navbar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
  61. @Override
  62. public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  63. switch(item.getItemId()) {
  64. case R.id.culture:
  65. Toasty.info(getApplicationContext(),"Culture selected!", Toast.LENGTH_SHORT,true).show();
  66. break;
  67. case R.id.beaches:
  68. Toasty.info(getApplicationContext(),"Beaches selected!", Toast.LENGTH_SHORT,true).show();
  69. break;
  70. case R.id.home:
  71. Toasty.info(getApplicationContext(),"Home selected!", Toast.LENGTH_SHORT,true).show();
  72. break;
  73. case R.id.poi:
  74. Toasty.info(getApplicationContext(),"POI selected!", Toast.LENGTH_SHORT,true).show();
  75. break;
  76. default:
  77.  
  78. }
  79.  
  80. return true;
  81. }
  82. });
  83.  
  84. TextView dialogTitle = findViewById(R.id.title);
  85. TextView dialogMessage = findViewById(R.id.msg);
  86. Button button = findViewById(R.id.buttonOK);
  87. RoundedDialog roundedDialog = new RoundedDialog(this,this,R.style.RoundedDialog,R.layout.test,dialogTitle,dialogMessage,button,"Title","Message");
  88. roundedDialog.generateDialog().show();
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement