Browse Source

Password validation

master
Krish 1 year ago
parent
commit
5e82b320e7
5 changed files with 194 additions and 4 deletions
  1. +94
    -0
      app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java
  2. +43
    -1
      app/src/main/java/com/example/beacondemo/Activity/MainActivity.java
  3. +13
    -3
      app/src/main/res/layout/activity_detail.xml
  4. +19
    -0
      app/src/main/res/layout/password_dialog.xml
  5. +25
    -0
      app/src/main/res/layout/password_reset.xml

+ 94
- 0
app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java View File

@ -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<MinewFrame> 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 asFirmware Version 0.9.1;
HashMap<String, String> systeminfos = (HashMap<String, String>) 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 modifiednoneadv,txpower,adv/txpower
FeatureSupported featureSupported = mtConnectionFeature.getFeatureSupported();
Log.d("featureSupported", String.valueOf(featureSupported));
// // frames supportedmultiple
List<FrameType> supportedSlots = mtConnectionFeature.getSupportedSlots();
Log.d("supportedSlots", String.valueOf(supportedSlots));
// Txpower supportedmultiple
byte[] supportedTxpowers = mtConnectionFeature.getSupportedTxpowers();
Log.d("supportedTxpowers", String.valueOf(supportedTxpowers));
// trigger supportedmultiple
ArrayList<TriggerType> supportTriggers = (ArrayList<TriggerType>) 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) {


+ 43
- 1
app/src/main/java/com/example/beacondemo/Activity/MainActivity.java View File

@ -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");


+ 13
- 3
app/src/main/res/layout/activity_detail.xml View File

@ -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" />
</RelativeLayout>
@ -148,4 +150,12 @@
android:layout_marginTop="42dp"
android:text="Set trigger"/>
<TextView
android:id="@+id/tv_resetPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="42dp"
android:text="Reset password"/>
</LinearLayout>

+ 19
- 0
app/src/main/res/layout/password_dialog.xml View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/edtPass"
android:layout_width="match_parent"
android:hint="PASSWORD"
android:longClickable="false"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_margin="10dp"/>
</LinearLayout>

+ 25
- 0
app/src/main/res/layout/password_reset.xml View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/edtPassR"
android:layout_width="match_parent"
android:hint="PASSWORD"
android:longClickable="false"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_margin="10dp"/>
<EditText
android:id="@+id/edtConPassR"
android:layout_width="match_parent"
android:hint="CONFIRM PASSWORD"
android:longClickable="false"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_margin="10dp"/>
</LinearLayout>

Loading…
Cancel
Save