use of android.graphics.drawable.Drawable in project android_frameworks_base by ParanoidAndroid.
the class MipmapDrawableTest method testSizes.
public void testSizes() {
// Check default value with no mipmap defined
assertEquals(-1, mMipmapDrawable.getIntrinsicHeight());
assertEquals(-1, mMipmapDrawable.getIntrinsicWidth());
assertEquals(0, mMipmapDrawable.getMinimumHeight());
assertEquals(0, mMipmapDrawable.getMinimumWidth());
Drawable small = new MockDrawable(8, 4);
Drawable medium = new MockDrawable(32, 16);
Drawable large = new MockDrawable(128, 64);
mMipmapDrawable.addDrawable(medium);
assertEquals(medium.getIntrinsicHeight(), mMipmapDrawable.getIntrinsicHeight());
assertEquals(medium.getMinimumHeight(), mMipmapDrawable.getMinimumHeight());
mMipmapDrawable.addDrawable(large);
assertEquals(large.getIntrinsicHeight(), mMipmapDrawable.getIntrinsicHeight());
assertEquals(medium.getMinimumHeight(), mMipmapDrawable.getMinimumHeight());
mMipmapDrawable.addDrawable(small);
assertEquals(large.getIntrinsicHeight(), mMipmapDrawable.getIntrinsicHeight());
assertEquals(small.getMinimumHeight(), mMipmapDrawable.getMinimumHeight());
}
use of android.graphics.drawable.Drawable in project android_frameworks_base by ParanoidAndroid.
the class RecentTasksLoader method loadThumbnailAndIcon.
void loadThumbnailAndIcon(TaskDescription td) {
final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
final PackageManager pm = mContext.getPackageManager();
Bitmap thumbnail = am.getTaskTopThumbnail(td.persistentTaskId);
Drawable icon = getFullResIcon(td.resolveInfo, pm);
if (DEBUG)
Log.v(TAG, "Loaded bitmap for task " + td + ": " + thumbnail);
synchronized (td) {
if (thumbnail != null) {
td.setThumbnail(thumbnail);
} else {
td.setThumbnail(mDefaultThumbnailBackground);
}
if (icon != null) {
td.setIcon(icon);
}
td.setLoaded(true);
}
}
use of android.graphics.drawable.Drawable 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.Drawable 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.Drawable in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method prepareHaloNotification.
public void prepareHaloNotification(NotificationData.Entry entry, StatusBarNotification notification, boolean update) {
Notification notif = notification.getNotification();
// Get the remote view
try {
if (!update) {
ViewGroup mainView = (ViewGroup) notif.contentView.apply(mContext, null, mOnClickHandler);
if (mainView instanceof FrameLayout) {
entry.haloContent = mainView.getChildAt(1);
mainView.removeViewAt(1);
} else {
entry.haloContent = mainView;
}
} else {
notif.contentView.reapply(mContext, entry.haloContent, mOnClickHandler);
}
} catch (Exception e) {
// Non uniform content?
android.util.Log.d("PARANOID", " Non uniform content?");
}
// Construct the round icon
final float haloSize = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.HALO_SIZE, 1.0f);
int iconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
int smallIconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
int largeIconWidth = notif.largeIcon != null ? (int) (notif.largeIcon.getWidth() * haloSize) : 0;
int largeIconHeight = notif.largeIcon != null ? (int) (notif.largeIcon.getHeight() * haloSize) : 0;
Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(roundIcon);
canvas.drawARGB(0, 0, 0, 0);
// halo-bubble, we'll use that one and cut it round
if (notif.largeIcon != null && largeIconWidth >= iconSize / 2) {
Paint smoothingPaint = new Paint();
smoothingPaint.setAntiAlias(true);
smoothingPaint.setFilterBitmap(true);
smoothingPaint.setDither(true);
canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
final int newWidth = iconSize;
final int newHeight = iconSize * largeIconWidth / largeIconHeight;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(notif.largeIcon, newWidth, newHeight, true);
canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, iconSize, iconSize), smoothingPaint);
} else {
try {
Drawable icon = StatusBarIconView.getIcon(mContext, new StatusBarIcon(notification.getPackageName(), notification.getUser(), notif.icon, notif.iconLevel, notif.number, notif.tickerText));
if (icon == null)
icon = mContext.getPackageManager().getApplicationIcon(notification.getPackageName());
int margin = (iconSize - smallIconSize) / 2;
icon.setBounds(margin, margin, iconSize - margin, iconSize - margin);
icon.draw(canvas);
} catch (Exception e) {
// NameNotFoundException
}
}
entry.roundIcon = roundIcon;
}
Aggregations