package my.com.test;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Control extends Activity
{
private Button mButton1;
private EditText mEditText1;
private GridItemAdapter adapter;
private GridView mygridview;
//private Button on;
//private Button off;
//public List<MyGrid> list;
private String[] titles=new String[]{"灯1","灯2","灯3","灯4","灯5","灯6","灯7","灯8","灯9","灯10","灯11","灯12","灯13","灯14","灯15","灯16",};
private int[]images={R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,
R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,
R.drawable.loff,R.drawable.loff,};
public void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.grid);
mEditText1=(EditText)findViewById(R.id.editText1);
mButton1=(Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
String messageAddress = mEditText1.getText().toString();
String messageContent = "check";
SmsManager smsManager = SmsManager.getDefault();
if(messageAddress.trim().length()!=0 && messageContent.trim().length()!=0)
{
try{
PendingIntent pintent = PendingIntent.getBroadcast(Control.this, 0, new Intent(), 0);
smsManager.sendTextMessage(messageAddress, null, messageContent, pintent, null);
}catch(Exception e)
{
e.printStackTrace();
}
Toast.makeText(Control.this, "发送成功", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Control.this, "发送地址或者内容不能为空", Toast.LENGTH_SHORT).show();
}
}
});
mygridview=(GridView)findViewById(R.id.gridview); //寻找资源,在main中的GridView
adapter=new GridItemAdapter(titles,images,this);
mygridview.setAdapter(adapter);
mygridview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v,int position,long i)
//The AdapterView where the click happened
//The view within the AdapterView that was clicked
//The position of the view in the adapter
//The row id of the item that was clicked
{
GridView changedgridview=(GridView)findViewById(R.id.gridview);
if(images[position]==R.drawable.loff)
{
images[position]=R.drawable.lon2;
GridItemAdapter changedadapter=new GridItemAdapter(titles,images,Control.this);
changedgridview.setAdapter(changedadapter);
Toast.makeText(Control.this, "灯" (position 1) "已经打开", Toast.LENGTH_SHORT).show();
}
else
{
images[position]=R.drawable.loff;
GridItemAdapter changedadapter=new GridItemAdapter(titles,images,Control.this);
changedgridview.setAdapter(changedadapter);
Toast.makeText(Control.this, "灯" (position 1) "已经关闭", Toast.LENGTH_SHORT).show();
}
}
});
}
public class MyGrid
{
private String title;
private int imageId;
public MyGrid(String objname,int imageId)
{
super();
this.title=objname;
this.imageId=imageId;
}
public String getObjname()
{
return title;
}
public int getImageId()
{
return imageId;
}
}
public class GridItemAdapter extends BaseAdapter
{
private List<MyGrid> gridlist;
private LayoutInflater inflater;
public GridItemAdapter(String[] Objname,int[]images,Context context)
{
super();
gridlist=new ArrayList<MyGrid>();
inflater=LayoutInflater.from(context);
for(int i=0;i<images.length;i )
{
MyGrid picture=new MyGrid(Objname[i],images[i]);
gridlist.add(picture);
}
}
public int getCount()
{
return gridlist.size();
}
public long getItemId(int index)
{
return index;
}
public Object getItem(int index)
{
return gridlist.get(index);
}
public class ViewHolder
{
ImageView image;
TextView text;
}
public View getView(int index,View view,ViewGroup parent)
{
ViewHolder gridholder;
if(view==null)
{
view=inflater.inflate(R.layout.control, null);
gridholder=new ViewHolder();
gridholder.image=(ImageView)view.findViewById(R.id.gridimageview);
gridholder.text=(TextView)view.findViewById(R.id.gridtextview);
view.setTag(gridholder);
}
else
{
gridholder=(ViewHolder)view.getTag();
}
gridholder.image.setImageResource(gridlist.get(index).getImageId());
gridholder.text.setText(gridlist.get(index).getObjname());
return view;
}
}
}
资源文件列表
LightControl/.classpath , 475
LightControl/.project , 848
LightControl/.settings/org.eclipse.jdt.core.prefs , 177
LightControl/AndroidManifest.xml , 1345
LightControl/bin/AndroidManifest.xml , 1345
LightControl/bin/classes.dex , 15272
LightControl/bin/classes/my/com/test/BuildConfig.class , 331
LightControl/bin/classes/my/com/test/Control$1.class , 2106
LightControl/bin/classes/my/com/test/Control$2.class , 2313
LightControl/bin/classes/my/com/test/Control$GridItemAdapter$ViewHolder.class , 663
LightControl/bin/classes/my/com/test/Control$GridItemAdapter.class , 2847
LightControl/bin/classes/my/com/test/Control$MyGrid.class , 763
LightControl/bin/classes/my/com/test/Control.class , 2572
LightControl/bin/classes/my/com/test/LightControl$1.class , 1025
LightControl/bin/classes/my/com/test/LightControl$2.class , 1021
LightControl/bin/classes/my/com/test/LightControl.class , 1054
LightControl/bin/classes/my/com/test/R$attr.class , 319
LightControl/bin/classes/my/com/test/R$color.class , 518
LightControl/bin/classes/my/com/test/R$drawable.class , 489
LightControl/bin/classes/my/com/test/R$id.class , 981
LightControl/bin/classes/my/com/test/R$layout.class , 459
LightControl/bin/classes/my/com/test/R$string.class , 732
LightControl/bin/classes/my/com/test/R.class , 523
LightControl/bin/classes/my/com/test/reg$1.class , 1006
LightControl/bin/classes/my/com/test/reg.class , 894
LightControl/bin/classes/my/com/test/SmsReceiver.class , 2355
LightControl/bin/dexedLibs/annotations-8b8e17cfdff2c23e04390cb26df3b2cd.jar , 1265
LightControl/bin/jarlist.cache , 120
LightControl/bin/LightControl.apk , 21485
LightControl/bin/resources.ap_ , 12545
LightControl/bin/res/crunch/drawable/ic_launcher.png , 2200
LightControl/bin/res/crunch/drawable/loff.PNG , 923
LightControl/bin/res/crunch/drawable/lon2.PNG , 677
LightControl/bin/res/drawable/ic_launcher.png , 2200
LightControl/bin/res/drawable/loff.PNG , 923
LightControl/bin/res/drawable/lon2.PNG , 677
LightControl/gen/my/com/test/BuildConfig.java , 153
LightControl/gen/my/com/test/R.java , 2992
LightControl/proguard.cfg , 1248
LightControl/project.properties , 360
LightControl/res/drawable/background_login_div_bg.xml , 438
LightControl/res/drawable/ic_launcher.png , 2574
LightControl/res/drawable/loff.PNG , 1144
LightControl/res/drawable/lon2.PNG , 905
LightControl/res/layout/control.xml , 889
LightControl/res/layout/grid.xml , 1489
LightControl/res/layout/main.xml , 3568
LightControl/res/layout/reg.xml , 3529
LightControl/res/values/color.xml , 311
LightControl/res/values/strings.xml , 725
LightControl/src/my/com/test/Control.java , 6630
LightControl/src/my/com/test/LightControl.java , 1410
LightControl/src/my/com/test/reg.java , 815
LightControl/src/my/com/test/SmsReceiver.java , 1408
