哪款空气净化器除甲醛效果好-最新中式二层小别墅

2023年4月22日发(作者:美菱冰箱怎么样和海尔哪个好)
对于Android 2.1来说Live Wallpapers动态壁纸的加入为Android桌面加入了更好的动态效
果。如何开发一个Android动态桌面呢? 下面Android123给大家一个详细的步骤创建属于你
自己的Live Wallpaper吧。
1. 首先我使用Eclipse创建一个标准的Android工程这里package name我们使用
,然后进入工程的/res/文件夹,删除layout这个文件夹,当然里面的
也会被删除的,对于Live Wallpaper来说传统的布局文件是不需要的。
2. 类似AppWidget一样,我们可以加入动态壁纸的设置界面,我们在/res/文件夹中新建一
个名为xml的文件夹,新建一个utf8编码的xml文件,名为,内容为
<?xml version="1.0" encoding="utf-8"?>
android:settingsActivity="llpaperSettings" android:thumbnail="@drawable/icon"/> 这里我们可以看到上面的节点名为wallpaper,而设置的界面为 llpaperSettings 这个Activity,而在添加动态壁纸时显示图标为 /res/drawable/icon 这个文件,同时我们再创建一个xml文件用于LiveWallpaperSettings这个 Activity的布局,我们起名为livewallpaper_内容为 <?xml version="1.0" encoding="utf-8"?> android:title="@string/livewallpaper_settings" android:key="livewallpaper_settings"> android:key="livewallpaper_testpattern" android:title="标题" android:summary="简单描述" android:entries="@array/livewallpaper_testpattern_names" android:entryValues="@array/livewallpaper_testpattern_prefix"/> android:summary="动态描述" android:title="动态标题" android:summaryOn="动态测试" android:summaryOff="静止测试"/> 3. 创建一个名为LiveWallpaper的类作为动态壁纸的主类,从WallpaperService父类继承, 这里我们可以像写标准Android服务那样开发,代码为 public class LiveWallpaper extends WallpaperService { public static final String SHARED_PREFS_NAME = "livewallpapersettings"; @Override public void onCreate() { te(); } @Override public void onDestroy() { roy(); } @Override public Engine onCreateEngine() { return new TestPatternEngine(); } class TestPatternEngine extends Engine implements edPreferenceChangeListener { private final Handler mHandler = new Handler(); private float mTouchX = -1; private float mTouchY = -1; private final Paint mPaint = new Paint(); private final Runnable mDrawPattern = new Runnable() { public void run() { drawFrame(); } }; private boolean mVisible; private SharedPreferences mPreferences; private Rect mRectFrame; private Rect[] mColorRectangles; private int[] rectColor; private int mRectCount; // private private Rect mGradientRect; GradientDrawable mGradient; private boolean mHorizontal = false; private int mFrameCounter = 0; private boolean mMotion = true; private String mShape = "smpte"; TestPatternEngine() { final Paint paint = mPaint; or(0xffffffff); iAlias(true); okeWidth(2); okeCap(); le(); mPreferences = redPreferences(SHARED_PREFS_NAME, 0); erOnSharedPreferenceChangeListener(this); onSharedPreferenceChanged(mPreferences, null); } public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { mShape = ing("livewallpaper_testpattern", "smpte"); mMotion = lean("livewallpaper_movement", true); readColors(); } private void readColors() { int pid = getResources().getIdentifier(mShape + "colors", "array", getPackageName()); rectColor = getResources().getIntArray(pid); mRectCount = ; mColorRectangles = new Rect[mRectCount]; n("mRectCount "+mRectCount); initFrameParams(); } @Override public void onCreate(SurfaceHolder surfaceHolder) { te(surfaceHolder); setTouchEventsEnabled(true); } @Override public void onDestroy() { roy(); Callbacks(mDrawPattern); } @Override public void onVisibilityChanged(boolean visible) { mVisible = visible; if (visible) { drawFrame(); } else { Callbacks(mDrawPattern); } } @Override public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { aceChanged(holder, format, width, height); initFrameParams(); drawFrame(); } @Override public void onSurfaceCreated(SurfaceHolder holder) { aceCreated(holder); } @Override public void onSurfaceDestroyed(SurfaceHolder holder) { aceDestroyed(holder); mVisible = false; Callbacks(mDrawPattern); } @Override public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) { drawFrame(); } @Override public void onTouchEvent(MotionEvent event) { if (ion() == _MOVE) { mTouchX = (); mTouchY = (); } else { mTouchX = -1; mTouchY = -1; } hEvent(event); } void drawFrame() { final SurfaceHolder holder = getSurfaceHolder(); Canvas c = null; try { c = nvas(); if (c != null) { // draw something drawPattern(c); drawTouchPoint(c); } } finally { if (c != null) CanvasAndPost(c); } Callbacks(mDrawPattern); if (mVisible) { layed(mDrawPattern, 1000 / 25); } } void drawPattern(Canvas c) { (); lor(0xff000000); Paint paint = new Paint(); if (mMotion) { mFrameCounter++; if (mHorizontal) { int right; int left; if (mFrameCounter > ) mFrameCounter = 0; for (int i = 0; i < mRectCount; i++) { or(rectColor[i]); right = mColorRectangles[i].right + mFrameCounter; left = mColorRectangles[i].left + mFrameCounter; if(right > ) { ct(left - , mColorRectangles[i].top, right - , mColorRectangles[i].bottom, paint); } if(left < ) { ct(left, mColorRectangles[i].top, right, mColorRectangles[i].bottom, paint); } } if(eToIgnoreCase("smpte") == 0) { right = + mFrameCounter; left = + mFrameCounter; if(right > ) { nds(left - , , right - , ); (c); } if(left < ) { nds(left, , right, ); (c); } } } else { int top; int bottom; if (mFrameCounter > ) mFrameCounter = 0; for (int i = 0; i < mRectCount; i++) { or(rectColor[i]); top = mColorRectangles[i].top + mFrameCounter; bottom = mColorRectangles[i].bottom + mFrameCounter; if(bottom > ) { ct(mColorRectangles[i].left, top - , mColorRectangles[i].right, bottom - , paint); } if(top < ) { ct(mColorRectangles[i].left, top, mColorRectangles[i].right, bottom, paint); } } if(eToIgnoreCase("smpte") == 0) { top = + mFrameCounter; bottom = + mFrameCounter; if(bottom > ) { nds(, top - , , bottom - ); (c); } if(top < ) { nds(, top, , bottom); (c); } } } } else { for (int i = 0; i < mRectCount; i++) { or(rectColor[i]); ct(mColorRectangles[i], paint); } if(eToIgnoreCase("smpte") == 0) { nds(mGradientRect); (c); } } e(); } void drawTouchPoint(Canvas c) { if (mTouchX >= 0 && mTouchY >= 0) { rcle(mTouchX, mTouchY, 80, mPaint); } } void initFrameParams() { DisplayMetrics metrics = new DisplayMetrics(); Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); rics(metrics); mRectFrame = new Rect(0, 0, ixels, Pixels); int rotation = entation(); if(rotation == ON_0 || rotation == TION_180) mHorizontal = false; else mHorizontal = true; n("mHorizontal "+mHorizontal); n("mShape "+mShape); if(eToIgnoreCase("smpte") == 0) { n("mShape == smpte"); CreateSmpte(); } else if(eToIgnoreCase("bars") == 0) { n("mShape == bars"); CreateBars(); } else { n("mShape == ebu"); CreateEbu(); } } private void CreateSmpte() { if(mHorizontal) { int topHeight = * 7 / 12; int bottomHeight = * 3 / 4; int wideColumnWidth = / 8; int narrowColumnWidth = * 3 / 28; mColorRectangles[0] = new Rect(0, 0, wideColumnWidth, topHeight); for (int i = 1; i < 8; i++) { mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, 0, mColorRectangles[i - 1].right + narrowColumnWidth, topHeight); } mColorRectangles[8] = new Rect(mColorRectangles[7].right, 0, , topHeight); for (int i = 0; i < 2; i++) { int middleTop = * (7 + i) / 12; int middleBottom = * (8 + i) / 12; mColorRectangles[i + 9] = new Rect(0, middleTop, wideColumnWidth, middleBottom); mColorRectangles[i + 11] = new Rect(wideColumnWidth, middleTop, narrowColumnWidth + wideColumnWidth, middleBottom); mColorRectangles[i + 13] = new Rect(narrowColumnWidth * 7 + wideColumnWidth, middleTop, , middleBottom); } mColorRectangles[15] = new Rect(narrowColumnWidth + wideColumnWidth, topHeight, narrowColumnWidth * 7 + wideColumnWidth, * 8 / 12); mGradientRect = new Rect(mColorRectangles[15].left, mColorRectangles[15].bottom, mColorRectangles[15].right, * 9 / 12); mGradient = new GradientDrawable(_RIGHT, new int[] { 0xff050505, 0xfffdfdfd }); nds(mGradientRect); mColorRectangles[16] = new Rect(0, bottomHeight, wideColumnWidth, ); mColorRectangles[17] = new Rect(mColorRectangles[16].right, bottomHeight, * 9 / 56 + mColorRectangles[16].right, ); mColorRectangles[18] = new Rect(mColorRectangles[17].right, bottomHeight, * 3 / 14 + mColorRectangles[17].right, ); mColorRectangles[19] = new Rect(mColorRectangles[18].right, bottomHeight, * 45 / 448 + mColorRectangles[18].right, ); for (int i = 20; i < 25; i++) { mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, bottomHeight, * 15 / 448 + mColorRectangles[i - 1].right, ); } mColorRectangles[25] = new Rect(mColorRectangles[24].right, bottomHeight, narrowColumnWidth + mColorRectangles[24].right, ); mColorRectangles[26] = new Rect(mColorRectangles[25].right, bottomHeight, , ); } else { int topHeight = * 5 / 12; int bottomHeight = / 4; int wideColumnWidth = / 8; int narrowColumnWidth = * 3 / 28; mColorRectangles[0] = new Rect(topHeight, 0, , wideColumnWidth); for (int i = 1; i < 8; i++) { mColorRectangles[i] = new Rect(topHeight, mColorRectangles[i - 1].bottom, , narrowColumnWidth + mColorRectangles[i - 1].bottom); } mColorRectangles[8] = new Rect(topHeight, mColorRectangles[7].bottom, , ); for (int i = 0; i < 2; i++) { int middleLeft = * (4 - i) / 12; int middleRight = * (5 - i) / 12; mColorRectangles[i + 9] = new Rect(middleLeft, 0, middleRight, wideColumnWidth); mColorRectangles[i + 11] = new Rect(middleLeft, wideColumnWidth, middleRight, narrowColumnWidth + wideColumnWidth); mColorRectangles[i + 13] = new Rect(middleLeft, narrowColumnWidth * 7 + wideColumnWidth, middleRight, ); } mColorRectangles[15] = new Rect( * 4 / 12, narrowColumnWidth + wideColumnWidth, * 5 / 12, narrowColumnWidth * 7 + wideColumnWidth); mGradientRect = new Rect( * 3 / 12, mColorRectangles[15].top, mColorRectangles[15].left, mColorRectangles[15].bottom); mGradient = new GradientDrawable(_BOTTOM, new int[] { 0xff050505, 0xfffdfdfd }); nds(mGradientRect); mColorRectangles[16] = new Rect(0, 0, bottomHeight, wideColumnWidth); mColorRectangles[17] = new Rect(0, mColorRectangles[16].bottom, bottomHeight, * 9 / 56 + mColorRectangles[16].bottom); mColorRectangles[18] = new Rect(0, mColorRectangles[17].bottom, bottomHeight, * 3 / 14 + mColorRectangles[17].bottom); mColorRectangles[19] = new Rect(0, mColorRectangles[18].bottom, bottomHeight, * 45 / 448 + mColorRectangles[18].bottom); for (int i = 20; i < 25; i++) { mColorRectangles[i] = new Rect(0, mColorRectangles[i - 1].bottom, bottomHeight, * 15 / 448 + mColorRectangles[i - 1].bottom); } mColorRectangles[25] = new Rect(0, mColorRectangles[24].bottom, bottomHeight, narrowColumnWidth + mColorRectangles[24].bottom); mColorRectangles[26] = new Rect(0, mColorRectangles[25].bottom, bottomHeight, ); } } private void CreateBars() { if(mHorizontal) { int narrowColumnWidth = / 7; int wideColumnWidth = * 5 / 28; int narrowestColumnWidth = / 21; int topColumnHeight = *2/3; int middleColumnHeight = /12; mColorRectangles[0] = new Rect(0, 0, narrowColumnWidth, topColumnHeight); for (int i = 1; i < 7; i++) { mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, 0, mColorRectangles[i - 1].right + narrowColumnWidth, topColumnHeight); } mColorRectangles[7] = new Rect(0, mColorRectangles[0].bottom, narrowColumnWidth, mColorRectangles[0].bottom + middleColumnHeight); for (int i = 8; i < 14; i++) { mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, mColorRectangles[7].top, mColorRectangles[i - 1].right + narrowColumnWidth, mColorRectangles[7].bottom); } mColorRectangles[14] = new Rect(0, mColorRectangles[7].bottom, wideColumnWidth, ); for (int i = 15; i < 18; i++) { mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, mColorRectangles[14].top, mColorRectangles[i - 1].right + wideColumnWidth, ); } mColorRectangles[18] = new Rect(mColorRectangles[17].right, mColorRectangles[17].top, mColorRectangles[17].right + narrowestColumnWidth, ); for (int i = 19; i < 21; i++) { mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, mColorRectangles[14].top, mColorRectangles[i - 1].right + narrowestColumnWidth, ); } mColorRectangles[21] = new Rect(mColorRectangles[20].right, mColorRectangles[17].top, mColorRectangles[6].right, ); } else { int narrowColumnWidth = / 7; int wideColumnWidth = * 5 / 28; int narrowestColumnWidth = / 21; int topColumnHeight = /3; int middleColumnHeight = /12; mColorRectangles[0] = new Rect(topColumnHeight, 0, , narrowColumnWidth); for (int i = 1; i < 7; i++) { mColorRectangles[i] = new Rect(topColumnHeight, mColorRectangles[i - 1].bottom, , mColorRectangles[i - 1].bottom + narrowColumnWidth); } mColorRectangles[7] = new Rect(mColorRectangles[0].left + middleColumnHeight, 0, mColorRectangles[0].left, narrowColumnWidth); for (int i = 8; i < 14; i++) { mColorRectangles[i] = new Rect(mColorRectangles[7].left, mColorRectangles[i - 1].bottom, mColorRectangles[7].right, mColorRectangles[i - 1].bottom + narrowColumnWidth); } mColorRectangles[14] = new Rect(0, 0, mColorRectangles[7].right, wideColumnWidth); for (int i = 15; i < 18; i++) { mColorRectangles[i] = new Rect(0, mColorRectangles[i - 1].bottom, mColorRectangles[7].right, mColorRectangles[i - 1].bottom + wideColumnWidth); } mColorRectangles[18] = new Rect(0, mColorRectangles[17].bottom, mColorRectangles[7].right, mColorRectangles[17].bottom + narrowestColumnWidth); for (int i = 19; i < 21; i++) { mColorRectangles[i] = new Rect(0, mColorRectangles[i - 1].bottom, mColorRectangles[7].right, mColorRectangles[i - 1].bottom + narrowestColumnWidth); } mColorRectangles[21] = new Rect(0, mColorRectangles[20].bottom, mColorRectangles[7].right, ); } } private void CreateEbu() { if(mHorizontal) { int narrowColumnWidth = / 8; mColorRectangles[0] = new Rect(0, 0, narrowColumnWidth, ); for (int i = 1; i < 8; i++) { mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, 0, mColorRectangles[i - 1].right + narrowColumnWidth, ); } } else { int narrowColumnWidth = / 8; mColorRectangles[0] = new Rect(0, 0, , narrowColumnWidth); for (int i = 1; i < 8; i++) { mColorRectangles[i] = new Rect(0, mColorRectangles[i - 1].bottom, , narrowColumnWidth + mColorRectangles[i - 1].bottom); } } } } } 这里需要注意的是在文件中加入 android:icon="@drawable/icon"> /> 4. 新建类LiveWallpaperSettings从 PreferenceActivity 继承实现我们的设置界面,代码如下 public class LiveWallpaperSettings extends PreferenceActivity implements edPreferenceChangeListener { @Override protected void onCreate(Bundle icicle) { te(icicle); getPreferenceManager().setSharedPreferencesName(_PREFS_NAME); addPreferencesFromResource(llpaper_settings); getPreferenceManager().getSharedPreferences() .registerOnSharedPreferenceChangeListener(this); } @Override protected void onResume() { me(); } @Override protected void onDestroy() { getPreferenceManager().getSharedPreferences() .unregisterOnSharedPreferenceChangeListener(this); roy(); } public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { } } 同时仍然在中加入 下面的代码。 android:name=".LiveWallpaperSettings" android:theme="@android:style/perSettings" android:exported="true" android:icon="@drawable/icon"> 5. 由于Android动态壁纸是2.1 API Level为7才加入的,所以设置好minSDK以及需要设备 支持动态壁纸,我们在中加入 6. 对于文中ListPreference用到的数组,及代码中涉及的颜色数组,我们在/res/values/ 文件 夹中创建一个名为 的文件,内容为 <?xml version="1.0" encoding="utf-8"?>
中国墙布行业十大品牌-卫生间台面装修效果图

更多推荐
好看的动态壁纸免费
发布评论