diff --git a/app/src/main/java/com/simplemobiletools/gallery/MyImageView.java b/app/src/main/java/com/simplemobiletools/gallery/MyImageView.java index 8b94e9dc3..4dde27413 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/MyImageView.java +++ b/app/src/main/java/com/simplemobiletools/gallery/MyImageView.java @@ -5,6 +5,7 @@ import android.util.AttributeSet; import android.widget.ImageView; public class MyImageView extends ImageView { + public MyImageView(Context context) { super(context); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java index be730d84a..5c16f8b37 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java @@ -21,14 +21,15 @@ public class AboutActivity extends AppCompatActivity { @BindView(R.id.about_copyright) TextView copyright; @BindView(R.id.about_version) TextView version; @BindView(R.id.about_email) TextView emailTV; - private Resources res; + + private static Resources mRes; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); ButterKnife.bind(this); - res = getResources(); + mRes = getResources(); setupEmail(); setupVersion(); @@ -36,8 +37,8 @@ public class AboutActivity extends AppCompatActivity { } private void setupEmail() { - final String email = res.getString(R.string.email); - final String appName = res.getString(R.string.app_name); + final String email = mRes.getString(R.string.email); + final String appName = mRes.getString(R.string.app_name); final String href = "" + email + ""; emailTV.setText(Html.fromHtml(href)); emailTV.setMovementMethod(LinkMovementMethod.getInstance()); @@ -45,13 +46,13 @@ public class AboutActivity extends AppCompatActivity { private void setupVersion() { final String versionName = BuildConfig.VERSION_NAME; - final String versionText = String.format(res.getString(R.string.version), versionName); + final String versionText = String.format(mRes.getString(R.string.version), versionName); version.setText(versionText); } private void setupCopyright() { final int year = Calendar.getInstance().get(Calendar.YEAR); - final String copyrightText = String.format(res.getString(R.string.copyright), year); + final String copyrightText = String.format(mRes.getString(R.string.copyright), year); copyright.setText(copyrightText); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/LicenseActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/LicenseActivity.java index 86f3ecd03..6d90229de 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/LicenseActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/LicenseActivity.java @@ -11,6 +11,7 @@ import butterknife.ButterKnife; import butterknife.OnClick; public class LicenseActivity extends AppCompatActivity { + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index f201ca3aa..c24f31719 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -45,33 +45,34 @@ import butterknife.ButterKnife; public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { - @BindView(R.id.directories_grid) GridView gridView; + @BindView(R.id.directories_grid) GridView mGridView; private static final int STORAGE_PERMISSION = 1; private static final int PICK_MEDIA = 2; - private List dirs; - private int selectedItemsCnt; - private Snackbar snackbar; - private boolean isSnackbarShown; - private List toBeDeleted; - private ActionMode actionMode; - private Parcelable state; - private boolean isPickImageIntent; - private boolean isPickVideoIntent; + + private static List mDirs; + private static Snackbar mSnackbar; + private static List mToBeDeleted; + private static ActionMode mActionMode; + private static Parcelable mState; + + private static boolean mIsSnackbarShown; + private static boolean mIsPickImageIntent; + private static boolean mIsPickVideoIntent; + private static int mSelectedItemsCnt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); - isPickImageIntent = isPickImageIntent(getIntent()); - isPickVideoIntent = isPickVideoIntent(getIntent()); + mIsPickImageIntent = isPickImageIntent(getIntent()); + mIsPickVideoIntent = isPickVideoIntent(getIntent()); } @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.menu, menu); + getMenuInflater().inflate(R.menu.menu, menu); return true; } @@ -91,16 +92,16 @@ public class MainActivity extends AppCompatActivity protected void onResume() { super.onResume(); tryloadGallery(); - if (state != null && gridView != null) - gridView.onRestoreInstanceState(state); + if (mState != null && mGridView != null) + mGridView.onRestoreInstanceState(mState); } @Override protected void onPause() { super.onPause(); deleteDirs(); - if (gridView != null) - state = gridView.onSaveInstanceState(); + if (mGridView != null) + mState = mGridView.onSaveInstanceState(); } private void tryloadGallery() { @@ -126,26 +127,26 @@ public class MainActivity extends AppCompatActivity } private void initializeGallery() { - toBeDeleted = new ArrayList<>(); - dirs = getDirectories(); - final DirectoryAdapter adapter = new DirectoryAdapter(this, dirs); + mToBeDeleted = new ArrayList<>(); + mDirs = getDirectories(); - gridView.setAdapter(adapter); - gridView.setOnItemClickListener(this); - gridView.setMultiChoiceModeListener(this); - gridView.setOnTouchListener(this); + final DirectoryAdapter adapter = new DirectoryAdapter(this, mDirs); + mGridView.setAdapter(adapter); + mGridView.setOnItemClickListener(this); + mGridView.setMultiChoiceModeListener(this); + mGridView.setOnTouchListener(this); } private List getDirectories() { final Map directories = new LinkedHashMap<>(); final List invalidFiles = new ArrayList<>(); for (int i = 0; i < 2; i++) { - if (isPickVideoIntent && i == 0) + if (mIsPickVideoIntent && i == 0) continue; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; if (i == 1) { - if (isPickImageIntent) + if (mIsPickImageIntent) continue; uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; @@ -172,7 +173,7 @@ public class MainActivity extends AppCompatActivity final Directory directory = directories.get(fileDir); final int newImageCnt = directory.getMediaCnt() + 1; directory.setMediaCnt(newImageCnt); - } else if (!toBeDeleted.contains(fileDir)) { + } else if (!mToBeDeleted.contains(fileDir)) { final String dirName = Utils.getFilename(fileDir); directories.put(fileDir, new Directory(fileDir, path, dirName, 1, timestamp)); } @@ -192,14 +193,14 @@ public class MainActivity extends AppCompatActivity private void prepareForDeleting() { Utils.showToast(this, R.string.deleting); - final SparseBooleanArray items = gridView.getCheckedItemPositions(); - int cnt = items.size(); + final SparseBooleanArray items = mGridView.getCheckedItemPositions(); + final int cnt = items.size(); int deletedCnt = 0; for (int i = 0; i < cnt; i++) { if (items.valueAt(i)) { final int id = items.keyAt(i); - final String path = dirs.get(id).getPath(); - toBeDeleted.add(path); + final String path = mDirs.get(id).getPath(); + mToBeDeleted.add(path); deletedCnt++; } } @@ -208,31 +209,31 @@ public class MainActivity extends AppCompatActivity } private void notifyDeletion(int cnt) { - dirs = getDirectories(); + mDirs = getDirectories(); final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout); final Resources res = getResources(); final String msg = res.getQuantityString(R.plurals.folders_deleted, cnt, cnt); - snackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE); - snackbar.setAction(res.getString(R.string.undo), undoDeletion); - snackbar.setActionTextColor(Color.WHITE); - snackbar.show(); - isSnackbarShown = true; + mSnackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE); + mSnackbar.setAction(res.getString(R.string.undo), undoDeletion); + mSnackbar.setActionTextColor(Color.WHITE); + mSnackbar.show(); + mIsSnackbarShown = true; updateGridView(); } private void deleteDirs() { - if (toBeDeleted == null || toBeDeleted.isEmpty()) + if (mToBeDeleted == null || mToBeDeleted.isEmpty()) return; - if (snackbar != null) { - snackbar.dismiss(); + if (mSnackbar != null) { + mSnackbar.dismiss(); } - isSnackbarShown = false; + mIsSnackbarShown = false; final List updatedFiles = new ArrayList<>(); - for (String delPath : toBeDeleted) { + for (String delPath : mToBeDeleted) { final File dir = new File(delPath); if (dir.exists()) { final File[] files = dir.listFiles(); @@ -247,32 +248,32 @@ public class MainActivity extends AppCompatActivity final String[] deletedPaths = updatedFiles.toArray(new String[updatedFiles.size()]); MediaScannerConnection.scanFile(this, deletedPaths, null, null); - toBeDeleted.clear(); + mToBeDeleted.clear(); } private View.OnClickListener undoDeletion = new View.OnClickListener() { @Override public void onClick(View v) { - snackbar.dismiss(); - isSnackbarShown = false; - toBeDeleted.clear(); - dirs = getDirectories(); + mSnackbar.dismiss(); + mIsSnackbarShown = false; + mToBeDeleted.clear(); + mDirs = getDirectories(); updateGridView(); } }; private void updateGridView() { - final DirectoryAdapter adapter = (DirectoryAdapter) gridView.getAdapter(); - adapter.updateItems(dirs); + final DirectoryAdapter adapter = (DirectoryAdapter) mGridView.getAdapter(); + adapter.updateItems(mDirs); } private void editDirectory() { - final SparseBooleanArray items = gridView.getCheckedItemPositions(); + final SparseBooleanArray items = mGridView.getCheckedItemPositions(); final int cnt = items.size(); for (int i = 0; i < cnt; i++) { if (items.valueAt(i)) { final int id = items.keyAt(i); - final String path = dirs.get(id).getPath(); + final String path = mDirs.get(id).getPath(); renameDir(path); break; } @@ -312,7 +313,7 @@ public class MainActivity extends AppCompatActivity if (dir.renameTo(newDir)) { Utils.showToast(getApplicationContext(), R.string.renaming_folder); alertDialog.dismiss(); - actionMode.finish(); + mActionMode.finish(); final File[] files = newDir.listFiles(); for (File f : files) { @@ -361,22 +362,22 @@ public class MainActivity extends AppCompatActivity @Override public void onItemClick(AdapterView parent, View view, int position, long id) { final Intent intent = new Intent(this, MediaActivity.class); - intent.putExtra(Constants.DIRECTORY, dirs.get(position).getPath()); - intent.putExtra(Constants.PICK_IMAGE_INTENT, isPickImageIntent); - intent.putExtra(Constants.PICK_VIDEO_INTENT, isPickVideoIntent); + intent.putExtra(Constants.DIRECTORY, mDirs.get(position).getPath()); + intent.putExtra(Constants.PICK_IMAGE_INTENT, mIsPickImageIntent); + intent.putExtra(Constants.PICK_VIDEO_INTENT, mIsPickVideoIntent); startActivityForResult(intent, PICK_MEDIA); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { - selectedItemsCnt++; + mSelectedItemsCnt++; } else { - selectedItemsCnt--; + mSelectedItemsCnt--; } - if (selectedItemsCnt > 0) { - mode.setTitle(String.valueOf(selectedItemsCnt)); + if (mSelectedItemsCnt > 0) { + mode.setTitle(String.valueOf(mSelectedItemsCnt)); } mode.invalidate(); @@ -386,14 +387,14 @@ public class MainActivity extends AppCompatActivity public boolean onCreateActionMode(ActionMode mode, Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.directories_menu, menu); - actionMode = mode; + mActionMode = mode; return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { final MenuItem menuItem = menu.findItem(R.id.cab_edit); - menuItem.setVisible(selectedItemsCnt == 1); + menuItem.setVisible(mSelectedItemsCnt == 1); return true; } @@ -414,12 +415,12 @@ public class MainActivity extends AppCompatActivity @Override public void onDestroyActionMode(ActionMode mode) { - selectedItemsCnt = 0; + mSelectedItemsCnt = 0; } @Override public boolean onTouch(View v, MotionEvent event) { - if (isSnackbarShown) { + if (mIsSnackbarShown) { deleteDirs(); } @@ -429,13 +430,13 @@ public class MainActivity extends AppCompatActivity private void scanCompleted(final String path) { final File dir = new File(path); if (dir.isDirectory()) { - dirs = getDirectories(); + mDirs = getDirectories(); runOnUiThread(new Runnable() { @Override public void run() { updateGridView(); - gridView.requestLayout(); + mGridView.requestLayout(); Utils.showToast(getApplicationContext(), R.string.rename_folder_ok); } }); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index d349ae665..ea4ddfac1 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -39,41 +39,42 @@ import butterknife.ButterKnife; public class MediaActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { - @BindView(R.id.media_grid) GridView gridView; + @BindView(R.id.media_grid) GridView mGridView; - private List media; - private int selectedItemsCnt; - private String path; - private Snackbar snackbar; - private boolean isSnackbarShown; - private List toBeDeleted; - private Parcelable state; - private boolean isPickImageIntent; - private boolean isPickVideoIntent; + private static List mMedia; + private static String mPath; + private static Snackbar mSnackbar; + private static List mToBeDeleted; + private static Parcelable mState; + + private static boolean mIsSnackbarShown; + private static boolean mIsPickImageIntent; + private static boolean mIsPickVideoIntent; + private static int mSelectedItemsCnt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_media); ButterKnife.bind(this); - isPickImageIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false); - isPickVideoIntent = getIntent().getBooleanExtra(Constants.PICK_VIDEO_INTENT, false); + mIsPickImageIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false); + mIsPickVideoIntent = getIntent().getBooleanExtra(Constants.PICK_VIDEO_INTENT, false); } @Override protected void onResume() { super.onResume(); tryloadGallery(); - if (state != null && gridView != null) - gridView.onRestoreInstanceState(state); + if (mState != null && mGridView != null) + mGridView.onRestoreInstanceState(mState); } @Override protected void onPause() { super.onPause(); deleteFiles(); - if (gridView != null) - state = gridView.onSaveInstanceState(); + if (mGridView != null) + mState = mGridView.onSaveInstanceState(); } private void tryloadGallery() { @@ -85,60 +86,60 @@ public class MediaActivity extends AppCompatActivity } private void initializeGallery() { - toBeDeleted = new ArrayList<>(); - path = getIntent().getStringExtra(Constants.DIRECTORY); - media = getMedia(); + mToBeDeleted = new ArrayList<>(); + mPath = getIntent().getStringExtra(Constants.DIRECTORY); + mMedia = getMedia(); if (isDirEmpty()) return; - final MediaAdapter adapter = new MediaAdapter(this, media); - gridView.setAdapter(adapter); - gridView.setOnItemClickListener(this); - gridView.setMultiChoiceModeListener(this); - gridView.setOnTouchListener(this); - isSnackbarShown = false; + final MediaAdapter adapter = new MediaAdapter(this, mMedia); + mGridView.setAdapter(adapter); + mGridView.setOnItemClickListener(this); + mGridView.setMultiChoiceModeListener(this); + mGridView.setOnTouchListener(this); + mIsSnackbarShown = false; - final String dirName = Utils.getFilename(path); + final String dirName = Utils.getFilename(mPath); setTitle(dirName); } private void deleteDirectoryIfEmpty() { - final File file = new File(path); + final File file = new File(mPath); if (file.isDirectory() && file.listFiles().length == 0) { file.delete(); } } private List getMedia() { - final List myMedia = new ArrayList<>(); + final List media = new ArrayList<>(); final List invalidFiles = new ArrayList<>(); for (int i = 0; i < 2; i++) { - if (isPickVideoIntent && i == 0) + if (mIsPickVideoIntent && i == 0) continue; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; if (i == 1) { - if (isPickImageIntent) + if (mIsPickImageIntent) continue; uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } final String where = MediaStore.Images.Media.DATA + " like ? "; - final String[] args = new String[]{path + "%"}; + final String[] args = new String[]{mPath + "%"}; final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN}; final Cursor cursor = getContentResolver().query(uri, columns, where, args, null); - final String pattern = Pattern.quote(path) + "/[^/]*"; + final String pattern = Pattern.quote(mPath) + "/[^/]*"; if (cursor != null && cursor.moveToFirst()) { final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); do { final String curPath = cursor.getString(pathIndex); - if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) { + if (curPath.matches(pattern) && !mToBeDeleted.contains(curPath)) { final File file = new File(curPath); if (file.exists()) { final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN); final long timestamp = cursor.getLong(dateIndex); - myMedia.add(new Medium(curPath, (i == 1), timestamp)); + media.add(new Medium(curPath, (i == 1), timestamp)); } else { invalidFiles.add(file.getAbsolutePath()); } @@ -148,16 +149,16 @@ public class MediaActivity extends AppCompatActivity } } - Collections.sort(myMedia); + Collections.sort(media); final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]); MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null); - return myMedia; + return media; } private boolean isDirEmpty() { - if (media.size() <= 0) { + if (mMedia.size() <= 0) { deleteDirectoryIfEmpty(); finish(); return true; @@ -167,14 +168,14 @@ public class MediaActivity extends AppCompatActivity private void prepareForDeleting() { Utils.showToast(this, R.string.deleting); - final SparseBooleanArray items = gridView.getCheckedItemPositions(); - int cnt = items.size(); + final SparseBooleanArray items = mGridView.getCheckedItemPositions(); + final int cnt = items.size(); int deletedCnt = 0; for (int i = 0; i < cnt; i++) { if (items.valueAt(i)) { final int id = items.keyAt(i); - final String path = media.get(id).getPath(); - toBeDeleted.add(path); + final String path = mMedia.get(id).getPath(); + mToBeDeleted.add(path); deletedCnt++; } } @@ -183,79 +184,79 @@ public class MediaActivity extends AppCompatActivity } private void notifyDeletion(int cnt) { - media = getMedia(); + mMedia = getMedia(); - if (media.isEmpty()) { + if (mMedia.isEmpty()) { deleteFiles(); } else { final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout); final Resources res = getResources(); final String msg = res.getQuantityString(R.plurals.files_deleted, cnt, cnt); - snackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE); - snackbar.setAction(res.getString(R.string.undo), undoDeletion); - snackbar.setActionTextColor(Color.WHITE); - snackbar.show(); - isSnackbarShown = true; + mSnackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE); + mSnackbar.setAction(res.getString(R.string.undo), undoDeletion); + mSnackbar.setActionTextColor(Color.WHITE); + mSnackbar.show(); + mIsSnackbarShown = true; updateGridView(); } } private void deleteFiles() { - if (toBeDeleted == null || toBeDeleted.isEmpty()) + if (mToBeDeleted == null || mToBeDeleted.isEmpty()) return; - if (snackbar != null) { - snackbar.dismiss(); + if (mSnackbar != null) { + mSnackbar.dismiss(); } - isSnackbarShown = false; + mIsSnackbarShown = false; - for (String delPath : toBeDeleted) { + for (String delPath : mToBeDeleted) { final File file = new File(delPath); if (file.exists()) file.delete(); } - final String[] deletedPaths = toBeDeleted.toArray(new String[toBeDeleted.size()]); + final String[] deletedPaths = mToBeDeleted.toArray(new String[mToBeDeleted.size()]); MediaScannerConnection.scanFile(this, deletedPaths, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { - if (media != null && media.isEmpty()) { + if (mMedia != null && mMedia.isEmpty()) { finish(); } } }); - toBeDeleted.clear(); + mToBeDeleted.clear(); } private View.OnClickListener undoDeletion = new View.OnClickListener() { @Override public void onClick(View v) { - snackbar.dismiss(); - isSnackbarShown = false; - toBeDeleted.clear(); - media = getMedia(); + mSnackbar.dismiss(); + mIsSnackbarShown = false; + mToBeDeleted.clear(); + mMedia = getMedia(); updateGridView(); } }; private void updateGridView() { if (!isDirEmpty()) { - final MediaAdapter adapter = (MediaAdapter) gridView.getAdapter(); - adapter.updateItems(media); + final MediaAdapter adapter = (MediaAdapter) mGridView.getAdapter(); + adapter.updateItems(mMedia); } } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (isPickImageIntent || isPickVideoIntent) { + if (mIsPickImageIntent || mIsPickVideoIntent) { final Intent result = new Intent(); - result.setData(Uri.parse(media.get(position).getPath())); + result.setData(Uri.parse(mMedia.get(position).getPath())); setResult(RESULT_OK, result); finish(); } else { final Intent intent = new Intent(this, ViewPagerActivity.class); - intent.putExtra(Constants.MEDIUM, media.get(position).getPath()); + intent.putExtra(Constants.MEDIUM, mMedia.get(position).getPath()); startActivity(intent); } } @@ -263,13 +264,13 @@ public class MediaActivity extends AppCompatActivity @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { - selectedItemsCnt++; + mSelectedItemsCnt++; } else { - selectedItemsCnt--; + mSelectedItemsCnt--; } - if (selectedItemsCnt > 0) - mode.setTitle(String.valueOf(selectedItemsCnt)); + if (mSelectedItemsCnt > 0) + mode.setTitle(String.valueOf(mSelectedItemsCnt)); mode.invalidate(); } @@ -300,12 +301,12 @@ public class MediaActivity extends AppCompatActivity @Override public void onDestroyActionMode(ActionMode mode) { - selectedItemsCnt = 0; + mSelectedItemsCnt = 0; } @Override public boolean onTouch(View v, MotionEvent event) { - if (isSnackbarShown) { + if (mIsSnackbarShown) { deleteFiles(); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java index 337d37f2c..3fd6a5bc0 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java @@ -16,32 +16,33 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment; import com.simplemobiletools.gallery.models.Medium; public class PhotoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener { - private ActionBar actionbar; - private boolean isFullScreen; - private Uri uri; + private static ActionBar mActionbar; + private static Uri mUri; + + private static boolean mIsFullScreen; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_holder); - uri = getIntent().getData(); - if (uri == null) + mUri = getIntent().getData(); + if (mUri == null) return; - actionbar = getSupportActionBar(); - isFullScreen = true; + mActionbar = getSupportActionBar(); + mIsFullScreen = true; hideSystemUI(); final Bundle bundle = new Bundle(); - final Medium medium = new Medium(uri.toString(), false, 0); + final Medium medium = new Medium(mUri.toString(), false, 0); bundle.putSerializable(Constants.MEDIUM, medium); final ViewPagerFragment fragment = new PhotoFragment(); fragment.setListener(this); fragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit(); hideSystemUI(); - setTitle(Utils.getFilename(uri.toString())); + setTitle(Utils.getFilename(mUri.toString())); } @Override @@ -65,15 +66,15 @@ public class PhotoActivity extends AppCompatActivity implements ViewPagerFragmen final String shareTitle = getResources().getString(R.string.share_via); final Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_STREAM, uri); + sendIntent.putExtra(Intent.EXTRA_STREAM, mUri); sendIntent.setType("image/*"); startActivity(Intent.createChooser(sendIntent, shareTitle)); } @Override public void fragmentClicked() { - isFullScreen = !isFullScreen; - if (isFullScreen) { + mIsFullScreen = !mIsFullScreen; + if (mIsFullScreen) { hideSystemUI(); } else { showSystemUI(); @@ -81,10 +82,10 @@ public class PhotoActivity extends AppCompatActivity implements ViewPagerFragmen } private void hideSystemUI() { - Utils.hideSystemUI(actionbar, getWindow()); + Utils.hideSystemUI(mActionbar, getWindow()); } private void showSystemUI() { - Utils.showSystemUI(actionbar, getWindow()); + Utils.showSystemUI(mActionbar, getWindow()); } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java index 77b0d973f..e0297237f 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java @@ -16,32 +16,33 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment; import com.simplemobiletools.gallery.models.Medium; public class VideoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener { - private ActionBar actionbar; - private boolean isFullScreen; - private Uri uri; + private static ActionBar mActionbar; + private static Uri mUri; + + private static boolean mIsFullScreen; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_holder); - uri = getIntent().getData(); - if (uri == null) + mUri = getIntent().getData(); + if (mUri == null) return; - actionbar = getSupportActionBar(); - isFullScreen = true; + mActionbar = getSupportActionBar(); + mIsFullScreen = true; hideSystemUI(); final Bundle bundle = new Bundle(); - final Medium medium = new Medium(uri.toString(), true, 0); + final Medium medium = new Medium(mUri.toString(), true, 0); bundle.putSerializable(Constants.MEDIUM, medium); final ViewPagerFragment fragment = new VideoFragment(); fragment.setListener(this); fragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit(); hideSystemUI(); - setTitle(Utils.getFilename(uri.toString())); + setTitle(Utils.getFilename(mUri.toString())); } @Override @@ -65,15 +66,15 @@ public class VideoActivity extends AppCompatActivity implements ViewPagerFragmen final String shareTitle = getResources().getString(R.string.share_via); final Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_STREAM, uri); + sendIntent.putExtra(Intent.EXTRA_STREAM, mUri); sendIntent.setType("video/*"); startActivity(Intent.createChooser(sendIntent, shareTitle)); } @Override public void fragmentClicked() { - isFullScreen = !isFullScreen; - if (isFullScreen) { + mIsFullScreen = !mIsFullScreen; + if (mIsFullScreen) { hideSystemUI(); } else { showSystemUI(); @@ -81,10 +82,10 @@ public class VideoActivity extends AppCompatActivity implements ViewPagerFragmen } private void hideSystemUI() { - Utils.hideSystemUI(actionbar, getWindow()); + Utils.hideSystemUI(mActionbar, getWindow()); } private void showSystemUI() { - Utils.showSystemUI(actionbar, getWindow()); + Utils.showSystemUI(mActionbar, getWindow()); } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index 7efdff1c4..de14f9115 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -40,18 +40,19 @@ import butterknife.OnClick; public class ViewPagerActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener, ViewPagerFragment.FragmentClickListener { - @BindView(R.id.undo_delete) View undoBtn; - @BindView(R.id.view_pager) MyViewPager pager; + @BindView(R.id.undo_delete) View mUndoBtn; + @BindView(R.id.view_pager) MyViewPager mPager; - private int pos; - private boolean isFullScreen; - private boolean isUndoShown; - private ActionBar actionbar; - private List media; - private String path; - private String directory; - private String toBeDeleted; - private String beingDeleted; + private static ActionBar mActionbar; + private static List mMedia; + private static String mPath; + private static String mDirectory; + private static String mToBeDeleted; + private static String mBeingDeleted; + + private static boolean mIsFullScreen; + private static boolean mIsUndoShown; + private static int mPos; @Override protected void onCreate(Bundle savedInstanceState) { @@ -64,26 +65,26 @@ public class ViewPagerActivity extends AppCompatActivity return; } - pos = 0; - isFullScreen = true; - actionbar = getSupportActionBar(); - toBeDeleted = ""; - beingDeleted = ""; + mPos = 0; + mIsFullScreen = true; + mActionbar = getSupportActionBar(); + mToBeDeleted = ""; + mBeingDeleted = ""; hideSystemUI(); - path = getIntent().getStringExtra(Constants.MEDIUM); - MediaScannerConnection.scanFile(this, new String[]{path}, null, null); + mPath = getIntent().getStringExtra(Constants.MEDIUM); + MediaScannerConnection.scanFile(this, new String[]{mPath}, null, null); addUndoMargin(); - directory = new File(path).getParent(); - media = getMedia(); + mDirectory = new File(mPath).getParent(); + mMedia = getMedia(); if (isDirEmpty()) return; - final MyPagerAdapter adapter = new MyPagerAdapter(this, getSupportFragmentManager(), media); - pager.setAdapter(adapter); - pager.setCurrentItem(pos); - pager.addOnPageChangeListener(this); - pager.setOnTouchListener(this); + final MyPagerAdapter adapter = new MyPagerAdapter(this, getSupportFragmentManager(), mMedia); + mPager.setAdapter(adapter); + mPager.setCurrentItem(mPos); + mPager.addOnPageChangeListener(this); + mPager.setOnTouchListener(this); getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this); updateActionbarTitle(); @@ -99,10 +100,10 @@ public class ViewPagerActivity extends AppCompatActivity @OnClick(R.id.undo_delete) public void undoDeletion() { - isUndoShown = false; - toBeDeleted = ""; - beingDeleted = ""; - undoBtn.setVisibility(View.GONE); + mIsUndoShown = false; + mToBeDeleted = ""; + mBeingDeleted = ""; + mUndoBtn.setVisibility(View.GONE); reloadViewPager(); } @@ -138,37 +139,38 @@ public class ViewPagerActivity extends AppCompatActivity final Uri uri = Uri.fromFile(file); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, uri); - if (medium.getIsVideo()) + if (medium.getIsVideo()) { sendIntent.setType("video/*"); - else + } else { sendIntent.setType("image/*"); + } startActivity(Intent.createChooser(sendIntent, shareTitle)); } private void notifyDeletion() { - toBeDeleted = getCurrentFile().getAbsolutePath(); + mToBeDeleted = getCurrentFile().getAbsolutePath(); - if (media.size() <= 1) { + if (mMedia.size() <= 1) { deleteFile(); } else { Utils.showToast(this, R.string.file_deleted); - undoBtn.setVisibility(View.VISIBLE); - isUndoShown = true; + mUndoBtn.setVisibility(View.VISIBLE); + mIsUndoShown = true; reloadViewPager(); } } private void deleteFile() { - if (toBeDeleted.isEmpty()) + if (mToBeDeleted.isEmpty()) return; - isUndoShown = false; - beingDeleted = ""; + mIsUndoShown = false; + mBeingDeleted = ""; - final File file = new File(toBeDeleted); + final File file = new File(mToBeDeleted); if (file.delete()) { - beingDeleted = toBeDeleted; - final String[] deletedPath = new String[]{toBeDeleted}; + mBeingDeleted = mToBeDeleted; + final String[] deletedPath = new String[]{mToBeDeleted}; MediaScannerConnection.scanFile(this, deletedPath, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { @@ -176,12 +178,12 @@ public class ViewPagerActivity extends AppCompatActivity } }); } - toBeDeleted = ""; - undoBtn.setVisibility(View.GONE); + mToBeDeleted = ""; + mUndoBtn.setVisibility(View.GONE); } private boolean isDirEmpty() { - if (media.size() <= 0) { + if (mMedia.size() <= 0) { deleteDirectoryIfEmpty(); finish(); return true; @@ -229,8 +231,8 @@ public class ViewPagerActivity extends AppCompatActivity final File newFile = new File(file.getParent(), fileName + "." + extension); if (file.renameTo(newFile)) { - final int currItem = pager.getCurrentItem(); - media.set(currItem, new Medium(newFile.getAbsolutePath(), media.get(currItem).getIsVideo(), 0)); + final int currItem = mPager.getCurrentItem(); + mMedia.set(currItem, new Medium(newFile.getAbsolutePath(), mMedia.get(currItem).getIsVideo(), 0)); final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()}; MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); @@ -244,75 +246,75 @@ public class ViewPagerActivity extends AppCompatActivity } private void reloadViewPager() { - final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter(); - final int curPos = pager.getCurrentItem(); - media = getMedia(); + final MyPagerAdapter adapter = (MyPagerAdapter) mPager.getAdapter(); + final int curPos = mPager.getCurrentItem(); + mMedia = getMedia(); if (isDirEmpty()) return; - pager.setAdapter(null); - adapter.updateItems(media); - pager.setAdapter(adapter); + mPager.setAdapter(null); + adapter.updateItems(mMedia); + mPager.setAdapter(adapter); final int newPos = Math.min(curPos, adapter.getCount()); - pager.setCurrentItem(newPos); + mPager.setCurrentItem(newPos); updateActionbarTitle(); } private void deleteDirectoryIfEmpty() { - final File file = new File(directory); + final File file = new File(mDirectory); if (file.isDirectory() && file.listFiles().length == 0) { file.delete(); } - final String[] toBeDeleted = new String[]{directory}; + final String[] toBeDeleted = new String[]{mDirectory}; MediaScannerConnection.scanFile(getApplicationContext(), toBeDeleted, null, null); } private List getMedia() { - final List myMedia = new ArrayList<>(); + final List media = new ArrayList<>(); for (int i = 0; i < 2; i++) { Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; if (i == 1) { uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } final String where = MediaStore.Images.Media.DATA + " like ? "; - final String[] args = new String[]{directory + "%"}; + final String[] args = new String[]{mDirectory + "%"}; final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN}; final Cursor cursor = getContentResolver().query(uri, columns, where, args, null); - final String pattern = Pattern.quote(directory) + "/[^/]*"; + final String pattern = Pattern.quote(mDirectory) + "/[^/]*"; if (cursor != null && cursor.moveToFirst()) { final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); do { final String curPath = cursor.getString(pathIndex); - if (curPath.matches(pattern) && !curPath.equals(toBeDeleted) && !curPath.equals(beingDeleted)) { + if (curPath.matches(pattern) && !curPath.equals(mToBeDeleted) && !curPath.equals(mBeingDeleted)) { final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN); final long timestamp = cursor.getLong(dateIndex); - myMedia.add(new Medium(curPath, i == 1, timestamp)); + media.add(new Medium(curPath, i == 1, timestamp)); } } while (cursor.moveToNext()); cursor.close(); } } - Collections.sort(myMedia); + Collections.sort(media); int j = 0; - for (Medium medium : myMedia) { - if (medium.getPath().equals(path)) { - pos = j; + for (Medium medium : media) { + if (medium.getPath().equals(mPath)) { + mPos = j; break; } j++; } - return myMedia; + return media; } @Override public void fragmentClicked() { deleteFile(); - isFullScreen = !isFullScreen; - if (isFullScreen) { + mIsFullScreen = !mIsFullScreen; + if (mIsFullScreen) { hideSystemUI(); } else { showSystemUI(); @@ -320,21 +322,21 @@ public class ViewPagerActivity extends AppCompatActivity } private void hideSystemUI() { - Utils.hideSystemUI(actionbar, getWindow()); + Utils.hideSystemUI(mActionbar, getWindow()); } private void showSystemUI() { - Utils.showSystemUI(actionbar, getWindow()); + Utils.showSystemUI(mActionbar, getWindow()); } private void updateActionbarTitle() { - setTitle(Utils.getFilename(media.get(pager.getCurrentItem()).getPath())); + setTitle(Utils.getFilename(mMedia.get(mPager.getCurrentItem()).getPath())); } private Medium getCurrentMedium() { - if (pos >= media.size()) - pos = media.size() - 1; - return media.get(pos); + if (mPos >= mMedia.size()) + mPos = mMedia.size() - 1; + return mMedia.get(mPos); } private File getCurrentFile() { @@ -343,7 +345,7 @@ public class ViewPagerActivity extends AppCompatActivity private void addUndoMargin() { final Resources res = getResources(); - final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) undoBtn.getLayoutParams(); + final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mUndoBtn.getLayoutParams(); final int topMargin = Utils.getStatusBarHeight(res) + Utils.getActionBarHeight(getApplicationContext(), res); int rightMargin = params.rightMargin; @@ -362,33 +364,33 @@ public class ViewPagerActivity extends AppCompatActivity @Override public void onPageSelected(int position) { updateActionbarTitle(); - pos = position; + mPos = position; } @Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_DRAGGING) { - final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter(); - adapter.itemDragged(pos); + final MyPagerAdapter adapter = (MyPagerAdapter) mPager.getAdapter(); + adapter.itemDragged(mPos); } } @Override public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { - isFullScreen = false; + mIsFullScreen = false; } - final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter(); - adapter.updateUiVisibility(isFullScreen, pos); + final MyPagerAdapter adapter = (MyPagerAdapter) mPager.getAdapter(); + adapter.updateUiVisibility(mIsFullScreen, mPos); } private void scanCompleted() { - beingDeleted = ""; + mBeingDeleted = ""; runOnUiThread(new Runnable() { @Override public void run() { - if (media != null && media.size() <= 1) { + if (mMedia != null && mMedia.size() <= 1) { reloadViewPager(); } } @@ -397,7 +399,7 @@ public class ViewPagerActivity extends AppCompatActivity @Override public boolean onTouch(View v, MotionEvent event) { - if (isUndoShown) { + if (mIsUndoShown) { deleteFile(); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java index bd9619805..8594a3bcf 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java @@ -9,8 +9,8 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.simplemobiletools.gallery.models.Directory; import com.simplemobiletools.gallery.R; +import com.simplemobiletools.gallery.models.Directory; import java.util.List; @@ -18,43 +18,44 @@ import butterknife.BindView; import butterknife.ButterKnife; public class DirectoryAdapter extends BaseAdapter { - private final Context context; - private final List dirs; - private final LayoutInflater inflater; + private final Context mContext; + private final List mDirs; + private final LayoutInflater mInflater; public DirectoryAdapter(Context context, List dirs) { - this.context = context; - this.dirs = dirs; - this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.mContext = context; + this.mDirs = dirs; + this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position, View view, ViewGroup parent) { ViewHolder holder; if (view == null) { - view = inflater.inflate(R.layout.directory_item, parent, false); + view = mInflater.inflate(R.layout.directory_item, parent, false); holder = new ViewHolder(view); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } - final Directory dir = dirs.get(position); + final Directory dir = mDirs.get(position); holder.dirName.setText(dir.getName()); holder.photoCnt.setText(String.valueOf(dir.getMediaCnt())); - Glide.with(context).load(dir.getThumbnail()).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.dirThumbnail); + Glide.with(mContext).load(dir.getThumbnail()).placeholder(R.color.tmb_background).centerCrop().crossFade() + .into(holder.dirThumbnail); return view; } @Override public int getCount() { - return dirs.size(); + return mDirs.size(); } @Override public Object getItem(int position) { - return dirs.get(position); + return mDirs.get(position); } @Override @@ -63,8 +64,8 @@ public class DirectoryAdapter extends BaseAdapter { } public void updateItems(List newDirs) { - dirs.clear(); - dirs.addAll(newDirs); + mDirs.clear(); + mDirs.addAll(newDirs); notifyDataSetChanged(); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java index 571d16117..b179b6411 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java @@ -17,22 +17,22 @@ import butterknife.BindView; import butterknife.ButterKnife; public class MediaAdapter extends BaseAdapter { - private final Context context; - private final List media; - private final LayoutInflater inflater; + private final Context mContext; + private final List mMedia; + private final LayoutInflater mInflater; public MediaAdapter(Context context, List media) { - this.context = context; - this.media = media; - this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.mContext = context; + this.mMedia = media; + this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position, View view, ViewGroup parent) { - final Medium medium = media.get(position); + final Medium medium = mMedia.get(position); ViewHolder holder; if (view == null) { - view = inflater.inflate(R.layout.video_item, parent, false); + view = mInflater.inflate(R.layout.video_item, parent, false); holder = new ViewHolder(view); view.setTag(holder); } else { @@ -46,19 +46,19 @@ public class MediaAdapter extends BaseAdapter { } final String path = medium.getPath(); - Glide.with(context).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail); + Glide.with(mContext).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail); return view; } @Override public int getCount() { - return media.size(); + return mMedia.size(); } @Override public Object getItem(int position) { - return media.get(position); + return mMedia.get(position); } @Override @@ -67,14 +67,14 @@ public class MediaAdapter extends BaseAdapter { } public void updateItems(List newPhotos) { - media.clear(); - media.addAll(newPhotos); + mMedia.clear(); + mMedia.addAll(newPhotos); notifyDataSetChanged(); } static class ViewHolder { @BindView(R.id.medium_thumbnail) ImageView photoThumbnail; - @BindView(R.id.play_outline) ImageView playOutline; + @BindView(R.id.play_outline) View playOutline; public ViewHolder(View view) { ButterKnife.bind(this, view); diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java index a7e6f8786..76c598dde 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java @@ -17,25 +17,25 @@ import java.util.List; import java.util.Map; public class MyPagerAdapter extends FragmentStatePagerAdapter { - private List media; - private Map fragments; - private ViewPagerActivity activity; + private final List mMedia; + private final Map mFragments; + private final ViewPagerActivity mActivity; public MyPagerAdapter(ViewPagerActivity act, FragmentManager fm, List media) { super(fm); - this.activity = act; - this.media = media; - fragments = new HashMap<>(); + this.mActivity = act; + this.mMedia = media; + mFragments = new HashMap<>(); } @Override public int getCount() { - return media.size(); + return mMedia.size(); } @Override public Fragment getItem(int position) { - final Medium medium = media.get(position); + final Medium medium = mMedia.get(position); final Bundle bundle = new Bundle(); bundle.putSerializable(Constants.MEDIUM, medium); ViewPagerFragment fragment; @@ -46,21 +46,21 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter { fragment = new PhotoFragment(); } - fragments.put(position, fragment); + mFragments.put(position, fragment); fragment.setArguments(bundle); - fragment.setListener(activity); + fragment.setListener(mActivity); return fragment; } public void itemDragged(int pos) { - if (fragments.get(pos) != null) { - fragments.get(pos).itemDragged(); + if (mFragments.get(pos) != null) { + mFragments.get(pos).itemDragged(); } } public void updateUiVisibility(boolean isFullscreen, int pos) { for (int i = -1; i <= 1; i++) { - ViewPagerFragment fragment = fragments.get(pos + i); + final ViewPagerFragment fragment = mFragments.get(pos + i); if (fragment != null) { fragment.systemUiVisibilityChanged(isFullscreen); } @@ -68,8 +68,8 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter { } public void updateItems(List newPaths) { - media.clear(); - media.addAll(newPaths); + mMedia.clear(); + mMedia.addAll(newPaths); notifyDataSetChanged(); } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java index 68a7357d4..d68c0dbfe 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java @@ -37,10 +37,10 @@ public class PhotoFragment extends ViewPagerFragment implements View.OnClickList @Override public void onClick(View v) { - if (listener == null) - listener = (FragmentClickListener) getActivity(); + if (mListener == null) + mListener = (FragmentClickListener) getActivity(); - listener.fragmentClicked(); + mListener.fragmentClicked(); } @Override diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java index a60f5f782..82c86fc32 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java @@ -35,33 +35,34 @@ public class VideoFragment extends ViewPagerFragment SeekBar.OnSeekBarChangeListener, OnPreparedListener { private static final String TAG = VideoFragment.class.getSimpleName(); private static final String PROGRESS = "progress"; - private MediaPlayer mediaPlayer; - private SurfaceView surfaceView; - private SurfaceHolder surfaceHolder; - private ImageView playOutline; - private TextView currTimeView; - private TextView durationView; - private Handler timerHandler; - private SeekBar seekBar; - private Medium medium; - private View timeHolder; - private boolean isPlaying; - private boolean isDragged; - private boolean isFullscreen; - private int currTime; - private int duration; + private MediaPlayer mMediaPlayer; + private SurfaceView mSurfaceView; + private SurfaceHolder mSurfaceHolder; + private ImageView mPlayOutline; + private TextView mCurrTimeView; + private TextView mDurationView; + private Handler mTimerHandler; + private SeekBar mSeekBar; + private Medium mMedium; + private View mTimeHolder; + + private boolean mIsPlaying; + private boolean mIsDragged; + private boolean mIsFullscreen; + private int mCurrTime; + private int mDuration; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.pager_video_item, container, false); - medium = (Medium) getArguments().getSerializable(Constants.MEDIUM); + mMedium = (Medium) getArguments().getSerializable(Constants.MEDIUM); if (savedInstanceState != null) { - currTime = savedInstanceState.getInt(PROGRESS); + mCurrTime = savedInstanceState.getInt(PROGRESS); } - isFullscreen = (getActivity().getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) == + mIsFullscreen = (getActivity().getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) == View.SYSTEM_UI_FLAG_FULLSCREEN; setupPlayer(view); view.setOnClickListener(this); @@ -73,13 +74,13 @@ public class VideoFragment extends ViewPagerFragment if (getActivity() == null) return; - playOutline = (ImageView) view.findViewById(R.id.video_play_outline); - playOutline.setOnClickListener(this); + mPlayOutline = (ImageView) view.findViewById(R.id.video_play_outline); + mPlayOutline.setOnClickListener(this); - surfaceView = (SurfaceView) view.findViewById(R.id.video_surface); - surfaceView.setOnClickListener(this); - surfaceHolder = surfaceView.getHolder(); - surfaceHolder.addCallback(this); + mSurfaceView = (SurfaceView) view.findViewById(R.id.video_surface); + mSurfaceView.setOnClickListener(this); + mSurfaceHolder = mSurfaceView.getHolder(); + mSurfaceHolder.addCallback(this); initTimeHolder(view); } @@ -90,42 +91,42 @@ public class VideoFragment extends ViewPagerFragment @Override public void systemUiVisibilityChanged(boolean toFullscreen) { - if (isFullscreen != toFullscreen) { - isFullscreen = toFullscreen; + if (mIsFullscreen != toFullscreen) { + mIsFullscreen = toFullscreen; checkFullscreen(); } } private void initTimeHolder(View view) { - timeHolder = view.findViewById(R.id.video_time_holder); + mTimeHolder = view.findViewById(R.id.video_time_holder); final Resources res = getResources(); final int height = Utils.getNavBarHeight(res); - final int left = timeHolder.getPaddingLeft(); - final int top = timeHolder.getPaddingTop(); - final int right = timeHolder.getPaddingRight(); - final int bottom = timeHolder.getPaddingBottom(); + final int left = mTimeHolder.getPaddingLeft(); + final int top = mTimeHolder.getPaddingTop(); + final int right = mTimeHolder.getPaddingRight(); + final int bottom = mTimeHolder.getPaddingBottom(); if (Utils.hasNavBar(res)) { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - timeHolder.setPadding(left, top, right, bottom + height); + mTimeHolder.setPadding(left, top, right, bottom + height); } else { - timeHolder.setPadding(left, top, right + height, bottom); + mTimeHolder.setPadding(left, top, right + height, bottom); } } - currTimeView = (TextView) view.findViewById(R.id.video_curr_time); - durationView = (TextView) view.findViewById(R.id.video_duration); - seekBar = (SeekBar) view.findViewById(R.id.video_seekbar); - seekBar.setOnSeekBarChangeListener(this); + mCurrTimeView = (TextView) view.findViewById(R.id.video_curr_time); + mDurationView = (TextView) view.findViewById(R.id.video_duration); + mSeekBar = (SeekBar) view.findViewById(R.id.video_seekbar); + mSeekBar.setOnSeekBarChangeListener(this); - if (isFullscreen) - timeHolder.setVisibility(View.INVISIBLE); + if (mIsFullscreen) + mTimeHolder.setVisibility(View.INVISIBLE); } private void setupTimeHolder() { - seekBar.setMax(duration); - durationView.setText(getTimeString(duration)); - timerHandler = new Handler(); + mSeekBar.setMax(mDuration); + mDurationView.setText(getTimeString(mDuration)); + mTimerHandler = new Handler(); setupTimer(); } @@ -133,13 +134,13 @@ public class VideoFragment extends ViewPagerFragment getActivity().runOnUiThread(new Runnable() { @Override public void run() { - if (mediaPlayer != null && !isDragged && isPlaying) { - currTime = mediaPlayer.getCurrentPosition() / 1000; - seekBar.setProgress(currTime); - currTimeView.setText(getTimeString(currTime)); + if (mMediaPlayer != null && !mIsDragged && mIsPlaying) { + mCurrTime = mMediaPlayer.getCurrentPosition() / 1000; + mSeekBar.setProgress(mCurrTime); + mCurrTimeView.setText(getTimeString(mCurrTime)); } - timerHandler.postDelayed(this, 1000); + mTimerHandler.postDelayed(this, 1000); } }); } @@ -147,7 +148,7 @@ public class VideoFragment extends ViewPagerFragment @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(PROGRESS, currTime); + outState.putInt(PROGRESS, mCurrTime); } @Override @@ -157,31 +158,31 @@ public class VideoFragment extends ViewPagerFragment togglePlayPause(); break; default: - isFullscreen = !isFullscreen; + mIsFullscreen = !mIsFullscreen; checkFullscreen(); - if (listener == null) - listener = (FragmentClickListener) getActivity(); - listener.fragmentClicked(); + if (mListener == null) + mListener = (FragmentClickListener) getActivity(); + mListener.fragmentClicked(); break; } } private void checkFullscreen() { int anim = R.anim.fade_in; - if (isFullscreen) { + if (mIsFullscreen) { anim = R.anim.fade_out; - seekBar.setOnSeekBarChangeListener(null); + mSeekBar.setOnSeekBarChangeListener(null); } else { - seekBar.setOnSeekBarChangeListener(this); + mSeekBar.setOnSeekBarChangeListener(this); } final Animation animation = AnimationUtils.loadAnimation(getContext(), anim); - timeHolder.startAnimation(animation); + mTimeHolder.startAnimation(animation); } private void pauseVideo() { - if (isPlaying) { + if (mIsPlaying) { togglePlayPause(); } } @@ -190,19 +191,19 @@ public class VideoFragment extends ViewPagerFragment if (getActivity() == null) return; - isPlaying = !isPlaying; - if (isPlaying) { - if (mediaPlayer != null) { - mediaPlayer.start(); + mIsPlaying = !mIsPlaying; + if (mIsPlaying) { + if (mMediaPlayer != null) { + mMediaPlayer.start(); } - playOutline.setImageDrawable(null); + mPlayOutline.setImageDrawable(null); } else { - if (mediaPlayer != null) { - mediaPlayer.pause(); + if (mMediaPlayer != null) { + mMediaPlayer.pause(); } - playOutline.setImageDrawable(getResources().getDrawable(R.mipmap.play_outline_big)); + mPlayOutline.setImageDrawable(getResources().getDrawable(R.mipmap.play_outline_big)); } } @@ -212,32 +213,32 @@ public class VideoFragment extends ViewPagerFragment } private void initMediaPlayer() { - if (mediaPlayer != null) + if (mMediaPlayer != null) return; try { - mediaPlayer = new MediaPlayer(); - mediaPlayer.setDataSource(getContext(), Uri.parse(medium.getPath())); - mediaPlayer.setDisplay(surfaceHolder); - mediaPlayer.setOnCompletionListener(this); - mediaPlayer.setOnVideoSizeChangedListener(this); - mediaPlayer.setOnPreparedListener(this); - mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); - mediaPlayer.prepareAsync(); + mMediaPlayer = new MediaPlayer(); + mMediaPlayer.setDataSource(getContext(), Uri.parse(mMedium.getPath())); + mMediaPlayer.setDisplay(mSurfaceHolder); + mMediaPlayer.setOnCompletionListener(this); + mMediaPlayer.setOnVideoSizeChangedListener(this); + mMediaPlayer.setOnPreparedListener(this); + mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + mMediaPlayer.prepareAsync(); } catch (IOException e) { Log.e(TAG, "init media player " + e.getMessage()); } } private void setProgress(int seconds) { - mediaPlayer.seekTo(seconds * 1000); - seekBar.setProgress(seconds); - currTimeView.setText(getTimeString(seconds)); + mMediaPlayer.seekTo(seconds * 1000); + mSeekBar.setProgress(seconds); + mCurrTimeView.setText(getTimeString(seconds)); } private void addPreviewImage() { - mediaPlayer.start(); - mediaPlayer.pause(); + mMediaPlayer.start(); + mMediaPlayer.pause(); } @Override @@ -257,19 +258,19 @@ public class VideoFragment extends ViewPagerFragment private void cleanup() { pauseVideo(); - if (currTimeView != null) - currTimeView.setText(getTimeString(0)); + if (mCurrTimeView != null) + mCurrTimeView.setText(getTimeString(0)); - if (mediaPlayer != null) { - mediaPlayer.release(); - mediaPlayer = null; + if (mMediaPlayer != null) { + mMediaPlayer.release(); + mMediaPlayer = null; } - if (seekBar != null) - seekBar.setProgress(0); + if (mSeekBar != null) + mSeekBar.setProgress(0); - if (timerHandler != null) - timerHandler.removeCallbacksAndMessages(null); + if (mTimerHandler != null) + mTimerHandler.removeCallbacksAndMessages(null); } @Override @@ -284,8 +285,8 @@ public class VideoFragment extends ViewPagerFragment @Override public void onCompletion(MediaPlayer mp) { - seekBar.setProgress(seekBar.getMax()); - currTimeView.setText(getTimeString(duration)); + mSeekBar.setProgress(mSeekBar.getMax()); + mCurrTimeView.setText(getTimeString(mDuration)); pauseVideo(); } @@ -315,7 +316,7 @@ public class VideoFragment extends ViewPagerFragment final float screenProportion = (float) screenWidth / (float) screenHeight; - final android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams(); + final android.view.ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams(); if (videoProportion > screenProportion) { lp.width = screenWidth; lp.height = (int) ((float) screenWidth / videoProportion); @@ -323,7 +324,7 @@ public class VideoFragment extends ViewPagerFragment lp.width = (int) (videoProportion * (float) screenHeight); lp.height = screenHeight; } - surfaceView.setLayoutParams(lp); + mSurfaceView.setLayoutParams(lp); } private String getTimeString(int duration) { @@ -344,36 +345,36 @@ public class VideoFragment extends ViewPagerFragment @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - if (mediaPlayer != null && fromUser) { + if (mMediaPlayer != null && fromUser) { setProgress(progress); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { - if (mediaPlayer == null) + if (mMediaPlayer == null) initMediaPlayer(); - mediaPlayer.pause(); - isDragged = true; + mMediaPlayer.pause(); + mIsDragged = true; } @Override public void onStopTrackingTouch(SeekBar seekBar) { - if (!isPlaying) { + if (!mIsPlaying) { togglePlayPause(); } else { - mediaPlayer.start(); + mMediaPlayer.start(); } - isDragged = false; + mIsDragged = false; } @Override public void onPrepared(MediaPlayer mp) { - duration = mp.getDuration() / 1000; + mDuration = mp.getDuration() / 1000; addPreviewImage(); setupTimeHolder(); - setProgress(currTime); + setProgress(mCurrTime); } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java index 55502a4d7..235839c92 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java @@ -3,10 +3,10 @@ package com.simplemobiletools.gallery.fragments; import android.support.v4.app.Fragment; public abstract class ViewPagerFragment extends Fragment { - protected FragmentClickListener listener; + protected FragmentClickListener mListener; - public void setListener(FragmentClickListener ln) { - listener = ln; + public void setListener(FragmentClickListener listener) { + mListener = listener; } public abstract void itemDragged(); diff --git a/app/src/main/java/com/simplemobiletools/gallery/models/Directory.java b/app/src/main/java/com/simplemobiletools/gallery/models/Directory.java index f8454a890..9f8c155f1 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/models/Directory.java +++ b/app/src/main/java/com/simplemobiletools/gallery/models/Directory.java @@ -49,4 +49,14 @@ public class Directory implements Comparable { } return 0; } + + @Override + public String toString() { + return "Directory {" + + "path=" + getPath() + + ", thumbnail=" + getThumbnail() + + ", name=" + getName() + + ", timestamp=" + getTimestamp() + + ", mediaCnt=" + getMediaCnt() + "}"; + } }