Here map sdk to react native component - android

I have a problem with Here map sdk. Im trying to create a compmonent from native side and call from react native side. But i'm having this problem. I cant get the map initilize.
ScreenShot
I get this error from emulator.
These are my codes :
HereMapView.java :
public class HereMapView extends MapViewLite {
private static final String TAG = HereMapView.class.getSimpleName();
private MapViewLite mapView;
public HereMapView(ThemedReactContext reactContext) {
super(reactContext);
loadMapScene();
}
private void loadMapScene() {
// Load a scene from the SDK to render the map with a map style.
mapView.getMapScene().loadScene(MapStyle.NORMAL_DAY, new MapScene.LoadSceneCallback() {
#Override
public void onLoadScene(#Nullable MapScene.ErrorCode errorCode) {
if (errorCode == null) {
mapView.getCamera().setTarget(new GeoCoordinates(52.530932, 13.384915));
mapView.getCamera().setZoomLevel(14);
} else {
Log.d(TAG, "onLoadScene failed: " + errorCode.toString());
}
}
});
}
#Override
public void onPause() {
super.onPause();
this.onPause();
}
#Override
public void onResume() {
super.onResume();
this.onResume();
}
#Override
public void onDestroy() {
super.onDestroy();
this.onDestroy();
}
}
HereMapManager.java :
public class HereMapManager extends ViewGroupManager<HereMapView> {
private static final String TAG = HereMapManager.class.getSimpleName();
static final String REACT_CLASS = "HereMapView";
public Activity activity;
public HereMapManager(Activity activity){
this.activity = activity;
}
#Override
public String getName() {
return REACT_CLASS;
}
#Override
protected HereMapView createViewInstance(ThemedReactContext reactContext) {
return new HereMapView(reactContext);
}
}
HereMapModule.java :
public class HereMapModule extends ReactContextBaseJavaModule {
private static final String TAG = HereMapModule.class.getSimpleName();
HereMapModule(ReactApplicationContext reactContext) {
super(reactContext);
}
#Override
public String getName() {
return "HereMapView";
}
public Activity getActivity() {
return getCurrentActivity();
}
public static void closeQuietly(Closeable closeable) {
if (closeable == null) return;
try {
closeable.close();
} catch (IOException ignored) {
}
}
}
HereMapPackage :
public class HereMapPackage implements ReactPackage {
protected Activity activity;
public HereMapPackage() {
}
public HereMapPackage(Activity activity) {
this.activity = activity;
} // backwards compatibility
#Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new HereMapModule(reactContext));
}
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
#Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
//HereMapManager mapManager = new HereMapManager(reactContext);
HereMapManager mapManager = new HereMapManager(this.activity);
return Arrays.<ViewManager>asList(mapManager);
}
}
then i adding the package to :
MainAplication.java :
#Override
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new HereMapPackage());
return packages;
}
with this function.
And then i call from react native side with this code :
App.js :
const HereMapView = requireNativeComponent('HereMapView');
const App: () => React$Node = () => {
return (
<SafeAreaView style={styles.screen}>
<View style={styles.screen}>
<HereMapView style={{flex : 1}} />
</View>
</SafeAreaView>
);
};
Can you help me please? Im stuck over a 2 week in this.

Related

getting variable from native module in sub class

