1
0
mirror of https://gitlab.com/neothefox/LayTray synced 2026-03-23 13:44:53 +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
{
int mode;
int textSize;
boolean fakeBold;
int textColor;
private int mode;
private int textSize;
private boolean fakeBold;
private int textColor;
public IconBuilderPreview(Context context)
{
@ -47,11 +47,10 @@ public class IconBuilderPreview extends View
initValues();
}
public void initValues()
private void initValues()
{
textSize = 48 * 10;
fakeBold = true;
}
@Override

View File

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

View File

@ -31,9 +31,10 @@ import java.util.Map;
public class MainActivity extends AppCompatActivity
implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferences.OnSharedPreferenceChangeListener {
LinearLayout layoutLister;
SharedPreferences layouts;
public String TAG = "layiconActivity";
public final String TAG = "layiconActivity";
private LinearLayout layoutLister;
private SharedPreferences layouts;
@Override
protected void onCreate(Bundle savedInstanceState)
@ -65,7 +66,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
}
}
protected void updateLayouts()
private void updateLayouts()
{
layoutLister.removeAllViewsInLayout();
@ -81,7 +82,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
entry.getValue().toString());
i++;
if(entry.getKey() != "EMPT")
if(!entry.getKey().equals("EMPT"))
addLine(layoutLister, entry.getKey(), entry.getValue().toString());
}
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");
SharedPreferences.Editor layoutsEditor = layouts.edit();
@ -100,10 +101,10 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
layoutsEditor.putString("Русский", "RU");
layoutsEditor.putString("Буквы (АБВ)", "EN");
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());
layoutLine.setOrientation(LinearLayout.HORIZONTAL);
@ -147,7 +148,7 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
parent.addView(layoutLine);
}
protected void saveLayouts(LinearLayout parent)
private void saveLayouts(LinearLayout parent)
{
int count = parent.getChildCount();
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);
String layoutNameValue = layoutName.getText().toString();
String layoutIconValue = layoutIcon.getText().toString();
if(layoutNameValue != "")
if(!layoutNameValue.equals(""))
{
if(layoutIconValue != "")
if(!layoutIconValue.equals(""))
layoutsEditor.putString(layoutNameValue, layoutIconValue);
else
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
* 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
@ -46,10 +47,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
public boolean onPreferenceChange(Preference preference, Object value)
{
String stringValue = value.toString();
if (preference instanceof ListPreference) {
if (preference instanceof ListPreference)
{
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
@ -61,7 +64,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
? listPreference.getEntries()[index]
: null);
} else {
}
else
{
// For all other preferences, set the summary to the value's
// simple string representation.
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
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
private static boolean isXLargeTablet(Context context)
{
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
@ -88,7 +94,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
private static void bindPreferenceSummaryToValue(Preference preference)
{
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
@ -101,7 +108,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setupActionBar();
}
@ -109,19 +117,24 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
private void setupActionBar() {
private void setupActionBar()
{
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
if (actionBar != null)
{
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
int id = item.getItemId();
if (id == android.R.id.home) {
if (!super.onMenuItemSelected(featureId, item)) {
if (id == android.R.id.home)
{
if (!super.onMenuItemSelected(featureId, item))
{
NavUtils.navigateUpFromSameTask(this);
}
return true;
@ -133,7 +146,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* {@inheritDoc}
*/
@Override
public boolean onIsMultiPane() {
public boolean onIsMultiPane()
{
return isXLargeTablet(this);
}
@ -142,7 +156,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
*/
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onBuildHeaders(List<Header> target) {
public void onBuildHeaders(List<Header> target)
{
loadHeadersFromResource(R.xml.pref_headers, target);
}
@ -150,7 +165,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* This method stops fragment injection in malicious applications.
* Make sure to deny any unknown fragments here.
*/
protected boolean isValidFragment(String fragmentName) {
protected boolean isValidFragment(String fragmentName)
{
return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.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.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class GeneralPreferenceFragment extends PreferenceFragment {
public static class GeneralPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
setHasOptionsMenu(true);
@ -176,9 +194,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == android.R.id.home) {
if (id == android.R.id.home)
{
startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
}
@ -191,9 +211,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class NotificationPreferenceFragment extends PreferenceFragment {
public static class NotificationPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_notification);
setHasOptionsMenu(true);
@ -204,15 +226,18 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
// guidelines.
//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");
PreferenceGroup parent = notificationImportance.getParent();
parent.removePreference(notificationImportance);
Preference notificationImportanceOreo = new Preference(parent.getContext());
notificationImportanceOreo.setTitle(R.string.pref_title_notification_importance);
notificationImportanceOreo.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
notificationImportanceOreo.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(Preference preference)
{
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, "space.neothefox.laytray");
intent.putExtra(Settings.EXTRA_CHANNEL_ID, IconService.channelId);
@ -242,7 +267,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
@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;
VerticalSeekBar yBar;
@ -254,18 +280,18 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_icon_builder, container);
return view;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_icon_builder, container);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
xBar = getView().findViewById(R.id.horSeekBar);
@ -282,8 +308,10 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
@Override
public void onClick(View v) {
switch (v.getId()) {
public void onClick(View v)
{
switch (v.getId())
{
case R.id.saveButton:
return;
case R.id.closeButton:
@ -294,9 +322,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == android.R.id.home) {
if (id == android.R.id.home)
{
startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
}

View File

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

View File

@ -43,19 +43,10 @@
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:clickable="true"
android:focusable="true"
app:backgroundTint="?attr/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
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>