Skip to content

Commit

Permalink
added progressBar and audio
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityaguptaa committed Aug 7, 2020
1 parent fe1785e commit e924b10
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
34 changes: 34 additions & 0 deletions app/src/main/java/com/example/meaning4/PlayAudioManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.meaning4;

import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;

public class PlayAudioManager {
private static MediaPlayer mediaPlayer;

public static void playAudio(final Context context, final String url) throws Exception {
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(context, Uri.parse(url));
}
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
killMediaPlayer();
}
});
mediaPlayer.start();
}

private static void killMediaPlayer() {
if (mediaPlayer != null) {
try {
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
33 changes: 31 additions & 2 deletions app/src/main/java/com/example/meaning4/findMeaning.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.loader.content.Loader;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.common.io.ByteStreams;
Expand All @@ -23,10 +24,13 @@
import java.util.concurrent.ExecutionException;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
Expand All @@ -38,6 +42,7 @@
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import org.json.JSONArray;
Expand All @@ -47,6 +52,8 @@
import static com.example.meaning4.R.id.bottomSheet;
import static com.example.meaning4.R.id.etydef;
import static com.example.meaning4.R.id.etymologies;
import static com.example.meaning4.R.id.gone;
import static com.example.meaning4.R.id.invisible;
import static com.example.meaning4.R.id.wordsheet;

public class findMeaning extends AppCompatActivity {
Expand All @@ -62,6 +69,7 @@ public class findMeaning extends AppCompatActivity {
static final int REQUEST_IMAGE_CAPTURE = 1;
static final int REQUEST_TAKE_PHOTO = 1;
public String currentPhotoPath;
public String audioUri;



Expand All @@ -88,6 +96,18 @@ public void onClick(View v) {
}
});

ImageView audioPlay = findViewById((R.id.speaker));
audioPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
PlayAudioManager.playAudio(findMeaning.this, audioUri);
}catch (Exception e){
Log.i("Errororororo", e.toString());
}
}
});

//Request For Camera Permission
if(ContextCompat.checkSelfPermission(findMeaning.this, Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(findMeaning.this, new String[]{
Expand Down Expand Up @@ -151,6 +171,7 @@ public void onClick(View v) {
JSONArray audioLinkarray = etye.getJSONArray("pronunciations");
JSONObject audioLinkObject = audioLinkarray.getJSONObject(0);
String audioLink = audioLinkObject.getString("audioFile");
audioUri = audioLink;
JSONArray definitionarray = etye.getJSONArray("senses");
JSONObject definitionObject = definitionarray.getJSONObject(0);
JSONArray firstdefArr = definitionObject.getJSONArray("definitions");
Expand Down Expand Up @@ -237,12 +258,19 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
mSelectedImage = Bitmap.createScaledBitmap(bitmap, im.getWidth(), im.getHeight(), true);
im.setImageBitmap(mSelectedImage);

AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@SuppressLint("WrongThread")
@Override
protected Void doInBackground(Void... voids) {
ProgressBar progressBar = findViewById(R.id.indeterminateBar);

progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(5);
ComputerVisionClient compVisClient = ComputerVisionManager.authenticate(subscriptionKey).withEndpoint(endpoint);
Log.i("a", "\nAzure Cognitive Services Computer Vision - Java Quickstart Sample");
RecognizeTextOCRLocal(compVisClient);
progressBar.setVisibility(View.INVISIBLE);

return null;
}
};
Expand Down Expand Up @@ -303,9 +331,9 @@ public void RecognizeTextOCRLocal(ComputerVisionClient client) {
try {
byte[] localImageBytes = ByteStreams.toByteArray(inputStream);

// Recognize printed text in local image
OcrResult ocrResultLocal = client.computerVision().recognizePrintedTextInStream()
.withDetectOrientation(true).withImage(localImageBytes).withLanguage(OcrLanguages.EN).execute();

Log.i("a", "\n");
Log.i("a", "Recognizing printed text from a local image with OCR ...");
Log.i("a", "\nLanguage: " + ocrResultLocal.language());
Expand Down Expand Up @@ -338,6 +366,7 @@ public void RecognizeTextOCRLocal(ComputerVisionClient client) {
}
Log.i("a", "\n");
}

}
}catch (Exception e){
Log.i("a", e.toString());
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/layout/activity_find_meaning.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
Expand Down Expand Up @@ -93,6 +94,22 @@
app:layout_constraintVertical_bias="1.0"
app:srcCompat="@drawable/ic_add_black_48dp" />

<ProgressBar
android:id="@+id/indeterminateBar"
style="@android:style/Widget.Material.Light.ProgressBar"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#00FFFFFF"
android:indeterminate="true"
android:indeterminateTint="#110106"
android:indeterminateTintMode="src_atop"
android:progressBackgroundTintMode="multiply"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/image98" />

</androidx.constraintlayout.widget.ConstraintLayout>

<include layout="@layout/bottom_sheet_persistent" />
Expand Down

0 comments on commit e924b10

Please sign in to comment.