发布于 2016-02-17 15:16:02 | 134 次阅读 | 评论: 0 | 来源: 网友投递
Android移动端操作系统
Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<includelayout="@layout/head"android:id="@+id/head"/>
<cn.com.karl.view.MyGridView
android:id="@+id/bookShelf"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/head"
android:cacheColorHint="#00000000"
android:columnWidth="90.0dip"
android:fadingEdge="none"
android:horizontalSpacing="5dp"
android:listSelector="#00000000"
android:numColumns="3"
android:scrollbars="none"
android:verticalSpacing="20dp"/>
<SlidingDrawer
android:id="@+id/sliding"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="@+id/allApps"
android:handle="@+id/imageViewIcon"
android:orientation="vertical">
<Button
android:id="@+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="本地"
android:textSize="18dp"
android:background="@drawable/btn_local"/>
<GridView
android:id="@+id/allApps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/file_list_bg"
android:columnWidth="60dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:padding="10dp"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"/>
</SlidingDrawer>
</RelativeLayout>
publicclassMyGridViewextendsGridView{
privateBitmapbackground;
publicMyGridView(Contextcontext,AttributeSetattrs){
super(context,attrs);
background=BitmapFactory.decodeResource(getResources(),
R.drawable.bookshelf_layer_center);
}
@Override
protectedvoiddispatchDraw(Canvascanvas){
intcount=getChildCount();
inttop=count>0?getChildAt(0).getTop():0;
intbackgroundWidth=background.getWidth();
intbackgroundHeight=background.getHeight()+2;
intwidth=getWidth();
intheight=getHeight();
for(inty=top;y<height;y+=backgroundHeight){
for(intx=0;x<width;x+=backgroundWidth){
canvas.drawBitmap(background,x,y,null);
}
}
super.dispatchDraw(canvas);
}
}
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_height="110dp"
android:layout_width="90dp"
android:layout_marginTop="10dp"
android:background="@drawable/cover_txt"
android:id="@+id/imageView1"
android:text="天龙八部"
android:padding="15dp"
android:textColor="#000000"
/>
</LinearLayout>
publicclassBookShelfActivityextendsBaseActivity{
privateGridViewbookShelf;
privateint[]data={
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,
R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt,R.drawable.cover_txt
};
privateString[]name={
"天龙八部","搜神记","水浒传","黑道悲情"
};
privateGridViewgv;
privateSlidingDrawersd;
privateButtoniv;
privateList<ResolveInfo>apps;
/**Calledwhentheactivityisfirstcreated.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
bookShelf=(GridView)findViewById(R.id.bookShelf);
ShlefAdapteradapter=newShlefAdapter();
bookShelf.setAdapter(adapter);
bookShelf.setOnItemClickListener(newOnItemClickListener(){
@Override
publicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intarg2,
longarg3){
//TODOAuto-generatedmethodstub
if(arg2>=data.length){
}else{
Toast.makeText(getApplicationContext(),""+arg2,Toast.LENGTH_SHORT).show();
}
}
});
loadApps();
gv=(GridView)findViewById(R.id.allApps);
sd=(SlidingDrawer)findViewById(R.id.sliding);
iv=(Button)findViewById(R.id.imageViewIcon);
gv.setAdapter(newGridAdapter());
sd.setOnDrawerOpenListener(newSlidingDrawer.OnDrawerOpenListener()//开抽屉
{
@Override
publicvoidonDrawerOpened(){
iv.setText("返回");
iv.setBackgroundResource(R.drawable.btn_local);//响应开抽屉事件
//,把图片设为向下的
}
});
sd.setOnDrawerCloseListener(newSlidingDrawer.OnDrawerCloseListener(){
@Override
publicvoidonDrawerClosed(){
iv.setText("本地");
iv.setBackgroundResource(R.drawable.btn_local);//响应关抽屉事件
}
});
}
classShlefAdapterextendsBaseAdapter{
@Override
publicintgetCount(){
//TODOAuto-generatedmethodstub
returndata.length+5;
}
@Override
publicObjectgetItem(intarg0){
//TODOAuto-generatedmethodstub
returnarg0;
}
@Override
publiclonggetItemId(intarg0){
//TODOAuto-generatedmethodstub
returnarg0;
}
@Override
publicViewgetView(intposition,ViewcontentView,ViewGrouparg2){
//TODOAuto-generatedmethodstub
contentView=LayoutInflater.from(getApplicationContext()).inflate(R.layout.item1,null);
TextViewview=(TextView)contentView.findViewById(R.id.imageView1);
if(data.length>position){
if(position<name.length){
view.setText(name[position]);
}
view.setBackgroundResource(data[position]);
}else{
view.setBackgroundResource(data[0]);
view.setClickable(false);
view.setVisibility(View.INVISIBLE);
}
returncontentView;
}
}
@Override
publicbooleanonKeyDown(intkeyCode,KeyEventevent){
//TODOAuto-generatedmethodstub
if(keyCode==KeyEvent.KEYCODE_BACK){
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
builder.setMessage("你确定退出吗?")
.setCancelable(false)
.setPositiveButton("确定",
newDialogInterface.OnClickListener(){
publicvoidonClick(DialogInterfacedialog,
intid){
finish();
}
})
.setNegativeButton("返回",
newDialogInterface.OnClickListener(){
publicvoidonClick(DialogInterfacedialog,
intid){
dialog.cancel();
}
});
AlertDialogalert=builder.create();
alert.show();
returntrue;
}
returnsuper.onKeyDown(keyCode,event);
}
privatevoidloadApps(){
Intentintent=newIntent(Intent.ACTION_MAIN,null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
apps=getPackageManager().queryIntentActivities(intent,0);
}
publicclassGridAdapterextendsBaseAdapter{
publicGridAdapter(){
}
publicintgetCount(){
//TODOAuto-generatedmethodstub
returnapps.size();
}
publicObjectgetItem(intposition){
//TODOAuto-generatedmethodstub
returnapps.get(position);
}
publiclonggetItemId(intposition){
//TODOAuto-generatedmethodstub
returnposition;
}
publicViewgetView(intposition,ViewconvertView,ViewGroupparent){
//TODOAuto-generatedmethodstub
ImageViewimageView=null;
if(convertView==null){
imageView=newImageView(BookShelfActivity.this);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(newGridView.LayoutParams(50,50));
}else{
imageView=(ImageView)convertView;
}
ResolveInfori=apps.get(position);
imageView.setImageDrawable(ri.activityInfo
.loadIcon(getPackageManager()));
returnimageView;
}
}
}