Monday, March 25, 2013

web view demo

MainActivity.java
-----------------------------------------------------------------

package net.kerul.alfatihah;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
//import android.webkit.WebSettings;
import android.widget.Toast;

public class MainActivity extends Activity {

// this version is using WebView to provide al-Fatihah in Arabic,
// and translation in Malay.

private MediaPlayer mp;
private TextView tvFooter, tvHeader;
private Boolean reload_sound;
// String url = "http://www.youtube.com/";
// String url = "http://news.yahoo.com/";
String url = "http://news.yahoo.com/chemical-romance-breaks-decade-plus-151936152.html";


ProgressDialog mProgress;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
// flag to reload sound
reload_sound = true;

// UIs activation
tvHeader = (TextView) findViewById(R.id.tvHeader);
// btnplay.setOnClickListener(this);
tvFooter = (TextView) findViewById(R.id.tvFooter);
// btnpause.setOnClickListener(this);

tvHeader.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Log.e("-------Header--", " ");

// Toast.makeText(MainActivity.this, "Header",
// Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(Intent.ACTION_VIEW,
// Uri.parse("http://www.progmaatic.com/"));

}
});

tvFooter.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Log.e("-------Footer--", " ");

// Toast.makeText(MainActivity.this, "Footer",
// Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(Intent.ACTION_VIEW,
// Uri.parse("http://www.progmaatic.com/"));

}
});

// btnstop = (Button) findViewById(R.id.btnstop);
// btnstop.setOnClickListener(this);
// btnstop.setEnabled(false);

// define webview
WebView webview = (WebView) findViewById(R.id.webview);
webview.setHorizontalScrollBarEnabled(false);
webview.loadUrl(url);

getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
Window.PROGRESS_VISIBILITY_ON);
// set Javascript
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setTextSize(WebSettings.TextSize.LARGER);
settings.setSupportZoom(false); // Zoom Control on web (You don't need
// this
// if ROM supports Multi-Touch
settings.setBuiltInZoomControls(true); // Enabl

// the init state of progress dialog
mProgress = ProgressDialog.show(this, "Loading",
"Please wait for a moment...");

// add a WebViewClient for WebView, which actually handles loading data
// from web
webview.setWebViewClient(new WebViewClient() {
// load url
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}

// when finish loading page
public void onPageFinished(WebView view, String url) {
if (mProgress.isShowing()) {
mProgress.dismiss();
}
}
});

// webview.loadUrl("http://www.google.com.bd/");

}

}

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" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center_vertical" >

            <TextView
                android:id="@+id/tvHeader"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:layout_weight="6.64"
                android:gravity="center"
                android:text="La Fleur"
                android:background="@android:color/black"
                android:textColor="@android:color/white"
                android:textSize="25dp"
                android:textStyle="bold"/>

        </TableRow>
    </TableLayout>

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

    <TextView
        android:id="@+id/tvFooter"
        android:layout_width="fill_parent"
        android:layout_height="25dp"
        android:layout_weight="0.03"
        android:gravity="center"
        android:text="Powered by Yahoo! News"
        android:background="@android:color/black"
        android:textColor="@android:color/white" />

</LinearLayout>


Manifest.xml
--------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.kerul.alfatihah"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

    <uses-sdk android:minSdkVersion="7" />

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

</manifest>

download: http://www.mediafire.com/?0gupsnyq09r7zkv


No comments:

Post a Comment