@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);
 }
 /** Updates a target in the GlowPadView */
 private void setTarget(
     int position, String uri, Drawable draw, String iconType, String iconSource, String pkgName) {
   TargetInfo item = mTargetStore.get(position);
   StateListDrawable state = (StateListDrawable) item.icon;
   LayerDrawable inActiveLayer = (LayerDrawable) state.getStateDrawable(0);
   LayerDrawable activeLayer = (LayerDrawable) state.getStateDrawable(1);
   inActiveLayer.setDrawableByLayerId(1, draw);
   boolean isSystem = iconType != null && iconType.equals(GlowPadView.ICON_RESOURCE);
   if (!isSystem) {
     final Drawable activeBack =
         mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_target_activated);
     activeLayer.setDrawableByLayerId(0, new InsetDrawable(activeBack, 0, 0, 0, 0));
     activeLayer.setDrawableByLayerId(1, draw);
   } else {
     InsetDrawable empty =
         new InsetDrawable(mResources.getDrawable(android.R.color.transparent), 0, 0, 0, 0);
     activeLayer.setDrawableByLayerId(1, empty);
     int activeId =
         mResources.getIdentifier(
             iconSource.replaceAll("_normal", "_activated"), "drawable", "android");
     Drawable back = null;
     if (activeId != 0) {
       back = mResources.getDrawable(activeId);
       activeLayer.setDrawableByLayerId(0, back);
     } else {
       final Drawable activeBack =
           mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_target_activated);
       activeLayer.setDrawableByLayerId(0, new InsetDrawable(activeBack, 0, 0, 0, 0));
     }
   }
   item.defaultIcon = mDialogIcon.getDrawable().getConstantState().newDrawable().mutate();
   item.uri = uri;
   item.iconType = iconType;
   item.iconSource = iconSource;
   item.pkgName = pkgName;
 }
 @Override
 public void onTrigger(View v, final int target) {
   mTargetIndex = target;
   if ((target != 0 && (mIsScreenLarge || !mIsLandscape))
       || (target != 2 && !mIsScreenLarge && mIsLandscape)) {
     AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
     builder.setTitle(R.string.lockscreen_target_edit_title);
     builder.setMessage(R.string.lockscreen_target_edit_msg);
     View view = View.inflate(mActivity, R.layout.lockscreen_shortcut_dialog, null);
     view.findViewById(R.id.icon)
         .setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                 if (!mDialogLabel.getText().equals(EMPTY_LABEL)) {
                   try {
                     mImageTmp.createNewFile();
                     mImageTmp.setWritable(true, false);
                     mIconPicker.pickIcon(getId(), mImageTmp);
                   } catch (IOException e) {
                   }
                 }
               }
             });
     view.findViewById(R.id.label)
         .setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                 mPicker.pickShortcut(
                     new String[] {EMPTY_LABEL},
                     new ShortcutIconResource[] {
                       ShortcutIconResource.fromContext(mActivity, android.R.drawable.ic_delete)
                     },
                     getId());
               }
             });
     mDialogIcon = ((ImageButton) view.findViewById(R.id.icon));
     mDialogLabel = ((Button) view.findViewById(R.id.label));
     TargetInfo item = mTargetStore.get(target);
     mDialogIcon.setImageDrawable(mTargetStore.get(target).defaultIcon.mutate());
     TargetInfo tmpIcon = new TargetInfo(null);
     tmpIcon.iconType = item.iconType;
     tmpIcon.iconSource = item.iconSource;
     tmpIcon.pkgName = item.pkgName;
     mDialogIcon.setTag(tmpIcon);
     if (mTargetStore.get(target).uri.equals(GlowPadView.EMPTY_TARGET)) {
       mDialogLabel.setText(EMPTY_LABEL);
     } else {
       mDialogLabel.setText(mPicker.getFriendlyNameForUri(mTargetStore.get(target).uri));
     }
     mDialogLabel.setTag(mTargetStore.get(target).uri);
     builder.setView(view);
     builder.setPositiveButton(
         R.string.ok,
         new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
             TargetInfo vObject = (TargetInfo) mDialogIcon.getTag();
             String type = null, source = null, pkgName = null;
             int targetInset = mTargetInset;
             if (vObject != null) {
               type = vObject.iconType;
               source = vObject.iconSource;
               pkgName = vObject.pkgName;
             }
             if (type != null && type.equals(GlowPadView.ICON_RESOURCE)) {
               targetInset = 0;
             }
             InsetDrawable pD =
                 new InsetDrawable(
                     mDialogIcon.getDrawable(),
                     targetInset,
                     targetInset,
                     targetInset,
                     targetInset);
             setTarget(mTargetIndex, mDialogLabel.getTag().toString(), pD, type, source, pkgName);
           }
         });
     builder.setNegativeButton(R.string.cancel, null);
     builder.setCancelable(false);
     AlertDialog dialog = builder.create();
     dialog.show();
     ((TextView) dialog.findViewById(android.R.id.message))
         .setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small);
   }
 }