diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..70f212e --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,414 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..909c0df --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..bdd9278 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..d2fda44 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'com.example.translate_code' + compileSdk 33 + + defaultConfig { + applicationId "com.example.translate_code" + minSdk 24 + targetSdk 33 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation 'com.squareup.retrofit2:converter-gson:2.9.0' + implementation 'org.projectlombok:lombok:1.18.12' + implementation "androidx.slidingpanelayout:slidingpanelayout:1.2.0" + +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/translate_code/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/translate_code/ExampleInstrumentedTest.java new file mode 100644 index 0000000..a8e1706 --- /dev/null +++ b/app/src/androidTest/java/com/example/translate_code/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.translate_code; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.translate_code", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..bc75d93 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/translate_code/MainActivity.java b/app/src/main/java/com/example/translate_code/MainActivity.java new file mode 100644 index 0000000..0840b26 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/MainActivity.java @@ -0,0 +1,248 @@ +package com.example.translate_code; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.DialogInterface; +import android.os.Bundle; + +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.translate_code.adapter.Myadapter; +import com.example.translate_code.utility.Choose; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { + RecyclerView mRView; + Myadapter myadapter; + List itemList=new ArrayList<>(); + + /* @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main);*/ + /*mRView= findViewById(R.id.spinning_left); + for (int i=0;i<10;i++) + { + Choose choose = new Choose(); + choose.title="选项"+i; + choose.content="功能"+i; + relist.add(choose); + + } + myadapter = new Myadapter(MainActivity.this,relist); + LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this); + mRView.setLayoutManager(linearLayoutManager); + mRView.setAdapter(myadapter);*/ + + + TextView transTv, expTv; + EditText trans; + Button search; + + Button clean; + LinearLayout transLi, expLi; + String exp, tran, pho; + String from = "auto", to = "auto", q; + generate tr; + Spinner spinner; + private DrawerLayout drawerLayout; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + init(); + clickAndListener(); + drawerLayout=findViewById(R.id.drawer_layout); + mRView= findViewById(R.id.list_left_drawer); + LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this); + mRView.setLayoutManager(linearLayoutManager); + + } + + private void init() { + trans = findViewById(R.id.trans); + transTv = findViewById(R.id.trans_tv); + expTv = findViewById(R.id.exp_tv); + search = findViewById(R.id.search); + clean=findViewById(R.id.clean); + transLi = findViewById(R.id.trans_l); + expLi = findViewById(R.id.exp_l); + spinner = findViewById(R.id.lan_spinner); + } + + private void clickAndListener() { + search.setOnClickListener(v -> textResult()); + clean.setOnClickListener(this::onClick); + trans.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (s.length() == 0) { + transLi.setVisibility(View.GONE); + expLi.setVisibility(View.GONE); + } + search.setVisibility(View.VISIBLE); + } + + @Override + public void afterTextChanged(Editable s) { + } + }); + + spinnerListener(); + } + + private void textResult() { + q = trans.getText().toString().trim(); + generate_intimpl t = new generate_intimpl(q); + Call call = t.getCall(from, to); + call.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + tr = response.body(); + if (tr != null) { + int code =tr.getErrorCode(); + if (0 == code) { + exp = tr.getExplains(); + tran = String.valueOf(tr.getTranslation()); + pho = tr.getUkPho(); + if (pho != null) { + transTv.setText(tran + pho); + } else { + transTv.setText(tran); + } + transLi.setVisibility(View.VISIBLE); + search.setVisibility(View.GONE); + if (!tran.equals(exp) && exp != null) { + expTv.setText(exp); + expLi.setVisibility(View.VISIBLE); + } + } else if (113 == code) { + toaPrint("请输入翻译内容"); + } else toaPrint("请求错误,错误码为:" + tr.getErrorCode()); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + Log.i("TAG", "onFailure"); + toaPrint("请检查网络设置!"); + } + }); + } + + private void toaPrint(String s) { + Toast.makeText(this, s, Toast.LENGTH_SHORT).show(); + } + + private void spinnerListener() { + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + switch (position) { + case 1://英文 → 中文 + from = "en"; + to = "zh-CHS"; + break; + case 2://中文 → 英文 + from = "zh-CHS"; + to = "en"; + break; + case 3://中文 → 日语 + from = "zh-CHS"; + to = "ja"; + break; + case 4://中文 → 韩语 + from = "zh-CHS"; + to = "ko"; + break; + case 5://中文 → 法语 + from = "zh-CHS"; + to = "fr"; + break; + case 6://中文 → 俄语 + from = "zh-CHS"; + to = "ru"; + break; + default: + break; + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + } + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + public void onClick(View v) + { + switch (v.getId()) { + case R.id.clean: + String s = trans.getText().toString(); + Toast.makeText(this, "你搜索的词为"+s, Toast.LENGTH_SHORT).show(); + if (s !=null) { + String s1 = transTv.getText().toString(); + SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间 + sdf.applyPattern("yyyy-MM-dd HH:mm:ss a");// a为am/pm的标记 + Date date = new Date();// 获取当前时间 + Choose ch = new Choose(); + ch.yuanwen = s; + ch.fanyi = s1; + ch.time = "查询时间" + sdf.format(date); + itemList.add(ch); + setAdapter(itemList); + } + trans.setText(""); + break; + case R.id.search: + + + break; + + + } + } + void setAdapter(ListitemList) + { + myadapter = new Myadapter(this, itemList); + mRView.setAdapter(myadapter); + } + +} diff --git a/app/src/main/java/com/example/translate_code/ReadActivity.java b/app/src/main/java/com/example/translate_code/ReadActivity.java new file mode 100644 index 0000000..0bdeebb --- /dev/null +++ b/app/src/main/java/com/example/translate_code/ReadActivity.java @@ -0,0 +1,75 @@ +package com.example.translate_code; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.GridView; +import android.widget.ImageButton; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.translate_code.adapter.GridAdapter; +import com.example.translate_code.utility.Writing; +import com.example.translate_code.utility.WrtingBean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class ReadActivity extends AppCompatActivity { + private Listwriting=new ArrayList<>(); +/* private Listcontent=new ArrayList<>();*/ + private GridView gridView; + + + private int []image={R.drawable.narture,R.drawable.img_4,R.drawable.img_5}; + private String name[]={"nature","sea","mountain"}; + + private String allContent[]={"Stray birds of summer come to my window to sing and fly away.\n" + + "And yellow leaves of autumn, which have no songs, flutter and fall\n" + + "there with a sign.","What language is thine, O sea?\n" + + "The language of eternal question.\n" + + "What language is thy answer, O sky?\n" + + "The language of eternal silence.","The fish in the water is silent, the animal on the earth is noisy,\n" + + "the bird in the air is singing.\n" + + "But Man has in him the silence of the sea, the noise of the earth and\n" + + "the music of the air."}; +private int music[]={R.raw.one,R.raw.two,R.raw.three}; + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.read_layout); + initlist(); + gridView= findViewById(R.id.read_gv); + GridAdapter gridAdapter = new GridAdapter( writing,this); + gridView.setAdapter(gridAdapter); + setListener(); + + } + public void initlist() + { + for(int i=0;i parent, View view, int position, long id) { + Writing writing1 = writing.get(position); + Intent intent = new Intent(ReadActivity.this, WritingActivity.class); + intent.putExtra("writing", writing1); + startActivity(intent); + } + }); + } +} diff --git a/app/src/main/java/com/example/translate_code/WelcomeActivity.java b/app/src/main/java/com/example/translate_code/WelcomeActivity.java new file mode 100644 index 0000000..c8d20a2 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/WelcomeActivity.java @@ -0,0 +1,52 @@ +package com.example.translate_code; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +public class WelcomeActivity extends AppCompatActivity { + ImageButton searchView; + ImageButton readView; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.welcome_activity); + searchView=findViewById(R.id.gotosearch); + readView=findViewById(R.id.gotoread); + searchView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + toSearch(); + } + }); + readView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + toRead(); + } + }); + } + + public void toSearch() + { + Intent intent = new Intent(); + intent.setClass(WelcomeActivity.this,MainActivity.class); + startActivity(intent); + + + } + public void toRead() + { + Intent intent = new Intent(); + intent.setClass(WelcomeActivity.this,ReadActivity.class); + startActivity(intent); + + } +} diff --git a/app/src/main/java/com/example/translate_code/WritingActivity.java b/app/src/main/java/com/example/translate_code/WritingActivity.java new file mode 100644 index 0000000..687aa65 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/WritingActivity.java @@ -0,0 +1,83 @@ +package com.example.translate_code; + +import android.content.Intent; +import android.media.MediaPlayer; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; + +import com.example.translate_code.utility.Writing; + +public class WritingActivity extends AppCompatActivity { + private Button mButton01, mButton02; + MediaPlayer mediaPlayer; + + + + TextView titleTv2, descTv; + ImageView bigPicIv; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.item_rv); + initView(); +//结合搜上一级界面传来的数据 + Intent intent = getIntent(); + Writing writing = (Writing) intent.getSerializableExtra("writing"); + titleTv2.setText(writing.getName()); + descTv.setText(writing.getDesc()); + bigPicIv.setImageResource(writing.getWritePicture()); + mediaPlayer = MediaPlayer.create(this,writing.getMusicId()); + mButton01.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + start(); + + } + }); + mButton02.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + pause(); + } + }); + } + + public void start() { + + mediaPlayer.start(); + + + //1.等多久再执行什么 + //2.每隔多久执行一次什么 + + } + + public void pause() { + String pause1 = mButton02.getText().toString().trim(); + if ("暂停".equals(pause1)) { + mediaPlayer.pause(); + mButton02.setText("继续"); + } else { + mediaPlayer.start(); + mButton02.setText("暂停"); + } + } + + private void initView() { + titleTv2 = findViewById(R.id.wt_title); + descTv = findViewById(R.id.wt_content); + bigPicIv = findViewById(R.id.wt_picture); + mButton01 = findViewById(R.id.player); + mButton02 = findViewById(R.id.pause); + + } + + + } diff --git a/app/src/main/java/com/example/translate_code/adapter/GridAdapter.java b/app/src/main/java/com/example/translate_code/adapter/GridAdapter.java new file mode 100644 index 0000000..12b13be --- /dev/null +++ b/app/src/main/java/com/example/translate_code/adapter/GridAdapter.java @@ -0,0 +1,77 @@ +package com.example.translate_code.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.BaseAdapter; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; + +import com.example.translate_code.R; +import com.example.translate_code.holder.MyWrtingHolder; +import com.example.translate_code.utility.Writing; + +import java.util.List; + +public class GridAdapter extends BaseAdapter { + private Listlist; + private Context context; + + public GridAdapter(List list, Context context) { + this.list = list; + this.context=context; + } + + @Override + public int getCount() { + return list.size(); + } + + @Override + public Object getItem(int position) { + return list.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + MyWrtingHolder myWrtingHolder; + if (convertView == null){ + convertView = View.inflate(context, R.layout.item_gv,null); + myWrtingHolder= new MyWrtingHolder(convertView); + convertView.setTag(myWrtingHolder); + + } + else { + myWrtingHolder= (MyWrtingHolder) convertView.getTag(); + } + + Writing writing = list.get(position); + myWrtingHolder.writingpicture.setImageResource(writing.getWritePicture()); + myWrtingHolder.writingname.setText(writing.getName()); + + return convertView; + + } + + class MyWrtingHolder { + ImageView writingpicture; + TextView writingname; + + public MyWrtingHolder(View view) { + this.writingpicture = view.findViewById(R.id.read_image); + this.writingname = view.findViewById(R.id.read_name); + } + } +} diff --git a/app/src/main/java/com/example/translate_code/adapter/Myadapter.java b/app/src/main/java/com/example/translate_code/adapter/Myadapter.java new file mode 100644 index 0000000..a070566 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/adapter/Myadapter.java @@ -0,0 +1,49 @@ +package com.example.translate_code.adapter; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.translate_code.MainActivity; +import com.example.translate_code.R; +import com.example.translate_code.holder.MyViewholder; +import com.example.translate_code.utility.Choose; + +import java.util.ArrayList; +import java.util.List; + +public class Myadapter extends RecyclerView.Adapter { + private Context mcontext; + Listrelist; + + public Myadapter(Context mcontext,Listre) { + this.mcontext = mcontext; + this.relist=re; + } + + @NonNull + @Override + public MyViewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = View.inflate(mcontext, R.layout.item_list, null); + MyViewholder myViewholder = new MyViewholder(view); + return myViewholder; + } + + @Override + public void onBindViewHolder(@NonNull MyViewholder holder, int position) { + Choose choose = relist.get(position); + holder.mTitle.setText(choose.yuanwen); + holder.mContent.setText(choose.fanyi); + holder.mTime.setText(choose.time); + + + } + + @Override + public int getItemCount() { + return relist.size(); + } +} diff --git a/app/src/main/java/com/example/translate_code/generate.java b/app/src/main/java/com/example/translate_code/generate.java new file mode 100644 index 0000000..3586d85 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/generate.java @@ -0,0 +1,81 @@ +package com.example.translate_code; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class generate { + + @SerializedName("translation") + private List translation; + @SerializedName("basic") + private Basic basic; + @SerializedName("errorCode") + private Integer errorCode; + @SerializedName("tSpeakUrl") + private String tSpeakUrl; + + public List getTranslation() { + return translation; + } + + public Integer getErrorCode() { + return errorCode; + } + + public static class Basic { + @SerializedName("us-phonetic") + private String usphonetic; + @SerializedName("uk-speech") + private String ukspeech; + @SerializedName("speech") + private String speech; + @SerializedName("phonetic") + private String phonetic; + @SerializedName("uk-phonetic") + private String ukphonetic; + @SerializedName("us-speech") + private String usspeech; + @SerializedName("explains") + private List explains; + } + + public String getTrans() { + return translation.get(0); + } + + public String getExplains() { + if (basic != null && basic.explains != null) { + return basic.explains.get(0); + } + return null; + } + + public String getUkPho() { + if (basic != null && basic.ukphonetic != null) + return " 英:[" + basic.ukphonetic + "]"; + return null; + } + + public String getUsPho() { + if (basic != null && basic.usphonetic != null) + return " 美:[" + basic.usphonetic + "]"; + return null; + } + + public String getUkSpeech() { + if (basic != null) + return basic.ukspeech; + return null; + } + + public String getUsSpeech() { + if (basic != null) + return basic.usspeech; + return null; + } + + public String gettSpeakUrl() { + return tSpeakUrl; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/translate_code/generate_int.java b/app/src/main/java/com/example/translate_code/generate_int.java new file mode 100644 index 0000000..127ee05 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/generate_int.java @@ -0,0 +1,15 @@ +package com.example.translate_code; + +import retrofit2.Call; +import retrofit2.http.POST; +import retrofit2.http.Query; + +public interface generate_int { + + @POST("api") + Call getTextRes(@Query("from") String from, @Query("to") String to, + @Query("appKey") String ID, @Query("salt") String salt, + @Query("sign") String sign, @Query("signType") String signType, + @Query("curtime") String curtime, @Query("q") String q); + +} diff --git a/app/src/main/java/com/example/translate_code/generate_intimpl.java b/app/src/main/java/com/example/translate_code/generate_intimpl.java new file mode 100644 index 0000000..3b6834e --- /dev/null +++ b/app/src/main/java/com/example/translate_code/generate_intimpl.java @@ -0,0 +1,65 @@ +package com.example.translate_code; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import retrofit2.Call; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +public class generate_intimpl{ + String q; + + public generate_intimpl(String q) { + this.q = q; + } + + static String APP_KEY = "26c4025114f37897", signType = "v3"; + static final String APP_SECRET = "j3f4oDFH4e5ujKlgyZn3J9ollgIgl2QC"; + static String BASE_URL = "https://openapi.youdao.com/"; + + public Call getCall(String from, String to) { + Retrofit retrofit = new Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + final generate_int getR = retrofit.create(generate_int.class); + + String salt = String.valueOf(System.currentTimeMillis()); + String curtime = String.valueOf(System.currentTimeMillis() / 1000); + String sign = getDigest(APP_KEY + truncate(q) + salt + curtime + APP_SECRET); + return getR.getTextRes(from, to, APP_KEY, salt, sign, signType, curtime, q); + } + + private static String truncate(String q) { + if (q == null) { + return null; + } + int len = q.length(); + return len <= 20 ? q : (q.substring(0, 10) + len + q.substring(len - 10, len)); + } + + private static String getDigest(String string) { + if (string == null) { + return null; + } + char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + byte[] btInput = string.getBytes(StandardCharsets.UTF_8); + try { + MessageDigest mdInst = MessageDigest.getInstance("SHA-256"); + mdInst.update(btInput); + byte[] md = mdInst.digest(); + int j = md.length; + char[] str = new char[j * 2]; + int k = 0; + for (byte byte0 : md) { + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; + str[k++] = hexDigits[byte0 & 0xf]; + } + return new String(str); + } catch (NoSuchAlgorithmException e) { + return null; + } + } +} diff --git a/app/src/main/java/com/example/translate_code/holder/MyViewholder.java b/app/src/main/java/com/example/translate_code/holder/MyViewholder.java new file mode 100644 index 0000000..c59e5da --- /dev/null +++ b/app/src/main/java/com/example/translate_code/holder/MyViewholder.java @@ -0,0 +1,22 @@ +package com.example.translate_code.holder; + +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.translate_code.R; + +public class MyViewholder extends RecyclerView.ViewHolder { + public TextView mTitle; + public TextView mContent; + public TextView mTime; + public MyViewholder(@NonNull View itemView) { + super(itemView); + mTitle = itemView.findViewById(R.id.yuanwen); + mContent=itemView.findViewById(R.id.fanyi); + mTime=itemView.findViewById(R.id.time); + } +} diff --git a/app/src/main/java/com/example/translate_code/holder/MyWrtingHolder.java b/app/src/main/java/com/example/translate_code/holder/MyWrtingHolder.java new file mode 100644 index 0000000..5cc41d4 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/holder/MyWrtingHolder.java @@ -0,0 +1,25 @@ +package com.example.translate_code.holder; + +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.translate_code.R; + +public class MyWrtingHolder extends RecyclerView.ViewHolder { + public TextView wTtitle; + public ImageView wPicture; + public TextView wContent; + public MyWrtingHolder(@NonNull View itemView) { + super(itemView); + wTtitle=itemView.findViewById(R.id.wt_title); + wContent=itemView.findViewById(R.id.wt_content); + wPicture=itemView.findViewById(R.id.read_image); + } + + +} diff --git a/app/src/main/java/com/example/translate_code/transfragment.java b/app/src/main/java/com/example/translate_code/transfragment.java new file mode 100644 index 0000000..d670e4f --- /dev/null +++ b/app/src/main/java/com/example/translate_code/transfragment.java @@ -0,0 +1,6 @@ +package com.example.translate_code; + +import androidx.fragment.app.Fragment; + +public class transfragment extends Fragment { +} diff --git a/app/src/main/java/com/example/translate_code/utility/Choose.java b/app/src/main/java/com/example/translate_code/utility/Choose.java new file mode 100644 index 0000000..a85ef41 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/utility/Choose.java @@ -0,0 +1,7 @@ +package com.example.translate_code.utility; + +public class Choose { + public String yuanwen; + public String fanyi; + public String time; + } diff --git a/app/src/main/java/com/example/translate_code/utility/Writing.java b/app/src/main/java/com/example/translate_code/utility/Writing.java new file mode 100644 index 0000000..f0554f2 --- /dev/null +++ b/app/src/main/java/com/example/translate_code/utility/Writing.java @@ -0,0 +1,51 @@ +package com.example.translate_code.utility; + +import java.io.Serializable; + +public class Writing implements Serializable { + int writePicture; + String name; + + private String desc; + + int musicId; + + public Writing(int writePicture, String name, String desc, int musicId) { + this.writePicture = writePicture; + this.name = name; + this.desc = desc; + this.musicId = musicId; + } + + public String getDesc() { + return desc; + } + + public int getWritePicture() { + return writePicture; + } + + public void setWritePicture(int writePicture) { + this.writePicture = writePicture; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public int getMusicId() { + return musicId; + } + + public void setMusicId(int musicId) { + this.musicId = musicId; + } +} diff --git a/app/src/main/java/com/example/translate_code/utility/WrtingBean.java b/app/src/main/java/com/example/translate_code/utility/WrtingBean.java new file mode 100644 index 0000000..aea541d --- /dev/null +++ b/app/src/main/java/com/example/translate_code/utility/WrtingBean.java @@ -0,0 +1,39 @@ +package com.example.translate_code.utility; + +import java.io.Serializable; + +public class WrtingBean implements Serializable { + private String title; + private String desc; + private int picid; + + public WrtingBean(String title, String desc, int picid) { + this.title = title; + this.desc = desc; + this.picid = picid; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public int getPicid() { + return picid; + } + + public void setPicid(int picid) { + this.picid = picid; + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/edit_border.xml b/app/src/main/res/drawable/edit_border.xml new file mode 100644 index 0000000..9bfa4ce --- /dev/null +++ b/app/src/main/res/drawable/edit_border.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/img.png b/app/src/main/res/drawable/img.png new file mode 100644 index 0000000..51f63ea Binary files /dev/null and b/app/src/main/res/drawable/img.png differ diff --git a/app/src/main/res/drawable/img_1.png b/app/src/main/res/drawable/img_1.png new file mode 100644 index 0000000..4b79703 Binary files /dev/null and b/app/src/main/res/drawable/img_1.png differ diff --git a/app/src/main/res/drawable/img_2.png b/app/src/main/res/drawable/img_2.png new file mode 100644 index 0000000..3efcf39 Binary files /dev/null and b/app/src/main/res/drawable/img_2.png differ diff --git a/app/src/main/res/drawable/img_3.png b/app/src/main/res/drawable/img_3.png new file mode 100644 index 0000000..3efcf39 Binary files /dev/null and b/app/src/main/res/drawable/img_3.png differ diff --git a/app/src/main/res/drawable/img_4.png b/app/src/main/res/drawable/img_4.png new file mode 100644 index 0000000..c392879 Binary files /dev/null and b/app/src/main/res/drawable/img_4.png differ diff --git a/app/src/main/res/drawable/img_5.png b/app/src/main/res/drawable/img_5.png new file mode 100644 index 0000000..ad696ec Binary files /dev/null and b/app/src/main/res/drawable/img_5.png differ diff --git a/app/src/main/res/drawable/img_6.png b/app/src/main/res/drawable/img_6.png new file mode 100644 index 0000000..d45de6e Binary files /dev/null and b/app/src/main/res/drawable/img_6.png differ diff --git a/app/src/main/res/drawable/iv_menu_shoucang.png b/app/src/main/res/drawable/iv_menu_shoucang.png new file mode 100644 index 0000000..94f1ade Binary files /dev/null and b/app/src/main/res/drawable/iv_menu_shoucang.png differ diff --git a/app/src/main/res/drawable/narture.png b/app/src/main/res/drawable/narture.png new file mode 100644 index 0000000..1294030 Binary files /dev/null and b/app/src/main/res/drawable/narture.png differ diff --git a/app/src/main/res/drawable/read.png b/app/src/main/res/drawable/read.png new file mode 100644 index 0000000..d700960 Binary files /dev/null and b/app/src/main/res/drawable/read.png differ diff --git a/app/src/main/res/drawable/search.png b/app/src/main/res/drawable/search.png new file mode 100644 index 0000000..b489382 Binary files /dev/null and b/app/src/main/res/drawable/search.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..8d40646 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + +