List of usage examples for android.graphics.drawable Drawable equals
public boolean equals(Object obj)
From source file:Main.java
/** * Check if two Drawables are equal. A regular check for a Drawable equals * just checks for the instance reference, while this check is doing a * deeper equals when dealing with {@link DrawableContainer} instances. In * these cases, the method will run equals on each of the child drawables in * the container (order is importance as well). * // w w w. j a v a 2s . c om * @param d1 * @param d2 * @return <code>true</code> if the drawables are equal, <code>false</code> * otherwise. */ public static boolean isEquals(Drawable d1, Drawable d2) { if (d1 == d2) { return true; } if (d1 == null || d2 == null) { return false; } if (d1 instanceof DrawableContainer && d2 instanceof DrawableContainer) { // Try to match the content of those containers DrawableContainerState containerState1 = (DrawableContainerState) ((DrawableContainer) d1) .getConstantState(); DrawableContainerState containerState2 = (DrawableContainerState) ((DrawableContainer) d2) .getConstantState(); return Arrays.equals(containerState1.getChildren(), containerState2.getChildren()); } return d1.equals(d2); }
From source file:com.tr4android.support.extension.widget.CollapsingDrawableHelper.java
/** * Set the drawable to display// w ww . j a va 2 s . c om * * @param drawable */ void setDrawable(Drawable drawable) { if (drawable == null || !drawable.equals(mDrawable)) { mDrawable = drawable; recalculate(); } }
From source file:com.android.settings.users.RestrictedProfileSettings.java
@Override public Dialog onCreateDialog(int dialogId) { if (dialogId == DIALOG_ID_EDIT_USER_INFO) { if (mEditUserInfoDialog != null) { return mEditUserInfoDialog; }//w w w . j a va2 s .c o m LayoutInflater inflater = getActivity().getLayoutInflater(); View content = inflater.inflate(R.layout.edit_user_info_dialog_content, null); UserInfo info = mUserManager.getUserInfo(mUser.getIdentifier()); final EditText userNameView = (EditText) content.findViewById(R.id.user_name); userNameView.setText(info.name); final ImageView userPhotoView = (ImageView) content.findViewById(R.id.user_photo); Drawable drawable = null; if (mSavedPhoto != null) { drawable = CircleFramedDrawable.getInstance(getActivity(), mSavedPhoto); } else { drawable = mUserIconView.getDrawable(); if (drawable == null) { drawable = getCircularUserIcon(); } } userPhotoView.setImageDrawable(drawable); mEditUserPhotoController = new EditUserPhotoController(this, userPhotoView, mSavedPhoto, drawable, mWaitingForActivityResult); mEditUserInfoDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.profile_info_settings_title) .setIconAttribute(R.drawable.ic_settings_multiuser).setView(content).setCancelable(true) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { // Update the name if changed. CharSequence userName = userNameView.getText(); if (!TextUtils.isEmpty(userName)) { CharSequence oldUserName = mUserNameView.getText(); if (oldUserName == null || !userName.toString().equals(oldUserName.toString())) { ((TextView) mHeaderView.findViewById(android.R.id.title)) .setText(userName.toString()); mUserManager.setUserName(mUser.getIdentifier(), userName.toString()); } } // Update the photo if changed. Drawable drawable = mEditUserPhotoController.getNewUserPhotoDrawable(); Bitmap bitmap = mEditUserPhotoController.getNewUserPhotoBitmap(); if (drawable != null && bitmap != null && !drawable.equals(mUserIconView.getDrawable())) { mUserIconView.setImageDrawable(drawable); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mUserManager.setUserIcon(mUser.getIdentifier(), mEditUserPhotoController.getNewUserPhotoBitmap()); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); } removeDialog(DIALOG_ID_EDIT_USER_INFO); } clearEditUserInfoDialog(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clearEditUserInfoDialog(); } }).create(); // Make sure the IME is up. mEditUserInfoDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); return mEditUserInfoDialog; } return null; }