1
0
mirror of https://gitlab.com/neothefox/LayTray synced 2026-03-23 13:44:53 +03:00

Code cleanup and consistency

This commit is contained in:
NeoTheFox 2018-07-28 15:52:37 +03:00
parent 7de80ab3ec
commit 9f6332f9b4
6 changed files with 127 additions and 67 deletions

View File

@ -3,10 +3,12 @@ package space.neothefox.laytray;
import android.app.Activity;
import android.os.Bundle;
public class AboutActivity extends Activity {
public class AboutActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
}

View File

@ -16,19 +16,22 @@ import android.view.ViewGroup;
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
* to be used with AppCompat.
*/
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
public abstract class AppCompatPreferenceActivity extends PreferenceActivity
{
private AppCompatDelegate mDelegate;
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState)
{
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
protected void onPostCreate(Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
@ -37,17 +40,20 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
return getDelegate().getSupportActionBar();
}
public void setSupportActionBar(@Nullable Toolbar toolbar) {
public void setSupportActionBar(@Nullable Toolbar toolbar)
{
getDelegate().setSupportActionBar(toolbar);
}
@Override
public MenuInflater getMenuInflater() {
public MenuInflater getMenuInflater()
{
return getDelegate().getMenuInflater();
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
public void setContentView(@LayoutRes int layoutResID)
{
getDelegate().setContentView(layoutResID);
}
@ -57,51 +63,61 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
public void setContentView(View view, ViewGroup.LayoutParams params)
{
getDelegate().setContentView(view, params);
}
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
public void addContentView(View view, ViewGroup.LayoutParams params)
{
getDelegate().addContentView(view, params);
}
@Override
protected void onPostResume() {
protected void onPostResume()
{
super.onPostResume();
getDelegate().onPostResume();
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
protected void onTitleChanged(CharSequence title, int color)
{
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
@Override
protected void onStop() {
protected void onStop()
{
super.onStop();
getDelegate().onStop();
}
@Override
protected void onDestroy() {
protected void onDestroy()
{
super.onDestroy();
getDelegate().onDestroy();
}
public void invalidateOptionsMenu() {
public void invalidateOptionsMenu()
{
getDelegate().invalidateOptionsMenu();
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
private AppCompatDelegate getDelegate()
{
if (mDelegate == null)
{
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;

View File

@ -15,29 +15,34 @@ import android.widget.LinearLayout;
import static android.graphics.Paint.ANTI_ALIAS_FLAG;
public class IconBuilderPreview extends View {
public class IconBuilderPreview extends View
{
int mode;
int textSize;
boolean fakeBold;
int textColor;
public IconBuilderPreview(Context context) {
public IconBuilderPreview(Context context)
{
super(context);
initValues();
}
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs) {
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs)
{
super(context, attrs);
initValues();
}
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
initValues();
}
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)
{
super(context, attrs, defStyleAttr, defStyleRes);
initValues();
}
@ -50,7 +55,8 @@ public class IconBuilderPreview extends View {
}
@Override
protected void onDraw(Canvas canvas) {
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
mode = 2;
fakeBold = true;
@ -102,35 +108,43 @@ public class IconBuilderPreview extends View {
}
}
public int getMode() {
public int getMode()
{
return mode;
}
public int getTextSize() {
public int getTextSize()
{
return textSize;
}
public boolean isFakeBold() {
public boolean isFakeBold()
{
return fakeBold;
}
public int getTextColor() {
public int getTextColor()
{
return textColor;
}
public void setMode(int mode) {
public void setMode(int mode)
{
this.mode = mode;
}
public void setTextSize(int textSize) {
public void setTextSize(int textSize)
{
this.textSize = textSize * 10;
}
public void setFakeBold(boolean fakeBold) {
public void setFakeBold(boolean fakeBold)
{
this.fakeBold = fakeBold;
}
public void setTextColor(int textColor) {
public void setTextColor(int textColor)
{
this.textColor = textColor;
}
}

View File

@ -24,7 +24,8 @@ import static android.graphics.Paint.ANTI_ALIAS_FLAG;
public class IconService extends AccessibilityService
implements SharedPreferences.OnSharedPreferenceChangeListener{
implements SharedPreferences.OnSharedPreferenceChangeListener
{
public static String TAG = "layicon";
public static String channelId = "space.neothefox.laytray.IC";
@ -38,7 +39,8 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
NotificationChannel iconChannel;
@Override
protected void onServiceConnected() {
protected void onServiceConnected()
{
super.onServiceConnected();
Log.d(TAG, "Icon service started");
serviceInfo.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
@ -52,7 +54,8 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
options.registerOnSharedPreferenceChangeListener(this);
iconManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
iconChannel = iconManager.getNotificationChannel(channelId);
if(iconChannel == null) {
@ -95,7 +98,8 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
.setVisibility(Notification.VISIBILITY_SECRET)
.build();
}
else {
else
{
indicator = new Notification.Builder(this)
.setSmallIcon(smallIcon)
.setContentTitle(toast)
@ -109,7 +113,8 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
}
//Borrowed from Ted Hopp from StackOverflow
public static Bitmap textAsBitmap(String text, float textSize, boolean fakeBold, int mode, int textColor) {
public static 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);
@ -175,7 +180,8 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
public void onAccessibilityEvent(AccessibilityEvent event)
{
Log.d(TAG, event.toString());
if(event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
@ -188,19 +194,18 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
updateNotification(lastToast);
}
else
{
Log.d(TAG, "Caution! This service had been tampered with!");
}
}
@Override
public void onInterrupt() {
public void onInterrupt()
{
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
options = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
updateNotification(lastToast);
}

View File

@ -36,7 +36,8 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
public String TAG = "layiconActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layoutLister = findViewById(R.id.scrollLinearLayout);
@ -47,7 +48,8 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
addButton.setOnClickListener(this);
layouts.registerOnSharedPreferenceChangeListener(this);
if (!isAccessibilitySettingsOn(getApplicationContext())) {
if (!isAccessibilitySettingsOn(getApplicationContext()))
{
Toast.makeText(this, R.string.toast_enableme,
Toast.LENGTH_LONG).show();
startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
@ -73,7 +75,8 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
{
Log.d(TAG, "listing map:");
int i = 0;
for(Map.Entry<String,?> entry : keys.entrySet()){
for(Map.Entry<String,?> entry : keys.entrySet())
{
Log.d("map values",entry.getKey() + ": " +
entry.getValue().toString());
i++;
@ -128,9 +131,11 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
removeButton.setText("");
removeButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
removeButton.setOnClickListener(new View.OnClickListener() {
removeButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
public void onClick(View v)
{
LinearLayout daddy = (LinearLayout)removeButton.getParent();
LinearLayout grandpa = (LinearLayout)daddy.getParent();
daddy.removeAllViewsInLayout();
@ -171,46 +176,55 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
//Accessibility check by Antoine Bolvy
private boolean isAccessibilitySettingsOn(Context mContext) {
private boolean isAccessibilitySettingsOn(Context mContext)
{
int accessibilityEnabled = 0;
final String service = getPackageName() + "/" + IconService.class.getCanonicalName();
try {
try
{
accessibilityEnabled = Settings.Secure.getInt(
mContext.getApplicationContext().getContentResolver(),
android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
} catch (Settings.SettingNotFoundException e) {
}
catch (Settings.SettingNotFoundException e)
{
Log.e(TAG, "Error finding setting, default accessibility to not found: "
+ e.getMessage());
}
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
if (accessibilityEnabled == 1) {
if (accessibilityEnabled == 1)
{
Log.v(TAG, "Accessibility service enabled");
String settingValue = Settings.Secure.getString(
mContext.getApplicationContext().getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if (settingValue != null) {
if (settingValue != null)
{
mStringColonSplitter.setString(settingValue);
while (mStringColonSplitter.hasNext()) {
while (mStringColonSplitter.hasNext())
{
String accessibilityService = mStringColonSplitter.next();
Log.v(TAG, "-------------- > accessibilityService :: " + accessibilityService + " " + service);
if (accessibilityService.equalsIgnoreCase(service)) {
if (accessibilityService.equalsIgnoreCase(service))
{
Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
return true;
}
}
}
} else {
Log.v(TAG, "Accessibility is disabled");
}
else
Log.v(TAG, "Accessibility is disabled");
return false;
}
@Override
public void onClick(View v) {
public void onClick(View v)
{
switch(v.getId())
{
case R.id.floatingActionButton:
@ -221,14 +235,16 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.settings:
@ -243,22 +259,28 @@ implements View.OnClickListener, DialogInterface.OnClickListener, SharedPreferen
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
layouts = getSharedPreferences("layouts", 0);
updateLayouts();
}
private boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
private boolean isPackageInstalled(String packageName, PackageManager packageManager)
{
try
{
packageManager.getPackageInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
catch (PackageManager.NameNotFoundException e)
{
return false;
}
}
@Override
public void onClick(DialogInterface dialogInterface, int i) {
public void onClick(DialogInterface dialogInterface, int i)
{
//There is only one potential dialog
this.finish();
}

View File

@ -2,11 +2,12 @@ package space.neothefox.laytray;
import android.content.Context;
import android.graphics.Canvas;
import android.support.v7.widget.AppCompatSeekBar;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;
public class VerticalSeekBar extends SeekBar {
public class VerticalSeekBar extends AppCompatSeekBar
{
public VerticalSeekBar(Context context) {
super(context);