Ejemplo n.º 1
0
  /**
   * Searches the given package for a resource to use to replace the Drawable on the target with the
   * given resource id
   *
   * @param component of the .apk that contains the resource
   * @param name of the metadata in the .apk
   * @param existingResId the resource id of the target to search for
   * @return true if found in the given package and replaced at least one target Drawables
   */
  public boolean replaceTargetDrawablesIfPresent(
      ComponentName component, String name, int existingResId) {
    if (existingResId == 0) return false;

    boolean replaced = false;
    if (component != null) {
      try {
        PackageManager packageManager = getContext().getPackageManager();
        // Look for the search icon specified in the activity meta-data
        Bundle metaData =
            packageManager.getActivityInfo(component, PackageManager.GET_META_DATA).metaData;
        if (metaData != null) {
          int iconResId = metaData.getInt(name);
          if (iconResId != 0) {
            Resources res = packageManager.getResourcesForActivity(component);
            replaced = replaceTargetDrawables(res, existingResId, iconResId);
          }
        }
      } catch (NameNotFoundException e) {
        Log.w(
            TAG, "Failed to swap drawable; " + component.flattenToShortString() + " not found", e);
      } catch (Resources.NotFoundException nfe) {
        Log.w(TAG, "Failed to swap drawable from " + component.flattenToShortString(), nfe);
      }
    }
    if (!replaced) {
      // Restore the original drawable
      replaceTargetDrawables(getContext().getResources(), existingResId, existingResId);
    }
    return replaced;
  }
  /**
   * Switch to parent fragment and store the grand parent's info
   *
   * @param className name of the activity wrapper for the parent fragment.
   */
  private void switchToParent(String className) {
    final ComponentName cn = new ComponentName(this, className);
    try {
      final PackageManager pm = getPackageManager();
      final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA);

      if (parentInfo != null && parentInfo.metaData != null) {
        String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
        CharSequence fragmentTitle = parentInfo.loadLabel(pm);
        Header parentHeader = new Header();
        parentHeader.fragment = fragmentClass;
        parentHeader.title = fragmentTitle;
        mCurrentHeader = parentHeader;

        switchToHeaderLocal(parentHeader);
        highlightHeader(mTopLevelHeaderId);

        mParentHeader = new Header();
        mParentHeader.fragment = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
        mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE);
      }
    } catch (NameNotFoundException nnfe) {
      Log.w(LOG_TAG, "Could not find parent activity : " + className);
    }
  }
Ejemplo n.º 3
0
  /**
   * Shows at most one dialog using the intent extras and the restored state of the activity.
   *
   * @param savedInstanceState restored state
   */
  private void showDialogIfNeeded(Bundle savedInstanceState) {
    // Check if the intent has the ICON_COLOR_CHANGED action; if so, show a new dialog.
    if (getIntent().getBooleanExtra(IconColorReceiver.EXTRA_ICON_COLOR_CHANGED, false)) {
      // Clear the flag in the intent so that the dialog doesn't show up anymore
      getIntent().putExtra(IconColorReceiver.EXTRA_ICON_COLOR_CHANGED, false);

      // Display a dialog showcasing the new icon!
      ImageView imageView = new ImageView(this);
      PackageManager manager = getPackageManager();
      try {
        ComponentInfo info = manager.getActivityInfo(getComponentName(), 0);
        imageView.setImageDrawable(
            ContextCompat.getDrawable(getBaseContext(), info.getIconResource()));
      } catch (PackageManager.NameNotFoundException ignored) {
      }

      new QKDialog()
          .setContext(this)
          .setTitle(getString(R.string.icon_ready))
          .setMessage(R.string.icon_ready_message)
          .setCustomView(imageView)
          .setPositiveButton(R.string.okay, null)
          .show();

      // Only show the MMS setup fragment if it hasn't already been dismissed
    } else if (!wasMmsSetupFragmentDismissed(savedInstanceState)) {
      beginMmsSetup();
    }
  }
 public void replaceDrawable(
     ImageView v, ComponentName component, String name, boolean isService) {
   if (component != null) {
     try {
       PackageManager packageManager = mContext.getPackageManager();
       // Look for the search icon specified in the activity meta-data
       Bundle metaData =
           isService
               ? packageManager.getServiceInfo(component, PackageManager.GET_META_DATA).metaData
               : packageManager.getActivityInfo(component, PackageManager.GET_META_DATA).metaData;
       if (metaData != null) {
         int iconResId = metaData.getInt(name);
         if (iconResId != 0) {
           Resources res = packageManager.getResourcesForApplication(component.getPackageName());
           v.setImageDrawable(res.getDrawable(iconResId));
           return;
         }
       }
     } catch (PackageManager.NameNotFoundException e) {
       Log.w(
           TAG, "Failed to swap drawable; " + component.flattenToShortString() + " not found", e);
     } catch (Resources.NotFoundException nfe) {
       Log.w(TAG, "Failed to swap drawable from " + component.flattenToShortString(), nfe);
     }
   }
   v.setImageDrawable(null);
 }
Ejemplo n.º 5
0
  public void testOrientation() throws NameNotFoundException {
    /// Method 1: Assert it is currently in portrait mode.
    solo.clickOnText(solo.getString(R.string.main_menu_continue));
    solo.clickOnText(backgroundName);
    solo.waitForActivity(ProgramMenuActivity.class.getSimpleName());
    assertEquals(
        "ProgramMenuActivity not in Portrait mode!",
        Configuration.ORIENTATION_PORTRAIT,
        solo.getCurrentActivity().getResources().getConfiguration().orientation);

    /// Method 2: Retrieve info about Activity as collected from AndroidManifest.xml
    // https://developer.android.com/reference/android/content/pm/ActivityInfo.html
    PackageManager packageManager = solo.getCurrentActivity().getPackageManager();
    ActivityInfo activityInfo =
        packageManager.getActivityInfo(
            solo.getCurrentActivity().getComponentName(), PackageManager.GET_META_DATA);

    // Note that the activity is _indeed_ rotated on your device/emulator!
    // Robotium can _force_ the activity to be in landscapeMode mode (and so could we,
    // programmatically)
    solo.setActivityOrientation(Solo.LANDSCAPE);
    solo.sleep(200);

    assertEquals(
        ProgramMenuActivity.class.getSimpleName()
            + " not set to be in portrait mode in AndroidManifest.xml!",
        ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
        activityInfo.screenOrientation);
  }
 public boolean isActivityEnabledForProfile(ComponentName component, UserHandleCompat user) {
   try {
     ActivityInfo info = mPm.getActivityInfo(component, 0);
     return info != null && info.isEnabled();
   } catch (NameNotFoundException e) {
     return false;
   }
 }
Ejemplo n.º 7
0
  /**
   * Returns the meta data of the specified activity
   *
   * @param context The activity context
   * @return The meta data bundle
   */
  public static Bundle getMetaData(final Activity context) {
    final PackageManager pm = context.getPackageManager();

    try {
      final ComponentName componentName = ((Activity) context).getComponentName();
      return pm.getActivityInfo(componentName, PackageManager.GET_META_DATA).metaData;
    } catch (NameNotFoundException e) {
      return null;
    }
  }
Ejemplo n.º 8
0
 /**
  * Ensures that we have a valid, non-null name. If the provided name is null, we will return the
  * application name instead.
  */
 private static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) {
   if (name == null) {
     try {
       PackageManager pm = context.getPackageManager();
       ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
       name = info.loadLabel(pm).toString();
     } catch (PackageManager.NameNotFoundException nnfe) {
       return "";
     }
   }
   return name;
 }
