Merge "More watermark work." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
f467ca08dd
@ -16,11 +16,6 @@
|
|||||||
|
|
||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import static android.os.LocalPowerManager.CHEEK_EVENT;
|
|
||||||
import static android.os.LocalPowerManager.OTHER_EVENT;
|
|
||||||
import static android.os.LocalPowerManager.TOUCH_EVENT;
|
|
||||||
import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
|
|
||||||
import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
|
|
||||||
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
|
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
|
||||||
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
|
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
|
||||||
import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
|
import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
|
||||||
@ -76,7 +71,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Debug;
|
import android.os.Debug;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.LatencyTimer;
|
|
||||||
import android.os.LocalPowerManager;
|
import android.os.LocalPowerManager;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@ -109,13 +103,11 @@ import android.view.IWindowSession;
|
|||||||
import android.view.InputChannel;
|
import android.view.InputChannel;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.InputEvent;
|
import android.view.InputEvent;
|
||||||
import android.view.InputQueue;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.SurfaceSession;
|
import android.view.SurfaceSession;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewConfiguration;
|
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.WindowManagerImpl;
|
import android.view.WindowManagerImpl;
|
||||||
@ -127,9 +119,13 @@ import android.view.animation.Animation;
|
|||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.DataInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
@ -165,8 +161,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
static final boolean DEBUG_FREEZE = false;
|
static final boolean DEBUG_FREEZE = false;
|
||||||
static final boolean SHOW_TRANSACTIONS = false;
|
static final boolean SHOW_TRANSACTIONS = false;
|
||||||
static final boolean HIDE_STACK_CRAWLS = true;
|
static final boolean HIDE_STACK_CRAWLS = true;
|
||||||
static final boolean MEASURE_LATENCY = false;
|
|
||||||
static private LatencyTimer lt;
|
|
||||||
|
|
||||||
static final boolean PROFILE_ORIENTATION = false;
|
static final boolean PROFILE_ORIENTATION = false;
|
||||||
static final boolean BLUR = true;
|
static final boolean BLUR = true;
|
||||||
@ -604,10 +598,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
|
|
||||||
private WindowManagerService(Context context, PowerManagerService pm,
|
private WindowManagerService(Context context, PowerManagerService pm,
|
||||||
boolean haveInputMethods) {
|
boolean haveInputMethods) {
|
||||||
if (MEASURE_LATENCY) {
|
|
||||||
lt = new LatencyTimer(100, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mHaveInputMethods = haveInputMethods;
|
mHaveInputMethods = haveInputMethods;
|
||||||
mLimitedAlphaCompositing = context.getResources().getBoolean(
|
mLimitedAlphaCompositing = context.getResources().getBoolean(
|
||||||
@ -9579,6 +9569,10 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
|
|
||||||
Surface.closeTransaction();
|
Surface.closeTransaction();
|
||||||
|
|
||||||
|
if (mWatermark != null) {
|
||||||
|
mWatermark.drawIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
|
if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
|
||||||
"With display frozen, orientationChangeComplete="
|
"With display frozen, orientationChangeComplete="
|
||||||
+ orientationChangeComplete);
|
+ orientationChangeComplete);
|
||||||
@ -10072,12 +10066,17 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
mScreenFrozenLock.release();
|
mScreenFrozenLock.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getPropertyInt(String name, int defUnits, int defDps, DisplayMetrics dm) {
|
static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
|
||||||
String str = SystemProperties.get(name);
|
DisplayMetrics dm) {
|
||||||
try {
|
if (index < tokens.length) {
|
||||||
int val = Integer.parseInt(str);
|
String str = tokens[index];
|
||||||
return val;
|
if (str != null && str.length() > 0) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
|
int val = Integer.parseInt(str);
|
||||||
|
return val;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
|
if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
|
||||||
return defDps;
|
return defDps;
|
||||||
@ -10087,62 +10086,142 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Watermark {
|
class Watermark {
|
||||||
Surface mSurface;
|
final String[] mTokens;
|
||||||
int mWidth;
|
final String mText;
|
||||||
int mHeight;
|
final Paint mTextPaint;
|
||||||
int mXPercent;
|
final int mTextWidth;
|
||||||
int mYPercent;
|
final int mTextHeight;
|
||||||
|
final int mTextAscent;
|
||||||
|
final int mTextDescent;
|
||||||
|
final int mDeltaX;
|
||||||
|
final int mDeltaY;
|
||||||
|
|
||||||
Watermark(SurfaceSession session, String text) {
|
Surface mSurface;
|
||||||
|
int mLastDW;
|
||||||
|
int mLastDH;
|
||||||
|
boolean mDrawNeeded;
|
||||||
|
|
||||||
|
Watermark(SurfaceSession session, String[] tokens) {
|
||||||
final DisplayMetrics dm = new DisplayMetrics();
|
final DisplayMetrics dm = new DisplayMetrics();
|
||||||
mDisplay.getMetrics(dm);
|
mDisplay.getMetrics(dm);
|
||||||
|
|
||||||
int fontSize = getPropertyInt("ro.watermark.height",
|
if (false) {
|
||||||
TypedValue.COMPLEX_UNIT_DIP, 48, dm);
|
Log.i(TAG, "*********************** WATERMARK");
|
||||||
mXPercent = getPropertyInt("ro.watermark.x",
|
for (int i=0; i<tokens.length; i++) {
|
||||||
TypedValue.COMPLEX_UNIT_PX, 50, dm);
|
Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
|
||||||
mYPercent = getPropertyInt("ro.watermark.y",
|
}
|
||||||
TypedValue.COMPLEX_UNIT_PX, 99, dm);
|
}
|
||||||
int color = getPropertyInt("ro.watermark.color",
|
|
||||||
TypedValue.COMPLEX_UNIT_PX, 0x80ffffff, dm);
|
|
||||||
int shadowRadius = getPropertyInt("ro.watermark.shadow.radius",
|
|
||||||
TypedValue.COMPLEX_UNIT_PX, 5, dm);
|
|
||||||
int shadowDx = getPropertyInt("ro.watermark.shadow.dx",
|
|
||||||
TypedValue.COMPLEX_UNIT_PX, 0, dm);
|
|
||||||
int shadowDy = getPropertyInt("ro.watermark.shadow.dy",
|
|
||||||
TypedValue.COMPLEX_UNIT_PX, 0, dm);
|
|
||||||
int shadowColor = getPropertyInt("ro.watermark.shadow.color",
|
|
||||||
TypedValue.COMPLEX_UNIT_PX, 0xff000000, dm);
|
|
||||||
|
|
||||||
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mTokens = tokens;
|
||||||
paint.setTextSize(fontSize);
|
|
||||||
paint.setColor(color);
|
|
||||||
paint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
|
|
||||||
paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
|
|
||||||
|
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
StringBuilder builder = new StringBuilder(32);
|
||||||
mHeight = fm.descent - fm.ascent + 20;
|
int len = mTokens[0].length();
|
||||||
mWidth = (int)paint.measureText(text) + 20;
|
len = len & ~1;
|
||||||
|
for (int i=0; i<len; i+=2) {
|
||||||
|
int c1 = mTokens[0].charAt(i);
|
||||||
|
int c2 = mTokens[0].charAt(i+1);
|
||||||
|
if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
|
||||||
|
else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
|
||||||
|
else c1 -= '0';
|
||||||
|
if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
|
||||||
|
else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
|
||||||
|
else c2 -= '0';
|
||||||
|
builder.append((char)(255-((c1*16)+c2)));
|
||||||
|
}
|
||||||
|
mText = builder.toString();
|
||||||
|
if (false) {
|
||||||
|
Log.i(TAG, "Final text: " + mText);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fontSize = getPropertyInt(tokens, 1,
|
||||||
|
TypedValue.COMPLEX_UNIT_DIP, 20, dm);
|
||||||
|
|
||||||
|
mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
mTextPaint.setTextSize(fontSize);
|
||||||
|
mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
|
||||||
|
|
||||||
|
FontMetricsInt fm = mTextPaint.getFontMetricsInt();
|
||||||
|
mTextWidth = (int)mTextPaint.measureText(mText);
|
||||||
|
mTextAscent = fm.ascent;
|
||||||
|
mTextDescent = fm.descent;
|
||||||
|
mTextHeight = fm.descent - fm.ascent;
|
||||||
|
|
||||||
|
mDeltaX = getPropertyInt(tokens, 2,
|
||||||
|
TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
|
||||||
|
mDeltaY = getPropertyInt(tokens, 3,
|
||||||
|
TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
|
||||||
|
int shadowColor = getPropertyInt(tokens, 4,
|
||||||
|
TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
|
||||||
|
int color = getPropertyInt(tokens, 5,
|
||||||
|
TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
|
||||||
|
int shadowRadius = getPropertyInt(tokens, 6,
|
||||||
|
TypedValue.COMPLEX_UNIT_PX, 7, dm);
|
||||||
|
int shadowDx = getPropertyInt(tokens, 8,
|
||||||
|
TypedValue.COMPLEX_UNIT_PX, 0, dm);
|
||||||
|
int shadowDy = getPropertyInt(tokens, 9,
|
||||||
|
TypedValue.COMPLEX_UNIT_PX, 0, dm);
|
||||||
|
|
||||||
|
mTextPaint.setColor(color);
|
||||||
|
mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mSurface = new Surface(session, 0,
|
mSurface = new Surface(session, 0,
|
||||||
"WatermarkSurface",
|
"WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
|
||||||
-1, mWidth, mHeight, PixelFormat.TRANSLUCENT, 0);
|
|
||||||
mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
|
mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
|
||||||
Rect dirty = new Rect(0, 0, mWidth, mHeight);
|
mSurface.setPosition(0, 0);
|
||||||
Canvas c = mSurface.lockCanvas(dirty);
|
|
||||||
c.drawText(text, 10, -fm.ascent+10, paint);
|
|
||||||
mSurface.unlockCanvasAndPost(c);
|
|
||||||
mSurface.show();
|
mSurface.show();
|
||||||
} catch (OutOfResourcesException e) {
|
} catch (OutOfResourcesException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void positionSurface(int dw, int dh) {
|
void positionSurface(int dw, int dh) {
|
||||||
int availW = dw - mWidth;
|
if (mLastDW != dw || mLastDH != dh) {
|
||||||
int availH = dh - mHeight;
|
mLastDW = dw;
|
||||||
mSurface.setPosition((availW*mXPercent)/100,
|
mLastDH = dh;
|
||||||
(availH*mYPercent)/100);
|
mSurface.setSize(dw, dh);
|
||||||
|
mDrawNeeded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawIfNeeded() {
|
||||||
|
if (mDrawNeeded) {
|
||||||
|
final int dw = mLastDW;
|
||||||
|
final int dh = mLastDH;
|
||||||
|
|
||||||
|
mDrawNeeded = false;
|
||||||
|
Rect dirty = new Rect(0, 0, dw, dh);
|
||||||
|
Canvas c = null;
|
||||||
|
try {
|
||||||
|
c = mSurface.lockCanvas(dirty);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
} catch (OutOfResourcesException e) {
|
||||||
|
}
|
||||||
|
if (c != null) {
|
||||||
|
int deltaX = mDeltaX;
|
||||||
|
int deltaY = mDeltaY;
|
||||||
|
|
||||||
|
// deltaX shouldn't be close to a round fraction of our
|
||||||
|
// x step, or else things will line up too much.
|
||||||
|
int div = (dw+mTextWidth)/deltaX;
|
||||||
|
int rem = (dw+mTextWidth) - (div*deltaX);
|
||||||
|
int qdelta = deltaX/4;
|
||||||
|
if (rem < qdelta || rem > (deltaX-qdelta)) {
|
||||||
|
deltaX += deltaX/3;
|
||||||
|
}
|
||||||
|
|
||||||
|
int y = -mTextHeight;
|
||||||
|
int x = -mTextWidth;
|
||||||
|
while (y < (dh+mTextHeight)) {
|
||||||
|
c.drawText(mText, x, y, mTextPaint);
|
||||||
|
x += deltaX;
|
||||||
|
if (x >= dw) {
|
||||||
|
x -= (dw+mTextWidth);
|
||||||
|
y += deltaY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mSurface.unlockCanvasAndPost(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10151,12 +10230,28 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String text = SystemProperties.get("ro.watermark.text");
|
File file = new File("/system/etc/setup.conf");
|
||||||
if (text == null || text.length() <= 0) {
|
FileInputStream in = null;
|
||||||
return;
|
try {
|
||||||
|
in = new FileInputStream(file);
|
||||||
|
DataInputStream ind = new DataInputStream(in);
|
||||||
|
String line = ind.readLine();
|
||||||
|
if (line != null) {
|
||||||
|
String[] toks = line.split("%");
|
||||||
|
if (toks != null && toks.length > 0) {
|
||||||
|
mWatermark = new Watermark(mFxSession, toks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mWatermark = new Watermark(mFxSession, text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user