mirror of
https://gitlab.com/neothefox/LayTray
synced 2026-03-23 21:54:54 +03:00
Added different icon shapes
This commit is contained in:
parent
e35de238e5
commit
da2acfb09c
@ -10,6 +10,9 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
@ -61,6 +64,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
Icon smallIcon = Icon.createWithBitmap(textAsBitmap(textIcon,
|
||||
Integer.parseInt(options.getString("textSize", "48")),
|
||||
options.getBoolean("textFakeBold", true),
|
||||
Integer.parseInt(options.getString("textMode", "0")),
|
||||
Color.WHITE));
|
||||
|
||||
indicator = new Notification.Builder(this)
|
||||
@ -74,11 +78,46 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
}
|
||||
|
||||
//Borrowed from Ted Hopp from StackOverflow
|
||||
public Bitmap textAsBitmap(String text, float textSize, boolean fakeBold, int textColor) {
|
||||
public Bitmap textAsBitmap(String text, float textSize, boolean fakeBold, int mode, int textColor) {
|
||||
Paint paint = new Paint(ANTI_ALIAS_FLAG);
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
|
||||
paint.setTextSize(textSize);
|
||||
paint.setFakeBoldText(fakeBold);
|
||||
paint.setColor(textColor);
|
||||
switch (mode)
|
||||
{
|
||||
case 1: {
|
||||
float baseline = -paint.ascent(); // ascent() is negative
|
||||
int width = 48;
|
||||
int height = 48;
|
||||
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(image);
|
||||
canvas.drawCircle(width / 2f, height / 2f, width / 2f, paint);
|
||||
paint.setAlpha(255);
|
||||
paint.setColor(Color.TRANSPARENT);
|
||||
paint.setTextSize(textSize);
|
||||
paint.setTextAlign(Paint.Align.CENTER);
|
||||
canvas.drawText(text, width / 2f, height / 2f + textSize / 2f, paint);
|
||||
return image;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
float baseline = -paint.ascent(); // ascent() is negative
|
||||
int width = 48;
|
||||
int height = 48;
|
||||
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(image);
|
||||
canvas.drawRoundRect(new RectF(0, 0, height, width), 5, 5, paint);
|
||||
paint.setAlpha(255);
|
||||
paint.setColor(Color.TRANSPARENT);
|
||||
paint.setTextSize(textSize);
|
||||
paint.setTextAlign(Paint.Align.CENTER);
|
||||
canvas.drawText(text, width / 2f, height / 2f + textSize / 2f, paint);
|
||||
return image;
|
||||
}
|
||||
|
||||
case 0:
|
||||
default:
|
||||
paint.setTextAlign(Paint.Align.LEFT);
|
||||
float baseline = -paint.ascent(); // ascent() is negative
|
||||
int width = (int) (paint.measureText(text) + 0.5f); // round
|
||||
@ -88,6 +127,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
canvas.drawText(text, 0, baseline, paint);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccessibilityEvent(AccessibilityEvent event) {
|
||||
@ -116,6 +156,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
options = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
updateNotification(lastToast);
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,6 +198,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
// updated to reflect the new value, per the Android Design
|
||||
// guidelines.
|
||||
bindPreferenceSummaryToValue(findPreference("notificationImportance"));
|
||||
bindPreferenceSummaryToValue(findPreference("textMode"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -27,6 +27,18 @@
|
||||
<item>-2</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_title_notification_mode">Notification shape</string>
|
||||
<string-array name="pref_notification_mode_list_titles">
|
||||
<item>Plain Text</item>
|
||||
<item>Text in circle</item>
|
||||
<item>Text in a square</item>
|
||||
</string-array>
|
||||
<string-array name="pref_notification_mode_list_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
|
||||
<!-- Example settings for Notifications -->
|
||||
|
||||
@ -11,6 +11,13 @@
|
||||
android:positiveButtonText="@null"
|
||||
android:title="@string/pref_title_notification_importance" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/pref_notification_mode_list_titles"
|
||||
android:entryValues="@array/pref_notification_mode_list_values"
|
||||
android:key="textMode"
|
||||
android:title="@string/pref_title_notification_mode" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="textFakeBold"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user