OK, I'm sure it's simple but I will try to explain everything I'm doing in detail so someone could show me my mistakes. Xcode, iOS SDK 6.1, I'm using StoryBoard.
-I have my MenuViewController (View Controller) with some buttons. In Identity inspector I have set my custom class. Every button has it's outlet in MenuViewController.h (using Ctrl drag). Every button is synthesized in MenuController.m and only thing I'm doing so far is setting background in -viewDidLoad Method in MenuViewController.m
-I have another WebViewController (View Controller with Navigation Bar, Bar Button and UIWebView). I have also created new class for that ViewController and set it in Identity inspector. WebView has it's outlet in WebViewController.h and it's synthesized in WebViewController.m
-I have made connection between those two ViewControllers also through Xcode. One button from my MenuViewController is opening WebViewController (I'v done that by Ctrl+Dragging that button to WebViewController and style is set to Modal). I'v done the same thing with button in NavigationBar of my WebViewController, made connection that is opening MenuViewController when clicked (something like Back button).
-Right now, that WebView is opening some webpage when -viewDidLoad method in WebViewController is called.
What I WOULD LIKE TO DO is to set buttonPressed actions in my MenuViewController and for example, if one button is pressed, I want to switch to WebViewController and open some specific URL. If another button is pressed I want also to open that same WebViewController and load some different URL. This should not be hard but I would just like someone to show me the right way for calling method of webView from another class. I'm new in Objective C and only language I know so far is Java, so I'm a bit confused with this .h .m stuff, not sure where to declare what properly. Also if someone could compare what would something here in Objective-C look in Java, that would be great for understanding.
Thanks folks!
I dont use storyboard and do some thing like this:
In your WebViewController .m file make a method some thing like this:
-(id)initWithURL:(NSString *)urlstring
{
self = [super init];
receivedURL = [NSURL URLWithString:urlstring];
return self;
}
and in .h file declare an object of NSURL
NSURL *receivedURL;
and just above the #end
-(id)initWithURL:(NSString *)urlstring;
and in your viewDidLoad Method of WebViewController do
[webview loadRequest:[NSURLRequest requestWithURL:receivedURL]];
Now in your MenuViewController when ever the button action is performed do something like this:
WebViewController *webViewObj = [[WebViewController alloc]initWithURL:yourURLString];
[self presentModalViewController:webViewObj animated:YES];
Related
I'm developing a custom android keyboard in Kotlin and I have looked at this post for how to detect cursor movement/change when the user clicks on text editor.
Here is a snippet of my code of my custom keyboard class which extends InputMethodService.
class CustomKeyboard: InputMethodService() {
override fun onCreateInputView(): View {
// initiated keyboard
}
override fun onStartInputView(info: EditorInfo?, restarting: Boolean) {
// call onUpdateCursorAnchorInfo() whenever cursor/anchor position is changed
this.currentInputConnection.requestCursorUpdates(InputConnection.CURSOR_UPDATE_MONITOR)
Log.i("--------------", "onStartInputView is called")
}
override fun onUpdateCursorAnchorInfo(cursorAnchorInfo: CursorAnchorInfo) {
Log.i("--------------", "onUpdateCursorAnchorInfo is called")
}
}
Then I ran this app on Android Studio emulator and tested on an EditText view in the following way:
I click on the EditText view on my app
I input many random characters in the EditText view
I click randomly on different characters in the EditText view
The system log did print out "onStartInputView is called" when I first clicked on the EditText view.
But it did not print out "onUpdateCursorAnchorInfo is called" anywhere.
What I thought would happen was that "onUpdateCursorAnchorInfo is called" would have been printed multiple times as I clicked on different parts of the EditText view.
However, when I changed to a different app and click on the text editor there, the Log did print out "onStartInputView is called" and "onUpdateCursorAnchorInfo is called" once.
But when I repeat step 1~3 on that app it did not work either
I have no idea why this behaviour occurs.
Any help would be appreciated.
Okay never mind somehow it works now. It must have been a bug or something.
I need to simulate home button click in Espresso on Android phone.
I tried
onView(withId(android.R.id.home)).perform(click());
and onView(withContentDescription("Navigate up")).perform(click());
as some posts suggested but it always fails to find the view.
I'm new to Espresso and not sure how to debug it. Thanks.
Better to use withContentDescription(R.string.abc_action_bar_up_description) rather than "Navigate up" but it doesn't act like a home button click anyway, it only uses the navigation bar's "back" button, so it would only work if you have it in your app.
If you want to simulate the home button click and you are using the UI Automator library, you can simulate it like this
fun pressHome() {
// Might be a good idea to initialize it somewhere else
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
uiDevice.pressHome()
}
Alternatively, if you don't want to or can't use UI Automator, you might try calling Intrstumentation.sendKeyDownUpSync() with the KeyEvent.KEYCODE_HOME.
I've been struggling with the problem in the subject for a bit longer than I'd like to admit.
I'm attempting to programatically execute the same Action that occurs when the user either clicks on the View > Collapse All button or right-clicks within the editor window and then Code Folding > Fold All.
What I tried\found so far:
The String that corresponds to the Action may be found in the enum com.mathworks.mde.editor.ActionID and is: 'collapse-all-folds'.
When the Action activates, the following method seems to be executed: org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...) (hence the netbeans tag).
This code allows me to get instances of EditorAction, ActionManager, MatlabEditor:
jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor;
jAm = com.mathworks.mde.editor.ActionManager(jEd);
jAc = com.mathworks.mde.editor.EditorAction('collapse-all-folds');
My problem is that I can't find a way to actually activate the Action.
Any ideas / alternatives?
EDIT1: After digging a bit in "the book", I think I came even closer than before (but still not quite there). Quoting from the book:
Java GUI components often use anActionMapto store runnableActionsthat are
invoked by listeners on mouse, keyboard, property, or container events. Unlike object methods,Actionscannot be directly invoked by MATLAB.
And then a workaround is explained which involves roughly: getting some sort of an Action object; creating an ActionEvent and invoking Action's actionPerformed with the ActionEvent as an argument, as implemented below:
import java.awt.event.*;
jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor;
jAm = com.mathworks.mde.editor.ActionManager(jEd);
jAc = jAm.getAction(com.mathworks.mde.editor.EditorAction('collapse-all-folds'));
jAe = ActionEvent(jAm, ActionEvent.ACTION_PERFORMED, '');
jAc.actionPerformed(jAe);
This code runs without errors - but does (seemingly?) nothing. I suspect that I'm calling ActionEvent and actionPerformed on the wrong objects (ActionManager has possibly nothing to do with this problem at all).
P.S.
I know that there's a hotkey that does this (Ctrl + =), but this is not what I'm looking for (unless there's a command to simulate a hotkey press :) ).
After immeasurable digging, trial and way too much error - I've done it!
function FullyCollapseCurrentScript()
%// Get the relevant javax.swing.text.JTextComponent:
jTc = com.mathworks.mlservices.MLEditorServices ...
.getEditorApplication.getActiveEditor.getTextComponent();
%// Get the FoldHierarchy for the JTextComponent:
jFh = org.netbeans.api.editor.fold.FoldHierarchy.get(jTc);
%// Finally, collapse every possible fold:
org.netbeans.api.editor.fold.FoldUtilities.collapseAll(jFh);
end
or if compressed into a single, messy, command:
org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...
org.netbeans.api.editor.fold.FoldHierarchy.get(com.mathworks. ...
mlservices.MLEditorServices.getEditorApplication.getActiveEditor. ...
getTextComponent()));
Note that this works on the script currently open in the editor.
Not a perfect solution but simulating the default hotkey press with java.awt.robot is possible.
...finding a way to actually fire the Action directly would be better...
import java.awt.Robot;
import java.awt.event.*;
RoboKey = Robot;
jTextComp = com.mathworks.mlservices.MLEditorServices. ...
getEditorApplication.getActiveEditor.getTextComponent;
jTextComp.grabFocus()
drawnow; %// give time for focus
if jTextComp.hasFocus()
RoboKey.keyPress(KeyEvent.VK_CONTROL);
RoboKey.keyPress(KeyEvent.VK_EQUALS);
RoboKey.keyRelease(KeyEvent.VK_CONTROL);
RoboKey.keyRelease(KeyEvent.VK_EQUALS);
com.mathworks.mde.cmdwin.CmdWin.getInstance.grabFocus; %// focus back to cmdwin
else
warning('Failed to collapse folds: Editor could not take focus')
end
I have a problem with my code using zk components.
I am trying to make a popup window without zul file but compose it within my java code.
This is the sample of the code of mine
#Listen("onClick = #btnPopUp")public void popUp(){
Window win = new Window();
win.setId("winPop");
/* i compose some rows, label and other component here...*/
win.doModal();
}
When i click the btnPopUp button, i got an error message ERROR org.zkoss - >> org.zkoss.zk.ui.SuspendNotAllowedException: Not attached, <Window null#winPop>
I got a clue to use Executions.createComponents() method. But is this method can really help? because i usually use this method with a zul file for ex: Window win = (Window) Executions.createComponents("myZul",parent, map);
Thanks guys, really appreciate your help
//Sorry for my bad english :(
‘Not attached‘ is ZK's way of saying the component (the ‘Window‘) doesn't have a parent component.
win.setParent(parent);
or
parent.appendChild(win);
I believe this needs to be done before ‘win.doModal()‘ is called.
I have an android app that uses the permission "CALL_PHONE". This simple app would just contain a button that would use the call intent to call a specific number. I would like to install this app on both tablets and phone but when it is installed on the tablet, I would like the button to be disabled during runtime so errors wouldn't show when the user tries to call using the tablet without a call function.
At the moment, I am using the setEnabled() and setClickable() method in my MainActivity.java and setting it to false when the user clicks on the button the first time. My question is whether the button can be disabled and the text changed during runtime or when the app is first opened (in a tablet) so the user wouldn't have to click the button first for it to show that the "call" button should be disabled and unclickable?
Refer to this
That will help you in identifying that your application is running on tablet. Now as for disabling your button, I would suggest something like this:
onCreate()
{
setContentView(R.layout.main);
boolean isTablet = checkDevice();
callBtn = (Button) findViewById(R.id.call);
if (isTablet)
{
callBtn.setEnabled(false);
callBtn.setText("Not allowed to make a call");
}
callBtn.setOnClickListener( new onClickListener(){
//Make a call
});
}
public boolean isTablet()
{
//Code for identifying. Return true if application is running on tablet
//return false otherwise
}
So you won't have to wait for user's click on Call button to disable it in tablet.
Hope that helps.
Use button.setEnabled(false); to make visible but user cant click and
button.setVisibility(View.GONE); to make button invisible.and button.setText("YOUR_NEW_TEXT"); to change the button text runtime
And this is not depend on the size of the screen.
Is this you wanted?? OR be more specific with your queston.
... the text changed during runtime?
You can use the setText(); method.
About the other part of your question, you need first to define "What is a tablet?". Is it a 7", 8", 10" screen? Is it a mdpi, hdpi, xhdpi screen? Is it a device which is able to do phone calls? What is a tablet for you or your project? Depending on your answer, you can filter your code (or xml in folders) to make them work the way you want.