提交 614f476e 编写于 作者: 门心叼龙's avatar 门心叼龙

map touch add

上级 871d3e9f
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.touchevent">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
......@@ -13,12 +14,12 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".MyApplication"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
......@@ -32,9 +33,13 @@
android:label="@string/title_activity_trip_detail"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="8eecfc5d75d050cdd6d872e09073ca1e"/>
<activity android:name=".SelectTouchActivity">
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -16,30 +16,37 @@ import com.android.touchevent.util.MotionEventUtil;
* Version: V1.0.0<br>
* Update: <br>
*/
public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
public static String TAG = "MYTAG";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,MapTouchActivity.class));
}
});
findViewById(R.id.btn1).setOnClickListener(this);
findViewById(R.id.btn2).setOnClickListener(this);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.v(TAG,"MainActivity isTouchTransView start:"+MotionEventUtil.getMotionEventName(ev));
Log.v(TAG,"MainActivity dispatchTouchEvent start:"+MotionEventUtil.getMotionEventName(ev));
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.v(TAG,"MainActivity isTouchTransView start:"+MotionEventUtil.getMotionEventName(event));
Log.v(TAG,"MainActivity onTouchEvent start:"+MotionEventUtil.getMotionEventName(event));
return super.onTouchEvent(event);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn1:
startActivity(new Intent(MainActivity.this,SelectTouchActivity.class));
break;
case R.id.btn2:
startActivity(new Intent(MainActivity.this,MapTouchActivity.class));
break;
}
}
}
package com.android.touchevent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import com.android.touchevent.view.FatArrowView;
import com.android.touchevent.view.SettingBarView;
public class SelectTouchActivity extends AppCompatActivity {
private CheckBox mCheckBox;
private FatArrowView mFatArrowView;
private SettingBarView mSetBarCarSelect;
private SettingBarView mSetBarStartPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_touch);
mCheckBox = findViewById(R.id.chb);
mFatArrowView = findViewById(R.id.view_arrow);
mSetBarCarSelect = findViewById(R.id.view_car_select);
mSetBarStartPosition = findViewById(R.id.view_start_positon);
mSetBarCarSelect.enableEditContext(false);
mSetBarStartPosition.enableEditContext(true);
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(SelectTouchActivity.this,"选中了",Toast.LENGTH_LONG).show();
}
});
mFatArrowView.setChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(SelectTouchActivity.this,"选中了",Toast.LENGTH_LONG).show();
}
});
mSetBarCarSelect.setOnClickSettingBarViewListener(new SettingBarView.OnClickSettingBarViewListener() {
@Override
public void onClick() {
Toast.makeText(SelectTouchActivity.this,"我要选择车辆了",Toast.LENGTH_LONG).show();
}
});
//mSetBarStartPosition.setOnClickSettingBarViewListener();
}
}
......@@ -2,6 +2,7 @@ package com.android.touchevent.view;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.CheckBox;
import android.widget.CompoundButton;
......@@ -21,7 +22,7 @@ public class FatArrowView extends RelativeLayout {
public static final String TAG = FatArrowView.class.getSimpleName();
private CheckBox mCheckBox;
private CompoundButton.OnCheckedChangeListener mChangeListener;
private boolean ischeck = false;
public void setChangeListener(CompoundButton.OnCheckedChangeListener changeListener) {
mChangeListener = changeListener;
}
......@@ -33,6 +34,7 @@ public class FatArrowView extends RelativeLayout {
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.v(TAG,"setOnCheckedChangeListener start...");
if(mChangeListener != null){
mChangeListener.onCheckedChanged(buttonView,isChecked);
}
......@@ -40,8 +42,22 @@ public class FatArrowView extends RelativeLayout {
});
}
//拦截事件
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.v(TAG,"onInterceptTouchEvent start...");
return true;
}
//把事件分发给我们的子View CheckBox
@Override
public boolean onTouchEvent(MotionEvent event) {
return mCheckBox.onTouchEvent(event);
Log.v(TAG,"onTouchEvent start...");
//当手指离开屏幕的时候设置CheckBox的状态
if (event.getAction() == MotionEvent.ACTION_UP){
ischeck = !ischeck;
mCheckBox.setChecked(ischeck);
}
return true;
}
}
......@@ -25,13 +25,13 @@ public class MyButton extends Button {
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.v(TAG,"MyButton isTouchTransView start:"+MotionEventUtil.getMotionEventName(ev));
Log.v(TAG,"MyButton dispatchTouchEvent start:"+MotionEventUtil.getMotionEventName(ev));
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.v(TAG,"MyButton isTouchTransView start:"+MotionEventUtil.getMotionEventName(event));
Log.v(TAG,"MyButton onTouchEvent start:"+MotionEventUtil.getMotionEventName(event));
return super.onTouchEvent(event);
}
}
......@@ -24,7 +24,7 @@ public class MyLayout extends LinearLayout {
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.v(TAG,"MyLayout isTouchTransView start:"+MotionEventUtil.getMotionEventName(ev));
Log.v(TAG,"MyLayout dispatchTouchEvent start:"+MotionEventUtil.getMotionEventName(ev));
return super.dispatchTouchEvent(ev);
}
......@@ -36,7 +36,7 @@ public class MyLayout extends LinearLayout {
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.v(TAG,"MyLayout isTouchTransView start:"+MotionEventUtil.getMotionEventName(event));
Log.v(TAG,"MyLayout onTouchEvent start:"+MotionEventUtil.getMotionEventName(event));
return super.onTouchEvent(event);
}
}
......@@ -123,11 +123,13 @@ public class SettingBarView extends RelativeLayout {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
//当处于不可编辑状态的时候拦截该事件,否则该事件就继续往下分发
return !isEdit;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//当拦截该事件的时候就把它分发给自己的根View,响应全局的点击事件
return layoutSettingBar.onTouchEvent(event);
}
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/usecar_icon_fold" android:state_checked="true"/>
<item android:drawable="@mipmap/usecar_icon_unfold" android:state_checked="false"/>
<item android:drawable="@mipmap/usecar_icon_unfold"/>
<item android:drawable="@mipmap/usecar_icon_fold" android:state_checked="true"/>
<item android:drawable="@mipmap/usecar_icon_unfold" android:state_checked="false"/>
<item android:drawable="@mipmap/usecar_icon_unfold"/>
</selector>
\ No newline at end of file
......@@ -8,11 +8,22 @@
xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.touchevent.view.MyButton
android:id="@+id/btn_test"
android:id="@+id/btn0"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_height="wrap_content"
android:text="点击测试"
android:background="#00FF00"
/>
<Button
android:id="@+id/btn1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="实战案例1"
/>
<Button
android:id="@+id/btn2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="实战案例2"
/>
</com.android.touchevent.view.MyLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SelectTouchActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.这个不容易点击"
/>
<CheckBox
android:id="@+id/chb"
android:layout_width="12dp"
android:layout_height="7dp"
android:background="@drawable/bg_usecar_arrow"
android:button="@null"
android:layout_centerInParent="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.这个很容点点击"
android:layout_marginTop="20dp"
/>
<com.android.touchevent.view.FatArrowView
android:id="@+id/view_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.android.touchevent.view.SettingBarView
android:id="@+id/view_car_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:set_title="车辆选择"
app:set_content_hint="由公车负责人分配"
android:layout_marginTop="20dp"
app:set_right_icon="@mipmap/usecar_list_icon_into"
app:set_right_icon_visable="true"
/>
<com.android.touchevent.view.SettingBarView
android:id="@+id/view_start_positon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:set_title="始发地点"
app:set_content_hint="请输入"
app:set_right_icon="@mipmap/usecar_list_icon_into"
android:layout_marginTop="20dp"
app:set_right_icon_visable="true"
/>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册