SirPorthos SirPorthos - 1 year ago
1041 0

No description

Java

Activity Java

package example.com.myapplication;

import android.content.Context;
import android.content.Intent;

import android.net.Uri;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;


import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;


public class Profile extends AppCompatActivity {

    private EditText t1,t2,t3,t4,t5;
    private Button b1;
    private static final int PICK_IMAGE_REQUEST = 234;
    private Spinner s1,s2,s3,s4,s5;

    //Buttons
    private ImageButton pb1;
   // Context cntx;
    private Uri filePath;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);




        pb1 = (ImageButton)findViewById(R.id.pickimage);

        pb1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_PICK);
                startActivityForResult(Intent.createChooser(intent, "Select Image"), PICK_IMAGE_REQUEST);

            }


        });




        b1 = (Button)findViewById(R.id.ProfSubmit);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {



                t1 = (EditText)findViewById(R.id.FirstNameField);
                t2 = (EditText)findViewById(R.id.LastNameField);
                t3 = (EditText)findViewById(R.id.AgeField);
                t4 = (EditText)findViewById(R.id.WL1);
                t5 = (EditText)findViewById(R.id.WL2);

                s1 = (Spinner)findViewById(R.id.spinner);
                s2 = (Spinner)findViewById(R.id.spinner2);
                s3 = (Spinner)findViewById(R.id.spinner3);
                s4 = (Spinner)findViewById(R.id.spinner5);
                s5 = (Spinner) findViewById(R.id.spinner5);




                FirebaseStorage ProfileImage = FirebaseStorage.getInstance();
                FirebaseDatabase User1 = FirebaseDatabase.getInstance();
                DatabaseReference Name = User1.getReference("Fname");
                DatabaseReference LName = User1.getReference("LName");
                DatabaseReference age = User1.getReference("age");
                DatabaseReference Work1 = User1.getReference("WorkLink1");
                DatabaseReference Work2 = User1.getReference("WorkLink2");
                DatabaseReference Craft1 = User1.getReference("Craft1");
                DatabaseReference Craft2 = User1.getReference("Craft2");
                DatabaseReference Craft3 = User1.getReference("Craft3");
                DatabaseReference Craft4 = User1.getReference("Craft4");
                DatabaseReference Craft5 = User1.getReference("Craft5");




                    if(filePath != null) {
                        StorageReference profimage = ProfileImage.getReference("ProfileImage");

                        //uploading the image
                        UploadTask uploadTask = profimage.putFile(filePath);

                        uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            @Override
                            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                Toast.makeText(Profile.this, "Upload successful", Toast.LENGTH_SHORT).show();
                            }
                        }).addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                Toast.makeText(Profile.this, "Upload Failed -> " + e, Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                    else {
                        Toast.makeText(Profile.this, "Select an image", Toast.LENGTH_SHORT).show();
                    }


                Name.setValue(t1.getText().toString());
                LName.setValue(t2.getText().toString());
                age.setValue(t3.getText().toString());
                Work1.setValue(t4.getText().toString());
                Work2.setValue(t5.getText().toString());
                Craft1.setValue(s1.getOnItemSelectedListener().toString());
                Craft2.setValue(s2.getOnItemSelectedListener().toString());
                Craft3.setValue(s3.getOnItemSelectedListener().toString());
                Craft4.setValue(s4.getOnItemSelectedListener().toString());
                Craft5.setValue(s5.getOnItemSelectedListener().toString());








                startActivity(new Intent(Profile.this, HomeScreen.class));
            }
        });












// ...
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download