How to disable the prompt about Debug Perspective mode switching in eclipse programatically? - eclipse

#Override
public void createInitialLayout(IPageLayout layout) {
String editor = layout.getEditorArea();
layout.setEditorAreaVisible(true);
layout.addView(VIEW_EXLPORER, IPageLayout.LEFT, 0.20f, editor);
layout.getViewLayout(VIEW_EXLPORER).setCloseable(false);
IFolderLayout bottom = layout.createFolder("bottom", IPageLayout.BOTTOM, 0.80f, editor);
bottom.addView(VIEW_PROGRESS);
bottom.addView(IPageLayout.ID_TASK_LIST);
bottom.addView(IPageLayout.ID_OUTLINE);
bottom.addView(IPageLayout.ID_PROBLEM_VIEW);
//shows debug view area here
layout.addView("org.eclipse.debug.ui.DebugView", IPageLayout.LEFT, (float) 0.40, layout.getEditorArea());
}
As you see from my code i already have debug view in my custom perspective but eclipse keep promting me to switch to debug perspective when i start debugging automatically which i would like to avoid this programatically since i do now want to confuse my users.
Any way to follow?

You can try to use DebugUITools.setLaunchPerspective to either let the prompt open your custom perspective instead of the default one or disable the prompt at all.
From its Javadoc:
/**
* Sets the perspective to switch to when a configuration of the given type
* is launched in the given mode. <code>PERSPECTIVE_NONE</code> indicates no
* perspective switch should take place. <code>PERSPECTIVE_DEFAULT</code> indicates
* a default perspective switch should take place, as defined by the associated
* launch tab group extension.
*
* In 3.3 this method is equivalent to calling <code>setLaunchPerspective(ILaunchConfigurationType type, Set modes, ILaunchDelegate delegate, String perspectiveid)</code>,
* with the parameter 'mode' used in the set modes, and null passed as the delegate
*
* #param type launch configuration type
* #param mode launch mode identifier
* #param perspective identifier, <code>PERSPECTIVE_NONE</code>, or
* <code>PERSPECTIVE_DEFAULT</code>
* #since 3.0
*/

Related

Click on Camera Shutter using UIAutomator

