Commit d5d56972 authored by Jeremy JAMET's avatar Jeremy JAMET

Fix notification call

parent c5f7ef8c
package com.kunzisoft.keyboard.switcher;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
/**
* Activity to show keyboard manager
*/
public class KeyboardManagerActivity extends AppCompatActivity {
public static final String DELAY_SHOW_KEY = "DELAY_SHOW_KEY";
private long delay = 200L;
private InputMethodManager imeManager;
private View rootView;
enum DialogState {
PICKING, CHOSEN
NONE, PICKING, CHOSEN
}
private DialogState mState;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mState = DialogState.NONE;
setContentView(R.layout.empty);
rootView = findViewById(R.id.root_view);
super.onCreate(savedInstanceState);
imeManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (getIntent() != null) {
delay = getIntent().getLongExtra(DELAY_SHOW_KEY, delay);
}
}
@Override
......@@ -44,13 +56,12 @@ public class KeyboardManagerActivity extends AppCompatActivity {
rootView.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imeManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (imeManager != null) {
imeManager.showInputMethodPicker();
}
mState = DialogState.PICKING;
}
}, 100);
}, delay);
}
@Override
......
......@@ -40,7 +40,7 @@ public class NotificationBuilder {
.setPriority(NotificationCompat.PRIORITY_LOW)
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setContentText(context.getString(R.string.notification_content_text))
.setContentIntent(Utilities.getPendingIntent(context));
.setContentIntent(Utilities.getPendingIntent(context, 500L)); // Trick 500ms delay to show th dialog
mNotificationManager.cancel(notificationId);
mNotificationManager.notify(notificationId, builder.build());
......
......@@ -44,10 +44,16 @@ public class Utilities {
}
}
public static PendingIntent getPendingIntent(Context context) {
public static PendingIntent getPendingIntent(Context context) {
return getPendingIntent(context, null);
}
public static PendingIntent getPendingIntent(Context context, @Nullable Long delay) {
Intent chooserIntent = new Intent(context, KeyboardManagerActivity.class);
chooserIntent.setAction(Intent.ACTION_MAIN);
chooserIntent.addCategory(Intent.CATEGORY_LAUNCHER);
if (delay != null)
chooserIntent.putExtra(KeyboardManagerActivity.DELAY_SHOW_KEY, delay);
return PendingIntent.getActivity(
context, 0, chooserIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment