use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.
the class UserTile method queryForUserInformation.
private void queryForUserInformation() {
Context currentUserContext = null;
UserInfo userInfo = null;
try {
userInfo = ActivityManagerNative.getDefault().getCurrentUser();
currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
} catch (NameNotFoundException e) {
Log.e(TAG, "Couldn't create user context", e);
throw new RuntimeException(e);
} catch (RemoteException e) {
Log.e(TAG, "Couldn't get user info", e);
}
final int userId = userInfo.id;
final String userName = userInfo.name;
final Context context = currentUserContext;
mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
@Override
protected Pair<String, Drawable> doInBackground(Void... params) {
try {
// The system needs some time to change the picture, if we try to load it when we receive the broadcast, we will load the old one
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
// Fall back to the UserManager nickname if we can't read the name from the local
// profile below.
String name = userName;
Drawable avatar = null;
Bitmap rawAvatar = um.getUserIcon(userId);
if (rawAvatar != null) {
avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
} else {
avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
}
// usually valid
if (um.getUsers().size() <= 1) {
// Try and read the display name from the local profile
final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
}
return new Pair<String, Drawable>(name, avatar);
}
@Override
protected void onPostExecute(Pair<String, Drawable> result) {
super.onPostExecute(result);
setUserTileInfo(result.first, result.second);
mUserInfoTask = null;
}
};
mUserInfoTask.execute();
}
use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method start.
public void start() {
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
mDisplay = mWindowManager.getDefaultDisplay();
// set up
mProvisioningObserver.onChange(false);
mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, mProvisioningObserver);
mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
mStatusBarContainer = new FrameLayout(mContext);
mLocale = mContext.getResources().getConfiguration().locale;
mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale);
// Connect in to the status bar manager service
StatusBarIconList iconList = new StatusBarIconList();
ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
mCommandQueue = new CommandQueue(this, iconList);
int[] switches = new int[7];
ArrayList<IBinder> binders = new ArrayList<IBinder>();
try {
mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, switches, binders);
} catch (RemoteException ex) {
// If the system process isn't there we're doomed anyway.
}
mHaloActive = Settings.System.getInt(mContext.getContentResolver(), Settings.System.HALO_ACTIVE, 0) == 1;
createAndAddWindows();
disable(switches[0]);
setSystemUiVisibility(switches[1], 0xffffffff);
topAppWindowChanged(switches[2] != 0);
// StatusBarManagerService has a back up of IME token and it's restored here.
setImeWindowStatus(binders.get(0), switches[3], switches[4]);
setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);
// Set up the initial icon state
int N = iconList.size();
int viewIndex = 0;
for (int i = 0; i < N; i++) {
StatusBarIcon icon = iconList.getIcon(i);
if (icon != null) {
addIcon(iconList.getSlot(i), i, viewIndex, icon);
viewIndex++;
}
}
// Set up the initial notification state
N = notificationKeys.size();
if (N == notifications.size()) {
for (int i = 0; i < N; i++) {
addNotification(notificationKeys.get(i), notifications.get(i));
}
} else {
Log.wtf(TAG, "Notification list length mismatch: keys=" + N + " notifications=" + notifications.size());
}
if (DEBUG) {
Slog.d(TAG, String.format("init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", iconList.size(), switches[0], switches[1], switches[2], switches[3]));
}
mCurrentUserId = ActivityManager.getCurrentUser();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_SWITCHED);
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
if (true)
Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
userSwitched(mCurrentUserId);
}
}
}, filter);
// Only watch for per app color changes when the setting is in check
if (ColorUtils.getPerAppColorState(mContext)) {
// Reset all colors
Bitmap currentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
mCurrentCanvas = new Canvas(currentBitmap);
mCurrentCanvas.drawColor(0xFF000000);
BitmapDrawable currentBitmapDrawable = new BitmapDrawable(currentBitmap);
Bitmap newBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
mNewCanvas = new Canvas(newBitmap);
mNewCanvas.drawColor(0xFF000000);
BitmapDrawable newBitmapDrawable = new BitmapDrawable(newBitmap);
mTransition = new TransitionDrawable(new Drawable[] { currentBitmapDrawable, newBitmapDrawable });
mBarView.setBackground(mTransition);
mLastIconColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR);
updateIconColor();
updateBackgroundColor();
// Listen for status bar icon color changes
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.STATUS_ICON_COLOR), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
updateIconColor();
}
});
// Listen for status bar background color changes
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
updateBackgroundColor();
}
});
// Listen for per-app-color state changes, this one will revert to stock colors all over
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PER_APP_COLOR), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
if (!ColorUtils.getPerAppColorState(mContext)) {
for (int i = 0; i < ExtendedPropertiesUtils.PARANOID_COLORS_COUNT; i++) {
ColorUtils.ColorSettingInfo colorInfo = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
ColorUtils.setColor(mContext, ExtendedPropertiesUtils.PARANOID_COLORS_SETTINGS[i], colorInfo.systemColorString, "NULL", 1, 250);
}
}
}
});
}
attachPie();
// Listen for PIE gravity
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PIE_GRAVITY), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
updatePieControls();
}
});
// Listen for HALO state
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_ACTIVE), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
updateHalo();
}
});
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_SIZE), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
restartHalo();
}
});
updateHalo();
SettingsObserver settingsObserver = new SettingsObserver(new Handler());
settingsObserver.observe();
}
use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.
the class QuickSettings method queryForUserInformation.
private void queryForUserInformation() {
Context currentUserContext = null;
UserInfo userInfo = null;
try {
userInfo = ActivityManagerNative.getDefault().getCurrentUser();
currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
} catch (NameNotFoundException e) {
Log.e(TAG, "Couldn't create user context", e);
throw new RuntimeException(e);
} catch (RemoteException e) {
Log.e(TAG, "Couldn't get user info", e);
}
final int userId = userInfo.id;
final String userName = userInfo.name;
final Context context = currentUserContext;
mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
@Override
protected Pair<String, Drawable> doInBackground(Void... params) {
final UserManager um = UserManager.get(mContext);
// Fall back to the UserManager nickname if we can't read the name from the local
// profile below.
String name = userName;
Drawable avatar = null;
Bitmap rawAvatar = um.getUserIcon(userId);
if (rawAvatar != null) {
avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
} else {
avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
mUseDefaultAvatar = true;
}
// usually valid
if (um.getUsers().size() <= 1) {
// Try and read the display name from the local profile
final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
}
return new Pair<String, Drawable>(name, avatar);
}
@Override
protected void onPostExecute(Pair<String, Drawable> result) {
super.onPostExecute(result);
mModel.setUserTileInfo(result.first, result.second);
mUserInfoTask = null;
}
};
mUserInfoTask.execute();
}
use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.
the class NavigationBarView method getIcons.
private void getIcons(Resources res) {
mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land);
mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
mRecentsIcon = res.getDrawable(R.drawable.ic_sysbar_recent);
mRecentsLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_land);
mRecentsAltIcon = res.getDrawable(R.drawable.ic_sysbar_recent_clear);
mRecentsAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_clear_land);
// Only watch for per app color changes when the setting is in check
if (ColorUtils.getPerAppColorState(mContext)) {
// Reset all colors
mCurrentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
mCurrentCanvas = new Canvas(mCurrentBitmap);
mCurrentCanvas.drawColor(0xFF000000);
mCurrentBitmapDrawable = new BitmapDrawable(mCurrentBitmap);
mNewBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
mNewCanvas = new Canvas(mNewBitmap);
mNewCanvas.drawColor(0xFF000000);
mNewBitmapDrawable = new BitmapDrawable(mNewBitmap);
mTransition = new TransitionDrawable(new Drawable[] { mCurrentBitmapDrawable, mNewBitmapDrawable });
setBackground(mTransition);
mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.NAV_BAR_COLOR);
updateColor();
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.NAV_BAR_COLOR), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
updateColor();
}
});
}
}
use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.
the class IconUtilities method createIconBitmap.
/**
* Returns a bitmap suitable for the all apps view. The bitmap will be a power
* of two sized ARGB_8888 bitmap that can be used as a gl texture.
*/
private Bitmap createIconBitmap(Drawable icon) {
int width = mIconWidth;
int height = mIconHeight;
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
painter.setIntrinsicHeight(height);
} else if (icon instanceof BitmapDrawable) {
// Ensure the bitmap has a density.
BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
Bitmap bitmap = bitmapDrawable.getBitmap();
if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
bitmapDrawable.setTargetDensity(mDisplayMetrics);
}
}
int sourceWidth = icon.getIntrinsicWidth();
int sourceHeight = icon.getIntrinsicHeight();
if (sourceWidth > 0 && sourceHeight > 0) {
// There are intrinsic sizes.
if (width < sourceWidth || height < sourceHeight) {
// It's too big, scale it down.
final float ratio = (float) sourceWidth / sourceHeight;
if (sourceWidth > sourceHeight) {
height = (int) (width / ratio);
} else if (sourceHeight > sourceWidth) {
width = (int) (height * ratio);
}
} else if (sourceWidth < width && sourceHeight < height) {
// It's small, use the size they gave us.
width = sourceWidth;
height = sourceHeight;
}
}
// no intrinsic size --> use default size
int textureWidth = mIconTextureWidth;
int textureHeight = mIconTextureHeight;
final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = mCanvas;
canvas.setBitmap(bitmap);
final int left = (textureWidth - width) / 2;
final int top = (textureHeight - height) / 2;
if (false) {
// draw a big box for the icon for debugging
canvas.drawColor(sColors[mColorIndex]);
if (++mColorIndex >= sColors.length)
mColorIndex = 0;
Paint debugPaint = new Paint();
debugPaint.setColor(0xffcccc00);
canvas.drawRect(left, top, left + width, top + height, debugPaint);
}
mOldBounds.set(icon.getBounds());
icon.setBounds(left, top, left + width, top + height);
icon.draw(canvas);
icon.setBounds(mOldBounds);
return bitmap;
}
Aggregations