I Dont know how can I get bookmark button in fire base - java

iam already did add bookmark in the firebase but i dont know how can i get it
reference = FirebaseDatabase.getInstance().getReference("pagenumber");
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pagenumber = pdfView.getCurrentPage();
reference.setValue(pagenumber);
if (true) {
Toast.makeText(getApplicationContext(), "تم حفظ العلامة", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "لم يتم حفظ العلامة", Toast.LENGTH_SHORT).show();
}
}
});
load.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}

Related

REST POST API using with request Query Params in android Studio

I'm using the Retrofit2 Library to consume Rest API with a post request that delivers data in query parameters not in body. Now I want to integrate that api but retrofit stops us from providing data as a query parameters through a post request. It is possible to use a post request with retrofit to deliver data in query parameters?
Here is API Interface
#POST("calculation")
Call<QuestionResponse> calculation(
#Query("height") Double height,
#Query("age") Integer age,
#Query("gender") Boolean gender,
#Query("current_weight") Double current_weight,
#Query("activity_level") Double activity_level,
#Query("user_id") Integer user_id
Here is Question.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmiquestions);
getSupportActionBar().hide();
nextbtn = findViewById(R.id.Next);
date = findViewById(R.id.calender);
age = findViewById(R.id.age);
height = findViewById(R.id.currentHeight);
weight = findViewById(R.id.currentWeight);
rgGender = findViewById(R.id.gender_group);
rbMale = findViewById(R.id.male);
rbFemale = findViewById(R.id.female);
rgGender.clearCheck();
rgGender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
rbMale = group.findViewById(R.id.male);
rbFemale = group.findViewById(R.id.female);
if (rbMale.isSelected()) {
gender= Boolean.valueOf("0");
}
if (rbFemale.isSelected()) {
gender= Boolean.valueOf("1");
}
}
});
findViewById(R.id.female).setOnClickListener(this);
findViewById(R.id.male).setOnClickListener(this);
findViewById(R.id.Next).setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.Next:
openHomePage();
break;
}
}
public void openHomePage() {
Double userHeight = Double.valueOf(height.getText().toString());
Double userWeight = Double.valueOf(weight.getText().toString());
Integer userAge = Integer.valueOf(age.getText().toString());
if(rgGender.getCheckedRadioButtonId() == -1) {
Toast.makeText(this, "Please Select Gender", Toast.LENGTH_SHORT).show();
return;
}
Intent i=new Intent(BMIquestions.this,ActivityLevel.class);
i.putExtra("age",userAge);
i.putExtra("height",userHeight);
i.putExtra("weight",userWeight);
i.putExtra("gender",gender);
startActivity(i);
Here is Activity_level.java
public class ActivityLevel extends AppCompatActivity implements View.OnClickListener {
ImageButton next;
ImageButton previous;
CardView card1,card2,card3,card4;
SharedPreferenceManager sharedPreferenceManager;
SharedPreferences.Editor editor;
TextView l1,l2,l3,l4;
Double activity_level;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
getSupportActionBar().hide();
next = findViewById(R.id.NextButton);
previous = findViewById(R.id.PreviousButton);
card1 = (CardView) findViewById(R.id.level1);
card2 = (CardView) findViewById(R.id.level2);
card3 = (CardView) findViewById(R.id.level3);
card4 = (CardView) findViewById(R.id.level4);
card1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
activity_level=1.55;
Toast.makeText(ActivityLevel.this, activity_level.toString(), Toast.LENGTH_SHORT).show();
}
});
card2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
activity_level=1.725;
Toast.makeText(ActivityLevel.this, activity_level.toString(), Toast.LENGTH_SHORT).show();
}
});
card3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
activity_level=1.75;
Toast.makeText(ActivityLevel.this, activity_level.toString(), Toast.LENGTH_SHORT).show();
}
});
card4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
activity_level=2.04;
Toast.makeText(ActivityLevel.this, activity_level.toString(), Toast.LENGTH_SHORT).show();
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openHomePage();
}
});
sharedPreferenceManager=new SharedPreferenceManager(getApplicationContext());
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.PreviousButton:
openBMIPage();
break;
}
}
public void openHomePage() {
Integer age= Integer.valueOf(getIntent().getStringExtra("age"));
Boolean gender= Boolean.valueOf(getIntent().getStringExtra("gender"));
Double height= Double.valueOf(getIntent().getStringExtra("height"));
Double weight= Double.valueOf(getIntent().getStringExtra("weight"));
Integer userId= sharedPreferenceManager.getUser().getUserId();
Call<QuestionResponse> call = RetrofitClient
.getInstance()
.getApi()
.calculation(height,age,gender,weight,activity_level,userId);
call.enqueue(new Callback<QuestionResponse>() {
#Override
public void onResponse(Call<QuestionResponse> call, Response<QuestionResponse> response) {
QuestionResponse questionResponse = response.body();
if (response.isSuccessful()) {
if (questionResponse.getStatus().equals("SUCCESS")) {
Toast.makeText(ActivityLevel.this, questionResponse.getMessage(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ActivityLevel.this, HomePage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
} else {
Toast.makeText(ActivityLevel.this, questionResponse.getMessage(), Toast.LENGTH_SHORT).show();
}
}
else {
Toast.makeText(ActivityLevel.this, questionResponse.getMessage(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(Call<QuestionResponse> call, Throwable t) {
Toast.makeText(ActivityLevel.this, t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
public void openBMIPage() {
Intent intent1 = new Intent(this, BMIquestions.class);
startActivity(intent1);
}
}
After Debugging
Connected to the target VM, address: 'localhost:52230', transport: 'socket'
Disconnected from the target VM, address: 'localhost:52230', transport: 'socket'
How do I fix this?

How do I make the terms and conditions appear only when I log in to Google for the first time?

I want to add terms and conditions when users use my app.
But I have to show terms and conditions only one time.
I'm using firebase google login. But I have a problem when I show terms and conditions and how code remembers users accept terms and conditions and shows only one time.
Here's a google login code.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//새로운 코드다 마
signInButton = findViewById(R.id.signInButton);
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
googleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this,this)
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();
auth = FirebaseAuth.getInstance(); //파이어 베이스 인증 객체 초기화
signInButton.setOnClickListener(new View.OnClickListener() { // 구글 로그인 버튼을 클릭했을때 이곳을 수행
#Override
public void onClick(View view) {
Intent intent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
startActivityForResult(intent,REQ_SIGN_GOOGLE);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) { // 구글 로그인 인증을 요청했을때 결과 값을 되돌려 받는 곳
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQ_SIGN_GOOGLE) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if(result.isSuccess() == true) { // true 생략 가능, 인증 결과가 성공적이면
GoogleSignInAccount account = result.getSignInAccount(); //account 라는 데이터는 구글 로그인 정보를 담고 있습니다. - 닉네임,프로필사진uri,이메일 주소등
resultLogin(account); // 로그인 결과 값 출력 수행하라는 메서드
}
}
}
private void resultLogin(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
auth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()) { //로그인이 성공했으면
Intent intent = new Intent(getApplicationContext(),Home.class);
startActivity(intent);
}
else{
Toast.makeText(LoginActivity.this,"로그인 실패",Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
public void onBackPressed() {
long curTime=System.currentTimeMillis();
long gapTime=curTime-backBtnTime;
if(0<=gapTime && 2000>= gapTime){
moveTaskToBack(true);
finishAndRemoveTask();
android.os.Process.killProcess(android.os.Process.myPid());
}
else {
backBtnTime = curTime;
Toast.makeText(this,"뒤로 버튼을 한 번 더 누르면 종료됩니다.",Toast.LENGTH_SHORT).show();
}
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
}
Here is a code I want to show (terms and conditions)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_terms);
CheckBox checkBox=findViewById(R.id.checkbox);
CheckBox checkBox2=findViewById(R.id.checkbox2);
CheckBox checkBox3=findViewById(R.id.checkbox3);
checkBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(checkBox.isChecked()){
checkBox2.setChecked(true);
checkBox3.setChecked(true);
}else {
checkBox2.setChecked(false);
checkBox3.setChecked(false);
}
}
});
checkBox2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(checkBox.isChecked()){
checkBox.setChecked(false);
}else if(checkBox2.isChecked()&&checkBox3.isChecked()){
checkBox.setChecked(true);
}
}
});
checkBox3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(checkBox.isChecked()){
checkBox.setChecked(false);
}else if(checkBox2.isChecked()&&checkBox3.isChecked()){
checkBox.setChecked(true);
}
}
});
Button btn_agr = findViewById(R.id.btn_agr1);
btn_agr.setText(R.string.app_name);
btn_agr.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(TermsActivity.this);
builder.setTitle("서비스 이용약관 ");
builder.setMessage(R.string.app_name);
builder.setNegativeButton("닫기",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.out.println(TAG + "이용약관 닫기");
}
});
builder.show();
}
});
Button btn_agr2 = findViewById(R.id.btn_agr2);
btn_agr2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(TermsActivity.this);
builder.setTitle("위치 정보 이용 약관 ");
builder.setMessage(R.string.app_name);
builder.setNegativeButton("닫기",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.out.println(TAG + "이용약관 닫기");
}
});
builder.show();
}
});
Button btn_complete = findViewById(R.id.button_complete);
btn_complete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
I tried my self - transmit variables when the user accept terms and conditions but when the user reopens the app user has to open it again
Maybe there is a way to transmit certain variables to firebase and confirm it when the user clicks the login button??
There is a way to transmit certain variables to firebase and confirm it when the user clicks the login button?
The simplest solution would be to call AuthResult#getAdditionalUserInfo() method on the Task object, because it returns an object of type AdditionalUserInfo. In this class, you can find a very useful method called isNewUser(), which can help you check if the user signs in for the first time. In code should look like this:
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
auth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()) { //로그인이 성공했으면
boolean isNewUser = task.getResult().getAdditionalUserInfo().isNewUser();
if (isNewUser) {
//Display Terms & Conditions
}
Intent intent = new Intent(getApplicationContext(),Home.class);
startActivity(intent);
}
else{
Toast.makeText(LoginActivity.this,"로그인 실패",Toast.LENGTH_SHORT).show();
}
}
});

