Toast custom / variable / timer / layout / animation



📋
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="onesignal.aksr.com.br.onesignal">

    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" android:maxSdkVersion="27"  />
    <application        
android:allowBackup="true"        
android:icon="@drawable/ic_stat_onesignal_default"        
android:label="@string/app_name"        
android:roundIcon="@drawable/ic_stat_onesignal_default"        
android:supportsRtl="true"        
android:theme="@style/AppTheme">
        <activity            
android:name=".Toasting"            
android:label="@string/app_name"            
android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



📋
package My_package_name;

import android.content.Context;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.concurrent.TimeUnit;

public class Toasting extends AppCompatActivity {
    Button Toast1;
    Button Toast2;
    Button Toast3;
    Button Toast4;
    EditText Variavel;
    Button Toast5;
    ImageView imageInToast;
    TextView textInToastAnimated;
    TextView textInToast;
    Toast Show;
    Toast toastCustom;
    RelativeLayout ToasCustom;
    LayoutInflater inflaterToasCustom;
    View layoutToasCustom;
    RelativeLayout ToasAnimated;
    RelativeLayout animarLayout;
    CountDownTimer toastTimer;
    Animation AnimarToast;
    String Var = "Isto é uma variavel : %1$s "/* %1$s = Algum valor que será definido*/;
    CharSequence Valor;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toast_layout);
        final Context context = this;
        Toast1 = (Button)findViewById(R.id.Toast1);
        Toast2 = (Button)findViewById(R.id.Toast2);
        Variavel = (EditText)findViewById(R.id.Variavel);
        Toast3 = (Button)findViewById(R.id.Toast3);
        Toast4 = (Button)findViewById(R.id.Toast4);
        Toast5 = (Button)findViewById(R.id.Toast5);
        inflaterToasCustom = getLayoutInflater();
        layoutToasCustom = inflaterToasCustom.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toast_layout_root));
        ToasCustom = (RelativeLayout) layoutToasCustom.findViewById(R.id.ToasCustom);
        ToasAnimated = (RelativeLayout) layoutToasCustom.findViewById(R.id.ToasAnimated);
        animarLayout = (RelativeLayout) layoutToasCustom.findViewById(R.id.animarLayout);
        imageInToast = (ImageView) layoutToasCustom.findViewById(R.id.image);
        imageInToast.setImageResource(R.drawable.ic_stat_onesignal_default);
        textInToast = (TextView) layoutToasCustom.findViewById(R.id.text);
        textInToastAnimated = (TextView) layoutToasCustom.findViewById(R.id.textInToastAnimated);
        toastCustom = new Toast(getApplicationContext());
       // toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);        toastCustom.setDuration(Toast.LENGTH_LONG);
        toastCustom.setView(layoutToasCustom);



        final int ToastTimer = 10000;
        toastTimer = new CountDownTimer(ToastTimer, 1000 /*Tick duration*/) {
            public void onTick(long Tempos) {
                Show.show();
                String SEGUNDO = String.valueOf(
                        TimeUnit.MILLISECONDS.toSeconds(Tempos) -
                        TimeUnit.MINUTES.toSeconds(
                        TimeUnit.MILLISECONDS.toMinutes(Tempos)));
                Toast2.setText(SEGUNDO);
            }
            public void onFinish() {
                Show.cancel();
                Toast2.setText("Toast Timer");
            }
        };

        Toast1.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Toast.makeText(context, "Toast.LENGTH_SHORT", Toast.LENGTH_SHORT).show();
            }
        });
        Toast1.setOnLongClickListener(new View.OnLongClickListener() {
            @Override            public boolean onLongClick(View view) {
                Toast.makeText(context, "Toast.LENGTH_LONG", Toast.LENGTH_LONG).show();
                return false;
            }
        });

        Toast2.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Show =  Toast.makeText(context, "Toast Timer", Toast.LENGTH_LONG);
                Show.show();
                toastTimer.start();
            }
        });

        Toast3.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if(layoutToasCustom.getParent() == null) {
                    textInToast.setText("Hello! This is a custom toast!");
                    ToasCustom.setVisibility(View.VISIBLE);
                    ToasAnimated.setVisibility(View.GONE);
                    toastCustom.show();
                }
            }
        });
        Toast4.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                String PegarVariavel = Variavel.getText().toString();
                if(PegarVariavel.length()>0){
                    Valor = String.format(Var,  PegarVariavel);
                }else{
                    Valor = String.format(Var,  "Valor não definido");
                }
                Toast.makeText(context, Valor, Toast.LENGTH_SHORT).show();
            }
        });


        Toast5.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(final View view) {
                if(layoutToasCustom.getParent() == null) {
                    animarLayout.clearAnimation();
                    textInToastAnimated.setText("Toast Animated");
                    ToasAnimated.setVisibility(View.VISIBLE);
                    AnimarToast = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animacao);
                    animarLayout.startAnimation(AnimarToast);
                    ToasCustom.setVisibility(View.GONE);
                    toastCustom.show();
                }
            }
        });
    }
}



📋

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:app="http://schemas.android.com/apk/res-auto"    
xmlns:tools="http://schemas.android.com/tools"    
android:id="@+id/ToastLayout"    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
app:layout_behavior="@string/appbar_scrolling_view_behavior">
 




    <Button android:id="@+id/Toast1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentTop="true" 
android:layout_centerHorizontal="true" 
android:text="Toast Simples" 
tools:layout_editor_absoluteX="148dp" 
tools:layout_editor_absoluteY="16dp" />
 


    <Button android:id="@+id/Toast2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_below="@+id/Toast1" 
android:layout_centerHorizontal="true" 
android:text="Toast Timer" />
 


    <Button android:id="@+id/Toast3" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_below="@+id/Toast2" 
android:layout_centerHorizontal="true" 
android:text="Toast Custom" />
 

    <Button android:id="@+id/Toast4" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_below="@+id/Toast3" 
android:layout_centerHorizontal="true" 
android:text="Toast com Variavel" />
 


    <Button android:id="@+id/Toast5" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignEnd="@+id/Toast3" 
android:layout_alignRight="@+id/Toast3" 
android:layout_centerVertical="true" 
android:text="Toast Animada" />
 


    <EditText android:id="@+id/Variavel" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_below="@+id/Toast4" 
android:layout_centerHorizontal="true" 
android:ems="10" 
android:hint="Variavel" 
android:inputType="textPersonName" />
 


</RelativeLayout>



📋

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" >
 
<corners android:radius="100dp" />
    <solid android:color="#000000" />
    <size android:width="250dp" android:height="35dp" />
 
</shape> 
 



📋

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:duration="1000"
        android:fromXDelta="-5%"
         android:repeatCount="infinite"
         android:repeatMode="reverse"
         android:toXDelta="5%"/>
</set>
 
  



📋

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:id="@+id/toast_layout_root"    
android:layout_width="match_parent"    
android:layout_height="fill_parent"

<RelativeLayout android:id="@+id/ToasCustom" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:alpha="0.6" android:background="@drawable/buttonshape" android:visibility="gone"

 <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toEndOf="@+id/image" android:layout_toRightOf="@+id/image" android:paddingLeft="10dp" android:text="Texto" android:textColor="@color/common_google_signin_btn_text_dark_default" /> 

<ImageView android:id="@+id/image" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_centerVertical="true" /> 

</RelativeLayout



 <RelativeLayout android:id="@+id/ToasAnimated" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:visibility="gone">

<RelativeLayout android:id="@+id/animarLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:alpha="0.6" android:background="@drawable/buttonshape"> 

<TextView android:id="@+id/textInToastAnimated" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Toast" android:textAlignment="center" android:textColor="#FFFFFF" android:textSize="15sp" /> 

</RelativeLayout> 


</RelativeLayout> 



</RelativeLayout>



Nenhum comentário:

Postar um comentário

Obrigado por comentar, volte sempre!

Seguidores

Pages




Ajude continuar nossos projetos.    

Copie este código: [[address]]

Donation of [[value]] BTC Received. Thank You.
[[error]]






Copiado