mirror of
https://gitlab.com/neothefox/LayTray
synced 2026-03-23 21:54:54 +03:00
Ability to select an Icon instead of text.
This commit is contained in:
parent
9c62b6a457
commit
8167c776d7
@ -8,6 +8,7 @@ import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
@ -33,6 +34,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
private final AccessibilityServiceInfo serviceInfo = new AccessibilityServiceInfo();
|
||||
|
||||
private SharedPreferences layouts;
|
||||
private SharedPreferences iconsPrefs;
|
||||
private SharedPreferences options;
|
||||
private String lastToast;
|
||||
|
||||
@ -50,6 +52,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
serviceInfo.notificationTimeout = 100;
|
||||
this.setServiceInfo(serviceInfo);
|
||||
layouts = getSharedPreferences("layouts", 0);
|
||||
iconsPrefs = getSharedPreferences("icons", 0);
|
||||
options = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
lastToast = "EMPT";
|
||||
options.registerOnSharedPreferenceChangeListener(this);
|
||||
@ -90,11 +93,20 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
layoutsEditor.apply();
|
||||
textIcon = "??";
|
||||
}
|
||||
Icon smallIcon = Icon.createWithBitmap(textAsBitmap(textIcon,
|
||||
Integer.parseInt(options.getString("textSize", "48")),
|
||||
options.getBoolean("textFakeBold", true),
|
||||
Integer.parseInt(options.getString("textMode", "0")),
|
||||
Color.WHITE));
|
||||
|
||||
Icon smallIcon;
|
||||
|
||||
if (Integer.parseInt(options.getString("textMode", "0")) == 4) {
|
||||
// Icon selected
|
||||
smallIcon = Icon.createWithResource(this, iconsPrefs.getInt(toast, R.drawable.ic_language_default));
|
||||
} else {
|
||||
// Text variations
|
||||
smallIcon = Icon.createWithBitmap(textAsBitmap(textIcon,
|
||||
Integer.parseInt(options.getString("textSize", "48")),
|
||||
options.getBoolean("textFakeBold", true),
|
||||
Integer.parseInt(options.getString("textMode", "0")),
|
||||
Color.WHITE));
|
||||
}
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
{
|
||||
@ -104,6 +116,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
.setOngoing(true)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.build();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
56
app/src/main/java/space/neothefox/laytray/IconsAdapter.java
Normal file
56
app/src/main/java/space/neothefox/laytray/IconsAdapter.java
Normal file
@ -0,0 +1,56 @@
|
||||
package space.neothefox.laytray;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
public class IconsAdapter extends BaseAdapter {
|
||||
private Context context;
|
||||
private int flags[];
|
||||
private LayoutInflater inflter;
|
||||
|
||||
public IconsAdapter(Context applicationContext, int[] flags) {
|
||||
this.context = applicationContext;
|
||||
this.flags = flags;
|
||||
inflter = (LayoutInflater.from(applicationContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return flags.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return flags[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getPosition(int value) {
|
||||
int position = -1;
|
||||
for (int i = 0; i < flags.length; i++) {
|
||||
if (value == flags[i]) {
|
||||
position = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View convertView, ViewGroup parent) {
|
||||
convertView = inflter.inflate(R.layout.spinner_item, null);
|
||||
ImageView icon = (ImageView) convertView.findViewById(R.id.imageView);
|
||||
icon.setImageResource(flags[i]);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
@ -19,13 +19,14 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Space;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
@ -35,6 +36,8 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
|
||||
|
||||
private LinearLayout layoutLister;
|
||||
private SharedPreferences layouts;
|
||||
private SharedPreferences iconsPrefs;
|
||||
private boolean shouldRefresh = true;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
@ -43,6 +46,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
|
||||
setContentView(R.layout.activity_main);
|
||||
layoutLister = findViewById(R.id.scrollLinearLayout);
|
||||
layouts = getSharedPreferences("layouts", 0);
|
||||
iconsPrefs = getSharedPreferences("icons", 0);
|
||||
updateLayouts();
|
||||
|
||||
FloatingActionButton addButton = findViewById(R.id.floatingActionButton);
|
||||
@ -82,8 +86,13 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
|
||||
entry.getValue().toString());
|
||||
i++;
|
||||
|
||||
if(!entry.getKey().equals("EMPT"))
|
||||
addLine(layoutLister, entry.getKey(), entry.getValue().toString());
|
||||
if(!entry.getKey().equals("EMPT")) {
|
||||
addLine(
|
||||
layoutLister, entry.getKey(),
|
||||
entry.getValue().toString(),
|
||||
iconsPrefs.getInt(entry.getKey(), R.drawable.ic_language_default)
|
||||
);
|
||||
}
|
||||
}
|
||||
if(i == 0)
|
||||
populateLayouts();
|
||||
@ -97,14 +106,20 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
|
||||
{
|
||||
Log.d("map values", "Shared Prefs are empty");
|
||||
SharedPreferences.Editor layoutsEditor = layouts.edit();
|
||||
SharedPreferences.Editor iconsEditor = iconsPrefs.edit();
|
||||
iconsEditor.clear();
|
||||
layoutsEditor.clear();
|
||||
layoutsEditor.putString("Русский", "RU");
|
||||
layoutsEditor.putString("Буквы (АБВ)", "EN");
|
||||
layoutsEditor.putString("EMPT", "??");
|
||||
|
||||
shouldRefresh = false;
|
||||
iconsEditor.apply();
|
||||
shouldRefresh = true;
|
||||
layoutsEditor.apply();
|
||||
}
|
||||
|
||||
private void addLine(LinearLayout parent, String name, String icon)
|
||||
private void addLine(LinearLayout parent, String name, String icon, int iconDrawableId)
|
||||
{
|
||||
final LinearLayout layoutLine = new LinearLayout(getApplicationContext());
|
||||
layoutLine.setOrientation(LinearLayout.HORIZONTAL);
|
||||
@ -123,11 +138,29 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
|
||||
layoutIcon.setText(icon);
|
||||
layoutLine.addView(layoutIcon);
|
||||
|
||||
|
||||
// Icons Dropdown
|
||||
final int[] iconFlags = {
|
||||
R.drawable.ic_language_default,
|
||||
R.drawable.ic_flag_russia,
|
||||
R.drawable.ic_flag_gb,
|
||||
R.drawable.ic_flag_belarus,
|
||||
R.drawable.ic_flag_ukr
|
||||
};
|
||||
IconsAdapter arrayAdapter = new IconsAdapter(this, iconFlags);
|
||||
final Spinner iconSpinner = new Spinner(this);
|
||||
iconSpinner.setAdapter(arrayAdapter);
|
||||
iconSpinner.setSelection(arrayAdapter.getPosition(iconDrawableId));
|
||||
layoutLine.addView(iconSpinner);
|
||||
iconSpinner.setSelection(arrayAdapter.getPosition(iconDrawableId));
|
||||
|
||||
|
||||
Space space = new Space(getApplicationContext());
|
||||
space.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, 2));
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, 2));
|
||||
layoutLine.addView(space);
|
||||
|
||||
|
||||
final Button removeButton = new Button(getApplicationContext());
|
||||
removeButton.setText("➖");
|
||||
removeButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
@ -155,23 +188,35 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
|
||||
if (count != 0)
|
||||
{
|
||||
SharedPreferences.Editor layoutsEditor = layouts.edit();
|
||||
SharedPreferences.Editor iconsEditor = iconsPrefs.edit();
|
||||
layoutsEditor.clear();
|
||||
iconsEditor.clear();
|
||||
for (int i=0; i < count; i++)
|
||||
{
|
||||
LinearLayout layoutLine = (LinearLayout)parent.getChildAt(i);
|
||||
TextView layoutName = (TextView)layoutLine.getChildAt(0);
|
||||
EditText layoutIcon = (EditText)layoutLine.getChildAt(1);
|
||||
Spinner layoutDropdown = (Spinner)layoutLine.getChildAt(2);
|
||||
String layoutNameValue = layoutName.getText().toString();
|
||||
String layoutIconValue = layoutIcon.getText().toString();
|
||||
int layoutDropdownValue = (int)layoutDropdown.getSelectedItem();
|
||||
if(!layoutNameValue.equals(""))
|
||||
{
|
||||
if(!layoutIconValue.equals(""))
|
||||
if(!layoutIconValue.equals("")) {
|
||||
layoutsEditor.putString(layoutNameValue, layoutIconValue);
|
||||
else
|
||||
iconsEditor.putInt(layoutNameValue, layoutDropdownValue);
|
||||
} else {
|
||||
layoutsEditor.putString(layoutNameValue, "??");
|
||||
iconsEditor.putInt(layoutNameValue, layoutDropdownValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
shouldRefresh = false;
|
||||
iconsEditor.apply();
|
||||
shouldRefresh = true;
|
||||
layoutsEditor.apply();
|
||||
} else {
|
||||
populateLayouts();
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,8 +309,11 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||
{
|
||||
layouts = getSharedPreferences("layouts", 0);
|
||||
updateLayouts();
|
||||
if (shouldRefresh) {
|
||||
layouts = getSharedPreferences("layouts", 0);
|
||||
iconsPrefs = getSharedPreferences("icons", 0);
|
||||
updateLayouts();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPackageInstalled(String packageName, PackageManager packageManager)
|
||||
|
||||
6
app/src/main/res/drawable/ic_flag_belarus.xml
Normal file
6
app/src/main/res/drawable/ic_flag_belarus.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<vector android:height="24dp" android:viewportHeight="2"
|
||||
android:viewportWidth="3" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#66000000" android:pathData="M0,1h3v0.75h-3z"/>
|
||||
<path android:fillColor="#99000000" android:pathData="M0,0h3v1h-3z"/>
|
||||
<path android:fillColor="#FF000000" android:pathData="M0,0h0.5v1.75h-3z"/>
|
||||
</vector>
|
||||
5
app/src/main/res/drawable/ic_flag_gb.xml
Normal file
5
app/src/main/res/drawable/ic_flag_gb.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="32dp" android:viewportHeight="25.1"
|
||||
android:viewportWidth="40.9" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M18,0h5v10h18v5H23.1a3,3 0,0 0,-0.3 0,0.6 0.6,0 0,0 0,0.2v9.9H18V15H0v-5h18a1,1 0,0 0,0 -0.1z"/>
|
||||
<path android:fillColor="#99000000" android:pathData="M15.6,0v7a1.4,1.4 0,0 1,-0.3 -0.1L4.3,0.2 4.2,0zM36.7,0a2.8,2.8 0,0 1,-0.3 0.2L25.7,6.8l-0.4,0.3L25.3,0zM4.2,25a2,2 0,0 1,0.3 -0.1l10.8,-6.7 0.3,-0.2v7zM25.3,25v-6.9l0.3,0.1 10.9,6.7a1.6,1.6 0,0 1,0.2 0.2zM0,2.2l0.3,0.1 8.3,5.1v0.2L0,7.6zM41,7.6h-8.8l0.3,-0.2 8,-5a4,4 0,0 1,0.4 -0.2zM0,17.5h8.7a2.6,2.6 0,0 1,-0.2 0.2l-8.1,5a2.3,2.3 0,0 1,-0.4 0.2zM41,22.9a1.4,1.4 0,0 1,-0.3 -0.1l-8.3,-5.1 -0.1,-0.2h8.6z"/>
|
||||
</vector>
|
||||
6
app/src/main/res/drawable/ic_flag_russia.xml
Normal file
6
app/src/main/res/drawable/ic_flag_russia.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<vector android:height="24dp" android:viewportHeight="512.001"
|
||||
android:viewportWidth="512.001" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M512,200.093H0V97.104c0,-4.875 3.953,-8.828 8.828,-8.828h494.345c4.875,0 8.828,3.953 8.828,8.828L512,200.093L512,200.093z"/>
|
||||
<path android:fillColor="#88000000" android:pathData="M503.172,423.725H8.828c-4.875,0 -8.828,-3.953 -8.828,-8.828V311.909h512v102.988C512,419.773 508.047,423.725 503.172,423.725z"/>
|
||||
<path android:fillColor="#22000000" android:pathData="M0,200.091h512v111.81h-512z"/>
|
||||
</vector>
|
||||
5
app/src/main/res/drawable/ic_flag_ukr.xml
Normal file
5
app/src/main/res/drawable/ic_flag_ukr.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="2"
|
||||
android:viewportWidth="3" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#88000000" android:pathData="M0,1h3v1h-3z"/>
|
||||
<path android:fillColor="#FF000000" android:pathData="M0,0h3v1h-3z"/>
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_language_default.xml
Normal file
9
app/src/main/res/drawable/ic_language_default.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/>
|
||||
</vector>
|
||||
24
app/src/main/res/layout/spinner_item.xml
Normal file
24
app/src/main/res/layout/spinner_item.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/ic_info_black_24dp" />
|
||||
|
||||
<!--
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="0dp"
|
||||
android:text="Icon"
|
||||
android:textColor="#000" />
|
||||
-->
|
||||
|
||||
</LinearLayout>
|
||||
@ -37,12 +37,14 @@
|
||||
<item>Тэкст у крузе</item>
|
||||
<item>Тэкст у квадраце</item>
|
||||
<item>Тэкст у квадраце з абрысам</item>
|
||||
<item>Іконка</item>
|
||||
</string-array>
|
||||
<string-array name="pref_notification_mode_list_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_title_icon_builder">Рэдактар іконак</string>
|
||||
|
||||
@ -42,12 +42,14 @@
|
||||
<item>Text v kruhu</item>
|
||||
<item>Text ve čtverci</item>
|
||||
<item>Text v obrysu čtverce</item>
|
||||
<item>Ikona</item>
|
||||
</string-array>
|
||||
<string-array name="pref_notification_mode_list_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_title_icon_builder">Vytváření ikony</string>
|
||||
|
||||
@ -37,12 +37,14 @@
|
||||
<item>Текст в круге</item>
|
||||
<item>Текст в квадрате</item>
|
||||
<item>Текст в квадрате с обводкой</item>
|
||||
<item>Иконка</item>
|
||||
</string-array>
|
||||
<string-array name="pref_notification_mode_list_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_title_icon_builder">Редактор иконок</string>
|
||||
|
||||
@ -43,12 +43,14 @@
|
||||
<item>Text in circle</item>
|
||||
<item>Text in a square</item>
|
||||
<item>Text in a square outline</item>
|
||||
<item>Icon</item>
|
||||
</string-array>
|
||||
<string-array name="pref_notification_mode_list_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_title_icon_builder">Icon builder</string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user