E4 compat app: "Pre-load" perspective from fragment via e4xmi-defined menu - user-interface

I develop a Neon-based compatibility mode Eclipse RCP.
In a plugin, I add a new perspective via fragment.e4xmi as follows.
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_BxaXACerEeWxCPrV0pAZQQ">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_j2XU0CE8EeicB9o_IvsRpg" featurename="snippets" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="advanced:Perspective" xmi:id="_-awZgCE8EeicB9o_IvsRpg" elementId="net.my.editor.ui.perspective.editing" selectedElement="_HyeW0CE9EeicB9o_IvsRpg" label="Editing Perspective">
<children xsi:type="basic:PartSashContainer" xmi:id="_HyeW0CE9EeicB9o_IvsRpg" elementId="net.my.editor.ui.partsashcontainer.0" selectedElement="_KOMLUCE9EeicB9o_IvsRpg" horizontal="true">
<children xsi:type="basic:PartStack" xmi:id="_iprjYCH5EeilmepNhpTrFQ" elementId="net.my.editor.ui.partstack.navigation" containerData="20">
<children xsi:type="advanced:Placeholder" xmi:id="_RcRHECH3EeilmepNhpTrFQ" elementId="net.my.plugin.views.navigation" ref="_F0GUoCH4EeilmepNhpTrFQ" closeable="true"/>
</children>
<children xsi:type="basic:PartStack" xmi:id="_KOMLUCE9EeicB9o_IvsRpg" elementId="net.my.editor.ui.partstack.editing" containerData="80" selectedElement="_0KJQ0CH2EeilmepNhpTrFQ">
<children xsi:type="basic:Part" xmi:id="_0KJQ0CH2EeilmepNhpTrFQ" elementId="net.my.editor.ui.part.splitter" contributionURI="bundleclass://net.my.editor.ui/net.my.editor.ui.parts.SplitterView" label="splitter" iconURI="platform:/plugin/net.my.editor.ui/icons/Sample.png" closeable="true"/>
<children xsi:type="basic:Part" xmi:id="_LXR6UCE9EeicB9o_IvsRpg" elementId="net.my.editor.ui.parts.MyEditor.static" contributionURI="bundleclass://net.my.editor.ui/net.my.editor.ui.parts.MyEditor" label="Editor" iconURI="platform:/plugin/net.my.editor.ui/icons/Sample.png">
</children>
</children>
</children>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_HSMw4FS4Eeacy4vmBL0tEQ" featurename="sharedElements" parentElementId="IDEWindow">
<elements xsi:type="basic:Part" xmi:id="_F0GUoCH4EeilmepNhpTrFQ" elementId="net.my.plugin.views.navigation" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView"/>
</fragments>
</fragment:ModelFragments>
The perspective works fine and I can open it from the Perspective Toolbar.
I want to provide a menu item in the main menu which opens the perspective programmatically. It is here I'm running into issues.
I've added a menu item, command and handler to programmatically open the perspective. In it, the EModelService cannot find the perspective unless it has been opened beforehand.
I.e., modelService.find(perspectiveId, application) returns null, unless the perspective has been previously opened via the Perspective Toolbar (at which point its icon also appears in the toolbar for itself).
Hence my question: Is there a way that I can "pre-load" the perspective so that it is available in the model at the time the menu entry is handled, even if the perspective hasn't been opened before?

Managed to make it work by adding the perspective programmatically to the children of the PerspectiveStack parent of the currently active perspective.
Smells of brute force, so I'd still be interested in a better solution!
MPerspective myPerspective = null;
List<MUIElement> snips = application.getSnippets();
for (MUIElement snip : snips) {
if (snip.getElementId().equals(myPerspectiveId)) {
if (snip instanceof MPerspective) {
myPerspective = (MPerspective) snip;
}
}
}
if (myPerspective != null) {
MPerspective activePerspective = modelService.getActivePerspective(window);
MPerspectiveStack perspectiveStack = (MPerspectiveStack) (MElementContainer<?>) activePerspective
.getParent();
perspectiveStack.getChildren().add(myPerspective);
partService.switchPerspective(myPerspective);
}

Related

Is there a way to create a Windows 10 app that reside in taskbar similar to People App?

