Skip to content

Commit a6232a2

Browse files
committed
init
1 parent 2e44420 commit a6232a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+523
-700
lines changed

app/build.gradle

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 32
4+
compileSdkVersion 33
55
defaultConfig {
66
applicationId "com.dds.anyui"
7-
minSdkVersion 21
8-
targetSdkVersion 32
7+
minSdkVersion 24
8+
targetSdkVersion 33
99
versionCode 1
1010
versionName "1.0"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -29,14 +29,17 @@ android {
2929

3030
dependencies {
3131
implementation fileTree(dir: 'libs', include: ['*.jar'])
32-
implementation 'androidx.appcompat:appcompat:1.1.0'
33-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
34-
implementation 'androidx.recyclerview:recyclerview:1.1.0'
32+
implementation 'androidx.appcompat:appcompat:1.6.1'
33+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
34+
implementation 'androidx.recyclerview:recyclerview:1.3.0'
35+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
36+
37+
// feature
38+
implementation project(path: ':feature_recyclerview')
39+
3540

36-
// library
37-
implementation project(path: ':studiodemo')
3841
// test
39-
testImplementation 'junit:junit:4.12'
40-
androidTestImplementation 'androidx.test:runner:1.2.0'
41-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
42+
testImplementation 'junit:junit:4.13.2'
43+
androidTestImplementation 'androidx.test:runner:1.5.2'
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
4245
}

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
android:supportsRtl="true"
1212
android:theme="@style/AppTheme"
1313
tools:ignore="GoogleAppIndexingWarning">
14-
<activity android:name=".TestActivity" />
1514
<activity
1615
android:name=".MainActivity"
16+
android:label="MainActivity"
1717
android:exported="true">
1818
<intent-filter>
1919
<action android:name="android.intent.action.MAIN" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
package com.dds.anyui;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
7+
import androidx.annotation.NonNull;
8+
import androidx.fragment.app.Fragment;
9+
import androidx.fragment.app.FragmentActivity;
10+
import androidx.recyclerview.widget.GridLayoutManager;
11+
import androidx.recyclerview.widget.LinearLayoutManager;
12+
import androidx.recyclerview.widget.RecyclerView;
13+
14+
import android.view.LayoutInflater;
15+
import android.view.View;
16+
import android.view.ViewGroup;
17+
import android.widget.TextView;
18+
19+
import com.dds.recyclerview.RecyclerActivity;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
/**
25+
* A fragment representing a list of Items.
26+
*/
27+
public class ItemFragment extends Fragment {
28+
29+
private static final String ARG_COLUMN_COUNT = "column-count";
30+
private int mColumnCount = 1;
31+
32+
static {
33+
addItem("测试1", RecyclerActivity.class);
34+
addItem("测试2", RecyclerActivity.class);
35+
addItem("测试3", RecyclerActivity.class);
36+
addItem("测试4", RecyclerActivity.class);
37+
38+
}
39+
40+
public static void addItem(String content, Class<?> clazz) {
41+
PlaceholderContent.addItem(new PlaceholderContent.PlaceholderItem(content, clazz));
42+
}
43+
44+
public ItemFragment() {
45+
}
46+
47+
public static ItemFragment newInstance(int columnCount) {
48+
ItemFragment fragment = new ItemFragment();
49+
Bundle args = new Bundle();
50+
args.putInt(ARG_COLUMN_COUNT, columnCount);
51+
fragment.setArguments(args);
52+
return fragment;
53+
}
54+
55+
@Override
56+
public void onCreate(Bundle savedInstanceState) {
57+
super.onCreate(savedInstanceState);
58+
59+
if (getArguments() != null) {
60+
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
61+
}
62+
}
63+
64+
@Override
65+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
66+
Bundle savedInstanceState) {
67+
View view = inflater.inflate(R.layout.fragment_item_list, container, false);
68+
69+
// Set the adapter
70+
if (view instanceof RecyclerView) {
71+
Context context = view.getContext();
72+
RecyclerView recyclerView = (RecyclerView) view;
73+
if (mColumnCount <= 1) {
74+
recyclerView.setLayoutManager(new LinearLayoutManager(context));
75+
} else {
76+
recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
77+
}
78+
MyItemRecyclerViewAdapter adapter = new MyItemRecyclerViewAdapter(PlaceholderContent.ITEMS);
79+
adapter.setOnItemClickListener((view1, placeholderItem, position) -> {
80+
FragmentActivity activity = getActivity();
81+
if (activity != null) {
82+
activity.startActivity(new Intent(activity, placeholderItem.clazz));
83+
}
84+
});
85+
recyclerView.setAdapter(adapter);
86+
}
87+
return view;
88+
}
89+
90+
91+
public static class MyItemRecyclerViewAdapter extends RecyclerView.Adapter<MyItemRecyclerViewAdapter.ViewHolder> {
92+
93+
private final List<PlaceholderContent.PlaceholderItem> mValues;
94+
private OnItemClickListener mOnItemClickListener;
95+
96+
public MyItemRecyclerViewAdapter(List<PlaceholderContent.PlaceholderItem> items) {
97+
mValues = items;
98+
}
99+
100+
@NonNull
101+
@Override
102+
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
103+
ViewHolder viewHolder = new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_item, parent, false));
104+
bindViewClickListener(viewHolder);
105+
return viewHolder;
106+
}
107+
108+
private void bindViewClickListener(ViewHolder viewHolder) {
109+
bindViewItemClickListener(viewHolder);
110+
}
111+
112+
private void bindViewItemClickListener(ViewHolder viewHolder) {
113+
viewHolder.itemView.setOnClickListener(v -> {
114+
if (mOnItemClickListener != null) {
115+
int position = viewHolder.getAbsoluteAdapterPosition();
116+
PlaceholderContent.PlaceholderItem placeholderItem = mValues.get(position);
117+
mOnItemClickListener.onItemClick(viewHolder.itemView, placeholderItem, position);
118+
}
119+
120+
121+
});
122+
}
123+
124+
@Override
125+
public void onBindViewHolder(final ViewHolder holder, int position) {
126+
holder.mItem = mValues.get(position);
127+
holder.mContentView.setText(mValues.get(position).content);
128+
}
129+
130+
@Override
131+
public int getItemCount() {
132+
return mValues.size();
133+
}
134+
135+
public void setOnItemClickListener(OnItemClickListener l) {
136+
mOnItemClickListener = l;
137+
}
138+
139+
public static class ViewHolder extends RecyclerView.ViewHolder {
140+
public final TextView mContentView;
141+
public PlaceholderContent.PlaceholderItem mItem;
142+
143+
public ViewHolder(View view) {
144+
super(view);
145+
mContentView = view.findViewById(R.id.content);
146+
}
147+
148+
@NonNull
149+
@Override
150+
public String toString() {
151+
return super.toString() + " '" + mContentView.getText() + "'";
152+
}
153+
154+
}
155+
156+
public interface OnItemClickListener {
157+
void onItemClick(View view, PlaceholderContent.PlaceholderItem placeholderItem, int position);
158+
}
159+
}
160+
161+
public static class PlaceholderContent {
162+
163+
public static final List<PlaceholderContent.PlaceholderItem> ITEMS = new ArrayList<>();
164+
165+
public static void addItem(PlaceholderContent.PlaceholderItem item) {
166+
ITEMS.add(item);
167+
}
168+
169+
/**
170+
* A placeholder item representing a piece of content.
171+
*/
172+
public static class PlaceholderItem {
173+
public final String content;
174+
public final Class<?> clazz;
175+
176+
public PlaceholderItem(String content, Class<?> clazz) {
177+
this.content = content;
178+
this.clazz = clazz;
179+
}
180+
181+
@NonNull
182+
@Override
183+
public String toString() {
184+
return content;
185+
}
186+
}
187+
}
188+
189+
190+
}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
package com.dds.anyui;
22

