Sunteți pe pagina 1din 6

Ministerul Educatiei al Republicii Moldova

Universitatea Tehnica a Moldovei


Facultate Calculatoare, Informatica si Microelectronica
Departamentul Ingeneria Software si Automatica

Raport
la disciplina Proiectarea aplicatiilor mobile

Tema: UI View Model - Lucrarea Nr.1


Chiinu 2017

Scopul lucrrii: De prezentat o aplicaie ce ruleaz pe un dispozitiv sau emulator, ce va conine


pe interfaa sa, urmtoarele elemente:

4 butoane (ce vor executa condiiile de mai jos)


1 TextBox (pentru input)
2 Radio butoane (pentru camera fa, spate)

De utilizat componentele UI pentru a realiza urmtoarele condiii:

Conditii:
De creat un push notification pe ecranul dispozitivului care se va trata peste 10s.
De utilizat browserul intern al dispozitivului, pentru a iniializa o cutare n Google, conform
cuvntului cheie introdus n TextBox.
De rulat evenimentul de lucru a camerei frontale i/sau spate la selectarea unuia din cele 2
radio butoane propuse.
de tratat evenimentul de captare a pozei executate cu una din cele doua camere, i de afiat
ntr-o alt Activitate
este un punct la dorina voastr (sau un brainstorming)

Implementarea sarcinii :

Fig. 1

Concluzii:
In acest laborator am realizat o aplicatie pe platforma Android in cod nativ, utilizind drept IDE
Android Studio. Aplicatia poate face cautare dupa cuvintul cheie introdus in textbox ,transmitind
printrun intent implicit mesajul sistemului de operare si poate captura imagini foto si video de pe
ambele camere ,deasemenea utilizind un intent implicit. Imaginea capturata se afiseaza intro activitate
noua.

Anexa A
Codul surs

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.net.Uri;
import android.os.Environment;
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.ImageButton;
import android.widget.RadioButton;
import android.widget.SearchView;
import android.os.Handler;
import android.widget.TextView;

import java.io.File;
import java.sql.Time;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class MainActivity extends AppCompatActivity {

private int REQUEST_PHOTO = 1;


private int REQUEST_VIDEO = 2;

private Button imageButton;


private Button videoButton;
private RadioButton frontCameraRadioBtn;
private RadioButton mainCameraRadioBtn;
private NotificationManager notificationManager;
private TextView searchView;
private Button searchButton;
private File image;
private File video;
private boolean isFrontCameraSelected;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
showNotification();
}
}, TimeUnit.SECONDS.toMillis(10));
imageButton = (Button)findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image = getFile(true);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

boolean canTakePhoto = image != null &&


intent.resolveActivity(getPackageManager()) != null;
imageButton.setEnabled(canTakePhoto);
if (canTakePhoto)
{
Uri uri = Uri.fromFile(image);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

if (isFrontCameraSelected)
intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(intent, REQUEST_PHOTO);
}
}
});

videoButton = (Button)findViewById(R.id.videoButton);

videoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
video = getFile(false);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

boolean canTakeVideo = video != null &&


intent.resolveActivity(getPackageManager()) != null;
videoButton.setEnabled(canTakeVideo);
if (canTakeVideo)
{
Uri uri = Uri.fromFile(video);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

if (isFrontCameraSelected)
intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(intent, REQUEST_VIDEO);
}
}
});

isFrontCameraSelected = true;

frontCameraRadioBtn = (RadioButton)findViewById(R.id.front_camera_radio_button);
frontCameraRadioBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isFrontCameraSelected = true;
}
});

mainCameraRadioBtn = (RadioButton)findViewById(R.id.main_camera_radio_button);
mainCameraRadioBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showNotification();
isFrontCameraSelected = false;
}
});

searchView = (TextView)findViewById(R.id.search);
searchView.requestFocus();
searchView.setHint("Enter your keyword here");

searchButton = (Button)findViewById(R.id.search_button);
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("http://www.google.com/#q=" + searchView.getText());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});

notificationManager = (NotificationManager)
getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

private void showNotification(){


Notification.Builder builder= new Notification.Builder(getApplicationContext());
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentIntent(pending);
builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(),
R.drawable.ic_android_black_48dp));
builder.setSmallIcon(R.drawable.ic_android_black_48dp);
builder.setContentTitle("Lab 1 Notification");
builder.setContentText("Press this to see nothing");
builder.setAutoCancel(true);
notificationManager.notify(127, builder.build());
}
private File getFile(boolean isPhoto) {
File externalFilesDir =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

if (externalFilesDir == null)
return null;
File appDir = new File(externalFilesDir.getPath() + "/lab1");
appDir.mkdir();
if (isPhoto)
{
return new File(appDir, new Date().toString() + ".jpg");
}
else
{
return new File(appDir, new Date().toString() + ".MP4");
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == REQUEST_PHOTO) {
if (resultCode == RESULT_OK) {
Intent i=new Intent(Intent.ACTION_VIEW);

i.setDataAndType(Uri.fromFile(image), "image/jpeg");
startActivity(i);
finish();
}
} else if (requestCode == REQUEST_VIDEO) {
if (resultCode == RESULT_OK) {
Intent i=new Intent(Intent.ACTION_VIEW);

i.setDataAndType(Uri.fromFile(video), "video/*");
startActivity(i);
finish();
}
}
}