Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5def6c71 authored by Abhisek Devkota's avatar Abhisek Devkota
Browse files

Add CM Legal (2 of 2)

New settings activity for CM Legal info. Needs vendor/cm piece.

PS2: Manual Rebase

Cherrypick from CM-11

Change-Id: I6238afe23f957a571d29c186447b455ecb7a186e
parent c2514c1b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -753,6 +753,16 @@
            </intent-filter>
        </activity>

        <activity android:name="SettingsCMLicenseActivity"
                android:label="@string/settings_cmlicense_activity_title"
                android:theme="@android:style/Theme.Holo.Panel"
                android:configChanges="orientation|screenSize">
            <intent-filter>
                <action android:name="android.settings.CMLICENSE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity android:name="SettingsSafetyLegalActivity"
                android:label="@string/settings_safetylegal_activity_title"
                android:theme="@*android:style/Theme.Holo.Dialog.Alert">
+5 −0
Original line number Diff line number Diff line
@@ -1043,4 +1043,9 @@ two in order to insert additional control points. \'Remove\' deletes the selecte
    <string name="whisperpush_registration_summary">Register for WhisperPush to enable encrypted SMS</string>
    <string name="whisperpush_identitykey_title">Review identity keys</string>

    <!-- CM Legal -->
    <string name="cmlicense_title">CyanogenMod Legal</string>
    <string name="settings_cmlicense_activity_title">CyanogenMod Legal</string>
    <string name="settings_cmlicense_activity_unreachable">You don\'t have a data connection. To view this information now, go to %s from any computer connected to the Internet.</string>

</resources>
+7 −0
Original line number Diff line number Diff line
@@ -89,6 +89,13 @@
                <intent android:action="android.settings.LICENSE" />
            </PreferenceScreen>

            <!-- CM License information -->
            <PreferenceScreen
                    android:key="cmlicense"
                    android:title="@string/cmlicense_title">
                <intent android:action="android.settings.CMLICENSE" />
            </PreferenceScreen>

            <!-- Terms and conditions -->
            <PreferenceScreen
                    android:key="terms"
+142 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source 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 com.android.settings;

import android.app.AlertDialog;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemProperties;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import android.content.DialogInterface;

/**
 * The "dialog" that shows from "CyanogenMod Legal" in the Settings app.
 */
public class SettingsCMLicenseActivity extends AlertActivity
        implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener {
    private static final String PROPERTY_CMLICENSE_URL = "ro.cmlegal.url";

    private WebView mWebView;

    private AlertDialog mErrorDialog = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String userCMLicenseUrl = SystemProperties.get(PROPERTY_CMLICENSE_URL);

        final Configuration configuration = getResources().getConfiguration();
        final String language = configuration.locale.getLanguage();
        final String country = configuration.locale.getCountry();

        //String loc = String.format("locale=%s-%s", language, country);

        userCMLicenseUrl = String.format(userCMLicenseUrl);

        mWebView = new WebView(this);

        // Begin accessing
        mWebView.getSettings().setJavaScriptEnabled(true);
        if (savedInstanceState == null) {
            mWebView.loadUrl(userCMLicenseUrl);
        } else {
            mWebView.restoreState(savedInstanceState);
        }
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                // Change from 'Loading...' to the real title
                mAlert.setTitle(getString(R.string.settings_cmlicense_activity_title));
            }

            @Override
            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                showErrorAndFinish(failingUrl);
            }
        });

        final AlertController.AlertParams p = mAlertParams;
        p.mTitle = getString(R.string.settings_license_activity_loading);
        p.mView = mWebView;
        p.mForceInverseBackground = true;
        setupAlert();
    }

    private void showErrorAndFinish(String url) {
        if (mErrorDialog == null) {
            mErrorDialog = new AlertDialog.Builder(this)
                    .setTitle(R.string.settings_cmlicense_activity_title)
                    .setPositiveButton(android.R.string.ok, this)
                    .setOnCancelListener(this)
                    .setCancelable(true)
                    .create();
        } else {
            if (mErrorDialog.isShowing()) {
                mErrorDialog.dismiss();
            }
        }
        mErrorDialog.setMessage(getResources()
                .getString(R.string.settings_cmlicense_activity_unreachable, url));
        mErrorDialog.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mErrorDialog != null) {
            mErrorDialog.dismiss();
            mErrorDialog = null;
        }
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if (mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
        }
        return super.dispatchKeyEvent(event);
    }

    public void onClick(DialogInterface dialog, int whichButton) {
        finish();
    }

    public void onCancel(DialogInterface dialog) {
        finish();
    }

    @Override
    public void onSaveInstanceState(Bundle icicle) {
        mWebView.saveState(icicle);
        super.onSaveInstanceState(icicle);
    }
}