Click here to Skip to main content
15,891,864 members
Home / Discussions / Android
   

Android

 
AnswerRe: simpe doctor appointment app Pin
Peter Leow30-Dec-16 1:48
professionalPeter Leow30-Dec-16 1:48 
AnswerRe: simpe doctor appointment app Pin
Ravi Bhavnani30-Dec-16 6:56
professionalRavi Bhavnani30-Dec-16 6:56 
AnswerRe: simpe doctor appointment app Pin
Member 149880838-May-21 13:55
Member 149880838-May-21 13:55 
QuestionActivity Not opening from the notification bar Pin
Shanmugapriya D12-Dec-16 23:48
Shanmugapriya D12-Dec-16 23:48 
QuestionRe: Activity Not opening from the notification bar Pin
Richard MacCutchan13-Dec-16 0:06
mveRichard MacCutchan13-Dec-16 0:06 
AnswerRe: Activity Not opening from the notification bar Pin
Shanmugapriya D13-Dec-16 0:41
Shanmugapriya D13-Dec-16 0:41 
GeneralRe: Activity Not opening from the notification bar Pin
Richard MacCutchan13-Dec-16 5:46
mveRichard MacCutchan13-Dec-16 5:46 
QuestionSpeech to text notepad Pin
Member 108502537-Dec-16 15:30
Member 108502537-Dec-16 15:30 
I am trying to make a speech to text notepad.
I have made an app in which I can take notes manually, but when I select the option to speak, I am thrown outside of the note, and nothing is written into the note.
I wish to be able to write down everything that is being said in the environment, and I also want to make changes to the note, before its saved.
I also want to be able to select the language that is being used.
I have made a condition in which the audio is captured only the first time that I press the speak button, and the second time it does nothing and the boolean is set to false again.
I also want to be able to convert the text that was captured, into speech one I select another option in the options menu, in the editText class.
I am just trying to get this app working, so I used the code in an example I found here in the code project. I hope that there's no problem with that.
I really need help, so can someone please help me fix this?
Thanks.
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class NoteEdit extends Activity{

<pre>
public static int numTitle = 1;
public static String curDate = "";
public static String curText = "";<br />
private EditText mTitleText;
private EditText mBodyText;
private TextView mDateText;
private Long mRowId;
protected static final int RESULT_SPEECH = 1;
public boolean count=false;

private Cursor note;

private NotesDbAdapter mDbHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDbHelper = new NotesDbAdapter(this);
    mDbHelper.open();        

    setContentView(R.layout.note_edit);
    setTitle(R.string.app_name);

    mTitleText = (EditText) findViewById(R.id.title);
    mBodyText = (EditText) findViewById(R.id.body);
    mDateText = (TextView) findViewById(R.id.notelist_date);

    long msTime = System.currentTimeMillis();<br />
    Date curDateTime = new Date(msTime);

    SimpleDateFormat formatter = new SimpleDateFormat("d'/'M'/'y");<br />
    curDate = formatter.format(curDateTime);        

    mDateText.setText(""+curDate);

    mRowId = (savedInstanceState == null) ? null :
        (Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
    if (mRowId == null) {
        Bundle extras = getIntent().getExtras();
        mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
                                : null;
    }

    populateFields();

}

  public static class LineEditText extends EditText{
        // we need this constructor for LayoutInflater
        public LineEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
                mRect = new Rect();
                mPaint = new Paint();
                mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
                mPaint.setColor(Color.BLUE);
        }

        private Rect mRect;
        private Paint mPaint;       

        @Override
        protected void onDraw(Canvas canvas) {

            int height = getHeight();
            int line_height = getLineHeight();

            int count = height / line_height;

            if (getLineCount() > count)
                count = getLineCount();

            Rect r = mRect;
            Paint paint = mPaint;
            int baseline = getLineBounds(0, r);

            for (int i = 0; i < count; i++) {

                canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
                baseline += getLineHeight();

            super.onDraw(canvas);
        }

    }
  }

  @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        saveState();
        outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
    }

    @Override
    protected void onPause() {
        super.onPause();
        saveState();
    }

    @Override
    protected void onResume() {
        super.onResume();
        populateFields();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.noteedit_menu, menu);
        return true;<br />
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.menu_about:

            /* Here is the introduce about myself */<br />
            AlertDialog.Builder dialog = new AlertDialog.Builder(NoteEdit.this);
            dialog.setTitle("About");
            dialog.setMessage("Hello! I'm Heng, the creator of this application. This application is created for learning." +
                    " Using it on trading or any others activity that is related to business is strictly forbidden."
                       +"If there is any bug is found please freely e-mail me. "+
                        "\n\tedisonthk@gmail.com"
                       );
            dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

                   @Override
                   public void onClick(DialogInterface dialog, int which) {
                       dialog.cancel();

                   }
               });
               dialog.show();<br />
               return true;
        case R.id.menu_delete:
            if(note != null){
                note.close();
                note = null;
            }
            if(mRowId != null){
                mDbHelper.deleteNote(mRowId);
            }
            finish();

            return true;
        case R.id.menu_speak:
            if(count==false){

                Intent intent = new Intent(
                        RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

                try {
                    startActivityForResult(intent, RESULT_SPEECH);
                   // txtText.setText("");
                } catch (ActivityNotFoundException a) {
                    Toast t = Toast.makeText(getApplicationContext(),
                            "Opps! Your device doesn't support Speech to Text",
                            Toast.LENGTH_SHORT);
                    t.show();
                }
                count=true;
            }else{count=false;}
            case R.id.menu_save:
                saveState();
                finish();
            default:
                return super.onOptionsItemSelected(item);
            }

        }
