OSDN Git Service

cmfm: use courier typeface for hex editor
[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.BroadcastReceiver;
22 import android.content.Context;
23 import android.content.DialogInterface;
24 import android.content.DialogInterface.OnCancelListener;
25 import android.content.DialogInterface.OnDismissListener;
26 import android.content.Intent;
27 import android.content.IntentFilter;
28 import android.os.Bundle;
29 import android.util.Log;
30
31 import com.cyanogenmod.filemanager.R;
32 import com.cyanogenmod.filemanager.preferences.FileManagerSettings;
33 import com.cyanogenmod.filemanager.ui.ThemeManager;
34 import com.cyanogenmod.filemanager.ui.ThemeManager.Theme;
35 import com.cyanogenmod.filemanager.util.DialogHelper;
36
37 import java.io.InputStream;
38
39 /**
40  * The activity for show the changelog of the application
41  */
42 public class ChangeLogActivity extends Activity implements OnCancelListener, OnDismissListener {
43
44     private static final String TAG = "ChangeLogActivity"; //$NON-NLS-1$
45
46     private static boolean DEBUG = false;
47
48     private final BroadcastReceiver mNotificationReceiver = new BroadcastReceiver() {
49         @Override
50         public void onReceive(Context context, Intent intent) {
51             if (intent != null) {
52                 if (intent.getAction().compareTo(FileManagerSettings.INTENT_THEME_CHANGED) == 0) {
53                     applyTheme();
54                 }
55             }
56         }
57     };
58
59     /**
60      * {@inheritDoc}
61      */
62     @Override
63     protected void onCreate(Bundle state) {
64         if (DEBUG) {
65             Log.d(TAG, "ChangeLogActivity.onCreate"); //$NON-NLS-1$
66         }
67
68         // Register the broadcast receiver
69         IntentFilter filter = new IntentFilter();
70         filter.addAction(FileManagerSettings.INTENT_THEME_CHANGED);
71         registerReceiver(this.mNotificationReceiver, filter);
72         applyTheme();
73
74         //Save state
75         super.onCreate(state);
76
77         init();
78     }
79
80     /**
81      * {@inheritDoc}
82      */
83     @Override
84     protected void onDestroy() {
85         if (DEBUG) {
86             Log.d(TAG, "ChangeLogActivity.onDestroy"); //$NON-NLS-1$
87         }
88
89         // Unregister the receiver
90         try {
91             unregisterReceiver(this.mNotificationReceiver);
92         } catch (Throwable ex) {
93             /**NON BLOCK**/
94         }
95
96         //All destroy. Continue
97         super.onDestroy();
98     }
99
100     /**
101      * Initialize the activity. This method handles the passed intent, opens
102      * the appropriate activity and ends.
103      */
104     private void init() {
105         InputStream is = getApplicationContext().getResources().openRawResource(R.raw.changelog);
106         if (is == null) {
107             Log.e(TAG, "Changelog file not exists"); //$NON-NLS-1$
108             finish();
109             return;
110         }
111
112         try {
113             // Read the changelog
114             StringBuilder sb = new StringBuilder();
115             int read = 0;
116             byte[] data = new byte[512];
117             while ((read = is.read(data, 0, 512)) != -1) {
118                 sb.append(new String(data, 0, read));
119             }
120
121             // Show a dialog
122             AlertDialog dialog = DialogHelper.createAlertDialog(
123                 this, R.drawable.ic_launcher,
124                 R.string.changelog_title, sb.toString(), false);
125             dialog.setOnCancelListener(this);
126             dialog.setOnDismissListener(this);
127             DialogHelper.delegateDialogShow(this, dialog);
128
129         } catch (Exception e) {
130             Log.e(TAG, "Failed to read changelog file", e); //$NON-NLS-1$
131             finish();
132
133         } finally {
134             try {
135                 is.close();
136             } catch (Exception e) {/**NON BLOCK**/}
137         }
138     }
139
140     /**
141      * {@inheritDoc}
142      */
143     @Override
144     public void onDismiss(DialogInterface dialog) {
145         // We have to finish here; this activity is only a wrapper
146         finish();
147     }
148
149     /**
150      * {@inheritDoc}
151      */
152     @Override
153     public void onCancel(DialogInterface dialog) {
154         // We have to finish here; this activity is only a wrapper
155         finish();
156     }
157
158     /**
159      * Method that applies the current theme to the activity
160      * @hide
161      */
162     void applyTheme() {
163         Theme theme = ThemeManager.getCurrentTheme(this);
164         theme.setBaseTheme(this, true);
165     }
166
167 }