Skip to content

Commit

Permalink
title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
br3ant committed Oct 9, 2020
1 parent c008767 commit eaf4a53
Show file tree
Hide file tree
Showing 14 changed files with 1,294 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'

implementation project(':utils')

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.0"
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
Expand Down
51 changes: 51 additions & 0 deletions utils/src/main/java/com/br3ant/bar/ITitleBarInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.br3ant.bar;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;


/**
* author : Android 轮子哥
* github : https://github.com/getActivity/TitleBar
* time : 2020/08/16
* desc : 默认初始化器
*/
public interface ITitleBarInitializer {

/**
* 获取左标题 View
*/
TextView getLeftView(Context context);

/**
* 获取中间标题 View
*/
TextView getTitleView(Context context);

/**
* 获取右标题 View
*/
TextView getRightView(Context context);

/**
* 获取分割线 View
*/
View getLineView(Context context);

/**
* 获取标题栏背景
*/
Drawable getBackgroundDrawable(Context context);

/**
* 获取子控件的水平内间距
*/
int getHorizontalPadding(Context context);

/**
* 获取子控件的垂直内间距
*/
int getVerticalPadding(Context context);
}
33 changes: 33 additions & 0 deletions utils/src/main/java/com/br3ant/bar/OnTitleBarListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.br3ant.bar;

import android.view.View;

/**
* author : Android 轮子哥
* github : https://github.com/getActivity/TitleBar
* time : 2018/08/20
* desc : 标题栏点击监听接口
*/
public interface OnTitleBarListener {

/**
* 左项被点击
*
* @param v 被点击的左项View
*/
void onLeftClick(View v);

/**
* 标题被点击
*
* @param v 被点击的标题View
*/
void onTitleClick(View v);

/**
* 右项被点击
*
* @param v 被点击的右项View
*/
void onRightClick(View v);
}
95 changes: 95 additions & 0 deletions utils/src/main/java/com/br3ant/bar/SelectorDrawable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.br3ant.bar;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;

/**
* author : Android 轮子哥
* github : https://github.com/getActivity/TitleBar
* time : 2019/03/10
* desc : 状态选择器构建器
*/
public final class SelectorDrawable extends StateListDrawable {

public final static class Builder {

/** 默认状态 */
private Drawable mDefault;
/** 焦点状态 */
private Drawable mFocused;
/** 按下状态 */
private Drawable mPressed;
/** 选中状态 */
private Drawable mChecked;
/** 启用状态 */
private Drawable mEnabled;
/** 选择状态 */
private Drawable mSelected;
/** 光标悬浮状态(4.0新特性) */
private Drawable mHovered;

public Builder setDefault(Drawable drawable) {
mDefault = drawable;
return this;
}

public Builder setFocused(Drawable drawable) {
mFocused = drawable;
return this;
}

public Builder setPressed(Drawable drawable) {
mPressed = drawable;
return this;
}

public Builder setChecked(Drawable drawable) {
mChecked = drawable;
return this;
}

public Builder setEnabled(Drawable drawable) {
mEnabled = drawable;
return this;
}

public Builder setSelected(Drawable drawable) {
mSelected = drawable;
return this;
}

public Builder setHovered(Drawable drawable) {
mHovered = drawable;
return this;
}

public SelectorDrawable build() {
SelectorDrawable selector = new SelectorDrawable();
if (mPressed != null) {
selector.addState(new int[]{android.R.attr.state_pressed}, mPressed);
}
if (mFocused != null) {
selector.addState(new int[]{android.R.attr.state_focused}, mFocused);
}
if (mChecked != null) {
selector.addState(new int[]{android.R.attr.state_checked}, mChecked);
}
if (mEnabled != null) {
selector.addState(new int[]{android.R.attr.state_enabled}, mEnabled);
}
if (mSelected != null) {
selector.addState(new int[]{android.R.attr.state_selected}, mSelected);
}
if (mHovered != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
selector.addState(new int[]{android.R.attr.state_hovered}, mHovered);
}
}
if (mDefault != null) {
selector.addState(new int[]{}, mDefault);
}
return selector;
}
}
}
Loading

0 comments on commit eaf4a53

Please sign in to comment.