blob: a669c6781140fc32672a31358c8cc9c052e8afc0 [file] [log] [blame]
Zachary Kuznia5adcb3d2015-08-07 16:32:28 -07001/*
2 * Copyright (C) 2015 The Android Open Source 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
17package com.android.settings;
18
19import android.app.Activity;
20import android.content.ActivityNotFoundException;
21import android.content.Intent;
22import android.content.res.Resources;
23import android.net.Uri;
24import android.os.Bundle;
Zachary Kuznia5adcb3d2015-08-07 16:32:28 -070025import android.util.Log;
26import android.widget.Toast;
27
28import java.io.File;
29
30/**
31 * The "dialog" that shows from "Manual" in the Settings app.
32 */
33public class ManualDisplayActivity extends Activity {
34 private static final String TAG = "SettingsManualActivity";
35
Inseob Kim4d56f112018-12-19 12:05:22 +090036 private static final String MANUAL_PATH = "/system/etc/MANUAL.html.gz";
Zachary Kuznia5adcb3d2015-08-07 16:32:28 -070037
38 @Override
39 protected void onCreate(Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
41 Resources resources = getResources();
42
43 if (!resources.getBoolean(R.bool.config_show_manual)) {
44 finish(); // No manual to display for this device
45 }
46
Inseob Kim4d56f112018-12-19 12:05:22 +090047 final File file = new File(MANUAL_PATH);
Zachary Kuznia5adcb3d2015-08-07 16:32:28 -070048 if (!file.exists() || file.length() == 0) {
Inseob Kim4d56f112018-12-19 12:05:22 +090049 Log.e(TAG, "Manual file " + MANUAL_PATH + " does not exist");
Zachary Kuznia5adcb3d2015-08-07 16:32:28 -070050 showErrorAndFinish();
51 return;
52 }
53
54 final Intent intent = new Intent(Intent.ACTION_VIEW);
55 intent.setDataAndType(Uri.fromFile(file), "text/html");
56
57 intent.putExtra(Intent.EXTRA_TITLE, getString(R.string.settings_manual_activity_title));
58 intent.addCategory(Intent.CATEGORY_DEFAULT);
59 intent.setPackage("com.android.htmlviewer");
60
61 try {
62 startActivity(intent);
63 finish();
64 } catch (ActivityNotFoundException e) {
65 Log.e(TAG, "Failed to find viewer", e);
66 showErrorAndFinish();
67 }
68 }
69
70 private void showErrorAndFinish() {
71 Toast.makeText(this, R.string.settings_manual_activity_unavailable, Toast.LENGTH_LONG)
72 .show();
73 finish();
74 }
75}