Showing posts with label Disable soft keypad. Show all posts
Showing posts with label Disable soft keypad. Show all posts

Wednesday, July 4, 2012

Android Tricks

How to Disable Home Button
    @Override
    public void onAttachedToWindow()
    {  
        this.getWindow().setType(WindowManager.
          LayoutParams.TYPE_KEYGUARD_DIALOG);     
        super.onAttachedToWindow();  
    }

How to Disable Back Button
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }

How to Disable Soft Keypad
final EditText txtName = (EditText) findViewById(R.id.txtName);
txtName.setInputType(InputType.TYPE_NULL);

How to Make Static Rotation/orientation in Android
        //if you want to lock screen for always Portrait mode
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                                     or
        //if you want to lock screen for always Landscape mode
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);



How to Disable screen Rotation/orientation in Android (better way is java code)
        
//put this code in Manifest file, activity tag
android:screenOrientation="nosensor"
android:configChanges="keyboardHidden|orientation|screenSize"
/* or even you can do it by programmatically -- just put 
Configuration code in onResume method before calling super 
like this */
@Override
protected void onResume() {
    int currentOrientation = getResources().getConfiguration()
                               .orientation;
    if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) 
    {
        setRequestedOrientation(ActivityInfo
                    .SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }
    else {
        setRequestedOrientation(ActivityInfo
                    .SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }
    super.onResume();
}
How to Disable Title Bar and Make Full Screen View
        
//1. put this line to manifest file in Application tag
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

//2. put below code in your activity onCreate method

//to disable notification bar (Top Bar)
        requestWindowFeature(Window.FEATURE_NO_TITLE);        
                         
        
        //to set full screen view
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        //make sure code should be before calling below method
        setContentView(R.layout.main);

How to Create Alert Dialog Box in Android
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("App has been started..")
               .setCancelable(false)
               .setTitle("Alert Box")           
               .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                   }
               });
        AlertDialog alert = builder.create();
        alert.show();


How to Create Toast message in Android
        Toast.makeText(getApplicationContext(), "I am splash message..", 
          Toast.LENGTH_LONG).show();

How to create Progress Dialog in Android
        ProgressDialog dialog = ProgressDialog.show(this, "", 
                "Loading. Please wait...", true);

Load Home Screen Programmatically in Android
  //to load home screen put this code in onClick method of desired button
  Intent startMain = new Intent(Intent.ACTION_MAIN);
  startMain.addCategory(Intent.CATEGORY_HOME);
  startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(startMain)

Start/Load Activity from Activity
//put this code where you want to load another Activity
Intent intent = new Intent(FirstActivty.this, SecondActivity.class);

//below 2 lines (Flags) are optional
// 1. if set, it will clear the back stack
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

// 2. If set, this activity will become the start of a new task
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

Make a Phone Call
String mobileNo = "+919741817902";
String uri = "tel:" + mobileNo.trim() ;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);

//add permission to Manifest file

How to check WiFi is Connected or Not
public void chekcWifiConnectDisconnect() {
  ConnectivityManager connManager = (ConnectivityManager) 
    getSystemService(CONNECTIVITY_SERVICE);
  NetworkInfo mWifi = connManager
    .getNetworkInfo(ConnectivityManager.TYPE_WIFI);

  if (mWifi.isConnected()) {
   Log.v("Debug", "Wifi is connectd..");   
  } else {
   Log.v("Debug", "Wifi is not connectd..");   
  }

}

//dont forget to put Wifi permission in manifest file

Friday, June 15, 2012

Disable Soft KeyPad in Android

Today we will learn another small trick to disable the softkeypad in Android

Sometime you need to disable the Soft Keypad / Virtual Keypad and want to input from either Physical Keypad or Design your own keypad.

Pretty simple and only single line code i have written below

        //disable soft keypad
        txtName.setInputType(InputType.TYPE_NULL);


also i made simple app to achieve this if need then have look on it.

-------------------------------------------
App Name: DisableKeypad
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 / API 10
Default Activity Name: DisableKeypadActivity
-------------------------------------------
so here is the code

DisableKeypadActivity.java

package com.rdc;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.widget.EditText;

public class DisableKeypadActivity extends Activity {
    private EditText txtName=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.main);
        
        //get the id of edit text 
        txtName =(EditText) findViewById(R.id.txtName);
        
        //disable soft keypad
        txtName.setInputType(InputType.TYPE_NULL);
    }
}

main.xml

 
 
  
 



AndroidManifest.xml




 
  
  
  
  
 




Tested on Real Androd Device [Sony Ericsson (XPERIA)] the output will be like this..


I'd love to hear your thoughts!