commit 08b2370f471a4964b652f75dfcf43bac8bb7f4be Author: NeoTheFox Date: Thu Jul 5 23:39:32 2018 +0300 Initial commit - beta1 diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..e6cb14c --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "space.neothefox.laytray" + minSdkVersion 25 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + buildToolsVersion '28.0.1' +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.2' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.android.support:design:26.1.0' + implementation 'com.github.javadev:underscore:1.34' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0fb2e2a --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/space/neothefox/laytray/IconService.java b/app/src/main/java/space/neothefox/laytray/IconService.java new file mode 100644 index 0000000..39ad9e7 --- /dev/null +++ b/app/src/main/java/space/neothefox/laytray/IconService.java @@ -0,0 +1,109 @@ +package space.neothefox.laytray; + +import android.accessibilityservice.AccessibilityService; +import android.accessibilityservice.AccessibilityServiceInfo; +import android.app.Notification; +import android.app.NotificationManager; +import android.content.Context; +import android.content.SharedPreferences; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.drawable.Icon; +import android.util.Log; +import android.view.accessibility.AccessibilityEvent; + +import java.util.HashMap; +import java.util.Map; + +import static android.graphics.Paint.ANTI_ALIAS_FLAG; + + +public class IconService extends AccessibilityService +implements SharedPreferences.OnSharedPreferenceChangeListener{ + + public String TAG = "layicon"; + private final AccessibilityServiceInfo serviceInfo = new AccessibilityServiceInfo(); + //Map layoutText = new HashMap<>(); + + SharedPreferences layouts; + + NotificationManager iconManager; + + @Override + protected void onServiceConnected() { + super.onServiceConnected(); + Log.d(TAG, "Icon service started"); + serviceInfo.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; + serviceInfo.packageNames = new String[] {"com.blackberry.keyboard"}; + serviceInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_VISUAL; + serviceInfo.notificationTimeout = 100; + this.setServiceInfo(serviceInfo); + layouts = getSharedPreferences("layouts", 0); + + iconManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + //layoutText.put("Русский", "RU"); + //layoutText.put("Буквы (АБВ)", "EN"); + } + + protected void updateNotification(String toast) + { + Notification icon; + Icon smallIcon = Icon.createWithBitmap(textAsBitmap(layouts.getString(toast, "??"), 30, Color.WHITE)); + + icon = new Notification.Builder(this) + .setSmallIcon(smallIcon) + .setContentTitle(toast) + .setOngoing(true) + .build(); + iconManager.notify(0, icon); + return; + } + + //Borrowed from Ted Hopp from StackOverflow + public Bitmap textAsBitmap(String text, float textSize, int textColor) { + Paint paint = new Paint(ANTI_ALIAS_FLAG); + paint.setTextSize(textSize); + paint.setColor(textColor); + 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 + public void onAccessibilityEvent(AccessibilityEvent event) { + + Log.d(TAG, event.toString()); + if(event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) + { + Log.d(TAG, "Caught a Toast: "); + Log.d(TAG, (String)event.getPackageName()); + String toast = (String)event.getText().get(0); + Log.d(TAG, toast); + + updateNotification(toast); + } + else + { + Log.d(TAG, "Caution! This service had been tampered with!"); + } + + } + + @Override + public void onInterrupt() { + + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + layouts = getSharedPreferences("layouts", 0); + } +} diff --git a/app/src/main/java/space/neothefox/laytray/MainActivity.java b/app/src/main/java/space/neothefox/laytray/MainActivity.java new file mode 100644 index 0000000..14db873 --- /dev/null +++ b/app/src/main/java/space/neothefox/laytray/MainActivity.java @@ -0,0 +1,148 @@ +package space.neothefox.laytray; + +import android.content.SharedPreferences; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.util.Log; + +import java.util.List; +import java.util.Map; + +public class MainActivity extends AppCompatActivity +implements View.OnClickListener, SharedPreferences.OnSharedPreferenceChangeListener { + + LinearLayout layoutLister; + SharedPreferences layouts; + public String TAG = "layiconActivity"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + layoutLister = findViewById(R.id.scrollLinearLayout); + layouts = getSharedPreferences("layouts", 0); + updateLayouts(); + + FloatingActionButton addButton = findViewById(R.id.floatingActionButton); + Button saveButton = findViewById(R.id.saveButton); + addButton.setOnClickListener(this); + saveButton.setOnClickListener(this); + + } + + protected void updateLayouts() + { + layoutLister.removeAllViewsInLayout(); + + Log.d(TAG, "Updateing Layouts:"); + Map keys = layouts.getAll(); + if(keys != null) + { + Log.d(TAG, "listing map:"); + int i = 0; + for(Map.Entry entry : keys.entrySet()){ + Log.d("map values",entry.getKey() + ": " + + entry.getValue().toString()); + i++; + + addLine(layoutLister, entry.getKey(), entry.getValue().toString()); + } + if(i == 0) + { + populateLayouts(); + } + } + else + { + populateLayouts(); + } + + } + + protected void populateLayouts() + { + Log.d("map values", "Shared Prefs are empty"); + SharedPreferences.Editor layoutsEditor = layouts.edit(); + layoutsEditor.clear(); + layoutsEditor.putString("Русский", "RU"); + layoutsEditor.putString("Буквы (АБВ)", "EN"); + layoutsEditor.commit(); + } + + protected void addLine(LinearLayout parent) + { + addLine(parent, "Name", "ICO"); + } + + protected void addLine(LinearLayout parent, String name, String icon) + { + LinearLayout layoutLine = new LinearLayout(getApplicationContext()); + layoutLine.setOrientation(LinearLayout.HORIZONTAL); + + EditText layoutName = new EditText(getApplicationContext()); + layoutName.setText(name); + layoutLine.addView(layoutName); + + EditText layoutIcon = new EditText(getApplicationContext()); + layoutIcon.setText(icon); + layoutLine.addView(layoutIcon); + + parent.addView(layoutLine); + } + + protected void saveLayouts(LinearLayout parent) + { + int count = parent.getChildCount(); + Log.d(TAG, String.format("%d layouts to save", count)); + if (count != 0) + { + SharedPreferences.Editor layoutsEditor = layouts.edit(); + layoutsEditor.clear(); + for (int i=0; i < count; i++) + { + LinearLayout layoutLine = (LinearLayout)parent.getChildAt(i); + EditText layoutName = (EditText)layoutLine.getChildAt(0); + EditText layoutIcon = (EditText)layoutLine.getChildAt(1); + String layoutNameValue = layoutName.getText().toString(); + String layoutIconValue = layoutIcon.getText().toString(); + if(layoutNameValue != "") + { + if(layoutIconValue != "") + { + layoutsEditor.putString(layoutNameValue, layoutIconValue); + } + else + { + layoutsEditor.putString(layoutNameValue, "??"); + } + } + } + layoutsEditor.commit(); + } + } + + @Override + public void onClick(View v) { + switch(v.getId()) + { + case R.id.floatingActionButton: + addLine(layoutLister); + break; + case R.id.saveButton: + saveLayouts(layoutLister); + break; + } + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + layouts = getSharedPreferences("layouts", 0); + updateLayouts(); + } + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..aade80d --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + +