Пример #1
0
 /** Bitmap → Drawable */
 @SuppressWarnings("deprecation")
 public static Drawable bitmap2Drawable(Bitmap bm) {
   if (bm == null) {
     return null;
   }
   BitmapDrawable bd = new BitmapDrawable(bm);
   bd.setTargetDensity(bm.getDensity());
   return new BitmapDrawable(bm);
 }
  @SuppressWarnings("deprecation")
  public static Drawable createFromXmlInner(
      Context c, Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {
    Drawable drawable;

    final String name = parser.getName();

    // TODO: add the remaining drawables that are not covered.
    if (name.equals("selector")) {
      drawable = new StateListMaterialDrawable(c);
      // } else if (name.equals("animated-selector")) {
      // } else if (name.equals("level-list")) {
    } else if (name.equals("layer-list")) {
      drawable = new LayerMaterialDrawable(c);
      // } else if (name.equals("transition")) {
    } else if (name.equals("ripple")) {
      drawable = new RippleMaterialDrawable(c);
    } else if (name.equals("color")) {
      drawable = new ColorMaterialDrawable(c);
    } else if (name.equals("shape")) {
      drawable = new GradientMaterialDrawable(c);
      // } else if (name.equals("vector")) {
      // } else if (name.equals("animated-vector")) {
      // } else if (name.equals("scale")) {
      // } else if (name.equals("clip")) {
      // } else if (name.equals("rotate")) {
      // } else if (name.equals("animated-rotate")) {
    } else if (name.equals("animation-list")) {
      drawable = new AnimationMaterialDrawable(c);
    } else if (name.equals("inset")) {
      drawable = new InsetMaterialDrawable(c);
    } else if (name.equals("bitmap")) {
      drawable = new BitmapDrawable();
      if (r != null) {
        ((BitmapDrawable) drawable).setTargetDensity(r.getDisplayMetrics());
      }
      drawable = new TintDrawable(c, drawable);
    } else if (name.equals("nine-patch")) {
      drawable = new NinePatchDrawable(null, null);
      if (r != null) {
        ((NinePatchDrawable) drawable).setTargetDensity(r.getDisplayMetrics());
      }
      drawable = new TintDrawable(c, drawable);
    } else {
      drawable = null;
    }

    if (drawable != null) {
      drawable.inflate(r, parser, attrs);

      if (drawable instanceof GradientMaterialDrawable) {
        // Before Lollipop, GradientDrawable does not support a ColorStateList solid color.
        // In the case of a stateful solid color, enclose the drawable inside a TintDrawable.
        ColorStateList solidColor = ((GradientMaterialDrawable) drawable).getSolidColor();
        if (solidColor != null && solidColor.isStateful()) {
          drawable = new TintDrawable(c, drawable, solidColor);
        }
      }
    } else {
      drawable = Drawable.createFromXmlInner(r, parser, attrs);
    }

    return drawable;
  }
Пример #3
0
  /** Returns a bitmap suitable for the all apps view. */
  public static Bitmap createIconBitmap(Drawable icon, Context context) {
    synchronized (sCanvas) {
      final int iconBitmapSize = getIconBitmapSize();

      int width = iconBitmapSize;
      int height = iconBitmapSize;

      if (icon instanceof PaintDrawable) {
        PaintDrawable painter = (PaintDrawable) icon;
        painter.setIntrinsicWidth(width);
        painter.setIntrinsicHeight(height);
      } else if (icon instanceof BitmapDrawable) {
        // Ensure the bitmap has a density.
        BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
          bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
        }
      }
      int sourceWidth = icon.getIntrinsicWidth();
      int sourceHeight = icon.getIntrinsicHeight();
      if (sourceWidth > 0 && sourceHeight > 0) {
        // Scale the icon proportionally to the icon dimensions
        final float ratio = (float) sourceWidth / sourceHeight;
        if (sourceWidth > sourceHeight) {
          height = (int) (width / ratio);
        } else if (sourceHeight > sourceWidth) {
          width = (int) (height * ratio);
        }
      }

      // no intrinsic size --> use default size
      int textureWidth = iconBitmapSize;
      int textureHeight = iconBitmapSize;

      final Bitmap bitmap =
          Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
      final Canvas canvas = sCanvas;
      canvas.setBitmap(bitmap);

      final int left = (textureWidth - width) / 2;
      final int top = (textureHeight - height) / 2;

      @SuppressWarnings("all") // suppress dead code warning
      final boolean debug = false;
      if (debug) {
        // draw a big box for the icon for debugging
        canvas.drawColor(sColors[sColorIndex]);
        if (++sColorIndex >= sColors.length) sColorIndex = 0;
        Paint debugPaint = new Paint();
        debugPaint.setColor(0xffcccc00);
        canvas.drawRect(left, top, left + width, top + height, debugPaint);
      }

      sOldBounds.set(icon.getBounds());
      icon.setBounds(left, top, left + width, top + height);
      icon.draw(canvas);
      icon.setBounds(sOldBounds);
      canvas.setBitmap(null);

      return bitmap;
    }
  }
