Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
added javadoc; streamlined code; implemented deleteDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Winger committed Oct 1, 2014
1 parent 66f39e4 commit 5c813c9
Show file tree
Hide file tree
Showing 21 changed files with 1,279 additions and 1,268 deletions.
3 changes: 3 additions & 0 deletions AIS.iml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/r" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/aidl" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/combined-assets" />
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/combined-resources" />
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/extracted-dependencies" />
<excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
<excludeFolder url="file://$MODULE_DIR$/target/maven-status" />
</content>
<orderEntry type="jdk" jdkName="Maven Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.dracode</groupId>
<artifactId>ais</artifactId>
<version>0.4.0</version>
<version>0.5.1</version>
<packaging>apk</packaging>
<name>AndroidIndexingService</name>
<dependencies>
Expand Down
90 changes: 53 additions & 37 deletions src/ca/dracode/ais/alarm/Alarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,65 @@

public class Alarm extends BroadcastReceiver {

public static void SetAlarm(Context context) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
// sets the alarm to repeat every 10 minutes
// TODO - Make alarm time change according to a user preference
if(am != null)
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), getMinutes(10), pi);
}
/**
* Starts the wakeup that calls for the device to be re-indexed after a certain period
* @param context
*/
public static void SetAlarm(Context context) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
// sets the alarm to repeat every 10 minutes
// TODO - Make alarm time change according to a user preference
if(am != null)
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
10 * 60000, pi);
}

public static void CancelAlarm(Context context) {
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
AlarmManager am = (AlarmManager) context.getSystemService("Context.ALARM_SERVICE");
if(am != null) {
/**
* Cancels the alerm started in SetAlarm(context) if it has been set
* @param context
*/
public static void CancelAlarm(Context context) {
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
AlarmManager am = (AlarmManager) context.getSystemService("Context.ALARM_SERVICE");
if(am != null) {
am.cancel(pi);
}
}
}

private static int getMinutes(int minutes) {
return minutes * 60000;
}

public void onReceive(Context context, Intent intent) {
// Starts the indexService
/**
* Starts the indexer if it is not already running
* @param context
* @param intent
*/
public void onReceive(Context context, Intent intent) {
// Starts the indexService
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

if (!this.isMyServiceRunning(context) && prefs.getBoolean("enabled", true)) {
Intent serviceIntent = new Intent(context, IndexService.class);
if(!this.isMyServiceRunning(context) && prefs.getBoolean("enabled", true)) {
Intent serviceIntent = new Intent(context, IndexService.class);
serviceIntent.putExtra("crawl", true);
context.startService(serviceIntent);
}
}
context.startService(serviceIntent);
}
}

private boolean isMyServiceRunning(Context c) {
ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
if (IndexService.class.getName().equals(
service.service.getClassName())) {
return true;
}
}
return false;
}
/**
* Checks if the indexing service is running
* @param context
* @return true if the service was found; false otherwise
*/
private boolean isMyServiceRunning(Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context
.ACTIVITY_SERVICE);
for(ActivityManager.RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
if(IndexService.class.getName().equals(
service.service.getClassName())) {
return true;
}
}
return false;
}
}
15 changes: 10 additions & 5 deletions src/ca/dracode/ais/alarm/AutoStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@

public class AutoStart extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
/**
* Checks if the received action is BOOT_COMPLETED and if so, sets the alarm for the Indexer
* @param context
* @param intent
*/
public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED") && prefs.getBoolean("enabled", true)) {
Alarm.SetAlarm(context);
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED") && prefs.getBoolean("enabled", true)) {
Alarm.SetAlarm(context);
Intent serviceIntent = new Intent(context, FileListener.class);
context.startService(serviceIntent);
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/ca/dracode/ais/indexclient/MClientService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface MClientService {
String getWordsForPage(int page);

/**
*
* Gets the number of pages in the file
* @return - the number of pages in the file specified at loadFile(String path)
*/
int getPageCount();
Expand Down
19 changes: 8 additions & 11 deletions src/ca/dracode/ais/indexdata/PageResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,26 @@ public PageResult[] newArray(int size) {
return new PageResult[size];
}
};
/**
*
*/
private static final long serialVersionUID = -2204743540787327738L;
public List<String> text;
public int page;
public String document;
public String document;

public PageResult() {
this.text = new ArrayList<String>();
this.text = new ArrayList<String>();
}

private PageResult(Parcel in) {
this();
this();
in.readList(this.text, null);
this.page = in.readInt();
this.document = in.readString();
this.page = in.readInt();
this.document = in.readString();
}

public PageResult(List<String> text, int page, String document) {
this.text = text;
this.page = page;
this.document = document;
this.document = document;
}

public int describeContents() {
Expand All @@ -74,8 +71,8 @@ public int describeContents() {

public void writeToParcel(Parcel out, int arg1) {
out.writeList(text);
out.writeInt(this.page);
out.writeString(this.document);
out.writeInt(this.page);
out.writeString(this.document);
}

}
Loading

0 comments on commit 5c813c9

Please sign in to comment.