I am writing an Espresso test for my app, and am trying to automate clicking the shutter button after opening of a camera in my app.
I am using Espresso and UIAutomator in the Android Emulator. I managed to dump this UI in UIAutomatorViewer.
I can't figure out why I am unable to click on the shutter button using UIAutomator using this code:
public void clickCameraShutterButton() throws UiObjectNotFoundException
{
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiSelector shutterSelector = new UiSelector().resourceId("com.android.camera:id/shutter_button");
UiObject shutterButton = device.findObject(shutterSelector);
shutterButton.click();
}
The camera just sits there, and the shutter button is never clicked. This is the stack trace I'm getting in the Android Studio monitor:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
Any advice would be appreciated.
You can try this code:
device.findObject(new UiSelector().resourceId("com.android.camera:id/shutter_button")).click();
or
device.findObject(new UiSelector().description("Shutter button")).click();
or
device.executeShellCommand("input keyevent 27");
this mean KEYCODE_CAMERA value is 27
or
device.click(x,y);
This worked for me
#Before
public void setUp() {
// Initialize UiDevice instance
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
mDevice = UiDevice.getInstance(instrumentation);
}
...
/**
* ##Test comment here##
*
* #throws Exception
*/
#Test
public void culebraGeneratedTest_CameraShutter() throws Exception {
mDevice.findObject(By.res("com.android.camera2:id/shutter_button").desc("Shutter").clazz("android.widget.ImageView").text(Pattern.compile("")).pkg("com.android.camera2")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
}
This test finds the shutter and clicks on it.
If you are interested this test was automatically generated using CulebraTester.
Just need to put the UI Automator Viewer "resource-id" value at the place of *
mdevice.findObject(new UiSelector().resourceId("*")).click();

Rearrange docs in Eclipse IDE

I want to reposition the params docs, I had written the docs for my code earlier. Now I have rearranged the arguments of my method, I want the same to reflect in my docs written above my method. How can I do this, is there any shortcut keys? I don't want to do it manually. I have too many methods.
Earlier code and docs
/** Places the spinner on the screen on specified co-ordinates and customized drop down menu.It can be used for various option selection purpose.
* #param options The list of items the that is to be shown in the spinner's drop down menu.
* #param xCordinate The start point of the this view along x [To be given in cell number].
* #param yCordinate The start point of the this view along y [To be given in cell number].
* #param spinnerTextSize Text size of the text that is displayed on the spinner.
* #param spinnerTextColorCode The color of the text on the spinner,stored in database.[HTML color codes or Hex codes].
* #param spinnerWidth The width of the spinner.
* #param fontSize Text size of the text that is displayed on the spinner's drop down menu.
* #param fontColorCode The color of the text(stored in database) on the spinner's drop down menu.[HTML color codes or Hex codes].
* #param dropDownBackgroundColorCode The background color of the spinner's drop down menu,stored in database.[HTML color codes or Hex codes].
*/
public void spinner( int[] options, int xCoordinate, int yCoordinate, final float spinnerTextSize, int spinnerTextColorCode, int spinnerWidth, float fontSize, int fontColorCode, int dropDownBackgroundColorCode);
Repositioned arguments in the above method
public void spinner(int spinnerId, int xCordinate, int yCordinate, int spinnerWidth, final int spinnerTextSize, float fontSize, int spinnerTextColorCode, int fontColorCode, int dropDownBackgroundColorCode, int[] options)
You can do this using Eclipse's refactoring feature. Here is how:
Right-click on the method you want to change. Refactor -> Change Method Signature... or simply use Alt-Shift-C. In the menu that pops up you can change you method any way you want. In your case you will want to move parameters around. Select a parameter and use the Up and Down buttons to rearrange the list of parameters. This will also rearrange the documentation as long as the parameter names match up.
I would also like to issue some advice. You might want to look into the telescoping anti-pattern and the use of the Builder pattern to get around this pitfall.

Is it there a property to arrange menu items horizontally in AndEngine?

Is it there a property to arrange menu items horizontally AndEngine?
The default layout is vertical, do you know a way to set it horizontal?
There isn't a built it functionality that would arrange menu items horizontally, but check the MenuSceneAnimator class, especially getMenuItemX and getMenuItemY methods. It should be pretty easy to implement your own positioning that will suit your needs.
This is the solution I came up with, I know it can be optimized, but it works.
/**
* Sets menu items layout to horizontal
* #author Lucas Massuh
* #version 1.0
* #since 2015-05-28
* #return returns the "horizontalised" menu, just in case.
* #param menu This should be the menu scene containing all the Menu Items to be set horizontal
* #param padding This is the horizontal padding between each Menu Item
*/ private static MenuScene setMenuLayoutToHorizontal(MenuScene menu, int padding){
if (menu.getChildCount()<=1) return menu;
// Starts at 1 since child[0] position won't be changed
for(int i=1; i<menu.getChildCount();i++){
menu.getChildByIndex(i).setPosition(
//it can be optimized by pre-calculating item's width if they are all equal
menu.getChildByIndex(i-1).getX()+menu.getChildByIndex(i).getWidth()+padding,
menu.getChildByIndex(0).getY());
}
return menu;
}

Invisble GtkEventBox vs cursor change

In my application, sometimes I need to disable most of the buttons and event boxes while a process is taking place (except the "cancel" button of course). Each event box contains a label which can be clicked. To make the user understand that these labels are clickable, I have underlined the texts and have made the cursor change when hovered over those labels.
The problem is that when I disable an event box (make it insensitive), you can see a rather ugly artifact:
So, I searched and found this function: gtk_event_box_set_visible_window. Note: I'm using (I have to, unfortunately) Gtk 2.22, but they just removed the documentation from their website. Anyway, the text of this function is the same.
According to this function, you can make the event box create a GDK_INPUT_ONLY window. If I do so, then disabling the event box doesn't make it ugly anymore.
However, since the event box now doesn't have an outputable window, the
gdk_window_set_cursor(event_box->window, cursor);
makes the cursor change for the whole window instead of just the event box.
I can somewhat see the contradiction between no visible window and cursor change over window, but my question is how, otherwise, can I have the cursor change over the event box, but don't see a visible artifact when the event box is disabled?
I tried different methods, such as changing the background of the event box to transparent etc, but all of them were quite complicated.
The simplest solution I found was the following:
static GdkCursor *_normal_cursor = NULL;
static GdkCursor *_hand_cursor = NULL;
/* in main */
_normal_cursor = gdk_window_get_cursor(widgets_to_remember->window->window);
_hand_cursor = gdk_cursor_new(GDK_HAND2);
/* create the event box */
gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE);
gtk_widget_set_events(event_box, GDK_BUTTON_PRESS_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
_fix_event_box(event_box, window);
/* rest of main */
static gboolean _set_hand(GtkWidget *w, GdkEventCrossing *e, gpointer data)
{
gdk_window_set_cursor(w->window, _hand_cursor);
return TRUE;
}
static gboolean _set_normal(GtkWidget *w, GdkEventCrossing *e, gpointer data)
{
gdk_window_set_cursor(w->window, _normal_cursor);
return TRUE;
}
static void _fix_event_box(GtkWidget *eb, GtkWidget *window)
{
g_signal_connect_swapped(eb, "enter_notify_event", G_CALLBACK(_set_hand), window);
g_signal_connect_swapped(eb, "leave_notify_event", G_CALLBACK(_set_normal), window);
}
What this basically does is set the event box invisible, and then set its enter-notify-event and leave-notify-event signal handlers to change the window cursor when the mouse enters or leaves their window.

Can't Get Eclipse Watch Points To Work

I can't get watch points to work in eclipse. Here is what i've done, double clicked to the left of the variable intilization and now it says watchpoints for modify/access. When I run in debug mode the eclipse debugger does not break when the variable is modified. I don't have problems when setting line break points. Any ideas?
Right click on your debugger and choose source look up then add selection on your project
Will work with you :)
It works for me, here's what I did:
package dao;
public class Watchpoint {
/* placed breakpoint here in Eclipse*/ private int i = 0;
public void modif() {
this.i = 3;
}
public static void main(String args[]) {
new Watchpoint().modif();
}
}
Having the above code in Eclipse Helios (Service Release 2), I've added a breakpoint on the "private int i=0; line (by double clicking to it's left). Then if I go into debug mode, in the Breakpoint tab (in upper right), I can select that watchpoint, and then I have the checkable options "Access" and "Modifications". If I check both and then debug the code, the debugger will halt at the line "this.i = 3;" inside the modif() method.