List of usage examples for android.widget ImageView getDrawable
public Drawable getDrawable()
From source file:com.kf5.sdk.system.photoview.PhotoViewAttacher.java
@Override public void onGlobalLayout() { ImageView imageView = getImageView(); if (null != imageView) { if (mZoomEnabled) { final int top = imageView.getTop(); final int right = imageView.getRight(); final int bottom = imageView.getBottom(); final int left = imageView.getLeft(); /**// w ww . j a v a 2s . c o m * We need to check whether the ImageView's bounds have changed. * This would be easier if we targeted IChatModel 11+ as we could just use * View.OnLayoutChangeListener. Instead we have to replicate the * work, keeping track of the ImageView's bounds and then checking * if the values change. */ if (top != mIvTop || bottom != mIvBottom || left != mIvLeft || right != mIvRight) { // Update our base matrix, as the bounds have changed updateBaseMatrix(imageView.getDrawable()); // Update values as something has changed mIvTop = top; mIvRight = right; mIvBottom = bottom; mIvLeft = left; } } else { updateBaseMatrix(imageView.getDrawable()); } } }
From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java
@Override public void onGlobalLayout() { ImageView imageView = getImageView(); if (null != imageView) { if (mZoomEnabled) { final int top = imageView.getTop(); final int right = imageView.getRight(); final int bottom = imageView.getBottom(); final int left = imageView.getLeft(); /**//from w ww .ja v a 2 s . c o m * We need to check whether the ImageView'account bounds have changed. * This would be easier if we targeted API 11+ as we could just use * View.OnLayoutChangeListener. Instead we have to replicate the * work, keeping track of the ImageView'account bounds and then checking * if the values change. */ if (top != mIvTop || bottom != mIvBottom || left != mIvLeft || right != mIvRight) { // Update our base matrix, as the bounds have changed updateBaseMatrix(imageView.getDrawable()); // Update values as something has changed mIvTop = top; mIvRight = right; mIvBottom = bottom; mIvLeft = left; } } else { updateBaseMatrix(imageView.getDrawable()); } } }
From source file:cn.golden.pinchzoomcanvasview.PinchZoomCanvasViewAttacher.java
@Override public void onGlobalLayout() { ImageView imageView = getImageView(); if (null != imageView) { if (mZoomEnabled) { final int top = imageView.getTop(); final int right = imageView.getRight(); final int bottom = imageView.getBottom(); final int left = imageView.getLeft(); /**//from w ww .j a v a 2 s .c o m * We need to check whether the ImageView's bounds have changed. * This would be easier if we targeted API 11+ as we could just use * View.OnLayoutChangeListener. Instead we have to replicate the * work, keeping track of the ImageView's bounds and then checking * if the values change. */ if (top != mIvTop || bottom != mIvBottom || left != mIvLeft || right != mIvRight) { // Update our base matrix, as the bounds have changed updateBaseMatrix(imageView.getDrawable()); // Update values as something has changed mIvTop = top; mIvRight = right; mIvBottom = bottom; mIvLeft = left; } } else { if (!isInEdit) { updateBaseMatrix(imageView.getDrawable()); } } } }
From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java
@Override public void onGlobalLayout() { ImageView imageView = getImageView(); if (null != imageView) { if (mZoomEnabled) { final int top = imageView.getTop(); final int right = imageView.getRight(); final int bottom = imageView.getBottom(); final int left = imageView.getLeft(); /**/* w w w.jav a2s . c o m*/ * We need to check whether the ImageView's bounds have changed. * This would be easier if we targeted API 11+ as we could just use * View.OnLayoutChangeListener. Instead we have to replicate the * work, keeping track of the ImageView's bounds and then checking * if the values change. */ if (top != mIvTop || bottom != mIvBottom || left != mIvLeft || right != mIvRight) { // Update our base matrix, as the bounds have changed updateBaseMatrix(imageView.getDrawable()); // Update values as something has changed mIvTop = top; mIvRight = right; mIvBottom = bottom; mIvLeft = left; } } else { updateBaseMatrix(imageView.getDrawable()); } } }
From source file:com.first.akashshrivastava.showernow.ShowerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_shower_activity); /*Launching BootReceiver to test Intent playIntent = new Intent(getApplicationContext(), BootReceiver.class); startActivity(playIntent);//from w w w . j av a2 s.c o m */ //Mobile ads initialization....The long number is the AdID, can be found on AdMob - ca-app-pub-8782530512283806/2988799979 MobileAds.initialize(getApplicationContext(), "ca-app-pub-8782530512283806/2988799979"); AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); //Facebook SDK initialization... FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); shareDialog = new ShareDialog(this); mDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAuth = FirebaseAuth.getInstance(); final ImageView genderImage = (ImageView) findViewById(R.id.imageGender); guyText = (TextView) findViewById(R.id.guyText); topText = (TextView) findViewById(R.id.textView2); SharedPreferences prefs = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); extraAge = prefs.getInt("age", 0); extraFluffiness = prefs.getString("fluffiness", ""); extraGender = prefs.getString("gender", ""); extraOldTime = prefs.getLong("time", 0); extraSteps = prefs.getFloat("stepsBoot", 0); switch (extraGender) { case "male": genderImage.setImageResource(R.drawable.male_white_outline); break; case "female": genderImage.setImageResource(R.drawable.female_white_outline); break; case "other": genderImage.setImageResource(R.drawable.other_white_outline); break; } genderImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { //set alarm //Swith ccase switch (event.getAction()) { case MotionEvent.ACTION_UP: // PRESSED ..PRESSED if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.female_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.female_white_outline); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.male_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.male_white_outline); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.other_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.other_white_outline); } //Resets the wave after shower..this is not getting called for some reason.... waveProgressbar.setCurrent(0, ""); guyText.setText("0 %"); waveProgressbar.setVisibility(View.INVISIBLE); topText.setText("You have showered! \n When the wave hits 100% its time for your next shower "); if (fluffiness != null && gotSteps) { Calendar cal = Calendar.getInstance(); Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class); activate.putExtra("age", age); activate.putExtra("fluffiness", fluffiness); activate.putExtra("gender", gender); activate.putExtra("steps", steps); activate.putExtra("time", System.currentTimeMillis()); AlarmManager alarms; PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate, FLAG_CANCEL_CURRENT); alarms = (AlarmManager) getSystemService(ALARM_SERVICE); alarms.cancel(alarmIntent); alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + 5000, 1000 * 60, alarmIntent);//sets the alarm mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Steps").setValue(steps);//sets old steps oldSteps = steps; mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Time").setValue(System.currentTimeMillis()); oldTime = System.currentTimeMillis(); newUser = false; SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("age", age); editor.putString("fluffiness", fluffiness); editor.putString("gender", gender); editor.putFloat("steps", steps); editor.putLong("time", System.currentTimeMillis()); editor.putFloat("stepsBoot", 0); editor.putBoolean("bootStart", true); editor.apply(); } else if (!gotSteps) { Toast.makeText(getApplicationContext(), "Waiting for steps", Toast.LENGTH_SHORT).show(); } return true; // if you want to handle the touch event case MotionEvent.ACTION_DOWN: // RELEASED..RELEASED.. if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.female_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.female_white_outline_pressed); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.male_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.male_white_outline_pressed); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.other_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.other_white_outline_pressed); } return true; // if you want to handle the touch event } //Switch case end bracket return false; } }); createWave(); setMenuColor(); setupStepcount(); setWaveHeight(); FloatingActionButton editDetails = (FloatingActionButton) findViewById(R.id.menu_item4); //edit user information. Goes to main activity editDetails.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { /* Fragment fragment = new Fragment(); FragmentTransaction transaction = manager.beginTransaction(); transaction.add(ShowerActivity.java); transaction.addToBackStack(ShowerActivity.java); transaction.commit(); */ //Fragment B at pos 2 should open when edit details is pressed.. Intent i = new Intent(ShowerActivity.this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } }); FloatingActionButton fabmenuDeleteAccount = (FloatingActionButton) findViewById(R.id.delete_Account); fabmenuDeleteAccount.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog(); } }); FloatingActionButton fabMenuItem1 = (FloatingActionButton) findViewById(R.id.menu_item); fabMenuItem1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*ComponentName receiver = new ComponentName(ShowerActivity.this, AlarmReceiver.class); // alarms.cancel(alarmIntent);?? PackageManager pm = ShowerActivity.this.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); stopService(new Intent(StepCountService.STEP_COUNT_SERVICE));*/ //mFirebaseAuth.getCurrentUser().getUid() =null; SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("age", 0); editor.putString("fluffiness", ""); editor.putString("gender", ""); editor.putFloat("steps", 0); editor.putLong("time", 0); editor.putFloat("stepsBoot", 0); editor.putBoolean("bootStart", false); editor.apply(); Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate, FLAG_CANCEL_CURRENT); AlarmManager alarms = (AlarmManager) getSystemService(ALARM_SERVICE); alarms.cancel(alarmIntent); stopService(new Intent(ShowerActivity.this, StepCountService.class)); mFirebaseAuth.getInstance().signOut(); Intent i = new Intent(ShowerActivity.this, LoginActivity.class); startActivity(i); } }); final FloatingActionButton shareButton = (FloatingActionButton) findViewById(R.id.shareButton); shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); String shareBody = "Check out this showering app at: https://play.google.com/store/apps/details?id=com.first.akashshrivastava.showernow \n"; String shareSubString = "An app that tells you when you should shower and apparently keeps you clean"; shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubString); shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(shareIntent, " Share using the following")); } }); mDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snap) { try { if ((!(mFirebaseAuth.getCurrentUser().getUid().isEmpty())) && snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("female")) { genderImage.setImageResource(R.drawable.female_white_outline); } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("male")) { genderImage.setImageResource(R.drawable.male_white_outline); } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("other")) { genderImage.setImageResource(R.drawable.other_white_outline); } } catch (Exception e) { e.printStackTrace(); } age = Integer.parseInt(snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Age").getValue().toString());//gotta get int fluffiness = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString(); gender = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString(); if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time").exists()) { oldTime = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time") .getValue(Long.class); oldSteps = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Steps") .getValue(float.class); } else { newUser = true; } } @Override public void onCancelled(DatabaseError databaseError) { } }); }
From source file:com.android.launcher2.AsyncTaskCallback.java
private boolean beginDraggingWidget(View v) { mDraggingWidget = true;// w w w . jav a 2s . co m // Get the widget preview as the drag representation ImageView image = (ImageView) v.findViewById(R.id.widget_preview); PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag(); // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and // we abort the drag. if (image.getDrawable() == null) { mDraggingWidget = false; return false; } // Compose the drag image Bitmap preview; Bitmap outline; float scale = 1f; if (createItemInfo instanceof PendingAddWidgetInfo) { // This can happen in some weird cases involving multi-touch. We can't start dragging // the widget if this is null, so we break out. if (mCreateWidgetInfo == null) { return false; } PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo; createItemInfo = createWidgetInfo; int spanX = createItemInfo.spanX; int spanY = createItemInfo.spanY; int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true); FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable(); float minScale = 1.25f; int maxWidth, maxHeight; maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]); maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]); preview = getWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage, createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight); // Determine the image view drawable scale relative to the preview float[] mv = new float[9]; Matrix m = new Matrix(); m.setRectToRect(new RectF(0f, 0f, (float) preview.getWidth(), (float) preview.getHeight()), new RectF(0f, 0f, (float) previewDrawable.getIntrinsicWidth(), (float) previewDrawable.getIntrinsicHeight()), Matrix.ScaleToFit.START); m.getValues(mv); scale = (float) mv[0]; } else { PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag(); Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo); preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); mCanvas.setBitmap(preview); mCanvas.save(); renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); mCanvas.restore(); mCanvas.setBitmap(null); createItemInfo.spanX = createItemInfo.spanY = 1; } // Don't clip alpha values for the drag outline if we're using the default widget preview boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0)); // Save the preview for the outline generation, then dim the preview outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false); // Start the drag mLauncher.lockScreenOrientation(); mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha); mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY, null, scale); outline.recycle(); preview.recycle(); return true; }
From source file:com.mooc.viewpage_photoview_circleindicator.photoview.PhotoViewAttacher.java
@Override public void onGlobalLayout() { ImageView imageView = getImageView(); if (null != imageView) { if (mZoomEnabled) { final int top = imageView.getTop(); final int right = imageView.getRight(); final int bottom = imageView.getBottom(); final int left = imageView.getLeft(); /**/* w w w . j a va2s . com*/ * We need to check whether the ImageView's bounds have changed. * This would be easier if we targeted API 11+ as we could just use * View.OnLayoutChangeListener. Instead we have to replicate the * work, keeping track of the ImageView's bounds and then checking * if the values change. * ? */ if (top != mIvTop || bottom != mIvBottom || left != mIvLeft || right != mIvRight) { // Update our base matrix, as the bounds have changed updateBaseMatrix(imageView.getDrawable(), false); // Update values as something has changed mIvTop = top; mIvRight = right; mIvBottom = bottom; mIvLeft = left; } } else { updateBaseMatrix(imageView.getDrawable(), false); } } }
From source file:com.c4mprod.utils.ImageDownloader.java
/** * Download the specified image from the Internet and binds it to the provided ImageView. The * binding is immediate if the image is found in the cache and will be done asynchronously * otherwise. A null bitmap will be associated to the ImageView if an error occurs. * //from w w w.j av a 2 s .com * @param url * @param imageView * @param subfolder * the subfolder in sdcard cache * */ public void download(String url, ImageView imageView, String subfolder) { if (subfolder != null) { mSubfolder = "/" + subfolder; } else { mSubfolder = ""; } mfolder = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + imageView.getContext().getPackageName() + "/files/images" + mSubfolder; if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true; try { (new File(mfolder)).mkdirs(); (new File(mfolder + "/.nomedia")).createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else { // Something else is wrong. It may be one of many other states, but // all we need // to know is we can neither read nor write mExternalStorageAvailable = mExternalStorageWriteable = false; } resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { forceDownload(url, imageView); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); imageView.setBackgroundDrawable(null); if (listener != null) { listener.onImageDownloaded(imageView, url, mfolder + "/" + URLEncoder.encode(url), imageView.getDrawable().getIntrinsicWidth(), imageView.getDrawable().getIntrinsicWidth()); } } }
From source file:com.silentcircle.contacts.ContactPhotoManager.java
/** * Checks if the photo is present in cache. If so, sets the photo on the view. * * @return false if the photo needs to be (re)loaded from the provider. *///www. jav a2 s. c o m private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) { BitmapHolder holder = mBitmapHolderCache.get(request.getKey()); if (holder == null) { // The bitmap has not been loaded ==> show default avatar request.applyDefaultImage(view); return false; } if (holder.bytes == null) { request.applyDefaultImage(view); return holder.fresh; } Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get(); if (cachedBitmap == null) { if (holder.bytes.length < 8 * 1024) { // Small thumbnails are usually quick to inflate. Let's do that on the UI thread inflateBitmap(holder, request.getRequestedExtent()); cachedBitmap = holder.bitmap; if (cachedBitmap == null) return false; } else { // This is bigger data. Let's send that back to the Loader so that we can // inflate this in the background request.applyDefaultImage(view); return false; } } final Drawable previousDrawable = view.getDrawable(); if (fadeIn && previousDrawable != null) { final Drawable[] layers = new Drawable[2]; // Prevent cascade of TransitionDrawables. if (previousDrawable instanceof TransitionDrawable) { final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable; layers[0] = previousTransitionDrawable .getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1); } else { layers[0] = previousDrawable; } layers[1] = new BitmapDrawable(mContext.getResources(), cachedBitmap); TransitionDrawable drawable = new TransitionDrawable(layers); view.setImageDrawable(drawable); drawable.startTransition(FADE_TRANSITION_DURATION); } else { view.setImageBitmap(cachedBitmap); } // Put the bitmap in the LRU cache. But only do this for images that are small enough // (we require that at least six of those can be cached at the same time) int byteCount = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) ? cachedBitmap.getRowBytes() * cachedBitmap.getHeight() : cachedBitmap.getByteCount(); if (byteCount < mBitmapCache.maxSize() / 6) { mBitmapCache.put(request.getKey(), cachedBitmap); } holder.bitmap = null; // Soften the reference return holder.fresh; }
From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java
private boolean beginDraggingWidget(View v) { mDraggingWidget = true;// w w w .j a v a 2 s . c o m // Get the widget preview as the drag representation ImageView image = (ImageView) v.findViewById(R.id.widget_preview); PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag(); // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and // we abort the drag. if (image.getDrawable() == null) { mDraggingWidget = false; return false; } // Compose the drag image Bitmap preview; Bitmap outline; float scale = 1f; Point previewPadding = null; if (createItemInfo instanceof PendingAddWidgetInfo) { // This can happen in some weird cases involving multi-touch. We can't start dragging // the widget if this is null, so we break out. if (mCreateWidgetInfo == null) { return false; } PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo; createItemInfo = createWidgetInfo; int spanX = createItemInfo.spanX; int spanY = createItemInfo.spanY; int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true); FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable(); float minScale = 1.25f; int maxWidth, maxHeight; maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]); maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]); int[] previewSizeBeforeScale = new int[1]; preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage, createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight, null, previewSizeBeforeScale); // Compare the size of the drag preview to the preview in the AppsCustomize tray int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0], getWidgetPreviewLoader().maxWidthForWidgetPreview(spanX)); scale = previewWidthInAppsCustomize / (float) preview.getWidth(); // The bitmap in the AppsCustomize tray is always the the same size, so there // might be extra pixels around the preview itself - this accounts for that if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) { int padding = (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2; previewPadding = new Point(padding, 0); } } else { PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag(); Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo); preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); mCanvas.setBitmap(preview); mCanvas.save(); WidgetPreviewLoader.renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); mCanvas.restore(); mCanvas.setBitmap(null); createItemInfo.spanX = createItemInfo.spanY = 1; } // Don't clip alpha values for the drag outline if we're using the default widget preview boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0)); // Save the preview for the outline generation, then dim the preview outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false); // Start the drag mLauncher.lockScreenOrientation(); mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha); mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY, previewPadding, scale); outline.recycle(); preview.recycle(); return true; }