Skip to content

Commit dbcf9e6

Browse files
author
王宏雷
committed
[update]首次提交
0 parents  commit dbcf9e6

Some content is hidden

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

55 files changed

+2099
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdkVersion 29
7+
8+
defaultConfig {
9+
applicationId "com.whl.toutiaothumb"
10+
minSdkVersion 21
11+
targetSdkVersion 29
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
}
29+
30+
dependencies {
31+
32+
implementation 'androidx.appcompat:appcompat:1.2.0'
33+
implementation 'com.google.android.material:material:1.2.1'
34+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
35+
implementation 'androidx.navigation:navigation-fragment:2.3.1'
36+
implementation 'androidx.navigation:navigation-ui:2.3.1'
37+
testImplementation 'junit:junit:4.+'
38+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
39+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
40+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.whl.toutiaothumb;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.whl.toutiaothumb", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.whl.toutiaothumb">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.Toutiaothumb">
12+
<activity
13+
android:name=".MainActivity"
14+
android:label="@string/app_name"
15+
android:theme="@style/Theme.Toutiaothumb.NoActionBar">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.whl.toutiaothumb;
2+
3+
import android.os.Bundle;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.fragment.app.Fragment;
10+
import androidx.navigation.fragment.NavHostFragment;
11+
12+
public class FirstFragment extends Fragment {
13+
14+
@Override
15+
public View onCreateView(
16+
LayoutInflater inflater, ViewGroup container,
17+
Bundle savedInstanceState
18+
) {
19+
// Inflate the layout for this fragment
20+
return inflater.inflate(R.layout.fragment_first, container, false);
21+
}
22+
23+
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
24+
super.onViewCreated(view, savedInstanceState);
25+
26+
view.findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
27+
@Override
28+
public void onClick(View view) {
29+
NavHostFragment.findNavController(FirstFragment.this)
30+
.navigate(R.id.action_FirstFragment_to_SecondFragment);
31+
}
32+
});
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.whl.toutiaothumb;
2+
3+
import android.media.Image;
4+
import android.os.Bundle;
5+
6+
import com.google.android.material.floatingactionbutton.FloatingActionButton;
7+
import com.google.android.material.snackbar.Snackbar;
8+
import com.whl.toutiaothumb.View.ArticleRl;
9+
import com.whl.toutiaothumb.View.ArticleThumb;
10+
11+
import androidx.appcompat.app.AppCompatActivity;
12+
import androidx.appcompat.widget.Toolbar;
13+
14+
import android.view.View;
15+
16+
import android.view.Menu;
17+
import android.view.MenuItem;
18+
import android.widget.ImageView;
19+
20+
public class MainActivity extends AppCompatActivity {
21+
private ImageView ivThumb;
22+
private ArticleRl articleThumbRl;
23+
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.activity_main);
28+
ivThumb = findViewById(R.id.ivThumb);
29+
articleThumbRl = findViewById(R.id.articleThumbRl);
30+
ivThumb.setOnClickListener(new View.OnClickListener() {
31+
@Override
32+
public void onClick(View v) {
33+
articleThumbRl.setVisibility(View.VISIBLE);
34+
articleThumbRl.setThumb(true);
35+
}
36+
});
37+
}
38+
39+
@Override
40+
public boolean onCreateOptionsMenu(Menu menu) {
41+
// Inflate the menu; this adds items to the action bar if it is present.
42+
getMenuInflater().inflate(R.menu.menu_main, menu);
43+
return true;
44+
}
45+
46+
@Override
47+
public boolean onOptionsItemSelected(MenuItem item) {
48+
// Handle action bar item clicks here. The action bar will
49+
// automatically handle clicks on the Home/Up button, so long
50+
// as you specify a parent activity in AndroidManifest.xml.
51+
int id = item.getItemId();
52+
53+
//noinspection SimplifiableIfStatement
54+
if (id == R.id.action_settings) {
55+
return true;
56+
}
57+
58+
return super.onOptionsItemSelected(item);
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.whl.toutiaothumb;
2+
3+
import android.os.Bundle;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.fragment.app.Fragment;
10+
import androidx.navigation.fragment.NavHostFragment;
11+
12+
public class SecondFragment extends Fragment {
13+
14+
@Override
15+
public View onCreateView(
16+
LayoutInflater inflater, ViewGroup container,
17+
Bundle savedInstanceState
18+
) {
19+
// Inflate the layout for this fragment
20+
return inflater.inflate(R.layout.fragment_second, container, false);
21+
}
22+
23+
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
24+
super.onViewCreated(view, savedInstanceState);
25+
26+
view.findViewById(R.id.button_second).setOnClickListener(new View.OnClickListener() {
27+
@Override
28+
public void onClick(View view) {
29+
NavHostFragment.findNavController(SecondFragment.this)
30+
.navigate(R.id.action_SecondFragment_to_FirstFragment);
31+
}
32+
});
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.whl.toutiaothumb.View;
2+
3+
import android.content.Context;
4+
import android.graphics.Paint;
5+
import android.util.AttributeSet;
6+
import android.util.Log;
7+
import android.view.ViewGroup;
8+
import android.widget.RelativeLayout;
9+
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
import java.util.Collections;
13+
import java.util.List;
14+
15+
/**
16+
* author honglei92
17+
* date 2021/1/9
18+
*/
19+
public class ArticleRl extends RelativeLayout {
20+
private static final String TAG = "ArticleThumb";
21+
private long lastClickTime;
22+
private Context mContext;
23+
24+
public ArticleRl(Context context) {
25+
this(context, null);
26+
}
27+
28+
public ArticleRl(Context context, AttributeSet attrs) {
29+
this(context, attrs, 0);
30+
}
31+
32+
public ArticleRl(Context context, AttributeSet attrs, int defStyleAttr) {
33+
super(context, attrs, defStyleAttr);
34+
init(context);
35+
mContext = context;
36+
}
37+
38+
private void init(Context context) {
39+
addThumbImage(context);
40+
}
41+
42+
private void addThumbImage(Context context) {
43+
List<Integer> list = new ArrayList<>();
44+
for (int i = 0; i < 5; i++) {
45+
list.add(i);
46+
}
47+
Collections.shuffle(list);
48+
for (int i = 0; i < 5; i++) {
49+
LayoutParams layoutParams = new LayoutParams(100, 100);
50+
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
51+
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
52+
switch (list.get(i)) {
53+
case 1:
54+
this.addView(new ArticleThumb1(context), layoutParams);
55+
break;
56+
case 2:
57+
this.addView(new ArticleThumb2(context), layoutParams);
58+
break;
59+
case 3:
60+
this.addView(new ArticleThumb3(context), layoutParams);
61+
break;
62+
case 4:
63+
this.addView(new ArticleThumb4(context), layoutParams);
64+
break;
65+
default:
66+
this.addView(new ArticleThumb(context), layoutParams);
67+
}
68+
}
69+
}
70+
71+
public ArticleRl(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
72+
super(context, attrs, defStyleAttr, defStyleRes);
73+
}
74+
75+
public void setThumb(boolean isThumb) {
76+
if (System.currentTimeMillis() - lastClickTime > 800) {
77+
lastClickTime = System.currentTimeMillis();
78+
for (int i = 0; i < 5; i++) {
79+
if (getChildAt(i) instanceof ArticleThumb)
80+
((ArticleThumb) getChildAt(i)).setThumb(true);
81+
else if (getChildAt(i) instanceof ArticleThumb1)
82+
((ArticleThumb1) getChildAt(i)).setThumb(true);
83+
else if (getChildAt(i) instanceof ArticleThumb2)
84+
((ArticleThumb2) getChildAt(i)).setThumb(true);
85+
else if (getChildAt(i) instanceof ArticleThumb3)
86+
((ArticleThumb3) getChildAt(i)).setThumb(true);
87+
else if (getChildAt(i) instanceof ArticleThumb4)
88+
((ArticleThumb4) getChildAt(i)).setThumb(true);
89+
}
90+
} else {
91+
Log.i(TAG, "当前动画化正在执行");
92+
addThumbImage(mContext);
93+
for (int i = getChildCount() - 5; i < getChildCount(); i++) {
94+
if (getChildAt(i) instanceof ArticleThumb)
95+
((ArticleThumb) getChildAt(i)).setThumb(true);
96+
else if (getChildAt(i) instanceof ArticleThumb1)
97+
((ArticleThumb1) getChildAt(i)).setThumb(true);
98+
else if (getChildAt(i) instanceof ArticleThumb2)
99+
((ArticleThumb2) getChildAt(i)).setThumb(true);
100+
else if (getChildAt(i) instanceof ArticleThumb3)
101+
((ArticleThumb3) getChildAt(i)).setThumb(true);
102+
else if (getChildAt(i) instanceof ArticleThumb4)
103+
((ArticleThumb4) getChildAt(i)).setThumb(true);
104+
}
105+
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)