I am developing in J2ME, I need to show a text, and then an underlined link / button that people can press.
I cannot use Canvas.
As a temporal solution, I am using the typical command button but I would like to show this option on screen.
(I don't want to use any framework that implies to change everything so that it has a particular look, only an underlined link)
I found it, uff!!!
Command prospectoCommand = new Command("Prospecto", Command.EXIT, 1);
StringItem messageItem2 = new StringItem("", "", Item.HYPERLINK);
messageItem2.setText("push to go to the URL");
ItemCommandListener listener = new ItemCommandListener() {
public void commandAction(Command cmnd, Item item) {
if(cmnd==prospectoCommand)
{
try {
midlet.platformRequest(URL);
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
}
}
};
messageItem2.setDefaultCommand(prospectoCommand);
Related
I have this JavaFx app when I press one of the buttons, an other javafx class lauch!
so all what i need to know is : when I press the back button of the seconde class I need to find the first window with the same values entred in the bigging !
here what I can do for now:
Platform.runLater(new Runnable() {
#Override
public void run() {
try {
new MainApp().start(stage);
} catch (Exception e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
log.error(errors.toString());
}
}
});
I had the same problem and here is the solution:
let's suppose you have those 2 TextField one of them called apiurl and other called mainUrl ! all what you have to do is to to create String url = ""; and go to your button action and add this line : url=apiurl.getText(); in the initialize method in your controller add this : apiurl.setText(url); and this worked well for me !
Basically, what I am trying to do is change the CONTROL_AE_MODE by button click in the app. The user can use AUTO flash(ON_AUTO_FLASH), turn if ON(ON_ALWAYS_FLASH), or OFF(CONTROL_AE_MODE_OFF).
In this example: https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
Line 818, they set the flash once:
// Use the same AE and AF modes as the preview.
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
setAutoFlash(captureBuilder);
// Orientation
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
#Override
public void onCaptureCompleted(#NonNull CameraCaptureSession session,
#NonNull CaptureRequest request,
#NonNull TotalCaptureResult result) {
showToast("Saved: " + mFile);
Log.d(TAG, mFile.toString());
unlockFocus();
}
};
mCaptureSession.stopRepeating();
mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
And then builds the CaptureSession at line 840.
Is there a way to change the CONTROL_AE_MODE after the preview is made?
I have tried remaking the session, which kinda worked:
if(flashMode == CameraView.CAMERA_FLASH_ON){
Log.e("CAMERA 2", "FLASH ON");
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
}else if(flashMode == CameraView.CAMERA_FLASH_OFF){
Log.e("CAMERA 2", "FLASH OFF");
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
}else if(flashMode == CameraView.CAMERA_FLASH_AUTO){
Log.e("CAMERA 2", "FLASH AUTO");
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
}
mFlashMode = flashMode;
if (mCameraCaptureSession != null) {
mCameraCaptureSession.close();
mCameraCaptureSession = null;
}
createCameraPreviewSession();
For some reason, CONTROL_AE_MODE_OFF would turn the whole preview black.
I tried looking in the docs for methods to update but haven't found anything.
Any tutorials or docs is much appreciated.
As mentioned by #cyborg86pl when switching flash modes you should not switch CONTROL_AE_MODE . Instead you can switch between FLASH_MODEĀ“s. Here is a working example for my case:
when (currentFlashState) {
FlashState.AUTO -> {
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH)
}
FlashState.ON -> {
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON)
previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH)
}
FlashState.OFF -> {
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON)
previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF)
}
}
previewRequest = previewRequestBuilder.build()
captureSession.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler)
I don't know why your preview turn black, but you don't need to close capture session manually. From .close() method's docs:
Using createCaptureSession(List , CameraCaptureSession.StateCallback,
Handler) directly without closing is the recommended approach for
quickly switching to a new session, since unchanged target outputs can
be reused more efficiently.
So you can reuse existing CaptureRequest.Builder, set your changed value, build new PreviewRequest and just start new session with this new request, like this:
try {
// Change some capture settings
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
// Build new request (we can't just edit existing one, as it is immutable)
mPreviewRequest = mPreviewRequestBuilder.build();
// Set new repeating request with our changed one
mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
It will be much faster (almost without any visible freeze of preview).
What you want is disabling flash, not auto-exposure (AE), thus you want to use CONTROL_AE_MODE_ON rather than CONTROL_AE_MODE_OFF.
As mentioned in the documentation:
CONTROL_AE_MODE_ON
The camera device's autoexposure routine is active, with no flash control.
I downloaded Launcher3 (Google's Kitkat Launcher) from 4.4 Sources.
I imported it into eclipse . I got rid of errors.And my launcher works pretty good.
But something missing. "GOOGLE NOW" page when you scroll to left.
I can't activate google now.Anyway i don't need that. I want to put my own fragment or layout into first page and other pages will work same like normal launcher.
Like a Google's experience Launcher(Kitkat Launcher of google)'s Google Now page ..
Like this :
I added my layout like this :
here is original codes from workspace.java
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
CellLayout newScreen = (CellLayout)
mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);
newScreen.setOnLongClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
here is edited codes by me on workspace.java
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
if (screenId == 2) //Firstscreen/page
{
RelativeLayout newScreen = (RelativeLayout)
mLauncher.getLayoutInflater().inflate(R.layout.blinkfeed, null);
newScreen.setOnClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
// mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
else
{
CellLayout newScreen = (CellLayout)
mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);
newScreen.setOnLongClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
}
as you can see when its first page i changed layout but i'm getting problems on childviews, animations etc,
anyway i cant even access other pages after that.
i putted everywhere try catch when i get errors because of "celllayout cannot bind to relative bla bla .."
my try catch like this
try
{
cell layout stuff its trying to make animations etc.
}
catch (Exception e)
{
//empty
}
i couldn't make it work at the moment like a google now pages :)
does anybody know about adding a fragment/layout into first page ?
Thanks.
If you want to add some fragment or view in the same manner as Google Now, the Launcher3 code supports that. You basically have 2 ways of getting the desired behavior:
Subclass the Launcher class and overwrite hasCustomContentToLeft() to return true and addCustomContentToLeft() where you can create/inflate your view to be added. Make sure you call addToCustomContentPage and implement the CustomContentCallbacks if you want to be notified when the screen is open.
Implement the same methods as described above in the Launcher class directly.
Hope this helps,
Mihai
I am just a beginner and i wanted to create a web browser in java using swing. now here are the three things that i m not able to do:
Dont know how to load a web page in a frame. here is my code for that:
AddressField.getText();
try {
URI uri=new URI(AddressField.getText());
URL url=uri.toURL();
InputStream in=url.openStream();
} catch (URISyntaxException ex) {
Logger.getLogger(MyBrowser.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(MyBrowser.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(MyBrowser.class.getName()).log(Level.SEVERE, null, ex);
}
I want to put a backward button to get back to previous page. I tried to do that but i doesnt worked well. i need a good code to get back button in function. here is the code for its action listener:
ActionListener ab = new ActionListener() {
#Override public void actionPerformed(ActionEvent e) {
int i= store.size();
loadURL(store.get(i-2).toString());//store is object of ArrayList
}
};
I also want to put an option to open a new tab and also show record of history of pages visited.
hoping for positive responses. every help will be appreciated. thank you
a) From this example it looks like you can just get the webEngine from the WebView instance and load the URL.
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
// that should do it...
webEngine.load(url.toExternalForm());
b) There seems to be history support built-in.
You'll just need to navigate between items...
c) As stated previously, Web History support seems to be built-in. For tabs, you'll likely need to have a TabPane (each tab with its one WebView component).
How to enable the default text highlights menu like: Copy/Paste/Search/Share in android webview ?
Working on Android 1.5 - 2.3 you can use emulateShiftHeld() made public since 2.2 but now is deprecated. this method put your WebView into text selection mode.
https://developer.android.com/reference/android/webkit/WebView.html#emulateShiftHeld%28%29
Unfortunately there's no copy/paste/search/share function integrated in Android, since Android 2.0 the text selection
can be driven by touch but other than that, there's no other thing you can do.
I found a workaround for this
Check out method selectText() on WebView (it's not in API, but can be invoked using reflection)
here is my full method source code:
public void startTextSelection() {
try {
WebView.class.getMethod("selectText").invoke(this);
} catch (Exception e) {
try {
WebView.class.getMethod("emulateShiftHeld").invoke(this);
} catch (Exception e1) {
KeyEvent shiftPressEvent = new KeyEvent(0, 0,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(this);
Toast.makeText(getContext(), R.string.select_text, Toast.LENGTH_LONG).show();
}
}
}
Works on ICS too.
Try this:
mWebView.setHapticFeedbackEnabled(true);
mWebView.setLongClickable(true);