Skip to content

Commit c20846e

Browse files
committed
committed the first version
0 parents  commit c20846e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2541
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
.DS_Store
6+
/build
7+
/captures

build.gradle

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apply plugin: 'com.android.library'
2+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
dependencies {
9+
classpath 'com.android.tools.build:gradle:2.2.2'
10+
11+
// NOTE: Do not place your application dependencies here; they belong
12+
// in the individual module build.gradle files
13+
}
14+
}
15+
16+
allprojects {
17+
repositories {
18+
jcenter()
19+
mavenCentral()
20+
}
21+
}
22+
23+
task clean(type: Delete) {
24+
delete rootProject.buildDir
25+
}
26+
27+
android {
28+
compileSdkVersion 25
29+
buildToolsVersion "25.0.1"
30+
31+
defaultConfig {
32+
minSdkVersion 14
33+
targetSdkVersion 25
34+
versionCode 1
35+
versionName "1.0"
36+
}
37+
buildTypes {
38+
release {
39+
minifyEnabled false
40+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
41+
}
42+
}
43+
compileOptions {
44+
targetCompatibility 1.7
45+
sourceCompatibility 1.7
46+
}
47+
}
48+
49+
dependencies {
50+
testCompile 'junit:junit:4.12'
51+
52+
compile 'com.android.support:appcompat-v7:25.0.1'
53+
compile 'com.android.support:recyclerview-v7:25.0.1'
54+
55+
compile 'com.google.guava:guava:19.0'
56+
}

gradle.properties

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14+
15+
# When configured, Gradle will run in incubating parallel mode.
16+
# This option should only be used with decoupled projects. More details, visit
17+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18+
# org.gradle.parallel=true

proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/shepilov/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

settings.gradle

Whitespace-only changes.

