Skip to content

Commit

Permalink
Creation and intent complete.:
Browse files Browse the repository at this point in the history
  • Loading branch information
jainakshansh committed Feb 20, 2018
1 parent d9fafb6 commit 512c3d3
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
Expand Down Expand Up @@ -66,9 +67,10 @@ public void onClick(View v) {

document.finishPage(page);

SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyhhmmss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
String pdfName = titleInput.getText().toString() + sdf.format(Calendar.getInstance().getTime()) + ".pdf";
if (!contentInput.getText().toString().trim().isEmpty()) {
Log.d("ADebug", "Content present condition");
createFile(document, pdfName);
} else {
Toast.makeText(CreatePDFActivity.this, "Cannot save empty PDF file!", Toast.LENGTH_SHORT).show();
Expand All @@ -82,13 +84,15 @@ private void createFile(PdfDocument document, String pdfName) {
try {
File folder = new File(Environment.getExternalStorageDirectory(), "PDFReader MadHouse");
if (!folder.exists()) {
Log.d("ADebug", "Checking if folder exists");
folder.mkdirs();
}
File outputFile = new File(folder, pdfName);
outputFile.createNewFile();
fos = new FileOutputStream(outputFile);
document.writeTo(fos);
Toast.makeText(CreatePDFActivity.this, "File created successfully!", Toast.LENGTH_SHORT).show();
Log.d("ADebug", "File created successfully!");

//Opening the recently saved file.
Intent openIntent = new Intent(getApplicationContext(), ReadingActivity.class);
Expand Down

0 comments on commit 512c3d3

Please sign in to comment.