Esempio n. 1
1
 private void initializeView(String input) {
   if (input == null) {
     input = GlowPadView.DEFAULT_TARGETS;
   }
   mTargetStore.clear();
   final int maxTargets =
       mIsScreenLarge ? GlowPadView.MAX_TABLET_TARGETS : GlowPadView.MAX_PHONE_TARGETS;
   final PackageManager packMan = mActivity.getPackageManager();
   final Drawable activeBack =
       mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_target_activated);
   final String[] targetStore = input.split("\\|");
   // Shift by 2 targets for phones in landscape
   if (mIsLandscape && !mIsScreenLarge) {
     mTargetStore.add(new TargetInfo(null));
     mTargetStore.add(new TargetInfo(null));
   }
   // Add the unlock icon
   Drawable unlockFront =
       mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_unlock_normal);
   Drawable unlockBack =
       mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_unlock_activated);
   mTargetStore.add(new TargetInfo(getLayeredDrawable(unlockBack, unlockFront, 0, true)));
   for (int cc = 0; cc < 8 - mTargetOffset - 1; cc++) {
     String uri = GlowPadView.EMPTY_TARGET;
     Drawable front = null;
     Drawable back = activeBack;
     boolean frontBlank = false;
     String iconType = null;
     String iconSource = null;
     int tmpInset = mTargetInset;
     if (cc < targetStore.length && cc < maxTargets) {
       uri = targetStore[cc];
       if (!uri.equals(GlowPadView.EMPTY_TARGET)) {
         try {
           Intent in = Intent.parseUri(uri, 0);
           if (in.hasExtra(GlowPadView.ICON_FILE)) {
             String rSource = in.getStringExtra(GlowPadView.ICON_FILE);
             File fPath = new File(rSource);
             if (fPath != null) {
               if (fPath.exists()) {
                 front = new BitmapDrawable(getResources(), BitmapFactory.decodeFile(rSource));
               }
             }
           } else if (in.hasExtra(GlowPadView.ICON_RESOURCE)) {
             String rSource = in.getStringExtra(GlowPadView.ICON_RESOURCE);
             String rPackage = in.getStringExtra(GlowPadView.ICON_PACKAGE);
             if (rSource != null) {
               if (rPackage != null) {
                 try {
                   Context rContext = mActivity.createPackageContext(rPackage, 0);
                   int id = rContext.getResources().getIdentifier(rSource, "drawable", rPackage);
                   front = rContext.getResources().getDrawable(id);
                   id =
                       rContext
                           .getResources()
                           .getIdentifier(
                               rSource.replaceAll("_normal", "_activated"), "drawable", rPackage);
                   back = rContext.getResources().getDrawable(id);
                   tmpInset = 0;
                   frontBlank = true;
                 } catch (NameNotFoundException e) {
                   e.printStackTrace();
                 } catch (NotFoundException e) {
                   e.printStackTrace();
                 }
               } else {
                 front =
                     mResources.getDrawable(
                         mResources.getIdentifier(rSource, "drawable", "android"));
                 back =
                     mResources.getDrawable(
                         mResources.getIdentifier(
                             rSource.replaceAll("_normal", "_activated"), "drawable", "android"));
                 tmpInset = 0;
                 frontBlank = true;
               }
             }
           }
           if (front == null) {
             ActivityInfo aInfo = in.resolveActivityInfo(packMan, PackageManager.GET_ACTIVITIES);
             if (aInfo != null) {
               front = aInfo.loadIcon(packMan);
             } else {
               front = mResources.getDrawable(android.R.drawable.sym_def_app_icon).mutate();
             }
           }
         } catch (Exception e) {
         }
       }
     } else if (cc >= maxTargets) {
       mTargetStore.add(new TargetInfo(null));
       continue;
     }
     if (back == null || front == null) {
       Drawable emptyIcon = mResources.getDrawable(R.drawable.ic_empty).mutate();
       front = emptyIcon;
     }
     mTargetStore.add(
         new TargetInfo(
             uri,
             getLayeredDrawable(back, front, tmpInset, frontBlank),
             iconType,
             iconSource,
             front.getConstantState().newDrawable().mutate()));
   }
   ArrayList<TargetDrawable> tDraw = new ArrayList<TargetDrawable>();
   for (TargetInfo i : mTargetStore) {
     if (i != null) {
       tDraw.add(new TargetDrawable(mResources, i.icon));
     } else {
       tDraw.add(new TargetDrawable(mResources, null));
     }
   }
   mWaveView.setTargetResources(tDraw);
 }
