();
41 | for (int i=0;i<50;i++){
42 | PraiseBean bean=new PraiseBean();
43 | bean.userNick="测试点赞 "+i+" 号";
44 | bean.userId=i;
45 | testBeans.add(bean);
46 | }
47 | }
48 |
49 | @Override
50 | protected void onDestroy() {
51 | super.onDestroy();
52 | PraiseWidget.clearPraiseWidgetCache();
53 | }
54 |
55 | @Override
56 | public void onClick(View v) {
57 | switch (v.getId()){
58 | case R.id.btn_add:
59 | add();
60 | break;
61 | case R.id.btn_sub:
62 | sub();
63 | break;
64 | default:
65 | break;
66 | }
67 |
68 | }
69 |
70 | private void sub() {
71 | if (testBeans!=null&&testBeans.size()>0){
72 | testBeans.remove(testBeans.size()-1);
73 | }
74 | mPraiseWidget.setDataByArray(testBeans);
75 | }
76 |
77 | private void add() {
78 | if (testBeans!=null){
79 | PraiseBean newBean=new PraiseBean();
80 | newBean.userId=testBeans.size()+1;
81 | newBean.userNick="新加入的哦";
82 | testBeans.add(newBean);
83 | }
84 | mPraiseWidget.setDataByArray(testBeans);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/widget/praisewidget/bean/PraiseBean.java:
--------------------------------------------------------------------------------
1 | package widget.praisewidget.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by 大灯泡 on 2015/11/21.
7 | */
8 | public class PraiseBean implements Serializable {
9 | public String userNick;//点赞用户的名字
10 | public int userId;//点赞用户的ID
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/widget/praisewidget/clickable/PraiseClick.java:
--------------------------------------------------------------------------------
1 | package widget.praisewidget.clickable;
2 |
3 | import android.content.Context;
4 | import android.text.TextPaint;
5 | import android.text.style.ClickableSpan;
6 | import android.view.View;
7 | import android.widget.Toast;
8 |
9 | /**
10 | * Created by 大灯泡 on 2015/11/21.
11 | */
12 | public class PraiseClick extends ClickableSpan{
13 | private static final int DEFAULT_COLOR=0xff517fae;
14 |
15 | private int color;
16 | private int userID;
17 | private String userNick;
18 | private Context mContext;
19 | private int textSize;
20 |
21 | public PraiseClick(Context context, String userNick, int userID, int color) {
22 | mContext = context;
23 | this.userNick = userNick;
24 | this.userID = userID;
25 | this.color = color;
26 | }
27 |
28 | public PraiseClick(Context context, int userID, int color) {
29 | this(context,"",userID,color);
30 | }
31 |
32 | public PraiseClick(Context context, int userID) {
33 | this(context,"",userID,0);
34 | }
35 |
36 | public PraiseClick(Context context, String userNick, int userID) {
37 | this(context,userNick,userID,0);
38 | }
39 | public PraiseClick(Context context, String userNick, int userID, int color,int textSize) {
40 | this(context,userNick,userID,color);
41 | this.textSize=textSize;
42 | }
43 | @Override
44 | public void onClick(View widget) {
45 | Toast.makeText(mContext,"当前用户名是: "+userNick+" 它的ID是: "+userID,Toast.LENGTH_SHORT).show();
46 |
47 | }
48 |
49 | @Override
50 | public void updateDrawState(TextPaint ds) {
51 | super.updateDrawState(ds);
52 | //去掉下划线
53 | if (color == 0) {
54 | ds.setColor(DEFAULT_COLOR);
55 | } else {
56 | ds.setColor(color);
57 | }
58 | ds.setTextSize(textSize);
59 | ds.setUnderlineText(false);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/widget/praisewidget/widget/CustomImageSpan.java:
--------------------------------------------------------------------------------
1 | package widget.praisewidget.widget;
2 |
3 | /**
4 | * Created by 大灯泡 on 2015/9/28.
5 | */
6 |
7 | import android.content.Context;
8 | import android.graphics.Canvas;
9 | import android.graphics.Paint;
10 | import android.graphics.Rect;
11 | import android.graphics.drawable.Drawable;
12 | import android.text.style.ImageSpan;
13 |
14 | public class CustomImageSpan extends ImageSpan {
15 |
16 | public CustomImageSpan(Drawable drawable) {
17 | super(drawable);
18 | }
19 | public CustomImageSpan(Context context, int resID){
20 | super(context,resID, ALIGN_BASELINE);
21 | }
22 |
23 | public int getSize(Paint paint, CharSequence text, int start, int end,
24 | Paint.FontMetricsInt fontMetricsInt) {
25 | Drawable drawable = getDrawable();
26 | Rect rect = drawable.getBounds();
27 | if (fontMetricsInt != null) {
28 | Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
29 | int fontHeight = fmPaint.bottom - fmPaint.top;
30 | int drHeight = rect.bottom - rect.top;
31 |
32 | int top = drHeight / 2 - fontHeight / 4;
33 | int bottom = drHeight / 2 + fontHeight / 4;
34 |
35 | fontMetricsInt.ascent = -bottom;
36 | fontMetricsInt.top = -bottom;
37 | fontMetricsInt.bottom = top;
38 | fontMetricsInt.descent = top;
39 | }
40 | return rect.right;
41 | }
42 |
43 | @Override
44 | public void draw(Canvas canvas, CharSequence text, int start, int end,
45 | float x, int top, int y, int bottom, Paint paint) {
46 | Drawable drawable = getDrawable();
47 | canvas.save();
48 | int transY = 0;
49 | //居中
50 | transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top;
51 | canvas.translate(x, transY);
52 | drawable.draw(canvas);
53 | canvas.restore();
54 | }
55 | }
--------------------------------------------------------------------------------
/app/src/main/java/widget/praisewidget/widget/PraiseWidget.java:
--------------------------------------------------------------------------------
1 | package widget.praisewidget.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.os.Build;
6 | import android.text.DynamicLayout;
7 | import android.text.Layout;
8 | import android.text.Spannable;
9 | import android.text.SpannableString;
10 | import android.text.method.LinkMovementMethod;
11 | import android.util.AttributeSet;
12 | import android.util.LruCache;
13 | import android.widget.TextView;
14 | import java.lang.reflect.Field;
15 | import java.util.List;
16 | import widget.praisewidget.R;
17 | import widget.praisewidget.bean.PraiseBean;
18 | import widget.praisewidget.clickable.PraiseClick;
19 |
20 | /**
21 | * Created by 大灯泡 on 2015/9/25.
22 | * 这是实现点赞显示的控件
23 | * 请用setDataByArray(PraiseBean数组)来绑定数据
24 | *
25 | *
26 | *
27 | *
28 | * smaple:
29 | *
30 | *
31 | * < com.weijuba.widget.moment.PraiseWidget
32 | * android:id="@+id/test_friend"
33 | * android:layout_width="250dp"//可以是match
34 | * android:maxLines="3"//最大显示行数
35 | * android:lineSpacingExtra="2.5px" //行距
36 | * android:lineSpacingMultiplier="1"//行距倍数
37 | * android:layout_height="wrap_content"
38 | * app:font_size="@dimen/sp_16"//内部字体大小
39 | * app:font_color="#ff259cf8"//内部字体颜色
40 | * app:zan_icon="@drawable/ba_zan"//赞图标
41 | *
42 | * />
43 | */
44 | public class PraiseWidget extends TextView {
45 | private static final String TAG = "PraiseWidget";
46 |
47 | //===================参数定义====================
48 | private int color = 0xff517fae;
49 | private int size = 16;
50 | private Context mContext;
51 | private int iconID = R.drawable.ic_moment_liked;
52 | private List mBeans;
53 | private int curLine;//渲染当前文本的行数
54 | private int mMaxLine = 3;
55 | float LineSpacingMultiplier = 0.0f;
56 | float LineSpacingExtra = 0.0f;
57 | private int clickBgColor=0x00000000;
58 |
59 | //缓存
60 | private static LruCache mCache =
61 | new LruCache(50) {
62 | @Override
63 | protected int sizeOf(String key, SpannableStringBuilderAllVer value) {
64 | return 1;
65 | }
66 | };
67 |
68 | //销毁窗口记得清除缓存,清掉对context的引用
69 | public static void clearPraiseWidgetCache() {
70 | if (mCache != null) mCache.evictAll();
71 | }
72 |
73 | public static int getPraiseWidgetCacheEvictionCount() {
74 | if (mCache != null) {
75 | return mCache.evictionCount();
76 | } else {
77 | return -1;
78 | }
79 | }
80 |
81 | public PraiseWidget(Context context) {
82 | this(context, null);
83 | }
84 |
85 | public PraiseWidget(Context context, AttributeSet attrs) {
86 | this(context, attrs, 0);
87 | }
88 |
89 | public PraiseWidget(Context context, AttributeSet attrs, int defStyleAttr) {
90 | super(context, attrs, defStyleAttr);
91 | this.mContext = context;
92 |
93 | TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.PraiseWidget);
94 | this.color = attr.getColor(R.styleable.PraiseWidget_font_color, 0xff517fae);
95 | this.size = attr.getDimensionPixelSize(R.styleable.PraiseWidget_font_size, 16);
96 | this.iconID =
97 | attr.getResourceId(R.styleable.PraiseWidget_zan_icon, R.drawable.ic_moment_liked);
98 | TypedArray systemAttr =
99 | context.obtainStyledAttributes(attrs, new int[] { android.R.attr.maxLines });
100 | this.mMaxLine=systemAttr.getInt(0,3);
101 | this.clickBgColor=attr.getColor(R.styleable.PraiseWidget_click_bg_color,0x00000000);
102 | attr.recycle();
103 | systemAttr.recycle();
104 | //如果不设置,clickableSpan不能响应点击事件
105 | this.setMovementMethod(LinkMovementMethod.getInstance());
106 | this.setHighlightColor(0x00000000);
107 | }
108 |
109 | @Override
110 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
111 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
112 | if (getMeasuredWidth() > 0) {
113 | renderView();
114 | }
115 | }
116 |
117 | //------------------------------------------传参-----------------------------------------------
118 | public void setDataByArray(List list) {
119 | this.mBeans = list;
120 | if (getMeasuredWidth() > 0) {
121 | renderView();
122 | } else {
123 | requestLayout();
124 | }
125 | }
126 |
127 | private void renderView() {
128 | if (mBeans == null || mBeans.size() == 0) {
129 | setText("");
130 | return;
131 | }
132 |
133 | int textTotalWidth = getMeasuredWidth();
134 | //从缓存读取,避免重复测量导致的过多对象被创建问题
135 | String key = Integer.toString(mBeans.hashCode()) + mBeans.size() + textTotalWidth;
136 | SpannableStringBuilderAllVer spannable = mCache.get(key);
137 | if (spannable != null) {
138 | setText(spannable);
139 | } else {
140 | int lastPos = 0;//最后一个位置
141 | curLine = 0;
142 | int maxLine = mMaxLine;
143 | int beanSize = mBeans.size();
144 | String peopleCount =
145 | mContext.getResources().getString(R.string.praise_zan, mBeans.size());
146 | StringBuilder stringBuilder = new StringBuilder();
147 | stringBuilder.append("like ");//预留位置给点赞的心,防止超出指定行数行
148 | for (int i = 0; i < beanSize && curLine <= maxLine; i++) {
149 | stringBuilder.append(mBeans.get(i).userNick);
150 | /**测量当前文字的所属行数(加上“等xxx人测量,保证最后一个可以被顶替掉”)*/
151 | curLine = createWorkingLayout(stringBuilder.toString() + peopleCount,
152 | textTotalWidth).getLineCount();
153 | if (curLine <= maxLine) {
154 | lastPos = i;
155 | stringBuilder.append(", ");
156 | } else {
157 | break;
158 | }
159 | }
160 | spannable = addClickablePart(lastPos);
161 | setText(spannable);
162 | mCache.put(key, spannable);
163 | }
164 | }
165 |
166 | private SpannableStringBuilderAllVer addClickablePart(int LastPos) {
167 | // 第一个心心图标
168 | CustomImageSpan span = new CustomImageSpan(mContext, iconID);
169 | //空字符,保证有一个位置
170 | SpannableString spanStr = new SpannableString(" ");
171 | spanStr.setSpan(span, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
172 | // 构建 builder
173 | SpannableStringBuilderAllVer spanBuilder = new SpannableStringBuilderAllVer(spanStr);
174 |
175 | for (int i = 0; i <= LastPos; i++) {
176 | PraiseBean bean = mBeans.get(i);
177 | if (i == 0) {
178 | spanBuilder.append(" " + bean.userNick,
179 | new PraiseClick(mContext, bean.userNick, bean.userId,color,size), 0);
180 | } else {
181 | spanBuilder.append(mBeans.get(i).userNick,
182 | new PraiseClick(mContext, bean.userNick, bean.userId,color,size), 0);
183 | }
184 | if (i != LastPos) spanBuilder.append(", ");
185 | }
186 | if (LastPos < mBeans.size() - 1) {
187 | //等xxx人
188 | return spanBuilder.append(
189 | mContext.getResources().getString(R.string.praise_zan, mBeans.size()-LastPos));
190 | } else {
191 | return spanBuilder;
192 | }
193 | }
194 |
195 | private Layout createWorkingLayout(String workingText, int textTotalWidth) {
196 |
197 | /**
198 | * float spacingmult:相对行间距,相对字体大小,1.5f表示行间距为1.5倍的字体高度。
199 | * float spacingadd:在基础行距上添加多少
200 | */
201 |
202 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
203 | LineSpacingMultiplier = getLineSpacingMultiplier();
204 | LineSpacingExtra = getLineSpacingExtra();
205 | } else {
206 | if (LineSpacingMultiplier == 0.0f && LineSpacingExtra == 0.0f) {
207 | try {
208 | Field Multiplier = TextView.class.getDeclaredField("mSpacingMult");
209 | Multiplier.setAccessible(true);
210 | LineSpacingMultiplier = Multiplier.getFloat(this);
211 |
212 | Field SpacingExtra = TextView.class.getDeclaredField("mSpacingAdd");
213 | SpacingExtra.setAccessible(true);
214 | LineSpacingExtra = SpacingExtra.getFloat(this);
215 | } catch (Exception e) {
216 | e.printStackTrace();
217 | LineSpacingMultiplier = 1.0f;
218 | LineSpacingExtra = 3.0f;
219 | }
220 | }
221 | }
222 | return new DynamicLayout(workingText, getPaint(),
223 | (textTotalWidth == 0 ? getScreenPixWidth(mContext) : textTotalWidth),
224 | Layout.Alignment.ALIGN_NORMAL, LineSpacingMultiplier, LineSpacingExtra, false);
225 | }
226 |
227 | /** 获取屏幕分辨率:宽 */
228 | public int getScreenPixWidth(Context context) {
229 | return context.getResources().getDisplayMetrics().widthPixels;
230 | }
231 | }
--------------------------------------------------------------------------------
/app/src/main/java/widget/praisewidget/widget/SpannableStringBuilderAllVer.java:
--------------------------------------------------------------------------------
1 | package widget.praisewidget.widget;
2 |
3 | import android.text.SpannableStringBuilder;
4 |
5 | /**
6 | * Created by 大灯泡 on 2015/9/30.
7 | */
8 | public class SpannableStringBuilderAllVer extends SpannableStringBuilder {
9 | public SpannableStringBuilderAllVer() {
10 | super("");
11 | }
12 | public SpannableStringBuilderAllVer(CharSequence text) {
13 | super(text, 0, text.length());
14 | }
15 | public SpannableStringBuilderAllVer(CharSequence text, int start, int end){
16 | super(text,start,end);
17 | }
18 |
19 | public SpannableStringBuilderAllVer append(CharSequence text) {
20 | if (text == null) return this;
21 | int length = length();
22 | return (SpannableStringBuilderAllVer)replace(length, length, text, 0, text.length());
23 | }
24 |
25 |
26 | /**该方法在原API里面只支持API21或者以上,这里抽取出来以适应低版本*/
27 | public SpannableStringBuilderAllVer append(CharSequence text, Object what, int flags) {
28 | if (text == null) return this;
29 | int start = length();
30 | append(text);
31 | setSpan(what, start, length(), flags);
32 | return this;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_moment_liked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/app/src/main/res/drawable/ic_moment_liked.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
23 |
31 |
40 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PraiseWidget
3 | 等%d人
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/widget/praisewidget/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package widget.praisewidget;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/img/praise widget.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/razerdp/PraiseWidget/06c07739b1717c51b428b6b0736e00055201677d/img/praise widget.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------