100+ tutorials, source code, and examples to help you develop creative and technical skills.

activity.java

/* Code From Learnoset - Learn Code Online Android App.
Download Learnoset from PlayStore to learn coding*/

 @Override
    public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo){
        super.onCreateContextMenu(contextMenu, view, contextMenuInfo);

        final WebView.HitTestResult webViewHitTestResult = webView.getHitTestResult();

        if (webViewHitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE ||
                webViewHitTestResult.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {

            contextMenu.setHeaderTitle("Download Image");

            contextMenu.add(0, 1, 0, "Save - Download Image")
                    .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {

                            String DownloadImageURL = webViewHitTestResult.getExtra();

                            if(URLUtil.isValidUrl(DownloadImageURL)){



                                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);


                                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(DownloadImageURL));
                                request.allowScanningByMediaScanner();
                                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                                DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                                downloadManager.enqueue(request);

                                Toast.makeText(MainActivity.this,"Image Downloaded Successfully.",Toast.LENGTH_LONG).show();
                            }
                            else {
                                Toast.makeText(MainActivity.this,"Sorry.. Something Went Wrong.",Toast.LENGTH_LONG).show();
                            }
                            return false;
                        }
                    });
        }
    }

activity.java

/* Code From Learnoset - Learn Code Online Android App.
Download Learnoset from PlayStore to learn coding*/

public class YourActivity extends Activity {

     private WebView webView; // make sure to init your webview
     private DownloadManager downloadManager;



    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // your any other onCreate() code...
        downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
        registerReceiver(onDownloadComplete,
                new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    }

    @Override
     public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
        super.onCreateContextMenu(contextMenu, view, contextMenuInfo);

        final WebView.HitTestResult webViewHitTestResult = webView.getHitTestResult();
         if (isHitResultAnImage(webViewHitTestResult)) {
            contextMenu.setHeaderTitle("Download Image");
            contextMenu.add(0, 1, 0, "Save - Download Image")
                    .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                            return handleMenuItemClick(menuItem, webViewHitTestResult.getExtra());
                        }
                    });
         }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(onDownloadComplete);
    }


    private boolean isHitResultAnImage(WebView.HitTestResult hitTestResult) {
         return hitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE ||
                 hitTestResult.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE;
    }

    private boolean handleMenuItemClick(MenuItem menuItem, String imageDownloadUrl) {
        if(URLUtil.isValidUrl(imageDownloadUrl)){
            downloadImage(imageDownloadUrl);
            Toast.makeText(this,"Image Downloaded Successfully.",Toast.LENGTH_LONG).show();
            return false;
        }
        Toast.makeText(this,"Sorry.. Something Went Wrong.",Toast.LENGTH_LONG).show();
        return false;
    }


    private void downloadImage(String imageUrl) {
        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(imageUrl));
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        downloadManager.enqueue(request);
    }


    public String getFilePathFromUri(Uri uri) {
        String filePath = null;
        if ("content".equals(uri.getScheme())) {
            String[] filePathColumn = { MediaStore.MediaColumns.DATA };
            ContentResolver contentResolver = getContentResolver();

            Cursor cursor = contentResolver.query(uri, filePathColumn, null,
                    null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            filePath = cursor.getString(columnIndex);
            cursor.close();
        } else if ("file".equals(uri.getScheme())) {
            filePath = new File(uri.getPath()).getAbsolutePath();
        }
        return filePath;
    }

     private void saveAsJpeg(Bitmap bitmapImage) {
        ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
        // path to /data/data/yourapp/app_data/imageDir
        File directory = contextWrapper.getDir("imageDir", Context.MODE_PRIVATE);
        // Create imageDir
        File mypath = new File(directory,"imageName.jpg");
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(mypath);
            // Use the compress method on the BitMap object to write image to the OutputStream
            bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }



    BroadcastReceiver onDownloadComplete = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(downloadId);
            Cursor cursor = downloadManager.query(query);
            if (cursor.moveToFirst()) {
                int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
                if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(columnIndex)) {
                    String uriString = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                    File file = new File(getFilePathFromUri(Uri.parse(uriString)));
                    try {
                    Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(file));
                    saveAsJpeg(bitmap);
                } catch (FileNotFoundException e) {
                    // cant save
                }
                } else {
                    // downloadFailed, show toast or something..
                }
            }
        }
    };


}