Ejemplo n.º 9
0
    private boolean addAppShortcut(
        SQLiteDatabase db,
        ContentValues values,
        TypedArray a,
        PackageManager packageManager,
        Intent intent) {

      ActivityInfo info;
      String packageName = a.getString(R.styleable.Favorite_packageName);
      String className = a.getString(R.styleable.Favorite_className);
      try {
        ComponentName cn;
        try {
          cn = new ComponentName(packageName, className);
          info = packageManager.getActivityInfo(cn, 0);
        } catch (PackageManager.NameNotFoundException nnfe) {
          String[] packages =
              packageManager.currentToCanonicalPackageNames(new String[] {packageName});
          cn = new ComponentName(packages[0], className);
          info = packageManager.getActivityInfo(cn, 0);
        }

        intent.setComponent(cn);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        values.put(Favorites.INTENT, intent.toUri(0));
        values.put(Favorites.TITLE, info.loadLabel(packageManager).toString());
        values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPLICATION);
        values.put(Favorites.SPANX, 1);
        values.put(Favorites.SPANY, 1);
        db.insert(TABLE_FAVORITES, null, values);
      } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "Unable to add favorite: " + packageName + "/" + className, e);
        return false;
      }
      return true;
    }
 /**
  * Gets the activity or application icon for an activity.
  *
  * @param component Name of an activity.
  * @return A drawable, or {@code null} if neither the acitivy or the application have an icon set.
  */
 private Drawable getActivityIcon(ComponentName component) {
   PackageManager pm = mContext.getPackageManager();
   final ActivityInfo activityInfo;
   try {
     activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
   } catch (NameNotFoundException ex) {
     Log.w(LOG_TAG, ex.toString());
     return null;
   }
   int iconId = activityInfo.getIconResource();
   if (iconId == 0) return null;
   String pkg = component.getPackageName();
   Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
   if (drawable == null) {
     Log.w(
         LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
     return null;
   }
   return drawable;
 }
Ejemplo n.º 11
0
  private void loadAllFolders() {
    mFolders = new SparseArray<FolderModel>();
    String[] folders = fileList();
    for (String folderFileName : folders) {

      FileInputStream in = null;
      try {
        if (folderFileName.startsWith("folder")) {
          FolderModel folder = new FolderModel();
          folder.id = Integer.parseInt(folderFileName.substring("folder".length()));

          in = openFileInput(folderFileName);
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          byte[] b = new byte[1024];
          int bytesRead;
          while ((bytesRead = in.read(b)) != -1) {
            bos.write(b, 0, bytesRead);
          }
          byte[] bytes = bos.toByteArray();
          String appNames = new String(bytes);

          int i = 0;
          for (String appName : appNames.split("\n")) {
            if (i < 2) {
              // width and height
              try {
                if (i == 0) {
                  folder.width = Integer.parseInt(appName);
                } else if (i == 1) {
                  folder.height = Integer.parseInt(appName);
                }
              } catch (NumberFormatException ex) {
                String msg =
                    "Please uninstall Floating Folders and reinstall it. The folder format has changed.";
                Log.d("FloatingFolder", msg);
                Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
                break;
              }
              i++;
            } else {
              if (appName.length() > 0) {
                ComponentName name = ComponentName.unflattenFromString(appName);
                try {
                  ActivityInfo app = mPackageManager.getActivityInfo(name, 0);
                  folder.apps.add(app);
                  mFolders.put(folder.id, folder);
                } catch (NameNotFoundException e) {
                  e.printStackTrace();
                }
              }
            }
          }
        }
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
  }
  private void setDrawables() {
    String target3 =
        Settings.System.getString(
            mContext.getContentResolver(), Settings.System.SYSTEMUI_NAVRING_3);
    if (target3 == null || target3.equals("")) {
      Settings.System.putString(
          mContext.getContentResolver(), Settings.System.SYSTEMUI_NAVRING_3, "assist");
    }

    // Custom Targets
    ArrayList<TargetDrawable> storedDraw = new ArrayList<TargetDrawable>();

    int startPosOffset;
    int endPosOffset;

    if (screenLayout() == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
      startPosOffset = 1;
      endPosOffset = 8;
    } else if (screenLayout() == Configuration.SCREENLAYOUT_SIZE_LARGE) {
      if (mNavRingAmount == 4 || mNavRingAmount == 2) {
        startPosOffset = 0;
        endPosOffset = 1;
      } else {
        startPosOffset = 0;
        endPosOffset = 3;
      }
    } else {
      if (isScreenPortrait() == true) {
        if (mNavRingAmount == 4 || mNavRingAmount == 2) {
          startPosOffset = 0;
          endPosOffset = 1;
        } else {
          startPosOffset = 0;
          endPosOffset = 3;
        }
      } else {
        if (mNavRingAmount == 4 || mNavRingAmount == 2) {
          startPosOffset = 2;
          endPosOffset = 0;
        } else {
          startPosOffset = 2;
          endPosOffset = 1;
        }
      }
    }

    List<String> targetActivities =
        Arrays.asList(
            Settings.System.getString(mContext.getContentResolver(), targetList.get(0)),
            Settings.System.getString(mContext.getContentResolver(), targetList.get(1)),
            Settings.System.getString(mContext.getContentResolver(), targetList.get(2)),
            Settings.System.getString(mContext.getContentResolver(), targetList.get(3)),
            Settings.System.getString(mContext.getContentResolver(), targetList.get(4)));

    // Place Holder Targets
    TargetDrawable cDrawable =
        new TargetDrawable(
            mResources,
            mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_camera));
    cDrawable.setEnabled(false);

    // Add Initial Place Holder Targets
    for (int i = 0; i < startPosOffset; i++) {
      storedDraw.add(cDrawable);
    }

    // Add User Targets
    for (int i = 0; i < targetActivities.size(); i++)
      if (targetActivities.get(i) == null
          || targetActivities.get(i).equals("")
          || targetActivities.get(i).equals("none")) {
        storedDraw.add(cDrawable);
      } else if (targetActivities.get(i).equals("screenshot")) {
        storedDraw.add(
            new TargetDrawable(
                mResources, mResources.getDrawable(R.drawable.ic_navbar_screenshot)));
      } else if (targetActivities.get(i).equals("ime_switcher")) {
        storedDraw.add(
            new TargetDrawable(
                mResources, mResources.getDrawable(R.drawable.ic_sysbar_ime_switcher)));
      } else if (targetActivities.get(i).equals("ring_vib")) {
        storedDraw.add(
            new TargetDrawable(mResources, mResources.getDrawable(R.drawable.ic_navbar_vib)));
      } else if (targetActivities.get(i).equals("ring_silent")) {
        storedDraw.add(
            new TargetDrawable(mResources, mResources.getDrawable(R.drawable.ic_navbar_silent)));
      } else if (targetActivities.get(i).equals("ring_vib_silent")) {
        storedDraw.add(
            new TargetDrawable(
                mResources, mResources.getDrawable(R.drawable.ic_navbar_ring_vib_silent)));
      } else if (targetActivities.get(i).equals("killcurrent")) {
        storedDraw.add(
            new TargetDrawable(mResources, mResources.getDrawable(R.drawable.ic_navbar_killtask)));
      } else if (targetActivities.get(i).equals("power")) {
        storedDraw.add(
            new TargetDrawable(mResources, mResources.getDrawable(R.drawable.ic_navbar_power)));
      } else if (targetActivities.get(i).equals("screenoff")) {
        storedDraw.add(
            new TargetDrawable(mResources, mResources.getDrawable(R.drawable.ic_navbar_power)));
      } else if (targetActivities.get(i).equals("assist")) {
        storedDraw.add(
            new TargetDrawable(
                mResources, com.android.internal.R.drawable.ic_action_assist_generic));
      } else if (targetActivities.get(i).startsWith("app:")) {
        try {
          ActivityInfo activityInfo =
              mPackageManager.getActivityInfo(
                  ComponentName.unflattenFromString(targetActivities.get(i).substring(4)),
                  PackageManager.GET_RECEIVERS);
          Drawable activityIcon = activityInfo.loadIcon(mPackageManager);

          storedDraw.add(new TargetDrawable(mResources, activityIcon));
        } catch (Exception e) { // /
        }
      }

    // Add End Place Holder Targets
    for (int i = 0; i < endPosOffset; i++) {
      storedDraw.add(cDrawable);
    }

    mGlowPadView.setTargetResources(storedDraw);
  }
Ejemplo n.º 13
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {

    // GET SETTINGS FROM SHARED PREFERENCES
    SharedPreferences settingsF = getSharedPreferences(FUZZY_STUFF, 0);
    int backgroundColorF =
        settingsF.getInt("BackgroundColorF", this.getResources().getColor(R.color.palesky));
    int textColorF = settingsF.getInt("TextColorF", this.getResources().getColor(R.color.night));
    String packageName = settingsF.getString("PackageName", "com.android.alarmclock");
    String className = settingsF.getString("ClassName", "com.android.alarmclock.AlarmClock");

    // CALCULATE ALL THE TIME DEPENDENT VARIABLES

    // reset the time dependent addition
    long alarmAddMillis = 0;

    // get time instance and values
    Calendar rightNow = Calendar.getInstance();
    int thisMin = rightNow.get(Calendar.MINUTE);
    int thisHour = rightNow.get(Calendar.HOUR);

    // set correct hour values
    nextHour = thisHour + 1;
    if (thisHour == 0) {
      thisHour = 12;
    }
    if (nextHour == 13) {
      nextHour = 1;
    }

    // set text values based on minutes
    if (thisMin >= 0 && thisMin <= 7) {
      wordA = "its";
      wordB = "about";
      wordA_B = "its_about";
      clockH = thisHour;
      nextAlarmMin = 8;
      alarmAddMillis = 0;
    }
    if (thisMin >= 8 && thisMin <= 22) {
      wordA = "quarter";
      wordB = "past";
      wordA_B = "quarter_past";
      clockH = thisHour;
      nextAlarmMin = 23;
      alarmAddMillis = 0;
    }
    if (thisMin >= 23 && thisMin <= 37) {
      wordA = "half";
      wordB = "past";
      wordA_B = "half_past";
      clockH = thisHour;
      nextAlarmMin = 38;
      alarmAddMillis = 0;
    }
    if (thisMin >= 38 && thisMin <= 52) {
      wordA = "quarter";
      wordB = "to";
      wordA_B = "quarter_to";
      clockH = nextHour;
      nextAlarmMin = 53;
      alarmAddMillis = 0;
    }
    if (thisMin >= 53 && thisMin <= 59) {
      wordA = "its";
      wordB = "about";
      wordA_B = "its_about";
      clockH = nextHour;
      nextAlarmMin = 8;
      alarmAddMillis = 3600000;
    }

    // CANCEL ANY UNSENT ALARM
    if (alarmManager != null) {
      alarmManager.cancel(pendingIntent);
    }

    // SET UP THE NEXT ALARM

    // set the time
    Calendar nextAlarm = Calendar.getInstance();
    // add one hour of millis if its for the next hour
    nextAlarm.setTimeInMillis(System.currentTimeMillis() + alarmAddMillis);
    // set the correct minute
    nextAlarm.set(Calendar.MINUTE, nextAlarmMin);
    nextAlarm.set(Calendar.SECOND, 15);
    nextAlarm.set(Calendar.MILLISECOND, 0);

    // request the alarm
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent usIntent = new Intent(this, AlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(this, 0, usIntent, 0);
    // use onExact for API19+
    int currentApiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentApiVersion <= 18) {
      alarmManager.set(AlarmManager.RTC, nextAlarm.getTimeInMillis(), pendingIntent);
    } else {
      alarmManager.setExact(AlarmManager.RTC, nextAlarm.getTimeInMillis(), pendingIntent);
    }

    // SET UP THE IMAGES

    // get the resource id ints for images to send by remoteviews
    int timePhraseA =
        this.getResources().getIdentifier("phr_" + wordA, "drawable", this.getPackageName());
    int timePhraseB =
        this.getResources().getIdentifier("phr_" + wordB, "drawable", this.getPackageName());
    int timePhraseA_B =
        this.getResources().getIdentifier("phr_" + wordA_B, "drawable", this.getPackageName());
    int hourWordImageCrop =
        this.getResources().getIdentifier("num_" + clockH, "drawable", this.getPackageName());
    int hourWordImageWide =
        this.getResources()
            .getIdentifier("num_" + clockH + "_w", "drawable", this.getPackageName());

    // SET THE BITMAP COLOR AND OTHER VALUES
    fillPaintF = new Paint(Paint.FILTER_BITMAP_FLAG);
    fillPaintF.setColor(textColorF);
    fillPaintF.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;

    // ASSEMBLE THE PENDING INTENTS

    // create the open configuration pending intent
    Intent openAWC = new Intent(this, AppWidgetConfigure.class);
    openAWC.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent openAwcPi =
        PendingIntent.getActivity(this, 0, openAWC, PendingIntent.FLAG_UPDATE_CURRENT);

    // create the open alarms pending intent - done here because it couldnt be saved in prefs
    // set up open Alarms Intent
    PendingIntent alarmPI = null;
    PackageManager packageManager = this.getPackageManager();
    Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
    // get the activity info and attach to the intent
    try {
      ComponentName cn = new ComponentName(packageName, className);
      packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
      alarmClockIntent.setComponent(cn);
    } catch (PackageManager.NameNotFoundException e) {
      stopSelf();
    }
    // finalize the pending intent
    alarmPI = PendingIntent.getActivity(this, 0, alarmClockIntent, 0);

    // create the refresh widget pending intent
    Intent startUpdateF = new Intent(this, UpdateService.class);
    startUpdateF.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pendingStartUpdateF =
        PendingIntent.getService(this, 0, startUpdateF, PendingIntent.FLAG_UPDATE_CURRENT);

    // **** BACKGROUND IMAGE PREPARATION ****

    // draw an empty image
    bitmapBackgroundF = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    // paint in the color
    Canvas canvasBackgroundF = new Canvas(bitmapBackgroundF);
    fillPaintBackgroundF = new Paint();
    fillPaintBackgroundF.setColor(backgroundColorF);
    canvasBackgroundF.drawPaint(fillPaintBackgroundF);

    // SEND ALL THE STUFF TO THE PLACED WIDGETS

    // get appwidgetmanager instance for all widgets
    AppWidgetManager localAppWidgetManager = AppWidgetManager.getInstance(this);

    // update all 4x1 widget instances
    ComponentName thisWidget4x1 = new ComponentName(getBaseContext(), WidgetProvider4x1.class);
    int[] allWidgetIds4x1 = localAppWidgetManager.getAppWidgetIds(thisWidget4x1);
    if (allWidgetIds4x1 != null) {

      // join the images together into one strip
      Bitmap bitmap4x1partA = BitmapFactory.decodeResource(getResources(), timePhraseA, options);
      Bitmap bitmap4x1partB = BitmapFactory.decodeResource(getResources(), timePhraseB, options);
      Bitmap bitmap4x1partC =
          BitmapFactory.decodeResource(getResources(), hourWordImageCrop, options);

      Bitmap bitmap4x1strip =
          Bitmap.createBitmap(
              bitmap4x1partA.getWidth() + bitmap4x1partB.getWidth() + bitmap4x1partC.getWidth(),
              bitmap4x1partA.getHeight(),
              Bitmap.Config.ARGB_8888);
      Canvas canvas4x1strip = new Canvas(bitmap4x1strip);
      canvas4x1strip.drawBitmap(bitmap4x1partA, 0, 0, null);
      canvas4x1strip.drawBitmap(bitmap4x1partB, bitmap4x1partA.getWidth(), 0, null);
      canvas4x1strip.drawBitmap(
          bitmap4x1partC, bitmap4x1partA.getWidth() + bitmap4x1partB.getWidth(), 0, null);

      // generate adjusted images if color theme isnt default

      // strip
      Bitmap bitmap4x1strip2 = bitmap4x1strip.copy(Bitmap.Config.ARGB_8888, true);
      Canvas canvas4x1strip2 = new Canvas(bitmap4x1strip2);
      canvas4x1strip2.drawPaint(fillPaintF);

      for (int widgetId : allWidgetIds4x1) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout_4x1);
        remoteViews.setImageViewBitmap(R.id.imageviewBG, bitmapBackgroundF);
        remoteViews.setImageViewBitmap(R.id.imageviewABC, bitmap4x1strip2);
        remoteViews.setOnClickPendingIntent(R.id.topclickLeft, alarmPI);
        remoteViews.setOnClickPendingIntent(R.id.topclickRight, openAwcPi);
        localAppWidgetManager.updateAppWidget(widgetId, remoteViews);
      }
      bitmap4x1strip2 = null;
      canvas4x1strip2 = null;
      bitmap4x1strip = null;
      canvas4x1strip = null;
    }

    // update all 3x2 widget instances
    ComponentName thisWidget3x2 = new ComponentName(getBaseContext(), WidgetProvider3x2.class);
    int[] allWidgetIds3x2 = localAppWidgetManager.getAppWidgetIds(thisWidget3x2);
    if (allWidgetIds3x2 != null) {
      // generate adjusted images if color theme isnt default
      // time phrase
      if (bitmapTimePhraseA_B == null) {
        bitmapTimePhraseA_B1 = BitmapFactory.decodeResource(getResources(), timePhraseA_B, options);
        bitmapTimePhraseA_B = bitmapTimePhraseA_B1.copy(Bitmap.Config.ARGB_8888, true);
        canvasPhrase = new Canvas(bitmapTimePhraseA_B);
        canvasPhrase.drawPaint(fillPaintF);
      }
      // hour word
      if (bitmapHourWordImage == null) {
        bitmapHourWordImage1 =
            BitmapFactory.decodeResource(getResources(), hourWordImageWide, options);
        bitmapHourWordImage = bitmapHourWordImage1.copy(Bitmap.Config.ARGB_8888, true);
        canvasHour = new Canvas(bitmapHourWordImage);
        canvasHour.drawPaint(fillPaintF);
      }
      for (int widgetId : allWidgetIds3x2) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout_3x2);
        remoteViews.setImageViewBitmap(R.id.imageviewA_B, bitmapTimePhraseA_B);
        remoteViews.setImageViewBitmap(R.id.imageviewC, bitmapHourWordImage);
        remoteViews.setImageViewBitmap(R.id.imageviewBG, bitmapBackgroundF);
        remoteViews.setOnClickPendingIntent(R.id.topclickLeft, alarmPI);
        remoteViews.setOnClickPendingIntent(R.id.topclickRight, openAwcPi);
        localAppWidgetManager.updateAppWidget(widgetId, remoteViews);
      }
    }

    // CLEAR ALL THE BITMAPS
    bitmapTimePhraseA_B = null;
    bitmapTimePhraseA_B1 = null;
    bitmapHourWordImageCrop = null;
    bitmapHourWordImageCrop1 = null;
    bitmapHourWordImage = null;
    bitmapHourWordImage1 = null;
    canvasPhrase = null;
    canvasHour = null;
    bitmapBackgroundF = null;

    stopSelf();
    return super.onStartCommand(intent, flags, startId);
  }