OSDN Git Service

Disable save button when there's no modification
authorDoris Liu <tianliu@google.com>
Mon, 29 Oct 2012 20:11:10 +0000 (13:11 -0700)
committerDoris Liu <tianliu@google.com>
Mon, 29 Oct 2012 20:39:06 +0000 (13:39 -0700)
Bug: 7353884
Change-Id: I1b88e8b8ab3a92aad1226c60062a17a2f4badfb9

res/drawable-hdpi/ic_menu_savephoto_disabled.png [new file with mode: 0755]
res/drawable-mdpi/ic_menu_savephoto_disabled.png [new file with mode: 0755]
res/drawable-xhdpi/ic_menu_savephoto_disabled.png [new file with mode: 0755]
res/drawable/menu_save_photo.xml [new file with mode: 0644]
res/layout/filtershow_actionbar.xml
res/layout/trim_menu.xml
src/com/android/gallery3d/app/TrimVideo.java
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/imageshow/ImageShow.java

diff --git a/res/drawable-hdpi/ic_menu_savephoto_disabled.png b/res/drawable-hdpi/ic_menu_savephoto_disabled.png
new file mode 100755 (executable)
index 0000000..afb34ec
Binary files /dev/null and b/res/drawable-hdpi/ic_menu_savephoto_disabled.png differ
diff --git a/res/drawable-mdpi/ic_menu_savephoto_disabled.png b/res/drawable-mdpi/ic_menu_savephoto_disabled.png
new file mode 100755 (executable)
index 0000000..dc9b406
Binary files /dev/null and b/res/drawable-mdpi/ic_menu_savephoto_disabled.png differ
diff --git a/res/drawable-xhdpi/ic_menu_savephoto_disabled.png b/res/drawable-xhdpi/ic_menu_savephoto_disabled.png
new file mode 100755 (executable)
index 0000000..fab1c55
Binary files /dev/null and b/res/drawable-xhdpi/ic_menu_savephoto_disabled.png differ
diff --git a/res/drawable/menu_save_photo.xml b/res/drawable/menu_save_photo.xml
new file mode 100644 (file)
index 0000000..0b92ac9
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     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_enabled="true" android:drawable="@drawable/ic_menu_savephoto" />
+    <item android:state_enabled="false" android:drawable="@drawable/ic_menu_savephoto_disabled" />
+</selector>
index 93c8c59..5f0aa3f 100644 (file)
@@ -23,5 +23,5 @@
     android:text="@string/save"
     android:gravity="center_vertical"
     android:textSize="14sp"
-    android:drawableLeft="@drawable/ic_menu_savephoto"
+    android:drawableLeft="@drawable/menu_save_photo"
     android:drawablePadding="8dip" />
\ No newline at end of file
index b619220..e233392 100644 (file)
@@ -27,6 +27,6 @@
         android:textAllCaps="true"
         android:textSize="14sp"
         android:gravity="left|center_vertical"
-        android:drawableLeft="@drawable/ic_menu_savephoto"
+        android:drawableLeft="@drawable/menu_save_photo"
         android:drawablePadding="8dp" />
 </FrameLayout>
index 38b403b..f246ff6 100644 (file)
@@ -53,6 +53,7 @@ public class TrimVideo extends Activity implements
         ControllerOverlay.Listener {
 
     private VideoView mVideoView;
+    private TextView mSaveVideoTextView;
     private TrimControllerOverlay mController;
     private Context mContext;
     private Uri mUri;
@@ -93,13 +94,14 @@ public class TrimVideo extends Activity implements
         actionBar.setDisplayOptions(displayOptions, displayOptions);
         actionBar.setCustomView(R.layout.trim_menu);
 
-        TextView mSaveVideoTextView = (TextView) findViewById(R.id.start_trim);
+        mSaveVideoTextView = (TextView) findViewById(R.id.start_trim);
         mSaveVideoTextView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View arg0) {
                 trimVideo();
             }
         });
+        mSaveVideoTextView.setEnabled(false);
 
         Intent intent = getIntent();
         mUri = intent.getData();
@@ -257,21 +259,18 @@ public class TrimVideo extends Activity implements
         return dir[0];
     }
 
-    private void trimVideo() {
+    private boolean isModified() {
         int delta = mTrimEndTime - mTrimStartTime;
+
         // Considering that we only trim at sync frame, we don't want to trim
         // when the time interval is too short or too close to the origin.
-        if (delta < 100 ) {
-            Toast.makeText(getApplicationContext(),
-                getString(R.string.trim_too_short),
-                Toast.LENGTH_SHORT).show();
-            return;
-        }
-        if (Math.abs(mVideoView.getDuration() - delta) < 100) {
-            // If no change has been made, go back
-            onBackPressed();
-            return;
+        if (delta < 100 || Math.abs(mVideoView.getDuration() - delta) < 100) {
+            return false;
+        } else {
+            return true;
         }
+    }
+    private void trimVideo() {
         // Use the default save directory if the source directory cannot be
         // saved.
         mSaveDirectory = getSaveDirectory();
@@ -410,6 +409,8 @@ public class TrimVideo extends Activity implements
         mTrimStartTime = start;
         mTrimEndTime = end;
         setProgress();
+        // Enable save if there's modifications
+        mSaveVideoTextView.setEnabled(isModified());
     }
 
     @Override
index ef0415f..94d3185 100644 (file)
@@ -117,6 +117,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
     private View mListGeometry = null;
     private View mListColors = null;
     private View mListFilterButtons = null;
+    private View mSaveButton = null;
 
     private ImageButton mFxButton = null;
     private ImageButton mBorderButton = null;
@@ -178,7 +179,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
         actionBar.setCustomView(R.layout.filtershow_actionbar);
 
-        actionBar.getCustomView().setOnClickListener(new OnClickListener() {
+        mSaveButton = actionBar.getCustomView();
+        mSaveButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View view) {
                 saveImage();
@@ -633,6 +635,11 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         return false;
     }
 
+    public void enableSave(boolean enable) {
+        if (mSaveButton != null)
+            mSaveButton.setEnabled(enable);
+    }
+
     private void fillListImages(LinearLayout listFilters) {
         // TODO: use listview
         // TODO: load the filters straight from the filesystem
index 0145c24..358d5b7 100644 (file)
@@ -230,6 +230,7 @@ public class ImageShow extends View implements OnGestureListener,
         }
         updateSeekBar(parameter, minp, maxp);
         invalidate();
+        mActivity.enableSave(hasModifications());
     }
 
     @Override
@@ -396,6 +397,7 @@ public class ImageShow extends View implements OnGestureListener,
     public void updateImagePresets(boolean force) {
         ImagePreset preset = getImagePreset();
         if (preset == null) {
+            mActivity.enableSave(false);
             return;
         }
         if (force) {
@@ -419,6 +421,7 @@ public class ImageShow extends View implements OnGestureListener,
                 mFiltersOnlyImage = null;
             }
         }
+        mActivity.enableSave(hasModifications());
     }
 
     public void requestFilteredImages() {