Monday, 11 February 2013

Log-in while Username and Passwords are saved in String array ?



1)xml file:
 
<?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:background="#ffffff"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="Enter UserName"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <EditText
        android:id="@+id/edtUserName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Enter Password"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <EditText
        android:id="@+id/edtPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/btnClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="Click Me" />

</LinearLayout>

2)Activity:



package venky.loginthroughstringarray;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.venkool.gvrproject.R;

public class LoginthroughStringArray extends Activity {
      /** Called when the activity is first created. */

      EditText edtUserName, edtPassword;
      Button btnClick;

      boolean status = false;

String[] MyUserName = { "android", "android1", "android2", "android3",
                  "android4", "android5", "Android" };

String[] MyPassword = { "password", "password1", "password2", "password3",
                  "password4", "password5", "Password" };

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.login_test);

            edtUserName = (EditText) findViewById(R.id.edtUserName);
            edtPassword = (EditText) findViewById(R.id.edtPassword);
            btnClick = (Button) findViewById(R.id.btnClick);

            btnClick.setOnClickListener(new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                        // TODO Auto-generated method stub

         String UserName = edtUserName.getText().toString();
         String Password = edtPassword.getText().toString();

                        for (int i = 0; i < MyUserName.length; i++) {

                              if (MyUserName[i].equals(UserName)
&& MyPassword[i].equals(Password)) {

                                    status = true;
                                    Log.e("status", status + "");

                              }

                        }

                        if (status) {
                              Log.e("status", status + "");
                              Toast.makeText(
                                        LoginthroughStringArray.this,
"Successfully Login", Toast.LENGTH_LONG).show();

                        } else {
                              Log.e("status", status + "");
                              Toast.makeText(getApplicationContext(), "Login failed",
                                          Toast.LENGTH_LONG).show();
                        }
                        status = false;
                  }

            });
      }
}

Monday, 4 February 2013

WebView Demo

Demo:

 1.main.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>


2.Activity:
package com.inventiveera.webview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class WebViewActivity extends Activity {
     /** Called when the activity is first created. */

     WebView webview;

     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

          webview = (WebView) findViewById(R.id.webview);

          webview.loadUrl("http://www.venkoolit.blogspot.in");
          WebSettings ws = webview.getSettings();
          ws.setJavaScriptEnabled(true);
          ws.setBuiltInZoomControls(true);
          ws.setMinimumFontSize(20);
     }
}


3.mainifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.inventiveera.webview"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
     <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".WebViewActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

4)Download this Project Click Here