Friday 23 April 2021

In Android EditText, how to force writing uppercase?

In Android EditText, how to force writing uppercase? 

@Override

public void setFilters(InputFilter[] filters) {
try {
InputFilter[] oldFilter = filters;
InputFilter[] newFilters = new InputFilter[oldFilter.length + 1];
System.arraycopy(oldFilter, 0, newFilters, 0, oldFilter.length);
newFilters[newFilters.length - 1] = new InputFilter.AllCaps();
super.setFilters(newFilters);
} catch (Exception e) {
e.printStackTrace();
FirebaseCrashlytics.getInstance().recordException(e);
}

}

Disabling Android O auto-fill service for an application

So I have my own class which is extends the android.support.v7.widget.AppCompatEditText
 and all I did is overwrote the following method with the following value:


@Override
public int getAutofillType() {
return AUTOFILL_TYPE_NONE;
}

no other solutions worked, not even android:importantForAutofill="no".

getAutofillType() comes from the View class, so it should work for every other
class such as TextInputEditText too!

Monday 12 April 2021

Firebase : -Firestore Live Location

FIRESTORE Live Location 

AUTHENTICATION:-






EDIT RULES :-

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /dev/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
match /LiveData/{userId} {
allow read, update, delete,create: if request.auth.uid != null;

}
}
}

}

ANDROID CODE:

String token;
FirebaseAuth authref;
private FirebaseFirestore db;
<string name="FIREBASE_DATABASE_NAME">dev</string>
<string name="FIREBASE_DATABASE_NODE_NAME">LiveData</string>
<string name="FIREBASE_EMAIL_DB">amitrawat@gmail.com</string>
<string name="FIREBASE_PASS_DB">123456789</string>
@Override
public void onCreate() {
super.onCreate();

try {
        setup();
notificationToken();
loginFirebase();
} catch (Exception e) {
e.printStackTrace();

}


}
public void setup() {

db = FirebaseFirestore.getInstance();

}
private void notificationToken() throws Exception {
try {
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
return;
}
token = task.getResult().getToken();

Log.e("token", token);
}
});
} catch (Exception e) {
throw new Exception(e);
}
}


  private void loginToFirebase() {
//Authenticate with Firebase, using the email and password we created earlier//
String email = getString(R.string.FIREBASE_EMAIL_DB);
String password = getString(R.string.FIREBASE_PASS_DB);
//Call OnCompleteListener if the user is signed in successfully//
authref = FirebaseAuth.getInstance();
authref.signInWithEmailAndPassword(
email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(Task<AuthResult> task) {
if (task.isSuccessful()) {
try {
requestLocationUpdates();
} catch (Exception e) {

}

} else {
Log.d(TAG, "Firebase authentication failed");
}
}
});
}


 private void requestLocationUpdates() {

LocationRequest request = new LocationRequest();
request.setInterval(60000);
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
FusedLocationProviderClient client = LocationServices.getFusedLocationProviderClient(this);
int permission = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION);
//If the app currently has access to the location permission...//
if (permission == PackageManager.PERMISSION_GRANTED) {
//...then request location updates//
client.requestLocationUpdates(request, new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
//Get a reference to the database, so your app can perform read and write operations//
if (isNullOrEmpty(token)) {
try {
notificationToken();
} catch (Exception e) {
e.printStackTrace();
Util.Crash(e);
}
} else {
try {

Location location = locationResult.getLastLocation();
if (location != null) {
FirebaseDTO locdto = new FirebaseDTO ();
locdto.setLatitude(location.getLatitude());
locdto.setLongitude(location.getLongitude());

locdto.setLastUpdatedOn(String.valueOf(new Timestamp(System.currentTimeMillis())));
Log.e("loc1", String.valueOf(location.getLatitude()));
Log.e("loc2", String.valueOf(location.getLongitude()));


// Add a new document with a generated ID\

db.collection(getResources().getString(R.string.FIREBASE_DATABASE_NAME)).
document(authref.getUid()).
collection(getResources().getString(R.string.FIREBASE_DATABASE_NODE_NAME)).
document(token).
set(locdto)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "DocumentSnapshot successfully written!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error writing document", e);
}
});

}


} catch (Exception e) {
Util.Crash(e);
}

}

}
}, null);
}
}
public class FirebaseDTO {
private double latitude;
private double longitude
private String lastUpdatedOn;

}

 

Monday 5 April 2021

Alert Dialog in flutter

 Alert Dialog in flutter

 new IconButton(
icon: new Icon(Icons.cloud_download_rounded),
highlightColor: Colors.orange,
iconSize: 30,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return getDialogBox();
});
},
),

method of AlertDialog 
AlertDialog getDialogBox() {
return AlertDialog(
title: Row(children: [
new IconButton(
icon: new Icon(Icons.warning_amber_outlined),
color: Colors.black45,
highlightColor: Colors.orange,
iconSize: 30,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return getDialogBox();
});
},
),
/* Image.network(
'https://flutter-examples.com/wp-content/uploads/2019/12/android_icon.png',
width: 50,
height: 50,
fit: BoxFit.contain,
),*/
Text(' Download ')
]),
content: Text("Are You Sure Want To Proceed?"),
actions: <Widget>[
TextButton(
child: Text("YES"),
onPressed: () {
//Put your code here which you want to execute on Yes button click.
Navigator.of(context).pop();
},
),
TextButton(
child:
Text("CANCEL"),
onPressed: () {
//Put your code here which you want to execute on Cancel button click.
Navigator.of(context).pop();
},
),
],
);
}