OSDN Git Service

Show status in importer for empty or no device
authorBobby Georgescu <georgescu@google.com>
Thu, 17 Jan 2013 20:30:06 +0000 (12:30 -0800)
committerBobby Georgescu <georgescu@google.com>
Fri, 18 Jan 2013 01:06:50 +0000 (17:06 -0800)
Bug: 8000251
Change-Id: Iefbbe6df59f432ffeb10ac9fa846a8908584ab58

res/layout/ingest_activity_item_list.xml
res/values/strings.xml
src/com/android/gallery3d/ingest/IngestActivity.java
src/com/android/gallery3d/ingest/MtpDeviceIndex.java
src/com/android/gallery3d/ingest/adapter/MtpAdapter.java

index 120cf15..23a95f6 100644 (file)
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<GridView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/ingest_gridview"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:columnWidth="200px"
-    android:numColumns="auto_fit"
-    android:fastScrollEnabled="true"
-    android:background="@android:color/background_dark"
-    android:choiceMode="multipleChoiceModal"
-    android:stretchMode="columnWidth"  />
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+    <GridView
+        android:id="@+id/ingest_gridview"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:columnWidth="200px"
+        android:numColumns="auto_fit"
+        android:fastScrollEnabled="true"
+        android:background="@android:color/background_dark"
+        android:choiceMode="multipleChoiceModal"
+        android:stretchMode="columnWidth"  />
+
+    <LinearLayout
+        android:id="@+id/ingest_warning_overlay"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_margin="20dip"
+        android:gravity="center"
+        android:orientation="horizontal"
+        android:visibility="gone" >
+
+        <ImageView
+            android:id="@+id/ingest_warning_overlay_icon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:src="@android:drawable/ic_dialog_alert" />
+
+        <TextView
+            android:id="@+id/ingest_warning_overlay_text"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="10dip"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+    </LinearLayout>
+</merge>
+
index 94f5646..9cbf72f 100644 (file)
 
     <!--  Status message shown when content from an external camera is being imported -->
     <string name="ingest_importing">Importing...</string>
+
+    <!--  Status message shown when there is no content available to be imported -->
+    <string name="ingest_empty_device">There is no content available for importing on this device.</string>
+
+    <!--  Status message shown when there is no MTP device connected  -->
+    <string name="ingest_no_device">There is no MTP device connected</string>
 </resources>
index feaf465..4e603be 100644 (file)
@@ -37,6 +37,7 @@ import android.widget.AbsListView.MultiChoiceModeListener;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.GridView;
+import android.widget.TextView;
 
 import com.android.gallery3d.R;
 import com.android.gallery3d.ingest.adapter.MtpAdapter;
@@ -56,6 +57,9 @@ public class IngestActivity extends Activity implements
     private ProgressDialog mProgressDialog;
     private ActionMode mActiveActionMode;
 
+    private View mWarningOverlay;
+    private TextView mWarningOverlayText;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -171,6 +175,7 @@ public class IngestActivity extends Activity implements
         DateTileView.refreshLocale();
         mActive = true;
         if (mHelperService != null) mHelperService.setClientActivity(this);
+        updateWarningOverlay();
         super.onResume();
     }
 
@@ -182,12 +187,45 @@ public class IngestActivity extends Activity implements
         super.onPause();
     }
 
-    protected void notifyIndexChanged() {
+    private void showWarningOverlay(int textResId) {
+        if (mWarningOverlay == null) {
+            mWarningOverlay = findViewById(R.id.ingest_warning_overlay);
+            mWarningOverlayText =
+                    (TextView)mWarningOverlay.findViewById(R.id.ingest_warning_overlay_text);
+        }
+        mWarningOverlayText.setText(textResId);
+        mWarningOverlay.setVisibility(View.VISIBLE);
+        mGridView.setVisibility(View.GONE);
+    }
+
+    private void hideWarningOverlay() {
+        if (mWarningOverlay != null) {
+            mWarningOverlay.setVisibility(View.GONE);
+            mGridView.setVisibility(View.VISIBLE);
+        }
+    }
+
+    private void updateWarningOverlay() {
+        if (!mAdapter.deviceConnected()) {
+            showWarningOverlay(R.string.ingest_no_device);
+        } else if (mAdapter.indexReady() && mAdapter.getCount() == 0) {
+            showWarningOverlay(R.string.ingest_empty_device);
+        } else {
+            hideWarningOverlay();
+        }
+    }
+
+    private void UiThreadNotifyIndexChanged() {
         mAdapter.notifyDataSetChanged();
         if (mActiveActionMode != null) {
             mActiveActionMode.finish();
             mActiveActionMode = null;
         }
+        updateWarningOverlay();
+    }
+
+    protected void notifyIndexChanged() {
+        mHandler.sendEmptyMessage(ItemListHandler.MSG_NOTIFY_CHANGED);
     }
 
     private static class ProgressState {
@@ -229,7 +267,7 @@ public class IngestActivity extends Activity implements
     public void onIndexFinish() {
         // Not guaranteed to be called on the UI thread
         mHandler.sendEmptyMessage(ItemListHandler.MSG_PROGRESS_HIDE);
-        mHandler.sendEmptyMessage(ItemListHandler.MSG_ADAPTER_NOTIFY_CHANGED);
+        mHandler.sendEmptyMessage(ItemListHandler.MSG_NOTIFY_CHANGED);
     }
 
     @Override
@@ -291,7 +329,7 @@ public class IngestActivity extends Activity implements
     private static class ItemListHandler extends Handler {
         public static final int MSG_PROGRESS_UPDATE = 0;
         public static final int MSG_PROGRESS_HIDE = 1;
-        public static final int MSG_ADAPTER_NOTIFY_CHANGED = 2;
+        public static final int MSG_NOTIFY_CHANGED = 2;
 
         WeakReference<IngestActivity> mParentReference;
 
@@ -311,8 +349,8 @@ public class IngestActivity extends Activity implements
                 case MSG_PROGRESS_UPDATE:
                     parent.updateProgressDialog();
                     break;
-                case MSG_ADAPTER_NOTIFY_CHANGED:
-                    parent.notifyIndexChanged();
+                case MSG_NOTIFY_CHANGED:
+                    parent.UiThreadNotifyIndexChanged();
                     break;
                 default:
                     break;
index 10ccb82..5a0f948 100644 (file)
@@ -143,6 +143,10 @@ public class MtpDeviceIndex {
         };
     }
 
+    synchronized public boolean indexReady() {
+        return mProgress == Progress.Finished;
+    }
+
     synchronized public Progress getProgress() {
         return mProgress;
     }
index e09fcd9..3cf0df2 100644 (file)
@@ -53,6 +53,14 @@ public class MtpAdapter extends BaseAdapter implements SectionIndexer {
         notifyDataSetChanged();
     }
 
+    public boolean deviceConnected() {
+        return (mModel != null) && (mModel.getDevice() != null);
+    }
+
+    public boolean indexReady() {
+        return (mModel != null) && mModel.indexReady();
+    }
+
     @Override
     public int getCount() {
         return mModel != null ? mModel.size() : 0;