2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.gadget;
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.content.res.AssetFileDescriptor;
22 import android.net.Uri;
23 import android.os.Bundle;
24 import android.util.Log;
25 import android.widget.Toast;
27 import com.android.gallery3d.R;
28 import com.android.gallery3d.app.Gallery;
30 public class WidgetClickHandler extends Activity {
31 private static final String TAG = "PhotoAppWidgetClickHandler";
33 private boolean isValidDataUri(Uri dataUri) {
34 if (dataUri == null) return false;
36 AssetFileDescriptor f = getContentResolver()
37 .openAssetFileDescriptor(dataUri, "r");
40 } catch (Throwable e) {
41 Log.w(TAG, "cannot open uri: " + dataUri, e);
47 protected void onCreate(Bundle savedState) {
48 super.onCreate(savedState);
49 Intent intent = getIntent();
50 if (isValidDataUri(intent.getData())) {
51 startActivity(new Intent(Intent.ACTION_VIEW, intent.getData()));
54 R.string.no_such_item, Toast.LENGTH_LONG).show();
55 startActivity(new Intent(this, Gallery.class));