Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net1314080903212 #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidworks">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".homeworks.BackActivity"
android:label="@string/title_activity_back">
</activity>
<activity
android:name=".exmaples.ViewBasicActivity"
android:label="@string/title_activity_view_basic">
</activity>
<activity
android:name=".exmaples.ActivityBasicActivity"
android:label="@string/title_activity_activity_basic">
</activity>
<activity
android:name=".exmaples.ActivityBasic2Activity"
android:label="@string/title_activity_activity_basic2">
</activity>
<activity
android:name=".exmaples.FragmentDemoActivity"
android:label="@string/title_activity_fragment">
</activity>
<activity
android:name=".exmaples.FragmentDemoContentActivity"
android:label="@string/title_activity_fragment_content">
</activity>

</application>

</manifest>
100 changes: 100 additions & 0 deletions app/src/main/java/edu/hzuapps/androidworks/MainActivity.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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(), "回收!");
}
*/
}