📄 ac01.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.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.LinearLayout;import android.widget.RadioButton;import android.widget.RadioGroup;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; private int state_var_C, state_var_D; private TextView tx; private String file_name = null; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); this.goto_state_1(); } void show_layout_01(){ RadioGroup rg = new RadioGroup(this); RadioGroup.LayoutParams rg_param = new RadioGroup.LayoutParams(WC, WC); rg.setOrientation(RadioGroup.HORIZONTAL); rg.setLayoutParams(rg_param); // rg.setOnClickListener(this); RadioButton rb_btn1 = new RadioButton(this); rb_btn1.setText("KM.xml"); rb_btn1.setId(1001); rb_btn1.setChecked(false); rb_btn1.setOnClickListener(this); rg.addView(rb_btn1,rg_param); RadioButton rb_btn2 = new RadioButton(this); rb_btn2.setText("Customer.xml"); rb_btn2.setId(1002); rb_btn2.setChecked(false); rb_btn2.setOnClickListener(this); rg_param.leftMargin = 12; rg.addView(rb_btn2, rg_param); //================================= LinearLayout.LayoutParams l_ck_param; LinearLayout ck_layout = new LinearLayout(this); ck_layout.setOrientation(LinearLayout.HORIZONTAL); CheckBox 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); CheckBox 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.LayoutParams param; LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); param = new LinearLayout.LayoutParams(WC, WC); param.leftMargin = 3; param.topMargin = 3; layout.addView(ck_layout,param); tx = new TextView(this); tx.setBackgroundResource(R.drawable.bk); param = new LinearLayout.LayoutParams(300, 150); param.leftMargin = 3; param.topMargin = 3; layout.addView(tx,param); param = new LinearLayout.LayoutParams(WC, WC); param.leftMargin = 3; param.topMargin = 10; layout.addView(rg, param); //------------------------------------- setContentView(layout); } void goto_state_1() // Transit { state_var_A = 1; goto_state_2(); } void goto_state_2() { state_var_A = 2; this.show_layout_01(); state_var_B = 3; // default state_var_C = 6; // default state_var_D = 8; // default } void goto_state_3() { state_var_B = 3; tx.setTextColor(Color.RED); tx.setText(" Select a XML file..."); } void goto_state_4() { state_var_B = 4; tx.setTextColor(Color.BLACK); file_name = "/res/raw/km.xml"; this.transition_action(); } void goto_state_5() { state_var_B = 5; tx.setTextColor(Color.BLUE); file_name = "/res/raw/customer.xml"; 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() { state_var_D = 8; this.transition_action(); } void goto_state_9() { state_var_D = 9; this.transition_action(); } void transition_action() { this.showXml(file_name); } public void showXml(String full_name) { if(state_var_B == 3) { tx.setTextColor(Color.RED); tx.setText(" Select a XML file..."); return; } 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_C == 7 && state_var_D == 9 ) tx.setTypeface(null, Typeface.BOLD_ITALIC); else if(state_var_C == 7) tx.setTypeface(null, Typeface.BOLD); else if(state_var_D == 9) tx.setTypeface(null, Typeface.ITALIC); else tx.setTypeface(null, Typeface.NORMAL); } @Override public void onClick(View v) { if(v.getId() == 1001) { if(state_var_B == 3 || state_var_B == 5) goto_state_4(); } else if(v.getId() == 1002){ if(state_var_B == 3 || state_var_B == 4) goto_state_5(); } } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(buttonView.getId() == 2001){ if(state_var_C == 6) goto_state_7(); else if(state_var_C == 7) goto_state_6(); } else if(buttonView.getId() == 2002){ if(state_var_D == 8) goto_state_9(); else if(state_var_D == 9) goto_state_8(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -