From 5e82b320e7e8b045f0310ce73a36452e5a897e6a Mon Sep 17 00:00:00 2001 From: Krish Date: Tue, 11 Apr 2023 19:18:15 +0530 Subject: [PATCH] Password validation --- .../beacondemo/Activity/DetailActivity.java | 94 +++++++++++++++++++ .../beacondemo/Activity/MainActivity.java | 44 ++++++++- app/src/main/res/layout/activity_detail.xml | 16 +++- app/src/main/res/layout/password_dialog.xml | 19 ++++ app/src/main/res/layout/password_reset.xml | 25 +++++ 5 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/layout/password_dialog.xml create mode 100644 app/src/main/res/layout/password_reset.xml diff --git a/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java b/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java index ebb5681..482012c 100644 --- a/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java +++ b/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java @@ -2,25 +2,36 @@ package com.example.beacondemo.Activity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import android.annotation.SuppressLint; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; +import android.provider.SyncStateContract; import android.text.Html; import android.util.Log; +import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; +import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import com.example.beacondemo.R; import com.example.beacondemo.adapter.RecycleAdapter; import com.minew.beaconplus.sdk.MTCentralManager; +import com.minew.beaconplus.sdk.MTConnectionFeature; import com.minew.beaconplus.sdk.MTConnectionHandler; import com.minew.beaconplus.sdk.MTFrameHandler; import com.minew.beaconplus.sdk.MTPeripheral; +import com.minew.beaconplus.sdk.enums.ConnectState; +import com.minew.beaconplus.sdk.enums.FeatureSupported; import com.minew.beaconplus.sdk.enums.FrameType; +import com.minew.beaconplus.sdk.enums.PasswordState; import com.minew.beaconplus.sdk.enums.TriggerType; import com.minew.beaconplus.sdk.enums.Version; import com.minew.beaconplus.sdk.exception.MTException; @@ -44,6 +55,7 @@ import com.minew.beaconplus.sdk.interfaces.SetTriggerListener; import com.minew.beaconplus.sdk.model.Trigger; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class DetailActivity extends AppCompatActivity implements View.OnClickListener { @@ -69,6 +81,8 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis RecyclerView mRecycle; ArrayList advFrames; + TextView tv_resetPass; + EditText edtPassR,edtConPassR; @Override protected void onCreate(Bundle savedInstanceState) { @@ -80,6 +94,48 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis initView(); initData(); initListener(); + + + tv_resetPass.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + resetPassword(); + } + }); + + } + + @SuppressLint("MissingInflatedId") + public void resetPassword() { + final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); + LayoutInflater inflater = this.getLayoutInflater(); + dialogBuilder.setCancelable(false); + final View dialogView = inflater.inflate(R.layout.password_reset, null); + dialogBuilder.setView(dialogView); + edtPassR = dialogView.findViewById(R.id.edtPassR); + edtConPassR = dialogView.findViewById(R.id.edtConPassR); + + //System.out.println("Value of userPass "+String.valueOf(userPass)); + dialogBuilder.setPositiveButton("SUBMIT", null); + dialogBuilder.setTitle("Reset Password"); + dialogBuilder.setMessage("Please enter password to you want to reset."); + + dialogBuilder.setNegativeButton("CANCEL",null); + final AlertDialog b = dialogBuilder.create(); + b.show(); + Button positiveButton = b.getButton(AlertDialog.BUTTON_POSITIVE); + Button cancel = b.getButton(AlertDialog.BUTTON_NEGATIVE); + positiveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + } + }); + cancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + b.dismiss(); + } + }); } private void initView() { @@ -96,6 +152,8 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis txt_zaxis=findViewById(R.id.txt_zaxis); mRecycle = findViewById(R.id.recycle); + tv_resetPass = findViewById(R.id.tv_resetPass); + Intent intent = getIntent(); String mac = intent.getStringExtra("mac"); @@ -292,6 +350,40 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis return super.toString(); } }); + + /*MTConnectionHandler mtConnectionHandler = mtPeripheral.mMTConnectionHandler; + ConnectState connectState = mtConnectionHandler.getConnectState(); + // password require or not. None, Require + PasswordState passwordState = mMTConnectionHandler.getPasswordState(); + // device info, such as:(Firmware Version: 0.9.1); + HashMap systeminfos = (HashMap) mMTConnectionHandler.systeminfos; + String manufacturer = systeminfos.get(SyncStateContract.Constants.manufacturer); + String modlenumber = systeminfos.get(Constants.modlenumber); + String macAddress = systeminfos.get(Constants.serialnumber); + String hardware = systeminfos.get(Constants.hardware); + String firmware = systeminfos.get(Constants.firmware); + String software = systeminfos.get(Constants.software);*/ + + // device features + /*MTConnectionFeature mtConnectionFeature = mMTConnectionHandler.mTConnectionFeature; + // atitude of slot(s), + int slotAtitude = mtConnectionFeature.getSlotAtitude(); + Log.d("slotAtitude", String.valueOf(slotAtitude)); + // parameters can be modified:none,adv,txpower,adv/txpower + FeatureSupported featureSupported = mtConnectionFeature.getFeatureSupported(); + Log.d("featureSupported", String.valueOf(featureSupported)); + // // frames supported(multiple) + List supportedSlots = mtConnectionFeature.getSupportedSlots(); + Log.d("supportedSlots", String.valueOf(supportedSlots)); + // Txpower supported(multiple) + byte[] supportedTxpowers = mtConnectionFeature.getSupportedTxpowers(); + Log.d("supportedTxpowers", String.valueOf(supportedTxpowers)); + // trigger supported(multiple) + ArrayList supportTriggers = (ArrayList) mtConnectionFeature.supportTriggers; + Log.d("supportTriggers", String.valueOf(supportTriggers)); + // Version of firmware; + Version version = mtConnectionFeature.getVersion(); + Log.d("version", String.valueOf(version));*/ } private void initListener() { @@ -300,7 +392,9 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis } public void saveTrigger() { + System.out.println("Inside save trigger method"); Version version = this.mMTConnectionHandler.mTConnectionFeature.getVersion(); + System.out.println("Version Inside save trigger method" + version.getValue()); if (version.getValue() >= 4) { if (this.mMTConnectionHandler.mTConnectionFeature.supportTriggers.size() > 0 && this.mMTConnectionHandler.triggers.size() > 0) { diff --git a/app/src/main/java/com/example/beacondemo/Activity/MainActivity.java b/app/src/main/java/com/example/beacondemo/Activity/MainActivity.java index 948981b..c48635e 100644 --- a/app/src/main/java/com/example/beacondemo/Activity/MainActivity.java +++ b/app/src/main/java/com/example/beacondemo/Activity/MainActivity.java @@ -2,6 +2,7 @@ package com.example.beacondemo.Activity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.recyclerview.widget.LinearLayoutManager; @@ -20,7 +21,10 @@ import android.os.Build; import android.os.Bundle; import android.text.Html; import android.util.Log; +import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; +import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; @@ -81,6 +85,9 @@ public class MainActivity extends AppCompatActivity { TextView txt_name,txt_mac,txt_battery,txt_rssi,txt_device,txt_xaxis,txt_yaxis,txt_zaxis; String mac,name,xaxis,yaxis,zaxis; int battery,rssi; + String password= ""; + EditText edtPass; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -476,6 +483,40 @@ public class MainActivity extends AppCompatActivity { } }); } + public void passwordFromUser() { + final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); + LayoutInflater inflater = this.getLayoutInflater(); + dialogBuilder.setCancelable(false); + final View dialogView = inflater.inflate(R.layout.password_dialog, null); + dialogBuilder.setView(dialogView); + edtPass = dialogView.findViewById(R.id.edtPass); + + //System.out.println("Value of userPass "+String.valueOf(userPass)); + dialogBuilder.setPositiveButton("SUBMIT", null); + dialogBuilder.setTitle("Password Validation"); + dialogBuilder.setMessage("Please enter password to connect to bluetooth."); + final AlertDialog b = dialogBuilder.create(); + b.show(); + Button positiveButton = b.getButton(AlertDialog.BUTTON_POSITIVE); + //String finalUserPass = userPass; + //password = "minew123"; + positiveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String userPass = edtPass.getText().toString().trim(); + System.out.println("Value of userPass "+userPass); + if(userPass.equals("minew123")){ + Toast.makeText(MainActivity.this, "Password accepted", Toast.LENGTH_SHORT).show(); + Intent intent2 = new Intent(MainActivity.this,DetailActivity.class); + startActivity(intent2); + b.dismiss(); + } + else{ + Toast.makeText(MainActivity.this, "Password incorrect", Toast.LENGTH_SHORT).show(); + } + } + }); + } private ConnectionStatueListener connectionStatueListener = new ConnectionStatueListener() { @Override @@ -503,8 +544,9 @@ public class MainActivity extends AppCompatActivity { case PASSWORDVALIDATING: Log.e("tag", "PASSWORDVALIDATING"); Toast.makeText(MainActivity.this, "PASSWORDVALIDATING", Toast.LENGTH_SHORT).show(); - String password = "minew123"; + passwordFromUser(); getPasswordListener.getPassword(password); + break; case SYNCHRONIZINGTIME: Log.e("tag", "SYNCHRONIZINGTIME"); diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml index 6bafc5c..7d0533d 100644 --- a/app/src/main/res/layout/activity_detail.xml +++ b/app/src/main/res/layout/activity_detail.xml @@ -24,10 +24,12 @@ android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textSize="18sp" - android:textColor="@color/black" + android:layout_centerInParent="true" android:text="Detail" - android:layout_centerInParent="true"/> + android:textColor="@color/black" + android:textSize="18sp" /> + + @@ -148,4 +150,12 @@ android:layout_marginTop="42dp" android:text="Set trigger"/> + \ No newline at end of file diff --git a/app/src/main/res/layout/password_dialog.xml b/app/src/main/res/layout/password_dialog.xml new file mode 100644 index 0000000..be918a0 --- /dev/null +++ b/app/src/main/res/layout/password_dialog.xml @@ -0,0 +1,19 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/password_reset.xml b/app/src/main/res/layout/password_reset.xml new file mode 100644 index 0000000..1dae2ce --- /dev/null +++ b/app/src/main/res/layout/password_reset.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file