Skip to content

Commit

Permalink
Add shortcuts (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
frimtec authored Apr 24, 2023
1 parent 6f18fd3 commit 6121150
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity android:name=".ui.alerts.AlertDetailActivity">
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -169,7 +170,13 @@ protected void onCreate(Bundle savedInstanceState) {

this.billingAdapter = new BillingAdapter(this);

FragmentPosition savedFragmentPosition = FragmentPosition.STATE;
FragmentPosition savedFragmentPosition = Arrays.stream(FragmentPosition.values())
.map(Enum::name)
.filter(value -> value.equals(getIntent().getAction()))
.findFirst()
.map(FragmentPosition::valueOf)
.orElse(FragmentPosition.STATE);

if (savedInstanceState != null) {
savedFragmentPosition = ensureValidFragmentPosition(savedInstanceState.getInt(ACTIVE_FRAGMENT_STATE, savedFragmentPosition.ordinal()));
} else {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/drawable/ic_event_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="612"
android:viewportHeight="612"
android:fillColor="#FF0000">
<path
android:fillColor="@color/notificationIcon"
android:pathData="M233.667,58.286l-0.146,29.143l143.004,0l0.175,-29.143z" />
<path
android:fillColor="@color/notificationIcon"
android:pathData="M466.286,87.458V29.114C466.286,13.027 453.2,0 437.143,0C421.056,0 408,13.027 408,29.114v58.344c0,16.087 13.085,29.114 29.143,29.114C453.229,116.571 466.286,103.544 466.286,87.458z" />
<path
android:fillColor="@color/notificationIcon"
android:pathData="M182.143,116.571c12.065,0 21.857,-9.733 21.857,-21.915V21.916C204,9.821 194.237,0 182.143,0h-14.572c-12.065,0 -21.857,9.734 -21.857,21.916v72.711c0,12.124 9.763,21.944 21.857,21.944H182.143z" />
<path
android:fillColor="@color/notificationIcon"
android:pathData="M115.697,87.429l0.146,-29.143H18.331C8.189,58.286 0,66.766 0,77.199v515.916C0,603.549 8.189,612 18.302,612h575.367c10.142,0 18.331,-8.48 18.331,-18.885V77.199c0,-10.462 -8.219,-18.914 -18.331,-18.914h-98.036l-0.146,29.143h87.37v145.714H29.143V87.429H115.697zM116.571,582.857H41.674c-6.936,0 -12.531,-4.867 -12.531,-10.899v-76.529h87.428V582.857zM116.571,466.286H29.143v-87.429h87.428V466.286zM495.429,262.286h87.429v87.428h-87.429V262.286zM495.429,378.857h87.429v87.429h-87.429V378.857zM495.429,495.429h87.429v76.529c0,6.003 -5.625,10.899 -12.531,10.899h-74.897V495.429zM378.857,262.286h87.429v87.428h-87.429V262.286zM378.857,378.857h87.429v87.429h-87.429V378.857zM378.857,495.429h87.429v87.429h-87.429V495.429zM262.286,262.286h87.428v87.428h-87.428V262.286zM262.286,495.429h87.428v87.429h-87.428V495.429zM145.714,262.286h87.429v87.428h-87.429V262.286zM145.714,378.857h87.429v87.429h-87.429V378.857zM145.714,495.429h87.429v87.429h-87.429V495.429zM116.571,262.286v87.428H29.143v-87.428H116.571z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_home_24dp_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/notificationIcon"
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
</vector>
38 changes: 38 additions & 0 deletions app/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/ic_home_24dp_black"
android:shortcutDisabledMessage="@string/title_home"
android:shortcutId="overview"
android:shortcutLongLabel="@string/title_home"
android:shortcutShortLabel="@string/title_home">
<intent
android:action="STATE"
android:targetClass="com.github.frimtec.android.pikettassist.ui.MainActivity"
android:targetPackage="com.github.frimtec.android.pikettassist" />
</shortcut>
<shortcut
android:enabled="true"
android:icon="@drawable/ic_event_black"
android:shortcutDisabledMessage="@string/title_shift_overview"
android:shortcutId="calendar"
android:shortcutLongLabel="@string/title_shift_overview"
android:shortcutShortLabel="@string/title_shift_overview">
<intent
android:action="SHIFTS"
android:targetClass="com.github.frimtec.android.pikettassist.ui.MainActivity"
android:targetPackage="com.github.frimtec.android.pikettassist" />
</shortcut>
<shortcut
android:enabled="true"
android:icon="@drawable/ic_siren_black"
android:shortcutDisabledMessage="@string/title_alert_log"
android:shortcutId="alert_log"
android:shortcutLongLabel="@string/title_alert_log"
android:shortcutShortLabel="@string/title_alert_log">
<intent
android:action="ALERT_LOG"
android:targetClass="com.github.frimtec.android.pikettassist.ui.MainActivity"
android:targetPackage="com.github.frimtec.android.pikettassist" />
</shortcut>
</shortcuts>

0 comments on commit 6121150

Please sign in to comment.