I'm developìng an app in Vaadin and I've found a problem.
I would like to open a new browser window from the action handler added to a vaadin table, and I don't know how to do that. Is that possible?.
table.addActionHandler(new Handler() {
public void handleAction(Action action, Object sender, Object target) {
if (action == ACTION_OPEN_WINDOW) {
// code to open a new browser window
BrowserWindowOpener opener = new BrowserWindowOpener....
/// is it possible open oit here?
}
}
public Action[] getActions(Object target, Object sender) {
return ACTIONS;
}
});
you still can run JavaScript:
JavaScript.getCurrent().execute("window.open('http://google.com', 'Google', 'height=800,width=600');");
Related
I'm trying to make an app which sends a image to a server, it transforms the image and it return to the app. But when the app receive the image, only receive a part of it. I did a web with flask and I saw that it send well the picture, and I used Okhttp to download a picture from Internet I don't have any problem.
To send the picture from server I've used:
return flask.send_from_directory('path') and return flask.send_file(...)
To send and receive the picture in the client I've used:
void postRequest(String postUrl, RequestBody postBody) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(postUrl)
.post(postBody)
.build();
client.newCall(request).enqueue(new Callback() {
#Override
public void onFailure(Call call, IOException e) {
// Cancel the post on failure.
call.cancel();
Log.d("FAIL", e.getMessage());
// In order to access the TextView inside the UI thread, the code is executed inside runOnUiThread()
runOnUiThread(new Runnable() {
#Override
public void run() {
TextView responseText = findViewById(R.id.responseText);
responseText.setText(R.string.ip_failure);
}
});
}
#Override
public void onResponse(Call call, final Response response) throws IOException {
// In order to access the TextView inside the UI thread, the code is executed inside runOnUiThread()
runOnUiThread(new Runnable() {
#Override
public void run() {
TextView responseText = findViewById(R.id.responseText);
responseText.setText("");
try {
Bitmap imagenGAN;
imagenGAN = BitmapFactory.decodeStream(response.body().byteStream());
ImageView imagen = findViewById(R.id.imageView);
imagen.setImageBitmap(imagenGAN);
SaveImage(imagenGAN);
}catch(Exception e){
}
}
});
}
});
}
Example of the received image:
I don't know why I don't receive the full image. Can someone help me?
I'm trying to implement a settings page (with XAML and C++), with three radio buttons: "Light", "Dark" and "Use system theme". How do I do Application.RequestedTheme? Thanks!
Based on this document about Application.RequestedTheme, it mentions
The theme can only be set when the app is started, not while it's
running. Attempting to set RequestedTheme while the app is running
throws an exception (NotSupportedException for Microsoft .NET code).
If you give the user an option to pick a theme that's part of app UI,
you must save the setting in the app data and apply it when the app is
restarted.
So you could save the setting of theme in the app data and apply it in the constructorof App when you restart your app. For example:
App.xaml.cpp:
App::App()
{
InitializeComponent();
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
if (value != nullptr)
{
String^ colorS = safe_cast<String^>(value);
// Apply theme choice.
if (colorS == L"Dark") {
App::Current->RequestedTheme = ApplicationTheme::Dark;
}
else {
App::Current->RequestedTheme = ApplicationTheme::Light;
}
}
}
Setting.xaml.cpp:
void AppCX::BlankPage::Light_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
}
void AppCX::BlankPage::Dark_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
}
void AppCX::BlankPage::UseSystemTheme_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings();
auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString();
if (uiTheme == Windows::UI::Colors::Black.ToString()) {
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
}
else if (uiTheme == Windows::UI::Colors::White.ToString())
{
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
}
}
Hello I'm using Lync SDK 2013, to display number phones from contact in ListBox, and use the Items (phone number) to call this number by my API. So i did a WPF application, that contains just a ListBox, and 2 buttons (Call - Hang up). My apllication is added as custom command in Lync, in RightClick in the contact. and it doesn't have any Lync Controls. So what i want to do is: if i Right Click on the contact, my application launches and gives me the number phone List in the ListBox. I did it with a WPF that contains the controls: ContactSearchInputBox (to search a contact) and ContactSearchResultList and it works very Well, I don't know how to do it without controls.
Any One Can Help Me !!!! :(
You need to read and understand the Lync SDK 2013 Lync Contact documentation.
If you wish to "simulate" the Lync Contact "search" (as per the Client search) then you need to look into the search API.
The other concepts you need to understand is the results returned from all the API are NOT guaranteed to return all the Lync Contact data that asked for.
There is no way with the Lync SDK to "load" all the contact information which is what most people seem to not understand.
The results returned are what the local cache has and no more. To get the all the Lync Contact information you need to understand the ContactSubscription model.
For each Lync Contact that you wish to be notified of field updates (or loads) you "subscribe" to the Lync Contact and then you will be notified via the Contact.ContactInformationChanged event.
So your UI must to able to auto-update the information as the fields get loaded / updated from any initial value returned from any Lync Contact value.
public partial class ChoosePhoneNumber : Window
{
LyncClient lync_client;
Contact contact;
ContactSubscription contact_subscription;
List<ContactInformationType> contact_information_list;
ContactManager contact_manager;
public ChoosePhoneNumber()
{
InitializeComponent();
connect_lync();
get_subscribed_contact(this.contact);
}
}
private void connect_lync()
{
try
{
lync_client = LyncClient.GetClient();
contact_manager = lync_client.ContactManager;
}
catch (ClientNotFoundException)
{
MessageBox.Show("Client is ot running", "Error While GetClient", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void get_subscribed_contact(Contact contact)
{
List<object> contact_phone_numbers_list = new List<object>();
contact_information_list = new List<ContactInformationType>();
contact_information_list.Add(ContactInformationType.ContactEndpoints);
contact_information_list.Add(ContactInformationType.DisplayName);
contact = contact_manager.GetContactByUri("number"); // I put here the number phone of a contact in my list
contact_subscription = LyncClient.GetClient().ContactManager.CreateSubscription();
contact_subscription.AddContact(contact);
contact.ContactInformationChanged += Contact_ContactInformationChanged;
contact_subscription.Subscribe(ContactSubscriptionRefreshRate.High, contact_information_list);
List<object> endpoints = (List<object>)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
var phone_numbers_list = endpoints.Where<object>(N => ((ContactEndpoint)N).Type == ContactEndpointType.HomePhone ||
((ContactEndpoint)N).Type == ContactEndpointType.MobilePhone || ((ContactEndpoint)N).Type == ContactEndpointType.OtherPhone
|| ((ContactEndpoint)N).Type == ContactEndpointType.WorkPhone).ToList<object>();
var name = contact.GetContactInformation(ContactInformationType.DisplayName);
if (phone_numbers_list != null)
{
foreach (var phone_number in phone_numbers_list)
{
contact_phone_numbers_list.Add(((ContactEndpoint)phone_number).DisplayName);
}
conboboxPhoneNumbers.ItemsSource = contact_phone_numbers_list;
}
}
private void Contact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
{
var contact = (Contact)sender;
if (e.ChangedContactInformation.Contains(ContactInformationType.ContactEndpoints))
{
update_endpoints(contact);
}
}
private void update_endpoints(Contact contact)
{
if ((lync_client != null) && (lync_client.State == ClientState.SignedIn))
{
ContactEndpoint endpoints = (ContactEndpoint)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
}
}
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; ;
try
{
string argsParam = "Contacts=";
if (e.Args.Length > 1)
{
if (e.Args[2].Contains(argsParam))
{
var contacts_sip_uri = e.Args[2].Split('<', '>')[1];
Params.contacts = contacts_sip_uri;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Reading Startup Arguments Error - " + ex.Message);
}
}
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
string message = e.Exception.Message;
if (e.Exception.InnerException != null)
{
message += string.Format("{0}Inner Exception: {1}", Environment.NewLine, e.Exception.InnerException.Message);
}
MessageBox.Show(message, "Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Params is a public static class that contains just contact as public static string contacts { get; set; }
public static class ParamContact
{
public static string contacts { get; set; }
}
I'm creating a live card app that recieves PNGs from a php script running on my server in response to a request from scanning QR codes. At the moment, I simply replace the image on my Live card with the PNG I recieve from the server, but I would like to recieve and display multiple images from the server with each request.
Is there an approved way to show multiple images on a live card? I was thinking there may be a possiblity of generating a menu full of images that simply closed itself when clicked, but it seems like there might be a better alternative.
This is my code at the moment:
Current Code
import com.google.android.glass.timeline.LiveCard;
import com.google.android.glass.timeline.LiveCard.PublishMode;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.IBinder;
import android.util.Base64;
import android.widget.RemoteViews;
public class iotSplashScreen extends Service {
private static final String LIVE_CARD_TAG = "iotSplashScreen";
private LiveCard mLiveCard;
private RemoteViews mLiveCardView;
public class iotBinder extends Binder {
public void changeImage(String change) {
try {
byte[] bob = Base64.decode(change, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(bob, 0, bob.length);
if(bitmap != null) {
mLiveCardView.setImageViewBitmap(R.id.image_view_id, bitmap);
mLiveCard.setViews(mLiveCardView);
}
else
{
System.out.println("Daaang, dat bitmap was null doe");
}
}
catch (IllegalArgumentException e)
{
System.out.println("Base64 had an issues: " + e);
System.out.println(change);
}
catch (NullPointerException e)
{
System.out.println("Null Pointer: " + e);
}
}
}
private final iotBinder mBinder = new iotBinder();
#Override
public IBinder onBind(Intent intent) {
return mBinder;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
mLiveCardView = new RemoteViews(getPackageName(), R.layout.iot_splash_screen);
mLiveCard.setViews(mLiveCardView);
// Display the options menu when the live card is tapped.
Intent menuIntent = new Intent(this, LiveCardMenuActivity.class);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.publish(PublishMode.REVEAL);
} else {
mLiveCard.navigate();
}
return START_STICKY;
}
#Override
public void onDestroy() {
if (mLiveCard != null && mLiveCard.isPublished()) {
mLiveCard.unpublish();
mLiveCard = null;
}
super.onDestroy();
}
}
Simply add more ImageViews, either in your layout file (iot_splash_screen) or programmatically.
With the resource IDs of your ImageViews, you can call setImageViewResource on each one.
Make sure that you are setting these images before calling setViews on your Live Card.
I want to hook the item:renamed event to do some processing. It may take a few minutes though. Are event handlers executed asynchronously or synchronously with normal pipeline execution? Is there a standard Sitecore way to kick this off asynchronously if I need to do that myself?
The only time this handler needs to execute is when an item is renamed in Content Editor.
Sitecore events are executed synchronously. There is a Sitecore Development Toolkit module on Sitecore Marketplace which contains a code for firing events asynchronously which you can easily reuse in your solution Sitecore Development Toolkit.
Here is a part of their code which fires methods asynchronously when the event is fired:
public void OnItemRenamed(object sender, EventArgs args)
{
if (args != null)
{
var item = Event.ExtractParameter(args, 0) as Item;
Assert.IsNotNull(item, "No item in parameters");
var name = Event.ExtractParameter(args, 1) as string;
Assert.IsNotNullOrEmpty(name, "No name in parameters");
DoAsync(() => OnItemRenameAsync(item, name));
}
}
private void OnItemRenameAsync(Item item, string name)
{
var itemRef = new ItemReference(item.Parent);
var itemRefText = itemRef.ToString();
// do some work here
}
Sitecore events are synchronous. You can kick off your long running task as a job. First create a class to handle the event:
namespace MyNamespace
{
public class MyClass
{
public void ItemRenamed (object sender, EventArgs args)
{
Run("LongRenameTask");
}
protected void Run(string methodName, EventArgs args)
{
var item = Event.ExtractParameter(args, 0) as Item;
var name = Event.ExtractParameter(args, 1) as string;
RunJob(methodName, item, name);
}
protected Handle RunJob(string methodName, Item item, string name)
{
var options = new JobOptions(
"Preparing rename job '{0}' for '{1}'".FormatWith(
methodName,
item.ID.ToString()),
"item:renamed",
"shell",
new ItemRenamedManager(item, name),
methodName)
{
WriteToLog = true,
AtomicExecution = true,
};
var job = new Job(options);
JobManager.Start(job);
return job.Handle;
}
}
}
Then create a class to do your work (this will be called on a background thread by Sitecore):
namespace MyNamespace
{
public class ItemRenamedManager
{
protected Item RenamedItem { get; set; }
protected string Name { get; set; }
public ItemRenamedManager(Item item, string name)
{
RenamedItem = item;
Name = name;
}
public void LongRenameTask()
{
// Do your long running task here.
// The property 'RenamedItem' will give you the item
}
}
}
Then patch your event handler in:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="item:renamed">
<handler type="MyNamespace.MyClass" method="ItemRenamed" />
</event>
</events>
</sitecore>
</configuration>
The above code is cribbed a bit from memory and needs some error handling, but should be pretty close, but this way, your long running task won't block the Content Editor UI.