Java Code Examples for android.graphics.drawable.Icon#createWithResource()

The following examples show how to use android.graphics.drawable.Icon#createWithResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShadowsocksTileService.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);

    iconIdle = Icon.createWithResource(this, R.drawable.ic_start_idle).setTint(0x80ffffff);
    iconBusy = Icon.createWithResource(this, R.drawable.ic_start_busy);
    iconConnected = Icon.createWithResource(this, R.drawable.ic_start_connected);

    mServiceBoundContext = new ServiceBoundContext(base) {
        @Override
        protected void onServiceConnected() {
            try {
                callback.stateChanged(bgService.getState(), bgService.getProfileName(), null);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    };
}
 
Example 2
Source File: ShadowsocksTileService.java    From Maying with Apache License 2.0 6 votes vote down vote up
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);

    iconIdle = Icon.createWithResource(this, R.drawable.ic_start_idle).setTint(0x80ffffff);
    iconBusy = Icon.createWithResource(this, R.drawable.ic_start_busy);
    iconConnected = Icon.createWithResource(this, R.drawable.ic_start_connected);

    mServiceBoundContext = new ServiceBoundContext(base) {
        @Override
        protected void onServiceConnected() {
            try {
                callback.stateChanged(bgService.getState(), bgService.getProfileName(), null);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    };
}
 
Example 3
Source File: HostChooserTargetService.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    final List<ChooserTarget> targets = new ArrayList<>();
    HostManager hostManager = HostManager.getInstance(this);

    final Icon icon = Icon.createWithResource(this, R.mipmap.ic_launcher);
    final float score = 0;
    final ComponentName componentName = new ComponentName(getPackageName(), "org.xbmc.kore.ui.sections.remote.RemoteActivity");

    for (HostInfo host : hostManager.getHosts()) {
        Bundle intentExtras = new Bundle();
        intentExtras.putInt("hostId", host.getId());
        targets.add(new ChooserTarget(host.getName(), icon, score, componentName, intentExtras));
    }

    return targets;
}
 
Example 4
Source File: AndroidOPiPActivity.java    From DKVideoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * Update the state of pause/resume action item in Picture-in-Picture mode.
 *
 * @param iconId      The icon to be used.
 * @param title       The title text.
 * @param controlType The type of the action. either {@link #CONTROL_TYPE_PLAY} or {@link
 *                    #CONTROL_TYPE_PAUSE}.
 * @param requestCode The request code for the {@link PendingIntent}.
 */
void updatePictureInPictureActions(
        @DrawableRes int iconId, String title, int controlType, int requestCode) {
    final ArrayList<RemoteAction> actions = new ArrayList<>();

    // This is the PendingIntent that is invoked when a user clicks on the action item.
    // You need to use distinct request codes for play and pause, or the PendingIntent won't
    // be properly updated.
    final PendingIntent intent =
            PendingIntent.getBroadcast(
                    AndroidOPiPActivity.this,
                    requestCode,
                    new Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
                    0);
    final Icon icon = Icon.createWithResource(AndroidOPiPActivity.this, iconId);
    actions.add(new RemoteAction(icon, title, title, intent));

    mPictureInPictureParamsBuilder.setActions(actions);

    // This is how you can update action items (or aspect ratio) for Picture-in-Picture mode.
    // Note this call can happen even when the app is not in PiP mode. In that case, the
    // arguments will be used for at the next call of #enterPictureInPictureMode.
    setPictureInPictureParams(mPictureInPictureParamsBuilder.build());
}
 
Example 5
Source File: TextClassifierImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Nullable
RemoteAction asRemoteAction(Context context) {
    final PackageManager pm = context.getPackageManager();
    final ResolveInfo resolveInfo = pm.resolveActivity(mIntent, 0);
    final String packageName = resolveInfo != null && resolveInfo.activityInfo != null
            ? resolveInfo.activityInfo.packageName : null;
    Icon icon = null;
    boolean shouldShowIcon = false;
    if (packageName != null && !"android".equals(packageName)) {
        // There is a default activity handling the intent.
        mIntent.setComponent(new ComponentName(packageName, resolveInfo.activityInfo.name));
        if (resolveInfo.activityInfo.getIconResource() != 0) {
            icon = Icon.createWithResource(
                    packageName, resolveInfo.activityInfo.getIconResource());
            shouldShowIcon = true;
        }
    }
    if (icon == null) {
        // RemoteAction requires that there be an icon.
        icon = Icon.createWithResource("android",
                com.android.internal.R.drawable.ic_more_items);
    }
    final PendingIntent pendingIntent =
            TextClassification.createPendingIntent(context, mIntent, mRequestCode);
    if (pendingIntent == null) {
        return null;
    }
    final RemoteAction action = new RemoteAction(icon, mTitle, mDescription, pendingIntent);
    action.setShouldShowIcon(shouldShowIcon);
    return action;
}
 
Example 6
Source File: ShortcutsManager.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static Icon getShortcutsIcon(Context context,
                                     @DrawableRes int id, @DrawableRes int foregroundId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        try {
            DisplayUtils utils = new DisplayUtils(context);
            int size = (int) Math.min(utils.dpToPx(108), 288);
            Bitmap bitmap = ImageHelper.loadBitmap(context, foregroundId, new int[] {size, size});
            return Icon.createWithAdaptiveBitmap(bitmap);
        } catch (ExecutionException | InterruptedException ignored) {

        }
    }
    return Icon.createWithResource(context, id);
}
 
