Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lorienzhang committed May 25, 2017
0 parents commit bf117ee
Show file tree
Hide file tree
Showing 28 changed files with 1,370 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
applicationId "com.lorien.wl"
minSdkVersion 15
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'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
testCompile 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions 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/lorienzhang/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
26 changes: 26 additions & 0 deletions src/androidTest/java/com/lorien/wl/ExampleInstrumentedTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lorien.wl;

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.lorien.wl", appContext.getPackageName());
}
}
23 changes: 23 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lorien.wl">

<uses-permission android:name="android.permission.INTERNET" />

<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>
</application>

</manifest>
67 changes: 67 additions & 0 deletions src/main/java/com/lorien/wl/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.lorien.wl;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.lorien.wl.view.WLLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private List<String> list = new ArrayList<>();
private WLLayout wl;

String htmlString = "<h1>Title1</h1><p>This is HTML text. <i>Formatted in italics.</i><br>Anothor Line.</p><br>" +
"<img src=\"http://img.blog.csdn.net/20160405153830915\" width=\"330px\" height=\"330px\"/><br>" +
"<h1>Title2</h1><p>This is HTML text. <i>Formatted in italics.</i><br>Anothor Line.</p><br>" +
"<img src=\"http://img.blog.csdn.net/20160405153830915\" width=\"330px\" height=\"330px\"/><br>" +
"<h1>Title3</h1><p>This is HTML text. <i>Formatted in italics.</i><br>Anothor Line.</p>" +
"<img src=\"http://img.blog.csdn.net/20160405153830915\" width=\"330px\" height=\"330px\"/><br>" +
"<h1>Title4</h1><p>This is HTML text. <i>Formatted in italics.</i><br>Anothor Line.</p>" +
"<img src=\"http://img.blog.csdn.net/20160405153830915\" width=\"330px\" height=\"330px\"/><br>" +
"<h1>Title5</h1><p>This is HTML text. <i>Formatted in italics.</i><br>Anothor Line.</p>" +
"<img src=\"http://img.blog.csdn.net/20160405153830915\" width=\"330px\" height=\"330px\"/><br>" +
"<h1>Title6</h1><p>This is HTML text. <i>Formatted in italics.</i><br>Anothor Line.</p>" +
"<img src=\"http://img.blog.csdn.net/20160405153830915\" width=\"330px\" height=\"330px\"/><br>";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

wl = (WLLayout) findViewById(R.id.wl);

// WebView
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadData(htmlString, "text/html", "utf-8");
WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
};
myWebView.setWebViewClient(webViewClient);

// ListView
for (int i = 0; i < 60; i++) {
list.add("评论:" + i);
}
ListView lv = (ListView) findViewById(R.id.list_view);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
View header = LayoutInflater.from(this).inflate(R.layout.header_view, lv, false);
lv.addHeaderView(header);
}

}
88 changes: 88 additions & 0 deletions src/main/java/com/lorien/wl/view/MyListView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.lorien.wl.view;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.ListView;
import android.widget.OverScroller;

/**
* Created by lorienzhang on 2017/5/23.
*/

public class MyListView extends ListView {

private FlingRunnable mFlingRunnable;

public MyListView(Context context) {
this(context, null);
}

public MyListView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

mFlingRunnable = new FlingRunnable();
}

public void flingY(int velocityY) {
// if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
// fling(velocityY);
// } else {
//
// }
mFlingRunnable.startFling(velocityY);
}

private class FlingRunnable implements Runnable {

private final OverScroller mScroller;

private int mLastFlingY;

private FlingRunnable() {
mScroller = new OverScroller(getContext());
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void run() {
if (getChildCount() == 0) {
endFling();
return;
}

boolean finish = !mScroller.computeScrollOffset()
|| mScroller.isFinished();
final int y = mScroller.getCurrY();
int delta = y - mLastFlingY;
if (!finish) {
mLastFlingY = y;
// ListView自动滚动
MyListView.this.scrollListBy(delta);
post(this);
} else {
endFling();
}
}

void startFling(int initialVelocity) {
int initialY = 0;
mLastFlingY = initialY;
mScroller.fling(0, initialY, 0, initialVelocity,
0, Integer.MAX_VALUE,
0, Integer.MAX_VALUE);
post(this);
}

void endFling() {
removeCallbacks(this);

mScroller.abortAnimation();
}
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/lorien/wl/view/MyWebView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.lorien.wl.view;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;

/**
* Created by lorienzhang on 2017/5/22.
*/

public class MyWebView extends WebView {

private OnScrollChangedCallback mOnScrollChangedCallback;

public MyWebView(Context context) {
super(context);
}

public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public MyWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);

if (mOnScrollChangedCallback != null) {
mOnScrollChangedCallback.onScroll(l, t, l - oldl, t - oldt, canScrollVertically(1));
}
}

public void setOnScrollChangedCallback(
final OnScrollChangedCallback onScrollChangedCallback) {
mOnScrollChangedCallback = onScrollChangedCallback;
}

/**
* 如果想要监听WebView的Scroll状态,实现这个借口
*/
public interface OnScrollChangedCallback {
void onScroll(int left, int top, int dx, int dy, boolean canScrollUp);
}
}

Loading

0 comments on commit bf117ee

Please sign in to comment.