public void onClick(View v) {
final Intent intent=new Intent(Intent.ACTION_MAIN,null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn= new ComponentName("com.android.settings","com.android.settings.LOCALE_SETTINGS");
intent.setComponent(cn);
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
You can use this, When the user hits the back button, it will return to your app.
startActivityForResult(new Intent(Settings.ACTION_LOCALE_SETTINGS), 0);
It will bring you to the system language menu. Or:
startActivityForResult(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0);
For keyboards and inputs.
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// button 2 was clicked!
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
}
});
This tutorial can be helpful
http://weimenglee.blogspot.in/2013/06/android-tip-programmatically-displaying.html
If you want to use other constants instead of ACTION_SETTINGS then take a look of android official documentations .http://developer.android.com/reference/android/provider/Settings.html
Related
I am using the lib bellow to make a qr scanner, I am calling the scan with a button. Everything is ok. I need to add a custom button at the bottom center of capture.
lib: com.journeyapps:zxing-android-embedded:3.1.0#aar
And my code to call the scanner:
scannow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
IntentIntegrator scanIntegrator = new IntentIntegrator(MainActivity.this);
scanIntegrator.setPrompt("Scanning...");
scanIntegrator.setBeepEnabled(true);
scanIntegrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES); scanIntegrator.setCaptureActivity(CaptureActivityAnyOrientation.class);
scanIntegrator.setOrientationLocked(true);
scanIntegrator.setBarcodeImageEnabled(true);
scanIntegrator.initiateScan();
}
});
In android studio you can collapse/expand code snippets by toggling +/- in editor(Code/Folding). But when I have a listener, it doesn't collapse whole code but just part of it. How can I hide whole listener? For example when I want to collapse below code:
View.OnClickListener ctgClick = new View.OnClickListener(){ //hide from here
public void onClick(View v){
int tag =(Integer) v.getTag();
Intent intent= new Intent();
intent.putExtra("ctg", tag);
setResult(RESULT_OK, intent);
finish();
}
};//to here
it just hides part of code like this:
View.OnClickListener ctgClick = (v) -> {
int tag =(Integer) v.getTag();
Intent intent= new Intent();
intent.putExtra("ctg", tag);
setResult(RESULT_OK, intent);
finish();
}
};
#mayan anger was partly right. Just go to
File->Settings->Editor->General->Code Folding
And uncheck Closures, now it's working the way I wanted.
In Android Studio this 'collapse' called Folding.
You can try setting your own Custom Folding,
Just go to File->Setting->General->Code Folding.
And make share this one choose :
this one
I dont know why my application can not detect my keyboard.
Application its a JFrame who implements SerialPortEventListener and KeyListener.
In the Jframe of my application I have 1 Tabbed Pane with 2 Panels.
When I press some buttons it doesn't work( NOTHING IN THE OUTPUT).
I will show you my code(Not all, just the most importants parts) :
MY CLASS:
public class java_arduino_frame extends javax.swing.JFrame implements SerialPortEventListener, KeyListener {
MY KEYS FUNCTIONS:
public void keyTyped(KeyEvent e){
throw new UnsupportedOperationException("not yet");
}
public void keyPressed(KeyEvent e){
int keyCode;
keyCode = e.getKeyCode();
System.out.println(keyCode);
}
public void keyReleased(KeyEvent e){
throw new UnsupportedOperationException("not yet");
}
MY CONSTRUCTOR OF MY CLASS:
public java_arduino_frame() {
getContentPane().setBackground( Color.LIGHT_GRAY );
initComponents();
addKeyListener(this);
}
THE MAIN
public static void main(String args[]) {
strong text
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new java_arduino_frame().setVisible(true);
}
});
A KeyListener will only respond when the component it is registered IS focusable AND has focus, since clicking a button will cause the focus to be transferred to the button, the frame will no longer have input focus.
It's also unlikely that the frame would be able to receive keyboard focus directly either.
As a general rule of thumb, you should be using the Key Bindings API instead, which will provide you with the ability to over come the focus realated issues.
Depending on what you're doing, you might also consider using a JTextArea or a JTextField with a DocumentListener, assuming you want to send characters to through the serial connection. Have a look at Listening for Changes on a Document for more details
I am new in android game development. Right now developing an Hidden Object game for android phones.
my question is how to remove an object on touch?
if player touch the object how can it will be removed. i tried on click listener with imageview. but not know what to do next..here is my code
setContentView(R.layout.level1);
bowTie = (ImageView) findViewById(R.id.bowtie);
bowTie.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
???? what goes here ???
is it: finisht():
or
destroy();
or
bowTie.remove();
}
});
}
}
I have a project with 2 activities, the first one is the "SplashActivity" - where I load some network data - the second one, the MainActivity.
Inside of my MainActivity I have a fragment and inside of this fragment a webview. My first point is, when the user clicks on back button, the SplashScreen is open again.
The back button should behave like:
When the user doesn't navigate inside of my webview, close the app.
When the user navigates in webview, use the back history of the browswer.
I read about back stack here: http://developer.android.com/training/implementing-navigation/temporal.html#back-webviews
I didn't understand at all how it should work, because I have all cases "mixed". Anyone knows what should I do to fix this problem?
Any idea or sample code will be appreciate!
Define Webview wb as a global variable. Then try this;
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(wb.canGoBack() == true){
wb.goBack();
}else{
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Application will be closed")
.setMessage("Close app?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
System.exit(0);
}
}).setNegativeButton("No", null).show();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}