这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit 3c60178

Browse files
Changed: Rename TermuxTaskerActivity to TermuxTaskerMainActivity stage 2
The `TermuxTaskerLauncherActivity` activity alias has been added for `TermuxTaskerMainActivity`. This will allow disabling the launcher activity, but still allow the main activity to be launched from Termux app. The launcher activity will also now be allowed to be enabled again without having to reinstall the app with the `Enable Launcher Icon` button in the main activity if its currently disabled.
1 parent 07f8694 commit 3c60178

File tree

4 files changed

+86
-24
lines changed

4 files changed

+86
-24
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
android:supportsRtl="true">
1414

1515
<activity
16-
android:name=".activities.TermuxTaskerActivity"
16+
android:name=".activities.TermuxTaskerMainActivity"
1717
android:exported="true"
18-
android:theme="@style/Theme.BaseActivity.DayNight.NoActionBar"
19-
>
18+
android:theme="@style/Theme.BaseActivity.DayNight.NoActionBar">
19+
</activity>
20+
21+
<activity-alias
22+
android:name=".activities.TermuxTaskerLauncherActivity"
23+
android:exported="true"
24+
android:targetActivity=".activities.TermuxTaskerMainActivity">
2025
<intent-filter>
2126
<action android:name="android.intent.action.MAIN"/>
2227
<category android:name="android.intent.category.LAUNCHER"/>
2328
</intent-filter>
24-
</activity>
29+
</activity-alias>
2530

2631
<!--
2732
This is the "edit" Activity. Note that Locale will reject plug-in Activities for the following reasons:·

app/src/main/java/com/termux/tasker/activities/TermuxTaskerMainActivity.java

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
import com.termux.shared.activity.media.AppCompatActivityUtils;
1010
import com.termux.shared.android.PackageUtils;
1111
import com.termux.shared.logger.Logger;
12+
import com.termux.shared.markdown.MarkdownUtils;
1213
import com.termux.shared.termux.TermuxConstants;
1314
import com.termux.shared.termux.theme.TermuxThemeUtils;
1415
import com.termux.shared.theme.NightMode;
1516
import com.termux.tasker.R;
1617

