Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textToSpeech added #63

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions app/src/main/java/nsit/app/com/nsitapp/CalculatorActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package nsit.app.com.nsitapp;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
Expand All @@ -15,6 +17,7 @@
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -25,6 +28,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -67,6 +71,11 @@ public class CalculatorActivity extends Fragment {
@BindView(R.id.per) TextView resultTextView;
@BindView(R.id.button) Button b;
@BindView(R.id.buttC) Button c;
@BindView(R.id.vol) ImageView vol;

String s;
Integer k=1;
TextToSpeech ts;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use descriptive variable names


@OnClick(R.id.button)
public void onButtonBClicked(View view){
Expand All @@ -78,6 +87,17 @@ public void onButtonBClicked(View view){
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);


ts=new TextToSpeech(getContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
ts.setLanguage(Locale.getDefault());
}

}
});
}

@Override
Expand Down Expand Up @@ -106,6 +126,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);





sanket099 marked this conversation as resolved.
Show resolved Hide resolved

semSpinner.setAdapter(adapter1);
semSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
Expand Down Expand Up @@ -1401,7 +1425,33 @@ private void onCalculate(View a) {
break;
}




resultTextView.setText(String.format("%.2f ", p));
s= resultTextView.getText().toString();

vol.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (k==1){
k=0;
vol.setImageResource(R.drawable.vol_off);


}
else{
k=1;
vol.setImageResource(R.drawable.vol_on);
}
}
});
if (k==1){
ts.speak(s,TextToSpeech.QUEUE_FLUSH,null);

}


if (f == 1)
addToStorage();

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/vol_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v2.21l2.45,2.45c0.03,-0.2 0.05,-0.41 0.05,-0.63zM19,12c0,0.94 -0.2,1.82 -0.54,2.64l1.51,1.51C20.63,14.91 21,13.5 21,12c0,-4.28 -2.99,-7.86 -7,-8.77v2.06c2.89,0.86 5,3.54 5,6.71zM4.27,3L3,4.27 7.73,9L3,9v6h4l5,5v-6.73l4.25,4.25c-0.67,0.52 -1.42,0.93 -2.25,1.18v2.06c1.38,-0.31 2.63,-0.95 3.69,-1.81L19.73,21 21,19.73l-9,-9L4.27,3zM12,4L9.91,6.09 12,8.18L12,4z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/vol_on.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,9v6h4l5,5L12,4L7,9L3,9zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77s-2.99,-7.86 -7,-8.77z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/layout-land/activity_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
Expand Down Expand Up @@ -366,6 +368,14 @@

android:textSize="30dp" />
</LinearLayout>
<ImageView
android:id="@+id/vol"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_margin="10dp"
android:clickable="true"
app:srcCompat="@drawable/vol_on" />


</LinearLayout>
</ScrollView>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_calculator.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand Down Expand Up @@ -451,6 +452,16 @@
android:textSize="30dp" />
</LinearLayout>

<ImageView
android:id="@+id/vol"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_margin="10dp"
android:clickable="true"
app:srcCompat="@drawable/vol_on" />



</LinearLayout>
</ScrollView>

Expand Down