appcelerator titanium iPhone twitter timeline resize - iphone

I'm working in appcelerator and I have a tab which is the profile. On the top half there is the profile picture, the name, and other misc items, then on the bottom half is a twitter timeline. When i started putting on the twitter timeline code, it takes up the whole screen. Is there a way to reduce the timeline to only take up a portion of the screen to be able to see the other items?
This is my twitter timeline code:
var twitterUserName = "foundationsix";
var httpClient = Ti.Network.createHTTPClient();
httpClient.timeout = 10000;
httpClient.open("GET","http://api.twitter.com/1/statuses/" +
"user_timeline.json?count=10&screen_name=" + twitterUserName);
var twitterData = [];
httpClient.onload = function() {
try {
var tweets = JSON.parse(this.responseText);
for (var i=0; i < tweets.length; i++) {
var tweetText = tweets[i].text;
var user = tweets[i].user.screen_name;
var avatar = tweets[i].user.profile_image_url;
var created_at = tweets[i].created_at;
var row = Ti.UI.createTableViewRow({hasChild:true,
height:'auto'});
var postView = Ti.UI.createView({
height:'55',
top:5,
bottom:5,
left:5,
right:5,
});
var avatarImageView = Ti.UI.createImageView({
image:avatar,
left:0,
top:0,
height:48,
width:48
});
postView.add(avatarImageView);
var userLabel = Ti.UI.createLabel({
text:user,
left:54,
width:120,
top:-48,
bottom:2,
height:16,
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:14,
fontWeight:'bold'}
});
postView.add(userLabel);
var dateLabel = Ti.UI.createLabel({
text:created_at,
right:0,
top:-18,
bottom:2,
height:14,
textAlign:'right',
width:110,
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:12}
});
postView.add(dateLabel);
var tweetTextLabel = Ti.UI.createLabel({
text:tweetText,
left:54,
top:0,
bottom:2,
height:'auto',
width:236,
textAlign:'left',
font:{fontSize:14}
});
postView.add(tweetTextLabel);
row.add(postView);
twitterData[i] = row;
}
var tableview = Titanium.UI.createTableView({data:twitterData,
minRowHeight:58});
win1.add(tableview);
}
catch(E) {
alert(E);
}
};
httpClient.send();

Please keep in mind .. We need to use either top and left or bottom and right.. dont mix up top and bottom in same element....
coming to solution to yours .. give top to table so that it goes down .......
i have created top view where you can specify username and etc
below you can post timeline
var win1=Ti.UI.createWindow()
///// this is top portion
var topView=Ti.UI.createView({
top:0,
left:0,
height:100,
background:"#2d2d2d"
})
var username=Ti.UI.createLabel({
text:"foundationsix",
color:"#fff"
})
topView.add(username)
win1.add(topView)
var twitterUserName = "foundationsix";
var httpClient = Ti.Network.createHTTPClient();
httpClient.timeout = 10000;
httpClient.open("GET","http://api.twitter.com/1/statuses/" + "user_timeline.json?count=10&screen_name=" + twitterUserName);
var twitterData = [];
httpClient.onload = function() {
try {
var tweets = JSON.parse(this.responseText);
for (var i=0; i < tweets.length; i++) {
var tweetText = tweets[i].text;
var user = tweets[i].user.screen_name;
var avatar = tweets[i].user.profile_image_url;
var created_at = tweets[i].created_at;
var row = Ti.UI.createTableViewRow({hasChild:true,
height:'auto'});
var postView = Ti.UI.createView({height:55});
var avatarImageView = Ti.UI.createImageView({
image:avatar,
left:0,
top:0,
height:48,
width:48
});
postView.add(avatarImageView);
var userLabel = Ti.UI.createLabel({
text:user,
left:54,
width:120,
top:-48,
bottom:2,
height:16,
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:14,
fontWeight:'bold'}
});
postView.add(userLabel);
var dateLabel = Ti.UI.createLabel({
text:created_at,
right:0,
top:-18,
bottom:2,
height:14,
textAlign:'right',
width:110,
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:12}
});
postView.add(dateLabel);
var tweetTextLabel = Ti.UI.createLabel({
text:tweetText,
left:54,
top:0,
bottom:2,
height:'auto',
width:236,
textAlign:'left',
font:{fontSize:14}
});
postView.add(tweetTextLabel);
row.add(postView);
twitterData[i] = row;
}
var tableview = Titanium.UI.createTableView({
data:twitterData,
minRowHeight:58,
top:100
});
win1.add(tableview);
}
catch(E) {
alert(E);
}
};
httpClient.send();
win1.open()

Related

Displaying image from device in ionic

Let's say I have an image under file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1542035689920.jpg path. Is it possible to display this image in <image> tag just by assigning .url property? Probably not, if so are there any good solutions to do it? I'm trying to do a thumbnail of an image in the list, the way I've done it is to read an image as base64, convert it with the usage of canvas then display it. Problem is it takes too much time to render all the images.
ionViewDidLoad() {
this.defectImages.forEach(defectImage => this.loadThumbnail(defectImage.url))
}
loadThumbnail(url) {
return this.fileProvider.getDefectCachedImage(url)
.then(data => {
return this.generateFromImage(data, 400, 400, 0.5, thumbnail => {
let image = document.getElementById(url) as any;
image.src = thumbnail;
})
});
}
showImage(url: string) {
this.photoViewer.show(this.fileProvider.getCacheFolderPath() + url, '', {share: true})
}
generateFromImage(img, MAX_WIDTH: number = 700, MAX_HEIGHT: number = 700, quality: number = 0.5, callback) {
var canvas: any = document.createElement("canvas");
var image = new Image();
image.onload = () => {
var width = image.width;
var height = image.height;
if (width > height) {
if (width > MAX_WIDTH) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if (height > MAX_HEIGHT) {
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
}
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0, width, height);
// IMPORTANT: 'jpeg' NOT 'jpg'
var dataUrl = canvas.toDataURL('image/jpeg', quality);
callback(dataUrl)
};
image.src = img;
}
It is working but working too slow. I have noticed PhotoLibrary package but as far I know it access to the shared memory and my pictures are being held in app only space.
This is the issue with the latest webview. The latest webview is not allowing the local resources to load. It was working fine on Ionic 2. Though not an optimal solution, I'm pasting the solution that worked for me.
ionic cordova plugins rm cordova-plugin-ionic-webview
ionic cordova plugins add cordova-plugin-ionic-webview#1.2.1
cordova clean android
And you can build(ionic cordova build android) the app and test it.

how to add flyout text to flyout in button programatically

Im a generating this button and i would like to set text in the flyout
var button = new Button();
button.Height = height;
button.Width = width;
button.Margin = new Thickness(left, top, 0, 0);
button.BorderBrush = new SolidColorBrush(Windows.UI.Colors.Red);
button.BorderThickness = new Thickness(2);
button.Background = new SolidColorBrush(Windows.UI.Colors.Transparent);
button.Flyout = new Flyout();
how do i set content of button.Flyout?
how do i set content of button.Flyout?
You could pass button instance to the follow method.
public void AddFlyoutToBtn(Button TargetBtn)
{
TargetBtn.Flyout = new Flyout()
{
Content = new StackPanel
{
Children =
{
new TextBlock
{
Text = "All items will be removed. Do you want to continue?",
Margin = new Thickness(10, 10, 0, 0)
},
new Button
{
Content = "Yes, empty my cart"
}
}
}
};
}

Adding array of images to the stage with easeljs and preloadjs

Different images should appear on stage. For this I am trying to create an array and put it in a container but id doesn't work. What am I doing wrong? Thanks
canvas = document.getElementById("testCanvas");
stage = new createjs.Stage(canvas);
var queue = new createjs.LoadQueue(true);
var imagesPic = queue.loadManifest(["image1.png", "image2.png","image3.png","image4.png"]);
var w = canvas.width = window.innerWidth;
var h = canvas.height = window.innerHeight;
container = new createjs.Container();
stage.addChild(container);
captureContainers = [];
captureIndex = 0;
for (var i=0; i<50; i++) {
container.addChild(imagesPic);
}
for (i=0; i<100; i++) {
var captureContainer = new createjs.Container();
captureContainer.cache(0,0,w,h);
captureContainers.push(captureContainer);
}

Titanium EventListener Not Working

