Commit 1526e0f2 by Kunj Gupta

Fixed - Permission crash issue.

parent e88590d9
package com.vsoft.servicenow.chat;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
......@@ -20,11 +17,9 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageButton;
......@@ -38,7 +33,6 @@ import com.vsoft.servicenow.R;
import com.vsoft.servicenow.speechRecognizer.DroidSpeech;
import com.vsoft.servicenow.speechRecognizer.OnDSListener;
import com.vsoft.servicenow.speechRecognizer.OnDSPermissionsListener;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONException;
......@@ -47,8 +41,6 @@ import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import static android.app.Activity.RESULT_OK;
/**
* A chat Activity containing messages view and input form.
......@@ -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.setShowRecognitionProgressView(true);
......@@ -229,7 +221,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
private void addMessage(String username, String message) {
CatalogueLog.e("message: "+message);
if(username.isEmpty() || message.isEmpty())
return;
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
Log.e(TAG, e.getMessage());
return;
}
// addLog(getResources().getString(R.string.message_user_left, username));
// addParticipantsLog(numUsers);
removeTyping(username);
}
});
......@@ -493,7 +481,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onDone(String utteranceId) {
Log.e("MainActivity", "onDone: Continuous: "+droidSpeech.getContinuousSpeechRecognition());
if (droidSpeech != null) {
if(speaker != null && speaker.isSpeaking()) {
speaker.stop();
......@@ -510,12 +497,10 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override
public void onError(String utteranceId) {
Log.e("MainActivity", "onError");
}
@Override
public void onStart(String utteranceId) {
Log.e("MainActivity", "onStart");
if (droidSpeech != null) {
droidSpeech.closeDroidSpeechOperations();
}
......@@ -538,7 +523,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
RecyclerView.OnItemTouchListener mOnItemTouchListener = new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
CatalogueLog.e("onInterceptTouchEvent");
if(speaker != null && speaker.isSpeaking()) {
speaker.stop();
if(droidSpeech != null) {
......@@ -609,21 +593,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
// Permissions error
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;
/**
* AnimatorBarRms
*
* @author Vikram Ezhil
* @author Kunj
*/
class AnimatorBarRms implements OnBarParamsAnimListener {
......
......@@ -5,7 +5,7 @@ import java.util.List;
/**
* AnimatorIdle
*
* @author Vikram Ezhil
* @author Kunj
*/
class AnimatorIdle implements OnBarParamsAnimListener {
......
......@@ -6,7 +6,7 @@ import java.util.List;
/**
* AnimatorRms
*
* @author Vikram Ezhil
* @author Kunj
*/
class AnimatorRms implements OnBarParamsAnimListener {
......
......@@ -9,7 +9,7 @@ import java.util.List;
/**
* AnimatorRotating
*
* @author Vikram Ezhil
* @author Kunj
*/
class AnimatorRotating implements OnBarParamsAnimListener {
......
......@@ -8,7 +8,7 @@ import java.util.List;
/**
* AnimatorTransform
*
* @author Vikram Ezhil
* @author Kunj
*/
class AnimatorTransform implements OnBarParamsAnimListener {
......
......@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
......@@ -17,7 +16,7 @@ import android.os.Handler;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.app.FragmentManager;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
......@@ -33,7 +32,7 @@ import java.util.List;
/**
* Droid Speech
*
* @author Vikram Ezhil
* @author Kunj
*/
public class DroidSpeech {
......@@ -170,35 +169,6 @@ public class DroidSpeech {
recognitionProgressView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, Extensions.PV_HEIGHT));
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.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
......
package com.vsoft.servicenow.speechRecognizer;
import android.Manifest;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.vsoft.servicenow.R;
/**
* Droid Speech Permissions - Non UI Fragment
*
* @author Vikram Ezhil
* @author Kunj
*/
public class DroidSpeechPermissions extends Fragment {
......@@ -62,23 +62,18 @@ public class DroidSpeechPermissions extends Fragment {
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_AUDIO_PERMISSIONS:
for (int result : grantResults) {
if (result != PackageManager.PERMISSION_GRANTED) {
// Audio permission not granted
// if(droidSpeechPermissionsListener != null)
droidSpeechPermissionsListener.onDroidSpeechAudioPermissionStatus(false, getResources().getString(R.string.ds_mic_permissions_required));
return;
}
}
// Audio permission granted
droidSpeechPermissionsListener.onDroidSpeechAudioPermissionStatus(true, null);
break;
}
}
......
......@@ -8,7 +8,7 @@ import android.net.NetworkInfo;
/**
* Droid Speech Extensions
*
* @author Vikram Ezhil
* @author Kunj
*/
class Extensions {
......
......@@ -13,7 +13,7 @@ import java.util.List;
/**
* Droid Speech Language Receiver
*
* @author Vikram Ezhil
* @author Kunj
*/
class LanguageReceiver extends BroadcastReceiver {
......
......@@ -3,7 +3,7 @@ package com.vsoft.servicenow.speechRecognizer;
/**
* Bar Animation Listener
*
* @author Vikram Ezhil
* @author Kunj
*/
interface OnBarParamsAnimListener {
......
......@@ -5,7 +5,7 @@ import java.util.List;
/**
* Droid Speech Listener
*
* @author Vikram Ezhil
* @author Kunj
*/
public interface OnDSListener {
......
......@@ -3,7 +3,7 @@ package com.vsoft.servicenow.speechRecognizer;
/**
* Droid Speech Permissions Listener
*
* @author Vikram Ezhil
* @author Kunj
*/
public interface OnDSPermissionsListener {
......
......@@ -5,7 +5,7 @@ import java.util.List;
/**
* Droid Speech Language Details Listener
*
* @author Vikram Ezhil
* @author Kunj
*/
interface OnLanguageDetailsListener {
......
......@@ -6,7 +6,7 @@ import java.util.List;
/**
* Droid Speech Properties
*
* @author Vikram Ezhil
* @author Kunj
*/
class Properties {
......
......@@ -5,7 +5,7 @@ import android.graphics.RectF;
/**
* Recognition Bar View
*
* @author Vikram Ezhil
* @author Kunj
*/
class RecognitionBarView {
......
......@@ -13,7 +13,7 @@ import java.util.List;
/**
* Recognition Progress View
*
* @author Vikram Ezhil
* @author Kunj
*/
class RecognitionProgressView extends View {
......
......@@ -33,7 +33,6 @@ import butterknife.OnItemClick;
public class HomeScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view) GridView mGridView;
private Socket mSocket;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -42,9 +41,6 @@ public class HomeScreen extends AppCompatActivity {
setContentView(R.layout.home_screen);
CatalogueApplication app = (CatalogueApplication) getApplication();
mSocket = app.getSocket();
ButterKnife.bind(this);
......@@ -58,14 +54,6 @@ public class HomeScreen extends AppCompatActivity {
TypedArray gridViewIcons = getResources().obtainTypedArray(R.array.home_screen_icon_array);
HomeScreenAdapter adapter = new HomeScreenAdapter(this, gridValuesArray, gridViewIcons);
mGridView.setAdapter(adapter);
// mSocket.on("login", onLogin);
}
@Override
protected void onDestroy() {
super.onDestroy();
// mSocket.off("login", onLogin);
}
@OnItemClick(R.id.home_screen_grid_view)
......@@ -81,10 +69,6 @@ public class HomeScreen extends AppCompatActivity {
} else if (position == 4) {
// perform the user login attempt.
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.putExtra("username", userFirstName);
startActivity(intent);
......@@ -119,24 +103,4 @@ public class HomeScreen extends AppCompatActivity {
AlertDialog alert = builder.create();
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