Skip to content

Commit c703e4a

Browse files
committed
Todos 1: Query usage for a specific package.
1 parent 6750841 commit c703e4a

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

app/src/main/java/com/example/appusage/MainActivity.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ protected void onCreate(Bundle savedInstanceState) {
3737
super.onCreate(savedInstanceState);
3838
setContentView(R.layout.activity_main);
3939

40+
41+
Monitor.scan().queryFor(this).whichPackage("com.whatsapp").
42+
fetchFor(Duration.TODAY);//check usage for specific package.
4043
}
4144

4245
@Override
@@ -70,9 +73,7 @@ private void init() {
7073

7174
@Override
7275
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
73-
// Monitor.scan().getAppLists(this).fetchFor(Duration.TODAY);
74-
Monitor.scan().queryFor(this).whichPackage("com.whatsapp").
75-
fetchFor(Duration.TODAY);
76+
Monitor.scan().getAppLists(this).fetchFor(i);
7677
}
7778

7879
@Override
@@ -82,12 +83,10 @@ public void onNothingSelected(AdapterView<?> adapterView) {
8283

8384
@Override
8485
public void showProgress() {
85-
8686
}
8787

8888
@Override
8989
public void hideProgress() {
90-
9190
}
9291
/**
9392
* @param usageData list of application that has been within the duration for which query has been made.
@@ -102,5 +101,7 @@ public void getUsageData(List<AppData> usageData, long mTotalUsage, int duration
102101

103102
@Override
104103
public void getUsageForPackage(String mPackage, long mTotalUsage, int duration) {
104+
System.out.println("Usage for "+mPackage+" is : "+UsageUtils.humanReadableMillis(mTotalUsage)
105+
+" for "+ Duration.getCurrentReadableDay(duration));
105106
}
106107
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package bot.box.appusage;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("bot.box.appusage.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package bot.box.appusage;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

0 commit comments

Comments
 (0)