diff --git a/src/Comment/.gitignore b/src/Comment/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/src/Comment/.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/src/Comment/.idea/.gitignore b/src/Comment/.idea/.gitignore new file mode 100644 index 0000000..eaf91e2 --- /dev/null +++ b/src/Comment/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/Comment/.idea/.name b/src/Comment/.idea/.name new file mode 100644 index 0000000..b3405b3 --- /dev/null +++ b/src/Comment/.idea/.name @@ -0,0 +1 @@ +My Application \ No newline at end of file diff --git a/src/Comment/.idea/compiler.xml b/src/Comment/.idea/compiler.xml new file mode 100644 index 0000000..7d7ec2e --- /dev/null +++ b/src/Comment/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Comment/.idea/dbnavigator.xml b/src/Comment/.idea/dbnavigator.xml new file mode 100644 index 0000000..309eda1 --- /dev/null +++ b/src/Comment/.idea/dbnavigator.xml @@ -0,0 +1,463 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Comment/.idea/gradle.xml b/src/Comment/.idea/gradle.xml new file mode 100644 index 0000000..64d29a1 --- /dev/null +++ b/src/Comment/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/src/Comment/.idea/misc.xml b/src/Comment/.idea/misc.xml new file mode 100644 index 0000000..7063837 --- /dev/null +++ b/src/Comment/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/Comment/app/.gitignore b/src/Comment/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/src/Comment/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/src/Comment/app/build.gradle b/src/Comment/app/build.gradle new file mode 100644 index 0000000..3863ce2 --- /dev/null +++ b/src/Comment/app/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'com.example.myapplication' + compileSdk 33 + + defaultConfig { + applicationId "com.example.myapplication" + minSdk 17 + 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 + } + buildFeatures { + viewBinding true + } +} + +dependencies { +// implementation 'org.litepal.android:core:3.2.3' + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.navigation:navigation-fragment:2.4.1' + implementation 'androidx.navigation:navigation-ui:2.4.1' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/src/Comment/app/proguard-rules.pro b/src/Comment/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/src/Comment/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/src/Comment/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java b/src/Comment/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java new file mode 100644 index 0000000..982ba51 --- /dev/null +++ b/src/Comment/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.myapplication; + +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.myapplication", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/src/Comment/app/src/main/AndroidManifest.xml b/src/Comment/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4075db8 --- /dev/null +++ b/src/Comment/app/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Comment/app/src/main/java/com/example/myapplication/AdapterComment.java b/src/Comment/app/src/main/java/com/example/myapplication/AdapterComment.java new file mode 100644 index 0000000..8bf6feb --- /dev/null +++ b/src/Comment/app/src/main/java/com/example/myapplication/AdapterComment.java @@ -0,0 +1,80 @@ +package com.example.myapplication; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.example.myapplication.R; +import com.example.myapplication.Comment; + +import java.util.List; + +/** + * Created by yyp on 2016/8/10. + */ +public class AdapterComment extends BaseAdapter { + + Context context; + List data; + + public AdapterComment(Context c, List data){ + this.context = c; + this.data = data; + } + + @Override + public int getCount() { + return data.size(); + } + + @Override + public Object getItem(int i) { + return data.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View convertView, ViewGroup viewGroup) { + ViewHolder holder; + // 重用convertView + if(convertView == null){ + holder = new ViewHolder(); + convertView = LayoutInflater.from(context).inflate(R.layout.item_comment, null); + holder.comment_name = (TextView) convertView.findViewById(R.id.comment_name); + holder.comment_content = (TextView) convertView.findViewById(R.id.comment_content); + + convertView.setTag(holder); + }else{ + holder = (ViewHolder) convertView.getTag(); + } + // 适配数据 + holder.comment_name.setText(data.get(i).getName()); + holder.comment_content.setText(data.get(i).getContent()); + + return convertView; + } + + /** + * 添加一条评论,刷新列表 + * @param comment + */ + public void addComment(Comment comment){ + data.add(comment); + notifyDataSetChanged(); + } + + /** + * 静态类,便于GC回收 + */ + public static class ViewHolder{ + TextView comment_name; + TextView comment_content; + } +} diff --git a/src/Comment/app/src/main/java/com/example/myapplication/Comment.java b/src/Comment/app/src/main/java/com/example/myapplication/Comment.java new file mode 100644 index 0000000..1214c00 --- /dev/null +++ b/src/Comment/app/src/main/java/com/example/myapplication/Comment.java @@ -0,0 +1,33 @@ +package com.example.myapplication; + + +public class Comment { + + String name; //评论者 + String content; //评论内容 + + public Comment(){ + + } + + public Comment(String name, String content){ + this.name = name; + this.content = content; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} \ No newline at end of file diff --git a/src/Comment/app/src/main/java/com/example/myapplication/FirstFragment.java b/src/Comment/app/src/main/java/com/example/myapplication/FirstFragment.java new file mode 100644 index 0000000..3c16010 --- /dev/null +++ b/src/Comment/app/src/main/java/com/example/myapplication/FirstFragment.java @@ -0,0 +1,47 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.navigation.fragment.NavHostFragment; + +import com.example.myapplication.databinding.FragmentFirstBinding; + +public class FirstFragment extends Fragment { + + private FragmentFirstBinding binding; + + @Override + public View onCreateView( + LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState + ) { + + binding = FragmentFirstBinding.inflate(inflater, container, false); + return binding.getRoot(); + + } + + public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + binding.buttonFirst.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + NavHostFragment.findNavController(FirstFragment.this) + .navigate(R.id.action_FirstFragment_to_SecondFragment); + } + }); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } + +} \ No newline at end of file diff --git a/src/Comment/app/src/main/java/com/example/myapplication/MainActivity.java b/src/Comment/app/src/main/java/com/example/myapplication/MainActivity.java new file mode 100644 index 0000000..dc4d6b6 --- /dev/null +++ b/src/Comment/app/src/main/java/com/example/myapplication/MainActivity.java @@ -0,0 +1,121 @@ +package com.example.myapplication; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.myapplication.AdapterComment; +import com.example.myapplication.Comment; + +import java.util.ArrayList; +import java.util.List; + +public class MainActivity extends Activity implements View.OnClickListener { + + private ImageView comment; + private TextView hide_down; + private EditText comment_content; + private Button comment_send; + + private LinearLayout rl_enroll; + private RelativeLayout rl_comment; + + private ListView comment_list; + private AdapterComment adapterComment; + private List data; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + initView(); + } + + private void initView() { + + // 初始化评论列表 + comment_list = (ListView) findViewById(R.id.comment_list); + // 初始化数据 + data = new ArrayList<>(); + // 初始化适配器 + adapterComment = new AdapterComment(getApplicationContext(), data); + // 为评论列表设置适配器 + comment_list.setAdapter(adapterComment); + + comment = (ImageView) findViewById(R.id.comment); + hide_down = (TextView) findViewById(R.id.hide_down); + comment_content = (EditText) findViewById(R.id.comment_content); + comment_send = (Button) findViewById(R.id.comment_send); + + rl_enroll = (LinearLayout) findViewById(R.id.rl_enroll); + rl_comment = (RelativeLayout) findViewById(R.id.rl_comment); + + setListener(); + } + + /** + * 设置监听 + */ + public void setListener(){ + comment.setOnClickListener(this); + + hide_down.setOnClickListener(this); + comment_send.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.comment: + // 弹出输入法 + InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); + // 显示评论框 + rl_enroll.setVisibility(View.GONE); + rl_comment.setVisibility(View.VISIBLE); + break; + case R.id.hide_down: + // 隐藏评论框 + rl_enroll.setVisibility(View.VISIBLE); + rl_comment.setVisibility(View.GONE); + // 隐藏输入法,然后暂存当前输入框的内容,方便下次使用 + InputMethodManager im = (InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); + im.hideSoftInputFromWindow(comment_content.getWindowToken(), 0); + break; + case R.id.comment_send: + sendComment(); + break; + default: + break; + } + } + + /** + * 发送评论 + */ + public void sendComment(){ + if(comment_content.getText().toString().equals("")){ + Toast.makeText(getApplicationContext(), "评论不能为空!", Toast.LENGTH_SHORT).show(); + }else{ + // 生成评论数据 + Comment comment = new Comment(); + comment.setName("评论者"+(data.size()+1)+":"); + comment.setContent(comment_content.getText().toString()); + adapterComment.addComment(comment); + // 发送完,清空输入框 + comment_content.setText(""); + + Toast.makeText(getApplicationContext(), "评论成功!", Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/src/Comment/app/src/main/java/com/example/myapplication/SecondFragment.java b/src/Comment/app/src/main/java/com/example/myapplication/SecondFragment.java new file mode 100644 index 0000000..3d37bd9 --- /dev/null +++ b/src/Comment/app/src/main/java/com/example/myapplication/SecondFragment.java @@ -0,0 +1,47 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.navigation.fragment.NavHostFragment; + +import com.example.myapplication.databinding.FragmentSecondBinding; + +public class SecondFragment extends Fragment { + + private FragmentSecondBinding binding; + + @Override + public View onCreateView( + LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState + ) { + + binding = FragmentSecondBinding.inflate(inflater, container, false); + return binding.getRoot(); + + } + + public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + binding.buttonSecond.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + NavHostFragment.findNavController(SecondFragment.this) + .navigate(R.id.action_SecondFragment_to_FirstFragment); + } + }); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } + +} \ No newline at end of file diff --git a/src/Comment/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/src/Comment/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/src/Comment/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Comment/app/src/main/res/drawable/chat.png b/src/Comment/app/src/main/res/drawable/chat.png new file mode 100644 index 0000000..84b5101 Binary files /dev/null and b/src/Comment/app/src/main/res/drawable/chat.png differ diff --git a/src/Comment/app/src/main/res/drawable/comment.png b/src/Comment/app/src/main/res/drawable/comment.png new file mode 100644 index 0000000..fb0a35a Binary files /dev/null and b/src/Comment/app/src/main/res/drawable/comment.png differ diff --git a/src/Comment/app/src/main/res/drawable/hide_dowm.png b/src/Comment/app/src/main/res/drawable/hide_dowm.png new file mode 100644 index 0000000..a2861a9 Binary files /dev/null and b/src/Comment/app/src/main/res/drawable/hide_dowm.png differ diff --git a/src/Comment/app/src/main/res/drawable/ic_launcher_background.xml b/src/Comment/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/src/Comment/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Comment/app/src/main/res/layout/activity_main.xml b/src/Comment/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..c9838d0 --- /dev/null +++ b/src/Comment/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + +