01
02
03
04
05
06
07
08
09
10
11
|
if
(keyCode == event.KEYCODE_BACK) {
return
true
;
}
else
if
(keyCode == event.KEYCODE_MENU){
return
true
;
}
else
if
(keyCode == event.KEYCODE_VOLUME_UP){
return
true
;
}
else
if
(keyCode == event.KEYCODE_VOLUME_DOWN){
return
true
;
}
else
{
return
super
.onKeyDown(keyCode, event);
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
PackageManager pm = getPackageManager();
ResolveInfo homeInfo = pm.resolveActivity(
new
Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME),
0
);
if
(keyCode == KeyEvent.KEYCODE_BACK) {
ActivityInfo ai = homeInfo.activityInfo;
Intent startIntent =
new
Intent(Intent.ACTION_MAIN);
startIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startIntent
.setComponent(
new
ComponentName(ai.packageName, ai.name));
startActivitySafely(startIntent);
return
true
;
}
else
return
super
.onKeyDown(keyCode, event);
|
01
02
03
04
05
06
07
08
09
10
11
12
|
|
01
02
03
04
05
06
07
08
09
10
11
|
public
class
ShutdownBroadcastReceiver
extends
BroadcastReceiver {
private
static
final
String TAG =
"ShutdownBroadcastReceiver"
;
private
static
final
String ACTION_SHUTDOWN =
"android.intent.action.ACTION_SHUTDOWN"
;
@Override
public
void
onReceive(Context context, Intent intent) {
if
(intent.getAction().equals(ACTION_SHUTDOWN)){
Log.d(TAG,
"手机即将光机"
);
Toast.makeText(context,
"手机即将关机"
, Toast.LENGTH_SHORT).show();
}
}
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
public
class
BootBroadcastReceiver
extends
BroadcastReceiver {
private
static
final
String TAG =
"BootBroadcastReceiver"
;
private
static
final
String ACTION_BOOT =
"android.intent.action.BOOT_COMPLETED"
;
@Override
public
void
onReceive(Context context, Intent intent) {
if
(intent.getAction().equals(ACTION_BOOT)){
Log.d(TAG,
"手机开机了"
);
Toast.makeText(context,
"手机开机了"
, Toast.LENGTH_SHORT).show();
Intent i =
new
Intent(context, MainActivity.
class
);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
|
1
2
3
4
5
|
//注册Receiver
HomeKeyEventBroadCastReceiver receiver =
new
HomeKeyEventBroadCastReceiver();
registerReceiver(receiver,
new
IntentFilter(
Intent. ACTION_CLOSE_SYSTEM_DIALOGS));
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
private
void
handleLongPressOnHome() {
// We can't initialize this in init() since the configuration hasn't been loaded yet.
if
(mLongPressOnHomeBehavior <
0
) {
mLongPressOnHomeBehavior
= mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
if
(mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
}
}
if
(mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
performHapticFeedbackLw(
null
, HapticFeedbackConstants.LONG_PRESS,
false
);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
// Eat the longpress so it won't dismiss the recent apps dialog when
// the user lets go of the home key
mHomeLongPressed =
true
;
}
if
(mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
}
else
if
(mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
try
{
IStatusBarService statusbar = getStatusBarService();
if
(statusbar !=
null
) {
statusbar.toggleRecentApps();
}
}
catch
(RemoteException e) {
Slog.e(TAG,
"RemoteException when showing recent apps"
, e);
// re-acquire status bar service next time it is needed.
mStatusBarService =
null
;
}
}
}
|
1
2
3
4
|
public
void
onAttachedToWindow() {
this
.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super
.onAttachedToWindow();
}
|
01
02
03
04
05
06
07
08
09
10
|
WindowManager.LayoutParams params = getWindow().getAttributes();
params.type = TYPE_SYSTEM_ERROR;
params.dimAmount =
0
.0F;
// transparent
params.width =
0
;
params.height =
0
;
params.gravity = Gravity.BOTTOM;
getWindow().setAttributes(params);
getWindow().setFlags(FLAG_SHOW_WHEN_LOCKED | FLAG_NOT_TOUCH_MODAL,
0xffffff
);
setOwnerActivity(activity);
setCancelable(
false
);
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
@@ -
494
,
6
+
494
,
31
@@
public
class
PhoneStatusBar
extends
BaseStatusBar
implements
DemoMode {
}
+
//add steven zhang by 20160701
+
private
BroadcastReceiver mStatusShowHide =
new
BroadcastReceiver() {
+
+
@Override
+
public
void
onReceive(
final
Context context, Intent intent) {
+
// TODO Auto-generated method stub
+ String action = intent.getAction();
+
+
if
(
"com.aura.statusbar.SHOW_OR_HIDE"
.equals(action)) {
+
// StatusBarManager.DISABLE_NONE
+
// StatusBarManager.DISABLE_EXPAND
+
final
int
mode = intent.getIntExtra(
"mode"
, StatusBarManager.DISABLE_NONE);
+
if
(mNavigationBarView !=
null
) {
+ mHandler.post(
new
Runnable() {
+
+
@Override
+
public
void
run() {
+
+ disable(mode);
+ }
+ });
+ }
+ }
+ }
+ };
//micheal add the Broadcast interface for Control the wifi sleep mode change begin 20150514
private
BroadcastReceiver wifiSleepModeChangeReceiver =
new
BroadcastReceiver(){
@Override
@@ -
519
,
6
+
544
,
10
@@
public
class
PhoneStatusBar
extends
BaseStatusBar
implements
DemoMode {
// ================================================================================
protected
PhoneStatusBarView makeStatusBarView() {
final
Context context = mContext;
+
// add steven zhang by 20160701
+ IntentFilter statusFilter =
new
IntentFilter();
+ statusFilter.addAction(
"com.aura.statusbar.SHOW_OR_HIDE"
);
+ context.registerReceiver(mStatusShowHide, statusFilter);
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
@Override
protected
void
onResume() {
super
.onResume();
Intent i =
new
Intent(
"com.aura.statusbar.SHOW_OR_HIDE"
);
i.putExtra(
"mode"
, StatusBarManager.DISABLE_EXPAND);
sendBroadcast(i);
}
@Override
protected
void
onPause() {
super
.onPause();
Intent i =
new
Intent(
"com.aura.statusbar.SHOW_OR_HIDE"
);
i.putExtra(
"mode"
, StatusBarManager.DISABLE_NONE);
sendBroadcast(i);
}
|