I put all the notification code but it does not appear android studio

0

I'm trying to create a notification with the following code but it does not generate an error or notification

      package model;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.NotificationCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.fumec.interpet.AdmActivity;
import com.example.fumec.interpet.BD;
import com.example.fumec.interpet.R;
import com.example.fumec.interpet.UserActivity;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

/**
 * Created by Matheus on 27/04/2018.
 */

public class AnimalAdapter extends RecyclerView.Adapter {
    private ArrayList<Animal> animais;
    private Context context;



    public AnimalAdapter(ArrayList<Animal> animais, Context context) {
    this.animais = animais;
    this.context = context;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.linha, parent, false);

        AnimalViewHolder holder = new AnimalViewHolder(view);

        return holder;
}
    public Animal getItem(int position) {
        return animais.get(position);
    }
    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return animais.get(arg0).getId();
    }
    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder viewHolder, final int position) {
        Resources resources;
        final int auxPosition = position;

        final AnimalViewHolder holder = (AnimalViewHolder) viewHolder;
        final Animal animal  = animais.get(position) ;
        holder.nomeTextView.setText(animal.getNome());
        holder.idadeTextView.setText("Data de nascimento:"+animal.getIdade());
        holder.pesoTextView.setText(animal.getPeso()+"Kg");
        holder.tutorTextView.setText(animal.getTutor());
        holder.imageView.setImageResource(R.drawable.amora);

        holder.nomeEdit.setText(animal.getNome());
        holder.tutorEdit.setText(animal.getTutor());
        holder.sexoEdit.setText(animal.getSexo());
        holder.especieEdit.setText(animal.getEspecie());
        holder.racaEdit.setText(animal.getRaca());
        holder.idadeEdit.setText(animal.getIdade());
        holder.pesoEdit.setText(animal.getPeso());


        int indexfigure = -1;
        resources = context.getResources();
        indexfigure = resources.getIdentifier(animal.getImg(),"drawable",context.getPackageName());
        holder.imageView.setImageResource(indexfigure);

        holder.fab2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(holder.teste.getVisibility() == v.VISIBLE){
                    holder.teste.setVisibility(v.GONE);
                }else{
                    holder.teste.setVisibility(v.VISIBLE);
                }
            }
        });

        holder.btnProcedimento.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                Intent intent = new Intent(context, UserActivity.class);
                intent.putExtra("animal", animal);
                PendingIntent p = PendingIntent.getActivity(context, 0,intent , 0);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
                builder.setTicker("Ticker Texto");
                builder.setContentTitle("Titulo");
                builder.setContentText("Descicao");
                builder.setSmallIcon(R.drawable.logo2);
                builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.logo2));
                builder.setContentIntent(p);

                Notification n = builder.build();
                n.vibrate = new long[]{150, 300, 150, 600};
                n.flags = Notification.FLAG_AUTO_CANCEL;
                nm.notify(R.drawable.logo2, n);

                try{
                    Uri som = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    Ringtone toque = RingtoneManager.getRingtone(context, som);
                    toque.play();
                }
                catch(Exception e){}

                Animal animal = animais.get(position);
                long date = System.currentTimeMillis();
                SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
                String dateString = sdf.format(date);
                animal.setProcedimento( holder.procedimentoSpiner.getSelectedItem().toString(), holder.veterinariospiner.getSelectedItem().toString(),dateString);
                BD bd = new BD(context);
                bd.atualizarProcedimento(animal);
                notifyDataSetChanged();
                notifyItemChanged(position);

            }

        });


        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(holder.linearLayout.getVisibility() == v.VISIBLE){
                    holder.linearLayout.setVisibility(v.GONE);
                }else{
                    holder.linearLayout.setVisibility(v.VISIBLE);
                }
            }
        });


        holder.btnAlterar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateItem(auxPosition, holder.nomeEdit.getText().toString(), holder.tutorEdit.getText().toString(), holder.racaEdit.getText().toString(), holder.idadeEdit.getText().toString(), holder.sexoEdit.getText().toString(), holder.especieEdit.getText().toString(),holder.pesoEdit.getText().toString());
            }
        });


        holder.imageView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                    removerItem(auxPosition);

                return false;
            }
        });
    }
    private void removerItem(int position) {
        BD bd = new BD(context);
        bd.deletar(animais.get(position));
        animais.remove(position);
        notifyDataSetChanged();

    }
    @Override
    public int getItemCount() {
        return animais.size();
    }
    public void updateItem(int position, String nome,String tutor,String raca, String idade, String sexo, String especie,String peso ) {
        Animal animal = animais.get(position);
        animal.setNome(nome);
        animal.setTutor(tutor);
        animal.setRaca(raca);
        animal.setIdade(idade);
        animal.setSexo(sexo);
        animal.setEspecie(especie);
        animal.setPeso(peso);
        BD bd = new BD(context);
        bd.atualizar(animal);
        notifyItemChanged(position);
        notifyDataSetChanged();
    }
    public class AnimalViewHolder extends RecyclerView.ViewHolder {

        private TextView nomeTextView;
        private TextView pesoTextView;
        private TextView idadeTextView;
        private TextView tutorTextView;
        private ImageView imageView;
        private RelativeLayout linearLayout;
        private Button btnAlterar;
        private Button btnProcedimento;
        private EditText nomeEdit;
        private EditText tutorEdit;
        private EditText idadeEdit;
        private EditText sexoEdit;
        private EditText especieEdit;
        private EditText racaEdit;
        private EditText pesoEdit;
        private LinearLayout teste;
        private FloatingActionButton fab2;
        private Spinner procedimentoSpiner;
        private Spinner veterinariospiner;


        private AnimalViewHolder(View view) {
            super(view);
            procedimentoSpiner = view.findViewById(R.id.procedimentos);
            veterinariospiner = view.findViewById(R.id.veterinarios);
            teste = view.findViewById(R.id.layout3);
            imageView = view.findViewById(R.id.foto);
            nomeTextView = view.findViewById(R.id.nomeAnimal);
            pesoTextView = view.findViewById(R.id.peso);
            idadeTextView = view.findViewById(R.id.data);
            tutorTextView = view.findViewById(R.id.tutor);
            imageView = view.findViewById(R.id.foto);
            fab2 = view.findViewById(R.id.fab2);
            btnProcedimento = view.findViewById(R.id.btnProcedimento);
            linearLayout = view.findViewById(R.id.layout2);
            btnAlterar = view.findViewById(R.id.btnAlterar);
            nomeEdit = view.findViewById(R.id.nomeEdit);
            tutorEdit = view.findViewById(R.id.tutorEdit);
            idadeEdit = view.findViewById(R.id.idadeEdit);
            sexoEdit = view.findViewById(R.id.sexoEdit);
            especieEdit = view.findViewById(R.id.especieEdit);
            racaEdit = view.findViewById(R.id.racaEdit);
            pesoEdit = view.findViewById(R.id.pesoEdit);

        }
    }
}
    
asked by anonymous 04.05.2018 / 20:24

0 answers