Mobile Security Defender Learning (2)

Source: Internet
Author: User

Today is security defender study the next day, mainly involves the following content:

1 Security Defender home Page layout

This involves the use of the GridView, including a reference to the layout file, and a custom control 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= "Feature List"
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 days from pre-season, for more information, please login to view details, the new season is more exciting and worth looking forward to"
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 = {
"Mobile phone anti-theft", "Communication Defender", "Software Management",
"Process Management", "traffic statistics", "mobile antivirus",
"Cache cleanup", "Advanced tools", "Setting Center"};
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 Set the layout of the center,

It involves a custom component, where the component involves two TextView, a checkbox, a view, and the action processing of the custom component, which changes the information

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) {
   //automatic upgrade has been turned on
   setitemview.setchecked (true);
   setitemview.setdesc ("open Upgrade");
  }
  else {
   //automatic upgrade has been turned off
   setitemview.setchecked (false);
   setitemview.setdesc ("Off Upgrade");
  }
  setitemview.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
Editor editor = Sp.edit ();
Component has been selected
if (setitemview.ischecked ()) {
Set component unchecked, turn off upgrade
Setitemview.setchecked (FALSE);
Setitemview.setdesc ("Off Upgrade");
Editor.putboolean ("Update", false);
} else//Component not selected
{
Setitemview.setchecked (TRUE);
Setitemview.setdesc ("open Upgrade");
Editor.putboolean ("Update", true);
}
Editor.commit ();
}
});
}
}

customizing component Layouts

<?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= "Setting Center"
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>

Mobile Security Defender Learning (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.