diff --git a/.idea/.name b/.idea/.name index a45e357..d90b2f0 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -Password Manager \ No newline at end of file +PasswordManager-master \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 00a4ff6..2470b19 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/PasswordManager-master.iml b/PasswordManager-master.iml new file mode 100644 index 0000000..615adcf --- /dev/null +++ b/PasswordManager-master.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 9dddc5d..c2c44c7 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 73d054c..b1da8ac 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,6 +6,9 @@ + + + + + + + diff --git a/app/src/main/java/osu/passwordmanager/CameraPreview.java b/app/src/main/java/osu/passwordmanager/CameraPreview.java new file mode 100644 index 0000000..ab022dd --- /dev/null +++ b/app/src/main/java/osu/passwordmanager/CameraPreview.java @@ -0,0 +1,55 @@ +package osu.passwordmanager; + +import android.content.Context; +import android.hardware.Camera; +import android.view.SurfaceHolder; +import android.view.SurfaceView; + +import java.io.IOException; + +/** + * Created by Tom on 11/24/2015. + */ +public class CameraPreview extends SurfaceView implements + SurfaceHolder.Callback { + private SurfaceHolder mSurfaceHolder; + private Camera mCamera; + + // Constructor that obtains context and camera + @SuppressWarnings("deprecation") + public CameraPreview(Context context, Camera camera) { + super(context); + this.mCamera = camera; + this.mSurfaceHolder = this.getHolder(); + this.mSurfaceHolder.addCallback(this); + this.mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); + } + + @Override + public void surfaceCreated(SurfaceHolder surfaceHolder) { + try { + mCamera.setPreviewDisplay(surfaceHolder); + mCamera.startPreview(); + } catch (IOException e) { + // left blank for now + } + } + + @Override + public void surfaceDestroyed(SurfaceHolder surfaceHolder) { + mCamera.stopPreview(); + mCamera.release(); + } + + @Override + public void surfaceChanged(SurfaceHolder surfaceHolder, int format, + int width, int height) { + // start preview with new settings + try { + mCamera.setPreviewDisplay(surfaceHolder); + mCamera.startPreview(); + } catch (Exception e) { + // intentionally left blank for a test + } + } +} \ No newline at end of file diff --git a/app/src/main/java/osu/passwordmanager/ImageActivity.java b/app/src/main/java/osu/passwordmanager/ImageActivity.java new file mode 100644 index 0000000..51849f0 --- /dev/null +++ b/app/src/main/java/osu/passwordmanager/ImageActivity.java @@ -0,0 +1,112 @@ +package osu.passwordmanager; + +import android.os.Bundle; +import android.os.Environment; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.hardware.Camera; +import android.hardware.Camera.*; + +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.Toast; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +@SuppressWarnings("deprecation") +public class ImageActivity extends AppCompatActivity { + + private Camera mCamera; + private CameraPreview mCameraPreview; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_image); + + mCamera = getCameraInstance(); + mCamera.setDisplayOrientation(90); + mCameraPreview = new CameraPreview(this, mCamera); + FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); + preview.addView(mCameraPreview); + + Button captureButton = (Button) findViewById(R.id.button_capture); + captureButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mCamera.takePicture(null, null, mPicture); + } + }); + } + + /** + * Helper method to access the camera returns null if it cannot get the + * camera or does not exist + * + * @return + */ + private Camera getCameraInstance() { + int cameraCount = 0; + Camera cam = null; + Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); + cameraCount = Camera.getNumberOfCameras(); + for (int camIdx = 0; camIdx < cameraCount; camIdx++) { + Camera.getCameraInfo(camIdx, cameraInfo); + if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { + try { + cam = Camera.open(camIdx); + } catch (RuntimeException e) { + Toast.makeText(this, "Front Camera not working", + Toast.LENGTH_SHORT).show(); + } + } + } + + return cam; + } + + PictureCallback mPicture = new PictureCallback() { + @Override + public void onPictureTaken(byte[] data, Camera camera) { + File pictureFile = getOutputMediaFile(); + if (pictureFile == null) { + return; + } + try { + FileOutputStream fos = new FileOutputStream(pictureFile); + fos.write(data); + fos.close(); + } catch (FileNotFoundException e) { + + } catch (IOException e) { + } + } + }; + + private static File getOutputMediaFile() { + File mediaStorageDir = new File( + Environment + .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), + "MyCameraApp"); + if (!mediaStorageDir.exists()) { + if (!mediaStorageDir.mkdirs()) { + Log.d("MyCameraApp", "failed to create directory"); + return null; + } + } + // Create a media file name + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") + .format(new Date()); + File mediaFile; + mediaFile = new File(mediaStorageDir.getPath() + File.separator + + "IMG_" + timeStamp + ".jpg"); + + return mediaFile; + } + } \ No newline at end of file diff --git a/app/src/main/java/osu/passwordmanager/LoginActivity.java b/app/src/main/java/osu/passwordmanager/LoginActivity.java index 3355145..d5fac75 100644 --- a/app/src/main/java/osu/passwordmanager/LoginActivity.java +++ b/app/src/main/java/osu/passwordmanager/LoginActivity.java @@ -149,50 +149,55 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis * errors are presented and no actual login attempt is made. */ private void attemptLogin() { - if (mAuthTask != null) { - return; - } - - // Reset errors. - mEmailView.setError(null); - mPasswordView.setError(null); - // Store values at the time of the login attempt. - String email = mEmailView.getText().toString(); - String password = mPasswordView.getText().toString(); - - boolean cancel = false; - View focusView = null; - - // Check for a valid password, if the user entered one. - if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { - mPasswordView.setError(getString(R.string.error_invalid_password)); - focusView = mPasswordView; - cancel = true; - } - - // Check for a valid email address. - if (TextUtils.isEmpty(email)) { - mEmailView.setError(getString(R.string.error_field_required)); - focusView = mEmailView; - cancel = true; - } else if (!isEmailValid(email)) { - mEmailView.setError(getString(R.string.error_invalid_email)); - focusView = mEmailView; - cancel = true; - } - - if (cancel) { - // There was an error; don't attempt login and focus the first - // form field with an error. - focusView.requestFocus(); - } else { - // Show a progress spinner, and kick off a background task to - // perform the user login attempt. - showProgress(true); - mAuthTask = new UserLoginTask(email, password); - mAuthTask.execute((Void) null); - } + Intent i = new Intent(getBaseContext(), ImageActivity.class); + //i.putExtra("PersonID", personID); + startActivity(i); +// +// if (mAuthTask != null) { +// return; +// } +// +// // Reset errors. +// mEmailView.setError(null); +// mPasswordView.setError(null); +// +// // Store values at the time of the login attempt. +// String email = mEmailView.getText().toString(); +// String password = mPasswordView.getText().toString(); +// +// boolean cancel = false; +// View focusView = null; +// +// // Check for a valid password, if the user entered one. +// if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { +// mPasswordView.setError(getString(R.string.error_invalid_password)); +// focusView = mPasswordView; +// cancel = true; +// } +// +// // Check for a valid email address. +// if (TextUtils.isEmpty(email)) { +// mEmailView.setError(getString(R.string.error_field_required)); +// focusView = mEmailView; +// cancel = true; +// } else if (!isEmailValid(email)) { +// mEmailView.setError(getString(R.string.error_invalid_email)); +// focusView = mEmailView; +// cancel = true; +// } +// +// if (cancel) { +// // There was an error; don't attempt login and focus the first +// // form field with an error. +// focusView.requestFocus(); +// } else { +// // Show a progress spinner, and kick off a background task to +// // perform the user login attempt. +// showProgress(true); +// mAuthTask = new UserLoginTask(email, password); +// mAuthTask.execute((Void) null); +// } } private boolean isEmailValid(String email) { diff --git a/app/src/main/java/osu/passwordmanager/VoiceActivity.java b/app/src/main/java/osu/passwordmanager/VoiceActivity.java new file mode 100644 index 0000000..869233e --- /dev/null +++ b/app/src/main/java/osu/passwordmanager/VoiceActivity.java @@ -0,0 +1,144 @@ +package osu.passwordmanager; + +import android.os.Bundle; +import android.speech.RecognizerIntent; +import android.view.View; +import android.app.Activity; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.view.View.OnClickListener; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; + +import java.util.ArrayList; +import java.util.List; + +import android.app.SearchManager; +import android.widget.AdapterView; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; + + +public class VoiceActivity extends Activity implements OnClickListener { + + private static final int VOICE_RECOGNITION_REQUEST_CODE = 1001; + + private EditText metTextHint; + private ListView mlvTextMatches; + private Spinner msTextMatches; + private Button mbtSpeak; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_voice); + metTextHint = (EditText) findViewById(R.id.etTextHint); + mlvTextMatches = (ListView) findViewById(R.id.lvTextMatches); + msTextMatches = (Spinner) findViewById(R.id.sNoOfMatches); + mbtSpeak = (Button) findViewById(R.id.btSpeak); + checkVoiceRecognition(); + } + + public void checkVoiceRecognition() { + // Check if voice recognition is present + PackageManager pm = getPackageManager(); + List activities = pm.queryIntentActivities(new Intent( + RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); + if (activities.size() == 0) { + mbtSpeak.setEnabled(false); + mbtSpeak.setText("Voice recognizer not present"); + Toast.makeText(this, "Voice recognizer not present", + Toast.LENGTH_SHORT).show(); + } + } + public void onClick(View v) { + if (v.getId() == R.id.btSpeak) { + + } + } + + public void speak(View view) { + Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); + + // Specify the calling package to identify your application + intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass() + .getPackage().getName()); + + // Display an hint to the user about what he should say. + intent.putExtra(RecognizerIntent.EXTRA_PROMPT, metTextHint.getText() + .toString()); + + // Given an hint to the recognizer about what the user is going to say + //There are two form of language model available + //1.LANGUAGE_MODEL_WEB_SEARCH : For short phrases + //2.LANGUAGE_MODEL_FREE_FORM : If not sure about the words or phrases and its domain. + intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, + RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); + + // If number of Matches is not selected then return show toast message + if (msTextMatches.getSelectedItemPosition() == AdapterView.INVALID_POSITION) { + Toast.makeText(this, "Please select No. of Matches from spinner", + Toast.LENGTH_SHORT).show(); + return; + } + + int noOfMatches = Integer.parseInt(msTextMatches.getSelectedItem() + .toString()); + // Specify how many results you want to receive. The results will be + // sorted where the first result is the one with higher confidence. + intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, noOfMatches); + //Start the Voice recognizer activity for the result. + startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) + + //If Voice recognition is successful then it returns RESULT_OK + if(resultCode == RESULT_OK) { + + ArrayList textMatchList = data + .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); + + if (!textMatchList.isEmpty()) { + // If first Match contains the 'search' word + // Then start web search. + if (textMatchList.get(0).contains("search")) { + + String searchQuery = textMatchList.get(0); + searchQuery = searchQuery.replace("search",""); + Intent search = new Intent(Intent.ACTION_WEB_SEARCH); + search.putExtra(SearchManager.QUERY, searchQuery); + startActivity(search); + } else { + // populate the Matches + mlvTextMatches + .setAdapter(new ArrayAdapter(this, + android.R.layout.simple_list_item_1, + textMatchList)); + } + + } + //Result code for various error. + }else if(resultCode == RecognizerIntent.RESULT_AUDIO_ERROR){ + showToastMessage("Audio Error"); + }else if(resultCode == RecognizerIntent.RESULT_CLIENT_ERROR){ + showToastMessage("Client Error"); + }else if(resultCode == RecognizerIntent.RESULT_NETWORK_ERROR){ + showToastMessage("Network Error"); + }else if(resultCode == RecognizerIntent.RESULT_NO_MATCH){ + showToastMessage("No Match"); + }else if(resultCode == RecognizerIntent.RESULT_SERVER_ERROR){ + showToastMessage("Server Error"); + } + super.onActivityResult(requestCode, resultCode, data); + } + + void showToastMessage(String message){ + Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); + } + } diff --git a/app/src/main/res/layout/activity_image.xml b/app/src/main/res/layout/activity_image.xml new file mode 100644 index 0000000..13f15bb --- /dev/null +++ b/app/src/main/res/layout/activity_image.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/app/src/main/res/layout/activity_voice.xml b/app/src/main/res/layout/activity_voice.xml new file mode 100644 index 0000000..7d056e2 --- /dev/null +++ b/app/src/main/res/layout/activity_voice.xml @@ -0,0 +1,54 @@ + + + + + + + +