Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;

import com.cloudinary.android.preprocess.ResourceCreationException;
import com.cloudinary.android.preprocess.ResourceEncoder;
Expand Down Expand Up @@ -80,9 +81,13 @@ protected final String saveFile(Context context, Bitmap resource, int quality, F
return file;
}

@SuppressWarnings("deprecation")
private Bitmap.CompressFormat adaptFormat(Format format) {
switch (format) {
case WEBP:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return Bitmap.CompressFormat.WEBP_LOSSY;
}
return Bitmap.CompressFormat.WEBP;
case JPEG:
return Bitmap.CompressFormat.JPEG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.linkedin.android.litr.MediaTransformer;
import com.linkedin.android.litr.TransformationListener;
import com.linkedin.android.litr.TransformationOptions;
import com.linkedin.android.litr.analytics.TrackTransformationInfo;

import java.io.File;
Expand Down Expand Up @@ -55,14 +56,14 @@ public Uri execute(Context context, Uri resource) throws PreprocessException {

TransformationListener transformationListener = new VideoTransformationListener();
MediaTransformer mediaTransformer = new MediaTransformer(context.getApplicationContext());
TransformationOptions options = new TransformationOptions.Builder().setGranularity(MediaTransformer.GRANULARITY_DEFAULT).build();
mediaTransformer.transform(parameters.getRequestId(),
resource,
targetFilePath,
targetVideoFormat,
targetAudioFormat,
transformationListener,
MediaTransformer.GRANULARITY_DEFAULT,
null);
options);

synchronized (lockObject) {
try {
Expand Down
1 change: 1 addition & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {

dependencies {
implementation project(':all')
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.os.HandlerThread;
import android.os.IBinder;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.util.TypedValue;

Expand Down Expand Up @@ -40,14 +42,14 @@ public class CloudinaryService extends ListenerService {
private NotificationManager notificationManager;
private AtomicInteger idsProvider = new AtomicInteger(1000);
private Map<String, Integer> requestIdsToNotificationIds = new ConcurrentHashMap<>();
private Notification.Builder builder;
private NotificationCompat.Builder builder;
private Handler backgroundThreadHandler;

@Override
public void onCreate() {
super.onCreate();
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
builder = new Notification.Builder(this);
builder = new NotificationCompat.Builder(this, MainApplication.NOTIFICATION_CHANNEL_ID);
builder.setContentTitle("Uploading to Cloudinary...")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(PendingIntent.getActivity(this, 999,
Expand All @@ -72,8 +74,8 @@ public IBinder onBind(Intent intent) {
}


private Notification.Builder getBuilder(String requestId, Resource.UploadStatus status) {
Notification.Builder builder = new Notification.Builder(this)
private NotificationCompat.Builder getBuilder(String requestId, Resource.UploadStatus status) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, MainApplication.NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(this, 1234,
Expand All @@ -87,7 +89,7 @@ private Notification.Builder getBuilder(String requestId, Resource.UploadStatus
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setColor(getResources().getColor(R.color.colorPrimary));
builder.setColor(ContextCompat.getColor(this, R.color.colorPrimary));
}

return builder;
Expand Down Expand Up @@ -151,7 +153,7 @@ private void cancelNotification(String requestId) {
notificationManager.cancel(id);
}
}

@SuppressWarnings("deprecation")
private boolean sendBroadcast(Resource updatedResource) {
// This is called from background threads and the main thread may touch the resource and delete it
// in the meantime (from the activity) - verify it's still around before sending the broadcast
Expand Down Expand Up @@ -179,6 +181,7 @@ public void run() {
.build());
}

@SuppressWarnings("deprecation")
@Override
public synchronized void onProgress(String requestId, long bytes, long totalBytes) {
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_UPLOAD_PROGRESS).putExtra("requestId", requestId).putExtra("bytes", bytes).putExtra("totalBytes", totalBytes));
Expand Down Expand Up @@ -257,7 +260,7 @@ public void run() {
getBuilder(requestId, Resource.UploadStatus.FAILED)
.setContentTitle("Error uploading.")
.setContentText(error.getDescription())
.setStyle(new Notification.BigTextStyle()
.setStyle(new NotificationCompat.BigTextStyle()
.setBigContentTitle("Error uploading.")
.bigText(error.getDescription()))
.build());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.cloudinary.android.sample.app;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -34,18 +32,15 @@
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.TracksInfo;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.material.snackbar.Snackbar;

import java.util.List;
Expand All @@ -61,9 +56,9 @@ public class ImageActivity extends AppCompatActivity {
private int thumbHeight;
private TextView descriptionTextView;
private ProgressBar progressBar;
private SimpleExoPlayer exoPlayer;
private ExoPlayer exoPlayer;
private PlayerView exoPlayerView;
private ExoPlayer.EventListener listener;
private Player.Listener listener;
private String currentUrl = null;

@Override
Expand Down Expand Up @@ -96,37 +91,31 @@ public boolean onCreateOptionsMenu(Menu menu) {


private void initExoPlayer() {
exoPlayer = new SimpleExoPlayer.Builder(this).build();
exoPlayer = new ExoPlayer.Builder(this).build();
exoPlayerView = ((PlayerView) findViewById(R.id.exoPlayer));
exoPlayerView.setPlayer(exoPlayer);

listener = new ExoPlayer.EventListener() {
listener = new Player.Listener() {

@Override
public void onTracksChanged(TrackGroupArray trackGroupArray, TrackSelectionArray trackSelectionArray) {
if (trackGroupArray.length > 0) {
public void onTracksInfoChanged(TracksInfo tracksInfo) {
Player.Listener.super.onTracksInfoChanged(tracksInfo);
if (tracksInfo.getTrackGroupInfos().isEmpty()) {
progressBar.setVisibility(View.GONE);
}
}

@Override
public void onLoadingChanged(boolean b) {
progressBar.setVisibility(b ? View.VISIBLE : View.GONE);
}

@Override
public void onPlayerStateChanged(boolean b, int i) {

public void onIsLoadingChanged(boolean isLoading) {
Player.Listener.super.onIsLoadingChanged(isLoading);
progressBar.setVisibility(isLoading ? View.VISIBLE : View.GONE);
}

@Override
public void onPlayerError(PlaybackException error) {
Player.Listener.super.onPlayerError(error);
progressBar.setVisibility(View.GONE);
Toast.makeText(ImageActivity.this, "Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
}

@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {

}
};
Expand Down Expand Up @@ -174,7 +163,7 @@ private void updateMainImage(EffectData data) {
private void loadVideo(final EffectData data) {
progressBar.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE);
final DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "Cloudinary Sample App"), null);
final DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this);
final ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
Url baseUrl = MediaManager.get().url().secure(true).resourceType("video").publicId(data.getPublicId()).transformation(data.getTransformation());
MediaManager.get().responsiveUrl(exoPlayerView, baseUrl, FIT, new ResponsiveUrl.Callback() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cloudinary.android.sample.app;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.Context;
Expand All @@ -25,7 +24,6 @@
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.cloudinary.android.MediaManager;
Expand All @@ -42,6 +40,7 @@
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("deprecation")
public class MainActivity extends AppCompatActivity implements ResourcesAdapter.ImageClickedListener, DeleteRequestsCallback {
public static final int PAGE_COUNT = 4;
public static final int UPLOADED_PAGE_POSITION = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cloudinary.android.sample.app;

import android.os.Build;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -235,6 +236,7 @@ public void onUrlReady(Url url) {
}
}

@SuppressWarnings("deprecation")
private void setProgress(ResourceViewHolder holder, ResourceWithMeta resourceWithMeta) {
holder.progressBar.setVisibility(View.VISIBLE);
((ViewGroup)holder.progressBar.getParent()).findViewById(R.id.progressContainer).setVisibility(View.VISIBLE);
Expand All @@ -261,7 +263,13 @@ private void setProgress(ResourceViewHolder holder, ResourceWithMeta resourceWit

String text = holder.statusText.getContext().getString(R.string.uploading, progressStr);
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new ForegroundColorSpan(holder.statusText.getContext().getResources().getColor(R.color.buttonColor)), text.indexOf(progressStr), text.length(), 0);
ForegroundColorSpan color;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
color = new ForegroundColorSpan(holder.statusText.getContext().getColor(R.color.buttonColor));
} else {
color = new ForegroundColorSpan(holder.statusText.getContext().getResources().getColor(R.color.buttonColor));
}
spannableString.setSpan(color, text.indexOf(progressStr), text.length(), 0);
holder.statusText.setText(spannableString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import androidx.core.util.Pair;
import android.view.WindowManager;
Expand Down Expand Up @@ -94,11 +95,15 @@ public static Uri toUri(Context context, int resourceId) {
+ '/' + res.getResourceTypeName(resourceId) + '/' + res.getResourceEntryName(resourceId));
}

@SuppressWarnings("deprecation")
public static int getScreenWidth(Context context) {
WindowManager window = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Point point = new Point();
window.getDefaultDisplay().getSize(point);
return point.x;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
window.getDefaultDisplay().getSize(point);
return point.x;
}
return window.getCurrentWindowMetrics().getBounds().width();
}

@SuppressLint("Range")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.cloudinary.android.sample.persist;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import androidx.preference.PreferenceManager;

import com.cloudinary.android.sample.app.MainApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,11 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
return false;
}
});

setToolbarIfNeeded();
return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

private void setToolbarIfNeeded() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
Toolbar toolbar = getActivity().findViewById(R.id.cropRotateToolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@ public void onThumbnailClicked(Uri uri) {
} else {
thumbnailsRecyclerView.setVisibility(View.INVISIBLE);
}

setToolbarIfNeeded();
return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

private void setToolbarIfNeeded() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
Expand Down