Delete Report.java
This commit is contained in:
@@ -1,302 +0,0 @@
|
||||
package com.ShanMukhaInnovations.ArrestTB;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.pdf.PdfDocument;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class Report extends AppCompatActivity {
|
||||
TextView patient_id,patient_dob,patientnikshayid,agepatient,patientgender,patientsample,validatyd,spintubeid,nirtlab,dated,timed,resultd;
|
||||
ImageButton shared ,dowbloadd;
|
||||
String string1,string2,string3,string4,string5,string6,string7,string8,string9,date,time;
|
||||
File filePath=null;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_report);
|
||||
/* super.onCreate(savedInstanceState);
|
||||
LayoutInflater inflater = (LayoutInflater) this
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View contentView = inflater.inflate(R.layout.activity_report, null, false);
|
||||
draw.addView(contentView, 0);
|
||||
*/
|
||||
|
||||
setContentView(R.layout.activity_report);
|
||||
shared=findViewById(R.id.share);
|
||||
dowbloadd=findViewById(R.id.downlaod);
|
||||
patient_id=findViewById(R.id.patient_idr);
|
||||
patient_dob=findViewById(R.id.patien_dobr);
|
||||
patientnikshayid=findViewById(R.id.patient_nikshayidr);
|
||||
agepatient=findViewById(R.id.patient_ager);
|
||||
date = String.valueOf(android.text.format.DateFormat.format("dd-MM-yyyy", new java.util.Date()));
|
||||
DateFormat df = new SimpleDateFormat("h:mm a");
|
||||
time = df.format(Calendar.getInstance().getTime());
|
||||
|
||||
patientgender=findViewById(R.id.patient_genderr);
|
||||
patientsample=findViewById(R.id.patient_typesampler);
|
||||
validatyd=findViewById(R.id.patient_tubevisibler);
|
||||
spintubeid=findViewById(R.id.patient_spintuber);
|
||||
nirtlab=findViewById(R.id.patient_nirtr);
|
||||
timed=findViewById(R.id.timer);
|
||||
resultd=findViewById(R.id.patient_resultr);
|
||||
dated=findViewById(R.id.dater);
|
||||
dated.setText(date);
|
||||
timed.setText(time);
|
||||
resultd.setText("POSITIVE");
|
||||
resultd.setTextColor(Color.RED);
|
||||
|
||||
|
||||
SharedPreferences preferences=getSharedPreferences("PhoneBook",MODE_PRIVATE);
|
||||
|
||||
string1 = preferences.getString("gender", null);
|
||||
string2 = preferences.getString("patientid", null);
|
||||
string3 = preferences.getString("patientage", null);
|
||||
string4 = preferences.getString("patientnikshayid", null);
|
||||
string5 = preferences.getString("dob", null);
|
||||
|
||||
|
||||
SharedPreferences preferences1=getSharedPreferences("PhoneBook1",MODE_PRIVATE);
|
||||
|
||||
string6 = preferences1.getString("NIRTLabde", null);
|
||||
string7 = preferences1.getString("SPINTubeIDde", null);
|
||||
string8 = preferences1.getString("sample", null);
|
||||
string9 = preferences1.getString("validity", null);
|
||||
|
||||
shared.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(ContextCompat.checkSelfPermission(Report.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
|
||||
ActivityCompat.requestPermissions(Report.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},23);
|
||||
}
|
||||
else
|
||||
{
|
||||
createPdf();
|
||||
|
||||
Intent intent=new Intent(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_TEXT,"Report");
|
||||
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N) {
|
||||
Uri path= FileProvider.getUriForFile(Report.this,"com.ShanMukhaInnovations.ArrestTB.fileprovider",filePath);
|
||||
intent.putExtra(Intent.EXTRA_STREAM,path);
|
||||
}
|
||||
else{
|
||||
|
||||
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(filePath));
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
intent.setType("application/pdf");
|
||||
startActivity(intent);
|
||||
|
||||
//startCropImageActivity();
|
||||
// createPdf(editText.getText().toString());
|
||||
|
||||
|
||||
}
|
||||
//now for sharing file i need to create file provider for android version greater than noughat let's do it
|
||||
|
||||
|
||||
//Everything WOrking
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
dowbloadd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(ContextCompat.checkSelfPermission(Report.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
|
||||
ActivityCompat.requestPermissions(Report.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},23);
|
||||
}
|
||||
else
|
||||
{
|
||||
//startCropImageActivity();
|
||||
createPdf();
|
||||
Toast.makeText(Report.this, "File Downloaded", Toast.LENGTH_LONG).show();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
patient_id.setText(string2);
|
||||
patient_dob.setText(string5);
|
||||
patientgender.setText(string1);
|
||||
patientnikshayid.setText(string4);
|
||||
patientsample.setText(string8);
|
||||
agepatient.setText(string3);
|
||||
validatyd.setText(string9);
|
||||
spintubeid.setText(string7);
|
||||
nirtlab.setText(string6);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
private void createPdf(){
|
||||
// create a new document
|
||||
PdfDocument document = new PdfDocument();
|
||||
|
||||
// crate a page description
|
||||
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(1000, 2000, 1).create();
|
||||
|
||||
// start a page
|
||||
PdfDocument.Page page = document.startPage(pageInfo);
|
||||
Canvas canvas = page.getCanvas();
|
||||
Paint paint = new Paint();
|
||||
paint.setTextSize(80);
|
||||
canvas.drawText("Arrest Tb",40,80,paint);
|
||||
paint.setTextSize(30);
|
||||
canvas.drawText("ShanMukha Innovations Pvt Ltd",30,120,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText(date,canvas.getWidth()-40,40,paint);
|
||||
canvas.drawText(time,canvas.getWidth()-40,80,paint);
|
||||
paint.setTextAlign(Paint.Align.LEFT);
|
||||
paint.setColor(Color.rgb(150,150,150));
|
||||
canvas.drawRect(30,250,canvas.getWidth()-30,300,paint);
|
||||
paint.setColor(Color.WHITE);
|
||||
canvas.drawText("Result",50,285,paint);
|
||||
// canvas.drawText("name 2",450,435,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText("POSITIVE",canvas.getWidth()-40,285,paint);
|
||||
paint.setTextAlign(Paint.Align.LEFT);
|
||||
|
||||
|
||||
paint.setColor(Color.rgb(150,150,150));
|
||||
// canvas.drawRect(30,150,canvas.getWidth()-30,160,paint);
|
||||
|
||||
|
||||
canvas.drawRect(30,400,canvas.getWidth()-30,450,paint);
|
||||
paint.setColor(Color.WHITE);
|
||||
canvas.drawText("Patient ID",50,435,paint);
|
||||
canvas.drawText("Patient Gender",450,435,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText("Date of Birth",canvas.getWidth()-40,435,paint);
|
||||
paint.setTextAlign(Paint.Align.LEFT);
|
||||
paint.setColor(Color.BLACK);
|
||||
|
||||
canvas.drawText(string2,50,480,paint);
|
||||
canvas.drawText(string1,450,480,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText(string5+".",canvas.getWidth()-40,480,paint);
|
||||
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
|
||||
paint.setColor(Color.rgb(150,150,150));
|
||||
// canvas.drawRect(30,150,canvas.getWidth()-30,160,paint);
|
||||
|
||||
// canvas.drawRect(30,550,canvas.getWidth()-30,560,paint);
|
||||
canvas.drawRect(30,570,canvas.getWidth()-30,620,paint);
|
||||
|
||||
|
||||
paint.setColor(Color.WHITE);
|
||||
canvas.drawText("Age",100,605,paint);
|
||||
canvas.drawText("Nikshay ID ",540,605,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText("NIRT Lab Number",canvas.getWidth()-40,605,paint);
|
||||
paint.setTextAlign(Paint.Align.LEFT);
|
||||
paint.setColor(Color.BLACK);
|
||||
|
||||
canvas.drawText(string3,50,650,paint);
|
||||
canvas.drawText(string4,440,650,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText(string6,canvas.getWidth()-40,650,paint);
|
||||
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
paint.setColor(Color.rgb(150,150,150));
|
||||
|
||||
canvas.drawRect(30,740,canvas.getWidth()-30,790,paint);
|
||||
|
||||
paint.setColor(Color.WHITE);
|
||||
canvas.drawText("SPIN Tube ID",220,775,paint);
|
||||
canvas.drawText("Type of Sample",540,775,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText("Tube Validity",canvas.getWidth()-40,775,paint);
|
||||
paint.setTextAlign(Paint.Align.LEFT);
|
||||
paint.setColor(Color.BLACK);
|
||||
|
||||
canvas.drawText(string7,50,820,paint);
|
||||
canvas.drawText(string8,440,820,paint);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText(string9,canvas.getWidth()-40,820,paint);
|
||||
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
paint.setColor(Color.rgb(150,150,150));
|
||||
|
||||
// finish the page
|
||||
document.finishPage(page);
|
||||
/* File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"Raman.pdf");
|
||||
|
||||
|
||||
// write the document content
|
||||
*//*String directory_path = Environment.getExternalStorageDirectory().getPath() + "/ArrestTb/";
|
||||
File file = new File(directory_path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}*//*
|
||||
// String targetPdf = directory_path+"Report_"+string2+".pdf";
|
||||
filePath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"Report_"+string2+".pdf");
|
||||
*/
|
||||
String directory_path = Environment.getExternalStorageDirectory().getPath() + "/ArrestTb/";
|
||||
File file = new File(directory_path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
String targetPdf = directory_path+"Report_"+string2+".pdf";
|
||||
filePath = new File(targetPdf);
|
||||
|
||||
try {
|
||||
document.writeTo(new FileOutputStream(filePath));
|
||||
} catch (IOException e) {
|
||||
Log.e("main", "error "+e.toString());
|
||||
}
|
||||
// filePath= new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"Report_"+string2+".pdf");
|
||||
|
||||
|
||||
// close the document
|
||||
document.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user