diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..3e21a7f4 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/edu/hzuapps/androidworks/MainActivity.java b/app/src/main/java/edu/hzuapps/androidworks/MainActivity.java new file mode 100644 index 00000000..4fa0b793 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/MainActivity.java @@ -0,0 +1,100 @@ +package edu.hzuapps.androidworks; + +import android.app.Activity; +import android.content.Intent; +import android.nfc.Tag; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; + +import java.util.List; + +import edu.hzuapps.androidworks.exmaples.ActivityBasicActivity; +import edu.hzuapps.androidworks.exmaples.FragmentDemoActivity; +import edu.hzuapps.androidworks.exmaples.ViewBasicActivity; +import edu.hzuapps.androidworks.homeworks.BackActivity; + +public class MainActivity extends ActionBarActivity { + + public static final String TAG = MainActivity.class.getSimpleName(); + + String mName; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); +// TODO 解析学生实验目录 + setContentView(R.layout.activity_main); + + // 显示例子按钮 + prepareExampleButton(R.id.button_activitybasic); + prepareExampleButton(R.id.button_viewbasic); + prepareExampleButton(R.id.button_fragmentdemo); + + // 随机显示一位同学的作业 + prepareExampleButton(R.id.button_random); + + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + System.out.println("Yes"); +// Log.i(this.getClass().getSimpleName(), "View created!"); + Log.i("标题", "信息"); + return true; + } + + return super.onOptionsItemSelected(item); + } + + private void openActivity(Activity activity, Class activityClass) { + Intent intent = new Intent(activity, activityClass); + activity.startActivity(intent); + } + + private void prepareExampleButton(final int buttonId) { + final Activity thisActivity = this; + Button button = (Button) findViewById(buttonId); + if (button != null) { + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + openActivity(thisActivity, getActivity(buttonId)); + } + }); + } else { + Log.e(TAG, "按钮不存在: " + buttonId); + } + } + + private Class getActivity(int id) { + if (R.id.button_activitybasic == id) { + return ActivityBasicActivity.class; + } else if (R.id.button_viewbasic == id) { + return ViewBasicActivity.class; + } else if (R.id.button_fragmentdemo == id) { + return FragmentDemoActivity.class; + } else { + // return BackActivity.class; + return Net1314080903212.class; + } + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/Net1314080903212.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/Net1314080903212.java new file mode 100644 index 00000000..f8bb7172 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/Net1314080903212.java @@ -0,0 +1,79 @@ +package edu.hzuapps.androidworks.homeworks; + +import android.os.Bundle; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import edu.hzuapps.androidworks.R; +//import edu.hzuapps.androidworks.homeworks.Net1314080903212; + +/** + * Created by dell on 2016/3/21. + */ +public class Net1314080903212 extends BackActivity { + + private LinearLayout mTextContainer; + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + +// TextView textView = new TextView(this); +// textView.setText("isshe"); + + createViewInJava(); + setContentView(mTextContainer); + + // 默认使用XML创建的View +// setContentView(R.layout.net1314080903212); + +// prepareExampleButton(R.id.button_net1314080903212); +} + + + private void createViewInJava() { + mTextContainer = new LinearLayout(this); + ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( // + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + mTextContainer.setLayoutParams(layoutParams); + mTextContainer.setOrientation(LinearLayout.HORIZONTAL); + + TextView textView = new TextView(this); + textView.setText("isshe: Net13140809032122"); + + mTextContainer.addView(textView); + } + +/* + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_subactivity, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == R.id.action_back) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + protected void onStop() { + super.onStop(); + Log.i(this.getClass().getSimpleName(), "停止!"); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + Log.i(this.getClass().getSimpleName(), "回收!"); + } +*/ +}