display the selected image fullscreen

This commit is contained in:
tibbi 2016-02-20 22:54:41 +01:00
parent 0ab046c8d5
commit 497ca6b127
8 changed files with 134 additions and 4 deletions

View File

@ -24,5 +24,10 @@
<activity
android:name=".PhotosActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".PhotoActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
</application>
</manifest>

View File

@ -2,4 +2,5 @@ package gallery.simplemobiletools.com;
public class Constants {
public static final String DIRECTORY = "directory";
public static final String PHOTO = "photo";
}

View File

@ -0,0 +1,48 @@
package gallery.simplemobiletools.com;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import java.util.List;
public class MyPagerAdapter extends PagerAdapter {
private final Context context;
private final List<String> paths;
private final LayoutInflater inflater;
public MyPagerAdapter(Context context, List<String> paths) {
this.context = context;
this.paths = paths;
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return paths.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
final View view = inflater.inflate(R.layout.pager_item, container, false);
final ImageView imageView = (ImageView) view.findViewById(R.id.photo);
Glide.with(context).load(paths.get(position)).fitCenter().crossFade().into(imageView);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}

View File

@ -0,0 +1,55 @@
package gallery.simplemobiletools.com;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class PhotoActivity extends AppCompatActivity {
private int pos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
pos = 0;
final ViewPager pager = (ViewPager) findViewById(R.id.view_pager);
final MyPagerAdapter adapter = new MyPagerAdapter(this, getPhotos());
pager.setAdapter(adapter);
pager.setCurrentItem(pos);
}
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 Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
int i = 0;
if (cursor != null && cursor.moveToFirst()) {
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
do {
final String curPath = cursor.getString(pathIndex);
photos.add(curPath);
if (curPath.equals(path))
pos = i;
i++;
} while (cursor.moveToNext());
cursor.close();
}
return photos;
}
}

View File

@ -1,5 +1,6 @@
package gallery.simplemobiletools.com;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
@ -13,12 +14,14 @@ import java.util.ArrayList;
import java.util.List;
public class PhotosActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private List<String> photos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photos);
photos = new ArrayList<>();
final GridView gridView = (GridView) findViewById(R.id.photos_grid);
final PhotosAdapter adapter = new PhotosAdapter(this, getPhotos());
gridView.setAdapter(adapter);
@ -26,7 +29,6 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
}
private List<String> getPhotos() {
final List<String> photos = new ArrayList<>();
final String path = getIntent().getStringExtra(Constants.DIRECTORY);
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
final String where = MediaStore.Images.Media.DATA + " like ? ";
@ -46,6 +48,8 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Intent intent = new Intent(this, PhotoActivity.class);
intent.putExtra(Constants.PHOTO, photos.get(position));
startActivity(intent);
}
}

View File

@ -0,0 +1,13 @@
<?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="match_parent"
android:background="@android:color/black">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/photo"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

View File

@ -1,8 +1,6 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>