我正在为一个设备编写一个控件类,直到我需要将ARGB颜色转换为其格式.起初,我写了这个函数(有效):
private static int convertFormat(System.Drawing.Color c)
{
String all;
int a = (int)((float)c.A / 31.875);
if (a == 0)
a = 1;
all = a.ToString() + c.B.ToString("X").PadLeft(2, '0') + c.G.ToString("X").PadLeft(2, '0') + c.R.ToString("X").PadLeft(2, '0');
int num = int.Parse(all, System.Globalization.NumberStyles.AllowHexSpecifier);
return num;
}
Run Code Online (Sandbox Code Playgroud)
但它太丑了我想写一个更优雅的解决方案.所以我做了一些以获得正确的值,尝试0到50之间的所有组合.它工作,我最终得到了这个:
private static int convertFormatShifting(System.Drawing.Color c)
{
int alpha = (int)Math.Round((float)c.A / 31.875);
int a = Math.Max(alpha,1);
return (a << 24) | (c.B << 48) | (c.G << 40) | (c.R << 32);
}
Run Code Online (Sandbox Code Playgroud)
有效!
但是现在,我希望有人能够解释为什么这些是正确的变化值.
我不确定我做错了什么,通知是我喜欢它的方式,但我不能让它让手表振动,它显示为最小化.我想要实现的效果应该看起来像环聊通知,它会振动并全屏显示.这是我正在使用的代码(在手表上):
Intent actionIntent = new Intent(this, ConvActivity.class);
actionIntent.putExtra("num",num);
PendingIntent actionPendingIntent =
PendingIntent.getActivity(this, 0, actionIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Create the action
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.ic_launcher,"Reply"
, actionPendingIntent)
.build();
NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(body).setBigContentTitle(name);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(name)
.setContentText(body)
//.setContentIntent(viewPendingIntent)
//.addAction(R.drawable.ic_map,
// getString(R.string.map), mapPendingIntent)
.setStyle(bigStyle).setAutoCancel(true)
.addAction(R.drawable.ic_launcher,"Reply"
, actionPendingIntent);
if(pic != null)
notificationBuilder.setLargeIcon(BitmapFactory.decodeByteArray(pic,0,pic.length));
//.extend(new NotificationCompat.WearableExtender().addAction(action)) ;
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
// Issue the notification with notification manager.
notificationManager.notify(0, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)