diff --git a/.travis.yml b/.travis.yml index 69f1e2271..287bcf822 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ android: components: - platform-tools - tools - - build-tools-27.0.3 - - android-27 + - build-tools-28.0.3 + - android-28 # Support library - extra-android-support - extra-android-m2repository diff --git a/README.md b/README.md index 256e72f39..ac2c09fe4 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,6 @@ Black | Dark | White | + [Picasso-transformations](https://github.com/wasabeef/picasso-transformations) + [PhotoEditor](https://github.com/burhanrashid52/PhotoEditor) + [viewpager-transformers](https://github.com/geftimov/android-viewpager-transformers) -+ [What's new](https://github.com/TonnyL/WhatsNew) + [zxing](https://github.com/zxing/zxing) #### Code & Issues diff --git a/app/build.gradle b/app/build.gradle index 8c12560cf..4933a1349 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,16 +2,16 @@ apply plugin: 'com.android.application' apply from: '../config/checkstyle.gradle' android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 + buildToolsVersion '28.0.3' defaultConfig { applicationId "swati4star.createpdf" vectorDrawables.useSupportLibrary = true minSdkVersion 21 multiDexEnabled true targetSdkVersion 28 - versionCode 80 - versionName "8.5.3" + versionCode 83 + versionName "8.5.6" } buildTypes { release { diff --git a/app/src/main/assets/whatsnew.json b/app/src/main/assets/whatsnew.json index 96c85f911..87bd96792 100644 --- a/app/src/main/assets/whatsnew.json +++ b/app/src/main/assets/whatsnew.json @@ -2,9 +2,9 @@ "data": [ { - "title": "Reorder PDF pages", - "content": "Fixed errors in Reorder and Remove PDF pages.", - "icon": "" + "title": "Remove duplicate pages", + "content": "New feature: remove duplicate pages from PDF.", + "icon": "ic_remove_circle_black_24dp" } ], @@ -13,6 +13,13 @@ "version_code": [ ], + "80" : [ + { + "title": "Reorder PDF pages", + "content": "Fixed errors in Reorder and Remove PDF pages.", + "icon": "" + } + ], "79" : [ { "title": "Modify Existing PDF", diff --git a/app/src/main/java/swati4star/createpdf/activity/ImageEditor.java b/app/src/main/java/swati4star/createpdf/activity/ImageEditor.java index 98cef5cec..d8cef7e02 100644 --- a/app/src/main/java/swati4star/createpdf/activity/ImageEditor.java +++ b/app/src/main/java/swati4star/createpdf/activity/ImageEditor.java @@ -38,6 +38,7 @@ import static swati4star.createpdf.util.Constants.IMAGE_EDITOR_KEY; import static swati4star.createpdf.util.Constants.RESULT; import static swati4star.createpdf.util.ImageFilterUtils.getFiltersList; +import static swati4star.createpdf.util.StringUtils.showSnackbar; public class ImageEditor extends AppCompatActivity implements OnFilterItemClickedListener, OnItemClickListner { @@ -46,9 +47,8 @@ public class ImageEditor extends AppCompatActivity implements OnFilterItemClicke private ArrayList mFilterItems; private ArrayList mBrushItems; - private int mImagesCount; private int mDisplaySize; - private int mCurrentImage = 0; + private int mCurrentImage; // 0 by default private String mFilterName; @BindView(R.id.nextimageButton) @@ -80,24 +80,31 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_photo_editor); ButterKnife.bind(this); + initValues(); + + if (getSupportActionBar() != null) { + getSupportActionBar().hide(); + } + } + + void initValues() { + // Extract images mFilterUris = getIntent().getStringArrayListExtra(IMAGE_EDITOR_KEY); mDisplaySize = mFilterUris.size(); - mImagesCount = mDisplaySize - 1; + mFilterItems = getFiltersList(this); + mBrushItems = getBrushItems(); + mImagepaths.addAll(mFilterUris); + mPhotoEditorView.getSource() .setImageBitmap(BitmapFactory.decodeFile(mFilterUris.get(0))); - - setImageCount(); - - if (mDisplaySize == 1) - mNextButton.setVisibility(View.INVISIBLE); + changeAndShowImageCount(0); initRecyclerView(); mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView) .setPinchTextScalable(true) .build(); - mPhotoEditor.setBrushSize(30); doodleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { @@ -112,30 +119,39 @@ public void onStartTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) { } }); + + mPhotoEditor.setBrushSize(30); mPhotoEditor.setBrushDrawingMode(false); - if (getSupportActionBar() != null) { - getSupportActionBar().hide(); - } } @OnClick(R.id.nextimageButton) void nextImg() { //Proceed to next if Save Current has been clicked if (mClicked) { - next(); - incrementImageCount(); + changeAndShowImageCount((mCurrentImage + 1) % mDisplaySize); } else - Toast.makeText(getApplicationContext(), R.string.save_first, Toast.LENGTH_SHORT).show(); + showSnackbar(this, R.string.save_first); } @OnClick(R.id.previousImageButton) void previousImg() { //move to previous if Save Current has been clicked if (mClicked) { - previous(); - decrementImageCount(); + changeAndShowImageCount((mCurrentImage - 1 % mDisplaySize)); } else - Toast.makeText(getApplicationContext(), R.string.save_first, Toast.LENGTH_SHORT).show(); + showSnackbar(this, R.string.save_first); + } + + // modify current image num & display in textview + private void changeAndShowImageCount(int count) { + + if (count < 0 || count >= mDisplaySize) + return; + + mCurrentImage = count % mDisplaySize; + mPhotoEditorView.getSource() + .setImageBitmap(BitmapFactory.decodeFile(mImagepaths.get(mCurrentImage))); + mImgcount.setText(String.format(getString(R.string.showing_image), mCurrentImage + 1, mDisplaySize)); } @OnClick(R.id.savecurrent) @@ -159,44 +175,6 @@ void resetCurrent() { mPhotoEditor.undo(); } - /** - * Increment image count to display in textView - */ - private void incrementImageCount() { - if (mCurrentImage < mImagesCount) { - setImageCount(); - mPreviousButton.setVisibility(View.VISIBLE); - } else if (mCurrentImage == mImagesCount) { - setImageCount(); - mNextButton.setVisibility(View.INVISIBLE); - mPreviousButton.setVisibility(View.VISIBLE); - } else { - mNextButton.setEnabled(false); - } - } - - /** - * Decrement image count to display in textView - */ - private void decrementImageCount() { - if (mCurrentImage > 0) { - setImageCount(); - mNextButton.setVisibility(View.VISIBLE); - } else if (mCurrentImage == 0) { - setImageCount(); - mPreviousButton.setVisibility(View.INVISIBLE); - mNextButton.setVisibility(View.VISIBLE); - } else { - mPreviousButton.setEnabled(false); - } - } - - /** - * Display current image count in the textview - */ - private void setImageCount() { - mImgcount.setText(String.format(getString(R.string.showing_image), mCurrentImage + 1, mDisplaySize)); - } /** * Saves Current Image with applied filter @@ -231,45 +209,12 @@ public void onFailure(@NonNull Exception exception) { } } - /** - * Display next image on nextImage button click - */ - private void next() { - try { - if (mCurrentImage + 1 <= mImagesCount) { - mPhotoEditorView.getSource() - .setImageBitmap(BitmapFactory.decodeFile(mImagepaths.get(mCurrentImage + 1))); - mCurrentImage++; - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Display Previous image on previousImage button click - */ - private void previous() { - try { - if (mCurrentImage - 1 >= 0) { - mPhotoEditorView.getSource() - .setImageBitmap(BitmapFactory.decodeFile(mImagepaths.get((mCurrentImage - 1)))); - mCurrentImage--; - } - } catch (Exception e) { - e.printStackTrace(); - } - } /** * Initialize Recycler View */ private void initRecyclerView() { - mFilterItems = getFiltersList(this); - mBrushItems = getBrushItems(); - mImagepaths.addAll(mFilterUris); - LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); RecyclerView recyclerView = findViewById(R.id.recyclerView); recyclerView.setLayoutManager(layoutManager); @@ -305,8 +250,7 @@ public void onItemClick(View view, int position) { hideBrushEffect(); } } else { - PhotoFilter filter = mFilterItems.get(position).getFilter(); - applyFilter(filter); + applyFilter(mFilterItems.get(position).getFilter()); } } diff --git a/app/src/main/java/swati4star/createpdf/activity/MainActivity.java b/app/src/main/java/swati4star/createpdf/activity/MainActivity.java index 1e6eac961..c4c6252f9 100644 --- a/app/src/main/java/swati4star/createpdf/activity/MainActivity.java +++ b/app/src/main/java/swati4star/createpdf/activity/MainActivity.java @@ -28,7 +28,6 @@ import swati4star.createpdf.R; import swati4star.createpdf.fragment.AboutUsFragment; import swati4star.createpdf.fragment.AddImagesFragment; -import swati4star.createpdf.fragment.ExtractImagesFragment; import swati4star.createpdf.fragment.HistoryFragment; import swati4star.createpdf.fragment.HomeFragment; import swati4star.createpdf.fragment.ImageToPdfFragment; @@ -53,9 +52,11 @@ import static swati4star.createpdf.util.Constants.ADD_PWD; import static swati4star.createpdf.util.Constants.BUNDLE_DATA; import static swati4star.createpdf.util.Constants.COMPRESS_PDF; +import static swati4star.createpdf.util.Constants.EXTRACT_IMAGES; import static swati4star.createpdf.util.Constants.IS_WELCOME_ACTIVITY_SHOWN; import static swati4star.createpdf.util.Constants.LAUNCH_COUNT; import static swati4star.createpdf.util.Constants.OPEN_SELECT_IMAGES; +import static swati4star.createpdf.util.Constants.PDF_TO_IMAGES; import static swati4star.createpdf.util.Constants.REMOVE_PAGES; import static swati4star.createpdf.util.Constants.REMOVE_PWd; import static swati4star.createpdf.util.Constants.REORDER_PAGES; @@ -341,10 +342,14 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { fragment = new SettingsFragment(); break; case R.id.nav_extract_images: - fragment = new ExtractImagesFragment(); + fragment = new PdfToImageFragment(); + bundle.putString(BUNDLE_DATA, EXTRACT_IMAGES); + fragment.setArguments(bundle); break; case R.id.nav_pdf_to_images: fragment = new PdfToImageFragment(); + bundle.putString(BUNDLE_DATA, PDF_TO_IMAGES); + fragment.setArguments(bundle); break; case R.id.nav_remove_pages: fragment = new RemovePagesFragment(); diff --git a/app/src/main/java/swati4star/createpdf/activity/PreviewActivity.java b/app/src/main/java/swati4star/createpdf/activity/PreviewActivity.java index 7c17e81f2..f5c9eb661 100644 --- a/app/src/main/java/swati4star/createpdf/activity/PreviewActivity.java +++ b/app/src/main/java/swati4star/createpdf/activity/PreviewActivity.java @@ -72,6 +72,7 @@ private void showOptions() { /** * Returns a list of options for preview activity + * * @return - list */ private ArrayList getOptions() { @@ -123,17 +124,18 @@ private void passUris() { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); + + if (resultCode != RESULT_OK) + return; + switch (requestCode) { case INTENT_REQUEST_REARRANGE_IMAGE: - switch (resultCode) { - case Activity.RESULT_OK: - try { - mImagesArrayList = data.getStringArrayListExtra(Constants.RESULT); - mPreviewAdapter.setData(mImagesArrayList); - mViewPager.setAdapter(mPreviewAdapter); - } catch (Exception e) { - e.printStackTrace(); - } + try { + mImagesArrayList = data.getStringArrayListExtra(Constants.RESULT); + mPreviewAdapter.setData(mImagesArrayList); + mViewPager.setAdapter(mPreviewAdapter); + } catch (Exception e) { + e.printStackTrace(); } break; } @@ -144,7 +146,7 @@ public void onBackPressed() { passUris(); } - public static Intent getStartIntent(Context context, ArrayList uris) { + public static Intent getStartIntent(Context context, ArrayList uris) { Intent intent = new Intent(context, PreviewActivity.class); intent.putExtra(PREVIEW_IMAGES, uris); return intent; diff --git a/app/src/main/java/swati4star/createpdf/activity/WelcomeActivity.java b/app/src/main/java/swati4star/createpdf/activity/WelcomeActivity.java index c23bfeb03..e55c285ca 100644 --- a/app/src/main/java/swati4star/createpdf/activity/WelcomeActivity.java +++ b/app/src/main/java/swati4star/createpdf/activity/WelcomeActivity.java @@ -29,7 +29,6 @@ public class WelcomeActivity extends AppCompatActivity { public Button mBtnSkip; private int[] mLayouts; - private long mBackPressed; @Override protected void onCreate(Bundle savedInstanceState) { @@ -84,7 +83,7 @@ private void addBottomDots(int currentPage) { } // viewpager change listener - ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { + final ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { diff --git a/app/src/main/java/swati4star/createpdf/adapter/FilesListAdapter.java b/app/src/main/java/swati4star/createpdf/adapter/FilesListAdapter.java index dcf90ff11..fdb64d352 100644 --- a/app/src/main/java/swati4star/createpdf/adapter/FilesListAdapter.java +++ b/app/src/main/java/swati4star/createpdf/adapter/FilesListAdapter.java @@ -41,7 +41,7 @@ public ViewMergeFilesHolder onCreateViewHolder(@NonNull ViewGroup parent, int vi @Override public void onBindViewHolder(@NonNull ViewMergeFilesHolder holder, int position) { - holder.mFileName.setText(mFileUtils.getFileName(mFilePaths.get(position))); + holder.mFileName.setText(FileUtils.getFileName(mFilePaths.get(position))); holder.mEncryptionImage.setVisibility(View.GONE); } diff --git a/app/src/main/java/swati4star/createpdf/adapter/MergeFilesAdapter.java b/app/src/main/java/swati4star/createpdf/adapter/MergeFilesAdapter.java index 2469f6260..e1ce5fcfa 100644 --- a/app/src/main/java/swati4star/createpdf/adapter/MergeFilesAdapter.java +++ b/app/src/main/java/swati4star/createpdf/adapter/MergeFilesAdapter.java @@ -49,7 +49,7 @@ public ViewMergeFilesHolder onCreateViewHolder(@NonNull ViewGroup parent, int vi @Override public void onBindViewHolder(@NonNull ViewMergeFilesHolder holder, int position) { boolean isEncrypted = mPDFUtils.isPDFEncrypted(mFilePaths.get(position)); - holder.mFileName.setText(mFileUtils.getFileName(mFilePaths.get(position))); + holder.mFileName.setText(FileUtils.getFileName(mFilePaths.get(position))); holder.mEncryptionImage.setVisibility(isEncrypted ? View.VISIBLE : View.INVISIBLE); } diff --git a/app/src/main/java/swati4star/createpdf/adapter/MergeSelectedFilesAdapter.java b/app/src/main/java/swati4star/createpdf/adapter/MergeSelectedFilesAdapter.java index 9bf41fe43..cb166136f 100644 --- a/app/src/main/java/swati4star/createpdf/adapter/MergeSelectedFilesAdapter.java +++ b/app/src/main/java/swati4star/createpdf/adapter/MergeSelectedFilesAdapter.java @@ -42,7 +42,7 @@ public MergeSelectedFilesHolder onCreateViewHolder(@NonNull ViewGroup parent, in @Override public void onBindViewHolder(@NonNull MergeSelectedFilesHolder holder, int position) { - holder.mFileName.setText(mFileUtils.getFileName(mFilePaths.get(position))); + holder.mFileName.setText(FileUtils.getFileName(mFilePaths.get(position))); } @Override diff --git a/app/src/main/java/swati4star/createpdf/adapter/ViewFilesAdapter.java b/app/src/main/java/swati4star/createpdf/adapter/ViewFilesAdapter.java index 641ca1cd5..206d56b5f 100644 --- a/app/src/main/java/swati4star/createpdf/adapter/ViewFilesAdapter.java +++ b/app/src/main/java/swati4star/createpdf/adapter/ViewFilesAdapter.java @@ -32,6 +32,7 @@ import swati4star.createpdf.util.PDFEncryptionUtility; import swati4star.createpdf.util.PDFUtils; import swati4star.createpdf.util.PopulateList; +import swati4star.createpdf.util.WatermarkUtils; import static swati4star.createpdf.util.Constants.SORTING_INDEX; import static swati4star.createpdf.util.DialogUtils.createOverwriteDialog; @@ -58,6 +59,7 @@ public class ViewFilesAdapter extends RecyclerView.Adapter mImagesUri = new ArrayList<>(); - private Uri mUri; @BindView(R.id.lottie_progress) LottieAnimationView mLottieProgress; @@ -152,7 +149,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { mMorphButtonUtility.morphToSquare(mCreatePdf, mMorphButtonUtility.integer()); break; case INTENT_REQUEST_PICKFILE_CODE: - mUri = data.getData(); setTextAndActivateButtons(getFilePath(data.getData())); break; } @@ -219,11 +215,11 @@ private void resetValues() { */ @OnClick(R.id.addImages) void startAddingImages() { - if (getRuntimePermissions(true)) + if (getRuntimePermissions()) selectImages(); } - private boolean getRuntimePermissions(boolean openImagesActivity) { + private boolean getRuntimePermissions() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if ((ContextCompat.checkSelfPermission(mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) || @@ -280,18 +276,6 @@ private void setTextAndActivateButtons(String path) { @Override public void onPopulate(ArrayList paths) { - if (paths == null || paths.size() == 0) { - mLayout.setVisibility(View.GONE); - } else { - // Init recycler view - mRecyclerViewFiles.setVisibility(View.VISIBLE); - MergeFilesAdapter mergeFilesAdapter = new MergeFilesAdapter(mActivity, - paths, false, this); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); - mRecyclerViewFiles.setLayoutManager(mLayoutManager); - mRecyclerViewFiles.setAdapter(mergeFilesAdapter); - mRecyclerViewFiles.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); - } - mLottieProgress.setVisibility(View.GONE); + populateUtil(mActivity, paths, this, mLayout, mLottieProgress, mRecyclerViewFiles); } } diff --git a/app/src/main/java/swati4star/createpdf/fragment/ExtractImagesFragment.java b/app/src/main/java/swati4star/createpdf/fragment/ExtractImagesFragment.java deleted file mode 100644 index a4f69d436..000000000 --- a/app/src/main/java/swati4star/createpdf/fragment/ExtractImagesFragment.java +++ /dev/null @@ -1,217 +0,0 @@ -package swati4star.createpdf.fragment; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.BottomSheetBehavior; -import android.support.v4.app.Fragment; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import com.afollestad.materialdialogs.MaterialDialog; -import com.airbnb.lottie.LottieAnimationView; -import com.dd.morphingbutton.MorphingButton; - -import java.io.File; -import java.util.ArrayList; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import swati4star.createpdf.R; -import swati4star.createpdf.activity.ImagesPreviewActivity; -import swati4star.createpdf.adapter.ExtractImagesAdapter; -import swati4star.createpdf.adapter.MergeFilesAdapter; -import swati4star.createpdf.interfaces.BottomSheetPopulate; -import swati4star.createpdf.interfaces.ExtractImagesListener; -import swati4star.createpdf.util.BottomSheetCallback; -import swati4star.createpdf.util.BottomSheetUtils; -import swati4star.createpdf.util.ExtractImages; -import swati4star.createpdf.util.FileUtils; -import swati4star.createpdf.util.MorphButtonUtility; -import swati4star.createpdf.util.ViewFilesDividerItemDecoration; - -import static android.app.Activity.RESULT_OK; -import static swati4star.createpdf.util.DialogUtils.createAnimationDialog; -import static swati4star.createpdf.util.FileUriUtils.getFilePath; -import static swati4star.createpdf.util.StringUtils.showSnackbar; - -public class ExtractImagesFragment extends Fragment implements MergeFilesAdapter.OnClickListener, - ExtractImagesAdapter.OnFileItemClickedListener, ExtractImagesListener, BottomSheetPopulate { - - private Activity mActivity; - private String mPath; - private MorphButtonUtility mMorphButtonUtility; - private FileUtils mFileUtils; - private BottomSheetUtils mBottomSheetUtils; - private static final int INTENT_REQUEST_PICKFILE_CODE = 10; - private ArrayList mOutFilePaths; - private MaterialDialog mMaterialDialog; - - @BindView(R.id.lottie_progress) - LottieAnimationView mLottieProgress; - @BindView(R.id.selectFile) - MorphingButton selectFileButton; - @BindView(R.id.extractImages) - MorphingButton extractImagesButton; - BottomSheetBehavior sheetBehavior; - @BindView(R.id.bottom_sheet) - LinearLayout layoutBottomSheet; - @BindView(R.id.upArrow) - ImageView mUpArrow; - @BindView(R.id.downArrow) - ImageView mDownArrow; - @BindView(R.id.layout) - RelativeLayout mLayout; - @BindView(R.id.recyclerViewFiles) - RecyclerView mRecyclerViewFiles; - @BindView(R.id.extracted_files) - RecyclerView mExtractedFiles; - @BindView(R.id.extractedimages_text) - TextView extractImagesSuccessText; - @BindView(R.id.options) - LinearLayout options; - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootview = inflater.inflate(R.layout.fragment_extract_images, container, false); - ButterKnife.bind(this, rootview); - sheetBehavior = BottomSheetBehavior.from(layoutBottomSheet); - sheetBehavior.setBottomSheetCallback(new BottomSheetCallback(mUpArrow, isAdded())); - mLottieProgress.setVisibility(View.VISIBLE); - mBottomSheetUtils.populateBottomSheetWithPDFs(this); - resetView(); - return rootview; - } - - @OnClick(R.id.share_files) - void onShareFilesClick(View view) { - if (mOutFilePaths != null) { - ArrayList fileArrayList = new ArrayList<>(); - for (String path : mOutFilePaths) { - fileArrayList.add(new File(path)); - } - mFileUtils.shareMultipleFiles(fileArrayList); - } - } - - @OnClick(R.id.viewFiles) - void onViewFilesClick(View view) { - mBottomSheetUtils.showHideSheet(sheetBehavior); - } - - @OnClick(R.id.view_images) - void onViewImagesClicked(View view) { - mActivity.startActivity(ImagesPreviewActivity.getStartIntent(mActivity, mOutFilePaths)); - } - - @OnClick(R.id.selectFile) - public void showFileChooser() { - startActivityForResult(mFileUtils.getFileChooser(), - INTENT_REQUEST_PICKFILE_CODE); - } - - public void onActivityResult(int requestCode, int resultCode, Intent data) throws NullPointerException { - if (data == null || resultCode != RESULT_OK || data.getData() == null) - return; - if (requestCode == INTENT_REQUEST_PICKFILE_CODE) - setTextAndActivateButtons(getFilePath(data.getData())); - } - - @OnClick(R.id.extractImages) - public void parse() { - new ExtractImages(mPath, this).execute(); - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); - mActivity = (Activity) context; - mMorphButtonUtility = new MorphButtonUtility(mActivity); - mFileUtils = new FileUtils(mActivity); - mBottomSheetUtils = new BottomSheetUtils(mActivity); - } - - @Override - public void onItemClick(String path) { - sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); - setTextAndActivateButtons(path); - } - - private void setTextAndActivateButtons(String path) { - mExtractedFiles.setVisibility(View.GONE); - options.setVisibility(View.GONE); - extractImagesSuccessText.setVisibility(View.GONE); - mPath = path; - mMorphButtonUtility.setTextAndActivateButtons(path, - selectFileButton, extractImagesButton); - } - - @Override - public void onFileItemClick(String path) { - mFileUtils.openImage(path); - } - - @Override - public void resetView() { - mPath = null; - mMorphButtonUtility.initializeButton(selectFileButton, extractImagesButton); - } - - @Override - public void extractionStarted() { - mMaterialDialog = createAnimationDialog(mActivity); - mMaterialDialog.show(); - } - - @Override - public void updateView(int imagecount, ArrayList outputFilePaths) { - - mMaterialDialog.dismiss(); - resetView(); - if (imagecount == 0) { - showSnackbar(mActivity, R.string.extract_images_failed); - return; - } - - String text = String.format(mActivity.getString(R.string.extract_images_success), imagecount); - showSnackbar(mActivity, text); - extractImagesSuccessText.setVisibility(View.VISIBLE); - options.setVisibility(View.VISIBLE); - mOutFilePaths = outputFilePaths; - ExtractImagesAdapter extractImagesAdapter = new ExtractImagesAdapter(mActivity, outputFilePaths, this); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); - extractImagesSuccessText.setText(text); - mExtractedFiles.setVisibility(View.VISIBLE); - mExtractedFiles.setLayoutManager(mLayoutManager); - mExtractedFiles.setAdapter(extractImagesAdapter); - mExtractedFiles.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); - } - - @Override - public void onPopulate(ArrayList paths) { - if (paths == null || paths.size() == 0) { - mLayout.setVisibility(View.GONE); - } else { - // Init recycler view - mRecyclerViewFiles.setVisibility(View.VISIBLE); - MergeFilesAdapter mergeFilesAdapter = new MergeFilesAdapter(mActivity, - paths, false, this); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); - mRecyclerViewFiles.setLayoutManager(mLayoutManager); - mRecyclerViewFiles.setAdapter(mergeFilesAdapter); - mRecyclerViewFiles.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); - } - mLottieProgress.setVisibility(View.GONE); - } -} diff --git a/app/src/main/java/swati4star/createpdf/fragment/HomeFragment.java b/app/src/main/java/swati4star/createpdf/fragment/HomeFragment.java index dd0965445..79e0e5c37 100644 --- a/app/src/main/java/swati4star/createpdf/fragment/HomeFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/HomeFragment.java @@ -10,6 +10,8 @@ import android.view.View; import android.view.ViewGroup; +import java.util.HashMap; + import butterknife.BindView; import butterknife.ButterKnife; import swati4star.createpdf.R; @@ -20,6 +22,8 @@ import static swati4star.createpdf.util.Constants.ADD_PWD; import static swati4star.createpdf.util.Constants.BUNDLE_DATA; import static swati4star.createpdf.util.Constants.COMPRESS_PDF; +import static swati4star.createpdf.util.Constants.EXTRACT_IMAGES; +import static swati4star.createpdf.util.Constants.PDF_TO_IMAGES; import static swati4star.createpdf.util.Constants.REMOVE_PAGES; import static swati4star.createpdf.util.Constants.REMOVE_PWd; import static swati4star.createpdf.util.Constants.REORDER_PAGES; @@ -65,11 +69,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener { MyCardView addImages; @BindView(R.id.remove_duplicates_pages_pdf) MyCardView removeDuplicatePages; + + + private HashMap mFragmentPositionMap; + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootview = inflater.inflate(R.layout.fragment_home, container, false); ButterKnife.bind(this, rootview); + fillMap(); imagesToPdf.setOnClickListener(this); qrbarcodeToPdf.setOnClickListener(this); textToPdf.setOnClickListener(this); @@ -91,6 +100,28 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, return rootview; } + private void fillMap() { + mFragmentPositionMap = new HashMap<>(); + mFragmentPositionMap.put(R.id.images_to_pdf, 1); + mFragmentPositionMap.put(R.id.qr_barcode_to_pdf, 2); + mFragmentPositionMap.put(R.id.view_files, 3); + mFragmentPositionMap.put(R.id.rotate_pages, 3); + mFragmentPositionMap.put(R.id.add_watermark, 3); + mFragmentPositionMap.put(R.id.merge_pdf, 4); + mFragmentPositionMap.put(R.id.split_pdf, 5); + mFragmentPositionMap.put(R.id.text_to_pdf, 6); + mFragmentPositionMap.put(R.id.compress_pdf, 7); + mFragmentPositionMap.put(R.id.remove_pages, 8); + mFragmentPositionMap.put(R.id.rearrange_pages, 9); + mFragmentPositionMap.put(R.id.extract_images, 10); + mFragmentPositionMap.put(R.id.view_history, 11); + mFragmentPositionMap.put(R.id.pdf_to_images, 11); + mFragmentPositionMap.put(R.id.add_password, 12); + mFragmentPositionMap.put(R.id.remove_password, 13); + mFragmentPositionMap.put(R.id.add_images, 14); + mFragmentPositionMap.put(R.id.remove_duplicates_pages_pdf, 15); + } + @Override public void onAttach(Context context) { super.onAttach(context); @@ -108,95 +139,82 @@ public void onClick(View v) { Fragment fragment = null; FragmentManager fragmentManager = getFragmentManager(); Bundle bundle = new Bundle(); + highLightNavigationDrawerItem(v); switch (v.getId()) { case R.id.images_to_pdf: fragment = new ImageToPdfFragment(); - setNavigationViewSelection(1); break; case R.id.qr_barcode_to_pdf: fragment = new QrBarcodeScanFragment(); - setNavigationViewSelection(2); break; case R.id.text_to_pdf: fragment = new TextToPdfFragment(); - setNavigationViewSelection(6); break; case R.id.view_files: fragment = new ViewFilesFragment(); - setNavigationViewSelection(3); break; case R.id.view_history: fragment = new HistoryFragment(); - setNavigationViewSelection(11); break; case R.id.merge_pdf: fragment = new MergeFilesFragment(); - setNavigationViewSelection(4); break; case R.id.split_pdf: fragment = new SplitFilesFragment(); - setNavigationViewSelection(5); break; case R.id.compress_pdf: fragment = new RemovePagesFragment(); bundle.putString(BUNDLE_DATA, COMPRESS_PDF); fragment.setArguments(bundle); - setNavigationViewSelection(7); break; case R.id.extract_images: - fragment = new ExtractImagesFragment(); - setNavigationViewSelection(10); + fragment = new PdfToImageFragment(); + bundle.putString(BUNDLE_DATA, EXTRACT_IMAGES); + fragment.setArguments(bundle); break; case R.id.pdf_to_images: fragment = new PdfToImageFragment(); - setNavigationViewSelection(11); + bundle.putString(BUNDLE_DATA, PDF_TO_IMAGES); + fragment.setArguments(bundle); break; case R.id.remove_pages: fragment = new RemovePagesFragment(); bundle.putString(BUNDLE_DATA, REMOVE_PAGES); fragment.setArguments(bundle); - setNavigationViewSelection(8); break; case R.id.rearrange_pages: fragment = new RemovePagesFragment(); bundle.putString(BUNDLE_DATA, REORDER_PAGES); fragment.setArguments(bundle); - setNavigationViewSelection(9); break; case R.id.add_password: fragment = new RemovePagesFragment(); bundle.putString(BUNDLE_DATA, ADD_PWD); fragment.setArguments(bundle); - setNavigationViewSelection(12); break; case R.id.remove_password: fragment = new RemovePagesFragment(); bundle.putString(BUNDLE_DATA, REMOVE_PWd); fragment.setArguments(bundle); - setNavigationViewSelection(13); break; case R.id.rotate_pages: fragment = new ViewFilesFragment(); bundle.putInt(BUNDLE_DATA, ROTATE_PAGES); fragment.setArguments(bundle); - setNavigationViewSelection(3); break; case R.id.add_watermark: fragment = new ViewFilesFragment(); bundle.putInt(BUNDLE_DATA, ADD_WATERMARK); fragment.setArguments(bundle); - setNavigationViewSelection(3); break; case R.id.add_images: fragment = new AddImagesFragment(); bundle.putString(BUNDLE_DATA, ADD_IMAGES); fragment.setArguments(bundle); - setNavigationViewSelection(3); break; case R.id.remove_duplicates_pages_pdf: fragment = new RemoveDuplicatePagesFragment(); - setNavigationViewSelection(12); break; } @@ -207,4 +225,11 @@ public void onClick(View v) { e.printStackTrace(); } } + + + private void highLightNavigationDrawerItem(View v) { + if (mFragmentPositionMap.containsKey(v.getId())) { + setNavigationViewSelection(mFragmentPositionMap.get(v.getId())); + } + } } diff --git a/app/src/main/java/swati4star/createpdf/fragment/ImageToPdfFragment.java b/app/src/main/java/swati4star/createpdf/fragment/ImageToPdfFragment.java index f07c255f0..2e584de9b 100755 --- a/app/src/main/java/swati4star/createpdf/fragment/ImageToPdfFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/ImageToPdfFragment.java @@ -73,7 +73,6 @@ import swati4star.createpdf.util.CreatePdf; import swati4star.createpdf.util.FileUtils; import swati4star.createpdf.util.MorphButtonUtility; -import swati4star.createpdf.util.PDFUtils; import swati4star.createpdf.util.PageSizeUtils; import swati4star.createpdf.util.StringUtils; @@ -101,6 +100,8 @@ import static swati4star.createpdf.util.StringUtils.getDefaultStorageLocation; import static swati4star.createpdf.util.StringUtils.getSnackbarwithAction; import static swati4star.createpdf.util.StringUtils.showSnackbar; +import static swati4star.createpdf.util.WatermarkUtils.getStyleNameFromFont; +import static swati4star.createpdf.util.WatermarkUtils.getStyleValueFromName; /** * ImageToPdfFragment fragment to start with creating PDF @@ -600,7 +601,7 @@ private void addWatermark() { )); fontFamilyInput.setSelection(fontFamilyAdapter.getPosition(mPdfOptions.getWatermark().getFontFamily())); styleInput.setSelection(styleAdapter.getPosition( - PDFUtils.getStyleNameFromFont(mPdfOptions.getWatermark().getFontStyle()))); + getStyleNameFromFont(mPdfOptions.getWatermark().getFontStyle()))); } else { angleInput.setText("0"); fontSizeInput.setText("50"); @@ -640,7 +641,7 @@ public void afterTextChanged(Editable input) { positiveAction.setOnClickListener(v -> { watermark.setWatermarkText(watermarkTextInput.getText().toString()); watermark.setFontFamily(((Font.FontFamily) fontFamilyInput.getSelectedItem())); - watermark.setFontStyle(PDFUtils.getStyleValueFromName(((String) styleInput.getSelectedItem()))); + watermark.setFontStyle(getStyleValueFromName(((String) styleInput.getSelectedItem()))); if (StringUtils.isEmpty(angleInput.getText())) { watermark.setRotationAngle(0); @@ -669,6 +670,7 @@ public void afterTextChanged(Editable input) { dialog.show(); } + @Override public void onPDFCreationStarted() { mMaterialDialog = createAnimationDialog(mActivity); diff --git a/app/src/main/java/swati4star/createpdf/fragment/PdfToImageFragment.java b/app/src/main/java/swati4star/createpdf/fragment/PdfToImageFragment.java index 5a97ee1a9..db1224863 100644 --- a/app/src/main/java/swati4star/createpdf/fragment/PdfToImageFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/PdfToImageFragment.java @@ -9,7 +9,6 @@ import android.support.annotation.NonNull; import android.support.design.widget.BottomSheetBehavior; import android.support.v4.app.Fragment; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -37,15 +36,18 @@ import swati4star.createpdf.interfaces.ExtractImagesListener; import swati4star.createpdf.util.BottomSheetCallback; import swati4star.createpdf.util.BottomSheetUtils; +import swati4star.createpdf.util.CommonCodeUtils; +import swati4star.createpdf.util.ExtractImages; import swati4star.createpdf.util.FileUtils; import swati4star.createpdf.util.MorphButtonUtility; import swati4star.createpdf.util.PdfToImages; -import swati4star.createpdf.util.ViewFilesDividerItemDecoration; import static android.app.Activity.RESULT_OK; +import static swati4star.createpdf.util.CommonCodeUtils.populateUtil; +import static swati4star.createpdf.util.Constants.BUNDLE_DATA; +import static swati4star.createpdf.util.Constants.PDF_TO_IMAGES; import static swati4star.createpdf.util.DialogUtils.createAnimationDialog; import static swati4star.createpdf.util.FileUriUtils.getFilePath; -import static swati4star.createpdf.util.StringUtils.showSnackbar; public class PdfToImageFragment extends Fragment implements BottomSheetPopulate, MergeFilesAdapter.OnClickListener, ExtractImagesListener, ExtractImagesAdapter.OnFileItemClickedListener { @@ -60,6 +62,7 @@ public class PdfToImageFragment extends Fragment implements BottomSheetPopulate, private BottomSheetUtils mBottomSheetUtils; private ArrayList mOutputFilePaths; private MaterialDialog mMaterialDialog; + private String mOperation; @BindView(R.id.lottie_progress) LottieAnimationView mLottieProgress; @@ -94,6 +97,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_pdf_to_image, container, false); ButterKnife.bind(this, rootView); + mOperation = getArguments().getString(BUNDLE_DATA); mSheetBehavior = BottomSheetBehavior.from(mLayoutBottomSheet); mSheetBehavior.setBottomSheetCallback(new BottomSheetCallback(mUpArrow, isAdded())); mLottieProgress.setVisibility(View.VISIBLE); @@ -159,7 +163,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) throw */ @OnClick(R.id.createImages) public void parse() { - new PdfToImages(mPath, mUri, this).execute(); + if (mOperation.equals(PDF_TO_IMAGES)) + new PdfToImages(mPath, mUri, this).execute(); + else + new ExtractImages(mPath, this).execute(); } @Override @@ -232,25 +239,10 @@ public void updateView(int imageCount, ArrayList outputFilePaths) { mMaterialDialog.dismiss(); resetView(); - if (imageCount == 0) { - showSnackbar(mActivity, R.string.extract_images_failed); - return; - } - - String text = String.format(mActivity.getString(R.string.extract_images_success), imageCount); - showSnackbar(mActivity, text); - mCreateImagesSuccessText.setVisibility(View.VISIBLE); - options.setVisibility(View.VISIBLE); mOutputFilePaths = outputFilePaths; - ExtractImagesAdapter extractImagesAdapter = new ExtractImagesAdapter(mActivity, outputFilePaths, this); - // init recycler view for displaying generated image list - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); - mCreateImagesSuccessText.setText(text); - mCreatedImages.setVisibility(View.VISIBLE); - mCreatedImages.setLayoutManager(mLayoutManager); - // set up adapter - mCreatedImages.setAdapter(extractImagesAdapter); - mCreatedImages.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); + + CommonCodeUtils.updateView(mActivity, imageCount, outputFilePaths, + mCreateImagesSuccessText, options, mCreatedImages, this); } /** @@ -259,18 +251,6 @@ public void updateView(int imageCount, ArrayList outputFilePaths) { */ @Override public void onPopulate(ArrayList paths) { - if (paths == null || paths.size() == 0) { - mLayout.setVisibility(View.GONE); - } else { - // init recycler view for bottom sheet - mRecyclerViewFiles.setVisibility(View.VISIBLE); - MergeFilesAdapter mergeFilesAdapter = new MergeFilesAdapter(mActivity, paths, false, this); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); - mRecyclerViewFiles.setLayoutManager(mLayoutManager); - // set up adapter - mRecyclerViewFiles.setAdapter(mergeFilesAdapter); - mRecyclerViewFiles.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); - } - mLottieProgress.setVisibility(View.GONE); + populateUtil(mActivity, paths, this, mLayout, mLottieProgress, mRecyclerViewFiles); } } diff --git a/app/src/main/java/swati4star/createpdf/fragment/QrBarcodeScanFragment.java b/app/src/main/java/swati4star/createpdf/fragment/QrBarcodeScanFragment.java index f4cf09c65..a1736f203 100644 --- a/app/src/main/java/swati4star/createpdf/fragment/QrBarcodeScanFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/QrBarcodeScanFragment.java @@ -86,7 +86,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, scanBarcode.setOnClickListener(this); mFontFamily = Font.FontFamily.valueOf(mSharedPreferences.getString(Constants.DEFAULT_FONT_FAMILY_TEXT, Constants.DEFAULT_FONT_FAMILY)); - PageSizeUtils.mPageSize = mSharedPreferences.getString(Constants.DEFAULT_PAGE_SIZE_TEXT , + PageSizeUtils.mPageSize = mSharedPreferences.getString(Constants.DEFAULT_PAGE_SIZE_TEXT, Constants.DEFAULT_PAGE_SIZE); getRuntimePermissions(); @@ -97,26 +97,24 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); - if (result != null) { - if (result.getContents() == null) { - showSnackbar(mActivity, R.string.scan_cancelled); - } else { - Toast.makeText(mActivity, "Scan Result: " + result.getContents(), Toast.LENGTH_SHORT).show(); + if (result == null || result.getContents() == null) + showSnackbar(mActivity, R.string.scan_cancelled); + else { + Toast.makeText(mActivity, " " + result.getContents(), Toast.LENGTH_SHORT).show(); - File mDir = mActivity.getCacheDir(); - File mTempFile = new File(mDir.getPath() + "/" + mTempFileName); - PrintWriter mWriter; - try { - mWriter = new PrintWriter(mTempFile); - mWriter.print(""); - mWriter.append(result.getContents()); - mWriter.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - Uri uri = Uri.fromFile(mTempFile); - resultToTextPdf(uri); + File mDir = mActivity.getCacheDir(); + File mTempFile = new File(mDir.getPath() + "/" + mTempFileName); + PrintWriter mWriter; + try { + mWriter = new PrintWriter(mTempFile); + mWriter.print(""); + mWriter.append(result.getContents()); + mWriter.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); } + Uri uri = Uri.fromFile(mTempFile); + resultToTextPdf(uri); } } @@ -134,8 +132,9 @@ public void onClick(View v) { /** * Open scanner + * * @param scannerType - type (qr code/bar code) - * @param promptId - string resource id for prompt + * @param promptId - string resource id for prompt */ public void openScanner(Collection scannerType, int promptId) { IntentIntegrator integrator = IntentIntegrator.forSupportFragment(this); @@ -148,6 +147,7 @@ public void openScanner(Collection scannerType, int promptId) { /** * Generate Result to PDF + * * @param uri - uri where text is located */ private void resultToTextPdf(Uri uri) { @@ -176,7 +176,7 @@ private void resultToTextPdf(Uri uri) { * function to create PDF * * @param mFilename name of file to be created. - * @param uri - uri where text is located + * @param uri - uri where text is located */ private void createPdf(String mFilename, Uri uri) { mPath = mSharedPreferences.getString(STORAGE_LOCATION, diff --git a/app/src/main/java/swati4star/createpdf/fragment/RemoveDuplicatePagesFragment.java b/app/src/main/java/swati4star/createpdf/fragment/RemoveDuplicatePagesFragment.java index e407ce66e..38b500e56 100644 --- a/app/src/main/java/swati4star/createpdf/fragment/RemoveDuplicatePagesFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/RemoveDuplicatePagesFragment.java @@ -36,7 +36,6 @@ import swati4star.createpdf.util.BottomSheetUtils; import swati4star.createpdf.util.FileUtils; import swati4star.createpdf.util.MorphButtonUtility; -import swati4star.createpdf.util.PDFUtils; import swati4star.createpdf.util.RemoveDuplicates; import swati4star.createpdf.util.ViewFilesDividerItemDecoration; @@ -53,7 +52,6 @@ public class RemoveDuplicatePagesFragment extends Fragment implements MergeFiles private String mPath; private MorphButtonUtility mMorphButtonUtility; private FileUtils mFileUtils; - private PDFUtils mPDFUtils; private BottomSheetUtils mBottomSheetUtils; private static final int INTENT_REQUEST_PICKFILE_CODE = 10; private MaterialDialog mMaterialDialog; @@ -152,7 +150,6 @@ public void onAttach(Context context) { mActivity = (Activity) context; mMorphButtonUtility = new MorphButtonUtility(mActivity); mFileUtils = new FileUtils(mActivity); - mPDFUtils = new PDFUtils(mActivity); mBottomSheetUtils = new BottomSheetUtils(mActivity); } @@ -169,12 +166,7 @@ public void onFileItemClick(String path) { private void viewPdfButton(String path) { mViewPdf.setVisibility(View.VISIBLE); - mViewPdf.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mFileUtils.openFile(path); - } - }); + mViewPdf.setOnClickListener(v -> mFileUtils.openFile(path)); } @Override @@ -198,7 +190,5 @@ public void onPDFCreated(boolean isNewPdfCreated, String path) { viewPdfButton(path); resetValues(); } - - } diff --git a/app/src/main/java/swati4star/createpdf/fragment/RemovePagesFragment.java b/app/src/main/java/swati4star/createpdf/fragment/RemovePagesFragment.java index 07b6c30ea..70a584022 100644 --- a/app/src/main/java/swati4star/createpdf/fragment/RemovePagesFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/RemovePagesFragment.java @@ -11,7 +11,6 @@ import android.support.annotation.NonNull; import android.support.design.widget.BottomSheetBehavior; import android.support.v4.app.Fragment; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; @@ -47,10 +46,10 @@ import swati4star.createpdf.util.MorphButtonUtility; import swati4star.createpdf.util.PDFEncryptionUtility; import swati4star.createpdf.util.PDFUtils; -import swati4star.createpdf.util.ViewFilesDividerItemDecoration; import static android.app.Activity.RESULT_OK; import static android.os.ParcelFileDescriptor.MODE_READ_ONLY; +import static swati4star.createpdf.util.CommonCodeUtils.populateUtil; import static swati4star.createpdf.util.Constants.ADD_PWD; import static swati4star.createpdf.util.Constants.BUNDLE_DATA; import static swati4star.createpdf.util.Constants.COMPRESS_PDF; @@ -322,18 +321,6 @@ private void viewPdfButton(String path) { @Override public void onPopulate(ArrayList paths) { - if (paths == null || paths.size() == 0) { - mLayout.setVisibility(View.GONE); - } else { - // Init recycler view - mRecyclerViewFiles.setVisibility(View.VISIBLE); - MergeFilesAdapter mergeFilesAdapter = new MergeFilesAdapter(mActivity, - paths, false, this); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); - mRecyclerViewFiles.setLayoutManager(mLayoutManager); - mRecyclerViewFiles.setAdapter(mergeFilesAdapter); - mRecyclerViewFiles.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); - } - mLottieProgress.setVisibility(View.GONE); + populateUtil(mActivity, paths, this, mLayout, mLottieProgress, mRecyclerViewFiles); } } diff --git a/app/src/main/java/swati4star/createpdf/fragment/SplitFilesFragment.java b/app/src/main/java/swati4star/createpdf/fragment/SplitFilesFragment.java index a319d28c3..046ce39f3 100644 --- a/app/src/main/java/swati4star/createpdf/fragment/SplitFilesFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/SplitFilesFragment.java @@ -37,6 +37,7 @@ import swati4star.createpdf.util.ViewFilesDividerItemDecoration; import static android.app.Activity.RESULT_OK; +import static swati4star.createpdf.util.CommonCodeUtils.populateUtil; import static swati4star.createpdf.util.FileUriUtils.getFilePath; import static swati4star.createpdf.util.StringUtils.showSnackbar; @@ -164,17 +165,6 @@ public void onFileItemClick(String path) { @Override public void onPopulate(ArrayList paths) { - if (paths == null || paths.size() == 0) { - mLayout.setVisibility(View.GONE); - } else { - // Init recycler view - mRecyclerViewFiles.setVisibility(View.VISIBLE); - MergeFilesAdapter mergeFilesAdapter = new MergeFilesAdapter(mActivity, paths, false, this); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); - mRecyclerViewFiles.setLayoutManager(mLayoutManager); - mRecyclerViewFiles.setAdapter(mergeFilesAdapter); - mRecyclerViewFiles.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); - } - mLottieProgress.setVisibility(View.GONE); + populateUtil(mActivity, paths, this, mLayout, mLottieProgress, mRecyclerViewFiles); } } diff --git a/app/src/main/java/swati4star/createpdf/fragment/ViewFilesFragment.java b/app/src/main/java/swati4star/createpdf/fragment/ViewFilesFragment.java index aa504890c..144d12482 100644 --- a/app/src/main/java/swati4star/createpdf/fragment/ViewFilesFragment.java +++ b/app/src/main/java/swati4star/createpdf/fragment/ViewFilesFragment.java @@ -27,9 +27,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.EditText; import android.widget.RelativeLayout; -import android.widget.TextView; import java.io.File; import java.util.ArrayList; @@ -46,7 +44,6 @@ import swati4star.createpdf.util.DirectoryUtils; import swati4star.createpdf.util.FileSortUtils; import swati4star.createpdf.util.MergeHelper; -import swati4star.createpdf.util.MoveFilesToDirectory; import swati4star.createpdf.util.PopulateList; import swati4star.createpdf.util.ViewFilesDividerItemDecoration; @@ -62,10 +59,6 @@ public class ViewFilesFragment extends Fragment EmptyStateChangeListener, ItemSelectedListener { - // Directory operations constants - public static final int NEW_DIR = 1; - public static final int EXISTING_DIR = 2; - private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE_RESULT = 10; @BindView(R.id.getStarted) @@ -91,7 +84,6 @@ public class ViewFilesFragment extends Fragment private boolean mCheckBoxChanged = false; private AlertDialog.Builder mAlertDialogBuilder; - private int mCountFiles; private MergeHelper mMergeHelper; @@ -209,54 +201,6 @@ public boolean onOptionsItemSelected(final MenuItem item) { } - /** - * Moves files from one directory to another - * - * @param operation - type of operation to be performed - * (create new Directory or move to an existing directory) - */ - private void moveFilesToDirectory(int operation) { - LayoutInflater inflater = getLayoutInflater(); - View alertView = inflater.inflate(R.layout.directory_dialog, null); - final ArrayList filePath = mViewFilesAdapter.getSelectedFilePath(); - if (filePath == null) { - showSnackbar(mActivity, R.string.snackbar_no_pdfs_selected); - } else { - final EditText input = alertView.findViewById(R.id.directory_editText); - TextView message = alertView.findViewById(R.id.directory_textView); - if (operation == NEW_DIR) { - message.setText(R.string.dialog_new_dir); - mAlertDialogBuilder.setTitle(R.string.new_directory) - .setView(alertView) - .setPositiveButton(R.string.ok, (dialogInterface, i) -> { - String fileName = input.getText().toString(); - new MoveFilesToDirectory(mActivity - , filePath - , fileName - , MoveFilesToDirectory.MOVE_FILES) - .execute(); - populatePdfList(); - }); - } else if (operation == EXISTING_DIR) { - message.setText(R.string.dialog_dir); - mAlertDialogBuilder.setTitle(R.string.directory) - .setView(alertView) - .setPositiveButton(R.string.ok, (dialogInterface, i) -> { - String fileName = input.getText().toString(); - File directory = mDirectoryUtils.getDirectory(fileName); - if (directory != null) { - new MoveFilesToDirectory(mActivity, filePath, fileName, MoveFilesToDirectory.MOVE_FILES) - .execute(); - populatePdfList(); - } else { - showSnackbar(mActivity, R.string.dir_does_not_exists); - dialogInterface.dismiss(); - } - }); - } - mAlertDialogBuilder.create().show(); - } - } /** * Shows an alert to delete files @@ -434,14 +378,51 @@ public void isSelected(Boolean isSelected, int countFiles) { } } - @Override - public void onStop() { - super.onStop(); - AppCompatActivity activity = ((AppCompatActivity) - Objects.requireNonNull(getActivity())); - ActionBar toolbar = activity.getSupportActionBar(); - toolbar.setTitle(appName); - } + /* + Just for reference + private void moveFilesToDirectory(int operation) { + LayoutInflater inflater = getLayoutInflater(); + View alertView = inflater.inflate(R.layout.directory_dialog, null); + final ArrayList filePath = mViewFilesAdapter.getSelectedFilePath(); + if (filePath == null) { + showSnackbar(mActivity, R.string.snackbar_no_pdfs_selected); + } else { + final EditText input = alertView.findViewById(R.id.directory_editText); + TextView message = alertView.findViewById(R.id.directory_textView); + if (operation == NEW_DIR) { + message.setText(R.string.dialog_new_dir); + mAlertDialogBuilder.setTitle(R.string.new_directory) + .setView(alertView) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> { + String fileName = input.getText().toString(); + new MoveFilesToDirectory(mActivity + , filePath + , fileName + , MoveFilesToDirectory.MOVE_FILES) + .execute(); + populatePdfList(); + }); + } else if (operation == EXISTING_DIR) { + message.setText(R.string.dialog_dir); + mAlertDialogBuilder.setTitle(R.string.directory) + .setView(alertView) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> { + String fileName = input.getText().toString(); + File directory = mDirectoryUtils.getDirectory(fileName); + if (directory != null) { + new MoveFilesToDirectory(mActivity, filePath, fileName, MoveFilesToDirectory.MOVE_FILES) + .execute(); + populatePdfList(); + } else { + showSnackbar(mActivity, R.string.dir_does_not_exists); + dialogInterface.dismiss(); + } + }); + } + mAlertDialogBuilder.create().show(); + } + }*/ + } \ No newline at end of file diff --git a/app/src/main/java/swati4star/createpdf/model/EnhancementOptionsEntity.java b/app/src/main/java/swati4star/createpdf/model/EnhancementOptionsEntity.java index 52a9d50c8..1d3167d58 100644 --- a/app/src/main/java/swati4star/createpdf/model/EnhancementOptionsEntity.java +++ b/app/src/main/java/swati4star/createpdf/model/EnhancementOptionsEntity.java @@ -1,5 +1,6 @@ package swati4star.createpdf.model; +import android.content.Context; import android.graphics.drawable.Drawable; /** @@ -15,6 +16,16 @@ public EnhancementOptionsEntity(Drawable image, String name) { this.mName = name; } + public EnhancementOptionsEntity(Context context, int imageId, String name) { + this.mImage = context.getResources().getDrawable(imageId); + this.mName = name; + } + + public EnhancementOptionsEntity(Context context, int resourceId, int stringId) { + this.mImage = context.getResources().getDrawable(resourceId); + this.mName = context.getString(stringId); + } + public Drawable getImage() { return mImage; } diff --git a/app/src/main/java/swati4star/createpdf/util/CommonCodeUtils.java b/app/src/main/java/swati4star/createpdf/util/CommonCodeUtils.java new file mode 100644 index 000000000..3525db7e1 --- /dev/null +++ b/app/src/main/java/swati4star/createpdf/util/CommonCodeUtils.java @@ -0,0 +1,74 @@ +package swati4star.createpdf.util; + +import android.app.Activity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.airbnb.lottie.LottieAnimationView; + +import java.util.ArrayList; + +import swati4star.createpdf.R; +import swati4star.createpdf.adapter.ExtractImagesAdapter; +import swati4star.createpdf.adapter.MergeFilesAdapter; + +import static swati4star.createpdf.util.StringUtils.showSnackbar; + +public class CommonCodeUtils { + + /** + * updates the output recycler view if paths.size > 0 + * else gides the main view + */ + public static void populateUtil(Activity mActivity, ArrayList paths, + MergeFilesAdapter.OnClickListener onClickListener, + RelativeLayout layout, LottieAnimationView animationView, + RecyclerView recyclerView) { + + if (paths == null || paths.size() == 0) { + layout.setVisibility(View.GONE); + } else { + // Init recycler view + recyclerView.setVisibility(View.VISIBLE); + MergeFilesAdapter mergeFilesAdapter = new MergeFilesAdapter(mActivity, + paths, false, onClickListener); + RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); + recyclerView.setLayoutManager(mLayoutManager); + recyclerView.setAdapter(mergeFilesAdapter); + recyclerView.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); + } + animationView.setVisibility(View.GONE); + } + + + /** + * sets the appropriate text to successtextview & display images in adapter + */ + public static void updateView(Activity mActivity, int imageCount, ArrayList outputFilePaths, + TextView successTextView, LinearLayout options, RecyclerView mCreatedImages, + ExtractImagesAdapter.OnFileItemClickedListener listener) { + + if (imageCount == 0) { + showSnackbar(mActivity, R.string.extract_images_failed); + return; + } + + String text = String.format(mActivity.getString(R.string.extract_images_success), imageCount); + showSnackbar(mActivity, text); + successTextView.setVisibility(View.VISIBLE); + options.setVisibility(View.VISIBLE); + ExtractImagesAdapter extractImagesAdapter = new ExtractImagesAdapter(mActivity, outputFilePaths, listener); + // init recycler view for displaying generated image list + RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity); + successTextView.setText(text); + mCreatedImages.setVisibility(View.VISIBLE); + mCreatedImages.setLayoutManager(mLayoutManager); + // set up adapter + mCreatedImages.setAdapter(extractImagesAdapter); + mCreatedImages.addItemDecoration(new ViewFilesDividerItemDecoration(mActivity)); + } +} diff --git a/app/src/main/java/swati4star/createpdf/util/Constants.java b/app/src/main/java/swati4star/createpdf/util/Constants.java index 853151627..450946098 100644 --- a/app/src/main/java/swati4star/createpdf/util/Constants.java +++ b/app/src/main/java/swati4star/createpdf/util/Constants.java @@ -37,6 +37,9 @@ public class Constants { public static final String ADD_PWD = "add_pwd"; public static final String REMOVE_PWd = "remove_pwd"; public static final String ADD_IMAGES = "add_images"; + public static final String PDF_TO_IMAGES = "pdf_to_images"; + public static final String EXTRACT_IMAGES = "extract_images"; + public static final String LAUNCH_COUNT = "launch_count"; diff --git a/app/src/main/java/swati4star/createpdf/util/FeedbackUtils.java b/app/src/main/java/swati4star/createpdf/util/FeedbackUtils.java index 7196701e1..615b7d755 100644 --- a/app/src/main/java/swati4star/createpdf/util/FeedbackUtils.java +++ b/app/src/main/java/swati4star/createpdf/util/FeedbackUtils.java @@ -29,6 +29,10 @@ public void shareApplication() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, mContext.getResources().getString(R.string.rate_us_text)); + openMailIntent(intent); + } + + public void openMailIntent(Intent intent) { try { mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.share_chooser))); } catch (android.content.ActivityNotFoundException ex) { diff --git a/app/src/main/java/swati4star/createpdf/util/FileUtils.java b/app/src/main/java/swati4star/createpdf/util/FileUtils.java index e7247d257..6629ba556 100644 --- a/app/src/main/java/swati4star/createpdf/util/FileUtils.java +++ b/app/src/main/java/swati4star/createpdf/util/FileUtils.java @@ -2,7 +2,6 @@ import android.app.Activity; import android.content.ActivityNotFoundException; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -49,12 +48,10 @@ public class FileUtils { private final Activity mContext; - private final ContentResolver mContentResolver; private final SharedPreferences mSharedPreferences; public FileUtils(Activity context) { this.mContext = context; - mContentResolver = mContext.getContentResolver(); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); } @@ -210,7 +207,7 @@ public void openFile(String path) { * @param mFile File List of all PDFs * @return Number to be added finally in the name to avoid overwrite */ - public int checkRepeat(String finalOutputFile, final ArrayList mFile) { + private int checkRepeat(String finalOutputFile, final ArrayList mFile) { boolean flag = true; int append = 0; while (flag) { @@ -327,13 +324,13 @@ public static String saveImage(String filename, Bitmap finalBitmap) { String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + pdfDirectory); - String fname = filename + ".jpg"; + String fname = filename + ".png"; File file = new File(myDir, fname); if (file.exists()) file.delete(); try { FileOutputStream out = new FileOutputStream(file); - finalBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); + finalBitmap.compress(Bitmap.CompressFormat.PNG, 100, out); Log.v("saving", fname); out.flush(); out.close(); @@ -404,4 +401,15 @@ public Intent getFileChooser() { intent.setDataAndType(myUri, mContext.getString(R.string.pdf_type)); return Intent.createChooser(intent, mContext.getString(R.string.merge_file_select)); } + + String getUniqueFileName(String fileName, ArrayList fileList) { + String outputFileName = fileName; + File file = new File(outputFileName); + if (isFileExist(file.getName())) { + int append = checkRepeat(outputFileName, fileList); + outputFileName = outputFileName.replace(mContext.getString(R.string.pdf_ext), + append + mContext.getResources().getString(R.string.pdf_ext)); + } + return outputFileName; + } } \ No newline at end of file diff --git a/app/src/main/java/swati4star/createpdf/util/ImageEnhancementOptionsUtils.java b/app/src/main/java/swati4star/createpdf/util/ImageEnhancementOptionsUtils.java index 0e003a79f..9366f51a5 100644 --- a/app/src/main/java/swati4star/createpdf/util/ImageEnhancementOptionsUtils.java +++ b/app/src/main/java/swati4star/createpdf/util/ImageEnhancementOptionsUtils.java @@ -20,57 +20,52 @@ public static ArrayList getEnhancementOptions(Context passwordicon = R.drawable.baseline_done_24; options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(passwordicon), - context.getResources().getString(R.string.password_protect_pdf_text))); + context, passwordicon, R.string.password_protect_pdf_text)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.baseline_crop_rotate_24), - context.getResources().getString(R.string.edit_images_text))); + context, R.drawable.baseline_crop_rotate_24, R.string.edit_images_text)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_compress_image), + context, R.drawable.ic_compress_image, String.format(context.getResources().getString(R.string.compress_image), pdfOptions.getQualityString()))); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_photo_filter_black_24dp), - context.getResources().getString(R.string.filter_images_Text))); + context, R.drawable.ic_photo_filter_black_24dp, R.string.filter_images_Text)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_page_size_24dp), - context.getResources().getString(R.string.set_page_size_text))); + context, R.drawable.ic_page_size_24dp, R.string.set_page_size_text)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_aspect_ratio_black_24dp), - context.getResources().getString(R.string.image_scale_type))); + context, R.drawable.ic_aspect_ratio_black_24dp, R.string.image_scale_type)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_play_circle_outline_black_24dp), - context.getResources().getString(R.string.preview_image_to_pdf))); + context, R.drawable.ic_play_circle_outline_black_24dp, R.string.preview_image_to_pdf)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_border_image_black_24dp), + context, R.drawable.ic_border_image_black_24dp, String.format(context.getResources().getString(R.string.border_dialog_title), pdfOptions.getBorderWidth()))); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_rearrange), - context.getResources().getString(R.string.rearrange_images))); + context, R.drawable.ic_rearrange, R.string.rearrange_images)); Drawable iconGrayscale = context.getResources().getDrawable(R.drawable.ic_photo_filter_black_24dp); iconGrayscale.setColorFilter(Color.GRAY, android.graphics.PorterDuff.Mode.SRC_IN); + options.add(new EnhancementOptionsEntity( iconGrayscale, context.getResources().getString(R.string.grayscale_images))); + options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_page_size_24dp), - context.getString(R.string.add_margins))); + context, R.drawable.ic_page_size_24dp, R.string.add_margins)); + options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_format_list_numbered_black_24dp), - context.getString(R.string.show_pg_num))); + context, R.drawable.ic_format_list_numbered_black_24dp, R.string.show_pg_num)); + options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_branding_watermark_black_24dp), - context.getResources().getString(R.string.add_watermark))); + context, R.drawable.ic_branding_watermark_black_24dp, R.string.add_watermark)); + return options; } } diff --git a/app/src/main/java/swati4star/createpdf/util/MergePdfEnhancementOptionsUtils.java b/app/src/main/java/swati4star/createpdf/util/MergePdfEnhancementOptionsUtils.java index 145a1f1af..350880f37 100644 --- a/app/src/main/java/swati4star/createpdf/util/MergePdfEnhancementOptionsUtils.java +++ b/app/src/main/java/swati4star/createpdf/util/MergePdfEnhancementOptionsUtils.java @@ -10,9 +10,9 @@ public class MergePdfEnhancementOptionsUtils { public static ArrayList getEnhancementOptions(Context context) { ArrayList options = new ArrayList<>(); + options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.baseline_enhanced_encryption_24), - context.getString(R.string.set_password))); + context, R.drawable.baseline_enhanced_encryption_24, R.string.set_password)); return options; } } \ No newline at end of file diff --git a/app/src/main/java/swati4star/createpdf/util/PDFEncryptionUtility.java b/app/src/main/java/swati4star/createpdf/util/PDFEncryptionUtility.java index 8d1e80f2c..ced44dd56 100644 --- a/app/src/main/java/swati4star/createpdf/util/PDFEncryptionUtility.java +++ b/app/src/main/java/swati4star/createpdf/util/PDFEncryptionUtility.java @@ -52,7 +52,6 @@ public PDFEncryptionUtility(Activity context) { .build(); } - /** * Opens the password mDialog to set Password for an existing PDF file. * @@ -111,14 +110,8 @@ private String doEncryption(String path, String password, final ArrayList mFileList) throws IOException, DocumentException { String masterpwd = mSharedPrefs.getString(MASTER_PWD_STRING, appName); - String finalOutputFile = path.replace(mContext.getString(R.string.pdf_ext), - mContext.getString(R.string.encrypted_file)); - File file = new File(finalOutputFile); - if (mFileUtils.isFileExist(file.getName())) { - int append = mFileUtils.checkRepeat(finalOutputFile, mFileList); - finalOutputFile = finalOutputFile.replace(mContext.getString(R.string.pdf_ext), - append + mContext.getResources().getString(R.string.pdf_ext)); - } + String finalOutputFile = mFileUtils.getUniqueFileName(path.replace(mContext.getString(R.string.pdf_ext), + mContext.getString(R.string.encrypted_file)), mFileList); PdfReader reader = new PdfReader(path); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(finalOutputFile)); @@ -199,7 +192,6 @@ public void afterTextChanged(Editable input) { showSnackbar(mContext, R.string.master_password_changed); } } - mDialog.dismiss(); }); } @@ -208,21 +200,14 @@ private boolean removePasswordUsingDefMasterPAssword(final String file, final DataSetChanged dataSetChanged, final ArrayList mFileList, final String[] inputPassword) { - String finalOutputFile; - PdfReader reader; try { String masterpwd = mSharedPrefs.getString(MASTER_PWD_STRING, appName); - reader = new PdfReader(file, masterpwd.getBytes()); + PdfReader reader = new PdfReader(file, masterpwd.getBytes()); byte[] password; - finalOutputFile = file.replace(mContext.getResources().getString(R.string.pdf_ext), - mContext.getString(R.string.decrypted_file)); - File temp = new File(finalOutputFile); - if (mFileUtils.isFileExist(temp.getName())) { - int append = mFileUtils.checkRepeat(finalOutputFile, mFileList); - finalOutputFile = finalOutputFile.replace(mContext.getResources().getString(R.string.pdf_ext), - append + mContext.getResources().getString(R.string.pdf_ext)); - } + finalOutputFile = mFileUtils.getUniqueFileName + (file.replace(mContext.getResources().getString(R.string.pdf_ext), + mContext.getString(R.string.decrypted_file)), mFileList); password = reader.computeUserPassword(); byte[] input = inputPassword[0].getBytes(); if (Arrays.equals(input, password)) { @@ -250,19 +235,12 @@ private boolean removePasswordUsingInputMasterPAssword(final String file, final DataSetChanged dataSetChanged, final ArrayList mFileList, final String[] inputPassword) { - String finalOutputFile; - PdfReader reader; try { - reader = new PdfReader(file, inputPassword[0].getBytes()); - finalOutputFile = file.replace(mContext.getResources().getString(R.string.pdf_ext), - mContext.getString(R.string.decrypted_file)); - File temp = new File(finalOutputFile); - if (mFileUtils.isFileExist(temp.getName())) { - int append = mFileUtils.checkRepeat(finalOutputFile, mFileList); - finalOutputFile = finalOutputFile.replace(mContext.getResources().getString(R.string.pdf_ext), - append + mContext.getResources().getString(R.string.pdf_ext)); - } + PdfReader reader = new PdfReader(file, inputPassword[0].getBytes()); + finalOutputFile = mFileUtils.getUniqueFileName( + file.replace(mContext.getResources().getString(R.string.pdf_ext), + mContext.getString(R.string.decrypted_file)), mFileList); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(finalOutputFile)); stamper.close(); reader.close(); @@ -277,7 +255,6 @@ private boolean removePasswordUsingInputMasterPAssword(final String file, } catch (DocumentException | IOException e) { e.printStackTrace(); } - return false; } } diff --git a/app/src/main/java/swati4star/createpdf/util/PDFUtils.java b/app/src/main/java/swati4star/createpdf/util/PDFUtils.java index ed3173915..2d045c203 100644 --- a/app/src/main/java/swati4star/createpdf/util/PDFUtils.java +++ b/app/src/main/java/swati4star/createpdf/util/PDFUtils.java @@ -6,25 +6,15 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; -import android.graphics.Color; import android.net.Uri; import android.os.AsyncTask; import android.preference.PreferenceManager; -import android.text.Editable; -import android.text.TextWatcher; import android.util.Log; import android.util.SparseIntArray; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.EditText; import android.widget.RadioGroup; -import android.widget.Spinner; import android.widget.TextView; -import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; -import com.github.danielnilsson9.colorpickerview.view.ColorPickerView; -import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; @@ -32,9 +22,7 @@ import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; -import com.itextpdf.text.Phrase; import com.itextpdf.text.Rectangle; -import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.PRStream; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfCopy; @@ -67,7 +55,6 @@ import swati4star.createpdf.interfaces.DataSetChanged; import swati4star.createpdf.interfaces.OnPDFCompressedInterface; import swati4star.createpdf.model.TextToPDFOptions; -import swati4star.createpdf.model.Watermark; import static swati4star.createpdf.util.Constants.MASTER_PWD_STRING; import static swati4star.createpdf.util.Constants.STORAGE_LOCATION; @@ -83,7 +70,6 @@ public class PDFUtils { private final FileUtils mFileUtils; private SparseIntArray mAngleRadioButton; private SharedPreferences mSharedPreferences; - private Watermark mWatermark; public PDFUtils(Activity context) { this.mContext = context; @@ -295,8 +281,8 @@ public void rotatePages(String sourceFilePath, final DataSetChanged dataSetChang .onPositive((dialog, which) -> { final RadioGroup angleInput = dialog.getCustomView().findViewById(R.id.rotation_angle); int angle = mAngleRadioButton.get(angleInput.getCheckedRadioButtonId()); - String destFilePath = mFileUtils.getFileDirectoryPath(sourceFilePath); - String fileName = mFileUtils.getFileName(sourceFilePath); + String destFilePath = FileUtils.getFileDirectoryPath(sourceFilePath); + String fileName = FileUtils.getFileName(sourceFilePath); destFilePath += String.format(mContext.getString(R.string.rotated_file_name), fileName.substring(0, fileName.lastIndexOf('.')), Integer.toString(angle), @@ -529,7 +515,7 @@ public ArrayList splitPDF(String path) { int pages = reader.getNumberOfPages(); for (int i = 1; i <= pages; i++) { document = new Document(); - String fileName = folderPath + mFileUtils.getFileName(path); + String fileName = folderPath + FileUtils.getFileName(path); fileName = fileName.replace(mContext.getString(R.string.pdf_ext), i + mContext.getString(R.string.pdf_ext)); Log.v("splitting", fileName); @@ -548,90 +534,6 @@ public ArrayList splitPDF(String path) { return outputPaths; } - public void setWatermark(String path, final DataSetChanged dataSetChanged, final ArrayList mFileList) { - - final MaterialDialog mDialog = new MaterialDialog.Builder(mContext) - .title(R.string.add_watermark) - .customView(R.layout.add_watermark_dialog, true) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .build(); - - final View mPositiveAction = mDialog.getActionButton(DialogAction.POSITIVE); - - this.mWatermark = new Watermark(); - - final EditText watermarkTextInput = mDialog.getCustomView().findViewById(R.id.watermarkText); - final EditText angleInput = mDialog.getCustomView().findViewById(R.id.watermarkAngle); - final ColorPickerView colorPickerInput = mDialog.getCustomView().findViewById(R.id.watermarkColor); - final EditText fontSizeInput = mDialog.getCustomView().findViewById(R.id.watermarkFontSize); - final Spinner fontFamilyInput = mDialog.getCustomView().findViewById(R.id.watermarkFontFamily); - final Spinner styleInput = mDialog.getCustomView().findViewById(R.id.watermarkStyle); - - fontFamilyInput.setAdapter(new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_dropdown_item, - Font.FontFamily.values())); - styleInput.setAdapter(new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_dropdown_item, - mContext.getResources().getStringArray(R.array.fontStyles))); - - angleInput.setText("0"); - fontSizeInput.setText("50"); - - watermarkTextInput.addTextChangedListener( - new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - mPositiveAction.setEnabled(s.toString().trim().length() > 0); - } - - @Override - public void afterTextChanged(Editable input) { - if (StringUtils.isEmpty(input)) - showSnackbar(mContext, R.string.snackbar_watermark_cannot_be_blank); - else { - mWatermark.setWatermarkText(input.toString()); - } - } - }); - - mPositiveAction.setEnabled(false); - mPositiveAction.setOnClickListener(v -> { - try { - mWatermark.setWatermarkText(watermarkTextInput.getText().toString()); - mWatermark.setFontFamily(((Font.FontFamily) fontFamilyInput.getSelectedItem())); - mWatermark.setFontStyle(getStyleValueFromName(((String) styleInput.getSelectedItem()))); - if (StringUtils.isEmpty(angleInput.getText())) { - mWatermark.setRotationAngle(0); - } else { - mWatermark.setRotationAngle(Integer.valueOf(angleInput.getText().toString())); - } - - if (StringUtils.isEmpty(fontSizeInput.getText())) { - mWatermark.setTextSize(50); - } else { - mWatermark.setTextSize(Integer.valueOf(fontSizeInput.getText().toString())); - } - mWatermark.setTextColor((new BaseColor( - Color.red(colorPickerInput.getColor()), - Color.green(colorPickerInput.getColor()), - Color.blue(colorPickerInput.getColor()), - Color.alpha(colorPickerInput.getColor()) - ))); - createWatermark(path, mFileList); - dataSetChanged.updateDataset(); - showSnackbar(mContext, R.string.watermark_added); - } catch (IOException | DocumentException e) { - e.printStackTrace(); - showSnackbar(mContext, R.string.cannot_add_watermark); - } - mDialog.dismiss(); - }); - mDialog.show(); - } - /** * Shows the dialog to allow users to add images */ @@ -644,79 +546,4 @@ public void setImages() { .build(); } - public static int getStyleValueFromName(String name) { - switch (name) { - case "NORMAL": - return Font.NORMAL; - case "BOLD": - return Font.BOLD; - case "ITALIC": - return Font.ITALIC; - case "UNDERLINE": - return Font.UNDERLINE; - case "STRIKETHRU": - return Font.STRIKETHRU; - case "BOLDITALIC": - return Font.BOLDITALIC; - default: - return Font.NORMAL; - } - } - - public static String getStyleNameFromFont(int font) { - switch (font) { - case Font.NORMAL: - return "NORMAL"; - case Font.BOLD: - return "BOLD"; - case Font.ITALIC: - return "ITALIC"; - case Font.UNDERLINE: - return "UNDERLINE"; - case Font.STRIKETHRU: - return "STRIKETHRU"; - case Font.BOLDITALIC: - return "BOLDITALIC"; - default: - return "NORMAL"; - } - } - - private String createWatermark(String path, final ArrayList mFileList) throws IOException, DocumentException { - String finalOutputFile = path.replace(mContext.getString(R.string.pdf_ext), - mContext.getString(R.string.watermarked_file)); - File file = new File(finalOutputFile); - if (mFileUtils.isFileExist(file.getName())) { - int append = mFileUtils.checkRepeat(finalOutputFile, mFileList); - finalOutputFile = finalOutputFile.replace(mContext.getString(R.string.pdf_ext), - append + mContext.getResources().getString(R.string.pdf_ext)); - } - - PdfReader reader = new PdfReader(path); - PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(finalOutputFile)); - Font font = new Font(this.mWatermark.getFontFamily(), this.mWatermark.getTextSize(), - this.mWatermark.getFontStyle(), this.mWatermark.getTextColor()); - Phrase p = new Phrase(this.mWatermark.getWatermarkText(), font); - - PdfContentByte over; - Rectangle pagesize; - float x, y; - int n = reader.getNumberOfPages(); - for (int i = 1; i <= n; i++) { - - // get page size and position - pagesize = reader.getPageSizeWithRotation(i); - x = (pagesize.getLeft() + pagesize.getRight()) / 2; - y = (pagesize.getTop() + pagesize.getBottom()) / 2; - over = stamper.getUnderContent(i); - - ColumnText.showTextAligned(over, Element.ALIGN_CENTER, p, x, y, this.mWatermark.getRotationAngle()); - } - - stamper.close(); - reader.close(); - new DatabaseHelper(mContext).insertRecord(finalOutputFile, mContext.getString(R.string.watermarked)); - return finalOutputFile; - } - } diff --git a/app/src/main/java/swati4star/createpdf/util/RemoveDuplicates.java b/app/src/main/java/swati4star/createpdf/util/RemoveDuplicates.java index e60472aad..f333505d7 100644 --- a/app/src/main/java/swati4star/createpdf/util/RemoveDuplicates.java +++ b/app/src/main/java/swati4star/createpdf/util/RemoveDuplicates.java @@ -4,7 +4,6 @@ import android.graphics.pdf.PdfRenderer; import android.os.AsyncTask; import android.os.ParcelFileDescriptor; -import android.util.Log; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfReader; @@ -23,12 +22,12 @@ public class RemoveDuplicates extends AsyncTask { private String mPath; private OnPDFCreatedInterface mOnPDFCreatedInterface; private ArrayList mBitmaps; - private ArrayList mSequence; - private String mPages; + private StringBuilder mSequence; private Boolean mIsNewPDFCreated; + public RemoveDuplicates(String mPath, OnPDFCreatedInterface onPDFCreatedInterface) { this.mPath = mPath; - mSequence = new ArrayList<>(); + mSequence = new StringBuilder(); mBitmaps = new ArrayList<>(); this.mOnPDFCreatedInterface = onPDFCreatedInterface; } @@ -46,49 +45,37 @@ protected Void doInBackground(Void... voids) { // Render pdf pages as bitmap ParcelFileDescriptor fileDescriptor = null; try { - if (mPath != null) // resolve pdf file path based on relative path fileDescriptor = ParcelFileDescriptor.open(new File(mPath), MODE_READ_ONLY); + if (fileDescriptor != null) { PdfRenderer renderer = new PdfRenderer(fileDescriptor); final int pageCount = renderer.getPageCount(); + for (int i = 0; i < pageCount; i++) { PdfRenderer.Page page = renderer.openPage(i); // generate bitmaps for individual pdf pages - Bitmap bitmap = Bitmap.createBitmap(page.getWidth(), page.getHeight(), + Bitmap currentBitmap = Bitmap.createBitmap(page.getWidth(), page.getHeight(), Bitmap.Config.ARGB_8888); // say we render for showing on the screen - page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); + page.render(currentBitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); // close the page page.close(); + //Adding bitmap to arrayList if not same - Boolean add = true; - if (mBitmaps.size() == 0) { - mBitmaps.add(bitmap); - mSequence.add(1); - } else { - for (int j = 0; j < mBitmaps.size(); j++) { - if (mBitmaps.get(j).sameAs(bitmap)) { - add = false; - } - } - if (add) { - mBitmaps.add(bitmap); - mSequence.add(i + 1); - } - } + checkAndAddIfBitmapExists(currentBitmap, i); } + // close the renderer renderer.close(); + if (mBitmaps.size() == pageCount) { //No repetition found + return null; } else { - StringBuilder pages = new StringBuilder(); - for ( int x : mSequence) - pages.append(x).append(","); - mPages = pages.toString(); + String mPages = mSequence.toString(); String outputPath = mPath.replace(".pdf", "_edited_" + mPages + ".pdf"); if (createPDF(mPath, outputPath, mPages)) { mPath = outputPath; @@ -96,7 +83,6 @@ protected Void doInBackground(Void... voids) { } } - } } catch (IOException | SecurityException e) { e.printStackTrace(); @@ -106,15 +92,29 @@ protected Void doInBackground(Void... voids) { return null; } + + private void checkAndAddIfBitmapExists(Bitmap bitmap, int position) { + + Boolean add = true; + for (Bitmap b : mBitmaps) { + if (b.sameAs(bitmap)) + add = false; + } + if (add) { + mBitmaps.add(bitmap); + mSequence.append(position).append(","); + } + } + @Override protected void onPostExecute(Void avoid) { // execution of result of Long time consuming operation super.onPostExecute(avoid); mOnPDFCreatedInterface.onPDFCreated(mIsNewPDFCreated, mPath); } - public boolean createPDF(String inputPath, String output, String pages) { + + private boolean createPDF(String inputPath, String output, String pages) { try { - Log.e("create ", pages); PdfReader reader = new PdfReader(inputPath); reader.selectPages(pages); PdfStamper pdfStamper = new PdfStamper(reader, @@ -128,4 +128,4 @@ public boolean createPDF(String inputPath, String output, String pages) { } } -} +} \ No newline at end of file diff --git a/app/src/main/java/swati4star/createpdf/util/SettingsOptions.java b/app/src/main/java/swati4star/createpdf/util/SettingsOptions.java index f79aa9c9f..6840c3f10 100644 --- a/app/src/main/java/swati4star/createpdf/util/SettingsOptions.java +++ b/app/src/main/java/swati4star/createpdf/util/SettingsOptions.java @@ -22,18 +22,18 @@ public static ArrayList getEnhancementOptions(Context SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_compress_image), + context, R.drawable.ic_compress_image, String.format(context.getString(R.string.image_compression_value_default), sharedPreferences.getInt(DEFAULT_COMPRESSION, 30)))); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_page_size_24dp), + context, R.drawable.ic_page_size_24dp, String.format(context.getString(R.string.page_size_value_def), sharedPreferences.getString(Constants.DEFAULT_PAGE_SIZE_TEXT, Constants.DEFAULT_PAGE_SIZE)))); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_font_black_24dp), + context, R.drawable.ic_font_black_24dp, String.format(context.getString(R.string.font_size_value_def), sharedPreferences.getInt(Constants.DEFAULT_FONT_SIZE_TEXT, Constants.DEFAULT_FONT_SIZE)))); @@ -43,23 +43,21 @@ public static ArrayList getEnhancementOptions(Context Constants.DEFAULT_FONT_FAMILY)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_font_family_24dp), + context, R.drawable.ic_font_family_24dp, String.format(context.getString(R.string.font_family_value_def), fontFamily.name()))); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.baseline_settings_brightness_24), + context, R.drawable.baseline_settings_brightness_24, String.format(context.getString(R.string.theme_value_def), sharedPreferences.getString(Constants.DEFAULT_THEME_TEXT, Constants.DEFAULT_THEME)))); - options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_aspect_ratio_black_24dp), - context.getString(R.string.image_scale_type))); + options.add(new EnhancementOptionsEntity(context, + R.drawable.ic_aspect_ratio_black_24dp, R.string.image_scale_type)); - options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_lock_black_24dp), - context.getString(R.string.change_master_pwd))); + options.add(new EnhancementOptionsEntity(context, + R.drawable.ic_lock_black_24dp, R.string.change_master_pwd)); return options; } diff --git a/app/src/main/java/swati4star/createpdf/util/TextEnhancementOptionsUtils.java b/app/src/main/java/swati4star/createpdf/util/TextEnhancementOptionsUtils.java index c5dd614ec..f7597594a 100644 --- a/app/src/main/java/swati4star/createpdf/util/TextEnhancementOptionsUtils.java +++ b/app/src/main/java/swati4star/createpdf/util/TextEnhancementOptionsUtils.java @@ -15,18 +15,17 @@ public static ArrayList getEnhancementOptions(Context String fontTitle, Font.FontFamily fontFamily) { ArrayList options = new ArrayList<>(); + options.add(new EnhancementOptionsEntity( context.getResources().getDrawable(R.drawable.ic_font_black_24dp), fontTitle)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_font_family_24dp), + context, R.drawable.ic_font_family_24dp, String.format(context.getString(R.string.default_font_family_text), fontFamily.name()))); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.ic_page_size_24dp), - context.getString(R.string.set_page_size_text))); + context, R.drawable.ic_page_size_24dp, R.string.set_page_size_text)); options.add(new EnhancementOptionsEntity( - context.getResources().getDrawable(R.drawable.baseline_enhanced_encryption_24), - context.getString(R.string.set_password))); + context, R.drawable.baseline_enhanced_encryption_24, R.string.set_password)); return options; } } diff --git a/app/src/main/java/swati4star/createpdf/util/WatermarkUtils.java b/app/src/main/java/swati4star/createpdf/util/WatermarkUtils.java new file mode 100644 index 000000000..033237fea --- /dev/null +++ b/app/src/main/java/swati4star/createpdf/util/WatermarkUtils.java @@ -0,0 +1,203 @@ +package swati4star.createpdf.util; + +import android.app.Activity; +import android.graphics.Color; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.Spinner; + +import com.afollestad.materialdialogs.DialogAction; +import com.afollestad.materialdialogs.MaterialDialog; +import com.github.danielnilsson9.colorpickerview.view.ColorPickerView; +import com.itextpdf.text.BaseColor; +import com.itextpdf.text.DocumentException; +import com.itextpdf.text.Element; +import com.itextpdf.text.Font; +import com.itextpdf.text.Phrase; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.ColumnText; +import com.itextpdf.text.pdf.PdfContentByte; +import com.itextpdf.text.pdf.PdfReader; +import com.itextpdf.text.pdf.PdfStamper; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +import swati4star.createpdf.R; +import swati4star.createpdf.database.DatabaseHelper; +import swati4star.createpdf.interfaces.DataSetChanged; +import swati4star.createpdf.model.Watermark; + +import static swati4star.createpdf.util.StringUtils.showSnackbar; + +public class WatermarkUtils { + + private final Activity mContext; + private Watermark mWatermark; + private FileUtils mFileUtils; + + public WatermarkUtils(Activity context) { + mContext = context; + mFileUtils = new FileUtils(context); + } + + public void setWatermark(String path, final DataSetChanged dataSetChanged, final ArrayList mFileList) { + + final MaterialDialog mDialog = new MaterialDialog.Builder(mContext) + .title(R.string.add_watermark) + .customView(R.layout.add_watermark_dialog, true) + .positiveText(android.R.string.ok) + .negativeText(android.R.string.cancel) + .build(); + + final View mPositiveAction = mDialog.getActionButton(DialogAction.POSITIVE); + + this.mWatermark = new Watermark(); + + final EditText watermarkTextInput = mDialog.getCustomView().findViewById(R.id.watermarkText); + final EditText angleInput = mDialog.getCustomView().findViewById(R.id.watermarkAngle); + final ColorPickerView colorPickerInput = mDialog.getCustomView().findViewById(R.id.watermarkColor); + final EditText fontSizeInput = mDialog.getCustomView().findViewById(R.id.watermarkFontSize); + final Spinner fontFamilyInput = mDialog.getCustomView().findViewById(R.id.watermarkFontFamily); + final Spinner styleInput = mDialog.getCustomView().findViewById(R.id.watermarkStyle); + + fontFamilyInput.setAdapter(new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_dropdown_item, + Font.FontFamily.values())); + styleInput.setAdapter(new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_dropdown_item, + mContext.getResources().getStringArray(R.array.fontStyles))); + + angleInput.setText("0"); + fontSizeInput.setText("50"); + + watermarkTextInput.addTextChangedListener( + new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + mPositiveAction.setEnabled(s.toString().trim().length() > 0); + } + + @Override + public void afterTextChanged(Editable input) { + if (StringUtils.isEmpty(input)) + showSnackbar(mContext, R.string.snackbar_watermark_cannot_be_blank); + else { + mWatermark.setWatermarkText(input.toString()); + } + } + }); + + mPositiveAction.setEnabled(false); + mPositiveAction.setOnClickListener(v -> { + try { + mWatermark.setWatermarkText(watermarkTextInput.getText().toString()); + mWatermark.setFontFamily(((Font.FontFamily) fontFamilyInput.getSelectedItem())); + mWatermark.setFontStyle(getStyleValueFromName(((String) styleInput.getSelectedItem()))); + if (StringUtils.isEmpty(angleInput.getText())) { + mWatermark.setRotationAngle(0); + } else { + mWatermark.setRotationAngle(Integer.valueOf(angleInput.getText().toString())); + } + + if (StringUtils.isEmpty(fontSizeInput.getText())) { + mWatermark.setTextSize(50); + } else { + mWatermark.setTextSize(Integer.valueOf(fontSizeInput.getText().toString())); + } + mWatermark.setTextColor((new BaseColor( + Color.red(colorPickerInput.getColor()), + Color.green(colorPickerInput.getColor()), + Color.blue(colorPickerInput.getColor()), + Color.alpha(colorPickerInput.getColor()) + ))); + createWatermark(path, mFileList); + dataSetChanged.updateDataset(); + showSnackbar(mContext, R.string.watermark_added); + } catch (IOException | DocumentException e) { + e.printStackTrace(); + showSnackbar(mContext, R.string.cannot_add_watermark); + } + mDialog.dismiss(); + }); + mDialog.show(); + } + + private String createWatermark(String path, final ArrayList mFileList) throws IOException, DocumentException { + String finalOutputFile = mFileUtils.getUniqueFileName(path.replace(mContext.getString(R.string.pdf_ext), + mContext.getString(R.string.watermarked_file)), mFileList); + + PdfReader reader = new PdfReader(path); + PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(finalOutputFile)); + Font font = new Font(this.mWatermark.getFontFamily(), this.mWatermark.getTextSize(), + this.mWatermark.getFontStyle(), this.mWatermark.getTextColor()); + Phrase p = new Phrase(this.mWatermark.getWatermarkText(), font); + + PdfContentByte over; + Rectangle pagesize; + float x, y; + int n = reader.getNumberOfPages(); + for (int i = 1; i <= n; i++) { + + // get page size and position + pagesize = reader.getPageSizeWithRotation(i); + x = (pagesize.getLeft() + pagesize.getRight()) / 2; + y = (pagesize.getTop() + pagesize.getBottom()) / 2; + over = stamper.getUnderContent(i); + + ColumnText.showTextAligned(over, Element.ALIGN_CENTER, p, x, y, this.mWatermark.getRotationAngle()); + } + + stamper.close(); + reader.close(); + new DatabaseHelper(mContext).insertRecord(finalOutputFile, mContext.getString(R.string.watermarked)); + return finalOutputFile; + } + + + public static int getStyleValueFromName(String name) { + switch (name) { + case "NORMAL": + return Font.NORMAL; + case "BOLD": + return Font.BOLD; + case "ITALIC": + return Font.ITALIC; + case "UNDERLINE": + return Font.UNDERLINE; + case "STRIKETHRU": + return Font.STRIKETHRU; + case "BOLDITALIC": + return Font.BOLDITALIC; + default: + return Font.NORMAL; + } + } + + public static String getStyleNameFromFont(int font) { + switch (font) { + case Font.NORMAL: + return "NORMAL"; + case Font.BOLD: + return "BOLD"; + case Font.ITALIC: + return "ITALIC"; + case Font.UNDERLINE: + return "UNDERLINE"; + case Font.STRIKETHRU: + return "STRIKETHRU"; + case Font.BOLDITALIC: + return "BOLDITALIC"; + default: + return "NORMAL"; + } + } + +} diff --git a/app/src/main/res/drawable-hdpi/circle_white.png b/app/src/main/res/drawable-hdpi/circle_white.png deleted file mode 100644 index ed347f030..000000000 Binary files a/app/src/main/res/drawable-hdpi/circle_white.png and /dev/null differ diff --git a/app/src/main/res/drawable-hdpi/circle_white.xml b/app/src/main/res/drawable-hdpi/circle_white.xml new file mode 100644 index 000000000..624e766c7 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/circle_white.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_arrow_upward_white.xml b/app/src/main/res/drawable/ic_arrow_upward_white.xml deleted file mode 100644 index fee89d2d8..000000000 --- a/app/src/main/res/drawable/ic_arrow_upward_white.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/app/src/main/res/layout/activity_photo_editor.xml b/app/src/main/res/layout/activity_photo_editor.xml index 4bbbae696..d881d10ee 100644 --- a/app/src/main/res/layout/activity_photo_editor.xml +++ b/app/src/main/res/layout/activity_photo_editor.xml @@ -43,7 +43,6 @@ android:contentDescription="@string/previous_image_content_desc" android:gravity="center" android:tint="?attr/bottomSheetColor" - android:visibility="invisible" app:srcCompat="@drawable/ic_navigate_before_white_24dp" tools:targetApi="lollipop" /> diff --git a/app/src/main/res/layout/compress_image_dialog.xml b/app/src/main/res/layout/compress_image_dialog.xml index e3f00daf8..285271101 100644 --- a/app/src/main/res/layout/compress_image_dialog.xml +++ b/app/src/main/res/layout/compress_image_dialog.xml @@ -18,6 +18,7 @@ android:orientation="horizontal"> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_add_images.xml b/app/src/main/res/layout/fragment_add_images.xml index 11c9a5499..004ee9afe 100644 --- a/app/src/main/res/layout/fragment_add_images.xml +++ b/app/src/main/res/layout/fragment_add_images.xml @@ -13,7 +13,7 @@ android:layout_height="match_parent" android:orientation="vertical" android:stretchColumns="*" - tools:context=".fragment.ExtractImagesFragment"> + tools:context=".fragment.AddImagesFragment"> - - - - - - - - - - - - - - -