Skip to content

Commit

Permalink
Merge pull request Yalantis#394 from Legementarion/round_cut
Browse files Browse the repository at this point in the history
crop with fragment
  • Loading branch information
PenzK authored Mar 28, 2018
2 parents c931206 + f140b2c commit 8319036
Show file tree
Hide file tree
Showing 20 changed files with 1,270 additions and 372 deletions.
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
ext {
support = '27.1.0'
constraints = '1.0.2'
}
}

def isReleaseBuild() {
Expand All @@ -22,6 +30,10 @@ allprojects {

repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
26 changes: 17 additions & 9 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '25.0.0'

compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.yalantis.ucrop.sample"
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 27
versionCode 10
versionName "1.2.2"
}
flavorDimensions "default"
buildTypes {
release {
minifyEnabled false
Expand All @@ -21,14 +21,22 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
lintOptions {
abortOnError false
}

productFlavors {
activity {
buildConfigField("int","RequestMode", "1")
}
fragment {
buildConfigField("int","RequestMode", "2")
}
}
}

dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'

compile project (':ucrop')
implementation "com.android.support:appcompat-v7:$support"
implementation "com.android.support:support-compat:$support"
implementation "com.android.support.constraint:constraint-layout:$constraints"
compile project(':ucrop')
}
25 changes: 12 additions & 13 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.yalantis.ucrop.sample"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yalantis.ucrop.sample">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@string/file_provider_authorities"
Expand All @@ -23,24 +22,24 @@
</provider>

<activity
android:name="com.yalantis.ucrop.sample.SampleActivity"
android:name=".SampleActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.yalantis.ucrop.sample.ResultActivity"
android:screenOrientation="portrait"/>
android:name=".ResultActivity"
android:screenOrientation="portrait" />

<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

</application>

</manifest>
</manifest>
53 changes: 38 additions & 15 deletions sample/src/main/java/com/yalantis/ucrop/sample/ResultActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yalantis.ucrop.sample;

import android.Manifest;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
Expand All @@ -10,6 +11,7 @@
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -41,6 +43,7 @@
public class ResultActivity extends BaseActivity {

private static final String TAG = "ResultActivity";
private static final String CHANNEL_ID = "3000";
private static final int DOWNLOAD_NOTIFICATION_ID_DONE = 911;

public static void startWithUri(@NonNull Context context, @NonNull Uri uri) {
Expand All @@ -53,18 +56,19 @@ public static void startWithUri(@NonNull Context context, @NonNull Uri uri) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);

try {
UCropView uCropView = (UCropView) findViewById(R.id.ucrop);
uCropView.getCropImageView().setImageUri(getIntent().getData(), null);
uCropView.getOverlayView().setShowCropFrame(false);
uCropView.getOverlayView().setShowCropGrid(false);
uCropView.getOverlayView().setDimmedColor(Color.TRANSPARENT);
} catch (Exception e) {
Log.e(TAG, "setImageUri", e);
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
Uri uri = getIntent().getData();
if (uri != null) {
try {
UCropView uCropView = findViewById(R.id.ucrop);
uCropView.getCropImageView().setImageUri(getIntent().getData(), null);
uCropView.getOverlayView().setShowCropFrame(false);
uCropView.getOverlayView().setShowCropGrid(false);
uCropView.getOverlayView().setDimmedColor(Color.TRANSPARENT);
} catch (Exception e) {
Log.e(TAG, "setImageUri", e);
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}

final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(new File(getIntent().getData().getPath()).getAbsolutePath(), options);
Expand Down Expand Up @@ -146,6 +150,8 @@ private void copyFileToDownloads(Uri croppedFileUri) throws Exception {
outStream.close();

showNotification(saveFile);
Toast.makeText(this, R.string.notification_image_saved, Toast.LENGTH_SHORT).show();
finish();
}

private void showNotification(@NonNull File file) {
Expand All @@ -161,23 +167,40 @@ private void showNotification(@NonNull File file) {
List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(
intent,
PackageManager.MATCH_DEFAULT_ONLY);
for(ResolveInfo info: resInfoList) {
for (ResolveInfo info : resInfoList) {
grantUriPermission(
info.activityInfo.packageName,
fileUri, FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_READ_URI_PERMISSION);
}

NotificationCompat.Builder mNotification = new NotificationCompat.Builder(this);
NotificationCompat.Builder notificationBuilder;
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, getString(R.string.channel_name), importance);
mChannel.setDescription(getString(R.string.channel_description));
mChannel.enableLights(true);
mChannel.setLightColor(Color.YELLOW);
if (notificationManager != null) {
notificationManager.createNotificationChannel(mChannel);
}
notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
} else {
notificationBuilder = new NotificationCompat.Builder(this);
}

mNotification
notificationBuilder
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.notification_image_saved_click_to_preview))
.setTicker(getString(R.string.notification_image_saved))
.setSmallIcon(R.drawable.ic_done)
.setOngoing(false)
.setContentIntent(PendingIntent.getActivity(this, 0, intent, 0))
.setAutoCancel(true);
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(DOWNLOAD_NOTIFICATION_ID_DONE, mNotification.build());
if (notificationManager != null) {
notificationManager.notify(DOWNLOAD_NOTIFICATION_ID_DONE, notificationBuilder.build());
}
}

}
Loading

0 comments on commit 8319036

Please sign in to comment.