Example 7
Source File: MaskTileService.java    From Blackbulb with GNU General Public License v3.0 5 votes vote down vote up
private void updateActiveTile(Tile tile) {
    Icon activeIcon = Icon
            .createWithResource(getApplicationContext(),
                    R.drawable.ic_qs_night_mode_on);

    tile.setIcon(activeIcon);
    tile.setState(Tile.STATE_ACTIVE);
    tile.updateTile();
}
 
Example 8
Source File: MaskTileService.java    From Blackbulb with GNU General Public License v3.0 5 votes vote down vote up
private void updateInactiveTile(Tile tile) {
    Icon inActiveIcon = Icon
            .createWithResource(getApplicationContext(),
                    R.drawable.ic_qs_night_mode_off);

    tile.setIcon(inActiveIcon);
    tile.setState(Tile.STATE_INACTIVE);
    tile.updateTile();
}
 
Example 9
Source File: QuickSettingsService.java    From android-samples with Apache License 2.0 5 votes vote down vote up
private void updateTile() {
    Tile tile = this.getQsTile();

    boolean isActive = this.getServiceStatus();

    String newLabel;
    Icon newIcon;
    int newState;
    if (isActive) {
        newLabel = "MyQs is active.";
        newIcon = Icon.createWithResource(getApplicationContext(),
                android.R.drawable.ic_dialog_alert);
        newState = Tile.STATE_ACTIVE;

        //open result activity
        Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    } else {
        newLabel = "MyQs is inactive.";
        newIcon = Icon.createWithResource(getApplicationContext(),
                R.mipmap.ic_tile_inactive);
        newState = Tile.STATE_INACTIVE;
    }

    tile.setIcon(newIcon);
    tile.setLabel(newLabel);
    tile.setState(newState);

    tile.updateTile();
}
 
Example 10
Source File: MainActivity.java    From android-PictureInPicture with Apache License 2.0 5 votes vote down vote up
/**
 * Update the state of pause/resume action item in Picture-in-Picture mode.
 *
 * @param iconId The icon to be used.
 * @param title The title text.
 * @param controlType The type of the action. either {@link #CONTROL_TYPE_PLAY} or {@link
 *     #CONTROL_TYPE_PAUSE}.
 * @param requestCode The request code for the {@link PendingIntent}.
 */
