+++ /dev/null
-/* \r
- * Copyright (C) 2007-2011 OpenIntents.org\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openintents.filemanager;\r
-\r
-\r
-import java.io.BufferedReader;\r
-import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-\r
-import org.openintents.util.VersionUtils;\r
-\r
-import android.app.Activity;\r
-import android.content.Intent;\r
-import android.content.SharedPreferences;\r
-import android.content.res.Resources;\r
-import android.os.Bundle;\r
-import android.preference.PreferenceManager;\r
-import android.text.TextUtils;\r
-import android.view.View;\r
-import android.widget.Button;\r
-import android.widget.ImageView;\r
-import android.widget.TextView;\r
-\r
-/**\r
- * Displays the Eula for the first time, reading it from a raw resource.\r
- * \r
- * @author Peli\r
- *\r
- */\r
-public class EulaActivity extends Activity {\r
- \r
- Button mAgree;\r
- Button mDisagree;\r
- \r
- String mLaunchPackage;\r
- String mLaunchClass;\r
- Intent mLaunchIntent;\r
- \r
- String mAppName;\r
-\r
- TextView mText1;\r
- TextView mText2;\r
- TextView mText;\r
- ImageView mImage;\r
- \r
- /** Called when the activity is first created. */\r
- @Override\r
- public void onCreate(Bundle icicle) {\r
- super.onCreate(icicle);\r
- \r
- setContentView(R.layout.oi_distribution_eula);\r
- \r
- // Extras are provided by checkEula() below.\r
- Intent i = getIntent();\r
- Bundle b = i.getExtras();\r
- mLaunchPackage = b.getString(EulaOrNewVersion.EXTRA_LAUNCH_ACTIVITY_PACKAGE);\r
- mLaunchClass = b.getString(EulaOrNewVersion.EXTRA_LAUNCH_ACTIVITY_CLASS);\r
- //mLaunchIntent \r
- mLaunchIntent = b.getParcelable(EulaOrNewVersion.EXTRA_LAUNCH_ACTIVITY_INTENT);\r
- \r
- //mIntroContinue = (Button) findViewById(R.id.intro_continue);\r
- mAgree = (Button) findViewById(R.id.button1);\r
- mAgree.setOnClickListener(new View.OnClickListener() {\r
- public void onClick(View view) {\r
- accept();\r
- }\r
- });\r
- \r
- mDisagree = (Button) findViewById(R.id.button2);\r
- mDisagree.setOnClickListener(new View.OnClickListener() {\r
- public void onClick(View view) {\r
- refuse();\r
- }\r
- });\r
-\r
- mText1 = (TextView) findViewById(R.id.text1);\r
- mText2 = (TextView) findViewById(R.id.text2);\r
- mText = (TextView) findViewById(R.id.text);\r
- mImage = (ImageView) findViewById(R.id.imageview);\r
- \r
- mAppName = VersionUtils.getApplicationName(this);\r
- int iconRes = VersionUtils.getApplicationIcon(this);\r
- \r
- setTitle(mAppName);\r
- mImage.setImageResource(iconRes);\r
-\r
- String title = getString(R.string.oi_distribution_eula_title, \r
- mAppName);\r
- String message = getString(R.string.oi_distribution_eula_message, \r
- mAppName);\r
- \r
- mText1.setText(title);\r
- mText2.setText(message);\r
- mText.setText(readTextFromRawResource(R.raw.license_short, false));\r
- }\r
- \r
- \r
- /**\r
- * Accept EULA and proceed with main application.\r
- */\r
- void accept() {\r
- EulaOrNewVersion.storeEulaAccepted(this);\r
- \r
- startOriginalActivity();\r
- }\r
-\r
-\r
-\r
-\r
- void startOriginalActivity() {\r
- // Call the activity that originally called checkEula()\r
- // or checkNewVersion()\r
- Intent i;\r
- if (mLaunchIntent != null) {\r
- i = mLaunchIntent;\r
- \r
- // Android 2.3: category LAUNCHER needs to be removed,\r
- // otherwise main activity is not called.\r
- i.removeCategory(Intent.CATEGORY_LAUNCHER);\r
- } else {\r
- i = new Intent();\r
- i.setClassName(mLaunchPackage, mLaunchClass);\r
- }\r
- i.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);\r
- startActivity(i);\r
- finish();\r
- }\r
- \r
- /**\r
- * Refuse EULA.\r
- */\r
- void refuse() {\r
- finish();\r
- }\r
-\r
- \r
- /**\r
- * Read license from raw resource.\r
- * @param resourceid ID of the raw resource.\r
- * @return\r
- */\r
- String readTextFromRawResource(int resourceid, boolean preserveLineBreaks) {\r
-\r
- // Retrieve license from resource:\r
- String license = "";\r
- Resources resources = getResources();\r
- \r
- //Read in the license file as a big String\r
- BufferedReader in\r
- = new BufferedReader(new InputStreamReader(\r
- resources.openRawResource(resourceid)));\r
- String line;\r
- StringBuilder sb = new StringBuilder();\r
- try {\r
- while ((line = in.readLine()) != null) { // Read line per line.\r
- if (TextUtils.isEmpty(line)) {\r
- // Empty line: Leave line break\r
- sb.append("\n\n");\r
- } else {\r
- sb.append(line);\r
- if (preserveLineBreaks) {\r
- sb.append("\n");\r
- } else {\r
- sb.append(" ");\r
- }\r
- }\r
- }\r
- license = sb.toString();\r
- } catch (IOException e) {\r
- //Should not happen.\r
- e.printStackTrace();\r
- }\r
- \r
- \r
- return license;\r
- }\r
-}\r