I would like to create a solution that will be like an icon on the taskbar and once clicked it will open as a small popup above the taskbar which will not interrupt the user or other windows similar to the Microsoft People app that will show on the bottom right as the following image:
This question has a similar title to my question but it's different subject where the asker was asking for the AppBar of the UWP app which is not my intention.
Other question
Is there a way to do that for normal developers, enterprise companies, or Microsoft partners?
Update 3rd :
Recently I tried to build the App, shared in this repo https://github.com/ejabu/TrayApp
things to note :
WindowStyle
to get Borderless window like People App.
<!-- MainWindow.xaml -->
<Window
....
WindowStyle="None">
<Grid/>
</Window>
ShowInTaskbar
ShowInTaskbar -> False
to prevent it appears on Taskbar
<!-- MainWindow.xaml -->
<Window
....
ShowInTaskbar="False"
...>
<Grid/>
</Window>
Use Hide Method
/// MainWindow.xaml.cs
private void Hide_Window()
{
this.Hide(); /// Minimize Window
}
Adjust Position according to Taskbar
/// MainWindow.xaml.cs
private void AdjustWindowPosition()
{
Screen sc = Screen.FromHandle(new WindowInteropHelper(this).Handle);
if (sc.WorkingArea.Top > 0)
{
Rect desktopWorkingArea = SystemParameters.WorkArea;
Left = desktopWorkingArea.Right - Width;
Top = desktopWorkingArea.Top;
}
else if ((sc.Bounds.Height - sc.WorkingArea.Height) > 0)
{
Rect desktopWorkingArea = SystemParameters.WorkArea;
Left = desktopWorkingArea.Right - Width;
Top = desktopWorkingArea.Bottom - Height;
}
else
{
Rect desktopWorkingArea = SystemParameters.WorkArea;
Left = desktopWorkingArea.Right - Width;
Top = desktopWorkingArea.Bottom - Height;
}
}
Update 2nd :
https://github.com/AronDavis/TwitchBot/blob/master/TwitchBotApp/Notification.xaml
Update:
https://www.youtube.com/watch?v=jdvD55ir1is
original :
this is the good example
Final Result
the Window page has no Close button. And also it cannot be dragged by commenting this line https://github.com/ejabu/AcrylicWindow/blob/343f4f5a6bc23109a97640f9ac35facb31e9ae43/AcrylicWindow/MainWindow.xaml.cs#L30
I found example project here
https://github.com/shenchauhan/MyPeople/tree/master/MyPeople/MyPeople
We may look at MyPeopleCanvas then.
I found also there is new update from Microsoft, that maybe we can replace Icon images with text in System Tray icon in the near future.
https://newswwc.com/technology/dotnet-technologies/personalized-content-at-a-glance-introducing-news-and-interests-on-the-windows-10-taskbar/
This is the closest i got to what i needed.
Although it's using ElectronJS and not WPF or UWP. But since it's doable with ElectronJS then it should also be doable on WPF.
https://github.com/sfatihk/electron-tray-window
Library is not created by me.

Picasso Images not loading with USB debugging, but working fine during emulation

Issue: When using a Navigation Drawer Activity, Picasso loads images during emulation, but not during USB debugging... Any help is greatly appreciated!
UPDATE: SOLUTION In Answer!
Here's an image of my phone not showing the image, and the emulator working fine. I'm using a YouTube thumbnail as an online test image:
https://imagizer.imageshack.com/img921/7876/4sd4ak.jpg
I noticed this in a larger project I was working on when I decided to whip it out on my phone, but in searching for the solution was able to isolate it to a fresh Navigation Drawer Layout Activity.
Here's what I know:
All my SDK, AndroidStudio, GooglePixel 3XL Phone (IRL), are updated
Invalidated/Restarted my Cashes in Android Studio
The issue also occurs when migrated to AnrdroidX
All Android phones work as expected when using the emulator, just not the USB Debugging on my physical Google Pixel 3XL
UPDATE: I got it to work on my Samsung Galaxy 7 through USB!
Other layouts like Empty Activity/etc all work fine, even in the same project
I made a new Navigation Drawer Layout Activity in Android Studio and added this:
1) Build.gradle (Module:app) dependencies:
implementation 'com.squareup.picasso:picasso:2.5.2'
2) In my Android Manifest: uses-permission android:name="android.permission.INTERNET"
3) An ImageView to my content_main
4) In my MainActivity's onCreate:
Picasso.with(this).load("http://img.youtube.com/vi/ek-5vIz_gDw/0.jpg").into(imageView)
// MainActivity without the additional override functions (no changes)
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)
val fab: FloatingActionButton = findViewById(R.id.fab)
fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
val navView: NavigationView = findViewById(R.id.nav_view)
val toggle = ActionBarDrawerToggle(
this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
)
drawerLayout.addDrawerListener(toggle)
toggle.syncState()
navView.setNavigationItemSelectedListener(this)
Picasso.with(this).load("http://img.youtube.com/vi/ek-5vIz_gDw/0.jpg").into(imageView)
}
And my content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/app_bar_main"
tools:context=".MainActivity">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp" app:srcCompat="#mipmap/ic_launcher_round"
android:id="#+id/imageView" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:contentDescription="#string/description"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I'm not getting any error messages on run, only the image just doesn't load in USB Debugging IRL.
UPDATE: So I was able to get it working on all other physical phones I tried it on. However To get it to work on the Google Pixel 3XL, I had to make this change. Not sure why it is any different, but it does work!
I was doing this before (Did not work only my physical Pixel 3):
val imageLink = video.link
Picasso.with(context).load("http://img.youtube.com/vi/$imageLink/0.jpg").into(imageView)
Not sure why, but here's the solution that works:
val imageLink = "https://img.youtube.com/vi/${video.link}/0.jpg"
Picasso.with(context).load(imageLink).into(imageView)
Hope this helps anyone in the same predicament!

Custom Page Transitions in Xamarin Forms when using ContentPage

I am creating a xamarin forms app and i want to change the transition when navigating between pages. I couldnt use https://components.xamarin.com/view/customnavpage because im using ContentPage. I also read the famous thread on xamarin forums but nothing worked for me. here is the link.
https://forums.xamarin.com/discussion/18818/custom-page-transitions-with-xamarin-forms
i'm using xamarin forms 2.3.4.247 and android api level 25 and appCompat 23.3.0.
any idea?
I found a workaround and I answer my own question maybe it helps someone else.
First we need to create a custom renderer for any platform(in this case android)
. create a new class under your Renderers folder in Droid target.
CustomTransitionsRenderer.cs
[assembly:ExportRenderer(typeof(NavigationPage),typeof(CustomTransitionsRenderer))]
namespace TesarSmartwatchForms.Droid.Renderers
{
public class CustomTransitionsRenderer : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
{
//SwitchContentAsync
protected override void SetupPageTransition(Android.Support.V4.App.FragmentTransaction transaction, bool isPush)
{
if (isPush)
transaction.SetCustomAnimations(Resource.Animator.move_in_left, 0);
else //prevView enter:
transaction.SetCustomAnimations(Resource.Animator.side_in_right, 0);
}
}
}
and then add your custom animations under Droid>Resources>animator like these:
move_in_left.xml
<?xml version="1.0" encoding="UTF-8" ?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="300"/>
</set>
and slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="300" />
</set>
then we need to modify our android theme just adding this line
<item name="android:windowBackground">#android:color/transparent</item>
and remember to navigate between pages with the default navigation transition, just like this
Navigation.PushAsync(page);

Menu Options not working in tablet

The menu options created are working perfectly fine in phone(both as overflow menu or left click device button).
But in tablet it only works on ones which have the overflow menu(the 3 dots).
When I click on the device left button nothing shows up. Not sure whats the problem
Layout:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/menu_settings"
android:title="#string/settings_menu"
app:showAsAction="never" />
<item
android:id="#+id/menu_signout"
android:title="#string/settings_sign_out"
app:showAsAction="never" />
</menu>
Code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.overflow_menu, menu);
settings = menu.findItem(R.id.menu_settings);
signOut = menu.findItem(R.id.menu_signout);
return true;
}

Controlling showAsAction of MenuItem under AppCompat v21 and using a Toolbar

I am trying adopt the v21 AppCompat libraries and leverage the better control of the ActionBar using a Toolbar as described here and here. But no matter how I modify the menu XML, I can only get the menu items to show up in the overflow area. I would like to see the MenuItem represented as an icon on the Toolbar/ActionBar.
My menu declaration looks like this (note the showAsAction line):
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res-auto="http:/>/schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="#+id/action_add"
android:icon="#android:drawable/ic_menu_add"
android:title="#string/action_add"
android:orderInCategory="2"
res-auto:showAsAction="always" />
</menu>
I have also tried this (with a slightly different showAsAction line):
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res-auto="http:/>/schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="#+id/action_add"
android:icon="#android:drawable/ic_menu_add"
android:title="#string/action_add"
android:orderInCategory="2"
android:showAsAction="always" />
</menu>
But the only way I have successfully been able to get the icon to show up on the Toolbar/ActionBar is to force it in code.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
// Try to manually force the item onto the bar instead of allowing it in the overflow
// for some reason, android is not picking up the setting in the menu declaration
// using android:showAsAction="always" (even when using the auto-res namespace)
MenuItem addItem = menu.findItem(R.id.action_add);
MenuCompat.setShowAsAction(addItem, MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
I am using the android.support.v4.view.MenuCompat static methods to achieve this. But I believe I should be able to do this declaratively in the XML. I have tried using both "always" and "ifRoom" but for no effect. I can only assume that the XML attribute is not being picked up.
I guess it is really something simple or related to the fact that I am using the new Toolbar to function as the holder of the menu. The Toolbar layout is very simple:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
and the usage seems quite standard:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Any help would be appreciated. And I am happy to share more of the project content if it helps to get to the bottom of it.

Resources