移动开发人机交互
来源:互联网 发布:js数组删除元素splice 编辑:程序博客网 时间:2024/06/08 14:23
一、密码长度太短了提示
第一种方法:
final EditText editText= (EditText) findViewById(R.id.editText);editText.setOnFocusChangeListener(new OnFocusChangeListener() {@Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if (!hasFocus) { //如果失去焦点 EditText eText = (EditText) v; int len = eText.length(); if (len < 5)="" {="" etext.settext("");//清空="" toast.maketext(testlinearlayout.this,="" "长度短了!len="+len, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(TestLinearLayout.this, " 长度符合!len="+len, Toast.LENGTH_SHORT).show(); } } }});Button button = (Button) findViewById(R.id.editTextb);button.setOnClickListener(new OnClickListener() {@Override public void onClick(View v) { editText.clearFocus(); //失去焦点 }});
第二种方法:
在确定的监听中取得输入框“输入字符的长度”len,在这里判断,如果len<4就不跳转,然后showtoast.提示就可以了,符合要求再正常做。
二、Android实现长时间不用屏幕变暗
原理就是修改window的亮度,然后达到让屏幕变黑的效果,通过监听activity的dispatchTouchEvent方法来全局监听屏幕的变化。
import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.view.MotionEvent; import android.view.WindowManager; public class BaseActivity extends Activity { /** * 最大的屏幕亮度 */ float maxLight; /** * 当前的亮度 */ float currentLight; /** * 用来控制屏幕亮度 */ Handler handler; /** * 延时时间 */ long DenyTime = 5 * 1000L; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); InitData(); } private void InitData() { handler = new Handler(Looper.getMainLooper()); maxLight = GetLightness(this); } /** * 设置亮度 * * @param context * @param light */ void SetLight(Activity context, int light) { currentLight = light; WindowManager.LayoutParams localLayoutParams = context.getWindow().getAttributes(); localLayoutParams.screenBrightness = (light / 255.0F); context.getWindow().setAttributes(localLayoutParams); } /** * 获取亮度 * * @param context * @return */ float GetLightness(Activity context) { WindowManager.LayoutParams localLayoutParams = context.getWindow().getAttributes(); float light = localLayoutParams.screenBrightness; return light; } @Override protected void onPause() { super.onPause(); stopSleepTask(); } @Override protected void onResume() { super.onResume(); startSleepTask(); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (currentLight == 1) { startSleepTask(); } return super.dispatchTouchEvent(ev); } /** * 开启休眠任务 */ void startSleepTask() { SetLight(this, (int) maxLight); handler.removeCallbacks(sleepWindowTask); handler.postDelayed(sleepWindowTask, DenyTime); } /** * 结束休眠任务 */ void stopSleepTask() { handler.removeCallbacks(sleepWindowTask); } /** * 休眠任务 */ Runnable sleepWindowTask = new Runnable() { @Override public void run() { SetLight(BaseActivity.this, 1); } }; }
三、android监听返回按钮事件
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } protected void dialog() { AlertDialog.Builder builder = new Builder(HanderTestActivty.this); builder.setMessage("确定要退出吗?"); builder.setTitle("提示"); builder.setPositiveButton("确认", new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); HanderTestActivty.this.finish(); } }); builder.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { dialog(); return false; } return false; }
四、Android利用Bundle实现Activity间消息的传递
关于Activity之间的消息的传递。利用Bundle是一种比较方便的办法。 程序的效果是活动A向B跳转的同时发送一字符串,B读出字符串。 先在AndroidManifest.xml中定义一个新的Activity
1.[XML]代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
manifest
xmlns:android
=
"http://schemas.android.com/apk/res/android"
package
=
"com.ray.test"
android:versionCode
=
"1"
android:versionName
=
"1.0"
>
<
application
android:icon
=
"@drawable/icon"
android:label
=
"@string/app_name"
>
<
activity
android:name
=
".TestBundle"
android:label
=
"@string/app_name"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.action.MAIN"
/>
<
category
android:name
=
"android.intent.category.LAUNCHER"
/>
</
intent-filter
>
</
activity
>
<
activity
android:name
=
".Target"
></
activity
>
</
application
>
<
uses-sdk
android:minSdkVersion
=
"3"
/>
</
manifest
>
2. TestBundle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package
com.ray.test;
import
android.app.Activity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.MotionEvent;
public
class
TestBundle
extends
Activity {
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public
boolean
onTouchEvent(MotionEvent event) {
Intent intent =
new
Intent();
intent.setClass(TestBundle.
this
, Target.
class
);
Bundle mBundle =
new
Bundle();
mBundle.putString(
"Data"
,
"ray'blog"
);
//压入数据
intent.putExtras(mBundle);
startActivity(intent);
finish();
return
super
.onTouchEvent(event);
}
}
3. TargetActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package
com.ray.test;
import
android.app.Activity;
import
android.os.Bundle;
public
class
TargetActivity
extends
Activity{
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bundle bundle = getIntent().getExtras();
String data=bundle.getString(
"Data"
);
//读出数据
setTitle(data);
}
}
五、还可改变屏幕方向来使人机交互性更好
0 0
- 移动开发人机交互
- CTO俱乐部-移动开发技术沙龙 次世代人机交互接口开发及应用开发
- Kinect人机交互开发实践
- 人机交互实验:Android开发之人物移动、地图滑动、传感器、触屏的应用
- 移动办公应用——人机交互
- 人机交互
- 人机交互
- 人机交互
- 人机交互
- 《UI进化论——移动设备人机交互界面设计》
- 人机交互、大数据分析:移动互联网的技术创新探索
- 人机交互、大数据分析:移动互联网的技术创新探索
- iOS 人机交互设计(开发)指南及一些综合知识整合
- 移动开发
- 移动开发
- 移动开发
- 移动开发
- 移动开发
- 这儿有自学前端开发的吗-
- 58 同城 iOS 客户端网络框架的演进之路
- 服务器跳转与客户端跳转的区别
- MySQL数据库——修改数据库与列的基本操作
- web.xml 配置介绍
- 移动开发人机交互
- 1039. Course List for Student (25)PAT甲级
- Ability To Convert
- Wifi模块——ESP8266(三)
- [区间GCD预处理 树状数组 离线] HDU 5869 Different GCD Subarray Query
- BZOJ3164: [Heoi2013]Eden的博弈问题
- Add Two Numbers
- File类
- 关于Linux xfs文件系统修复的文章