From ffbbcb64e63fd72fc2eede7eec2c502d46cb6628 Mon Sep 17 00:00:00 2001 From: Maekawa Yuichi Date: Mon, 12 Sep 2016 01:57:09 +0900 Subject: [PATCH 01/21] Update gradle libraries --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 559ccba..e570622 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,9 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.2' + classpath 'com.android.tools.build:gradle:2.1.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 122a0dc..2c9d775 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Sun Sep 11 20:32:26 JST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip From 1044f458d6332f80d7058b1f7fd24db29d6518d5 Mon Sep 17 00:00:00 2001 From: kaelaela Date: Sun, 30 Oct 2016 17:59:36 +0900 Subject: [PATCH 02/21] Add uri --- .../java/me/kaelaela/opengraphview/OpenGraphView.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java b/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java index 7bf63c0..6012551 100644 --- a/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java +++ b/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java @@ -38,6 +38,7 @@ public class OpenGraphView extends RelativeLayout { private View mSeparator; private ImageView mImageView; private ImageView mFavicon; + private Uri mUri; private String mUrl; private OnLoadListener mOnLoadListener; private Paint mFill = new Paint(); @@ -190,9 +191,10 @@ public void setOnLoadListener(OnLoadListener listener) { public void loadFrom(@Nullable final String url) { setVisibility(TextUtils.isEmpty(url) ? GONE : VISIBLE); - if (TextUtils.isEmpty(url) || mSeparator == null) { + if (TextUtils.isEmpty(url) || mSeparator == null || url.startsWith("http://") || url.startsWith("https://")) { return; } + mUri = Uri.parse(url); mUrl = url; mSeparator.setVisibility(GONE); OGData ogData = mOGCache.get(url); @@ -237,6 +239,7 @@ public void loadFrom(Uri uri) { if (uri == null) { return; } + mUri = uri; mUrl = uri.getPath(); loadFrom(mUrl); } @@ -357,6 +360,10 @@ public String getUrl() { return mUrl; } + public Uri getUri() { + return mUri; + } + public void clear() { mImageView.setImageDrawable(null); ((TextView) findViewById(R.id.og_url)).setText(""); From 2d4768254fc9069670c2fe6c186634b6f97ca459 Mon Sep 17 00:00:00 2001 From: Maekawa Yuichi Date: Mon, 16 Jan 2017 11:41:15 +0900 Subject: [PATCH 03/21] Update build.gradle --- build.gradle | 2 +- gradle.properties | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index e570622..e3bc62b 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } diff --git a/gradle.properties b/gradle.properties index 8d295f2..13e871c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ -COMPILE_SDK_VERSION=23 -BUILD_TOOLS_VERSION=23.0.2 +COMPILE_SDK_VERSION=25 +BUILD_TOOLS_VERSION=23.0.3 MIN_SDK_VERSION=16 -TARGET_SDK_VERSION=24 -SUPPORT_APP_COMPAT_VERSION=24.1.0 +TARGET_SDK_VERSION=25 +SUPPORT_APP_COMPAT_VERSION=25.1.0 VERSION_NAME=1.0.3 VERSION_CODE=4 From 49859621c0b7cd543bee340f175f67c51f36778c Mon Sep 17 00:00:00 2001 From: Maekawa Yuichi Date: Mon, 16 Jan 2017 13:58:37 +0900 Subject: [PATCH 04/21] Add RoundableImageView --- .../kaelaela/opengraphview/OpenGraphView.java | 83 +++++++---------- .../opengraphview/RoundableImageView.java | 93 +++++++++++++++++++ .../src/main/res/layout/view_open_graph.xml | 4 +- library/src/main/res/values/dimen.xml | 2 +- .../java/me/kaelaela/sample/MainActivity.java | 4 +- 5 files changed, 133 insertions(+), 53 deletions(-) create mode 100644 library/src/main/java/me/kaelaela/opengraphview/RoundableImageView.java diff --git a/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java b/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java index 7bf63c0..43e8757 100644 --- a/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java +++ b/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java @@ -1,7 +1,6 @@ package me.kaelaela.opengraphview; import android.content.Context; -import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -24,8 +23,9 @@ public class OpenGraphView extends RelativeLayout { - public static final int IMAGE_POS_LEFT = 0; - public static final int IMAGE_POS_RIGHT = 1; + public enum IMAGE_POSITION { + LEFT, RIGHT + } @ColorInt private int mStrokeColor = -1; @@ -36,7 +36,7 @@ public class OpenGraphView extends RelativeLayout { private float mStrokeWidth = 0; private boolean mSeparate = false; private View mSeparator; - private ImageView mImageView; + private RoundableImageView mRoundableImageView; private ImageView mFavicon; private String mUrl; private OnLoadListener mOnLoadListener; @@ -69,7 +69,7 @@ public OpenGraphView(Context context, AttributeSet attrs, int defStyleAttr) { mStroke.setAntiAlias(true); mStroke.setColor(ContextCompat.getColor(context, R.color.light_gray)); - mImageView = (ImageView) findViewById(R.id.og_image); + mRoundableImageView = (RoundableImageView) findViewById(R.id.og_image); mFavicon = (ImageView) findViewById(R.id.favicon); setBgColor(array.getColor(R.styleable.OpenGraphView_bgColor, ContextCompat.getColor(context, android.R.color.white))); @@ -85,10 +85,13 @@ public OpenGraphView(Context context, AttributeSet attrs, int defStyleAttr) { setStrokeColor(array.getColor(R.styleable.OpenGraphView_strokeColor, ContextCompat.getColor(context, R.color.light_gray))); setStrokeWidth(array.getDimension(R.styleable.OpenGraphView_strokeWidth, 2f)); - setImagePosition(array.getInteger(R.styleable.OpenGraphView_imagePosition, IMAGE_POS_LEFT)); + setCornerRadius(array.getDimension(R.styleable.OpenGraphView_cornerRadius, 0)); + int attrPosition = array.getInteger(R.styleable.OpenGraphView_imagePosition, 0); + + setImagePosition((attrPosition == 0 || attrPosition != 1) ? IMAGE_POSITION.LEFT : IMAGE_POSITION.RIGHT); mSeparate = array.getBoolean(R.styleable.OpenGraphView_separateImage, true); mSeparator.setVisibility(mSeparate ? VISIBLE : GONE); - mImageView.setImageDrawable(array.getDrawable(R.styleable.OpenGraphView_imagePlaceHolder)); + mRoundableImageView.setImageDrawable(array.getDrawable(R.styleable.OpenGraphView_imagePlaceHolder)); ((ImageView) findViewById(R.id.favicon)) .setImageDrawable(array.getDrawable(R.styleable.OpenGraphView_faviconPlaceHolder)); array.recycle(); @@ -109,60 +112,44 @@ public void setStrokeWidth(float strokeWidth) { mStrokeWidth = getContext().getResources().getDimensionPixelOffset(R.dimen.default_stroke_width); return; } - RelativeLayout.LayoutParams sepaParam = (RelativeLayout.LayoutParams) mSeparator.getLayoutParams(); - sepaParam.width = (int) strokeWidth; - mSeparator.setLayoutParams(sepaParam); + RelativeLayout.LayoutParams param = (RelativeLayout.LayoutParams) mSeparator.getLayoutParams(); + param.width = (int) strokeWidth; + mSeparator.setLayoutParams(param); mSeparator.setBackgroundColor(mStrokeColor); mStrokeWidth = strokeWidth; mStroke.setStrokeWidth(strokeWidth); - - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mImageView.getLayoutParams(); - int margin = (int) (mStrokeWidth); - params.setMargins(margin, margin, margin, margin); - params.width = params.width - margin * 2; - params.height = params.height - margin * 2; - mImageView.setLayoutParams(params); - mImageView.setTranslationX(margin / 2); + int defaultImageSize = getContext().getResources().getDimensionPixelOffset(R.dimen.default_image_size); + mRoundableImageView.setMargin(defaultImageSize, (int) mStrokeWidth); invalidate(); } - /** - * set image position. - * - * @param position IMAGE_POS_LEFT(=0), IMAGE_POS_RIGHT(=1) - */ - public void setImagePosition(int position) { + public void setCornerRadius(float cornerRadius) { + if (cornerRadius < 0) { + cornerRadius = 0; + } + mRoundableImageView.setRadius(cornerRadius); + } + + public void setImagePosition(IMAGE_POSITION position) { int parentPadding = getContext().getResources().getDimensionPixelOffset(R.dimen.default_stroke_width); View parent = findViewById(R.id.parent); - if (position == IMAGE_POS_LEFT) { - setImageParam(ALIGN_PARENT_LEFT); + if (position == IMAGE_POSITION.LEFT) { setContentParam(RIGHT_OF); setSeparatorParam(RIGHT_OF); parent.setPadding(parentPadding, 0, 0, 0); - } else if (position == IMAGE_POS_RIGHT) { - setImageParam(ALIGN_PARENT_RIGHT); + } else if (position == IMAGE_POSITION.RIGHT) { setContentParam(LEFT_OF); setSeparatorParam(LEFT_OF); parent.setPadding(0, 0, parentPadding, 0); } - } - - private void setImageParam(int rule) { - Resources resources = getContext().getResources(); - int imageSize = resources.getDimensionPixelSize(R.dimen.default_image_size); - RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(imageSize, imageSize); - imageParams.addRule(rule); - int margin = resources.getDimensionPixelOffset(R.dimen.default_stroke_width); - imageParams.topMargin = margin; - imageParams.bottomMargin = margin; - mImageView.setLayoutParams(imageParams); + mRoundableImageView.setPosition(position); } private void setContentParam(int rule) { RelativeLayout.LayoutParams contentsParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - contentsParams.addRule(rule, mImageView.getId()); + contentsParams.addRule(rule, mRoundableImageView.getId()); View contents = findViewById(R.id.og_contents); contents.setLayoutParams(contentsParams); int padding = getContext().getResources().getDimensionPixelOffset(R.dimen.default_content_padding); @@ -172,7 +159,7 @@ private void setContentParam(int rule) { private void setSeparatorParam(int rule) { RelativeLayout.LayoutParams separatorParams = new RelativeLayout.LayoutParams( (int) mStrokeWidth, ViewGroup.LayoutParams.MATCH_PARENT); - separatorParams.addRule(rule, mImageView.getId()); + separatorParams.addRule(rule, mRoundableImageView.getId()); mSeparator.setLayoutParams(separatorParams); } @@ -268,6 +255,9 @@ public void onLoadStart() { @Override public void onLoadSuccess(Bitmap bitmap) { super.onLoadSuccess(bitmap); + if (bitmap == null) { + return; + } mOGCache.addImage(url, bitmap); setImage(bitmap); } @@ -283,9 +273,8 @@ public void onLoadError() { } private void setImage(Bitmap bitmap) { - mImageView.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.white)); - mImageView.setImageBitmap(bitmap); - ImageAnimator.alphaAnimation(mImageView); + mRoundableImageView.setImageBitmap(bitmap); + ImageAnimator.alphaAnimation(mRoundableImageView); if (mSeparate) { mSeparator.setVisibility(VISIBLE); } @@ -334,12 +323,12 @@ private void setOpenGraphData(OGData data) { title.setText(mUrl); url.setText(""); description.setText(""); - mImageView.setVisibility(VISIBLE); + mRoundableImageView.setVisibility(VISIBLE); return; } boolean isImageEmpty = TextUtils.isEmpty(data.getImage()); - mImageView.setVisibility(isImageEmpty ? GONE : VISIBLE); + mRoundableImageView.setVisibility(isImageEmpty ? GONE : VISIBLE); if (TextUtils.isEmpty(data.getTitle()) && TextUtils.isEmpty(data.getDescription())) { title.setText(mUrl); description.setText(""); @@ -358,7 +347,7 @@ public String getUrl() { } public void clear() { - mImageView.setImageDrawable(null); + mRoundableImageView.setImageDrawable(null); ((TextView) findViewById(R.id.og_url)).setText(""); ((TextView) findViewById(R.id.og_title)).setText(""); ((TextView) findViewById(R.id.og_description)).setText(""); diff --git a/library/src/main/java/me/kaelaela/opengraphview/RoundableImageView.java b/library/src/main/java/me/kaelaela/opengraphview/RoundableImageView.java new file mode 100644 index 0000000..19176ec --- /dev/null +++ b/library/src/main/java/me/kaelaela/opengraphview/RoundableImageView.java @@ -0,0 +1,93 @@ +package me.kaelaela.opengraphview; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.Shader; +import android.util.AttributeSet; +import android.widget.ImageView; +import android.widget.RelativeLayout; + +public class RoundableImageView extends ImageView { + + private int mSide; + private int mMargin; + private float mCornerRadius; + private final RectF mRect = new RectF(); + private final Paint mPaint = new Paint(); + private OpenGraphView.IMAGE_POSITION mPosition = OpenGraphView.IMAGE_POSITION.LEFT; + + public RoundableImageView(Context context) { + this(context, null); + } + + public RoundableImageView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public RoundableImageView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + mPaint.setAntiAlias(true); + } + + public void setMargin(int viewSize, int margin) { + mMargin = margin; + mSide = viewSize; + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams(); + params.setMargins(margin, margin, margin, margin); + params.width = mSide; + params.height = mSide; + setLayoutParams(params); + invalidate(); + } + + public void setRadius(float radius) { + if (mCornerRadius == radius) { + return; + } + mCornerRadius = radius; + invalidate(); + } + + public void setPosition(OpenGraphView.IMAGE_POSITION position) { + mPosition = position; + setImageParam(mPosition == OpenGraphView.IMAGE_POSITION.LEFT ? + RelativeLayout.ALIGN_PARENT_LEFT : RelativeLayout.ALIGN_PARENT_RIGHT); + invalidate(); + } + + private void setImageParam(int rule) { + RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(mSide, mSide); + imageParams.addRule(rule); + imageParams.topMargin = mMargin; + imageParams.bottomMargin = mMargin; + setLayoutParams(imageParams); + } + + @Override + public void setImageBitmap(Bitmap bm) { + super.setImageBitmap(bm); + Bitmap centerCroppedBitmap = Bitmap.createBitmap(bm, (bm.getWidth() / 2) - (mSide / 2), + (bm.getHeight() / 2) - (mSide / 2), mSide, mSide); + BitmapShader shader = new BitmapShader(centerCroppedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); + mPaint.setShader(shader); + } + + @Override + protected void onDraw(Canvas canvas) { + if (mPosition == OpenGraphView.IMAGE_POSITION.LEFT) { + mRect.set(0, 0, mSide, mSide); + canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, mPaint); + mRect.set(mSide - mCornerRadius, 0, mSide, mSide); + canvas.drawRect(mRect, mPaint); + } else { + mRect.set(0, 0, mSide, mSide); + canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, mPaint); + mRect.set(0, 0, mCornerRadius, mSide); + canvas.drawRect(mRect, mPaint); + } + } +} diff --git a/library/src/main/res/layout/view_open_graph.xml b/library/src/main/res/layout/view_open_graph.xml index 2c04865..391a6be 100644 --- a/library/src/main/res/layout/view_open_graph.xml +++ b/library/src/main/res/layout/view_open_graph.xml @@ -6,7 +6,7 @@ android:foreground="@drawable/open_graph_foreground" > - 2dp 8dp - 96dp + 92dp \ No newline at end of file diff --git a/sample/src/main/java/me/kaelaela/sample/MainActivity.java b/sample/src/main/java/me/kaelaela/sample/MainActivity.java index a3b0ce0..9868f9d 100644 --- a/sample/src/main/java/me/kaelaela/sample/MainActivity.java +++ b/sample/src/main/java/me/kaelaela/sample/MainActivity.java @@ -73,13 +73,13 @@ public void onClick(View v) { findViewById(R.id.left_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - openGraphView.setImagePosition(OpenGraphView.IMAGE_POS_LEFT); + openGraphView.setImagePosition(OpenGraphView.IMAGE_POSITION.LEFT); } }); findViewById(R.id.right_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - openGraphView.setImagePosition(OpenGraphView.IMAGE_POS_RIGHT); + openGraphView.setImagePosition(OpenGraphView.IMAGE_POSITION.RIGHT); } }); From 8becaf2253175f366953019e66648cdaf69f04ca Mon Sep 17 00:00:00 2001 From: Maekawa Yuichi Date: Mon, 16 Jan 2017 18:56:47 +0900 Subject: [PATCH 05/21] Add corner radius attribute --- .../kaelaela/opengraphview/OpenGraphView.java | 17 ++++++++++++++--- library/src/main/res/values/attr.xml | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java b/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java index 43e8757..11b47d4 100644 --- a/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java +++ b/library/src/main/java/me/kaelaela/opengraphview/OpenGraphView.java @@ -5,12 +5,14 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.RectF; import android.net.Uri; import android.support.annotation.ColorInt; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.util.AttributeSet; +import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -34,12 +36,15 @@ public enum IMAGE_POSITION { private int mViewWidth; private int mViewHeight; private float mStrokeWidth = 0; + private float mCornerRadius = 0; private boolean mSeparate = false; private View mSeparator; private RoundableImageView mRoundableImageView; private ImageView mFavicon; private String mUrl; private OnLoadListener mOnLoadListener; + private RectF mFillRect = new RectF(); + private RectF mStrokeRect = new RectF(); private Paint mFill = new Paint(); private Paint mStroke = new Paint(); private static OGCache mOGCache = OGCache.getInstance(); @@ -118,6 +123,7 @@ public void setStrokeWidth(float strokeWidth) { mSeparator.setBackgroundColor(mStrokeColor); mStrokeWidth = strokeWidth; + mFillRect.set(mStrokeWidth, mStrokeWidth, mViewWidth - mStrokeWidth, mViewHeight- mStrokeWidth); mStroke.setStrokeWidth(strokeWidth); int defaultImageSize = getContext().getResources().getDimensionPixelOffset(R.dimen.default_image_size); mRoundableImageView.setMargin(defaultImageSize, (int) mStrokeWidth); @@ -128,7 +134,9 @@ public void setCornerRadius(float cornerRadius) { if (cornerRadius < 0) { cornerRadius = 0; } + mCornerRadius = cornerRadius; mRoundableImageView.setRadius(cornerRadius); + invalidate(); } public void setImagePosition(IMAGE_POSITION position) { @@ -231,9 +239,8 @@ public void loadFrom(Uri uri) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - float padding = mStrokeWidth / 2; - canvas.drawRect(padding, padding, mViewWidth - padding, mViewHeight - padding, mStroke); - canvas.drawRect(mStrokeWidth, mStrokeWidth, mViewWidth - mStrokeWidth, mViewHeight - mStrokeWidth, mFill); + canvas.drawRoundRect(mStrokeRect, mCornerRadius, mCornerRadius, mStroke); + canvas.drawRoundRect(mFillRect, mCornerRadius, mCornerRadius, mFill); } @Override @@ -241,6 +248,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mViewWidth = w; mViewHeight = h; + if (mStrokeRect.width() == 0 && mStrokeRect.height() == 0) { + float padding = mStrokeWidth / 2; + mStrokeRect.set(padding, padding, mViewWidth - padding, mViewHeight - padding); + } } private void loadImage(final String url) { diff --git a/library/src/main/res/values/attr.xml b/library/src/main/res/values/attr.xml index 52d1f21..b5f8286 100644 --- a/library/src/main/res/values/attr.xml +++ b/library/src/main/res/values/attr.xml @@ -6,6 +6,7 @@ + From a76dbd8037c3ad12a55dec6a3900dd78f69d868d Mon Sep 17 00:00:00 2001 From: Maekawa Yuichi Date: Mon, 16 Jan 2017 19:43:34 +0900 Subject: [PATCH 06/21] Update sample --- .../java/me/kaelaela/sample/MainActivity.java | 19 +++++++++++++++++++ sample/src/main/res/layout/activity_main.xml | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/sample/src/main/java/me/kaelaela/sample/MainActivity.java b/sample/src/main/java/me/kaelaela/sample/MainActivity.java index 9868f9d..440fd45 100644 --- a/sample/src/main/java/me/kaelaela/sample/MainActivity.java +++ b/sample/src/main/java/me/kaelaela/sample/MainActivity.java @@ -7,6 +7,7 @@ import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.SeekBar; import me.kaelaela.opengraphview.OpenGraphView; public class MainActivity extends AppCompatActivity { @@ -83,6 +84,24 @@ public void onClick(View v) { } }); + final float density = getResources().getDisplayMetrics().density; + ((SeekBar) findViewById(R.id.radius_seek_bar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + openGraphView.setCornerRadius(progress * density); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + findViewById(R.id.open_list_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 7c224da..6bb500c 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -17,6 +17,7 @@ android:layout_width="match_parent" android:layout_height="96dp" og:bgColor="@android:color/white" + og:cornerRadius="4dp" og:descTextColor="@color/text_black" og:faviconPlaceHolder="@color/light_gray" og:imagePlaceHolder="@color/light_gray" @@ -122,6 +123,21 @@ + + + +