正在查看: St.John's v1.0.9 应用的 LearningAssessmentQuestionsActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: St.John's v1.0.9 应用的 LearningAssessmentQuestionsActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mcb.stjohnsemschool.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.C;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.model.LearningAssessmentQuestionModelClass;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.ToggleButtonGroupTableLayout;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import com.squareup.picasso.Picasso;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class LearningAssessmentQuestionsActivity extends AppCompatActivity {
private static final String TAG = "com.mcb.stjohnsemschool.activity.LearningAssessmentQuestionsActivity";
private Activity activity;
private int chapterId;
private Context context;
private ToggleButtonGroupTableLayout mOptionsTL;
private TransparentProgressDialog mProgressbar;
private ImageView mQuestionImg;
private TextView mQuestionNoTxv;
private WebView mQuestionTxv;
private int topicId;
private int position = 0;
private String studentEnrollmentId = "0";
private String academicYearId = "0";
private String userId = "0";
private String organizationId = "0";
private String classId = "0";
private String topicName = "";
private String subject = "";
private String subjectGUID = "";
private ArrayList<LearningAssessmentQuestionModelClass> questionsList = new ArrayList<>();
static int access$208(LearningAssessmentQuestionsActivity learningAssessmentQuestionsActivity) {
int i = learningAssessmentQuestionsActivity.position;
learningAssessmentQuestionsActivity.position = i + 1;
return i;
}
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_learning_assessment_questions);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.context = getApplicationContext();
this.activity = this;
this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
this.studentEnrollmentId = sharedPreferences.getString("studentEnrollmentIdKey", this.studentEnrollmentId);
this.userId = sharedPreferences.getString("UseridKey", this.userId);
this.academicYearId = sharedPreferences.getString("academicyearIdKey", this.academicYearId);
this.organizationId = sharedPreferences.getString("orgnizationIdKey", "0");
this.classId = sharedPreferences.getString("ClassidKey", "0");
Bundle extras = getIntent().getExtras();
this.chapterId = extras.getInt("ChapterId", 0);
this.subject = extras.getString("SubjectName", "");
this.subjectGUID = extras.getString("SubjectGUID", "");
this.topicId = extras.getInt("TopicId", 0);
this.topicName = extras.getString("TopicName", "");
getSupportActionBar().setTitle(this.topicName);
getSupportActionBar().setSubtitle("Questions");
initializations();
}
private void initializations() {
this.mQuestionImg = (ImageView) findViewById(R.id.img_question);
this.mQuestionNoTxv = (TextView) findViewById(R.id.txv_question_no);
WebView webView = (WebView) findViewById(R.id.txv_question);
this.mQuestionTxv = webView;
webView.setScrollBarStyle(33554432);
this.mQuestionTxv.setScrollbarFadingEnabled(false);
this.mQuestionTxv.setVerticalScrollBarEnabled(true);
this.mQuestionTxv.setHorizontalScrollBarEnabled(true);
this.mOptionsTL = findViewById(R.id.tl_options);
getExamsQuestions();
}
RadioButton getElementRadioButton(String str, float f, int i) {
final RadioButton radioButton = (RadioButton) LayoutInflater.from(this.context).inflate(R.layout.radio_button, (ViewGroup) null);
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0, -2, f);
layoutParams.gravity = 17;
radioButton.setLayoutParams(layoutParams);
radioButton.setText(str);
radioButton.setTag(i + "_" + str);
if (this.questionsList.get(i).getSelectedAnswer() != null && this.questionsList.get(i).getSelectedAnswer().equalsIgnoreCase(str)) {
radioButton.setChecked(true);
}
radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
if (z) {
String trim = radioButton.getTag().toString().trim();
int parseInt = Integer.parseInt(trim.substring(0, trim.indexOf("_")).trim());
((LearningAssessmentQuestionModelClass) LearningAssessmentQuestionsActivity.this.questionsList.get(parseInt)).setSelectedAnswer(trim.substring(trim.indexOf("_") + 1).trim());
}
}
});
return radioButton;
}
private void getExamsQuestions() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
getTopicExerciseQuestionsForLearning();
} else {
Toast.makeText(this.context, "Check your Network Connection", 0).show();
}
}
private void getTopicExerciseQuestionsForLearning() {
TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
this.mProgressbar.show();
}
((ApiInterface) ApiClient.getClient1(this.context).create(ApiInterface.class)).GetTopicExerciseQuestionsForLearning(Integer.parseInt(this.organizationId), Integer.parseInt(this.classId), this.chapterId, this.topicId, this.subjectGUID, Utility.getSchoolApiKey(this.context)).enqueue(new Callback<ArrayList<LearningAssessmentQuestionModelClass>>() {
public void onResponse(Call<ArrayList<LearningAssessmentQuestionModelClass>> call, Response<ArrayList<LearningAssessmentQuestionModelClass>> response) {
if (LearningAssessmentQuestionsActivity.this.mProgressbar != null && LearningAssessmentQuestionsActivity.this.mProgressbar.isShowing()) {
LearningAssessmentQuestionsActivity.this.mProgressbar.dismiss();
}
if (response == null || response.body() == null) {
Utility.showAlertDialog(LearningAssessmentQuestionsActivity.this.activity);
return;
}
LearningAssessmentQuestionsActivity.this.questionsList.clear();
LearningAssessmentQuestionsActivity.this.questionsList = (ArrayList) response.body();
LearningAssessmentQuestionsActivity.this.position = 0;
LearningAssessmentQuestionsActivity.this.loadQuestion();
}
public void onFailure(Call<ArrayList<LearningAssessmentQuestionModelClass>> call, Throwable th) {
if (LearningAssessmentQuestionsActivity.this.mProgressbar != null && LearningAssessmentQuestionsActivity.this.mProgressbar.isShowing()) {
LearningAssessmentQuestionsActivity.this.mProgressbar.dismiss();
}
Utility.showAlertDialog(LearningAssessmentQuestionsActivity.this.activity);
}
});
}
public void loadQuestion() {
this.mQuestionImg.setVisibility(8);
this.mQuestionTxv.setVisibility(8);
LearningAssessmentQuestionModelClass learningAssessmentQuestionModelClass = this.questionsList.get(this.position);
this.mQuestionNoTxv.setText((this.position + 1) + ".");
if (learningAssessmentQuestionModelClass.getQuestionImage() != null && learningAssessmentQuestionModelClass.getQuestionImage().length() > 0 && !learningAssessmentQuestionModelClass.getQuestionImage().equalsIgnoreCase(null)) {
this.mQuestionImg.setVisibility(0);
Picasso.get().load(learningAssessmentQuestionModelClass.getQuestionImage()).into(this.mQuestionImg);
} else {
try {
this.mQuestionTxv.loadData(Base64.encodeToString(learningAssessmentQuestionModelClass.getQuestionText().getBytes(C.UTF8_NAME), 0), "text/html; charset=utf-8", "base64");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
this.mQuestionTxv.setVisibility(0);
}
this.mOptionsTL.removeAllViews();
int noOfOptions = learningAssessmentQuestionModelClass.getNoOfOptions();
int i = noOfOptions > 4 ? (noOfOptions % 4) + (noOfOptions / 4) : 1;
int i2 = 1;
for (int i3 = 0; i3 < i; i3++) {
TableRow tableRow = new TableRow(this.context);
tableRow.addView(getElementRadioButton(String.valueOf(i2), 1.0f, this.position));
if (i2 < noOfOptions) {
i2++;
tableRow.addView(getElementRadioButton(String.valueOf(i2), 1.0f, this.position));
}
if (i2 < noOfOptions) {
i2++;
tableRow.addView(getElementRadioButton(String.valueOf(i2), 1.0f, this.position));
}
if (i2 < noOfOptions) {
i2++;
tableRow.addView(getElementRadioButton(String.valueOf(i2), 1.0f, this.position));
}
this.mOptionsTL.addView(tableRow);
i2++;
}
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.save_icon_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem menuItem) {
int itemId = menuItem.getItemId();
if (itemId == 16908332) {
finish();
} else if (itemId == 2131361885) {
saveOnlineExaminationAnswers();
}
return super.onOptionsItemSelected(menuItem);
}
private void saveOnlineExaminationAnswers() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
saveTopicExerciseAnswers();
} else {
Toast.makeText(this.context, "Check your Network Connection", 0).show();
}
}
private void saveTopicExerciseAnswers() {
String str;
String str2;
TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
this.mProgressbar.show();
}
LearningAssessmentQuestionModelClass learningAssessmentQuestionModelClass = this.questionsList.get(this.position);
str = "0";
if (learningAssessmentQuestionModelClass.getSelectedAnswer() == null || learningAssessmentQuestionModelClass.getSelectedAnswer().length() <= 0 || learningAssessmentQuestionModelClass.getSelectedAnswer().equalsIgnoreCase("null")) {
str2 = "0";
} else {
String selectedAnswer = learningAssessmentQuestionModelClass.getSelectedAnswer();
str = selectedAnswer;
str2 = selectedAnswer.equalsIgnoreCase(learningAssessmentQuestionModelClass.getAnswerNo()) ? "1" : "0";
}
HashMap hashMap = new HashMap();
hashMap.put("OrganisationID", this.organizationId);
hashMap.put("ClassID", this.classId);
hashMap.put("SubjectSyllabusID", String.valueOf(this.chapterId));
hashMap.put("TopicID", String.valueOf(this.topicId));
hashMap.put("SubjectGUID", this.subjectGUID);
hashMap.put("StudentEnrollmentID", this.studentEnrollmentId);
hashMap.put("ExerciseNo", String.valueOf(learningAssessmentQuestionModelClass.getExerciseNo()));
hashMap.put("TopicExerciseID", String.valueOf(learningAssessmentQuestionModelClass.getExerciseId()));
hashMap.put("QuestionBankQuestionID", String.valueOf(learningAssessmentQuestionModelClass.getQuestionBankQuestionId()));
hashMap.put("DifficultyLevel", String.valueOf(learningAssessmentQuestionModelClass.getDifficultyLevel()));
hashMap.put("CorrectAnswerNo", learningAssessmentQuestionModelClass.getAnswerNo());
hashMap.put("GivenAnswer", str);
hashMap.put("Marks", str2);
hashMap.put("UserID", this.userId);
hashMap.put("apikey", Utility.getSchoolApiKey(this.context));
((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).SaveTopicExerciseAnswers(hashMap).enqueue(new Callback<String>() {
public void onResponse(Call<String> call, Response<String> response) {
if (LearningAssessmentQuestionsActivity.this.mProgressbar != null && LearningAssessmentQuestionsActivity.this.mProgressbar.isShowing()) {
LearningAssessmentQuestionsActivity.this.mProgressbar.dismiss();
}
if (response == null || response.body() == null) {
Utility.showAlertDialog(LearningAssessmentQuestionsActivity.this.activity);
return;
}
if (LearningAssessmentQuestionsActivity.this.position < LearningAssessmentQuestionsActivity.this.questionsList.size() - 1) {
LearningAssessmentQuestionsActivity.access$208(LearningAssessmentQuestionsActivity.this);
LearningAssessmentQuestionsActivity.this.loadQuestion();
return;
}
Intent intent = new Intent(LearningAssessmentQuestionsActivity.this.context, (Class<?>) LearningAssessmentResultActivity.class);
intent.putExtra("TopicId", LearningAssessmentQuestionsActivity.this.topicId);
intent.putExtra("TopicName", LearningAssessmentQuestionsActivity.this.topicName);
intent.putExtra("SubjectName", LearningAssessmentQuestionsActivity.this.subject);
intent.putExtra("SubjectGUID", LearningAssessmentQuestionsActivity.this.subjectGUID);
intent.putExtra("ChapterId", LearningAssessmentQuestionsActivity.this.chapterId);
LearningAssessmentQuestionsActivity.this.startActivity(intent);
LearningAssessmentQuestionsActivity.this.finish();
}
public void onFailure(Call<String> call, Throwable th) {
if (LearningAssessmentQuestionsActivity.this.mProgressbar != null && LearningAssessmentQuestionsActivity.this.mProgressbar.isShowing()) {
LearningAssessmentQuestionsActivity.this.mProgressbar.dismiss();
}
Utility.showAlertDialog(LearningAssessmentQuestionsActivity.this.activity);
}
});
}
protected void onResume() {
super.onResume();
String string = getSharedPreferences("", 0).getString("usernamekey", "");
Bundle bundle = new Bundle();
bundle.putString("user_name", string);
FirebaseAnalytics.getInstance(this).logEvent("PAGE_LEARNING_EXAM_QUESTIONS", bundle);
}
protected void onStop() {
TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
if (transparentProgressDialog != null && transparentProgressDialog.isShowing()) {
this.mProgressbar.dismiss();
}
super.onStop();
}
}