1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* Copyright (C) 2013 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cyanogenmod.wallpapers.photophase.preferences;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.util.Log;
import org.cyanogenmod.wallpapers.photophase.R;
import java.io.InputStream;
/**
* The activity for show the changelog of the application
*/
public class ChangeLogActivity extends Activity implements OnCancelListener, OnDismissListener {
private static final String TAG = "ChangeLogActivity"; //$NON-NLS-1$
/**
* {@inheritDoc}
*/
@Override
protected void onCreate(Bundle state) {
//Save state
super.onCreate(state);
init();
}
/**
* Initialize the activity. This method handles the passed intent, opens
* the appropriate activity and ends.
*/
private void init() {
InputStream is = getApplicationContext().getResources().openRawResource(R.raw.changelog);
if (is == null) {
Log.e(TAG, "Changelog file not exists"); //$NON-NLS-1$
finish();
return;
}
try {
// Read the changelog
StringBuilder sb = new StringBuilder();
int read = 0;
byte[] data = new byte[512];
while ((read = is.read(data, 0, 512)) != -1) {
sb.append(new String(data, 0, read));
}
//Create the alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.changelog_title);
builder.setMessage(sb);
builder.setPositiveButton(getString(R.string.mnu_ok), null);
builder.setOnDismissListener(this);
builder.setOnCancelListener(this);
AlertDialog dialog = builder.create();
dialog.show();
} catch (Exception e) {
Log.e(TAG, "Failed to read changelog file", e); //$NON-NLS-1$
finish();
} finally {
try {
is.close();
} catch (Exception e) {/**NON BLOCK**/}
}
}
/**
* {@inheritDoc}
*/
@Override
public void onDismiss(DialogInterface dialog) {
// We have to finish here; this activity is only a wrapper
finish();
}
/**
* {@inheritDoc}
*/
@Override
public void onCancel(DialogInterface dialog) {
// We have to finish here; this activity is only a wrapper
finish();
}
}
|