use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.
the class WallpaperManager method generateBitmap.
static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
if (bm == null) {
return null;
}
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
bm.setDensity(metrics.noncompatDensityDpi);
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(metrics.noncompatDensityDpi);
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) {
Log.w(TAG, "Can't generate default bitmap", e);
return bm;
}
}
use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.
the class FakeApp method onCreate.
@Override
public void onCreate() {
String processName = ActivityThread.currentProcessName();
Slog.i("FakeOEMFeatures", "Creating app in process: " + processName);
if (!getApplicationInfo().packageName.equals(processName)) {
// our extra overhead stuff.
return;
}
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
// is a user build, WARN! Do not want!
if ("user".equals(android.os.Build.TYPE)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Should not be on user build");
builder.setMessage("The app Fake OEM Features should not be installed on a " + "user build. Please remove this .apk before shipping this build to " + " your customers!");
builder.setCancelable(false);
builder.setPositiveButton("I understand", null);
Dialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
}
// Make a fake window that is always around eating graphics resources.
FakeView view = new FakeView(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
if (ActivityManager.isHighEndGfx()) {
lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
}
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
int maxSize = display.getMaximumSizeDimension();
maxSize *= 2;
lp.x = maxSize;
lp.y = maxSize;
lp.setTitle(getPackageName());
wm.addView(view, lp);
// Bind to a fake service we want to keep running in another process.
bindService(new Intent(this, FakeCoreService.class), mServiceConnection, Context.BIND_AUTO_CREATE);
bindService(new Intent(this, FakeCoreService2.class), mServiceConnection2, Context.BIND_AUTO_CREATE);
bindService(new Intent(this, FakeCoreService3.class), mServiceConnection3, Context.BIND_AUTO_CREATE);
// Start to a fake service that should run in the background of
// another process.
mHandler.sendEmptyMessage(MSG_TICK);
// Make a fake allocation to consume some RAM.
mStuffing = new int[STUFFING_SIZE_INTS];
for (int i = 0; i < STUFFING_SIZE_BYTES / PAGE_SIZE; i++) {
// Fill each page with a unique value.
final int VAL = i * 2 + 100;
final int OFF = (i * PAGE_SIZE) / 4;
for (int j = 0; j < (PAGE_SIZE / 4); j++) {
mStuffing[OFF + j] = VAL;
}
}
}
use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.
the class LoadAverageService method onCreate.
@Override
public void onCreate() {
super.onCreate();
mView = new LoadView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.END | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}
use of android.view.WindowManager in project KeepScore by nolanlawson.
the class DragSortListView method startDragging.
private void startDragging(Bitmap bm, int x, int y) {
if (getParent() != null)
getParent().requestDisallowInterceptTouchEvent(true);
//removeFloatView();
mWindowParams = new WindowManager.LayoutParams();
mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
mWindowParams.x = x - mDragPointX + mXOffset;
mWindowParams.y = y - mDragPointY + mYOffset;
//Log.d("mobeta", "float view x=" + mWindowParams.x + " y=" + mWindowParams.y);
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
mWindowParams.format = PixelFormat.TRANSLUCENT;
mWindowParams.windowAnimations = 0;
Context context = getContext();
ImageView v = new ImageView(context);
//int backGroundColor = context.getResources().getColor(R.color.dragndrop_background);
v.setBackgroundColor(mFloatBGColor);
v.setAlpha(mFloatAlpha);
//v.setBackgroundResource(R.drawable.playlist_title_drag);
v.setPadding(0, 0, 0, 0);
v.setImageBitmap(bm);
mDragBitmap = bm;
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(v, mWindowParams);
mFloatView = v;
mDragState = SRC_EXP;
}
use of android.view.WindowManager in project c-geo by just-radovan.
the class cgBase method storeCache.
public void storeCache(cgeoapplication app, Activity activity, cgCache cache, String geocode, int listId, Handler handler) {
try {
// cache details
if (cache != null) {
final HashMap<String, String> params = new HashMap<String, String>();
params.put("geocode", cache.geocode);
final Long searchId = searchByGeocode(params, listId, false);
cache = app.getCache(searchId);
} else if (geocode != null) {
final HashMap<String, String> params = new HashMap<String, String>();
params.put("geocode", geocode);
final Long searchId = searchByGeocode(params, listId, false);
cache = app.getCache(searchId);
}
if (cache == null) {
if (handler != null) {
handler.sendMessage(new Message());
}
return;
}
final cgHtmlImg imgGetter = new cgHtmlImg(activity, settings, cache.geocode, false, listId, true);
// store images from description
if (cache.description != null) {
Html.fromHtml(cache.description, imgGetter, null);
}
// store spoilers
if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
for (cgSpoiler oneSpoiler : cache.spoilers) {
imgGetter.getDrawable(oneSpoiler.url);
}
}
// store map previews
if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) {
final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + "," + String.format((Locale) null, "%.6f", cache.longitude);
final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
final int maxWidth = display.getWidth() - 25;
final int maxHeight = display.getHeight() - 25;
int edge = 0;
if (maxWidth > maxHeight) {
edge = maxWidth;
} else {
edge = maxHeight;
}
String type = "mystery";
if (cache.found == true) {
type = cache.type + "_found";
} else if (cache.disabled == true) {
type = cache.type + "_disabled";
} else {
type = cache.type;
}
final String markerUrl = urlencode_rfc3986("http://cgeo.carnero.cc/_markers/marker_cache_" + type + ".png");
final StringBuilder waypoints = new StringBuilder();
if (cache.waypoints != null && cache.waypoints.size() > 0) {
for (cgWaypoint waypoint : cache.waypoints) {
if (waypoint.latitude == null && waypoint.longitude == null) {
continue;
}
waypoints.append("&markers=icon%3Ahttp://cgeo.carnero.cc/_markers/marker_waypoint_");
waypoints.append(waypoint.type);
waypoints.append(".png%7C");
waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude));
waypoints.append(",");
waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude));
}
}
// download map images in separate background thread for higher performance
final String code = cache.geocode;
final int finalEdge = edge;
Thread staticMapsThread = new Thread("getting static map") {
@Override
public void run() {
cgMapImg mapGetter = new cgMapImg(settings, code);
mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=20&size=" + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 1);
mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=18&size=" + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 2);
mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=16&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 3);
mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=14&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 4);
mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=11&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 5);
}
};
staticMapsThread.setPriority(Thread.MIN_PRIORITY);
staticMapsThread.start();
}
app.markStored(cache.geocode, listId);
app.removeCacheFromCache(cache.geocode);
if (handler != null) {
handler.sendMessage(new Message());
}
} catch (Exception e) {
Log.e(cgSettings.tag, "cgBase.storeCache: " + e.toString());
}
}
Aggregations