In the new Codename One bare-bones project (https://start.codenameone.com/), there is a default theme.css that starts with:
#Constants {
includeNativeBool: true;
defaultSourceDPIInt: "0";
}
What is defaultSourceDPIInt: "0";? I couldn't find anything in the blog about this.
It's discussed here: https://www.reddit.com/r/cn1/comments/p0utte/defaultsourcedpiint_css_theme_constant_can_make/
The defaultSourceDPIInt constant which you can use as:
#Constants {
/* ... */
defaultSourceDPIInt: 0;
}
Sets the default DPI of images you use in the theme. This is very
important as the default is the creation of multi images. With 0 we're
essentially importing all images as regular images by default which
means you need to explicitly state the source DPI to prevent mistakes.
Check out the git commit for the full story:
https://github.com/codenameone/CodenameOne/commit/f31fb8a046759ed884ab61b2d34b42a614b2dbd2
Related
Are there any examples of using the Jetpack / androidx preference library alongside the navigation component / Single activity? All the examples I'm seeing ( e.g. Google's example ) are using supportFragmentManager and replacing the content of a FrameLayout.
Navigating to the PreferenceFragmentCompat() with the navigation component almost works, in that it shows the Preferences page, but it is missing all of the toolbar/navigation icons. It's just implanted over the previous fragment, so to exit it, you need to hit the hardware back button.
Looks like this already has an issue filed with Google's issue tracker here
I just ran into the same problem and this is how I implemented it. Before I get into the code I want to give a quick summary. I have a single activity and two fragments. One of the fragments is the main fragment that is the home screen for the application and the other is the fragment that shows the settings. I end up not using SupportFragmentManager (which Google shows in their settings guide) as I was running into the same problem where the view would just appear on top of the previous view. So I just navigate to the settings fragment in the same way you would navigate to any other fragment in the single activity architecture using findNavController().navigate(...).
Firstly you will need to add the appropriate dependencies to your app build.gradle:
dependencies {
...
// androidx Preferences
implementation "androidx.preference:preference-ktx:1.1.0"
// androidx Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.0'
Then I set up my MainActivity.kt for Navigation as described in Google's navigation guide
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
NavigationUI.setupActionBarWithNavController(
this, this.findNavController(R.id.nav_host_fragment)
)
}
// Allows the up arrow to navigate back to the navigation host fragment.
override fun onSupportNavigateUp(): Boolean {
return Navigation.findNavController(this, R.id.nav_host_fragment).navigateUp()
}
}
After that, set up a fragment that will be hosted by MainActivity.kt. This fragment is what will appear when you open up your app. I call mine MainFragment.kt. See Google's menu guide for help on creating the dropdown menu that is inflated when the three dot icon in the toolbar is clicked.
class MainFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Show the three dot icon in the top right had corner of the toolbar
setHasOptionsMenu(true)
return inflater.inflate(R.layout.fragment_main, container, false)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
// Navigate to the settings fragment when the options menu item is selected
R.id.settings -> {
findNavController().navigate(MainFragmentDirections.actionMainToSettings())
true
}
else -> super.onOptionsItemSelected(item)
}
}
// Inflates menu.xml when the three dot icon is clicked
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu, menu)
}
}
Finally, the settings fragment is pretty easy to implement. Reference Google's settings guide (see link above) on how to set that up.
class MySettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
}
}
Also, don't forget to hook up your fragments in nav_graph.xml. Reference Google's navigation guide linked above for examples of that.
Hope this helps!
Using .NET WPF and Windows 10, is there a way to push a local toast notification onto the action center using c#? I've only seen people making custom dialogs for that but there must be a way to do it through the os.
You can use a NotifyIcon from System.Windows.Forms namespace like this:
class Test
{
private readonly NotifyIcon _notifyIcon;
public Test()
{
_notifyIcon = new NotifyIcon();
// Extracts your app's icon and uses it as notify icon
_notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
// Hides the icon when the notification is closed
_notifyIcon.BalloonTipClosed += (s, e) => _notifyIcon.Visible = false;
}
public void ShowNotification()
{
_notifyIcon.Visible = true;
// Shows a notification with specified message and title
_notifyIcon.ShowBalloonTip(3000, "Title", "Message", ToolTipIcon.Info);
}
}
This should work since .NET Framework 1.1. Refer to this MSDN page for parameters of ShowBalloonTip.
As I found out, the first parameter of ShowBalloonTip (in my example that would be 3000 milliseconds) is generously ignored. Comments are appreciated ;)
I know this is an old post but I thought this might help someone that stumbles on this as I did when attempting to get Toast Notifications to work on Win 10.
This seems to be good outline to follow -
Send a local toast notification from desktop C# apps
I used that link along with this great blog post- Pop a Toast Notification in WPF using Win 10 APIs
to get my WPF app working on Win10. This is a much better solution vs the "old school" notify icon because you can add buttons to complete specific actions within your toasts even after the notification has entered the action center.
Note- the first link mentions "If you are using WiX" but it's really a requirement. You must create and install your Wix setup project before you Toasts will work. As the appUserModelId for your app needs to be registered first. The second link does not mention this unless you read my comments within it.
TIP- Once your app is installed you can verify the AppUserModelId by running this command on the run line shell:appsfolder . Make sure you are in the details view, next click View , Choose Details and ensure AppUserModeId is checked. Compare your AppUserModelId against other installed apps.
Here's a snipit of code that I used. One thing two note here, I did not install the "Notifications library" mentioned in step 7 of the first link because I prefer to use the raw XML.
private const String APP_ID = "YourCompanyName.YourAppName";
public static void CreateToast()
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(
ToastTemplateType.ToastImageAndText02);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("This is my title!!!!!!!!!!"));
stringElements[1].AppendChild(toastXml.CreateTextNode("This is my message!!!!!!!!!!!!"));
// Specify the absolute path to an image
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + #"\Your Path To File\Your Image Name.png";
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = filePath;
// Change default audio if desired - ref - https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio
XmlElement audio = toastXml.CreateElement("audio");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Reminder");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Mail"); // sounds like default
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call7");
audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call2");
//audio.SetAttribute("loop", "false");
// Add the audio element
toastXml.DocumentElement.AppendChild(audio);
XmlElement actions = toastXml.CreateElement("actions");
toastXml.DocumentElement.AppendChild(actions);
// Create a simple button to display on the toast
XmlElement action = toastXml.CreateElement("action");
actions.AppendChild(action);
action.SetAttribute("content", "Show details");
action.SetAttribute("arguments", "viewdetails");
// Create the toast
ToastNotification toast = new ToastNotification(toastXml);
// Show the toast. Be sure to specify the AppUserModelId
// on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
}
UPDATE
This seems to be working fine on windows 10
https://msdn.microsoft.com/library/windows/apps/windows.ui.notifications.toastnotificationmanager.aspx
you will need to add these nugets
Install-Package WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-Shell
Add reference to:
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd
And
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
And use the following code:
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}
// Specify the absolute path to an image
string imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier("Toast Sample").Show(toast);
The original code can be found here: https://www.michaelcrump.net/pop-toast-notification-in-wpf/
I managed to gain access to the working API for windows 8 and 10 by referencing
Windows.winmd:
C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral
This exposes Windows.UI.Notifications.
You can have a look at this post for creating a COM server that is needed in order to have notifications persisted in the AC with Win32 apps https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/.
A working sample can be found at https://github.com/WindowsNotifications/desktop-toasts
I've been using JFormDesigner with the runtime library to create dialogs directly from the .jfd files at runtime (I can't change this; not my decision). My problem is that the runtime library doesn't seem to preserve any custom code generation listed in the .jfd file. For example, if I have a simple panel, with the background set to red, and a post-initialization command to set the background to green, the runtime library will yield a red background, while directly loading the generated .java file will properly set the background to green.
Here's a code sample of what I'm doing:
public class EntryPoint
{
public static void main( String[] args )
{
// Load .jfd file. Shows red background (incorrect).
String form = "testProject/entry/TestDialog.jfd";
new EntryPoint(form);
// Load .java file. Shows green background (correct).
JFrame frame = new JFrame();
TestDialog test = new TestDialog( frame );
test.setVisible( true );
}
EntryPoint( String form )
{
try
{
// Example loading
// see http://www.formdev.com/jformdesigner/doc/runtime-library/
FormModel formModel = FormLoader.load( form );
FormCreator formCreator = new FormCreator(formModel);
formCreator.setTarget(this);
JDialog dialog = formCreator.createDialog(null);
dialog.setModal(true);
dialog.pack();
dialog.show();
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
I took a quick look at the documentation, but to no avail. I have an e-mail sent to JFD's support team, and will update the question if I get any response. I'm looking through the runtime library code now (it's open source), but was curious if anyone had any info on it before I go too far down the rabbit hole. Thanks.
Support replied; feature not currently supported (as of version 5.2).
Who tried add native function to javascript in CEF? It was not work, simple to reappear:
download the CEF3 binary package (1750)
open cefclient2010.sln
open client_app.cpp which in cefclient project
goto line 110, set a breakpoint
F5
input any url, any try, the breakpoint never breaked
Am I missed some steps? or some settings?
i had the same problem
you must add CefRenderProcessHandler interface in SimpleApp ,then the most important is you must implement CefApp::GetRenderProcessHandler() method.
just like this:
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() {
return this;
}
by default, the base class return NULL,so OnContextCreated() will not call.
Perhaps it has something to do with the process model? How can you tell if the function is getting called? If by using a debugger, make sure you attached all child-processes too.
By default sample CEF application is multi-process. Either attach CEF render process to the debugger or simply do following (force the CEF app run into single process mode):
CefSettings settings;
#ifdef _DEBUG
settings.single_process = true;
#endif
Does anybody know if it's possible to use MoSync to create apps with a native UI?
From what I can tell all the UI/graphics is done with their own UI library and don't the the native ui elements.
Also, now that I'm creating a question anyway. Why does MoSync target specific telephones? Is it not possible to just create a generic install package for whatever platform you're targeting? (like .apk files for android). If it's possible it should make distribution easier.
The standard way up til now has been to create a custom non-native UI through the MAUI library. As of 2011-02-03 there is an experimental native UI framework for Android and iPhone. The user documentation is however rather non-existent, so you will have to check the source code for more information. I'll point you in the right direction, for accessing native widgets you use the maWidget* system calls defined in: maapi.idl. For a list of available widgets and properties see: Types.java. Note that this API is likely to change and be expanded.
A simple native UI example:
#include <MAUtil/Moblet.h>
#include <IX_WIDGET.h>
class NativeUIMoblet : public MAUtil::Moblet
{
public:
NativeUIMoblet()
{
// Create a screen
MAHandle mainScreen = maWidgetCreate( "Screen" );
// Create a 'Hello World' label
MAHandle helloLabel = maWidgetCreate( "Label" );
maWidgetSetProperty( helloLabel, "text", "Hello World!" );
// Add the label to the screen
maWidgetAddChild( mainScreen, helloLabel );
// Show the screen
maWidgetScreenShow( mainScreen );
}
void keyPressEvent(int keyCode, int nativeCode)
{
}
void keyReleaseEvent(int keyCode, int nativeCode)
{
}
};
extern "C" int MAMain()
{
MAUtil::Moblet::run( new NativeUIMoblet( ) );
return 0;
};
Presently, there is no emulator support available, so you will have to run it on a device or in a specific SDKs emulator.
The reason for targeting a specific phone is that there exists bugs specific to a certain device. But in the recent nightly builds of MoSync you can build for generic platforms like Android 2.1.
http://www.mosync.com/blog/2011/03/using-nativeeditbox