Skip to content

Commit

Permalink
Moved privacy policy to about section. Bug fixes for too much work be…
Browse files Browse the repository at this point in the history
…ing done on UI thread. Refactored code
  • Loading branch information
Aftaab99 committed Dec 19, 2023
1 parent ecd6fc7 commit 54bd1ed
Show file tree
Hide file tree
Showing 410 changed files with 264 additions and 949 deletions.
7 changes: 3 additions & 4 deletions .idea/assetWizardSettings.xml

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

Binary file modified .idea/caches/build_file_checksums.ser
100755 → 100644
Binary file not shown.
9 changes: 9 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
/build
app/build/
app/debug/
app/release/


openCVLibrary343/build/
openCVLibrary343/debug/
openCVLibrary343/release/
.idea/
9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

apply plugin: 'com.android.application'

repositories {
Expand All @@ -8,13 +7,13 @@ repositories {
}
android {

compileSdkVersion 31
compileSdkVersion 33
defaultConfig {
applicationId "com.spectrumeditor.aftaab.spectrum"
minSdkVersion 21
targetSdkVersion 31
versionCode 12
versionName "1.4.5"
targetSdkVersion 33
versionCode 14
versionName "1.4.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
21 changes: 12 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,41 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />


<application
android:allowBackup="true"
android:icon="@mipmap/ic_app_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_app_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".AboutActivity"
android:label="@string/title_activity_about"
android:parentActivityName=".MainActivity"
android:theme="@style/CropActivityTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.spectrumeditor.aftaab.spectrum.MainActivity" />
</activity>
<activity
android:name="com.spectrumeditor.aftaab.spectrum.SettingsActivity"
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName="com.spectrumeditor.aftaab.spectrum.MainActivity"
android:parentActivityName=".MainActivity"
android:theme="@style/CropActivityTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.spectrumeditor.aftaab.spectrum.MainActivity" />
</activity>
<activity
android:name="com.spectrumeditor.aftaab.spectrum.MainActivity"
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTop">

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />

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

</intent-filter>
</activity>
<activity
Expand All @@ -53,7 +57,6 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/picker_provider_paths" />
</provider>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.spectrumeditor.aftaab.spectrum;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;

import android.os.Bundle;

public class AboutActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.about, new AboutFragment())
.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

public static class AboutFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.about, rootKey);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

public class ArtStyleAdapter extends RecyclerView.Adapter<ArtStyleAdapter.ArtListViewHolder>{

private Context context;
private List<ArtStyle> artStyleList;
private ArtListViewHolder.ItemSelectListener itemSelectListener;

static class ArtListViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
// each data item is just a string in this case
Expand All @@ -40,9 +43,6 @@ public interface ItemSelectListener{
}
}

private Context context;
private List<ArtStyle> artStyleList;
private ArtListViewHolder.ItemSelectListener itemSelectListener;
ArtStyleAdapter(Context context, List<ArtStyle> artStyleList, ArtListViewHolder.ItemSelectListener itemSelectListener) {
this.context = context;
this.artStyleList = artStyleList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

if (item.getItemId() == R.id.about_screen) {
Intent intent = new Intent(getActivity(), AboutActivity.class);
startActivity(intent);
return true;
}
if (item.getItemId() == R.id.settings_screen) {
Intent intent = new Intent(getActivity(), SettingsActivity.class);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.graphics.Matrix;
import android.graphics.Paint;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -39,7 +38,6 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -57,7 +55,7 @@ public class MainActivity extends AppCompatActivity implements ArtStyleAdapter.A
Integer currentOpacity = 100;

Boolean isImageSelected = false, isStyleApplied = false, isStyleBeingApplied = false;
Bitmap originalImage, styleImage;
Bitmap originalImage, styleImage, styleImageWithOpacity;
LruCache<String, Bitmap> memoryCache;
BottomAppBar appBar;
Toolbar toolbar;
Expand Down Expand Up @@ -149,7 +147,7 @@ public boolean onMenuItemClick(MenuItem item) {
if (styleImage != null) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
boolean isWaterMarkEnabled = sharedPreferences.getBoolean("watermark", true);
Bitmap styleImageWithAlpha = getBitmapWithAlpha(currentOpacity);
Bitmap styleImageWithAlpha = styleImageWithOpacity;

if (isWaterMarkEnabled) {
styleImageWithAlpha = Utility.addWaterMark(styleImageWithAlpha, MainActivity.this);
Expand All @@ -176,8 +174,8 @@ public boolean onMenuItemClick(MenuItem item) {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
currentOpacity = progress;
styleOpacities.put(currentStyle, currentOpacity);
selectedImageView.setImageBitmap(getBitmapWithAlpha(progress));
}
UpdateOpacityTask updateOpacityTask = new UpdateOpacityTask(MainActivity.this);
updateOpacityTask.execute(new UpdateOpacityTaskParams(originalImage, styleImage, currentOpacity)); }

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Expand Down Expand Up @@ -247,17 +245,6 @@ public void onClick(View v) {

}

public Bitmap getBitmapWithAlpha(int opacity) {
float scaledOpacity = Utility.scaleOpacity(opacity);
Bitmap bmOverlay = Bitmap.createBitmap(originalImage.getWidth(), originalImage.getHeight(), originalImage.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(originalImage, new Matrix(), null);
Paint paint = new Paint();
paint.setAlpha((int) scaledOpacity);
canvas.drawBitmap(styleImage, new Matrix(), paint);
return bmOverlay;

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand All @@ -279,7 +266,8 @@ public void onClick(final int position) {
currentStyle = styles.get(position).getStyleName();
opacitySeekbar.setProgress(currentOpacity);

selectedImageView.setImageBitmap(getBitmapWithAlpha(currentOpacity));
UpdateOpacityTask updateOpacityTask = new UpdateOpacityTask(this);
updateOpacityTask.execute(new UpdateOpacityTaskParams(this.originalImage, this.styleImage, this.currentOpacity));

resetStyleStatus(position);
} else {
Expand Down Expand Up @@ -361,60 +349,6 @@ void resetStyleStatus(int position) {
adapter.notifyDataSetChanged();
}

private static class StylizeTask extends AsyncTask<String, Void, Void> {

private WeakReference<MainActivity> activityWeakReference;
private int position;

StylizeTask(MainActivity context) {
activityWeakReference = new WeakReference<>(context);
}

@Override
protected void onPreExecute() {
super.onPreExecute();
MainActivity activity = activityWeakReference.get();
if (activity == null || activity.isFinishing()) return;

activity.progressBar.setVisibility(View.VISIBLE);
activity.isStyleBeingApplied = true;
}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
MainActivity activity = activityWeakReference.get();
if (activity == null || activity.isFinishing()) return;

activity.opacitySeekbar.setVisibility(View.VISIBLE);
activity.opacitySeekbar.setProgress(activity.currentOpacity);
activity.selectedImageView.setImageBitmap(activity.getBitmapWithAlpha(activity.currentOpacity));
activity.isStyleApplied = true;
activity.toolbar.getMenu().removeItem(R.id.toolbar_menu_crop);
activity.toolbar.invalidate();
activity.isStyleBeingApplied = false;
activity.progressBar.setVisibility(View.INVISIBLE);
activity.resetStyleStatus(position);
}


@Override
protected Void doInBackground(String... strings) {

MainActivity activity = activityWeakReference.get();
if (activity == null || activity.isFinishing()) return null;

Stylize stylize = new Stylize(strings[0], activity);
this.position = Integer.parseInt(strings[2]);
activity.styleImage = stylize.stylizeImage(activity, activity.originalImage);
activity.addBitmapToMemoryCache(strings[0], activity.styleImage);
activity.styleImage = Bitmap.createScaledBitmap(activity.styleImage, activity.originalImage.getWidth(), activity.originalImage.getHeight(), true);
activity.currentOpacity = activity.styleOpacities.get(strings[1]);
activity.currentStyle = strings[1];
return null;
}

}


public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
Expand Down Expand Up @@ -477,9 +411,8 @@ public boolean onMenuItemClick(MenuItem item) {
}
break;
case R.id.toolbar_menu_save:
if (styleImage != null) {
Bitmap styleImageWithAlpha = getBitmapWithAlpha(currentOpacity);
Utility.saveToInternalStorage(styleImageWithAlpha, MainActivity.this);
if (styleImageWithOpacity != null) {
Utility.saveToInternalStorage(styleImageWithOpacity, MainActivity.this);
} else
Utility.saveToInternalStorage(originalImage, MainActivity.this);
break;
Expand Down Expand Up @@ -568,7 +501,8 @@ public void onClick(View v) {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
currentOpacity = progress;
styleOpacities.put(currentStyle, currentOpacity);
selectedImageView.setImageBitmap(getBitmapWithAlpha(progress));
UpdateOpacityTask updateOpacityTask = new UpdateOpacityTask(MainActivity.this);
updateOpacityTask.execute(new UpdateOpacityTaskParams(originalImage, styleImage, currentOpacity));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected void onCreate(Bundle savedInstanceState) {
public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
setPreferencesFromResource(R.xml.settings, rootKey);
Preference instagramPreference = findPreference("instagram");
if (Utility.getDevicePerformance(Objects.requireNonNull(getActivity()))==Utility.DevicePerf.DEVICE_PERF_HIGHRES_NOT_COMPATIBLE)
Objects.requireNonNull(getPreferenceScreen().findPreference("highResolution")).setEnabled(false);
Expand Down
Loading

0 comments on commit 54bd1ed

Please sign in to comment.