⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac01.java

📁 基于ANdroid平台的高欢堂书籍的对应源代码 非常有用
💻 JAVA
字号:
package com.misoo.ppxx;import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import android.app.Activity;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Color;import android.graphics.Typeface;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.ImageButton;import android.widget.LinearLayout;import android.widget.TextView;import android.widget.CompoundButton.OnCheckedChangeListener;public class ac01 extends Activity implements OnCheckedChangeListener, OnClickListener {  	private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT; 	private int state_var_A, state_var_B, state_B_history, state_C_history;	private int state_var_C;	private TextView tx;	private CheckBox cx1, cx2; 	    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        this.goto_state_1();      }            void show_layout_01(){  	        LinearLayout.LayoutParams l_ck_param;           	LinearLayout ck_layout = new LinearLayout(this);        	ck_layout.setOrientation(LinearLayout.HORIZONTAL);                       	cx1 = new CheckBox(this);        	cx1.setId(2001);    	    cx1.setText("Bold");    	    cx1.setChecked(false);    	    cx1.setOnCheckedChangeListener(this);    	    l_ck_param = new LinearLayout.LayoutParams(WC, WC);    	    l_ck_param.topMargin = 20;    	    l_ck_param.leftMargin = 12;    	    ck_layout.addView(cx1, l_ck_param);    	        	    cx2 = new CheckBox(this);    	    cx2.setId(2002);    	    cx2.setText("Italic");    	    cx2.setChecked(false);    	    cx2.setOnCheckedChangeListener(this);    	    l_ck_param = new LinearLayout.LayoutParams(WC, WC);    	    l_ck_param.topMargin = 20;    	    l_ck_param.leftMargin = 32;    	    ck_layout.addView(cx2, l_ck_param);            //================================     	    LinearLayout layout = new LinearLayout(this);         	layout.setOrientation(LinearLayout.VERTICAL);         	LinearLayout.LayoutParams param          	      = new LinearLayout.LayoutParams(WC, WC);            param.leftMargin = 20;            param.topMargin = 3;            layout.addView(ck_layout,param);                        tx = new TextView(this);            tx.setId(3002);            tx.setBackgroundResource(R.drawable.bk);            tx.setBackgroundColor(Color.WHITE);            tx.setTextColor(Color.BLUE);            tx.setOnClickListener(this);            param = new LinearLayout.LayoutParams(250, 150);            param.leftMargin = 3;            param.topMargin = 3;            layout.addView(tx,param);                        ImageButton ibtn = new ImageButton(this);            ibtn.setId(3003);            ibtn.setBackgroundResource(R.drawable.x_blue);            ibtn.setAlpha(88);            ibtn.setOnClickListener(this);            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.x_xxx);            ibtn.setImageBitmap(bmp);                                               param = new LinearLayout.LayoutParams(50, 50);            param.topMargin = 15;            param.leftMargin = 75;            layout.addView(ibtn, param);            setContentView(layout);                          }        void goto_state_1() // Transit        {          	state_var_A = 1;          	state_B_history = 0;          	state_C_history = 0;  	        }          void goto_state_2()         {        	state_var_A = 2;        	this.show_layout_01();        	if(state_B_history == 0)  state_B_history = 4;        	state_var_B = state_B_history;        	if(state_var_B == 4 )        		cx1.setChecked(false);        	else        		cx1.setChecked(true);        	if(state_C_history == 0)  state_C_history = 6;         	state_var_C = state_C_history;         	if(state_var_C == 6 )        		cx2.setChecked(false);        	else        		cx2.setChecked(true);         	this.transition_action();        }                  void goto_state_3() // initial & transit        {            state_var_A = 3;            tx.setTextColor(Color.RED);      	    tx.setText(" Pause...");      	    Editor editor = getSharedPreferences("STATE", 0).edit();  		    editor.putInt("state_B", state_var_B);  		    editor.putInt("state_C", state_var_C);  		    editor.commit();         }          void goto_state_4()         {            state_var_B = 4;            this.transition_action();        }          void goto_state_5()         {            state_var_B = 5;            this.transition_action();        }          void goto_state_6()         {            state_var_C = 6;            this.transition_action();        }         void goto_state_7()         {            state_var_C = 7;            this.transition_action();        }          void goto_state_8() // transit        {        	SharedPreferences passwdfile = getSharedPreferences("STATE", 0);   	        state_B_history = passwdfile.getInt("state_B", 4);   	        state_C_history = passwdfile.getInt("state_C", 6);  	        goto_state_2();         }         void transition_action()         {            this.showXml("/res/raw/km.xml");        }           public void showXml(String full_name) {       	    String preXml = "";      		InputStream is = R.class.getResourceAsStream(full_name);      		if(is == null)      			setTitle("fail to open " + full_name);      		BufferedInputStream bso = new BufferedInputStream(is);      	  	BufferedReader reader = new BufferedReader(new InputStreamReader(bso));       	  	String s;      		try {      			s = reader.readLine();      		   	while(s != null){         	        preXml += s.trim();;	      	   	    s = reader.readLine();      	  	    }      		}      	    catch (Exception e1) {      	     	e1.printStackTrace();      	   }      	    tx.setText(preXml);            if(state_var_B == 5 && state_var_C == 7 )    	                  tx.setTypeface(null, Typeface.BOLD_ITALIC);            else if(state_var_B == 5)          	  tx.setTypeface(null, Typeface.BOLD);            else if(state_var_C == 7)          	  tx.setTypeface(null, Typeface.ITALIC);            else          	  tx.setTypeface(null, Typeface.NORMAL);      }     @Override  	 public void onPause() {  	        super.onPause();             this.goto_state_3();  	   }     @Override 	 protected void onResume() {         super.onResume();         if(state_var_A == 1)             this.goto_state_2();         else if(state_var_A == 3) {        	    goto_state_8();         }      }  	 @Override	 public void onCheckedChanged(CompoundButton buttonView,				boolean isChecked) {  		    if(state_var_A != 2) return;			if(buttonView.getId() == 2001)				if(isChecked)				    goto_state_5();				else					goto_state_4();		    else if(buttonView.getId() == 2002)			    if(isChecked)				    goto_state_7();				else					goto_state_6();		}		@Override		public void onClick(View v) {			 if(v.getId() == 3002 && state_var_A == 2)				 finish();			 else if(v.getId() == 3003){				    if(state_var_A == 2)	    	          this.goto_state_3();				    else if(state_var_A == 3)					  this.goto_state_8();			 }		}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -