Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
whilu committed Dec 30, 2015
0 parents commit 3802a9e
Show file tree
Hide file tree
Showing 35 changed files with 843 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.gradle
/local.properties
/.idea/workspace.xml
.DS_Store
/build
# built application files
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class
.DS_Store

# generated files
bin/
gen/
Wiki/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project
.settings/

# Proguard folder generated by Eclipse
proguard/

#Android Studio
build/
src/androidTest/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

#gradle
.gradle/
.idea
app/build
app/src/androidTest
46 changes: 46 additions & 0 deletions androidtagview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.gradle
/local.properties
/.idea/workspace.xml
.DS_Store
/build
# built application files
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class
.DS_Store

# generated files
bin/
gen/
Wiki/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project
.settings/

# Proguard folder generated by Eclipse
proguard/

#Android Studio
build/
src/androidTest/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

#gradle
.gradle/
.idea
app/build
app/src/androidTest
25 changes: 25 additions & 0 deletions androidtagview/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
17 changes: 17 additions & 0 deletions androidtagview/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in F:\code\android\adt-bundle-windows-x86_64-20140702\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 *;
#}
11 changes: 11 additions & 0 deletions androidtagview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.lujun.androidtagview">

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

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package co.lujun.androidtagview;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

/**
* Author: lujun
* Date: 2015/12/30 17:14
*/
public class ContainerLayout extends ViewGroup {

private int mVerticalInterval = 10;

private int mHorizontalInterval = 10;
private int mScreenWidth;

private static final String TAG = "ContainerLayout";

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

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

public ContainerLayout(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
init(context);
}

private void init(Context context){
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
mScreenWidth = metrics.widthPixels;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

measureChildren(widthMeasureSpec, heightMeasureSpec);
final int childCount = getChildCount();
int lines = childCount == 0 ? 0 : getChildLines(childCount);
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);

if (childCount == 0){
setMeasuredDimension(0, 0);
}else if (heightSpecMode == MeasureSpec.AT_MOST) {
setMeasuredDimension(widthSpecSize,
(mVerticalInterval + getChildAt(0).getMeasuredHeight()) * lines);
}else {
setMeasuredDimension(widthSpecSize, heightSpecSize);
}
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int childCount = getChildCount();
int curLeft = l, curTop = t;
for (int i = 0; i < childCount; i++) {
final View childView = getChildAt(i);
if (childView.getVisibility() != GONE) {
final int width = childView.getMeasuredWidth();
final int height = childView.getMeasuredHeight();
if (curLeft + width + mHorizontalInterval > mScreenWidth){
curLeft = l;
curTop += height + mVerticalInterval;
}
Log.d(TAG, getTop() + "," + curTop);
childView.layout(curLeft, curTop, curLeft + width, curTop + height);
curLeft += width + mHorizontalInterval;
}
}
}

private int getChildLines(int childCount){
int lines = 1;
for (int i = 0, curLineW = 0; i < childCount; i++) {
curLineW += getChildAt(i).getMeasuredWidth() + mHorizontalInterval;
if (curLineW > mScreenWidth){
lines++;
curLineW = 0;
}
}
return lines;
}

private int sp2px(float spValue) {
final float fontScale = getContext().getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}

private int dp2px(float dp) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
}
3 changes: 3 additions & 0 deletions androidtagview/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">AndroidTagView</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.lujun.androidtagview;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
23 changes: 23 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
18 changes: 18 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Loading

0 comments on commit 3802a9e

Please sign in to comment.