change the package name to com.simplemobiletools.gallery

- no real functionality change
This commit is contained in:
tibbi
2016-02-24 00:08:09 +01:00
parent c5224c12e5
commit f630b9aa3d
18 changed files with 37 additions and 38 deletions

View File

@ -0,0 +1,146 @@
package com.simplemobiletools.gallery.activities;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import com.simplemobiletools.gallery.Constants;
import com.simplemobiletools.gallery.MyViewPager;
import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.adapters.MyPagerAdapter;
public class ViewPagerActivity extends AppCompatActivity {
private int pos;
private boolean isFullScreen;
private ActionBar actionbar;
private List<String> photos;
private MyViewPager pager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
pos = 0;
actionbar = getSupportActionBar();
isFullScreen = true;
hideSystemUI();
final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
pager = (MyViewPager) findViewById(R.id.view_pager);
photos = getPhotos();
adapter.setPaths(photos);
pager.setAdapter(adapter);
pager.setCurrentItem(pos);
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
isFullScreen = false;
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_share:
shareImage();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void shareImage() {
final String shareTitle = getResources().getString(R.string.share_via);
final Intent sendIntent = new Intent();
final File file = new File(photos.get(pager.getCurrentItem()));
final Uri uri = Uri.fromFile(file);
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/*");
startActivity(Intent.createChooser(sendIntent, shareTitle));
}
private List<String> getPhotos() {
final List<String> photos = new ArrayList<>();
final String path = getIntent().getStringExtra(Constants.PHOTO);
final String fileDir = new File(path).getParent().toLowerCase();
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
final String where = MediaStore.Images.Media.DATA + " like ? ";
final String[] args = new String[]{fileDir + "%"};
final String[] columns = {MediaStore.Images.Media.DATA};
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
final String pattern = Pattern.quote(fileDir) + "/[^/]*";
int i = 0;
if (cursor != null && cursor.moveToFirst()) {
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
do {
final String curPath = cursor.getString(pathIndex);
if (curPath.toLowerCase().matches(pattern)) {
photos.add(curPath);
if (curPath.equals(path))
pos = i;
}
i++;
} while (cursor.moveToNext());
cursor.close();
}
return photos;
}
public void photoClicked() {
isFullScreen = !isFullScreen;
if (isFullScreen) {
hideSystemUI();
} else {
showSystemUI();
}
}
private void hideSystemUI() {
if (actionbar != null)
actionbar.hide();
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LOW_PROFILE |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE);
}
private void showSystemUI() {
if (actionbar != null)
actionbar.show();
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}