1
0
mirror of https://gitlab.com/neothefox/LayTray synced 2026-03-23 21:54:54 +03:00

Fixing small gotchas

This commit is contained in:
NeoTheFox 2018-07-28 16:19:10 +03:00
parent 4498c4716f
commit 0cd75e6760
6 changed files with 119 additions and 84 deletions

View File

@ -18,10 +18,10 @@ import static android.graphics.Paint.ANTI_ALIAS_FLAG;
public class IconBuilderPreview extends View public class IconBuilderPreview extends View
{ {
int mode; private int mode;
int textSize; private int textSize;
boolean fakeBold; private boolean fakeBold;
int textColor; private int textColor;
public IconBuilderPreview(Context context) public IconBuilderPreview(Context context)
{ {
@ -47,11 +47,10 @@ public class IconBuilderPreview extends View
initValues(); initValues();
} }
public void initValues() private void initValues()
{ {
textSize = 48 * 10; textSize = 48 * 10;
fakeBold = true; fakeBold = true;
} }
@Override @Override

View File

@ -23,20 +23,21 @@ import android.view.accessibility.AccessibilityEvent;
import static android.graphics.Paint.ANTI_ALIAS_FLAG; import static android.graphics.Paint.ANTI_ALIAS_FLAG;
@SuppressWarnings("SuspiciousNameCombination")
public class IconService extends AccessibilityService public class IconService extends AccessibilityService
implements SharedPreferences.OnSharedPreferenceChangeListener implements SharedPreferences.OnSharedPreferenceChangeListener
{ {
public static String TAG = "layicon"; public static final String TAG = "layicon";
public static String channelId = "space.neothefox.laytray.IC"; public static final String channelId = "space.neothefox.laytray.IC";
private final AccessibilityServiceInfo serviceInfo = new AccessibilityServiceInfo(); private final AccessibilityServiceInfo serviceInfo = new AccessibilityServiceInfo();
SharedPreferences layouts; private SharedPreferences layouts;
SharedPreferences options; private SharedPreferences options;
String lastToast; private String lastToast;
NotificationManager iconManager; private NotificationManager iconManager;
NotificationChannel iconChannel; private NotificationChannel iconChannel;
@Override @Override
protected void onServiceConnected() protected void onServiceConnected()
@ -56,8 +57,14 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
iconManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); iconManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{ {
try
{
iconChannel = iconManager.getNotificationChannel(channelId); iconChannel = iconManager.getNotificationChannel(channelId);
}
catch (NullPointerException e)
{
Log.d(TAG, "No NotificationChannel found");
}
if(iconChannel == null) { if(iconChannel == null) {
iconChannel = new NotificationChannel( iconChannel = new NotificationChannel(
channelId, channelId,
@ -72,15 +79,15 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
} }
} }
protected void updateNotification(String toast) private void updateNotification(String toast)
{ {
Notification indicator; Notification indicator;
String textIcon = layouts.getString(toast,"EMPT"); String textIcon = layouts.getString(toast,"EMPT");
if(textIcon == "EMPT") if(textIcon.equals("EMPT"))
{ {
SharedPreferences.Editor layoutsEditor = layouts.edit(); SharedPreferences.Editor layoutsEditor = layouts.edit();
layoutsEditor.putString(toast, "??"); layoutsEditor.putString(toast, "??");
layoutsEditor.commit(); layoutsEditor.apply();
textIcon = "??"; textIcon = "??";
} }
Icon smallIcon = Icon.createWithBitmap(textAsBitmap(textIcon, Icon smallIcon = Icon.createWithBitmap(textAsBitmap(textIcon,

View File

@ -31,9 +31,10 @@ import java.util.Map;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferences.OnSharedPreferenceChangeListener { implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferences.OnSharedPreferenceChangeListener {
LinearLayout layoutLister; public final String TAG = "layiconActivity";
SharedPreferences layouts;
public String TAG = "layiconActivity"; private LinearLayout layoutLister;
private SharedPreferences layouts;
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
@ -65,7 +66,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
} }
} }
protected void updateLayouts() private void updateLayouts()
{ {
layoutLister.removeAllViewsInLayout(); layoutLister.removeAllViewsInLayout();
@ -81,7 +82,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
entry.getValue().toString()); entry.getValue().toString());
i++; i++;
if(entry.getKey() != "EMPT") if(!entry.getKey().equals("EMPT"))
addLine(layoutLister, entry.getKey(), entry.getValue().toString()); addLine(layoutLister, entry.getKey(), entry.getValue().toString());
} }
if(i == 0) if(i == 0)
@ -92,7 +93,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
} }
protected void populateLayouts() private void populateLayouts()
{ {
Log.d("map values", "Shared Prefs are empty"); Log.d("map values", "Shared Prefs are empty");
SharedPreferences.Editor layoutsEditor = layouts.edit(); SharedPreferences.Editor layoutsEditor = layouts.edit();
@ -100,10 +101,10 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
layoutsEditor.putString("Русский", "RU"); layoutsEditor.putString("Русский", "RU");
layoutsEditor.putString("Буквы (АБВ)", "EN"); layoutsEditor.putString("Буквы (АБВ)", "EN");
layoutsEditor.putString("EMPT", "??"); layoutsEditor.putString("EMPT", "??");
layoutsEditor.commit(); layoutsEditor.apply();
} }
protected void addLine(LinearLayout parent, String name, String icon) private void addLine(LinearLayout parent, String name, String icon)
{ {
final LinearLayout layoutLine = new LinearLayout(getApplicationContext()); final LinearLayout layoutLine = new LinearLayout(getApplicationContext());
layoutLine.setOrientation(LinearLayout.HORIZONTAL); layoutLine.setOrientation(LinearLayout.HORIZONTAL);
@ -147,7 +148,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
parent.addView(layoutLine); parent.addView(layoutLine);
} }
protected void saveLayouts(LinearLayout parent) private void saveLayouts(LinearLayout parent)
{ {
int count = parent.getChildCount(); int count = parent.getChildCount();
Log.d(TAG, String.format("%d layouts to save", count)); Log.d(TAG, String.format("%d layouts to save", count));
@ -162,15 +163,15 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
EditText layoutIcon = (EditText)layoutLine.getChildAt(1); EditText layoutIcon = (EditText)layoutLine.getChildAt(1);
String layoutNameValue = layoutName.getText().toString(); String layoutNameValue = layoutName.getText().toString();
String layoutIconValue = layoutIcon.getText().toString(); String layoutIconValue = layoutIcon.getText().toString();
if(layoutNameValue != "") if(!layoutNameValue.equals(""))
{ {
if(layoutIconValue != "") if(!layoutIconValue.equals(""))
layoutsEditor.putString(layoutNameValue, layoutIconValue); layoutsEditor.putString(layoutNameValue, layoutIconValue);
else else
layoutsEditor.putString(layoutNameValue, "??"); layoutsEditor.putString(layoutNameValue, "??");
} }
} }
layoutsEditor.commit(); layoutsEditor.apply();
} }
} }

View File

@ -38,7 +38,8 @@ import java.util.List;
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings * href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI. * API Guide</a> for more information on developing a Settings UI.
*/ */
public class SettingsActivity extends AppCompatPreferenceActivity { public class SettingsActivity extends AppCompatPreferenceActivity
{
/** /**
* A preference value change listener that updates the preference's summary * A preference value change listener that updates the preference's summary
@ -46,10 +47,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
*/ */
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object value) { public boolean onPreferenceChange(Preference preference, Object value)
{
String stringValue = value.toString(); String stringValue = value.toString();
if (preference instanceof ListPreference) { if (preference instanceof ListPreference)
{
// For list preferences, look up the correct display value in // For list preferences, look up the correct display value in
// the preference's 'entries' list. // the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference; ListPreference listPreference = (ListPreference) preference;
@ -61,7 +64,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
? listPreference.getEntries()[index] ? listPreference.getEntries()[index]
: null); : null);
} else { }
else
{
// For all other preferences, set the summary to the value's // For all other preferences, set the summary to the value's
// simple string representation. // simple string representation.
preference.setSummary(stringValue); preference.setSummary(stringValue);
@ -74,7 +79,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* Helper method to determine if the device has an extra-large screen. For * Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large. * example, 10" tablets are extra-large.
*/ */
private static boolean isXLargeTablet(Context context) { private static boolean isXLargeTablet(Context context)
{
return (context.getResources().getConfiguration().screenLayout return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
} }
@ -88,7 +94,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* *
* @see #sBindPreferenceSummaryToValueListener * @see #sBindPreferenceSummaryToValueListener
*/ */
private static void bindPreferenceSummaryToValue(Preference preference) { private static void bindPreferenceSummaryToValue(Preference preference)
{
// Set the listener to watch for value changes. // Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
@ -101,7 +108,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setupActionBar(); setupActionBar();
} }
@ -109,19 +117,24 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
/** /**
* Set up the {@link android.app.ActionBar}, if the API is available. * Set up the {@link android.app.ActionBar}, if the API is available.
*/ */
private void setupActionBar() { private void setupActionBar()
{
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null)
{
// Show the Up button in the action bar. // Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
} }
} }
@Override @Override
public boolean onMenuItemSelected(int featureId, MenuItem item) { public boolean onMenuItemSelected(int featureId, MenuItem item)
{
int id = item.getItemId(); int id = item.getItemId();
if (id == android.R.id.home) { if (id == android.R.id.home)
if (!super.onMenuItemSelected(featureId, item)) { {
if (!super.onMenuItemSelected(featureId, item))
{
NavUtils.navigateUpFromSameTask(this); NavUtils.navigateUpFromSameTask(this);
} }
return true; return true;
@ -133,7 +146,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean onIsMultiPane() { public boolean onIsMultiPane()
{
return isXLargeTablet(this); return isXLargeTablet(this);
} }
@ -142,7 +156,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
*/ */
@Override @Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onBuildHeaders(List<Header> target) { public void onBuildHeaders(List<Header> target)
{
loadHeadersFromResource(R.xml.pref_headers, target); loadHeadersFromResource(R.xml.pref_headers, target);
} }
@ -150,7 +165,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* This method stops fragment injection in malicious applications. * This method stops fragment injection in malicious applications.
* Make sure to deny any unknown fragments here. * Make sure to deny any unknown fragments here.
*/ */
protected boolean isValidFragment(String fragmentName) { protected boolean isValidFragment(String fragmentName)
{
return PreferenceFragment.class.getName().equals(fragmentName) return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName)
|| NotificationPreferenceFragment.class.getName().equals(fragmentName); || NotificationPreferenceFragment.class.getName().equals(fragmentName);
@ -161,9 +177,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* activity is showing a two-pane settings UI. * activity is showing a two-pane settings UI.
*/ */
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class GeneralPreferenceFragment extends PreferenceFragment { public static class GeneralPreferenceFragment extends PreferenceFragment
{
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general); addPreferencesFromResource(R.xml.pref_general);
setHasOptionsMenu(true); setHasOptionsMenu(true);
@ -176,9 +194,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId(); int id = item.getItemId();
if (id == android.R.id.home) { if (id == android.R.id.home)
{
startActivity(new Intent(getActivity(), SettingsActivity.class)); startActivity(new Intent(getActivity(), SettingsActivity.class));
return true; return true;
} }
@ -191,9 +211,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* activity is showing a two-pane settings UI. * activity is showing a two-pane settings UI.
*/ */
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class NotificationPreferenceFragment extends PreferenceFragment { public static class NotificationPreferenceFragment extends PreferenceFragment
{
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_notification); addPreferencesFromResource(R.xml.pref_notification);
setHasOptionsMenu(true); setHasOptionsMenu(true);
@ -204,15 +226,18 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
// guidelines. // guidelines.
//With Oreo this setting should be set by the system dialog //With Oreo this setting should be set by the system dialog
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
Preference notificationImportance = getPreferenceScreen().findPreference("notificationImportance"); Preference notificationImportance = getPreferenceScreen().findPreference("notificationImportance");
PreferenceGroup parent = notificationImportance.getParent(); PreferenceGroup parent = notificationImportance.getParent();
parent.removePreference(notificationImportance); parent.removePreference(notificationImportance);
Preference notificationImportanceOreo = new Preference(parent.getContext()); Preference notificationImportanceOreo = new Preference(parent.getContext());
notificationImportanceOreo.setTitle(R.string.pref_title_notification_importance); notificationImportanceOreo.setTitle(R.string.pref_title_notification_importance);
notificationImportanceOreo.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { notificationImportanceOreo.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
{
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference)
{
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, "space.neothefox.laytray"); intent.putExtra(Settings.EXTRA_APP_PACKAGE, "space.neothefox.laytray");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, IconService.channelId); intent.putExtra(Settings.EXTRA_CHANNEL_ID, IconService.channelId);
@ -242,7 +267,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class IconBuilderPreferenceFragment extends DialogFragment implements View.OnClickListener { public static class IconBuilderPreferenceFragment extends DialogFragment implements View.OnClickListener
{
SeekBar xBar; SeekBar xBar;
VerticalSeekBar yBar; VerticalSeekBar yBar;
@ -254,18 +280,18 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.fragment_icon_builder, container); {
return view; return inflater.inflate(R.layout.fragment_icon_builder, container);
} }
@Override @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
xBar = getView().findViewById(R.id.horSeekBar); xBar = getView().findViewById(R.id.horSeekBar);
@ -282,8 +308,10 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
@Override @Override
public void onClick(View v) { public void onClick(View v)
switch (v.getId()) { {
switch (v.getId())
{
case R.id.saveButton: case R.id.saveButton:
return; return;
case R.id.closeButton: case R.id.closeButton:
@ -294,9 +322,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId(); int id = item.getItemId();
if (id == android.R.id.home) { if (id == android.R.id.home)
{
startActivity(new Intent(getActivity(), SettingsActivity.class)); startActivity(new Intent(getActivity(), SettingsActivity.class));
return true; return true;
} }

View File

@ -9,29 +9,35 @@ import android.view.MotionEvent;
public class VerticalSeekBar extends AppCompatSeekBar public class VerticalSeekBar extends AppCompatSeekBar
{ {
public VerticalSeekBar(Context context) { public VerticalSeekBar(Context context)
{
super(context); super(context);
} }
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) { public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle); super(context, attrs, defStyle);
} }
public VerticalSeekBar(Context context, AttributeSet attrs) { public VerticalSeekBar(Context context, AttributeSet attrs)
{
super(context, attrs); super(context, attrs);
} }
protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(h, w, oldh, oldw); super.onSizeChanged(h, w, oldh, oldw);
} }
@Override @Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(heightMeasureSpec, widthMeasureSpec); super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
} }
protected void onDraw(Canvas c) { protected void onDraw(Canvas c)
{
c.rotate(-90); c.rotate(-90);
c.translate(-getHeight(), 0); c.translate(-getHeight(), 0);
@ -39,12 +45,13 @@ public class VerticalSeekBar extends AppCompatSeekBar
} }
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event)
if (!isEnabled()) { {
if (!isEnabled())
return false; return false;
}
switch (event.getAction()) { switch (event.getAction())
{
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:

View File

@ -43,19 +43,10 @@
android:layout_marginBottom="24dp" android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:clickable="true" android:clickable="true"
android:focusable="true"
app:backgroundTint="?attr/colorPrimary" app:backgroundTint="?attr/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_menu_save" /> app:srcCompat="@android:drawable/ic_menu_save" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:text="by NeoTheFox"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>