Skip to content

Commit

Permalink
借鉴库
Browse files Browse the repository at this point in the history
  • Loading branch information
yxihc committed Mar 26, 2021
1 parent 1f709d9 commit 623bd9f
Show file tree
Hide file tree
Showing 43 changed files with 2,552 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

plugins {
id 'com.android.application'
}
Expand Down Expand Up @@ -26,14 +27,28 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

viewBinding {
enabled = true
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(path: ':music')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


// implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'

// implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'

implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'


}
22 changes: 21 additions & 1 deletion app/src/main/java/com/taopao/tpmusicdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.LayoutInflater;

import com.taopao.music.MusicPlayerManager;
import com.taopao.tpmusicdemo.databinding.ActivityMainBinding;

import org.apache.commons.lang3.time.DurationFormatUtils;

public class MainActivity extends AppCompatActivity {
private ActivityMainBinding mBinding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBinding = ActivityMainBinding.inflate(LayoutInflater.from(this));
setContentView(mBinding.getRoot());
initView();
}






private void initView() {
mBinding.btnStart.setOnClickListener(v -> {
MusicPlayerManager.getInstance().init(this);
});
}
}
43 changes: 43 additions & 0 deletions app/src/main/java/com/taopao/tpmusicdemo/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.taopao.tpmusicdemo;

import org.apache.commons.lang3.time.DurationFormatUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
* @Author: TaoPao
* @Date: 3/26/21 10:42 AM
* @Description: java类作用描述
*/
public class Test {

public static void main(String args[]) {

System.out.print("年龄:"+TpDateUtils.getAge("2019-8-30"));
System.out.print("\n年"+TpDateUtils.getAge2Year("2019-8-30"));
System.out.print("\n月"+TpDateUtils.getAge2Monh("2019-8-30"));
System.out.print("\n日"+TpDateUtils.getAge2Day("2019-8-30"));

}












}






165 changes: 165 additions & 0 deletions app/src/main/java/com/taopao/tpmusicdemo/TpDateUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package com.taopao.tpmusicdemo;

import org.apache.commons.lang3.time.DurationFormatUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
* @Author: TaoPao
* @Date: 3/26/21 4:29 PM
* @Description: java类作用描述
*/
public class TpDateUtils {

public static int getYear(String startTime, String endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date startDate = sdf.parse(startTime);
Date endDate = sdf.parse(endTime);
return getBaseDateType(startDate, endDate, "yyyy");
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}

public static int getYear(Date startDate, Date endDate) {
return getBaseDateType(startDate, endDate, "yyyy");
}


public static int getMonth(String startTime, String endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date startDate = sdf.parse(startTime);
Date endDate = sdf.parse(endTime);
return getBaseDateType(startDate, endDate, "MM");
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}

public static int getMonth(Date startDate, Date endDate) {
return getBaseDateType(startDate, endDate, "MM");
}


public static int getDay(String startTime, String endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date startDate = sdf.parse(startTime);
Date endDate = sdf.parse(endTime);
return getBaseDateType(startDate, endDate, "dd");
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}

public static int getDay(Date startDate, Date endDate) {
return getBaseDateType(startDate, endDate, "dd");
}

private static int getBaseDateType(Date startDate, Date endDate, String format) {
String nowDateString = "";
if (endDate.getTime() >= startDate.getTime()) {
nowDateString = DurationFormatUtils.formatPeriod(
startDate.getTime(),
endDate.getTime(),
format);
} else {
nowDateString = DurationFormatUtils.formatPeriod(
endDate.getTime(),
startDate.getTime(),
format);
}
return Integer.parseInt(nowDateString);
}

public static int getAge2Day(String startTime) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String format = sdf.format(date);
return getDay(startTime, format);
}

public static int getAge2Monh(String startTime) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String format = sdf.format(date);
return getMonth(startTime, format);
}

public static int getAge2Year(String startTime) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String format = sdf.format(date);
return getYear(startTime, format);
}

public static String getAge(String startTime) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String format = sdf.format(date);
return getAge(startTime, format);
}

public static String getAge(String startTime, String endTime) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = sdf.parse(startTime);
Date endDate = sdf.parse(endTime);

String nowDateString = "";
if (endDate.getTime() >= startDate.getTime()) {
nowDateString = DurationFormatUtils.formatPeriod(
startDate.getTime(),
endDate.getTime(),
"yyyy-MM-dd");
} else {
nowDateString = DurationFormatUtils.formatPeriod(
endDate.getTime(),
startDate.getTime(),
"yyyy-MM-dd");
}

Date nowDate = sdf.parse(nowDateString);
Calendar nowCalendar = Calendar.getInstance();
nowCalendar.setTime(nowDate);

int nowYear = nowCalendar.get(Calendar.YEAR); //当前年份
int nowMonth = nowCalendar.get(Calendar.MONTH) + 1; //当前月份
int nowDay = nowCalendar.get(Calendar.DAY_OF_MONTH); //当前日期


String age = "";
if (nowYear > 0) {
age = nowYear + "年";
}
if (nowMonth > 0) {
age = age + nowMonth + "月";
} else {
if (nowYear > 0) {
age = age + "零";
}
}
if (nowDay >= 0) {
age = age + nowDay + "天";
}
if (endDate.getTime() >= startDate.getTime()) {
return age;
} else {
return "距离出生还有" + age;
}

} catch (Exception e) {
e.printStackTrace();
}
return "";
}

}
21 changes: 11 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/btn_start"
android:text="开启服务"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Button>


</LinearLayout>
1 change: 1 addition & 0 deletions music/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions music/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

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

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Empty file added music/consumer-rules.pro
Empty file.
Loading

0 comments on commit 623bd9f

Please sign in to comment.