Skip to content

Zan2 #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Zan2 #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ public void createPDF() {





File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Test", "Test.pdf");
/*try {
// Save file address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
Expand Down Expand Up @@ -234,20 +235,26 @@ public void createPDF(String[] labels, WaterWayReport wp) {
//File naming convention: inspector _ site name _ date
String fileName = String.valueOf(wp.getH_inspector_name()) + "_" + String.valueOf(wp.getH_site_name()) + "_" + String.valueOf(wp.getH_date()) + ".pdf";

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), fileName);// + "/Test", fileName);//"Test.pdf");

File file = new File(getExternalFilesDir(null), fileName);//NEW

/*File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), fileName);// + "/Test", fileName);//"Test.pdf");
if (!file.exists()) {
Log.d("pdf", "DOESN'T EXIST");
file.getParentFile().mkdirs();
}
if (file.exists()) {
Log.d("pdf", "EXISTS NOW");
}
}*/


try {
//write pdf ot file location
file.createNewFile();//NEW
document.writeTo(new FileOutputStream(file));
Toast.makeText(WaterwayReportDetail.this, "PDF file generated succesfully.", Toast.LENGTH_SHORT).show();
//document.close();//MOVED THIS HERE
Log.d("pdf", "file name is " + String.valueOf(fileName));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -314,7 +321,16 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
canvas.drawText(labels[i], 20, currHi, title);
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
title.setColor(ContextCompat.getColor(this, R.color.gray));
canvas.drawText(String.valueOf(wp.getStringFields().get(keys[i])), 20 + title.measureText(labels[i]), currHi, title);
if (i == 3) {
canvas.drawText(String.valueOf(wp.getH_inspector_name()), 20 + title.measureText(labels[i]), currHi, title);
}
if (i == 4) {
canvas.drawText(String.valueOf(wp.getH_site_name()), 20 + title.measureText(labels[i]), currHi, title);
}
if (i == 5) {
canvas.drawText(String.valueOf(wp.getH_date()), 20 + title.measureText(labels[i]), currHi, title);
}
//canvas.drawText(String.valueOf(wp.getStringFields().get(keys[i])), 20 + title.measureText(labels[i]), currHi, title);
currHi += 16;//getHeight(title, labels[i]);
}
canvas.drawText("--------------------------------------------------------------------------------------------------------------------------------------------", 20, currHi, title);
Expand All @@ -323,6 +339,16 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
title.setColor(ContextCompat.getColor(this, R.color.black));
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(14);
//TEST HIGHLIGHT
Paint.FontMetrics fm = new Paint.FontMetrics();
title.setColor(Color.CYAN);
title.setTextSize(14.0f);
title.getFontMetrics(fm);
int margin = 1;
canvas.drawRect(20-margin, currHi + fm.top - margin,
20+title.measureText("General Outfall Data") + margin, currHi + fm.bottom + margin, title);
title.setColor(ContextCompat.getColor(this, R.color.black));
//END TEST HIGHLIGHT
canvas.drawText("General Outfall Data", 20, currHi,title);
currHi += 16;//getHeight(title, "General Outfall Data");
title.setTextSize(12);
Expand All @@ -338,6 +364,14 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
title.setColor(ContextCompat.getColor(this, R.color.black));
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(14);
//HIGHLIGHT
title.setColor(Color.CYAN);
title.setTextSize(14.0f);
title.getFontMetrics(fm);
canvas.drawRect(20-margin, currHi + fm.top - margin,
20+title.measureText("Dry Weather Screening") + margin, currHi + fm.bottom + margin, title);
title.setColor(ContextCompat.getColor(this, R.color.black));
//END HIGHLIGHT
canvas.drawText("Dry Weather Screening", 20, currHi,title);
currHi += 16;//getHeight(title, "Dry Weather Screening");
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
Expand All @@ -357,6 +391,14 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
title.setColor(ContextCompat.getColor(this, R.color.black));
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(14);
//HIGHLIGHT
title.setColor(Color.CYAN);
title.setTextSize(14.0f);
title.getFontMetrics(fm);
canvas.drawRect(20-margin, currHi + fm.top - margin,
20+title.measureText("Final Conclusion") + margin, currHi + fm.bottom + margin, title);
title.setColor(ContextCompat.getColor(this, R.color.black));
//END HIGHLIGHT
canvas.drawText("Final Conclusion", 20, currHi,title);
currHi += 16;//getHeight(title, "Final Conclusion");
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
Expand All @@ -376,6 +418,14 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
title.setColor(ContextCompat.getColor(this, R.color.black));
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(14);
//HIGHLIGHT
title.setColor(Color.CYAN);
title.setTextSize(14.0f);
title.getFontMetrics(fm);
canvas.drawRect(20-margin, currHi + fm.top - margin,
20+title.measureText("Chemical Testing (Q-Values)") + margin, currHi + fm.bottom + margin, title);
title.setColor(ContextCompat.getColor(this, R.color.black));
//END HIGHLIGHT
canvas.drawText("Chemical Testing (Q-Values)", 20, currHi,title);
currHi += 16;//getHeight(title, "Chemical Testing (Q-Values)");
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
Expand Down Expand Up @@ -404,6 +454,14 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
title.setTextSize(14);
currWi = (int)(8.5 * 72) / 2;
currHi = holdHi;
//HIGHLIGHT
title.setColor(Color.CYAN);
title.setTextSize(14.0f);
title.getFontMetrics(fm);
canvas.drawRect(currWi-margin, currHi + fm.top - margin,
currWi+title.measureText("Biological Monitoring (# of Taxa)") + margin, currHi + fm.bottom + margin, title);
title.setColor(ContextCompat.getColor(this, R.color.black));
//END HIGHLIGHT
canvas.drawText("Biological Monitoring (# of Taxa)", currWi, currHi,title);
currHi += 16;
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
Expand All @@ -421,6 +479,14 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
title.setColor(ContextCompat.getColor(this, R.color.black));
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(14);
//HIGHLIGHT
title.setColor(Color.CYAN);
title.setTextSize(14.0f);
title.getFontMetrics(fm);
canvas.drawRect(currWi-margin, currHi + fm.top - margin,
currWi+title.measureText("Habitat Quality") + margin, currHi + fm.bottom + margin, title);
title.setColor(ContextCompat.getColor(this, R.color.black));
//END HIGHLIGHT
canvas.drawText("Habitat Quality", currWi, currHi, title);
currHi += 16;
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
Expand All @@ -438,6 +504,14 @@ public void writeToCanvas(Canvas canvas, Paint title, String[] labels, WaterWayR
title.setColor(ContextCompat.getColor(this, R.color.black));
title.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
title.setTextSize(14);
//HIGHLIGHT
title.setColor(Color.CYAN);
title.setTextSize(14.0f);
title.getFontMetrics(fm);
canvas.drawRect(currWi-margin, currHi + fm.top - margin,
currWi+title.measureText("Comments") + margin, currHi + fm.bottom + margin, title);
title.setColor(ContextCompat.getColor(this, R.color.black));
//END HIGHLIGHT
canvas.drawText("Comments", currWi, currHi, title);
}

Expand Down