OSDN Git Service

Show changelog inside the application (issue #6)
[android-x86/packages-apps-CMFileManager.git] / src / com / cyanogenmod / filemanager / activities / ChangeLogActivity.java
1 /*
2  * Copyright (C) 2012 The CyanogenMod 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.cyanogenmod.filemanager.activities;
18
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.content.DialogInterface;
22 import android.content.DialogInterface.OnCancelListener;
23 import android.content.DialogInterface.OnDismissListener;
24 import android.os.Bundle;
25 import android.util.Log;
26
27 import com.cyanogenmod.filemanager.R;
28 import com.cyanogenmod.filemanager.util.DialogHelper;
29
30 import java.io.InputStream;
31
32 /**
33  * The activity for show the changelog of the application
34  */
35 public class ChangeLogActivity extends Activity implements OnCancelListener, OnDismissListener {
36
37     private static final String TAG = "ChangeLogActivity"; //$NON-NLS-1$
38
39     private static boolean DEBUG = false;
40
41     /**
42      * {@inheritDoc}
43      */
44     @Override
45     protected void onCreate(Bundle state) {
46         if (DEBUG) {
47             Log.d(TAG, "ChangeLogActivity.onCreate"); //$NON-NLS-1$
48         }
49
50         //Save state
51         super.onCreate(state);
52
53         init();
54     }
55
56     /**
57      * Initialize the activity. This method handles the passed intent, opens
58      * the appropriate activity and ends.
59      */
60     private void init() {
61         InputStream is = getApplicationContext().getResources().openRawResource(R.raw.changelog);
62         if (is == null) {
63             Log.e(TAG, "Changelog file not exists"); //$NON-NLS-1$
64             finish();
65             return;
66         }
67
68         try {
69             // Read the changelog
70             StringBuilder sb = new StringBuilder();
71             int read = 0;
72             byte[] data = new byte[512];
73             while ((read = is.read(data, 0, 512)) != -1) {
74                 sb.append(new String(data, 0, read));
75             }
76
77             // Show a dialog
78             AlertDialog dialog = DialogHelper.createAlertDialog(
79                 this, R.drawable.ic_launcher,
80                 R.string.changelog_title, sb.toString(), false, true);
81             dialog.setOnCancelListener(this);
82             dialog.setOnDismissListener(this);
83             dialog.show();
84
85         } catch (Exception e) {
86             Log.e(TAG, "Failed to read changelog file", e); //$NON-NLS-1$
87             finish();
88
89         } finally {
90             try {
91                 is.close();
92             } catch (Exception e) {/**NON BLOCK**/}
93         }
94     }
95
96     /**
97      * {@inheritDoc}
98      */
99     @Override
100     public void onDismiss(DialogInterface dialog) {
101         // We have to finish here; this activity is only a wrapper
102         finish();
103     }
104
105     /**
106      * {@inheritDoc}
107      */
108     @Override
109     public void onCancel(DialogInterface dialog) {
110         // We have to finish here; this activity is only a wrapper
111         finish();
112     }
113
114
115 }