Skip to content

Commit

Permalink
Update android version, add fix for 31 notification
Browse files Browse the repository at this point in the history
  • Loading branch information
askarbabu committed Apr 11, 2024
1 parent 44da283 commit b889f5e
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

31 changes: 16 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
namespace "com.gazlaws.codeboard"
compileSdkVersion 34
buildToolsVersion '34.0.0'

defaultConfig {
applicationId "com.gazlaws.codeboard"
minSdkVersion 23
targetSdkVersion 30
versionCode 20
versionName "6.0.0"
targetSdkVersion 34
versionCode 21
versionName "6.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down Expand Up @@ -41,32 +42,32 @@ repositories {

dependencies {

api 'androidx.appcompat:appcompat:1.2.0'
api 'androidx.appcompat:appcompat:1.6.1'
api 'androidx.legacy:legacy-support-v13:1.0.0'
api 'androidx.preference:preference:1.1.1'
api 'androidx.preference:preference:1.2.1'

implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'com.google.android.material:material:1.11.0'

//https://github.com/AppIntro/AppIntro
implementation 'com.github.AppIntro:AppIntro:6.1.0'
implementation 'com.github.AppIntro:AppIntro:6.3.1'

//Colour picker
implementation 'com.pes.materialcolorpicker:library:1.2.5'

// Required for local unit tests (JUnit 4 framework)
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'

// Required for instrumented tests
implementation 'androidx.annotation:annotation:1.2.0'
androidTestImplementation 'androidx.annotation:annotation:1.2.0'
implementation 'androidx.annotation:annotation:1.7.1'
androidTestImplementation 'androidx.annotation:annotation:1.7.1'


// Core library
androidTestImplementation 'androidx.test:core:1.3.0'
androidTestImplementation 'androidx.test:core:1.5.0'

// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:runner:1.5.2'

androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'

}
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gazlaws.codeboard"
>

<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
android:allowBackup="true"
Expand All @@ -14,7 +16,8 @@
<service
android:name=".CodeBoardIME"
android:label="@string/codeboard_ime"
android:permission="android.permission.BIND_INPUT_METHOD">
android:permission="android.permission.BIND_INPUT_METHOD"
android:exported="true">
<meta-data
android:name="android.view.im"
android:resource="@xml/method" />
Expand All @@ -27,7 +30,7 @@
<activity android:name="com.gazlaws.codeboard.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
>
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
98 changes: 79 additions & 19 deletions app/src/main/java/com/gazlaws/codeboard/CodeBoardIME.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gazlaws.codeboard;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -8,6 +10,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.inputmethodservice.InputMethodService;
Expand All @@ -16,6 +19,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.ResultReceiver;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
Expand All @@ -26,8 +30,10 @@
import android.view.inputmethod.InputMethodManager;
import android.media.MediaPlayer; // for keypress sound

import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.app.RemoteInput;
import androidx.core.graphics.ColorUtils;

import com.gazlaws.codeboard.layout.Box;
Expand All @@ -46,6 +52,8 @@
import java.util.TimerTask;

import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;

/*Created by Ruby(aka gazlaws) on 13/02/2016.
*/
Expand Down Expand Up @@ -73,7 +81,7 @@ public void onKey(int primaryCode, int[] KeyCodes) {
//NOTE: Long press goes second, this is onDown
InputConnection ic = getCurrentInputConnection();
char code = (char) primaryCode;
Log.i(getClass().getSimpleName(), "onKey: " + primaryCode);
Log.d(getClass().getSimpleName(), "onKey: " + primaryCode);

switch (primaryCode) {
//First handle cases that don't use shift/ctrl meta modifiers
Expand Down Expand Up @@ -274,7 +282,7 @@ public void onKey(int primaryCode, int[] KeyCodes) {
}
if (ke != 0) {

Log.i(getClass().getSimpleName(), "onKey: keyEvent " + ke);
Log.d(getClass().getSimpleName(), "onKey: keyEvent " + ke);

/*
* The if statement was added in order to prevent the space button
Expand All @@ -284,7 +292,9 @@ public void onKey(int primaryCode, int[] KeyCodes) {
* and afterwards produce the right output to the screen.
* TODO: Investigate whether KeyEvent.ACTION_UP is still required.
*/
if (primaryCode != 32) { ic.sendKeyEvent (new KeyEvent (0, 0, KeyEvent.ACTION_DOWN, ke, 0, meta)); }
if (primaryCode != 32) {
ic.sendKeyEvent(new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, ke, 0, meta));
}

ic.sendKeyEvent(new KeyEvent(0, 0, KeyEvent.ACTION_UP, ke, 0, meta));
} else {
Expand Down Expand Up @@ -341,6 +351,19 @@ public void run() {
}, ViewConfiguration.getLongPressTimeout());
}

@Override
public void onExtractingInputChanged(EditorInfo ei){
Log.d(getClass().getSimpleName(), "onExtractingInputChanged: ");
}
@Override
public void requestHideSelf(int flags){
int new_flag = HIDE_IMPLICIT_ONLY;
new_flag = flags;
Log.d(getClass().getSimpleName(), "requestHideSelf: "+new_flag + ","+ flags);
// do nothing
super.requestHideSelf(new_flag);
}

@Override
public void onWindowHidden() {
super.onWindowHidden();
Expand All @@ -361,10 +384,10 @@ public void onRelease(int primaryCode) {
* If it was, we don't do anything,
* but If it wasn't, we print a "space" to the screen.
*/
if ((primaryCode == 32) && (! longPressedSpaceButton)) {
if ((primaryCode == 32) && (!longPressedSpaceButton)) {

InputConnection ic = getCurrentInputConnection ();
ic.commitText (String.valueOf ((char) primaryCode), 1);
InputConnection ic = getCurrentInputConnection();
ic.commitText(String.valueOf((char) primaryCode), 1);
}

longPressedSpaceButton = false;
Expand Down Expand Up @@ -671,6 +694,7 @@ private void createNotificationChannel() {
private static final int NOTIFICATION_ONGOING_ID = 1001;

//Code from Hacker keyboard's source
@SuppressLint("MissingPermission")
private void setNotification(boolean visible) {
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Expand All @@ -682,19 +706,55 @@ private void setNotification(boolean visible) {
createNotificationChannel();
mNotificationReceiver = new NotificationReceiver(this);
final IntentFilter pFilter = new IntentFilter(NotificationReceiver.ACTION_SHOW);
pFilter.addAction(NotificationReceiver.ACTION_SETTINGS);
registerReceiver(mNotificationReceiver, pFilter);

Intent notificationIntent = new Intent(NotificationReceiver.ACTION_SHOW);
PendingIntent contentIntent =
PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(mNotificationReceiver, pFilter, Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(mNotificationReceiver, pFilter);
}


Intent imeIntent = new Intent(NotificationReceiver.ACTION_SHOW);
PendingIntent imePendingIntent =
PendingIntent.getBroadcast(getApplicationContext(),
1, imeIntent, PendingIntent.FLAG_IMMUTABLE);

Intent configIntent = new Intent(NotificationReceiver.ACTION_SETTINGS);
PendingIntent configPendingIntent =
PendingIntent.getBroadcast(getApplicationContext(), 2, configIntent, 0);
// BUG: IM closes when notification drawer is closed
// try making a input field here?
// Key for the string that's delivered in the action's intent.
String KEY_TEXT_REPLY = "key_text_reply";

RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
.setLabel("Now click first icon")
.build();


// Build a PendingIntent for the keyboard action to trigger first
int flags = PendingIntent.FLAG_MUTABLE;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
flags = PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT;
}
PendingIntent replyPendingIntent =
PendingIntent.getBroadcast(getApplicationContext(),
2,
imeIntent,
flags);


// Create the reply action and add the remote input.
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.icon_large,
getString(R.string.notification_action_open_keyboard_workaround), replyPendingIntent)
.addRemoteInput(remoteInput)
.build();

Intent settingsIntent = new Intent(this, MainActivity.class);
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent settingsPendingIntent =
PendingIntent.getActivity(this,0
, settingsIntent, PendingIntent.FLAG_IMMUTABLE);
String title = "Show Codeboard Keyboard";
String body = "Select this to open the keyboard. Disable in settings.";
String body = "Select this to open the keyboard. Disable in settings. You may have to fix open the fix as a workaround for newer Android versions";

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
Expand All @@ -704,17 +764,17 @@ private void setNotification(boolean visible) {
.setTicker(text)
.setContentTitle(title)
.setContentText(body)
.setContentIntent(contentIntent)
.setContentIntent(imePendingIntent)
.setOngoing(true)
.addAction(R.drawable.icon_large, getString(R.string.notification_action_open_keyboard),
contentIntent)
imePendingIntent)
.addAction(R.drawable.icon_large, getString(R.string.notification_action_settings),
configPendingIntent)
settingsPendingIntent)
.addAction(action)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

// notificationId is a unique int for each notification that you must define
notificationManager.notify(NOTIFICATION_ONGOING_ID, mBuilder.build());

} else if (!visible && mNotificationReceiver != null) {
Expand Down
Loading

0 comments on commit b889f5e

Please sign in to comment.