Skip to content

Commit

Permalink
备份代码
Browse files Browse the repository at this point in the history
  • Loading branch information
aichixiguaj committed Feb 16, 2022
1 parent d56a233 commit 5f3722c
Show file tree
Hide file tree
Showing 60 changed files with 2,570 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# NeuomorphismAndroid
# NeuomorphismAndroid

使用自定义Drawable实现
代码控制显示方式

![](img/img1.jpg)
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.example.neuomorphism"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation project("::neuomorphism")
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.neuomorphism

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.neuomorphism", appContext.packageName)
}
}
27 changes: 27 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.neuomorphism">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".Neuomprphism1Activity" >

</activity>

</application>

</manifest>
30 changes: 30 additions & 0 deletions app/src/main/java/com/example/neuomorphism/DimensionsUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.neuomorphism;

import android.content.Context;
import android.util.DisplayMetrics;

public class DimensionsUtil {

/**
* This method converts dp unit to equivalent pixels, depending on device density.
*
* @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
* @param context Context to get resources and device specific display metrics
* @return A float value to represent px equivalent to dp depending on device density
*/
public static float convertDpToPixel(float dp, Context context){
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}

/**
* This method converts device specific pixels to density independent pixels.
*
* @param px A value in px (pixels) unit. Which we need to convert into db
* @param context Context to get resources and device specific display metrics
* @return A float value to represent dp equivalent to px value
*/
public static float convertPixelsToDp(float px, Context context){
return px / ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}

}
61 changes: 61 additions & 0 deletions app/src/main/java/com/example/neuomorphism/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.example.neuomorphism

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.aichixigua.neuomorphism.manager.NEBuilder
import com.aichixigua.neuomorphism.ne_const.NEDrawableType
import com.aichixigua.neuomorphism.ne_const.NEStateType
import com.aichixigua.neuomorphism.util.NEColorUtil
import kotlinx.android.synthetic.main.activity_main.*

/**
* @author : JYM
* @description : 主页
* @email : [email protected]
* @date : 2021/6/25 15:32
*/
class MainActivity : AppCompatActivity(R.layout.activity_main) {

private val backgroundColor = Color.parseColor("#E0E0E0")

override fun onResume() {
super.onResume()

llContainer.setBackgroundColor(backgroundColor)

val brightColor = NEColorUtil.manipulateColor(backgroundColor, 1.095f)
val dimColor = NEColorUtil.manipulateColor(backgroundColor, 0.94f)

btn1.background = NEBuilder()
.setType(NEStateType.PRESSED)
.setCornerRadius(10f)
.setLightColor(brightColor, dimColor)
.buildDrawable()

NEBuilder()
.setType(NEStateType.FLAT)
.setLightWidth(18f)
.setCornerRadius(18f)
.setBackgroundColor(backgroundColor)
.setLightColor(brightColor, dimColor)
.withView(btn2)

btn3.background = NEBuilder()
.setType(NEStateType.CONVEX)
.setLightWidth(15f)
.setCornerRadius(18f)
.setLightColor(brightColor, dimColor)
.buildDrawable()


NEBuilder()
.setType(NEStateType.CONCAVE)
.setDrawableType(NEDrawableType.CIRCLE)
.setBackgroundColor(backgroundColor)
.setLightColor(brightColor, dimColor)
.withView(btn4)
}


}
Loading

0 comments on commit 5f3722c

Please sign in to comment.