Esempio n. 2
0
 @Override
 public void iconPicked(int requestCode, int resultCode, Intent in) {
   Drawable ic = null;
   String iconType = null;
   String pkgName = null;
   String iconSource = null;
   if (requestCode == IconPicker.REQUEST_PICK_GALLERY) {
     if (resultCode == Activity.RESULT_OK) {
       File mImage =
           new File(
               mActivity.getFilesDir() + "/lockscreen_" + System.currentTimeMillis() + ".png");
       if (mImageTmp.exists()) {
         mImageTmp.renameTo(mImage);
       }
       mImage.setReadOnly();
       iconType = GlowPadView.ICON_FILE;
       iconSource = mImage.toString();
       ic = new BitmapDrawable(getResources(), BitmapFactory.decodeFile(mImage.toString()));
     } else {
       if (mImageTmp.exists()) {
         mImageTmp.delete();
       }
       return;
     }
   } else if (requestCode == IconPicker.REQUEST_PICK_SYSTEM) {
     String resourceName = in.getStringExtra(IconPicker.RESOURCE_NAME);
     ic =
         mResources
             .getDrawable(mResources.getIdentifier(resourceName, "drawable", "android"))
             .mutate();
     iconType = GlowPadView.ICON_RESOURCE;
     iconSource = resourceName;
   } else if (requestCode == IconPicker.REQUEST_PICK_ICON_PACK
       && resultCode == Activity.RESULT_OK) {
     String resourceName = in.getStringExtra(IconPicker.RESOURCE_NAME);
     pkgName = in.getStringExtra(IconPicker.PACKAGE_NAME);
     try {
       Context rContext = mActivity.createPackageContext(pkgName, 0);
       int id = rContext.getResources().getIdentifier(resourceName, "drawable", pkgName);
       ic = rContext.getResources().getDrawable(id);
     } catch (NameNotFoundException e) {
       e.printStackTrace();
     }
     iconType = GlowPadView.ICON_RESOURCE;
     iconSource = resourceName;
   } else {
     return;
   }
   TargetInfo tmpIcon = new TargetInfo(null);
   tmpIcon.iconType = iconType;
   tmpIcon.iconSource = iconSource;
   tmpIcon.pkgName = pkgName;
   mDialogIcon.setTag(tmpIcon);
   mDialogIcon.setImageDrawable(ic);
 }
  private static int loadUiOptionsFromManifest(Activity activity) {
    int uiOptions = 0;
    try {
      final String thisPackage = activity.getClass().getName();
      if (DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);

      final String packageName = activity.getApplicationInfo().packageName;
      final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
      final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");

      int eventType = xml.getEventType();
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
          String name = xml.getName();

          if ("application".equals(name)) {
            // Check if the <application> has the attribute
            if (DEBUG) Log.d(TAG, "Got <application>");

            for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
              if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

              if ("uiOptions".equals(xml.getAttributeName(i))) {
                uiOptions = xml.getAttributeIntValue(i, 0);
                break; // out of for loop
              }
            }
          } else if ("activity".equals(name)) {
            // Check if the <activity> is us and has the attribute
            if (DEBUG) Log.d(TAG, "Got <activity>");
            Integer activityUiOptions = null;
            String activityPackage = null;
            boolean isOurActivity = false;

            for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
              if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

              // We need both uiOptions and name attributes
              String attrName = xml.getAttributeName(i);
              if ("uiOptions".equals(attrName)) {
                activityUiOptions = xml.getAttributeIntValue(i, 0);
              } else if ("name".equals(attrName)) {
                activityPackage = cleanActivityName(packageName, xml.getAttributeValue(i));
                if (!thisPackage.equals(activityPackage)) {
                  break; // out of for loop
                }
                isOurActivity = true;
              }

              // Make sure we have both attributes before processing
              if ((activityUiOptions != null) && (activityPackage != null)) {
                // Our activity, uiOptions specified, override with our value
                uiOptions = activityUiOptions.intValue();
              }
            }
            if (isOurActivity) {
              // If we matched our activity but it had no logo don't
              // do any more processing of the manifest
              break;
            }
          }
        }
        eventType = xml.nextToken();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions));
    return uiOptions;
  }