3-
import android.content.Intent;
43
import android.os.Bundle;
5-
import android.view.View;
64

75
import androidx.appcompat.app.AppCompatActivity;
86

9-
import com.dds.studiodemo.TabbedActivity;
10-
117

128
public class MainActivity extends AppCompatActivity {
139

1410
@Override
1511
protected void onCreate(Bundle savedInstanceState) {
1612
super.onCreate(savedInstanceState);
1713
setContentView(R.layout.activity_main);
18-
}
19-
20-
public void NavDraActivity(View view) {
21-
startActivity(new Intent(this, TabbedActivity.class));
22-
}
23-
24-
public void recyclerView(View view) {
25-
startActivity(new Intent(this, TestActivity.class));
14+
if (savedInstanceState == null) {
15+
ItemFragment itemFragment = ItemFragment.newInstance(1);
16+
getSupportFragmentManager().beginTransaction()
17+
.setReorderingAllowed(true)
18+
.add(R.id.fragment_container_view, itemFragment, null)
19+
.commit();
20+
}
2621

2722
}
2823

29-
public void TestAnimation(View view) {
30-
}
3124
}

app/src/main/java/com/dds/anyui/TestActivity.java

-29
This file was deleted.

app/src/main/java/com/dds/anyui/TestButton.java

-19
This file was deleted.
+3-32
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/fragment_container_view"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
8-
android:padding="16dp"
9-
tools:context=".MainActivity">
10-
11-
12-
<Button
13-
android:id="@+id/button"
14-
android:layout_width="match_parent"
15-
android:layout_height="wrap_content"
16-
android:onClick="NavDraActivity"
17-
android:text="NavDraActivity"
18-
android:textAllCaps="false" />
19-
20-
<Button
21-
android:id="@+id/button1"
22-
android:layout_width="match_parent"
23-
android:layout_height="wrap_content"
24-
android:onClick="recyclerView"
25-
android:text="RecyclerView"
26-
android:textAllCaps="false" />
27-
28-
29-
<Button
30-
android:id="@+id/button2"
31-
android:layout_width="match_parent"
32-
android:layout_height="wrap_content"
33-
android:onClick="TestAnimation"
34-
android:text="TestAnimation"
35-
android:textAllCaps="false" />
36-
</LinearLayout>
7+
tools:context=".MainActivity" />

app/src/main/res/layout/activity_multi.xml

-15
This file was deleted.

0 commit comments

Comments
 (0)