I am new for Titanium and creating my dummy app for iPhone.
I was using this code from a tutorial.
But am stuck in 'itemSelected' eventListener, looks like not working here.
I have tried by adding button, label and their click events even they are not working.
I am not getting my mistake here.
So please advice.
Thanks in advance.
My ApplicationWindow.js is..
//Application Window Component Constructor
function ApplicationWindow() {
//declare module dependencies
var MasterView = require('ui/listView_common/MasterView'),
DetailView = require('ui/listView_common/DetailView');
//create object instance
var self = Ti.UI.createWindow({
backgroundColor:'#fff'
});
//construct UI
var masterView = new MasterView(),
detailView = new DetailView();
//create master view container
var masterContainerWindow = Ti.UI.createWindow({title:'List View'});
masterContainerWindow.add(masterView);
//create detail view container
var detailContainerWindow = Ti.UI.createWindow({left:100,title:'Detail View'});
detailContainerWindow.add(detailView);
//create iOS specific NavGroup UI
var navGroup = Ti.UI.iPhone.createNavigationGroup({
window:masterContainerWindow
});
self.add(navGroup);
//add behavior for master view
masterView.addEventListener('itemSelected', function(e) {
alert("Alert");
navGroup.open(detailContainerWindow);
detailView.showArticle(e.link);
});
function refreshData() {
var file = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory+'jsonFiles/data.json');
var data = file.read().text;
var json = JSON.parse(data);
masterView.refreshDataTable(json);
}
// load data
refreshData();
return self;
};
module.exports = ApplicationWindow;
and my 'MasterView.js' is..
var createRow = function(item) {
var tablerow = Ti.UI.createTableViewRow({
height: 90,
link: item.link,
className: 'itemRow',
hasChild: true
});
var imageview = Ti.UI.createImageView({
image: item.image,
height: 55,
width: 68,
left: 5,
top: 3
});
var titleview = Ti.UI.createLabel({
text: item.title,
color: '#000',
font: {
fontSize: 16
},
left: 83,
right: 5,
top:5,
width:300
});
var dateview = Ti.UI.createLabel({
text: item.pubDate,
textAlign: 'center',
color: '#444',
font: {
fontSize: 12
},
height: 'auto',
width: 68,
left: 5,
top: 60
});
var nameview = Ti.UI.createLabel({
text: item.firstName +" " + item.lastName,
color: '#000',
font: {
fontSize: 14
},
left: 83,
right: 5,
top:30
});
var descriptionview = Ti.UI.createLabel({
text: item.description,
color: '#000',
font: {
fontSize: 12
},
left: 83,
top:50
});
tablerow.add(imageview);
tablerow.add(dateview);
tablerow.add(titleview);
tablerow.add(nameview);
tablerow.add(descriptionview);
return tablerow;
};
//Master View Component Constructor
function MasterView() {
var self = Ti.UI.createView({
backgroundColor:'#fff'
});
var table = Ti.UI.createTableView();
self.add(table);
table.addEventListener('click', function(e) {
self.fireEvent('itemSelected', { link: e.row.link });
});
self.refreshDataTable = function(data) {
if (Object.prototype.toString.apply(data) === '[object Array]') {
var rows = [];
for (var i = 0; i < data.length; i++) {
rows.push(createRow(data[i]));
}
table.setData(rows);
}
};
return self;
}
module.exports = MasterView;
DetailView.js
//Detail View Component Constructor
function DetailView() {
var self = Ti.UI.createView();
var webview = Ti.UI.createWebView();
self.add(webview);
self.showArticle = function(url) {
webview.url = url;
};
webview.addEventListener('load', function(e) {
self.fireEvent('articleLoaded');
});
return self;
}
module.exports = DetailView;
itemSelected is not a event type of window. That's why it's not working.
Try the click event and get apiName and perform your work based on the apiName.
Example:
windowNAme.addEventListener('click',function(e){
//when we click on button then we get id from this
getId=e.source.id;
if(getId=="mybutton")
{
perform your action here;
}
})
Try to use Titanium.App.addEventListener in your code as follows
//add behavior for master view
Ti.App.addEventListener('itemSelected', function(e) {
alert("Alert");
navGroup.open(detailContainerWindow);
detailView.showArticle(e.link);
});
and fire the event like
table.addEventListener('click', function(e) {
Ti.App.fireEvent('itemSelected', { link: e.row.link });
});
This will do the trick
You may also refer what is fireevent how do i use it

Response is not working for the code in button action listener

var button = Ti.UI.createButton({
left: 180,
top: 180,
width: 100,
hight: 30,
title: 'Go'
});
self.add(button);
button.addEventListener('click', function() {
var xhr = Ti.Network.createHTTPClient();
var authstr = 'Basic ' +Titanium.Utils.base64encode('S0009231839'+':'+ 'm8390967743!');
xhr.open("GET","http://erp.esworkplace.sap.com/sap/bc/srt/wsdl/bndg_DF52FF9E9AF025F18F0400145E5ADE89/wsdl11/allinone/ws_policy/document?sap-client=800");
xhr.setRequestHeader('Authorization', authstr);
xhr.setRequestHeader('Content-Type','text/xml');
xhr.setRequestHeader('Accept-Language','en');
alert('show');
xhr.onload = function(e)
{ try
{
//get the xml data and let it roll!
var doc = this.responseXML.documentElement;
// var items = doc.getElementsByTagName("atom:entry");
var items = doc.getElementsByTagName("wsdl:portType");
for(var c=0; c<items.length;c++){
var item = items.item(c);
alert(items.length);
var attributeEmployeeLeave = items.item(c).attributes.getNamedItem("name").nodeValue;
Ti.API.info(items.item(c).attributes.getNamedItem("name").nodeValue);
}
}
catch(E)
{
alert('error on xhr');
}
The response for the button addEventListener is not working
I dont know why!
Any one can advice me!
Simple Button Example
var button = Titanium.UI.createButton({ title: 'Hello' });
button.addEventListener('click',function(e) {
Titanium.API.info("You clicked the button"); });
Please change your button.addEventListener('click', function() { to button.addEventListener('click', function(e) {.