private Drawable getNavbarIconImage(String uri) {
   if (uri == null) uri = AwesomeConstant.ACTION_NULL.value();
   if (uri.startsWith("**")) {
     return AwesomeConstants.getActionIcon(mContext, uri);
   } else {
     try {
       return mPackMan.getActivityIcon(Intent.parseUri(uri, 0));
     } catch (NameNotFoundException e) {
       e.printStackTrace();
     } catch (URISyntaxException e) {
       e.printStackTrace();
     }
   }
   return mResources.getDrawable(R.drawable.ic_sysbar_null);
 }
  private Drawable getCustomDrawable() {
    String mCustomURI =
        Settings.System.getString(
            mContext.getContentResolver(), Settings.System.QUICK_SETTINGS_CUSTOM);
    Drawable customIcon = null;
    try {
      customIcon = CustomIconUtil.getInstance(mContext).loadFromFile();
      if (customIcon == null) {
        customIcon = mPm.getActivityIcon(Intent.parseUri(mCustomURI, 0));
      }
    } catch (Exception e) {
      e.printStackTrace();
      return getIconDrawable("");
    }

    return customIcon;
  }
  private Drawable setIcon(String uri, String action) {
    if (uri != null && uri.length() > 0) {
      File f = new File(Uri.parse(uri).getPath());
      if (f.exists()) return resize(new BitmapDrawable(mResources, f.getAbsolutePath()));
    }
    if (uri != null && !uri.equals("") && uri.startsWith("file")) {
      // it's an icon the user chose from the gallery here
      File icon = new File(Uri.parse(uri).getPath());
      if (icon.exists()) return resize(new BitmapDrawable(mResources, icon.getAbsolutePath()));

    } else if (uri != null && !uri.equals("")) {
      // here they chose another app icon
      try {
        return resize(mPackMan.getActivityIcon(Intent.parseUri(uri, 0)));
      } catch (NameNotFoundException e) {
        e.printStackTrace();
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }
      // ok use default icons here
    }
    return resize(getNavbarIconImage(action));
  }
Exemplo n.º 4
0
  /**
   * Pre-load an icon into the persistent cache.
   *
   * <p>Queries for a component that does not exist in the package manager will be answered by the
   * persistent cache.
   *
   * @param componentName the icon should be returned for this component
   * @param icon the icon to be persisted
   * @param dpi the native density of the icon
   */
  public void preloadIcon(
      ComponentName componentName,
      Bitmap icon,
      int dpi,
      String label,
      long userSerial,
      InvariantDeviceProfile idp) {
    // TODO rescale to the correct native DPI
    try {
      PackageManager packageManager = mContext.getPackageManager();
      packageManager.getActivityIcon(componentName);
      // component is present on the system already, do nothing
      return;
    } catch (PackageManager.NameNotFoundException e) {
      // pass
    }

    ContentValues values =
        newContentValues(
            Bitmap.createScaledBitmap(icon, idp.iconBitmapSize, idp.iconBitmapSize, true),
            label,
            Color.TRANSPARENT);
    values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString());
    values.put(IconDB.COLUMN_USER, userSerial);
    mIconDb
        .getWritableDatabase()
        .insertWithOnConflict(IconDB.TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
  }
Exemplo n.º 5
0
  /**
   * Pre-load an icon into the persistent cache.
   *
   * <p>Queries for a component that does not exist in the package manager will be answered by the
   * persistent cache.
   *
   * @param context application context
   * @param componentName the icon should be returned for this component
   * @param icon the icon to be persisted
   * @param dpi the native density of the icon
   */
  public static void preloadIcon(
      Context context, ComponentName componentName, Bitmap icon, int dpi) {
    // TODO rescale to the correct native DPI
    try {
      PackageManager packageManager = context.getPackageManager();
      packageManager.getActivityIcon(componentName);
      // component is present on the system already, do nothing
      return;
    } catch (NameNotFoundException e) {
      // pass
    }

    final String key = componentName.flattenToString();
    FileOutputStream resourceFile = null;
    try {
      resourceFile =
          context.openFileOutput(getResourceFilename(componentName), Context.MODE_PRIVATE);
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      if (icon.compress(Bitmap.CompressFormat.PNG, 75, os)) {
        byte[] buffer = os.toByteArray();
        resourceFile.write(buffer, 0, buffer.length);
      } else {
        Log.w(TAG, "failed to encode cache for " + key);
        return;
      }
    } catch (FileNotFoundException e) {
      Log.w(TAG, "failed to pre-load cache for " + key, e);
    } catch (IOException e) {
      Log.w(TAG, "failed to pre-load cache for " + key, e);
    } finally {
      if (resourceFile != null) {
        try {
          resourceFile.close();
        } catch (IOException e) {
          Log.d(TAG, "failed to save restored icon for: " + key, e);
        }
      }
    }
  }
Exemplo n.º 6
0
  public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Background is always provided by the container.
    setBackgroundResource(0);

    TypedArray a =
        context.obtainStyledAttributes(
            attrs, R.styleable.SherlockActionBar, R.attr.actionBarStyleABS, 0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode =
        a.getInt(
            R.styleable.SherlockActionBar_navigationModeABS, ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.SherlockActionBar_titleABS);
    mSubtitle = a.getText(R.styleable.SherlockActionBar_subtitleABS);

    mLogo = a.getDrawable(R.styleable.SherlockActionBar_logoABS);
    if (mLogo == null) {
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        if (context instanceof Activity) {
          // Even though native methods existed in API 9 and 10 they don't work
          // so just parse the manifest to look for the logo pre-Honeycomb
          final int resId = ResourcesCompat.loadLogoFromManifest((Activity) context);
          if (resId != 0) {
            mLogo = context.getResources().getDrawable(resId);
          }
        }
      } else {
        if (context instanceof Activity) {
          try {
            mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
          } catch (NameNotFoundException e) {
            Log.e(TAG, "Activity component name not found!", e);
          }
        }
        if (mLogo == null) {
          mLogo = appInfo.loadLogo(pm);
        }
      }
    }

    mIcon = a.getDrawable(R.styleable.SherlockActionBar_iconABS);
    if (mIcon == null) {
      if (context instanceof Activity) {
        try {
          mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
        } catch (NameNotFoundException e) {
          Log.e(TAG, "Activity component name not found!", e);
        }
      }
      if (mIcon == null) {
        mIcon = appInfo.loadIcon(pm);
      }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId =
        a.getResourceId(R.styleable.SherlockActionBar_homeLayoutABS, R.layout.abs__action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(
        getResources().getText(R.string.abs__action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_titleTextStyleABS, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_subtitleTextStyleABS, 0);
    mProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_progressBarStyleABS, 0);
    mIndeterminateProgressStyle =
        a.getResourceId(R.styleable.SherlockActionBar_indeterminateProgressStyleABS, 0);

    mProgressBarPadding =
        a.getDimensionPixelOffset(R.styleable.SherlockActionBar_progressBarPaddingABS, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_itemPaddingABS, 0);

    setDisplayOptions(a.getInt(R.styleable.SherlockActionBar_displayOptionsABS, DISPLAY_DEFAULT));

    final int customNavId =
        a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayoutABS, 0);
    if (customNavId != 0) {
      mCustomNavView = inflater.inflate(customNavId, this, false);
      mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
      setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionBar_heightABS, 0);

    a.recycle();

    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);
  }