Skip to content

Commit

Permalink
Merge branch 'hotfix/6.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Nov 11, 2019
2 parents e547ffa + 263cde2 commit 66865bc
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 48 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
VERSION_NAME=6.0.3
VERSION_CODE=278
VERSION_NAME=6.0.4
VERSION_CODE=279
PACKAGE=it.feio.android.omninotes
MIN_SDK=16
TARGET_SDK=28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

import static org.junit.Assert.assertFalse;

import android.Manifest;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.GrantPermissionRule;
import it.feio.android.omninotes.db.DbHelper;
import it.feio.android.omninotes.utils.Constants;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;


public class BaseAndroidTestCase {
Expand All @@ -37,6 +40,13 @@ public class BaseAndroidTestCase {
protected static Context testContext;
protected static SharedPreferences prefs;

@Rule
public GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
);

@BeforeClass
public static void setUpBeforeClass () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@

public class BaseEspressoTest extends BaseAndroidTestCase {

@Rule
public GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
);

@Rule
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(MainActivity.class, false, false);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2013-2019 Federico Iosue ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package it.feio.android.omninotes.utils;

import static it.feio.android.omninotes.utils.ConstantsBase.MIME_TYPE_IMAGE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;

import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Looper;
import android.support.test.internal.runner.junit4.statement.UiThreadStatement;
import android.support.test.runner.AndroidJUnit4;
import it.feio.android.omninotes.BaseAndroidTestCase;
import it.feio.android.omninotes.models.Attachment;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class BitmapHelperTest extends BaseAndroidTestCase {

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

private Attachment attachment;

@Before
public void setUp () throws IOException {
File bitmapFile = tempFolder.newFile("bitmapFile.bmp");

Bitmap bmp = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
FileOutputStream out = new FileOutputStream(bitmapFile);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);

attachment = new Attachment(Uri.fromFile(bitmapFile), MIME_TYPE_IMAGE);
}

@Test
public void getBitmapFromAttachment_backgroundThread () {
Bitmap bmp = BitmapHelper.getBitmapFromAttachment(testContext, attachment, 100, 100);
assertNotEquals("Thread MUST be a background one", Looper.getMainLooper(), Looper.myLooper());
assertNotNull("Bitmap should not be null", bmp);
}

@Test
public void getBitmapFromAttachment_mainThread () throws Throwable {
UiThreadStatement.runOnUiThread(() -> {
Bitmap bmp = BitmapHelper.getBitmapFromAttachment(testContext, attachment, 100, 100);
assertEquals("Thread MUST be a the main one", Looper.getMainLooper(), Looper.myLooper());
assertNotNull("Bitmap should not be null", bmp);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@

package it.feio.android.omninotes.utils;

import android.support.test.filters.Suppress;
import android.support.test.runner.AndroidJUnit4;
import it.feio.android.omninotes.BaseAndroidTestCase;
import it.feio.android.omninotes.OmniNotes;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;


@Ignore("Unreliable Genymotion emulator results")
@RunWith(AndroidJUnit4.class)
public class GeocodeHelperTest extends BaseAndroidTestCase {

@Test
@Suppress
public void testGetAddressFromCoordinates () throws IOException {
if (ConnectionManager.internetAvailable(OmniNotes.getAppContext())) {
Double LAT = 43.799328;
Double LON = 11.171552;
double LAT = 43.799328;
double LON = 11.171552;
String address = GeocodeHelper.getAddressFromCoordinates(OmniNotes.getAppContext(), LAT, LON);
Assert.assertTrue(address.length() > 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import android.graphics.Bitmap;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.RemoteViews;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.AppWidgetTarget;
import it.feio.android.omninotes.OmniNotes;
import it.feio.android.omninotes.R;
import it.feio.android.omninotes.helpers.AttachmentsHelper;
Expand All @@ -54,16 +53,7 @@ public static Bitmap getBitmapFromAttachment (Context mContext, Attachment mAtta
mAttachment.getUri().getPath();

if (AttachmentsHelper.typeOf(mAttachment, MIME_TYPE_VIDEO, MIME_TYPE_IMAGE, MIME_TYPE_SKETCH)) {
try {
bmp = Glide.with(OmniNotes.getAppContext()).asBitmap()
.apply(new RequestOptions()
.centerCrop()
.error(R.drawable.attachment_broken))
.load(mAttachment.getUri())
.submit(width, height).get();
} catch (NullPointerException | InterruptedException | ExecutionException e) {
bmp = null;
}
bmp = getImageBitmap(mContext, mAttachment, width, height);

} else if (MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) {
bmp = ThumbnailUtils.extractThumbnail(
Expand All @@ -85,30 +75,24 @@ public static Bitmap getBitmapFromAttachment (Context mContext, Attachment mAtta
return bmp;
}

public static void loadAttachmentIntoWidget (Attachment mAttachment, AppWidgetTarget awt) {
mAttachment.getUri().getPath();

RequestBuilder<Bitmap> builder = Glide.with(OmniNotes.getAppContext()).asBitmap()
.apply(new RequestOptions()
.centerCrop()
.error(R.drawable.attachment_broken));

if (AttachmentsHelper.typeOf(mAttachment, MIME_TYPE_VIDEO, MIME_TYPE_IMAGE, MIME_TYPE_SKETCH)) {
builder = builder.load(mAttachment.getUri());
} else if (MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) {
builder = builder.load(R.raw.play);
} else if (MIME_TYPE_FILES.equals(mAttachment.getMime_type())) {
if (MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) {
builder = builder.load(R.raw.vcard);
@Nullable
private static Bitmap getImageBitmap (Context mContext, Attachment mAttachment, int width, int height) {
try {
if (Looper.getMainLooper() == Looper.myLooper()) {
return BitmapUtils.getThumbnail(mContext, mAttachment.getUri(), width, height);
} else {
builder = builder.load(R.raw.files);
return Glide.with(OmniNotes.getAppContext()).asBitmap()
.apply(new RequestOptions()
.centerCrop()
.error(R.drawable.attachment_broken))
.load(mAttachment.getUri())
.submit(width, height).get();
}
} catch (NullPointerException | InterruptedException | ExecutionException e) {
return null;
}

builder.into(awt);
}


public static Uri getThumbnailUri (Context mContext, Attachment mAttachment) {
Uri uri = mAttachment.getUri();
String mimeType = StorageHelper.getMimeType(uri.toString());
Expand Down
6 changes: 6 additions & 0 deletions omniNotes/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
-->
<changelog bulletedList="true">

<changelogversion
changeDate="Nov 11, 2019"
versionName="6.0.4">
<changelogtext>[u]Fix[/u] Notification on notes with attachments</changelogtext>
</changelogversion>

<changelogversion
changeDate="Nov 3, 2019"
versionName="6.0.3">
Expand Down

0 comments on commit 66865bc

Please sign in to comment.