// Path: matisse/src/main/java/com/zhihu/matisse/internal/entity/Album.java
// public class Album implements Parcelable {
//     public static final Creator<Album> CREATOR = new Creator<Album>() {
//         @Nullable
//         @Override
//         public Album createFromParcel(Parcel source) {
//             return new Album(source);
//         }
// 
//         @Override
//         public Album[] newArray(int size) {
//             return new Album[size];
//         }
//     };
//     public static final String ALBUM_ID_ALL = String.valueOf(-1);
//     public static final String ALBUM_NAME_ALL = "All";
// 
//     private final String mId;
//     private final Uri mCoverUri;
//     private final String mDisplayName;
//     private long mCount;
// 
//     public Album(String id, Uri coverUri, String albumName, long count) {
//         mId = id;
//         mCoverUri = coverUri;
//         mDisplayName = albumName;
//         mCount = count;
//     }
// 
//     private Album(Parcel source) {
//         mId = source.readString();
//         mCoverUri = source.readParcelable(Uri.class.getClassLoader());
//         mDisplayName = source.readString();
//         mCount = source.readLong();
//     }
// 
//     /**
//      * Constructs a new {@link Album} entity from the {@link Cursor}.
//      * This method is not responsible for managing cursor resource, such as close, iterate, and so on.
//      */
//     public static Album valueOf(Cursor cursor) {
//         String clumn = cursor.getString(cursor.getColumnIndex(AlbumLoader.COLUMN_URI));
//         return new Album(
//                 cursor.getString(cursor.getColumnIndex("bucket_id")),
//                 Uri.parse(clumn != null ? clumn : ""),
//                 cursor.getString(cursor.getColumnIndex("bucket_display_name")),
//                 cursor.getLong(cursor.getColumnIndex(AlbumLoader.COLUMN_COUNT)));
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(mId);
//         dest.writeParcelable(mCoverUri, 0);
//         dest.writeString(mDisplayName);
//         dest.writeLong(mCount);
//     }
// 
//     public String getId() {
//         return mId;
//     }
// 
//     public Uri getCoverUri() {
//         return mCoverUri;
//     }
// 
//     public long getCount() {
//         return mCount;
//     }
// 
//     public void addCaptureCount() {
//         mCount++;
//     }
// 
//     public String getDisplayName(Context context) {
//         if (isAll()) {
//             return context.getString(R.string.album_name_all);
//         }
//         return mDisplayName;
//     }
// 
//     public boolean isAll() {
//         return ALBUM_ID_ALL.equals(mId);
//     }
// 
//     public boolean isEmpty() {
//         return mCount == 0;
//     }
// 
// }


import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.ListPopupWindow;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.TextView;
import com.zhihu.matisse.R;
import com.zhihu.matisse.internal.entity.Album;
import com.zhihu.matisse.internal.utils.Platform;
        float density = context.getResources().getDisplayMetrics().density;
        mListPopupWindow.setContentWidth((int) (216 * density));
        mListPopupWindow.setHorizontalOffset((int) (16 * density));
        mListPopupWindow.setVerticalOffset((int) (-48 * density));

        mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AlbumsSpinner.this.onItemSelected(parent.getContext(), position);
                if (mOnItemSelectedListener != null) {
                    mOnItemSelectedListener.onItemSelected(parent, view, position, id);
                }
            }
        });
    }

    public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) {
        mOnItemSelectedListener = listener;
    }

    public void setSelection(Context context, int position) {
        mListPopupWindow.setSelection(position);
        onItemSelected(context, position);
    }

    private void onItemSelected(Context context, int position) {
        mListPopupWindow.dismiss();
        Cursor cursor = mAdapter.getCursor();
        cursor.moveToPosition(position);
// Path: matisse/src/main/java/com/zhihu/matisse/internal/entity/Album.java
// public class Album implements Parcelable {
//     public static final Creator<Album> CREATOR = new Creator<Album>() {
//         @Nullable
//         @Override
//         public Album createFromParcel(Parcel source) {
//             return new Album(source);
//         }
// 
//         @Override
//         public Album[] newArray(int size) {
//             return new Album[size];
//         }
//     };
//     public static final String ALBUM_ID_ALL = String.valueOf(-1);
//     public static final String ALBUM_NAME_ALL = "All";
// 
//     private final String mId;
//     private final Uri mCoverUri;
//     private final String mDisplayName;
//     private long mCount;
// 
//     public Album(String id, Uri coverUri, String albumName, long count) {
//         mId = id;
//         mCoverUri = coverUri;
//         mDisplayName = albumName;
//         mCount = count;
//     }
// 
//     private Album(Parcel source) {
//         mId = source.readString();
//         mCoverUri = source.readParcelable(Uri.class.getClassLoader());
//         mDisplayName = source.readString();
//         mCount = source.readLong();
//     }
// 
//     /**
//      * Constructs a new {@link Album} entity from the {@link Cursor}.
//      * This method is not responsible for managing cursor resource, such as close, iterate, and so on.
//      */
//     public static Album valueOf(Cursor cursor) {
//         String clumn = cursor.getString(cursor.getColumnIndex(AlbumLoader.COLUMN_URI));
//         return new Album(
//                 cursor.getString(cursor.getColumnIndex("bucket_id")),
//                 Uri.parse(clumn != null ? clumn : ""),
//                 cursor.getString(cursor.getColumnIndex("bucket_display_name")),
//                 cursor.getLong(cursor.getColumnIndex(AlbumLoader.COLUMN_COUNT)));
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(mId);
//         dest.writeParcelable(mCoverUri, 0);
//         dest.writeString(mDisplayName);
//         dest.writeLong(mCount);
//     }
// 
//     public String getId() {
//         return mId;
//     }
// 
//     public Uri getCoverUri() {
//         return mCoverUri;
//     }
// 
//     public long getCount() {
//         return mCount;
//     }
// 
//     public void addCaptureCount() {
//         mCount++;
//     }
// 
//     public String getDisplayName(Context context) {
//         if (isAll()) {
//             return context.getString(R.string.album_name_all);
//         }
//         return mDisplayName;
//     }
// 
//     public boolean isAll() {
//         return ALBUM_ID_ALL.equals(mId);
//     }
// 
//     public boolean isEmpty() {
//         return mCount == 0;
//     }
// 
// }


// Path: matisse/src/main/java/com/zhihu/matisse/internal/ui/widget/AlbumsSpinner.java
import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.ListPopupWindow;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.TextView;
import com.zhihu.matisse.R;
import com.zhihu.matisse.internal.entity.Album;
import com.zhihu.matisse.internal.utils.Platform;

        float density = context.getResources().getDisplayMetrics().density;
        mListPopupWindow.setContentWidth((int) (216 * density));
        mListPopupWindow.setHorizontalOffset((int) (16 * density));
        mListPopupWindow.setVerticalOffset((int) (-48 * density));

        mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AlbumsSpinner.this.onItemSelected(parent.getContext(), position);
                if (mOnItemSelectedListener != null) {
                    mOnItemSelectedListener.onItemSelected(parent, view, position, id);
                }
            }
        });
    }

    public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) {
        mOnItemSelectedListener = listener;
    }

    public void setSelection(Context context, int position) {
        mListPopupWindow.setSelection(position);
        onItemSelected(context, position);
    }

    private void onItemSelected(Context context, int position) {
        mListPopupWindow.dismiss();
        Cursor cursor = mAdapter.getCursor();
        cursor.moveToPosition(position);
        Album album = Album.valueOf(cursor);