Пример #4
0
  @SuppressWarnings("unchecked")
  public TabbedMainView(Object params) {
    Context ctx = RhodesActivity.getContext();

    mBackgroundColorEnable = false;

    Vector<Object> tabs = null;
    boolean place_tabs_bottom = false;
    if (params instanceof Vector<?>) tabs = (Vector<Object>) params;
    else if (params instanceof Map<?, ?>) {
      Map<Object, Object> settings = (Map<Object, Object>) params;

      Object bkgObj = settings.get("background_color");
      if ((bkgObj != null) && (bkgObj instanceof String)) {
        int color = Integer.parseInt((String) bkgObj) | 0xFF000000;
        mBackgroundColor = color;
        mBackgroundColorEnable = true;
      }

      Object callbackObj = settings.get("on_change_tab_callback");
      if ((callbackObj != null) && (callbackObj instanceof String)) {
        mChangeTabCallback = new String(((String) callbackObj));
      }

      Object placeBottomObj = settings.get("place_tabs_bottom");
      if ((placeBottomObj != null) && (placeBottomObj instanceof String)) {
        place_tabs_bottom = ((String) placeBottomObj).equalsIgnoreCase("true");
      }

      Object tabsObj = settings.get("tabs");
      if (tabsObj != null && (tabsObj instanceof Vector<?>)) tabs = (Vector<Object>) tabsObj;
    }

    if (tabs == null) throw new IllegalArgumentException("No tabs specified");

    int size = tabs.size();

    host = new TabHost(ctx, null);

    tabData = new Vector<TabData>(size);
    tabIndex = 0;

    TabWidget tabWidget = new TabWidget(ctx);
    tabWidget.setId(android.R.id.tabs);

    FrameLayout frame = new FrameLayout(ctx);
    FrameLayout.LayoutParams lpf = null;
    TabHost.LayoutParams lpt = null;
    if (place_tabs_bottom) {
      frame.setId(android.R.id.tabcontent);
      lpf =
          new FrameLayout.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.TOP);
      host.addView(frame, lpf);

      lpt =
          new TabHost.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
      host.addView(tabWidget, lpt);
    } else {
      lpt =
          new TabHost.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.TOP);
      host.addView(tabWidget, lpt);

      frame = new FrameLayout(ctx);
      frame.setId(android.R.id.tabcontent);
      lpf =
          new FrameLayout.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.BOTTOM);
      host.addView(frame, lpf);
    }

    host.setup();

    TabHost.TabSpec spec;
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);

    int selected_color = 0;
    boolean selected_color_enable = false;

    for (int i = 0; i < size; ++i) {
      Object param = tabs.elementAt(i);
      if (!(param instanceof Map<?, ?>)) throw new IllegalArgumentException("Hash expected");

      Map<Object, Object> hash = (Map<Object, Object>) param;

      Object labelObj = hash.get("label");
      if (labelObj == null || !(labelObj instanceof String))
        throw new IllegalArgumentException("'label' should be String");

      Object actionObj = hash.get("action");

      boolean use_current_view_for_tab = false;
      Object use_current_view_for_tab_Obj = hash.get("use_current_view_for_tab");
      if (use_current_view_for_tab_Obj != null) {
        use_current_view_for_tab = ((String) use_current_view_for_tab_Obj).equalsIgnoreCase("true");
      }

      if (use_current_view_for_tab) {
        actionObj = new String("none");
      }
      if (actionObj == null || !(actionObj instanceof String))
        throw new IllegalArgumentException("'action' should be String");

      String label = (String) labelObj;
      String action = (String) actionObj;
      String icon = null;
      boolean reload = false;
      boolean disabled = false;
      int web_bkg_color = 0xFFFFFFFF;

      Object iconObj = hash.get("icon");
      if (iconObj != null && (iconObj instanceof String)) icon = "apps/" + (String) iconObj;

      Object reloadObj = hash.get("reload");
      if (reloadObj != null && (reloadObj instanceof String))
        reload = ((String) reloadObj).equalsIgnoreCase("true");

      Object selected_color_Obj = hash.get("selected_color");
      if ((selected_color_Obj != null) && (selected_color_Obj instanceof String)) {
        selected_color_enable = true;
        selected_color = Integer.parseInt((String) selected_color_Obj) | 0xFF000000;
      }

      Object disabled_Obj = hash.get("disabled");
      if (disabled_Obj != null && (disabled_Obj instanceof String))
        disabled = ((String) disabled_Obj).equalsIgnoreCase("true");

      Object web_bkg_color_Obj = hash.get("web_bkg_color");
      if (web_bkg_color_Obj != null && (web_bkg_color_Obj instanceof String)) {
        web_bkg_color = Integer.parseInt((String) web_bkg_color_Obj) | 0xFF000000;
      }

      spec = host.newTabSpec(Integer.toString(i));

      // Set label and icon
      BitmapDrawable drawable = null;

      if (icon != null) {
        String iconPath = RhoFileApi.normalizePath(icon);
        Bitmap bitmap = BitmapFactory.decodeStream(RhoFileApi.open(iconPath));
        if (disabled && (bitmap != null)) {
          // replace Bitmap to gray
          bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); // prepare mutable bitmap
          int x;
          int y;
          int bw = bitmap.getWidth();
          int bh = bitmap.getHeight();
          int nc = DISABLED_IMG_COLOR & 0xFFFFFF;
          int c;
          for (y = 0; y < bh; y++) {
            for (x = 0; x < bw; x++) {
              c = bitmap.getPixel(x, y);
              c = nc | (c & 0xFF000000);
              bitmap.setPixel(x, y, c);
            }
          }
        }

        if (bitmap != null)
          bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM); // Bitmap.DENSITY_NONE);
        drawable = new BitmapDrawable(bitmap);
        drawable.setTargetDensity(metrics);
      }
      if (drawable == null) spec.setIndicator(label);
      else spec.setIndicator(label, drawable);

      SimpleMainView view = null;
      if (use_current_view_for_tab) {
        RhodesService r = RhodesService.getInstance();
        MainView mainView = r.getMainView();
        action = mainView.currentLocation(-1);
        view = new SimpleMainView(mainView);
      } else {
        view = new SimpleMainView();
      }
      // Set view factory

      if (web_bkg_color_Obj != null) {
        if (!use_current_view_for_tab) {
          view.setWebBackgroundColor(web_bkg_color);
        }
        host.setBackgroundColor(web_bkg_color);
      }

      TabData data = new TabData();
      data.view = view;
      data.url = action;
      data.reload = reload;

      if (use_current_view_for_tab) {
        data.loaded = true;
        tabIndex = i;
      }

      data.selected_color = selected_color;
      data.selected_color_enabled = selected_color_enable;
      data.disabled = disabled;

      TabViewFactory factory = new TabViewFactory(data);
      spec.setContent(factory);

      tabData.addElement(data);
      host.addTab(spec);
    }

    tabWidget.measure(host.getWidth(), host.getHeight());
    int hh = tabWidget.getMeasuredHeight();
    // if (hh < 64) {
    //	hh = 64;
    // }
    if (place_tabs_bottom) {
      lpf.setMargins(0, 0, 0, hh);
    } else {
      lpf.setMargins(0, hh, 0, 0);
    }
    host.updateViewLayout(frame, lpf);
  }
