Java Question Hide a some public method

Similar threads

B4A Code Snippet Advertising id
Java Question CacheCleaner
B4A Library Creat Your Own CacheCleaner App
B4A Question Now - Android 6 ServiceStartAtExact not accurate
B4A Library CacheCleaner

mohsen nasrabady

Active Member
Licensed User
Hi this code is a cache cleaner that works perfectly and i want to publish this in forum
the only problem is how can hide some public methods from B4A

B4X:
package anywheresoftware.b4a.cachecleaner;

import java.util.ArrayList;
import java.util.List;

import com.frozendevs.cache.cleaner.model.AppsListItem;
import com.frozendevs.cache.cleaner.model.CleanerService;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Environment;
import android.os.IBinder;
import android.os.StatFs;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ShortName("CacheCleaner")
@Version(1f)
@Events(values = { "OnScanStarted","onScanProgress (Current As int , Total As int)","onScanCompleted (AppsList As Object)","onCleanStarted","onCleanCompleted (CacheSize As Long)" })
@Permissions(values = {"android.permission.GET_PACKAGE_SIZE","android.permission.CLEAR_APP_CACHE"})

public class CacheCleaner implements CleanerService.OnActionListener {
   
    CleanerService mCleanerService;
    private long totalmem;
    private long freemem;
    private boolean isinitialized = false;
    BA ba;
    String event;
   
    private ServiceConnection mServiceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mCleanerService = ((CleanerService.CleanerServiceBinder) service).getService();
            mCleanerService.setOnActionListener(CacheCleaner.this);
            isinitialized = true;

            updateStorageUsage();

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mCleanerService.setOnActionListener(null);
            mCleanerService = null;
            isinitialized = false;
        }
    };
    private ArrayList<Object> L;
   
    public void initialize(String EventName,final BA baa){
       
        ba = baa;
        event = EventName;
        BA.applicationContext.bindService(new Intent(BA.applicationContext.getApplicationContext(), CleanerService.class),
            mServiceConnection, Context.BIND_AUTO_CREATE);
   
    }
   
    public void ScanCache(){
       
        if (mCleanerService != null && !mCleanerService.isScanning() &&
                !mCleanerService.isCleaning()) {
            mCleanerService.scanCache();
        }
       
    }
   
    public void CleanCache(){
       
        if (mCleanerService != null && !mCleanerService.isScanning() &&
                !mCleanerService.isCleaning() && mCleanerService.getCacheSize() > 0) {
    

            mCleanerService.cleanCache();
        }
    }

    @Override
    public void onScanStarted(Context context) {
        // TODO Auto-generated method stub
        BA.Log("Scan Started");
        ba.raiseEvent(this, event+"_onscanstarted",new Object[]{});
       
    }

    @Override
    public void onScanProgressUpdated(Context context, int current, int max) {
        // TODO Auto-generated method stub
        ba.raiseEvent(this, event+"_onscanprogress", new Object[]{current,max});
    }

    @Override
    public void onScanCompleted(Context context, List<AppsListItem> apps) {
        // TODO Auto-generated method stub
        int n;
        L = new ArrayList<>();
        for(n=0;n<apps.size();n++){
            AppsListItem item = apps.get(n);
            L.add(new Object[]{item.getApplicationName(),item.getPackageName(),item.getCacheSize(),item.getApplicationIcon()});
        }
        ba.raiseEvent(this, event+"_onscancompleted", new Object[]{L});
    }

    @Override
    public void onCleanStarted(Context context) {
        // TODO Auto-generated method stub
        ba.raiseEvent(this, event+"_oncleanstarted", new Object[]{});
    }

    @Override
    public void onCleanCompleted(Context context, long cacheSize) {
        // TODO Auto-generated method stub
        ba.raiseEvent(this, event+"_oncleancompleted", new Object[]{cacheSize});
        updateStorageUsage();
    }
   
    private void updateStorageUsage() {
        StatFs stat = new StatFs(Environment.getDataDirectory().getAbsolutePath());

        totalmem = (long) stat.getBlockCount() * (long) stat.getBlockSize();
        long medMemory = mCleanerService != null ? mCleanerService.getCacheSize() : 0;
        long lowMemory = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
        freemem = totalmem - medMemory - lowMemory;

    }
   

}
 
Top