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