The email address is badly formatted Firebase/ android project

hi i am working on a android project where i am using firebase as back-end and i am building a signup and login form . When ever i sign up the code is working well and . When i try to retrieve it using "signInWithEmailAndPassword i am getting the fallowing error. The email address is badly formatted Firebase`
login Activity
public class login extends AppCompatActivity {
Button create_Account, login_btn;
EditText l_email, l_password;
FirebaseAuth fAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
fAuth = FirebaseAuth.getInstance();
create_Account = findViewById(R.id.l_signup_btn);
create_Account.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(login.this, MainActivity.class));
}
});
l_password = findViewById(R.id.et_lpassword);
l_email = findViewById(R.id.et_lpassword);
login_btn = findViewById(R.id.l_login_btn);
login_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (l_email.getText().toString().isEmpty()) {
l_email.setError("Email is Missing");
return;
}
if (l_password.getText().toString().isEmpty()) {
l_password.setError("Password is Missing");
return;
}
fAuth.signInWithEmailAndPassword(l_email.getText().toString(), l_password.getText().toString()).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
#Override
public void onSuccess(AuthResult authResult) {
startActivity(new Intent(getApplicationContext(), dashboard.class));
finish();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(login.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
}
#Override
protected void onStart() {
super.onStart();
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
startActivity(new Intent(getApplicationContext(), dashboard.class));
finish();
}
}
}
Can you see what mistake you have
l_password = findViewById(R.id.et_lpassword);
l_email = findViewById(R.id.et_lpassword);

