Mobile Security Guard-main interface development and security guard Main Interface

Source: Internet
Author: User

Mobile Security Guard-main interface development and security guard Main Interface

Activity_home.xml

<? 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: id = "@ + id/text1" style = "@ style/TitleStyle"Android: text =" function list "/>
//Custom TextViewForce focus <com. mxn. mobilesafe. view. FocusedTextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: textColor = "@ color/Black"Android: textSize =" 22sp "android: text =" new message: today ..... "Android: singleLine =" true "// display a line of android: ellipsize =" marquee "// drive-down lights .. Start is omitted .. Android: layout_marginTop = "10dp" android: layout_marginBottom = "10dp"/>
// Add the two lines of code to TextView, which can also be used as a drive lamp <! -- Android: focusableInTouchMode = "true" -->
<!-- android:focusable="true" -->

<GridView android: id = "@ + id/gv_home" android: layout_width = "match_parent" android: layout_height = "0dp" android: layout_weight = "1" android: verticalSpacing = "30dp" android: numColumns = "3"> // display 3 columns </GridView> </LinearLayout>
FocusedTextView.java 
// Customize TextView to get the focus TextViewPublic classFocusedTextViewExtendsTextView {// If there is a style, public FocusedTextView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle ); // TODO Auto-generated constructor stub} // This method is used when attributes exist. public FocusedTextView (Context context, AttributeSet attrs) {super (context, attrs ); // TODO Auto-generated constructor stub} // This method is used when Code new object is used. public FocusedTextView (Context context) {super (context); // TODO Auto-genera Ted constructor stub} @ Override public boolean isFocused () {// indicates whether to obtain the focus. To run the headlight, call this function first to determine whether there is a focus, which is true, only when the horse lights are running can the result be achieved. Forcibly return true ;}}

Home_list_item.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:gravity="center"    android:orientation="vertical" >    <ImageView        android:id="@+id/iv_item"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/home_apps" />        <TextView        android:id="@+id/tv_item"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:textColor="@color/black"        android:textSize="20sp"        /></LinearLayout>

Style. xml

<resources><style name="TitleStyle">        <item name="android:layout_width">match_parent</item>        <item name="android:layout_height">100dp</item>        <item name="android:background">#8866ff00</item>        <item name="android:textColor">@color/black</item>        <item name="android:gravity">center</item>        <item name="android:textSize">22sp</item>    </style></resources>

Color. xml

<?xml version="1.0" encoding="utf-8"?><resources>    <color name="black">#000</color>    </resources>

HomeActivity. java

Public class HomeActivity extends Activity {private GridView gvHome; private String [] mItems = new String [] {"mobile anti-theft", "Communication guard", "software management ", "Process Management", "Traffic Statistics", "Mobile Anti-Virus", "cache cleaning", "advanced tools", "setting Center "}; private int [] mPics = new int [] {R. drawable. home_safe, R. drawable. home_callmsgsafe, R. drawable. home_apps, R. drawable. home_taskmanager, R. drawable. home_netmanager, R. drawable. home_trojan, R. drawable. home_sysoptimize, R. drawable. home_tools, R. drawable. home_settings}; private SharedPreferences mPref; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout.Activity_home); MPref = getSharedPreferences ("config", MODE_PRIVATE); gvHome = (GridView) findViewById (R. id. gv_home); gvHome.SetAdapter (NewHomeAdapter ()); // Set the gvHome. setOnItemClickListener (new OnItemClickListener () {@ Override public void onItemClick (AdapterView <?> Parent, View view, int position, long id) {switch (position) {case 0: // showPasswordDialog (); break; case 8: // set the center startActivity (new Intent (HomeActivity. this, SettingActivity. class); break; case 7: // advanced tool startActivity (new Intent (HomeActivity. this, AtoolsActivity. class); break; case 1: // communication guard, blacklist startActivity (new Intent (HomeActivity. this, CallSafeActivity. class); break; case 2: // software management StartActivity (new Intent (HomeActivity. this, AppManagerActivity. class); break; case 3: // Process Management startActivity (new Intent (HomeActivity. this, TaskManagerActivity. class); break; case 5: // startActivity (new Intent (HomeActivity. this, AntivirusActivity. class); break; case 6: // cache clearance startActivity (new Intent (HomeActivity. this, CleanCacheActivity. class); break; case 4: // traffic management startActivity (new Intent (Ho MeActivity. this, TrafficManagerActivity. class); default: break; }}});}/*** display password pop-up window */protected void showPasswordDialog () {// determine whether to set the password String savedPassword = mPref. getString ("password", null); if (! TextUtils. isEmpty (savedPassword) {// enter the password pop-up window showPasswordInputDialog ();} else {// if no password is set, the pop-up window showPasswordSetDailog ();}} /*** enter the password in the pop-up window */private void showPasswordInputDialog () {AlertDialog. builder builder = new AlertDialog. builder (this); final AlertDialog dialog = builder. create (); View view = View. inflate (this, R. layout.Dialog_input_password, Null); // dialog. setView (view); // set the custom Layout file to dialog. setView (view, 0, 0, 0, 0); // set the margin to 0, which must be 2. final EditText etPassword = (EditText) view. findViewById (R. id. et_password); Button btnOK = (Button) view. findViewById (R. id. btn_ OK); Button btnCancel = (Button) view. findViewById (R. id. btn_cancel); btnOK. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {St Ring password = etPassword. getText (). toString (); if (! TextUtils. isEmpty (password) {String savedPassword = mPref. getString ("password", null); if (MD5Utils. encode (password ). equals (savedPassword) {// Toast. makeText (HomeActivity. this, "Logon successful! ", // Toast. LENGTH_SHORT ). show (); dialog. dismiss (); // jump to the startActivity (new Intent (HomeActivity. this, LostFindActivity. class);} else {Toast. makeText (HomeActivity. this, "Incorrect password! ", Toast. LENGTH_SHORT). show () ;}} else {Toast. makeText (HomeActivity. this," the content of the input box cannot be blank! ", Toast. LENGTH_SHORT ). show () ;}}); btnCancel. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {dialog. dismiss (); // hide dialog}); dialog. show ();}/*** pop-up window for setting the password */private void showPasswordSetDailog () {AlertDialog. builder builder = new AlertDialog. builder (this); final AlertDialog dialog = builder. create (); View view = View. inflate (this,R. layout. dialog_set_password, Null); // dialog. setView (view); // set the custom Layout file to dialog. setView (view, 0, 0, 0, 0); // set the margin to 0, which must be 2. final EditText etPassword = (EditText) view. findViewById (R. id. et_password); final EditText etPasswordConfirm = (EditText) view. findViewById (R. id. et_confirm); Button btnOK = (Button) view. findViewById (R. id. btn_ OK); Button btnCancel = (Button) view. findViewById (R. id. btn_cancel); btnOK. set OnClickListener (new OnClickListener () {@ Override public void onClick (View v) {String password = etPassword. getText (). toString (); String passwordConfirm = etPasswordConfirm. getText (). toString (); // password! = Null &&! Password. equals ("") if (! TextUtils. isEmpty (password )&&! PasswordConfirm. isEmpty () {if (password. equals (passwordConfirm) {// Toast. makeText (HomeActivity. this, "Logon successful! ", // Toast. LENGTH_SHORT ). show (); // Save the password as mPref. edit (). putString ("password", MD5Utils. encode (password )). commit (); dialog. dismiss (); // jump to the startActivity (new Intent (HomeActivity. this, LostFindActivity. class);} else {Toast. makeText (HomeActivity. this, "The two passwords are inconsistent! ", Toast. LENGTH_SHORT). show () ;}} else {Toast. makeText (HomeActivity. this," the content of the input box cannot be blank! ", Toast. LENGTH_SHORT ). show () ;}}); btnCancel. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {dialog. dismiss (); // hide dialog}); dialog. show ();}
ClassHomeAdapterExtendsBaseAdapter{@ Override public int getCount () {return mItems. length; // how much data is displayed} @ Override public Object getItem (int position) {return mItems [position] ;}@ Override public long getItemId (int position) {return position ;} @ Override public View getView (int position, View convertView, ViewGroup parent ){
// Load the layout View = view. inflate (HomeActivity. this, R. layout.Home_list_item, Null );
// Obtain the specific content of each item ImageView ivItem = (ImageView) view. findViewById (R. id. iv_item); TextView tvItem = (TextView) view. findViewById (R. id. TV _item); // set tvItem for each item of girdview. setText (mItems [position]); ivItem. setImageResource (mPics [position]);
// Return the current position item return view ;}}}

 

Knowledge point:

GirdView + BaseAdapter + Click Event

Custom TextView

 

Related Article

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.