Skip to content

Commit

Permalink
Aggiornamenti gradle e librerie
Browse files Browse the repository at this point in the history
Fix name preferences ora protected
Modificata interamente classe PickerActivity per gestirla con FileProvider e per gestire la scalatura e la compressione dei bitmap
  • Loading branch information
Matty3Run committed Mar 21, 2017
1 parent 4a2a165 commit a9d5461
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 36 deletions.
10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion androidbase-account/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ dependencies {
})
compile 'com.facebook.android:facebook-android-sdk:4.18.0'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2'
testCompile 'junit:junit:4.12'
}
2 changes: 1 addition & 1 deletion androidbase-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2'
testCompile 'junit:junit:4.12'
}
4 changes: 2 additions & 2 deletions androidbase-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.google.android.gms:play-services-location:10.2.0'
compile 'com.google.android.gms:play-services-maps:10.2.0'
compile 'com.google.code.gson:gson:2.7'
Expand Down
10 changes: 10 additions & 0 deletions androidbase-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
android:theme="@style/CreditsTheme"
android:label="@string/Credits"/>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog;

import com.mr_apps.androidbase.utils.BitmapUtils;
import com.mr_apps.androidbase.utils.FileUtils;
import com.mr_apps.androidbase.utils.FileUtils.ElementType;
import com.mr_apps.androidbasecore.R;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;

/**
Expand All @@ -31,6 +37,9 @@
*/
public abstract class PickerActivity extends LocationActivity {

private static final int COMPRESSION_WIDTH = 1280;
private static final int COMPRESSION_HEIGHT = 1280;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -205,10 +214,19 @@ public void pickImage() {
* Opens the camera activity where the user can take a photo to return to this activity
*/
public void takePhoto() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = FileUtils.newFileToUpload(PickerActivity.this, getFolder(), ElementType.img, saveInInternalStorage);
imageUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

Uri uri;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file);
} else {
uri = Uri.fromFile(file);
}

intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, actionTakeImage);
}

Expand Down Expand Up @@ -236,9 +254,18 @@ public void pickVideo() {
* Opens the camera activity where the user can record a video to return to this activity
*/
public void recordVideo() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File file = FileUtils.newFileToUpload(PickerActivity.this, getFolder(), ElementType.vid, false);
videoUri = Uri.fromFile(file);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

Uri uri;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file);
} else {
uri = Uri.fromFile(file);
}

intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, getDurationVideo());
startActivityForResult(intent, actionRecordVideo);
Expand Down Expand Up @@ -271,7 +298,8 @@ public void recordAudio() {
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
File file = FileUtils.newFileToUpload(PickerActivity.this, getFolder(), ElementType.audio, false);
audioUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, audioUri);
Uri intentUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, intentUri);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, getDurationAudio());
startActivityForResult(intent, actionRecordAudio);
}
Expand Down Expand Up @@ -353,12 +381,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

FileUtils.MediaSelected mediaSelected = FileUtils.getPath(this, uri);
path = mediaSelected.path;
type = ElementType.img;

Bitmap bitmap = BitmapFactory.decodeFile(path);

pickerResult(path, type, bitmap);

onImageSelected(bitmap);

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -413,6 +439,25 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void onImageSelected(Bitmap bitmap) {
File file = FileUtils.newFileToUpload(PickerActivity.this, getFolder(), ElementType.img, saveInInternalStorage);

try {

Bitmap resizedBitmap = BitmapUtils.scaleBitmap(bitmap, COMPRESSION_WIDTH, COMPRESSION_HEIGHT);

OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, qualityImage, os);
os.close();

pickerResult(file.getPath(), ElementType.img, resizedBitmap);

} catch (IOException e) {
e.printStackTrace();
}

}

/**
* Method that should be override by the subclasses to manage the image taken from camera or picked from gallery
*
Expand Down Expand Up @@ -472,17 +517,20 @@ private void handleTempUri(Uri tempUri) {
ExifInterface exif = new ExifInterface(tempUri.getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

Bitmap resizedBitmap = BitmapUtils.scaleBitmap(bitmap);
Bitmap resizedBitmap = BitmapUtils.scaleBitmap(bitmap, COMPRESSION_WIDTH, COMPRESSION_HEIGHT);

Bitmap bitmap1 = BitmapUtils.rotateBitmap(resizedBitmap, orientation);

if (bitmap1 != null)
bitmap = bitmap1;

String path = FileUtils.getRealPath(this, tempUri);
ElementType type = ElementType.img;
File file = FileUtils.newFileToUpload(PickerActivity.this, getFolder(), ElementType.img, saveInInternalStorage);

OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, qualityImage, os);
os.close();

pickerResult(path, type, bitmap);
pickerResult(file.getPath(), ElementType.img, bitmap);

} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class GlobalPreferences extends AbstractBasePreferences {

private static final String namePreferences = "GlobalPreferences";
protected static final String namePreferences = "GlobalPreferences";
private static final String latitude = "latitude";
private static final String longitude = "longitude";
private static final String altitude = "altitude";
Expand Down
4 changes: 4 additions & 0 deletions androidbase-core/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>
4 changes: 2 additions & 2 deletions androidbase-gallery/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
})
compile 'com.github.chrisbanes:PhotoView:1.2.6'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-share:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-share:1.1.2'
testCompile 'junit:junit:4.12'
}
2 changes: 1 addition & 1 deletion androidbase-tutorial/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.viewpagerindicator:library:2.4.1'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2'
testCompile 'junit:junit:4.12'
}
2 changes: 1 addition & 1 deletion androidbase-webservice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2'
testCompile 'junit:junit:4.12'
}
14 changes: 7 additions & 7 deletions androidbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ artifacts {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-account:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-gallery:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-share:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-tutorial:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-webservice:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-adapter:1.1.2beta'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-core:1.1.2'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-account:1.1.2'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-gallery:1.1.2'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-share:1.1.2'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-tutorial:1.1.2'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-webservice:1.1.2'
compile 'com.github.MrAPPs-RSM.MrAppsAndroidBase:androidbase-adapter:1.1.2'
}
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.18.0'
androidTestCompile 'com.android.support:support-annotations:25.2.0'
androidTestCompile 'com.android.support:support-annotations:25.3.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
compile project(':androidbase')
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Tue Mar 21 12:23:28 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 comments on commit a9d5461

Please sign in to comment.