SirPorthos SirPorthos - 2 years ago
1473 0

No description

Other

Activity Code

<?xml version="1.0" encoding="utf-8"?>

<ScrollView 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:layout_width="match_parent"
    android:layout_height="match_parent"

    android:fillViewport="true"
    android:scrollbarStyle="insideOverlay">
    <!-- tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="8dp"> -->


    <android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/profilescreen"

        tools:context="example.com.myapplication.sign_up"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="-254dp"
        tools:ignore="ScrollViewSize">

        <EditText
            android:id="@+id/FirstNameField"
            android:layout_width="218dp"
            android:layout_height="23dp"
            android:layout_marginStart="16dp"
            android:layout_weight="1"
            android:background="@color/transparent"
            android:ems="10"
            android:hint="@string/name"
            android:inputType="textPersonName"
            android:textAlignment="center"
            tools:ignore="RtlHardcoded"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="264dp"
            android:layout_marginLeft="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            tools:layout_editor_absoluteY="270dp" />

        <EditText
            android:id="@+id/LastNameField"
            android:layout_width="212dp"
            android:layout_height="21dp"
            android:layout_marginEnd="16dp"
            android:layout_weight="1"
            android:background="@color/transparent"
            android:ems="10"
            android:hint="@string/last_name"
            android:inputType="textPersonName"
            android:textAlignment="center"
            tools:ignore="RtlHardcoded"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="264dp"
            android:layout_marginRight="39dp"
            app:layout_constraintRight_toRightOf="parent"
            tools:layout_editor_absoluteY="272dp"
            tools:layout_editor_absoluteX="252dp" />

        <EditText
            android:id="@+id/AgeField"
            android:layout_width="212dp"
            android:layout_height="23dp"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="19dp"
            android:background="@color/transparent"
            android:ems="10"
            android:hint="@string/dd_mm_yy"
            android:inputType="date"
            android:textAlignment="center"
            android:layout_marginRight="16dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="303dp"
            tools:layout_editor_absoluteY="304dp"
            tools:layout_editor_absoluteX="252dp"
            android:layout_marginLeft="19dp" />

        <TextView
            android:id="@+id/DOB"
            android:layout_width="69dp"
            android:layout_height="27dp"
            android:layout_marginEnd="29dp"
            android:layout_marginLeft="11dp"
            android:layout_marginTop="303dp"
            android:layout_weight="0.83"
            android:background="@color/transparent"
            android:padding="0dp"
            android:paddingBottom="0dp"
            android:paddingEnd="0dp"
            android:paddingLeft="0dp"
            android:paddingRight="0dp"
            android:paddingStart="0dp"
            android:textAlignment="center"
            android:textAppearance="@style/TextAppearance.AppCompat.Title"
            android:visibility="invisible"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:ignore="NestedWeights"
            android:layout_marginRight="29dp" />

        <Spinner
            android:id="@+id/spinner2"
            android:layout_width="289dp"
            android:layout_height="26dp"
            android:layout_marginEnd="30dp"
            android:layout_marginStart="30dp"
            android:entries="@array/craftmenu"
            android:spinnerMode="dropdown"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="451dp"
            android:layout_marginLeft="121dp"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginRight="0dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            tools:layout_editor_absoluteY="452dp"
            tools:layout_editor_absoluteX="161dp" />

        <Spinner
            android:id="@+id/spinner5"
            android:layout_width="292dp"
            android:layout_height="27dp"
            android:layout_marginEnd="30dp"
            android:layout_marginStart="30dp"
            android:entries="@array/craftmenu"
            android:spinnerMode="dropdown"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="416dp"
            android:layout_marginLeft="300dp"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginRight="8dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            tools:layout_editor_absoluteY="414dp"
            tools:layout_editor_absoluteX="158dp" />

        <Spinner
            android:id="@+id/spinner3"
            android:layout_width="288dp"
            android:layout_height="19dp"
            android:layout_marginEnd="30dp"
            android:layout_marginStart="30dp"
            android:entries="@array/craftmenu"
            android:spinnerMode="dropdown"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="530dp"
            android:layout_marginLeft="122dp"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginRight="8dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            tools:layout_editor_absoluteY="532dp"
            tools:layout_editor_absoluteX="162dp" />

        <Spinner
            android:id="@+id/spinner7"
            android:layout_width="290dp"
            android:layout_height="24dp"
            android:layout_marginEnd="30dp"
            android:layout_marginLeft="122dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="30dp"
            android:layout_marginTop="490dp"
            android:entries="@array/craftmenu"
            android:spinnerMode="dropdown"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:layout_editor_absoluteY="487dp"
            tools:layout_editor_absoluteX="160dp" />

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="289dp"
            android:layout_height="30dp"
            android:layout_marginEnd="30dp"
            android:layout_marginStart="30dp"
            android:entries="@array/craftmenu"
            android:spinnerMode="dropdown"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="376dp"
            android:layout_marginRight="8dp"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginLeft="8dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            android:orientation="horizontal"
            tools:layout_editor_absoluteY="376dp"
            tools:layout_editor_absoluteX="161dp" />

        <RadioButton
            android:id="@+id/MRadio"
            android:layout_width="134dp"
            android:layout_height="24dp"
            android:layout_marginLeft="157dp"
            android:layout_marginTop="343dp"
            android:checked="false"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <RadioButton
            android:id="@+id/FRadio"
            android:layout_width="177dp"
            android:layout_height="26dp"
            android:layout_marginLeft="295dp"
            android:layout_marginTop="343dp"
            android:checked="false"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:layout_editor_absoluteY="342dp"
            tools:layout_editor_absoluteX="294dp" />

        <EditText
            android:id="@+id/WL2"
            android:layout_width="163dp"
            android:layout_height="28dp"
            android:layout_marginEnd="72dp"
            android:layout_marginStart="72dp"
            android:background="@color/transparent"
            android:ems="10"
            android:hint="@string/worklink2"
            android:inputType="text"
            android:textAlignment="center"
            tools:ignore="MissingConstraints"
            android:layout_marginRight="72dp"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="79dp"
            app:layout_constraintTop_toBottomOf="@+id/spinner3" />

        <EditText
            android:id="@+id/WL1"
            android:layout_width="144dp"
            android:layout_height="28dp"
            android:background="@color/transparent"
            android:ems="10"
            android:hint="@string/worklink1"
            android:inputType="text"
            android:textAlignment="center"
            android:layout_marginLeft="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintBaseline_toBaselineOf="@+id/WL2" />

        <Button
            android:id="@+id/ProfSubmit"
            android:layout_width="98dp"
            android:layout_height="49dp"
            android:background="@drawable/roundedbutton"
            android:text="@string/submit"
            android:textColor="@color/colorPrimary"
            android:layout_marginLeft="8dp"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginRight="8dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginBottom="8dp"
            tools:layout_editor_absoluteY="723dp" />

        <ImageButton
            android:id="@+id/pickimage"
            android:layout_width="459dp"
            android:layout_height="165dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="83dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/accountsettingsicon"
            app:layout_constraintHorizontal_bias="0.504" />

    </android.support.constraint.ConstraintLayout>

</ScrollView>
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