@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case RESULT_SPEECH: {
if (resultCode == RESULT_OK && null != data) {

ArrayList<string> text = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

mBodyText.setText(text.get(0), TextView.BufferType.EDITABLE);
}
break;
}

}
}
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();

if(mRowId == null){
long id = mDbHelper.createNote(title, body, curDate);
if(id > 0){
mRowId = id;
}else{
Log.e("saveState","failed to create note");
}
}else{
if(!mDbHelper.updateNote(mRowId, title, body, curDate)){
Log.e("saveState","failed to update note");
}
}
}

private void populateFields() {
if (mRowId != null) {
note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
curText = note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY));
}
}

}


AnswerRe: Speech to text notepad Pin
Richard MacCutchan7-Dec-16 22:02
mveRichard MacCutchan7-Dec-16 22:02 
QuestionRemote Desktop Mobile app Pin
Member 127953594-Dec-16 2:49
Member 127953594-Dec-16 2:49 
AnswerRe: Remote Desktop Mobile app Pin
Afzaal Ahmad Zeeshan4-Dec-16 3:29
professionalAfzaal Ahmad Zeeshan4-Dec-16 3:29 
QuestionDrawing App CustomView Pin
Member 1065435022-Nov-16 6:58
Member 1065435022-Nov-16 6:58 
AnswerRe: Drawing App CustomView Pin
Richard MacCutchan22-Nov-16 8:36
mveRichard MacCutchan22-Nov-16 8:36 
AnswerRe: Drawing App CustomView Pin
David Crow22-Nov-16 12:51
David Crow22-Nov-16 12:51 
GeneralRe: Drawing App CustomView Pin
Member 1065435022-Nov-16 15:27
Member 1065435022-Nov-16 15:27 
Questionhelp Pin
Karan Malik10-Nov-16 18:34
Karan Malik10-Nov-16 18:34 
AnswerRe: help Pin
Richard MacCutchan10-Nov-16 22:01
mveRichard MacCutchan10-Nov-16 22:01 
AnswerRe: help Pin
ZurdoDev17-Nov-16 0:58
professionalZurdoDev17-Nov-16 0:58 
Questionandroid Pin
Member 128402858-Nov-16 18:52
Member 128402858-Nov-16 18:52 
AnswerRe: android Pin
Richard MacCutchan8-Nov-16 22:42
mveRichard MacCutchan8-Nov-16 22:42 
AnswerRe: android Pin
Rou199730-Nov-16 14:22
Rou199730-Nov-16 14:22 
QuestionI want to make an android application to add custom place and show on google map Pin
Member 128386578-Nov-16 0:54
Member 128386578-Nov-16 0:54 
QuestionRe: I want to make an android application to add custom place and show on google map Pin
David Crow8-Nov-16 2:19
David Crow8-Nov-16 2:19 
QuestionRe: I want to make an android application to add custom place and show on google map Pin
ZurdoDev17-Nov-16 0:59
professionalZurdoDev17-Nov-16 0:59 
Questionproblem whith warp photo in android Pin
mr ar30-Oct-16 7:58
mr ar30-Oct-16 7:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.