SHARE
TWEET

Untitled

a guest Apr 18th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:background="@color/colorPrimary"
  6.     android:id="@+id/toastRoot"
  7.     xmlns:app="http://schemas.android.com/apk/res-auto">
  8.     <TextView
  9.     android:id="@+id/textViewInToast"
  10.     app:layout_constraintTop_toTopOf="parent"
  11.     android:layout_width="match_parent"
  12.     android:layout_height="wrap_content" />
  13.     <SeekBar
  14.         android:id="@+id/seekBarInToast"
  15.         app:layout_constraintTop_toBottomOf="@id/textViewInToast"
  16.         app:layout_constraintLeft_toLeftOf="parent"
  17.         android:max="100"
  18.         android:layout_width="320dp"
  19.         android:layout_height="wrap_content" />
  20. </android.support.constraint.ConstraintLayout>
  21.  
  22. package com.example.mkaya.lab2april2019;
  23.  
  24. import android.support.design.widget.Snackbar;
  25. import android.support.v7.app.AppCompatActivity;
  26. import android.os.Bundle;
  27. import android.view.Gravity;
  28. import android.view.LayoutInflater;
  29. import android.view.View;
  30. import android.view.ViewGroup;
  31. import android.widget.RadioButton;
  32. import android.widget.SeekBar;
  33. import android.widget.TextView;
  34. import android.widget.Toast;
  35. import android.widget.ToggleButton;
  36.  
  37. public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
  38. private TextView textView;
  39. private ToggleButton toggleButton;
  40. private SeekBar seekBar;
  41. private Integer oldValue=50;
  42. @Override
  43.     protected void onCreate(Bundle savedInstanceState) {
  44. super.onCreate(savedInstanceState);
  45.         setContentView(R.layout.activity_main);
  46. textView=findViewById(R.id.scoretxt);
  47. toggleButton=findViewById(R.id.disable_snack);
  48. seekBar=findViewById(R.id.mySeekBar);
  49. seekBar.setOnSeekBarChangeListener(this);
  50.     }
  51. @Override
  52.     public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
  53. textView.setText(Integer.toString(seekBar.getProgress()));
  54.     }
  55.  
  56. @Override
  57.     public void onStartTrackingTouch(SeekBar seekBar) {
  58. oldValue=seekBar.getProgress();
  59.     }
  60.  
  61. @Override
  62.     public void onStopTrackingTouch(final SeekBar seekBar) {
  63. if(toggleButton.isChecked()){
  64.             Snackbar snackbar=Snackbar.make(seekBar,"Pregress Changed",Snackbar.LENGTH_LONG)
  65.                     .setAction("UNDO", new View.OnClickListener() {
  66. @Override
  67.                         public void onClick(View view) {
  68. textView.setText(Integer.toString(oldValue));
  69. seekBar.setProgress(oldValue);
  70.                                 Snackbar snackbar1=Snackbar.make(view,"Progress reset",Snackbar.LENGTH_SHORT);
  71.                                 snackbar1.show();
  72.                         }
  73.                     });
  74.             snackbar.show();
  75.  
  76.         }
  77.  
  78.     }
  79.  
  80. public void CreateToast(View view) {
  81.         RadioButton simpleRB=findViewById(R.id.rb_simple);
  82. if(simpleRB.isChecked()){
  83.             Toast t=Toast.makeText(this, "Simple Toast!", Toast.LENGTH_SHORT);
  84.             t.show();
  85.         }
  86. else
  87.         {
  88. //create a custome toast message
  89.             LayoutInflater inflater=getLayoutInflater();
  90.             View layout=inflater.inflate(R.layout.custom_toast,(ViewGroup)findViewById(R.id.toastRoot));
  91.  
  92.             SeekBar seekBarInToast=layout.findViewById(R.id.seekBarInToast);
  93.             seekBarInToast.setProgress(seekBar.getProgress());
  94.  
  95.             TextView textViewInToast=layout.findViewById(R.id.textViewInToast);
  96.             textViewInToast.setText(((Integer)seekBar.getProgress()).toString());
  97.  
  98.             Toast toast=new Toast(this);
  99.             toast.setGravity(Gravity.BOTTOM,0,0);
  100.             toast.setDuration(Toast.LENGTH_LONG);
  101.             toast.setView(layout);
  102.             toast.show();
  103.  
  104.         }
  105.     }
  106. }
  107.  
  108. <?xml version="1.0" encoding="utf-8"?>
  109. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  110.     xmlns:app="http://schemas.android.com/apk/res-auto"
  111.     xmlns:tools="http://schemas.android.com/tools"
  112.     android:layout_width="match_parent"
  113.     android:layout_height="match_parent"
  114.     tools:context=".MainActivity">
  115.  
  116.     <TextView
  117.         android:id="@+id/scoretxt"
  118.         android:text="50"
  119.         app:layout_constraintTop_toTopOf="parent"
  120.         android:layout_width="match_parent"
  121.         android:layout_height="wrap_content" />
  122.     <ToggleButton
  123.         android:id="@+id/disable_snack"
  124.         app:layout_constraintTop_toBottomOf="@id/scoretxt"
  125.         app:layout_constraintLeft_toLeftOf="parent"
  126.         android:layout_width="wrap_content"
  127.         android:layout_height="wrap_content" />
  128.     <SeekBar
  129.         android:id="@+id/mySeekBar"
  130.         android:max="100"
  131.         android:progress="50"
  132.         app:layout_constraintLeft_toRightOf="@id/disable_snack"
  133.         app:layout_constraintRight_toRightOf="parent"
  134.         app:layout_constraintTop_toTopOf="@id/disable_snack"
  135.         app:layout_constraintBottom_toBottomOf="@id/disable_snack"
  136.         android:layout_width="0dp"
  137.         android:layout_height="0dp" />
  138.     <RadioGroup
  139.         android:id="@+id/rb"
  140.         app:layout_constraintLeft_toLeftOf="parent"
  141.         app:layout_constraintTop_toBottomOf="@id/disable_snack"
  142.         android:layout_width="wrap_content"
  143.         android:layout_height="wrap_content">
  144.         <RadioButton
  145.             android:id="@+id/rb_simple"
  146.             android:checked="true"
  147.             android:text="Simple"
  148.             android:layout_width="wrap_content"
  149.             android:layout_height="wrap_content" />
  150.         <RadioButton
  151.             android:id="@+id/rb_custom"
  152.             android:text="Custom"
  153.             android:layout_width="wrap_content"
  154.             android:layout_height="wrap_content" />
  155.     </RadioGroup>
  156.     <Button
  157.         android:id="@+id/createToastBtn"
  158.         app:layout_constraintLeft_toRightOf="@id/rb"
  159.         app:layout_constraintRight_toRightOf="parent"
  160.         app:layout_constraintTop_toTopOf="@id/rb"
  161.         app:layout_constraintBottom_toBottomOf="@id/rb"
  162.         android:layout_width="0dp"
  163.         android:layout_height="0dp"
  164.         android:text="Create Toast"
  165.         android:XonClick="CreateToast"/>
  166. </android.support.constraint.ConstraintLayout>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top