Skip to content

Commit

Permalink
#165 - Added doodle option to images (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv07tiwari authored and Swati4star committed Aug 3, 2018
1 parent b064469 commit be2a799
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 3 deletions.
80 changes: 80 additions & 0 deletions app/src/main/java/swati4star/createpdf/activity/ImageEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -62,6 +65,7 @@ public class ImageEditor extends AppCompatActivity implements OnFilterItemClicke
ImageButton mPreviousButton;
@BindView(R.id.resetCurrent)
Button resetCurrent;
SeekBar doodleSeekBar;

private Bitmap mBitmap;
private PhotoEditorView mPhotoEditorView;
Expand All @@ -70,6 +74,7 @@ public class ImageEditor extends AppCompatActivity implements OnFilterItemClicke
private boolean mIsLast = false;

private PhotoEditor mPhotoEditor;
Button mDoodleButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -91,10 +96,60 @@ protected void onCreate(Bundle savedInstanceState) {
mFilterItems = getFiltersList(this);
mImagepaths.addAll(mFilterUris);
initRecyclerView();
mDoodleButton = findViewById(R.id.doodleButton);
doodleSeekBar = findViewById(R.id.doodleSeekBar);
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) {
mPhotoEditor.setBrushSize(progress);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
mPhotoEditor.setBrushDrawingMode(false);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
}

@OnClick(R.id.doodle_color_white)
void setColorWhite() {
doodleSeekBar.setBackgroundColor(getResources().getColor(R.color.mb_white));
mPhotoEditor.setBrushColor(getResources().getColor(R.color.mb_white));
}

@OnClick(R.id.doodle_color_black)
void setColorBlack() {
doodleSeekBar.setBackgroundColor(getResources().getColor(R.color.black_87));
mPhotoEditor.setBrushColor(getResources().getColor(R.color.black_87));
}

@OnClick(R.id.doodle_color_red)
void setColorRed() {
doodleSeekBar.setBackgroundColor(getResources().getColor(R.color.red));
mPhotoEditor.setBrushColor(getResources().getColor(R.color.red));
}

@OnClick(R.id.doodle_color_blue)
void setColorBlue() {
doodleSeekBar.setBackgroundColor(getResources().getColor(R.color.mb_blue));
mPhotoEditor.setBrushColor(getResources().getColor(R.color.mb_blue));
}

@OnClick(R.id.doodle_color_green)
void setColorGreen() {
doodleSeekBar.setBackgroundColor(getResources().getColor(R.color.mb_green));
mPhotoEditor.setBrushColor(getResources().getColor(R.color.mb_green));
}

@OnClick(R.id.nextimageButton)
void nextImg() {
//Proceed to next if Save Current has been clicked
Expand Down Expand Up @@ -134,6 +189,8 @@ void resetCurrent() {
mImagepaths.add(mCurrentImage, originalPath);
mBitmap = BitmapFactory.decodeFile(originalPath);
mPhotoEditorView.getSource().setImageBitmap(mBitmap);
mPhotoEditor.clearAllViews();
mPhotoEditor.undo();
}
}

Expand Down Expand Up @@ -330,6 +387,29 @@ private void cancelFilter() {

}

@OnClick(R.id.doodleButton)
public void doodleEffect() {

mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView)
.setPinchTextScalable(true)
.build();
LinearLayout colorLayout = findViewById(R.id.doodle_colors);
if (doodleSeekBar.getVisibility() == View.GONE && colorLayout.getVisibility() == View.GONE) {
mPhotoEditor.setBrushDrawingMode(true);
doodleSeekBar.setVisibility(View.VISIBLE);
mDoodleButton.setText(R.string.disable_doodle_effect);
mDoodleButton.setBackgroundColor(getResources().getColor(R.color.mb_white));
colorLayout.setVisibility(View.VISIBLE);
} else if (doodleSeekBar.getVisibility() == View.VISIBLE &&
colorLayout.getVisibility() == View.VISIBLE) {
mPhotoEditor.setBrushDrawingMode(false);
doodleSeekBar.setVisibility(View.GONE);
mDoodleButton.setText(R.string.enable_doodle_effect);
mDoodleButton.setBackgroundColor(getResources().getColor(android.R.color.holo_orange_dark));
colorLayout.setVisibility(View.GONE);
}
}

@Override
public void onBackPressed() {
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
}

