open a new activity with photos on directory click
This commit is contained in:
parent
8e66c935a6
commit
d285b3e261
6 changed files with 55 additions and 4 deletions
|
@ -20,5 +20,9 @@
|
|||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".PhotosActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package gallery.simplemobiletools.com;
|
||||
|
||||
public class Constants {
|
||||
public static final String DIRECTORY = "directory";
|
||||
}
|
|
@ -1,16 +1,22 @@
|
|||
package gallery.simplemobiletools.com;
|
||||
|
||||
public class Directory {
|
||||
private final String path;
|
||||
private final String thumbnail;
|
||||
private final String name;
|
||||
private int photoCnt;
|
||||
|
||||
public Directory(String thumbnail, String name, int photoCnt) {
|
||||
public Directory(String path, String thumbnail, String name, int photoCnt) {
|
||||
this.path = path;
|
||||
this.thumbnail = thumbnail;
|
||||
this.name = name;
|
||||
this.photoCnt = photoCnt;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getThumbnail() {
|
||||
return thumbnail;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package gallery.simplemobiletools.com;
|
||||
|
||||
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.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.GridView;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -13,7 +17,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
public class MainActivity extends AppCompatActivity implements OnItemClickListener {
|
||||
private List<Directory> dirs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -21,9 +26,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_main);
|
||||
final GridView gridView = (GridView) findViewById(R.id.photo_grid);
|
||||
|
||||
final List<Directory> dirs = new ArrayList<>(getDirectories().values());
|
||||
dirs = new ArrayList<>(getDirectories().values());
|
||||
final DirectoryAdapter adapter = new DirectoryAdapter(this, dirs);
|
||||
gridView.setAdapter(adapter);
|
||||
gridView.setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
private Map<String, Directory> getDirectories() {
|
||||
|
@ -44,7 +50,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
} else {
|
||||
final String thumbnail = file.getAbsolutePath();
|
||||
final String dirName = fileDir.substring(fileDir.lastIndexOf("/") + 1);
|
||||
directories.put(fileDir, new Directory(thumbnail, dirName, 1));
|
||||
directories.put(fileDir, new Directory(fileDir, thumbnail, dirName, 1));
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
cursor.close();
|
||||
|
@ -52,4 +58,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
return directories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final Intent intent = new Intent(this, PhotosActivity.class);
|
||||
intent.putExtra(Constants.DIRECTORY, dirs.get(position).getPath());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package gallery.simplemobiletools.com;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
public class PhotosActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_photos);
|
||||
|
||||
final String path = getIntent().getStringExtra(Constants.DIRECTORY);
|
||||
}
|
||||
}
|
8
app/src/main/res/layout/activity_photos.xml
Normal file
8
app/src/main/res/layout/activity_photos.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/black">
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue