Example usage for android.app ActivityManager getRunningServices

List of usage examples for android.app ActivityManager getRunningServices

Introduction

In this page you can find the example usage for android.app ActivityManager getRunningServices.

Prototype

@Deprecated
public List<RunningServiceInfo> getRunningServices(int maxNum) throws SecurityException 

Source Link

Document

Return a list of the services that are currently running.

Usage

From source file:csh.cryptonite.Cryptonite.java

private boolean extTermRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("jackpal.androidterm.TermService".equals(service.service.getClassName())) {
            return true;
        }//from  w  ww  . j  a v a  2s .  com
    }
    return false;
}

From source file:com.xperia64.timidityae.TimidityActivity.java

private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }/*from  w w w .j  av a 2 s . c  o m*/
    }
    return false;
}

From source file:piuk.blockchain.android.WalletApplication.java

private boolean isBitcoinJServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        //         if (BlockchainServiceImpl.class.getName().equals(service.service.getClassName())) {
        //            return true;
        //         }
    }/*from w  w w. j a v  a2 s .  c o  m*/
    return false;
}

From source file:com.entradahealth.entrada.android.app.personal.activities.job_list.JobListActivity.java

public void SyncData() {

    if (!isFinishing()) {

        if (BundleKeys.which == 6 || BundleKeys.which == 7)
            jobListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
        else//  www . j  av  a2 s.c  om
            jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

        ns = new NetworkState(getApplicationContext());
        isConnected = ns.isConnectingToInternet();

        if (isConnected) {
            running = false;
            ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
            for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
                if ("com.entradahealth.entrada.android.app.personal.sync.SyncService"
                        .equals(service.service.getClassName())
                        || "com.entradahealth.entrada.android.app.personal.sync.DictationUploadService"
                                .equals(service.service.getClassName())) {
                    running = true;
                }
            }

            if (!running) {
                etSearch.setText(null);
                if (!isFinishing()) {

                    //retryUploads();
                    boolean canSync = true;
                    try {
                        List<Job> jobs = AndroidState.getInstance().getUserState().getProvider(currentAccount)
                                .getJobs();

                        for (Job j : jobs) {
                            if (j.isPending()) {
                                canSync = false;
                                UserState state = AndroidState.getInstance().getUserState();
                                Log.e("", "syncData()--" + j.id);
                                DictationUploadService.startUpload(this, state, currentAccount, j);
                            }
                        }
                    } catch (Exception ex) {
                        ACRA.getErrorReporter().handleSilentException(ex);
                        canSync = false;
                    }

                    if (!canSync) {
                        //Toast.makeText(
                        //   this,
                        //"Please wait for all uploads to complete before syncing.",
                        //Toast.LENGTH_SHORT).show();

                    } else {
                        rlSyncError.setVisibility(View.GONE);
                        rlUpdated.setVisibility(View.INVISIBLE);
                        tvUpdating.setVisibility(View.VISIBLE);

                        Intent i = new Intent(this, SyncService.class);
                        startService(i);
                    }

                    isSyncing = true;
                    BundleKeys.SYNC_FOR_ACC = currentAccount.getDisplayName();
                    //BundleKeys.SYNC_FOR_CLINIC = currentAccount.getClinicCode();

                    /*task1 = buildMinderTask();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                       task1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    } else {
                       task1.execute();
                    }*/

                }
            } else {
                /*if (!isResumed)
                   Toast.makeText(
                this,
                "Please wait for all uploads to complete before syncing.",
                Toast.LENGTH_SHORT).show();*/
            }
            isResumed = false;

            BundleKeys.ACC_EDITED = false;

        } else {
            rlSyncError.setVisibility(View.VISIBLE);
            rlUpdated.setVisibility(View.GONE);
            tvUpdating.setVisibility(View.GONE);
        }
    }
}

From source file:pt.aptoide.backupapps.Aptoide.java

private void makeSureServiceDataIsRunning() {
    ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo runningService : activityManager.getRunningServices(Integer.MAX_VALUE)) {
        if (runningService.service.getClassName().equals(Constants.SERVICE_DATA_CLASS_NAME)) {
            this.serviceDataSeenRunning = true;
            break;
        }//from   w w w .  j  av a2  s .c  o m
    }

    if (!serviceDataIsBound) {
        startService(new Intent(this, AptoideServiceData.class)); //TODO uncomment this to make service independent of Aptoide's lifecycle
        bindService(new Intent(this, AptoideServiceData.class), serviceDataConnection,
                Context.BIND_AUTO_CREATE);
    } else {
        handleIncomingIntent(getIntent());
    }
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * Check to see what's going on with the services, useful to check if the spell-checker service is active.
 * Probably should remove this, no longer necessary.
 * @return true if the Spellchecker service is running
 *///  w  w w  . j a  va2 s  . co m
private boolean isMyServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        //Log.i("isService", service.service.getClassName()+",\n"+service.service.getPackageName());
        if (service.service.getClassName().contains("pell")) {
            //Log.i("isService", service.service.getClassName()+",\n"+service.service.getPackageName());
            if (service.service.getClassName().contains("ASpellChecker")) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.oakesville.mythling.MediaActivity.java

private boolean isPlayingMusic() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (MusicPlaybackService.class.getName().equals(service.service.getClassName()))
            return true;
    }//from w  ww.ja  v  a  2 s  .com
    return false;
}

From source file:com.entradahealth.entrada.android.app.personal.activities.job_list.JobListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    application = (EntradaApplication) EntradaApplication.getAppContext();
    sp = getSharedPreferences("Entrada", Context.MODE_WORLD_READABLE);
    if (sp.getBoolean("SECURE_MSG", true))
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    else/*from   w w w .j a  v  a2  s  .c  o m*/
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
    final JobListActivity thisActivity = this;

    //Custom view as action bar
    LayoutInflater mInflater = LayoutInflater.from(this);
    View mCustomView = mInflater.inflate(R.layout.acbar_job_list, null);
    tvAcTitle = (TextView) mCustomView.findViewById(R.id.tvAcTitle);
    ivInbox = (ImageView) mCustomView.findViewById(R.id.ivInbox);
    ivAddJob = (ImageView) mCustomView.findViewById(R.id.ivAddJob);
    ivSync = (ImageView) mCustomView.findViewById(R.id.ivSync);
    ivSchedule = (ImageView) mCustomView.findViewById(R.id.ivSchedule);
    tvAcTitle.setText(BundleKeys.title);

    //Sample icon badger on Action bar item
    badge = new BadgeView(this, ivInbox);
    if (BundleKeys.fromSecureMessaging || !application.isJobListEnabled()) {
        startActivity(new Intent(JobListActivity.this, SecureMessaging.class));
        finish();
    }

    ivInbox.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(JobListActivity.this, SecureMessaging.class));
            finish();
        }
    });

    ivAddJob.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent addJobIntent = new Intent(JobListActivity.this, AddJobActivity.class);
            addJobIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(addJobIntent);
            finish();
        }
    });

    ivSync.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            ns = new NetworkState(getApplicationContext());
            isConnected = ns.isConnectingToInternet();
            if (isConnected) {
                running = false;
                ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
                    if ("com.entradahealth.entrada.android.app.personal.sync.SyncService"
                            .equals(service.service.getClassName())
                            || "com.entradahealth.entrada.android.app.personal.sync.DictationUploadService"
                                    .equals(service.service.getClassName())) {
                        running = true;
                    }
                }

                if (!running) {
                    etSearch.setText(null);
                    if (!isFinishing()) {

                        //retryUploads();
                        boolean canSync = true;
                        try {
                            List<Job> jobs = AndroidState.getInstance().getUserState()
                                    .getProvider(currentAccount).getJobs();

                            for (Job j : jobs) {
                                if (j.isPending()) {
                                    canSync = false;
                                    UserState state = AndroidState.getInstance().getUserState();
                                    Log.e("", "onOptionsItemSelected-syncMenuItem--" + j.id);
                                    DictationUploadService.startUpload(JobListActivity.this, state,
                                            currentAccount, j);
                                }
                            }
                        } catch (Exception ex) {
                            ACRA.getErrorReporter().handleSilentException(ex);
                            canSync = false;
                        }

                        if (!canSync) {
                            Toast.makeText(JobListActivity.this,
                                    "Please wait for all uploads to complete before syncing.",
                                    Toast.LENGTH_SHORT).show();

                        } else {
                            rlSyncError.setVisibility(View.GONE);
                            rlUpdated.setVisibility(View.INVISIBLE);
                            tvUpdating.setVisibility(View.VISIBLE);

                            Intent i = new Intent(JobListActivity.this, SyncService.class);
                            startService(i);

                        }

                        isSyncing = true;
                        BundleKeys.SYNC_FOR_ACC = currentAccount.getDisplayName();
                        //BundleKeys.SYNC_FOR_CLINIC = currentAccount.getClinicCode(); 

                        /*task1 = buildMinderTask();
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                           task1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        } else {
                           task1.execute();
                        }*/

                    }
                } else {
                    if (!isResumed)
                        Toast.makeText(JobListActivity.this,
                                "Please wait for all uploads to complete before syncing.", Toast.LENGTH_SHORT)
                                .show();
                }
                isResumed = false;
            } else {
                rlSyncError.setVisibility(View.VISIBLE);
                rlUpdated.setVisibility(View.GONE);
                tvUpdating.setVisibility(View.GONE);
            }

        }
    });

    ivSchedule.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(JobListActivity.this, ScheduleActivity.class));
            finish();
        }
    });

    getActionBar().setCustomView(mCustomView);
    getActionBar().setDisplayShowCustomEnabled(true);

    //ActionBar ab = getActionBar();
    //ab.setTitle(BundleKeys.title);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    registerReceiver(broadcastReceiver, new IntentFilter("CONNECTIVITY_CHANGED"));
    jobIds = new ArrayList<Long>();
    BundleKeys.fromImageDisplay = false;
    BundleKeys.fromCaputreImages = false;
    BundleKeys.fromSecureMessaging = false;

    /*Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
         @Override
         public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
       Log.e("Job-List-Activity","Uncaught-Exception");
       System.exit(2);
         }
     });*/

    setBehindContentView(R.layout.job_list_sliding_menu);
    tvListTitle = (TextView) findViewById(R.id.tvListTitle);
    tvListTitle.setText("Jobs");
    lvSliding = (ListView) findViewById(R.id.lvSlidingMenu);
    lvSliding.setBackgroundColor(Color.parseColor("#262b38"));

    // Get screen width and set sliding width to 3/4
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int req_width = width * 3 / 4;

    slidingMenu = getSlidingMenu();
    slidingMenu.setFadeEnabled(true);
    slidingMenu.setFadeDegree(0.35f);
    slidingMenu.setBehindWidth(req_width);
    slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

    setContentView(R.layout.job_list);

    ivDrawer = (ImageView) findViewById(R.id.ivDrawer);
    ivDrawer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            slidingMenu.toggle();
            // JobCountTask();
        }
    });

    rlUpdated = (RelativeLayout) findViewById(R.id.rlDateTime);
    rlSyncError = (RelativeLayout) findViewById(R.id.rlSyncError);
    rlSyncError.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
            builder.setTitle(R.string.title_sync_error);
            builder.setMessage(R.string.msg_sync_error);
            builder.setPositiveButton("OK", null);
            dgSyncError = builder.create();
            dgSyncError.show();
        }
    });

    tvDate = (TextView) findViewById(R.id.tvDate);
    tvTime = (TextView) findViewById(R.id.tvTime);
    tvUpdating = (TextView) findViewById(R.id.lblUpdating);
    tvSyncFailed = (TextView) findViewById(R.id.lblSyncError);

    handler = new Handler();
    handler.postDelayed(runnable, BundleKeys.mins_to_sync * 60 * 1000);
    handler.postDelayed(runnable_logs, 5 * 60 * 1000);

    jobListView = (ListView) findViewById(R.id.jobListView);
    jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    jobListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            // TODO: evaluate whether to save search text in
            // UserState to repopulate on back press.

            itemClicked = true;
            if (searchTask != null) {
                searchTask.cancel(true);
            }

            Log.d("", "-- Job ItemClick --");
            List<Long> jobList = thisActivity.getJobIdList();
            Preconditions.checkNotNull(jobList, "null List<Job> when adapter view clicked.");
            Job job = AndroidState.getInstance().getUserState().getProvider(currentAccount)
                    .getJob(jobList.get(position));
            if (job != null) {
                Preconditions.checkNotNull(job, "null item in List<Job> when adapter view clicked.");

                if (job.isFlagSet(Job.Flags.UPLOAD_COMPLETED) || job.isFlagSet(Job.Flags.UPLOAD_IN_PROGRESS)
                        || (job.isFlagSet(Job.Flags.UPLOAD_PENDING) && BundleKeys.which == 6))

                {
                    Toast.makeText(thisActivity, "Cannot open a completed dictation.", Toast.LENGTH_SHORT)
                            .show();
                    return;
                } else if (job.isFlagSet(Job.Flags.LOCALLY_DELETED)) {
                    return;
                }

                Intent intent = new Intent(thisActivity, JobDisplayActivity.class);
                Bundle b = new Bundle();
                if (!job.isFlagSet(Flags.HOLD))
                    job = job.setFlag(Flags.IS_FIRST);
                else
                    job = job.clearFlag(Flags.IS_FIRST);
                try {
                    AndroidState.getInstance().getUserState().getProvider(currentAccount).updateJob(job);
                } catch (DomainObjectWriteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                b.putBoolean("isFirst", true);
                b.putBoolean("isFromList", true);
                b.putBoolean("isNew", false);
                b.putLong(BundleKeys.SELECTED_JOB, job.id);
                b.putString(BundleKeys.SELECTED_JOB_ACCOUNT, currentAccount.getName());
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtras(b);
                thisActivity.startActivity(intent);
                thisActivity.finish();
            }
        }

    });

    jobListView.setMultiChoiceModeListener(new JobListMultiChoiceModeListener(this));

    slidingMenu.setOnOpenListener(new OnOpenListener() {

        @Override
        public void onOpen() {
            // TODO Auto-generated method stub

            openSlide();
        }
    });

    lvSliding.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
            // TODO Auto-generated method stub

            switch (pos) {

            case 1:
                //getActionBar().setTitle("Today's Jobs");
                tvAcTitle.setText("Today's Jobs");
                BundleKeys.title = "Today's Jobs";
                BundleKeys.which = 1;
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 2:
                //getActionBar().setTitle("Tomorrow's Jobs");
                tvAcTitle.setText("Tomorrow's Jobs");
                BundleKeys.which = 2;
                BundleKeys.title = "Tomorrow's Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 3:
                //getActionBar().setTitle("Stat Jobs");
                tvAcTitle.setText("Stat Jobs");
                BundleKeys.which = 3;
                BundleKeys.title = "Stat Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 4:
                //getActionBar().setTitle("All Jobs");
                tvAcTitle.setText("All Jobs");
                BundleKeys.which = 4;
                BundleKeys.title = "All Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 6:
                //getActionBar().setTitle("Hold Jobs");
                tvAcTitle.setText("Hold Jobs");
                BundleKeys.which = 5;
                BundleKeys.title = "Hold Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 7:
                //getActionBar().setTitle("Deleted Jobs");
                tvAcTitle.setText("Deleted Jobs");
                BundleKeys.which = 7;
                BundleKeys.title = "Deleted Jobs";
                // Hide "Add Job" menu item
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(false);
                ivAddJob.setVisibility(View.GONE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
                etSearch.setText("");
                break;
            case 8:
                //getActionBar().setTitle("Completed Jobs");
                tvAcTitle.setText("Completed Jobs");
                BundleKeys.which = 6;
                BundleKeys.title = "Completed Jobs";
                // Hide "Add Job" menu item
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(false);
                ivAddJob.setVisibility(View.GONE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
                etSearch.setText("");
                break;

            case 10:
                isSetting = true;
                //getActionBar().setTitle("Settings");
                tvAcTitle.setText("Settings Jobs");
                startActivity(new Intent(JobListActivity.this, EntradaSettings.class)
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                finish();
                break;

            case 11:
                // Check if there are any held jobs or any uploads in
                // progress
                boolean isHeld = true, isPending = true;
                try {
                    List<Job> jobs = AndroidState.getInstance().getUserState().getProvider(currentAccount)
                            .getJobs();

                    for (Job j : jobs) {
                        if (j.isPending())
                            isPending = false;
                        if (j.isFlagSet(Job.Flags.HOLD))
                            isHeld = false;

                    }
                } catch (Exception ex) {
                    ACRA.getErrorReporter().handleSilentException(ex);
                    isPending = false;
                    isHeld = false;
                }
                if (SyncService.isRunning()) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
                    builder.setTitle(R.string.del_acc_err_title);
                    builder.setMessage(R.string.manage_q_upload_error);
                    builder.setPositiveButton("OK", null);
                    builder.setCancelable(true);
                    dgManageQ = builder.create();
                    dgManageQ.show();
                } else if (isPending && isHeld) {
                    Intent qIntent = new Intent(JobListActivity.this, ManageQueuesActivity.class);
                    qIntent.putExtra("from_settings", false);
                    qIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(qIntent);
                    finish();
                } else if (!isHeld) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
                    builder.setTitle(R.string.del_acc_err_title);
                    builder.setMessage(R.string.manage_q_hold_error);
                    builder.setPositiveButton("OK", null);
                    builder.setCancelable(true);
                    dgManageQ = builder.create();
                    dgManageQ.show();
                } else if (!isPending) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
                    builder.setTitle(R.string.del_acc_err_title);
                    builder.setMessage(R.string.manage_q_upload_error);
                    builder.setPositiveButton("OK", null);
                    builder.setCancelable(true);
                    dgManageQ = builder.create();
                    dgManageQ.show();
                }

                break;

            default:
                //getActionBar().setTitle("Today's Jobs");
                tvAcTitle.setText("Today's Jobs");
                BundleKeys.title = "Today's Jobs";
                BundleKeys.which = 1;
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
            }
            Log.e(LOG_NAME, Integer.toString(BundleKeys.which) + " - " + BundleKeys.title);
            isSync = false;
            slidingMenu.toggle(true);
            /*
             * Log.e("isSetting", Boolean.toString(isSetting));
             * if(BundleKeys.which != 8 && BundleKeys.which != 9 &&
             * !isSetting) etSearch.setText("");
             */
        }

    });

    rlSearch = (RelativeLayout) findViewById(R.id.rlSearch);

    etSearch = (EditText) findViewById(R.id.etSearch);
    etSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            //launchSearchTask();

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            launchSearchTask();
        }
    });

    GetResourcesTask task = new GetResourcesTask();
    task.execute();

}

