This commit is contained in:
LubuWest 2019-01-09 22:03:16 +01:00
commit 63dfb9b197
70 changed files with 2829 additions and 1056 deletions

View file

@ -4,6 +4,11 @@ import android.util.Log;
import android.app.Activity;
import android.os.*;
import java.util.Map;
import android.content.pm.PackageManager;
import android.content.Context;
import android.Manifest.permission;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
/** An alternative Activity class for Qt applicaiton.
@ -11,6 +16,8 @@ import java.util.Map;
*/
public class AndroidNativeActivity extends org.qtproject.qt5.android.bindings.QtActivity {
public static final int MY_PERMISSIONS_REQUEST_WRITE_STORAGE = 0x245285a8;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@ -21,6 +28,17 @@ public class AndroidNativeActivity extends org.qtproject.qt5.android.bindings.Qt
protected void onResume() {
super.onResume();
if (ContextCompat.checkSelfPermission(this,android.Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},MY_PERMISSIONS_REQUEST_WRITE_STORAGE);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
} else {
System.loadLibrary("friendiqa");
if((getIntent().getFlags() == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)) || (getIntent().getFlags() == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) || (getIntent().getFlags() == Intent.FLAG_ACTIVITY_NEW_TASK) || (getIntent().getFlags() == Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) || (getIntent().getFlags() == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED))) {
SystemDispatcher.onActivityResume();
@ -48,6 +66,25 @@ public class AndroidNativeActivity extends org.qtproject.qt5.android.bindings.Qt
SystemDispatcher.onActivityResume();
}}
}
}
@Override public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_STORAGE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
SystemDispatcher.onActivityResume();
} else {
}
return;
}
}
}
protected void onNewIntent(Intent data) {
System.loadLibrary("friendiqa");

View file

@ -0,0 +1,23 @@
package androidnative;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.qtproject.qt5.android.bindings.QtService;
public class AndroidNativeService extends QtService
{
private static String TAG = "AndroidNative";
public void startQtService(Context ctx) {
Log.d(TAG,"Friendiqa QtService");
ctx.startService(new Intent(ctx, AndroidNativeService.class));
}
public static void stopQtService(Context ctx) {
Log.d(TAG,"Friendiqa QtServiceStop");
ctx.stopService(new Intent(ctx, AndroidNativeService.class));
}
}

View file

@ -6,9 +6,15 @@ import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.content.Context;
import android.content.ComponentName;
import android.app.job.JobScheduler;
import android.app.job.JobInfo;
import org.qtproject.qt5.android.QtNative;
import androidnative.friendiqa.FriendiqaService;
import androidnative.friendiqa.FriendiqaStopService;
import androidnative.AndroidNativeService;
import android.content.Intent;
import java.util.Map;
public class Util {
@ -17,6 +23,7 @@ public class Util {
public static final String SET_TRANSLUCENT_STATUS_BAR = "androidnative.Util.setTranslucentStatusBar";
public static final String SET_FULL_SCREEN = "androidnative.Util.setFullScreen";
public static final String SET_SCHEDULE = "androidnative.Util.setSchedule";
static {
@ -26,6 +33,8 @@ public class Util {
setTranslucentStatusBar(message);
} else if (type.equals(SET_FULL_SCREEN)) {
setFullScreen(message);
} else if (type.equals(SET_SCHEDULE)) {
setSchedule(message);
}
}
});
@ -62,6 +71,10 @@ public class Util {
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return;
}
final Boolean value = (Boolean) message.get("value");
final Activity activity = QtNative.activity();
@ -84,4 +97,52 @@ public class Util {
activity.runOnUiThread(runnable);
}
static void setSchedule(Map message) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return;
}
Log.d(TAG,"Friendiqa schedule Androidnative service");
final Integer value = (Integer) message.get("value");
//final Activity activity = QtNative.activity();
//final Service service = QtNative.service();
//final int JOB_ID = 1;
final int ONE_MIN = 60 * 1000;
Context context;
if (QtNative.activity() == null){
context = QtNative.service().getApplicationContext();
} else {
context = QtNative.activity().getApplicationContext();
}
ComponentName component = new ComponentName(context, FriendiqaService.class);
JobInfo.Builder builder = new JobInfo.Builder(2, component)
// schedule it to run any time between 1 - 5 minutes
.setMinimumLatency(value * ONE_MIN)
.setOverrideDeadline((value + 5)*ONE_MIN)
//.setPeriodic(value * ONE_MIN)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(builder.build());
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());
//AndroidNativeService.stopQtService(context);
}
//context.stopService(new Intent(context, AndroidNativeService.class));
}
/**static void stopService(Map message){
this.stopService(new Intent(this, AndroidNativeService.class));
}
**/
}