Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pyone Thant Win
calorieEstimation
Commits
a671e044
Commit
a671e044
authored
Apr 11, 2020
by
Pyone Thant Win
Browse files
Added camera function in the app
parent
738e56ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
CalorieEstimator/app/src/main/java/com/example/calorieestimator/take_picture.java
View file @
a671e044
package
com.example.calorieestimator
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.os.Bundle
;
import
com.google.android.material.floatingactionbutton.FloatingActionButton
;
...
...
@@ -8,25 +10,59 @@ import com.google.android.material.snackbar.Snackbar;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.widget.Toolbar
;
import
android.provider.MediaStore
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageView
;
public
class
take_picture
extends
AppCompatActivity
{
//Button _btn_cam;
private
ImageView
_imageView
;
private
static
final
int
REQUEST_IMAGE_CAPTURE
=
101
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_take_picture
);
Toolbar
toolbar
=
findViewById
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
_imageView
=
findViewById
(
R
.
id
.
imageView
);
//_btn_cam = (Button)findViewById(R.id.btn_cam);
//Intent imageTakeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//if (imageTakeIntent.resolveActivity(getPackageManager())!=null){
// startActivityForResult(imageTakeIntent, REQUEST_IMAGE_CAPTURE);
FloatingActionButton
fab
=
findViewById
(
R
.
id
.
fab
);
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
/*_btnregister.setOnClickListener(new View.OnClickListener(){
@Override
public
void
onClick
(
View
view
)
{
Snackbar
.
make
(
view
,
"Replace with your own action"
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
"Action"
,
null
).
show
();
public void onClick(View v){
db = openHelper.getWritableDatabase();
String fname = _fname.getText().toString();
String lname = _lname.getText().toString();
String email = _user_email.getText().toString();
String pswd = _user_pswd.getText().toString();
insertdata(fname, lname, email, pswd);
Toast.makeText(getApplicationContext(), "register successfully", Toast.LENGTH_LONG).show();
}
});
});*/
}
public
void
btn_cam
(
View
view
)
{
Intent
imageTakeIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
if
(
imageTakeIntent
.
resolveActivity
(
getPackageManager
())
!=
null
)
{
startActivityForResult
(
imageTakeIntent
,
REQUEST_IMAGE_CAPTURE
);
}
}
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
){
Bundle
extras
=
data
.
getExtras
();
Bitmap
imageBitmap
=
(
Bitmap
)
extras
.
get
(
"data"
);
_imageView
.
setImageBitmap
(
imageBitmap
);
}
}
CalorieEstimator/app/src/main/res/layout/activity_main.xml
View file @
a671e044
...
...
@@ -79,6 +79,7 @@
android:layout_width=
"121dp"
android:layout_height=
"40dp"
android:layout_marginStart=
"70dp"
android:layout_marginTop=
"42dp"
android:layout_marginEnd=
"32dp"
android:layout_marginBottom=
"90dp"
android:text=
"Login"
...
...
@@ -96,7 +97,7 @@
android:layout_marginStart=
"16dp"
android:layout_marginTop=
"42dp"
android:layout_marginEnd=
"70dp"
android:layout_marginBottom=
"
127
dp"
android:layout_marginBottom=
"
90
dp"
android:text=
"Skip"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
...
...
CalorieEstimator/app/src/main/res/layout/activity_take_picture.xml
View file @
a671e044
<?xml version="1.0" encoding="utf-8"?>
<androidx.co
ordinator
layout.widget.Co
ordinator
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<androidx.co
nstraint
layout.widget.Co
nstraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/coordinatorLayout"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".take_picture"
>
<com.google.android.material.appbar.AppBarLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:theme=
"@style/AppTheme.AppBarOverlay"
>
<Button
android:id=
"@+id/btn_cam"
android:layout_width=
"126dp"
android:layout_height=
"55dp"
android:layout_marginStart=
"142dp"
android:layout_marginTop=
"550dp"
android:layout_marginEnd=
"143dp"
android:layout_marginBottom=
"126dp"
android:onClick=
"btn_cam"
android:text=
"Open Camera"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintVertical_bias=
"0.0"
/>
<androidx.appcompat.widget.Toolbar
android:id=
"@+id/toolbar"
android:layout_width=
"match_parent"
android:layout_height=
"?attr/actionBarSize"
android:background=
"?attr/colorPrimary"
app:popupTheme=
"@style/AppTheme.PopupOverlay"
/>
</com.google.android.material.appbar.AppBarLayout>
<include
layout=
"@layout/content_take_picture"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id=
"@+id/fab"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"bottom|end"
android:layout_margin=
"@dimen/fab_margin"
app:srcCompat=
"@android:drawable/ic_dialog_email"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
<ImageView
android:id=
"@+id/imageView"
android:layout_width=
"250dp"
android:layout_height=
"250dp"
android:layout_marginStart=
"80dp"
android:layout_marginTop=
"187dp"
android:layout_marginEnd=
"81dp"
android:layout_marginBottom=
"113dp"
app:layout_constraintBottom_toTopOf=
"@+id/btn_cam"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@mipmap/ic_launcher"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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