Пример #5
0
 public static WidgetIcon createWidgetIcon(ShortcutInfo info, boolean ifShadow) {
   WidgetIcon widgetIcon = null;
   InputStream is = null;
   String imagePath =
       DefaultLayout.getDefaultVirtureImage(info.intent.getComponent().getPackageName());
   boolean scale = false;
   if (imagePath == null) {
     scale = true;
     imagePath =
         DefaultLayout.GetVirtureImageWithPkgClassName(
             info.intent.getComponent().getPackageName(),
             info.intent.getComponent().getClassName());
     if (imagePath == null) return null;
     if (DefaultLayout.useCustomVirtual) {
       try {
         is = new FileInputStream(imagePath);
       } catch (FileNotFoundException e) {
         e.printStackTrace();
       }
     } else {
       is = ThemeManager.getInstance().getInputStream(imagePath);
     }
     if (info.intent.getComponent().getPackageName().equals("coco.desktopsettings")) {
       InputStream dtis =
           ThemeManager.getInstance().getCurrThemeInput("theme/icon/80/desksettings.png");
       if (dtis != null) {
         scale = false;
         try {
           dtis.close();
         } catch (IOException e) {
         }
       }
     }
   } else {
     is = ThemeManager.getInstance().getInputStream(imagePath);
     scale = !(ThemeManager.getInstance().loadFromTheme(imagePath));
   }
   Bitmap origBmp = ThemeManager.getInstance().getBitmap(is);
   try {
     if (is != null) {
       is.close();
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   int iconSize = DefaultLayout.app_icon_size;
   if (DefaultLayout.thirdapk_icon_scaleFactor != 1.0f
       && !R3D.doNotNeedScale(
           info.intent.getComponent().getPackageName(), info.intent.getComponent().getClassName())
       && scale) {
     iconSize *= DefaultLayout.thirdapk_icon_scaleFactor;
   }
   if (origBmp == null) return null;
   BitmapDrawable drawable = new BitmapDrawable(origBmp);
   drawable.setTargetDensity(iLoongLauncher.getInstance().getResources().getDisplayMetrics());
   Bitmap bmp = Utilities.createIconBitmap(drawable, iLoongLauncher.getInstance(), iconSize);
   origBmp.recycle();
   // teapotXu add start:
   Bitmap bg = null;
   if (iconSize != DefaultLayout.app_icon_size) bg = Icon3D.getIconBg();
   widgetIcon = new WidgetIcon((String) info.title, bmp, (String) info.title, bg, ifShadow);
   // teapotXu add end
   widgetIcon.setItemInfo(info);
   bmp.recycle();
   bmp = null;
   /** ********************** added by diaosixu begin ************************** */
   AppReminder.Info aInfo = iLoongLauncher.getInstance().appReminder.new Info();
   boolean r =
       iLoongLauncher
           .getInstance()
           .appReminder
           .isRemindApp(info.intent.getComponent().getPackageName(), aInfo);
   if (r) {
     Gdx.app.log("diaosixu", "show red point");
     widgetIcon.setAppRemind(true);
     iLoongLauncher
         .getInstance()
         .appReminder
         .startReminding(aInfo.packageName, widgetIcon, aInfo.remindNo);
   }
   /** ********************** added by diaosixu end ************************** */
   return widgetIcon;
 }
Пример #6
0
  /**
   * Returns a bitmap suitable for the all apps view. The bitmap will be a power of two sized
   * ARGB_8888 bitmap that can be used as a gl texture.
   */
  private Bitmap createIconBitmap(Drawable icon) {
    int width = mIconWidth;
    int height = mIconHeight;

    if (icon instanceof PaintDrawable) {
      PaintDrawable painter = (PaintDrawable) icon;
      painter.setIntrinsicWidth(width);
      painter.setIntrinsicHeight(height);
    } else if (icon instanceof BitmapDrawable) {
      // Ensure the bitmap has a density.
      BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
      Bitmap bitmap = bitmapDrawable.getBitmap();
      if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
        bitmapDrawable.setTargetDensity(mDisplayMetrics);
      }
    }
    int sourceWidth = icon.getIntrinsicWidth();
    int sourceHeight = icon.getIntrinsicHeight();

    if (sourceWidth > 0 && sourceWidth > 0) {
      // There are intrinsic sizes.
      if (width < sourceWidth || height < sourceHeight) {
        // It's too big, scale it down.
        final float ratio = (float) sourceWidth / sourceHeight;
        if (sourceWidth > sourceHeight) {
          height = (int) (width / ratio);
        } else if (sourceHeight > sourceWidth) {
          width = (int) (height * ratio);
        }
      } else if (sourceWidth < width && sourceHeight < height) {
        // It's small, use the size they gave us.
        width = sourceWidth;
        height = sourceHeight;
      }
    }

    // no intrinsic size --> use default size
    int textureWidth = mIconTextureWidth;
    int textureHeight = mIconTextureHeight;

    final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
    final Canvas canvas = mCanvas;
    canvas.setBitmap(bitmap);

    final int left = (textureWidth - width) / 2;
    final int top = (textureHeight - height) / 2;

    if (false) {
      // draw a big box for the icon for debugging
      canvas.drawColor(sColors[mColorIndex]);
      if (++mColorIndex >= sColors.length) mColorIndex = 0;
      Paint debugPaint = new Paint();
      debugPaint.setColor(0xffcccc00);
      canvas.drawRect(left, top, left + width, top + height, debugPaint);
    }

    mOldBounds.set(icon.getBounds());
    icon.setBounds(left, top, left + width, top + height);
    icon.draw(canvas);
    icon.setBounds(mOldBounds);

    return bitmap;
  }