OSDN Git Service

36575e412eca602daf14fcd53092d32dd32579e5
[android-x86/packages-apps-Camera2.git] / src / com / android / gallery3d / gadget / WidgetClickHandler.java
1 /*
2  * Copyright (C) 2009 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  */
16
17 package com.android.gallery3d.gadget;
18
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;
26
27 import com.android.gallery3d.R;
28 import com.android.gallery3d.app.Gallery;
29
30 public class WidgetClickHandler extends Activity {
31     private static final String TAG = "PhotoAppWidgetClickHandler";
32
33     private boolean isValidDataUri(Uri dataUri) {
34         if (dataUri == null) return false;
35         try {
36             AssetFileDescriptor f = getContentResolver()
37                     .openAssetFileDescriptor(dataUri, "r");
38             f.close();
39             return true;
40         } catch (Throwable e) {
41             Log.w(TAG, "cannot open uri: " + dataUri, e);
42             return false;
43         }
44     }
45
46     @Override
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()));
52         } else {
53             Toast.makeText(this,
54                     R.string.no_such_item, Toast.LENGTH_LONG).show();
55             startActivity(new Intent(this, Gallery.class));
56         }
57         finish();
58     }
59 }