Android Development Program Lock application Simple instance _android

Source: Internet
Author: User

1. Basic Ideas

①. Create a database with a locked application (field: _id,packagename), and if the application is locked, maintain the lock-applied package name into the database

②. Lock + unlocked = All applications in mobile phone (appinfoprovider)

2. Locked and unlocked data adapters

Class Myadapter extends baseadapter{private Boolean islock; /** * @param islock is used to differentiate between locked and unlocked applications. Lock data adapter False Unlocked data adapter */Public Myadapter (Boolean islock) {this.
  Islock = Islock;
      @Override public int GetCount () {if (Islock) {Tv_lock.settext ("Lock Applied:" +mlocklist.size ());
    return Mlocklist.size ();
      }else{Tv_unlock.settext ("Unlocked Application:" +munlocklist.size ());
    return Munlocklist.size ();
    @Override public AppInfo getitem (int position) {if (Islock) {return mlocklist.get (position);
    }else{return Munlocklist.get (position);
  @Override public long getitemid (int position) {return position;
    @Override public View getview (int position, View Convertview, ViewGroup parent) {Viewholder holder = null; 
      if (Convertview = = null) {Convertview = View.inflate (Getapplicationcontext (), r.layout.listview_islock_item, NULL);
      Holder = new Viewholder (); Holder.iv_icon = (ImAgeview) Convertview.findviewbyid (R.id.iv_icon);
      Holder.tv_name = (TextView) Convertview.findviewbyid (r.id.tv_name);
      
      Holder.iv_lock = (ImageView) Convertview.findviewbyid (R.id.iv_lock);
    Convertview.settag (holder);
    }else{holder = (viewholder) convertview.gettag ();
    Final AppInfo AppInfo = getitem (position);
    
    Final View Animationview = Convertview;
    Holder.iv_icon.setBackgroundDrawable (Appinfo.icon);
    Holder.tv_name.setText (Appinfo.name);
    if (islock) {holder.iv_lock.setBackgroundResource (r.drawable.lock);
    }else{Holder.iv_lock.setBackgroundResource (R.drawable.unlock);
        Holder.iv_lock.setOnClickListener (New Onclicklistener () {@Override public void OnClick (View v) { Add an animation effect, the animation default is non-blocking, so the animation, the following code also executes Animationview.startanimation (mtranslateanimation);//500 MS//To animation The implementation of the process to do event monitoring, monitor the animation after the completion of the implementation, then remove the data in the collection, manipulate the database, refresh the interface Mtranslateanimation.setanimationlistener (new AnimaTionlistener () {@Override public void Onanimationstart (Animation Animation) {//animation starts with caller
          METHOD} @Override public void Onanimationrepeat (Animation Animation) {//animation to call methods when repeated
            The call method @Override public void Onanimationend (Animation Animation) {After the end of animation execution
              if (islock) {//locked------> Unlocked Process//1. Lock collection deleted one, no lock collection add one, object is GetItem method get Object
              Mlocklist.remove (AppInfo);
              Munlocklist.add (AppInfo);
              2. Delete a data mdao.delete (Appinfo.packagename) from the locked database;
            3. Refresh data adapter mlockadapter.notifydatasetchanged (); }else{//UNLOCKED------> Locked process//1. The lock collection is added one, the collection is removed without a lock, and the object is the object that the GetItem method gets mlocklist
              . Add (AppInfo);
              Munlocklist.remove (AppInfo);
          2. Insert a data Mdao.insert (Appinfo.packagename) from the locked database;    3. Refresh data adapter munlockadapter.notifydatasetchanged ();
      }
          }
        });
    }
    });
  return convertview; }} Myadapter
Mlockadapter = new Myadapter (true);
Lv_lock.setadapter (mlockadapter);
       
Munlockadapter = new Myadapter (false);
Lv_unlock.setadapter (Munlockadapter);

Thank you for reading, I hope to help you, thank you for your support for this site!

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.