Search in sources :

Example 1 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class ExifEditorActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_exif_editor);
    AlbumItem albumItem = getIntent().getParcelableExtra(ALBUM_ITEM);
    if (savedInstanceState != null && savedInstanceState.containsKey(EDITED_ITEMS)) {
        editedItems = savedInstanceState.getParcelableArrayList(EDITED_ITEMS);
    } else {
        editedItems = new ArrayList<>();
    }
    if (albumItem == null) {
        this.finish();
        return;
    }
    String mimeType = MediaType.getMimeType(this, albumItem.getUri(this));
    if (!MediaType.doesSupportWritingExifMimeType(mimeType)) {
        Toast.makeText(this, "Editing Exif values is only supported for JPEG images", Toast.LENGTH_SHORT).show();
        this.finish();
        return;
    }
    exifInterface = null;
    try {
        exifInterface = new ExifInterface(albumItem.getPath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (exifInterface == null) {
        this.finish();
        return;
    }
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    final RecyclerView recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(new RecyclerViewAdapter(new RecyclerViewAdapter.OnEditCallback() {

        @Override
        public void onItemEdited(String tag, String newValue) {
            for (ExifUtil.ExifItem item : editedItems) {
                if (item.getTag().equals(tag)) {
                    item.setValue(newValue);
                    showSaveButton(true);
                    return;
                }
            }
            // ExifItem wasn't previously edited
            ExifUtil.ExifItem item = getItem(tag);
            item.setValue(newValue);
            editedItems.add(item);
            showSaveButton(true);
        }

        @Override
        public ExifUtil.ExifItem getItem(String tag) {
            for (ExifUtil.ExifItem item : editedItems) {
                if (item.getTag().equals(tag)) {
                    return item;
                }
            }
            return new ExifUtil.ExifItem(tag, exifInterface.getAttribute(tag));
        }
    }));
    final ViewGroup rootView = findViewById(R.id.root_view);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @Override
            @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
            public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
                toolbar.setPadding(toolbar.getPaddingStart() + insets.getSystemWindowInsetLeft(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd() + insets.getSystemWindowInsetRight(), toolbar.getPaddingBottom());
                recyclerView.setPadding(recyclerView.getPaddingStart() + insets.getSystemWindowInsetLeft(), recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + insets.getSystemWindowInsetRight(), recyclerView.getPaddingBottom() + insets.getSystemWindowInsetBottom());
                // clear this listener so insets aren't re-applied
                rootView.setOnApplyWindowInsetsListener(null);
                return insets.consumeSystemWindowInsets();
            }
        });
    } else {
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                // hacky way of getting window insets on pre-Lollipop
                int[] screenSize = Util.getScreenSize(ExifEditorActivity.this);
                int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
                toolbar.setPadding(toolbar.getPaddingStart() + windowInsets[0], toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd() + windowInsets[2], toolbar.getPaddingBottom());
                recyclerView.setPadding(recyclerView.getPaddingStart() + windowInsets[0], recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + windowInsets[2], recyclerView.getPaddingBottom() + windowInsets[3]);
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
}
Also used : ViewGroup(android.view.ViewGroup) ExifInterface(android.support.media.ExifInterface) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) IOException(java.io.IOException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) RequiresApi(android.support.annotation.RequiresApi) RecyclerView(android.support.v7.widget.RecyclerView) ExifUtil(us.koller.cameraroll.util.ExifUtil) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class AlbumActivity method deleteAlbumItemsSnackbar.

public void deleteAlbumItemsSnackbar(String[] selected_items) {
    if (!MediaProvider.checkPermission(this)) {
        return;
    }
    final int[] indices = new int[selected_items.length];
    final AlbumItem[] deletedItems = new AlbumItem[selected_items.length];
    for (int i = selected_items.length - 1; i >= 0; i--) {
        for (int k = 0; k < album.getAlbumItems().size(); k++) {
            AlbumItem albumItem = album.getAlbumItems().get(k);
            if (selected_items[i].equals(albumItem.getPath())) {
                indices[i] = k;
                deletedItems[i] = albumItem;
                album.getAlbumItems().remove(k);
                recyclerViewAdapter.notifyItemRemoved(k);
            }
        }
    }
    int messageRes = selected_items.length == 1 ? R.string.file_deleted : R.string.files_deleted;
    String message = getString(messageRes, selected_items.length);
    // noinspection deprecation
    snackbar = Snackbar.make(findViewById(R.id.root_view), message, Snackbar.LENGTH_LONG).setAction(R.string.undo, new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            for (int i = 0; i < deletedItems.length; i++) {
                AlbumItem albumItem = deletedItems[i];
                int index = indices[i];
                album.getAlbumItems().add(index, albumItem);
                recyclerViewAdapter.notifyItemInserted(index);
            }
        }
    }).setCallback(new Snackbar.Callback() {

        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            super.onDismissed(snackbar, event);
            if (event != Snackbar.Callback.DISMISS_EVENT_ACTION) {
                deleteAlbumItems(deletedItems, indices);
            }
        }
    });
    Util.showSnackbar(snackbar);
}
Also used : SharedElementCallback(android.support.v4.app.SharedElementCallback) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) View(android.view.View) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 3 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class ItemAdapter method instantiateItem.