src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="net.buggy.components">
3+
</manifest>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package net.buggy.components;
2+
3+
4+
import android.content.Context;
5+
import android.graphics.Canvas;
6+
import android.graphics.Paint;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.LinearLayout;
10+
11+
public class BorderDecorator extends LinearLayout {
12+
13+
private Border leftBorder;
14+
private Border rightBorder;
15+
private Border topBorder;
16+
private Border bottomBorder;
17+
18+
private final Paint paint;
19+
20+
public BorderDecorator(Context context) {
21+
super(context);
22+
23+
setWillNotDraw(false);
24+
25+
paint = new Paint();
26+
paint.setStyle(Paint.Style.STROKE);
27+
}
28+
29+
@Override
30+
public void addView(View child, int index, ViewGroup.LayoutParams params) {
31+
if (getChildCount() > 0) {
32+
throw new IllegalStateException();
33+
}
34+
35+
LayoutParams overwrittenParams = new LayoutParams(
36+
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
37+
38+
super.addView(child, index, overwrittenParams);
39+
}
40+
41+
public void setLeftBorder(Border leftBorder) {
42+
this.leftBorder = leftBorder;
43+
}
44+
45+
public void setRightBorder(Border rightBorder) {
46+
this.rightBorder = rightBorder;
47+
}
48+
49+
public void setTopBorder(Border topBorder) {
50+
this.topBorder = topBorder;
51+
}
52+
53+
public void setBottomBorder(Border bottomBorder) {
54+
this.bottomBorder = bottomBorder;
55+
}
56+
57+
public void setAllBorders(Border border) {
58+
this.leftBorder = border;
59+
this.rightBorder = border;
60+
this.topBorder = border;
61+
this.bottomBorder = border;
62+
}
63+
64+
@Override
65+
protected void onDraw(Canvas canvas) {
66+
super.onDraw(canvas);
67+
68+
if (leftBorder != null) {
69+
paint.setColor(leftBorder.color);
70+
paint.setStrokeWidth(leftBorder.width);
71+
72+
canvas.drawLine(0, 0, 0, getHeight(), paint);
73+
}
74+
75+
if (rightBorder != null) {
76+
paint.setColor(rightBorder.color);
77+
paint.setStrokeWidth(rightBorder.width);
78+
79+
canvas.drawLine(getWidth()-1, 0, getWidth()-1, getHeight(), paint);
80+
}
81+
82+
if (topBorder != null) {
83+
paint.setColor(topBorder.color);
84+
paint.setStrokeWidth(topBorder.width);
85+
86+
canvas.drawLine(0, 0, getWidth(), 0, paint);
87+
}
88+
89+
if (bottomBorder != null) {
90+
paint.setColor(bottomBorder.color);
91+
paint.setStrokeWidth(bottomBorder.width);
92+
93+
canvas.drawLine(0, getHeight()-1, getWidth(), getHeight()-1, paint);
94+
}
95+
}
96+
97+
public static class Border {
98+
private final int width;
99+
private final int color;
100+
101+
public Border(int width, int color) {
102+
this.width = width;
103+
this.color = color;
104+
}
105+
}
106+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package net.buggy.components;
2+
3+
4+
import android.annotation.TargetApi;
5+
import android.content.Context;
6+
import android.graphics.drawable.ShapeDrawable;
7+
import android.graphics.drawable.shapes.RoundRectShape;
8+
import android.os.Build;
9+
import android.util.AttributeSet;
10+
import android.view.Gravity;
11+
import android.view.View;
12+
import android.widget.ImageButton;
13+
import android.widget.ImageView;
14+
import android.widget.LinearLayout;
15+
import android.widget.TextView;
16+
17+
import java.util.Arrays;
18+
import java.util.List;
19+
import java.util.concurrent.CopyOnWriteArrayList;
20+
21+
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
22+
23+
public class Chip extends LinearLayout {
24+
25+
private TextView textView;
26+
27+
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
28+
29+
public Chip(Context context) {
30+
super(context);
31+
init();
32+
}
33+
34+
public Chip(Context context, AttributeSet attrs) {
35+
super(context, attrs);
36+
init();
37+
}
38+
39+
public Chip(Context context, AttributeSet attrs, int defStyleAttr) {
40+
super(context, attrs, defStyleAttr);
41+
init();
42+
}
43+
44+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
45+
public Chip(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
46+
super(context, attrs, defStyleAttr, defStyleRes);
47+
init();
48+
}
49+
50+
private void init() {
51+
final int dp4 = ViewUtils.dpToPx(4f, getContext());
52+
final int dp13 = ViewUtils.dpToPx(13f, getContext());
53+
final int dp32 = ViewUtils.dpToPx(32f, getContext());
54+
55+
setOrientation(HORIZONTAL);
56+
setGravity(Gravity.CENTER_VERTICAL);
57+
setPadding(
58+
ViewUtils.dpToPx(12f, getContext()),
59+
0,
60+
0,
61+
0);
62+
63+
textView = new TextView(getContext());
64+
textView.setGravity(Gravity.CENTER);
65+
textView.setIncludeFontPadding(false);
66+
final LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
67+
WRAP_CONTENT, dp32);
68+
textView.setLayoutParams(textViewParams);
69+
70+
final ImageButton imageButton = new ImageButton(getContext());
71+
imageButton.setImageResource(R.drawable.ic_cancel_black_24dp);
72+
final LinearLayout.LayoutParams imageViewParams = new LinearLayout.LayoutParams(
73+
WRAP_CONTENT, WRAP_CONTENT);
74+
imageViewParams.setMargins(dp4, 0, dp4, 0);
75+
imageButton.setLayoutParams(imageViewParams);
76+
imageButton.setPadding(0, 0, 0, 0);
77+
imageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
78+
imageButton.setAlpha(0.30f);
79+
imageButton.setOnClickListener(new OnClickListener() {
80+
@Override
81+
public void onClick(View v) {
82+
fireCloseClicked();
83+
}
84+
});
85+
86+
addView(textView, textViewParams);
87+
addView(imageButton, imageViewParams);
88+
89+
final float[] corners = new float[8];
90+
Arrays.fill(corners, dp13);
91+
final RoundRectShape rectShape = new RoundRectShape(corners, null, null);
92+
final ShapeDrawable background = new ShapeDrawable(rectShape);
93+
background.getPaint().setColor(0xFFE0E0E0);
94+
95+
ViewUtils.setBackground(this, background);
96+
}
97+
98+
public void setText(String text) {
99+
textView.setText(text);
100+
}
101+
102+
private void fireCloseClicked() {
103+
for (Listener listener : listeners) {
104+
listener.closeClicked();
105+
}
106+
}
107+
108+
public void addListener(Listener listener) {
109+
listeners.add(listener);
110+
}
111+
112+
public interface Listener {
113+
void closeClicked();
114+
}
115+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package net.buggy.components;
2+
3+
4+
import android.content.Context;
5+
import android.support.v4.widget.SwipeRefreshLayout;
6+
import android.util.AttributeSet;
7+
import android.view.GestureDetector;
8+
import android.view.MotionEvent;
9+
import android.view.ViewConfiguration;
10+
11+
public class SmartInterceptSwipeRefreshLayout extends SwipeRefreshLayout {
12+
private final int mTouchSlop;
13+
private final GestureDetector mGestureDetector;
14+
15+
public SmartInterceptSwipeRefreshLayout(Context context) {
16+
super(context);
17+
18+
mGestureDetector = new GestureDetector(context, new YScrollDetector());
19+
setFadingEdgeLength(0);
20+
21+
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
22+
}
23+
24+
public SmartInterceptSwipeRefreshLayout(Context context, AttributeSet attrs) {
25+
super(context, attrs);
26+
27+
mGestureDetector = new GestureDetector(context, new YScrollDetector());
28+
setFadingEdgeLength(0);
29+
30+
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
31+
}
32+
33+
@Override
34+
public boolean onInterceptTouchEvent(MotionEvent ev) {
35+
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
36+
}
37+
38+
private class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
39+
@Override
40+
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
41+
final float absDistanceY = Math.abs(distanceY);
42+
43+
if (absDistanceY < mTouchSlop) {
44+
return false;
45+
}
46+
47+
return absDistanceY > Math.abs(distanceX);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)