Compare commits
33 Commits
gallery-v1
...
UseWINBOT
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a700a0808 | |||
| dad179c15f | |||
| 1b62ff288f | |||
| 87ad6668a4 | |||
| 139083c22f | |||
| c49e68d7f1 | |||
| b035d461aa | |||
| 474ddcbb3b | |||
| a7e2646eca | |||
| a12577a369 | |||
| 990ca8e27c | |||
| 7f6cd8295c | |||
| ae3a0c6f64 | |||
| e07931fd3b | |||
| 8d62e7df21 | |||
| 1cca476acd | |||
| 31ea5c8fbb | |||
| e62a907378 | |||
| c85ba8324b | |||
| 3e49c33bc1 | |||
| 3aab93cc4d | |||
| 90d8330798 | |||
| b01482470a | |||
| 57c36b09ac | |||
| b5d68dfd1e | |||
| 262d35fb4e | |||
| 5b0bb599bb | |||
| 3955de100d | |||
| 7456db1729 | |||
| 226cbf43fe | |||
| 4a267d5606 | |||
| 4d0d8c4d59 | |||
| 9a43267b63 |
@@ -109,7 +109,7 @@ dependencies {
|
|||||||
*/
|
*/
|
||||||
// WinBoLL库 nexus.winboll.cc 地址
|
// WinBoLL库 nexus.winboll.cc 地址
|
||||||
api 'cc.winboll.studio:libaes:15.15.9'
|
api 'cc.winboll.studio:libaes:15.15.9'
|
||||||
api 'cc.winboll.studio:libappbase:15.15.19'
|
api 'cc.winboll.studio:libappbase:15.15.21'
|
||||||
|
|
||||||
// WinBoLL备用库 jitpack.io 地址
|
// WinBoLL备用库 jitpack.io 地址
|
||||||
//api 'com.github.ZhanGSKen:AES:aes-v15.15.7'
|
//api 'com.github.ZhanGSKen:AES:aes-v15.15.7'
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sat Apr 25 20:05:35 HKT 2026
|
#Tue Apr 28 19:41:44 CST 2026
|
||||||
stageCount=4
|
stageCount=10
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.0
|
baseVersion=15.0
|
||||||
publishVersion=15.0.3
|
publishVersion=15.0.9
|
||||||
buildCount=0
|
buildCount=11
|
||||||
baseBetaVersion=15.0.4
|
baseBetaVersion=15.0.10
|
||||||
|
|||||||
@@ -47,6 +47,14 @@
|
|||||||
android:name=".TrashActivity"
|
android:name=".TrashActivity"
|
||||||
android:label="@string/trash"/>
|
android:label="@string/trash"/>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".CropActivity"
|
||||||
|
android:label="调整封面"/>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".AboutActivity"
|
||||||
|
android:label="@string/about"/>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.max_aspect"
|
android:name="android.max_aspect"
|
||||||
android:value="4.0"/>
|
android:value="4.0"/>
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import cc.winboll.studio.libappbase.models.APPInfo;
|
||||||
|
import cc.winboll.studio.libappbase.views.AboutView;
|
||||||
|
|
||||||
|
public class AboutActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
public static final String TAG = "AboutActivity";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_about);
|
||||||
|
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AboutView aboutView = findViewById(R.id.aboutview);
|
||||||
|
aboutView.setAPPInfo(genDefaultAppInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
private APPInfo genDefaultAppInfo() {
|
||||||
|
LogUtils.d(TAG, "genDefaultAppInfo() 调用");
|
||||||
|
String branchName = "gallery";
|
||||||
|
APPInfo appInfo = new APPInfo();
|
||||||
|
appInfo.setAppName("Gallery");
|
||||||
|
appInfo.setAppIcon(R.drawable.ic_winboll);
|
||||||
|
appInfo.setAppDescription(getString(R.string.app_description));
|
||||||
|
appInfo.setAppGitName("WinBoLL");
|
||||||
|
appInfo.setAppGitOwner("Studio");
|
||||||
|
appInfo.setAppGitAPPBranch(branchName);
|
||||||
|
appInfo.setAppGitAPPSubProjectFolder(branchName);
|
||||||
|
appInfo.setAppHomePage("https://www.winboll.cc/apks/index.php?project=Gallery");
|
||||||
|
appInfo.setAppAPKName("Gallery");
|
||||||
|
appInfo.setAppAPKFolderName("Gallery");
|
||||||
|
LogUtils.d(TAG, "genDefaultAppInfo: 应用信息已生成");
|
||||||
|
return appInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import android.net.Uri;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@@ -16,6 +17,7 @@ import androidx.core.app.ActivityCompat;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
@@ -30,6 +32,8 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
private ImageAdapter adapter;
|
private ImageAdapter adapter;
|
||||||
private String albumPath;
|
private String albumPath;
|
||||||
private String albumName;
|
private String albumName;
|
||||||
|
private FloatingActionButton fabScrollTop;
|
||||||
|
private Preferences prefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -45,12 +49,39 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
getSupportActionBar().setTitle(albumName);
|
getSupportActionBar().setTitle(albumName);
|
||||||
|
|
||||||
|
prefs = new Preferences(this);
|
||||||
|
|
||||||
recyclerView = findViewById(R.id.recycler_view);
|
recyclerView = findViewById(R.id.recycler_view);
|
||||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
|
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
|
||||||
adapter = new ImageAdapter();
|
adapter = new ImageAdapter();
|
||||||
adapter.setContext(this);
|
adapter.setContext(this);
|
||||||
|
adapter.setAlbumPath(albumPath);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
fabScrollTop = findViewById(R.id.fab_scroll_top);
|
||||||
|
fabScrollTop.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
recyclerView.scrollToPosition(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
|
GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
|
||||||
|
if (layoutManager != null) {
|
||||||
|
int firstVisible = layoutManager.findFirstVisibleItemPosition();
|
||||||
|
if (firstVisible > 0) {
|
||||||
|
fabScrollTop.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
fabScrollTop.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
adapter.setOnImageClickListener(new OnImageClickListener() {
|
adapter.setOnImageClickListener(new OnImageClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onImageClick(int position, ArrayList<Uri> urls, ArrayList<String> paths) {
|
public void onImageClick(int position, ArrayList<Uri> urls, ArrayList<String> paths) {
|
||||||
@@ -93,6 +124,20 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSortOrder(int sortMode) {
|
||||||
|
switch (sortMode) {
|
||||||
|
case Preferences.SORT_TIME_ASC:
|
||||||
|
return android.provider.MediaStore.Images.Media.DATE_ADDED + " ASC";
|
||||||
|
case Preferences.SORT_NAME_DESC:
|
||||||
|
return android.provider.MediaStore.Images.Media.DISPLAY_NAME + " DESC";
|
||||||
|
case Preferences.SORT_NAME_ASC:
|
||||||
|
return android.provider.MediaStore.Images.Media.DISPLAY_NAME + " ASC";
|
||||||
|
case Preferences.SORT_TIME_DESC:
|
||||||
|
default:
|
||||||
|
return android.provider.MediaStore.Images.Media.DATE_ADDED + " DESC";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadImages() {
|
private void loadImages() {
|
||||||
LogUtils.d(TAG, "loadImages");
|
LogUtils.d(TAG, "loadImages");
|
||||||
ArrayList<Uri> imageUrls = new ArrayList<>();
|
ArrayList<Uri> imageUrls = new ArrayList<>();
|
||||||
@@ -102,7 +147,8 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
String selection = android.provider.MediaStore.Images.Media.DATA + " LIKE ?";
|
String selection = android.provider.MediaStore.Images.Media.DATA + " LIKE ?";
|
||||||
String[] selectionArgs = new String[]{albumPath + "%"};
|
String[] selectionArgs = new String[]{albumPath + "%"};
|
||||||
String sortOrder = android.provider.MediaStore.Images.Media.DATE_ADDED + " DESC";
|
int sortMode = prefs.getAlbumSortMode();
|
||||||
|
String sortOrder = getSortOrder(sortMode);
|
||||||
|
|
||||||
try (Cursor cursor = contentResolver.query(collection, null, selection, selectionArgs, sortOrder)) {
|
try (Cursor cursor = contentResolver.query(collection, null, selection, selectionArgs, sortOrder)) {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
@@ -129,16 +175,56 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
getMenuInflater().inflate(R.menu.menu_album, menu);
|
||||||
|
int sortMode = prefs.getAlbumSortMode();
|
||||||
|
int menuId = getSortMenuId(sortMode);
|
||||||
|
MenuItem item = menu.findItem(menuId);
|
||||||
|
if (item != null) {
|
||||||
|
item.setChecked(true);
|
||||||
|
}
|
||||||
|
MenuItem sortItem = menu.findItem(R.id.action_sort);
|
||||||
|
if (sortItem != null && sortItem.getSubMenu() != null) {
|
||||||
|
sortItem.getSubMenu().setGroupCheckable(0, true, true);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getSortMenuId(int sortMode) {
|
||||||
|
switch (sortMode) {
|
||||||
|
case Preferences.SORT_TIME_ASC:
|
||||||
|
return R.id.sort_time_asc;
|
||||||
|
case Preferences.SORT_NAME_DESC:
|
||||||
|
return R.id.sort_name_desc;
|
||||||
|
case Preferences.SORT_NAME_ASC:
|
||||||
|
return R.id.sort_name_asc;
|
||||||
|
case Preferences.SORT_TIME_DESC:
|
||||||
|
default:
|
||||||
|
return R.id.sort_time_desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
if (item.getItemId() == R.id.action_refresh) {
|
int itemId = item.getItemId();
|
||||||
if (checkPermission()) {
|
if (itemId == R.id.sort_time_desc) {
|
||||||
|
prefs.setAlbumSortMode(Preferences.SORT_TIME_DESC);
|
||||||
|
item.setChecked(true);
|
||||||
|
loadImages();
|
||||||
|
return true;
|
||||||
|
} else if (itemId == R.id.sort_time_asc) {
|
||||||
|
prefs.setAlbumSortMode(Preferences.SORT_TIME_ASC);
|
||||||
|
item.setChecked(true);
|
||||||
|
loadImages();
|
||||||
|
return true;
|
||||||
|
} else if (itemId == R.id.sort_name_desc) {
|
||||||
|
prefs.setAlbumSortMode(Preferences.SORT_NAME_DESC);
|
||||||
|
item.setChecked(true);
|
||||||
|
loadImages();
|
||||||
|
return true;
|
||||||
|
} else if (itemId == R.id.sort_name_asc) {
|
||||||
|
prefs.setAlbumSortMode(Preferences.SORT_NAME_ASC);
|
||||||
|
item.setChecked(true);
|
||||||
loadImages();
|
loadImages();
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@@ -154,4 +240,12 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
adapter.refreshBg();
|
adapter.refreshBg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == 100 && resultCode == RESULT_OK) {
|
||||||
|
loadImages();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import android.provider.MediaStore;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.View.OnLongClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -13,6 +14,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
@@ -22,6 +25,9 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
|||||||
private OnAlbumClickListener listener;
|
private OnAlbumClickListener listener;
|
||||||
private Preferences prefs;
|
private Preferences prefs;
|
||||||
private int bgType = 0;
|
private int bgType = 0;
|
||||||
|
private PinnedAlbumDbHelper pinnedDbHelper;
|
||||||
|
private OnCoverSizeListener coverSizeListener;
|
||||||
|
private boolean coverSizeReported = false;
|
||||||
|
|
||||||
private int getBgRes() {
|
private int getBgRes() {
|
||||||
switch (bgType) {
|
switch (bgType) {
|
||||||
@@ -40,26 +46,108 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
|||||||
void onAlbumClick(Album album);
|
void onAlbumClick(Album album);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnCoverSizeListener {
|
||||||
|
void onCoverSize(int width, int height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int DEFAULT_COVER_WIDTH = 240;
|
||||||
|
public static final int DEFAULT_COVER_HEIGHT = 120;
|
||||||
|
|
||||||
public void setOnAlbumClickListener(OnAlbumClickListener listener) {
|
public void setOnAlbumClickListener(OnAlbumClickListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOnCoverSizeListener(OnCoverSizeListener listener) {
|
||||||
|
this.coverSizeListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
public void setData(ArrayList<Album> albums) {
|
public void setData(ArrayList<Album> albums) {
|
||||||
this.albums = albums;
|
this.albums = sortAlbums(albums);
|
||||||
LogUtils.d(TAG, "setData: " + albums.size() + " albums");
|
LogUtils.d(TAG, "setData: " + albums.size() + " albums");
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArrayList<Album> sortAlbums(ArrayList<Album> list) {
|
||||||
|
if (pinnedDbHelper == null || list == null || list.isEmpty()) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
ArrayList<Album> pinned = new ArrayList<>();
|
||||||
|
ArrayList<Album> unpinned = new ArrayList<>();
|
||||||
|
for (Album album : list) {
|
||||||
|
if (pinnedDbHelper.isPinned(album.getPath())) {
|
||||||
|
pinned.add(album);
|
||||||
|
} else {
|
||||||
|
unpinned.add(album);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pinned.addAll(unpinned);
|
||||||
|
return pinned;
|
||||||
|
}
|
||||||
|
|
||||||
public void setContext(android.content.Context context) {
|
public void setContext(android.content.Context context) {
|
||||||
prefs = new Preferences(context);
|
prefs = new Preferences(context);
|
||||||
bgType = prefs.getBgType();
|
bgType = prefs.getBgType();
|
||||||
|
pinnedDbHelper = PinnedAlbumDbHelper.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshBg() {
|
public void refreshBg() {
|
||||||
if (prefs != null) {
|
if (prefs != null) {
|
||||||
bgType = prefs.getBgType();
|
bgType = prefs.getBgType();
|
||||||
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshCover() {
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshPinned() {
|
||||||
|
if (pinnedDbHelper != null && albums != null && !albums.isEmpty()) {
|
||||||
|
ArrayList<Album> pinned = new ArrayList<>();
|
||||||
|
ArrayList<Album> unpinned = new ArrayList<>();
|
||||||
|
for (Album album : albums) {
|
||||||
|
if (pinnedDbHelper.isPinned(album.getPath())) {
|
||||||
|
pinned.add(album);
|
||||||
|
} else {
|
||||||
|
unpinned.add(album);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Comparator<Album> nameComparator = new Comparator<Album>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Album a1, Album a2) {
|
||||||
|
return a1.getName().compareToIgnoreCase(a2.getName());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Collections.sort(pinned, nameComparator);
|
||||||
|
Collections.sort(unpinned, nameComparator);
|
||||||
|
albums.clear();
|
||||||
|
albums.addAll(pinned);
|
||||||
|
albums.addAll(unpinned);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showContextMenu(View view, final Album album) {
|
||||||
|
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(view.getContext());
|
||||||
|
builder.setTitle(album.getName());
|
||||||
|
boolean isPinned = pinnedDbHelper != null && pinnedDbHelper.isPinned(album.getPath());
|
||||||
|
String[] items = isPinned ? new String[]{"取消置顶"} : new String[]{"置顶"};
|
||||||
|
builder.setItems(items, new android.content.DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(android.content.DialogInterface dialog, int which) {
|
||||||
|
if (pinnedDbHelper != null) {
|
||||||
|
if (which == 0) {
|
||||||
|
if (isPinned) {
|
||||||
|
pinnedDbHelper.unpinAlbum(album.getPath());
|
||||||
|
} else {
|
||||||
|
pinnedDbHelper.pinAlbum(album.getPath());
|
||||||
|
}
|
||||||
|
refreshPinned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -77,9 +165,43 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
|||||||
|
|
||||||
holder.coverImage.setBackgroundResource(getBgRes());
|
holder.coverImage.setBackgroundResource(getBgRes());
|
||||||
|
|
||||||
|
boolean isPinned = pinnedDbHelper != null && pinnedDbHelper.isPinned(album.getPath());
|
||||||
|
holder.pinIcon.setVisibility(isPinned ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showContextMenu(holder.itemView, album);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
holder.albumName.setText(album.getName());
|
holder.albumName.setText(album.getName());
|
||||||
holder.imageCount.setText(album.getImageCount() + " photos");
|
holder.imageCount.setText(album.getImageCount() + " photos");
|
||||||
|
|
||||||
|
holder.itemView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!coverSizeReported && prefs != null) {
|
||||||
|
int savedWidth = prefs.getCoverWidth();
|
||||||
|
if (savedWidth == AlbumAdapter.DEFAULT_COVER_WIDTH) {
|
||||||
|
int width = holder.coverImage.getWidth();
|
||||||
|
int height = holder.coverImage.getHeight();
|
||||||
|
if (width > 0 && height > 0) {
|
||||||
|
prefs.setCoverWidth(width);
|
||||||
|
prefs.setCoverHeight(height);
|
||||||
|
float ratio = (float) width / height;
|
||||||
|
prefs.setCoverRatio(ratio);
|
||||||
|
coverSizeReported = true;
|
||||||
|
if (coverSizeListener != null) {
|
||||||
|
coverSizeListener.onCoverSize(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
holder.itemView.setOnClickListener(new OnClickListener() {
|
holder.itemView.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -94,38 +216,23 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
|||||||
String uriString = coverUri.toString();
|
String uriString = coverUri.toString();
|
||||||
LogUtils.d(TAG, "uri scheme: " + coverUri.getScheme() + ", path: " + uriString);
|
LogUtils.d(TAG, "uri scheme: " + coverUri.getScheme() + ", path: " + uriString);
|
||||||
|
|
||||||
// For content:// URIs, try to get the actual file path
|
if ("file".equals(coverUri.getScheme())) {
|
||||||
if ("content".equals(coverUri.getScheme())) {
|
File coverFile = new File(coverUri.getPath());
|
||||||
try {
|
if (coverFile.exists()) {
|
||||||
android.database.Cursor cursor = holder.coverImage.getContext().getContentResolver()
|
|
||||||
.query(coverUri, new String[]{MediaStore.Images.Media.DATA}, null, null, null);
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
|
||||||
String filePath = cursor.getString(dataColumn);
|
|
||||||
cursor.close();
|
|
||||||
if (filePath != null) {
|
|
||||||
File actualFile = new File(filePath);
|
|
||||||
LogUtils.d(TAG, "actual file: " + actualFile.getAbsolutePath() + ", exists=" + actualFile.exists());
|
|
||||||
// Use file path instead of content URI for better compatibility
|
|
||||||
Glide.with(holder.coverImage.getContext())
|
Glide.with(holder.coverImage.getContext())
|
||||||
.load(actualFile)
|
.load(coverFile)
|
||||||
.centerCrop()
|
.fitCenter()
|
||||||
.into(holder.coverImage);
|
.into(holder.coverImage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtils.e(TAG, "query error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to content URI
|
|
||||||
Glide.with(holder.coverImage.getContext())
|
Glide.with(holder.coverImage.getContext())
|
||||||
.load(coverUri)
|
.load(coverUri)
|
||||||
.centerCrop()
|
.fitCenter()
|
||||||
.into(holder.coverImage);
|
.into(holder.coverImage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
@@ -134,11 +241,13 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
|||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
ImageView coverImage;
|
ImageView coverImage;
|
||||||
|
ImageView pinIcon;
|
||||||
TextView albumName;
|
TextView albumName;
|
||||||
TextView imageCount;
|
TextView imageCount;
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
coverImage = itemView.findViewById(R.id.album_cover);
|
coverImage = itemView.findViewById(R.id.album_cover);
|
||||||
|
pinIcon = itemView.findViewById(R.id.pin_icon);
|
||||||
albumName = itemView.findViewById(R.id.album_name);
|
albumName = itemView.findViewById(R.id.album_name);
|
||||||
imageCount = itemView.findViewById(R.id.image_count);
|
imageCount = itemView.findViewById(R.id.image_count);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
|
public class AlbumCoverDbHelper extends SQLiteOpenHelper {
|
||||||
|
public static final String TAG = "AlbumCoverDbHelper";
|
||||||
|
private static final String DB_NAME = "album_cover.db";
|
||||||
|
private static final int DB_VERSION = 2;
|
||||||
|
private static final String TABLE_NAME = "album_covers";
|
||||||
|
private static final String COLUMN_ALBUM_PATH = "album_path";
|
||||||
|
private static final String COLUMN_IMAGE_PATH = "image_path";
|
||||||
|
private static final String COLUMN_CROP_PATH = "crop_path";
|
||||||
|
|
||||||
|
private static final String SQL_CREATE = "CREATE TABLE " + TABLE_NAME + " ("
|
||||||
|
+ COLUMN_ALBUM_PATH + " TEXT PRIMARY KEY, "
|
||||||
|
+ COLUMN_IMAGE_PATH + " TEXT, "
|
||||||
|
+ COLUMN_CROP_PATH + " TEXT)";
|
||||||
|
|
||||||
|
private static AlbumCoverDbHelper dbHelper;
|
||||||
|
|
||||||
|
public static AlbumCoverDbHelper getInstance(Context context) {
|
||||||
|
if (dbHelper == null) {
|
||||||
|
dbHelper = new AlbumCoverDbHelper(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
return dbHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumCoverDbHelper(Context context) {
|
||||||
|
super(context, DB_NAME, null, DB_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
db.execSQL(SQL_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
if (oldVersion < 2) {
|
||||||
|
try {
|
||||||
|
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_CROP_PATH + " TEXT");
|
||||||
|
} catch (Exception e) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoverWithCrop(String albumPath, String imagePath, String cropPath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(COLUMN_ALBUM_PATH, albumPath);
|
||||||
|
values.put(COLUMN_IMAGE_PATH, imagePath);
|
||||||
|
values.put(COLUMN_CROP_PATH, cropPath);
|
||||||
|
db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||||
|
LogUtils.d(TAG, "setCoverWithCrop: album=" + albumPath + ", image=" + imagePath + ", crop=" + cropPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCover(String albumPath, String imagePath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(COLUMN_ALBUM_PATH, albumPath);
|
||||||
|
values.put(COLUMN_IMAGE_PATH, imagePath);
|
||||||
|
db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||||
|
LogUtils.d(TAG, "setCover: album=" + albumPath + ", image=" + imagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCover(String albumPath) {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_CROP_PATH, COLUMN_IMAGE_PATH},
|
||||||
|
COLUMN_ALBUM_PATH + " = ?", new String[]{albumPath}, null, null, null);
|
||||||
|
String coverPath = null;
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
coverPath = cursor.getString(0);
|
||||||
|
if (coverPath == null) {
|
||||||
|
coverPath = cursor.getString(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return coverPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCropPath(String albumPath) {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_CROP_PATH},
|
||||||
|
COLUMN_ALBUM_PATH + " = ?", new String[]{albumPath}, null, null, null);
|
||||||
|
String cropPath = null;
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
cropPath = cursor.getString(0);
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return cropPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginalImagePath(String albumPath) {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_IMAGE_PATH},
|
||||||
|
COLUMN_ALBUM_PATH + " = ?", new String[]{albumPath}, null, null, null);
|
||||||
|
String imagePath = null;
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
imagePath = cursor.getString(0);
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return imagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearCover(String albumPath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.putNull(COLUMN_CROP_PATH);
|
||||||
|
db.update(TABLE_NAME, values, COLUMN_ALBUM_PATH + " = ?", new String[]{albumPath});
|
||||||
|
LogUtils.d(TAG, "clearCover: " + albumPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteCover(String albumPath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
db.delete(TABLE_NAME, COLUMN_ALBUM_PATH + " = ?", new String[]{albumPath});
|
||||||
|
LogUtils.d(TAG, "deleteCover: " + albumPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.graphics.drawable.GradientDrawable;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CropActivity extends AppCompatActivity {
|
||||||
|
public static final String TAG = "CropActivity";
|
||||||
|
public static final String EXTRA_IMAGE_URI = "image_uri";
|
||||||
|
public static final String EXTRA_IMAGE_PATH = "image_path";
|
||||||
|
public static final String EXTRA_ALBUM_PATH = "album_path";
|
||||||
|
public static final String EXTRA_CROP_WIDTH = "crop_width";
|
||||||
|
public static final String EXTRA_CROP_HEIGHT = "crop_height";
|
||||||
|
|
||||||
|
private CropCanvasView cropCanvasView;
|
||||||
|
private ZoomContainerView zoomContainer;
|
||||||
|
private Bitmap originalBitmap;
|
||||||
|
private String imagePath;
|
||||||
|
private String albumPath;
|
||||||
|
private int cropWidth = 240;
|
||||||
|
private int cropHeight = 120;
|
||||||
|
private float cropRatio = 2.0f;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_crop);
|
||||||
|
|
||||||
|
imagePath = getIntent().getStringExtra(EXTRA_IMAGE_PATH);
|
||||||
|
albumPath = getIntent().getStringExtra(EXTRA_ALBUM_PATH);
|
||||||
|
cropWidth = getIntent().getIntExtra(EXTRA_CROP_WIDTH, 240);
|
||||||
|
cropHeight = getIntent().getIntExtra(EXTRA_CROP_HEIGHT, 120);
|
||||||
|
|
||||||
|
Preferences prefs = new Preferences(this);
|
||||||
|
if (cropWidth > 0 && cropHeight > 0) {
|
||||||
|
cropRatio = (float) cropWidth / cropHeight;
|
||||||
|
} else {
|
||||||
|
cropRatio = prefs.getCoverRatio();
|
||||||
|
cropWidth = (int) (120 * cropRatio);
|
||||||
|
cropHeight = 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final ImageView btnColorPick = findViewById(R.id.btn_color_pick);
|
||||||
|
btnColorPick.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean pickMode = !cropCanvasView.isColorPickMode();
|
||||||
|
cropCanvasView.setColorPickMode(pickMode);
|
||||||
|
btnColorPick.setAlpha(pickMode ? 0.5f : 1.0f);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
findViewById(R.id.btn_done).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
saveCroppedCover();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
findViewById(R.id.btn_info).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
showCropInfoDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
zoomContainer = findViewById(R.id.zoom_container);
|
||||||
|
|
||||||
|
SeekBar seekBarZoom = findViewById(R.id.seekbar_zoom);
|
||||||
|
seekBarZoom.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
if (zoomContainer != null && fromUser) {
|
||||||
|
float scale = 0.1f + (progress / 100f) * 4.9f;
|
||||||
|
zoomContainer.setScaleFactor(scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
cropCanvasView = findViewById(R.id.crop_canvas_view);
|
||||||
|
|
||||||
|
final View colorView = findViewById(R.id.color_view);
|
||||||
|
final GradientDrawable colorDrawable = (GradientDrawable) colorView.getBackground();
|
||||||
|
cropCanvasView.setOnBackgroundColorChangedListener(new CropCanvasView.OnBackgroundColorChangedListener() {
|
||||||
|
@Override
|
||||||
|
public void onBackgroundColorChanged(int color) {
|
||||||
|
colorDrawable.setColor(color);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cropCanvasView.setOnColorPickedListener(new CropCanvasView.OnColorPickedListener() {
|
||||||
|
@Override
|
||||||
|
public void onColorPicked(int color) {
|
||||||
|
int pickX = cropCanvasView.getLastPickImageX();
|
||||||
|
int pickY = cropCanvasView.getLastPickImageY();
|
||||||
|
colorDrawable.setColor(color);
|
||||||
|
Toast.makeText(CropActivity.this,
|
||||||
|
"颜色已拾取: #" + String.format("%06X", color & 0xFFFFFF) +
|
||||||
|
" (" + pickX + "," + pickY + ")",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cropCanvasView.setOnColorPickEndListener(new CropCanvasView.OnColorPickEndListener() {
|
||||||
|
@Override
|
||||||
|
public void onColorPickEnd() {
|
||||||
|
cropCanvasView.setColorPickMode(false);
|
||||||
|
btnColorPick.setAlpha(1.0f);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
colorDrawable.setColor(cropCanvasView.getBackgroundColor());
|
||||||
|
|
||||||
|
loadImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadImage() {
|
||||||
|
try {
|
||||||
|
if (imagePath != null && new File(imagePath).exists()) {
|
||||||
|
originalBitmap = BitmapFactory.decodeFile(imagePath);
|
||||||
|
} else {
|
||||||
|
Uri imageUri = getIntent().getParcelableExtra(EXTRA_IMAGE_URI);
|
||||||
|
if (imageUri != null) {
|
||||||
|
originalBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originalBitmap != null) {
|
||||||
|
cropCanvasView.setImageBitmap(originalBitmap);
|
||||||
|
cropCanvasView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
initCrop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Failed to load image", Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.e(TAG, "loadImage error: " + e.getMessage());
|
||||||
|
Toast.makeText(this, "Failed to load image", Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCrop() {
|
||||||
|
cropCanvasView.initCanvas(originalBitmap.getWidth(), originalBitmap.getHeight(), cropRatio);
|
||||||
|
|
||||||
|
int viewW = cropCanvasView.getWidth();
|
||||||
|
int viewH = cropCanvasView.getHeight();
|
||||||
|
if (viewW > 0 && viewH > 0) {
|
||||||
|
cropCanvasView.scaleToView(viewW, viewH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveCroppedCover() {
|
||||||
|
if (originalBitmap == null || originalBitmap.isRecycled()) {
|
||||||
|
Toast.makeText(this, "Failed to get image", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Bitmap canvasBitmap = cropCanvasView.getCanvasBitmap();
|
||||||
|
if (canvasBitmap == null || canvasBitmap.isRecycled()) {
|
||||||
|
Toast.makeText(this, "Failed to get canvas bitmap", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RectF cropRect = cropCanvasView.getCropRect();
|
||||||
|
|
||||||
|
int bmpX = (int) cropRect.left;
|
||||||
|
int bmpY = (int) cropRect.top;
|
||||||
|
int bmpW = (int) cropRect.width();
|
||||||
|
int bmpH = (int) cropRect.height();
|
||||||
|
|
||||||
|
bmpX = Math.max(0, Math.min(bmpX, canvasBitmap.getWidth() - 1));
|
||||||
|
bmpY = Math.max(0, Math.min(bmpY, canvasBitmap.getHeight() - 1));
|
||||||
|
bmpW = Math.max(1, Math.min(bmpW, canvasBitmap.getWidth() - bmpX));
|
||||||
|
bmpH = Math.max(1, Math.min(bmpH, canvasBitmap.getHeight() - bmpY));
|
||||||
|
|
||||||
|
LogUtils.d(TAG, "saveCroppedCover: cropRect=" + cropRect);
|
||||||
|
LogUtils.d(TAG, "saveCroppedCover: crop=(" + bmpX + "," + bmpY + "," + bmpW + "," + bmpH + ")");
|
||||||
|
LogUtils.d(TAG, "saveCroppedCover: canvas size=" + canvasBitmap.getWidth() + "x" + canvasBitmap.getHeight());
|
||||||
|
|
||||||
|
Bitmap cropped = Bitmap.createBitmap(canvasBitmap, bmpX, bmpY, bmpW, bmpH);
|
||||||
|
canvasBitmap.recycle();
|
||||||
|
|
||||||
|
LogUtils.d(TAG, "saveCroppedCover: cropped size=" + cropped.getWidth() + "x" + cropped.getHeight());
|
||||||
|
|
||||||
|
File coverDir = new File(getFilesDir(), "covers");
|
||||||
|
if (!coverDir.exists()) {
|
||||||
|
coverDir.mkdirs();
|
||||||
|
}
|
||||||
|
File coverFile = new File(coverDir, "cover_" + System.currentTimeMillis() + ".png");
|
||||||
|
LogUtils.d(TAG, "saveCroppedCover: cover file=" + coverFile.getAbsolutePath());
|
||||||
|
|
||||||
|
FileOutputStream fos = new FileOutputStream(coverFile);
|
||||||
|
cropped.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||||||
|
fos.close();
|
||||||
|
|
||||||
|
LogUtils.d(TAG, "saveCroppedCover: file exists=" + coverFile.exists() + ", length=" + coverFile.length());
|
||||||
|
|
||||||
|
cropped.recycle();
|
||||||
|
|
||||||
|
AlbumCoverDbHelper coverDbHelper = AlbumCoverDbHelper.getInstance(this);
|
||||||
|
coverDbHelper.setCoverWithCrop(albumPath, imagePath, coverFile.getAbsolutePath());
|
||||||
|
LogUtils.d(TAG, "saveCroppedCover: cover saved to db, albumPath=" + albumPath);
|
||||||
|
|
||||||
|
Intent broadcastIntent = new Intent(Preferences.ACTION_COVER_UPDATED);
|
||||||
|
sendBroadcast(broadcastIntent);
|
||||||
|
|
||||||
|
Toast.makeText(this, "封面已保存", Toast.LENGTH_SHORT).show();
|
||||||
|
setResult(RESULT_OK);
|
||||||
|
finish();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.e(TAG, "saveCroppedCover error: " + e.getMessage());
|
||||||
|
Toast.makeText(this, "Failed to save cover", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showCropInfoDialog() {
|
||||||
|
StringBuilder info = new StringBuilder();
|
||||||
|
info.append("=== 画布信息 ===\n");
|
||||||
|
info.append("画布宽度: ").append(cropCanvasView.getCanvasWidth()).append("px\n");
|
||||||
|
info.append("画布高度: ").append(cropCanvasView.getCanvasHeight()).append("px\n");
|
||||||
|
|
||||||
|
info.append("\n=== 拾取颜色 ===\n");
|
||||||
|
int bgColor = cropCanvasView.getBackgroundColor();
|
||||||
|
info.append("背景颜色: #").append(String.format("%06X", bgColor & 0xFFFFFF)).append("\n");
|
||||||
|
info.append("拾取坐标: ").append(cropCanvasView.getLastPickImageX()).append(",")
|
||||||
|
.append(cropCanvasView.getLastPickImageY()).append("\n");
|
||||||
|
|
||||||
|
info.append("\n=== 裁剪结果 ===\n");
|
||||||
|
RectF cropRect = cropCanvasView.getCropRect();
|
||||||
|
if (cropRect != null) {
|
||||||
|
info.append("裁剪区域: ").append((int)cropRect.left).append(",")
|
||||||
|
.append((int)cropRect.top).append(",")
|
||||||
|
.append((int)cropRect.right).append(",")
|
||||||
|
.append((int)cropRect.bottom).append("\n");
|
||||||
|
info.append("裁剪宽度: ").append((int)cropRect.width()).append("px\n");
|
||||||
|
info.append("裁剪高度: ").append((int)cropRect.height()).append("px\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap canvasBitmap = cropCanvasView.getCanvasBitmap();
|
||||||
|
final Bitmap[] previewHolder = new Bitmap[1];
|
||||||
|
if (canvasBitmap != null && !canvasBitmap.isRecycled() && cropRect != null) {
|
||||||
|
int bmpX = Math.max(0, (int) cropRect.left);
|
||||||
|
int bmpY = Math.max(0, (int) cropRect.top);
|
||||||
|
int bmpW = Math.min((int) cropRect.width(), canvasBitmap.getWidth() - bmpX);
|
||||||
|
int bmpH = Math.min((int) cropRect.height(), canvasBitmap.getHeight() - bmpY);
|
||||||
|
if (bmpW > 0 && bmpH > 0) {
|
||||||
|
previewHolder[0] = Bitmap.createBitmap(canvasBitmap, bmpX, bmpY, bmpW, bmpH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Bitmap previewBitmap = previewHolder[0];
|
||||||
|
|
||||||
|
View dialogView = getLayoutInflater().inflate(R.layout.dialog_crop_info, null);
|
||||||
|
TextView infoText = dialogView.findViewById(R.id.info_text);
|
||||||
|
ImageView previewImage = dialogView.findViewById(R.id.preview_image);
|
||||||
|
infoText.setText(info.toString());
|
||||||
|
if (previewBitmap != null) {
|
||||||
|
previewImage.setImageBitmap(previewBitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||||
|
.setTitle("裁剪信息")
|
||||||
|
.setView(dialogView)
|
||||||
|
.setPositiveButton("确定", null)
|
||||||
|
.create();
|
||||||
|
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
if (previewBitmap != null && !previewBitmap.isRecycled()) {
|
||||||
|
previewBitmap.recycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if (originalBitmap != null) {
|
||||||
|
originalBitmap.recycle();
|
||||||
|
originalBitmap = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,689 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Matrix;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class CropCanvasView extends View {
|
||||||
|
public interface OnBackgroundColorChangedListener {
|
||||||
|
void onBackgroundColorChanged(int color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnColorPickedListener {
|
||||||
|
void onColorPicked(int color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnColorPickEndListener {
|
||||||
|
void onColorPickEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private OnBackgroundColorChangedListener backgroundColorChangedListener;
|
||||||
|
private OnColorPickedListener colorPickedListener;
|
||||||
|
private OnColorPickEndListener colorPickEndListener;
|
||||||
|
|
||||||
|
public void setOnBackgroundColorChangedListener(OnBackgroundColorChangedListener listener) {
|
||||||
|
this.backgroundColorChangedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnColorPickedListener(OnColorPickedListener listener) {
|
||||||
|
this.colorPickedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnColorPickEndListener(OnColorPickEndListener listener) {
|
||||||
|
this.colorPickEndListener = listener;
|
||||||
|
}
|
||||||
|
private Paint imagePaint;
|
||||||
|
private Paint borderPaint;
|
||||||
|
private Paint cornerPaint;
|
||||||
|
private RectF cropRect;
|
||||||
|
private int touchArea = 50;
|
||||||
|
|
||||||
|
private float lastX, lastY;
|
||||||
|
private int activeCorner = -1;
|
||||||
|
private static final int CORNER_TOP_LEFT = 0;
|
||||||
|
private static final int CORNER_TOP_RIGHT = 1;
|
||||||
|
private static final int CORNER_BOTTOM_LEFT = 2;
|
||||||
|
private static final int CORNER_BOTTOM_RIGHT = 3;
|
||||||
|
private static final int CORNER_CENTER = 4;
|
||||||
|
|
||||||
|
private int imageWidth;
|
||||||
|
private int imageHeight;
|
||||||
|
private float coverRatio = 2.0f;
|
||||||
|
|
||||||
|
private int extendHeight;
|
||||||
|
private int extendWidth;
|
||||||
|
private int canvasWidth;
|
||||||
|
private int canvasHeight;
|
||||||
|
private float minSize = 50;
|
||||||
|
|
||||||
|
private RectF imageBounds = new RectF();
|
||||||
|
private RectF canvasBounds = new RectF();
|
||||||
|
private Bitmap originalBitmap;
|
||||||
|
private Bitmap canvasBitmap;
|
||||||
|
private float bitmapScale = 1.0f;
|
||||||
|
private Bitmap displayBitmap;
|
||||||
|
private RectF initialSpanRect;
|
||||||
|
private float initialSpan;
|
||||||
|
private int backgroundColor = Color.BLUE;
|
||||||
|
private boolean colorPickMode = false;
|
||||||
|
private int previewColor = 0;
|
||||||
|
private float lastPickX = 0;
|
||||||
|
private float lastPickY = 0;
|
||||||
|
private float pickX, pickY;
|
||||||
|
|
||||||
|
private float displayScale = 1.0f;
|
||||||
|
private float displayOffsetX = 0f;
|
||||||
|
private float displayOffsetY = 0f;
|
||||||
|
private static final int MAX_DISPLAY_SIZE = 2048;
|
||||||
|
private float containerScale = 1.0f;
|
||||||
|
|
||||||
|
public CropCanvasView(Context context) {
|
||||||
|
super(context);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropCanvasView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropCanvasView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
imagePaint = new Paint();
|
||||||
|
imagePaint.setFilterBitmap(true);
|
||||||
|
|
||||||
|
borderPaint = new Paint();
|
||||||
|
borderPaint.setColor(Color.parseColor("#CCAA00"));
|
||||||
|
borderPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
borderPaint.setStrokeWidth(3);
|
||||||
|
|
||||||
|
cornerPaint = new Paint();
|
||||||
|
cornerPaint.setColor(Color.WHITE);
|
||||||
|
cornerPaint.setStyle(Paint.Style.FILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageBitmap(Bitmap bitmap) {
|
||||||
|
if (displayBitmap != null && displayBitmap != originalBitmap) {
|
||||||
|
displayBitmap.recycle();
|
||||||
|
}
|
||||||
|
this.originalBitmap = bitmap;
|
||||||
|
createDisplayBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createDisplayBitmap() {
|
||||||
|
if (displayBitmap != null && displayBitmap != originalBitmap) {
|
||||||
|
displayBitmap.recycle();
|
||||||
|
displayBitmap = null;
|
||||||
|
}
|
||||||
|
if (originalBitmap == null || originalBitmap.isRecycled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int w = originalBitmap.getWidth();
|
||||||
|
int h = originalBitmap.getHeight();
|
||||||
|
float scale = 1.0f;
|
||||||
|
if (w > MAX_DISPLAY_SIZE || h > MAX_DISPLAY_SIZE) {
|
||||||
|
scale = Math.min((float) MAX_DISPLAY_SIZE / w, (float) MAX_DISPLAY_SIZE / h);
|
||||||
|
int newW = (int) (w * scale);
|
||||||
|
int newH = (int) (h * scale);
|
||||||
|
displayBitmap = Bitmap.createScaledBitmap(originalBitmap, newW, newH, true);
|
||||||
|
} else {
|
||||||
|
displayBitmap = originalBitmap;
|
||||||
|
}
|
||||||
|
displayBitmapScale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float displayBitmapScale = 1.0f;
|
||||||
|
|
||||||
|
public Bitmap getOriginalBitmap() {
|
||||||
|
return originalBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getDisplayBitmapScale() {
|
||||||
|
return displayBitmapScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onContainerScaled() {
|
||||||
|
containerScale = 1.0f;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContainerScale(float scale) {
|
||||||
|
if (scale > 0 && scale != containerScale) {
|
||||||
|
containerScale = scale;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getContainerScale() {
|
||||||
|
return containerScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getCanvasBitmap() {
|
||||||
|
if (canvasWidth <= 0 || canvasHeight <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Bitmap canvasBmp = Bitmap.createBitmap(canvasWidth, canvasHeight, Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas(canvasBmp);
|
||||||
|
canvas.drawColor(backgroundColor);
|
||||||
|
if (displayBitmap != null && !displayBitmap.isRecycled()) {
|
||||||
|
if (displayBitmap == originalBitmap) {
|
||||||
|
canvas.drawBitmap(displayBitmap, imageBounds.left, imageBounds.top, imagePaint);
|
||||||
|
} else {
|
||||||
|
float invScale = 1f / displayBitmapScale;
|
||||||
|
canvas.save();
|
||||||
|
canvas.scale(invScale, invScale);
|
||||||
|
canvas.drawBitmap(displayBitmap, imageBounds.left * displayBitmapScale,
|
||||||
|
imageBounds.top * displayBitmapScale, imagePaint);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return canvasBmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initCanvas(int imgWidth, int imgHeight, float ratio) {
|
||||||
|
this.imageWidth = imgWidth;
|
||||||
|
this.imageHeight = imgHeight;
|
||||||
|
this.coverRatio = ratio;
|
||||||
|
|
||||||
|
float imgRatio = (float) imgWidth / imgHeight;
|
||||||
|
|
||||||
|
if (coverRatio >= imgRatio) {
|
||||||
|
extendHeight = imgHeight;
|
||||||
|
extendWidth = (int) (imgHeight * coverRatio);
|
||||||
|
} else {
|
||||||
|
extendWidth = imgWidth;
|
||||||
|
extendHeight = (int) (imgWidth / coverRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
canvasHeight = Math.max(imageHeight, extendHeight);
|
||||||
|
canvasWidth = Math.max(imageWidth, extendWidth);
|
||||||
|
|
||||||
|
float left = (canvasWidth - imageWidth) / 2f;
|
||||||
|
float top = (canvasHeight - imageHeight) / 2f;
|
||||||
|
imageBounds.set(left, top, left + imageWidth, top + imageHeight);
|
||||||
|
canvasBounds.set(0, 0, canvasWidth, canvasHeight);
|
||||||
|
|
||||||
|
cropRect = new RectF(canvasBounds);
|
||||||
|
|
||||||
|
requestLayout();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getDisplayMatrix(Matrix matrix) {
|
||||||
|
if (canvasWidth <= 0 || canvasHeight <= 0 || getWidth() <= 0 || getHeight() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
matrix.reset();
|
||||||
|
|
||||||
|
float displayScaleX = (float) getWidth() / canvasWidth;
|
||||||
|
float displayScaleY = (float) getHeight() / canvasHeight;
|
||||||
|
displayScale = Math.min(displayScaleX, displayScaleY);
|
||||||
|
|
||||||
|
displayOffsetX = (getWidth() - canvasWidth * displayScale) / 2f;
|
||||||
|
displayOffsetY = (getHeight() - canvasHeight * displayScale) / 2f;
|
||||||
|
|
||||||
|
matrix.postTranslate(displayOffsetX, displayOffsetY);
|
||||||
|
matrix.postScale(displayScale, displayScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float screenToImageX(float screenX) {
|
||||||
|
return (screenX - displayOffsetX) / displayScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float screenToImageY(float screenY) {
|
||||||
|
return (screenY - displayOffsetY) / displayScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float imageToScreenX(float imageX) {
|
||||||
|
return imageX * displayScale + displayOffsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float imageToScreenY(float imageY) {
|
||||||
|
return imageY * displayScale + displayOffsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getImageColorAt(float screenX, float screenY) {
|
||||||
|
Bitmap bmp = (displayBitmap != null) ? displayBitmap : originalBitmap;
|
||||||
|
if (bmp == null || bmp.isRecycled()) {
|
||||||
|
return Color.TRANSPARENT;
|
||||||
|
}
|
||||||
|
float imgX = screenToImageX(screenX);
|
||||||
|
float imgY = screenToImageY(screenY);
|
||||||
|
int bmpX = (int) ((imgX - imageBounds.left) * displayBitmapScale);
|
||||||
|
int bmpY = (int) ((imgY - imageBounds.top) * displayBitmapScale);
|
||||||
|
if (bmpX >= 0 && bmpX < bmp.getWidth() &&
|
||||||
|
bmpY >= 0 && bmpY < bmp.getHeight()) {
|
||||||
|
return bmp.getPixel(bmpX, bmpY);
|
||||||
|
}
|
||||||
|
return Color.TRANSPARENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackgroundColor(int color) {
|
||||||
|
this.backgroundColor = color;
|
||||||
|
if (backgroundColorChangedListener != null) {
|
||||||
|
backgroundColorChangedListener.onBackgroundColorChanged(color);
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBackgroundColor() {
|
||||||
|
return backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPreviewColor() {
|
||||||
|
return previewColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLastPickX() {
|
||||||
|
return lastPickX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLastPickY() {
|
||||||
|
return lastPickY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastPickImageX() {
|
||||||
|
if (originalBitmap == null || originalBitmap.isRecycled()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
float imgX = screenToImageX(lastPickX);
|
||||||
|
float imgY = screenToImageY(lastPickY);
|
||||||
|
int bmpX = (int) ((imgX - imageBounds.left) * displayBitmapScale);
|
||||||
|
int bmpY = (int) ((imgY - imageBounds.top) * displayBitmapScale);
|
||||||
|
return Math.max(0, Math.min(bmpX, originalBitmap.getWidth() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastPickImageY() {
|
||||||
|
if (originalBitmap == null || originalBitmap.isRecycled()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
float imgX = screenToImageX(lastPickX);
|
||||||
|
float imgY = screenToImageY(lastPickY);
|
||||||
|
int bmpX = (int) ((imgX - imageBounds.left) * displayBitmapScale);
|
||||||
|
int bmpY = (int) ((imgY - imageBounds.top) * displayBitmapScale);
|
||||||
|
return Math.max(0, Math.min(bmpY, originalBitmap.getHeight() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorPickMode(boolean enable) {
|
||||||
|
this.colorPickMode = enable;
|
||||||
|
if (enable) {
|
||||||
|
pickX = -1;
|
||||||
|
pickY = -1;
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isColorPickMode() {
|
||||||
|
return colorPickMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scaleToView(int viewWidth, int viewHeight) {
|
||||||
|
if (viewWidth > 0 && viewHeight > 0 && canvasWidth > 0 && canvasHeight > 0) {
|
||||||
|
float scale = Math.max((float) viewWidth / canvasWidth, (float) viewHeight / canvasHeight);
|
||||||
|
int oldCanvasW = canvasWidth;
|
||||||
|
int oldCanvasH = canvasHeight;
|
||||||
|
canvasWidth = (int) (canvasWidth * scale);
|
||||||
|
canvasHeight = (int) (canvasHeight * scale);
|
||||||
|
|
||||||
|
float left = (canvasWidth - imageWidth) / 2f;
|
||||||
|
float top = (canvasHeight - imageHeight) / 2f;
|
||||||
|
imageBounds.set(left, top, left + imageWidth, top + imageHeight);
|
||||||
|
canvasBounds.set(0, 0, canvasWidth, canvasHeight);
|
||||||
|
|
||||||
|
if (cropRect != null) {
|
||||||
|
float scaleX = (float) canvasWidth / oldCanvasW;
|
||||||
|
float scaleY = (float) canvasHeight / oldCanvasH;
|
||||||
|
cropRect.left *= scaleX;
|
||||||
|
cropRect.top *= scaleY;
|
||||||
|
cropRect.right *= scaleX;
|
||||||
|
cropRect.bottom *= scaleY;
|
||||||
|
}
|
||||||
|
|
||||||
|
requestLayout();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RectF getCropRect() {
|
||||||
|
return new RectF(cropRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCanvasWidth() {
|
||||||
|
return canvasWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCanvasHeight() {
|
||||||
|
return canvasHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RectF getCanvasBounds() {
|
||||||
|
return new RectF(canvasBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RectF getImageBounds() {
|
||||||
|
return new RectF(imageBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getBitmapScale() {
|
||||||
|
return displayScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getDisplayScale() {
|
||||||
|
return displayScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
int w = canvasWidth > 0 ? canvasWidth : 0;
|
||||||
|
int h = canvasHeight > 0 ? canvasHeight : 0;
|
||||||
|
setMeasuredDimension(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
getDisplayMatrix(new Matrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
|
||||||
|
if (cropRect == null) return;
|
||||||
|
|
||||||
|
if (displayBitmap != null && !displayBitmap.isRecycled()) {
|
||||||
|
canvas.save();
|
||||||
|
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
getDisplayMatrix(matrix);
|
||||||
|
canvas.concat(matrix);
|
||||||
|
|
||||||
|
canvas.drawColor(backgroundColor);
|
||||||
|
|
||||||
|
if (displayBitmap == originalBitmap) {
|
||||||
|
canvas.drawBitmap(displayBitmap, imageBounds.left, imageBounds.top, imagePaint);
|
||||||
|
} else {
|
||||||
|
float invScale = 1f / displayBitmapScale;
|
||||||
|
canvas.save();
|
||||||
|
canvas.scale(invScale, invScale);
|
||||||
|
canvas.drawBitmap(displayBitmap, imageBounds.left * displayBitmapScale,
|
||||||
|
imageBounds.top * displayBitmapScale, imagePaint);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas.restore();
|
||||||
|
|
||||||
|
if (containerScale != 1.0f) {
|
||||||
|
canvas.save();
|
||||||
|
canvas.scale(containerScale, containerScale);
|
||||||
|
canvas.drawRect(cropRect, borderPaint);
|
||||||
|
float cornerRadius = 12f / containerScale;
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.top, cornerRadius, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.top, cornerRadius, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.bottom, cornerRadius, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.bottom, cornerRadius, cornerPaint);
|
||||||
|
canvas.restore();
|
||||||
|
} else {
|
||||||
|
canvas.drawRect(cropRect, borderPaint);
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.top, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.top, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.bottom, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.bottom, 12, cornerPaint);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (containerScale != 1.0f) {
|
||||||
|
canvas.save();
|
||||||
|
canvas.scale(containerScale, containerScale);
|
||||||
|
canvas.drawRect(cropRect, borderPaint);
|
||||||
|
float cornerRadius = 12f / containerScale;
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.top, cornerRadius, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.top, cornerRadius, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.bottom, cornerRadius, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.bottom, cornerRadius, cornerPaint);
|
||||||
|
canvas.restore();
|
||||||
|
} else {
|
||||||
|
canvas.drawRect(cropRect, borderPaint);
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.top, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.top, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.bottom, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.bottom, 12, cornerPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
if (cropRect == null || canvasBounds.isEmpty()) return super.onTouchEvent(event);
|
||||||
|
|
||||||
|
if (event.getPointerCount() == 2) {
|
||||||
|
int action = event.getActionMasked();
|
||||||
|
if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
||||||
|
initialSpan = getSpan(event);
|
||||||
|
return true;
|
||||||
|
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||||
|
float span = getSpan(event);
|
||||||
|
if (initialSpan > 0) {
|
||||||
|
float scale = span / initialSpan;
|
||||||
|
float centerX = cropRect.centerX();
|
||||||
|
float centerY = cropRect.centerY();
|
||||||
|
float newWidth = cropRect.width() * scale;
|
||||||
|
float newHeight = newWidth / coverRatio;
|
||||||
|
|
||||||
|
newWidth = Math.max(minSize, Math.min(newWidth, canvasBounds.width()));
|
||||||
|
newHeight = newWidth / coverRatio;
|
||||||
|
|
||||||
|
float newLeft = centerX - newWidth / 2;
|
||||||
|
float newTop = centerY - newHeight / 2;
|
||||||
|
float newRight = centerX + newWidth / 2;
|
||||||
|
float newBottom = centerY + newHeight / 2;
|
||||||
|
|
||||||
|
if (newLeft >= canvasBounds.left && newRight <= canvasBounds.right &&
|
||||||
|
newTop >= canvasBounds.top && newBottom <= canvasBounds.bottom) {
|
||||||
|
cropRect.set(newLeft, newTop, newRight, newBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
initialSpan = span;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float x = event.getX();
|
||||||
|
float y = event.getY();
|
||||||
|
|
||||||
|
RectF bounds = canvasBounds;
|
||||||
|
if (containerScale != 1.0f) {
|
||||||
|
x = x / containerScale;
|
||||||
|
y = y / containerScale;
|
||||||
|
bounds = new RectF(
|
||||||
|
canvasBounds.left,
|
||||||
|
canvasBounds.top,
|
||||||
|
canvasBounds.right,
|
||||||
|
canvasBounds.bottom
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colorPickMode) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
|
if (originalBitmap != null && !originalBitmap.isRecycled()) {
|
||||||
|
float imgX = screenToImageX(x);
|
||||||
|
float imgY = screenToImageY(y);
|
||||||
|
if (imageBounds.contains(imgX, imgY)) {
|
||||||
|
previewColor = getImageColorAt(x, y);
|
||||||
|
} else if (canvasBounds.contains(x, y)) {
|
||||||
|
previewColor = backgroundColor;
|
||||||
|
} else {
|
||||||
|
previewColor = Color.TRANSPARENT;
|
||||||
|
}
|
||||||
|
lastPickX = x;
|
||||||
|
lastPickY = y;
|
||||||
|
if (backgroundColorChangedListener != null) {
|
||||||
|
backgroundColorChangedListener.onBackgroundColorChanged(previewColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
|
if (canvasBounds.contains(x, y)) {
|
||||||
|
int pickedColor;
|
||||||
|
float imgX = screenToImageX(x);
|
||||||
|
float imgY = screenToImageY(y);
|
||||||
|
if (imageBounds.contains(imgX, imgY)) {
|
||||||
|
int colorAtPoint = getImageColorAt(x, y);
|
||||||
|
pickedColor = colorAtPoint;
|
||||||
|
backgroundColor = colorAtPoint;
|
||||||
|
} else {
|
||||||
|
pickedColor = backgroundColor;
|
||||||
|
}
|
||||||
|
if (colorPickedListener != null) {
|
||||||
|
colorPickedListener.onColorPicked(pickedColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (colorPickEndListener != null) {
|
||||||
|
colorPickEndListener.onColorPickEnd();
|
||||||
|
}
|
||||||
|
previewColor = 0;
|
||||||
|
invalidate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.getAction()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
|
activeCorner = getActiveCorner(x, y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
float dx = x - lastX;
|
||||||
|
float dy = y - lastY;
|
||||||
|
|
||||||
|
if (activeCorner == CORNER_CENTER) {
|
||||||
|
float newLeft = cropRect.left + dx;
|
||||||
|
float newTop = cropRect.top + dy;
|
||||||
|
float newRight = cropRect.right + dx;
|
||||||
|
float newBottom = cropRect.bottom + dy;
|
||||||
|
|
||||||
|
if (newLeft >= bounds.left && newRight <= bounds.right) {
|
||||||
|
cropRect.left = newLeft;
|
||||||
|
cropRect.right = newRight;
|
||||||
|
}
|
||||||
|
if (newTop >= bounds.top && newBottom <= bounds.bottom) {
|
||||||
|
cropRect.top = newTop;
|
||||||
|
cropRect.bottom = newBottom;
|
||||||
|
}
|
||||||
|
} else if (activeCorner == CORNER_TOP_LEFT) {
|
||||||
|
adjustCorner(cropRect.left + dx, cropRect.top + dy, true, true);
|
||||||
|
} else if (activeCorner == CORNER_TOP_RIGHT) {
|
||||||
|
adjustCorner(cropRect.right + dx, cropRect.top + dy, false, true);
|
||||||
|
} else if (activeCorner == CORNER_BOTTOM_LEFT) {
|
||||||
|
adjustCorner(cropRect.left + dx, cropRect.bottom + dy, true, false);
|
||||||
|
} else if (activeCorner == CORNER_BOTTOM_RIGHT) {
|
||||||
|
adjustCorner(cropRect.right + dx, cropRect.bottom + dy, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
|
invalidate();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
activeCorner = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void adjustCorner(float nx, float ny, boolean left, boolean top) {
|
||||||
|
float newWidth;
|
||||||
|
float newLeft = cropRect.left;
|
||||||
|
float newTop = cropRect.top;
|
||||||
|
float newRight = cropRect.right;
|
||||||
|
float newBottom = cropRect.bottom;
|
||||||
|
|
||||||
|
if (left) {
|
||||||
|
newWidth = cropRect.width() - (nx - cropRect.left);
|
||||||
|
newLeft = Math.max(canvasBounds.left, Math.min(nx, cropRect.right - minSize));
|
||||||
|
} else {
|
||||||
|
newWidth = nx - cropRect.left;
|
||||||
|
newRight = Math.min(canvasBounds.right, Math.max(nx, cropRect.left + minSize));
|
||||||
|
newLeft = cropRect.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
float newHeight = newWidth / coverRatio;
|
||||||
|
|
||||||
|
if (top) {
|
||||||
|
newTop = Math.max(canvasBounds.top, Math.min(cropRect.bottom - minSize, cropRect.bottom - newHeight));
|
||||||
|
newBottom = newTop + newHeight;
|
||||||
|
} else {
|
||||||
|
newBottom = Math.min(canvasBounds.bottom, Math.max(cropRect.top + minSize, cropRect.top + newHeight));
|
||||||
|
newTop = newBottom - newHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left) {
|
||||||
|
cropRect.left = newLeft;
|
||||||
|
cropRect.right = newLeft + newWidth;
|
||||||
|
} else {
|
||||||
|
cropRect.right = newRight;
|
||||||
|
cropRect.left = newRight - newWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (top) {
|
||||||
|
cropRect.top = newTop;
|
||||||
|
cropRect.bottom = newTop + newHeight;
|
||||||
|
} else {
|
||||||
|
cropRect.bottom = newBottom;
|
||||||
|
cropRect.top = newBottom - newHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getActiveCorner(float x, float y) {
|
||||||
|
float dx = Math.abs(x - cropRect.left);
|
||||||
|
float dy = Math.abs(y - cropRect.top);
|
||||||
|
float dx2 = Math.abs(x - cropRect.right);
|
||||||
|
float dy2 = Math.abs(y - cropRect.bottom);
|
||||||
|
|
||||||
|
if (dx <= touchArea && dy <= touchArea) {
|
||||||
|
return CORNER_TOP_LEFT;
|
||||||
|
}
|
||||||
|
if (dx2 <= touchArea && dy <= touchArea) {
|
||||||
|
return CORNER_TOP_RIGHT;
|
||||||
|
}
|
||||||
|
if (dx <= touchArea && dy2 <= touchArea) {
|
||||||
|
return CORNER_BOTTOM_LEFT;
|
||||||
|
}
|
||||||
|
if (dx2 <= touchArea && dy2 <= touchArea) {
|
||||||
|
return CORNER_BOTTOM_RIGHT;
|
||||||
|
}
|
||||||
|
if (x > cropRect.left && x < cropRect.right && y > cropRect.top && y < cropRect.bottom) {
|
||||||
|
return CORNER_CENTER;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getSpan(MotionEvent event) {
|
||||||
|
float x0 = event.getX(0);
|
||||||
|
float y0 = event.getY(0);
|
||||||
|
float x1 = event.getX(1);
|
||||||
|
float y1 = event.getY(1);
|
||||||
|
return (float) Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorAt(float x, float y) {
|
||||||
|
return getImageColorAt(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class CropOverlayView extends View {
|
||||||
|
public interface OnCanvasSizeChangedListener {
|
||||||
|
void onCanvasSizeChanged(RectF canvasBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OnCanvasSizeChangedListener canvasSizeChangedListener;
|
||||||
|
|
||||||
|
private Paint borderPaint;
|
||||||
|
private Paint cornerPaint;
|
||||||
|
private RectF cropRect;
|
||||||
|
private int touchArea = 50;
|
||||||
|
|
||||||
|
private float lastX, lastY;
|
||||||
|
private int activeCorner = -1;
|
||||||
|
private static final int CORNER_TOP_LEFT = 0;
|
||||||
|
private static final int CORNER_TOP_RIGHT = 1;
|
||||||
|
private static final int CORNER_BOTTOM_LEFT = 2;
|
||||||
|
private static final int CORNER_BOTTOM_RIGHT = 3;
|
||||||
|
private static final int CORNER_CENTER = 4;
|
||||||
|
|
||||||
|
private float targetRatio = 2.0f;
|
||||||
|
private RectF canvasBounds = new RectF();
|
||||||
|
private float minSize = 50;
|
||||||
|
|
||||||
|
public CropOverlayView(Context context) {
|
||||||
|
super(context);
|
||||||
|
initPaints();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropOverlayView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initPaints();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropOverlayView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
initPaints();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initPaints() {
|
||||||
|
borderPaint = new Paint();
|
||||||
|
borderPaint.setColor(Color.parseColor("#CCAA00"));
|
||||||
|
borderPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
borderPaint.setStrokeWidth(3);
|
||||||
|
|
||||||
|
cornerPaint = new Paint();
|
||||||
|
cornerPaint.setColor(Color.WHITE);
|
||||||
|
cornerPaint.setStyle(Paint.Style.FILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetRatio(float ratio) {
|
||||||
|
this.targetRatio = ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTargetRatio() {
|
||||||
|
return targetRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnCanvasSizeChangedListener(OnCanvasSizeChangedListener listener) {
|
||||||
|
this.canvasSizeChangedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initCanvas(int canvasW, int canvasH) {
|
||||||
|
canvasBounds.set(0, 0, canvasW, canvasH);
|
||||||
|
|
||||||
|
cropRect = new RectF(0, 0, canvasW, canvasH);
|
||||||
|
|
||||||
|
if (canvasSizeChangedListener != null) {
|
||||||
|
canvasSizeChangedListener.onCanvasSizeChanged(new RectF(canvasBounds));
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RectF getCropRect() {
|
||||||
|
return new RectF(cropRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RectF getCanvasBounds() {
|
||||||
|
return new RectF(canvasBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
|
||||||
|
canvas.drawColor(Color.TRANSPARENT);
|
||||||
|
|
||||||
|
if (cropRect != null) {
|
||||||
|
canvas.drawRect(cropRect, borderPaint);
|
||||||
|
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.top, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.top, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.left, cropRect.bottom, 12, cornerPaint);
|
||||||
|
canvas.drawCircle(cropRect.right, cropRect.bottom, 12, cornerPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
if (cropRect == null || canvasBounds.isEmpty()) return false;
|
||||||
|
|
||||||
|
float x = event.getX();
|
||||||
|
float y = event.getY();
|
||||||
|
|
||||||
|
switch (event.getAction()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
|
activeCorner = getActiveCorner(x, y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
float dx = x - lastX;
|
||||||
|
float dy = y - lastY;
|
||||||
|
|
||||||
|
if (activeCorner == CORNER_CENTER) {
|
||||||
|
float newLeft = cropRect.left + dx;
|
||||||
|
float newTop = cropRect.top + dy;
|
||||||
|
float newRight = cropRect.right + dx;
|
||||||
|
float newBottom = cropRect.bottom + dy;
|
||||||
|
|
||||||
|
if (newLeft >= canvasBounds.left && newRight <= canvasBounds.right) {
|
||||||
|
cropRect.left = newLeft;
|
||||||
|
cropRect.right = newRight;
|
||||||
|
}
|
||||||
|
if (newTop >= canvasBounds.top && newBottom <= canvasBounds.bottom) {
|
||||||
|
cropRect.top = newTop;
|
||||||
|
cropRect.bottom = newBottom;
|
||||||
|
}
|
||||||
|
} else if (activeCorner == CORNER_TOP_LEFT) {
|
||||||
|
adjustCorner(cropRect.left + dx, cropRect.top + dy, true, true);
|
||||||
|
} else if (activeCorner == CORNER_TOP_RIGHT) {
|
||||||
|
adjustCorner(cropRect.right + dx, cropRect.top + dy, false, true);
|
||||||
|
} else if (activeCorner == CORNER_BOTTOM_LEFT) {
|
||||||
|
adjustCorner(cropRect.left + dx, cropRect.bottom + dy, true, false);
|
||||||
|
} else if (activeCorner == CORNER_BOTTOM_RIGHT) {
|
||||||
|
adjustCorner(cropRect.right + dx, cropRect.bottom + dy, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
|
invalidate();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
activeCorner = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void adjustCorner(float nx, float ny, boolean left, boolean top) {
|
||||||
|
float newWidth;
|
||||||
|
float newLeft = cropRect.left;
|
||||||
|
float newTop = cropRect.top;
|
||||||
|
float newRight = cropRect.right;
|
||||||
|
float newBottom = cropRect.bottom;
|
||||||
|
|
||||||
|
if (left) {
|
||||||
|
newWidth = cropRect.width() - (nx - cropRect.left);
|
||||||
|
newLeft = Math.max(canvasBounds.left, Math.min(nx, cropRect.right - minSize));
|
||||||
|
} else {
|
||||||
|
newWidth = nx - cropRect.left;
|
||||||
|
newRight = Math.min(canvasBounds.right, Math.max(nx, cropRect.left + minSize));
|
||||||
|
newLeft = cropRect.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
float newHeight = newWidth / targetRatio;
|
||||||
|
|
||||||
|
if (top) {
|
||||||
|
newTop = Math.max(canvasBounds.top, Math.min(cropRect.bottom - minSize, cropRect.bottom - newHeight));
|
||||||
|
newBottom = newTop + newHeight;
|
||||||
|
} else {
|
||||||
|
newBottom = Math.min(canvasBounds.bottom, Math.max(cropRect.top + minSize, cropRect.top + newHeight));
|
||||||
|
newTop = newBottom - newHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left) {
|
||||||
|
cropRect.left = newLeft;
|
||||||
|
cropRect.right = newLeft + newWidth;
|
||||||
|
} else {
|
||||||
|
cropRect.right = newRight;
|
||||||
|
cropRect.left = newRight - newWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (top) {
|
||||||
|
cropRect.top = newTop;
|
||||||
|
cropRect.bottom = newTop + newHeight;
|
||||||
|
} else {
|
||||||
|
cropRect.bottom = newBottom;
|
||||||
|
cropRect.top = newBottom - newHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getActiveCorner(float x, float y) {
|
||||||
|
if (Math.abs(x - cropRect.left) <= touchArea && Math.abs(y - cropRect.top) <= touchArea) {
|
||||||
|
return CORNER_TOP_LEFT;
|
||||||
|
}
|
||||||
|
if (Math.abs(x - cropRect.right) <= touchArea && Math.abs(y - cropRect.top) <= touchArea) {
|
||||||
|
return CORNER_TOP_RIGHT;
|
||||||
|
}
|
||||||
|
if (Math.abs(x - cropRect.left) <= touchArea && Math.abs(y - cropRect.bottom) <= touchArea) {
|
||||||
|
return CORNER_BOTTOM_LEFT;
|
||||||
|
}
|
||||||
|
if (Math.abs(x - cropRect.right) <= touchArea && Math.abs(y - cropRect.bottom) <= touchArea) {
|
||||||
|
return CORNER_BOTTOM_RIGHT;
|
||||||
|
}
|
||||||
|
if (cropRect.contains(x, y)) {
|
||||||
|
return CORNER_CENTER;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package cc.winboll.studio.gallery;
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -10,6 +12,8 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
@@ -20,6 +24,9 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
|||||||
private OnImageClickListener listener;
|
private OnImageClickListener listener;
|
||||||
private int bgType = 0;
|
private int bgType = 0;
|
||||||
private Preferences prefs;
|
private Preferences prefs;
|
||||||
|
private PinnedImageDbHelper pinnedDbHelper;
|
||||||
|
private AlbumCoverDbHelper coverDbHelper;
|
||||||
|
private String albumPath;
|
||||||
|
|
||||||
private int getBgRes() {
|
private int getBgRes() {
|
||||||
switch (bgType) {
|
switch (bgType) {
|
||||||
@@ -45,13 +52,55 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
|||||||
public void setData(ArrayList<Uri> urls, ArrayList<String> paths) {
|
public void setData(ArrayList<Uri> urls, ArrayList<String> paths) {
|
||||||
this.imageUrls = urls;
|
this.imageUrls = urls;
|
||||||
this.imagePaths = paths;
|
this.imagePaths = paths;
|
||||||
|
sortPinnedFirst();
|
||||||
LogUtils.d(TAG, "setData: " + urls.size() + " images");
|
LogUtils.d(TAG, "setData: " + urls.size() + " images");
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sortPinnedFirst() {
|
||||||
|
if (pinnedDbHelper == null || imagePaths.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ArrayList<Uri> pinnedUrls = new ArrayList<>();
|
||||||
|
ArrayList<String> pinnedPaths = new ArrayList<>();
|
||||||
|
ArrayList<Uri> unpinnedUrls = new ArrayList<>();
|
||||||
|
ArrayList<String> unpinnedPaths = new ArrayList<>();
|
||||||
|
for (int i = 0; i < imagePaths.size(); i++) {
|
||||||
|
String path = imagePaths.get(i);
|
||||||
|
if (pinnedDbHelper.isPinned(path)) {
|
||||||
|
pinnedUrls.add(imageUrls.get(i));
|
||||||
|
pinnedPaths.add(path);
|
||||||
|
} else {
|
||||||
|
unpinnedUrls.add(imageUrls.get(i));
|
||||||
|
unpinnedPaths.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
imageUrls.clear();
|
||||||
|
imagePaths.clear();
|
||||||
|
imageUrls.addAll(pinnedUrls);
|
||||||
|
imageUrls.addAll(unpinnedUrls);
|
||||||
|
imagePaths.addAll(pinnedPaths);
|
||||||
|
imagePaths.addAll(unpinnedPaths);
|
||||||
|
}
|
||||||
|
|
||||||
public void setContext(android.content.Context context) {
|
public void setContext(android.content.Context context) {
|
||||||
prefs = new Preferences(context);
|
prefs = new Preferences(context);
|
||||||
bgType = prefs.getBgType();
|
bgType = prefs.getBgType();
|
||||||
|
pinnedDbHelper = PinnedImageDbHelper.getInstance(context);
|
||||||
|
coverDbHelper = AlbumCoverDbHelper.getInstance(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumPath(String albumPath) {
|
||||||
|
this.albumPath = albumPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCropWidth() {
|
||||||
|
return prefs != null ? prefs.getCoverWidth() : 240;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCropHeight() {
|
||||||
|
return prefs != null ? prefs.getCoverHeight() : 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshBg() {
|
public void refreshBg() {
|
||||||
@@ -61,6 +110,75 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshPinned() {
|
||||||
|
if (pinnedDbHelper == null || imagePaths.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sortPinnedFirst();
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showContextMenu(View view, final int position) {
|
||||||
|
final String imagePath = imagePaths.get(position);
|
||||||
|
final Uri imageUri = imageUrls.get(position);
|
||||||
|
final boolean[] isPinned = {pinnedDbHelper != null && pinnedDbHelper.isPinned(imagePath)};
|
||||||
|
final boolean[] isCover = {false};
|
||||||
|
if (coverDbHelper != null && albumPath != null) {
|
||||||
|
String originalPath = coverDbHelper.getOriginalImagePath(albumPath);
|
||||||
|
isCover[0] = originalPath != null && originalPath.equals(imagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(view.getContext());
|
||||||
|
builder.setTitle("Image");
|
||||||
|
|
||||||
|
String[] items;
|
||||||
|
if (isPinned[0]) {
|
||||||
|
if (isCover[0]) {
|
||||||
|
items = new String[]{"取消置顶", "调整封面", "取消封面"};
|
||||||
|
} else {
|
||||||
|
items = new String[]{"取消置顶", "设置为封面"};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isCover[0]) {
|
||||||
|
items = new String[]{"置顶", "调整封面", "取消封面"};
|
||||||
|
} else {
|
||||||
|
items = new String[]{"置顶", "设置为封面"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setItems(items, new android.content.DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(android.content.DialogInterface dialog, int which) {
|
||||||
|
if (which == 0) {
|
||||||
|
if (pinnedDbHelper != null) {
|
||||||
|
if (isPinned[0]) {
|
||||||
|
pinnedDbHelper.unpinImage(imagePath);
|
||||||
|
} else {
|
||||||
|
pinnedDbHelper.pinImage(imagePath);
|
||||||
|
}
|
||||||
|
refreshPinned();
|
||||||
|
}
|
||||||
|
} else if (which == 1) {
|
||||||
|
if (coverDbHelper != null && albumPath != null) {
|
||||||
|
Intent cropIntent = new Intent(view.getContext(), CropActivity.class);
|
||||||
|
cropIntent.putExtra(CropActivity.EXTRA_IMAGE_URI, imageUri);
|
||||||
|
cropIntent.putExtra(CropActivity.EXTRA_IMAGE_PATH, imagePath);
|
||||||
|
cropIntent.putExtra(CropActivity.EXTRA_ALBUM_PATH, albumPath);
|
||||||
|
cropIntent.putExtra(CropActivity.EXTRA_CROP_WIDTH, getCropWidth());
|
||||||
|
cropIntent.putExtra(CropActivity.EXTRA_CROP_HEIGHT, getCropHeight());
|
||||||
|
((AlbumActivity) view.getContext()).startActivityForResult(cropIntent, 100);
|
||||||
|
}
|
||||||
|
} else if (which == 2) {
|
||||||
|
if (coverDbHelper != null && albumPath != null && isCover[0]) {
|
||||||
|
coverDbHelper.deleteCover(albumPath);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
@@ -80,7 +198,19 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
|||||||
|
|
||||||
final ArrayList<Uri> urls = imageUrls;
|
final ArrayList<Uri> urls = imageUrls;
|
||||||
final ArrayList<String> paths = imagePaths;
|
final ArrayList<String> paths = imagePaths;
|
||||||
holder.imageView.setOnClickListener(new OnClickListener() {
|
final String imagePath = imagePaths.get(position);
|
||||||
|
|
||||||
|
boolean isPinned = pinnedDbHelper != null && pinnedDbHelper.isPinned(imagePath);
|
||||||
|
holder.pinIcon.setVisibility(isPinned ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
boolean isCover = false;
|
||||||
|
if (coverDbHelper != null && albumPath != null) {
|
||||||
|
String originalPath = coverDbHelper.getOriginalImagePath(albumPath);
|
||||||
|
isCover = originalPath != null && originalPath.equals(imagePath);
|
||||||
|
}
|
||||||
|
holder.coverIcon.setVisibility(isCover ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
holder.itemView.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
@@ -88,6 +218,14 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showContextMenu(holder.itemView, position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -97,9 +235,13 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
|||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
ImageView imageView;
|
ImageView imageView;
|
||||||
|
ImageView pinIcon;
|
||||||
|
ImageView coverIcon;
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
imageView = itemView.findViewById(R.id.image);
|
imageView = itemView.findViewById(R.id.image);
|
||||||
|
pinIcon = itemView.findViewById(R.id.pin_icon);
|
||||||
|
coverIcon = itemView.findViewById(R.id.cover_icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package cc.winboll.studio.gallery;
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.media.MediaScannerConnection;
|
import android.media.MediaScannerConnection;
|
||||||
@@ -14,6 +17,7 @@ import android.provider.MediaStore;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@@ -22,6 +26,7 @@ import androidx.core.app.ActivityCompat;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import cc.winboll.studio.gallery.AlbumAdapter.OnAlbumClickListener;
|
import cc.winboll.studio.gallery.AlbumAdapter.OnAlbumClickListener;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.LogActivity;
|
import cc.winboll.studio.libappbase.LogActivity;
|
||||||
@@ -37,6 +42,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private AlbumAdapter adapter;
|
private AlbumAdapter adapter;
|
||||||
private Preferences prefs;
|
private Preferences prefs;
|
||||||
|
private FloatingActionButton fabScrollTop;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -55,6 +61,30 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
adapter.setContext(this);
|
adapter.setContext(this);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
fabScrollTop = findViewById(R.id.fab_scroll_top);
|
||||||
|
fabScrollTop.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
recyclerView.scrollToPosition(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
|
GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
|
||||||
|
if (layoutManager != null) {
|
||||||
|
int firstVisible = layoutManager.findFirstVisibleItemPosition();
|
||||||
|
if (firstVisible > 0) {
|
||||||
|
fabScrollTop.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
fabScrollTop.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
adapter.setOnAlbumClickListener(new OnAlbumClickListener() {
|
adapter.setOnAlbumClickListener(new OnAlbumClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAlbumClick(Album album) {
|
public void onAlbumClick(Album album) {
|
||||||
@@ -149,6 +179,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AlbumCoverDbHelper coverDbHelper = AlbumCoverDbHelper.getInstance(this);
|
||||||
ArrayList<Album> albums = new ArrayList<>();
|
ArrayList<Album> albums = new ArrayList<>();
|
||||||
|
|
||||||
FileFilter directoryFilter = new FileFilter() {
|
FileFilter directoryFilter = new FileFilter() {
|
||||||
@@ -162,11 +193,34 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
if (subfolders != null) {
|
if (subfolders != null) {
|
||||||
for (File subfolder : subfolders) {
|
for (File subfolder : subfolders) {
|
||||||
LogUtils.d(TAG, "scanning folder: " + subfolder.getName());
|
LogUtils.d(TAG, "scanning folder: " + subfolder.getName());
|
||||||
ArrayList<Uri> images = getImagesInFolder(subfolder.getAbsolutePath());
|
String albumPath = subfolder.getAbsolutePath();
|
||||||
|
String coverPath = coverDbHelper.getCover(albumPath);
|
||||||
|
LogUtils.d(TAG, "loadAlbums: album=" + albumPath + ", coverPath=" + coverPath);
|
||||||
|
Uri coverUri = null;
|
||||||
|
if (coverPath != null) {
|
||||||
|
File coverFile = new File(coverPath);
|
||||||
|
if (coverFile.exists()) {
|
||||||
|
coverUri = Uri.fromFile(coverFile);
|
||||||
|
LogUtils.d(TAG, "loadAlbums: cover from file=" + coverFile.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
coverUri = getUriFromPath(coverPath);
|
||||||
|
LogUtils.d(TAG, "loadAlbums: cover from media store path=" + coverPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (coverUri == null) {
|
||||||
|
ArrayList<Uri> images = getImagesInFolder(albumPath);
|
||||||
if (!images.isEmpty()) {
|
if (!images.isEmpty()) {
|
||||||
Uri latestImage = images.get(0);
|
coverUri = images.get(0);
|
||||||
albums.add(new Album(subfolder.getName(), subfolder.getAbsolutePath(), latestImage, images.size()));
|
}
|
||||||
LogUtils.d(TAG, "album added: " + subfolder.getName() + ", " + images.size() + " images");
|
}
|
||||||
|
ArrayList<Uri> allImages = getImagesInFolder(albumPath);
|
||||||
|
if (coverUri != null || !allImages.isEmpty()) {
|
||||||
|
if (coverUri == null && !allImages.isEmpty()) {
|
||||||
|
coverUri = allImages.get(0);
|
||||||
|
}
|
||||||
|
int imageCount = allImages.size();
|
||||||
|
albums.add(new Album(subfolder.getName(), albumPath, coverUri, imageCount));
|
||||||
|
LogUtils.d(TAG, "album added: " + subfolder.getName() + ", " + imageCount + " images");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,6 +233,23 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
LogUtils.d(TAG, "Loaded " + albums.size() + " albums");
|
LogUtils.d(TAG, "Loaded " + albums.size() + " albums");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Uri getUriFromPath(String path) {
|
||||||
|
String[] projection = { MediaStore.Images.Media._ID };
|
||||||
|
String selection = MediaStore.Images.Media.DATA + " = ?";
|
||||||
|
String[] selectionArgs = { path };
|
||||||
|
try (Cursor cursor = getContentResolver().query(
|
||||||
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||||
|
projection, selection, selectionArgs, null)) {
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
long id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
|
||||||
|
return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private ArrayList<Uri> getImagesInFolder(String folderPath) {
|
private ArrayList<Uri> getImagesInFolder(String folderPath) {
|
||||||
ArrayList<Uri> imageUrls = new ArrayList<>();
|
ArrayList<Uri> imageUrls = new ArrayList<>();
|
||||||
ContentResolver contentResolver = getContentResolver();
|
ContentResolver contentResolver = getContentResolver();
|
||||||
@@ -221,35 +292,49 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
if (id == R.id.action_settings) {
|
if (id == R.id.action_settings) {
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
return true;
|
return true;
|
||||||
|
} else if (id == R.id.action_about) {
|
||||||
|
startActivity(new Intent(this, AboutActivity.class));
|
||||||
|
return true;
|
||||||
} else if (id == R.id.action_trash) {
|
} else if (id == R.id.action_trash) {
|
||||||
startActivity(new Intent(this, TrashActivity.class));
|
startActivity(new Intent(this, TrashActivity.class));
|
||||||
return true;
|
return true;
|
||||||
} else if (id == R.id.action_refresh) {
|
|
||||||
if (checkPermission()) {
|
|
||||||
loadAlbums();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (id == R.id.action_debug) {
|
} else if (id == R.id.action_debug) {
|
||||||
LogActivity.startLogActivity(this);
|
LogActivity.startLogActivity(this);
|
||||||
// Log.d("Gallery", "Debug log message");
|
|
||||||
// Toast.makeText(this, R.string.debug_message, Toast.LENGTH_SHORT).show();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BroadcastReceiver coverUpdatedReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (Preferences.ACTION_COVER_UPDATED.equals(intent.getAction())) {
|
||||||
|
loadAlbums();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
registerReceiver(coverUpdatedReceiver, new IntentFilter(Preferences.ACTION_COVER_UPDATED));
|
||||||
if (checkPermission()) {
|
if (checkPermission()) {
|
||||||
scanMediaStore();
|
scanMediaStore();
|
||||||
loadAlbums();
|
loadAlbums();
|
||||||
}
|
}
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
adapter.refreshBg();
|
adapter.refreshBg();
|
||||||
|
adapter.refreshPinned();
|
||||||
|
adapter.refreshCover();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
unregisterReceiver(coverUpdatedReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
private void scanMediaStore() {
|
private void scanMediaStore() {
|
||||||
String folderPath = prefs.getFolderPath();
|
String folderPath = prefs.getFolderPath();
|
||||||
File baseFolder = new File(folderPath);
|
File baseFolder = new File(folderPath);
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
|
public class PinnedAlbumDbHelper extends SQLiteOpenHelper {
|
||||||
|
public static final String TAG = "PinnedAlbumDbHelper";
|
||||||
|
private static final String DB_NAME = "pinned_album.db";
|
||||||
|
private static final int DB_VERSION = 1;
|
||||||
|
private static final String TABLE_NAME = "pinned_albums";
|
||||||
|
private static final String COLUMN_PATH = "album_path";
|
||||||
|
|
||||||
|
private static final String SQL_CREATE = "CREATE TABLE " + TABLE_NAME + " ("
|
||||||
|
+ COLUMN_PATH + " TEXT PRIMARY KEY)";
|
||||||
|
|
||||||
|
private static PinnedAlbumDbHelper dbHelper;
|
||||||
|
|
||||||
|
public static PinnedAlbumDbHelper getInstance(Context context) {
|
||||||
|
if (dbHelper == null) {
|
||||||
|
dbHelper = new PinnedAlbumDbHelper(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
return dbHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PinnedAlbumDbHelper(Context context) {
|
||||||
|
super(context, DB_NAME, null, DB_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
db.execSQL(SQL_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pinAlbum(String albumPath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(COLUMN_PATH, albumPath);
|
||||||
|
db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
|
||||||
|
LogUtils.d(TAG, "pinAlbum: " + albumPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unpinAlbum(String albumPath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
db.delete(TABLE_NAME, COLUMN_PATH + " = ?", new String[]{albumPath});
|
||||||
|
LogUtils.d(TAG, "unpinAlbum: " + albumPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPinned(String albumPath) {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, null, COLUMN_PATH + " = ?",
|
||||||
|
new String[]{albumPath}, null, null, null);
|
||||||
|
boolean pinned = cursor.getCount() > 0;
|
||||||
|
cursor.close();
|
||||||
|
return pinned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getPinnedPaths() {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_PATH}, null, null, null, null, null);
|
||||||
|
String[] paths = new String[cursor.getCount()];
|
||||||
|
int i = 0;
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
paths[i++] = cursor.getString(0);
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
|
public class PinnedImageDbHelper extends SQLiteOpenHelper {
|
||||||
|
public static final String TAG = "PinnedImageDbHelper";
|
||||||
|
private static final String DB_NAME = "pinned_image.db";
|
||||||
|
private static final int DB_VERSION = 1;
|
||||||
|
private static final String TABLE_NAME = "pinned_images";
|
||||||
|
private static final String COLUMN_PATH = "image_path";
|
||||||
|
|
||||||
|
private static final String SQL_CREATE = "CREATE TABLE " + TABLE_NAME + " ("
|
||||||
|
+ COLUMN_PATH + " TEXT PRIMARY KEY)";
|
||||||
|
|
||||||
|
private static PinnedImageDbHelper dbHelper;
|
||||||
|
|
||||||
|
public static PinnedImageDbHelper getInstance(Context context) {
|
||||||
|
if (dbHelper == null) {
|
||||||
|
dbHelper = new PinnedImageDbHelper(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
return dbHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PinnedImageDbHelper(Context context) {
|
||||||
|
super(context, DB_NAME, null, DB_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
db.execSQL(SQL_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pinImage(String imagePath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(COLUMN_PATH, imagePath);
|
||||||
|
db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
|
||||||
|
LogUtils.d(TAG, "pinImage: " + imagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unpinImage(String imagePath) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
db.delete(TABLE_NAME, COLUMN_PATH + " = ?", new String[]{imagePath});
|
||||||
|
LogUtils.d(TAG, "unpinImage: " + imagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPinned(String imagePath) {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, null, COLUMN_PATH + " = ?",
|
||||||
|
new String[]{imagePath}, null, null, null);
|
||||||
|
boolean pinned = cursor.getCount() > 0;
|
||||||
|
cursor.close();
|
||||||
|
return pinned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getPinnedPaths() {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_PATH}, null, null, null, null, null);
|
||||||
|
String[] paths = new String[cursor.getCount()];
|
||||||
|
int i = 0;
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
paths[i++] = cursor.getString(0);
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,25 @@ public class Preferences {
|
|||||||
private static final String PREF_NAME = "gallery_prefs";
|
private static final String PREF_NAME = "gallery_prefs";
|
||||||
private static final String KEY_FOLDER_PATH = "folder_path";
|
private static final String KEY_FOLDER_PATH = "folder_path";
|
||||||
private static final String KEY_BG_TYPE = "bg_type";
|
private static final String KEY_BG_TYPE = "bg_type";
|
||||||
|
private static final String KEY_ALBUM_SORT_MODE = "album_sort_mode";
|
||||||
|
private static final String KEY_COVER_WIDTH = "cover_width";
|
||||||
|
private static final String KEY_COVER_HEIGHT = "cover_height";
|
||||||
|
private static final String KEY_COVER_RATIO = "cover_ratio";
|
||||||
|
|
||||||
|
public static final String ACTION_COVER_UPDATED = "cc.winboll.studio.gallery.COVER_UPDATED";
|
||||||
|
|
||||||
private static final int DEFAULT_BG_TYPE = 0;
|
private static final int DEFAULT_BG_TYPE = 0;
|
||||||
|
private static final int DEFAULT_SORT_MODE = 0;
|
||||||
|
private static final int DEFAULT_COVER_WIDTH = 240;
|
||||||
|
private static final int DEFAULT_COVER_HEIGHT = 120;
|
||||||
|
private static final float DEFAULT_COVER_RATIO = 2.0f;
|
||||||
private static final String DEFAULT_PATH = "/storage/emulated/0/Pictures/Gallery/owner";
|
private static final String DEFAULT_PATH = "/storage/emulated/0/Pictures/Gallery/owner";
|
||||||
|
|
||||||
|
public static final int SORT_TIME_DESC = 0;
|
||||||
|
public static final int SORT_TIME_ASC = 1;
|
||||||
|
public static final int SORT_NAME_DESC = 2;
|
||||||
|
public static final int SORT_NAME_ASC = 3;
|
||||||
|
|
||||||
public static String getDefaultPath() {
|
public static String getDefaultPath() {
|
||||||
return DEFAULT_PATH;
|
return DEFAULT_PATH;
|
||||||
}
|
}
|
||||||
@@ -41,4 +57,37 @@ public class Preferences {
|
|||||||
LogUtils.d(TAG, "setBgType: " + type);
|
LogUtils.d(TAG, "setBgType: " + type);
|
||||||
prefs.edit().putInt(KEY_BG_TYPE, type).apply();
|
prefs.edit().putInt(KEY_BG_TYPE, type).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAlbumSortMode() {
|
||||||
|
return prefs.getInt(KEY_ALBUM_SORT_MODE, DEFAULT_SORT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumSortMode(int mode) {
|
||||||
|
LogUtils.d(TAG, "setAlbumSortMode: " + mode);
|
||||||
|
prefs.edit().putInt(KEY_ALBUM_SORT_MODE, mode).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCoverWidth() {
|
||||||
|
return prefs.getInt(KEY_COVER_WIDTH, DEFAULT_COVER_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoverWidth(int width) {
|
||||||
|
prefs.edit().putInt(KEY_COVER_WIDTH, width).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCoverHeight() {
|
||||||
|
return prefs.getInt(KEY_COVER_HEIGHT, DEFAULT_COVER_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoverHeight(int height) {
|
||||||
|
prefs.edit().putInt(KEY_COVER_HEIGHT, height).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCoverRatio() {
|
||||||
|
return prefs.getFloat(KEY_COVER_RATIO, DEFAULT_COVER_RATIO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoverRatio(float ratio) {
|
||||||
|
prefs.edit().putFloat(KEY_COVER_RATIO, ratio).apply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package cc.winboll.studio.gallery;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.GestureDetector;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.ScaleGestureDetector;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
public class ZoomContainerView extends FrameLayout {
|
||||||
|
private float scaleFactor = 1.0f;
|
||||||
|
private float minScale = 0.1f;
|
||||||
|
private float maxScale = 5.0f;
|
||||||
|
private static final float ZOOM_STEP = 0.25f;
|
||||||
|
|
||||||
|
private ScaleGestureDetector scaleGestureDetector;
|
||||||
|
private GestureDetector gestureDetector;
|
||||||
|
private Paint borderPaint;
|
||||||
|
|
||||||
|
public ZoomContainerView(Context context) {
|
||||||
|
super(context);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZoomContainerView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZoomContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
setWillNotDraw(false);
|
||||||
|
setBackgroundColor(Color.YELLOW);
|
||||||
|
|
||||||
|
borderPaint = new Paint();
|
||||||
|
borderPaint.setColor(Color.parseColor("#333333"));
|
||||||
|
borderPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
borderPaint.setStrokeWidth(2);
|
||||||
|
|
||||||
|
scaleGestureDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onScale(ScaleGestureDetector detector) {
|
||||||
|
scaleFactor *= detector.getScaleFactor();
|
||||||
|
scaleFactor = Math.max(minScale, Math.min(scaleFactor, maxScale));
|
||||||
|
invalidate();
|
||||||
|
requestLayout();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
|
if (scaleFactor > 1.5f) {
|
||||||
|
scaleFactor = 1.0f;
|
||||||
|
} else {
|
||||||
|
scaleFactor = 2.0f;
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
requestLayout();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zoomIn() {
|
||||||
|
scaleFactor = Math.min(maxScale, scaleFactor + ZOOM_STEP);
|
||||||
|
requestMeasure();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zoomOut() {
|
||||||
|
scaleFactor = Math.max(minScale, scaleFactor - ZOOM_STEP);
|
||||||
|
requestMeasure();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestMeasure() {
|
||||||
|
removeCallbacks(measureRunable);
|
||||||
|
post(measureRunable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Runnable measureRunable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
requestLayout();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public float getScaleFactor() {
|
||||||
|
return scaleFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScaleFactor(float scale) {
|
||||||
|
scaleFactor = Math.max(minScale, Math.min(scale, maxScale));
|
||||||
|
int childCount = getChildCount();
|
||||||
|
if (childCount > 0) {
|
||||||
|
View child = getChildAt(0);
|
||||||
|
if (child instanceof CropCanvasView) {
|
||||||
|
((CropCanvasView) child).setContainerScale(scaleFactor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requestLayout();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetZoom() {
|
||||||
|
scaleFactor = 1.0f;
|
||||||
|
invalidate();
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
int childCount = getChildCount();
|
||||||
|
if (childCount > 0) {
|
||||||
|
View child = getChildAt(0);
|
||||||
|
child.measure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
int childW = child.getMeasuredWidth();
|
||||||
|
int childH = child.getMeasuredHeight();
|
||||||
|
int scaledW = (int) (childW * scaleFactor);
|
||||||
|
int scaledH = (int) (childH * scaleFactor);
|
||||||
|
int widthSpec = MeasureSpec.makeMeasureSpec(scaledW, MeasureSpec.EXACTLY);
|
||||||
|
int heightSpec = MeasureSpec.makeMeasureSpec(scaledH, MeasureSpec.EXACTLY);
|
||||||
|
child.measure(widthSpec, heightSpec);
|
||||||
|
setMeasuredDimension(scaledW, scaledH);
|
||||||
|
} else {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
int childCount = getChildCount();
|
||||||
|
if (childCount > 0) {
|
||||||
|
View child = getChildAt(0);
|
||||||
|
int childW = child.getMeasuredWidth();
|
||||||
|
int childH = child.getMeasuredHeight();
|
||||||
|
int scaledW = (int) (childW * scaleFactor);
|
||||||
|
int scaledH = (int) (childH * scaleFactor);
|
||||||
|
int parentW = right - left;
|
||||||
|
int parentH = bottom - top;
|
||||||
|
int childLeft = (parentW - scaledW) / 2;
|
||||||
|
int childTop = (parentH - scaledH) / 2;
|
||||||
|
child.layout(childLeft, childTop, childLeft + scaledW, childTop + scaledH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
boolean handled = scaleGestureDetector.onTouchEvent(event);
|
||||||
|
if (!scaleGestureDetector.isInProgress()) {
|
||||||
|
handled = gestureDetector.onTouchEvent(event) || handled;
|
||||||
|
}
|
||||||
|
return handled || super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
gallery/src/main/res/drawable/bg_circle_white.xml
Normal file
8
gallery/src/main/res/drawable/bg_circle_white.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
<solid android:color="#CCFFFFFF"/>
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="#000000"/>
|
||||||
|
</shape>
|
||||||
7
gallery/src/main/res/drawable/bg_color_circle.xml
Normal file
7
gallery/src/main/res/drawable/bg_color_circle.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
<solid android:color="@android:color/transparent"/>
|
||||||
|
<stroke android:width="2dp" android:color="@android:color/white"/>
|
||||||
|
<size android:width="32dp" android:height="32dp"/>
|
||||||
|
</shape>
|
||||||
6
gallery/src/main/res/drawable/bg_color_circle_border.xml
Normal file
6
gallery/src/main/res/drawable/bg_color_circle_border.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
<stroke android:width="2dp" android:color="@android:color/white"/>
|
||||||
|
<size android:width="36dp" android:height="36dp"/>
|
||||||
|
</shape>
|
||||||
6
gallery/src/main/res/drawable/bg_dialog.xml
Normal file
6
gallery/src/main/res/drawable/bg_dialog.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="@android:color/black"/>
|
||||||
|
<stroke android:width="2dp" android:color="@android:color/white"/>
|
||||||
|
</shape>
|
||||||
10
gallery/src/main/res/drawable/ic_arrow_up.xml
Normal file
10
gallery/src/main/res/drawable/ic_arrow_up.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z"/>
|
||||||
|
</vector>
|
||||||
10
gallery/src/main/res/drawable/ic_close.xml
Normal file
10
gallery/src/main/res/drawable/ic_close.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||||
|
</vector>
|
||||||
10
gallery/src/main/res/drawable/ic_color_pick.xml
Normal file
10
gallery/src/main/res/drawable/ic_color_pick.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M20.71,5.63l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-3.12,3.12 -1.93,-1.91 -1.41,1.41 1.42,1.42L3,16.25V21h4.75l8.92,-8.92 1.42,1.42 1.41,-1.41 -1.92,-1.92 3.12,-3.12c0.4,-0.4 0.4,-1.03 0.01,-1.42zM6.92,19H5v-1.92l8.06,-8.06 1.92,1.92L6.92,19z"/>
|
||||||
|
</vector>
|
||||||
13
gallery/src/main/res/drawable/ic_cover.xml
Normal file
13
gallery/src/main/res/drawable/ic_cover.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:pathData="M21,3H3C1.9,3 1,3.9 1,5v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2V5C23,3.9 22.1,3 21,3zM21,19H3V5h18V19z"/>
|
||||||
|
<path
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:pathData="M9,12l2,2l4,-4l1.5,1.5L11,17l-3,-3z"/>
|
||||||
|
</vector>
|
||||||
9
gallery/src/main/res/drawable/ic_done.xml
Normal file
9
gallery/src/main/res/drawable/ic_done.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||||
|
</vector>
|
||||||
9
gallery/src/main/res/drawable/ic_pin.xml
Normal file
9
gallery/src/main/res/drawable/ic_pin.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M16,12V4H17V2H7V4H8V12L6,14V16H11.5V22H12.5V16H18V14L16,12Z"/>
|
||||||
|
</vector>
|
||||||
10
gallery/src/main/res/drawable/ic_sort.xml
Normal file
10
gallery/src/main/res/drawable/ic_sort.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M3,18h6v-2H3v2zM3,6v2h18V6H3zM3,13h12v-2H3v2z"/>
|
||||||
|
</vector>
|
||||||
9
gallery/src/main/res/drawable/ic_zoom_in.xml
Normal file
9
gallery/src/main/res/drawable/ic_zoom_in.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||||
|
</vector>
|
||||||
9
gallery/src/main/res/drawable/ic_zoom_out.xml
Normal file
9
gallery/src/main/res/drawable/ic_zoom_out.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M19,13H5v-2h14v2z"/>
|
||||||
|
</vector>
|
||||||
33
gallery/src/main/res/layout/activity_about.xml
Normal file
33
gallery/src/main/res/layout/activity_about.xml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<cc.winboll.studio.libappbase.views.AboutView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/aboutview"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
131
gallery/src/main/res/layout/activity_crop.xml
Normal file
131
gallery/src/main/res/layout/activity_crop.xml
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/black">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:background="@color/colorPrimary"
|
||||||
|
android:paddingHorizontal="16dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/btn_close"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:src="@drawable/ic_close"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/color_icon_container"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:background="@android:color/transparent">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/color_view"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/bg_color_circle"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/btn_color_pick"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:src="@drawable/ic_color_pick"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/btn_info"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:src="@drawable/ic_info"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/btn_done"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:src="@drawable/ic_done"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scroll_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="56dp"
|
||||||
|
android:layout_marginBottom="56dp"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<cc.winboll.studio.gallery.ZoomContainerView
|
||||||
|
android:id="@+id/zoom_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center">
|
||||||
|
|
||||||
|
<cc.winboll.studio.gallery.CropCanvasView
|
||||||
|
android:id="@+id/crop_canvas_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
|
</cc.winboll.studio.gallery.ZoomContainerView>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:background="@color/colorPrimary"
|
||||||
|
android:paddingHorizontal="16dp"
|
||||||
|
android:layout_marginBottom="0dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="缩小"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="12sp"/>
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/seekbar_zoom"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:min="0"
|
||||||
|
android:max="100"
|
||||||
|
android:progress="50"
|
||||||
|
android:layout_marginHorizontal="8dp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="放大"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="12sp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
@@ -26,3 +30,16 @@
|
|||||||
android:background="@color/black"/>
|
android:background="@color/black"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/fab_scroll_top"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:src="@drawable/ic_arrow_up"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:backgroundTint="@color/colorAccent"
|
||||||
|
app:tint="@color/white"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
26
gallery/src/main/res/layout/dialog_crop_info.xml
Normal file
26
gallery/src/main/res/layout/dialog_crop_info.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:background="@drawable/bg_dialog">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/info_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:fontFamily="monospace"
|
||||||
|
android:textColor="@android:color/white"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/preview_image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:background="@android:color/black"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
android:id="@+id/album_cover"
|
android:id="@+id/album_cover"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="120dp"
|
android:layout_height="120dp"
|
||||||
android:scaleType="centerCrop"
|
android:layout_margin="2dp"
|
||||||
android:background="@color/black"/>
|
android:scaleType="centerCrop"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/album_name"
|
android:id="@+id/album_name"
|
||||||
@@ -24,6 +24,17 @@
|
|||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:ellipsize="end"/>
|
android:ellipsize="end"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/pin_icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="6dp"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:src="@drawable/ic_pin"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/image_count"
|
android:id="@+id/image_count"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
20
gallery/src/main/res/layout/item_color_icon.xml
Normal file
20
gallery/src/main/res/layout/item_color_icon.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/color_view"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/bg_color_circle"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/bg_color_circle_border"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@@ -12,4 +12,30 @@
|
|||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
android:background="@color/black"/>
|
android:background="@color/black"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/pin_icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="top|end"
|
||||||
|
android:layout_margin="4dp"
|
||||||
|
android:background="@drawable/bg_circle_white"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:src="@drawable/ic_pin"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:tint="@color/black"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/cover_icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="4dp"
|
||||||
|
android:background="@drawable/bg_circle_white"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:src="@drawable/ic_cover"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:tint="@color/black"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
26
gallery/src/main/res/menu/menu_album.xml
Normal file
26
gallery/src/main/res/menu/menu_album.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_sort"
|
||||||
|
android:icon="@drawable/ic_sort"
|
||||||
|
android:title="排序"
|
||||||
|
app:showAsAction="ifRoom">
|
||||||
|
<menu>
|
||||||
|
<group android:checkableBehavior="single">
|
||||||
|
<item
|
||||||
|
android:id="@+id/sort_time_desc"
|
||||||
|
android:title="时间倒序"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/sort_time_asc"
|
||||||
|
android:title="时间正序"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/sort_name_desc"
|
||||||
|
android:title="名称倒序"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/sort_name_asc"
|
||||||
|
android:title="名称正序"/>
|
||||||
|
</group>
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
</menu>
|
||||||
8
gallery/src/main/res/menu/menu_crop.xml
Normal file
8
gallery/src/main/res/menu/menu_crop.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_done"
|
||||||
|
android:title="完成"
|
||||||
|
app:showAsAction="always"/>
|
||||||
|
</menu>
|
||||||
@@ -13,8 +13,8 @@
|
|||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_refresh"
|
android:id="@+id/action_about"
|
||||||
android:title="@string/refresh"
|
android:title="@string/about"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Gallery</string>
|
<string name="app_name">Gallery</string>
|
||||||
|
<string name="app_description">WinBoLL Album App</string>
|
||||||
<string name="refresh">Refresh</string>
|
<string name="refresh">Refresh</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="settings_title">Settings</string>
|
<string name="settings_title">Settings</string>
|
||||||
|
<string name="about">About</string>
|
||||||
<string name="folder_path">Folder Path</string>
|
<string name="folder_path">Folder Path</string>
|
||||||
<string name="enter_folder_path">Enter folder path</string>
|
<string name="enter_folder_path">Enter folder path</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user