新公司第一个修改的需求,可以设置桌面壁纸;设置锁屏壁纸;同时设置桌面和锁屏壁纸,锁屏壁纸只能用静态的图片 效果如下所示:
直接贴代码,
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index f808eba..8e5f0cb 100755
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -211,6 +211,15 @@ import java.lang.reflect.Field;
import android.widget.TextView;
/// @}
+//add by frankchen
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.Paint;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import android.graphics.Bitmap.CompressFormat;
+
public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener,
HeadsUpManager.OnHeadsUpChangedListener {
@@ -254,6 +263,16 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
* The delay to reset the hint text when the hint animation is finished running.
*/
private static final int HINT_RESET_DELAY_MS = 1200;
+
+ //add by frankchen start
+
+ private byte[] outByteArray =null;
+ private Bitmap bitmap_receive=null;
+
+ private File appDir = new File("/data/data/com.android.systemui", "locked");;
+ private static String lockfileName = "lockwallpaper" + ".jpg";
+
+ //add by frankchen end
private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
@@ -1004,6 +1023,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
filter.addAction(Intent.ACTION_USER_PRESENT);
context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
+
+ //add by frankchen start
+ IntentFilter filter_hy = new IntentFilter();
+ filter_hy.addAction("android.yue.lockscreen.action");
+ context.registerReceiverAsUser(mTestReceiver, UserHandle.ALL, filter_hy, null, null);
+ //add by frankchen end
IntentFilter demoFilter = new IntentFilter();
if (DEBUG_MEDIA_FAKE_ARTWORK) {
@@ -3459,6 +3484,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
}
mContext.unregisterReceiver(mBroadcastReceiver);
mContext.unregisterReceiver(mDemoReceiver);
+
+ mContext.unregisterReceiver(mTestReceiver);
+
mAssistManager.destroy();
final SignalClusterView signalCluster =
@@ -3789,7 +3817,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
goingToFullShade || mState == StatusBarState.SHADE_LOCKED || fromShadeLocked);
}
if (mState == StatusBarState.KEYGUARD || mState == StatusBarState.SHADE_LOCKED) {
- if(i== 1){
+ /*frankchen
+ if(i== 1){
mHolder.setBackgroundResource(R.drawable.a1);
}else if(i==2){
mHolder.setBackgroundResource(R.drawable.a2);
@@ -3810,7 +3839,19 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
}else if(i==10){
mHolder.setBackgroundResource(R.drawable.a10);
}
-
+ /*/
+ Bitmap bm =getImage();
+ Log.d(TAG, "getImage getImage bm ===" + bm);
+ if (bm != null) {
+ Drawable dr = new BitmapDrawable(mContext.getResources(), generateBitmap(bm, 480, 854));
+ dr.setDither(false);
+ mHolder.setBackground(dr);
+ }else
+ {
+ // mHolder.setBackgroundResource(0);
+ mHolder.setBackgroundResource(R.drawable.a1);
+ }
+ //*/
mScrimController.setKeyguardShowing(true);
mIconPolicy.setKeyguardShowing(true);
} else {
@@ -3833,6 +3874,110 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mKeyguardMonitor.notifyKeyguardState(mStatusBarKeyguardViewManager.isShowing(),
mStatusBarKeyguardViewManager.isSecure());
}
+
+ //add by frankchen start
+
+ private void saveImage(Bitmap bmp) {
+
+ if (!appDir.exists()) {
+ appDir.mkdir();
+ }
+
+ File file = new File(appDir, lockfileName);
+ try {
+ FileOutputStream fos = new FileOutputStream(file);
+ bmp.compress(CompressFormat.JPEG, 100, fos);
+ fos.flush();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Bitmap getImage()
+ {
+ File file = new File(appDir, lockfileName);
+ System.out.println(file.getPath());
+ if (file.exists()) {
+ Bitmap bitmap=BitmapFactory.decodeFile(file.getPath());
+ return bitmap;
+ }else
+ {
+ return null;
+ }
+ }
+
+ private BroadcastReceiver mTestReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if ("android.yue.lockscreen.action".equals(intent.getAction())) {
+
+ outByteArray= intent.getExtras().getByteArray("outByteArray");
+ Log.i("frankchen","outByteArray=====------ "+outByteArray);
+ InputStream is = new ByteArrayInputStream(outByteArray);
+ bitmap_receive = BitmapFactory.decodeStream(is);
+ saveImage(bitmap_receive);
+ }
+ }
+ };
+
+ private Bitmap generateBitmap(Bitmap bm, int width, int height) {
+ if (bm == null) {
+ return null;
+ }
+
+ bm.setDensity(DisplayMetrics.DENSITY_HIGH);
+
+ if (width <= 0 || height <= 0
+ || (bm.getWidth() == width && bm.getHeight() == height)) {
+ return bm;
+ }
+
+ // This is the final bitmap we want to return.
+ try {
+ Bitmap newbm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ newbm.setDensity(DisplayMetrics.DENSITY_HIGH);
+
+ Canvas c = new Canvas(newbm);
+ Rect targetRect = new Rect();
+ targetRect.right = bm.getWidth();
+ targetRect.bottom = bm.getHeight();
+
+ int deltaw = width - targetRect.right;
+ int deltah = height - targetRect.bottom;
+
+ if (deltaw > 0 || deltah > 0) {
+ // We need to scale up so it covers the entire area.
+ float scale;
+ if (deltaw > deltah) {
+ scale = width / (float)targetRect.right;
+ } else {
+ scale = height / (float)targetRect.bottom;
+ }
+ targetRect.right = (int)(targetRect.right*scale);
+ targetRect.bottom = (int)(targetRect.bottom*scale);
+ deltaw = width - targetRect.right;
+ deltah = height - targetRect.bottom;
+ }
+
+ targetRect.offset(deltaw/2, deltah/2);
+
+ Paint paint = new Paint();
+ paint.setFilterBitmap(true);
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
+ c.drawBitmap(bm, null, targetRect, paint);
+
+ bm.recycle();
+ c.setBitmap(null);
+ return newbm;
+ } catch (OutOfMemoryError e) {
+ return bm;
+ }
+ }
+
+ //add by frankchen end
private void updateDozingState() {
boolean animate = !mDozing && mDozeScrimController.isPulsing();
diff --git a/alps/packages/apps/LauncherL1/WallpaperPicker/res/values-zh-rCN/strings.xml b/alps/packages/apps/LauncherL1/WallpaperPicker/res/values-zh-rCN/strings.xml
index 1def9ed..44eeac1 100755
--- a/alps/packages/apps/LauncherL1/WallpaperPicker/res/values-zh-rCN/strings.xml
+++ b/alps/packages/apps/LauncherL1/WallpaperPicker/res/values-zh-rCN/strings.xml
@@ -33,4 +33,10 @@
"选择图片"
"壁纸"
"剪裁壁纸"
+
+ 设置墙纸
+ 设置桌面墙纸
+ 设置锁屏墙纸
+ 设置桌面和锁屏墙纸
+
diff --git a/alps/packages/apps/LauncherL1/WallpaperPicker/res/values/strings.xml b/alps/packages/apps/LauncherL1/WallpaperPicker/res/values/strings.xml
index 1ee3513..0f860af 100755
--- a/alps/packages/apps/LauncherL1/WallpaperPicker/res/values/strings.xml
+++ b/alps/packages/apps/LauncherL1/WallpaperPicker/res/values/strings.xml
@@ -50,4 +50,11 @@
Wallpapers
Crop wallpaper
+
+
+ Set Wallpaper
+ Set home screen wallpaper
+ Set locked screen wallpaper
+ Set both
+
diff --git a/alps/packages/apps/LauncherL1/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/alps/packages/apps/LauncherL1/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index 8593525..23d1e45 100755
--- a/alps/packages/apps/LauncherL1/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/alps/packages/apps/LauncherL1/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -67,6 +67,8 @@ import java.lang.SecurityException;
import android.app.AlertDialog;
import android.content.DialogInterface;
+//add by frankchen
+import android.content.DialogInterface.OnClickListener;
public class WallpaperCropActivity extends Activity {
private static final String LOGTAG = "Launcher3.CropActivity";
@@ -109,6 +111,8 @@ public class WallpaperCropActivity extends Activity {
protected View mSetWallpaperButton;
private static int flag=-1;
+ private static int mWallpaperMode=0;
+
private static final boolean mIsOmaDrmSupport =
(SystemProperties.getInt("ro.mtk_oma_drm_support", 0) == 1) ? true : false;
@@ -142,6 +146,64 @@ public class WallpaperCropActivity extends Activity {
flag = mFlag;
}
+ //add by frankchen start
+ /**
+ * 单选Dialog
+ */
+ int choice=0;
+ private void showSingDialog(){
+ Intent cropIntent = getIntent();
+ final Uri imageUri = cropIntent.getData();
+
+ if (imageUri == null) {
+ Log.e(LOGTAG, "No URI passed in intent, exiting WallpaperCropActivity");
+ finish();
+ return;
+ }
+
+ final String[] items = {getString(R.string.set_home_sreen_wallpaper),getString(R.string.set_locked_sreen_wallpaper),getString(R.string.set_both_home_locked)};
+ AlertDialog.Builder singleChoiceDialog = new AlertDialog.Builder(WallpaperCropActivity.this,4);
+ // singleChoiceDialog.setIcon(R.drawable.ic_launcher);
+ singleChoiceDialog.setTitle(getString(R.string.set_wallpaper_title));
+ //
+ singleChoiceDialog.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ choice= which;
+ }
+ });
+ singleChoiceDialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (choice!=-1){
+ if(choice==0)
+ {
+ mWallpaperMode = 0;
+ cropImageAndSetWallpaper(imageUri, null, true);
+ }else if(choice==1)
+ {
+ mWallpaperMode = 1;
+ cropImageAndSetWallpaper(imageUri, null, true);
+ }else if(choice==2)
+ {
+ mWallpaperMode = 2;
+ cropImageAndSetWallpaper(imageUri, null, true);
+ }
+ }
+ }
+ });
+ singleChoiceDialog.setNegativeButton(android.R.string.cancel, new OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // TODO Auto-generated method stub
+ dialog.cancel();
+ }
+ });
+ singleChoiceDialog.show();
+ }
+ //add by frankchen end
+
protected void init() {
setContentView(R.layout.wallpaper_cropper);
@@ -165,8 +227,12 @@ public class WallpaperCropActivity extends Activity {
new View.OnClickListener() {
@Override
public void onClick(View v) {
+ /*
boolean finishActivityWhenDone = true;
cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone);
+ /*/
+ showSingDialog();
+ //*/
}
});
mSetWallpaperButton = findViewById(R.id.set_wallpaper_button);
@@ -174,10 +240,13 @@ public class WallpaperCropActivity extends Activity {
@Override
public void onClick(View arg0) {
Log.e("wyy","View");
- android.util.Log.e("chengrq","mSetWallpaperButton show show");
+ /*android.util.Log.e("chengrq","mSetWallpaperButton show show");
//flag = getIntent().getIntExtra("flag", 0);
flag = 0;
- cropImageAndSetWallpaper(imageUri, null, true);
+ cropImageAndSetWallpaper(imageUri, null, true);
+ /*/
+ showSingDialog();
+ //*/
}
});
@@ -532,6 +601,7 @@ public class WallpaperCropActivity extends Activity {
if (onBitmapCroppedHandler != null) {
cropTask.setOnBitmapCropped(onBitmapCroppedHandler);
}
+ //cropTask.setWallpaperMode(mWallpaperMode);//add by frankchen
cropTask.execute();
}
@@ -720,7 +790,8 @@ public class WallpaperCropActivity extends Activity {
if (mSetWallpaper && mNoCrop) {
try {
- InputStream is = regenerateInputStream();
+ /* frankchen
+ InputStream is = regenerateInputStream();
if (is != null) {
//wallpaperManager.setStream(is);
//Utils.closeSilently(is);
@@ -732,6 +803,26 @@ public class WallpaperCropActivity extends Activity {
}
Utils.closeSilently(is);
}
+ /*/
+
+
+
+ InputStream is_home = regenerateInputStream();
+ Log.i(LOGTAG, "mWallpaperMode mWallpaperMode==" + mWallpaperMode);
+ Log.e("frankchen","mWallpaperMode aaaaaaa mWallpaperMode="+mWallpaperMode);
+ if (is_home != null) {
+ if(mWallpaperMode==1){
+ wallpaperManager.setStream(is_home);
+ }else if(mWallpaperMode==2){
+ wallpaperManager.setStream(is_home);
+ }else{
+ wallpaperManager.setStream(is_home);
+ }
+
+ Utils.closeSilently(is_home);
+ }
+ //*/
+
} catch (IOException e) {
Log.w(LOGTAG, "cannot write stream to wallpaper", e);
failure = true;
@@ -968,6 +1059,7 @@ public class WallpaperCropActivity extends Activity {
Log.e("chengrqq","flag="+flag);
byte[] outByteArray = tmpOut.toByteArray();
+ /*frankchen
if(flag==1)
{
//wallpaperManager.setStream(new ByteArrayInputStream(outByteArray),1);
@@ -977,6 +1069,30 @@ public class WallpaperCropActivity extends Activity {
{
wallpaperManager.setStream(new ByteArrayInputStream(outByteArray));
}
+ /*/
+ //int choose_mode= getLockScreenSettingFlag();
+ Log.e("frankchen","mWallpaperMode bbbbbb mWallpaperMode="+mWallpaperMode);
+ // Log.e("frankchen","choose_mode choose_mode ="+choose_mode);
+ if(mWallpaperMode==1||flag==1){
+
+ //lock
+ Intent intent = new Intent("android.yue.lockscreen.action");//
+ intent.putExtra("outByteArray",outByteArray);
+ mContext.sendBroadcast(intent);
+
+ }else if(mWallpaperMode==2||flag==2){
+ //both
+ wallpaperManager.setStream(new ByteArrayInputStream(outByteArray));
+
+ Intent intent = new Intent("android.yue.lockscreen.action");//
+ intent.putExtra("outByteArray",outByteArray);
+ mContext.sendBroadcast(intent);
+ }else{
+
+ //home
+ wallpaperManager.setStream(new ByteArrayInputStream(outByteArray));
+ }
+ //*/
if (mOnBitmapCroppedHandler != null) {
mOnBitmapCroppedHandler.onBitmapCropped(outByteArray);
}
@@ -992,6 +1108,12 @@ public class WallpaperCropActivity extends Activity {
}
return !failure; // True if any of the operations failed
}
+
+ //add by frankchen start
+ /*public void setWallpaperMode(int wpMode){
+ mWallpaperMode = wpMode;
+ }*/
+ //add by frankchen end