Guest User

Untitled

a guest
Jul 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. public class UninstallerActivity extends Activity {
  2.  
  3. private EditText mEditText = null;
  4. private ListView mListView = null;
  5. private AppListAdapter mAppListAdapter = null;
  6.  
  7.  
  8.  
  9. public void update() {
  10. // TODO
  11. mAppListAdapter.clear();
  12.  
  13.  
  14.  
  15. Intent aIntent = new Intent(Intent.ACTION_MAIN, null);
  16. aIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  17.  
  18. PackageManager aPackageManager = getPackageManager();
  19. List<ResolveInfo>aList = aPackageManager.queryIntentActivities(aIntent, PackageManager.PERMISSION_GRANTED);
  20.  
  21. for( ResolveInfo rInfo : aList )
  22. if (isSystemPackage(rInfo)){
  23. mAppListAdapter.add( rInfo.activityInfo.applicationInfo );
  24. }
  25.  
  26.  
  27.  
  28.  
  29. if( mListView != null ) {
  30. mListView.setAdapter( mAppListAdapter );
  31. }
  32. }
  33.  
  34. private boolean isSystemPackage(ResolveInfo ri){
  35. return ((ri.activityInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)!=1)?true:false;
  36. }
  37.  
  38. public void remove( ApplicationInfo mApplicationInfo ) {
  39. // TODO
  40. Intent aIntent = new Intent(Intent.ACTION_DELETE, Uri.parse( "package:" + mApplicationInfo.packageName ) );
  41. startActivity( aIntent );
  42. }
  43.  
  44.  
  45.  
  46. @Override
  47. public void onCreate(Bundle savedInstanceState) {
  48. super.onCreate(savedInstanceState);
  49.  
  50. setContentView(R.layout.main);
  51.  
  52. mEditText = (EditText) findViewById( R.id.EditText );
  53. mEditText.setSingleLine();
  54. mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
  55.  
  56. mEditText.addTextChangedListener( new TextWatcher() {
  57. public void onTextChanged(CharSequence s, int start, int before, int count) {
  58. if( s.length() > 0 ) {
  59. // TODO
  60. mAppListAdapter.clear();
  61.  
  62. Intent aIntent = new Intent(Intent.ACTION_MAIN, null);
  63. aIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  64.  
  65. PackageManager aPackageManager = getPackageManager();
  66. List<ResolveInfo>aList = aPackageManager.queryIntentActivities(aIntent, PackageManager.PERMISSION_GRANTED);
  67.  
  68. for( ResolveInfo rInfo : aList ) {
  69. String aName = rInfo.activityInfo.applicationInfo.loadLabel( aPackageManager ).toString().toLowerCase();
  70. String aValue = s.toString().toLowerCase();
  71.  
  72. if( aName.contains( aValue ) ) {
  73. mAppListAdapter.add( rInfo.activityInfo.applicationInfo );
  74. }
  75. }
  76.  
  77. if( mListView != null ) {
  78. mListView.setAdapter( mAppListAdapter );
  79. }
  80. }
  81. else {
  82. UninstallerActivity.this.update();
  83. }
  84. }
  85.  
  86. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  87. }
  88.  
  89. public void afterTextChanged(Editable s) {
  90. }
  91. });
  92.  
  93. mListView = (ListView) findViewById( R.id.ListView );
  94. mAppListAdapter = new AppListAdapter( this );
  95.  
  96. //if( mListView != null ) {
  97. //mListView.setAdapter( mAppListAdapter );
  98. //}
  99.  
  100.  
  101. this.update();
  102.  
  103. mListView.setOnItemClickListener( new OnItemClickListener() {
  104. public void onItemClick( AdapterView<?> parent, View view, int position, long id ) {
  105. ApplicationInfo mApplicationInfo = (ApplicationInfo) mAppListAdapter.getItem(position);
  106. UninstallerActivity.this.remove( mApplicationInfo );
  107. }
  108. });
  109. }
  110.  
  111.  
  112. }
  113.  
  114. mAppListAdapter.remove(mApplicationInfo );
  115. mAppListAdapter.notifyDataSetChanged();
Add Comment
Please, Sign In to add comment