完成 学拼音

master
wanghao 1 month ago
parent 9096d93bad
commit 6fc7c018cb

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\wanghao\.android\avd\Nexus_10_API_33.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-10-28T05:42:02.521700100Z" />
</component>
</project>

@ -10,8 +10,8 @@ android {
applicationId "com.example.readtext"
minSdk 24
targetSdk 33
versionCode 2
versionName "1.1"
versionCode 4
versionName "2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

@ -19,41 +19,58 @@ import java.util.Arrays;
import java.util.List;
public class PinyinActivity extends AppCompatActivity {
private ActivityPinyinBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityPinyinBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_pinyin);
StaggeredGridLayoutManager layout = new StaggeredGridLayoutManager(9, StaggeredGridLayoutManager.VERTICAL);
binding.mainRecyclerView.setLayoutManager(layout);
String[] pinyin=new String[]{
binding = DataBindingUtil.setContentView(this, R.layout.activity_pinyin);
StaggeredGridLayoutManager layout1 = new StaggeredGridLayoutManager(8, StaggeredGridLayoutManager.VERTICAL);
StaggeredGridLayoutManager layout2 = new StaggeredGridLayoutManager(8, StaggeredGridLayoutManager.VERTICAL);
binding.mainRecyclerView1.setLayoutManager(layout1);
binding.mainRecyclerView2.setLayoutManager(layout2);
initShengmu();
initYunmu();
}
private MainAdapter adapter1;
private int length1;
private MainAdapter adapter2;
private int length2;
// 初始化声母表
private void initShengmu() {
String[] shengmB = new String[]{
"b", "p", "m", "f", "d", "t", "n", "l", "g", "k", "h", "j", "q", "x", "zh", "ch", "sh", "r", "z", "c", "s", "y", "w",
"a", "o", "e", "i", "u", "ü", "ai", "ei", "ui", "ao", "ou", "iu", "ie", "üe", "er", "an", "en", "in", "un", "ün", "ang", "eng", "ing", "ong"
};
String[] hanziList= new String[]{
"波", "坡", "摸", "佛", "得", "特", "讷", "了", "歌", "科", "喝", "基", "欺", "希", "知", "吃", "师", "日", "资", "雌", "思", "衣", "乌",
"啊", "喔", "鹅", "衣", "乌", "吁", "哀", "诶", "威", "熬", "欧", "优", "耶", "约", "耳", "安", "恩", "因", "温", "晕", "昂", "嗯", "英", "嗡"
String[] shengmH = new String[]{
"波", "坡", "摸", "佛", "得", "特", "讷", "了", "歌", "科", "喝", "基", "欺", "希", "知", "吃", "师", "日", "资", "雌", "思", "衣", "乌"
};
var length = pinyin.length;
List<ReadTextBeen> list=new ArrayList<>(length);
for (int i = 0; i < length; i++) {
ReadTextBeen readTextBeen=new ReadTextBeen();
readTextBeen.setHanzi(pinyin[i]);
readTextBeen.setPinyin(hanziList[i]);
list.add(readTextBeen);
length1 = shengmB.length;
List<ReadTextBeen> list1 = new ArrayList<>(length1);
for (int i = 0; i < length1; i++) {
ReadTextBeen readTextBeen = new ReadTextBeen();
readTextBeen.setHanzi(shengmB[i]);
readTextBeen.setPinyin(shengmH[i]);
list1.add(readTextBeen);
}
MainAdapter adapter1=new MainAdapter(this, new MyClickInterface() {
adapter1 = new MainAdapter(this, new MyClickInterface() {
@Override
public void onClickCall(int index) {
var readTextBeen = list.get(index);
var hanzi = readTextBeen.getHanzi();
if (hanzi.contains("ü")){
hanzi= hanzi.replace("ü","v");
}
adapter2.setSelectedList(length2);
AudioPlayerUtil.playAudio(PinyinActivity.this, hanzi + "1");
adapter2.notifyDataSetChanged();
var readTextBeen = list1.get(index);
readSone(readTextBeen);
}
@Override
public void onClickUpdateCall(int index) {
@ -64,12 +81,67 @@ public class PinyinActivity extends AppCompatActivity {
}
});
adapter1.setList(list);
adapter1.setList(list1);
binding.setAdapter1(adapter1);
adapter1.notifyDataSetChanged();
}
// 初始化韵母表
private void initYunmu() {
String[] yunmB = new String[]{
"a", "o", "e", "i", "u", "ü", "ai", "ei", "ui", "ao", "ou", "iu", "ie", "üe", "er", "an", "en", "in", "un", "ün", "ang", "eng", "ing", "ong"
};
String[] yunmH = new String[]{
"啊", "喔", "鹅", "衣", "乌", "吁", "哀", "诶", "威", "熬", "欧", "优", "耶", "约", "耳", "安", "恩", "因", "温", "晕", "昂", "嗯", "英", "嗡"
};
length2 = yunmB.length;
List<ReadTextBeen> list2 = new ArrayList<>(length2);
for (int i = 0; i < length2; i++) {
ReadTextBeen readTextBeen = new ReadTextBeen();
readTextBeen.setHanzi(yunmB[i]);
readTextBeen.setPinyin(yunmH[i]);
list2.add(readTextBeen);
}
adapter2 = new MainAdapter(this, new MyClickInterface() {
@Override
public void onClickCall(int index) {
adapter1.setSelectedList(length1);
adapter1.notifyDataSetChanged();
var readTextBeen = list2.get(index);
readSone(readTextBeen);
}
@Override
public void onClickUpdateCall(int index) {
}
@Override
public void onPinyinClick(int index) {
}
});
adapter2.setList(list2);
binding.setAdapter2(adapter2);
adapter2.notifyDataSetChanged();
}
public void mainBack(View view){
// 返回
public void mainBack(View view) {
finish();
}
// 发音
private void readSone(ReadTextBeen readTextBeen) {
var hanzi = readTextBeen.getHanzi();
if (hanzi.contains("ü")) {
hanzi = hanzi.replace("ü", "v");
}
AudioPlayerUtil.playAudio(PinyinActivity.this, hanzi + "1");
}
}

@ -1,106 +0,0 @@
package com.example.readtext.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.example.readtext.R;
import com.example.readtext.been.ReadTextBeen;
import com.example.readtext.databinding.ItemMainBinding;
import java.util.ArrayList;
import java.util.List;
public class LearnPinyinAdapter extends RecyclerView.Adapter<LearnPinyinAdapter.MyViewHolder> {
private Context context;
private List<ReadTextBeen> list;
private MyClickInterface clickInterface;
private LayoutInflater layoutInflater;
private List<Boolean> selectedList;
private boolean aBoolean=false;
public void setaBoolean(boolean aBoolean) {
this.aBoolean = aBoolean;
notifyDataSetChanged();
}
public LearnPinyinAdapter(Context context, MyClickInterface clickInterface) {
this.context = context;
this.clickInterface = clickInterface;
layoutInflater = LayoutInflater.from(context);
}
public void setList(List<ReadTextBeen> list) {
this.list = list;
int size = list.size();
setSelectedList(size);
}
public void setSelectedList(int size) {
selectedList = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
selectedList.add(false);
}
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemMainBinding binding = DataBindingUtil.inflate(layoutInflater, R.layout.item_main, parent, false);
return new MyViewHolder(binding);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
// Log.e("TAG", "onBindViewHolder:运行"+position );
ReadTextBeen readTextBeen = list.get(position);
ItemMainBinding binding = holder.binding;
binding.setItem(readTextBeen);
binding.setState(aBoolean);
if (selectedList.get(position)) {
// 设置选中时的颜色
binding.itemView.setBackgroundResource(R.drawable.item_main_bg2);
} else {
// 设置未选中时的颜色
binding.itemView.setBackgroundResource(R.drawable.item_bg);
}
binding.itemHanzi.setOnClickListener(v -> {
clickInterface.onClickCall(position);
// 切换选中状态
int size = selectedList.size();
for (int i = 0; i < size; i++) {
if (selectedList.get(i)){
selectedList.set(i,false);
}
}
selectedList.set(position,true);
notifyDataSetChanged();
});
binding.itemDelete.setOnClickListener(v -> clickInterface.onClickUpdateCall(position));
binding.itemPinyin.setOnClickListener(v -> clickInterface.onPinyinClick(position));
holder.binding.executePendingBindings();
}
@Override
public int getItemCount() {
return list == null ? 0 : list.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
private ItemMainBinding binding;
public MyViewHolder(ItemMainBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="adapter1"
type="com.example.readtext.adapter.MainAdapter" />
@ -14,6 +15,7 @@
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -45,15 +47,58 @@
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/main_recyclerView"
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:adapter="@{adapter1}"
android:background="@color/white"/>
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginStart="10dp"
android:gravity="center"
android:letterSpacing="0.1"
android:text="声母表"
android:textSize="20dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/main_recyclerView1"
android:layout_width="match_parent"
android:layout_height="540dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:adapter="@{adapter1}"
android:layout_weight="1"
android:background="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginStart="10dp"
android:gravity="center"
android:letterSpacing="0.1"
android:text="韵母表"
android:textSize="20dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/main_recyclerView2"
android:layout_width="match_parent"
android:layout_height="540dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:adapter="@{adapter2}"
android:background="@color/white" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</layout>

@ -1,4 +1,4 @@
<resources>
<string name="app_name">学习工具</string>
<string name="app_name">学习工具(学拼音版)2.0</string>
<string name="xiaoyu"><![CDATA[<]]></string>
</resources>
Loading…
Cancel
Save