Pages

Thursday, June 20, 2013

Set textview and 2 buttons in a android layout

You use this relativeLayout, that the first Button (Your left button) has to be set after set the second button(Your right button). This only works, if the button, that should be right, still exists before setting the left button.

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

    <RelativeLayout
        android:id="@+id/upperView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray"
        android:orientation="vertical"
        android:padding="10dip" >

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="Hello.."
            android:textColor="@android:color/white" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Button 1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/button1"
            android:text="Button 2" />
    </RelativeLayout>

    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/upperView" />

</RelativeLayout>

enter image description here

Wednesday, June 19, 2013

WebView Methods and properties Android


In on create
WebView wv = (WebView)findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);


     
   if(isInternetAvailable()){
    wv.setWebViewClient(new myWebClient(){
       @Override
       public void onPageFinished(WebView view, String url)
       {
           /* Call whatever, It's finished loading. */
//                wv.setVisibility(View.VISIBLE);
//                iv.setVisibility(View.GONE);
               if (checkk==1)
               {
               
               }
               else{
                wv.setVisibility(View.VISIBLE);
               iv.setVisibility(View.GONE);
           
               }
             
               }
    });

    wv.loadUrl("http://www.google.com");
  }else {
 
  Toast.makeText(getApplicationContext(), "Use internet for better performance", Toast.LENGTH_LONG).show();
  }


public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
   // TODO Auto-generated method stub
   super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
   // TODO Auto-generated method stub

   view.loadUrl(url);
   return true;


// or if you want to open default link in webiview and external in other browser
// if (Uri.parse(url).getHost().equals("http://www.google.com")) {
            // This is my web site, so do not override; let my WebView load the page
          //  return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
     //   Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
     //   startActivity(intent);
     //   return true;

}

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

// Toast.makeText(frontPagee.this, "Your Internet Connection May not be active Or " + description , Toast.LENGTH_LONG).show();
Toast.makeText(frontPagee.this, "Your Internet Connection May not be active ", Toast.LENGTH_LONG).show();
// checkk=1;

}
}

Tuesday, June 18, 2013

ListView -Top and bottom fixed

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
    >
        <TextView 
            android:textSize="12px" 
            android:text="something here" 
            android:layout_width="50px" 
            android:layout_height="wrap_content"
            /> 
        <TextView 
            android:textSize="12px" 
            android:text="something here" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
        />
    </LinearLayout>
    <RelativeLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
        <LinearLayout
            android:id="@+id/footer"
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_alignParentBottom="true"
        >

            <TextView 
                android:layout_height="wrap_content" 
                android:layout_width="0dip" 
                android:layout_weight="1" 
                android:textSize="12px" 
                android:text="50%" 
                /> 
            <TextView 
                android:layout_height="wrap_content" 
                android:layout_width="0dip" 
                android:layout_weight="1" 
                android:textSize="12px" 
                android:text="50%" 
            /> 

        </LinearLayout>
        <ListView
            android:id="@+id/tablebody"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_above="@id/footer"
        />
    </RelativeLayout>
</LinearLayout>

Monday, June 17, 2013

Android Vibrate on click

If you want to make the phone to vibrate when you click on a button from your application:
1. You have to declare in your AndroidManifest.xml the permission:
?
1
<uses-permission android:name="android.permission.VIBRATE"/> 

Tuesday, June 11, 2013

Android camera .set wallapaper

Android Camera App Tutorial

             In this tutorial how to take a photo using the Android Phone camera and set the photo as wallpaper.Here we are using a Image View and 2 buttons for two actions.Lets start learning.
STEP BY STEP

Facebook key-android hash key

To get android key hash code follow these steps (for facebook apps)
  1. Download the openssl for windows here
  2. now unzip to c drive
  3. open cmd prompt
  4. type cd C:\Program Files\Java\jdk1.6.0_26\bin
  5. then type only keytool -export -alias myAlias -keystore C:\Users\your user name\.android\myKeyStore | C:\openssl-0.9.8k_WIN32\bin\openssl sha1 -binary | C:\openssl-0.9.8k_WIN32\bin\openssl enc -a -e
i.e
keytool -exportcert -alias androiddebugkey -keystore C:\Users\YOURUSERNAME\.android\debug.keystore | C:\openssl-0.9.8k_WIN32\bin\openssl sha1 -binary | C:\openssl-0.9.8k_WIN32\bin\openssl enc -a -e

ENTER PASSWORD: android 
  1. Done


GOOGLE MAPS KEY

  1. open cmd prompt
  2. type cd C:\Program Files\Java\jdk1.7.0_10\bin
  3. then type  
keytool -v -list -alias androiddebugkey -keystore "C:\Users\YOUR USERNAME\.android\debug.keystore" 

password is android
4.copy md5 and sh1 


Simple Camera App Android

Java file