forked from lubuwest/Friendiqa
Native colors and new message create window
This commit is contained in:
parent
17f25d6809
commit
2debd8f2ab
122 changed files with 3525 additions and 3122 deletions
|
@ -10,6 +10,7 @@ import android.content.Context;
|
|||
import android.Manifest.permission;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidnative.AndroidNativeService;
|
||||
|
||||
/** An alternative Activity class for Qt applicaiton.
|
||||
|
||||
|
@ -18,7 +19,8 @@ import androidx.core.content.ContextCompat;
|
|||
|
||||
public class AndroidNativeActivity extends org.qtproject.qt5.android.bindings.QtActivity {
|
||||
public static final int MY_PERMISSIONS_REQUEST_READ_STORAGE = 0x245285a8;
|
||||
|
||||
public static final int MY_PERMISSIONS_REQUEST_POST_NOTIFICATIONS = 0x245285a9;
|
||||
private static final String TAG = "AndroidNativeActivity";
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
@ -29,6 +31,11 @@ public class AndroidNativeActivity extends org.qtproject.qt5.android.bindings.Qt
|
|||
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
|
||||
|
||||
AndroidNativeService fs = new AndroidNativeService();
|
||||
fs.startQtService(this);
|
||||
//if (ContextCompat.checkSelfPermission(this,android.Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
// Permission is not granted
|
||||
|
@ -75,19 +82,29 @@ public class AndroidNativeActivity extends org.qtproject.qt5.android.bindings.Qt
|
|||
|
||||
|
||||
@Override public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
|
||||
Log.d(TAG,"onRequestPermissionsResult");
|
||||
switch (requestCode) {
|
||||
case MY_PERMISSIONS_REQUEST_READ_STORAGE: {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Map message = new HashMap();
|
||||
message.put("multiple",false);
|
||||
SystemDispatcher.dispatch("androidnative.ImagePicker.pickImage",message);
|
||||
} else {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Map message = new HashMap();
|
||||
message.put("multiple",false);
|
||||
SystemDispatcher.dispatch("androidnative.ImagePicker.pickImage",message);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
case MY_PERMISSIONS_REQUEST_POST_NOTIFICATIONS: {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Map message = new HashMap();
|
||||
message.put("multiple",false);
|
||||
SystemDispatcher.dispatch("androidnative.Util.setPostNotification",message);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,14 +20,14 @@ public class AndroidNativeService extends QtService
|
|||
private static String TAG = "AndroidNative";
|
||||
|
||||
public void startQtService(Context ctx) {
|
||||
//Log.d(TAG, "QtActivity active "+String.valueOf(QtNative.activity()!=null));
|
||||
Log.d(TAG, "QtActivity active "+String.valueOf(QtNative.activity()!=null));
|
||||
if (QtNative.activity()==null){
|
||||
//Log.d(TAG,"Friendiqasync Stop existing QtService");
|
||||
Log.d(TAG,"Friendiqasync Stop existing QtService");
|
||||
ctx.stopService(new Intent(ctx, AndroidNativeService.class));
|
||||
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
//Log.d(TAG,"Friendiqasync startForegroundService");
|
||||
Log.d(TAG,"Friendiqasync startForegroundService");
|
||||
ctx.startForegroundService(new Intent(ctx, AndroidNativeService.class));
|
||||
} else {
|
||||
ctx.startService(new Intent(ctx, AndroidNativeService.class));
|
||||
|
@ -35,7 +35,7 @@ public class AndroidNativeService extends QtService
|
|||
}
|
||||
|
||||
public static void stopQtService(Context ctx) {
|
||||
//Log.d(TAG,"Friendiqasync QtServiceStop");
|
||||
Log.d(TAG,"Friendiqasync QtServiceStop");
|
||||
ctx.stopService(new Intent(ctx, AndroidNativeService.class));
|
||||
}
|
||||
|
||||
|
@ -44,11 +44,12 @@ public class AndroidNativeService extends QtService
|
|||
{
|
||||
Context context;
|
||||
context = this.getApplicationContext();
|
||||
Log.d(TAG,"Friendiqa onCreate");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
||||
Intent intent = new Intent(context,FriendiqaActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||
String CHANNEL_ID = "channel_02";
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||
"Sync Channel",
|
||||
|
|
|
@ -25,6 +25,11 @@ import android.content.Intent;
|
|||
import java.util.Map;
|
||||
import org.qtproject.friendiqa.R;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.Manifest;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class Util {
|
||||
|
||||
private static final String TAG = "androidnative.Util";
|
||||
|
@ -33,7 +38,8 @@ public class Util {
|
|||
public static final String SET_FULL_SCREEN = "androidnative.Util.setFullScreen";
|
||||
public static final String SET_SCHEDULE = "androidnative.Util.setSchedule";
|
||||
public static final String SET_NOTIFICATION = "androidnative.Util.setNotification";
|
||||
|
||||
public static final String SET_POST_NOTIFICATION = "androidnative.Util.setPostNotification";
|
||||
public static final int MY_PERMISSIONS_REQUEST_POST_NOTIFICATIONS = 0x245285a9;
|
||||
|
||||
static {
|
||||
SystemDispatcher.addListener(new SystemDispatcher.Listener() {
|
||||
|
@ -46,6 +52,8 @@ public class Util {
|
|||
setSchedule(message);
|
||||
} else if (type.equals(SET_NOTIFICATION)) {
|
||||
setNotification(message);
|
||||
} else if (type.equals(SET_POST_NOTIFICATION)) {
|
||||
setPostNotification(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -110,14 +118,14 @@ public class Util {
|
|||
}
|
||||
|
||||
static void setNotification(Map message) {
|
||||
//Log.d(TAG,"setNotification");
|
||||
Log.d(TAG,"setNotification");
|
||||
Context context;
|
||||
//Context appcontext;
|
||||
context = QtNative.service().getApplicationContext();
|
||||
//appcontext = QtNative.activity().getApplicationContext();
|
||||
Intent intent = new Intent(context,FriendiqaActivity.class);
|
||||
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||
|
||||
final String textTitle = (String) message.get("title");
|
||||
final String textContent = (String) message.get("message");
|
||||
|
@ -171,14 +179,23 @@ public class Util {
|
|||
} else {
|
||||
context = QtNative.activity().getApplicationContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//AndroidNativeService fs = new AndroidNativeService();
|
||||
//fs.startQtService(context);
|
||||
|
||||
|
||||
if (value==0){
|
||||
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
jobScheduler.cancelAll();
|
||||
//Log.d(TAG,"Friendiqasync deleting Androidnative jobscheduler");
|
||||
Log.d(TAG,"Friendiqasync deleting Androidnative jobscheduler");
|
||||
} else {
|
||||
//Log.d(TAG,"Friendiqasync schedule Androidnative jobscheduler");
|
||||
Log.d(TAG,"Friendiqasync schedule Androidnative jobscheduler");
|
||||
ComponentName component = new ComponentName(context, FriendiqaService.class);
|
||||
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
|
||||
|
||||
//Log.d(TAG,"Jobinfolist size " + String.valueOf(jobScheduler.getAllPendingJobs().size()));
|
||||
if (jobScheduler.getAllPendingJobs().size()==0){
|
||||
JobInfo.Builder builder = new JobInfo.Builder(2, component)
|
||||
|
@ -186,7 +203,7 @@ public class Util {
|
|||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||
.setPersisted(true)
|
||||
.setPrefetch(true);
|
||||
//Log.d(TAG,"Friendiqa schedule Androidnative sync schedule"+ (value * ONE_MIN));
|
||||
Log.d(TAG,"1 Friendiqa schedule Androidnative sync schedule"+ (value * ONE_MIN));
|
||||
jobScheduler.schedule(builder.build());
|
||||
} else {
|
||||
for ( JobInfo jobInfo : jobScheduler.getAllPendingJobs() ) {
|
||||
|
@ -197,23 +214,42 @@ public class Util {
|
|||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||
.setPersisted(true)
|
||||
.setPrefetch(true);
|
||||
//Log.d(TAG,"Friendiqa schedule Androidnative sync schedule"+ (value * ONE_MIN));
|
||||
Log.d(TAG,"2 Friendiqa schedule Androidnative sync schedule"+ (value * ONE_MIN));
|
||||
jobScheduler.schedule(builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
//Log.d(TAG,"Active service " + String.valueOf(QtNative.service()!=null));
|
||||
if (QtNative.service() != null){
|
||||
//Log.d(TAG,"Schedule Stopping Friendiqa Androidnative service");
|
||||
ComponentName componentStopper = new ComponentName(context, FriendiqaStopService.class);
|
||||
JobInfo.Builder stopbuilder = new JobInfo.Builder(1, componentStopper)
|
||||
.setMinimumLatency(50)
|
||||
.setOverrideDeadline(100);
|
||||
//if (QtNative.service() != null){
|
||||
// Log.d(TAG,"Schedule Stopping Friendiqa Androidnative service");
|
||||
// ComponentName componentStopper = new ComponentName(context, FriendiqaStopService.class);
|
||||
// JobInfo.Builder stopbuilder = new JobInfo.Builder(1, componentStopper)
|
||||
// .setMinimumLatency(50)
|
||||
// .setOverrideDeadline(100);
|
||||
|
||||
JobScheduler jobStopScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
jobStopScheduler.schedule(stopbuilder.build());
|
||||
}
|
||||
// JobScheduler jobStopScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
// jobStopScheduler.schedule(stopbuilder.build());
|
||||
//}
|
||||
}
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
notificationManager.cancelAll();
|
||||
//context.stopService(new Intent(context, AndroidNativeService.class));
|
||||
}
|
||||
|
||||
static void setPostNotification(Map message) {
|
||||
Log.d(TAG,"setPostNotification");
|
||||
Context context;
|
||||
if (QtNative.activity() == null){
|
||||
context = QtNative.service().getApplicationContext();
|
||||
} else {
|
||||
context = QtNative.activity().getApplicationContext();
|
||||
}
|
||||
Activity activity = org.qtproject.qt5.android.QtNative.activity();
|
||||
Log.d(TAG,String.valueOf(ContextCompat.checkSelfPermission(context,Manifest.permission.POST_NOTIFICATIONS)));
|
||||
if (ContextCompat.checkSelfPermission(context,Manifest.permission.POST_NOTIFICATIONS)!= PackageManager.PERMISSION_GRANTED) {
|
||||
// Permission is not granted
|
||||
Log.d(TAG,String.valueOf(PackageManager.PERMISSION_GRANTED));
|
||||
ActivityCompat.requestPermissions(activity,new String[]{Manifest.permission.POST_NOTIFICATIONS},MY_PERMISSIONS_REQUEST_POST_NOTIFICATIONS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue