Skip to content

Commit

Permalink
add lyric group
Browse files Browse the repository at this point in the history
  • Loading branch information
moomoon committed Dec 21, 2016
1 parent 3d62683 commit 0a2ebff
Show file tree
Hide file tree
Showing 19 changed files with 435 additions and 84 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
testCompile 'junit:junit:4.12'
compile project(path: ':library')
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.yi.lrc;
package com.dxm.sample;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yi.lrc">
package="com.dxm.sample">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Expand All @@ -12,7 +12,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name="com.dxm.sample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/lyric.lrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ti:一个人想着一个人] [ar:曾沛慈] [al:终极一班2片尾曲] [t_time:(01:40)] [length: 2:31][offset: - 23][00:01.99] 一个人想着一个人[00:03.46] 《终极一班2》片尾曲[00:05.47] 演唱:曾沛慈[00:12.61] 你离开的那一天[00:15.93] 天空有点灰[00:19.48] 见不著你最爱的蓝天[00:25.69] 少了一个人斗嘴[00:30.26] 多些朋友的安慰[00:34.00] 一切都不是错觉[00:40.78] 来不及道声感谢[00:44.06] 故事已结尾[00:47.79] 太多事情来不及后悔[00:54.20] 我还有太多心愿[00:58.43] 太多梦没有实现[01:01.90] 桌上还留著过去的照片[01:08.11] 我一个人的失眠[01:09.89] 一个的空间[01:11.60] 一个人的想念[01:13.43] 两个人的画面[01:15.60] 是谁的眼泪[01:17.42] 是谁的憔悴[01:19.10] 洒满地的心碎[01:21.98] 我一个人的冒险[01:23.77] 一个人的座位[01:25.56] 一个人想著一个人[03:01:29.81] 眼角的泪这不是错觉
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/com/dxm/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.dxm.sample;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.dxm.lrc.FileLineReader;
import com.dxm.lrc.LyricGroup;
import com.dxm.lrc.LyricItem;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
FileLineReader reader = FileLineReader.fromStream(getAssets().open("lyric.lrc"));
if (null != reader) {
LyricGroup group = LyricGroup.builder().addItems(reader.parse(LyricItem.LineParser.Instance), LyricGroup.Policy.PickFirst).build();
((TextView) findViewById(R.id.tv)).setText(group.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
26 changes: 0 additions & 26 deletions app/src/main/java/com/yi/lrc/MainActivity.java

This file was deleted.

3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.yi.lrc.MainActivity">
tools:context="com.dxm.sample.MainActivity">

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
Expand Down
17 changes: 17 additions & 0 deletions app/src/test/java/com/dxm/lrc/ExampleUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.dxm.sample;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
1 change: 1 addition & 0 deletions library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
27 changes: 27 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions library/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/ants/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# 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,26 @@
package com.dxm.lrc;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

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

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.dxm.lrc.test", appContext.getPackageName());
}
}
13 changes: 13 additions & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.dxm.lrc"
>

<application android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.yi.lrc;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
package com.dxm.lrc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
Expand All @@ -20,13 +14,13 @@
*/

public class FileLineReader {
@NonNull private final BufferedReader reader;
private final BufferedReader reader;

private FileLineReader(@NonNull BufferedReader reader) {
private FileLineReader(BufferedReader reader) {
this.reader = reader;
}

@Nullable private String readLine() {
private String readLine() {
try {
return reader.readLine();
} catch (IOException e) {
Expand All @@ -35,23 +29,19 @@ private FileLineReader(@NonNull BufferedReader reader) {
}
}

@Nullable public static FileLineReader fromPath(@NonNull String path) {
public static FileLineReader fromStream(InputStream stream) {
try {
return new FileLineReader(new BufferedReader(new InputStreamReader(new FileInputStream(new File(path)), "utf-8")));
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
return new FileLineReader(new BufferedReader(new InputStreamReader(stream, "utf-8")));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}

@NonNull public<T> List<T> read(Output<T> output) {
public <T> List<T> parse(Parser<T> output) {
List<T> l = new LinkedList<>();
String s;
while (!output.stop() && null != (s = readLine())) {
Log.e("read", "s = " + s);
T value = output.parse(s);
if (null != value) l.add(value);
}
Expand All @@ -63,8 +53,8 @@ private FileLineReader(@NonNull BufferedReader reader) {
return Collections.unmodifiableList(l);
}

interface Output<T> {
@Nullable T parse(@NonNull String input);
interface Parser<T> {
T parse(String input);

boolean stop();
}
Expand Down
Loading

0 comments on commit 0a2ebff

Please sign in to comment.