Skip to content

Commit 7c7612a

Browse files
Added: Add launcher icon/activity that can optionally be disabled
Related issue #56
1 parent da4b437 commit 7c7612a

File tree

6 files changed

+119
-3
lines changed

6 files changed

+119
-3
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ dependencies {
6464
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
6565

6666
implementation "androidx.annotation:annotation:1.2.0"
67-
implementation 'com.termux.termux-app:termux-shared:4f66786b98'
67+
implementation 'com.google.android.material:material:1.4.0'
68+
implementation 'com.termux.termux-app:termux-shared:5e2bec0f4c'
6869

6970
// Use if below libraries are published locally by termux-app with `./gradlew publishReleasePublicationToMavenLocal` and used with `mavenLocal()`.
7071
// If updates are done, republish there and sync project with gradle files here

app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@
2525
android:name="android.appwidget.provider"
2626
android:resource="@xml/termux_appwidget_info" />
2727
</receiver>
28+
2829
<receiver android:name=".TermuxWidgetControlExecutorReceiver" />
2930

31+
<activity
32+
android:name=".activities.TermuxWidgetActivity"
33+
android:theme="@style/Theme.MaterialComponents.DayNight.TermuxPrimaryActivity" >
34+
<intent-filter>
35+
<action android:name="android.intent.action.MAIN"/>
36+
<category android:name="android.intent.category.LAUNCHER"/>
37+
</intent-filter>
38+
</activity>
39+
3040
<activity
3141
android:name=".TermuxCreateShortcutActivity"
3242
android:label="@string/title_single_shortcut_name">
@@ -35,6 +45,7 @@
3545
<category android:name="android.intent.category.DEFAULT" />
3646
</intent-filter>
3747
</activity>
48+
3849
<activity
3950
android:name=".TermuxLaunchShortcutActivity"
4051
android:noHistory="true"

app/src/main/java/com/termux/widget/TermuxWidgetProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public static void sendExecutionIntentToTermuxService(final Context context, Str
227227
Intent executionIntent = new Intent(TERMUX_SERVICE.ACTION_SERVICE_EXECUTE, executionCommand.executableUri);
228228
executionIntent.setClassName(TermuxConstants.TERMUX_PACKAGE_NAME, TermuxConstants.TERMUX_APP.TERMUX_SERVICE_NAME);
229229
executionIntent.putExtra(TERMUX_SERVICE.EXTRA_BACKGROUND, executionCommand.inBackground);
230-
executionIntent.putExtra(TERMUX_SERVICE.EXTRA_PLUGIN_API_HELP, context.getString(R.string.help, TermuxConstants.TERMUX_WIDGET_GITHUB_REPO_URL));
230+
executionIntent.putExtra(TERMUX_SERVICE.EXTRA_PLUGIN_API_HELP, context.getString(R.string.plugin_api_help, TermuxConstants.TERMUX_WIDGET_GITHUB_REPO_URL));
231231

232232
Logger.logVerboseExtended(logTag, executionCommand.toString());
233233
Logger.logDebug(logTag, "Sending execution intent to " + executionIntent.getComponent().toString() + " for \"" + executionCommand.executable + "\" with background mode " + executionCommand.inBackground);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.termux.widget.activities;
2+
3+
import android.os.Bundle;
4+
import android.widget.Button;
5+
import android.widget.TextView;
6+
7+
import androidx.appcompat.app.AppCompatActivity;
8+
9+
import com.termux.shared.logger.Logger;
10+
import com.termux.shared.packages.PackageUtils;
11+
import com.termux.shared.termux.TermuxConstants;
12+
import com.termux.widget.R;
13+
14+
public class TermuxWidgetActivity extends AppCompatActivity {
15+
16+
private static final String LOG_TAG = "TermuxWidgetActivity";
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_termux_widget);
22+
23+
TextView pluginInfo = findViewById(R.id.textview_plugin_info);
24+
pluginInfo.setText(getString(R.string.plugin_info, TermuxConstants.TERMUX_GITHUB_REPO_URL,
25+
TermuxConstants.TERMUX_WIDGET_GITHUB_REPO_URL));
26+
27+
Button disableLauncherIconButton = findViewById(R.id.btn_disable_launcher_icon);
28+
disableLauncherIconButton.setOnClickListener(v -> {
29+
String message = getString(R.string.msg_disabling_launcher_icon, TermuxConstants.TERMUX_WIDGET_APP_NAME);
30+
Logger.logInfo(LOG_TAG, message);
31+
PackageUtils.setComponentState(TermuxWidgetActivity.this,
32+
TermuxConstants.TERMUX_WIDGET_PACKAGE_NAME, TermuxConstants.TERMUX_WIDGET.TERMUX_WIDGET_ACTIVITY_NAME,
33+
false, message, true);
34+
});
35+
}
36+
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent" >
7+
<LinearLayout
8+
android:orientation="vertical"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:paddingTop="@dimen/activity_vertical_margin"
12+
android:paddingBottom="@dimen/activity_vertical_margin"
13+
android:paddingLeft="@dimen/activity_horizontal_margin"
14+
android:paddingRight="@dimen/activity_horizontal_margin"
15+
tools:context=".activities.TermuxWidgetActivity">
16+
17+
<com.google.android.material.textview.MaterialTextView
18+
android:id="@+id/textview_plugin_info"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:paddingTop="@dimen/activity_vertical_margin"
22+
android:paddingBottom="@dimen/activity_vertical_margin"
23+
android:gravity="start|center_vertical"
24+
android:textSize="14sp"
25+
android:textStyle="normal"
26+
android:textColor="?android:textColorPrimary"
27+
android:textColorLink="?android:textColorLink"
28+
android:autoLink="web"/>
29+
30+
<View style="@style/ViewDivider"/>
31+
32+
<com.google.android.material.textview.MaterialTextView
33+
android:id="@+id/textview_disable_launcher_icon_details"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:paddingBottom="@dimen/activity_vertical_margin"
37+
android:gravity="start|center_vertical"
38+
android:text="@string/msg_disable_launcher_icon_details"
39+
android:textSize="14sp"
40+
android:textStyle="normal"
41+
android:textColor="?android:textColorPrimary"
42+
android:textColorLink="?android:textColorLink"
43+
android:autoLink="web"/>
44+
45+
<com.google.android.material.button.MaterialButton
46+
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
47+
android:id="@+id/btn_disable_launcher_icon"
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content"
50+
android:layout_gravity="end"
51+
android:gravity="center"
52+
android:text="@string/action_disable_launcher_icon"
53+
android:textSize="12sp"
54+
android:textColor="?android:textColorPrimary"
55+
app:strokeColor="?android:textColorPrimary"
56+
app:strokeWidth="2dp"/>
57+
</LinearLayout>
58+
59+
</ScrollView>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010

1111
<resources>EXTRA_SHORTCUT_INTENT
1212
<string name="app_name">&TERMUX_WIDGET_APP_NAME;</string>
13-
<string name="help">Visit %1$s for more info on plugin usage.</string>
13+
<string name="plugin_info">&TERMUX_WIDGET_APP_NAME; is a plugin app for the &TERMUX_APP_NAME; app. Check &TERMUX_APP_NAME; app github %1$s and &TERMUX_WIDGET_APP_NAME; app github %2$s for more info.</string>
14+
<string name="plugin_api_help">Visit %1$s for more info on plugin usage.</string>
15+
16+
<!-- TermuxWidgetActivity -->
17+
<string name="msg_disable_launcher_icon_details">The &TERMUX_WIDGET_APP_NAME; app does not require
18+
a require launcher icon/activity to function. You can optionally disable it if you want and
19+
can enabled in again either by reinstalling the app or from the &TERMUX_APP_NAME; app settings
20+
if the option has been implemented in your installed version."</string>
21+
1422

1523
<string name="title_widget">&TERMUX_APP_NAME;</string>
1624
<string name="title_shortcut_widget_name">&TERMUX_APP_NAME; widget</string>

0 commit comments

Comments
 (0)