void updatePictureInPictureActions(
        @DrawableRes int iconId, String title, int controlType, int requestCode) {
    final ArrayList<RemoteAction> actions = new ArrayList<>();

    // This is the PendingIntent that is invoked when a user clicks on the action item.
    // You need to use distinct request codes for play and pause, or the PendingIntent won't
    // be properly updated.
    final PendingIntent intent =
            PendingIntent.getBroadcast(
                    MainActivity.this,
                    requestCode,
                    new Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
                    0);
    final Icon icon = Icon.createWithResource(MainActivity.this, iconId);
    actions.add(new RemoteAction(icon, title, title, intent));

    // Another action item. This is a fixed action.
    actions.add(
            new RemoteAction(
                    Icon.createWithResource(MainActivity.this, R.drawable.ic_info_24dp),
                    getString(R.string.info),
                    getString(R.string.info_description),
                    PendingIntent.getActivity(
                            MainActivity.this,
                            REQUEST_INFO,
                            new Intent(
                                    Intent.ACTION_VIEW,
                                    Uri.parse(getString(R.string.info_uri))),
                            0)));

    mPictureInPictureParamsBuilder.setActions(actions);

    // This is how you can update action items (or aspect ratio) for Picture-in-Picture mode.
    // Note this call can happen even when the app is not in PiP mode. In that case, the
    // arguments will be used for at the next call of #enterPictureInPictureMode.
    setPictureInPictureParams(mPictureInPictureParamsBuilder.build());
}
 
Example 11
Source File: SpectrumTile.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
private void resetTileStatus() {
      int profile = Utils.strToInt(Spectrum.getProfile());
      Tile tile = this.getQsTile();
      Icon newIcon;
      String newLabel;
      int newState;

      // Update tile
      if (!(Spectrum.supported())) {
          newLabel = "No Spectrum support";
          newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_logo);
          newState = Tile.STATE_INACTIVE;
      }else {
          if (profile == 3) {
newLabel = "Gaming";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_game);
newState = Tile.STATE_ACTIVE;
          } else if (profile == 2) {
newLabel = "Battery";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_battery);
newState = Tile.STATE_ACTIVE;
          } else if (profile == 1) {
newLabel = "Performance";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_performance);
newState = Tile.STATE_ACTIVE;
          } else {
newLabel = "Balance";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_balanced);
newState = Tile.STATE_ACTIVE;
          }
      }

      // Change the UI of the tile.
      tile.setLabel(newLabel);
      tile.setIcon(newIcon);
      tile.setState(newState);
      tile.updateTile();
  }
 
