Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshaobo committed May 28, 2018
1 parent 682c41b commit 444b6ce
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 221 deletions.
Binary file modified .gradle/4.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.4/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/taskJars.bin
Binary file not shown.
Binary file modified .gradle/4.4/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.4/taskHistory/taskHistory.lock
Binary file not shown.
190 changes: 85 additions & 105 deletions .idea/workspace.xml

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions app/src/main/java/com/luka/title/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
titleView.setOnTitleClickListener(object : TitleView.OnTitleClickListener {
override fun onMoreTextClick() {
Log.d("luka", "设置")
override fun onBackClick() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onMoreImgClick() {
Expand All @@ -26,9 +26,8 @@ class MainActivity : AppCompatActivity() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onBackClick() {


override fun onMoreTextClick() {
Log.d("luka", "设置")
}

})
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
app:showBack="true"
app:showDivider="true"
app:titleMoreText="设置"
app:titleBackDrawable="@mipmap/ic_launcher_round"
app:titleMoreDrawable="@mipmap/ic_back"
app:titleMore2Drawable="@mipmap/ic_launcher"
app:titleText="hehe" />

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -15,6 +16,7 @@

public class TitleView extends FrameLayout implements View.OnClickListener {

private Drawable mTitleBackDrawable;
private Drawable mTitleMoreDrawable;
private Drawable mTitleMore2Drawable;
private boolean mShowDivider;
Expand All @@ -28,7 +30,6 @@ public class TitleView extends FrameLayout implements View.OnClickListener {
private ImageView ivMore2;
private String mTitleText;
private ImageView ivBack;
private ImageView ivMoreSecond;
private RelativeLayout rlyt_title;
private LinearLayout llLine;
private TextView tvMore;
Expand Down Expand Up @@ -61,6 +62,8 @@ public TitleView(Context context, AttributeSet attrs, int defStyleAttr) {
mBackground = typedArray.getColor(attr, defStyleAttr);
} else if (attr == R.styleable.TitleView_titleMoreText) {
mTitleMoreText = typedArray.getString(attr);
} else if (attr == R.styleable.TitleView_titleBackDrawable) {
mTitleBackDrawable = typedArray.getDrawable(attr);
} else if (attr == R.styleable.TitleView_titleMoreDrawable) {
mTitleMoreDrawable = typedArray.getDrawable(attr);
} else if (attr == R.styleable.TitleView_titleMore2Drawable) {
Expand All @@ -81,23 +84,29 @@ private void initView() {
ivBack = findViewById(R.id.ivBack);
ivBack.setOnClickListener(this);
ivBack.setVisibility(mIsShowBack ? VISIBLE : GONE);
ivBack.setImageDrawable(mTitleBackDrawable);

tvTitle = findViewById(R.id.tvTitle);
tvTitle.setText(mTitleText);
tvTitle.setTextColor(mTitleColor == 0 ? Color.BLACK : mTitleColor);

tvMore = findViewById(R.id.tvMore);
tvMore.setText(mTitleMoreText);
tvMore.setOnClickListener(this);

ivMore = findViewById(R.id.ivMore);
ivMore.setImageDrawable(mTitleMoreDrawable);

ivMore2 = findViewById(R.id.ivMoreSecond);
ivMore2.setImageDrawable(mTitleMore2Drawable);

rlyt_title = findViewById(R.id.rlyt_title);
tvMore = findViewById(R.id.tvMore);
if(!TextUtils.isEmpty(mTitleMoreText)){
tvMore.setText(mTitleMoreText);
tvMore.setOnClickListener(this);
}

rlyt_title = findViewById(R.id.rlContainer);
rlyt_title.setBackgroundColor(mBackground);

View vDivider = findViewById(R.id.vDivider);
vDivider.setVisibility(mShowDivider ? View.VISIBLE : View.GONE);
}

@Override
Expand Down Expand Up @@ -126,97 +135,4 @@ public void setOnTitleClickListener(OnTitleClickListener listener) {
this.listener = listener;
}


public void setTitle(String text) {
if (text.length() > 12) {
tvTitle.setText(text.substring(0, 12));
} else {
tvTitle.setText(text);
}
}

public void setTitleVisible(boolean visible) {
tvTitle.setVisibility(visible ? VISIBLE : GONE);
}

/**
* 设置右边的图片
*
* @param drawable
*/
public void setMoreImg(int drawable, OnClickListener listener) {
ivMore = (ImageView) findViewById(R.id.ivMore);
ivMore.setVisibility(View.VISIBLE);
ivMore.setImageResource(drawable);
ivMore.setOnClickListener(listener);
}

/**
* 设置右边的点击事件
*
* @param listener
*/
public void setMoreClickListener(OnClickListener listener) {
if (ivMore == null) {
ivMore = (ImageView) findViewById(R.id.ivMore);
}
ivMore.setVisibility(View.VISIBLE);
ivMore.setOnClickListener(listener);
}

/**
* 设置右边的文字
*
* @param text
*/
public void setMoreText(String text, OnClickListener listener) {
tvMore.setVisibility(VISIBLE);
tvMore.setText(text);
tvMore.setOnClickListener(listener);
}

public void setBackListener(OnClickListener listener) {
ImageView ivBack = (ImageView) findViewById(R.id.ivBack);
ivBack.setVisibility(VISIBLE);
ivBack.setOnClickListener(listener);
}

public void setBackVisible(boolean visible) {
ivBack.setVisibility(visible ? VISIBLE : GONE);
}

/**
* 设置右边的图片
*
* @param drawable
*/
public void setMoreSecondImg(int drawable, OnClickListener listener) {
ivMoreSecond = findViewById(R.id.ivMoreSecond);
ivMoreSecond.setVisibility(View.VISIBLE);
ivMoreSecond.setImageResource(drawable);
ivMoreSecond.setOnClickListener(listener);
}

public void setTitleTextColor(int color) {
tvTitle.setTextColor(color);
tvMore.setTextColor(color);
// ivBack.setImageResource(R.drawable.icon_back_white);
}

public void setBackDrawable(int drawable) {
ivBack.setImageResource(drawable);
}

/**
* 分割线是否可见
*
* @param isInvisible
*/
public void setSplitLineInvisible(boolean isInvisible) {
if (isInvisible) llLine.setVisibility(GONE);
}

public void setBackColorWhite(boolean b) {
// if (b) ivBack.setImageResource(R.drawable.icon_back_white);
}
}
12 changes: 3 additions & 9 deletions mylibrary/src/main/res/layout/layout_widget_title.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlyt_title"
android:id="@+id/rlContainer"
style="@style/titleView">

<ImageView
Expand All @@ -19,20 +19,14 @@

<ImageView
android:id="@+id/ivMoreSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/ivMore"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scaleType="center" />

style="@style/titleViewRight2Image" />

<TextView
android:id="@+id/tvMore"
style="@style/titleViewRightImageText" />

<View
android:id="@+id/vDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
Expand Down
1 change: 1 addition & 0 deletions mylibrary/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<attr name="titleMoreText" format="string" />
<attr name="titleMoreDrawable" format="reference" />
<attr name="titleMore2Drawable" format="reference" />
<attr name="titleBackDrawable" format="reference" />
<attr name="titleColor" format="color" />
<attr name="showBack" format="boolean" />
<attr name="showDivider" format="boolean" />
Expand Down
11 changes: 8 additions & 3 deletions mylibrary/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
<item name="android:layout_margin">10dp</item>
<item name="android:gravity">center</item>
<item name="android:textStyle">bold</item>

</style>


<style name="titleViewRightImageText">
<item name="android:textSize">17sp</item>
<item name="android:layout_width">wrap_content</item>
Expand Down Expand Up @@ -48,7 +46,6 @@


<style name="titleViewRightImage">
<item name="android:textSize">18sp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingRight">10dp</item>
Expand All @@ -59,5 +56,13 @@
<item name="android:gravity">center</item>
</style>

<style name="titleViewRight2Image">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingRight">10dp</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:gravity">center</item>
<item name="android:layout_toLeftOf">@id/ivMore</item>
</style>

</resources>

0 comments on commit 444b6ce

Please sign in to comment.