Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 881ce4ca authored by zhuw's avatar zhuw Committed by Rajshekar Eashwarappa
Browse files

Fix unable save image with gif underlay.

reopen pick activity and toast don't support gif extension

Change-Id: I3bb36cb74571ff01cd6b9a8de51a5e5c80ada731
CRs-Fixed: 2104809
parent bc4019fa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -238,4 +238,5 @@
    <!--Filtershow Toast -->
    <string name="no_faces_found">未能检测到人脸</string>
    <string name="image_size_too_small">图片尺寸太小</string>
    <string name="not_support_gif">不支持gif格式的图片,请重新选择</string>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -441,4 +441,5 @@
    <!--Filtershow Toast -->
    <string name="no_faces_found">No Faces Found</string>
    <string name="image_size_too_small">Image size too small</string>
    <string name="not_support_gif">do not support gif extension, please pick again</string>
</resources>
+50 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
@@ -38,6 +39,7 @@ import android.content.ServiceConnection;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
@@ -51,6 +53,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
@@ -68,6 +71,7 @@ import android.view.View.OnTouchListener;
import android.view.ViewPropertyAnimator;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
@@ -2540,13 +2544,57 @@ DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
                    EditorDualCamFusion editor = (EditorDualCamFusion)mCurrentEditor;
                    editor.setUnderlayImageUri(underlayImageUri);
                } else if (mCurrentEditor instanceof EditorTruePortraitFusion) {
                    if (checkExtensionValidity(this, underlayImageUri)) {
                        Toast.makeText(getApplicationContext(), getString(R.string.not_support_gif),
                                Toast.LENGTH_SHORT).show();
                        pickImage(SELECT_FUSION_UNDERLAY);
                    } else {
                        EditorTruePortraitFusion editor = (EditorTruePortraitFusion)mCurrentEditor;
                        editor.setUnderlayImageUri(underlayImageUri);
                    }
                }
            }
        }
    }

    /**
     * check whether the extension of the given uri is supported to be underlay
     * @param context context for get ContentResolver
     * @param uri uri need to check
     * @return validity of uri's extension, true means unsupported, false means supported
     */
    private boolean checkExtensionValidity(final Context context, final Uri uri) {
        if (uri == null) {
            return false;
        }
        // get file path from uri
        String filePath = null;
        final String scheme = uri.getScheme();
        if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) {
            filePath = uri.getPath();
        } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
            Cursor cursor = context.getContentResolver().query(
                    uri, new String[] {MediaStore.Images.ImageColumns.DATA}, null, null, null);
            if (null != cursor) {
                if (cursor.moveToFirst()) {
                    int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
                    if (index > -1) {
                        filePath = cursor.getString(index);
                    }
                }
                cursor.close();
            }
        }

        //get extension from filepath
        String extension = MimeTypeMap.getFileExtensionFromUrl(filePath);

        //check validity of extension
        boolean notSupported = false;
        //if have new unsupported extension, add it below
        notSupported |= (extension.equals("gif") || extension.equals("GIF"));
        return notSupported;
    }

    private int nameFilter(FilterPresetSource source,
                                            ArrayList <SaveOption> tempFilterArray) {