Example 12
Source File: LinphoneShortcutManager.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
public ShortcutInfo createChatRoomShortcutInfo(
        LinphoneContact contact, String chatRoomAddress) {
    if (contact == null) return null;

    Bitmap bm = null;
    if (contact.getThumbnailUri() != null) {
        bm = ImageUtils.getRoundBitmapFromUri(mContext, contact.getThumbnailUri());
    }
    Icon icon =
            bm == null
                    ? Icon.createWithResource(mContext, R.drawable.avatar)
                    : Icon.createWithBitmap(bm);

    try {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClass(mContext, ChatActivity.class);
        intent.addFlags(
                Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        intent.putExtra("RemoteSipUri", chatRoomAddress);

        return new ShortcutInfo.Builder(mContext, chatRoomAddress)
                .setShortLabel(contact.getFullName())
                .setIcon(icon)
                .setCategories(mCategories)
                .setIntent(intent)
                .build();
    } catch (Exception e) {
        Log.e("[Shortcuts Manager] ShortcutInfo.Builder exception: " + e);
    }

    return null;
}
 
Example 13
Source File: MainActivity.java    From c3nav-android with Apache License 2.0 5 votes vote down vote up
@RequiresApi(Build.VERSION_CODES.N_MR1)
public ShortcutInfo getShortcutInfo(@NonNull String id, @NonNull int shortLabelRessource, int longLabelRessource, @NonNull int iconRessource, @NonNull String action, Uri data) {
    String shortLabel = getString(shortLabelRessource);
    String longLabel = (longLabelRessource != -1) ? getString(longLabelRessource) : null;
    Icon icon = Icon.createWithResource(getApplicationContext(), iconRessource);
    return getShortcutInfo(id,shortLabel, longLabel, icon, action, data);
}
 
Example 14
Source File: BaseSmsDecoratorService.java    From nevo-decorators-sms-captchas with GNU General Public License v3.0 5 votes vote down vote up
protected Notification.Action createNonIconAction(String key, String title, Parcelable cookies) {
    Icon icon = Icon.createWithResource(this, R.drawable.ic_empty);
    Intent intent = new Intent().setAction(INTENT_ACTION_CLICKED_ACTION).putExtra(INTENT_EXTRA_COOKIES, cookies).putExtra(INTENT_EXTRA_NOTIFICATION_KEY, key);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, cookies.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

    return new Notification.Action.Builder(icon, title, pendingIntent).build();
}
 
Example 15
Source File: RecoverableSecurityException.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** {@hide} */
@Deprecated
public RecoverableSecurityException(Throwable cause, CharSequence userMessage,
        CharSequence userActionTitle, PendingIntent userAction) {
    this(cause, userMessage,
            new RemoteAction(
                    Icon.createWithResource("android",
                            com.android.internal.R.drawable.ic_restart),
                    userActionTitle, userActionTitle, userAction));
}
 
Example 16
Source File: MainActivity.java    From media-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Update the state of pause/resume action item in Picture-in-Picture mode.
 *
 * @param iconId The icon to be used.
 * @param title The title text.
 * @param controlType The type of the action. either {@link #CONTROL_TYPE_PLAY} or {@link
 *     #CONTROL_TYPE_PAUSE}.
 * @param requestCode The request code for the {@link PendingIntent}.
 */
void updatePictureInPictureActions(
        @DrawableRes int iconId, String title, int controlType, int requestCode) {
    final ArrayList<RemoteAction> actions = new ArrayList<>();

    // This is the PendingIntent that is invoked when a user clicks on the action item.
    // You need to use distinct request codes for play and pause, or the PendingIntent won't
    // be properly updated.
    final PendingIntent intent =
            PendingIntent.getBroadcast(
                    MainActivity.this,
                    requestCode,
                    new Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
                    0);
    final Icon icon = Icon.createWithResource(MainActivity.this, iconId);
    actions.add(new RemoteAction(icon, title, title, intent));

    // Another action item. This is a fixed action.
    actions.add(
            new RemoteAction(
                    Icon.createWithResource(MainActivity.this, R.drawable.ic_info_24dp),
                    getString(R.string.info),
                    getString(R.string.info_description),
                    PendingIntent.getActivity(
                            MainActivity.this,
                            REQUEST_INFO,
                            new Intent(
                                    Intent.ACTION_VIEW,
                                    Uri.parse(getString(R.string.info_uri))),
                            0)));

    mPictureInPictureParamsBuilder.setActions(actions);

    // This is how you can update action items (or aspect ratio) for Picture-in-Picture mode.
    // Note this call can happen even when the app is not in PiP mode. In that case, the
    // arguments will be used for at the next call of #enterPictureInPictureMode.
    setPictureInPictureParams(mPictureInPictureParamsBuilder.build());
}
 
Example 17
Source File: SpectrumTile.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
private void updateTile() {
      Tile tile = this.getQsTile();
      Icon newIcon;
      String newLabel;
      int newState;

      // Update tile and set profile
      if (!(Spectrum.supported())) {
          newLabel = "No Spectrum support";
          newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_logo);
          newState = Tile.STATE_INACTIVE;
      } else {
          if (id == 0) {
newLabel = "Performance";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_game);
newState = Tile.STATE_ACTIVE;
id +=1;
Spectrum.setProfile(1);
Prefs.saveInt("spectrum_profile", 1, getApplicationContext());
          } else if (id == 1) {
newLabel = "Battery";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_battery);
newState = Tile.STATE_ACTIVE;
id +=1;
Spectrum.setProfile(2);
Prefs.saveInt("spectrum_profile", 2, getApplicationContext());
          } else if (id == 2) {
newLabel = "Gaming";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_performance);
newState = Tile.STATE_ACTIVE;
id +=1;
Spectrum.setProfile(3);
Prefs.saveInt("spectrum_profile", 3, getApplicationContext());
          } else {
newLabel = "Balance";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_balanced);
newState = Tile.STATE_ACTIVE;
id = 0;
Spectrum.setProfile(0);
Prefs.saveInt("spectrum_profile", 0, getApplicationContext());
          }
      }

      // Change the UI of the tile.
      tile.setLabel(newLabel);
      tile.setIcon(newIcon);
      tile.setState(newState);
      tile.updateTile();
  }
 
