mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Add Notification Permission for T"
This commit is contained in:
commit
ee855c281c
@ -18,6 +18,7 @@
|
|||||||
package="com.android.inputmethod.tools.edittextvariations"
|
package="com.android.inputmethod.tools.edittextvariations"
|
||||||
android:versionName="0.67"
|
android:versionName="0.67"
|
||||||
android:versionCode="67">
|
android:versionCode="67">
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<supports-screens android:resizeable="true"/>
|
<supports-screens android:resizeable="true"/>
|
||||||
<uses-sdk android:targetSdkVersion="27"
|
<uses-sdk android:targetSdkVersion="27"
|
||||||
android:minSdkVersion="11"/>
|
android:minSdkVersion="11"/>
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.inputmethod.tools.edittextvariations;
|
package com.android.inputmethod.tools.edittextvariations;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@ -24,6 +25,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -45,7 +47,9 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -64,6 +68,7 @@ public final class EditTextVariations extends Activity implements TextView.OnEdi
|
|||||||
private static final String PREF_THEME = "theme";
|
private static final String PREF_THEME = "theme";
|
||||||
private static final String PREF_NAVIGATE = "navigate";
|
private static final String PREF_NAVIGATE = "navigate";
|
||||||
private static final String PREF_SOFTINPUT = "softinput";
|
private static final String PREF_SOFTINPUT = "softinput";
|
||||||
|
private static final int NOTIFICATION_PERMISSION_REQUEST_CODE = 0;
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private View[] fields;
|
private View[] fields;
|
||||||
@ -199,11 +204,35 @@ public final class EditTextVariations extends Activity implements TextView.OnEdi
|
|||||||
saveSoftInputMode(itemId == MENU_SOFTINPUT_VISIBLE);
|
saveSoftInputMode(itemId == MENU_SOFTINPUT_VISIBLE);
|
||||||
restartActivity();
|
restartActivity();
|
||||||
} else if (itemId == MENU_DIRECT_REPLY) {
|
} else if (itemId == MENU_DIRECT_REPLY) {
|
||||||
|
final boolean needPermissionCheck = isNeedNotificationPermission()
|
||||||
|
&& checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) !=
|
||||||
|
PackageManager.PERMISSION_GRANTED;
|
||||||
|
if (needPermissionCheck) {
|
||||||
|
requestPermissions(new String[] { Manifest.permission.POST_NOTIFICATIONS },
|
||||||
|
NOTIFICATION_PERMISSION_REQUEST_CODE);
|
||||||
|
} else {
|
||||||
NotificationUtils.sendDirectReplyNotification(this);
|
NotificationUtils.sendDirectReplyNotification(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||||
|
int[] grantResults) {
|
||||||
|
if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE) {
|
||||||
|
if (grantResults.length == 1 &&
|
||||||
|
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// Permission is granted. Continue to send the notification.
|
||||||
|
NotificationUtils.sendDirectReplyNotification(this);
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "POST_NOTIFICATIONS Permissions denied.");
|
||||||
|
Toast.makeText(this, "Required permission has denied",
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final DialogInterface dialog, final int which) {
|
public void onClick(final DialogInterface dialog, final int which) {
|
||||||
saveTheme(ThemeItem.THEME_LIST.get(which));
|
saveTheme(ThemeItem.THEME_LIST.get(which));
|
||||||
@ -476,4 +505,14 @@ public final class EditTextVariations extends Activity implements TextView.OnEdi
|
|||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isNeedNotificationPermission() {
|
||||||
|
for(Field field : Manifest.permission.class.getFields()) {
|
||||||
|
if (field.getName().equals("POST_NOTIFICATIONS")) {
|
||||||
|
Log.d(TAG, "Need notification permission.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user