how to make button stop working once timer is over - android-studio

i have created a 50 second timer. Once the timer reach zero a pop view will appear displaying the score and the button on the application should stop working but i am not sure how to make the button stop being clickable
equal.setOnClickListener{
++total
if(ans == ans4 || ans1 == ans4 || ans2 == ans4 || ans3 == ans4 || ans == ans5 || ans1 == ans5 || ans2 == ans5 || ans3 == ans5
|| ans == ans6 || ans1 == ans6 || ans2 == ans6 || ans3 == ans6){
answer.setText("Correct")
answer.setTextColor(Color.GREEN)
++correct
score.setText("Score: $correct/$total")
} else {
answer.setText("Wrong")
answer.setTextColor(Color.RED)
score.setText("Score: $correct/$total")
}
}
val timer = object: CountDownTimer(50000, 1000) {
override fun onTick(millisUntilFinished: Long) {
countTimer.setText("Remaining: " + millisUntilFinished / 1000);
if (correct >= 5){
countTimer.setText("Remaining: " + (millisUntilFinished + 10000 ) / 1000);
}
}
override fun onFinish() {
popup()
}
}
timer.start()
}
fun popup(){
var popupView: View = layoutInflater.inflate(R.layout.score, null)
var gameover_textView = popupView.findViewById<TextView>(R.id.endMessage)
gameover_textView.setText("Score: $correct/$total ")
var popupwindow = PopupWindow(this)
popupwindow.contentView = popupView
popupwindow.showAtLocation(popupView, Gravity.CENTER, 0, 100)
popupView.setOnClickListener{
popupwindow.dismiss()
}
}

equal.setClickable(false);
equal.setClickable(true);
//according to the requirement

Related

Gupshup Save response labels of the users in whatsapp

I have an array declared at the beginning and inside my MessageHandler function I capture the responses with if(event.message) and push the message in the array but when it comes to displaying them in a variable called "datos" in a whatsapp message it doesn't work . In the development environment by gupshup it works but when deploying it in whatsapp it doesn't.
var botScriptExecutor = require('bot-script').executor;
var scr_config = require('./scr_config.json');
var arr = [];
function MessageHandler(context, event) {
if (event.message == "Evento" || event.message == "Construccion" || event.message == "Servicio" || event.message == "Evento 1" || event.message == "Construccion 2" || event.message == "Servicio 3") {
json.categ = event.message;
}
if (event.message == "Saltillo" || event.message == "Monterrey" || event.message == "Otro" || event.message == "Saltillo 2" || event.message == "Monterrey 2" || event.message == "Otro 3") {
json.zona = event.message;
}
}
exports.array = json;
in my script defalt.js I work with the label of the "datos" variable
module.exports.datos = {
label_baas: datosSoli
}
var message = require('./index.js');
function datosSoli(options, event, context, callback) {
console.log("---------------------label datosSoli---------------------");
var info = "";
info = "categoria: " + message.array.categ + "zona: " + message.array.zona;
options.next_state = 'label_baaj';
options.data.datos = info;
console.log("-----------options.data.datos-------------", options.data.datos);
callback(options, event, context);
}
This is the flow of my conversation where the "datos" variable module is shown
enter image description here

How to calculate the working hours in flutter using mongodb

