唐詩宋詞具體軟件(源碼講解)

 

下載地址:http://static.apk.hiapk.com/html/2012/05/593136.html

 

—————–主ACTIVITY
package tangshi.co.cc;

import net.miidi.credit.MiidiCredit;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

public class HahamxActivity extends Activity {
    private WebView webView;

    /** 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);

        MiidiCredit
                .init(HahamxActivity.this, "4573", "h3mj1k5b5lwopknk", false);

        setContentView(R.layout.main);
        // webView = (WebView) findViewById(R.id.webview1);
        // ProxyBridge pBridge = new ProxyBridge();
        // webView.addJavascriptInterface(pBridge, "AliansBridge");
        // WebSettings wSet = webView.getSettings();
        // wSet.setJavaScriptEnabled(true);
        // webView.loadUrl("file:///android_asset/naojing.htm");
        // TextView mTextView=(TextView)findViewById(R.id.webview1);

        WebView mWebView = (WebView) findViewById(R.id.webview1);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.loadUrl("file:///android_asset/index.htm");

    }

    protected void dialog() {
        AlertDialog.Builder builder = new Builder(HahamxActivity.this);

        builder.setTitle("唐詩宋詞元曲");
        builder.setMessage("你真的要退出唐詩宋詞元曲嗎?");

        builder.setPositiveButton("否",
                new android.content.DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                    }
                });
        builder.setNegativeButton("是",
                new android.content.DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        android.os.Process.killProcess(android.os.Process
                                .myPid());
                    }
                });
        builder.create().show();

    }

    public void onBackPressed() {
        dialog();
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub

        SubMenu subMenu2 = menu.addSubMenu(0, 2, 0, "唐詩三百首");
        SubMenu subMenu3 = menu.addSubMenu(0, 3, 0, "宋詞");
        SubMenu subMenu4 = menu.addSubMenu(0, 4, 0, "元曲");
        // SubMenu subMenu5 = menu.addSubMenu(0, 5, 0, "英文諺語");
        SubMenu subMenu = menu.addSubMenu(0, 6, 0, "軟件簡介");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
        case 6:
            AlertDialog.Builder builder = new Builder(HahamxActivity.this);

            builder.setTitle("唐詩宋詞元曲!");
            builder.setMessage(R.string.about);
            builder.setPositiveButton("確定",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                        }
                    });

            builder.create().show();

            break;

        case 3:
            Intent intent = new Intent(HahamxActivity.this, xiaohua3.class);
            startActivity(intent);

            break;

        case 2:
            Intent intent1 = new Intent(HahamxActivity.this, xiaohua.class);
            startActivity(intent1);

            break;

        case 4:
            Intent intent4 = new Intent(HahamxActivity.this, chunjie.class);
            startActivity(intent4);
            break;
        // case 5:
        // Intent intent5 = new Intent(HahamxActivity.this, yanyu.class);
        // startActivity(intent5);
        // break;

        default:
            break;
        }

        return super.onOptionsItemSelected(item);
    }

    public class ProxyBridge {
        public int one() {
            return 1;
        }
    }

}

———————接下來的ACTIVITY 類似創建
package tangshi.co.cc;

import tangshi.co.cc.R;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class chunjie extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main4);
        WebView mWebView4=(WebView)findViewById(R.id.webview4);
       
       
        mWebView4.loadUrl("file:///android_asset/index4.htm");
        mWebView4.getSettings().setBuiltInZoomControls(true);
    }

}

 

————–Splash動畫
package tangshi.co.cc;

 

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
   
        new Handler().postDelayed(new Runnable()
        {

            @Override
            public void run()
            {
                // TODO Auto-generated method stub
                Intent it = new Intent(Splash.this, HahamxActivity.class);
                startActivity(it);
                finish();
            }
        }, 3000);
    }

}

—————-main.xml 佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:umadsdk="http://schemas.android.com/apk/res/tangshi.co.cc"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        xmlns:umadsdk="http://schemas.android.com/apk/res/tangshi.co.cc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20px"
        android:orientation="vertical" >

        <net.miidi.credit.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            umadsdk:backgroundColor="#4076AA"
            umadsdk:backgroundTransparent="255"
            umadsdk:textColor="#ffffff" >
        </net.miidi.credit.AdView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="300px"
            android:layout_height="180px"
            android:layout_gravity="center"
            android:src="@drawable/icon1" >
        </ImageView>

        <WebView
            android:id="@+id/webview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </WebView>
    </LinearLayout>

</LinearLayout>

————————
小程序僅供學習參考,祝大傢學習愉快!

 

 

摘自 gongzibai的專欄

發佈留言