-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add weather command, remove unused permissions
- Loading branch information
devycarol
committed
Aug 3, 2024
1 parent
cc2a145
commit ce0113f
Showing
14 changed files
with
176 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.emilla.commands; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.ResolveInfo; | ||
|
||
import androidx.annotation.StringRes; | ||
|
||
import net.emilla.AssistActivity; | ||
import net.emilla.utils.Apps; | ||
import net.emilla.utils.Dialogs; | ||
|
||
import java.util.List; | ||
|
||
public abstract class CatCommand extends CoreCommand { | ||
private final int mAppCount; | ||
private Intent mLaunchIntent; | ||
private AlertDialog mAppChooser; | ||
|
||
public CatCommand(final AssistActivity act, @StringRes final int nameId, | ||
@StringRes final int instructionId, final String category) { | ||
super(act, nameId, instructionId); | ||
|
||
final PackageManager pm = act.getPackageManager(); | ||
final List<ResolveInfo> appList = Apps.resolveList(pm, category); | ||
mAppCount = appList.size(); | ||
if (mAppCount == 1) mLaunchIntent = Apps.launchIntent(appList.get(0).activityInfo); | ||
else if (mAppCount > 1) mAppChooser = Dialogs.appChooser(act, pm, appList).create(); | ||
} | ||
|
||
protected abstract void noSuchApp(); // TODO: handle at mapping | ||
|
||
@Override | ||
public void run() { | ||
switch (mAppCount) { | ||
case 0 -> noSuchApp(); | ||
case 1 -> succeed(mLaunchIntent); | ||
default -> offer(mAppChooser); | ||
// todo: allow to select a default app, ensuring that the preference is cleared if ever the default is no longer installed or a new candidate is installed | ||
// interestingly, Tasker is included if you remove CATEGORY_LAUNCHER from the intent. i assume this is for its special shortcut functionality. | ||
// will keep an eye on this. it shouldn't be included in this dialog (by default it "succeeds" to no actual activity, which was confusing to debug lol) | ||
// but it would be pretty useful to have a toolchain of those special launches ifwhen a dedicated "tasker" command is added. | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/net/emilla/commands/CatCommandCalculate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.emilla.commands; | ||
|
||
import static android.content.Intent.CATEGORY_APP_CALCULATOR; | ||
|
||
import net.emilla.AssistActivity; | ||
import net.emilla.R; | ||
import net.emilla.exceptions.EmlaAppsException; | ||
import net.emilla.parsing.Calculator; | ||
|
||
public class CatCommandCalculate extends CatCommand { | ||
public CatCommandCalculate(final AssistActivity act) { | ||
super(act, R.string.command_calculate, R.string.instruction_calculate, CATEGORY_APP_CALCULATOR); | ||
} | ||
|
||
@Override | ||
protected void noSuchApp() { | ||
throw new EmlaAppsException("No calculator app found for your device."); | ||
} | ||
|
||
@Override | ||
public Command cmd() { | ||
return Command.CALCULATE; | ||
} | ||
|
||
@Override | ||
public void run(final String expression) { | ||
// todo: AOSP calculator doesn't support piping in text, but maybe others do via ACTION_SEND? | ||
// i think run-with-instruction should still be a custom implementation, but you could add special support for such apps with a simple AppSendCommand | ||
give(String.valueOf(Calculator.compute(expression)), true); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/net/emilla/commands/CatCommandWeather.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.emilla.commands; | ||
|
||
import static android.content.Intent.CATEGORY_APP_WEATHER; | ||
|
||
import android.os.Build; | ||
|
||
import net.emilla.AssistActivity; | ||
import net.emilla.R; | ||
import net.emilla.exceptions.EmlaAppsException; | ||
import net.emilla.exceptions.EmlaBadCommandException; | ||
|
||
public class CatCommandWeather extends CatCommand { | ||
public CatCommandWeather(final AssistActivity act) { | ||
super(act, R.string.command_weather, R.string.instruction_app, CATEGORY_APP_WEATHER); | ||
} | ||
|
||
@Override | ||
protected void noSuchApp() { | ||
throw new EmlaAppsException("No weather app found for your device."); | ||
} | ||
|
||
@Override | ||
public Command cmd() { | ||
return Command.WEATHER; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) throw new EmlaBadCommandException("Sorry! This command doesn't support your Android version yet."); // Todo | ||
super.run(); | ||
} | ||
|
||
@Override | ||
public void run(final String expression) { | ||
throw new EmlaBadCommandException("Sorry! I don't have categorical app search yet."); // Todo | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path android:fillColor="#FFF" | ||
android:pathData="M6.76,4.84l-1.8,-1.79 -1.41,1.41 1.79,1.79 1.42,-1.41zM4,10.5L1,10.5v2h3v-2zM13,0.55h-2L11,3.5h2L13,0.55zM20.45,4.46l-1.41,-1.41 -1.79,1.79 1.41,1.41 1.79,-1.79zM17.24,18.16l1.79,1.8 1.41,-1.41 -1.8,-1.79 -1.4,1.4zM20,10.5v2h3v-2h-3zM12,5.5c-3.31,0 -6,2.69 -6,6s2.69,6 6,6 6,-2.69 6,-6 -2.69,-6 -6,-6zM11,22.45h2L13,19.5h-2v2.95zM3.55,18.54l1.41,1.41 1.79,-1.8 -1.41,-1.41 -1.79,1.8z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.