forked from hzuapps/android-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hzuapps#91....hzuapps#48 lab5....lab9
实验基本完成
- Loading branch information
Showing
3 changed files
with
77 additions
and
61 deletions.
There are no files selected for viewing
70 changes: 35 additions & 35 deletions
70
...in/java/edu/hzuapps/androidworks/homeworks/com1314080901106/Com1314080901106Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
package com.example.chenpeixin.com1314080901106; | ||
package edu.hzuapps.androidworks.homeworks.com1314080901106; | ||
|
||
import android.os.Bundle; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.Snackbar; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
||
public class Com1314080901106Activity extends AppCompatActivity { | ||
public class Com1314080901106Activity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_com1314080901106); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | ||
.setAction("Action", null).show(); | ||
} | ||
}); | ||
} | ||
|
||
@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_com1314080901106, menu); | ||
return true; | ||
findViewById(R.id.btnSendMsg).setOnClickListener(this); | ||
findViewById(R.id.btnReg).setOnClickListener(this); | ||
findViewById(R.id.btnunReg).setOnClickListener(this); | ||
} | ||
|
||
|
||
|
||
|
||
@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) { | ||
return true; | ||
public void onClick(View v) { | ||
|
||
switch (v.getId()) { | ||
case R.id.btnSendMsg: | ||
//Intent i =new Intent(this,MyReceiver.class); | ||
Intent i =new Intent(Com1314080901106Receiver.ACTION); | ||
i.putExtra("data","HzuUniversity"); | ||
sendBroadcast(i); | ||
break; | ||
case R.id.btnReg: | ||
if(receiver==null) { | ||
receiver=new Com1314080901106Receiver(); | ||
registerReceiver(receiver,new IntentFilter(Com1314080901106Receiver.ACTION)); | ||
} | ||
break; | ||
case R.id.btnunReg: | ||
if(receiver!=null) { | ||
unregisterReceiver(receiver); | ||
receiver =null; | ||
} | ||
break; | ||
|
||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
private Com1314080901106Receiver receiver = null; | ||
} |
16 changes: 16 additions & 0 deletions
16
...in/java/edu/hzuapps/androidworks/homeworks/com1314080901106/Com1314080901106Receiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package edu.hzuapps.androidworks.homeworks.com1314080901106; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
public class Com1314080901106Receiver extends BroadcastReceiver { | ||
public static final String ACTION ="edu.hzuapps.androidworks.homeworks.com1314080901106.intent.action.Com1314080901106Receiver"; | ||
public Com1314080901106Receiver() { | ||
} | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
System.out.println("接收到了消息,消息的内容是:"+intent.getStringExtra("data")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" | ||
android:layout_height="match_parent" android:fitsSystemWindows="true" | ||
tools:context=".Com1314080901106"> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:orientation="vertical" | ||
tools:context="edu.hzuapps.androidworks.homeworks.com1314080901106.Com1314080901106Activity"> | ||
|
||
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content" | ||
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> | ||
<Button | ||
android:layout_width="94dp" | ||
android:layout_height="wrap_content" | ||
android:text="发送消息" | ||
android:id="@+id/btnSendMsg" /> | ||
|
||
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" | ||
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> | ||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="注册接收器" | ||
android:id="@+id/btnReg" /> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<include layout="@layout/content_com1314080901106" /> | ||
|
||
<android.support.design.widget.FloatingActionButton android:id="@+id/fab" | ||
android:layout_width="wrap_content" android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" | ||
android:src="@android:drawable/ic_dialog_email" /> | ||
|
||
<ImageView | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:src="@drawable/link"/> | ||
|
||
</android.support.design.widget.CoordinatorLayout> | ||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="注销接收器" | ||
android:id="@+id/btnunReg" /> | ||
</LinearLayout> |