2 * Copyright (C) 2007-2011 OpenIntents.org
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.openintents.filemanager;
\r
20 import java.io.BufferedReader;
\r
21 import java.io.IOException;
\r
22 import java.io.InputStreamReader;
\r
24 import org.openintents.util.VersionUtils;
\r
26 import android.app.Activity;
\r
27 import android.content.Intent;
\r
28 import android.content.SharedPreferences;
\r
29 import android.content.res.Resources;
\r
30 import android.os.Bundle;
\r
31 import android.preference.PreferenceManager;
\r
32 import android.text.TextUtils;
\r
33 import android.view.View;
\r
34 import android.widget.Button;
\r
35 import android.widget.ImageView;
\r
36 import android.widget.TextView;
\r
39 * Displays the Eula for the first time, reading it from a raw resource.
\r
44 public class EulaActivity extends Activity {
\r
49 String mLaunchPackage;
\r
50 String mLaunchClass;
\r
51 Intent mLaunchIntent;
\r
60 /** Called when the activity is first created. */
\r
62 public void onCreate(Bundle icicle) {
\r
63 super.onCreate(icicle);
\r
65 setContentView(R.layout.oi_distribution_eula);
\r
67 // Extras are provided by checkEula() below.
\r
68 Intent i = getIntent();
\r
69 Bundle b = i.getExtras();
\r
70 mLaunchPackage = b.getString(EulaOrNewVersion.EXTRA_LAUNCH_ACTIVITY_PACKAGE);
\r
71 mLaunchClass = b.getString(EulaOrNewVersion.EXTRA_LAUNCH_ACTIVITY_CLASS);
\r
73 mLaunchIntent = b.getParcelable(EulaOrNewVersion.EXTRA_LAUNCH_ACTIVITY_INTENT);
\r
75 //mIntroContinue = (Button) findViewById(R.id.intro_continue);
\r
76 mAgree = (Button) findViewById(R.id.button1);
\r
77 mAgree.setOnClickListener(new View.OnClickListener() {
\r
78 public void onClick(View view) {
\r
83 mDisagree = (Button) findViewById(R.id.button2);
\r
84 mDisagree.setOnClickListener(new View.OnClickListener() {
\r
85 public void onClick(View view) {
\r
90 mText1 = (TextView) findViewById(R.id.text1);
\r
91 mText2 = (TextView) findViewById(R.id.text2);
\r
92 mText = (TextView) findViewById(R.id.text);
\r
93 mImage = (ImageView) findViewById(R.id.imageview);
\r
95 mAppName = VersionUtils.getApplicationName(this);
\r
96 int iconRes = VersionUtils.getApplicationIcon(this);
\r
99 mImage.setImageResource(iconRes);
\r
101 String title = getString(R.string.oi_distribution_eula_title,
\r
103 String message = getString(R.string.oi_distribution_eula_message,
\r
106 mText1.setText(title);
\r
107 mText2.setText(message);
\r
108 mText.setText(readTextFromRawResource(R.raw.license_short, false));
\r
113 * Accept EULA and proceed with main application.
\r
116 EulaOrNewVersion.storeEulaAccepted(this);
\r
118 startOriginalActivity();
\r
124 void startOriginalActivity() {
\r
125 // Call the activity that originally called checkEula()
\r
126 // or checkNewVersion()
\r
128 if (mLaunchIntent != null) {
\r
131 // Android 2.3: category LAUNCHER needs to be removed,
\r
132 // otherwise main activity is not called.
\r
133 i.removeCategory(Intent.CATEGORY_LAUNCHER);
\r
136 i.setClassName(mLaunchPackage, mLaunchClass);
\r
138 i.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
\r
152 * Read license from raw resource.
\r
153 * @param resourceid ID of the raw resource.
\r
156 String readTextFromRawResource(int resourceid, boolean preserveLineBreaks) {
\r
158 // Retrieve license from resource:
\r
159 String license = "";
\r
160 Resources resources = getResources();
\r
162 //Read in the license file as a big String
\r
164 = new BufferedReader(new InputStreamReader(
\r
165 resources.openRawResource(resourceid)));
\r
167 StringBuilder sb = new StringBuilder();
\r
169 while ((line = in.readLine()) != null) { // Read line per line.
\r
170 if (TextUtils.isEmpty(line)) {
\r
171 // Empty line: Leave line break
\r
175 if (preserveLineBreaks) {
\r
182 license = sb.toString();
\r
183 } catch (IOException e) {
\r
184 //Should not happen.
\r
185 e.printStackTrace();
\r