Skip to content

Commit

Permalink
Additional modernisation and lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrob committed Aug 1, 2023
1 parent 867057f commit 1009bfd
Show file tree
Hide file tree
Showing 46 changed files with 201 additions and 563 deletions.
7 changes: 7 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.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MediaPhone {
public static final int MAX_AUDIO_ITEMS = 3;

// we can pause/resume recording only in AAC (M4A) formats - get extensions from MediaUtilities
public static String[] EDITABLE_AUDIO_EXTENSIONS;
public static final String[] EDITABLE_AUDIO_EXTENSIONS;

static {
String[] tempExtensions = new String[MediaUtilities.M4A_FILE_EXTENSIONS.length];
Expand Down Expand Up @@ -95,7 +95,6 @@ public class MediaPhone {

// in milliseconds: duration of the frame icon fade in; time to wait after finishing scrolling before showing icons
public static int ANIMATION_FADE_TRANSITION_DURATION = 175;
public static int ANIMATION_ICON_SHOW_DELAY = 350;
public static int ANIMATION_ICON_REFRESH_DELAY = 250;
public static int ANIMATION_POPUP_SHOW_DELAY = 250;
public static int ANIMATION_POPUP_HIDE_DELAY = 600;
Expand All @@ -113,7 +112,7 @@ public class MediaPhone {

// in milliseconds, the length of time to show an image (if audio is not longer), and the minimum text duration
public static int PLAYBACK_EXPORT_MINIMUM_FRAME_DURATION = 2500;
public static int PLAYBACK_EXPORT_WORD_DURATION = 200;
public static int PLAYBACK_EXPORT_WORD_DURATION = 200; // note: always overridden in MediaPhoneActivity.loadAllPreferences()

// -----------------------------------------------------------------------------------------------------------------
// The following are globals that should eventually be moved to preferences, detected, or overridden at startup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
import android.app.PendingIntent;
Expand Down Expand Up @@ -219,11 +218,6 @@ protected void onPause() {
((MediaPhoneApplication) getApplication()).removeActivityHandle(this);
}

@Override
protected void onDestroy() {
super.onDestroy();
}

@Override
public Object onRetainCustomNonConfigurationInstance() {
// called before screen change - have to remove the parent activity
Expand All @@ -247,10 +241,6 @@ protected void registerForSwipeEvents() {
}
}

protected void setSwipeEventsEnabled(boolean enabled) {
mCanSwipe = enabled;
}

// see: http://stackoverflow.com/a/7767610
private class SwipeDetector extends SimpleOnGestureListener {
@Override
Expand Down Expand Up @@ -373,7 +363,8 @@ protected Dialog onCreateDialog(int id) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MediaPhoneActivity.this,
Manifest.permission.POST_NOTIFICATIONS)) {
UIUtilities.showFormattedToast(MediaPhoneActivity.this,
R.string.permission_notification_rationale, getString(R.string.app_name));
R.string.permission_notification_rationale,
getString(R.string.app_name));
}
ActivityCompat.requestPermissions(MediaPhoneActivity.this,
new String[]{ Manifest.permission.POST_NOTIFICATIONS }, PERMISSION_POST_NOTIFICATIONS);
Expand Down Expand Up @@ -461,16 +452,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

protected void createMediaMenuNavigationButtons(MenuInflater inflater, Menu menu, boolean edited) {
protected void createMediaMenuNavigationButtons(MenuInflater inflater, Menu menu) {
inflater.inflate(R.menu.add_frame, menu);
inflater.inflate(R.menu.copy_media, menu);
inflater.inflate(R.menu.paste_media, menu);

// if (edited) {
inflater.inflate(R.menu.finished_editing, menu);
// } else {
// inflater.inflate(R.menu.back_without_editing, menu);
// }
}

protected void prepareMediaMenuNavigationButtons(Menu menu, String mediaId) {
Expand All @@ -486,8 +473,7 @@ protected void prepareMediaMenuNavigationButtons(Menu menu, String mediaId) {
menu.findItem(R.id.menu_copy_media).setVisible(true);
menu.findItem(R.id.menu_paste_media).setVisible(false);
} else {
SharedPreferences copyFrameSettings = getSharedPreferences(MediaPhone.APPLICATION_NAME,
Context.MODE_PRIVATE);
SharedPreferences copyFrameSettings = getSharedPreferences(MediaPhone.APPLICATION_NAME, Context.MODE_PRIVATE);
String copiedFrameId = copyFrameSettings.getString(getString(R.string.key_copied_frame), null);
menu.findItem(R.id.menu_copy_media).setVisible(false);
menu.findItem(R.id.menu_paste_media).setVisible(!TextUtils.isEmpty(copiedFrameId));
Expand Down Expand Up @@ -665,18 +651,6 @@ public void run() {
};
}

protected void setBackButtonIcons(Activity activity, int button1, int button2, boolean isEdited) {
//if (button1 != 0) {
// ((CenteredImageTextButton) findViewById(button1)).setCompoundDrawablesWithIntrinsicBounds(0, (isEdited ? R.drawable
// .ic_menu_accept : R.drawable.ic_menu_back), 0, 0);
//}
//if (button2 != 0) {
// ((CenteredImageTextButton) findViewById(button2)).setCompoundDrawablesWithIntrinsicBounds(0, (isEdited ? R.drawable
// .ic_menu_accept : R.drawable.ic_menu_back), 0, 0);
//}
//UIUtilities.refreshActionBar(activity);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultIntent) {
if (requestCode == MediaPhone.R_id_intent_preferences) {
Expand Down Expand Up @@ -770,7 +744,7 @@ private void loadAllPreferences() {
try {
String requestedOrientationString = mediaPhoneSettings.getString(getString(R.string.key_screen_orientation), null);
if (requestedOrientationString != null) {
requestedOrientation = Integer.valueOf(requestedOrientationString);
requestedOrientation = Integer.parseInt(requestedOrientationString);
}
} catch (Exception e) {
requestedOrientation = res.getInteger(R.integer.default_screen_orientation);
Expand Down Expand Up @@ -1064,7 +1038,7 @@ protected String insertFrameAfterMedia(MediaItem existingMedia) {
/**
* Switch from one frame to another. Will call onBackPressed() on the calling activity
*/
protected boolean switchFrames(String currentFrameId, int buttonId, String newFrameId, boolean showOptionsMenu) {
protected boolean switchFrames(String currentFrameId, int buttonId, String newFrameId) {
if (currentFrameId == null) {
return false;
}
Expand Down Expand Up @@ -1794,8 +1768,7 @@ protected void deleteNarrativeDialog(final String narrativeInternalId) {
AlertDialog.Builder builder1 = new AlertDialog.Builder(MediaPhoneActivity.this);
builder1.setTitle(R.string.delete_narrative_second_confirmation);
builder1.setMessage(
getResources().getQuantityString(R.plurals.delete_narrative_second_hint, numFramesDeleted,
numFramesDeleted));
getResources().getQuantityString(R.plurals.delete_narrative_second_hint, numFramesDeleted, numFramesDeleted));
builder1.setNegativeButton(R.string.button_cancel, null);
builder1.setPositiveButton(R.string.button_delete, (dialog1, whichButton1) -> {
ContentResolver contentResolver = getContentResolver();
Expand All @@ -1822,8 +1795,7 @@ protected void exportContent(final String narrativeId, final boolean isTemplate)
UIUtilities.showFormattedToast(MediaPhoneActivity.this, R.string.permission_storage_rationale,
getString(R.string.app_name));
}
ActivityCompat.requestPermissions(MediaPhoneActivity.this,
new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE },
ActivityCompat.requestPermissions(MediaPhoneActivity.this, new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE },
PERMISSION_EXPORT_STORAGE);
}

Expand Down Expand Up @@ -1880,13 +1852,13 @@ protected void exportContent(final String narrativeId, final boolean isTemplate)
settings.put(MediaUtilities.KEY_TEXT_BACKGROUND_COLOUR, res.getColor(R.color.export_text_background));

// TODO: do we want to do getDimensionPixelSize for export?
settings.put(MediaUtilities.KEY_TEXT_BACKGROUND_SPAN_WIDTH, Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB);
settings.put(MediaUtilities.KEY_TEXT_BACKGROUND_SPAN_WIDTH, true);
settings.put(MediaUtilities.KEY_MAX_TEXT_FONT_SIZE, res.getDimensionPixelSize(R.dimen.export_maximum_text_size));
settings.put(MediaUtilities.KEY_MAX_TEXT_PERCENTAGE_HEIGHT_WITH_IMAGE,
res.getInteger(R.integer.export_maximum_text_percentage_height_with_image));
settings.put(MediaUtilities.KEY_TEXT_SPACING, res.getDimensionPixelSize(R.dimen.export_icon_text_padding));
settings.put(MediaUtilities.KEY_TEXT_CORNER_RADIUS,
res.getDimensionPixelSize(R.dimen.export_icon_text_corner_radius));
res.getDimensionPixelSize(R.dimen.export_icon_text_corner_radius));

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MediaPhoneActivity.this);

Expand All @@ -1905,7 +1877,7 @@ protected void exportContent(final String narrativeId, final boolean isTemplate)
int outputSize;
try {
String requestedExportSize = preferences.getString(getString(R.string.key_video_quality), null);
outputSize = Integer.valueOf(requestedExportSize);
outputSize = Integer.parseInt(requestedExportSize);
} catch (Exception e) {
outputSize = res.getInteger(R.integer.default_video_quality);
}
Expand All @@ -1926,9 +1898,10 @@ protected void exportContent(final String narrativeId, final boolean isTemplate)
// set audio resampling rate: -1 = automatically selected (default); 0 = none
int newBitrate;
try {
String requestedBitrateString = preferences.getString(
getString(R.string.key_audio_resampling_bitrate), null);
newBitrate = Integer.valueOf(requestedBitrateString);
String requestedBitrateString =
preferences.getString(getString(R.string.key_audio_resampling_bitrate),
null);
newBitrate = Integer.parseInt(requestedBitrateString);
} catch (Exception e) {
newBitrate = res.getInteger(R.integer.default_resampling_bitrate);
}
Expand Down Expand Up @@ -2961,8 +2934,7 @@ public void run() {
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM + "/" + appName);
contentUri = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
} else if (Environment.DIRECTORY_MUSIC.equals(outputDirectoryType)) {
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH,
Environment.DIRECTORY_MUSIC + "/" + appName);
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_MUSIC + "/" + appName);
contentUri = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
}
if (contentUri != null) {
Expand Down Expand Up @@ -2995,8 +2967,7 @@ public void run() {
File outputFile = IOUtilities.newDatedFileName(outputDirectory,
IOUtilities.getFileExtension(mediaFile.getName()));
IOUtilities.copyFile(mediaFile, outputFile);
MediaScannerConnection.scanFile(MediaPhoneActivity.this,
new String[]{ outputFile.getAbsolutePath() },
MediaScannerConnection.scanFile(MediaPhoneActivity.this, new String[]{ outputFile.getAbsolutePath() },
null, new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ private void initialiseParameters() {
Resources res = getResources();

MediaPhone.ANIMATION_FADE_TRANSITION_DURATION = res.getInteger(R.integer.animation_fade_transition_duration);
MediaPhone.ANIMATION_ICON_SHOW_DELAY = res.getInteger(R.integer.animation_icon_show_delay);
MediaPhone.ANIMATION_ICON_REFRESH_DELAY = res.getInteger(R.integer.animation_icon_refresh_delay);
MediaPhone.ANIMATION_POPUP_SHOW_DELAY = res.getInteger(R.integer.animation_popup_show_delay);
MediaPhone.ANIMATION_POPUP_HIDE_DELAY = res.getInteger(R.integer.animation_popup_hide_delay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ protected void onCreate(Bundle savedInstanceState) {
mMediaItemInternalId = savedInstanceState.getString(getString(R.string.extra_internal_id));
mHasEditedMedia = savedInstanceState.getBoolean(getString(R.string.extra_media_edited), true);
mAudioPickerShown = savedInstanceState.getBoolean(getString(R.string.extra_external_chooser_shown), false);
if (mHasEditedMedia) {
setBackButtonIcons(AudioActivity.this, R.id.button_finished_audio, R.id.button_cancel_recording, true);
}
}

// prevent spanning if appropriate
Expand Down Expand Up @@ -228,8 +225,6 @@ public void onBackPressed() {
// update this frame's icon to show audio; propagate to following frames if applicable
// TODO: we could just update when the audio is added or removed; edits not needed
updateMediaFrameIcons(audioMediaItem, null);
setBackButtonIcons(AudioActivity.this, R.id.button_finished_audio, R.id.button_cancel_recording,
true);

// if we do this then we can't tell whether to change icons on screen rotation; disabled
// mHasEditedMedia = false; // we've saved the icon, so are no longer in edit mode
Expand Down Expand Up @@ -262,7 +257,7 @@ public void onBackPressed() {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
createMediaMenuNavigationButtons(inflater, menu, mHasEditedMedia);
createMediaMenuNavigationButtons(inflater, menu);
return super.onCreateOptionsMenu(menu);
}

Expand Down Expand Up @@ -306,7 +301,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
return true;

} else if (itemId == R.id.menu_back_without_editing || itemId == R.id.menu_finished_editing) {
} else if (itemId == R.id.menu_finished_editing) {
onBackPressed();
return true;
}
Expand Down Expand Up @@ -350,17 +345,6 @@ protected void loadPreferences(SharedPreferences mediaPhoneSettings) {

@Override
protected void configureInterfacePreferences(SharedPreferences mediaPhoneSettings) {
// the soft done/back button
// TODO: remove this to fit with new styling (Toolbar etc)
int newVisibility = View.VISIBLE;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ||
!mediaPhoneSettings.getBoolean(getString(R.string.key_show_back_button),
getResources().getBoolean(R.bool.default_show_back_button))) {
newVisibility = View.GONE;
}
findViewById(R.id.button_finished_audio).setVisibility(newVisibility);
findViewById(R.id.button_cancel_recording).setVisibility(newVisibility);

// to enable or disable spanning, all we do is show/hide the interface - eg., items that already span will not be removed
findViewById(R.id.button_toggle_mode_audio).setVisibility(
mediaPhoneSettings.getBoolean(getString(R.string.key_spanning_media),
Expand Down Expand Up @@ -500,8 +484,6 @@ private boolean switchToRecording(File currentFile) {
return initialised;
}

// @TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1) is for AAC/HE_AAC audio recording
@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
private boolean initialiseAudioRecording(File currentFile) {

// where to record the new audio
Expand All @@ -516,9 +498,10 @@ private boolean initialiseAudioRecording(File currentFile) {

try {
CheapSoundFile existingFile = CheapSoundFile.create(currentFile.getAbsolutePath(), true, null);
enforcedSampleRate = existingFile.getSampleRate();
} catch (Exception e) {
enforcedSampleRate = -1;
if (existingFile != null) {
enforcedSampleRate = existingFile.getSampleRate();
}
} catch (Exception ignored) {
}
}

Expand Down Expand Up @@ -582,7 +565,6 @@ private void startRecording() {
// if (MediaPhone.DEBUG) Log.d(DebugUtilities.getLogTag(this), "Recording - what: " + what + ", ex: " + extra);
});
mMediaRecorder.start();
setBackButtonIcons(AudioActivity.this, R.id.button_finished_audio, R.id.button_cancel_recording, true);
} catch (Throwable t) {
UIUtilities.showToast(AudioActivity.this, R.string.error_recording_audio);
if (MediaPhone.DEBUG) {
Expand Down Expand Up @@ -1008,12 +990,18 @@ public void seekTo(int pos) {

@Override
public boolean isPlaying() {
return mMediaPlayer != null ? mMediaPlayer.isPlaying() : false;
if (mMediaPlayer != null) {
return mMediaPlayer.isPlaying();
}
return false;
}

@Override
public boolean isLoading() {
return mMediaPlayer != null ? mMediaPlayer.isPlaying() : false;
if (mMediaPlayer != null) {
return mMediaPlayer.isPlaying();
}
return false;
}

@Override
Expand Down Expand Up @@ -1047,10 +1035,7 @@ public void handleButtonClicks(View currentButton) {
}

int buttonId = currentButton.getId();
if (buttonId == R.id.button_cancel_recording || buttonId == R.id.button_finished_audio) {
onBackPressed();

} else if (buttonId == R.id.button_record_audio) {
if (buttonId == R.id.button_record_audio) {
currentButton.setEnabled(false); // don't let them press twice
if (mAudioRecordingInProgress) {
stopRecording(AfterRecordingMode.DO_NOTHING); // don't switch to playback afterwards (can continue)
Expand All @@ -1072,7 +1057,6 @@ public void handleButtonClicks(View currentButton) {
mMediaItemInternalId);
if (spanningAudioMediaItem != null && spanningAudioMediaItem.getFile().length() > 0) {
mHasEditedMedia = true; // so we update/inherit on exit and show the media edited icon
setBackButtonIcons(AudioActivity.this, R.id.button_finished_audio, R.id.button_cancel_recording, true);
boolean frameSpanning = toggleFrameSpanningMedia(spanningAudioMediaItem);
updateSpanFramesButtonIcon(R.id.button_toggle_mode_audio, frameSpanning, true);
UIUtilities.showToast(AudioActivity.this,
Expand Down
Loading

0 comments on commit 1009bfd

Please sign in to comment.