正在查看: Harvest v2.32 应用的 QrCodeScannerDetailActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Harvest v2.32 应用的 QrCodeScannerDetailActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.ufields.tracking;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.google.android.material.snackbar.Snackbar;
import com.itextpdf.text.xml.xmp.DublinCoreProperties;
import com.ufields.tracking.App.EndPoints;
import com.ufields.tracking.Helper.Constants;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class QrCodeScannerDetailActivity extends AppCompatActivity {
@BindView(R.id.backBtn)
ImageView backBtn;
private Context ctx;
@BindView(R.id.cultivarTV)
TextView cultivarTV;
@BindView(R.id.dateTV)
TextView dateTV;
@BindView(R.id.etField)
TextView etField;
@BindView(R.id.etSubfield)
TextView etSubfield;
@BindView(R.id.harvestLOTTV)
TextView harvestLotTV;
@BindView(R.id.llPackages)
LinearLayout llPackages;
@BindView(R.id.notesTV)
TextView notesTV;
private Dialog pDialog;
@BindView(R.id.packagesTitle)
TextView packagesTitle;
private ProgressBar progressBar;
private TextView setMessage;
@BindView(R.id.mainContainer)
ConstraintLayout snack;
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_qr_code_scanner_detail);
ButterKnife.bind(this);
setView();
setOnClickListener();
String stringExtra = getIntent().getStringExtra(Constants.HARVEST_ID);
if (stringExtra.equals("")) {
return;
}
new getHarvestDetail().execute(stringExtra);
}
private void setView() {
Dialog dialog = new Dialog(this);
this.pDialog = dialog;
dialog.setCanceledOnTouchOutside(false);
this.pDialog.requestWindowFeature(1);
this.pDialog.setContentView(R.layout.progress_dialog);
this.pDialog.setTitle("");
this.progressBar = (ProgressBar) this.pDialog.findViewById(R.id.progress);
this.setMessage = (TextView) this.pDialog.findViewById(R.id.message);
}
public void showDialog() {
if (this.pDialog.isShowing()) {
return;
}
this.progressBar.setVisibility(0);
this.pDialog.show();
}
public void hideDialog() {
if (!this.pDialog.isShowing() || this.pDialog == null) {
return;
}
this.progressBar.setVisibility(4);
try {
this.pDialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}
private void setOnClickListener() {
this.backBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
QrCodeScannerDetailActivity.this.finish();
}
});
}
public class getHarvestDetail extends AsyncTask<String, Void, String> {
String organizationId = "";
public getHarvestDetail() {
}
@Override
protected void onPreExecute() {
QrCodeScannerDetailActivity.this.setMessage.setText(QrCodeScannerDetailActivity.this.getResources().getText(R.string.loading));
QrCodeScannerDetailActivity.this.showDialog();
}
@Override
public String doInBackground(String... strArr) {
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(defaultHttpClient.getParams(), 5000);
InputStream inputStream = null;
try {
HttpResponse execute = defaultHttpClient.execute(new HttpGet(EndPoints.GET_HARVEST_DETAIL + strArr[0]));
if (execute != null) {
inputStream = execute.getEntity().getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e2) {
e2.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
}
return inputStream != null ? QrCodeScannerDetailActivity.this.convertStreamToString(inputStream) : "";
}
@Override
public void onPostExecute(String str) {
QrCodeScannerDetailActivity.this.hideDialog();
if (!str.equals("")) {
try {
JSONObject jSONObject = new JSONObject(str);
if (jSONObject.has("data")) {
JSONObject jSONObject2 = jSONObject.getJSONObject("data").getJSONObject("harvest");
JSONArray jSONArray = jSONObject2.getJSONArray("packages");
String string = jSONObject2.getJSONObject("cultivarDetail").getString("name");
String string2 = jSONObject2.getString("harvestLot");
String string3 = jSONObject2.getString(DublinCoreProperties.DATE);
String string4 = jSONObject2.getString("notes");
QrCodeScannerDetailActivity.this.harvestLotTV.setText(string2);
QrCodeScannerDetailActivity.this.cultivarTV.setText(string);
QrCodeScannerDetailActivity.this.dateTV.setText(QrCodeScannerDetailActivity.this.convertISOTimeToDate(string3));
if (!jSONObject2.isNull("fieldDetail")) {
QrCodeScannerDetailActivity.this.etField.setText(jSONObject2.getJSONObject("fieldDetail").getString("name"));
}
QrCodeScannerDetailActivity.this.notesTV.setText(string4);
if (!jSONObject2.isNull("subFieldDetail")) {
QrCodeScannerDetailActivity.this.etSubfield.setText(jSONObject2.getJSONObject("subFieldDetail").getString("name").toString());
}
if (jSONArray.length() == 0) {
QrCodeScannerDetailActivity.this.llPackages.setVisibility(8);
QrCodeScannerDetailActivity.this.packagesTitle.setVisibility(8);
}
for (int i = 0; i < jSONArray.length(); i++) {
View inflate = QrCodeScannerDetailActivity.this.getLayoutInflater().inflate(R.layout.package_item_layout, (ViewGroup) null);
JSONObject jSONObject3 = jSONArray.getJSONObject(i);
TextView textView = (TextView) inflate.findViewById(R.id.etPackages);
TextView textView2 = (TextView) inflate.findViewById(R.id.tvPackageCount);
textView.setText(jSONObject3.getString("name"));
textView2.setText(jSONObject3.getString("totalPackages"));
QrCodeScannerDetailActivity.this.llPackages.addView(inflate);
}
return;
}
QrCodeScannerDetailActivity.this.showSnackBar(jSONObject.getString("message"));
return;
} catch (JSONException unused) {
QrCodeScannerDetailActivity qrCodeScannerDetailActivity = QrCodeScannerDetailActivity.this;
qrCodeScannerDetailActivity.showSnackBar(qrCodeScannerDetailActivity.getResources().getString(R.string.somethingwentwrong));
return;
}
}
QrCodeScannerDetailActivity qrCodeScannerDetailActivity2 = QrCodeScannerDetailActivity.this;
qrCodeScannerDetailActivity2.showSnackBar(qrCodeScannerDetailActivity2.getResources().getString(R.string.internetconnectionproblem));
}
}
public void showSnackBar(String str) {
Snackbar make = Snackbar.make(this.snack, str, 0);
View view = make.getView();
view.setBackgroundColor(Color.parseColor("#D0021B"));
TextView textView = (TextView) view.findViewById(R.id.snackbar_text);
textView.setGravity(17);
textView.setTextColor(Color.parseColor("#FFFFFF"));
textView.setAllCaps(true);
make.show();
}
public String convertStreamToString(InputStream inputStream) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder();
while (true) {
try {
try {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
sb.append(readLine);
sb.append('\n');
} catch (IOException e) {
e.printStackTrace();
inputStream.close();
}
} catch (Throwable th) {
try {
inputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
throw th;
}
} catch (IOException e3) {
e3.printStackTrace();
}
}
inputStream.close();
return sb.toString();
}
public String convertISOTimeToDate(String str) {
try {
return new SimpleDateFormat("yyyy/MM/dd").format(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(str));
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
}