How to Disable Button after first Click in android

I am using this code but its not working i am still able to click more than 2 times.
accept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
accept.setEnabled(false);
if (dialog1 != null && dialog1.isShowing()) {
dialog1.dismiss();
}
handler.removeCallbacks(runnable);
}
});
its not showing any error but not working as desired.
boolean run = true;
accept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(run) {
run = false;
//your code
}
}
});

Change music with a variable in Android Studio

I want to change the song with a variable but can not do that.
Button btnSpeaker = (Button)findViewById(R.id.btnSpeaker);
btnSpeaker.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MediaPlayer file = MediaPlayer.create(MainActivity.this , R.raw.file1);
file.start();
}
});
final MediaPlayer mediaPlayer=MediaPlayer.create(getApplicationContext(),R.raw.file1);
Button btnSpeaker = (Button)findViewById(R.id.btnSpeaker);
final int[] resources={R.raw.file1,R.raw.file2};
btnSpeaker.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int resource;
//if u meant getting resource variable from the file name
resource=getApplicationContext().getResources().getIdentifier("file2","raw",getPackageName());
//or
resource=resources[index];
mediaPlayer.reset();
try {
mediaPlayer.setDataSource(getApplicationContext().getResources().openRawResourceFd(resource).getFileDescriptor());
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}
});
Button btnSpeaker = (Button)findViewById(R.id.btnSpeaker);
btnSpeaker.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MediaPlayer mp;
mp=MediaPlayer.create(getApplicationContext(), getResources().getIdentifier(word.toLowerCase(),"raw",getPackageName()));
mp.start();
}
});

Categories

Resources