use of com.facebook.react.bridge.WritableNativeArray in project maps by rnmapbox.
the class RCTMGLMapView method getCenter.
public void getCenter(String callbackID) {
LatLng center = mMap.getCameraPosition().target;
WritableArray array = new WritableNativeArray();
array.pushDouble(center.getLongitude());
array.pushDouble(center.getLatitude());
WritableMap payload = new WritableNativeMap();
payload.putArray("center", array);
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
mManager.handleEvent(event);
}
use of com.facebook.react.bridge.WritableNativeArray in project maps by rnmapbox.
the class RCTMGLMapView method getCoordinateFromView.
public void getCoordinateFromView(String callbackID, PointF pointInView) {
float density = getDisplayDensity();
pointInView.x *= density;
pointInView.y *= density;
LatLng mapCoordinate = mMap.getProjection().fromScreenLocation(pointInView);
WritableMap payload = new WritableNativeMap();
WritableArray array = new WritableNativeArray();
array.pushDouble(mapCoordinate.getLongitude());
array.pushDouble(mapCoordinate.getLatitude());
payload.putArray("coordinateFromView", array);
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
mManager.handleEvent(event);
}
use of com.facebook.react.bridge.WritableNativeArray in project react-native-yamap by volga-volga.
the class YamapView method convertRouteSection.
private WritableMap convertRouteSection(Route route, final Section section, Polyline geometry, Weight routeWeight, int routeIndex) {
SectionMetadata.SectionData data = section.getMetadata().getData();
WritableMap routeMetadata = Arguments.createMap();
WritableMap routeWeightData = Arguments.createMap();
WritableMap sectionWeightData = Arguments.createMap();
Map<String, ArrayList<String>> transports = new HashMap<>();
routeWeightData.putString("time", routeWeight.getTime().getText());
routeWeightData.putInt("transferCount", routeWeight.getTransfersCount());
routeWeightData.putDouble("walkingDistance", routeWeight.getWalkingDistance().getValue());
sectionWeightData.putString("time", section.getMetadata().getWeight().getTime().getText());
sectionWeightData.putInt("transferCount", section.getMetadata().getWeight().getTransfersCount());
sectionWeightData.putDouble("walkingDistance", section.getMetadata().getWeight().getWalkingDistance().getValue());
routeMetadata.putMap("sectionInfo", sectionWeightData);
routeMetadata.putMap("routeInfo", routeWeightData);
routeMetadata.putInt("routeIndex", routeIndex);
final WritableArray stops = new WritableNativeArray();
for (RouteStop stop : section.getStops()) {
stops.pushString(stop.getStop().getName());
}
routeMetadata.putArray("stops", stops);
if (data.getTransports() != null) {
for (Transport transport : data.getTransports()) {
for (String type : transport.getLine().getVehicleTypes()) {
if (type.equals("suburban"))
continue;
if (transports.get(type) != null) {
ArrayList<String> list = transports.get(type);
if (list != null) {
list.add(transport.getLine().getName());
transports.put(type, list);
}
} else {
ArrayList<String> list = new ArrayList<>();
list.add(transport.getLine().getName());
transports.put(type, list);
}
routeMetadata.putString("type", type);
int color = Color.BLACK;
if (transportHasStyle(transport)) {
try {
color = transport.getLine().getStyle().getColor();
} catch (Exception ignored) {
}
}
routeMetadata.putString("sectionColor", formatColor(color));
}
}
} else {
routeMetadata.putString("sectionColor", formatColor(Color.DKGRAY));
if (section.getMetadata().getWeight().getWalkingDistance().getValue() == 0) {
routeMetadata.putString("type", "waiting");
} else {
routeMetadata.putString("type", "walk");
}
}
WritableMap wTransports = Arguments.createMap();
for (Map.Entry<String, ArrayList<String>> entry : transports.entrySet()) {
wTransports.putArray(entry.getKey(), Arguments.fromList(entry.getValue()));
}
routeMetadata.putMap("transports", wTransports);
Polyline subpolyline = SubpolylineHelper.subpolyline(route.getGeometry(), section.getGeometry());
List<Point> linePoints = subpolyline.getPoints();
WritableArray jsonPoints = Arguments.createArray();
for (Point point : linePoints) {
WritableMap jsonPoint = Arguments.createMap();
jsonPoint.putDouble("lat", point.getLatitude());
jsonPoint.putDouble("lon", point.getLongitude());
jsonPoints.pushMap(jsonPoint);
}
routeMetadata.putArray("points", jsonPoints);
return routeMetadata;
}
use of com.facebook.react.bridge.WritableNativeArray in project react-native-yamap by volga-volga.
the class YamapView method convertDrivingRouteSection.
private WritableMap convertDrivingRouteSection(DrivingRoute route, final DrivingSection section, int routeIndex) {
com.yandex.mapkit.directions.driving.Weight routeWeight = route.getMetadata().getWeight();
WritableMap routeMetadata = Arguments.createMap();
WritableMap routeWeightData = Arguments.createMap();
WritableMap sectionWeightData = Arguments.createMap();
Map<String, ArrayList<String>> transports = new HashMap<>();
routeWeightData.putString("time", routeWeight.getTime().getText());
routeWeightData.putString("timeWithTraffic", routeWeight.getTimeWithTraffic().getText());
routeWeightData.putDouble("distance", routeWeight.getDistance().getValue());
sectionWeightData.putString("time", section.getMetadata().getWeight().getTime().getText());
sectionWeightData.putString("timeWithTraffic", section.getMetadata().getWeight().getTimeWithTraffic().getText());
sectionWeightData.putDouble("distance", section.getMetadata().getWeight().getDistance().getValue());
routeMetadata.putMap("sectionInfo", sectionWeightData);
routeMetadata.putMap("routeInfo", routeWeightData);
routeMetadata.putInt("routeIndex", routeIndex);
final WritableArray stops = new WritableNativeArray();
routeMetadata.putArray("stops", stops);
routeMetadata.putString("sectionColor", formatColor(Color.DKGRAY));
if (section.getMetadata().getWeight().getDistance().getValue() == 0) {
routeMetadata.putString("type", "waiting");
} else {
routeMetadata.putString("type", "car");
}
WritableMap wTransports = Arguments.createMap();
routeMetadata.putMap("transports", wTransports);
Polyline subpolyline = SubpolylineHelper.subpolyline(route.getGeometry(), section.getGeometry());
List<Point> linePoints = subpolyline.getPoints();
WritableArray jsonPoints = Arguments.createArray();
for (Point point : linePoints) {
WritableMap jsonPoint = Arguments.createMap();
jsonPoint.putDouble("lat", point.getLatitude());
jsonPoint.putDouble("lon", point.getLongitude());
jsonPoints.pushMap(jsonPoint);
}
routeMetadata.putArray("points", jsonPoints);
return routeMetadata;
}
use of com.facebook.react.bridge.WritableNativeArray in project aurora-imui by jpush.
the class ReactChatInputManager method createViewInstance.
@Override
protected ChatInputView createViewInstance(final ThemedReactContext reactContext) {
mContext = reactContext;
final SharedPreferences sp = reactContext.getSharedPreferences(AURORA_IMUI_SHARED_PREFERENCES, Context.MODE_PRIVATE);
mSoftKeyboardHeight = sp.getInt(SOFT_KEYBOARD_HEIGHT, 0);
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
final Activity activity = reactContext.getCurrentActivity();
mChatInput = new ChatInputView(activity, null);
final EditText editText = mChatInput.getInputView();
editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_TOUCH_EDIT_TEXT_EVENT, null);
if (!mChatInput.isFocused()) {
EmoticonsKeyboardUtils.openSoftKeyboard(mChatInput.getInputView());
}
EventBus.getDefault().post(new ScrollEvent(true));
int height = mChatInput.getSoftKeyboardHeight();
if (mSoftKeyboardHeight != height && height != 0 && height < 1000) {
mSoftKeyboardHeight = mChatInput.getSoftKeyboardHeight();
SharedPreferences.Editor editor = sp.edit();
editor.putInt(SOFT_KEYBOARD_HEIGHT, mSoftKeyboardHeight);
editor.commit();
}
}
return false;
}
});
editText.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
editText.getViewTreeObserver().removeGlobalOnLayoutListener(this);
mWidth = editText.getWidth();
}
});
DisplayMetrics dm = new DisplayMetrics();
reactContext.getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
mDensity = dm.density;
mScreenWidth = dm.widthPixels;
mMenuContainerHeight = (int) (mMenuContainerHeight / mDensity);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
WritableMap event = Arguments.createMap();
double layoutHeight = calculateMenuHeight();
mInitState = false;
event.putDouble("height", layoutHeight);
editText.setLayoutParams(new LinearLayout.LayoutParams(editText.getWidth(), (int) (mCurrentInputHeight)));
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, event);
}
});
// Use default layout
mChatInput.setMenuClickListener(new OnMenuClickListener() {
@Override
public boolean onSendTextMessage(CharSequence input) {
if (input.length() == 0) {
return false;
}
// WritableMap map = Arguments.createMap();
// map.putDouble("height", mInitialChatInputHeight);
// reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, map);
WritableMap event = Arguments.createMap();
event.putString("text", input.toString());
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_SEND_TEXT_EVENT, event);
return true;
}
@Override
public void onSendFiles(List<FileItem> list) {
if (list == null || list.isEmpty()) {
return;
}
WritableMap event = Arguments.createMap();
WritableArray array = new WritableNativeArray();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
for (FileItem fileItem : list) {
WritableMap map = new WritableNativeMap();
if (fileItem.getType().ordinal() == 0) {
map.putString("mediaType", "image");
BitmapFactory.decodeFile(fileItem.getFilePath(), options);
map.putInt("width", options.outWidth);
map.putInt("height", options.outHeight);
} else {
map.putString("mediaType", "video");
map.putInt("duration", (int) ((VideoItem) fileItem).getDuration());
}
map.putDouble("size", fileItem.getLongFileSize());
map.putString("mediaPath", fileItem.getFilePath());
array.pushMap(map);
}
event.putArray("mediaFiles", array);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_SEND_FILES_EVENT, event);
}
@Override
public boolean switchToMicrophoneMode() {
String[] perms = new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE };
if (!EasyPermissions.hasPermissions(activity, perms)) {
EasyPermissions.requestPermissions(activity, activity.getResources().getString(R.string.rationale_record_voice), RC_RECORD_VOICE, perms);
}
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), SWITCH_TO_MIC_EVENT, null);
// If menu is visible, close menu.
if (mLastClickId == 0 && mShowMenu) {
mShowMenu = false;
mChatInput.dismissMenuLayout();
mChatInput.dismissRecordVoiceLayout();
sendSizeChangedEvent(mInitialChatInputHeight + mLineExpend);
} else if (mShowMenu) {
mChatInput.showMenuLayout();
mChatInput.showRecordVoiceLayout();
mChatInput.requestLayout();
} else {
mShowMenu = true;
// mChatInput.setPendingShowMenu(true);
EmoticonsKeyboardUtils.closeSoftKeyboard(editText);
sendSizeChangedEvent(calculateMenuHeight());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mChatInput.showMenuLayout();
mChatInput.showRecordVoiceLayout();
mChatInput.requestLayout();
}
}, 150);
}
mLastClickId = 0;
return false;
}
@Override
public boolean switchToGalleryMode() {
String[] perms = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE };
if (!EasyPermissions.hasPermissions(activity, perms)) {
EasyPermissions.requestPermissions(activity, activity.getResources().getString(R.string.rationale_photo), RC_SELECT_PHOTO, perms);
return false;
}
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), SWITCH_TO_GALLERY_EVENT, null);
if (mLastClickId == 1 && mShowMenu) {
mShowMenu = false;
mChatInput.dismissMenuLayout();
mChatInput.dismissPhotoLayout();
sendSizeChangedEvent(mInitialChatInputHeight + mLineExpend);
} else if (mShowMenu) {
mChatInput.getSelectPhotoView().updateData();
mChatInput.showMenuLayout();
mChatInput.showSelectPhotoLayout();
mChatInput.requestLayout();
} else {
mChatInput.getSelectPhotoView().updateData();
mShowMenu = true;
// mChatInput.setPendingShowMenu(true);
EmoticonsKeyboardUtils.closeSoftKeyboard(editText);
sendSizeChangedEvent(calculateMenuHeight());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mChatInput.showMenuLayout();
mChatInput.showSelectPhotoLayout();
mChatInput.requestLayout();
}
}, 150);
}
mLastClickId = 1;
return false;
}
@Override
public boolean switchToCameraMode() {
String[] perms = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO };
if (!EasyPermissions.hasPermissions(activity, perms)) {
EasyPermissions.requestPermissions(activity, activity.getResources().getString(R.string.rationale_camera), RC_CAMERA, perms);
return false;
}
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), SWITCH_TO_CAMERA_EVENT, null);
if (mLastClickId == 2 && mShowMenu) {
mShowMenu = false;
mChatInput.dismissMenuLayout();
mChatInput.dismissCameraLayout();
sendSizeChangedEvent(mInitialChatInputHeight + mLineExpend);
} else if (mShowMenu) {
mChatInput.initCamera();
mChatInput.showMenuLayout();
mChatInput.showCameraLayout();
mChatInput.requestLayout();
} else {
mShowMenu = true;
// mChatInput.setPendingShowMenu(true);
mChatInput.initCamera();
EmoticonsKeyboardUtils.closeSoftKeyboard(editText);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mChatInput.showMenuLayout();
mChatInput.showCameraLayout();
sendSizeChangedEvent(calculateMenuHeight());
mChatInput.requestLayout();
}
}, 100);
}
mLastClickId = 2;
return false;
}
@Override
public boolean switchToEmojiMode() {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), SWITCH_TO_EMOJI_EVENT, null);
if (mLastClickId == 3 && mShowMenu) {
mShowMenu = false;
mChatInput.dismissMenuLayout();
mChatInput.dismissEmojiLayout();
sendSizeChangedEvent(mInitialChatInputHeight + mLineExpend);
} else if (mShowMenu) {
mChatInput.showMenuLayout();
mChatInput.showEmojiLayout();
mChatInput.requestLayout();
} else {
mShowMenu = true;
// mChatInput.setPendingShowMenu(true);
EmoticonsKeyboardUtils.closeSoftKeyboard(editText);
sendSizeChangedEvent(calculateMenuHeight());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mChatInput.showMenuLayout();
mChatInput.showEmojiLayout();
mChatInput.requestLayout();
}
}, 150);
}
mLastClickId = 3;
return false;
}
});
mChatInput.setOnCameraCallbackListener(new OnCameraCallbackListener() {
@Override
public void onTakePictureCompleted(String photoPath) {
if (mLastPhotoPath.equals(photoPath)) {
return;
}
mLastPhotoPath = photoPath;
mContext.runOnUiQueueThread(new Runnable() {
@Override
public void run() {
if (mChatInput.isFullScreen()) {
mChatInput.dismissCameraLayout();
}
mChatInput.dismissMenuLayout();
}
});
WritableMap event = Arguments.createMap();
event.putString("mediaPath", photoPath);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(photoPath, options);
event.putInt("width", options.outWidth);
event.putInt("height", options.outHeight);
File file = new File(photoPath);
event.putDouble("size", file.length());
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), TAKE_PICTURE_EVENT, event);
}
@Override
public void onStartVideoRecord() {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), START_RECORD_VIDEO_EVENT, null);
}
@Override
public void onFinishVideoRecord(String videoPath) {
if (videoPath != null) {
WritableMap event = Arguments.createMap();
event.putString("mediaPath", videoPath);
MediaPlayer mediaPlayer = MediaPlayer.create(reactContext, Uri.parse(videoPath));
// Millisecond to second.
int duration = mediaPlayer.getDuration() / 1000;
mediaPlayer.release();
File file = new File(videoPath);
event.putDouble("size", file.length());
event.putInt("duration", duration);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), FINISH_RECORD_VIDEO_EVENT, event);
}
}
@Override
public void onCancelVideoRecord() {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), CANCEL_RECORD_VIDEO_EVENT, null);
}
});
mChatInput.setRecordVoiceListener(new RecordVoiceListener() {
@Override
public void onStartRecord() {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), START_RECORD_VOICE_EVENT, null);
File rootDir = reactContext.getFilesDir();
String fileDir = rootDir.getAbsolutePath() + "/voice";
mChatInput.getRecordVoiceButton().setVoiceFilePath(fileDir, DateFormat.format("yyyy_MMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + "");
}
@Override
public void onFinishRecord(File voiceFile, int duration) {
WritableMap event = Arguments.createMap();
event.putString("mediaPath", voiceFile.getAbsolutePath());
event.putInt("duration", duration);
event.putDouble("size", voiceFile.length());
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), FINISH_RECORD_VOICE_EVENT, event);
}
@Override
public void onCancelRecord() {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), CANCEL_RECORD_VOICE_EVENT, null);
}
@Override
public void onPreviewCancel() {
}
@Override
public void onPreviewSend() {
sendSizeChangedEvent(mInitialChatInputHeight + mLineExpend);
}
});
mChatInput.setCameraControllerListener(new CameraControllerListener() {
@Override
public void onFullScreenClick() {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_FULL_SCREEN_EVENT, null);
}
@Override
public void onRecoverScreenClick() {
mShowMenu = false;
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_RECOVER_SCREEN_EVENT, null);
WritableMap map = Arguments.createMap();
Log.e(REACT_CHAT_INPUT, "send onSizeChangedEvent to js, height: " + mInitialChatInputHeight + mLineExpend);
map.putDouble("height", mInitialChatInputHeight + mLineExpend);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, map);
}
@Override
public void onCloseCameraClick() {
mShowMenu = false;
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), CLOSE_CAMERA_EVENT, null);
}
@Override
public void onSwitchCameraModeClick(boolean isRecordVideoMode) {
WritableMap map = Arguments.createMap();
map.putBoolean("isRecordVideoMode", isRecordVideoMode);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), SWITCH_CAMERA_MODE_EVENT, map);
}
});
mChatInput.getSelectAlbumBtn().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_CLICK_SELECT_ALBUM_EVENT, null);
}
});
mChatInput.getEmojiContainer().getEmoticonsFuncView().addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
Log.e(REACT_CHAT_INPUT, "EmotionPage Position" + position);
mChatInput.requestLayout();
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
return mChatInput;
}
Aggregations