-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.geteit.view | ||
|
||
import android.view.View.MeasureSpec | ||
import android.view.{ViewGroup, View} | ||
import com.geteit.util.GtObjHandler | ||
|
||
trait GtViewGroup extends Seq[View] { | ||
self: ViewGroup => | ||
|
||
def length = getChildCount | ||
def apply(i: Int) = getChildAt(i) | ||
def iterator = new Iterator[View] { | ||
var index = 0 | ||
def hasNext = index < getChildCount | ||
def next() = { | ||
val v = getChildAt(index) | ||
index += 1 | ||
v | ||
} | ||
} | ||
|
||
def relayout() { | ||
forceLayout() | ||
GtViewGroup.relayoutHandler !! this | ||
} | ||
} | ||
|
||
object GtViewGroup { | ||
lazy val relayoutHandler = new GtObjHandler({ (view: View) => | ||
view.measure(MeasureSpec.makeMeasureSpec(view.getWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(view.getHeight, MeasureSpec.EXACTLY)) | ||
view.layout(view.getLeft, view.getTop, view.getRight, view.getBottom) | ||
}) | ||
} |
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,47 @@ | ||
package com.geteit.view | ||
|
||
import android.content.Context | ||
import android.graphics.Typeface | ||
import android.support.v7.widget.{AppCompatCheckBox, AppCompatTextView} | ||
import android.util.AttributeSet | ||
import android.widget.TextView | ||
import com.geteit.app.R | ||
|
||
import scala.collection.mutable | ||
|
||
trait RoboView { self: TextView => | ||
import RoboView._ | ||
|
||
protected def initFont(attrs: AttributeSet)(implicit context: Context) { | ||
val a = context.obtainStyledAttributes(attrs, R.styleable.RoboView) | ||
val typeId = a.getInt(R.styleable.RoboView_fontFamily, 0) | ||
setTypeface(roboTypeface(typeId)) | ||
a.recycle() | ||
} | ||
} | ||
|
||
object RoboView { | ||
val typefaceNames = Array("Roboto-Regular.ttf", "Roboto-Light.ttf", "Roboto-Thin.ttf") | ||
val typefaces = new mutable.HashMap[String, Typeface] | ||
|
||
def roboTypeface(id: Int)(implicit context: Context) = { | ||
val name = typefaceNames(id) | ||
typefaces.getOrElseUpdate(name, Typeface.createFromAsset(context.getAssets, name)) | ||
} | ||
} | ||
|
||
class RoboTextView(context: Context, attrs: AttributeSet, style: Int) extends AppCompatTextView(context, attrs, style) with RoboView { | ||
|
||
def this(context: Context, attrs: AttributeSet) = this(context, attrs, 0) | ||
def this(context: Context) = this(context, null, 0) | ||
|
||
initFont(attrs)(context) | ||
} | ||
|
||
class RoboCheckBox(context: Context, attrs: AttributeSet, style: Int) extends AppCompatCheckBox(context, attrs, style) with RoboView { | ||
|
||
def this(context: Context, attrs: AttributeSet) = this(context, attrs, 0) | ||
def this(context: Context) = this(context, null, 0) | ||
|
||
initFont(attrs)(context) | ||
} |