I want to calculate the working hours, my scenario is, when user login to the app and clicks on time in button that time will be stored in the database (I am using mongodb) and if user logout and then login again and then time in button should display the time at which user did last time, and then if user clicks on time out button then it should calculate the working hours, for example, if user time in at 9:10:35 AM and time out at 5:50:47 PM then the total working hours should be 9:40:13 , but from my logic of calculating total working hours it give me this 4:40:12.
Here is my code:
totalWorkingHours() {
print("working hours");
var totalWorkingMin;
var totalWorkingSec;
var totalWorkingHour;
var timeInHoursSplit;
var timeOutHoursSplit;
var timeInHours0;
var timeOutHours0;
List timeInHours;
List timeOutHours;
var inHour;
var outHour;
var inMin;
var outMin;
var inSec;
var outSec;
var flagMin = false;
var flagSec = false;
var defaultIn = " 00:00:00 PM";
var defaultOut = " 00:00:00 PM";
var data = {};
//here i am getting the time in and time out values and using api if in case user logout, and spliting it to get the hours, min and sec
if(workinghours=="0" && getapitimeout==""){
print("11");
timeInHoursSplit = defaultIn.split(' '); //18:35:00 PM
timeOutHoursSplit = defaultOut.split(' ');
}
else if (workinghours == "0" && getTimeInStatus == true) {
print("12");
timeInHoursSplit = gettimeinvalue.split(' '); //18:35:00 PM
timeOutHoursSplit = getapitimeout.split(' ');
}
//if logged in , did timein and timeout at once.
else if(gettimeinworkinghours=="0" && getapitimeout!=""){
print("13");
print(getapitimein);
print(getapitimeout);
timeInHoursSplit = getapitimein.split(' ');
timeOutHoursSplit = getapitimeout.split(' ');
}
//if not time in and time out yet
else {
print("14");
print(getapitimeout);
timeInHoursSplit = defaultIn.split(' ');
timeOutHoursSplit = defaultOut.split(' ');
}
print("1");
print(timeInHoursSplit); //[18:35:00, PM]
timeInHours0 = timeInHoursSplit[1]; //18:35:00
print("2");
print(timeInHours0);
timeOutHours0 = timeOutHoursSplit[1];
timeInHours = timeInHours0.split(':'); //[18, 35, 00]
print(timeInHours);
timeOutHours = timeOutHours0.split(':');
inHour = timeInHours[0];
outHour = timeOutHours[0];
inMin = timeInHours[1];
outMin = timeOutHours[1];
inSec=timeInHours[2];
outSec=timeOutHours[2];
// here i am calculating the hours
if (int.parse(inHour) > int.parse(outHour)) {
totalWorkingHour = int.parse(inHour) - int.parse(outHour);
print(totalWorkingHours);
} else {
totalWorkingHour = int.parse(outHour) - int.parse(outHour);
print(totalWorkingHours);
}
// here i am calculating the min
if (inMin != outMin) {
if (int.parse(outMin) > int.parse(inMin)) {
totalWorkingMin = int.parse(outMin) - int.parse(inMin);
flagMin = true;
} else if (int.parse(inMin) > int.parse(outMin)) {
totalWorkingMin = int.parse(inMin) - int.parse(outMin);
flagMin = true;
}
} else if (inMin == outMin) {
totalWorkingMin = int.parse(outMin) - int.parse(inMin);
flagMin = true;
}
// here i am calculating the sec
if (inSec != outSec) {
if (int.parse(outSec) > int.parse(inSec)) {
totalWorkingSec = int.parse(outSec) - int.parse(inSec);
flagSec = true;
} else if (int.parse(inSec) > int.parse(outSec)) {
totalWorkingSec = int.parse(inSec) - int.parse(outSec);
flagSec = true;
}
} else if (inSec == outSec) {
totalWorkingSec = int.parse(outSec) - int.parse(inSec);
flagSec = true;
}
//// here i am getting the totalworkinghours by concatenating the hours, min and sec
if (flagMin == true && flagSec==true) {
print("1 output");
totalTime = totalWorkingHour.toString() +":" +totalWorkingMin.toString() +":"+totalWorkingSec.toString();
print(totalTime);
return totalTime;
}
//cond 2
else if (flagMin == false && flagSec==false){
print("2 output");
totalTime = totalWorkingHour.toString() +":" +inMin.toString() + ":" +inSec.toString();
return totalTime;
}
//cond 3
else if (flagMin == false && flagSec == true) {
print("3 output");
totalTime = totalWorkingHour.toString() +":" +inMin.toString() ;
return totalTime;
}
//cond 4
else if (flagMin == true && flagSec == false) {
print("4 output");
totalTime = totalWorkingHour.toString() +":" +totalWorkingMin.toString() +":" +inSec.toString();
return totalTime;
}
}
Kindly please help how I can do this.

