My Glass app is very simple. I have one static card and I set its text and display it in the overridden "onCreate()" method of my Activity:
myCard.setText("First text");
View cardView = myCard.getView();
// Display the card we just created
setContentView(cardView);
I want to sleep for 5 seconds then display "Second Text" to the user. An earlier question on StackExchange discussed that you get a new view as above, and call setContentView() again.
This is fine so far, but my naive question is, where do I sleep and reset the content view? Obviously I can't sleep in "onCreate()" or "onStart()" of the activity, because the display has not been rendered for the user yet. I have a simple Service. In the service? Do I create a thread somewhere and use that? Thanks!
No need to start a new thread or sleep. You can do this with Android's Handler.postDelayed method, which posts a task to be executed on the UI thread at a later time.
public class MyActivity {
private Handler mHandler = new Handler();
#Override
protected boolean onCreate() {
myCard.setText("First text");
View cardView = myCard.getView();
// Display the card we just created
setContentView(cardView);
mHandler.postDelayed(new Runnable() {
#Override
public void run() {
updateCard();
}
}, 5000 /* 5 sec in millis */);
}
private void updateCard() {
// update the card with "Second text"
}
}
Related
I am very new sitecore, working with sitecore 7.
The question is when I am in a page editor, when I delete an item using the floating menu 'delete' function, It just deletes the item.
Customer requirement is to add a confirmation box here. Something like 'are you sure to delete'. and two typical buttons(yes/cancel).
is that even possible? any help would be appreciated.
EDIT:
In the picture below, The red cross, is a delete/remove button. If I click it just deletes. I want to show confirmation upon clicking the button.
EDIT 2:
Ok, I am writing a custom command.
I have added a new button. The target is this new button will ask if the user wants to remove the component or not. And if user says 'yes' it will do the same as the default built in remove button does.
Code:
public class RemoveWithNoti:Sitecore.Shell.Applications.WebEdit.Commands.WebEditCommand
{
public override void Execute(CommandContext context)
{
Context.ClientPage.Start(this, "Run", context.Parameters);
}
protected static void Run(ClientPipelineArgs args)
{
if (args.IsPostBack)
{
if (args.HasResult)
{
//Here I need to call "chrome:rendering:delete" this . I just dont know how to!!
}
}
else
{
SheerResponse.Confirm("Are you certain that you want to remove this component");
args.WaitForPostBack();
}
}
}
How do I call chrome:rendering:delete from code??
The "chrome:rendering:delete" event is handled on the client side by javascript. Here is the exact places:
/sitecore/shell/Applications/Page Modes/ChromeTypes/RenderingChromeType.js file:
handleMessage: function(message, params, sender) {
switch (message) {
...
case "chrome:rendering:delete":
this.deleteControl();
break;
...
},
You can do something like this in the same file:
deleteControl: function() {
if(confirm('Are you sure to remove this component?')){
var placeholder = this.getPlaceholder();
if (placeholder) {
placeholder.type.deleteControl(this.chrome);
}
}
}
I'm using Sitecore 8. I have custom ModalDialog, it is getting triggered by a button in the Ribbon (Content Editor).
On the Dialog backend, I'm removing the scope Item. So OnOk I want Refresh the Parent and load Parent item on dialog close.
I have the following code but it is not working,
protected override void OnOK(object sender, EventArgs args)
{
//ScopeItem - Current Item in the Content Tree
//db - Database
RemoveItem(ScopeItem, db);
//ScopeItemParent- Current Item's Parent Item
Context.ClientPage.SendMessage(this, string.Format("item:updated(id={0})", ScopeItemParent.ID));
Context.ClientPage.SendMessage(this, string.Format("item:refreshchildren(id={0})", ScopeItemParent.ID));
Context.ClientPage.ClientResponse.Timer(string.Format("item:load(id={0})", ScopeItemParent.ID), 100);
base.OnOK(sender, args);
}
Thanks for your help.
The normal Delete command does exactly that. It simply calls Sitecore.Shell.Framework.Items.Delete(), which then runs the uiDeleteItems client pipeline. You should be able to do the same by doing something like this:
protected override void OnOK(object sender, EventArgs args)
{
//ScopeItem - Current Item in the Content Tree
Sitecore.Shell.Framework.Items.Delete(new[] { ScopeItem });
base.OnOK(sender, args);
}
How do you update a Glass CardScrollView programatically in XE16 (KitKat)?
I have a CardScrollView of cards that display photos from url's. I download the photos from the url's in a background thread and then I want to "refresh" or update the CardScrolView to make the cards display the new images.
I was calling:
cardScrollView.updateViews(true);
In XE12, but in XE16/KitKat that operation is deprecated. So how do you download an image in the background and then update a displayed "Card" with that image? Just calling card.addImage() seems to add a blank image and doesn't display the image.
I've updated my call from the background thread to be:
cardScrollView.getAdapter().notifyDataSetChanged();
Here is the code for the card scroll adapter with
private class SpecialCardsScrollAdapter extends CardScrollAdapter {
#Override
public int getPosition(Object item) {
return specialCardsList.indexOf(item);
}
#Override
public int getCount() {
return specialCardsList.size();
}
#Override
public Object getItem(int position) {
return specialCardsList.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return specialCardsList.get(position).getView();
}
}
Should I expect that calling cardScrollView.getAdapter().notifyDataSetChanged(); would cause Cards already put into the scrollview to update the image they have stored?
As mentioned in the release notes, use BaseAdapter#notifyDataSetChanged() from your CardScrollAdapter instead.
I want to be able to right click on a content item in Sitecore and then select something like "Run My App" in the context menu. Then in the app that runs I need to be able to reference the content item that was right clicked. Is this possible?
Yes you can do this, its not as hard as it sounds.
You want to drop into the Core database and open up the content editor. The right click menu is defined within the sitecore/content/Applications/Content Editor/Context Menus/Default
The items within that folder are what you see when you right-click an item in the tree. So you can add a new item there with a template of Menu Item.
If you look at the existing ones, most of them send a message to the Sitecore Desktop. These messages are the commands defined in /App_Config/Commands.config. I can't see anything in there that would just launch another Sitecore application, so you would need to create a new command to do that. To create one, just inherit from the Sitecore.Shell.Framework.Commands.Command class. That passes in a CommandContext which will holds a collection of Items.
public class DemoCommand: Command
{
#region Overrides of Command
/// <summary>
/// Executes the command in the specified context.
/// </summary>
/// <param name="context">The context.</param>
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
var parameters = new NameValueCollection();
if (context.Items != null && context.Items.Length == 1)
{
var item = context.Items[0];
parameters["id"] = item.ID.ToString();
}
Context.ClientPage.Start(this, "Run", parameters);
}
#endregion
public CommandState QueryStat(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
return CommandState.Enabled;
}
protected static void Run(ClientPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
SheerResponse.CheckModified(false);
SheerResponse.Broadcast(
SheerResponse.ShowModalDialog(
"[Path to your application here]"
),
"Shell");
}
}
To get the item passed over, in your message call - just pass the variable $Target.
So the field Message in the Menu Item would be something like:
item:runMyApplication(id=$Target)
Hope that makes sense :)
Are there events that I can observe, similar to ember-data's events around data loading such as isLoaded/isUpdating, for while view/templates are being rendered?
I have a list of ~1000 elements going into a list, and it takes quite some time to even render (the topic of a whole other question). I'd like to show some indication to the user that rendering work is being done.
There are events at a more microcosmic level such as: http://emberjs.com/api/classes/Ember.View.html#event_willClearRender. I'm curious to know if there are events for when any rendering is being performed.
Ember.Instrumentation provides a general purpose way to instrument code and conveniently, by default, Ember emits instrumentation events anytime something is rendered.
Ember.subscribe is used to setup a listener for before and after-- the events are namespaced with periods so subscribing to "render" will get you all render instrumentation calls, which by default is like "render.boundHandlebars", "render.metamorph", "render.view" ...
Here's a little function to help you get started.. you can paste this into the console and click around your app to check it out (or if you want to see all the rendering from the start paste it somewhere in your code so its loaded after ember but before your app).
If no event is passed to beginInstrumentation it'll default to render ...
beginInstrumentation = function(eventName) {
var styles;
if (eventName == null) {
eventName = "render";
}
styles = {
"render.render.metamorph": "color: #a47701;",
"render.render.boundHandlebars": "color: #0f51fe;",
"render.view": "color: #37be02;"
};
Ember.subscribe(eventName, {
before: function(name, ts, payload) {
console.group(name);
return ts;
},
after: function(name, ts, payload, b_ts) {
var elapsed, style;
style = styles[name] || "";
elapsed = (ts - b_ts).toFixed(4);
console.log("%c" + payload.object + ": " + elapsed + "ms", style);
return console.groupEnd();
}
});
};
beginInstrumentation();
Heres the output in chrome when I paste it into the TodoMVC app and click the all/completed/active filters (should work in firefox/firebug as well)