Skip to content

Commit fffd05e

Browse files
committed
Initial commit
0 parents  commit fffd05e

35 files changed

+1235
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/compiler.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
defaultConfig {
6+
applicationId "x.chestnut.code.snippet"
7+
minSdkVersion 21
8+
targetSdkVersion 26
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
compileOptions {
20+
sourceCompatibility JavaVersion.VERSION_1_8
21+
targetCompatibility JavaVersion.VERSION_1_8
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
implementation 'com.android.support:appcompat-v7:26.1.0'
28+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
29+
implementation 'com.google.android:flexbox:0.2.5'
30+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
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

app/src/main/AndroidManifest.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="x.chestnut.code.snippet">
4+
5+
<application
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:theme="@style/AppTheme">
9+
<activity android:name=".MainActivity">
10+
<intent-filter>
11+
<action android:name="android.intent.action.MAIN" />
12+
13+
<category android:name="android.intent.category.LAUNCHER" />
14+
</intent-filter>
15+
</activity>
16+
<activity android:name=".ui.textView.TextViewActivity"></activity>
17+
</application>
18+
19+
</manifest>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package x.chestnut.code.snippet;
2+
3+
import android.view.Gravity;
4+
import android.view.View;
5+
import android.widget.TextView;
6+
7+
import com.google.android.flexbox.FlexboxLayout;
8+
9+
import x.chestnut.code.snippet.base.BaseActivity;
10+
import x.chestnut.code.snippet.ui.textView.TextViewActivity;
11+
import x.chestnut.code.snippet.utils.ConvertUtils;
12+
13+
public class MainActivity extends BaseActivity {
14+
15+
protected void addView(String content, View.OnClickListener onClickListener) {
16+
FlexboxLayout flexboxLayout = (FlexboxLayout) findViewById(R.id.flx);
17+
TextView textView = new TextView(this);
18+
textView.setBackground(getResources().getDrawable(R.drawable.tv_bg_round));
19+
textView.setText(content);
20+
textView.setGravity(Gravity.CENTER);
21+
int padding = ConvertUtils.dp2px(this, 10);
22+
textView.setPadding(padding,padding,padding,padding);
23+
flexboxLayout.addView(textView);
24+
int margin = ConvertUtils.dp2px(this, 5);
25+
int marginTopBottom = ConvertUtils.dp2px(this, 5);
26+
FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) textView.getLayoutParams();
27+
layoutParams.setMargins(margin, marginTopBottom, margin, marginTopBottom);
28+
textView.setClickable(true);
29+
textView.setFocusable(true);
30+
textView.setTag(content);
31+
textView.setOnClickListener(onClickListener);
32+
}
33+
34+
@Override
35+
public int getLayoutId() {
36+
return R.layout.activity_main;
37+
}
38+
39+
@Override
40+
public void lazyLoadViewAfterOnResume() {
41+
addView("TextView", view -> startActivity(TextViewActivity.class));
42+
}
43+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package x.chestnut.code.snippet.base;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.os.Looper;
6+
import android.support.annotation.LayoutRes;
7+
import android.support.annotation.Nullable;
8+
import android.support.v7.app.ActionBar;
9+
import android.support.v7.app.AppCompatActivity;
10+
11+
/**
12+
* <pre>
13+
* author: Chestnut
14+
* blog : http://www.jianshu.com/u/a0206b5f4526
15+
* time : 2019/3/24 23:26
16+
* desc :
17+
* thanks To:
18+
* dependent on:
19+
* update log:
20+
* </pre>
21+
*/
22+
23+
public abstract class BaseActivity extends AppCompatActivity{
24+
25+
@Override
26+
protected void onCreate(@Nullable Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(getLayoutId());
29+
Looper.myQueue().addIdleHandler(() -> {
30+
lazyLoadViewAfterOnResume();
31+
return false;
32+
});
33+
}
34+
35+
@LayoutRes
36+
public abstract int getLayoutId();
37+
38+
public abstract void lazyLoadViewAfterOnResume();
39+
40+
public void setTitle(String title) {
41+
ActionBar actionBar = getSupportActionBar();
42+
if (actionBar!=null) {
43+
actionBar.setTitle(title);
44+
}
45+
}
46+
47+
protected void startActivity(Class c) {
48+
startActivity(new Intent(this, c));
49+
}
50+
}

0 commit comments

Comments
 (0)