Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
My notepad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9731301
My notepad
Commits
b0482b44
Commit
b0482b44
authored
Nov 05, 2020
by
9731301
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complete choosing pic from gallery or camera
parent
f41c3748
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
85 additions
and
94 deletions
+85
-94
AddTextToPicDialog.java
...uFeatures/Pics/AddTextToPicDialog/AddTextToPicDialog.java
+6
-7
OnSavePicListenerClick.java
...tures/Pics/AddTextToPicDialog/OnSavePicListenerClick.java
+1
-2
CameraActivity.java
...le/mynotepad/MenuFeatures/Pics/Camera/CameraActivity.java
+14
-47
ChoosingPicsFragment.java
...ple/mynotepad/MenuFeatures/Pics/ChoosingPicsFragment.java
+52
-3
NotedPicsListFragment.java
...le/mynotepad/MenuFeatures/Pics/NotedPicsListFragment.java
+3
-31
activity_main.xml
app/src/main/res/layout/activity_main.xml
+8
-2
dialog_add_text_to_pic.xml
app/src/main/res/layout/dialog_add_text_to_pic.xml
+1
-2
No files found.
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/AddTextToPicDialog/AddTextToPicDialog.java
View file @
b0482b44
...
...
@@ -2,6 +2,7 @@ package com.example.mynotepad.MenuFeatures.Pics.AddTextToPicDialog;
import
android.app.Activity
;
import
android.app.Dialog
;
import
android.graphics.Bitmap
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
...
...
@@ -16,25 +17,25 @@ public class AddTextToPicDialog {
private
EditText
editText
;
private
Button
save
,
back
;
public
void
showAddTxtDialog
(
Activity
activity
,
String
filePath
)
{
public
void
showAddTxtDialog
(
Activity
activity
,
Bitmap
bitmap
)
{
final
Dialog
dialog
=
new
Dialog
(
activity
);
dialog
.
setCancelable
(
true
);
dialog
.
setContentView
(
R
.
layout
.
dialog_add_text_to_pic
);
save
=
dialog
.
findViewById
(
R
.
id
.
save_button
);
back
=
dialog
.
findViewById
(
R
.
id
.
back_button
);
imageView
=
dialog
.
findViewById
(
R
.
id
.
imageView
);
imageView
.
setImageBitmap
(
bitmap
);
editText
=
dialog
.
findViewById
(
R
.
id
.
editText
);
addListener
(
dialog
,
filePath
);
addListener
(
dialog
);
dialog
.
show
();
}
private
void
addListener
(
final
Dialog
dialog
,
String
filePath
)
{
setPic
(
filePath
);
private
void
addListener
(
final
Dialog
dialog
)
{
save
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
onSavePicListenerClick
.
saveClicked
(
editText
.
getText
().
toString
());
onSavePicListenerClick
.
saveClicked
(
editText
.
getText
().
toString
()
);
dialog
.
dismiss
();
}
});
...
...
@@ -46,8 +47,6 @@ public class AddTextToPicDialog {
});
}
private
void
setPic
(
String
filePath
)
{
}
public
void
setOnSavePicListenerClick
(
OnSavePicListenerClick
onSavePicListenerClick
)
{
this
.
onSavePicListenerClick
=
onSavePicListenerClick
;
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/AddTextToPicDialog/OnSavePicListenerClick.java
View file @
b0482b44
package
com
.
example
.
mynotepad
.
MenuFeatures
.
Pics
.
AddTextToPicDialog
;
import
android.text.Editable
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
public
interface
OnSavePicListenerClick
{
void
saveClicked
(
String
editTextTxt
);
...
...
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/Camera/CameraActivity.java
View file @
b0482b44
...
...
@@ -6,8 +6,6 @@ import androidx.appcompat.app.AppCompatActivity;
import
androidx.core.content.ContextCompat
;
import
android.Manifest
;
import
android.app.AlertDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.graphics.Bitmap
;
...
...
@@ -22,7 +20,6 @@ import android.widget.ImageView;
import
android.widget.SeekBar
;
import
android.widget.Toast
;
import
com.example.mynotepad.MenuFeatures.Pics.AddTextToPicDialog.AddTextToPicDialog
;
import
com.example.mynotepad.R
;
import
java.io.File
;
...
...
@@ -31,21 +28,14 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.Executors
;
public
class
CameraActivity
extends
AppCompatActivity
{
private
Executor
executor
=
Executors
.
newSingleThreadExecutor
();
private
int
REQUEST_CODE_PERMISSIONS
=
1001
;
private
ImageView
switchCamera
;
private
Button
torch
,
flash
,
captureBtn
;
private
Button
torch
,
flash
,
captureBtn
;
private
SeekBar
seekBarZoom
;
private
static
String
filePath
;
private
android
.
hardware
.
Camera
mCamera
;
private
Bitmap
bitmap
;
private
final
int
RECORD_CAMERA_CODE
=
130
;
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
...
...
@@ -81,6 +71,7 @@ public class CameraActivity extends AppCompatActivity {
}
return
camera
;
}
private
void
addListeners
()
{
captureBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -111,7 +102,6 @@ public class CameraActivity extends AppCompatActivity {
private
void
onCaptureImage
(
View
v
)
{
mCamera
.
takePicture
(
null
,
null
,
mPicture
);
showCapturedImage
(
v
);
}
private
SeekBar
.
OnSeekBarChangeListener
onSeekBarChange
()
{
...
...
@@ -130,21 +120,29 @@ public class CameraActivity extends AppCompatActivity {
android
.
hardware
.
Camera
.
PictureCallback
mPicture
=
new
android
.
hardware
.
Camera
.
PictureCallback
()
{
@Override
public
void
onPictureTaken
(
byte
[]
data
,
android
.
hardware
.
Camera
camera
)
{
bitmap
=
BitmapFactory
.
decodeByteArray
(
data
,
0
,
data
.
length
);
File
pictureFile
=
getOutputMediaFile
();
filePath
=
pictureFile
.
getPath
();
if
(
pictureFile
==
null
)
{
return
;
}
try
{
FileOutputStream
out
=
new
FileOutputStream
(
pictureFile
);
//write on a file
out
.
write
(
data
);
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
out
);
out
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}++++++++++ "
+
filePath
);
if
(
filePath
!=
null
)
{
Intent
intent
=
new
Intent
();
intent
.
putExtra
(
"filePath"
,
filePath
);
setResult
(
2
,
intent
);
}
finish
();
}
};
...
...
@@ -160,39 +158,9 @@ public class CameraActivity extends AppCompatActivity {
// Create a media file for pic
String
timeStamp
=
new
SimpleDateFormat
(
"yyyyMMdd_HHmmss"
).
format
(
new
Date
());
File
mediaFile
=
new
File
(
mediaStorageDir
.
getPath
()
+
File
.
separator
+
"IMG_"
+
timeStamp
+
".jpg"
);
filePath
=
mediaFile
.
getPath
();
return
mediaFile
;
// return the pic file which we wanna write a pic on it
}
private
void
showCapturedImage
(
View
view
)
{
AddTextToPicDialog
addTextToPicDialog
=
new
AddTextToPicDialog
();
addTextToPicDialog
.
showAddTxtDialog
(
this
,
filePath
);
AlertDialog
.
Builder
alert
=
new
AlertDialog
.
Builder
(
this
);
alert
.
setMessage
(
"do you want to save the pic?"
);
alert
.
setPositiveButton
(
"yes"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
dismiss
();
if
(
filePath
!=
null
)
{
Intent
intent
=
new
Intent
();
intent
.
putExtra
(
"filePath"
,
filePath
);
setResult
(
2
,
intent
);
}
finish
();
}
});
alert
.
setNegativeButton
(
"no"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Intent
intent
=
getIntent
();
finish
();
startActivity
(
intent
);
dialog
.
dismiss
();
}
});
alert
.
show
();
}
//check permissions
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
...
...
@@ -208,7 +176,8 @@ public class CameraActivity extends AppCompatActivity {
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
if
(
requestCode
==
RECORD_CAMERA_CODE
)
{
if
(
grantResults
.
length
==
3
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
&&
grantResults
[
1
]
==
PackageManager
.
PERMISSION_GRANTED
&&
grantResults
[
2
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
grantResults
.
length
==
3
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
&&
grantResults
[
1
]
==
PackageManager
.
PERMISSION_GRANTED
&&
grantResults
[
2
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
Toast
.
makeText
(
this
,
"accepted"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
Toast
.
makeText
(
this
,
"You must give permissions to use this app. App is exiting."
,
Toast
.
LENGTH_SHORT
).
show
();
...
...
@@ -216,8 +185,6 @@ public class CameraActivity extends AppCompatActivity {
}
}
}
}
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/ChoosingPicsFragment.java
View file @
b0482b44
package
com
.
example
.
mynotepad
.
MenuFeatures
.
Pics
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.os.Bundle
;
import
androidx.annotation.NonNull
;
...
...
@@ -11,14 +13,22 @@ import android.provider.MediaStore;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
com.example.mynotepad.MenuFeatures.Pics.AddTextToPicDialog.AddTextToPicDialog
;
import
com.example.mynotepad.MenuFeatures.Pics.AddTextToPicDialog.OnSavePicListenerClick
;
import
com.example.mynotepad.MenuFeatures.Pics.Camera.CameraActivity
;
import
com.example.mynotepad.R
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
public
class
ChoosingPicsFragment
extends
Fragment
{
LinearLayout
camera
,
gallery
;
private
LinearLayout
camera
,
gallery
;
private
String
newFilePath
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
...
...
@@ -40,11 +50,11 @@ public class ChoosingPicsFragment extends Fragment {
gallery
=
view
.
findViewById
(
R
.
id
.
galleryBtn
);
}
private
void
addListeners
(){
private
void
addListeners
()
{
camera
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
startActivityForResult
(
new
Intent
(
getActivity
()
,
CameraActivity
.
class
)
,
2
);
startActivityForResult
(
new
Intent
(
getActivity
()
,
CameraActivity
.
class
)
,
2
);
}
});
...
...
@@ -57,4 +67,43 @@ public class ChoosingPicsFragment extends Fragment {
});
}
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
@Nullable
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
newFilePath
=
""
;
System
.
out
.
println
(
"================================================================================================"
);
if
(
data
!=
null
)
{
if
(
requestCode
==
1
)
{
// get image from gallery
newFilePath
=
data
.
getData
().
getPath
();
InputStream
stream
=
null
;
try
{
stream
=
getActivity
().
getContentResolver
().
openInputStream
(
data
.
getData
());
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
")))))))))))))))))))))))))))))))))))))))))))))))"
+
newFilePath
);
showDialogOnResult
(
BitmapFactory
.
decodeStream
(
stream
));
}
else
if
(
requestCode
==
2
)
{
// get image from camera
newFilePath
=
data
.
getStringExtra
(
"filePath"
);
File
imgFile
=
new
File
(
newFilePath
);
if
(
imgFile
.
exists
())
{
System
.
out
.
println
(
"(((((((((((((((((((((((((((((((((((((((((((("
+
newFilePath
);
showDialogOnResult
(
BitmapFactory
.
decodeFile
(
imgFile
.
getAbsolutePath
()));
}
}
}
}
private
void
showDialogOnResult
(
final
Bitmap
bitmap
)
{
//show dialog to save pic with note
AddTextToPicDialog
addTextToPicDialog
=
new
AddTextToPicDialog
();
addTextToPicDialog
.
showAddTxtDialog
(
getActivity
()
,
bitmap
);
addTextToPicDialog
.
setOnSavePicListenerClick
(
new
OnSavePicListenerClick
()
{
@Override
public
void
saveClicked
(
String
editTextTxt
)
{
//todo save image path and txt in data base
//todo txt should be save in database with pic path if file pah is not null and add it to my list
}
});
}
}
\ No newline at end of file
app/src/main/java/com/example/mynotepad/MenuFeatures/Pics/NotedPicsListFragment.java
View file @
b0482b44
package
com
.
example
.
mynotepad
.
MenuFeatures
.
Pics
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
import
android.os.Bundle
;
...
...
@@ -12,8 +13,8 @@ import androidx.fragment.app.Fragment;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
com.example.mynotepad.MainActivity
;
import
com.example.mynotepad.MenuFeatures.Pics.AddTextToPicDialog.AddTextToPicDialog
;
import
com.example.mynotepad.MenuFeatures.Pics.AddTextToPicDialog.OnSavePicListenerClick
;
import
com.example.mynotepad.R
;
...
...
@@ -24,7 +25,7 @@ import java.io.InputStream;
public
class
NotedPicsListFragment
extends
Fragment
{
private
String
newFilePath
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
...
...
@@ -38,33 +39,4 @@ public class NotedPicsListFragment extends Fragment {
super
.
onViewCreated
(
view
,
savedInstanceState
);
}
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
@Nullable
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
newFilePath
=
""
;
if
(
data
!=
null
)
if
(
requestCode
==
1
)
{
newFilePath
=
data
.
getData
().
getPath
();
}
else
if
(
requestCode
==
2
)
{
newFilePath
=
data
.
getStringExtra
(
"filePath"
);
}
//show dialog to save pic with note
AddTextToPicDialog
addTextToPicDialog
=
new
AddTextToPicDialog
();
addTextToPicDialog
.
showAddTxtDialog
(
getActivity
(),
newFilePath
);
addTextToPicDialog
.
setOnSavePicListenerClick
(
new
OnSavePicListenerClick
()
{
@Override
public
void
saveClicked
(
String
editTextTxt
)
{
// sent data to activity
if
(!
newFilePath
.
equals
(
""
))
{
Intent
intent
=
new
Intent
();
intent
.
putExtra
(
"filePath"
,
newFilePath
);
intent
.
putExtra
(
"imageTxt"
,
editTextTxt
);
//todo txt should be save in database with pic path if file pah is not null and add it to my list
}
}
});
}
}
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
View file @
b0482b44
...
...
@@ -61,6 +61,8 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:background=
"@drawable/bg_icon"
android:onClick=
"allNoteClicked"
android:padding=
"8dp"
android:src=
"@drawable/ic_notes"
/>
</LinearLayout>
...
...
@@ -89,6 +91,8 @@
<ImageView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:onClick=
"onCalendarClicked"
android:background=
"@drawable/bg_icon"
android:padding=
"10dp"
android:src=
"@drawable/ic_calender"
/>
...
...
@@ -105,16 +109,17 @@
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:text=
"@string/voice_massages"
android:background=
"@drawable/bg_button2"
android:gravity=
"center"
android:onClick=
"allNoteClicked"
android:onClick=
"onVoiceMassagesClicked"
android:text=
"@string/voice_massages"
android:textColor=
"@color/design_default_color_surface"
/>
<ImageView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:background=
"@drawable/bg_icon"
android:onClick=
"onVoiceMassagesClicked"
android:padding=
"8dp"
android:src=
"@drawable/ic_voice"
/>
</LinearLayout>
...
...
@@ -145,6 +150,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:background=
"@drawable/bg_icon"
android:onClick=
"noNotedPicsClicked"
android:padding=
"10dp"
android:src=
"@drawable/ic_noted_pictures"
/>
</LinearLayout>
...
...
app/src/main/res/layout/dialog_add_text_to_pic.xml
View file @
b0482b44
...
...
@@ -11,8 +11,7 @@
android:id=
"@+id/imageView"
android:layout_width=
"414dp"
android:layout_height=
"562dp"
android:layout_marginBottom=
"60dp"
android:src=
"@drawable/main_bg_bright"
android:layout_marginBottom=
"120dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment