Network diagram in PlantUML not working as expected? - plantuml

I am trying to create a network diagram for my office using PlantUML. I am stuck very early on. I am beginning at the edge of our network and working downwards. I would like to use the sprites as much as possible.
I have
#startuml
!include <office/Servers/application_server>
!include <office/Devices/router>
nwdiag {
internet [shape = cloud];
router [description="<$router>\nRouter"];
internet -- router;
}
#enduml
which shows
which is not using the sprite I asked for. If I rename the router in the connection like so -
#startuml
!include <office/Servers/application_server>
!include <office/Devices/router>
nwdiag {
internet [shape = cloud];
router [description="<$router>\nRouter"];
internet -- router2;
}
#enduml
I do see my sprite though obviously it's not in the right place.
I do not see what I am doing wrong. How I can I connect the internet to the object called router which has the sprite attached?

This is one of those quirky things about ordering in PlantUML (not very logical). But I put the link line before the sprite line, and it works.
#startuml
!include <office/Servers/application_server>
!include <office/Devices/router>
nwdiag {
internet [shape = cloud];
internet -- router;
router [description="<$router>\nRouter"];
}
#enduml

Related

Code examples with 'context.' do not work when I paste them

Hi I am a novice Java and Android programmer and apologies if this is a bit of a dumb question.
I have seen many examples recently where the top voted solution includes code that will not resolve/run when i cut and paste it into my code.
My main issue is that I cannot work out how to change 'context.' given in the example below to something that will run.
As an example
I get this error ...
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dummies.silentmodetoggle, PID: 12988
java.lang.SecurityException: Not allowed to change Do Not Disturb state
at android.os.Parcel.createExceptionOrNull(Parcel.java:2285)
at android.os.Parcel.createException(Parcel.java:2269)
at android.os.Parcel.readException(Parcel.java:2252)
at android.os.Parcel.readException(Parcel.java:2194)
at android.media.IAudioService$Stub$Proxy.setRingerModeExternal(IAudioService.java:2835)
at android.media.AudioManager.setRingerMode(AudioManager.java:1150)
at com.dummies.silentmodetoggle.util.RingerHelper.performToggle(RingerHelper.java:20)
at com.dummies.silentmodetoggle.MainActivity$1.onClick(MainActivity.java:41)
at android.view.View.performClick(View.java:7350)
at android.view.View.performClickInternal(View.java:7327)
at android.view.View.access$3600(View.java:807)
at android.view.View$PerformClick.run(View.java:28166)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.audio.AudioService.setRingerModeExternal(AudioService.java:3169)
at android.media.IAudioService$Stub.onTransact(IAudioService.java:1257)
at android.os.Binder.execTransactInternal(Binder.java:1138)
at android.os.Binder.execTransact(Binder.java:1102)
I/Process: Sending signal. PID: 12988 SIG: 9
The Solution is in:
https://stackoverflow.com/questions/39151453/in-android-7-api-level-24-my-app-is-not-allowed-to-mute-phone-set-ringer-mode#
When I cut and paste this code in:
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& !notificationManager.isNotificationPolicyAccessGranted()) {
Intent intent = new Intent(
android.provider.Settings
.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivity(intent);
}
many of the parts do not initially work but after importing a few classes most of the issues go away apart from:
context.getSystemService(Context.NOTIFICATION_SERVICE); where it can't work out what to use for context
and
startActivity(intent); where it cannot find the class or what to use for intent.
As an aside, I am not looking for an answer to the Notification issue, I am after help with understanding how do I successfully take Stack overflow code paste it into my code and work out where the missing parts come from, particularly 'context.'.
I am working through a few different Android learning books including Android App Development for Dummies which is where this example is from. I have got the code to work by using an emulator with Lollipop code as this predates the introduction of the newish DND functionality.
Finally, I am trying to get it straight in my head how to use the reference guide as I come from a mainframe background where they seem to use a different way of explaining things.
All help gratefully received
Cheers
Craig
Right so I have dug a little and get it now.
'context.' is generic and can b replaced in this instance with this.getBaseContext().
Here is the code example.
private void updateUI() {
// Find the view named phone_icon in our layout. We know it's
// an ImageView in the layout , so downcast it to an ImageView.
ImageView imageView = (ImageView) findViewById(R.id.phone_icon);
NotificationManager notificationManager;
notificationManager = (NotificationManager) this.getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& !notificationManager.isNotificationPolicyAccessGranted()) {
Intent intent = new Intent(
android.provider.Settings
.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivity(intent);
}

AndroidX Preferences and Navigation

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!

Media has stopped working the way it should

I have an app which I made over two years ago which has a list of videos. When one of the list buttons is clicked, the media played full screen. This was working perfectly OK on Android (I have't tried other platforms) until I resubmitted it to the build server on 31-07-2016. After this I noticed that the videos were no longer working full screen.
This month, I resubmitted the app to the build server and now there are a couple of things that don't work. The most noticeable feature is that the video is stretched in portrait mode to fill the form (even without setFullScreen()). The other issue I have noticed is that if I click the back button and play another video, I get the new video and the old video still playing at the side / corner of the screen. I have tried pause() and cleanup() but they seem to have no effect. I have tried adding the Media directly to a Container and using MediaPlayer and found the same issues with both.
try {
((com.codename1.ui.layouts.BorderLayout) getLayout()).setCenterBehavior(com.codename1.ui.layouts.BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
Media media = createMedia(currentExternalContent.getIs(), "video/m4v");
Component videoComponent = media.getVideoComponent();
Container videoContainer = new Container(new com.codename1.ui.layouts.BorderLayout());
videoContainer.addComponent(BorderLayout.CENTER, videoComponent);
addComponent(BorderLayout.CENTER, videoContainer);
revalidate();
media.play();
} catch (IOException ex) {
// Dialog.show("Catch", ex.getMessage(), "OK", "Cancel"); // gives 'read failed: EBADF (Bad file descriptor)'
}
}

IOS 6 - Auto Rotate MPMovieplayer

So, i'm fix interface Iphone is portrait and i wanna show landscapte when i playing video(using MPMoviePlayerController), i have read in ios6 sdk,ShouldAutorotateToInterfaceOrientation is deprecated. How to rotate only this player view? I can only rotate whole app, but don't want to do this.
i tryed with
(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
in this link or link but video still doesn't change.. Can you help me
First of all, in your app settings, do you allow any other orientation besides portrait?
Second, is your view controller embedded in an UINavigationController/UITabBarController/UISplitViewController?
The code you posted is supposed to work as a category or by subclassing an UINavigationController. If your container is not a UINavigationController, it won't work.(at least not for UITabBarController).
Can you also post the code where you enable to rotation for your view controller?
Also, it could be helpful to also show the whole code for your category/subclass.

Silverlight MP3 Playing Library

I'm trying to play MP3 files in SilverSprite, and it's super buggy. Is there an alternative library I can use to play MP3s in Silverlight?
Edit: Now that there's a bounty, I'm specifically looking for something that:
Works with SL 3-4
Is a separate project/DLL
Will work in SilverSprite projects (I'm using a layer on top of SS) -- no GUI, just methods I can call to play sounds
Works with content that has the build action set to Content. I cannot use embedded resources due to a bug in SilverSprite. My app will not run.
Plays MP3s.
Can play multiple audio files at the same time
I hope it's clear what I'm trying to find. I would like something I can embed in my own game engine, which sits on top of SilverSprite. I will supply all the audio files in the XAP. (The SilverSprite audio is quite broken and doesn't work.)
Update: The specific direction I would probably like to go in is to instantiate a new MediaElement, set the source, and play it. I have some code below, but a) NaturalDuration.TimeSpan.TotalMilliseconds reports 0, and b) the .MediaOpened never triggers.
MediaElement m = new MediaElement();
m.Source = new Uri("Content/Audio/chimes.mp3", UriKind.Relative);
m.Stop(); // useless?
//m.SetSource(new FileStream("Content/Audio/chimes.mp3", FileMode.Open)); // "Permission denied" exception, is it even finding the file?
m.Volume = 1; // Max
m.Position = TimeSpan.FromMilliseconds(0);
while (m.CurrentState != System.Windows.Media.MediaElementState.Closed)
{
Thread.Sleep(10);
}
m.MediaOpened += (sender, e) =>
{
m.Play();
};
m.Play();
For some working code rather similar to your updated approach see http://www.wiredprairie.us/blog/index.php/archives/577 . Beware that the MediaElement needs to be added to the control/component tree - see http://www.michaelsnow.com/2010/12/17/playing-sound-effects-on-windows-phone-7/.
Two very interesting options for your requirements is this library and this one.
For this kind of stuff you could also implement/use a custom MediaStreamSource like this one... see here and here.
EDIT - some other options:
Playing multiple sounds in parallel via XNA see source code at http://create.msdn.com/en-US/education/catalog/sample/silverlightsound
Using MediaPlayer class from XNA 4 for example:
MediaPlayer.Stop();
MediaPlayer.Volume = 1;
MediaPlayer.Play(Song.FromUri("TestSound", new Uri("/Content/Audio/chimes.mp3", UriKind.Relative)));
As for playing multiple sound files at the same time:
IIRC this is something which could cause your app to fail validation.

Resources