Skip to content

Commit

Permalink
ver 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hantrungkien committed Jul 23, 2018
1 parent 0ec14c9 commit e344fc5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kienht.circlesliceimageview

import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
Expand All @@ -25,6 +26,8 @@ class MainActivity : AppCompatActivity() {

button_slice.setOnClickListener {
circleSliceImageView.mode = CircleSliceImageView.CircularImageMode.SLICE_MODE.getValue()
circleSliceImageView.sliceSections = 5
circleSliceImageView.sliceStartAngle = 90
}

button_border.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.support.v7.widget.AppCompatImageView
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.ImageView
import java.security.SecureRandom
Expand Down Expand Up @@ -91,6 +90,8 @@ class CircleSliceImageView(context: Context?, attrs: AttributeSet?) : AppCompatI
var sliceSections = 2
set(value) {
field = value
fullArcSliceLength = 360 / value
colorArcLineLength = fullArcSliceLength - 2 * (fullArcSliceLength / 10)
invalidate()
}

Expand All @@ -103,7 +104,7 @@ class CircleSliceImageView(context: Context?, attrs: AttributeSet?) : AppCompatI
invalidate()
}

var isSpaceSliceAndImage = true
var isSpaceSliceWithImage = true
set(value) {
field = value
invalidate()
Expand Down Expand Up @@ -133,6 +134,8 @@ class CircleSliceImageView(context: Context?, attrs: AttributeSet?) : AppCompatI
paintBackground!!.isAntiAlias = true
paintBackground!!.style = Paint.Style.FILL_AND_STROKE

sliceSections = 2

val attributes = context!!.obtainStyledAttributes(attrs, R.styleable.CircleSliceImageView)

mode = attributes.getInteger(R.styleable.CircleSliceImageView_civ_mode, CircularImageMode.DEFAULT_MODE.getValue())
Expand All @@ -145,6 +148,7 @@ class CircleSliceImageView(context: Context?, attrs: AttributeSet?) : AppCompatI
sliceSections = attributes.getInteger(R.styleable.CircleSliceImageView_civ_slice_sections, 2)
sliceStartAngle = attributes.getInteger(R.styleable.CircleSliceImageView_civ_slice_start_angle, 0)
isSliceRandomColor = attributes.getBoolean(R.styleable.CircleSliceImageView_civ_slice_random_color, false)
isSpaceSliceWithImage = attributes.getBoolean(R.styleable.CircleSliceImageView_civ_slice_space_with_image, false)
sliceBorderWidth = attributes.getDimension(R.styleable.CircleSliceImageView_civ_slice_border_width, defSliceBorderSize)
setSliceBorderColor(attributes.getColor(R.styleable.CircleSliceImageView_civ_slice_border_color, Color.BLACK))
}
Expand All @@ -162,9 +166,6 @@ class CircleSliceImageView(context: Context?, attrs: AttributeSet?) : AppCompatI
}
}

fullArcSliceLength = 360 / sliceSections
colorArcLineLength = fullArcSliceLength - 2 * (fullArcSliceLength / 10)

setBackgroundColor(attributes.getColor(R.styleable.CircleSliceImageView_civ_background_color, Color.WHITE))

attributes.recycle()
Expand Down Expand Up @@ -236,7 +237,7 @@ class CircleSliceImageView(context: Context?, attrs: AttributeSet?) : AppCompatI
canvas.drawArc(mSliceRect, (i * fullArcSliceLength + sliceStartAngle).toFloat(), colorArcLineLength.toFloat(), false, paintSliceBorder)
}

val radius: Float = if (isSpaceSliceAndImage) {
val radius: Float = if (isSpaceSliceWithImage) {
circleCenter.toFloat() - sliceBorderWidth - sliceBorderWidth / 2
} else {
circleCenter.toFloat() - sliceBorderWidth
Expand Down
2 changes: 1 addition & 1 deletion circle-slice-image/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<attr name="civ_shadow_color" format="color" />
<attr name="civ_shadow_radius" format="float" />

<attr name="civ_is_use_slice_border" format="boolean"/>
<attr name="civ_slice_sections" format="integer"/>
<attr name="civ_slice_start_angle" format="integer"/>
<attr name="civ_slice_border_width" format="dimension"/>
<attr name="civ_slice_border_color" format="color" />
<attr name="civ_slice_random_color" format="boolean"/>
<attr name="civ_slice_space_with_image" format="boolean"/>

<attr name="civ_shadow_gravity">
<flag name="center" value="1" />
Expand Down
Binary file added slice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e344fc5

Please sign in to comment.