当前位置: 编程技术>移动开发
本页文章导读:
▪关于荧幕解锁的实例 关于屏幕解锁的实例
AndroidManifest.xml加两个权限 Java代码 <uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission> <uses-permission android:name="android.permission.WAKE_LOCK">&.........
▪ 自定义题目Title 自定义标题Title
Java代码 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.my); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title); request.........
▪ Dialog舒卷动画效果 Dialog伸缩动画效果
ViewScale.java: Java代码 public class ViewScale extends Activity implements OnClickListener { private LinearLayout mLayout; private Animation mScaleIn, mScaleOut; @Override p.........
[1]关于荧幕解锁的实例
来源: 互联网 发布时间: 2014-02-18
关于屏幕解锁的实例
AndroidManifest.xml加两个权限
Java代码
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
Android屏幕解锁:
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("");
keyguardLock.disableKeyguard();
Android 点亮屏幕:
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.SCREEN_DIM_WAKE_LOCK, "SimpleTimer");
mWakelock.acquire();
//...
mWakelock.release();//关闭
Java代码
import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;
public class ScreenLockManager {
private Context mContext;
private KeyguardManager.KeyguardLock mKeyguardLock;
private boolean isScreenLock;
private PowerManager.WakeLock mWakelock;
public ScreenLockManager(Context context) {
mContext = context;
}
public void getUnlock() {
// acquire wake lock
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mWakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "SimpleTimer");
mWakelock.acquire();
// unlock screen
KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock = km.newKeyguardLock(Log.TAG);
if (km.inKeyguardRestrictedInputMode()) {
mKeyguardLock.disableKeyguard();
isScreenLock = true;
} else {
isScreenLock = false;
}
}
public void releaseUnlock() {
// release screen
if (isScreenLock) {
mKeyguardLock.reenableKeyguard();
isScreenLock = false;
}
// release wake lock
if (mWakelock.isHeld()) {
mWakelock.release();
}
}
------------
public class Log {
public static final String TAG = "SimpleTimer";
public static void v(String msg){
android.util.Log.v(TAG, msg);
}
public static void d(String msg){
android.util.Log.d(TAG, msg);
}
public static void e(String msg){
android.util.Log.e(TAG, msg);
}
public static void e(Exception e){
android.util.Log.e(TAG, e.getMessage(),e);
}
}
AndroidManifest.xml加两个权限
Java代码
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
Android屏幕解锁:
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("");
keyguardLock.disableKeyguard();
Android 点亮屏幕:
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.SCREEN_DIM_WAKE_LOCK, "SimpleTimer");
mWakelock.acquire();
//...
mWakelock.release();//关闭
Java代码
import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;
public class ScreenLockManager {
private Context mContext;
private KeyguardManager.KeyguardLock mKeyguardLock;
private boolean isScreenLock;
private PowerManager.WakeLock mWakelock;
public ScreenLockManager(Context context) {
mContext = context;
}
public void getUnlock() {
// acquire wake lock
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mWakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "SimpleTimer");
mWakelock.acquire();
// unlock screen
KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock = km.newKeyguardLock(Log.TAG);
if (km.inKeyguardRestrictedInputMode()) {
mKeyguardLock.disableKeyguard();
isScreenLock = true;
} else {
isScreenLock = false;
}
}
public void releaseUnlock() {
// release screen
if (isScreenLock) {
mKeyguardLock.reenableKeyguard();
isScreenLock = false;
}
// release wake lock
if (mWakelock.isHeld()) {
mWakelock.release();
}
}
------------
public class Log {
public static final String TAG = "SimpleTimer";
public static void v(String msg){
android.util.Log.v(TAG, msg);
}
public static void d(String msg){
android.util.Log.d(TAG, msg);
}
public static void e(String msg){
android.util.Log.e(TAG, msg);
}
public static void e(Exception e){
android.util.Log.e(TAG, e.getMessage(),e);
}
}
[2] 自定义题目Title
来源: 互联网 发布时间: 2014-02-18
自定义标题Title
Java代码
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.my);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.my_title);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.my);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.my_title);
my_title.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#d4e9a9">
<ImageView android:src="/blog_article/@drawable/jetpack/index.html"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:textSize="20px"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:text="New Title"
android:background="#a5c639"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:padding="9dip"
android:layout_margin="5dip" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#d4e9a9">
<ImageView android:src="/blog_article/@drawable/jetpack/index.html"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:textSize="20px"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:text="New Title"
android:background="#a5c639"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:padding="9dip"
android:layout_margin="5dip" />
</RelativeLayout>
jetpack.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="@drawable/jetpack_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/jetpack_pressed" />
</selector>
Java代码
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.my);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.my_title);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.my);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.my_title);
my_title.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#d4e9a9">
<ImageView android:src="/blog_article/@drawable/jetpack/index.html"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:textSize="20px"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:text="New Title"
android:background="#a5c639"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:padding="9dip"
android:layout_margin="5dip" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#d4e9a9">
<ImageView android:src="/blog_article/@drawable/jetpack/index.html"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:textSize="20px"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:text="New Title"
android:background="#a5c639"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:padding="9dip"
android:layout_margin="5dip" />
</RelativeLayout>
jetpack.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="@drawable/jetpack_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/jetpack_pressed" />
</selector>
[3] Dialog舒卷动画效果
来源: 互联网 发布时间: 2014-02-18
Dialog伸缩动画效果
ViewScale.java:
Java代码
public class ViewScale extends Activity implements OnClickListener {
private LinearLayout mLayout;
private Animation mScaleIn, mScaleOut;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mScaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);
mScaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out);
mLayout = (LinearLayout) findViewById(R.id.mLayout);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
iv = new ImageView(ViewScale.this);
LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(mParam);
iv.setBackgroundResource(R.drawable.belle_frame);
}
private int i = 0;
private ImageView iv;
@Override
public void onClick(View v) {
if (i % 2 == 0) {
mLayout.addView(iv);
iv.startAnimation(mScaleOut);
mScaleOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
// mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
} else {
iv.startAnimation(mScaleIn);
mScaleIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
i++;
}
}
public class ViewScale extends Activity implements OnClickListener {
private LinearLayout mLayout;
private Animation mScaleIn, mScaleOut;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mScaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);
mScaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out);
mLayout = (LinearLayout) findViewById(R.id.mLayout);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
iv = new ImageView(ViewScale.this);
LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(mParam);
iv.setBackgroundResource(R.drawable.belle_frame);
}
private int i = 0;
private ImageView iv;
@Override
public void onClick(View v) {
if (i % 2 == 0) {
mLayout.addView(iv);
iv.startAnimation(mScaleOut);
mScaleOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
// mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
} else {
iv.startAnimation(mScaleIn);
mScaleIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
i++;
}
}
scale_out.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0"
android:toYScale="1.0" android:pivotX="1%" android:pivotY="1%"
android:fillAfter="true" android:duration="400" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0"
android:toYScale="1.0" android:pivotX="1%" android:pivotY="1%"
android:fillAfter="true" android:duration="400" />
</set>
scale_in.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0"
android:toYScale="0.0" android:pivotX="1%" android:pivotY="1%"
android:fillAfter="true" android:duration="400" />
</set>
ViewScale.java:
Java代码
public class ViewScale extends Activity implements OnClickListener {
private LinearLayout mLayout;
private Animation mScaleIn, mScaleOut;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mScaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);
mScaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out);
mLayout = (LinearLayout) findViewById(R.id.mLayout);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
iv = new ImageView(ViewScale.this);
LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(mParam);
iv.setBackgroundResource(R.drawable.belle_frame);
}
private int i = 0;
private ImageView iv;
@Override
public void onClick(View v) {
if (i % 2 == 0) {
mLayout.addView(iv);
iv.startAnimation(mScaleOut);
mScaleOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
// mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
} else {
iv.startAnimation(mScaleIn);
mScaleIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
i++;
}
}
public class ViewScale extends Activity implements OnClickListener {
private LinearLayout mLayout;
private Animation mScaleIn, mScaleOut;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mScaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);
mScaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out);
mLayout = (LinearLayout) findViewById(R.id.mLayout);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
iv = new ImageView(ViewScale.this);
LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(mParam);
iv.setBackgroundResource(R.drawable.belle_frame);
}
private int i = 0;
private ImageView iv;
@Override
public void onClick(View v) {
if (i % 2 == 0) {
mLayout.addView(iv);
iv.startAnimation(mScaleOut);
mScaleOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
// mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
} else {
iv.startAnimation(mScaleIn);
mScaleIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
mLayout.removeView(iv);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
i++;
}
}
scale_out.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0"
android:toYScale="1.0" android:pivotX="1%" android:pivotY="1%"
android:fillAfter="true" android:duration="400" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0"
android:toYScale="1.0" android:pivotX="1%" android:pivotY="1%"
android:fillAfter="true" android:duration="400" />
</set>
scale_in.xml:
Java代码
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0"
android:toYScale="0.0" android:pivotX="1%" android:pivotY="1%"
android:fillAfter="true" android:duration="400" />
</set>
最新技术文章: