Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UninstallerActivity extends Activity {
- private EditText mEditText = null;
- private ListView mListView = null;
- private AppListAdapter mAppListAdapter = null;
- public void update() {
- // TODO
- mAppListAdapter.clear();
- Intent aIntent = new Intent(Intent.ACTION_MAIN, null);
- aIntent.addCategory(Intent.CATEGORY_LAUNCHER);
- PackageManager aPackageManager = getPackageManager();
- List<ResolveInfo>aList = aPackageManager.queryIntentActivities(aIntent, PackageManager.PERMISSION_GRANTED);
- for( ResolveInfo rInfo : aList )
- if (isSystemPackage(rInfo)){
- mAppListAdapter.add( rInfo.activityInfo.applicationInfo );
- }
- if( mListView != null ) {
- mListView.setAdapter( mAppListAdapter );
- }
- }
- private boolean isSystemPackage(ResolveInfo ri){
- return ((ri.activityInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)!=1)?true:false;
- }
- public void remove( ApplicationInfo mApplicationInfo ) {
- // TODO
- Intent aIntent = new Intent(Intent.ACTION_DELETE, Uri.parse( "package:" + mApplicationInfo.packageName ) );
- startActivity( aIntent );
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- mEditText = (EditText) findViewById( R.id.EditText );
- mEditText.setSingleLine();
- mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
- mEditText.addTextChangedListener( new TextWatcher() {
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- if( s.length() > 0 ) {
- // TODO
- mAppListAdapter.clear();
- Intent aIntent = new Intent(Intent.ACTION_MAIN, null);
- aIntent.addCategory(Intent.CATEGORY_LAUNCHER);
- PackageManager aPackageManager = getPackageManager();
- List<ResolveInfo>aList = aPackageManager.queryIntentActivities(aIntent, PackageManager.PERMISSION_GRANTED);
- for( ResolveInfo rInfo : aList ) {
- String aName = rInfo.activityInfo.applicationInfo.loadLabel( aPackageManager ).toString().toLowerCase();
- String aValue = s.toString().toLowerCase();
- if( aName.contains( aValue ) ) {
- mAppListAdapter.add( rInfo.activityInfo.applicationInfo );
- }
- }
- if( mListView != null ) {
- mListView.setAdapter( mAppListAdapter );
- }
- }
- else {
- UninstallerActivity.this.update();
- }
- }
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- public void afterTextChanged(Editable s) {
- }
- });
- mListView = (ListView) findViewById( R.id.ListView );
- mAppListAdapter = new AppListAdapter( this );
- //if( mListView != null ) {
- //mListView.setAdapter( mAppListAdapter );
- //}
- this.update();
- mListView.setOnItemClickListener( new OnItemClickListener() {
- public void onItemClick( AdapterView<?> parent, View view, int position, long id ) {
- ApplicationInfo mApplicationInfo = (ApplicationInfo) mAppListAdapter.getItem(position);
- UninstallerActivity.this.remove( mApplicationInfo );
- }
- });
- }
- }
- mAppListAdapter.remove(mApplicationInfo );
- mAppListAdapter.notifyDataSetChanged();
Add Comment
Please, Sign In to add comment