Saturday 29 December 2012

Jquery Mobile: Filtered List - only match beginning of string


$("document").ready( function (){
function beginsWith( text, pattern) {
text= text.toLowerCase();
pattern = pattern.toLowerCase();
return pattern != text.substr( 0, pattern.length );
}
 $(".ui-listview").listview('option', 'filterCallback', beginsWith)

});

Friday 21 December 2012

android: Intent


Intent intent = new Intent(this, Main.class);
startActivity(intent);

android: Intent clear flags

intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

android: Count down timer


int timer = b.getInt("time", 0);                                      

new CountDownTimer(timer, 500) {

@Override
public void onTick(long millisUntilFinished) {
tv1.setText("Sec Left:" + millisUntilFinished / 1000 + " ");

// TODO Auto-generated method stub

}

Thursday 20 December 2012

android: Getting source code from an APK file


Step 1:

Make a new folder and put .apk file (which you want to decode) now rename this .apk file with extension .zip (eg:rename from filename.apk to filename.apk.zip) and save it..now you get classes.dex files etc...at this stage you are able to see drawable but not xml and java file...so cont...

Step 2:

Now extract this zip apk file in the same folder(in this eg or case NEW FOLDER). now dowmload dex2jar from this link http://code.google.com/p/dex2jar/ and extract it to the same folder (in this case NEW FOLDER).....now open command prompt and reach to that folder (in this case NEW FOLDER)....after reaching write dex2jar classes.dex and press enter.....now you get classes.dex.dex2jar file in the same folder......now download java decompiler from http://java.decompiler.free.fr/?q=jdgui and now double click on jd-gui and click on open file then open classes.dex.dex2jar file from that folder...now you get class file...save all these class file (click on file then click "save all sources" in jd-gui)..by src name....at this stage you get source...but xml files are still unreadable...so cont...

Step 3:

Now open another new folder and put these files
  1. put .apk file which you want to decode
  2. download apktool v1.x AND apktool install window using google and put in the same folder
  3. download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)
  4. Open a command window
  5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
  6. apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one

Thursday 13 December 2012

android: Showing keypad moves layout up

android:windowSoftInputMode="adjustResize"

add this to the activity in the manifest file

Wednesday 12 December 2012

android: User Current location

Note: Enable your provider


locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);

if (location != null) {
System.out.println("Provider " + provider + " has been selected.");

} else {
Toast.makeText(this, "Provider not available",
Toast.LENGTH_SHORT).show();
}

double lat = location.getLatitude();
double lng = location.getLongitude();
String addressString = "no address found";
           Geocoder gc = new Geocoder(this, Locale.getDefault());
           try
           {
               List<Address> addresses = gc.getFromLocation(lat,
                       lng, 1);
               StringBuilder sb = new StringBuilder();
               if (addresses.size() > 0)
               {
                   address = (Address) addresses.get(0);
                   sb.append(address.getLocality());
               }
               addressString = sb.toString();
           
           } catch (Exception e)
           {
           }
           Toast.makeText(this,"Your Current Location is :"+String.valueOf(addressString),
    Toast.LENGTH_SHORT).show();
           System.out.println(String.valueOf(addressString));
                   Toast.makeText(this,address.getLocality(),
     Toast.LENGTH_SHORT).show();

android: android with SOAP webservice interaction.

Android:


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class Registration extends Activity {
private String METHOD_NAME ="insertRegistrationData";
private String NAMESPACE ="http://DefaultNamespace";
private String SOAP_ACTION ="RegistrationDataService";
private static final String URL="http://192.168.2.7:8080/AptbusServer/services/RegistrationData";
EditText pname,address,zip,birth;
TextView newpatient,exist;
RadioButton pnew,exis;
Button button;
private RadioGroup choice;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        pname=(EditText)findViewById(R.id.pname);
        address=(EditText)findViewById(R.id.address);
        zip=(EditText)findViewById(R.id.zip);
        birth=(EditText)findViewById(R.id.birth);
        choice=(RadioGroup)findViewById(R.id.ptype);
        pnew=(RadioButton)findViewById(R.id.newpatient);
        exis=(RadioButton)findViewById(R.id.exist);
        button=(Button)findViewById(R.id.next);
        button.setOnClickListener(new OnClickListener(){
        String radio=null;
@Override
public void onClick(View v) {
   
Editable patientname=pname.getText();
       String patname=patientname.toString();
     
       Editable addr=address.getText();
       String paddr=addr.toString();
     
       Editable zipco=zip.getText();
       String pzip=zipco.toString();
       int pzipcode=Integer.parseInt(pzip);
     
       Editable pbirth=birth.getText();
       String pbirthdate=pbirth.toString();
       if(pnew.isChecked())
       {
        radio=(String) pnew.getText();
       }
       if(exis.isChecked())
       {
        radio=(String) exis.getText();
       }
     
       Toast.makeText(getApplicationContext(),
                            patname+""+ paddr+""+ pzip+""+pbirthdate+""+radio, Toast.LENGTH_LONG).show();
       try
       {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("s",patname);
        request.addProperty("s1",paddr);
        request.addProperty("zip",pzipcode);
        request.addProperty("gender",radio);
        request.addProperty("dat",pbirthdate);
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) soapEnvelope
.getResponse();
String result = resultsRequestSOAP.toString();
System.out.println("Result : " + result);
       
       }
       catch(Exception e)
       {
        System.out.println(e);
       }
   
     
}
       
        });
     
       
   
    }
}

