I am unable to include this class in my project.
how could I do?
how could I do?
B4X:
package library;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ziwiIntegrator {
private static final int REQUEST_CODE = 0x0000978c; //Utilizzo solo dei 16 bit bassi
private static final String TAG = ziwiIntegrator.class.getSimpleName();
private static final String ZIWI_PACKAGE = "sv.ziwi.external";
private static final String DEFAULT_TITLE = "Installare Ziwi - Invio corrispettivi AdE ?";
private static final String DEFAULT_MESSAGE =
"Questa applicazione richiede l'App Ziwi, procedere con l'installazione ?";
private static final String YES = "SI";
private static final String NO = "NO";
private final String titolo=DEFAULT_TITLE;
private final String messaggio=DEFAULT_MESSAGE;
private final String yes=YES;
private final String no=NO;
private final Activity activity;
private final Fragment fragment;
private Context mContext;
private static final List<String> TARGET_ALL_KNOWN = list(
ZIWI_PACKAGE
);
private List<String> targetApplications;
public static int IRDABOUD_2400=16;
public static int IRDABOUD_4800=32;
public static int IRDABOUD_9600=48;
public static int IRDABOUD_19200=64;
public static int IRDABOUD_38400=80;
public static int IRDABOUD_57600=96;
public static int IRDABOUD_AUTO=112;
public ziwiIntegrator(Activity activity) {
this.activity = activity;
this.fragment = null;
mContext=activity;
InitData();
}
public ziwiIntegrator(Fragment fragment, Context context) {
this.activity = fragment.getActivity();
this.fragment = fragment;
mContext=context;
InitData();
}
private void InitData(){
targetApplications = TARGET_ALL_KNOWN;
}
private static String getApplicationName(Context context) {
ApplicationInfo applicationInfo = context.getApplicationInfo();
int stringId = applicationInfo.labelRes;
return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
}
public final AlertDialog GetEVA_JS(String User_key, boolean resetEVACounter) {
Intent intentScan = new Intent(Intent.ACTION_MAIN);
Intent intentSend;
intentScan.addCategory(ZIWI_PACKAGE);
ApplicationInfo targetAppPackage = findTargetAppPackage(intentScan);
if (targetAppPackage == null) {
return showDownloadDialog();
}
intentSend = new Intent("sv.ziwi.external");
intentSend.putExtra("ACTION", "GetEVA_JS" );
intentSend.putExtra("KEY", User_key );
intentSend.putExtra("CALLER_ID", getApplicationName(mContext));
intentSend.putExtra("RESETEVACOUNTER",resetEVACounter);
startActivityForResult(intentSend , REQUEST_CODE);
return null;
}
public final AlertDialog GetEVA_Stitch(int IrDaSecurity, int IrDaPassword, int boudRate, boolean resetEVACounter) {
Intent intentScan = new Intent(Intent.ACTION_MAIN);
Intent intentSend;
intentScan.addCategory(ZIWI_PACKAGE);
ApplicationInfo targetAppPackage = findTargetAppPackage(intentScan);
if (targetAppPackage == null) {
return showDownloadDialog();
}
intentSend = new Intent("sv.ziwi.external");
intentSend.putExtra("ACTION", "GetEVA_Stitch" );
intentSend.putExtra("KEY", "" );
intentSend.putExtra("BOUDRATE", boudRate);
intentSend.putExtra("IRDA_SECURITY", IrDaSecurity);
intentSend.putExtra("IRDA_PASSWORD", IrDaPassword);
intentSend.putExtra("CALLER_ID", getApplicationName(mContext));
intentSend.putExtra("RESETEVACOUNTER",resetEVACounter);
startActivityForResult(intentSend , REQUEST_CODE);
return null;
}
protected void startActivityForResult(Intent intent, int code) {
if (fragment == null) {
activity.startActivityForResult(intent, code);
} else {
fragment.startActivityForResult(intent, code);
}
}
private ApplicationInfo findTargetAppPackage(Intent intent) {
PackageManager pm = activity.getPackageManager();
List<ResolveInfo> availableApps = pm.queryIntentActivities(intent, 0);
final List<ApplicationInfo> pluginApps = new ArrayList<>();
for (ResolveInfo resolveInfo : availableApps) {
if (resolveInfo.activityInfo != null) {
pluginApps.add(resolveInfo.activityInfo.applicationInfo);
}
}
if (pluginApps.size()>0){
return pluginApps.get(0);
}
return null;
}
private static boolean contains(Iterable<ResolveInfo> availableApps, String targetApp) {
for (ResolveInfo availableApp : availableApps) {
String packageName = availableApp.activityInfo.packageName;
if (packageName.startsWith(targetApp)) {
return true;
}
}
return false;
}
private static List<String> list(String... values) {
return Collections.unmodifiableList(Arrays.asList(values));
}
private AlertDialog showDownloadDialog() {
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
downloadDialog.setTitle(titolo);
downloadDialog.setMessage(messaggio);
downloadDialog.setPositiveButton(yes, (dialogInterface, i) -> {
Uri uri = Uri.parse("market://details?id=sv.ziwi");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
if (fragment == null) {
activity.startActivity(intent);
} else {
fragment.startActivity(intent);
}
} catch (ActivityNotFoundException anfe) {
// Hmm, market is not installed
Log.w(TAG, "Google play non installata; impossibile installare Ziwi!");
}
});
downloadDialog.setNegativeButton(no, null);
downloadDialog.setCancelable(true);
return downloadDialog.show();
}
}