yuiii.pyc

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

main activity

sorting.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset App from PlayStore to learn coding*/

List <String > list =
    new ArrayList<>(
        List.of(
              "20*20",
              "20*10",
              "30*20",
              "30*10",
              "10*14",
              "10*20",
              "10*15"
        )
    )
;
Collections.sort( list ) ;
System.out.println( list ) ;

// OUTPUT
//[10*14, 10*15, 10*20, 20*10, 20*20, 30*10, 30*20]

quiz.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

what is your name?

a.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

jfjfujcchcjvjvjch

janab.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

ydbsbbsbanansnbzbzbzzbsbwbwbwbbw

av
s
s
x
x
x
x
s
w

d
e
s
d
d
d
d
dd
x
x
x
x
x
x
x
x
x
x
x
xx

aa.java

test working working working 222222

a.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

jxnbdgfjtehhshthsbfshwfhfqharhrqg

ns.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

msghdajsfhadharharhadhdh editted

nsns.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

nznnsbfsnsfhadhadhadhd

a.html

htwbsvsrhfshshfshadgdagdag2222

a.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

garhdhfHsfhfwhrahtwhafhafhdh

Android manifest.xml

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TicTacToe">
        <activity android:name=".AddPlayers">            
        </activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

a.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

tjgjgutfufjfnchhhvjvhhvhvhvyvyvyvyvyv

testfile.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

test java code

testhtml.html

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

test html file

textxml.xml

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

test XML file

am.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

ggcgcggg vvjbg. gvhjb

layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/normalButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@color/black"
        android:text="Normal Button with Black Background + White Text"
        android:textColor="#FFFFFF" />

    <androidx.appcompat.widget.AppCompatButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/round_corner_button"
        android:text="Button with Round Corner" />

    <androidx.appcompat.widget.AppCompatButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/round_button"
        android:text="Round Button" />

    <androidx.appcompat.widget.AppCompatButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/button_click_effect"
        android:text="Button with click effect" />

    <androidx.appcompat.widget.AppCompatButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/button_bottom_shadow"
        android:paddingStart="20dp"
        android:paddingEnd="20dp"
        android:text="Button with Bottom Shadow" />

    <androidx.appcompat.widget.AppCompatButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/round_corner_2"
        android:paddingStart="20dp"
        android:paddingEnd="20dp"
        android:text="Button with Round Corner" />
</LinearLayout>

drawable/button_bottom_shadow.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">

            <!--Button Color-->
            <solid android:color="#80000000" />

            <corners android:radius="10dp" />
        </shape>
    </item>
    <item android:bottom="5dp">
        <shape android:shape="rectangle">

            <!--Button Color-->
            <solid android:color="@color/teal_200" />

            <corners android:radius="10dp" />
        </shape>
    </item>
</layer-list>

drawable/button_click_effect.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="@color/white"
    tools:targetApi="lollipop">

    <!--this creates the mask with the ripple effect-->
    <item
        android:id="@+id/mask"
        android:drawable="@color/teal_200" />

</ripple>

drawable/round_button.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!--Button Color-->
    <solid android:color="@color/teal_200" />

    <corners android:radius="1000dp"/>
</shape>

drawable/round_corner2.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!--Button Color-->
    <solid android:color="@color/teal_200" />

    <!---Make Round Corner with radius. you can increase or decrease radius according to your need-->
    <corners android:radius="100dp"/>
</shape>

drawable/round_corner_button.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!--Button Color-->
    <solid android:color="@color/teal_200" />

    <!---Make Round Corner with radius. you can increase or decrease radius according to your need-->
    <corners android:radius="10dp"/>
</shape>

MainActivity.java

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;

public class MainActivity extends AppCompatActivity {

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

        // getting button reference from xml file through button id (normalButton)
        final AppCompatButton normalButton = findViewById(R.id.normalButton);

