I wish to ask is there anyone face the problem when you guys activate showCamera and open photo Gallery function of titanium in android. It will crash the app and restart app automatically. I have searched a lot of forum especially JIRA appcelator and titanium forum but most of the cases are unresolved. I have tried a lot of method in the forum but still the same. I wish to know is this a bug of titanium?
The best code to choose from camera or gallery
//Create a dialog with options
var dialog = Titanium.UI.createOptionDialog({
//title of dialog
title: 'Choose an image source...',
//options
options: ['Camera','Photo Gallery', 'Cancel'],
//index of cancel button
cancel:2
});
//add event listener
dialog.addEventListener('click', function(e) {
//if first option was selected
if(e.index == 0)
{
//then we are getting image from camera
Titanium.Media.showCamera({
//we got something
success:function(event)
{
//getting media
var image = event.media;
//checking if it is photo
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
//we may create image view with contents from image variable
//or simply save path to image
Ti.App.Properties.setString("image", image.nativePath);
}
},
cancel:function()
{
//do somehting if user cancels operation
},
error:function(error)
{
//error happend, create alert
var a = Titanium.UI.createAlertDialog({title:'Camera'});
//set message
if (error.code == Titanium.Media.NO_CAMERA)
{
a.setMessage('Device does not have camera');
}
else
{
a.setMessage('Unexpected error: ' + error.code);
}
// show alert
a.show();
},
allowImageEditing:true,
saveToPhotoGallery:true
});
}
else if(e.index == 1)
{
//obtain an image from the gallery
Titanium.Media.openPhotoGallery({
success:function(event)
{
//getting media
var image = event.media;
// set image view
//checking if it is photo
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
//we may create image view with contents from image variable
//or simply save path to image
Ti.App.Properties.setString("image", image.nativePath);
}
},
cancel:function()
{
//user cancelled the action fron within
//the photo gallery
}
});
}
else
{
//cancel was tapped
//user opted not to choose a photo
}
});
//show dialog
dialog.show();
Thanks
I'm using this code for opening the camera and it works correctly:
Titanium.Media.showCamera({
success:function(event)
{
//getting media
var image = event.media;
im=image;
//checking if it is photo
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
imgpath= image.nativePath;
$.userphoto.image=imgpath;//$.userphoto is an imageview
}
},
cancel:function()
{
//do somehting
},
error:function(error)
{
//error happened,
var a = Titanium.UI.createAlertDialog({title:'Camera'});
//set message
if (error.code == Titanium.Media.NO_CAMERA)
{
alert('No Cam');
}
else
{
alert('error');
}
},
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
}
and this is the code i use for opening the photo gallery (also works fine):
Titanium.Media.openPhotoGallery({
success:function(event)
{
//check if photo
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
im=resize(event.media); //just a function to resize the photo
imgpath= event.media.nativePath;
$.userphoto.image=imgpath;
}
},
cancel:function()
{
//user cancelled
}
});
By the way now i'm using Titanium SDK 3.4.1 GA, but it also used to work on 3.1.3GA
Related
I'm working on a project that use Firebase Storage and Firestore. I added function that allows to upload images from phone gallery to Storage and storage url of this image is saved in Firestore with some other informations. Everything works fine, even the image url in firestore displays selected image correctly in browser. The problem is when i try to set this image to ImageView using Glide or Picasso, because it only shows a blank image/placeholder. This is how my repository functions looks to add and download data:
override fun addProject(uri: Uri, project: Project) {
val imagesRef = storage.reference.child("images/${uri.lastPathSegment}")
Log.d("firebase ref url", imagesRef.toString())
imagesRef.putFile(uri).addOnCompleteListener {
Log.d("firebase image", "Succesfully uploaded")
imagesRef.downloadUrl.addOnSuccessListener { uri->
project.photoUrl = uri.toString()
db.collection("projects").add(project)
}
}.addOnFailureListener {
Log.d("firebase image", "Unsuccessfully uploaded")
}
}
override suspend fun getProjects(): List<Project> {
val projectList = mutableListOf<Project>()
val projectRef = db.collection("projects")
val snapshot = projectRef.get().await()
val docs = snapshot.documents
docs.forEach {
val project = it.toObject(Project::class.java)
if (project != null) {
projectList.add(project)
Log.d("firebase listen", projectList.toString())
}
}
return projectList
}
firebase storage
firebase firestore
After i retrieve all projects with their photoUrl and other informations i want to display them in recycler view using ListAdapter. Title and description are displayed correctly in every recycler view item but it seems like this url can't be accessed by glide/ picasso . There is also a log line which shows photoUrl and if I click on it from logcat the browser displays correct image.
fun bind(project: Project) {
binding.apply {
Log.d("recycler view url", project.photoUrl)
// Picasso.get().load(project.photoUrl).into(projectIv)
Glide.with(binding.root).load(project.photoUrl).into(projectIv)
titleTv.text = project.name
descriptionTv.text = project.description
}
binding.executePendingBindings()
}
I have found some related topics but still haven't found working solution to that problem.
EDIT
Log result inside recyclerview bind method:
Log resylt
After clicking on link:
Link result
How it looks in my app:
app screenshot 1
app screenshot 2
It looks like it only takes the photo size parameters but can't resolve the photo content, but i'm not sure
I am trying to write a macro, which embed draw.io. when user double click the diagram image I want to open draw.io in aonther window and get image data back as text. but my javascript inside macro not working at all.
It seems my javascript code in macro is not executed at all, can somebody tell me the right way to inject javascrpt code inside a velocity macro?
updates: I have noticed that when editing in CKEditor, my javascript code will not be executed, bu when editing in inline editor it will be executed.
{{velocity}}
$wikimacro.content
#if($wikimacro.content == '')
#set ($wikimacro.content = 'iVBORw0KGgoAAAANSUhEUgAAAIMAAABHCAYAAAAk5PTEAAAC4HRFWHRteGZpbGUAJTNDbXhmaWxlJTIwaG9zdCUzRCUyMjE3Mi4yNS4xNjEuMjExJTIyJTIwbW9kaWZpZWQlM0QlMjIyMDIxLTExLTA4VDA3JTNBNDglM0EzMC4wMzdaJTIyJTIwYWdlbnQlM0QlMjI1LjAlMjAoWDExKSUyMiUyMGV0YWclM0QlMjJ4MTM1OUpQR29sZ21udEFCTFIxSCUyMiUyMHZlcnNpb24lM0QlMjIxNS42LjIlMjIlMjB0eXBlJTNEJTIyZGV2aWNlJTIyJTNFJTNDZGlhZ3JhbSUyMGlkJTNEJTIyNEd0aVp4cWRuemJnanpmMC0zXzElMjIlMjBuYW1lJTNEJTIyUGFnZS0xJTIyJTNFalpKTlQ4UWdFSVolMkZUWThtTFdqdFhsMjdidHg0cXNaNEpHVXNKTFEwTEYxYWY3MVVwbCUyRlpiT0tKNFprUFp0NGhvdnU2ZnpHc0ZXJTJCYWc0cEl6UHVJUGtlRWtEZ2wlMkZoakpFRWlTa0N5UXlraU9iQUdGJTJGQUdFTWRKT2NqaHZBcTNXeXNwMkMwdmRORkRhRFdQR2FMY04lMkI5WnElMkIyckxLcmdDUmNuVU5mMlUzSXBBTSUyRks0OENQSVNrd3ZKJTJCa3VlR28yQmVNa1o4RzRkaXRFODRqdWpkWTJXSFclMkZCeldxTiUyQmtTOGc0M3ZITmpCaHI3bjRRRFl6S1Z1OVBISlQ5JTJCdVpOOUw5enJIVmE1TU5YaHdOaXNIU1lGak80YURtT1JPS0pQVGtnTFJjdkswZXY4MGowVHRsYiUyQmxuZ1R5NEd4ME4lMkZzTTVtbjklMkY4R2RBM1dERDRFRSUyQmpEZlVqQkwwTXpGTkF0JTJCaWVUcUdLbGZZcU00Y3FydWZTaWlqZFFtT202TE9EUHQlMkZySE5QOEYlM0MlMkZkaWFncmFtJTNFJTNDJTJGbXhmaWxlJTNFUXJoXAAAAKNJREFUeJzt0rENACEQwDD2X5rvUoOe6mRL2SBrAQDAA1vjO7aZywzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzEDMQMxAzkegaNDwAA/vkAmk+zV9RvOdkAAAAASUVORK5CYII=')
#end
#if($xcontext.action == 'edit')
{{html}}
<img
class="drawio"
style="cursor: default"
src="data:image/png;base64,$wikimacro.content"
/>
<script>
//<![CDATA[
document.addEventListener('dblclick', function(evt)
{
var url = 'http://172.25.161.211/?embed=1&ui=atlas&spin=1&modified=unsavedChanges&proto=json';
var source = evt.srcElement || evt.target;
if (source.nodeName == 'IMG' && source.className == 'drawio'){
if (source.drawIoWindow == null || source.drawIoWindow.closed) {
// Implements protocol for loading and exporting with embedded XML
var receive = function(evt) {
if (evt.data.length > 0 && evt.source == source.drawIoWindow) {
var msg = JSON.parse(evt.data);
// Received if the editor is ready
if (msg.event == 'init') {
// Sends the data URI with embedded XML to editor
source.drawIoWindow.postMessage(JSON.stringify({action: 'load', xmlpng: source.getAttribute('src')}), '*');
}
// Received if the user clicks save
else if (msg.event == 'save')
{
// Sends a request to export the diagram as XML with embedded PNG
source.drawIoWindow.postMessage(JSON.stringify(
{action: 'export', format: 'xmlpng', spinKey: 'saving'}), '*');
}
// Received if the export request was processed
else if (msg.event == 'export')
{
// Updates the data URI of the image
// TODO save to xwiki server as macro's content
source.setAttribute('src', msg.data);
}
// Received if the user clicks exit or after export
if (msg.event == 'exit' || msg.event == 'export')
{
// Closes the editor
window.removeEventListener('message', receive);
source.drawIoWindow.close();
source.drawIoWindow = null;
}
}
};
// Opens the editor
window.addEventListener('message', receive);
source.drawIoWindow = window.open(url);
}
else
{
// Shows existing editor window
source.drawIoWindow.focus();
}
}
});
// ]]>
</script>
{{/html}}
#else
{{html}}
<img src="data:image/png;base64,$wikimacro.content" />
{{/html}}
#end
{{/velocity}}
In XWiki the insertion of web resources like css and js content is generally done separately through what is called "skin extensions", best is probably to look at the documentation on https://extensions.xwiki.org/xwiki/bin/view/Extension/Skin%20Extension%20Plugin.
In short, it involves adding an object of type XWiki.JavaScriptExtention in the page holding your macro and reference to it in your macro's code.
Note that an extension which integrate draw.io already exist on https://extensions.xwiki.org/xwiki/bin/view/Extension/Diagram%20Application, and I guess looking at the source of this extension might be interesting.
I'm working on a swiftUI app where I have to display multiple PDF files in one screen.
I've created a PDFView:
struct PDFKitRepresentedView: UIViewRepresentable {
let url: URL
init(_ url: URL) {
self.url = url
}
func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
let pdfView = PDFView()
let pdfDocument = PDFDocument(url: self.url)
pdfView.document = pdfDocument
return pdfView
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {
// Update the view.
}
}
struct PDFKitView: View {
var url: URL
var body: some View {
PDFKitRepresentedView(url)
}
}
The PDF is created here:
if let url = attachment.path {
PDFKitView(url: url)
.frame(width: UIScreen.screenWidth - 40, height: UIScreen.screenHeight - 40, alignment: .center)
.padding()
}
The problem I'm having is that, whenever the first document is multipage, in order to see the other documents the user has first to pinch to zoom out completely and the other PDF's are shown in sequence.
I've tried to add this values, but that just makes the content of the PDF to disappear
I was wondering if setting the frame on the PDFKitView directly could be causing the issue, but no.
Anyone has any suggestions on how to make this work? I assume that if I could make the pdf to show already with a min zoom it would display the view correctly.
I finally found the answer on this post How to detect where NaN is passing to CoreGraphics API on Mac OS X 10.9
I've managed to get the camera going cross platform using xamarin and this tutorial:
Camera access with Xamarin.Forms
I'm now trying to get it working on a different navigation form (The camera functionality would be several forms away from the main page.) However the device specific code accesses many things wired up to the App instance which I'm struggling to wire up from another form. Does anyone know of a good camera example that isn't on the main page? I've been coding C# for years but I'm new to Xamarin and the camera stuff seems to be the hardest to get going. Thanks in advance.
Jeff
use the Media plugin
takePhoto.Clicked += async (sender, args) =>
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
if (file == null)
return;
await DisplayAlert("File Location", file.Path, "OK");
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
};
I am using Ti Studio 3.1.1 GA to build a native iOS app (6.1) integrated into facebook.
I am trying to post a story to one of my fan pages that I own.
The story is always written to "Recently posted by others" section in facebook than using the facebook page id.
fb.requestWithGraphPath('me/accounts', {}, 'GET', function(e) {
if (e.success) {
fb.permissions = ['publish_stream', 'read_stream','manage_pages'];
fb.authorize();
access_tokens = JSON.parse(e.result);
for (var i = 0; i < fanpages.length; i++) {
for ( var j=0; j < access_tokens.data.length; j++) {
if (fanpages[i].id === access_tokens.data[j].id){
var data = {
link: "http://www.example.co/index.html",
picture: returnedData[0].image, };
fb.requestWithGraphPath(fanpages[i].id + '/feed' , data, 'POST',showRequestResult);
}
}
}
}
});
}
If instead of 'link' above, if I have 'message' in the {data} section then it writes to the fanpage as page id but if I use 'link' then it writes in the 'Recent story by others' section...
When i tested the above functionality using the Tools->Graph API explorer from http://developers.facebook.com, by using the page id token then the story gets posted to the facebook fanpage as page id.
I am not sure how we can pass the page access token if its 'link'. Thought the above code is already passing the page access token....
Anyone has implemented or any ideas on how to go further?
Thanks in advance,
Regards, KP
have you tried just using the feed dialog API call?
http://docs.appcelerator.com/titanium/latest/#!/api/Modules.Facebook-method-dialog
Sample from Appcelerator Documentation
var data = {
link : "http://www.appcelerator.com",
name : "Appcelerator Titanium Mobile",
message : "Checkout this cool open source project for creating mobile apps",
caption : "Appcelerator Titanium Mobile",
picture : "http://developer.appcelerator.com/assets/img/DEV_titmobile_image.png",
description : "You've got the ideas, now you've got the power. Titanium translates " +
"your hard won web skills into native applications..."
};
fb.dialog("feed", data, function(e) {
if(e.success && e.result) {
alert("Success! New Post ID: " + e.result);
} else {
if(e.error) {
alert(e.error);
} else {
alert("User canceled dialog.");
}
}
});