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.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.graphics.PorterDuffXfermode;
|
||||||
|
import android.graphics.RectF;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -61,6 +64,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
|
|||||||
Icon smallIcon = Icon.createWithBitmap(textAsBitmap(textIcon,
|
Icon smallIcon = Icon.createWithBitmap(textAsBitmap(textIcon,
|
||||||
Integer.parseInt(options.getString("textSize", "48")),
|
Integer.parseInt(options.getString("textSize", "48")),
|
||||||
options.getBoolean("textFakeBold", true),
|
options.getBoolean("textFakeBold", true),
|
||||||
|
Integer.parseInt(options.getString("textMode", "0")),
|
||||||
Color.WHITE));
|
Color.WHITE));
|
||||||
|
|
||||||
indicator = new Notification.Builder(this)
|
indicator = new Notification.Builder(this)
|
||||||
@ -74,19 +78,55 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Borrowed from Ted Hopp from StackOverflow
|
//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 paint = new Paint(ANTI_ALIAS_FLAG);
|
||||||
|
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
|
||||||
paint.setTextSize(textSize);
|
paint.setTextSize(textSize);
|
||||||
paint.setFakeBoldText(fakeBold);
|
paint.setFakeBoldText(fakeBold);
|
||||||
paint.setColor(textColor);
|
paint.setColor(textColor);
|
||||||
paint.setTextAlign(Paint.Align.LEFT);
|
switch (mode)
|
||||||
float baseline = -paint.ascent(); // ascent() is negative
|
{
|
||||||
int width = (int) (paint.measureText(text) + 0.5f); // round
|
case 1: {
|
||||||
int height = (int) (baseline + paint.descent() + 0.5f);
|
float baseline = -paint.ascent(); // ascent() is negative
|
||||||
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
int width = 48;
|
||||||
Canvas canvas = new Canvas(image);
|
int height = 48;
|
||||||
canvas.drawText(text, 0, baseline, paint);
|
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
return image;
|
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
|
||||||
|
int height = (int) (baseline + paint.descent() + 0.5f);
|
||||||
|
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas(image);
|
||||||
|
canvas.drawText(text, 0, baseline, paint);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,6 +156,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
options = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
updateNotification(lastToast);
|
updateNotification(lastToast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -198,6 +198,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||||||
// updated to reflect the new value, per the Android Design
|
// updated to reflect the new value, per the Android Design
|
||||||
// guidelines.
|
// guidelines.
|
||||||
bindPreferenceSummaryToValue(findPreference("notificationImportance"));
|
bindPreferenceSummaryToValue(findPreference("notificationImportance"));
|
||||||
|
bindPreferenceSummaryToValue(findPreference("textMode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -27,6 +27,18 @@
|
|||||||
<item>-2</item>
|
<item>-2</item>
|
||||||
</string-array>
|
</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 -->
|
<!-- Example settings for Notifications -->
|
||||||
|
|||||||
@ -11,6 +11,13 @@
|
|||||||
android:positiveButtonText="@null"
|
android:positiveButtonText="@null"
|
||||||
android:title="@string/pref_title_notification_importance" />
|
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
|
<SwitchPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="textFakeBold"
|
android:key="textFakeBold"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user