17-
public class TermuxTaskerActivity extends AppCompatActivity {
18+
public class TermuxTaskerMainActivity extends AppCompatActivity {
1819

19-
private static final String LOG_TAG = "TermuxTaskerActivity";
20+
public static final String LOG_TAG = "TermuxTaskerMainActivity";
2021

2122
@Override
2223
protected void onCreate(Bundle savedInstanceState) {
2324
super.onCreate(savedInstanceState);
24-
setContentView(R.layout.activity_termux_tasker);
25+
setContentView(R.layout.activity_termux_tasker_main);
2526

2627
// Set NightMode.APP_NIGHT_MODE
2728
TermuxThemeUtils.setAppNightMode(this);
@@ -33,14 +34,62 @@ protected void onCreate(Bundle savedInstanceState) {
3334
TextView pluginInfo = findViewById(R.id.textview_plugin_info);
3435
pluginInfo.setText(getString(R.string.plugin_info, TermuxConstants.TERMUX_GITHUB_REPO_URL,
3536
TermuxConstants.TERMUX_TASKER_GITHUB_REPO_URL));
37+
}
38+
39+
@Override
40+
protected void onResume() {
41+
super.onResume();
42+
43+
Logger.logVerbose(LOG_TAG, "onResume");
44+
45+
setChangeLauncherActivityStateViews();
46+
}
47+
48+
49+
50+
private void setChangeLauncherActivityStateViews() {
51+
String packageName = TermuxConstants.TERMUX_TASKER_PACKAGE_NAME;
52+
String className = TermuxConstants.TERMUX_TASKER_APP.TERMUX_TASKER_LAUNCHER_ACTIVITY_NAME;
53+
54+
TextView changeLauncherActivityStateTextView = findViewById(R.id.textview_change_launcher_activity_state_details);
55+
changeLauncherActivityStateTextView.setText(MarkdownUtils.getSpannedMarkdownText(this,
56+
getString(R.string.msg_change_launcher_activity_state_info, packageName, getClass().getName())));
57+
58+
Button changeLauncherActivityStateButton = findViewById(R.id.button_change_launcher_activity_state);
59+
String stateChangeMessage;
60+
boolean newState;
61+
62+
Boolean currentlyDisabled = PackageUtils.isComponentDisabled(this,
63+
packageName, className, false);
64+
if (currentlyDisabled == null) {
65+
Logger.logError(LOG_TAG, "Failed to check if \"" + packageName + "/" + className + "\" launcher activity is disabled");
66+
changeLauncherActivityStateButton.setEnabled(false);
67+
changeLauncherActivityStateButton.setAlpha(.5f);
68+
changeLauncherActivityStateButton.setText(com.termux.shared.R.string.action_disable_launcher_icon);
69+
changeLauncherActivityStateButton.setOnClickListener(null);
70+
return;
71+
}
72+
73+
changeLauncherActivityStateButton.setEnabled(true);
74+
changeLauncherActivityStateButton.setAlpha(1f);
75+
if (currentlyDisabled) {
76+
changeLauncherActivityStateButton.setText(com.termux.shared.R.string.action_enable_launcher_icon);
77+
stateChangeMessage = getString(com.termux.shared.R.string.msg_enabling_launcher_icon, TermuxConstants.TERMUX_TASKER_APP_NAME);
78+
newState = true;
79+
} else {
80+
changeLauncherActivityStateButton.setText(com.termux.shared.R.string.action_disable_launcher_icon);
81+
stateChangeMessage = getString(com.termux.shared.R.string.msg_disabling_launcher_icon, TermuxConstants.TERMUX_TASKER_APP_NAME);
82+
newState = false;
83+
}
3684

37-
Button disableLauncherIconButton = findViewById(R.id.btn_disable_launcher_icon);
38-
disableLauncherIconButton.setOnClickListener(v -> {
39-
String message = getString(com.termux.shared.R.string.msg_disabling_launcher_icon, TermuxConstants.TERMUX_TASKER_APP_NAME);
40-
Logger.logInfo(LOG_TAG, message);
41-
PackageUtils.setComponentState(TermuxTaskerActivity.this,
42-
TermuxConstants.TERMUX_TASKER_PACKAGE_NAME, TermuxConstants.TERMUX_TASKER.TERMUX_TASKER_ACTIVITY_NAME,
43-
false, message, true);
85+
changeLauncherActivityStateButton.setOnClickListener(v -> {
86+
Logger.logInfo(LOG_TAG, stateChangeMessage);
87+
String errmsg = PackageUtils.setComponentState(this,
88+
packageName, className, newState, stateChangeMessage, true);
89+
if (errmsg == null)
90+
setChangeLauncherActivityStateViews();
91+
else
92+
Logger.logError(LOG_TAG, errmsg);
4493
});
4594
}
4695

app/src/main/res/layout/activity_termux_tasker_main.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
android:paddingBottom="@dimen/activity_vertical_margin"
2222
android:paddingLeft="@dimen/activity_horizontal_margin"
2323
android:paddingRight="@dimen/activity_horizontal_margin"
24-
tools:context=".activities.TermuxTaskerActivity">
24+
tools:context=".activities.TermuxTaskerMainActivity">
2525

2626
<com.google.android.material.textview.MaterialTextView
2727
android:id="@+id/textview_plugin_info"
@@ -34,31 +34,33 @@
3434
android:textStyle="normal"
3535
android:textColor="?android:textColorPrimary"
3636
android:textColorLink="?android:textColorLink"
37+
android:textIsSelectable="true"
3738
android:autoLink="web"/>
3839

40+
41+
3942
<View style="@style/ViewDivider"/>
4043

4144
<com.google.android.material.textview.MaterialTextView
42-
android:id="@+id/textview_disable_launcher_icon_details"
45+
android:id="@+id/textview_change_launcher_activity_state_details"
4346
android:layout_width="match_parent"
4447
android:layout_height="wrap_content"
4548
android:paddingBottom="@dimen/activity_vertical_margin"
4649
android:gravity="start|center_vertical"
47-
android:text="@string/msg_disable_launcher_icon_details"
4850
android:textSize="14sp"
4951
android:textStyle="normal"
5052
android:textColor="?android:textColorPrimary"
5153
android:textColorLink="?android:textColorLink"
54+
android:textIsSelectable="true"
5255
android:autoLink="web"/>
5356

5457
<com.google.android.material.button.MaterialButton
5558
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
56-
android:id="@+id/btn_disable_launcher_icon"
59+
android:id="@+id/button_change_launcher_activity_state"
5760
android:layout_width="wrap_content"
5861
android:layout_height="wrap_content"
5962
android:layout_gravity="end"
6063
android:gravity="center"
61-
android:text="@string/action_disable_launcher_icon"
6264
android:textSize="12sp"
6365
android:textColor="?android:textColorPrimary"
6466
app:strokeColor="?android:textColorPrimary"

app/src/main/res/values/strings.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
Check &TERMUX_APP_NAME; app github %1$s and &TERMUX_TASKER_APP_NAME; app github %2$s for more info.</string>
2020
<string name="plugin_api_help">Visit %1$s for more info on plugin usage.</string>
2121

22-
<!-- TermuxTaskerActivity -->
23-
<string name="msg_disable_launcher_icon_details">The &TERMUX_TASKER_APP_NAME; app does not require
24-
a launcher icon/activity to function. You can optionally disable it if you want and
25-
can enable it again either by reinstalling the app or from the &TERMUX_APP_NAME; app settings
26-
if the option has been implemented in your installed version."</string>
22+
<!-- TermuxTaskerMainActivity -->
23+
<string name="msg_change_launcher_activity_state_info">The &TERMUX_TASKER_APP_NAME; app does not
24+
require a require launcher activity/icon to function. You can optionally disable the launcher
25+
activity if you want and enable it again from the main activity if required.
26+
\n\nThe launcher activity is an alias for the current main activity of the app which can
27+
still be opened after disabling the launcher activity. The main activity can be opened
28+
from `&TERMUX_APP_NAME; app settings` -> `&TERMUX_TASKER_APP_NAME;` -> `Open App` if the
29+
option has been implemented in your installed &TERMUX_APP_NAME; app version. Otherwise,
30+
running the `am start "%1$s/%2$s"` command in the &TERMUX_APP_NAME; app should open it.
31+
\n\nNote that on some devices the APIs may not function properly if the launcher activity is
32+
disabled.</string>
2733

2834

2935

0 commit comments

Comments
 (0)