-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix index exceptions Edit constructor
- Loading branch information
Showing
8 changed files
with
244 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<resources> | ||
<string name="app_name">Test Time</string> | ||
<string name="app_name">Step Line Library</string> | ||
</resources> |
150 changes: 150 additions & 0 deletions
150
timelineunit/src/main/java/mishmarot/guy/com/timelineunit/StepLineLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package mishmarot.guy.com.timelineunit; | ||
|
||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.support.v4.content.res.ResourcesCompat; | ||
import android.util.AttributeSet; | ||
import android.widget.LinearLayout; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class StepLineLayout extends LinearLayout { | ||
|
||
public ArrayList<StepLineView> stepLineViews; | ||
|
||
int mainColor = Color.argb(255, 0, 0, 200); | ||
int secondColor = Color.argb(255, 0, 0, 200); | ||
int lineColor = Color.argb(255, 0, 0, 200); | ||
|
||
int markerRadius = 20; | ||
int lineSize = 3; | ||
int linePadding = 0; | ||
StepLineView.LineOrientation lineOrientation = StepLineView.LineOrientation.VERTICAL; | ||
|
||
public StepLineLayout(Context context) { | ||
this(context, null, 0); | ||
} | ||
|
||
public StepLineLayout(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public StepLineLayout(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
init(context); | ||
} | ||
|
||
private void init(Context context) { | ||
this.setOrientation(LinearLayout.HORIZONTAL); | ||
} | ||
|
||
public void setTimeLines(Context context, StepLineView.LineOrientation _lineOrientation, int _numOfItems, int _mainColor, int _secondColor, int _lineColor, int _lineSize, int _markerRadius, int _linePadding){ | ||
this.lineSize = _lineSize; | ||
this.markerRadius = _markerRadius; | ||
this.linePadding = _linePadding; | ||
setTimeLines(context, _lineOrientation, _numOfItems, _mainColor, _secondColor, _lineColor); | ||
} | ||
|
||
public void setTimeLines(Context context, StepLineView.LineOrientation _lineOrientation, int _numOfItems, int _mainColor, int _secondColor, int _lineColor){ | ||
|
||
// If the user send resource int instead of Color int.. | ||
try { | ||
_lineColor = ResourcesCompat.getColor(getResources(), _lineColor, null); | ||
} catch (Exception ignored) { } | ||
|
||
try { | ||
_mainColor = ResourcesCompat.getColor(getResources(), _mainColor, null); | ||
} catch (Exception ignored) { } | ||
|
||
try { | ||
_secondColor = ResourcesCompat.getColor(getResources(), _secondColor, null); | ||
} catch (Exception ignored) { } | ||
|
||
|
||
this.mainColor = _mainColor; | ||
this.lineColor = _lineColor; | ||
this.secondColor = _secondColor; | ||
setTimeLines(context, _lineOrientation, _numOfItems); | ||
} | ||
|
||
private void setTimeLines(Context context, StepLineView.LineOrientation _lineOrientation, int numOfItems) { | ||
stepLineViews = new ArrayList<>(); | ||
|
||
this.lineOrientation = _lineOrientation; | ||
if (_lineOrientation == StepLineView.LineOrientation.HORIZONTAL) | ||
this.setOrientation(LinearLayout.HORIZONTAL); | ||
else | ||
this.setOrientation(LinearLayout.VERTICAL); | ||
|
||
if (numOfItems <=0) { | ||
return; | ||
} | ||
else if (numOfItems == 1) { | ||
StepLineView stepLineView4 = getTimeLineUnit(context, StepLineView.LineType.ONLY_ONE, StepLineView.OrderStatus.ACTIVE); | ||
stepLineViews.add(stepLineView4); | ||
} | ||
else { | ||
// numOfItems > 1 | ||
StepLineView stepLineView0 = getTimeLineUnit(context, StepLineView.LineType.BEGIN, StepLineView.OrderStatus.ACTIVE); | ||
stepLineViews.add(stepLineView0); | ||
|
||
for (int i = 1; i < numOfItems-1; i++) { | ||
StepLineView stepLineView1 = getTimeLineUnit(context, StepLineView.LineType.NORMAL, StepLineView.OrderStatus.ACTIVE); | ||
stepLineViews.add(stepLineView1); | ||
} | ||
|
||
StepLineView stepLineView2 = getTimeLineUnit(context, StepLineView.LineType.END, StepLineView.OrderStatus.ACTIVE); | ||
stepLineViews.add(stepLineView2); | ||
} | ||
|
||
attachListToView(); | ||
} | ||
|
||
private void attachListToView() { | ||
for (int i = 0; i < stepLineViews.size(); i++) { | ||
this.addView(stepLineViews.get(i)); | ||
} | ||
} | ||
|
||
public void setUnitActive(int activeIndex) { | ||
if (activeIndex >= 0 && activeIndex < stepLineViews.size()) | ||
stepLineViews.get(activeIndex).setOrderStatus(StepLineView.OrderStatus.ACTIVE); | ||
} | ||
|
||
public void setUnitInactive(int inactiveIndex) { | ||
if (inactiveIndex >= 0 && inactiveIndex < stepLineViews.size()) | ||
stepLineViews.get(inactiveIndex).setOrderStatus(StepLineView.OrderStatus.INACTIVE); | ||
} | ||
|
||
public void setUnitCompleted(int completedIndex) { | ||
if (completedIndex >= 0 && completedIndex < stepLineViews.size()) | ||
stepLineViews.get(completedIndex).setOrderStatus(StepLineView.OrderStatus.COMPLETED); | ||
} | ||
|
||
public StepLineView getTimeLineUnit(Context context, StepLineView.LineType lineType, StepLineView.OrderStatus orderStatus) { | ||
// markerSize - default=20 | ||
LinearLayout.LayoutParams linearParams; | ||
if (lineOrientation == StepLineView.LineOrientation.HORIZONTAL) | ||
linearParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1); | ||
else | ||
linearParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1); | ||
|
||
float density = context.getResources().getDisplayMetrics().density; | ||
|
||
StepLineView stepLineView = new StepLineView(context, null); | ||
stepLineView.setMarkerSize(markerRadius); | ||
stepLineView.setMainColor(mainColor); | ||
stepLineView.setSecondColor(secondColor); | ||
stepLineView.setLineColor(lineColor); | ||
stepLineView.initLine(lineType); | ||
stepLineView.setLayoutParams(linearParams); | ||
stepLineView.setLineOrientation(lineOrientation); | ||
stepLineView.setLineSize((int) (lineSize * density)); | ||
stepLineView.setMarkerSize((int) (markerRadius * density)); | ||
stepLineView.setLinePadding(linePadding); | ||
stepLineView.setDrawables(); | ||
stepLineView.setOrderStatus(orderStatus); | ||
|
||
return stepLineView; | ||
} | ||
} |
Oops, something went wrong.