{"id":27938568,"url":"https://github.com/willowtreeapps/trafficcop","last_synced_at":"2025-05-07T08:49:20.211Z","repository":{"id":21936062,"uuid":"25260486","full_name":"willowtreeapps/trafficcop","owner":"willowtreeapps","description":"Monitor your Android apps' data usage so you can take action if it's over a threshold.","archived":false,"fork":false,"pushed_at":"2014-10-22T16:19:43.000Z","size":311,"stargazers_count":27,"open_issues_count":5,"forks_count":12,"subscribers_count":44,"default_branch":"master","last_synced_at":"2024-04-14T23:17:23.846Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willowtreeapps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-15T15:18:37.000Z","updated_at":"2024-04-04T03:09:38.000Z","dependencies_parsed_at":"2022-08-20T03:21:05.641Z","dependency_job_id":null,"html_url":"https://github.com/willowtreeapps/trafficcop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Ftrafficcop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Ftrafficcop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Ftrafficcop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willowtreeapps%2Ftrafficcop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willowtreeapps","download_url":"https://codeload.github.com/willowtreeapps/trafficcop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252847286,"owners_count":21813438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T08:49:19.693Z","updated_at":"2025-05-07T08:49:20.192Z","avatar_url":"https://github.com/willowtreeapps.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Traffic Cop Icon](https://raw.github.com/willowtreeapps/trafficcop/master/trafficcop.png\n)](https://github.com/willowtreeapps/trafficcop)\n\nTraffic Cop\n==========\n\nMonitor your Android app's data usage so you can take action if it's over a threshold.\n\n### Usage\nUse `TrafficCop.Builder` to create an instance to use throughout your app.  This is usually done in your Application subclass.\n\n```java\npublic class MyApplication extends Application {\n  public void onCreate() {\n    new TrafficCop.Builder()\n      // Set a threshold for downloads\n      .downloadWarningThreshold(Threshold.of(1, SizeUnit.GIGABYTE).per(1, TimeUnit.WEEK))\n      // Set a threshold for uploads\n      .uploadWarningThreshold(Threshold.of(10, SizeUnit.MEGABYTES).per(TimeUnit.HOUR))\n      // Register callbacks to be alerted when the threshold is reached\n      .alert(new LogDataUsageAlertAdapter(), new DataUsageAlertAdapter() {\n          @Override\n          public void alertThreshold(Threshold threshold, DataUsage dataUsage) {\n              // Alert somehow!\n          }\n      })\n      // Pass a string that uniquely identifies this instance. \n      .register(\"myTrafficCop\", this);\n  }\n}\n```\n\nThat's it!\n\nIf you want more control of when you measure you can create the `TrafficCop` instance instead of registering it.\n```java\nTrafficCop trafficCop = new TrafficCop.Builder()\n  .downloadWarningThreshold(Threshold.of(1, SizeUnit.GIGABYTE).per(1, TimeUnit.WEEK))\n  .uploadWarningThreshold(Threshold.of(10, SizeUnit.MEGABYTES).per(TimeUnit.HOUR))\n  .alert(new LogDataUsageAlertAdapter(), new DataUsageAlertAdapter() {\n      @Override\n      public void alertThreshold(Threshold threshold, DataUsage dataUsage) {\n          // Alert somehow!\n      }\n  })\n  .create(\"myTrafficCop\", this);\n```\n\nthen call `trafficCop.startMeasuring()` and `trafficCop.stopMeasuing()` at the approprite times.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillowtreeapps%2Ftrafficcop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillowtreeapps%2Ftrafficcop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillowtreeapps%2Ftrafficcop/lists"}