码迷,mamicode.com
首页 > 移动开发 > 详细

手机安全卫士学习(2)

时间:2014-10-23 22:23:57      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:des   android   http   color   io   os   ar   使用   sp   

今天是安全卫士学习第二天,主要涉及以下内容:

1 安全卫士主页面的布局

  其中涉及gridview的使用,包括布局文件的引用,以及自定义控件textview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:gravity="center"
        android:background="#8866ff00"
        android:id="@+id/tv_function_list"
        android:layout_width="fill_parent"
        android:layout_height="55dip"
        android:text="功能列表"
        android:textSize="22sp"
        android:textColor="#000000"/>
    <com.djf.mobilesafty.ui.FocusdTextView
        android:layout_marginTop="10dip"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textSize="22sp"
        android:text="距离季前赛还有11天,欲知详细信息,请登录查看详细信息,新赛季更精彩,值得期待··"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <GridView
        android:verticalSpacing="30dip"
        android:layout_marginTop="60dip"
        android:numColumns="3"
        android:id="@+id/gv_item_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

package com.djf.mobilesafty;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class HomeActivity extends Activity {
 private GridView gv_item_home;
 private Myadapter adapter;
 private String[] names  = {
   "手机防盗","通讯卫士","软件管理",
   "进程管理","流量统计","手机杀毒",
   "缓存清理","高级工具","设置中心"};
 private static int[] ids = {
  R.drawable.safe,R.drawable.callmsgsafe,R.drawable.app,
  R.drawable.taskmanager,R.drawable.netmanager,R.drawable.trojan,
  R.drawable.sysoptimize,R.drawable.atools,R.drawable.settings
  
 };
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_home);
  gv_item_home = (GridView) findViewById(R.id.gv_item_home);
  adapter = new Myadapter();
  gv_item_home.setAdapter(adapter);
  gv_item_home.setOnItemClickListener(new OnItemClickListener() {

   @Override
   public void onItemClick(AdapterView<?> parent, View view,
     int position, long id) {
    // TODO Auto-generated method stub
    switch (position) {
    case 8:
     Intent intent = new Intent(HomeActivity.this,SetActivity.class);
     
     startActivity(intent);
     break;

    default:
     break;
    }
   }
  });
 }
 public class  Myadapter extends BaseAdapter{

  @Override
  public int getCount() {
   // TODO Auto-generated method stub
   return names.length;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   // TODO Auto-generated method stub
   View view = View.inflate(HomeActivity.this, R.layout.list_item_home, null);
   TextView  tv_item = (TextView) view.findViewById(R.id.tv_item);
   ImageView iv_item = (ImageView) view.findViewById(R.id.iv_item);
   tv_item.setText(names[position]);
   iv_item.setImageResource(ids[position]);
   return view;
  }
  @Override
  public Object getItem(int position) {
   // TODO Auto-generated method stub
   return null;
  }

  @Override
  public long getItemId(int position) {
   // TODO Auto-generated method stub
   return 0;
  }

  
 }

}

2 设置中心的布局,

其中涉及自定义组件,其中组件中涉及两个textview,一个checkbox,一个view,以及对自定义组件的动作处理,信息的改变

package com.djf.mobilesafty;

import com.djf.mobilesafty.ui.SetItemView;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class SetActivity extends Activity {
 private SetItemView setItemView;
 private SharedPreferences sp;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_set);
  sp = getSharedPreferences("config", MODE_PRIVATE);
  
  setItemView = (SetItemView) findViewById(R.id.siv_update);
  boolean update = sp.getBoolean("update", false);
  if (update) {
   //自动升级已经开启
   setItemView.SetChecked(true);
   setItemView.SetDesc("开启升级");
  }
  else {
   //自动升级已经关闭
   setItemView.SetChecked(false);
   setItemView.SetDesc("关闭升级");
  }
  setItemView.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    Editor editor = sp.edit();
    // 组件已经被选中
    if (setItemView.isChecked()) {
     // 设置组件处于非选中状态,关闭升级
     setItemView.SetChecked(false);
     setItemView.SetDesc("关闭升级");
     editor.putBoolean("update", false);
    } else // 组件没有被选中
    {
     setItemView.SetChecked(true);
     setItemView.SetDesc("开启升级");
     editor.putBoolean("update", true);
    }
    editor.commit();
   }
  });
 }
}

自定义组件布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="55dip"
        android:background="#8866ff00"
        android:gravity="center"
        android:text="设置中心"
        android:textColor="#000000"
        android:textSize="22sp" />

    <com.djf.mobilesafty.ui.SetItemView
        android:id="@+id/siv_update"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </com.djf.mobilesafty.ui.SetItemView>

</LinearLayout>

手机安全卫士学习(2)

标签:des   android   http   color   io   os   ar   使用   sp   

原文地址:http://www.cnblogs.com/jiefeiduan/p/4046871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!