朗读功能

master
CYZ 2 years ago
parent b5259f06e2
commit cf1a454bf8

@ -57,11 +57,15 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.TextNote; import net.micode.notes.data.Notes.TextNote;
@ -88,6 +92,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class NoteEditActivity extends Activity implements OnClickListener, public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener { NoteSettingChangedListener, OnTextViewChangeListener {
public static final int LOCATION_CODE = 301; public static final int LOCATION_CODE = 301;
@ -103,6 +109,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public ImageView ibSetBgColor; public ImageView ibSetBgColor;
public ImageView startDraw; public ImageView startDraw;
public ImageButton note_Read;
} }
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
@ -174,8 +182,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private LinearLayout mEditTextList; private LinearLayout mEditTextList;
private String mUserQuery; private String mUserQuery;
private Pattern mPattern; private Pattern mPattern;
private TextToSpeech mTTS;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -398,7 +409,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon); mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date); mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color); mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
mNoteHeaderHolder.startDraw = (ImageView) findViewById(R.id.imageButton2); mNoteHeaderHolder.startDraw = (ImageButton) findViewById(R.id.imageButton2);
mNoteHeaderHolder.note_Read = (ImageButton) findViewById(R.id.menu_note_read);
mNoteHeaderHolder.note_Read.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
readText();
}
});
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this); mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
mNoteHeaderHolder.startDraw.setOnClickListener(new OnClickListener() { mNoteHeaderHolder.startDraw.setOnClickListener(new OnClickListener() {
@Override @Override
@ -437,11 +455,27 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE; mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
} }
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list); mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
mTTS = new TextToSpeech(this, new OnInitListener() {
@Override
public void onInit(int i) {
if (i == TextToSpeech.SUCCESS){
int result = mTTS.setLanguage(Locale.US);
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE
&& result != TextToSpeech.LANG_AVAILABLE){
//Toast.makeText(NoteEditActivity.this,"暂不支持此种语言", Toast.LENGTH_LONG);
return;
}
}
}
});
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
//Log.i(TAG, "onPause: 11111111111111111111111111111111111");
if(saveNote()) { if(saveNote()) {
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length()); Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
} }
@ -640,6 +674,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}); });
} }
public void readText(){
mTTS.speak(mNoteEditor.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
@ -684,6 +723,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
break; break;
case R.id.menu_private_folder: case R.id.menu_private_folder:
moveToPrivateFolder(); moveToPrivateFolder();
break;
default: default:
break; break;
} }

@ -34,13 +34,27 @@
<TextView <TextView
android:id="@+id/tv_modified_date" android:id="@+id/tv_modified_date"
android:layout_width="0dip" android:layout_width="73dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left|center_vertical" android:layout_gravity="left|center_vertical"
android:layout_marginRight="8dip" android:layout_marginRight="8dip"
android:layout_weight="1"
android:textAppearance="@style/TextAppearanceSecondaryItem" /> android:textAppearance="@style/TextAppearanceSecondaryItem" />
<ImageButton
android:id="@+id/menu_note_read"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:src="@android:drawable/ic_notification_overlay" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="67dp"
android:layout_height="88dp"
android:layout_weight="0"
tools:src="@tools:sample/avatars" />
<ImageView <ImageView
android:id="@+id/iv_alert_icon" android:id="@+id/iv_alert_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -49,13 +63,6 @@
android:background="@drawable/title_alert" android:background="@drawable/title_alert"
/> />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:src="@tools:sample/avatars" />
<TextView <TextView
android:id="@+id/tv_alert_date" android:id="@+id/tv_alert_date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -71,6 +78,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:background="@drawable/bg_btn_set_color" /> android:background="@drawable/bg_btn_set_color" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -102,13 +110,13 @@
android:id="@+id/note_edit_view" android:id="@+id/note_edit_view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="left|top"
android:background="@null"
android:autoLink="all" android:autoLink="all"
android:background="@null"
android:gravity="left|top"
android:lineSpacingMultiplier="1.2"
android:linksClickable="false" android:linksClickable="false"
android:minLines="12" android:minLines="12"
android:textAppearance="@style/TextAppearancePrimaryItem" android:textAppearance="@style/TextAppearancePrimaryItem" />
android:lineSpacingMultiplier="1.2" />
<LinearLayout <LinearLayout
android:id="@+id/note_edit_list" android:id="@+id/note_edit_list"
@ -129,10 +137,10 @@
<ImageView <ImageView
android:id="@+id/btn_set_bg_color" android:id="@+id/btn_set_bg_color"
android:layout_height="43dip"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:background="@drawable/bg_color_btn_mask" android:layout_height="wrap_content"
android:layout_gravity="top|right" /> android:layout_gravity="top|right"
android:background="@drawable/bg_color_btn_mask" />
<LinearLayout <LinearLayout
android:id="@+id/note_bg_color_selector" android:id="@+id/note_bg_color_selector"

Loading…
Cancel
Save