Example 18
Source File: NavigationService.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
private Notification getNotification() {
    String title = getString(R.string.msgNavigating, navWaypoint.name);
    String bearing = StringFormatter.angleH(navBearing);
    String distance = StringFormatter.distanceH(navDistance);

    StringBuilder sb = new StringBuilder(40);
    sb.append(getString(R.string.msgNavigationProgress, distance, bearing));
    String message = sb.toString();
    sb.append(". ");
    sb.append(getString(R.string.msgNavigationActions));
    sb.append(".");
    String bigText = sb.toString();

    Intent iLaunch = new Intent(Intent.ACTION_MAIN);
    iLaunch.addCategory(Intent.CATEGORY_LAUNCHER);
    iLaunch.setComponent(new ComponentName(getApplicationContext(), MainActivity.class));
    iLaunch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    PendingIntent piResult = PendingIntent.getActivity(this, 0, iLaunch, PendingIntent.FLAG_CANCEL_CURRENT);

    Intent iStop = new Intent(STOP_NAVIGATION, null, getApplicationContext(), NavigationService.class);
    PendingIntent piStop = PendingIntent.getService(this, 0, iStop, PendingIntent.FLAG_CANCEL_CURRENT);
    Icon stopIcon = Icon.createWithResource(this, R.drawable.ic_cancel_black);

    Intent iPause = new Intent(PAUSE_NAVIGATION, null, getApplicationContext(), NavigationService.class);
    PendingIntent piPause = PendingIntent.getService(this, 0, iPause, PendingIntent.FLAG_CANCEL_CURRENT);
    Icon pauseIcon = Icon.createWithResource(this, R.drawable.ic_pause);

    Notification.Action actionStop = new Notification.Action.Builder(stopIcon, getString(R.string.actionStop), piStop).build();
    Notification.Action actionPause = new Notification.Action.Builder(pauseIcon, getString(R.string.actionPause), piPause).build();

    Notification.Builder builder = new Notification.Builder(this);
    if (Build.VERSION.SDK_INT > 25)
        builder.setChannelId("ongoing");
    builder.setSmallIcon(R.mipmap.ic_stat_navigation);
    builder.setContentIntent(piResult);
    builder.setContentTitle(title);
    builder.setContentText(message);
    builder.setWhen(System.currentTimeMillis());
    builder.setStyle(new Notification.BigTextStyle().setBigContentTitle(title).bigText(bigText));
    builder.addAction(actionPause);
    builder.addAction(actionStop);
    builder.setGroup("maptrek");
    builder.setCategory(Notification.CATEGORY_SERVICE);
    builder.setPriority(Notification.PRIORITY_LOW);
    builder.setVisibility(Notification.VISIBILITY_PUBLIC);
    builder.setColor(getResources().getColor(R.color.colorAccent, getTheme()));
    builder.setOngoing(true);

    return builder.build();
}
 
Example 19
Source File: CameraRemoteServiceHandler.java    From Aerlink-for-Android with MIT License 4 votes vote down vote up
public void setCameraOpen(boolean cameraOpen) {
    this.cameraOpen = cameraOpen;

    Log.v(LOG_TAG, "Camera " + (cameraOpen ? "OPEN" : "CLOSED"));

    if (cameraRemoteCallback != null) {
        cameraRemoteCallback.onCameraChangedOpen(cameraOpen);
    }

    if (cameraOpen) {
        Bitmap background = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.bg_camera);

        Intent cameraIntent = new Intent(mContext, CameraRemoteActivity.class);
        cameraIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent cameraPendingIntent = PendingIntent.getActivity(mContext, 0, cameraIntent, 0);

        Icon cameraIcon = Icon.createWithResource(mContext, R.drawable.nic_camera);
        Notification.Action cameraAction = new Notification.Action.Builder(
                cameraIcon,
                "Camera",
                cameraPendingIntent
        ).build();

        Notification.WearableExtender wearableExtender = new Notification.WearableExtender()
                .setBackground(background)
                .setContentIcon(R.drawable.nic_camera)
                .setHintHideIcon(true)
                .setContentAction(0)
                .addAction(cameraAction);

        Notification.Builder builder = new Notification.Builder(mContext)
                .setSmallIcon(cameraIcon)
                .setContentTitle(mContext.getString(R.string.take_photo_title))
                .setContentText(mContext.getString(R.string.take_photo_text))
                .setPriority(Notification.PRIORITY_MAX)
                .extend(wearableExtender);

        mServiceUtils.notify(null, NOTIFICATION_CAMERA, builder.build());
    }
    else {
        mServiceUtils.cancelNotification(null, NOTIFICATION_CAMERA);
    }
}
 
