-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abec2d4
commit 16b6775
Showing
24 changed files
with
900 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
app/src/main/java/br/ufs/projetos/gocidade/repository/DataManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/br/ufs/projetos/gocidade/repository/model/AppDbHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package br.ufs.projetos.gocidade.repository.model | ||
|
||
import br.ufs.projetos.gocidade.util.Constants | ||
import com.google.firebase.database.DatabaseReference | ||
import com.google.firebase.database.FirebaseDatabase | ||
|
||
/** | ||
* Created by samila on 21/11/17. | ||
*/ | ||
class AppDbHelper : DbHelper { | ||
|
||
val database = FirebaseDatabase.getInstance() | ||
val dbReference : DatabaseReference? = database.reference | ||
|
||
override fun newPost(post : Post) { | ||
dbReference?.child(Constants.DataBase.DATABASE_POST) | ||
?.child(post.id.toString())?.setValue(post) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/br/ufs/projetos/gocidade/repository/model/DbHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package br.ufs.projetos.gocidade.repository.model | ||
|
||
/** | ||
* Created by samila on 21/11/17. | ||
*/ | ||
interface DbHelper { | ||
|
||
fun newPost (post : Post) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
app/src/main/java/br/ufs/projetos/gocidade/ui/main/CamActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package br.ufs.projetos.gocidade.ui.main; | ||
|
||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.hardware.Camera; | ||
import android.media.CamcorderProfile; | ||
import android.media.MediaRecorder; | ||
import android.net.Uri; | ||
import android.provider.MediaStore; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.FrameLayout; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import br.ufs.projetos.gocidade.R; | ||
|
||
public class CamActivity extends AppCompatActivity | ||
implements View.OnClickListener { | ||
|
||
private Camera mCamera; | ||
private CamView mPreview; | ||
private MediaRecorder mMediaRecorder; | ||
private boolean mGravando; | ||
private boolean mTirouFoto; | ||
private Button mBtnCapturar; | ||
private File mCaminhoArquivo; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_cam); | ||
|
||
if (cameraDisponivel()) { | ||
abrirCamera(); | ||
|
||
mPreview = new CamView(this, mCamera); | ||
FrameLayout preview = (FrameLayout) findViewById(R.id.previewCamera); | ||
preview.addView(mPreview); | ||
} | ||
|
||
Uri uri = getIntent().getParcelableExtra(MediaStore.EXTRA_OUTPUT); | ||
if (uri != null){ | ||
mCaminhoArquivo = new File(uri.getPath()); | ||
} | ||
|
||
mBtnCapturar = (Button) findViewById(R.id.btnCapturar); | ||
mBtnCapturar.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
liberarMediaRecorder(); | ||
liberarCamera(); | ||
if (mGravando){ | ||
if (mCaminhoArquivo.exists()){ | ||
mCaminhoArquivo.delete(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
if (cameraDisponivel()) { | ||
abrirCamera(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
String action = getIntent().getAction(); | ||
if (action.equals(MediaStore.ACTION_IMAGE_CAPTURE)){ | ||
tirarFoto(); | ||
} else if (action.equals(MediaStore.ACTION_VIDEO_CAPTURE)){ | ||
gravarVideo(); | ||
} | ||
} | ||
// Próximos métodos virão aqui | ||
private boolean cameraDisponivel() { | ||
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); | ||
} | ||
|
||
private void abrirCamera() { | ||
try { | ||
mCamera = Camera.open(); | ||
} catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void liberarMediaRecorder(){ | ||
if (mMediaRecorder != null) { | ||
mMediaRecorder.reset(); | ||
mMediaRecorder.release(); | ||
mMediaRecorder = null; | ||
mCamera.lock(); | ||
} | ||
} | ||
|
||
private void liberarCamera(){ | ||
if (mCamera != null){ | ||
mCamera.release(); | ||
mCamera = null; | ||
mPreview.getHolder().removeCallback(mPreview); | ||
} | ||
} | ||
|
||
private void tirarFoto(){ | ||
if (mTirouFoto){ | ||
setResult(RESULT_OK); | ||
finish(); | ||
} else { | ||
mCamera.takePicture(null, null, mPicture); | ||
} | ||
} | ||
|
||
private Camera.PictureCallback mPicture = new Camera.PictureCallback() { | ||
@Override | ||
public void onPictureTaken(byte[] data, Camera camera) { | ||
|
||
if (mCaminhoArquivo != null){ | ||
try { | ||
FileOutputStream fos = new FileOutputStream(mCaminhoArquivo); | ||
fos.write(data); | ||
fos.close(); | ||
mTirouFoto = true; | ||
mBtnCapturar.setText("OK"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
private void gravarVideo(){ | ||
if (mGravando) { | ||
concluirGravacao(); | ||
|
||
} else { | ||
if (prepararGravacao()) { | ||
mMediaRecorder.start(); | ||
mBtnCapturar.setText("Stop"); | ||
mGravando = true; | ||
} else { | ||
liberarMediaRecorder(); | ||
} | ||
} | ||
} | ||
|
||
private boolean prepararGravacao(){ | ||
|
||
abrirCamera(); | ||
mCamera.unlock(); | ||
|
||
mMediaRecorder = new MediaRecorder(); | ||
mMediaRecorder.setCamera(mCamera); | ||
|
||
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); | ||
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); | ||
|
||
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); | ||
|
||
mMediaRecorder.setOutputFile(mCaminhoArquivo.toString()); | ||
mMediaRecorder.setMaxDuration(60000); // 1 minuto | ||
mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() { | ||
@Override | ||
public void onInfo(MediaRecorder mr, int what, int extra) { | ||
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { | ||
concluirGravacao(); | ||
} | ||
} | ||
}); | ||
|
||
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); | ||
|
||
try { | ||
mMediaRecorder.prepare(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
liberarMediaRecorder(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private void concluirGravacao(){ | ||
mMediaRecorder.stop(); | ||
liberarMediaRecorder(); | ||
mCamera.lock(); | ||
|
||
mGravando = false; | ||
|
||
Intent it = new Intent(); | ||
it.setData(Uri.fromFile(mCaminhoArquivo)); | ||
setResult(RESULT_OK, it); | ||
finish(); | ||
} | ||
} |
Oops, something went wrong.