diff options
Diffstat (limited to 'SnapdragonCamera')
12 files changed, 894 insertions, 0 deletions
diff --git a/SnapdragonCamera/res/drawable/ic_ts_makeup_clean_selector.xml b/SnapdragonCamera/res/drawable/ic_ts_makeup_clean_selector.xml new file mode 100644 index 000000000..791658dd4 --- /dev/null +++ b/SnapdragonCamera/res/drawable/ic_ts_makeup_clean_selector.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_selected="true" android:drawable="@drawable/ic_ts_makeup_clean_selected" /> + <item android:drawable="@drawable/ic_ts_makeup_clean" /> +</selector> diff --git a/SnapdragonCamera/res/drawable/ic_ts_makeup_custom_selector.xml b/SnapdragonCamera/res/drawable/ic_ts_makeup_custom_selector.xml new file mode 100644 index 000000000..eecc2c7ce --- /dev/null +++ b/SnapdragonCamera/res/drawable/ic_ts_makeup_custom_selector.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_selected="true" android:drawable="@drawable/ic_ts_makeup_custom_selected" /> + <item android:drawable="@drawable/ic_ts_makeup_custom" /> +</selector> diff --git a/SnapdragonCamera/res/drawable/ic_ts_makeup_level_1_selector.xml b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_1_selector.xml new file mode 100644 index 000000000..38e9193ab --- /dev/null +++ b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_1_selector.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_selected="true" android:drawable="@drawable/ic_ts_makeup_level_1_selected" /> + <item android:drawable="@drawable/ic_ts_makeup_level_1" /> +</selector> diff --git a/SnapdragonCamera/res/drawable/ic_ts_makeup_level_2_selector.xml b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_2_selector.xml new file mode 100644 index 000000000..76d40bd88 --- /dev/null +++ b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_2_selector.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_selected="true" android:drawable="@drawable/ic_ts_makeup_level_2_selected" /> + <item android:drawable="@drawable/ic_ts_makeup_level_2" /> +</selector> diff --git a/SnapdragonCamera/res/drawable/ic_ts_makeup_level_3_selector.xml b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_3_selector.xml new file mode 100644 index 000000000..e26ecdfa5 --- /dev/null +++ b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_3_selector.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_selected="true" android:drawable="@drawable/ic_ts_makeup_level_3_selected" /> + <item android:drawable="@drawable/ic_ts_makeup_level_3" /> +</selector> diff --git a/SnapdragonCamera/res/drawable/ic_ts_makeup_level_off_selector.xml b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_off_selector.xml new file mode 100644 index 000000000..e1939673a --- /dev/null +++ b/SnapdragonCamera/res/drawable/ic_ts_makeup_level_off_selector.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_selected="true" android:drawable="@drawable/ic_ts_makeup_level_off_selected" /> + <item android:drawable="@drawable/ic_ts_makeup_level_off" /> +</selector> diff --git a/SnapdragonCamera/res/drawable/ic_ts_makeup_whiten_selector.xml b/SnapdragonCamera/res/drawable/ic_ts_makeup_whiten_selector.xml new file mode 100644 index 000000000..f1284b604 --- /dev/null +++ b/SnapdragonCamera/res/drawable/ic_ts_makeup_whiten_selector.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_selected="true" android:drawable="@drawable/ic_ts_makeup_whiten_selected" /> + <item android:drawable="@drawable/ic_ts_makeup_whiten" /> +</selector> diff --git a/SnapdragonCamera/res/layout/ts_makeup_item_view.xml b/SnapdragonCamera/res/layout/ts_makeup_item_view.xml new file mode 100644 index 000000000..4b5a050cf --- /dev/null +++ b/SnapdragonCamera/res/layout/ts_makeup_item_view.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<com.android.camera.ui.RotateLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical" > + + <LinearLayout + android:id="@+id/border" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical" > + + <ImageView + android:id="@+id/image" + android:layout_width="48dip" + android:layout_height="48dip" + android:layout_gravity="center" + android:gravity="center" /> + + <TextView + android:id="@+id/label" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:singleLine="true" + android:textColor="@android:color/white" + android:textSize="13sp" + android:textStyle="bold" /> + </LinearLayout> + +</com.android.camera.ui.RotateLayout>
\ No newline at end of file diff --git a/SnapdragonCamera/res/layout/ts_makeup_level_view_land.xml b/SnapdragonCamera/res/layout/ts_makeup_level_view_land.xml new file mode 100644 index 000000000..0d02562ff --- /dev/null +++ b/SnapdragonCamera/res/layout/ts_makeup_level_view_land.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/id_makeup_level_root" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_gravity="right" + android:layout_alignParentRight="true" + android:alpha="0.85" + android:orientation="vertical" > + +</LinearLayout>
\ No newline at end of file diff --git a/SnapdragonCamera/res/layout/ts_makeup_level_view_port.xml b/SnapdragonCamera/res/layout/ts_makeup_level_view_port.xml new file mode 100644 index 000000000..4ffaba5dd --- /dev/null +++ b/SnapdragonCamera/res/layout/ts_makeup_level_view_port.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/id_makeup_level_root" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:layout_alignParentBottom="true" + android:alpha="0.85" + android:orientation="horizontal" > + +</LinearLayout>
\ No newline at end of file diff --git a/SnapdragonCamera/res/layout/ts_makeup_single_level_view_port.xml b/SnapdragonCamera/res/layout/ts_makeup_single_level_view_port.xml new file mode 100644 index 000000000..fbfafeec3 --- /dev/null +++ b/SnapdragonCamera/res/layout/ts_makeup_single_level_view_port.xml @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014,2015 Thundersoft Corporation + All rights Reserved + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/id_makeup_single_level_root" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_gravity="bottom" + android:orientation="vertical" > + + <SeekBar + android:id="@+id/seekbar_makeup_level" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="8dip" + android:visibility="gone" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="@dimen/tsmakeup_mode_level_size" + android:layout_gravity="center" + android:gravity="center" > + + <LinearLayout + android:id="@+id/id_layout_makeup_back" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_weight="2.0" + android:gravity="center" > + + <ImageView + android:id="@+id/id_iv_makeup_back" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:src="@drawable/ic_ts_makeup_back" /> + </LinearLayout> + + <LinearLayout + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_weight="1.0" + android:gravity="center" > + + <View + android:layout_width="1dip" + android:layout_height="36dip" + android:layout_gravity="center" + android:background="@drawable/ic_ts_makeup_vline" /> + </LinearLayout> + + <com.android.camera.ui.RotateLayout + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_weight="3.5" + android:gravity="center" + android:orientation="vertical" > + + <LinearLayout + android:id="@+id/id_layout_makeup_clean" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical" + android:padding="2dip" > + + <ImageView + android:id="@+id/id_iv_makeup_clean" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:src="@drawable/ic_ts_makeup_clean_selector" /> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:shadowColor="@android:color/black" + android:shadowDx="1" + android:shadowDy="1" + android:shadowRadius="2" + android:singleLine="true" + android:text="@string/pref_camera_tsmakeup_level_clean" + android:textColor="@android:color/white" + android:textSize="13sp" + android:textStyle="bold" /> + </LinearLayout> + </com.android.camera.ui.RotateLayout> + + <com.android.camera.ui.RotateLayout + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_weight="3.5" + android:gravity="center" + android:orientation="vertical" > + + <LinearLayout + android:id="@+id/id_layout_makeup_whiten" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical" + android:padding="2dp" > + + <ImageView + android:id="@+id/id_iv_makeup_whiten" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:src="@drawable/ic_ts_makeup_whiten_selector" /> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:shadowColor="@android:color/black" + android:shadowDx="1" + android:shadowDy="1" + android:shadowRadius="2" + android:singleLine="true" + android:text="@string/pref_camera_tsmakeup_level_whiten" + android:textColor="@android:color/white" + android:textSize="13sp" + android:textStyle="bold" /> + </LinearLayout> + </com.android.camera.ui.RotateLayout> + </LinearLayout> + +</LinearLayout>
\ No newline at end of file diff --git a/SnapdragonCamera/src/com/android/camera/TsMakeupManager.java b/SnapdragonCamera/src/com/android/camera/TsMakeupManager.java new file mode 100644 index 000000000..db3505b45 --- /dev/null +++ b/SnapdragonCamera/src/com/android/camera/TsMakeupManager.java @@ -0,0 +1,476 @@ +/* +* Copyright (C) 2014,2015 Thundersoft Corporation +* All rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.camera; + +import android.content.Context; +import android.content.res.Resources; +import android.text.TextUtils; +import android.util.Log; +import android.view.Display; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.WindowManager; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.SeekBar; +import android.widget.TextView; +import android.widget.LinearLayout.LayoutParams; +import android.widget.SeekBar.OnSeekBarChangeListener; + +import com.android.camera.ui.RotateLayout; +import com.android.camera.util.CameraUtil; + +import org.codeaurora.snapcam.R; + +public class TsMakeupManager implements OnSeekBarChangeListener { + private static final String TAG = "TsMakeupManager"; + private PhotoUI mUI; + private PhotoMenu mMenu; + private CameraActivity mActivity; + private PreferenceGroup mPreferenceGroup; + private View mTsMakeupSwitcher; + + private RelativeLayout mMakeupLayoutRoot; + private LinearLayout mMakeupLevelRoot; + private LinearLayout mMakeupSingleRoot; + + public static final String MAKEUP_ON = "On"; + public static final String MAKEUP_OFF = "Off"; + public static final String MAKEUP_NONE = "none"; + + private static final int MODE_NONE = 0; + private static final int MODE_WHITEN = 1; + private static final int MODE_CLEAN = 2; + private int mMode = MODE_NONE; + private int mSingleSelectedIndex = MODE_NONE; + + private static final int MAKEUP_UI_STATUS_NONE = 0; + private static final int MAKEUP_UI_STATUS_ON = 1; + private static final int MAKEUP_UI_STATUS_OFF = 2; + private static final int MAKEUP_UI_STATUS_DISMISS = 3; + private int mMakeupUIStatus = MAKEUP_UI_STATUS_NONE; + + private static final int CLICK_THRESHOLD = 200; + + public static final boolean HAS_TS_MAKEUP = android.os.SystemProperties.getBoolean("persist.ts.rtmakeup", false); + + private MakeupLevelListener mMakeupLevelListener; + interface MakeupLevelListener { + void onMakeupLevel(String key, String value); + } + + public void setMakeupLevelListener(MakeupLevelListener l) { + mMakeupLevelListener = l; + } + + public TsMakeupManager(CameraActivity activity, PhotoMenu menu, PhotoUI ui, PreferenceGroup preferenceGroup, View makeupSwitcher) { + mActivity = activity; + mUI = ui; + mMenu = menu; + mPreferenceGroup = preferenceGroup; + mTsMakeupSwitcher = makeupSwitcher; + + mMakeupLayoutRoot = (RelativeLayout) mUI.getRootView().findViewById(R.id.id_tsmakeup_level_layout_root); + + mMakeupUIStatus = MAKEUP_UI_STATUS_NONE; + } + + public View getMakeupLayoutRoot() { + return mMakeupLayoutRoot; + } + + public boolean isShowMakeup() { + return mMakeupLayoutRoot != null && mMakeupLayoutRoot.isShown(); + } + + public void removeAllViews() { + if(mMakeupSingleRoot != null) { + mMakeupSingleRoot.removeAllViews(); + mMakeupSingleRoot = null; + } + if(mMakeupLevelRoot != null) { + mMakeupLevelRoot.removeAllViews(); + mMakeupLevelRoot = null; + } + if(mMakeupLayoutRoot != null) { + mMakeupLayoutRoot.removeAllViews(); + } + } + + public void dismissMakeupUI() { + mMakeupUIStatus = MAKEUP_UI_STATUS_DISMISS; + removeAllViews(); + if(mMakeupLayoutRoot != null) { + mMakeupLayoutRoot.setVisibility(View.GONE); + } + } + + public void resetMakeupUIStatus() { + mMakeupUIStatus = MAKEUP_UI_STATUS_NONE; + } + + private void changeMakeupIcon(String value) { + if( !TextUtils.isEmpty(value) ) { + String prefValue = MAKEUP_ON; + if(MAKEUP_OFF.equals(value)) { + prefValue = MAKEUP_OFF; + } + final IconListPreference pref = (IconListPreference) mPreferenceGroup + .findPreference(CameraSettings.KEY_TS_MAKEUP_UILABLE); + if(pref == null) + return; + pref.setValue(prefValue); + int index = pref.getCurrentIndex(); + ImageView iv = (ImageView) mTsMakeupSwitcher; + iv.setImageResource(((IconListPreference) pref).getLargeIconIds()[index]); + pref.setMakeupSeekBarValue(prefValue); + } + } + + public void hideMakeupUI() { + final IconListPreference pref = (IconListPreference) mPreferenceGroup + .findPreference(CameraSettings.KEY_TS_MAKEUP_UILABLE); + if(pref == null) + return; + mMakeupUIStatus = MAKEUP_UI_STATUS_NONE; + String tsMakeupOn = pref.getValue(); + Log.d(TAG, "TsMakeupManager.hideMakeupUI(): tsMakeupOn is " + tsMakeupOn); + if(MAKEUP_ON.equals(tsMakeupOn)) { + int index = pref.findIndexOfValue(pref.getValue()); + CharSequence[] values = pref.getEntryValues(); + index = (index + 1) % values.length; + pref.setMakeupSeekBarValue((String)values[index]); + ImageView iv = (ImageView) mTsMakeupSwitcher; + iv.setImageResource(((IconListPreference) pref).getLargeIconIds()[index]); + mMakeupLevelListener.onMakeupLevel(CameraSettings.KEY_TS_MAKEUP_LEVEL, pref.getValue()); + + IconListPreference levelPref = (IconListPreference) mPreferenceGroup + .findPreference(CameraSettings.KEY_TS_MAKEUP_LEVEL); + levelPref.setValueIndex(0); //Turn Off the Makeup feature; + + + mMakeupLayoutRoot.setVisibility(View.GONE); + mMakeupLayoutRoot.removeAllViews(); + if(mMakeupSingleRoot != null) { + mMakeupSingleRoot.removeAllViews(); + mMakeupSingleRoot = null; + } + if(mMakeupLevelRoot != null) { + mMakeupLevelRoot.removeAllViews(); + mMakeupLevelRoot = null; + } + } + } + + public void showMakeupView() { + mMakeupUIStatus = MAKEUP_UI_STATUS_OFF; + mMakeupLayoutRoot.setVisibility(View.GONE); + mMakeupLayoutRoot.removeAllViews(); + if(mMakeupSingleRoot != null) { + mMakeupSingleRoot.removeAllViews(); + mMakeupSingleRoot = null; + } + if(mMakeupLevelRoot != null) { + mMakeupLevelRoot.removeAllViews(); + mMakeupLevelRoot = null; + } + + if(mMakeupSingleRoot != null && mMakeupSingleRoot.getVisibility() == View.VISIBLE) { + showSingleView(MAKEUP_NONE); + return; + } + + if(mMakeupUIStatus == MAKEUP_UI_STATUS_DISMISS) + return; + + mMakeupLayoutRoot.setVisibility(View.VISIBLE); + final IconListPreference pref = (IconListPreference) mPreferenceGroup + .findPreference(CameraSettings.KEY_TS_MAKEUP_LEVEL); + if (pref == null) + return; + + if(mMakeupLevelRoot != null) { + mMakeupLevelRoot.removeAllViews(); + mMakeupLevelRoot = null; + } + mMakeupLayoutRoot.removeAllViews(); + + mMakeupUIStatus = MAKEUP_UI_STATUS_ON; + + int rotation = CameraUtil.getDisplayRotation(mActivity); + boolean mIsDefaultToPortrait = CameraUtil.isDefaultToPortrait(mActivity); + if (!mIsDefaultToPortrait) { + rotation = (rotation + 90) % 360; + } + CharSequence[] entries = pref.getEntries(); + int[] thumbnails = pref.getThumbnailIds(); + + WindowManager wm = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + int width = display.getWidth(); + int height = display.getHeight(); + Resources r = mActivity.getResources(); + int margin = (int) (r.getDimension(R.dimen.tsmakeup_mode_paddingBottom)); + int levelBgSize = (int) (r.getDimension(R.dimen.tsmakeup_mode_level_size)); + + Log.d(TAG, "TsMakeupManager.showMakeupView(): rotation is " + rotation + ", WH is (" + width + ", " + height + "), margin is " + + margin + ", levelBgSize is " + levelBgSize); + + int gridRes = 0; + boolean portrait = (rotation == 0) || (rotation == 180); + int size = height; + if (portrait) { + gridRes = R.layout.ts_makeup_level_view_port; + size = width; + } else { + gridRes = R.layout.ts_makeup_level_view_land; + size = height; + } + int itemWidth = size / entries.length; + + LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + LinearLayout layout = (LinearLayout) inflater.inflate(gridRes, null, false); + mMakeupLevelRoot = layout; + mUI.setMakeupMenuLayout(layout); + + LinearLayout.LayoutParams params = null; + if(portrait) { + params = new LayoutParams(itemWidth, itemWidth); + params.gravity = Gravity.CENTER_VERTICAL; + } else { + params = new LayoutParams(itemWidth, itemWidth); + params.gravity = Gravity.CENTER_HORIZONTAL; + } + + RelativeLayout.LayoutParams rootParams = null; + if(rotation == 0) { + rootParams = new RelativeLayout.LayoutParams(size, levelBgSize); +// rootParams.bottomMargin = margin; + rootParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + } else if(rotation == 90) { + rootParams = new RelativeLayout.LayoutParams(levelBgSize, size); +// rootParams.rightMargin = margin; + rootParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + } else if(rotation == 180) { + rootParams = new RelativeLayout.LayoutParams(size, levelBgSize); +// rootParams.topMargin = margin; + rootParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); + } else if(rotation == 270) { + rootParams = new RelativeLayout.LayoutParams(levelBgSize, size); +// rootParams.leftMargin = margin; + rootParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); + } + + final View[] views = new View[entries.length]; + int init = pref.getCurrentIndex(); + for (int i = 0; i < entries.length; i++) { + RotateLayout layout2 = (RotateLayout) inflater.inflate( + R.layout.ts_makeup_item_view, null, false); + + ImageView imageView = (ImageView) layout2.findViewById(R.id.image); + TextView label = (TextView) layout2.findViewById(R.id.label); + final int j = i; + + layout2.setOnTouchListener(new View.OnTouchListener() { + private long startTime; + + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + startTime = System.currentTimeMillis(); + } else if (event.getAction() == MotionEvent.ACTION_UP) { + if (System.currentTimeMillis() - startTime < CLICK_THRESHOLD) { + pref.setValueIndex(j); + changeMakeupIcon(pref.getValue()); + mMakeupLevelListener.onMakeupLevel(pref.getKey(), pref.getValue()); + for (View v1 : views) { + v1.setSelected(false); + } + View border = v.findViewById(R.id.image); + border.setSelected(true); + + showSingleView(pref.getValue()); + mUI.adjustOrientation(); + } + } + return true; + } + }); + + View border = layout2.findViewById(R.id.image); + views[j] = border; + if (i == init) { + border.setSelected(true); + } + imageView.setImageResource(thumbnails[i]); + label.setText(entries[i]); + layout.addView(layout2, params); + } + mMakeupLayoutRoot.addView(layout, rootParams); + } + + private void showSingleView(String value) { + if(MAKEUP_NONE.equals(value)) { + if(mMakeupSingleRoot != null) { + mMakeupSingleRoot.removeAllViews(); + mMakeupSingleRoot = null; + } + mMakeupLayoutRoot.removeAllViews(); + int rotation = CameraUtil.getDisplayRotation(mActivity); + boolean mIsDefaultToPortrait = CameraUtil.isDefaultToPortrait(mActivity); + if (!mIsDefaultToPortrait) { + rotation = (rotation + 90) % 360; + } + + WindowManager wm = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + int width = display.getWidth(); + int height = display.getHeight(); + Resources r = mActivity.getResources(); + int margin = (int) (r.getDimension(R.dimen.tsmakeup_mode_paddingBottom)); + int levelBgSize = (int) (r.getDimension(R.dimen.tsmakeup_mode_level_size)); + + Log.d(TAG, "TsMakeupManager.showSingleView(): rotation is " + rotation + ", WH is (" + width + ", " + height + "), margin is " + + margin + ", levelBgSize is " + levelBgSize); + + int gridRes = R.layout.ts_makeup_single_level_view_port; + int size = width; + + LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + final LinearLayout layout = (LinearLayout) inflater.inflate(gridRes, null, false); + mMakeupSingleRoot = layout; + mUI.setMakeupMenuLayout(layout); + + RelativeLayout.LayoutParams rootParams = new RelativeLayout.LayoutParams(size, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); + rootParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + + mMakeupLayoutRoot.addView(layout, rootParams); + final SeekBar seekBar = (SeekBar) layout.findViewById(R.id.seekbar_makeup_level); + seekBar.setOnSeekBarChangeListener(this); + setSingleView(layout); + + mMode = MODE_NONE; + + layout.findViewById(R.id.id_layout_makeup_back).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mMakeupSingleRoot.removeAllViews(); + mMakeupLayoutRoot.removeView(mMakeupSingleRoot); + mMakeupSingleRoot = null; + + mSingleSelectedIndex = MODE_NONE; + mMode = MODE_NONE; + + showMakeupView(); + mUI.adjustOrientation(); + } + }); + + layout.findViewById(R.id.id_layout_makeup_whiten).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if(mMode == MODE_WHITEN) { + seekBar.setVisibility(View.GONE); + mMode = MODE_NONE; + return; + } + mSingleSelectedIndex = MODE_WHITEN; + seekBar.setVisibility(View.VISIBLE); + seekBar.setProgress(getPrefValue(CameraSettings.KEY_TS_MAKEUP_LEVEL_WHITEN)); + mMode = MODE_WHITEN; + setSingleView(layout); + } + }); + + layout.findViewById(R.id.id_layout_makeup_clean).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if(mMode == MODE_CLEAN) { + seekBar.setVisibility(View.GONE); + mMode = MODE_NONE; + return; + } + mSingleSelectedIndex = MODE_CLEAN; + seekBar.setVisibility(View.VISIBLE); + seekBar.setProgress(getPrefValue(CameraSettings.KEY_TS_MAKEUP_LEVEL_CLEAN)); + mMode = MODE_CLEAN; + setSingleView(layout); + } + }); + } + } + + private void setSingleView(LinearLayout layout) { + if(mSingleSelectedIndex == MODE_WHITEN) { + layout.findViewById(R.id.id_iv_makeup_whiten).setSelected(true); + layout.findViewById(R.id.id_iv_makeup_clean).setSelected(false); + } else if(mSingleSelectedIndex == MODE_CLEAN) { + layout.findViewById(R.id.id_iv_makeup_whiten).setSelected(false); + layout.findViewById(R.id.id_iv_makeup_clean).setSelected(true); + } + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + setSeekbarValue(seekBar.getProgress()); + } + + private void setSeekbarValue(int value) { + String key = CameraSettings.KEY_TS_MAKEUP_LEVEL_WHITEN; + if(mMode == MODE_CLEAN) { + key = CameraSettings.KEY_TS_MAKEUP_LEVEL_CLEAN; + } + Log.d(TAG, "TsMakeupManager.onStopTrackingTouch(): value is " + value + ", key is " + key); + setEffectValue(key, String.valueOf(value)); + } + + private void setEffectValue(String key, String value) { + final ListPreference pref = (ListPreference) mPreferenceGroup.findPreference(key); + if (pref == null) + return; + + pref.setMakeupSeekBarValue(value); + mMakeupLevelListener.onMakeupLevel(key, value); + } + + private int getPrefValue(String key) { + ListPreference pref = mPreferenceGroup.findPreference(key); + String value = pref.getValue(); + Log.d(TAG, "TsMakeupManager.getPrefValue(): value is " + value + ", key is " + key); + if(TextUtils.isEmpty(value)) { + value = mActivity.getString(R.string.pref_camera_tsmakeup_level_default); + } + return Integer.parseInt(value); + } +} |