        // handle button click events
        normalButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                // write your code here to perform after the button is clicked
                // For example, show Toast message
                Toast.makeText(MainActivity.this, "Button Clicked", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

Output

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/normalTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is Normal Text"
        android:textSize="18sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@android:color/holo_red_light"
        android:text="Text with Red BackGround and white Text"
        android:textColor="#FFFFFF"
        android:textSize="18sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/round_corner_2"
        android:gravity="center"
        android:text="Text with Round Corner and center gravity"
        android:textSize="18sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:letterSpacing="0.2"
        android:text="TextView with letterSpacing"
        android:textSize="18sp" />

    <TextView
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:text="This is Line 1 \n This is line 2 \n this is line 3"
        android:textSize="18sp" />

    <TextView
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:ellipsize="end"
        android:gravity="center"
        android:maxLines="1"
        android:text="Ths is single line TextView"
        android:textSize="18sp" />
</LinearLayout>

drawable/round_corner_2

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!--Button Color-->
    <solid android:color="@color/teal_200" />

    <!---Make Round Corner with radius. you can increase or decrease radius according to your need-->
    <corners android:radius="100dp"/>
</shape>

MainActivity.java

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

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

        // getting TextViews from xml file
        final TextView normalTextView = findViewById(R.id.normalTextView);

        // setting text programmatically
        normalTextView.setText("This is Text");

        // setting background color programmatically
        normalTextView.setBackgroundColor(Color.RED);
        // OR setting color from res/values/color file
        normalTextView.setBackgroundColor(getResources().getColor(R.color.your_color));
        // OR setting color direct from color code
        normalTextView.setBackgroundColor(Color.parseColor("#FFFFFF"));

        // setting text size programmatically
        normalTextView.setTextSize(20);

        // setting text style (BOLD) programmatically
        Typeface typeface = Typeface.create(normalTextView.getTypeface(), Typeface.BOLD);
        normalTextView.setTypeface(typeface);

        // setting text style (ITALIC) programmatically
        Typeface typeface2 = Typeface.create(normalTextView.getTypeface(), Typeface.ITALIC);
        normalTextView.setTypeface(typeface2);

        // TextView click listener
        normalTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // handle TextView click...
            }
        });
    }
}

Output

Register.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

package com.example.capstone_project_redo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.firebase.FirebaseApiNotAvailableException;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

public class CreateAccount extends AppCompatActivity {

    DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://loginregister-34ed4-default-rtdb.firebaseio.com");

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

        Button goToLogIn = (Button)findViewById(R.id.backToLogInBtn);
        goToLogIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(CreateAccount.this, MainActivity.class));
            }
        });


        final EditText firstname = findViewById(R.id.firstname);
        final EditText lastname = findViewById(R.id.lastname);
        final EditText age = findViewById(R.id.age);
        final EditText province = findViewById(R.id.province);
        final EditText municipality = findViewById(R.id.municipality);
        final EditText email = findViewById(R.id.email);
        final EditText password = findViewById(R.id.password);
        final EditText phone = findViewById(R.id.phone);
        final EditText altemail = findViewById(R.id.altemail);

        final Button registerBtn = findViewById(R.id.registerBtn);
        final Button LoginNowBtn = findViewById(R.id.backToLogInBtn);



        registerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String firstnameTxt = firstname.getText().toString();
                final String lastnameTxt = lastname.getText().toString();
                final String ageTxt = age.getText().toString();
                final String provinceTxt = province.getText().toString();
                final String municipalityTxt = municipality.getText().toString();
                final String emailTxt = email.getText().toString();
                final String passwordTxt = password.getText().toString();
                final String phoneTxt = phone.getText().toString();
                final String altemailTxt = altemail.getText().toString();


                if(firstnameTxt.isEmpty() || lastnameTxt.isEmpty() || ageTxt.isEmpty()|| provinceTxt.isEmpty() || municipalityTxt.isEmpty() || emailTxt.isEmpty() || passwordTxt.isEmpty() || phoneTxt.isEmpty() || altemailTxt.isEmpty()){
                    Toast.makeText(CreateAccount.this, "Please fill all  fields", Toast.LENGTH_SHORT).show();
                }
                else {
                    databaseReference.child("users").addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot snapshot) {
                            if (snapshot.hasChild(emailTxt)){
                                Toast.makeText(CreateAccount.this, "This Email Address is already Registered", Toast.LENGTH_SHORT).show();
                            }

                            else {
                                databaseReference.child("users").child(emailTxt).child("Full Name").setValue(firstnameTxt,lastnameTxt);
                                databaseReference.child("users").child(emailTxt).child("Age").setValue(ageTxt);
                                databaseReference.child("users").child(emailTxt).child("Province").setValue(provinceTxt);
                                databaseReference.child("users").child(emailTxt).child("Municipality").setValue(municipalityTxt);
                                databaseReference.child("users").child(emailTxt).child("Password").setValue(passwordTxt);
                                databaseReference.child("users").child(emailTxt).child("Mobile Number").setValue(phoneTxt);
                                databaseReference.child("users").child(emailTxt).child("Alternative Email").setValue(altemailTxt);

                                Toast.makeText(CreateAccount.this, "User Registered Successfully", Toast.LENGTH_SHORT).show();
                                finish();
                            }

                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError error) {

                        }
                    });



                }

            }
        });





    }
}

