Skip to content

Instantly share code, notes, and snippets.

View ZieIony's full-sized avatar

ZieIony

View GitHub Profile
data class ListItem(val title: String, val subtitle: String)
// viewholder
class ItemViewHolder : RecyclerView.ViewHolder {
private val titleTv: TextView
private val subtitleTv: TextView
constructor(itemView: View) : super(itemView) {
titleTv = itemView.findViewById(R.id.title)
subtitleTv = itemView.findViewById(R.id.subtitle)
class TabsFragment : Fragment() {
private val tabFragments: Array<KClass<out BaseFragment>>
init {
val mainNavPlugins = PluginManager.getPlugins().filter {
it.getMainFragment() != null
}.toTypedArray()
tabFragments = arrayOf(
abstract class PluginProvider : ContentProvider() {
abstract fun getPlugin(): Plugin
override fun onCreate(): Boolean {
PluginManager.registerPlugin(getPlugin())
return true
}
// ... other provider methods
class ApiListPlugin : Plugin {
override fun getMainFragment() = ApiListFragment::class
}
class ApiListPluginProvider : PluginProvider() {
override fun getPlugin() = ApiListPlugin()
}
interface Plugin {
fun getMainFragment(): KClass<BaseFragment>?
}
object PluginManager {
private val plugins = mutableListOf<Plugin>()
@Synchronized
fun getPlugins() = plugins.toList()
public class FlowLayout extends FrameLayout {
// ..
@Override
protected LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(super.generateDefaultLayoutParams());
}
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}
public class FlowLayout extends FrameLayout {
public static class LayoutParams extends FrameLayout.LayoutParams {
private boolean fill = false;
public LayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.FlowLayout_Layout);
fill = a.getBoolean(R.styleable.FlowLayout_Layout_guide_layout_fill, false);
a.recycle();
}
}
<declare-styleable name="FlowLayout">
<attr name="android:gravity" />
</declare-styleable>
<declare-styleable name="FlowLayout_Layout">
<attr name="guide_layout_fill" format="boolean" />
</declare-styleable>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="OK" />
public class ImageView extends android.widget.ImageView {
public ImageView(Context context) {
super(context, null, R.attr.carbon_imageViewStyle);
initImageView(null, R.attr.carbon_imageViewStyle);
}
public ImageView(Context context, AttributeSet attrs) {
super(context, attrs, R.attr.carbon_imageViewStyle);
initImageView(attrs, R.attr.carbon_imageViewStyle);
}
private void initImageView(AttributeSet attrs, int defStyleAttr) {