node.js for loop doesen't loop with the continue command

The goal of the code is repeat the loop till the array index shows something greater than -1. But for some reason the loop stops after one run. And prints -1.
var Darray = ["Dienstag, 19.3.2019:","Donnerstag, 21.3.2019:", "Montag, 18.3.2019:", "Mittwoch, 20.3.2019:", "Montag, 25.3.2019:"];
var x = 1;
var y = 1;
var z = 2019;
loop: for (x = 1; x < 32; x++) {
var suchen = Darray.indexOf(`Montag, ${x}.${y}.${z}:`);
var suchen = Darray.indexOf(`Dienstag, ${x}.${y}.${z}:`);
var suchen = Darray.indexOf(`Mittwoch, ${x}.${y}.${z}:`);
var suchen = Darray.indexOf(`Donnerstag, ${x}.${y}.${z}:`);
var suchen = Darray.indexOf(`Freitag, ${x}.${y}.${z}:`);
if (x == 30) {
y++
}
if (y == 12) {
z++
}
if(suchen == -1) {
continue loop;
}
};
console.log(suchen)
I got my code working, thanks for comment about the var suchen, was a little bit sleepy yesterday. New working code:
loop: for (x = 1; x < 32; x++) {
var date = `${x}.${y}.${z}`
console.log(date)
var mon = Darray.indexOf(`Montag, ${x}.${y}.${z}:`);
var die = Darray.indexOf(`Dienstag, ${x}.${y}.${z}:`);
var mit = Darray.indexOf(`Mittwoch, ${x}.${y}.${z}:`);
var don = Darray.indexOf(`Donnerstag, ${x}.${y}.${z}:`);
var fre = Darray.indexOf(`Freitag, ${x}.${y}.${z}:`);
if (mon != -1 || die != -1 || mit != -1 || don != -1 || fre != -1) {
break;
}
else if (mon == -1 || die == -1 || mit == -1 || don == -1 || fre == -1) {
if (x == 31) {
y++
var x = 0;
}
if (y == 12) {
z++
var y = 1;
}
continue loop;
}
}
console.log(mon, die, mit, don, fre)
Any way to write if condition better looking?

Javascript: empty string