Login.java

package com.example.login_rt;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

public class Login extends AppCompatActivity {

    DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://vepldblogin-default-rtdb.firebaseio.com/");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        final EditText phone = findViewById(R.id.phone);
        final EditText password = findViewById(R.id.password);
        final Button loginBtn = findViewById(R.id.loginBtn);
        final TextView registerNowBtn = findViewById(R.id.registerNowBtn);

        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String phoneTxt = phone.getText().toString();
                final String passwordTxt = password.getText().toString();

                if(phoneTxt.isEmpty() || passwordTxt.isEmpty()){
                    Toast.makeText(Login.this, "Please Enter Your Mobile No and Password", Toast.LENGTH_SHORT).show();
                }
                else{
                    databaseReference.child("users").addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot snapshot) {
                            if(snapshot.hasChild(phoneTxt)){
                                final String getPassword =snapshot.child(phoneTxt).child("passowrd").getValue(String.class);
                                if(getPassword.equals(passwordTxt)){
                                    Toast.makeText(Login.this, "Login Successfully", Toast.LENGTH_SHORT).show();
                                    startActivity(new Intent(Login.this,MainActivity.class));
                                    finish();
                                }
                                else {
                                    Toast.makeText(Login.this, "Wrong Passowrd", Toast.LENGTH_SHORT).show();
                                }
                            }
                            else {
                                Toast.makeText(Login.this, "Wrong Mobile No", Toast.LENGTH_SHORT).show();
                            }

                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError error) {

                        }
                    });
                }
            }
        });

        registerNowBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(Login.this, Register.class));
            }
        });
    }
}

LoginPage.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset from PlayStore to learn coding*/

button3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				final String userr = user.getText().toString().trim();
				final String passwore = passwors.getText().toString().trim();
				if (userr.isEmpty() || passwore.isEmpty()) {
					Toast.makeText(LandingPage.this, "should be filled", Toast.LENGTH_LONG).show();
				} else {

					
					datab.child("USERSDATA").addListenerForSingleValueEvent(new ValueEventListener() {

						@Override
						public void onDataChange(DataSnapshot dataSnapshot) {
							if (dataSnapshot.hasChild(userr)) {
								// dataSnapshot is the "issue" node with all children with id 0

								final String passdb = dataSnapshot.child(userr).child("PASSWORD")
										.getValue(String.class);

								if (passdb.equals(passwore)) {
									Intent intent = new Intent(LandingPage.this, MainActivity.class);
									startActivity(intent);
								} else {
									Toast.makeText(LandingPage.this, "Password is wrong", Toast.LENGTH_LONG).show();
								}

							} else {
								Toast.makeText(LandingPage.this, "User not found", Toast.LENGTH_LONG).show();
							}
						}

						@Override
						public void onCancelled(DatabaseError databaseError) {

						}
					});

				}

			}

		});

Projects with Source Code + Video Tutorials

You can download our Java and Android Studio Projects with Source Code and Video Tutorials.

Custom-Navigation-bar-with-Material-UI-design
Custom Navigation bar with Material UI design
Online-Quiz-Application-using-Firebase-and-Admob
Online Quiz Application using Firebase and Admob
Login-&-Register-Screen-UI-Design---01
Login & Register Screen UI Design - 01

If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com

Follow us to learn Coding and get in touch with new Technologies.