List of usage examples for android.support.v4.content AsyncTaskLoader AsyncTaskLoader
public AsyncTaskLoader(Context context)
From source file:org.rm3l.ddwrt.tiles.status.router.StatusRouterStateTile.java
/** * Instantiate and return a new Loader for the given ID. * * @param id The ID whose loader is to be created. * @param args Any arguments supplied by the caller. * @return Return a new Loader instance that is ready to start loading. *//*from w w w . j av a 2 s .co m*/ @Override protected Loader<NVRAMInfo> getLoader(final int id, final Bundle args) { return new AsyncTaskLoader<NVRAMInfo>(this.mParentFragmentActivity) { @Nullable @Override public NVRAMInfo loadInBackground() { try { Log.d(LOG_TAG, "Init background loader for " + StatusRouterStateTile.class + ": routerInfo=" + mRouter + " / this.mAutoRefreshToggle= " + mAutoRefreshToggle + " / nbRunsLoader=" + nbRunsLoader); if (nbRunsLoader > 0 && !mAutoRefreshToggle) { //Skip run Log.d(LOG_TAG, "Skip loader run"); return new NVRAMInfo().setException(new DDWRTTileAutoRefreshNotAllowedException()); } nbRunsLoader++; @Nullable final NVRAMInfo nvramInfo = new NVRAMInfo(); NVRAMInfo nvramInfoTmp = null; try { nvramInfoTmp = SSHUtils.getNVRamInfoFromRouter(mRouter, mGlobalPreferences, NVRAMInfo.ROUTER_NAME, NVRAMInfo.WAN_IPADDR, NVRAMInfo.MODEL, NVRAMInfo.DIST_TYPE, NVRAMInfo.LAN_IPADDR); } finally { if (nvramInfoTmp != null) { nvramInfo.putAll(nvramInfoTmp); } //Add FW, Kernel and Uptime @Nullable final String[] otherCmds = SSHUtils.getManualProperty(mRouter, mGlobalPreferences, "uptime", "uname -a", "cat /tmp/loginprompt"); if (otherCmds != null) { if (otherCmds.length >= 3) { //Uptime final List<String> strings = SPLITTER.splitToList(otherCmds[0]); if (strings != null && strings.size() > 0) { nvramInfo.setProperty(NVRAMInfo.UPTIME, strings.get(0)); } //Kernel nvramInfo.setProperty(NVRAMInfo.KERNEL, otherCmds[1]); //Firmware //TODO Relying on loginprompt, since there is no easy way to get the info final String firmVer = otherCmds[2]; String firmReleaseAndBuildNumber = null; if (otherCmds.length >= 4) { firmReleaseAndBuildNumber = otherCmds[3]; } nvramInfo.setProperty(NVRAMInfo.FIRMWARE, firmVer + (firmReleaseAndBuildNumber != null ? (" - " + firmReleaseAndBuildNumber) : "")); } } } if (nvramInfo.isEmpty()) { throw new DDWRTNoDataException("No Data!"); } return nvramInfo; } catch (@NotNull final Exception e) { e.printStackTrace(); return new NVRAMInfo().setException(e); } } }; }
From source file:it.polimi.spf.app.fragments.ActivityFragment.java
@Override public Loader<Collection<ActivityVerb>> onCreateLoader(int id, Bundle args) { switch (id) { case LoadersConfig.LOAD_LIST_LOADER_ID: return new AsyncTaskLoader<Collection<ActivityVerb>>(getActivity()) { @Override//from w w w . j a v a2 s. co m public Collection<ActivityVerb> loadInBackground() { return SPF.get().getServiceRegistry().getSupportedVerbs(); } }; default: return null; } }
From source file:org.rm3l.ddwrt.tiles.status.router.StatusRouterMemoryTile.java
/** * Instantiate and return a new Loader for the given ID. * * @param id The ID whose loader is to be created. * @param args Any arguments supplied by the caller. * @return Return a new Loader instance that is ready to start loading. *//*ww w. j av a 2s .c om*/ @Override protected Loader<NVRAMInfo> getLoader(final int id, final Bundle args) { return new AsyncTaskLoader<NVRAMInfo>(this.mParentFragmentActivity) { @NotNull @Override public NVRAMInfo loadInBackground() { try { Log.d(LOG_TAG, "Init background loader for " + StatusRouterMemoryTile.class + ": routerInfo=" + mRouter + " / this.mAutoRefreshToggle= " + mAutoRefreshToggle + " / nbRunsLoader=" + nbRunsLoader); if (nbRunsLoader > 0 && !mAutoRefreshToggle) { //Skip run Log.d(LOG_TAG, "Skip loader run"); return new NVRAMInfo().setException(new DDWRTTileAutoRefreshNotAllowedException()); } nbRunsLoader++; @NotNull final NVRAMInfo nvramInfo = new NVRAMInfo(); @Nullable final String[] otherCmds = SSHUtils.getManualProperty(mRouter, mGlobalPreferences, getGrepProcMemInfo("MemTotal"), getGrepProcMemInfo("MemFree")); if (otherCmds != null && otherCmds.length >= 2) { //Total @Nullable String memTotal = null; List<String> strings = Splitter.on("MemTotal:").omitEmptyStrings().trimResults() .splitToList(otherCmds[0].trim()); Log.d(LOG_TAG, "strings for MemTotal: " + strings); if (strings != null && strings.size() >= 1) { memTotal = strings.get(0); nvramInfo.setProperty(NVRAMInfo.MEMORY_TOTAL, memTotal); } //Free @Nullable String memFree = null; strings = Splitter.on("MemFree:").omitEmptyStrings().trimResults() .splitToList(otherCmds[1].trim()); Log.d(LOG_TAG, "strings for MemFree: " + strings); if (strings != null && strings.size() >= 1) { memFree = strings.get(0); nvramInfo.setProperty(NVRAMInfo.MEMORY_FREE, strings.get(0)); } //Mem used @Nullable String memUsed = null; if (!(isNullOrEmpty(memTotal) || isNullOrEmpty(memFree))) { //noinspection ConstantConditions memUsed = Long.toString(Long.parseLong(memTotal.replaceAll(" kB", "")) - Long.parseLong(memFree.replaceAll(" kB", ""))) + " kB"; nvramInfo.setProperty(NVRAMInfo.MEMORY_USED, memUsed); } } if (nvramInfo.isEmpty()) { throw new DDWRTNoDataException("No Data!"); } return nvramInfo; } catch (@NotNull final Exception e) { e.printStackTrace(); return new NVRAMInfo().setException(e); } } }; }
From source file:it.polimi.spf.app.fragments.appmanager.AppManagerFragment.java
@Override public Loader<List<AppAuth>> onCreateLoader(int id, Bundle args) { switch (id) { case LoadersConfig.APP_LOADER: return new AsyncTaskLoader<List<AppAuth>>(getActivity()) { @Override/*from w ww.ja v a 2 s. c o m*/ public List<AppAuth> loadInBackground() { return SPF.get().getSecurityMonitor().getAvailableApplications(); } }; default: return null; } }
From source file:net.naonedbus.fragment.CustomInfiniteListFragement.java
@Override public Loader<AsyncResult<ListAdapter>> onCreateLoader(final int arg0, final Bundle bundle) { final Loader<AsyncResult<ListAdapter>> loader = new AsyncTaskLoader<AsyncResult<ListAdapter>>( getActivity()) {/*from w w w . j a v a2s . c o m*/ @Override public AsyncResult<ListAdapter> loadInBackground() { return loadContent(getActivity(), bundle); } }; if (getListAdapter() == null || getListAdapter().getCount() == 0) showLoader(); loader.forceLoad(); return loader; }
From source file:org.rm3l.ddwrt.fragments.status.StatusWirelessFragment.java
@Nullable @Override//w w w . java 2 s .c o m protected Loader<Collection<DDWRTTile>> getLoader(final int id, @NotNull final Bundle args) { return new AsyncTaskLoader<Collection<DDWRTTile>>(getSherlockActivity()) { @Nullable @Override public Collection<DDWRTTile> loadInBackground() { try { Log.d(LOG_TAG, "Init background loader for " + StatusWirelessFragment.class + ": routerInfo=" + router); final SherlockFragment parentFragment = StatusWirelessFragment.this; if (DDWRTCompanionConstants.TEST_MODE) { return Arrays.<DDWRTTile>asList( new WirelessIfaceTile("eth0.test", parentFragment, args, router), new WirelessIfaceTile("eth1.test", parentFragment, args, router), new WirelessIfaceTile("eth2.test", parentFragment, args, router)); } @Nullable final NVRAMInfo nvramInfo = SSHUtils.getNVRamInfoFromRouter(StatusWirelessFragment.this.router, getSherlockActivity().getSharedPreferences( DDWRTCompanionConstants.DEFAULT_SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE), NVRAMInfo.LANDEVS); if (nvramInfo == null) { return null; } final String landevs = nvramInfo.getProperty(NVRAMInfo.LANDEVS); if (landevs == null) { return null; } final List<String> splitToList = SPLITTER.splitToList(landevs); if (splitToList == null || splitToList.isEmpty()) { return null; } final List<DDWRTTile> tiles = Lists.newArrayList(); for (@Nullable final String landev : splitToList) { if (landev == null || !(landev.startsWith("wl") || landev.startsWith("ath"))) { continue; } tiles.add(new WirelessIfaceTile(landev, parentFragment, args, router)); //Also get Virtual Interfaces try { final String landevVifsKeyword = landev + "_vifs"; final NVRAMInfo landevVifsNVRAMInfo = SSHUtils.getNVRamInfoFromRouter( StatusWirelessFragment.this.router, getSherlockActivity().getSharedPreferences( DDWRTCompanionConstants.DEFAULT_SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE), landevVifsKeyword); if (landevVifsNVRAMInfo == null) { continue; } final String landevVifsNVRAMInfoProp = landevVifsNVRAMInfo .getProperty(landevVifsKeyword, DDWRTCompanionConstants.EMPTY_STRING); if (landevVifsNVRAMInfoProp == null) { continue; } final List<String> list = SPLITTER.splitToList(landevVifsNVRAMInfoProp); if (list == null) { continue; } for (final String landevVif : list) { if (landevVif == null || landevVif.isEmpty()) { continue; } tiles.add(new WirelessIfaceTile(landevVif, landev, parentFragment, args, router)); } } catch (final Exception e) { e.printStackTrace(); //No worries } } if (tiles.isEmpty()) { return null; } return tiles; } catch (@NotNull final Exception e) { e.printStackTrace(); return null; } } }; }
From source file:org.rm3l.ddwrt.tiles.status.router.StatusRouterCPUTile.java
/** * Instantiate and return a new Loader for the given ID. * * @param id The ID whose loader is to be created. * @param args Any arguments supplied by the caller. * @return Return a new Loader instance that is ready to start loading. *//*from ww w . j a v a 2 s . c om*/ @Override protected Loader<NVRAMInfo> getLoader(final int id, final Bundle args) { return new AsyncTaskLoader<NVRAMInfo>(this.mParentFragmentActivity) { @Nullable @Override public NVRAMInfo loadInBackground() { try { Log.d(LOG_TAG, "Init background loader for " + StatusRouterCPUTile.class + ": routerInfo=" + mRouter + " / this.mAutoRefreshToggle= " + mAutoRefreshToggle + " / nbRunsLoader=" + nbRunsLoader); if (nbRunsLoader > 0 && !mAutoRefreshToggle) { //Skip run Log.d(LOG_TAG, "Skip loader run"); return new NVRAMInfo().setException(new DDWRTTileAutoRefreshNotAllowedException()); } nbRunsLoader++; @NotNull final NVRAMInfo nvramInfo = new NVRAMInfo(); NVRAMInfo nvramInfoTmp = null; try { nvramInfoTmp = SSHUtils.getNVRamInfoFromRouter(mRouter, mGlobalPreferences, NVRAMInfo.CPU_CLOCK_FREQ); } finally { if (nvramInfoTmp != null) { nvramInfo.putAll(nvramInfoTmp); } List<String> strings = Splitter.on(",").omitEmptyStrings().trimResults() .splitToList(nullToEmpty(nvramInfo.getProperty(NVRAMInfo.CPU_CLOCK_FREQ))); Log.d(LOG_TAG, "strings for cpu clock: " + strings); if (strings != null && strings.size() > 0) { nvramInfo.setProperty(NVRAMInfo.CPU_CLOCK_FREQ, strings.get(0)); } @Nullable final String[] otherCmds = SSHUtils.getManualProperty(mRouter, mGlobalPreferences, "uptime | awk -F'average:' '{ print $2}'", GREP_MODEL_NAME_PROC_CPUINFO + "| uniq", GREP_MODEL_NAME_PROC_CPUINFO + "| wc -l"); if (otherCmds != null) { if (otherCmds.length >= 1) { //Load Avg nvramInfo.setProperty(NVRAMInfo.LOAD_AVERAGE, StringUtils.trimToNull(otherCmds[0])); //Removed: computation done on the router: // strings = Splitter.on("load average").omitEmptyStrings() // .trimResults().splitToList(otherCmds[0]); // Log.d(LOG_TAG, "strings for load avg: " + strings); // if (strings != null && strings.size() >= 2) { // final String loadAvg = strings.get(1); // if (loadAvg != null) { // nvramInfo.setProperty(NVRAMInfo.LOAD_AVERAGE, // loadAvg.replace(":", "").trim()); // } // } } if (otherCmds.length >= 2) { //Model final String modelNameLine = otherCmds[1]; if (modelNameLine != null) { nvramInfo.setProperty(NVRAMInfo.CPU_MODEL, modelNameLine.replace(":", "").replace("model name", "").trim()); } } if (otherCmds.length >= 3) { //Nb Cores nvramInfo.setProperty(NVRAMInfo.CPU_CORES_COUNT, otherCmds[2]); } } } if (nvramInfo.isEmpty()) { throw new DDWRTNoDataException("No Data!"); } return nvramInfo; } catch (@NotNull final Exception e) { e.printStackTrace(); return new NVRAMInfo().setException(e); } } }; }
From source file:com.nononsenseapps.filepicker.dropbox.DropboxFilePickerFragment.java
@Override protected Loader<List<FileSystemObjectInterface>> getLoader() { return new AsyncTaskLoader<List<FileSystemObjectInterface>>(getActivity()) { @Override//from www.j a va2 s . c om public List<FileSystemObjectInterface> loadInBackground() { ArrayList<FileSystemObjectInterface> files = new ArrayList<FileSystemObjectInterface>(); try { if (!dbApi.metadata(currentPath.getFullPath(), 1, null, false, null).isDir) { currentPath = getRoot(); } DropboxAPI.Entry dirEntry = dbApi.metadata(currentPath.getFullPath(), 0, null, true, null); for (DropboxAPI.Entry entry : dirEntry.contents) { if ((mode == SelectionMode.MODE_FILE || mode == SelectionMode.MODE_FILE_AND_DIR) || entry.isDir) { files.add(new DropboxFileSystemObject(entry)); } } } catch (DropboxException e) { } return files; } /** * Handles a request to start the Loader. */ @Override protected void onStartLoading() { super.onStartLoading(); if (currentPath == null /*|| !currentPath.isDir*/) { currentPath = getRoot(); } forceLoad(); } /** * Handles a request to completely reset the Loader. */ @Override protected void onReset() { super.onReset(); } }; }
From source file:it.polimi.spf.demo.chat.ConversationListFragment.java
@Override public Loader<List<Conversation>> onCreateLoader(int id, Bundle args) { switch (id) { case CONVERSATION_LOADER: return new AsyncTaskLoader<List<Conversation>>(getActivity()) { @Override/*w w w . j a v a 2 s . c o m*/ public List<Conversation> loadInBackground() { return ChatDemoApp.get().getChatStorage().getAllConversations(); } }; default: return null; } }
From source file:org.rm3l.ddwrt.tiles.status.bandwidth.BandwidthWANMonitoringTile.java
@Nullable @Override// w ww. ja va2 s . co m protected Loader<None> getLoader(int id, Bundle args) { return new AsyncTaskLoader<None>(this.mParentFragmentActivity) { @Nullable @Override public None loadInBackground() { try { Log.d(LOG_TAG, "Init background loader for " + BandwidthMonitoringTile.class + ": routerInfo=" + mRouter + " / this.mAutoRefreshToggle= " + mAutoRefreshToggle + " / nbRunsLoader=" + nbRunsLoader); if (nbRunsLoader > 0 && !mAutoRefreshToggle) { //Skip run Log.d(LOG_TAG, "Skip loader run"); return (None) new None().setException(new DDWRTTileAutoRefreshNotAllowedException()); } nbRunsLoader++; //Start by getting information about the WAN iface name @Nullable final NVRAMInfo nvRamInfoFromRouter = SSHUtils.getNVRamInfoFromRouter(mRouter, mGlobalPreferences, NVRAMInfo.WAN_IFACE); if (nvRamInfoFromRouter == null) { throw new IllegalStateException("Whoops. WAN Iface could not be determined."); } wanIface = nvRamInfoFromRouter.getProperty(NVRAMInfo.WAN_IFACE); if (Strings.isNullOrEmpty(wanIface)) { throw new IllegalStateException("Whoops. WAN Iface could not be determined."); } @Nullable final String[] netDevWanIfaces = SSHUtils.getManualProperty(mRouter, mGlobalPreferences, "cat /proc/net/dev | grep \"" + wanIface + "\""); if (netDevWanIfaces == null || netDevWanIfaces.length == 0) { return null; } String netDevWanIface = netDevWanIfaces[0]; if (netDevWanIface == null) { return null; } netDevWanIface = netDevWanIface.replaceAll(wanIface + ":", ""); final List<String> netDevWanIfaceList = Splitter.on(" ").omitEmptyStrings().trimResults() .splitToList(netDevWanIface); if (netDevWanIfaceList == null || netDevWanIfaceList.size() <= 15) { return null; } final long timestamp = System.currentTimeMillis(); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_bytes", netDevWanIfaceList.get(0)); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_packets", netDevWanIfaceList.get(1)); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_errs", netDevWanIfaceList.get(2)); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_drop", netDevWanIfaceList.get(3)); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_fifo", netDevWanIfaceList.get(4)); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_frame", netDevWanIfaceList.get(5)); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_compressed", netDevWanIfaceList.get(6)); nvRamInfoFromRouter.setProperty(wanIface + "_rcv_multicast", netDevWanIfaceList.get(7)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_bytes", netDevWanIfaceList.get(8)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_packets", netDevWanIfaceList.get(9)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_errs", netDevWanIfaceList.get(10)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_drop", netDevWanIfaceList.get(11)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_fifo", netDevWanIfaceList.get(12)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_colls", netDevWanIfaceList.get(13)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_carrier", netDevWanIfaceList.get(14)); nvRamInfoFromRouter.setProperty(wanIface + "_xmit_compressed", netDevWanIfaceList.get(15)); //Ingress double wanRcvMBytes; final String wanRcvBytes = nvRamInfoFromRouter.getProperty(wanIface + "_rcv_bytes", "-1"); try { wanRcvMBytes = Double.parseDouble(wanRcvBytes) / (1024 * 1024); if (wanRcvMBytes >= 0.) { wanRcvMBytes = new BigDecimal(wanRcvMBytes).setScale(2, RoundingMode.HALF_UP) .doubleValue(); bandwidthMonitoringIfaceData.addData("IN", new BandwidthMonitoringTile.DataPoint(timestamp, wanRcvMBytes)); } } catch (@NotNull final NumberFormatException nfe) { return null; } nvRamInfoFromRouter.setProperty(wanIface + "_ingress_MB", Double.toString(wanRcvMBytes)); //Egress double wanXmitMBytes; final String wanXmitBytes = nvRamInfoFromRouter.getProperty(wanIface + "_xmit_bytes", "-1"); try { wanXmitMBytes = Double.parseDouble(wanXmitBytes) / (1024 * 1024); if (wanXmitMBytes >= 0.) { wanXmitMBytes = new BigDecimal(wanXmitMBytes).setScale(2, RoundingMode.HALF_UP) .doubleValue(); bandwidthMonitoringIfaceData.addData("OUT", new BandwidthMonitoringTile.DataPoint(timestamp, wanXmitMBytes)); } } catch (@NotNull final NumberFormatException nfe) { return null; } nvRamInfoFromRouter.setProperty(wanIface + "_egress_MB", Double.toString(wanXmitMBytes)); return new None(); } catch (@NotNull final Exception e) { e.printStackTrace(); return (None) new None().setException(e); } } }; }