I have LibModule.java set as native module in reactnative
.....
class LibModule extends ReactContextBaseJavaModule {
boolean readingMyKad = false;
....
public void read_mykad_main() {
clear_results();
pre_card_status = -1;
new readMyKad(reactContext).execute();
}
public static class readMyKad extends AsyncTask<Void, Void, Integer> {
CountDownTimer readMyKadCdt;
readMyKad readMyKadObject;
private WeakReference<ReactApplicationContext> activityReference;
readMyKad(ReactApplicationContext reactContext) {
activityReference = new WeakReference<>(reactContext);
}
protected void onPreExecute() {
readMyKadObject = this;
readMyKadCdt = new CountDownTimer(25000, 1000) {
#Override
public void onTick(long millisUntilFinished) {
}
#Override
public void onFinish() {
if ( activityReference.get().readingMyKad ) {
try {
activityReference.get().readingMyKad = false;
if (readMyKadObject.getStatus() == AsyncTask.Status.RUNNING) {
boolean bret = readMyKadObject.cancel(true);
Log.e(TAG,"readMyKadAsyncTask Timeout, cancel: " + bret);
}
} catch (Exception ignored) {
}
}
}
};
readMyKadCdt.start();
}
...............
but in class readMyKad, i need to get variables from my main module LibModule such as activityReference.get().readingMyKad.
not just get the variable but also set and call function from LibModule. how can i do that because LibModule is not an activity.
im sorry for my english and the title.

Xposed - I can print inner class methods, but method hooking doesn't work

I'm trying to hook a method in inner class, but nothing happen, while I can print all the methods of that class.
All of the logs printed except which is in the replaceHookedMethod.
public class Keyguard implements IXposedHookLoadPackage {
#Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("com.android.keyguard"))
return;
XposedBridge.log("we are in keyguard!");
Class HwClockView = XposedHelpers.findClass("com.android.keyguard.AbsClockView$HwClockView",
lpparam.classLoader);
for (Method m : HwClockView.getDeclaredMethods()) {
XposedBridge.log("method: " + m.getName());
}
XposedHelpers.findAndHookMethod(HwClockView, "getDateString",
TimeZone.class, new XC_MethodReplacement() {
#Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("we are in getDateString!");
return String.format("%s", Utils.getPersianDateShort());
}
});
}
Update:
After second comment changed code to this, but same as before nothing happens:
public class Keyguard implements IXposedHookLoadPackage {
#Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
if (!lpparam.packageName.equals("com.android.keyguard"))
return;
XposedBridge.log("we are in keyguard!");
Class HwClockView = XposedHelpers.findClass("com.android.keyguard.AbsClockView$HwClockView",
lpparam.classLoader);
for (Method m : HwClockView.getDeclaredMethods()) {
XposedBridge.log("method: " + m.getName());
if ("getDateString".equalsIgnoreCase(m.getName())) {
XposedBridge.hookMethod(m, new XC_MethodReplacement() {
#Override
protected Object replaceHookedMethod(MethodHookParam param) {
XposedBridge.log("we are in getDateString!");
return String.format("%s", Utils.getPersianDateShort());
}
});
}
}
}
Target class:
public class AbsClockView extends RelativeLayout {
protected Calendar mCalendar;
private HwCustKeyguardStatusViewEx mCustKeyguardStatusViewEx;
protected TextView mDateView;
protected TextView mDescriptionView;
protected Factory mFactory;
protected final AtomicBoolean mFixedTimeZone;
protected FrameLayout mTimeParent;
protected TextView mTimeView;
public interface Factory {
void refreshDate();
void setHwDateFormat();
void updateHwTimeStyle();
}
private class HwClockView implements Factory {
protected Context mContext;
public HwClockView(Context context) {
...
}
private CharSequence getDateString(TimeZone timeZone) {
return someString;
}
}
public AbsClockView(Context context) {
this(context, null);
}
}

How to notify activity when repository class gets the data?

I'm new in android architecture component. this is my code , i'm at the point that I don't know how to notify my activity and get the results back
these are my codes:
Activity:
private void iniViewModels() {
Observer<List<User>>usersObserver=new Observer<List<User>>() {
#Override
public void onChanged(#Nullable List<User> users) {
Log.v("this","LiveData: ");
for (int i=0;i<users.size();i++){
Log.v("this",users.get(i).getName());
}
}
};
mViewModel = ViewModelProviders.of(this)//of-->name of act or fragment
.get(AcActivityViewModel.class);///get -->the name of viewModelClass
mViewModel.mUsers.observe(this,usersObserver);
}
this is my viewModel Class:
public class IpStaticViewModel extends AndroidViewModel {
public LiveData<List<Ipe>> ips;
private AppRepository repository;
public IpStaticViewModel(#NonNull Application application) {
super(application);
repository=AppRepository.getInstance(application.getApplicationContext());
}
public void getIpStatics() {
repository.getStaticIps();
}
}
this is my repository class:
public class AppRepository {
private static AppRepository ourInstance ;
private Context context;
private IpStaticInterface ipInterface;
public static AppRepository getInstance(Context context) {
if (ourInstance == null) {
ourInstance=new AppRepository(context);
}
return ourInstance;
}
private AppRepository(Context context) {
this.context=context;
}
public void getStaticIps() {
ipInterface= ApiConnection.getClient().create(IpStaticInterface.class);
ipInterface.getIpes()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new SingleObserver<IpStaticList>() {
#Override
public void onSubscribe(Disposable d) {
}
#Override
public void onSuccess(IpStaticList ipStaticList) {
List<Ipe>ips=ipStaticList.getIpes();
}
#Override
public void onError(Throwable e) {
Log.v("this","Eror "+ e.getMessage());
}
});
}
}
I'm using retrofit for fetching the data ,it fetch the data successfully but I don't know how to notify my activity
can you help me?
Have a MutableLiveData
final MutableLiveData<List<Ipe>> data = new MutableLiveData<>();
In onSucess
public MutableLiveData<List<Ipe>> getStaticIps() {
ipInterface= ApiConnection.getClient().create(IpStaticInterface.class);
ipInterface.getIpes()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new SingleObserver<IpStaticList>() {
#Override
public void onSubscribe(Disposable d) {
}
#Override
public void onSuccess(IpStaticList ipStaticList) {
List<Ipe>ips=ipStaticList.getIpes();
data.setValue(ips);
}
#Override
public void onError(Throwable e) {
Log.v("this","Eror "+ e.getMessage());
}
});
return data;
}
In repository expose this to viewmodel
public LiveData<List<Ipe>> getIpStatics() {
return repository.getStaticIps();
}
In Activity you observe the livedata
IpStaticViewModel viewmodel = ViewModelProviders.of(this
.get(IpStaticViewModel.class)
viewModel.getIpStatics().observe(this, new Observer<List<Ipe>>() {
#Override
public void onChanged(#Nullable List<Ipe> ipes) {
if (ipes != null) {
// dosomething
}
}
});
If you want to generalize your response in case you have a error or something have a look at https://github.com/googlesamples/android-architecture-components/blob/master/GithubBrowserSample/app/src/main/java/com/android/example/github/vo/Resource.kt

How can i pass an IDialogInterfaceOnDismissListener without my application crashing?

I've got an issue with my Xamarin.Android application regarding IDialogInterfaceOnDismissListener.
My repro sample:
public enum ConfirmationResult
{
Cancel,
Yes,
No
}
public interface IDialogService
{
Task<ConfirmationResult> ConfirmAsync(string title, string message, string acceptText, string declineText);
}
public class DialogService : IDialogService
{
class DismissDelegateListener : IDialogInterfaceOnDismissListener, IDialogInterfaceOnCancelListener
{
private Action _callback;
public DismissDelegateListener()
{
}
public DismissDelegateListener(Action callback)
{
_callback = callback;
}
public void Dispose()
{
_callback = null;
}
public IntPtr Handle { get; }
public void OnCancel(IDialogInterface dialog)
{
_callback?.Invoke();
}
public void OnDismiss(IDialogInterface dialog)
{
_callback?.Invoke();
}
}
private readonly WeakReference<Context> _activity;
public DialogService(Context activity)
{
_activity = new WeakReference<Context>(activity);
}
public async Task<ConfirmationResult> ConfirmAsync(string title, string message, string acceptText, string declineText)
{
Context target;
if (!_activity.TryGetTarget(out target))
return ConfirmationResult.Cancel;
TaskCompletionSource<ConfirmationResult> tcs = new TaskCompletionSource<ConfirmationResult>();
var builder = new AlertDialog.Builder(target);
var d = builder
.SetTitle(title)
.SetMessage(message)
.SetPositiveButton(acceptText, (sender, args) =>
{
tcs.SetResult(ConfirmationResult.Yes);
(sender as AlertDialog)?.Dispose();
})
.SetNegativeButton(declineText, (sender, args) =>
{
tcs.SetResult(ConfirmationResult.No);
(sender as AlertDialog)?.Dispose();
})
// if this line is uncommented my application crashes once the dialog is opened
// .SetOnCancelListener(new DismissDelegateListener(() => { tcs.SetResult(ConfirmationResult.Cancel); }))
.Create();
d.Show();
return await tcs.Task;
}
}
As soon as i call SetOnCancelListener my application will crash with the error message System.InvalidCastException: Specified cast is not valid.
To me everything appears to be correct - i am passing an implementation of the requested interface and my implementation isn't all that difficult either.
Does this problem ring a bell to anyone?
Deriving from Java.Lang.Object was the solution.
class DismissDelegateListener : Java.Lang.Object, IDialogInterfaceOnDismissListener, IDialogInterfaceOnCancelListener
//class DismissDelegateListener : IDialogInterfaceOnDismissListener, IDialogInterfaceOnCancelListener
{
private Action _callback;
public DismissDelegateListener()
{
}
public DismissDelegateListener(Action callback)
{
_callback = callback;
}
protected override void Dispose(bool disposing)
{
_callback = null;
base.Dispose(disposing);
}
public void OnCancel(IDialogInterface dialog)
{
_callback?.Invoke();
}
public void OnDismiss(IDialogInterface dialog)
{
_callback?.Invoke();
}
}

Android comunicate between library and app

I'm creating a library in Android and I want to pass some values (strings) from the library to the app that is using the library after some events. The app that uses the library has only one screen to display the strings sent by the library.
My app has a MainActivity that will populate an listView with the events received by the library.
It also have an MyApp that extends Application.
Here I'm doing this:
public class MyApp extends Application{
private static MyApp sMyApp;
public MyApp() {
}
#Override
public void onCreate() {
super.onCreate();
sMyApp= this;
MyLibrary.getInstance().setApplication(sMyApp);
}
public static MyApp getInstance() {
return sMyApp;
}
}
In my library:
public class MyLibrary {
private static MyLibrary sInstance = new MyLibrary();
private Application mMyApp;
public static MyLibrary getInstance() {
return sInstance;
}
private MyLibrary() {
}
public void setApplication(Application myApp) {
mMyApp = myApp;
}
public void sendEventMessage(String message) {
mMyApp.setEvent(message);
}
}
I've tried to implement an interface in MainActivity so that mMyApp.setEvent(message); could send a message that MainActivity could receive but with no success.
How can I achieve what I pretend?
You could try callback as this sample:
Firstly, declare your callback inside library
public interface ILibrary {
public void onStart(String msg);
public void onProcess(String msg);
public void onFish(String msg);}
public class SDK {
private static final String START = "I'm started";
private static final String PROCESSING = "I'm running";
private static final String STOP = "I'm done";
private ILibrary mCallback;
// Make it easy for demo
public SDK(ILibrary callback) {
mCallback = callback;
}
public void start() {
mCallback.onStart(START);
}
public void process() {
mCallback.onProcess(PROCESSING);
}
public void stop() {
mCallback.onFish(STOP);
}}
And then do something like that:
SDK sdk = new SDK(new ILibrary() {
#Override
public void onStart(String msg) {
Log.d("TAG", msg);
}
#Override
public void onProcess(String msg) {
Log.d("TAG", msg);
}
#Override
public void onFish(String msg) {
Log.d("TAG", msg);
}
});
AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
sdk.process();
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
sdk.stop();
}
#Override
protected void onPreExecute() {
super.onPreExecute();
sdk.start();
}
};
asyncTask.execute();

Categories

Resources