Example 20
Source File: LocationService.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
private Notification getNotification() {
    int titleId = R.string.notifTracking;
    int ntfId = R.mipmap.ic_stat_tracking;
    if (mGpsStatus != LocationService.GPS_OK) {
        titleId = R.string.notifLocationWaiting;
        ntfId = R.mipmap.ic_stat_waiting;
    }
    if (mGpsStatus == LocationService.GPS_OFF) {
        ntfId = R.mipmap.ic_stat_off;
    }
    if (mErrorTime > 0) {
        titleId = R.string.notifTrackingFailure;
        ntfId = R.mipmap.ic_stat_failure;
    }

    String timeTracked = (String) DateUtils.getRelativeTimeSpanString(getApplicationContext(), mTrackStarted);
    String distanceTracked = StringFormatter.distanceH(mDistanceTracked);

    StringBuilder sb = new StringBuilder(40);
    sb.append(getString(R.string.msgTracked, distanceTracked, timeTracked));
    String message = sb.toString();
    sb.insert(0, ". ");
    sb.insert(0, getString(R.string.msgTracking));
    sb.append(". ");
    sb.append(getString(R.string.msgTrackingActions));
    sb.append(".");
    String bigText = sb.toString();

    Intent iLaunch = new Intent(Intent.ACTION_MAIN);
    iLaunch.addCategory(Intent.CATEGORY_LAUNCHER);
    iLaunch.setComponent(new ComponentName(getApplicationContext(), MainActivity.class));
    iLaunch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    PendingIntent piResult = PendingIntent.getActivity(this, 0, iLaunch, PendingIntent.FLAG_CANCEL_CURRENT);

    Intent iStop = new Intent(DISABLE_TRACK, null, getApplicationContext(), LocationService.class);
    iStop.putExtra("self", true);
    PendingIntent piStop = PendingIntent.getService(this, 0, iStop, PendingIntent.FLAG_CANCEL_CURRENT);
    Icon stopIcon = Icon.createWithResource(this, R.drawable.ic_stop);

    Intent iPause = new Intent(PAUSE_TRACK, null, getApplicationContext(), LocationService.class);
    PendingIntent piPause = PendingIntent.getService(this, 0, iPause, PendingIntent.FLAG_CANCEL_CURRENT);
    Icon pauseIcon = Icon.createWithResource(this, R.drawable.ic_pause);

    Notification.Action actionStop = new Notification.Action.Builder(stopIcon, getString(R.string.actionStop), piStop).build();
    Notification.Action actionPause = new Notification.Action.Builder(pauseIcon, getString(R.string.actionPause), piPause).build();

    Notification.Builder builder = new Notification.Builder(this);
    if (Build.VERSION.SDK_INT > 25)
        builder.setChannelId("ongoing");
    builder.setWhen(mErrorTime);
    builder.setSmallIcon(ntfId);
    builder.setContentIntent(piResult);
    builder.setContentTitle(getText(titleId));
    builder.setStyle(new Notification.BigTextStyle().setBigContentTitle(getText(titleId)).bigText(bigText));
    builder.addAction(actionPause);
    builder.addAction(actionStop);
    builder.setGroup("maptrek");
    builder.setCategory(Notification.CATEGORY_SERVICE);
    builder.setPriority(Notification.PRIORITY_LOW);
    builder.setVisibility(Notification.VISIBILITY_PUBLIC);
    builder.setColor(getResources().getColor(R.color.colorAccent, getTheme()));
    if (mErrorTime > 0 && DEBUG_ERRORS)
        builder.setContentText(mErrorMsg);
    else
        builder.setContentText(message);
    builder.setOngoing(true);
    return builder.build();
}