From source file:com.landenlabs.all_devtool.SystemFragment.java

public void updateList() {
    // Time today = new Time(Time.getCurrentTimezone());
    // today.setToNow();
    // today.format(" %H:%M:%S")
    Date dt = new Date();
    m_titleTime.setText(m_timeFormat.format(dt));

    boolean expandAll = m_list.isEmpty();
    m_list.clear();/*from w w  w  .ja  v a2s .  c  o m*/

    // Swap colors
    int color = m_rowColor1;
    m_rowColor1 = m_rowColor2;
    m_rowColor2 = color;

    ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);

    try {
        String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);
        addBuild("Android ID", androidIDStr);

        try {
            AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext());
            final String adIdStr = adInfo.getId();
            final boolean isLAT = adInfo.isLimitAdTrackingEnabled();
            addBuild("Ad ID", adIdStr);
        } catch (IOException e) {
            // Unrecoverable error connecting to Google Play services (e.g.,
            // the old version of the service doesn't support getting AdvertisingId).
        } catch (GooglePlayServicesNotAvailableException e) {
            // Google Play services is not available entirely.
        }

        /*
        try {
        InstanceID instanceID = InstanceID.getInstance(getContext());
        if (instanceID != null) {
            // Requires a Google Developer project ID.
            String authorizedEntity = "<need to make this on google developer site>";
            instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            addBuild("Instance ID", instanceID.getId());
        }
        } catch (Exception ex) {
        }
        */

        ConfigurationInfo info = actMgr.getDeviceConfigurationInfo();
        addBuild("OpenGL", info.getGlEsVersion());
    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }

    try {
        long heapSize = Debug.getNativeHeapSize();
        // long maxHeap = Runtime.getRuntime().maxMemory();

        // ConfigurationInfo cfgInfo = actMgr.getDeviceConfigurationInfo();
        int largHeapMb = actMgr.getLargeMemoryClass();
        int heapMb = actMgr.getMemoryClass();

        MemoryInfo memInfo = new MemoryInfo();
        actMgr.getMemoryInfo(memInfo);

        final String sFmtMB = "%.2f MB";
        Map<String, String> listStr = new TreeMap<String, String>();
        listStr.put("Mem Available (now)", String.format(sFmtMB, (double) memInfo.availMem / MB));
        listStr.put("Mem LowWhenOnlyAvail", String.format(sFmtMB, (double) memInfo.threshold / MB));
        if (Build.VERSION.SDK_INT >= 16) {
            listStr.put("Mem Installed", String.format(sFmtMB, (double) memInfo.totalMem / MB));
        }
        listStr.put("Heap (this app)", String.format(sFmtMB, (double) heapSize / MB));
        listStr.put("HeapMax (default)", String.format(sFmtMB, (double) heapMb));
        listStr.put("HeapMax (large)", String.format(sFmtMB, (double) largHeapMb));
        addBuild("Memory...", listStr);
    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }

    try {
        List<ProcessErrorStateInfo> procErrList = actMgr.getProcessesInErrorState();
        int errCnt = (procErrList == null ? 0 : procErrList.size());
        procErrList = null;

        // List<RunningAppProcessInfo> procList = actMgr.getRunningAppProcesses();
        int procCnt = actMgr.getRunningAppProcesses().size();
        int srvCnt = actMgr.getRunningServices(100).size();

        Map<String, String> listStr = new TreeMap<String, String>();
        listStr.put("#Processes", String.valueOf(procCnt));
        listStr.put("#Proc With Err", String.valueOf(errCnt));
        listStr.put("#Services", String.valueOf(srvCnt));
        // Requires special permission
        //   int taskCnt = actMgr.getRunningTasks(100).size();
        //   listStr.put("#Tasks",  String.valueOf(taskCnt));
        addBuild("Processes...", listStr);
    } catch (Exception ex) {
        m_log.e("System-Processes %s", ex.getMessage());
    }

    try {
        Map<String, String> listStr = new LinkedHashMap<String, String>();
        listStr.put("LargeIconDensity", String.valueOf(actMgr.getLauncherLargeIconDensity()));
        listStr.put("LargeIconSize", String.valueOf(actMgr.getLauncherLargeIconSize()));
        putIf(listStr, "isRunningInTestHarness", "Yes", ActivityManager.isRunningInTestHarness());
        putIf(listStr, "isUserAMonkey", "Yes", ActivityManager.isUserAMonkey());
        addBuild("Misc...", listStr);
    } catch (Exception ex) {
        m_log.e("System-Misc %s", ex.getMessage());
    }

    // --------------- Locale / Timezone -------------
    try {
        Locale ourLocale = Locale.getDefault();
        Date m_date = new Date();
        TimeZone tz = TimeZone.getDefault();

        Map<String, String> localeListStr = new LinkedHashMap<String, String>();

        localeListStr.put("Locale Name", ourLocale.getDisplayName());
        localeListStr.put(" Variant", ourLocale.getVariant());
        localeListStr.put(" Country", ourLocale.getCountry());
        localeListStr.put(" Country ISO", ourLocale.getISO3Country());
        localeListStr.put(" Language", ourLocale.getLanguage());
        localeListStr.put(" Language ISO", ourLocale.getISO3Language());
        localeListStr.put(" Language Dsp", ourLocale.getDisplayLanguage());

        localeListStr.put("TimeZoneID", tz.getID());
        localeListStr.put(" DayLightSavings", tz.useDaylightTime() ? "Yes" : "No");
        localeListStr.put(" In DLS", tz.inDaylightTime(m_date) ? "Yes" : "No");
        localeListStr.put(" Short Name", tz.getDisplayName(false, TimeZone.SHORT, ourLocale));
        localeListStr.put(" Long Name", tz.getDisplayName(false, TimeZone.LONG, ourLocale));

        addBuild("Locale TZ...", localeListStr);
    } catch (Exception ex) {
        m_log.e("Locale/TZ %s", ex.getMessage());
    }

    // --------------- Location Services -------------
    try {
        Map<String, String> listStr = new LinkedHashMap<String, String>();

        final LocationManager locMgr = (LocationManager) getActivity()
                .getSystemService(Context.LOCATION_SERVICE);

        GpsStatus gpsStatus = locMgr.getGpsStatus(null);
        if (gpsStatus != null) {
            listStr.put("Sec ToGetGPS", String.valueOf(gpsStatus.getTimeToFirstFix()));

            Iterable<GpsSatellite> satellites = gpsStatus.getSatellites();
            Iterator<GpsSatellite> sat = satellites.iterator();
            while (sat.hasNext()) {
                GpsSatellite satellite = sat.next();

                putIf(listStr,
                        String.format("Azm:%.0f, Elev:%.0f", satellite.getAzimuth(), satellite.getElevation()),
                        String.format("%.2f Snr", satellite.getSnr()), satellite.usedInFix());
            }
        }

        Location location = null;
        if (ActivityCompat.checkSelfPermission(getContext(),
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(getContext(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

            location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (null == location)
                location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (null == location)
                location = locMgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
        }

        if (null != location) {
            listStr.put(location.getProvider() + " lat,lng",
                    String.format("%.3f, %.3f", location.getLatitude(), location.getLongitude()));
        }
        if (listStr.size() != 0) {
            List<String> gpsProviders = locMgr.getAllProviders();
            int idx = 1;
            for (String providerName : gpsProviders) {
                LocationProvider provider = locMgr.getProvider(providerName);
                if (null != provider) {
                    listStr.put(providerName,
                            (locMgr.isProviderEnabled(providerName) ? "On " : "Off ")
                                    + String.format("Accuracy:%d Pwr:%d", provider.getAccuracy(),
                                            provider.getPowerRequirement()));
                }
            }
            addBuild("GPS...", listStr);
        } else
            addBuild("GPS", "Off");
    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }

    // --------------- Application Info -------------
    ApplicationInfo appInfo = getActivity().getApplicationInfo();
    if (null != appInfo) {
        Map<String, String> appList = new LinkedHashMap<String, String>();
        try {
            appList.put("ProcName", appInfo.processName);
            appList.put("PkgName", appInfo.packageName);
            appList.put("DataDir", appInfo.dataDir);
            appList.put("SrcDir", appInfo.sourceDir);
            //    appList.put("PkgResDir", getActivity().getPackageResourcePath());
            //     appList.put("PkgCodeDir", getActivity().getPackageCodePath());
            String[] dbList = getActivity().databaseList();
            if (dbList != null && dbList.length != 0)
                appList.put("DataBase", dbList[0]);
            // getActivity().getComponentName().

        } catch (Exception ex) {
        }
        addBuild("AppInfo...", appList);
    }

    // --------------- Account Services -------------
    final AccountManager accMgr = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);
    if (null != accMgr) {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        try {
            for (Account account : accMgr.getAccounts()) {
                strList.put(account.name, account.type);
            }
        } catch (Exception ex) {
            m_log.e(ex.getMessage());
        }
        addBuild("Accounts...", strList);
    }

    // --------------- Package Features -------------
    PackageManager pm = getActivity().getPackageManager();
    FeatureInfo[] features = pm.getSystemAvailableFeatures();
    if (features != null) {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        for (FeatureInfo featureInfo : features) {
            strList.put(featureInfo.name, "");
        }
        addBuild("Features...", strList);
    }

    // --------------- Sensor Services -------------
    final SensorManager senMgr = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    if (null != senMgr) {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        // Sensor accelerometer = senMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        // senMgr.registerListener(foo, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
        List<Sensor> listSensor = senMgr.getSensorList(Sensor.TYPE_ALL);
        try {
            for (Sensor sensor : listSensor) {
                strList.put(sensor.getName(), sensor.getVendor());
            }
        } catch (Exception ex) {
            m_log.e(ex.getMessage());
        }
        addBuild("Sensors...", strList);
    }

    try {
        if (Build.VERSION.SDK_INT >= 17) {
            final UserManager userMgr = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
            if (null != userMgr) {
                try {
                    addBuild("UserName", userMgr.getUserName());
                } catch (Exception ex) {
                    m_log.e(ex.getMessage());
                }
            }
        }
    } catch (Exception ex) {
    }

    try {
        Map<String, String> strList = new LinkedHashMap<String, String>();
        int screenTimeout = Settings.System.getInt(getActivity().getContentResolver(),
                Settings.System.SCREEN_OFF_TIMEOUT);
        strList.put("ScreenTimeOut", String.valueOf(screenTimeout / 1000));
        int rotate = Settings.System.getInt(getActivity().getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION);
        strList.put("RotateEnabled", String.valueOf(rotate));
        if (Build.VERSION.SDK_INT >= 17) {
            // Global added in API 17
            int adb = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.ADB_ENABLED);
            strList.put("AdbEnabled", String.valueOf(adb));
        }
        addBuild("Settings...", strList);
    } catch (Exception ex) {
    }

    if (expandAll) {
        // updateList();
        int count = m_list.size();
        for (int position = 0; position < count; position++)
            m_listView.expandGroup(position);
    }

    m_adapter.notifyDataSetChanged();
}