if (fragment != null) {
fragmentManager.beginTransaction().replace(R.id.content, fragment).commit();
fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.content, fragment).commit();
}

DrawerLayout drawer = findViewById(R.id.drawer_layout);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_border_outer_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M13,7h-2v2h2L13,7zM13,11h-2v2h2v-2zM17,11h-2v2h2v-2zM3,3v18h18L21,3L3,3zM19,19L5,19L5,5h14v14zM13,15h-2v2h2v-2zM9,11L7,11v2h2v-2z"/>
</vector>
65 changes: 63 additions & 2 deletions app/src/main/res/layout/activity_photo_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
tools:context=".activity.ImageEditor">

<ScrollView
android:id="@+id/scrollViewImage"
android:layout_width="match_parent"
android:layout_height="378dp"
android:layout_alignParentStart="true"
Expand Down Expand Up @@ -88,13 +89,73 @@
android:text="@string/reset"
android:textAllCaps="false"
android:textColor="@android:color/white" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/doodleButton"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"
android:text="@string/enable_doodle_effect"
android:textAllCaps="false"
android:background="@android:color/holo_orange_dark"
android:layout_above="@+id/recyclerView"/>
<SeekBar
android:id="@+id/doodleSeekBar"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:visibility="gone"
android:layout_toEndOf="@id/doodleButton"
android:layout_above="@id/doodle_colors"
android:max="100"
android:progress="30"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/recyclerView"
android:id="@+id/doodle_colors"
android:padding="3dp"
android:visibility="gone"
android:background="@color/gray_background"
android:layout_marginStart="10dp"
android:layout_toEndOf="@id/doodleButton"
android:orientation="horizontal">
<Button
android:id="@+id/doodle_color_white"
android:layout_width="30dp"
android:layout_margin="3dp"
android:background="@color/mb_white"
android:layout_height="20dp" />
<Button
android:id="@+id/doodle_color_red"
android:layout_width="30dp"
android:layout_margin="3dp"
android:background="@color/red"
android:layout_height="20dp" />
<Button
android:id="@+id/doodle_color_black"
android:layout_width="30dp"
android:layout_margin="3dp"
android:background="@color/black_87"
android:layout_height="30dp" />
<Button
android:id="@+id/doodle_color_blue"
android:layout_width="30dp"
android:layout_margin="3dp"
android:background="@color/mb_blue"
android:layout_height="30dp" />
<Button
android:id="@+id/doodle_color_green"
android:layout_width="30dp"
android:layout_margin="3dp"
android:background="@color/mb_green"
android:layout_height="30dp" />
</LinearLayout>

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#e6e4e4"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,8 @@
<string name="image_rearranging_options">Image Rearranging Options</string>
<string name="filter_file_name">%s_%s.jpg</string>
<string name="reset">Reset</string>
<string name="border">Add Image Border</string>
<string name="enable_doodle_effect">Enable Doodle Effect</string>
<string name="disable_doodle_effect">Disable Doodle Effect</string>
<string name="select_as">Select as:</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,8 @@
<string name="image_rearranging_options">Image Rearranging Options</string>
<string name="filter_file_name">%s_%s.jpg</string>
<string name="reset">Reset</string>
<string name="border">Add Image Border</string>
<string name="enable_doodle_effect">Enable Doodle Effect</string>
<string name="disable_doodle_effect">Disable Doodle Effect</string>
<string name="select_as">Select as:</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,8 @@
<string name="image_rearranging_options">Image Rearranging Options</string>
<string name="filter_file_name">%s_%s.jpg</string>
<string name="reset">Reset</string>
<string name="border">Add Image Border</string>
<string name="enable_doodle_effect">Enable Doodle Effect</string>
<string name="disable_doodle_effect">Disable Doodle Effect</string>
<string name="select_as">Select as:</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<color name="colorGray">#607D8B</color>
<color name="gray_background">#eceff1</color>
<color name="black">#000000</color>
<color name="red">#FF0000</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,8 @@
<string name="image_rearranging_options">Image Rearranging Options</string>
<string name="filter_file_name">%s_%s.jpg</string>
<string name="reset">Reset</string>
<string name="border">Add Image Border</string>
<string name="enable_doodle_effect">Enable Doodle Effect</string>
<string name="disable_doodle_effect">Disable Doodle Effect</string>
<string name="select_as">Select as:</string>
</resources>

0 comments on commit be2a799

Please sign in to comment.