@NonNull
@Override
public Object instantiateItem(@NonNull final ViewGroup container, int position) {
    AlbumItem albumItem = album.getAlbumItems().get(position);
    ViewHolder viewHolder;
    if (albumItem instanceof Video) {
        viewHolder = new VideoViewHolder(albumItem, position);
    } else if (albumItem instanceof Gif) {
        viewHolder = new GifViewHolder(albumItem, position);
    } else if (albumItem instanceof RAWImage) {
        viewHolder = new RAWImageViewHolder(albumItem, position);
    } else {
        viewHolder = new PhotoViewHolder(albumItem, position);
    }
    viewHolders.add(viewHolder);
    View v = viewHolder.getView(container);
    container.addView(v);
    if (callback != null) {
        boolean b = callback.onInstantiateItem(viewHolder);
        if (!b) {
            callback = null;
        }
    }
    return v;
}
Also used : RAWImage(us.koller.cameraroll.data.models.RAWImage) PhotoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder) VideoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder) RAWImageViewHolder(us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) GifViewHolder(us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder) Gif(us.koller.cameraroll.data.models.Gif) Video(us.koller.cameraroll.data.models.Video) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) RAWImageViewHolder(us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder) PhotoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder) VideoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder) GifViewHolder(us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder) View(android.view.View) NonNull(android.support.annotation.NonNull)

Example 4 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class FileExplorerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    final File_POJO file = files.getChildren().get(position);
    ((FileHolder) holder).setFile(file);
    ((FileHolder) holder).setSelected(selected_items[position]);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mode == SELECTOR_MODE) {
                onItemSelect(file);
            } else if (file.isMedia) {
                int index = file.getPath().lastIndexOf("/");
                String path = file.getPath().substring(0, index);
                // load Album
                final Album album = new Album().setPath(path);
                AlbumItem albumItem = AlbumItem.getInstance(file.getPath());
                if (albumItem != null) {
                    album.getAlbumItems().add(albumItem);
                }
                if (albumItem != null) {
                    // create intent
                    Intent intent = new Intent(holder.itemView.getContext(), IntentReceiver.class).setAction(Intent.ACTION_VIEW).setData(albumItem.getUri(holder.itemView.getContext()));
                    holder.itemView.getContext().startActivity(intent);
                }
            } else {
                // to keep the ripple animation
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        directoryChangeCallback.changeDir(file.getPath());
                    }
                }, 300);
            }
        }
    });
    holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            onItemSelect(file);
            return true;
        }
    });
    // clicking on folder icons also selects this item
    holder.itemView.findViewById(R.id.folder_indicator).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onItemSelect(file);
        }
    });
}
Also used : Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Handler(android.os.Handler) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) FileHolder(us.koller.cameraroll.adapter.fileExplorer.viewHolder.FileHolder)

Example 5 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class MediaStoreRetriever method checkHiddenFolders.

private ArrayList<Album> checkHiddenFolders(final Activity context) {
    ArrayList<Album> hiddenAlbums = new ArrayList<>();
    // Scan all no Media files
    String nonMediaCondition = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
    // Files with name contain .nomedia
    String selection = nonMediaCondition + " AND " + MediaStore.Files.FileColumns.TITLE + " LIKE ?";
    String[] params = new String[] { "%" + MediaProvider.FILE_TYPE_NO_MEDIA + "%" };
    // make query for non media files with file title contain ".nomedia" as
    // text on External Media URI
    Cursor cursor = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), new String[] { MediaStore.Files.FileColumns.DATA }, selection, params, MediaStore.Images.Media.DATE_TAKEN);
    if (cursor == null || cursor.getCount() == 0) {
        return hiddenAlbums;
    }
    if (cursor.moveToFirst()) {
        int pathColumn = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
        do {
            String path = cursor.getString(pathColumn);
            path = path.replace(MediaProvider.FILE_TYPE_NO_MEDIA, "");
            File dir = new File(path);
            final Album album = new Album().setPath(path);
            File[] files = dir.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    AlbumItem albumItem = AlbumItem.getInstance(files[i].getPath());
                    if (albumItem != null) {
                        album.getAlbumItems().add(albumItem);
                    }
                }
            }
            if (album.getAlbumItems().size() > 0) {
                hiddenAlbums.add(album);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return hiddenAlbums;
}
Also used : ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Cursor(android.database.Cursor) File(java.io.File)

Aggregations

AlbumItem (us.koller.cameraroll.data.models.AlbumItem)13 View (android.view.View)6 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 Album (us.koller.cameraroll.data.models.Album)4 Uri (android.net.Uri)3 ArrayList (java.util.ArrayList)3 Video (us.koller.cameraroll.data.models.Video)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 RequiresApi (android.support.annotation.RequiresApi)2 AlbumActivity (us.koller.cameraroll.ui.AlbumActivity)2 FastScrollerRecyclerView (us.koller.cameraroll.ui.widget.FastScrollerRecyclerView)2 ClipData (android.content.ClipData)1 DialogInterface (android.content.DialogInterface)1 Bitmap (android.graphics.Bitmap)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 Snackbar (android.support.design.widget.Snackbar)1