Skip to content

Commit

Permalink
v1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
SiberiaDante committed Sep 14, 2018
1 parent 742cd38 commit 3b3dbd8
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 60 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![](https://jitpack.io/v/SiberiaDante/TitleLayout.svg)](https://jitpack.io/#SiberiaDante/TitleLayout)

```
compile 'com.github.SiberiaDante:TitleLayout:v1.1.3'
compile 'com.github.SiberiaDante:TitleLayout:----'
```
![图片](/images/show_title.png)

Expand Down Expand Up @@ -360,6 +360,7 @@
## 更新优化说明
* v1.1.4(未发布)
* 增加标题栏双击事件、单击事件回调
* 修复丢失的右边图片点击事件
* 修复设置左右图片Padding造成的问题
* v1.1.3:(2018-08-01发布)
* 增加动态设置标题栏背景颜色
Expand Down
45 changes: 31 additions & 14 deletions app/src/main/java/com/siberiadante/titlelayout/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.siberiadante.titlelayoutlib.OnMultiTouchListener;
import com.siberiadante.titlelayoutlib.TitleBarLayout;
import com.siberiadante.titlelayoutlib.TitleLayoutListener;
import com.siberiadante.titlelayoutlib.utils.ScreenUtil;
Expand All @@ -16,28 +19,42 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ScreenUtil.setStatusTranslucent(this);
// TitleBarLayout titleBarLayout = (TitleBarLayout) findViewById(R.id.title_layout_one);
// titleBarLayout.setTitleClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Log.d("MainActivity","title 被点击了");
// }
// });
// //设置Titlesize
// titleBarLayout.setTitleSize(30);
// //一键设置标题样式
// titleBarLayout.setTitleStyle("我是标题", 18, ContextCompat.getColor(this, R.color.colorAccent));
// titleBarLayout.setRightImageClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Log.d("MainActivity","右边图片被点击了");
// }
// });

final TitleBarLayout titleBarLayout2 = (TitleBarLayout) findViewById(R.id.title_layout_two);
titleBarLayout2.setTitle("Java代码设置新的标题");

final TitleBarLayout titleBarLayout = (TitleBarLayout) findViewById(R.id.title_layout_four);
titleBarLayout.setIsLeftBackView(true);
titleBarLayout.setTitleLayoutBackground(ContextCompat.getColor(this,R.color.colorPrimaryDark));
titleBarLayout.setTitleLayoutBackground(ContextCompat.getColor(this, R.color.colorPrimaryDark));
titleBarLayout.setRightImageClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "右边的图片被点击了", Toast.LENGTH_SHORT).show();
}
});

// titleBarLayout.setTitleClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Toast.makeText(MainActivity.this, "标题被点击了", Toast.LENGTH_SHORT).show();
// }
// });
titleBarLayout.setTitleClickListener(new OnMultiTouchListener(new TitleLayoutListener() {
@Override
public void onTitleClickListener() {
Toast.makeText(MainActivity.this, "标题被单击了", Toast.LENGTH_SHORT).show();

}

@Override
public void onTitleDoubleClickListener() {
Toast.makeText(MainActivity.this, "标题被双击了", Toast.LENGTH_SHORT).show();

}
}));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.siberiadante.titlelayoutlib;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;

Expand All @@ -13,9 +15,34 @@
* Describe:
*/
public class OnMultiTouchListener implements View.OnTouchListener {
private int clickCount = 0;
private TitleLayoutListener titleLayoutListener;
private Handler mHandler;

public OnMultiTouchListener(TitleLayoutListener titleLayoutListener) {
this.titleLayoutListener = titleLayoutListener;
mHandler = new Handler();
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
clickCount++;
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (clickCount == 1) {
titleLayoutListener.onTitleClickListener();
} else if (clickCount == 2) {
titleLayoutListener.onTitleDoubleClickListener();
}
mHandler.removeCallbacksAndMessages(null);
clickCount = 0;

}
}, 500);
}
return false;
}
}

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions titlelayoutlib/src/main/res/layout/title_bar_layout.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_title_bar_height"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sd_rl_title_bar_height"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red">

<LinearLayout
android:id="@+id/ll_center"
android:id="@+id/sd_ll_center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/tv_title"
android:id="@+id/sd_tv_title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
Expand All @@ -26,7 +27,7 @@
android:visibility="visible" />

<TextView
android:id="@+id/tv_sub_title"
android:id="@+id/sd_tv_sub_title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
Expand All @@ -37,59 +38,63 @@
</LinearLayout>

<RelativeLayout
android:id="@+id/rl_left"
android:id="@+id/sd_rl_left"
android:layout_width="wrap_content"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iv_left"
android:id="@+id/sd_iv_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingStart="10dp"
android:src="@drawable/icon_back"
android:visibility="visible" />
android:visibility="visible"
tools:ignore="RtlSymmetry" />

<TextView
android:id="@+id/tv_left"
android:id="@+id/sd_tv_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/iv_left"
android:layout_toEndOf="@id/sd_iv_left"
android:gravity="center"
android:paddingStart="10dp"
android:text="返回"
android:visibility="visible" />
android:visibility="visible"
tools:ignore="RtlSymmetry" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_right"
android:id="@+id/sd_rl_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true">

<ImageView
android:id="@+id/iv_right"
android:id="@+id/sd_iv_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:paddingEnd="10dp"
android:src="@drawable/icon_collection"
android:visibility="invisible" />
android:visibility="invisible"
tools:ignore="RtlSymmetry" />

<TextView
android:id="@+id/tv_right"
android:id="@+id/sd_tv_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:paddingEnd="10dp"
android:text="搜索"
android:visibility="gone" />
android:visibility="gone"
tools:ignore="RtlSymmetry" />
</RelativeLayout>


<!--</LinearLayout>-->

<View
android:id="@+id/view_line"
android:id="@+id/sd_view_line"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
Expand Down

0 comments on commit 3b3dbd8

Please sign in to comment.