How to check if a string is empty in Javascript?
I already used this condition if (res32.trim == "") and if (res32 == "") and didn't work.
res32 is a var res32 = str.subtring(111,112) and can have the following values: spaces, 0, 1, 4, 5, 6 and 7.
if (res32 == " ") {
if (res21 == 000000) {
document.write("<td bgcolor=#99FF00><font face=Verdana color=#FFFFFF size=1>true</font></td></tr>
}
} else {
if (res32 == 0 || res32 ==1 || res32 ==4 || res32 ==5 || res32 ==6 || res32 ==7) {
if (res21 > 0){
document.write("<td bgcolor=#99FF00><font face=Verdana color=#FFFFFF size=1>true</font></td></tr>");
} else {
document.write("<td bgcolor=#FF0000><font face=Verdana color=#FFFFFF size=1>false</font></td></tr>");
}
}
}
Use javascript .value:
function checkValue(){
var res32 = document.getElementById('res32');
if (res32.value == "" || res32.value == null){
alert('The text field is empty.');
}else{
alert('The text field is not empty.');
}
}
<input type="text" id="res32">
<input type="button" onclick="checkValue()" value="Check if the input field is null.">

String Subscript out of range in C++

I'm trying to convert Roman Numerals into Decimal numbers but I keep encountering this error every time I enter a Roman Numeral. I've tried editing the code numerous times but so far I haven't been able to figure out what's going on.
Here's my code:
Header:
#include <string>
using namespace std;
class romanNumeralType
{
public:
string setNumeral() const;
string getNumeral();
int convert(string romanNumber);
int getDecimal();
void printRoman() const;
void printDecimal() const;
private:
string romanNumber;
int englishNumbers;
};
Implementation:
string romanNumeralType::setNumeral() const
{
string romanNumber;
cout << "Please enter the Roman Numeral you wish to use: ";
cin >> romanNumber;
cout << endl;
return romanNumber;
}
string romanNumeralType::getNumeral()
{
return romanNumber;
}
int romanNumeralType::convert(string romanNumber)
{
englishNumbers = 0;
for (size_t i = 0; i < romanNumber.length(); i++ )
{
switch (romanNumber[i])
{
case 'm':
case 'M':
if (romanNumber[i] == 'M')
{
englishNumbers += 1000;
}
break;
case 'd':
case 'D':
if(romanNumber[i+1] == 'M')
{
englishNumbers += 500;
}
else if(romanNumber[i-1] == 'M')
{
englishNumbers -= 500;
}
break;
case 'c':
case 'C':
if(romanNumber[i+1] == 'M' || romanNumber[i+1] == 'D')
{
englishNumbers += 100;
}
else if(romanNumber[i-1] == 'M' || romanNumber[i-1] == 'D')
{
englishNumbers += 100;
}
break;
case 'l':
case 'L':
if(romanNumber[i+1] == 'M' || romanNumber[i+1] == 'D' || romanNumber[i+1] == 'C')
{
englishNumbers -= 50;
}
else if(romanNumber[i-1] == 'M' || romanNumber[i-1] == 'D' || romanNumber[i-1] == 'C')
{
englishNumbers += 50;
}
break;
case 'x':
case 'X':
if(romanNumber[i+1] == 'M' || romanNumber[i+1] == 'D' || romanNumber[i+1] == 'C' || romanNumber[i+1] == 'L')
{
englishNumbers -= 10;
}
else if(romanNumber[i-1] == 'M' || romanNumber[i-1] == 'D' || romanNumber[i-1] == 'C' || romanNumber[i-1] == 'L')
{
englishNumbers += 10;
}
break;
case 'v':
case 'V':
if(romanNumber[i+1] == 'M' || romanNumber[i+1] == 'D' || romanNumber[i+1] == 'C' || romanNumber[i+1] == 'L' || romanNumber[i+1] == 'X')
{
englishNumbers -= 5;
}
else if(romanNumber[i-1] == 'M' || romanNumber[i-1] == 'D' || romanNumber[i-1] == 'C' || romanNumber[i-1] == 'L' || romanNumber[i-1] == 'X')
{
englishNumbers += 5;
}
break;
case 'i':
case 'I':
if(romanNumber[i+1] == 'M' || romanNumber[i+1] == 'D' || romanNumber[i+1] == 'C' || romanNumber[i+1] == 'L' || romanNumber[i+1] == 'X' || romanNumber[i+1] == 'V')
{
englishNumbers -= 5;
}
else if(romanNumber[i-1] == 'M' || romanNumber[i-1] == 'D' || romanNumber[i-1] == 'C' || romanNumber[i-1] == 'L' || romanNumber[i-1] == 'X' || romanNumber[i-1] == 'V')
{
englishNumbers += 1;
}
break;
default:
return 0;
}//end switch
}//end for
return englishNumbers;
}
int romanNumeralType::getDecimal()
{
return englishNumbers;
}
void romanNumeralType::printRoman() const
{
cout << "The Roman Numeral is: " << romanNumber;
}
void romanNumeralType::printDecimal() const
{
cout << "The Decimal is: " << englishNumbers;
}
Any help at all would be greatly appreciated!
We have 0 <= i < romanNumber.length(), but you are getting access to romanNumber[i-1] and romanNumber[i+1]. So it is possible to try to get access to romanNumber[-1] or to romanNumber[romanNumber.length()] - it is forbidden.
So, you have to add checks. For example, before if(romanNumber[i+1] == 'M') it is necessary to check that i+1<romanNumber.length(). And before if(romanNumber[i-1] == 'M') it is necessary to check that i > 0.
I think this is happening because some of your code looks at array indexes ahead of the current index, e.g. i+1. When the end of the array is reached, i+1 will not be a valid element of the array, giving you an error.

Resources