SOAP:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://DefaultNamespace" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="insertRegistrationData">
    <complexType>
     <sequence>
      <element name="s" type="xsd:string"/>
      <element name="s1" type="xsd:string"/>
      <element name="zip" type="xsd:int"/>
      <element name="gender" type="xsd:string"/>
      <element name="dat" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="insertRegistrationDataResponse">
    <complexType>
     <sequence>
      <element name="insertRegistrationDataReturn" type="xsd:int"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="insertRegistrationDataResponse">

      <wsdl:part element="impl:insertRegistrationDataResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="insertRegistrationDataRequest">

      <wsdl:part element="impl:insertRegistrationData" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:portType name="RegistrationData">

      <wsdl:operation name="insertRegistrationData">

         <wsdl:input message="impl:insertRegistrationDataRequest" name="insertRegistrationDataRequest">

       </wsdl:input>

         <wsdl:output message="impl:insertRegistrationDataResponse" name="insertRegistrationDataResponse">

       </wsdl:output>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="RegistrationDataSoapBinding" type="impl:RegistrationData">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="insertRegistrationData">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="insertRegistrationDataRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="insertRegistrationDataResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="RegistrationDataService">

      <wsdl:port binding="impl:RegistrationDataSoapBinding" name="RegistrationData">

         <wsdlsoap:address location="http://localhost:8080/AptbusServer/services/RegistrationData"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>


android: alphabet indexer / display alphabets while scrolling.


class MyCursorAdapter extends SimpleCursorAdapter implements SectionIndexer {

AlphabetIndexer alphaIndexer;

public MyCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {

super(context, layout, c, from, to);

alphaIndexer = new AlphabetIndexer(c,
c.getColumnIndex(Dbasehelper.COL_WORD),
" ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}

@Override
public int getPositionForSection(int section) {

return alphaIndexer.getPositionForSection(section); // use the
// indexer

}

@Override
public int getSectionForPosition(int position) {

return alphaIndexer.getSectionForPosition(position); // use the
// indexer

}

@Override
public Object[] getSections() {

return alphaIndexer.getSections(); // use the indexer

}

}

Tuesday 11 December 2012

android: SharedPreference to compare dates.


 int thisDay = c.get(Calendar.DAY_OF_YEAR);
       
        SharedPreferences prefs = this.getSharedPreferences(
             "tempstore", Context.MODE_PRIVATE);
        int l = prefs.getInt("tempstore", 23);
        if(l != thisDay){
        Toast.makeText(getApplicationContext(), "not equal", Toast.LENGTH_SHORT).show();
        prefs.edit().putInt("tempstore", thisDay).commit();
        }

Tuesday 4 December 2012

android: menus


private static final int MENU_HELP = 0;
private static final int MENU_ABOUT = 1;
private static final int MENU_EXIT = 2;


public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_HELP, 0, "Help").setIcon(R.drawable.help);
menu.add(0, MENU_ABOUT, 0, "About").setIcon(R.drawable.about);
menu.add(0, MENU_EXIT, 0, "exit").setIcon(R.drawable.exit);
return true;
}


public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_HELP:
startActivity(new Intent(this, Help.class));
return true;
case MENU_ABOUT:
startActivity(new Intent(this, About.class));
return true;
case MENU_EXIT:
System.exit(0);
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

android: Preventing WebView reload on Rotation


HelloWebView.java

public class HelloWebView extends Activity {
WebView webview;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
if (savedInstanceState == null)
{
webview.loadUrl(" http://www.google.com");
}
webview.setWebViewClient(new HelloWebViewClient());

}

@Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
webview.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onSaveInstanceState(savedInstanceState);
webview.restoreState(savedInstanceState);
}

public class HelloWebViewClient extends WebViewClient {
ProgressDialog progressBar = ProgressDialog.show(HelloWebView.this, "Loading", "Please wait...");

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}

@Override
public void onPageFinished(WebView view, String url) {
if (progressBar.isShowing()) {
                 progressBar.dismiss();
             }
}
}

webview.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

</LinearLayout>