/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.home;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.ColorFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.util.Xml;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.TextView;
import java.io.IOException;
import java.io.FileReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class Home extends Activity {
/**
* Tag used for logging errors.
*/
private static final String LOG_TAG = "Home";
/**
* Keys during freeze/thaw.
*/
private static final String KEY_SAVE_GRID_OPENED = "grid.opened";
private static final String DEFAULT_FAVORITES_PATH = "etc/favorites.xml";
private static final String TAG_FAVORITES = "favorites";
private static final String TAG_FAVORITE = "favorite";
private static final String TAG_PACKAGE = "package";
private static final String TAG_CLASS = "class";
// Identifiers for option menu items
private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
private static final int MENU_SETTINGS = MENU_SEARCH + 1;
/**
* Maximum number of recent tasks to query.
*/
private static final int MAX_RECENT_TASKS = 20;
private static boolean mWallpaperChecked;
private static ArrayList<ApplicationInfo> mApplications;
private static LinkedList<ApplicationInfo> mFavorites;
private final BroadcastReceiver mWallpaperReceiver = new WallpaperIntentReceiver();
private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver();
private GridView mGrid;
private LayoutAnimationController mShowLayoutAnimation;
private LayoutAnimationController mHideLayoutAnimation;
private boolean mBlockAnimation;
private boolean mHomeDown;
private boolean mBackDown;
private View mShowApplications;
private CheckBox mShowApplicationsCheck;
private ApplicationsStackLayout mApplicationsStack;
private Animation mGridEntry;
private Animation mGridExit;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
setContentView(R.layout.home);
registerIntentReceivers();
setDefaultWallpaper();
loadApplications(true);
bindApplications();
bindFavorites(true);
bindRecents();
bindButtons();
mGridEntry = AnimationUtils.loadAnimation(this, R.anim.grid_entry);
mGridExit = AnimationUtils.loadAnimation(this, R.anim.grid_exit);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// Close the menu
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
getWindow().closeAllPanels();
}
}
@Override
public void onDestroy() {
super.onDestroy();
// Remove the callback for the cached drawables or we leak
// the previous Home screen on orientation change
final int count = mApplications.size();
for (int i = 0; i < count; i++) {
mApplications.get(i).icon.setCallback(null);
}
unregisterReceiver(mWallpaperReceiver);
unregisterReceiver(mApplicationsReceiver);
}
@Override
protected void onResume() {
super.onResume();
bindRecents();
}
@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
final boolean opened = state.getBoolean(KEY_SAVE_GRID_OPENED, false);
if (opened) {
showApplications(false);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_SAVE_GRID_OPENED, mGrid.getVisibility() == View.VISIBLE);
}
/**
* Registers various intent receivers. The current implementation registers
* only a wallpaper intent receiver to let other applications change the
* wallpaper.
*/
private void registerIntentReceivers() {
IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
registerReceiver(mWallpaperReceiver, filter);
filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package");
registerReceiver(mApplicationsReceiver, filter);
}
/**
* Creates a new appplications adapter for the grid view and registers it.
*/
private void bindApplications() {
if (mGrid == null) {
mGrid = (GridView) findViewById(R.id.all_apps);
}
mGrid.setAdapter(new ApplicationsAdapter(this, mApplications));
mGrid.setSelection(0);
if (mApplicationsStack == null) {
mApplicationsStack = (ApplicationsStackLayout) findViewById(R.id.faves_and_recents);
}
}
/**
* Binds actions to the various buttons.
*/
private void bindButtons() {
mShowApplications = findViewById(R.id.show_all_apps);
mShowApplications.setOnClickListener(new ShowApplications());
mShowApplicationsCheck = (CheckBox) findViewById(R.id.show_all_apps_check);
mGrid.setOnItemClickListener(new ApplicationLauncher());
}
/**
* When no wallpaper was manually set, a default wallpaper is used instead.
*/
private void setDefaultWallpaper() {
if (!mWallpaperChecked) {
Drawable wallpaper = peekWallpaper();
if (wallpaper == null) {
try {
clearWallpaper();
} catch (IOException e) {
Log.e(LOG_TAG, "Failed to clear wallpaper " + e);
}
} else {
getWindow().setBackgroundDrawable(new Clipp
没有合适的资源?快使用搜索试试~ 我知道了~
Android_Home.rar_Home Home
共64个文件
xml:27个
png:20个
jpg:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 34 浏览量
2022-09-24
18:38:51
上传
评论
收藏 246KB RAR 举报
温馨提示
Android 程序,可以方便用户处理Home物理按键。可以放在任何程序中。
资源推荐
资源详情
资源评论
收起资源包目录
Android_Home.rar (64个子文件)
Android—Home按键
NOTICE 10KB
res
drawable-land
bg_android_icon.jpg 1KB
bg_android.jpg 12KB
bg_sunset.jpg 29KB
bg_sunset_icon.jpg 4KB
bg_sunrise.jpg 29KB
bg_sunrise_icon.jpg 4KB
values-nl-rNL
strings.xml 576B
values-land
strings.xml 812B
values-cs
strings.xml 567B
layout-land
home.xml 2KB
drawable-hdpi
ic_launcher_home.png 6KB
pressed_application_background_static.png 2KB
show_all_applications.png 6KB
ic_launcher_allhide.png 4KB
application_background_static.png 508B
ic_launcher_allshow.png 4KB
focused_application_background_static.png 2KB
hide_all_applications.png 5KB
all_applications_label_background.9.png 178B
application_background.9.png 596B
drawable
all_applications_button_background.xml 1KB
all_applications.xml 988B
favorite_background.xml 1KB
all_applications_background.xml 891B
grid_selector.xml 1KB
color
bright_text_dark_focused.xml 982B
values
strings.xml 1KB
attrs.xml 1KB
styles.xml 183B
drawable-port
bg_android_icon.jpg 1KB
bg_android.jpg 15KB
bg_sunset.jpg 20KB
bg_sunset_icon.jpg 4KB
bg_sunrise.jpg 29KB
bg_sunrise_icon.jpg 4KB
values-es-rUS
strings.xml 580B
values-de-rDE
strings.xml 604B
drawable-mdpi
ic_launcher_home.png 3KB
pressed_application_background_static.png 4KB
show_all_applications.png 7KB
ic_launcher_allhide.png 5KB
application_background_static.png 3KB
ic_launcher_allshow.png 5KB
focused_application_background_static.png 4KB
hide_all_applications.png 6KB
all_applications_label_background.9.png 3KB
application_background.9.png 3KB
anim
grid_entry.xml 1KB
grid_exit.xml 882B
fade_in.xml 881B
fade_out.xml 881B
hide_applications.xml 875B
show_applications.xml 930B
layout
application.xml 1KB
wallpaper.xml 2KB
all_applications_button.xml 2KB
favorite.xml 1KB
layout-port
home.xml 2KB
src
com
example
android
home
Home.java 26KB
ApplicationsStackLayout.java 11KB
Wallpaper.java 4KB
ApplicationInfo.java 2KB
AndroidManifest.xml 3KB
共 64 条
- 1
资源评论
局外狗
- 粉丝: 67
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功