nicolasroard | a9f280f | 2012-10-23 11:26:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 16 | |
| 17 | package com.android.gallery3d.filtershow; |
| 18 | |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 19 | import java.io.File; |
| 20 | import java.lang.ref.WeakReference; |
| 21 | import java.util.ArrayList; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 22 | import java.util.Collections; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 23 | import java.util.Locale; |
Jay Wang | 723944e | 2016-06-15 16:14:50 -0700 | [diff] [blame] | 24 | import java.util.Vector; |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 25 | |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 26 | import android.app.ActionBar; |
Ruben Brunk | a3dbbd7 | 2013-03-29 12:36:30 -0700 | [diff] [blame] | 27 | import android.app.AlertDialog; |
Bobby Georgescu | ec29b73 | 2012-10-07 15:20:44 -0700 | [diff] [blame] | 28 | import android.app.ProgressDialog; |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 29 | import android.content.BroadcastReceiver; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
zhuw | f4f10df | 2017-09-18 09:23:03 +0800 | [diff] [blame] | 31 | import android.content.ContentResolver; |
nicolasroard | 0ee91a2 | 2012-10-01 00:25:11 -0700 | [diff] [blame] | 32 | import android.content.ContentValues; |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 33 | import android.content.Context; |
Ruben Brunk | a3dbbd7 | 2013-03-29 12:36:30 -0700 | [diff] [blame] | 34 | import android.content.DialogInterface; |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 35 | import android.content.DialogInterface.OnCancelListener; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 36 | import android.content.Intent; |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 37 | import android.content.IntentFilter; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 38 | import android.content.ServiceConnection; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 39 | import android.content.pm.ActivityInfo; |
nicolasroard | a9bc8ef | 2012-10-23 14:09:53 -0700 | [diff] [blame] | 40 | import android.content.res.Configuration; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 41 | import android.content.res.Resources; |
zhuw | f4f10df | 2017-09-18 09:23:03 +0800 | [diff] [blame] | 42 | import android.database.Cursor; |
John Hoford | 457e88c | 2012-10-09 16:17:17 -0700 | [diff] [blame] | 43 | import android.graphics.Bitmap; |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 44 | import android.graphics.Color; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 45 | import android.graphics.Matrix; |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 46 | import android.graphics.Point; |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 47 | import android.graphics.Rect; |
nicolasroard | 9f452e0 | 2013-08-23 00:10:01 -0700 | [diff] [blame] | 48 | import android.graphics.drawable.ColorDrawable; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 49 | import android.graphics.drawable.Drawable; |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 50 | import android.net.Uri; |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 51 | import android.os.AsyncTask; |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 52 | import android.os.Bundle; |
nicolasroard | af59322 | 2013-06-10 18:33:11 -0700 | [diff] [blame] | 53 | import android.os.Handler; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 54 | import android.os.IBinder; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 55 | import android.os.Message; |
zhuw | f4f10df | 2017-09-18 09:23:03 +0800 | [diff] [blame] | 56 | import android.provider.MediaStore; |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 57 | import android.support.v4.app.DialogFragment; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 58 | import android.support.v4.app.Fragment; |
nicolasroard | fb6a8e1 | 2013-04-15 14:41:00 -0700 | [diff] [blame] | 59 | import android.support.v4.app.FragmentTransaction; |
Svetoslav Ganov | 391e4a1 | 2013-10-06 20:03:32 -0700 | [diff] [blame] | 60 | import android.support.v4.print.PrintHelper; |
John Hoford | fafb2ed | 2012-10-11 12:55:05 -0700 | [diff] [blame] | 61 | import android.util.DisplayMetrics; |
John Hoford | 52fa110 | 2013-06-11 13:07:15 -0700 | [diff] [blame] | 62 | import android.util.Log; |
ztenghui | d2e9ea0 | 2013-06-24 13:54:04 -0700 | [diff] [blame] | 63 | import android.util.TypedValue; |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 64 | import android.view.Gravity; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 65 | import android.view.Menu; |
| 66 | import android.view.MenuItem; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 67 | import android.view.MotionEvent; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 68 | import android.view.View; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 69 | import android.view.View.OnClickListener; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 70 | import android.view.View.OnTouchListener; |
nicolasroard | af59322 | 2013-06-10 18:33:11 -0700 | [diff] [blame] | 71 | import android.view.ViewPropertyAnimator; |
Jay Wang | 723944e | 2016-06-15 16:14:50 -0700 | [diff] [blame] | 72 | import android.view.Window; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 73 | import android.view.WindowManager; |
zhuw | f4f10df | 2017-09-18 09:23:03 +0800 | [diff] [blame] | 74 | import android.webkit.MimeTypeMap; |
John Hoford | be61c1f | 2013-02-27 19:21:38 -0800 | [diff] [blame] | 75 | import android.widget.AdapterView; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 76 | import android.widget.AdapterView.OnItemClickListener; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 77 | import android.widget.Button; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 78 | import android.widget.EditText; |
John Hoford | be61c1f | 2013-02-27 19:21:38 -0800 | [diff] [blame] | 79 | import android.widget.FrameLayout; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 80 | import android.widget.ImageButton; |
| 81 | import android.widget.LinearLayout; |
John Hoford | 64fc2ed | 2013-10-09 13:54:45 -0700 | [diff] [blame] | 82 | import android.widget.PopupMenu; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 83 | import android.widget.RelativeLayout; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 84 | import android.widget.Toast; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 85 | |
Likai Ding | c83b5b7 | 2016-05-25 14:48:41 +0800 | [diff] [blame] | 86 | import org.codeaurora.gallery.R; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 87 | |
zhuw | ad6505d | 2017-07-26 15:09:37 +0800 | [diff] [blame] | 88 | import com.android.gallery3d.app.AbstractPermissionActivity; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 89 | import com.android.gallery3d.app.PhotoPage; |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 90 | import com.android.gallery3d.data.LocalAlbum; |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 91 | import com.android.gallery3d.filtershow.cache.ImageLoader; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 92 | import com.android.gallery3d.filtershow.category.Action; |
| 93 | import com.android.gallery3d.filtershow.category.CategoryAdapter; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 94 | import com.android.gallery3d.filtershow.category.CategoryPanelLevelTwo; |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 95 | import com.android.gallery3d.filtershow.category.CategoryView; |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 96 | import com.android.gallery3d.filtershow.category.EditorCropPanel; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 97 | import com.android.gallery3d.filtershow.category.MainPanel; |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 98 | import com.android.gallery3d.filtershow.category.StraightenPanel; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 99 | import com.android.gallery3d.filtershow.category.SwipableView; |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 100 | import com.android.gallery3d.filtershow.category.TruePortraitMaskEditorPanel; |
Jack Yoo | e94e766 | 2016-05-18 11:34:04 -0700 | [diff] [blame] | 101 | import com.android.gallery3d.filtershow.category.TrueScannerPanel; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 102 | import com.android.gallery3d.filtershow.data.FilterPresetSource; |
| 103 | import com.android.gallery3d.filtershow.data.FilterPresetSource.SaveOption; |
| 104 | import com.android.gallery3d.filtershow.category.WaterMarkView; |
Ruben Brunk | 077e718 | 2013-08-01 19:05:18 -0700 | [diff] [blame] | 105 | import com.android.gallery3d.filtershow.data.UserPresetsManager; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 106 | import com.android.gallery3d.filtershow.editors.Editor; |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 107 | import com.android.gallery3d.filtershow.editors.EditorCrop; |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 108 | import com.android.gallery3d.filtershow.editors.EditorDualCamFusion; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 109 | import com.android.gallery3d.filtershow.editors.EditorManager; |
| 110 | import com.android.gallery3d.filtershow.editors.EditorPanel; |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 111 | import com.android.gallery3d.filtershow.editors.EditorStraighten; |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 112 | import com.android.gallery3d.filtershow.editors.EditorTruePortraitFusion; |
| 113 | import com.android.gallery3d.filtershow.editors.EditorTruePortraitImageOnly; |
| 114 | import com.android.gallery3d.filtershow.editors.EditorTruePortraitMask; |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 115 | import com.android.gallery3d.filtershow.editors.HazeBusterEditor; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 116 | import com.android.gallery3d.filtershow.editors.ImageOnlyEditor; |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 117 | import com.android.gallery3d.filtershow.editors.SeeStraightEditor; |
| 118 | import com.android.gallery3d.filtershow.editors.TrueScannerEditor; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 119 | import com.android.gallery3d.filtershow.filters.FilterDualCamBasicRepresentation; |
| 120 | import com.android.gallery3d.filtershow.filters.FilterDualCamFusionRepresentation; |
nicolasroard | 57bd092 | 2013-08-12 14:04:11 -0700 | [diff] [blame] | 121 | import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 122 | import com.android.gallery3d.filtershow.filters.FilterPresetRepresentation; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 123 | import com.android.gallery3d.filtershow.filters.FilterRepresentation; |
nicolasroard | 57bd092 | 2013-08-12 14:04:11 -0700 | [diff] [blame] | 124 | import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation; |
Ruben Brunk | 077e718 | 2013-08-01 19:05:18 -0700 | [diff] [blame] | 125 | import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 126 | import com.android.gallery3d.filtershow.filters.FilterWatermarkRepresentation; |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 127 | import com.android.gallery3d.filtershow.filters.FiltersManager; |
| 128 | import com.android.gallery3d.filtershow.filters.ImageFilter; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 129 | import com.android.gallery3d.filtershow.filters.SaveWaterMark; |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 130 | import com.android.gallery3d.filtershow.filters.SimpleMakeupImageFilter; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 131 | import com.android.gallery3d.filtershow.filters.TrueScannerActs; |
nicolasroard | 5180e68 | 2013-06-27 14:12:17 -0700 | [diff] [blame] | 132 | import com.android.gallery3d.filtershow.history.HistoryItem; |
Ruben Brunk | 077e718 | 2013-08-01 19:05:18 -0700 | [diff] [blame] | 133 | import com.android.gallery3d.filtershow.history.HistoryManager; |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 134 | import com.android.gallery3d.filtershow.imageshow.ImageShow; |
John Hoford | 63a7dac | 2013-01-14 14:48:39 -0800 | [diff] [blame] | 135 | import com.android.gallery3d.filtershow.imageshow.MasterImage; |
nicolasroard | 368ae73 | 2013-07-22 14:08:04 -0700 | [diff] [blame] | 136 | import com.android.gallery3d.filtershow.imageshow.Spline; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 137 | import com.android.gallery3d.filtershow.info.InfoPanel; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 138 | import com.android.gallery3d.filtershow.mediapicker.MediaPickerFragment; |
Ruben Brunk | 077e718 | 2013-08-01 19:05:18 -0700 | [diff] [blame] | 139 | import com.android.gallery3d.filtershow.pipeline.CachingPipeline; |
nicolasroard | ce9ceff | 2013-07-02 15:46:23 -0700 | [diff] [blame] | 140 | import com.android.gallery3d.filtershow.pipeline.ImagePreset; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 141 | import com.android.gallery3d.filtershow.pipeline.ProcessingService; |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 142 | import com.android.gallery3d.filtershow.presets.PresetManagementDialog; |
| 143 | import com.android.gallery3d.filtershow.presets.UserPresetsAdapter; |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 144 | import com.android.gallery3d.filtershow.provider.SharedImageProvider; |
nicolasroard | fb6a8e1 | 2013-04-15 14:41:00 -0700 | [diff] [blame] | 145 | import com.android.gallery3d.filtershow.state.StateAdapter; |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 146 | import com.android.gallery3d.filtershow.tools.DualCameraEffect; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 147 | import com.android.gallery3d.filtershow.tools.FilterGeneratorNativeEngine; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 148 | import com.android.gallery3d.filtershow.tools.SaveImage; |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 149 | import com.android.gallery3d.filtershow.tools.TruePortraitNativeEngine; |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 150 | import com.android.gallery3d.filtershow.tools.XmpPresets; |
| 151 | import com.android.gallery3d.filtershow.tools.XmpPresets.XMresults; |
Ruben Brunk | 077e718 | 2013-08-01 19:05:18 -0700 | [diff] [blame] | 152 | import com.android.gallery3d.filtershow.ui.ExportDialog; |
nicolasroard | 7592704 | 2012-10-24 16:39:41 -0700 | [diff] [blame] | 153 | import com.android.gallery3d.filtershow.ui.FramedTextButton; |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 154 | import com.android.gallery3d.util.GalleryUtils; |
Ruben Brunk | f07bb27 | 2013-03-11 12:00:06 -0700 | [diff] [blame] | 155 | import com.android.photos.data.GalleryBitmapPool; |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 156 | import com.thundersoft.hz.selfportrait.detect.FaceDetect; |
| 157 | import com.thundersoft.hz.selfportrait.detect.FaceInfo; |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 158 | import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine; |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 159 | |
zhuw | ad6505d | 2017-07-26 15:09:37 +0800 | [diff] [blame] | 160 | public class FilterShowActivity extends AbstractPermissionActivity implements OnItemClickListener, |
maxwen | d57f723 | 2016-06-04 22:51:06 +0200 | [diff] [blame] | 161 | DialogInterface.OnShowListener, |
| 162 | DialogInterface.OnDismissListener, PopupMenu.OnDismissListener { |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 163 | |
Ruben Brunk | ab779de | 2013-02-14 16:18:22 -0800 | [diff] [blame] | 164 | private String mAction = ""; |
nicolasroard | 588c30c | 2013-02-08 14:06:33 -0800 | [diff] [blame] | 165 | MasterImage mMasterImage = null; |
Ruben Brunk | 6416dd5 | 2012-11-28 14:00:30 -0800 | [diff] [blame] | 166 | |
nicolasroard | 4dad1a9 | 2013-03-29 14:41:38 -0700 | [diff] [blame] | 167 | private static final long LIMIT_SUPPORTS_HIGHRES = 134217728; // 128Mb |
| 168 | |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 169 | public static final String TINY_PLANET_ACTION = "com.android.camera.action.TINY_PLANET"; |
Bobby Georgescu | a850a54 | 2012-10-23 15:40:06 -0700 | [diff] [blame] | 170 | public static final String LAUNCH_FULLSCREEN = "launch-fullscreen"; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 171 | private ImageShow mImageShow = null; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 172 | |
Doris Liu | bf1677a | 2012-10-29 13:11:10 -0700 | [diff] [blame] | 173 | private View mSaveButton = null; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 174 | |
John Hoford | 5aa0894 | 2013-01-18 08:59:35 -0800 | [diff] [blame] | 175 | private EditorPlaceHolder mEditorPlaceHolder = new EditorPlaceHolder(this); |
nicolasroard | 9f452e0 | 2013-08-23 00:10:01 -0700 | [diff] [blame] | 176 | private Editor mCurrentEditor = null; |
John Hoford | 5aa0894 | 2013-01-18 08:59:35 -0800 | [diff] [blame] | 177 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 178 | private MediaPickerFragment mMediaPicker; |
| 179 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 180 | private static final int SELECT_PICTURE = 1; |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 181 | public static final int SELECT_FUSION_UNDERLAY = 2; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 182 | private static final String LOGTAG = "FilterShowActivity"; |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 183 | |
John Hoford | 5300e0c | 2013-03-04 17:50:58 -0800 | [diff] [blame] | 184 | private boolean mShowingTinyPlanet = false; |
nicolasroard | bf93da7 | 2012-09-29 00:17:09 -0700 | [diff] [blame] | 185 | private boolean mShowingImageStatePanel = false; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 186 | private boolean mShowingVersionsPanel = false; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 187 | private boolean mShowingFilterGenerator = false; |
nicolasroard | bf93da7 | 2012-09-29 00:17:09 -0700 | [diff] [blame] | 188 | |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 189 | private final Vector<ImageShow> mImageViews = new Vector<ImageShow>(); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 190 | |
nicolasroard | 0ee91a2 | 2012-10-01 00:25:11 -0700 | [diff] [blame] | 191 | private File mSharedOutputFile = null; |
| 192 | |
| 193 | private boolean mSharingImage = false; |
| 194 | |
Bobby Georgescu | ec29b73 | 2012-10-07 15:20:44 -0700 | [diff] [blame] | 195 | private WeakReference<ProgressDialog> mSavingProgressDialog; |
nicolasroard | 5555069 | 2012-10-17 15:11:53 -0700 | [diff] [blame] | 196 | |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 197 | private LoadBitmapTask mLoadBitmapTask; |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 198 | private LoadHighresBitmapTask mHiResBitmapTask; |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 199 | private ParseDepthMapTask mParseDepthMapTask; |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 200 | private LoadTruePortraitTask mLoadTruePortraitTask; |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 201 | |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 202 | private Uri mOriginalImageUri = null; |
| 203 | private ImagePreset mOriginalPreset = null; |
nicolasroard | c7b38f3 | 2013-04-25 08:47:11 -0700 | [diff] [blame] | 204 | |
ztenghui | b3f62e4 | 2013-06-10 15:51:42 -0700 | [diff] [blame] | 205 | private Uri mSelectedImageUri = null; |
| 206 | |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 207 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 208 | private UserPresetsManager mUserPresetsManager = null; |
| 209 | private UserPresetsAdapter mUserPresetsAdapter = null; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 210 | private CategoryAdapter mCategoryLooksAdapter = null; |
| 211 | private CategoryAdapter mCategoryBordersAdapter = null; |
| 212 | private CategoryAdapter mCategoryGeometryAdapter = null; |
| 213 | private CategoryAdapter mCategoryFiltersAdapter = null; |
Jack Yoo | 66d2144 | 2015-10-27 16:27:49 -0700 | [diff] [blame] | 214 | private CategoryAdapter mCategoryTrueScannerAdapter = null; |
Jack Yoo | 1d415cf | 2016-01-18 15:49:46 -0800 | [diff] [blame] | 215 | private CategoryAdapter mCategoryHazeBusterAdapter = null; |
Jack Yoo | 813c89e | 2016-01-21 15:28:31 -0800 | [diff] [blame] | 216 | private CategoryAdapter mCategorySeeStraightAdapter = null; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 217 | private CategoryAdapter mCategoryVersionsAdapter = null; |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 218 | private CategoryAdapter mCategoryMakeupAdapter = null; |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 219 | private CategoryAdapter mCategoryDualCamAdapter = null; |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 220 | private CategoryAdapter mCategoryTruePortraitAdapter = null; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 221 | private CategoryAdapter mCategoryFilterPresetAdapter = null; |
| 222 | private ArrayList<CategoryAdapter> mCategoryWatermarkAdapters; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 223 | private int mCurrentPanel = MainPanel.LOOKS; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 224 | private Vector<FilterUserPresetRepresentation> mVersions = |
| 225 | new Vector<FilterUserPresetRepresentation>(); |
| 226 | private int mVersionsCounter = 0; |
| 227 | |
| 228 | private boolean mHandlingSwipeButton = false; |
| 229 | private View mHandledSwipeView = null; |
| 230 | private float mHandledSwipeViewLastDelta = 0; |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 231 | private float mSwipeStartX = 0; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 232 | private float mSwipeStartY = 0; |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 233 | |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 234 | private ProcessingService mBoundService; |
| 235 | private boolean mIsBound = false; |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 236 | private Menu mMenu; |
John Hoford | 6125a08 | 2013-09-12 07:49:24 -0700 | [diff] [blame] | 237 | private DialogInterface mCurrentDialog = null; |
John Hoford | 64fc2ed | 2013-10-09 13:54:45 -0700 | [diff] [blame] | 238 | private PopupMenu mCurrentMenu = null; |
jinwu | e99f722 | 2017-05-15 17:25:46 +0800 | [diff] [blame] | 239 | private boolean mReleaseDualCam = false; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 240 | private ImageButton imgComparison; |
Chao Zhang | a731e09 | 2016-04-01 10:49:29 +0800 | [diff] [blame] | 241 | private String mPopUpText, mCancel; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 242 | RelativeLayout rlImageContainer; |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 243 | private int mEditrCropButtonSelect = 0; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 244 | private boolean isComingFromEditorScreen; |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 245 | private boolean mIsReloadByConfigurationChanged; |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 246 | private AlertDialog.Builder mBackAlertDialogBuilder; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 247 | |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 248 | private ProgressDialog mLoadingDialog; |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 249 | private long mRequestId = -1; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 250 | private WaterMarkView mWaterMarkView; |
| 251 | private boolean hasWaterMark; |
| 252 | private String locationStr; |
| 253 | private String temperature; |
| 254 | protected Handler handler = new Handler() { |
| 255 | @Override |
| 256 | public void handleMessage(Message msg) { |
| 257 | switch (msg.what) { |
| 258 | case SaveWaterMark.MARK_SAVE_COMPLETE: |
jinwu | e99f722 | 2017-05-15 17:25:46 +0800 | [diff] [blame] | 259 | completeSaveImage((Uri) msg.obj); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 260 | break; |
| 261 | default: |
| 262 | break; |
| 263 | } |
| 264 | super.handleMessage(msg); |
| 265 | } |
| 266 | }; |
| 267 | private SaveWaterMark mSaveWaterMark = new SaveWaterMark(); |
| 268 | |
jinwu | f23224f | 2017-06-19 11:16:06 +0800 | [diff] [blame] | 269 | private PresetManagementDialog mPresetDialog; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 270 | private FilterPresetSource mFilterPresetSource; |
| 271 | private ArrayList <SaveOption> tempFilterArray = new ArrayList<SaveOption>(); |
| 272 | private boolean mChangeable = false; |
| 273 | private int mOrientation; |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 274 | |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 275 | public ProcessingService getProcessingService() { |
| 276 | return mBoundService; |
| 277 | } |
| 278 | |
| 279 | public boolean isSimpleEditAction() { |
| 280 | return !PhotoPage.ACTION_NEXTGEN_EDIT.equalsIgnoreCase(mAction); |
| 281 | } |
| 282 | |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 283 | public long getRequestId() { |
| 284 | return mRequestId; |
| 285 | } |
| 286 | |
| 287 | private void registerFilter() { |
| 288 | IntentFilter filter = new IntentFilter(); |
| 289 | filter.addAction(ProcessingService.SAVE_IMAGE_COMPLETE_ACTION); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 290 | filter.addAction(Intent.ACTION_LOCALE_CHANGED); |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 291 | registerReceiver(mHandlerReceiver, filter); |
| 292 | } |
| 293 | |
| 294 | private final BroadcastReceiver mHandlerReceiver = new BroadcastReceiver() { |
| 295 | @Override |
| 296 | public void onReceive(Context context, Intent intent) { |
| 297 | String action = intent.getAction(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 298 | if (ProcessingService.SAVE_IMAGE_COMPLETE_ACTION.equals(action)) { |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 299 | Bundle bundle = intent.getExtras(); |
| 300 | long requestId = bundle.getLong(ProcessingService.KEY_REQUEST_ID); |
| 301 | //only handle own request |
| 302 | if (requestId == mRequestId) { |
zhuw | 48efd7d | 2016-08-03 10:05:00 +0800 | [diff] [blame] | 303 | String url = bundle.getString(ProcessingService.KEY_URL); |
| 304 | Uri saveUri = url == null ? null : Uri.parse(url); |
jinwu | e99f722 | 2017-05-15 17:25:46 +0800 | [diff] [blame] | 305 | completeSaveImage(saveUri); |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 306 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 307 | } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
| 308 | FiltersManager.reset(); |
| 309 | getProcessingService().setupPipeline(); |
| 310 | fillCategories(); |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | }; |
| 314 | |
zhuw | ad6505d | 2017-07-26 15:09:37 +0800 | [diff] [blame] | 315 | private boolean canUpdataUI = false; |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 316 | private ServiceConnection mConnection = new ServiceConnection() { |
ztenghui | a08fab5 | 2013-07-22 14:06:22 -0700 | [diff] [blame] | 317 | @Override |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 318 | public void onServiceConnected(ComponentName className, IBinder service) { |
| 319 | /* |
| 320 | * This is called when the connection with the service has been |
| 321 | * established, giving us the service object we can use to |
| 322 | * interact with the service. Because we have bound to a explicit |
| 323 | * service that we know is running in our own process, we can |
| 324 | * cast its IBinder to a concrete class and directly access it. |
| 325 | */ |
| 326 | mBoundService = ((ProcessingService.LocalBinder)service).getService(); |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 327 | updateUIAfterServiceStarted(); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 328 | } |
| 329 | |
ztenghui | a08fab5 | 2013-07-22 14:06:22 -0700 | [diff] [blame] | 330 | @Override |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 331 | public void onServiceDisconnected(ComponentName className) { |
| 332 | /* |
| 333 | * This is called when the connection with the service has been |
| 334 | * unexpectedly disconnected -- that is, its process crashed. |
| 335 | * Because it is running in our same process, we should never |
| 336 | * see this happen. |
| 337 | */ |
| 338 | mBoundService = null; |
Kedi Xu | f1069d5 | 2016-09-26 19:53:51 +0800 | [diff] [blame] | 339 | ImageFilter.resetStatics(); |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 340 | MasterImage.setMaster(null); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 341 | } |
| 342 | }; |
| 343 | |
| 344 | void doBindService() { |
| 345 | /* |
| 346 | * Establish a connection with the service. We use an explicit |
| 347 | * class name because we want a specific service implementation that |
| 348 | * we know will be running in our own process (and thus won't be |
| 349 | * supporting component replacement by other applications). |
| 350 | */ |
| 351 | bindService(new Intent(FilterShowActivity.this, ProcessingService.class), |
| 352 | mConnection, Context.BIND_AUTO_CREATE); |
| 353 | mIsBound = true; |
| 354 | } |
| 355 | |
| 356 | void doUnbindService() { |
| 357 | if (mIsBound) { |
| 358 | // Detach our existing connection. |
| 359 | unbindService(mConnection); |
| 360 | mIsBound = false; |
| 361 | } |
| 362 | } |
| 363 | |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 364 | public void updateUIAfterServiceStarted() { |
zhuw | ad6505d | 2017-07-26 15:09:37 +0800 | [diff] [blame] | 365 | if (!isPermissionGranted()) { |
| 366 | canUpdataUI = true; |
| 367 | return; |
| 368 | } |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 369 | //This activity will have more than one running instances |
| 370 | //mRequestId to distinguish the different instance's request |
| 371 | mRequestId = System.currentTimeMillis(); |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 372 | MasterImage.setMaster(mMasterImage); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 373 | ImageFilter.setActivityForMemoryToasts(this); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 374 | mUserPresetsManager = new UserPresetsManager(this); |
| 375 | mUserPresetsAdapter = new UserPresetsAdapter(this); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 376 | |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 377 | setupMasterImage(); |
| 378 | setupMenu(); |
| 379 | setDefaultValues(); |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 380 | getWindow().setBackgroundDrawable(new ColorDrawable(0)); |
| 381 | loadXML(); |
| 382 | |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 383 | fillCategories(); |
| 384 | loadMainPanel(); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 385 | extractXMPData(); |
| 386 | processIntent(); |
| 387 | } |
| 388 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 389 | @Override |
| 390 | public void onCreate(Bundle savedInstanceState) { |
| 391 | super.onCreate(savedInstanceState); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 392 | mOrientation = getResources().getConfiguration().orientation; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 393 | boolean onlyUsePortrait = getResources().getBoolean(R.bool.only_use_portrait); |
| 394 | if (onlyUsePortrait) { |
| 395 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 396 | } |
| 397 | |
Ruben Brunk | f07bb27 | 2013-03-11 12:00:06 -0700 | [diff] [blame] | 398 | clearGalleryBitmapPool(); |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 399 | registerFilter(); |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 400 | doBindService(); |
| 401 | getWindow().setBackgroundDrawable(new ColorDrawable(Color.GRAY)); |
| 402 | setContentView(R.layout.filtershow_splashscreen); |
huiyan | 4c35ffd | 2016-03-09 11:48:47 +0800 | [diff] [blame] | 403 | Window win = getWindow(); |
| 404 | WindowManager.LayoutParams winParams = win.getAttributes(); |
| 405 | winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 406 | win.setAttributes(winParams); |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 407 | } |
nicolasroard | 5ec40a6 | 2012-10-13 18:38:51 -0700 | [diff] [blame] | 408 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 409 | public boolean isShowingImageStatePanel() { |
| 410 | return mShowingImageStatePanel; |
| 411 | } |
| 412 | |
| 413 | public void loadMainPanel() { |
| 414 | if (findViewById(R.id.main_panel_container) == null) { |
| 415 | return; |
| 416 | } |
| 417 | MainPanel panel = new MainPanel(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 418 | Bundle bundle = new Bundle(); |
| 419 | bundle.putBoolean(MainPanel.EDITOR_TAG, isComingFromEditorScreen); |
| 420 | panel.setArguments(bundle); |
| 421 | isComingFromEditorScreen = false; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 422 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
| 423 | transaction.replace(R.id.main_panel_container, panel, MainPanel.FRAGMENT_TAG); |
nicolasroard | d1a098e | 2013-10-15 19:46:05 -0700 | [diff] [blame] | 424 | transaction.commitAllowingStateLoss(); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 427 | public void loadEditorPanel(final FilterRepresentation representation) { |
| 428 | final int currentId = representation.getEditorId(); |
| 429 | |
| 430 | // show representation |
| 431 | if (mCurrentEditor != null) { |
| 432 | mCurrentEditor.detach(); |
| 433 | } |
| 434 | mCurrentEditor = mEditorPlaceHolder.showEditor(currentId); |
| 435 | |
| 436 | if (mCurrentEditor.showsActionBar()) { |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 437 | setActionBar(); |
| 438 | showActionBar(true); |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 439 | } |
| 440 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 441 | if (representation.getFilterType() == FilterRepresentation.TYPE_WATERMARK_CATEGORY) { |
| 442 | loadWaterMarkPanel((FilterWatermarkRepresentation) representation); |
jinwu | 523164f | 2017-05-23 15:32:00 +0800 | [diff] [blame] | 443 | return; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 444 | } |
| 445 | |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 446 | if (currentId == ImageOnlyEditor.ID) { |
| 447 | mCurrentEditor.reflectCurrentFilter(); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 448 | return; |
| 449 | } |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 450 | if (currentId == EditorTruePortraitImageOnly.ID) { |
| 451 | mCurrentEditor.reflectCurrentFilter(); |
| 452 | setActionBarForEffects(mCurrentEditor); |
| 453 | return; |
| 454 | } |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 455 | if (currentId == EditorCrop.ID) { |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 456 | loadEditorCropPanel(); |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 457 | return; |
| 458 | } |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 459 | if (useStraightenPanel(currentId)) { |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 460 | new Runnable() { |
| 461 | @Override |
| 462 | public void run() { |
| 463 | StraightenPanel panel = new StraightenPanel(); |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 464 | Bundle bundle = new Bundle(); |
| 465 | bundle.putInt(StraightenPanel.EDITOR_ID, currentId); |
| 466 | bundle.putString(StraightenPanel.EDITOR_NAME, representation.getName()); |
| 467 | panel.setArguments(bundle); |
wqi | 6c5a2dd | 2016-04-14 11:25:23 +0800 | [diff] [blame] | 468 | FragmentTransaction transaction = |
| 469 | getSupportFragmentManager().beginTransaction(); |
| 470 | transaction.remove(getSupportFragmentManager().findFragmentByTag( |
| 471 | MainPanel.FRAGMENT_TAG)); |
| 472 | transaction.replace(R.id.main_panel_container, panel, |
| 473 | MainPanel.FRAGMENT_TAG); |
| 474 | transaction.commit(); |
| 475 | } |
| 476 | }.run(); |
| 477 | return; |
| 478 | } |
Jack Yoo | e94e766 | 2016-05-18 11:34:04 -0700 | [diff] [blame] | 479 | if (currentId == TrueScannerEditor.ID) { |
| 480 | new Runnable() { |
| 481 | @Override |
| 482 | public void run() { |
| 483 | TrueScannerPanel panel = new TrueScannerPanel(); |
| 484 | FragmentTransaction transaction = |
| 485 | getSupportFragmentManager().beginTransaction(); |
| 486 | transaction.remove(getSupportFragmentManager().findFragmentByTag( |
| 487 | MainPanel.FRAGMENT_TAG)); |
| 488 | transaction.replace(R.id.main_panel_container, panel, |
| 489 | MainPanel.FRAGMENT_TAG); |
| 490 | transaction.commit(); |
| 491 | } |
| 492 | }.run(); |
| 493 | return; |
| 494 | } |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 495 | if(currentId == EditorTruePortraitMask.ID) { |
| 496 | new Runnable() { |
| 497 | @Override |
| 498 | public void run() { |
| 499 | setActionBarForEffects(mCurrentEditor); |
| 500 | TruePortraitMaskEditorPanel panel = new TruePortraitMaskEditorPanel(); |
| 501 | FragmentTransaction transaction = |
| 502 | getSupportFragmentManager().beginTransaction(); |
| 503 | transaction.remove(getSupportFragmentManager().findFragmentByTag( |
| 504 | MainPanel.FRAGMENT_TAG)); |
| 505 | transaction.replace(R.id.main_panel_container, panel, |
| 506 | MainPanel.FRAGMENT_TAG); |
| 507 | transaction.commit(); |
| 508 | } |
| 509 | }.run(); |
| 510 | return; |
| 511 | } |
| 512 | |
nicolasroard | 0025946 | 2013-04-30 20:50:03 -0700 | [diff] [blame] | 513 | Runnable showEditor = new Runnable() { |
| 514 | @Override |
| 515 | public void run() { |
| 516 | EditorPanel panel = new EditorPanel(); |
| 517 | panel.setEditor(currentId); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 518 | setActionBarForEffects(mCurrentEditor); |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 519 | Fragment main = |
| 520 | getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 521 | if (main instanceof MainPanel) { |
| 522 | ((MainPanel) main).setEditorPanelFragment(panel); |
| 523 | } |
nicolasroard | 0025946 | 2013-04-30 20:50:03 -0700 | [diff] [blame] | 524 | } |
| 525 | }; |
| 526 | Fragment main = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 527 | boolean doAnimation = false; |
| 528 | if (mShowingImageStatePanel |
| 529 | && getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 530 | doAnimation = true; |
| 531 | } |
| 532 | if (doAnimation && main != null && main instanceof MainPanel) { |
| 533 | MainPanel mainPanel = (MainPanel) main; |
| 534 | View container = mainPanel.getView().findViewById(R.id.category_panel_container); |
| 535 | View bottom = mainPanel.getView().findViewById(R.id.bottom_panel); |
| 536 | int panelHeight = container.getHeight() + bottom.getHeight(); |
nicolasroard | af59322 | 2013-06-10 18:33:11 -0700 | [diff] [blame] | 537 | ViewPropertyAnimator anim = mainPanel.getView().animate(); |
| 538 | anim.translationY(panelHeight).start(); |
| 539 | final Handler handler = new Handler(); |
| 540 | handler.postDelayed(showEditor, anim.getDuration()); |
nicolasroard | 0025946 | 2013-04-30 20:50:03 -0700 | [diff] [blame] | 541 | } else { |
| 542 | showEditor.run(); |
| 543 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 546 | private boolean useStraightenPanel(int EditorID) { |
Jack Yoo | e94e766 | 2016-05-18 11:34:04 -0700 | [diff] [blame] | 547 | return (EditorID == EditorStraighten.ID || EditorID == HazeBusterEditor.ID || EditorID == SeeStraightEditor.ID); |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 548 | } |
| 549 | |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 550 | private void loadEditorCropPanel() { |
| 551 | new Runnable() { |
| 552 | @Override |
| 553 | public void run() { |
| 554 | EditorCropPanel panel = new EditorCropPanel(); |
| 555 | FragmentTransaction transaction = |
| 556 | getSupportFragmentManager().beginTransaction(); |
| 557 | transaction.remove(getSupportFragmentManager().findFragmentByTag( |
| 558 | MainPanel.FRAGMENT_TAG)); |
| 559 | transaction.replace(R.id.main_panel_container, panel, |
| 560 | MainPanel.FRAGMENT_TAG); |
Kedi Xu | 5db68ed | 2016-08-10 17:48:13 +0800 | [diff] [blame] | 561 | transaction.commitAllowingStateLoss(); |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 562 | } |
| 563 | }.run(); |
| 564 | } |
| 565 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 566 | private void loadWaterMarkPanel(final FilterWatermarkRepresentation representation) { |
| 567 | new Runnable() { |
| 568 | @Override |
| 569 | public void run() { |
| 570 | CategoryPanelLevelTwo panel = new CategoryPanelLevelTwo(representation.getAdapterId()); |
| 571 | FragmentTransaction transaction = |
| 572 | getSupportFragmentManager().beginTransaction(); |
| 573 | transaction.remove(getSupportFragmentManager().findFragmentByTag( |
| 574 | MainPanel.FRAGMENT_TAG)); |
| 575 | transaction.replace(R.id.main_panel_container, panel, |
| 576 | MainPanel.FRAGMENT_TAG); |
| 577 | transaction.commitAllowingStateLoss(); |
| 578 | } |
| 579 | }.run(); |
| 580 | } |
| 581 | |
| 582 | public void setLocation(String location) { |
| 583 | locationStr = location; |
| 584 | } |
| 585 | |
| 586 | public void setTemperature(String temperature) { |
| 587 | this.temperature = temperature; |
| 588 | } |
| 589 | |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 590 | public void leaveSeekBarPanel() { |
| 591 | removeSeekBarPanel(); |
| 592 | showDefaultImageView(); |
| 593 | setActionBar(); |
| 594 | showActionBar(true); |
| 595 | } |
| 596 | |
| 597 | private void removeSeekBarPanel() { |
| 598 | Fragment currentPanel = |
| 599 | getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 600 | if (currentPanel instanceof MainPanel) { |
| 601 | ((MainPanel) currentPanel).removeEditorPanelFragment(); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 602 | if (mCurrentEditor != null) { |
| 603 | mCurrentEditor.detach(); |
| 604 | } |
| 605 | mCurrentEditor = null; |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
John Hoford | 5d1cf1f | 2013-08-14 12:14:54 -0700 | [diff] [blame] | 609 | public void toggleInformationPanel() { |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 610 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
| 611 | transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left); |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 612 | |
| 613 | InfoPanel panel = new InfoPanel(); |
nicolasroard | b203968 | 2013-09-11 17:46:38 -0700 | [diff] [blame] | 614 | panel.show(transaction, InfoPanel.FRAGMENT_TAG); |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 615 | } |
| 616 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 617 | private void loadXML() { |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 618 | setContentView(R.layout.filtershow_activity); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 619 | Resources r = getResources(); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 620 | setActionBar(); |
wqi | 85875ab | 2016-03-10 11:54:20 +0800 | [diff] [blame] | 621 | mPopUpText = r.getString(R.string.discard).toUpperCase( |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 622 | Locale.getDefault()); |
Chao Zhang | a731e09 | 2016-04-01 10:49:29 +0800 | [diff] [blame] | 623 | mCancel = r.getString(R.string.cancel).toUpperCase(Locale.getDefault()); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 624 | int marginTop = r.getDimensionPixelSize(R.dimen.compare_margin_top); |
| 625 | int marginRight = r.getDimensionPixelSize(R.dimen.compare_margin_right); |
| 626 | imgComparison = (ImageButton) findViewById(R.id.imgComparison); |
| 627 | rlImageContainer = (RelativeLayout) findViewById(R.id.imageContainer); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 628 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 629 | mImageShow = (ImageShow) findViewById(R.id.imageShow); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 630 | mImageViews.add(mImageShow); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 631 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 632 | setupEditors(); |
John Hoford | 5aa0894 | 2013-01-18 08:59:35 -0800 | [diff] [blame] | 633 | |
nicolasroard | 733a013 | 2013-02-08 17:00:42 -0800 | [diff] [blame] | 634 | mEditorPlaceHolder.hide(); |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 635 | mImageShow.attach(); |
John Hoford | db94725 | 2013-01-08 14:15:19 -0800 | [diff] [blame] | 636 | |
nicolasroard | 6019ad9 | 2013-03-09 11:18:43 -0800 | [diff] [blame] | 637 | setupStatePanel(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 638 | |
| 639 | imgComparison.setOnTouchListener(new OnTouchListener() { |
| 640 | |
| 641 | @Override |
| 642 | public boolean onTouch(View v, MotionEvent event) { |
| 643 | int action = event.getAction(); |
| 644 | action = action & MotionEvent.ACTION_MASK; |
| 645 | if (action == MotionEvent.ACTION_DOWN) { |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 646 | MasterImage.getImage().setShowsOriginal(true); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 647 | v.setPressed(true); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 648 | if (mWaterMarkView != null) { |
| 649 | mWaterMarkView.setVisibility(View.GONE); |
| 650 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 651 | } |
| 652 | if (action == MotionEvent.ACTION_UP |
| 653 | || action == MotionEvent.ACTION_CANCEL |
| 654 | || action == MotionEvent.ACTION_OUTSIDE) { |
| 655 | v.setPressed(false); |
Chao Zhang | 7362c02 | 2016-05-23 14:31:39 +0800 | [diff] [blame] | 656 | MasterImage.getImage().setShowsOriginal(false); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 657 | if (mWaterMarkView != null) { |
| 658 | mWaterMarkView.setVisibility(View.VISIBLE); |
| 659 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | return false; |
| 663 | } |
| 664 | }); |
| 665 | } |
| 666 | |
| 667 | public void toggleComparisonButtonVisibility() { |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 668 | if (imgComparison.getVisibility() == View.VISIBLE) |
| 669 | imgComparison.setVisibility(View.GONE); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 670 | } |
| 671 | |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 672 | private void showSaveButtonIfNeed() { |
| 673 | if (MasterImage.getImage().hasModifications()) { |
| 674 | mSaveButton.setVisibility(View.VISIBLE); |
| 675 | } else { |
| 676 | mSaveButton.setVisibility(View.GONE); |
| 677 | } |
| 678 | } |
| 679 | |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 680 | public void setActionBar() { |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 681 | ActionBar actionBar = getActionBar(); |
| 682 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 683 | actionBar.setBackgroundDrawable(new ColorDrawable(getResources() |
| 684 | .getColor(R.color.edit_actionbar_background))); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 685 | ActionBar.LayoutParams lp = new ActionBar.LayoutParams( |
| 686 | ActionBar.LayoutParams.MATCH_PARENT, |
| 687 | ActionBar.LayoutParams.MATCH_PARENT, |
| 688 | Gravity.CENTER); |
| 689 | View customView = getLayoutInflater().inflate(R.layout.filtershow_actionbar, null); |
| 690 | actionBar.setCustomView(customView, lp); |
| 691 | mSaveButton = actionBar.getCustomView().findViewById(R.id.filtershow_done); |
| 692 | mSaveButton.setOnClickListener(new OnClickListener() { |
| 693 | @Override |
| 694 | public void onClick(View view) { |
| 695 | saveImage(); |
zdi | ca9299d | 2016-02-25 11:14:33 +0800 | [diff] [blame] | 696 | } |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 697 | }); |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 698 | |
| 699 | showSaveButtonIfNeed(); |
| 700 | |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 701 | View exitButton = actionBar.getCustomView().findViewById(R.id.filtershow_exit); |
| 702 | exitButton.setOnClickListener(new OnClickListener() { |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 703 | @Override |
| 704 | public void onClick(View v) { |
| 705 | if (mImageShow.hasModifications()) { |
| 706 | if (mBackAlertDialogBuilder == null) { |
| 707 | createBackDialog(); |
| 708 | } |
| 709 | mBackAlertDialogBuilder.show(); |
| 710 | } else { |
| 711 | done(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 712 | } |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 713 | } |
| 714 | }); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 715 | |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 716 | invalidateOptionsMenu(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | public void setActionBarForEffects(final Editor currentEditor) { |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 720 | ActionBar actionBar = getActionBar(); |
| 721 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 722 | actionBar.setBackgroundDrawable(new ColorDrawable(getResources() |
| 723 | .getColor(R.color.edit_actionbar_background))); |
| 724 | actionBar.setCustomView(R.layout.filtershow_actionbar_effects); |
| 725 | ImageButton cancelButton = (ImageButton) actionBar.getCustomView() |
| 726 | .findViewById(R.id.cancelFilter); |
| 727 | ImageButton applyButton = (ImageButton) actionBar.getCustomView() |
| 728 | .findViewById(R.id.applyFilter); |
| 729 | Button editTitle = (Button) actionBar.getCustomView().findViewById( |
| 730 | R.id.applyEffect); |
| 731 | editTitle.setTransformationMethod(null); |
| 732 | View actionControl = actionBar.getCustomView().findViewById( |
| 733 | R.id.panelAccessoryViewList); |
| 734 | cancelButton.setOnClickListener(new View.OnClickListener() { |
| 735 | @Override |
| 736 | public void onClick(View v) { |
| 737 | cancelCurrentFilter(); |
| 738 | FilterShowActivity.this.backToMain(); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 739 | setActionBar(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 740 | } |
| 741 | }); |
| 742 | applyButton.setOnClickListener(new View.OnClickListener() { |
| 743 | @Override |
| 744 | public void onClick(View v) { |
| 745 | currentEditor.finalApplyCalled(); |
| 746 | FilterShowActivity.this.backToMain(); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 747 | setActionBar(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 748 | } |
| 749 | }); |
| 750 | |
| 751 | if (currentEditor != null) { |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 752 | if(!currentEditor.showsActionBarControls()) { |
| 753 | cancelButton.setVisibility(View.GONE); |
| 754 | applyButton.setVisibility(View.GONE); |
| 755 | } |
| 756 | currentEditor.setEditorTitle(editTitle); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 757 | currentEditor.reflectCurrentFilter(); |
| 758 | if (currentEditor.useUtilityPanel()) { |
| 759 | currentEditor.openUtilityPanel((LinearLayout) actionControl); |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 764 | private void showActionBar(boolean show) { |
| 765 | ActionBar actionBar = getActionBar(); |
| 766 | if (actionBar != null ) { |
| 767 | if (show) { |
| 768 | if (!actionBar.isShowing()) { |
| 769 | actionBar.show(); |
| 770 | } |
| 771 | } else { |
| 772 | if (actionBar.isShowing()) { |
| 773 | actionBar.hide(); |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 779 | public void cancelCurrentFilter() { |
| 780 | MasterImage masterImage = MasterImage.getImage(); |
| 781 | HistoryManager adapter = masterImage.getHistory(); |
| 782 | |
| 783 | int position = adapter.undo(); |
| 784 | masterImage.onHistoryItemClick(position); |
| 785 | invalidateViews(); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 786 | |
| 787 | if(!masterImage.hasFusionApplied()) { |
| 788 | masterImage.setFusionUnderlay(null); |
| 789 | masterImage.setScaleFactor(1); |
| 790 | masterImage.resetTranslation(); |
| 791 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 792 | clearWaterMark(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 793 | } |
| 794 | |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 795 | public void adjustCompareButton(boolean scaled) { |
Chao Zhang | a731e09 | 2016-04-01 10:49:29 +0800 | [diff] [blame] | 796 | if (imgComparison == null) { |
| 797 | return; |
| 798 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 799 | Resources r = getResources(); |
| 800 | int marginTop, marginRight; |
Chao Zhang | a731e09 | 2016-04-01 10:49:29 +0800 | [diff] [blame] | 801 | marginTop = r.getDimensionPixelSize(R.dimen.compare_margin_top); |
| 802 | marginRight = r.getDimensionPixelSize(R.dimen.compare_margin_right); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 803 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imgComparison |
| 804 | .getLayoutParams(); |
| 805 | params.setMargins(0, marginTop, marginRight, 0); |
| 806 | imgComparison.setLayoutParams(params); |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 807 | } |
| 808 | |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 809 | public void fillCategories() { |
| 810 | fillLooks(); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 811 | loadUserPresets(); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 812 | fillBorders(); |
| 813 | fillTools(); |
| 814 | fillEffects(); |
Jack Yoo | 66d2144 | 2015-10-27 16:27:49 -0700 | [diff] [blame] | 815 | fillTrueScanner(); |
Jack Yoo | 1d415cf | 2016-01-18 15:49:46 -0800 | [diff] [blame] | 816 | fillHazeBuster(); |
Jack Yoo | 813c89e | 2016-01-21 15:28:31 -0800 | [diff] [blame] | 817 | fillSeeStraight(); |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 818 | fillVersions(); |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 819 | fillMakeup(); |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 820 | fillDualCamera(); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 821 | fillTruePortrait(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 822 | fillWaterMarks(); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 823 | } |
| 824 | |
nicolasroard | 6019ad9 | 2013-03-09 11:18:43 -0800 | [diff] [blame] | 825 | public void setupStatePanel() { |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 826 | MasterImage.getImage().setHistoryManager(mMasterImage.getHistory()); |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 827 | } |
| 828 | |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 829 | private void fillVersions() { |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 830 | if (mCategoryVersionsAdapter != null) { |
| 831 | mCategoryVersionsAdapter.clear(); |
| 832 | } |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 833 | mCategoryVersionsAdapter = new CategoryAdapter(this); |
| 834 | mCategoryVersionsAdapter.setShowAddButton(true); |
| 835 | } |
| 836 | |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 837 | public void registerAction(Action action) { |
| 838 | if (mActions.contains(action)) { |
| 839 | return; |
| 840 | } |
| 841 | mActions.add(action); |
| 842 | } |
| 843 | |
| 844 | private void loadActions() { |
| 845 | for (int i = 0; i < mActions.size(); i++) { |
| 846 | Action action = mActions.get(i); |
| 847 | action.setImageFrame(new Rect(0, 0, 96, 96), 0); |
| 848 | } |
| 849 | } |
| 850 | |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 851 | public void updateVersions() { |
| 852 | mCategoryVersionsAdapter.clear(); |
| 853 | FilterUserPresetRepresentation originalRep = new FilterUserPresetRepresentation( |
| 854 | getString(R.string.filtershow_version_original), new ImagePreset(), -1); |
| 855 | mCategoryVersionsAdapter.add( |
| 856 | new Action(this, originalRep, Action.FULL_VIEW)); |
| 857 | ImagePreset current = new ImagePreset(MasterImage.getImage().getPreset()); |
| 858 | FilterUserPresetRepresentation currentRep = new FilterUserPresetRepresentation( |
| 859 | getString(R.string.filtershow_version_current), current, -1); |
| 860 | mCategoryVersionsAdapter.add( |
| 861 | new Action(this, currentRep, Action.FULL_VIEW)); |
nicolasroard | 55a0279 | 2013-08-13 17:36:00 -0700 | [diff] [blame] | 862 | if (mVersions.size() > 0) { |
| 863 | mCategoryVersionsAdapter.add(new Action(this, Action.SPACER)); |
| 864 | } |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 865 | for (FilterUserPresetRepresentation rep : mVersions) { |
| 866 | mCategoryVersionsAdapter.add( |
nicolasroard | 55a0279 | 2013-08-13 17:36:00 -0700 | [diff] [blame] | 867 | new Action(this, rep, Action.FULL_VIEW, true)); |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 868 | } |
| 869 | mCategoryVersionsAdapter.notifyDataSetInvalidated(); |
| 870 | } |
| 871 | |
| 872 | public void addCurrentVersion() { |
| 873 | ImagePreset current = new ImagePreset(MasterImage.getImage().getPreset()); |
| 874 | mVersionsCounter++; |
| 875 | FilterUserPresetRepresentation rep = new FilterUserPresetRepresentation( |
| 876 | "" + mVersionsCounter, current, -1); |
| 877 | mVersions.add(rep); |
| 878 | updateVersions(); |
| 879 | } |
| 880 | |
| 881 | public void removeVersion(Action action) { |
| 882 | mVersions.remove(action.getRepresentation()); |
| 883 | updateVersions(); |
| 884 | } |
| 885 | |
nicolasroard | 0a24e52 | 2013-08-14 10:04:37 -0700 | [diff] [blame] | 886 | public void removeLook(Action action) { |
nicolasroard | 5af55f4 | 2013-08-14 10:34:08 -0700 | [diff] [blame] | 887 | FilterUserPresetRepresentation rep = |
| 888 | (FilterUserPresetRepresentation) action.getRepresentation(); |
nicolasroard | 0a24e52 | 2013-08-14 10:04:37 -0700 | [diff] [blame] | 889 | if (rep == null) { |
| 890 | return; |
| 891 | } |
| 892 | mUserPresetsManager.delete(rep.getId()); |
nicolasroard | 5af55f4 | 2013-08-14 10:34:08 -0700 | [diff] [blame] | 893 | updateUserPresetsFromManager(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | public void handlePreset(Action action,View view,int i) { |
| 897 | mChangeable = true; |
| 898 | mHandledSwipeView = view; |
| 899 | final Action ac = action; |
| 900 | mFilterPresetSource = new FilterPresetSource(this); |
| 901 | switch (i) { |
| 902 | case R.id.renameButton: |
| 903 | final View layout = View.inflate(this,R.layout.filtershow_default_edittext,null); |
| 904 | AlertDialog.Builder renameAlertDialogBuilder = new AlertDialog.Builder(this); |
| 905 | renameAlertDialogBuilder.setTitle(R.string.rename_before_exit); |
| 906 | renameAlertDialogBuilder.setView(layout); |
| 907 | renameAlertDialogBuilder.setPositiveButton(R.string.ok, |
| 908 | new DialogInterface.OnClickListener(){ |
| 909 | @Override |
| 910 | public void onClick(DialogInterface dialog, int id){ |
| 911 | EditText mEditText = (EditText) layout.findViewById( |
| 912 | R.id.filtershow_default_edit); |
| 913 | String name = String.valueOf(mEditText.getText()); |
| 914 | if ( (name.trim().length() == 0)|| name.isEmpty()) { |
| 915 | Toast.makeText(getApplicationContext(), |
| 916 | getString(R.string.filter_name_notification), |
| 917 | Toast.LENGTH_SHORT).show(); |
| 918 | } else if (isDuplicateName(name)) { |
| 919 | Toast.makeText(getApplicationContext(), |
| 920 | getString(R.string.filter_name_duplicate), |
| 921 | Toast.LENGTH_SHORT).show(); |
| 922 | } else { |
| 923 | renamePreset(ac, name); |
| 924 | } |
| 925 | dialog.dismiss(); |
| 926 | } |
| 927 | } |
| 928 | ); |
| 929 | renameAlertDialogBuilder.setNegativeButton(mCancel, |
| 930 | new DialogInterface.OnClickListener() { |
| 931 | @Override |
| 932 | public void onClick (DialogInterface dialog, int id){ |
| 933 | |
| 934 | } |
| 935 | } |
| 936 | ); |
| 937 | renameAlertDialogBuilder.create().show(); |
| 938 | break; |
| 939 | |
| 940 | case R.id.deleteButton: |
| 941 | String name = action.getName(); |
| 942 | AlertDialog.Builder deleteAlertDialogBuilder = new AlertDialog.Builder(this); |
| 943 | String textview ="Do you want to delete "+name+"?"; |
| 944 | deleteAlertDialogBuilder.setMessage(textview) |
| 945 | .setTitle(R.string.delete_before_exit); |
| 946 | deleteAlertDialogBuilder.setPositiveButton(R.string.ok, |
| 947 | new DialogInterface.OnClickListener(){ |
| 948 | @Override |
| 949 | public void onClick(DialogInterface dialog, int id){ |
| 950 | ((SwipableView) mHandledSwipeView).delete(); |
| 951 | dialog.dismiss(); |
| 952 | } |
| 953 | } |
| 954 | ); |
| 955 | deleteAlertDialogBuilder.setNegativeButton(mCancel, |
| 956 | new DialogInterface.OnClickListener() { |
| 957 | @Override |
| 958 | public void onClick (DialogInterface dialog, int id){ |
| 959 | dialog.dismiss(); |
| 960 | |
| 961 | } |
| 962 | } |
| 963 | ); |
| 964 | deleteAlertDialogBuilder.create().show(); |
| 965 | break; |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | public void removePreset(Action action) { |
| 970 | FilterPresetRepresentation rep = |
| 971 | (FilterPresetRepresentation)action.getRepresentation(); |
| 972 | if (rep == null) { |
| 973 | return; |
| 974 | } |
| 975 | if (tempFilterArray.size() != 0) { |
| 976 | for (int i = 0; i < tempFilterArray.size(); i++) { |
| 977 | if (rep.getId() == tempFilterArray.get(i)._id) { |
| 978 | tempFilterArray.remove(i); |
| 979 | fillLooks(); |
| 980 | return; |
| 981 | } |
| 982 | } |
| 983 | } |
| 984 | mFilterPresetSource.removePreset(rep.getId()); |
| 985 | fillLooks(); |
| 986 | } |
| 987 | |
| 988 | public void renamePreset(Action action, String name) { |
| 989 | FilterPresetRepresentation rep = |
| 990 | (FilterPresetRepresentation)action.getRepresentation(); |
| 991 | if (rep == null) { |
| 992 | return; |
| 993 | } |
| 994 | if (tempFilterArray.size() != 0) { |
| 995 | for (int i = 0; i < tempFilterArray.size(); i++) { |
| 996 | if (rep.getId() == tempFilterArray.get(i)._id) { |
| 997 | tempFilterArray.get(i).name = name; |
| 998 | fillLooks(); |
| 999 | return; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | mFilterPresetSource.updatePresetName(rep.getId(),name); |
| 1004 | fillLooks(); |
| 1005 | } |
| 1006 | |
| 1007 | public boolean isDuplicateName(String name) { |
| 1008 | ArrayList<String> nameSum = new ArrayList<String>(); |
| 1009 | if (tempFilterArray.size() != 0) { |
| 1010 | for (int i = 0; i < tempFilterArray.size(); i++) |
| 1011 | nameSum.add(tempFilterArray.get(i).name); |
| 1012 | } |
| 1013 | |
| 1014 | ArrayList<SaveOption> ret = mFilterPresetSource.getAllUserPresets(); |
| 1015 | if (ret != null) { |
| 1016 | for (int id = 0; id < ret.size(); id++) |
| 1017 | nameSum.add(ret.get(id).name); |
| 1018 | } |
| 1019 | |
| 1020 | for (int i = 0; i < nameSum.size(); i++) { |
| 1021 | if (name.equals(nameSum.get(i))) return true; |
| 1022 | } |
| 1023 | return false; |
nicolasroard | 0a24e52 | 2013-08-14 10:04:37 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 1026 | private void fillEffects() { |
nicolasroard | 38fc044 | 2013-03-04 16:01:24 -0800 | [diff] [blame] | 1027 | FiltersManager filtersManager = FiltersManager.getManager(); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 1028 | ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getEffects(); |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 1029 | if (mCategoryFiltersAdapter != null) { |
| 1030 | mCategoryFiltersAdapter.clear(); |
| 1031 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1032 | mCategoryFiltersAdapter = new CategoryAdapter(this); |
| 1033 | for (FilterRepresentation representation : filtersRepresentations) { |
| 1034 | if (representation.getTextId() != 0) { |
| 1035 | representation.setName(getString(representation.getTextId())); |
| 1036 | } |
| 1037 | mCategoryFiltersAdapter.add(new Action(this, representation)); |
| 1038 | } |
nicolasroard | 38fc044 | 2013-03-04 16:01:24 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 1041 | private void fillMakeup() { |
| 1042 | if(!SimpleMakeupImageFilter.HAS_TS_MAKEUP) { |
| 1043 | return; |
| 1044 | } |
| 1045 | |
| 1046 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1047 | ArrayList<FilterRepresentation> makeups = filtersManager.getMakeup(); |
| 1048 | if (mCategoryMakeupAdapter != null) { |
| 1049 | mCategoryMakeupAdapter.clear(); |
| 1050 | } |
| 1051 | mCategoryMakeupAdapter = new CategoryAdapter(this); |
| 1052 | for (FilterRepresentation makeup : makeups) { |
| 1053 | if (makeup.getTextId() != 0) { |
| 1054 | makeup.setName(getString(makeup.getTextId())); |
| 1055 | } |
| 1056 | mCategoryMakeupAdapter.add(new Action(this, makeup)); |
| 1057 | } |
| 1058 | } |
| 1059 | |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 1060 | private void fillDualCamera() { |
| 1061 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1062 | ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getDualCamera(); |
| 1063 | if (mCategoryDualCamAdapter != null) { |
| 1064 | mCategoryDualCamAdapter.clear(); |
| 1065 | } |
| 1066 | mCategoryDualCamAdapter = new CategoryAdapter(this); |
| 1067 | for (FilterRepresentation representation : filtersRepresentations) { |
| 1068 | if (representation.getTextId() != 0) { |
| 1069 | representation.setName(getString(representation.getTextId())); |
| 1070 | } |
| 1071 | mCategoryDualCamAdapter.add(new Action(this, representation)); |
| 1072 | } |
| 1073 | } |
| 1074 | |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1075 | private void fillTruePortrait() { |
| 1076 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1077 | ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getTruePortrait(); |
| 1078 | if (mCategoryTruePortraitAdapter != null) { |
| 1079 | mCategoryTruePortraitAdapter.clear(); |
| 1080 | } |
| 1081 | mCategoryTruePortraitAdapter = new CategoryAdapter(this); |
| 1082 | for (FilterRepresentation representation : filtersRepresentations) { |
| 1083 | if (representation.getTextId() != 0) { |
| 1084 | representation.setName(getString(representation.getTextId())); |
| 1085 | } |
| 1086 | mCategoryTruePortraitAdapter.add(new Action(this, representation)); |
| 1087 | } |
| 1088 | } |
| 1089 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1090 | private void fillPresetFilter() { |
| 1091 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1092 | ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getFilterPreset(); |
| 1093 | if(mChangeable) { |
| 1094 | ArrayList<FilterRepresentation> mFilterPreset = new ArrayList<FilterRepresentation>(); |
| 1095 | ArrayList<SaveOption> ret = mFilterPresetSource.getAllUserPresets(); |
| 1096 | if (ret == null) return; |
| 1097 | for (int id = 0; id < ret.size(); id ++) { |
| 1098 | FilterPresetRepresentation representation = new FilterPresetRepresentation( |
| 1099 | ret.get(id).name, ret.get(id)._id, id + 1); |
| 1100 | Uri filteredUri = Uri.parse(ret.get(id).Uri); |
| 1101 | representation.setUri(filteredUri); |
| 1102 | representation.setSerializationName("Custom"); |
| 1103 | mFilterPreset.add(representation); |
| 1104 | } |
| 1105 | if (tempFilterArray.size() != 0){ |
| 1106 | for (int id = 0; id < tempFilterArray.size(); id ++) { |
| 1107 | FilterPresetRepresentation representation = new FilterPresetRepresentation( |
| 1108 | tempFilterArray.get(id).name, tempFilterArray.get(id)._id, id + 1); |
| 1109 | Uri filteredUri = Uri.parse(tempFilterArray.get(id).Uri); |
| 1110 | representation.setUri(filteredUri); |
| 1111 | representation.setSerializationName("Custom"); |
| 1112 | mFilterPreset.add(representation); |
| 1113 | } |
| 1114 | } |
| 1115 | filtersRepresentations = mFilterPreset; |
| 1116 | mChangeable = false; |
| 1117 | } |
| 1118 | |
| 1119 | if (filtersRepresentations == null) return; |
| 1120 | for (FilterRepresentation representation : filtersRepresentations) { |
| 1121 | mCategoryLooksAdapter.add(new Action(this, representation, Action.FULL_VIEW,true)); |
| 1122 | } |
| 1123 | } |
| 1124 | |
Jack Yoo | 66d2144 | 2015-10-27 16:27:49 -0700 | [diff] [blame] | 1125 | private void fillTrueScanner() { |
| 1126 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1127 | ArrayList<FilterRepresentation> trueScannerRepresentations = filtersManager.getTrueScanner(); |
| 1128 | if (mCategoryTrueScannerAdapter != null) { |
| 1129 | mCategoryTrueScannerAdapter.clear(); |
| 1130 | } |
| 1131 | mCategoryTrueScannerAdapter = new CategoryAdapter(this); |
| 1132 | for (FilterRepresentation representation : trueScannerRepresentations) { |
| 1133 | if (representation.getTextId() != 0) { |
| 1134 | representation.setName(getString(representation.getTextId())); |
| 1135 | } |
| 1136 | mCategoryTrueScannerAdapter.add(new Action(this, representation)); |
| 1137 | } |
| 1138 | } |
| 1139 | |
Jack Yoo | 1d415cf | 2016-01-18 15:49:46 -0800 | [diff] [blame] | 1140 | private void fillHazeBuster() { |
| 1141 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1142 | ArrayList<FilterRepresentation> hazeBusterRepresentations = filtersManager.getHazeBuster(); |
| 1143 | if (mCategoryHazeBusterAdapter != null) { |
| 1144 | mCategoryHazeBusterAdapter.clear(); |
| 1145 | } |
| 1146 | mCategoryHazeBusterAdapter = new CategoryAdapter(this); |
| 1147 | for (FilterRepresentation representation : hazeBusterRepresentations) { |
| 1148 | if (representation.getTextId() != 0) { |
| 1149 | representation.setName(getString(representation.getTextId())); |
| 1150 | } |
| 1151 | mCategoryHazeBusterAdapter.add(new Action(this, representation)); |
| 1152 | } |
| 1153 | } |
| 1154 | |
Jack Yoo | 813c89e | 2016-01-21 15:28:31 -0800 | [diff] [blame] | 1155 | private void fillSeeStraight() { |
| 1156 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1157 | ArrayList<FilterRepresentation> hazeBusterRepresentations = filtersManager.getSeeStraight(); |
| 1158 | if (mCategorySeeStraightAdapter != null) { |
| 1159 | mCategorySeeStraightAdapter.clear(); |
| 1160 | } |
| 1161 | mCategorySeeStraightAdapter = new CategoryAdapter(this); |
| 1162 | for (FilterRepresentation representation : hazeBusterRepresentations) { |
| 1163 | if (representation.getTextId() != 0) { |
| 1164 | representation.setName(getString(representation.getTextId())); |
| 1165 | } |
| 1166 | mCategorySeeStraightAdapter.add(new Action(this, representation)); |
| 1167 | } |
| 1168 | } |
| 1169 | |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 1170 | private void fillTools() { |
nicolasroard | 38fc044 | 2013-03-04 16:01:24 -0800 | [diff] [blame] | 1171 | FiltersManager filtersManager = FiltersManager.getManager(); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 1172 | ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getTools(); |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 1173 | if (mCategoryGeometryAdapter != null) { |
| 1174 | mCategoryGeometryAdapter.clear(); |
| 1175 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1176 | mCategoryGeometryAdapter = new CategoryAdapter(this); |
| 1177 | for (FilterRepresentation representation : filtersRepresentations) { |
| 1178 | mCategoryGeometryAdapter.add(new Action(this, representation)); |
| 1179 | } |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1180 | } |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 1181 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1182 | private void fillWaterMarks() { |
| 1183 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1184 | ArrayList<ArrayList<FilterRepresentation>> filters = new ArrayList<>(); |
| 1185 | filters.add(filtersManager.getWaterMarks()); |
| 1186 | filters.add(filtersManager.getLocations()); |
| 1187 | filters.add(filtersManager.getTimes()); |
| 1188 | filters.add(filtersManager.getWeathers()); |
| 1189 | filters.add(filtersManager.getEmotions()); |
| 1190 | filters.add(filtersManager.getFoods()); |
| 1191 | if (mCategoryWatermarkAdapters != null) { |
| 1192 | mCategoryWatermarkAdapters.clear(); |
| 1193 | } |
| 1194 | mCategoryWatermarkAdapters = new ArrayList<>(); |
| 1195 | for (int i = 0; i < filters.size(); i++) { |
| 1196 | mCategoryWatermarkAdapters.add(new CategoryAdapter(this)); |
| 1197 | for (FilterRepresentation representation : filters.get(i)) { |
| 1198 | mCategoryWatermarkAdapters.get(i).add(new Action(this, representation)); |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1203 | private void processIntent() { |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 1204 | Intent intent = getIntent(); |
Bobby Georgescu | a850a54 | 2012-10-23 15:40:06 -0700 | [diff] [blame] | 1205 | if (intent.getBooleanExtra(LAUNCH_FULLSCREEN, false)) { |
| 1206 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 1207 | } |
| 1208 | |
Ruben Brunk | ab779de | 2013-02-14 16:18:22 -0800 | [diff] [blame] | 1209 | mAction = intent.getAction(); |
ztenghui | b3f62e4 | 2013-06-10 15:51:42 -0700 | [diff] [blame] | 1210 | mSelectedImageUri = intent.getData(); |
| 1211 | Uri loadUri = mSelectedImageUri; |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 1212 | if (mOriginalImageUri != null) { |
ztenghui | b3f62e4 | 2013-06-10 15:51:42 -0700 | [diff] [blame] | 1213 | loadUri = mOriginalImageUri; |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 1214 | } |
ztenghui | b3f62e4 | 2013-06-10 15:51:42 -0700 | [diff] [blame] | 1215 | if (loadUri != null) { |
| 1216 | startLoadBitmap(loadUri); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 1217 | } else { |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 1218 | pickImage(SELECT_PICTURE); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1222 | private void setupEditors() { |
Chao Zhang | 0316f86 | 2016-01-28 20:55:00 +0800 | [diff] [blame] | 1223 | FrameLayout editorContainer = (FrameLayout) findViewById(R.id.editorContainer); |
Chao Zhang | 0316f86 | 2016-01-28 20:55:00 +0800 | [diff] [blame] | 1224 | mEditorPlaceHolder.setContainer(editorContainer); |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1225 | EditorManager.addEditors(mEditorPlaceHolder); |
| 1226 | mEditorPlaceHolder.setOldViews(mImageViews); |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1227 | } |
| 1228 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1229 | private void setDefaultValues() { |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1230 | Resources res = getResources(); |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1231 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1232 | // TODO: get those values from XML. |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1233 | FramedTextButton.setTextSize((int) getPixelsFromDip(14)); |
| 1234 | FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4)); |
| 1235 | FramedTextButton.setTriangleSize((int) getPixelsFromDip(10)); |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1236 | |
| 1237 | Drawable curveHandle = res.getDrawable(R.drawable.camera_crop); |
| 1238 | int curveHandleSize = (int) res.getDimension(R.dimen.crop_indicator_size); |
| 1239 | Spline.setCurveHandle(curveHandle, curveHandleSize); |
| 1240 | Spline.setCurveWidth((int) getPixelsFromDip(3)); |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 1241 | |
| 1242 | mOriginalImageUri = null; |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1245 | private void startLoadBitmap(Uri uri) { |
nicolasroard | 733a013 | 2013-02-08 17:00:42 -0800 | [diff] [blame] | 1246 | final View imageShow = findViewById(R.id.imageShow); |
| 1247 | imageShow.setVisibility(View.INVISIBLE); |
John Hoford | f7f24e8 | 2013-09-13 16:02:09 -0700 | [diff] [blame] | 1248 | startLoadingIndicator(); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1249 | mShowingTinyPlanet = false; |
| 1250 | mLoadBitmapTask = new LoadBitmapTask(); |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1251 | mLoadBitmapTask.execute(uri); |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 1252 | |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1253 | mParseDepthMapTask = new ParseDepthMapTask(); |
| 1254 | mParseDepthMapTask.execute(uri); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1255 | |
| 1256 | if(TruePortraitNativeEngine.getInstance().isLibLoaded()) { |
| 1257 | mLoadTruePortraitTask = new LoadTruePortraitTask(); |
| 1258 | mLoadTruePortraitTask.execute(uri); |
| 1259 | } |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1260 | } |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1261 | |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1262 | private void showDualCameraButton(boolean visible) { |
| 1263 | if (DualCameraEffect.isSupported()) |
| 1264 | mReleaseDualCam = true; |
| 1265 | Fragment currentPanel = getSupportFragmentManager() |
| 1266 | .findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 1267 | if (currentPanel instanceof MainPanel) { |
| 1268 | ((MainPanel) currentPanel).showDualCameraButton(visible && mReleaseDualCam); |
| 1269 | } |
| 1270 | } |
| 1271 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1272 | private void fillBorders() { |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 1273 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 1274 | ArrayList<FilterRepresentation> borders = filtersManager.getBorders(); |
kaiyiz | 6e4a5cc | 2014-10-20 11:43:17 +0800 | [diff] [blame] | 1275 | mCategoryBordersAdapter = new CategoryAdapter(this); |
Ruben Brunk | d88683e | 2013-04-01 16:55:05 -0700 | [diff] [blame] | 1276 | |
Ruben Brunk | f79f954 | 2013-03-18 22:23:43 -0700 | [diff] [blame] | 1277 | for (int i = 0; i < borders.size(); i++) { |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 1278 | FilterRepresentation filter = borders.get(i); |
Michael Bestas | f4f030b | 2016-06-07 00:06:53 +0300 | [diff] [blame] | 1279 | filter.setName(getString(R.string.frame, i)); |
Ruben Brunk | f79f954 | 2013-03-18 22:23:43 -0700 | [diff] [blame] | 1280 | if (i == 0) { |
Ruben Brunk | 3cb106d | 2013-06-03 15:41:36 -0700 | [diff] [blame] | 1281 | filter.setName(getString(R.string.none)); |
nicolasroard | 9090141 | 2013-02-01 13:48:21 -0800 | [diff] [blame] | 1282 | } |
kaiyiz | 6e4a5cc | 2014-10-20 11:43:17 +0800 | [diff] [blame] | 1283 | mCategoryBordersAdapter.add(new Action(this, filter, Action.FULL_VIEW)); |
nicolasroard | 9090141 | 2013-02-01 13:48:21 -0800 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 1287 | public UserPresetsAdapter getUserPresetsAdapter() { |
| 1288 | return mUserPresetsAdapter; |
| 1289 | } |
| 1290 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1291 | public CategoryAdapter getCategoryLooksAdapter() { |
| 1292 | return mCategoryLooksAdapter; |
| 1293 | } |
| 1294 | |
| 1295 | public CategoryAdapter getCategoryBordersAdapter() { |
| 1296 | return mCategoryBordersAdapter; |
| 1297 | } |
| 1298 | |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 1299 | public CategoryAdapter getCategoryMakeupAdapter() { |
| 1300 | return mCategoryMakeupAdapter; |
| 1301 | } |
| 1302 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1303 | public CategoryAdapter getCategoryGeometryAdapter() { |
| 1304 | return mCategoryGeometryAdapter; |
| 1305 | } |
| 1306 | |
| 1307 | public CategoryAdapter getCategoryFiltersAdapter() { |
| 1308 | return mCategoryFiltersAdapter; |
| 1309 | } |
| 1310 | |
Jack Yoo | 66d2144 | 2015-10-27 16:27:49 -0700 | [diff] [blame] | 1311 | public CategoryAdapter getCategoryTrueScannerAdapter() { |
| 1312 | return mCategoryTrueScannerAdapter; |
| 1313 | } |
| 1314 | |
Jack Yoo | 1d415cf | 2016-01-18 15:49:46 -0800 | [diff] [blame] | 1315 | public CategoryAdapter getCategoryHazeBusterAdapter() { |
| 1316 | return mCategoryHazeBusterAdapter; |
| 1317 | } |
| 1318 | |
Jack Yoo | 813c89e | 2016-01-21 15:28:31 -0800 | [diff] [blame] | 1319 | public CategoryAdapter getCategorySeeStraightAdapter() { |
| 1320 | return mCategorySeeStraightAdapter; |
| 1321 | } |
| 1322 | |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 1323 | public CategoryAdapter getCategoryVersionsAdapter() { |
| 1324 | return mCategoryVersionsAdapter; |
| 1325 | } |
| 1326 | |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 1327 | public CategoryAdapter getCategoryDualCamAdapter() { |
| 1328 | return mCategoryDualCamAdapter; |
| 1329 | } |
| 1330 | |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1331 | public CategoryAdapter getCategoryTruePortraitAdapter() { |
| 1332 | return mCategoryTruePortraitAdapter; |
| 1333 | } |
| 1334 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1335 | public CategoryAdapter getCategoryWatermarkAdapter() { |
| 1336 | return (mCategoryWatermarkAdapters != null) ? mCategoryWatermarkAdapters.get(0) : null; |
| 1337 | } |
| 1338 | |
| 1339 | public CategoryAdapter getCategoryLocationAdapter() { |
| 1340 | return (mCategoryWatermarkAdapters != null) ? mCategoryWatermarkAdapters.get(1) : null; |
| 1341 | } |
| 1342 | |
| 1343 | public CategoryAdapter getCategoryTimeAdapter() { |
| 1344 | return (mCategoryWatermarkAdapters != null) ? mCategoryWatermarkAdapters.get(2) : null; |
| 1345 | } |
| 1346 | |
| 1347 | public CategoryAdapter getCategoryWeatherAdapter() { |
| 1348 | return (mCategoryWatermarkAdapters != null) ? mCategoryWatermarkAdapters.get(3) : null; |
| 1349 | } |
| 1350 | |
| 1351 | public CategoryAdapter getCategoryEmotionAdapter() { |
| 1352 | return (mCategoryWatermarkAdapters != null) ? mCategoryWatermarkAdapters.get(4) : null; |
| 1353 | } |
| 1354 | |
| 1355 | public CategoryAdapter getCategoryFoodAdapter() { |
| 1356 | return (mCategoryWatermarkAdapters != null) ? mCategoryWatermarkAdapters.get(5) : null; |
| 1357 | } |
| 1358 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1359 | public void removeFilterRepresentation(FilterRepresentation filterRepresentation) { |
| 1360 | if (filterRepresentation == null) { |
| 1361 | return; |
| 1362 | } |
| 1363 | ImagePreset oldPreset = MasterImage.getImage().getPreset(); |
| 1364 | ImagePreset copy = new ImagePreset(oldPreset); |
| 1365 | copy.removeFilter(filterRepresentation); |
nicolasroard | ed60979 | 2013-06-26 16:56:31 -0700 | [diff] [blame] | 1366 | MasterImage.getImage().setPreset(copy, copy.getLastRepresentation(), true); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1367 | if (MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) { |
| 1368 | FilterRepresentation lastRepresentation = copy.getLastRepresentation(); |
| 1369 | MasterImage.getImage().setCurrentFilterRepresentation(lastRepresentation); |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | public void useFilterRepresentation(FilterRepresentation filterRepresentation) { |
| 1374 | if (filterRepresentation == null) { |
| 1375 | return; |
| 1376 | } |
nicolasroard | 57bd092 | 2013-08-12 14:04:11 -0700 | [diff] [blame] | 1377 | if (!(filterRepresentation instanceof FilterRotateRepresentation) |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1378 | && !(filterRepresentation instanceof FilterMirrorRepresentation) |
| 1379 | && MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) { |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1380 | return; |
| 1381 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1382 | if (filterRepresentation.getFilterType() == FilterWatermarkRepresentation.TYPE_WATERMARK_CATEGORY) { |
| 1383 | return; |
| 1384 | } |
zhuw | fa5ddff | 2017-11-23 11:33:33 +0800 | [diff] [blame] | 1385 | boolean addToHistory = filterRepresentation.getFilterType() |
| 1386 | != FilterWatermarkRepresentation.TYPE_WATERMARK; |
nicolasroard | 9f452e0 | 2013-08-23 00:10:01 -0700 | [diff] [blame] | 1387 | if (filterRepresentation instanceof FilterUserPresetRepresentation |
| 1388 | || filterRepresentation instanceof FilterRotateRepresentation |
| 1389 | || filterRepresentation instanceof FilterMirrorRepresentation) { |
| 1390 | MasterImage.getImage().onNewLook(filterRepresentation); |
| 1391 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1392 | ImagePreset oldPreset = MasterImage.getImage().getPreset(); |
| 1393 | ImagePreset copy = new ImagePreset(oldPreset); |
| 1394 | FilterRepresentation representation = copy.getRepresentation(filterRepresentation); |
| 1395 | if (representation == null) { |
nicolasroard | 3cd6fc8 | 2013-08-15 15:35:53 -0700 | [diff] [blame] | 1396 | filterRepresentation = filterRepresentation.copy(); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1397 | copy.addFilter(filterRepresentation); |
| 1398 | } else { |
ztenghui | c9ca6d1 | 2013-06-26 13:54:17 -0700 | [diff] [blame] | 1399 | if (filterRepresentation.allowsSingleInstanceOnly()) { |
ztenghui | d2e9ea0 | 2013-06-24 13:54:04 -0700 | [diff] [blame] | 1400 | // Don't just update the filter representation. Centralize the |
| 1401 | // logic in the addFilter(), such that we can keep "None" as |
| 1402 | // null. |
nicolasroard | 20667d2 | 2013-08-14 16:43:07 -0700 | [diff] [blame] | 1403 | if (!representation.equals(filterRepresentation)) { |
| 1404 | // Only do this if the filter isn't the same |
| 1405 | // (state panel clicks can lead us here) |
| 1406 | copy.removeFilter(representation); |
| 1407 | copy.addFilter(filterRepresentation); |
| 1408 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1409 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1410 | } |
zhuw | fa5ddff | 2017-11-23 11:33:33 +0800 | [diff] [blame] | 1411 | MasterImage.getImage().setPreset(copy, filterRepresentation, addToHistory); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1412 | MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation); |
| 1413 | } |
| 1414 | |
| 1415 | public void showRepresentation(FilterRepresentation representation) { |
John Hoford | f57e588 | 2013-05-20 18:24:12 -0700 | [diff] [blame] | 1416 | if (representation == null) { |
| 1417 | return; |
| 1418 | } |
zhuw | abf3079 | 2018-04-20 17:18:03 +0800 | [diff] [blame] | 1419 | if (hasWaterMark && representation.getFilterType() != FilterRepresentation.TYPE_WATERMARK && |
| 1420 | representation.getFilterType() != |
| 1421 | FilterWatermarkRepresentation.TYPE_WATERMARK_CATEGORY) { |
| 1422 | clearWaterMark(); |
| 1423 | resetHistory(); |
| 1424 | showWatermarkButton(false); |
| 1425 | } |
nicolasroard | e5f4b78 | 2013-06-26 14:33:15 -0700 | [diff] [blame] | 1426 | |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 1427 | Fragment currentPanel = |
| 1428 | getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 1429 | if (currentPanel instanceof MainPanel && ((MainPanel) currentPanel).hasEditorPanel()) { |
| 1430 | if (representation.equals(MasterImage.getImage().getCurrentFilterRepresentation())) { |
| 1431 | return; |
| 1432 | } |
| 1433 | // cancel previous filter. |
| 1434 | cancelCurrentFilter(); |
| 1435 | showDefaultImageView(); |
| 1436 | removeSeekBarPanel(); |
| 1437 | } |
| 1438 | |
nicolasroard | 57bd092 | 2013-08-12 14:04:11 -0700 | [diff] [blame] | 1439 | if (representation instanceof FilterRotateRepresentation) { |
| 1440 | FilterRotateRepresentation r = (FilterRotateRepresentation) representation; |
| 1441 | r.rotateCW(); |
| 1442 | } |
| 1443 | if (representation instanceof FilterMirrorRepresentation) { |
| 1444 | FilterMirrorRepresentation r = (FilterMirrorRepresentation) representation; |
| 1445 | r.cycle(); |
| 1446 | } |
nicolasroard | edf4b09 | 2013-09-13 16:37:43 -0700 | [diff] [blame] | 1447 | if (representation.isBooleanFilter()) { |
| 1448 | ImagePreset preset = MasterImage.getImage().getPreset(); |
| 1449 | if (preset.getRepresentation(representation) != null) { |
| 1450 | // remove |
| 1451 | ImagePreset copy = new ImagePreset(preset); |
| 1452 | copy.removeFilter(representation); |
| 1453 | FilterRepresentation filterRepresentation = representation.copy(); |
| 1454 | MasterImage.getImage().setPreset(copy, filterRepresentation, true); |
| 1455 | MasterImage.getImage().setCurrentFilterRepresentation(null); |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 1456 | |
| 1457 | setActionBar(); |
| 1458 | showActionBar(true); |
nicolasroard | edf4b09 | 2013-09-13 16:37:43 -0700 | [diff] [blame] | 1459 | return; |
| 1460 | } |
| 1461 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1462 | if (representation.getFilterType() == FilterRepresentation.TYPE_DUALCAM) { |
| 1463 | DisplayMetrics dm = getResources().getDisplayMetrics(); |
| 1464 | float[] mTmpPoint = new float[2]; |
| 1465 | mTmpPoint[0] = dm.widthPixels/2; |
| 1466 | mTmpPoint[1] = dm.heightPixels/2; |
| 1467 | Matrix m = MasterImage.getImage().getScreenToImageMatrix(true); |
| 1468 | m.mapPoints(mTmpPoint); |
| 1469 | if (representation instanceof FilterDualCamBasicRepresentation) { |
| 1470 | ((FilterDualCamBasicRepresentation)representation).setPoint((int)mTmpPoint[0],(int)mTmpPoint[1]); |
| 1471 | } |
| 1472 | if (representation instanceof FilterDualCamFusionRepresentation) { |
| 1473 | ((FilterDualCamFusionRepresentation)representation).setPoint((int)mTmpPoint[0],(int)mTmpPoint[1]); |
| 1474 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1475 | } |
| 1476 | if (representation.getFilterType() == FilterRepresentation.TYPE_WATERMARK) { |
zhuw | fa5ddff | 2017-11-23 11:33:33 +0800 | [diff] [blame] | 1477 | if (MasterImage.getImage().getCurrentFilterRepresentation() != null |
| 1478 | && representation.getSerializationName().equals(MasterImage.getImage() |
| 1479 | .getCurrentFilterRepresentation().getSerializationName())) { |
| 1480 | return; |
| 1481 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1482 | showWaterMark(representation); |
| 1483 | } |
| 1484 | if (TrueScannerActs.SERIALIZATION_NAME.equals(representation.getSerializationName())) { |
| 1485 | Bitmap b = MasterImage.getImage().getOriginalBitmapHighres(); |
| 1486 | int w = b.getWidth(); |
| 1487 | int h = b.getHeight(); |
| 1488 | if (w < h) { |
| 1489 | w = h; |
| 1490 | h = b.getWidth(); |
| 1491 | } |
| 1492 | if (w <= TrueScannerActs.MIN_WIDTH |
| 1493 | || h <= TrueScannerActs.MIN_HEIGHT) { |
zhuw | 012ade8 | 2017-09-06 16:20:11 +0800 | [diff] [blame] | 1494 | Toast.makeText(this, getString(R.string.image_size_too_small), |
| 1495 | Toast.LENGTH_SHORT).show(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1496 | return; |
| 1497 | } |
| 1498 | } |
Ruben Brunk | b0f7a8f | 2013-07-18 16:37:30 -0700 | [diff] [blame] | 1499 | useFilterRepresentation(representation); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1500 | |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1501 | loadEditorPanel(representation); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1504 | private void showWaterMark(FilterRepresentation representation) { |
| 1505 | FilterWatermarkRepresentation watermarkRepresentation = |
| 1506 | (FilterWatermarkRepresentation)representation; |
| 1507 | if (mWaterMarkView != null) { |
| 1508 | rlImageContainer.removeView(mWaterMarkView); |
| 1509 | hasWaterMark = false; |
jinwu | 5a67407 | 2017-06-06 10:41:59 +0800 | [diff] [blame] | 1510 | watermarkRepresentation.reset(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1511 | } |
| 1512 | DisplayMetrics dm = getResources().getDisplayMetrics(); |
| 1513 | RelativeLayout.LayoutParams params = |
| 1514 | new RelativeLayout.LayoutParams(dm.widthPixels, |
| 1515 | dm.heightPixels); |
| 1516 | String textHint; |
| 1517 | switch (watermarkRepresentation.getMarkType()) { |
| 1518 | case 0: |
| 1519 | textHint = locationStr; |
| 1520 | break; |
| 1521 | case 2: |
| 1522 | textHint = temperature; |
| 1523 | break; |
| 1524 | default: |
| 1525 | textHint = watermarkRepresentation.getTextHint(); |
| 1526 | break; |
| 1527 | } |
| 1528 | WaterMarkView waterMarkView = watermarkRepresentation.getWaterMarkView(textHint); |
| 1529 | rlImageContainer.addView(waterMarkView, params); |
| 1530 | mWaterMarkView = waterMarkView; |
| 1531 | mSaveWaterMark.useRepresentation(representation); |
| 1532 | imgComparison.bringToFront(); |
| 1533 | mSaveWaterMark.getExifData(this, mSelectedImageUri); |
| 1534 | mWaterMarkView.mTouchable = true; |
| 1535 | hasWaterMark = true; |
| 1536 | } |
| 1537 | |
| 1538 | private void clearWaterMark() { |
| 1539 | if (mWaterMarkView != null) { |
| 1540 | rlImageContainer.removeView(mWaterMarkView); |
| 1541 | mWaterMarkView = null; |
| 1542 | hasWaterMark = false; |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | public void disableTouchEvent() { |
| 1547 | if (mWaterMarkView == null) return; |
| 1548 | mWaterMarkView.mTouchable = false; |
| 1549 | } |
| 1550 | |
| 1551 | public boolean isWaterMarked() { |
| 1552 | return hasWaterMark; |
| 1553 | } |
| 1554 | |
| 1555 | public SaveWaterMark getSaveWaterMark() { |
| 1556 | return mSaveWaterMark; |
| 1557 | } |
| 1558 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1559 | public Editor getEditor(int editorID) { |
| 1560 | return mEditorPlaceHolder.getEditor(editorID); |
| 1561 | } |
| 1562 | |
| 1563 | public void setCurrentPanel(int currentPanel) { |
| 1564 | mCurrentPanel = currentPanel; |
Chao Zhang | a731e09 | 2016-04-01 10:49:29 +0800 | [diff] [blame] | 1565 | if (mMasterImage == null) { |
| 1566 | return; |
| 1567 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1568 | HistoryManager adapter = mMasterImage.getHistory(); |
| 1569 | adapter.setActiveFilter(currentPanel); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | public int getCurrentPanel() { |
| 1573 | return mCurrentPanel; |
| 1574 | } |
| 1575 | |
nicolasroard | acc00f8 | 2013-06-25 16:32:01 -0700 | [diff] [blame] | 1576 | public void updateCategories() { |
nicolasroard | 26f23e6 | 2013-09-23 18:36:25 -0700 | [diff] [blame] | 1577 | if (mMasterImage == null) { |
| 1578 | return; |
| 1579 | } |
nicolasroard | acc00f8 | 2013-06-25 16:32:01 -0700 | [diff] [blame] | 1580 | ImagePreset preset = mMasterImage.getPreset(); |
| 1581 | mCategoryLooksAdapter.reflectImagePreset(preset); |
| 1582 | mCategoryBordersAdapter.reflectImagePreset(preset); |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 1583 | mCategoryFiltersAdapter.reflectImagePreset(preset); |
Likai Ding | 49eee1c | 2016-06-17 15:30:06 +0800 | [diff] [blame] | 1584 | if (mCategoryMakeupAdapter != null) { |
| 1585 | mCategoryMakeupAdapter.reflectImagePreset(preset); |
| 1586 | } |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 1587 | mCategoryDualCamAdapter.reflectImagePreset(preset); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1588 | mCategoryTruePortraitAdapter.reflectImagePreset(preset); |
nicolasroard | acc00f8 | 2013-06-25 16:32:01 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
nicolasroard | e799626 | 2013-08-13 16:29:11 -0700 | [diff] [blame] | 1591 | public View getMainStatePanelContainer(int id) { |
| 1592 | return findViewById(id); |
| 1593 | } |
| 1594 | |
John Hoford | 64fc2ed | 2013-10-09 13:54:45 -0700 | [diff] [blame] | 1595 | public void onShowMenu(PopupMenu menu) { |
| 1596 | mCurrentMenu = menu; |
| 1597 | menu.setOnDismissListener(this); |
| 1598 | } |
| 1599 | |
| 1600 | @Override |
| 1601 | public void onDismiss(PopupMenu popupMenu){ |
| 1602 | if (mCurrentMenu == null) { |
| 1603 | return; |
| 1604 | } |
| 1605 | mCurrentMenu.setOnDismissListener(null); |
| 1606 | mCurrentMenu = null; |
| 1607 | } |
| 1608 | |
John Hoford | 6125a08 | 2013-09-12 07:49:24 -0700 | [diff] [blame] | 1609 | @Override |
| 1610 | public void onShow(DialogInterface dialog) { |
| 1611 | mCurrentDialog = dialog; |
| 1612 | } |
| 1613 | |
| 1614 | @Override |
| 1615 | public void onDismiss(DialogInterface dialogInterface) { |
| 1616 | mCurrentDialog = null; |
| 1617 | } |
| 1618 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1619 | public void onMediaPickerStarted() { |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1620 | toggleComparisonButtonVisibility(); |
| 1621 | ActionBar actionBar = getActionBar(); |
| 1622 | actionBar.hide(); |
| 1623 | if (mMediaPicker == null) |
| 1624 | mMediaPicker = MediaPickerFragment.newInstance(getApplicationContext()); |
| 1625 | getSupportFragmentManager() |
| 1626 | .beginTransaction() |
| 1627 | .replace(R.id.main_panel_container, mMediaPicker) |
| 1628 | .commit(); |
| 1629 | } |
| 1630 | |
| 1631 | public void onMediaPickerResult(Uri selImg) { |
| 1632 | mFilterPresetSource = new FilterPresetSource(this); |
| 1633 | int id = nameFilter(mFilterPresetSource, tempFilterArray); |
| 1634 | FilterPresetRepresentation fp= new FilterPresetRepresentation( |
| 1635 | getString(R.string.filtershow_preset_title) + id, id, id); |
| 1636 | fp.setSerializationName("Custom"); |
| 1637 | fp.setUri(selImg); |
| 1638 | ImagePreset preset = new ImagePreset(); |
| 1639 | preset.addFilter(fp); |
| 1640 | SaveOption sp= new SaveOption(); |
| 1641 | sp._id = id; |
| 1642 | sp.name = "Custom" + id; |
| 1643 | sp.Uri = selImg.toString(); |
| 1644 | tempFilterArray.add(sp); |
| 1645 | FiltersManager.getManager().addRepresentation(fp); |
| 1646 | mCategoryLooksAdapter.add(new Action(this, fp, Action.FULL_VIEW, true)); |
| 1647 | useFilterRepresentation(fp); |
| 1648 | int pos = mCategoryLooksAdapter.getPositionOfPresentation(fp); |
| 1649 | if (pos != -1) |
| 1650 | backAndSetCustomFilterSelected(pos); |
| 1651 | } |
| 1652 | |
| 1653 | private void backAndSetCustomFilterSelected(int pos) { |
| 1654 | showComparisonButton(); |
| 1655 | removeSeekBarPanel(); |
| 1656 | showActionBar(true); |
| 1657 | loadMainPanel(); |
| 1658 | if(mEditorPlaceHolder != null) |
| 1659 | mEditorPlaceHolder.hide(); |
| 1660 | if(mImageShow != null) |
| 1661 | mImageShow.setVisibility(View.VISIBLE); |
| 1662 | updateCategories(); |
| 1663 | mCategoryLooksAdapter.setSelected(pos); |
| 1664 | } |
| 1665 | |
| 1666 | public void applyCustomFilterRepresentation( |
| 1667 | FilterRepresentation filterRep, FilterRepresentation oldfilterRep) { |
| 1668 | ImagePreset oldPreset = MasterImage.getImage().getPreset(); |
| 1669 | ImagePreset copy = new ImagePreset(oldPreset); |
| 1670 | if (oldfilterRep != null) |
| 1671 | copy.removeFilter(oldfilterRep); |
| 1672 | |
| 1673 | FilterRepresentation rep = copy.getRepresentation(filterRep); |
| 1674 | if (rep == null) { |
| 1675 | filterRep = filterRep.copy(); |
| 1676 | copy.addFilter(filterRep); |
| 1677 | } else { |
| 1678 | if (filterRep.allowsSingleInstanceOnly()) { |
| 1679 | // Don't just update the filter representation. Centralize the |
| 1680 | // logic in the addFilter(), such that we can keep "None" as |
| 1681 | // null. |
| 1682 | if (!rep.equals(filterRep)) { |
| 1683 | // Only do this if the filter isn't the same |
| 1684 | // (state panel clicks can lead us here) |
| 1685 | copy.removeFilter(rep); |
| 1686 | copy.addFilter(filterRep); |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | MasterImage.getImage().setPreset(copy, filterRep, false); |
| 1691 | } |
| 1692 | |
| 1693 | public FilterRepresentation createUserPresentaion(Uri selImg, int index) { |
| 1694 | FilterPresetRepresentation fp= new FilterPresetRepresentation( |
| 1695 | getString(R.string.filtershow_preset_title) + index, index, index); |
| 1696 | fp.setSerializationName("Custom"); |
| 1697 | fp.setUri(selImg); |
| 1698 | return fp; |
| 1699 | } |
| 1700 | |
| 1701 | public FilterRepresentation getCurrentPresentation() { |
| 1702 | ImagePreset preset = MasterImage.getImage().getPreset(); |
| 1703 | return preset.getLastRepresentation(); |
| 1704 | } |
| 1705 | |
nicolasroard | be84355 | 2013-07-02 15:02:43 -0700 | [diff] [blame] | 1706 | private class LoadHighresBitmapTask extends AsyncTask<Void, Void, Boolean> { |
| 1707 | @Override |
| 1708 | protected Boolean doInBackground(Void... params) { |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1709 | MasterImage master = MasterImage.getImage(); |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1710 | if (master.supportsHighRes()) { |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 1711 | int highresPreviewSize = Math.min(MasterImage.MAX_BITMAP_DIM, getScreenImageSize()); |
| 1712 | Log.d(LOGTAG, "FilterShowActivity.LoadHighresBitmapTask.doInBackground(): after, highresPreviewSize is " + highresPreviewSize); |
Ruben Brunk | 47886ac | 2013-07-12 17:23:39 -0700 | [diff] [blame] | 1713 | Rect bounds = new Rect(); |
| 1714 | Bitmap originalHires = ImageLoader.loadOrientedConstrainedBitmap(master.getUri(), |
| 1715 | master.getActivity(), highresPreviewSize, |
| 1716 | master.getOrientation(), bounds); |
Jay Wang | e099032 | 2016-06-28 13:29:26 -0700 | [diff] [blame] | 1717 | |
| 1718 | // Force the bitmap to even width and height which is required by beautification algo |
| 1719 | Bitmap tempBmp = MasterImage.convertToEvenNumberWidthImage(originalHires); |
| 1720 | if(tempBmp != null && originalHires != null) { |
| 1721 | if(!originalHires.isRecycled() && originalHires != tempBmp) { |
| 1722 | originalHires.recycle(); |
| 1723 | } |
| 1724 | originalHires = tempBmp; |
| 1725 | } |
| 1726 | |
Ruben Brunk | 47886ac | 2013-07-12 17:23:39 -0700 | [diff] [blame] | 1727 | master.setOriginalBounds(bounds); |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1728 | master.setOriginalBitmapHighres(originalHires); |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 1729 | Log.d(LOGTAG, "FilterShowActivity.LoadHighresBitmapTask.doInBackground(): originalHires.WH is (" + originalHires.getWidth() |
| 1730 | + ", " + originalHires.getHeight() +"), bounds is " + bounds.toString()); |
nicolasroard | db5d060 | 2013-07-19 14:45:32 -0700 | [diff] [blame] | 1731 | mBoundService.setOriginalBitmapHighres(originalHires); |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1732 | master.warnListeners(); |
| 1733 | } |
nicolasroard | be84355 | 2013-07-02 15:02:43 -0700 | [diff] [blame] | 1734 | return true; |
| 1735 | } |
| 1736 | |
| 1737 | @Override |
| 1738 | protected void onPostExecute(Boolean result) { |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1739 | Bitmap highresBitmap = MasterImage.getImage().getOriginalBitmapHighres(); |
nicolasroard | be84355 | 2013-07-02 15:02:43 -0700 | [diff] [blame] | 1740 | if (highresBitmap != null) { |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1741 | float highResPreviewScale = (float) highresBitmap.getWidth() |
| 1742 | / (float) MasterImage.getImage().getOriginalBounds().width(); |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 1743 | Log.d(LOGTAG, "FilterShowActivity.LoadHighresBitmapTask.onPostExecute(): highResPreviewScale is " + highResPreviewScale); |
nicolasroard | db5d060 | 2013-07-19 14:45:32 -0700 | [diff] [blame] | 1744 | mBoundService.setHighresPreviewScaleFactor(highResPreviewScale); |
nicolasroard | be84355 | 2013-07-02 15:02:43 -0700 | [diff] [blame] | 1745 | } |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 1746 | |
nicolasroard | 80b216d | 2013-08-28 14:00:06 -0700 | [diff] [blame] | 1747 | MasterImage.getImage().warnListeners(); |
nicolasroard | be84355 | 2013-07-02 15:02:43 -0700 | [diff] [blame] | 1748 | } |
| 1749 | } |
| 1750 | |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1751 | private class ParseDepthMapTask extends AsyncTask<Uri, Void, Boolean> { |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 1752 | @Override |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1753 | protected Boolean doInBackground(Uri... params) { |
| 1754 | return MasterImage.getImage().parseDepthMap(FilterShowActivity.this, params[0]); |
Byunghun Jeon | fa9e745 | 2015-11-13 11:33:57 -0800 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | @Override |
| 1758 | protected void onPostExecute(Boolean result) { |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1759 | showDualCameraButton(result); |
Byunghun Jeon | fa9e745 | 2015-11-13 11:33:57 -0800 | [diff] [blame] | 1760 | stopLoadingIndicator(); |
| 1761 | } |
| 1762 | } |
| 1763 | |
John Hoford | f7f24e8 | 2013-09-13 16:02:09 -0700 | [diff] [blame] | 1764 | public boolean isLoadingVisible() { |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1765 | if (mLoadingDialog != null) { |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 1766 | return mLoadingDialog.isShowing(); |
| 1767 | } |
| 1768 | |
| 1769 | return false; |
John Hoford | f7f24e8 | 2013-09-13 16:02:09 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | public void startLoadingIndicator() { |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 1773 | if(mLoadingDialog == null) { |
| 1774 | mLoadingDialog = new ProgressDialog(this); |
| 1775 | mLoadingDialog.setMessage(getString(R.string.loading_image)); |
| 1776 | mLoadingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 1777 | mLoadingDialog.setIndeterminate(true); |
| 1778 | mLoadingDialog.setCancelable(true); |
| 1779 | mLoadingDialog.setCanceledOnTouchOutside(false); |
| 1780 | mLoadingDialog.setOnCancelListener(new OnCancelListener() { |
| 1781 | @Override |
| 1782 | public void onCancel(DialogInterface dialog) { |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 1783 | done(); |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 1784 | } |
| 1785 | }); |
| 1786 | } |
| 1787 | |
| 1788 | mLoadingDialog.show(); |
John Hoford | f7f24e8 | 2013-09-13 16:02:09 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 1791 | public void stopLoadingIndicator() { |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1792 | if (mLoadingDialog != null && mLoadingDialog.isShowing()) { |
Byunghun Jeon | 863bd52 | 2015-11-02 17:20:55 -0800 | [diff] [blame] | 1793 | mLoadingDialog.dismiss(); |
| 1794 | } |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | private class LoadTruePortraitTask extends AsyncTask<Uri, Void, Boolean> { |
| 1798 | |
| 1799 | @Override |
| 1800 | protected Boolean doInBackground(Uri... params) { |
| 1801 | boolean result = false; |
| 1802 | Bitmap src = ImageLoader.loadBitmap(FilterShowActivity.this, params[0], null); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1803 | if(src == null) { |
| 1804 | return false; |
| 1805 | } |
jinwu | c9060a8 | 2017-04-28 15:41:13 +0800 | [diff] [blame] | 1806 | |
| 1807 | FaceInfo[] faceInfos = null; |
jinwu | d1e64f4 | 2017-08-09 14:24:06 +0800 | [diff] [blame] | 1808 | FaceDetect fDetect = new FaceDetect(); |
jinwu | c9060a8 | 2017-04-28 15:41:13 +0800 | [diff] [blame] | 1809 | if (fDetect.isLibLoaded()) { |
| 1810 | fDetect.initialize(); |
| 1811 | faceInfos = fDetect.dectectFeatures(src); |
| 1812 | fDetect.uninitialize(); |
| 1813 | } |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1814 | |
| 1815 | if(faceInfos != null && faceInfos.length > 0) { |
| 1816 | Rect[] faces = new Rect[faceInfos.length]; |
| 1817 | for(int i=0; i<faceInfos.length; i++) { |
| 1818 | faces[i] = faceInfos[i].face; |
| 1819 | } |
| 1820 | |
| 1821 | result = TruePortraitNativeEngine.getInstance().init(FilterShowActivity.this, src, faces); |
| 1822 | } else { |
| 1823 | TruePortraitNativeEngine.getInstance().setFacesDetected(false); |
| 1824 | } |
| 1825 | |
| 1826 | src.recycle(); |
| 1827 | src = null; |
| 1828 | |
| 1829 | return result; |
| 1830 | } |
| 1831 | |
| 1832 | @Override |
| 1833 | protected void onPostExecute(Boolean result) { |
| 1834 | } |
| 1835 | } |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 1836 | |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1837 | private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> { |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1838 | int mBitmapSize; |
| 1839 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1840 | public LoadBitmapTask() { |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1841 | mBitmapSize = getScreenImageSize(); |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 1842 | Log.d(LOGTAG, "FilterShowActivity.LoadBitmapTask(): mBitmapSize is " + mBitmapSize); |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | @Override |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1846 | protected Boolean doInBackground(Uri... params) { |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1847 | if (!MasterImage.getImage().loadBitmap(params[0], mBitmapSize)) { |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1848 | return false; |
| 1849 | } |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1850 | publishProgress(ImageLoader.queryLightCycle360(MasterImage.getImage().getActivity())); |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1851 | return true; |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | @Override |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1855 | protected void onProgressUpdate(Boolean... values) { |
John Reck | 00914f5 | 2012-10-25 10:08:37 -0700 | [diff] [blame] | 1856 | super.onProgressUpdate(values); |
Ruben Brunk | 6416dd5 | 2012-11-28 14:00:30 -0800 | [diff] [blame] | 1857 | if (isCancelled()) { |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1858 | return; |
Ruben Brunk | 6416dd5 | 2012-11-28 14:00:30 -0800 | [diff] [blame] | 1859 | } |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1860 | if (values[0]) { |
John Hoford | 5300e0c | 2013-03-04 17:50:58 -0800 | [diff] [blame] | 1861 | mShowingTinyPlanet = true; |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1862 | } |
John Reck | 00914f5 | 2012-10-25 10:08:37 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | @Override |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1866 | protected void onPostExecute(Boolean result) { |
Ruben Brunk | 69f5d8c | 2013-04-24 15:46:15 -0700 | [diff] [blame] | 1867 | MasterImage.setMaster(mMasterImage); |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1868 | if (isCancelled()) { |
| 1869 | return; |
| 1870 | } |
nicolasroard | 588c30c | 2013-02-08 14:06:33 -0800 | [diff] [blame] | 1871 | |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1872 | if (!result) { |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 1873 | if (mOriginalImageUri != null |
| 1874 | && !mOriginalImageUri.equals(mSelectedImageUri)) { |
John Hoford | 441d7a8 | 2013-08-20 15:37:37 -0700 | [diff] [blame] | 1875 | mOriginalImageUri = mSelectedImageUri; |
| 1876 | mOriginalPreset = null; |
| 1877 | Toast.makeText(FilterShowActivity.this, |
| 1878 | R.string.cannot_edit_original, Toast.LENGTH_SHORT).show(); |
| 1879 | startLoadBitmap(mOriginalImageUri); |
| 1880 | } else { |
| 1881 | cannotLoadImage(); |
| 1882 | } |
ztenghui | a08fab5 | 2013-07-22 14:06:22 -0700 | [diff] [blame] | 1883 | return; |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1884 | } |
Ruben Brunk | 8965d1f | 2012-12-03 12:18:56 -0800 | [diff] [blame] | 1885 | |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 1886 | if (null == CachingPipeline.getRenderScriptContext()) { |
| 1887 | Log.v(LOGTAG, "RenderScript context destroyed during load"); |
John Hoford | 52fa110 | 2013-06-11 13:07:15 -0700 | [diff] [blame] | 1888 | return; |
| 1889 | } |
nicolasroard | 733a013 | 2013-02-08 17:00:42 -0800 | [diff] [blame] | 1890 | final View imageShow = findViewById(R.id.imageShow); |
| 1891 | imageShow.setVisibility(View.VISIBLE); |
| 1892 | |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1893 | Bitmap largeBitmap = MasterImage.getImage().getOriginalBitmapLarge(); |
nicolasroard | db5d060 | 2013-07-19 14:45:32 -0700 | [diff] [blame] | 1894 | mBoundService.setOriginalBitmap(largeBitmap); |
| 1895 | |
Ruben Brunk | 0c1b4c6 | 2013-07-08 18:11:49 -0700 | [diff] [blame] | 1896 | float previewScale = (float) largeBitmap.getWidth() |
| 1897 | / (float) MasterImage.getImage().getOriginalBounds().width(); |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 1898 | Log.d(LOGTAG, "FilterShowActivity.LoadBitmapTask.onPostExecute(): previewScale is " + previewScale); |
nicolasroard | db5d060 | 2013-07-19 14:45:32 -0700 | [diff] [blame] | 1899 | mBoundService.setPreviewScaleFactor(previewScale); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1900 | if (!mShowingTinyPlanet) { |
| 1901 | mCategoryFiltersAdapter.removeTinyPlanet(); |
| 1902 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1903 | mCategoryLooksAdapter.imageLoaded(); |
| 1904 | mCategoryBordersAdapter.imageLoaded(); |
| 1905 | mCategoryGeometryAdapter.imageLoaded(); |
| 1906 | mCategoryFiltersAdapter.imageLoaded(); |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 1907 | mCategoryDualCamAdapter.imageLoaded(); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1908 | mCategoryTruePortraitAdapter.imageLoaded(); |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 1909 | if(mCategoryMakeupAdapter != null) { |
| 1910 | mCategoryMakeupAdapter.imageLoaded(); |
| 1911 | } |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1912 | mLoadBitmapTask = null; |
Ruben Brunk | ab779de | 2013-02-14 16:18:22 -0800 | [diff] [blame] | 1913 | |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 1914 | MasterImage.getImage().warnListeners(); |
| 1915 | loadActions(); |
| 1916 | |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 1917 | if (mOriginalPreset != null) { |
ztenghui | d2e9ea0 | 2013-06-24 13:54:04 -0700 | [diff] [blame] | 1918 | MasterImage.getImage().setLoadedPreset(mOriginalPreset); |
nicolasroard | ed60979 | 2013-06-26 16:56:31 -0700 | [diff] [blame] | 1919 | MasterImage.getImage().setPreset(mOriginalPreset, |
| 1920 | mOriginalPreset.getLastRepresentation(), true); |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 1921 | mOriginalPreset = null; |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 1922 | } else { |
| 1923 | setDefaultPreset(); |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 1924 | } |
nicolasroard | c7b38f3 | 2013-04-25 08:47:11 -0700 | [diff] [blame] | 1925 | |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 1926 | MasterImage.getImage().resetGeometryImages(true); |
| 1927 | |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 1928 | if (mAction.equals(TINY_PLANET_ACTION)) { |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 1929 | showRepresentation(mCategoryFiltersAdapter.getTinyPlanet()); |
Ruben Brunk | ab779de | 2013-02-14 16:18:22 -0800 | [diff] [blame] | 1930 | } |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 1931 | mHiResBitmapTask = new LoadHighresBitmapTask(); |
| 1932 | mHiResBitmapTask.execute(); |
nicolasroard | 80b216d | 2013-08-28 14:00:06 -0700 | [diff] [blame] | 1933 | MasterImage.getImage().warnListeners(); |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1934 | super.onPostExecute(result); |
| 1935 | } |
| 1936 | |
| 1937 | } |
| 1938 | |
Ruben Brunk | f07bb27 | 2013-03-11 12:00:06 -0700 | [diff] [blame] | 1939 | private void clearGalleryBitmapPool() { |
| 1940 | (new AsyncTask<Void, Void, Void>() { |
| 1941 | @Override |
| 1942 | protected Void doInBackground(Void... params) { |
| 1943 | // Free memory held in Gallery's Bitmap pool. May be O(n) for n bitmaps. |
| 1944 | GalleryBitmapPool.getInstance().clear(); |
| 1945 | return null; |
| 1946 | } |
| 1947 | }).execute(); |
| 1948 | } |
| 1949 | |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1950 | @Override |
| 1951 | protected void onDestroy() { |
John Reck | d49d532 | 2012-10-24 12:56:31 -0700 | [diff] [blame] | 1952 | if (mLoadBitmapTask != null) { |
| 1953 | mLoadBitmapTask.cancel(false); |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1954 | } |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 1955 | |
| 1956 | if(mHiResBitmapTask != null) { |
| 1957 | mHiResBitmapTask.cancel(false); |
| 1958 | } |
| 1959 | |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1960 | if(mParseDepthMapTask != null) { |
| 1961 | mParseDepthMapTask.cancel(false); |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 1962 | } |
| 1963 | |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 1964 | if(mLoadTruePortraitTask != null) { |
| 1965 | mLoadTruePortraitTask.cancel(false); |
| 1966 | } |
| 1967 | |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 1968 | mUserPresetsManager.close(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1969 | if (mFilterPresetSource !=null) { |
| 1970 | mFilterPresetSource.close(); |
| 1971 | } |
| 1972 | |
| 1973 | if (tempFilterArray != null) { |
| 1974 | tempFilterArray.clear(); |
| 1975 | } |
huiyan | 3de604e | 2016-04-27 15:28:45 +0800 | [diff] [blame] | 1976 | unregisterReceiver(mHandlerReceiver); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 1977 | doUnbindService(); |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1978 | if (mReleaseDualCam && DualCameraEffect.isSupported()) |
| 1979 | DualCameraEffect.getInstance().release(); |
John Hoford | 3d4f2c7 | 2012-10-23 17:14:35 -0700 | [diff] [blame] | 1980 | super.onDestroy(); |
| 1981 | } |
| 1982 | |
Ruben Brunk | 47886ac | 2013-07-12 17:23:39 -0700 | [diff] [blame] | 1983 | // TODO: find a more robust way of handling image size selection |
| 1984 | // for high screen densities. |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1985 | public int getScreenImageSize() { |
Ruben Brunk | 47886ac | 2013-07-12 17:23:39 -0700 | [diff] [blame] | 1986 | DisplayMetrics outMetrics = new DisplayMetrics(); |
| 1987 | getWindowManager().getDefaultDisplay().getMetrics(outMetrics); |
ztenghui | a08fab5 | 2013-07-22 14:06:22 -0700 | [diff] [blame] | 1988 | return Math.max(outMetrics.heightPixels, outMetrics.widthPixels); |
John Hoford | fafb2ed | 2012-10-11 12:55:05 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 1991 | private void showSavingProgress(String albumName) { |
Bobby Georgescu | ec29b73 | 2012-10-07 15:20:44 -0700 | [diff] [blame] | 1992 | ProgressDialog progress; |
| 1993 | if (mSavingProgressDialog != null) { |
| 1994 | progress = mSavingProgressDialog.get(); |
| 1995 | if (progress != null) { |
| 1996 | progress.show(); |
| 1997 | return; |
| 1998 | } |
| 1999 | } |
| 2000 | // TODO: Allow cancellation of the saving process |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 2001 | String progressText; |
| 2002 | if (albumName == null) { |
| 2003 | progressText = getString(R.string.saving_image); |
| 2004 | } else { |
| 2005 | progressText = getString(R.string.filtershow_saving_image, albumName); |
| 2006 | } |
| 2007 | progress = ProgressDialog.show(this, "", progressText, true, false); |
Bobby Georgescu | ec29b73 | 2012-10-07 15:20:44 -0700 | [diff] [blame] | 2008 | mSavingProgressDialog = new WeakReference<ProgressDialog>(progress); |
| 2009 | } |
| 2010 | |
| 2011 | private void hideSavingProgress() { |
| 2012 | if (mSavingProgressDialog != null) { |
| 2013 | ProgressDialog progress = mSavingProgressDialog.get(); |
nicolasroard | 08458dc | 2012-10-09 16:34:58 -0700 | [diff] [blame] | 2014 | if (progress != null) |
| 2015 | progress.dismiss(); |
Bobby Georgescu | ec29b73 | 2012-10-07 15:20:44 -0700 | [diff] [blame] | 2016 | } |
| 2017 | } |
| 2018 | |
jinwu | e99f722 | 2017-05-15 17:25:46 +0800 | [diff] [blame] | 2019 | public void completeSaveImage(Uri saveUri) { |
nicolasroard | 0ee91a2 | 2012-10-01 00:25:11 -0700 | [diff] [blame] | 2020 | if (mSharingImage && mSharedOutputFile != null) { |
| 2021 | // Image saved, we unblock the content provider |
| 2022 | Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, |
| 2023 | Uri.encode(mSharedOutputFile.getAbsolutePath())); |
| 2024 | ContentValues values = new ContentValues(); |
| 2025 | values.put(SharedImageProvider.PREPARE, false); |
| 2026 | getContentResolver().insert(uri, values); |
| 2027 | } |
| 2028 | setResult(RESULT_OK, new Intent().setData(saveUri)); |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 2029 | if (mReleaseDualCam && DualCameraEffect.isSupported()) { |
| 2030 | DualCameraEffect.getInstance().release(); |
jinwu | e99f722 | 2017-05-15 17:25:46 +0800 | [diff] [blame] | 2031 | mReleaseDualCam = false; |
| 2032 | } |
Bobby Georgescu | ec29b73 | 2012-10-07 15:20:44 -0700 | [diff] [blame] | 2033 | hideSavingProgress(); |
nicolasroard | 0ee91a2 | 2012-10-01 00:25:11 -0700 | [diff] [blame] | 2034 | finish(); |
| 2035 | } |
| 2036 | |
maxwen | d57f723 | 2016-06-04 22:51:06 +0200 | [diff] [blame] | 2037 | private boolean onShareTargetSelected() { |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 2038 | // First, let's tell the SharedImageProvider that it will need to wait |
| 2039 | // for the image |
nicolasroard | 0ee91a2 | 2012-10-01 00:25:11 -0700 | [diff] [blame] | 2040 | Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, |
| 2041 | Uri.encode(mSharedOutputFile.getAbsolutePath())); |
| 2042 | ContentValues values = new ContentValues(); |
| 2043 | values.put(SharedImageProvider.PREPARE, true); |
| 2044 | getContentResolver().insert(uri, values); |
| 2045 | mSharingImage = true; |
| 2046 | |
| 2047 | // Process and save the image in the background. |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 2048 | showSavingProgress(null); |
nicolasroard | 0ee91a2 | 2012-10-01 00:25:11 -0700 | [diff] [blame] | 2049 | mImageShow.saveImage(this, mSharedOutputFile); |
| 2050 | return true; |
| 2051 | } |
| 2052 | |
| 2053 | private Intent getDefaultShareIntent() { |
| 2054 | Intent intent = new Intent(Intent.ACTION_SEND); |
| 2055 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
| 2056 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 2057 | intent.setType(SharedImageProvider.MIME_TYPE); |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 2058 | mSharedOutputFile = SaveImage.getNewFile(this, MasterImage.getImage().getUri()); |
nicolasroard | 0ee91a2 | 2012-10-01 00:25:11 -0700 | [diff] [blame] | 2059 | Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, |
| 2060 | Uri.encode(mSharedOutputFile.getAbsolutePath())); |
| 2061 | intent.putExtra(Intent.EXTRA_STREAM, uri); |
| 2062 | return intent; |
| 2063 | } |
| 2064 | |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2065 | @Override |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2066 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2067 | menu.clear(); |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2068 | getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu); |
maxwen | d57f723 | 2016-06-04 22:51:06 +0200 | [diff] [blame] | 2069 | MenuItem item = menu.findItem(R.id.menu_share); |
| 2070 | if (item != null) { |
| 2071 | item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
| 2072 | @Override |
| 2073 | public boolean onMenuItemClick(MenuItem item) { |
| 2074 | final Intent shareIntent = getDefaultShareIntent(); |
| 2075 | onShareTargetSelected(); |
| 2076 | Intent intent = Intent.createChooser(shareIntent, null); |
| 2077 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2078 | FilterShowActivity.this.startActivity(intent); |
| 2079 | return true; |
| 2080 | } |
| 2081 | }); |
| 2082 | } |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 2083 | mMenu = menu; |
John Hoford | 46868d0 | 2013-09-12 14:16:50 -0700 | [diff] [blame] | 2084 | setupMenu(); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2085 | |
| 2086 | if(mCurrentEditor != null) { |
| 2087 | mCurrentEditor.onPrepareOptionsMenu(menu); |
| 2088 | } |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2089 | return true; |
| 2090 | } |
| 2091 | |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 2092 | private void setupMenu(){ |
John Hoford | 46868d0 | 2013-09-12 14:16:50 -0700 | [diff] [blame] | 2093 | if (mMenu == null || mMasterImage == null) { |
| 2094 | return; |
| 2095 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2096 | //MenuItem undoItem = mMenu.findItem(R.id.undoButton); |
| 2097 | //MenuItem redoItem = mMenu.findItem(R.id.redoButton); |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 2098 | MenuItem resetItem = mMenu.findItem(R.id.resetHistoryButton); |
maxwen | d57f723 | 2016-06-04 22:51:06 +0200 | [diff] [blame] | 2099 | MenuItem shareItem = mMenu.findItem(R.id.menu_share); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2100 | //mMasterImage.getHistory().setMenuItems(undoItem, redoItem, resetItem); |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 2101 | if (!mMasterImage.hasModifications()) { |
| 2102 | mMenu.removeItem(R.id.resetHistoryButton); |
| 2103 | } |
John Hoford | 3759b2d | 2013-09-10 16:59:23 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 2106 | @Override |
Bobby Georgescu | 6e733b7 | 2012-10-09 11:02:38 -0700 | [diff] [blame] | 2107 | public void onPause() { |
| 2108 | super.onPause(); |
Bobby Georgescu | 6e733b7 | 2012-10-09 11:02:38 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | @Override |
| 2112 | public void onResume() { |
| 2113 | super.onResume(); |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 2114 | if (SimpleMakeupImageFilter.HAS_TS_MAKEUP) { |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 2115 | MakeupEngine.getMakeupObj(); |
Zhang Zhenzhen | 38478f2 | 2015-03-10 16:40:13 +0800 | [diff] [blame] | 2116 | } |
Bobby Georgescu | 6e733b7 | 2012-10-09 11:02:38 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | @Override |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2120 | public boolean onOptionsItemSelected(MenuItem item) { |
| 2121 | switch (item.getItemId()) { |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2122 | /*case R.id.undoButton: { |
nicolasroard | 6a50273 | 2013-06-27 14:41:58 -0700 | [diff] [blame] | 2123 | HistoryManager adapter = mMasterImage.getHistory(); |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2124 | int position = adapter.undo(); |
John Hoford | 63a7dac | 2013-01-14 14:48:39 -0800 | [diff] [blame] | 2125 | mMasterImage.onHistoryItemClick(position); |
John Hoford | a7a6a3a | 2013-05-22 15:41:20 -0700 | [diff] [blame] | 2126 | backToMain(); |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2127 | invalidateViews(); |
| 2128 | return true; |
| 2129 | } |
| 2130 | case R.id.redoButton: { |
nicolasroard | 6a50273 | 2013-06-27 14:41:58 -0700 | [diff] [blame] | 2131 | HistoryManager adapter = mMasterImage.getHistory(); |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2132 | int position = adapter.redo(); |
John Hoford | 63a7dac | 2013-01-14 14:48:39 -0800 | [diff] [blame] | 2133 | mMasterImage.onHistoryItemClick(position); |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2134 | invalidateViews(); |
| 2135 | return true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2136 | }*/ |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2137 | case R.id.resetHistoryButton: { |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2138 | clearWaterMark(); |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2139 | resetHistory(); |
| 2140 | return true; |
| 2141 | } |
| 2142 | /*case R.id.showImageStateButton: { |
nicolasroard | bf93da7 | 2012-09-29 00:17:09 -0700 | [diff] [blame] | 2143 | toggleImageStatePanel(); |
| 2144 | return true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2145 | }*/ |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2146 | case R.id.exportFlattenButton: { |
| 2147 | showExportOptionsDialog(); |
| 2148 | return true; |
| 2149 | } |
| 2150 | case android.R.id.home: { |
| 2151 | saveImage(); |
| 2152 | return true; |
| 2153 | } |
| 2154 | case R.id.manageUserPresets: { |
| 2155 | manageUserPresets(); |
| 2156 | return true; |
| 2157 | } |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2158 | } |
| 2159 | return false; |
| 2160 | } |
| 2161 | |
nicolasroard | 9c5d670 | 2013-08-16 14:06:43 -0700 | [diff] [blame] | 2162 | public void print() { |
| 2163 | Bitmap bitmap = MasterImage.getImage().getHighresImage(); |
Svetoslav Ganov | 391e4a1 | 2013-10-06 20:03:32 -0700 | [diff] [blame] | 2164 | PrintHelper printer = new PrintHelper(this); |
junjiez | 2e52436 | 2018-09-11 11:04:46 +0800 | [diff] [blame] | 2165 | try { |
| 2166 | printer.printBitmap("ImagePrint", bitmap); |
| 2167 | } catch (RuntimeException e) { |
| 2168 | Log.e(LOGTAG,"Print failure,",e); |
| 2169 | } |
nicolasroard | 9c5d670 | 2013-08-16 14:06:43 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
jinwu | f23224f | 2017-06-19 11:16:06 +0800 | [diff] [blame] | 2172 | private void manageUserPresets() { |
| 2173 | if (mPresetDialog == null) { |
| 2174 | mPresetDialog = new PresetManagementDialog(); |
| 2175 | mPresetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
| 2176 | @Override |
| 2177 | public void onDismiss(DialogInterface dialog) { |
| 2178 | mPresetDialog = null; |
| 2179 | } |
| 2180 | }); |
| 2181 | mPresetDialog.show(getSupportFragmentManager(), "NoticeDialogFragment"); |
| 2182 | } |
| 2183 | } |
| 2184 | |
nicolasroard | 55a0279 | 2013-08-13 17:36:00 -0700 | [diff] [blame] | 2185 | public void addNewPreset() { |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2186 | boolean skipIntro = GalleryUtils.getBooleanPref(this, |
| 2187 | this.getString(R.string.pref_filtergenerator_intro_show_key), false); |
| 2188 | if (!skipIntro) { |
jinwu | f23224f | 2017-06-19 11:16:06 +0800 | [diff] [blame] | 2189 | manageUserPresets(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2190 | } else { |
| 2191 | onMediaPickerStarted(); |
| 2192 | } |
nicolasroard | 55a0279 | 2013-08-13 17:36:00 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Ruben Brunk | 077e718 | 2013-08-01 19:05:18 -0700 | [diff] [blame] | 2195 | private void showExportOptionsDialog() { |
| 2196 | DialogFragment dialog = new ExportDialog(); |
| 2197 | dialog.show(getSupportFragmentManager(), "ExportDialogFragment"); |
| 2198 | } |
| 2199 | |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2200 | public void updateUserPresetsFromAdapter(UserPresetsAdapter adapter) { |
| 2201 | ArrayList<FilterUserPresetRepresentation> representations = |
| 2202 | adapter.getDeletedRepresentations(); |
| 2203 | for (FilterUserPresetRepresentation representation : representations) { |
| 2204 | deletePreset(representation.getId()); |
| 2205 | } |
| 2206 | ArrayList<FilterUserPresetRepresentation> changedRepresentations = |
| 2207 | adapter.getChangedRepresentations(); |
| 2208 | for (FilterUserPresetRepresentation representation : changedRepresentations) { |
| 2209 | updatePreset(representation); |
| 2210 | } |
| 2211 | adapter.clearDeletedRepresentations(); |
| 2212 | adapter.clearChangedRepresentations(); |
| 2213 | loadUserPresets(); |
| 2214 | } |
| 2215 | |
| 2216 | public void loadUserPresets() { |
| 2217 | mUserPresetsManager.load(); |
nicolasroard | 5af55f4 | 2013-08-14 10:34:08 -0700 | [diff] [blame] | 2218 | updateUserPresetsFromManager(); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | public void updateUserPresetsFromManager() { |
| 2222 | ArrayList<FilterUserPresetRepresentation> presets = mUserPresetsManager.getRepresentations(); |
| 2223 | if (presets == null) { |
| 2224 | return; |
| 2225 | } |
| 2226 | if (mCategoryLooksAdapter != null) { |
| 2227 | fillLooks(); |
| 2228 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2229 | /* if (presets.size() > 0) { |
nicolasroard | 55a0279 | 2013-08-13 17:36:00 -0700 | [diff] [blame] | 2230 | mCategoryLooksAdapter.add(new Action(this, Action.SPACER)); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2231 | } */ |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2232 | mUserPresetsAdapter.clear(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2233 | if (presets.size() > 0) { |
| 2234 | mCategoryLooksAdapter.add(new Action(this, Action.ADD_ACTION)); |
| 2235 | } |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2236 | for (int i = 0; i < presets.size(); i++) { |
| 2237 | FilterUserPresetRepresentation representation = presets.get(i); |
| 2238 | mCategoryLooksAdapter.add( |
nicolasroard | 0a24e52 | 2013-08-14 10:04:37 -0700 | [diff] [blame] | 2239 | new Action(this, representation, Action.FULL_VIEW, true)); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2240 | mUserPresetsAdapter.add(new Action(this, representation, Action.FULL_VIEW)); |
| 2241 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2242 | |
nicolasroard | 5af55f4 | 2013-08-14 10:34:08 -0700 | [diff] [blame] | 2243 | mCategoryLooksAdapter.notifyDataSetChanged(); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2244 | mCategoryLooksAdapter.notifyDataSetInvalidated(); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
nicolasroard | 0a24e52 | 2013-08-14 10:04:37 -0700 | [diff] [blame] | 2247 | public void saveCurrentImagePreset(String name) { |
| 2248 | mUserPresetsManager.save(MasterImage.getImage().getPreset(), name); |
nicolasroard | fa474a1 | 2013-07-15 11:24:36 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | private void deletePreset(int id) { |
| 2252 | mUserPresetsManager.delete(id); |
| 2253 | } |
| 2254 | |
| 2255 | private void updatePreset(FilterUserPresetRepresentation representation) { |
| 2256 | mUserPresetsManager.update(representation); |
| 2257 | } |
| 2258 | |
Doris Liu | bf1677a | 2012-10-29 13:11:10 -0700 | [diff] [blame] | 2259 | public void enableSave(boolean enable) { |
ztenghui | 545eca1 | 2013-06-28 09:25:23 -0700 | [diff] [blame] | 2260 | if (mSaveButton != null) { |
Doris Liu | bf1677a | 2012-10-29 13:11:10 -0700 | [diff] [blame] | 2261 | mSaveButton.setEnabled(enable); |
ztenghui | 545eca1 | 2013-06-28 09:25:23 -0700 | [diff] [blame] | 2262 | } |
Doris Liu | bf1677a | 2012-10-29 13:11:10 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 2265 | private void fillLooks() { |
| 2266 | FiltersManager filtersManager = FiltersManager.getManager(); |
| 2267 | ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getLooks(); |
nicolasroard | f607604 | 2013-02-12 12:19:19 -0800 | [diff] [blame] | 2268 | |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 2269 | if (mCategoryLooksAdapter != null) { |
| 2270 | mCategoryLooksAdapter.clear(); |
| 2271 | } |
nicolasroard | 1a1cb07 | 2013-08-10 17:23:38 -0700 | [diff] [blame] | 2272 | mCategoryLooksAdapter = new CategoryAdapter(this); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2273 | int verticalItemHeight = (int) getResources().getDimension(R.dimen.action_item_height); |
| 2274 | mCategoryLooksAdapter.setItemHeight(verticalItemHeight); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2275 | for (FilterRepresentation representation : filtersRepresentations) { |
| 2276 | mCategoryLooksAdapter.add(new Action(this, representation, Action.FULL_VIEW)); |
| 2277 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2278 | if (FilterGeneratorNativeEngine.getInstance().isLibLoaded()) { |
| 2279 | if (mUserPresetsManager.getRepresentations() == null |
| 2280 | || mUserPresetsManager.getRepresentations().size() == 0) { |
| 2281 | mCategoryLooksAdapter.add(new Action(this, Action.ADD_ACTION)); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | fillPresetFilter(); |
nicolasroard | 5af55f4 | 2013-08-14 10:34:08 -0700 | [diff] [blame] | 2286 | |
| 2287 | Fragment panel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 2288 | if (panel != null) { |
| 2289 | if (panel instanceof MainPanel) { |
| 2290 | MainPanel mainPanel = (MainPanel) panel; |
| 2291 | mainPanel.loadCategoryLookPanel(true); |
| 2292 | } |
| 2293 | } |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 2294 | } |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2295 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 2296 | public void setDefaultPreset() { |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2297 | // Default preset (original) |
nicolasroard | ed60979 | 2013-06-26 16:56:31 -0700 | [diff] [blame] | 2298 | ImagePreset preset = new ImagePreset(); // empty |
nicolasroard | ed60979 | 2013-06-26 16:56:31 -0700 | [diff] [blame] | 2299 | mMasterImage.setPreset(preset, preset.getLastRepresentation(), true); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2302 | // ////////////////////////////////////////////////////////////////////////////// |
| 2303 | // Some utility functions |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 2304 | // TODO: finish the cleanup. |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2305 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2306 | public void invalidateViews() { |
| 2307 | for (ImageShow views : mImageViews) { |
Ruben Brunk | 8537d09 | 2012-09-27 12:38:08 -0700 | [diff] [blame] | 2308 | views.updateImage(); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2309 | } |
| 2310 | } |
| 2311 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2312 | public void hideImageViews() { |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2313 | for (View view : mImageViews) { |
| 2314 | view.setVisibility(View.GONE); |
| 2315 | } |
nicolasroard | 5b85b09 | 2013-02-05 13:43:45 -0800 | [diff] [blame] | 2316 | mEditorPlaceHolder.hide(); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2319 | // ////////////////////////////////////////////////////////////////////////////// |
nicolasroard | bf93da7 | 2012-09-29 00:17:09 -0700 | [diff] [blame] | 2320 | // imageState panel... |
| 2321 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2322 | public void toggleImageStatePanel() { |
nicolasroard | bf93da7 | 2012-09-29 00:17:09 -0700 | [diff] [blame] | 2323 | invalidateOptionsMenu(); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2324 | mShowingImageStatePanel = !mShowingImageStatePanel; |
| 2325 | Fragment panel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 2326 | if (panel != null) { |
| 2327 | if (panel instanceof EditorPanel) { |
| 2328 | EditorPanel editorPanel = (EditorPanel) panel; |
| 2329 | editorPanel.showImageStatePanel(mShowingImageStatePanel); |
| 2330 | } else if (panel instanceof MainPanel) { |
| 2331 | MainPanel mainPanel = (MainPanel) panel; |
| 2332 | mainPanel.showImageStatePanel(mShowingImageStatePanel); |
| 2333 | } |
nicolasroard | fb6a8e1 | 2013-04-15 14:41:00 -0700 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2337 | public void toggleVersionsPanel() { |
| 2338 | mShowingVersionsPanel = !mShowingVersionsPanel; |
| 2339 | Fragment panel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 2340 | if (panel != null && panel instanceof MainPanel) { |
| 2341 | MainPanel mainPanel = (MainPanel) panel; |
| 2342 | mainPanel.loadCategoryVersionsPanel(); |
| 2343 | } |
| 2344 | } |
| 2345 | |
nicolasroard | a9bc8ef | 2012-10-23 14:09:53 -0700 | [diff] [blame] | 2346 | @Override |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2347 | public void onConfigurationChanged(Configuration newConfig) { |
nicolasroard | a9bc8ef | 2012-10-23 14:09:53 -0700 | [diff] [blame] | 2348 | super.onConfigurationChanged(newConfig); |
John Hoford | f7f24e8 | 2013-09-13 16:02:09 -0700 | [diff] [blame] | 2349 | |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 2350 | setDefaultValues(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2351 | if (mOrientation != newConfig.orientation) { |
| 2352 | TrueScannerActs.setRotating(true); |
| 2353 | mOrientation = newConfig.orientation; |
| 2354 | } |
| 2355 | switch (newConfig.orientation) { |
| 2356 | case (Configuration.ORIENTATION_LANDSCAPE): |
| 2357 | if (mPresetDialog != null) { |
jinwu | 3721f9b | 2017-08-23 15:26:32 +0800 | [diff] [blame] | 2358 | mPresetDialog.setDismissFlag(false); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2359 | mPresetDialog.dismiss(); |
| 2360 | mPresetDialog.show(getSupportFragmentManager(), "NoticeDialogFragment"); |
| 2361 | } |
| 2362 | break; |
| 2363 | case (Configuration.ORIENTATION_PORTRAIT): |
| 2364 | if (mPresetDialog != null) { |
jinwu | 3721f9b | 2017-08-23 15:26:32 +0800 | [diff] [blame] | 2365 | mPresetDialog.setDismissFlag(false); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2366 | mPresetDialog.dismiss(); |
| 2367 | mPresetDialog.show(getSupportFragmentManager(), "NoticeDialogFragment"); |
| 2368 | } |
| 2369 | break; |
| 2370 | } |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 2371 | if (isShowEditCropPanel()) { |
| 2372 | mIsReloadByConfigurationChanged = true; |
| 2373 | loadEditorCropPanel(); |
| 2374 | } |
John Hoford | f7f24e8 | 2013-09-13 16:02:09 -0700 | [diff] [blame] | 2375 | if (mMasterImage == null) { |
| 2376 | return; |
| 2377 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2378 | //loadXML(); |
| 2379 | //fillCategories(); |
| 2380 | //loadMainPanel(); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2381 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2382 | if (isWaterMarked()) { |
| 2383 | DisplayMetrics dm = getResources().getDisplayMetrics(); |
| 2384 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(dm.widthPixels, |
| 2385 | dm.heightPixels); |
| 2386 | rlImageContainer.updateViewLayout(mWaterMarkView, params); |
| 2387 | } |
John Hoford | 64fc2ed | 2013-10-09 13:54:45 -0700 | [diff] [blame] | 2388 | if (mCurrentMenu != null) { |
| 2389 | mCurrentMenu.dismiss(); |
| 2390 | mCurrentMenu = null; |
| 2391 | } |
John Hoford | 6125a08 | 2013-09-12 07:49:24 -0700 | [diff] [blame] | 2392 | if (mCurrentDialog != null) { |
| 2393 | mCurrentDialog.dismiss(); |
| 2394 | mCurrentDialog = null; |
| 2395 | } |
John Hoford | f57e588 | 2013-05-20 18:24:12 -0700 | [diff] [blame] | 2396 | // mLoadBitmapTask==null implies you have looked at the intent |
| 2397 | if (!mShowingTinyPlanet && (mLoadBitmapTask == null)) { |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2398 | mCategoryFiltersAdapter.removeTinyPlanet(); |
John Hoford | 5300e0c | 2013-03-04 17:50:58 -0800 | [diff] [blame] | 2399 | } |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 2400 | stopLoadingIndicator(); |
nicolasroard | a9bc8ef | 2012-10-23 14:09:53 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
John Hoford | 63a7dac | 2013-01-14 14:48:39 -0800 | [diff] [blame] | 2403 | public void setupMasterImage() { |
nicolasroard | 3a5556d | 2013-02-28 12:11:35 -0800 | [diff] [blame] | 2404 | |
nicolasroard | ffc6aea | 2013-07-10 16:14:51 -0700 | [diff] [blame] | 2405 | HistoryManager historyManager = new HistoryManager(); |
| 2406 | StateAdapter imageStateAdapter = new StateAdapter(this, 0); |
Jay Wang | 8f0f5c0 | 2015-11-06 14:35:17 -0800 | [diff] [blame] | 2407 | MasterImage.setMaster(null); |
nicolasroard | 588c30c | 2013-02-08 14:06:33 -0800 | [diff] [blame] | 2408 | mMasterImage = MasterImage.getImage(); |
nicolasroard | ffc6aea | 2013-07-10 16:14:51 -0700 | [diff] [blame] | 2409 | mMasterImage.setHistoryManager(historyManager); |
| 2410 | mMasterImage.setStateAdapter(imageStateAdapter); |
John Hoford | 63a7dac | 2013-01-14 14:48:39 -0800 | [diff] [blame] | 2411 | mMasterImage.setActivity(this); |
nicolasroard | 4dad1a9 | 2013-03-29 14:41:38 -0700 | [diff] [blame] | 2412 | |
| 2413 | if (Runtime.getRuntime().maxMemory() > LIMIT_SUPPORTS_HIGHRES) { |
| 2414 | mMasterImage.setSupportsHighRes(true); |
| 2415 | } else { |
| 2416 | mMasterImage.setSupportsHighRes(false); |
| 2417 | } |
John Hoford | 63a7dac | 2013-01-14 14:48:39 -0800 | [diff] [blame] | 2418 | } |
| 2419 | |
Ruben Brunk | 2e1a644 | 2012-12-19 10:47:49 -0800 | [diff] [blame] | 2420 | void resetHistory() { |
wqi | 794da4e | 2016-06-02 15:47:02 +0800 | [diff] [blame] | 2421 | if (mMasterImage == null) { |
| 2422 | return; |
| 2423 | } |
nicolasroard | 6a50273 | 2013-06-27 14:41:58 -0700 | [diff] [blame] | 2424 | HistoryManager adapter = mMasterImage.getHistory(); |
nicolasroard | 9594c8d | 2012-09-27 20:54:48 -0700 | [diff] [blame] | 2425 | adapter.reset(); |
nicolasroard | ed60979 | 2013-06-26 16:56:31 -0700 | [diff] [blame] | 2426 | HistoryItem historyItem = adapter.getItem(0); |
nicolasroard | 32646aa | 2013-09-20 19:00:33 -0700 | [diff] [blame] | 2427 | ImagePreset original = null; |
jinwu | 5487ffb | 2017-09-04 16:07:25 +0800 | [diff] [blame] | 2428 | original = new ImagePreset(); |
nicolasroard | 32646aa | 2013-09-20 19:00:33 -0700 | [diff] [blame] | 2429 | FilterRepresentation rep = null; |
| 2430 | if (historyItem != null) { |
| 2431 | rep = historyItem.getFilterRepresentation(); |
| 2432 | } |
| 2433 | mMasterImage.setPreset(original, rep, true); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2434 | mMasterImage.setFusionUnderlay(null); |
| 2435 | mMasterImage.resetTranslation(); |
| 2436 | mMasterImage.setScaleFactor(1); |
zhuw | 1360a25 | 2017-09-18 09:57:04 +0800 | [diff] [blame] | 2437 | mMasterImage.setCurrentFilterRepresentation(null); |
zhuw | d1776b2 | 2017-09-18 09:52:59 +0800 | [diff] [blame] | 2438 | ArrayList<FilterRepresentation> frList = FiltersManager.getManager().getTools(); |
| 2439 | for (FilterRepresentation fr : frList) { |
| 2440 | if (fr instanceof FilterRotateRepresentation) { |
| 2441 | ((FilterRotateRepresentation) fr).resetRotation(); |
| 2442 | } |
| 2443 | } |
jinwu | 5487ffb | 2017-09-04 16:07:25 +0800 | [diff] [blame] | 2444 | showDefaultImageView(); |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 2445 | showSaveButtonIfNeed(); |
jinwu | 5487ffb | 2017-09-04 16:07:25 +0800 | [diff] [blame] | 2446 | invalidateViews(); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2449 | public void showDefaultImageView() { |
Jack Yoo | 66d2144 | 2015-10-27 16:27:49 -0700 | [diff] [blame] | 2450 | if(mEditorPlaceHolder != null) |
| 2451 | mEditorPlaceHolder.hide(); |
| 2452 | if(mImageShow != null) |
| 2453 | mImageShow.setVisibility(View.VISIBLE); |
| 2454 | if(MasterImage.getImage() != null) { |
| 2455 | MasterImage.getImage().setCurrentFilter(null); |
| 2456 | MasterImage.getImage().setCurrentFilterRepresentation(null); |
| 2457 | } |
zhuw | abf3079 | 2018-04-20 17:18:03 +0800 | [diff] [blame] | 2458 | showWatermarkButton(true); |
| 2459 | } |
| 2460 | |
| 2461 | private void showWatermarkButton(boolean visible) { |
| 2462 | Fragment currentPanel = getSupportFragmentManager() |
| 2463 | .findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 2464 | if (currentPanel instanceof MainPanel) { |
| 2465 | ((MainPanel) currentPanel).showWatermarkButton(visible); |
| 2466 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | public void backToMain() { |
Chao Zhang | 80516ca | 2016-04-25 15:37:33 +0800 | [diff] [blame] | 2470 | removeSeekBarPanel(); |
Chao Zhang | 9c0d475 | 2016-04-14 18:04:44 +0800 | [diff] [blame] | 2471 | showActionBar(true); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2472 | Fragment currentPanel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); |
| 2473 | if (currentPanel instanceof MainPanel) { |
| 2474 | return; |
| 2475 | } |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 2476 | mIsReloadByConfigurationChanged = false; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2477 | loadMainPanel(); |
| 2478 | showDefaultImageView(); |
Chao Zhang | 4dbacef | 2016-04-20 11:08:03 +0800 | [diff] [blame] | 2479 | showComparisonButton(); |
| 2480 | } |
| 2481 | |
| 2482 | private void showComparisonButton() { |
| 2483 | if (imgComparison != null && imgComparison.getVisibility() == View.GONE) { |
| 2484 | imgComparison.setVisibility(View.VISIBLE); |
| 2485 | } |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
nicolasroard | 7560816 | 2012-10-12 00:18:51 -0700 | [diff] [blame] | 2488 | @Override |
| 2489 | public void onBackPressed() { |
Chao Zhang | 4dbacef | 2016-04-20 11:08:03 +0800 | [diff] [blame] | 2490 | showComparisonButton(); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 2491 | Fragment currentPanel = getSupportFragmentManager().findFragmentByTag( |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2492 | MainPanel.FRAGMENT_TAG); |
| 2493 | |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2494 | if (currentPanel instanceof MainPanel) { |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 2495 | if (mImageShow.hasModifications()) { |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 2496 | if (mBackAlertDialogBuilder == null) { |
| 2497 | createBackDialog(); |
| 2498 | } |
| 2499 | mBackAlertDialogBuilder.show(); |
Ruben Brunk | a3dbbd7 | 2013-03-29 12:36:30 -0700 | [diff] [blame] | 2500 | } else { |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 2501 | done(); |
Ruben Brunk | a3dbbd7 | 2013-03-29 12:36:30 -0700 | [diff] [blame] | 2502 | } |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 2503 | setActionBar(); |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 2504 | invalidateOptionsMenu(); |
| 2505 | if (MasterImage.getImage().getScaleFactor() < 1) |
| 2506 | setScaleImage(false); |
| 2507 | adjustCompareButton(false); |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2508 | } else { |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2509 | isComingFromEditorScreen = true; |
nicolasroard | f5eedf1 | 2013-04-19 17:13:30 -0700 | [diff] [blame] | 2510 | backToMain(); |
nicolasroard | 7560816 | 2012-10-12 00:18:51 -0700 | [diff] [blame] | 2511 | } |
| 2512 | } |
nicolasroard | e34a5a5 | 2012-10-16 14:25:09 -0700 | [diff] [blame] | 2513 | |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 2514 | private void createBackDialog() { |
| 2515 | mBackAlertDialogBuilder = new AlertDialog.Builder(this); |
Michael Bestas | f4f030b | 2016-06-07 00:06:53 +0300 | [diff] [blame] | 2516 | mBackAlertDialogBuilder.setMessage(R.string.discard_message).setTitle( |
| 2517 | R.string.discard_title); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 2518 | mBackAlertDialogBuilder.setPositiveButton(mPopUpText, |
| 2519 | new DialogInterface.OnClickListener() { |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2520 | @Override |
| 2521 | public void onClick(DialogInterface dialog, int id) { |
| 2522 | done(); |
| 2523 | } |
| 2524 | }); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 2525 | mBackAlertDialogBuilder.setNegativeButton(mCancel, |
| 2526 | new DialogInterface.OnClickListener() { |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2527 | @Override |
| 2528 | public void onClick(DialogInterface dialog, int id) { |
| 2529 | dialog.dismiss(); |
| 2530 | } |
| 2531 | }); |
wqi | 0705537 | 2016-04-13 09:57:51 +0800 | [diff] [blame] | 2532 | } |
| 2533 | |
nicolasroard | e34a5a5 | 2012-10-16 14:25:09 -0700 | [diff] [blame] | 2534 | public void cannotLoadImage() { |
Ruben Brunk | a2c4bda | 2013-05-29 11:18:31 -0700 | [diff] [blame] | 2535 | Toast.makeText(this, R.string.cannot_load_image, Toast.LENGTH_SHORT).show(); |
nicolasroard | e34a5a5 | 2012-10-16 14:25:09 -0700 | [diff] [blame] | 2536 | finish(); |
| 2537 | } |
| 2538 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2539 | // ////////////////////////////////////////////////////////////////////////////// |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2540 | |
| 2541 | public float getPixelsFromDip(float value) { |
| 2542 | Resources r = getResources(); |
| 2543 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, |
| 2544 | r.getDisplayMetrics()); |
| 2545 | } |
| 2546 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2547 | @Override |
| 2548 | public void onItemClick(AdapterView<?> parent, View view, int position, |
| 2549 | long id) { |
John Hoford | 63a7dac | 2013-01-14 14:48:39 -0800 | [diff] [blame] | 2550 | mMasterImage.onHistoryItemClick(position); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2551 | invalidateViews(); |
| 2552 | } |
| 2553 | |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 2554 | public void pickImage(int requestCode) { |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2555 | Intent intent = new Intent(); |
| 2556 | intent.setType("image/*"); |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 2557 | intent.setAction(Intent.ACTION_PICK); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2558 | startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)), |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 2559 | requestCode); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
nicolasroard | 92e2341 | 2012-10-05 03:48:34 -0700 | [diff] [blame] | 2562 | @Override |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2563 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2564 | if (resultCode == RESULT_OK) { |
| 2565 | if (requestCode == SELECT_PICTURE) { |
| 2566 | Uri selectedImageUri = data.getData(); |
zhuw | a674df5 | 2018-01-30 13:49:15 +0800 | [diff] [blame] | 2567 | if (selectedImageUri != null) { |
| 2568 | startLoadBitmap(selectedImageUri); |
| 2569 | } |
Byunghun Jeon | 8ea62fb | 2015-08-03 16:50:11 -0700 | [diff] [blame] | 2570 | } else if (requestCode == SELECT_FUSION_UNDERLAY) { |
| 2571 | Uri underlayImageUri = data.getData(); |
| 2572 | // find fusion representation |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2573 | if(mCurrentEditor instanceof EditorDualCamFusion) { |
| 2574 | EditorDualCamFusion editor = (EditorDualCamFusion)mCurrentEditor; |
| 2575 | editor.setUnderlayImageUri(underlayImageUri); |
| 2576 | } else if (mCurrentEditor instanceof EditorTruePortraitFusion) { |
zhuw | f4f10df | 2017-09-18 09:23:03 +0800 | [diff] [blame] | 2577 | if (checkExtensionValidity(this, underlayImageUri)) { |
| 2578 | Toast.makeText(getApplicationContext(), getString(R.string.not_support_gif), |
| 2579 | Toast.LENGTH_SHORT).show(); |
| 2580 | pickImage(SELECT_FUSION_UNDERLAY); |
| 2581 | } else { |
| 2582 | EditorTruePortraitFusion editor = (EditorTruePortraitFusion)mCurrentEditor; |
| 2583 | editor.setUnderlayImageUri(underlayImageUri); |
| 2584 | } |
Jay Wang | f19b070 | 2016-06-09 12:49:49 -0700 | [diff] [blame] | 2585 | } |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2586 | } |
| 2587 | } |
| 2588 | } |
| 2589 | |
zhuw | f4f10df | 2017-09-18 09:23:03 +0800 | [diff] [blame] | 2590 | /** |
| 2591 | * check whether the extension of the given uri is supported to be underlay |
| 2592 | * @param context context for get ContentResolver |
| 2593 | * @param uri uri need to check |
| 2594 | * @return validity of uri's extension, true means unsupported, false means supported |
| 2595 | */ |
| 2596 | private boolean checkExtensionValidity(final Context context, final Uri uri) { |
| 2597 | if (uri == null) { |
| 2598 | return false; |
| 2599 | } |
| 2600 | // get file path from uri |
| 2601 | String filePath = null; |
| 2602 | final String scheme = uri.getScheme(); |
| 2603 | if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { |
| 2604 | filePath = uri.getPath(); |
| 2605 | } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { |
| 2606 | Cursor cursor = context.getContentResolver().query( |
| 2607 | uri, new String[] {MediaStore.Images.ImageColumns.DATA}, null, null, null); |
| 2608 | if (null != cursor) { |
| 2609 | if (cursor.moveToFirst()) { |
| 2610 | int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); |
| 2611 | if (index > -1) { |
| 2612 | filePath = cursor.getString(index); |
| 2613 | } |
| 2614 | } |
| 2615 | cursor.close(); |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | //get extension from filepath |
| 2620 | String extension = MimeTypeMap.getFileExtensionFromUrl(filePath); |
| 2621 | |
| 2622 | //check validity of extension |
| 2623 | boolean notSupported = false; |
| 2624 | //if have new unsupported extension, add it below |
| 2625 | notSupported |= (extension.equals("gif") || extension.equals("GIF")); |
| 2626 | return notSupported; |
| 2627 | } |
Ruben Brunk | 6416dd5 | 2012-11-28 14:00:30 -0800 | [diff] [blame] | 2628 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2629 | private int nameFilter(FilterPresetSource source, |
| 2630 | ArrayList <SaveOption> tempFilterArray) { |
| 2631 | String s,s1,s2; |
| 2632 | ArrayList<SaveOption> sp = source.getAllUserPresets(); |
| 2633 | ArrayList<Integer> temp = new ArrayList<Integer>(); |
| 2634 | if (sp != null) { |
| 2635 | for (int i = 0; i < sp.size(); i++) { |
| 2636 | s = sp.get(i).name; |
| 2637 | if (s.length() > "Custom".length()) { |
| 2638 | s1 = s.substring(0, 6); |
| 2639 | if (s1.equals("Custom")) { |
| 2640 | s2 = s.substring(6); |
| 2641 | int tem; |
| 2642 | try { |
| 2643 | tem = Integer.parseInt(s2); |
| 2644 | } catch (NumberFormatException e) { |
| 2645 | continue; |
| 2646 | } |
| 2647 | temp.add(tem); |
| 2648 | } |
| 2649 | } |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | if (tempFilterArray.size() != 0 ){ |
| 2654 | for (int i = 0; i < tempFilterArray.size(); i++) { |
| 2655 | s = tempFilterArray.get(i).name; |
| 2656 | if (s.length() > "Custom".length()) { |
| 2657 | s1 = s.substring(0, 6); |
| 2658 | if (s1.equals("Custom")) { |
| 2659 | s2 = s.substring(6); |
| 2660 | int tem; |
| 2661 | try { |
| 2662 | tem = Integer.parseInt(s2); |
| 2663 | } catch (NumberFormatException e) { |
| 2664 | continue; |
| 2665 | } |
| 2666 | temp.add(tem); |
| 2667 | } |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | } |
| 2672 | |
| 2673 | if (temp != null) { |
| 2674 | Collections.sort(temp); |
| 2675 | for (int i = 1; i <= temp.size(); i++){ |
| 2676 | if (temp.get(i-1)!= i){ |
| 2677 | return i; |
| 2678 | } |
| 2679 | } |
| 2680 | } |
| 2681 | return temp.size()+1; |
| 2682 | } |
| 2683 | |
| 2684 | |
| 2685 | public static boolean completeSaveFilters (FilterPresetSource mFilterPresetSource, |
| 2686 | ArrayList<SaveOption> tempFilterArray) { |
| 2687 | |
| 2688 | for (int i = 0; i < tempFilterArray.size(); i++){ |
| 2689 | String name = tempFilterArray.get(i).name; |
| 2690 | String filteredUri = tempFilterArray.get(i).Uri; |
| 2691 | if (mFilterPresetSource.insertPreset(name,filteredUri) == false) return false; |
| 2692 | } |
| 2693 | tempFilterArray.clear(); |
| 2694 | return true; |
| 2695 | } |
| 2696 | |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2697 | public void saveImage() { |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 2698 | if (mImageShow.hasModifications()) { |
| 2699 | // Get the name of the album, to which the image will be saved |
nicolasroard | 24d6ec7 | 2013-07-12 18:27:54 -0700 | [diff] [blame] | 2700 | File saveDir = SaveImage.getFinalSaveDirectory(this, mSelectedImageUri); |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 2701 | int bucketId = GalleryUtils.getBucketId(saveDir.getPath()); |
| 2702 | String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null); |
| 2703 | showSavingProgress(albumName); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2704 | if (mWaterMarkView == null) { |
| 2705 | mImageShow.saveImage(this, null); |
| 2706 | } else { |
| 2707 | mSaveWaterMark.saveImage(this, mMasterImage.getHighresImage(), |
| 2708 | mSelectedImageUri, handler); |
| 2709 | } |
| 2710 | if (tempFilterArray.size() != 0) { |
| 2711 | completeSaveFilters(mFilterPresetSource, tempFilterArray); |
| 2712 | } |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 2713 | } else { |
Ruben Brunk | 6416dd5 | 2012-11-28 14:00:30 -0800 | [diff] [blame] | 2714 | done(); |
| 2715 | } |
| 2716 | } |
| 2717 | |
Ruben Brunk | a241458 | 2013-02-21 20:13:20 -0800 | [diff] [blame] | 2718 | |
Ruben Brunk | 6416dd5 | 2012-11-28 14:00:30 -0800 | [diff] [blame] | 2719 | public void done() { |
Ruben Brunk | d25fdea | 2013-05-28 12:34:14 -0700 | [diff] [blame] | 2720 | hideSavingProgress(); |
John Hoford | 52fa110 | 2013-06-11 13:07:15 -0700 | [diff] [blame] | 2721 | if (mLoadBitmapTask != null) { |
| 2722 | mLoadBitmapTask.cancel(false); |
| 2723 | } |
Ruben Brunk | 6416dd5 | 2012-11-28 14:00:30 -0800 | [diff] [blame] | 2724 | finish(); |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
John Hoford | afa8ed9 | 2013-04-15 22:10:43 -0700 | [diff] [blame] | 2727 | private void extractXMPData() { |
| 2728 | XMresults res = XmpPresets.extractXMPData( |
| 2729 | getBaseContext(), mMasterImage, getIntent().getData()); |
| 2730 | if (res == null) |
| 2731 | return; |
| 2732 | |
| 2733 | mOriginalImageUri = res.originalimage; |
| 2734 | mOriginalPreset = res.preset; |
| 2735 | } |
ztenghui | b3f62e4 | 2013-06-10 15:51:42 -0700 | [diff] [blame] | 2736 | |
| 2737 | public Uri getSelectedImageUri() { |
| 2738 | return mSelectedImageUri; |
| 2739 | } |
| 2740 | |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 2741 | public void setHandlesSwipeForView(View view, float startX, float startY) { |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2742 | if (view != null) { |
| 2743 | mHandlingSwipeButton = true; |
| 2744 | } else { |
| 2745 | mHandlingSwipeButton = false; |
| 2746 | } |
| 2747 | mHandledSwipeView = view; |
| 2748 | int[] location = new int[2]; |
| 2749 | view.getLocationInWindow(location); |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 2750 | mSwipeStartX = location[0] + startX; |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2751 | mSwipeStartY = location[1] + startY; |
| 2752 | } |
| 2753 | |
| 2754 | public boolean dispatchTouchEvent (MotionEvent ev) { |
| 2755 | if (mHandlingSwipeButton) { |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 2756 | int direction = CategoryView.HORIZONTAL; |
| 2757 | if (mHandledSwipeView instanceof CategoryView) { |
| 2758 | direction = ((CategoryView) mHandledSwipeView).getOrientation(); |
| 2759 | } |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2760 | if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) { |
| 2761 | float delta = ev.getY() - mSwipeStartY; |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 2762 | float distance = mHandledSwipeView.getHeight(); |
| 2763 | if (direction == CategoryView.VERTICAL) { |
| 2764 | delta = ev.getX() - mSwipeStartX; |
| 2765 | mHandledSwipeView.setTranslationX(delta); |
| 2766 | distance = mHandledSwipeView.getWidth(); |
| 2767 | } else { |
| 2768 | mHandledSwipeView.setTranslationY(delta); |
| 2769 | } |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2770 | delta = Math.abs(delta); |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 2771 | float transparency = Math.min(1, delta / distance); |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2772 | mHandledSwipeView.setAlpha(1.f - transparency); |
| 2773 | mHandledSwipeViewLastDelta = delta; |
| 2774 | } |
| 2775 | if (ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 2776 | || ev.getActionMasked() == MotionEvent.ACTION_UP) { |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 2777 | mHandledSwipeView.setTranslationX(0); |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2778 | mHandledSwipeView.setTranslationY(0); |
| 2779 | mHandledSwipeView.setAlpha(1.f); |
| 2780 | mHandlingSwipeButton = false; |
nicolasroard | 9737f3a | 2013-08-14 11:14:47 -0700 | [diff] [blame] | 2781 | float distance = mHandledSwipeView.getHeight(); |
| 2782 | if (direction == CategoryView.VERTICAL) { |
| 2783 | distance = mHandledSwipeView.getWidth(); |
| 2784 | } |
| 2785 | if (mHandledSwipeViewLastDelta > distance) { |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2786 | ((SwipableView) mHandledSwipeView).delete(); |
| 2787 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2788 | } |
nicolasroard | 860af32 | 2013-08-08 20:47:28 -0700 | [diff] [blame] | 2789 | return true; |
| 2790 | } |
| 2791 | return super.dispatchTouchEvent(ev); |
| 2792 | } |
nicolasroard | 9f452e0 | 2013-08-23 00:10:01 -0700 | [diff] [blame] | 2793 | |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 2794 | public Point mHintTouchPoint = new Point(); |
| 2795 | |
| 2796 | public Point hintTouchPoint(View view) { |
| 2797 | int location[] = new int[2]; |
| 2798 | view.getLocationOnScreen(location); |
| 2799 | int x = mHintTouchPoint.x - location[0]; |
| 2800 | int y = mHintTouchPoint.y - location[1]; |
| 2801 | return new Point(x, y); |
| 2802 | } |
| 2803 | |
nicolasroard | 9f452e0 | 2013-08-23 00:10:01 -0700 | [diff] [blame] | 2804 | public void startTouchAnimation(View target, float x, float y) { |
nicolasroard | 9f452e0 | 2013-08-23 00:10:01 -0700 | [diff] [blame] | 2805 | int location[] = new int[2]; |
| 2806 | target.getLocationOnScreen(location); |
nicolasroard | 32cc4dd | 2013-09-06 17:21:55 -0700 | [diff] [blame] | 2807 | mHintTouchPoint.x = (int) (location[0] + x); |
| 2808 | mHintTouchPoint.y = (int) (location[1] + y); |
nicolasroard | 9f452e0 | 2013-08-23 00:10:01 -0700 | [diff] [blame] | 2809 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2810 | |
| 2811 | public void setScaleImage(boolean isScaled) { |
Chao Zhang | 7deb94a | 2016-03-14 11:10:20 +0800 | [diff] [blame] | 2812 | mImageShow.scaleImage(isScaled, getBaseContext()); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 2813 | } |
wqi | 99b35c1 | 2016-05-03 17:17:10 +0800 | [diff] [blame] | 2814 | |
| 2815 | public void saveEditorCropState(int select) { |
| 2816 | mEditrCropButtonSelect = select; |
| 2817 | } |
| 2818 | |
| 2819 | public boolean isReloadByConfigurationChanged() { |
| 2820 | return mIsReloadByConfigurationChanged; |
| 2821 | } |
| 2822 | |
| 2823 | public boolean isShowEditCropPanel() { |
| 2824 | if (mCurrentEditor == null) { |
| 2825 | return false; |
| 2826 | } |
| 2827 | Fragment currentPanel = getSupportFragmentManager().findFragmentByTag( |
| 2828 | MainPanel.FRAGMENT_TAG); |
| 2829 | if (currentPanel instanceof MainPanel) { |
| 2830 | return false; |
| 2831 | } |
| 2832 | return mCurrentEditor.getID() == EditorCrop.ID; |
| 2833 | } |
| 2834 | |
| 2835 | public int getEditorCropButtonSelect() { |
| 2836 | return mEditrCropButtonSelect; |
| 2837 | } |
| 2838 | |
zhuw | ad6505d | 2017-07-26 15:09:37 +0800 | [diff] [blame] | 2839 | @Override |
| 2840 | protected void onGetPermissionsFailure() { |
| 2841 | finish(); |
| 2842 | } |
| 2843 | |
| 2844 | @Override |
| 2845 | protected void onGetPermissionsSuccess() { |
| 2846 | if (canUpdataUI) { |
| 2847 | updateUIAfterServiceStarted(); |
| 2848 | } |
| 2849 | } |
nicolasroard | 0d7cdf8 | 2012-09-25 14:27:56 -0700 | [diff] [blame] | 2850 | } |