Skip to content

Commit

Permalink
update version, code cleanup and fixed error in convert pdf pages to …
Browse files Browse the repository at this point in the history
…image
  • Loading branch information
Swati4star committed Jan 8, 2019
1 parent 53e0134 commit a1e0634
Show file tree
Hide file tree
Showing 57 changed files with 654 additions and 961 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/assets/whatsnew.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

],
Expand All @@ -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",
Expand Down
126 changes: 35 additions & 91 deletions app/src/main/java/swati4star/createpdf/activity/ImageEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -46,9 +47,8 @@ public class ImageEditor extends AppCompatActivity implements OnFilterItemClicke
private ArrayList<FilterItem> mFilterItems;
private ArrayList<BrushItem> mBrushItems;

private int mImagesCount;
private int mDisplaySize;
private int mCurrentImage = 0;
private int mCurrentImage; // 0 by default
private String mFilterName;

@BindView(R.id.nextimageButton)
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private void showOptions() {

/**
* Returns a list of options for preview activity
*
* @return - list
*/
private ArrayList<PreviewImageOptionItem> getOptions() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -144,7 +146,7 @@ public void onBackPressed() {
passUris();
}

public static Intent getStartIntent(Context context, ArrayList<String> uris) {
public static Intent getStartIntent(Context context, ArrayList<String> uris) {
Intent intent = new Intent(context, PreviewActivity.class);
intent.putExtra(PREVIEW_IMAGES, uris);
return intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class WelcomeActivity extends AppCompatActivity {
public Button mBtnSkip;

private int[] mLayouts;
private long mBackPressed;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit a1e0634

Please sign in to comment.