Commit 1526e0f2 by Kunj Gupta

Fixed - Permission crash issue.

parent e88590d9
package com.vsoft.servicenow.chat; package com.vsoft.servicenow.chat;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
...@@ -20,11 +17,9 @@ import android.text.TextUtils; ...@@ -20,11 +17,9 @@ import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
...@@ -38,7 +33,6 @@ import com.vsoft.servicenow.R; ...@@ -38,7 +33,6 @@ import com.vsoft.servicenow.R;
import com.vsoft.servicenow.speechRecognizer.DroidSpeech; import com.vsoft.servicenow.speechRecognizer.DroidSpeech;
import com.vsoft.servicenow.speechRecognizer.OnDSListener; import com.vsoft.servicenow.speechRecognizer.OnDSListener;
import com.vsoft.servicenow.speechRecognizer.OnDSPermissionsListener; import com.vsoft.servicenow.speechRecognizer.OnDSPermissionsListener;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONException; import org.json.JSONException;
...@@ -47,8 +41,6 @@ import org.json.JSONObject; ...@@ -47,8 +41,6 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static android.app.Activity.RESULT_OK;
/** /**
* A chat Activity containing messages view and input form. * A chat Activity containing messages view and input form.
...@@ -167,7 +159,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -167,7 +159,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
} }
}); });
droidSpeech = new DroidSpeech(this, getFragmentManager()); droidSpeech = new DroidSpeech(this, getSupportFragmentManager());
droidSpeech.setOnDroidSpeechListener(this); droidSpeech.setOnDroidSpeechListener(this);
droidSpeech.setShowRecognitionProgressView(true); droidSpeech.setShowRecognitionProgressView(true);
...@@ -229,7 +221,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -229,7 +221,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
} }
private void addMessage(String username, String message) { private void addMessage(String username, String message) {
CatalogueLog.e("message: "+message);
if(username.isEmpty() || message.isEmpty()) if(username.isEmpty() || message.isEmpty())
return; return;
if(CURRENT_STATE == VOICE_STATE && !username.equals(PrefManager.getSharedPref(this, PrefManager.PREFERENCE_FIRST_NAME))) { if(CURRENT_STATE == VOICE_STATE && !username.equals(PrefManager.getSharedPref(this, PrefManager.PREFERENCE_FIRST_NAME))) {
...@@ -402,9 +393,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -402,9 +393,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
Log.e(TAG, e.getMessage()); Log.e(TAG, e.getMessage());
return; return;
} }
// addLog(getResources().getString(R.string.message_user_left, username));
// addParticipantsLog(numUsers);
removeTyping(username); removeTyping(username);
} }
}); });
...@@ -493,7 +481,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -493,7 +481,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() { speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override @Override
public void onDone(String utteranceId) { public void onDone(String utteranceId) {
Log.e("MainActivity", "onDone: Continuous: "+droidSpeech.getContinuousSpeechRecognition());
if (droidSpeech != null) { if (droidSpeech != null) {
if(speaker != null && speaker.isSpeaking()) { if(speaker != null && speaker.isSpeaking()) {
speaker.stop(); speaker.stop();
...@@ -510,12 +497,10 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -510,12 +497,10 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void onError(String utteranceId) { public void onError(String utteranceId) {
Log.e("MainActivity", "onError");
} }
@Override @Override
public void onStart(String utteranceId) { public void onStart(String utteranceId) {
Log.e("MainActivity", "onStart");
if (droidSpeech != null) { if (droidSpeech != null) {
droidSpeech.closeDroidSpeechOperations(); droidSpeech.closeDroidSpeechOperations();
} }
...@@ -538,7 +523,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -538,7 +523,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
RecyclerView.OnItemTouchListener mOnItemTouchListener = new RecyclerView.OnItemTouchListener() { RecyclerView.OnItemTouchListener mOnItemTouchListener = new RecyclerView.OnItemTouchListener() {
@Override @Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
CatalogueLog.e("onInterceptTouchEvent");
if(speaker != null && speaker.isSpeaking()) { if(speaker != null && speaker.isSpeaking()) {
speaker.stop(); speaker.stop();
if(droidSpeech != null) { if(droidSpeech != null) {
...@@ -609,21 +593,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -609,21 +593,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
// Permissions error // Permissions error
Toast.makeText(this, errorMsgIfAny, Toast.LENGTH_LONG).show(); Toast.makeText(this, errorMsgIfAny, Toast.LENGTH_LONG).show();
} }
// stop.post(new Runnable() {
// @Override
// public void run() {
// // Stop listening
// stop.performClick();
// }
// });
} }
} }
// @Override
// public void onBackPressed() {
// super.onBackPressed();
// finish();
// }
} }
...@@ -8,7 +8,7 @@ import java.util.Random; ...@@ -8,7 +8,7 @@ import java.util.Random;
/** /**
* AnimatorBarRms * AnimatorBarRms
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class AnimatorBarRms implements OnBarParamsAnimListener { class AnimatorBarRms implements OnBarParamsAnimListener {
......
...@@ -5,7 +5,7 @@ import java.util.List; ...@@ -5,7 +5,7 @@ import java.util.List;
/** /**
* AnimatorIdle * AnimatorIdle
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class AnimatorIdle implements OnBarParamsAnimListener { class AnimatorIdle implements OnBarParamsAnimListener {
......
...@@ -6,7 +6,7 @@ import java.util.List; ...@@ -6,7 +6,7 @@ import java.util.List;
/** /**
* AnimatorRms * AnimatorRms
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class AnimatorRms implements OnBarParamsAnimListener { class AnimatorRms implements OnBarParamsAnimListener {
......
...@@ -9,7 +9,7 @@ import java.util.List; ...@@ -9,7 +9,7 @@ import java.util.List;
/** /**
* AnimatorRotating * AnimatorRotating
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class AnimatorRotating implements OnBarParamsAnimListener { class AnimatorRotating implements OnBarParamsAnimListener {
......
...@@ -8,7 +8,7 @@ import java.util.List; ...@@ -8,7 +8,7 @@ import java.util.List;
/** /**
* AnimatorTransform * AnimatorTransform
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class AnimatorTransform implements OnBarParamsAnimListener { class AnimatorTransform implements OnBarParamsAnimListener {
......
...@@ -4,7 +4,6 @@ import android.annotation.SuppressLint; ...@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
...@@ -17,7 +16,7 @@ import android.os.Handler; ...@@ -17,7 +16,7 @@ import android.os.Handler;
import android.speech.RecognitionListener; import android.speech.RecognitionListener;
import android.speech.RecognizerIntent; import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer; import android.speech.SpeechRecognizer;
import android.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -33,7 +32,7 @@ import java.util.List; ...@@ -33,7 +32,7 @@ import java.util.List;
/** /**
* Droid Speech * Droid Speech
* *
* @author Vikram Ezhil * @author Kunj
*/ */
public class DroidSpeech { public class DroidSpeech {
...@@ -170,35 +169,6 @@ public class DroidSpeech { ...@@ -170,35 +169,6 @@ public class DroidSpeech {
recognitionProgressView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, Extensions.PV_HEIGHT)); recognitionProgressView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, Extensions.PV_HEIGHT));
recognitionProgressMsg = speechProgressView.findViewById(R.id.recognitionProgressMsg); recognitionProgressMsg = speechProgressView.findViewById(R.id.recognitionProgressMsg);
// confirmLayout = speechProgressView.findViewById(R.id.confirmLayout);
// confirm = speechProgressView.findViewById(R.id.confirm);
// confirm.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//
// // Sending an update with the droid speech result
// droidSpeechListener.onDroidSpeechFinalResult(dsProperties.oneStepVerifySpeechResult);
//
// if (dsProperties.continuousSpeechRecognition) {
// // Start droid speech recognition again
// startDroidSpeechRecognition();
// } else {
// // Closing the droid speech operations entirely
// closeDroidSpeechOperations();
// }
// }
// });
//
// retry = speechProgressView.findViewById(R.id.retry);
// retry.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//
// // Start droid speech recognition again as user didn't
// // get the desired result
// startDroidSpeechRecognition();
// }
// });
speechProgressAlertDialog = speechProgressBuilder.create(); speechProgressAlertDialog = speechProgressBuilder.create();
speechProgressAlertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); speechProgressAlertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
......
package com.vsoft.servicenow.speechRecognizer; package com.vsoft.servicenow.speechRecognizer;
import android.Manifest; import android.Manifest;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.vsoft.servicenow.R; import com.vsoft.servicenow.R;
/** /**
* Droid Speech Permissions - Non UI Fragment * Droid Speech Permissions - Non UI Fragment
* *
* @author Vikram Ezhil * @author Kunj
*/ */
public class DroidSpeechPermissions extends Fragment { public class DroidSpeechPermissions extends Fragment {
...@@ -62,23 +62,18 @@ public class DroidSpeechPermissions extends Fragment { ...@@ -62,23 +62,18 @@ public class DroidSpeechPermissions extends Fragment {
@Override @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) { switch (requestCode) {
case REQUEST_AUDIO_PERMISSIONS: case REQUEST_AUDIO_PERMISSIONS:
for (int result : grantResults) { for (int result : grantResults) {
if (result != PackageManager.PERMISSION_GRANTED) { if (result != PackageManager.PERMISSION_GRANTED) {
// Audio permission not granted // Audio permission not granted
// if(droidSpeechPermissionsListener != null)
droidSpeechPermissionsListener.onDroidSpeechAudioPermissionStatus(false, getResources().getString(R.string.ds_mic_permissions_required)); droidSpeechPermissionsListener.onDroidSpeechAudioPermissionStatus(false, getResources().getString(R.string.ds_mic_permissions_required));
return; return;
} }
} }
// Audio permission granted // Audio permission granted
droidSpeechPermissionsListener.onDroidSpeechAudioPermissionStatus(true, null); droidSpeechPermissionsListener.onDroidSpeechAudioPermissionStatus(true, null);
break; break;
} }
} }
......
...@@ -8,7 +8,7 @@ import android.net.NetworkInfo; ...@@ -8,7 +8,7 @@ import android.net.NetworkInfo;
/** /**
* Droid Speech Extensions * Droid Speech Extensions
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class Extensions { class Extensions {
......
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
/** /**
* Droid Speech Language Receiver * Droid Speech Language Receiver
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class LanguageReceiver extends BroadcastReceiver { class LanguageReceiver extends BroadcastReceiver {
......
...@@ -3,7 +3,7 @@ package com.vsoft.servicenow.speechRecognizer; ...@@ -3,7 +3,7 @@ package com.vsoft.servicenow.speechRecognizer;
/** /**
* Bar Animation Listener * Bar Animation Listener
* *
* @author Vikram Ezhil * @author Kunj
*/ */
interface OnBarParamsAnimListener { interface OnBarParamsAnimListener {
......
...@@ -5,7 +5,7 @@ import java.util.List; ...@@ -5,7 +5,7 @@ import java.util.List;
/** /**
* Droid Speech Listener * Droid Speech Listener
* *
* @author Vikram Ezhil * @author Kunj
*/ */
public interface OnDSListener { public interface OnDSListener {
......
...@@ -3,7 +3,7 @@ package com.vsoft.servicenow.speechRecognizer; ...@@ -3,7 +3,7 @@ package com.vsoft.servicenow.speechRecognizer;
/** /**
* Droid Speech Permissions Listener * Droid Speech Permissions Listener
* *
* @author Vikram Ezhil * @author Kunj
*/ */
public interface OnDSPermissionsListener { public interface OnDSPermissionsListener {
......
...@@ -5,7 +5,7 @@ import java.util.List; ...@@ -5,7 +5,7 @@ import java.util.List;
/** /**
* Droid Speech Language Details Listener * Droid Speech Language Details Listener
* *
* @author Vikram Ezhil * @author Kunj
*/ */
interface OnLanguageDetailsListener { interface OnLanguageDetailsListener {
......
...@@ -6,7 +6,7 @@ import java.util.List; ...@@ -6,7 +6,7 @@ import java.util.List;
/** /**
* Droid Speech Properties * Droid Speech Properties
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class Properties { class Properties {
......
...@@ -5,7 +5,7 @@ import android.graphics.RectF; ...@@ -5,7 +5,7 @@ import android.graphics.RectF;
/** /**
* Recognition Bar View * Recognition Bar View
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class RecognitionBarView { class RecognitionBarView {
......
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
/** /**
* Recognition Progress View * Recognition Progress View
* *
* @author Vikram Ezhil * @author Kunj
*/ */
class RecognitionProgressView extends View { class RecognitionProgressView extends View {
......
...@@ -33,7 +33,6 @@ import butterknife.OnItemClick; ...@@ -33,7 +33,6 @@ import butterknife.OnItemClick;
public class HomeScreen extends AppCompatActivity { public class HomeScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar; @BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view) GridView mGridView; @BindView(R.id.home_screen_grid_view) GridView mGridView;
private Socket mSocket;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -42,9 +41,6 @@ public class HomeScreen extends AppCompatActivity { ...@@ -42,9 +41,6 @@ public class HomeScreen extends AppCompatActivity {
setContentView(R.layout.home_screen); setContentView(R.layout.home_screen);
CatalogueApplication app = (CatalogueApplication) getApplication(); CatalogueApplication app = (CatalogueApplication) getApplication();
mSocket = app.getSocket();
ButterKnife.bind(this); ButterKnife.bind(this);
...@@ -58,14 +54,6 @@ public class HomeScreen extends AppCompatActivity { ...@@ -58,14 +54,6 @@ public class HomeScreen extends AppCompatActivity {
TypedArray gridViewIcons = getResources().obtainTypedArray(R.array.home_screen_icon_array); TypedArray gridViewIcons = getResources().obtainTypedArray(R.array.home_screen_icon_array);
HomeScreenAdapter adapter = new HomeScreenAdapter(this, gridValuesArray, gridViewIcons); HomeScreenAdapter adapter = new HomeScreenAdapter(this, gridValuesArray, gridViewIcons);
mGridView.setAdapter(adapter); mGridView.setAdapter(adapter);
// mSocket.on("login", onLogin);
}
@Override
protected void onDestroy() {
super.onDestroy();
// mSocket.off("login", onLogin);
} }
@OnItemClick(R.id.home_screen_grid_view) @OnItemClick(R.id.home_screen_grid_view)
...@@ -81,10 +69,6 @@ public class HomeScreen extends AppCompatActivity { ...@@ -81,10 +69,6 @@ public class HomeScreen extends AppCompatActivity {
} else if (position == 4) { } else if (position == 4) {
// perform the user login attempt. // perform the user login attempt.
String userFirstName = PrefManager.getSharedPref(HomeScreen.this, PrefManager.PREFERENCE_FIRST_NAME); String userFirstName = PrefManager.getSharedPref(HomeScreen.this, PrefManager.PREFERENCE_FIRST_NAME);
// CatalogueLog.e("Socket is connect: "+mSocket.connected());
// if(!mSocket.connected())
// mSocket.connect();
// mSocket.emit("add user", userFirstName);
Intent intent = new Intent(HomeScreen.this, ChatActivity.class); Intent intent = new Intent(HomeScreen.this, ChatActivity.class);
intent.putExtra("username", userFirstName); intent.putExtra("username", userFirstName);
startActivity(intent); startActivity(intent);
...@@ -119,24 +103,4 @@ public class HomeScreen extends AppCompatActivity { ...@@ -119,24 +103,4 @@ public class HomeScreen extends AppCompatActivity {
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
} }
private Emitter.Listener onLogin = new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject data = (JSONObject) args[0];
int numUsers;
try {
numUsers = data.getInt("numUsers");
} catch (JSONException e) {
return;
}
Intent intent = new Intent();
intent.putExtra("username", PrefManager.getSharedPref(HomeScreen.this, PrefManager.PREFERENCE_FIRST_NAME));
intent.putExtra("numUsers", numUsers);
setResult(RESULT_OK, intent);
finish();
}
};
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment