错误:找不到android.support.v7.app.ActionBarActivity的ActionBarActivity类文件

时间:2018-12-25 08:03:30

标签: android android-studio material-design settings android-appcompat

package com.infonium.password.ui.activities;


import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.provider.Settings;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatCallback;
import android.support.v7.app.AppCompatDialog;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.infonium.password.events.CryptoEvent;
import com.infonium.password.events.DBExportEvent;
import com.infonium.password.runnable.DBExportRunnable;
import com.infonium.password.utils.AppConstants;
import com.infonium.password.utils.ResUtil;
import com.infonium.password.utils.UserDefault;
import com.kenumir.materialsettings.MaterialSettings;
import com.kenumir.materialsettings.items.CheckboxItem;
import com.kenumir.materialsettings.items.HeaderItem;
import com.kenumir.materialsettings.items.SwitcherItem;
import com.kenumir.materialsettings.items.TextItem;
import com.kenumir.materialsettings.storage.StorageInterface;

import de.greenrobot.event.EventBus;
import com.infonium.password.R;
import com.infonium.password.adapters.SettingsSpinnerAdapter;
import com.infonium.password.db.Account;
import com.infonium.password.db.AccountHelper;
import com.infonium.password.events.CryptoEvent;
import com.infonium.password.events.DBExportEvent;
import com.infonium.password.runnable.ChangePasswordRunnable;
import com.infonium.password.runnable.DBExportRunnable;
import com.infonium.password.ui.views.SelectorItem;
import com.infonium.password.utils.AppConstants;
import com.infonium.password.utils.CryptoUtil;
import com.infonium.password.utils.ResUtil;
import com.infonium.password.utils.UserDefault;

import static android.os.Build.VERSION_CODES.M;
import android.support.v7.widget.Toolbar;


/**
 * Created by bob.sun on 16/6/21.
 */
public class SettingsActivity extends MaterialSettings {

    public static final int RequestCodeSetMainPassword = 0x700;
    private TextItem quickSwitcher;
    private SelectorItem selectorItem;
    private AppCompatDialog dialog;
    private boolean didClickedChangeMaster;
    private MaterialSettings ms;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(R.string.settings);

        //ms = new MaterialSettings(this);

        EventBus.getDefault().register(this);

        addItem(new HeaderItem(this).setTitle(getString(R.string.security)));
        addItem(new CheckboxItem(this, UserDefault.kNeedPasswordWhenLaunch).setTitle(getString(R.string.need_password_when_launch)).setOnCheckedChangeListener(new CheckboxItem.OnCheckedChangeListener() {
            @Override
            public void onCheckedChange(CheckboxItem cbi, boolean isChecked) {
                UserDefault.getInstance(null).setNeedPasswordWhenLaunch(isChecked);
            }
        }));

        String title = UserDefault.getInstance(null).hasQuickPassword() ? getString(R.string.disable_gesture_lock) : getString(R.string.enable_gesture_lock);

        quickSwitcher = new TextItem(this, "quick_pass").setTitle(title).setOnclick(new TextItem.OnClickListener() {
            @Override
            public void onClick(TextItem textItem) {
                if (UserDefault.getInstance(null).hasQuickPassword()) {
                    UserDefault.getInstance(null).clearQuickPassword();
                    quickSwitcher.updateTitle(getString(R.string.enable_gesture_lock));
                } else {
                    Intent intent = new Intent(SettingsActivity.this, SetQuickPasswordActivity.class);
                    intent.putExtra("type", SetQuickPasswordActivity.ShowTypeSet);
                    startActivityForResult(intent, RequestCodeSetMainPassword);
                }
            }
        });
        addItem(quickSwitcher);

        didClickedChangeMaster = false;
        addItem(new TextItem(this, "change_password").setTitle(getString(R.string.change_master_password)).setOnclick(new TextItem.OnClickListener() {
            @Override
            public void onClick(TextItem textItem) {
                didClickedChangeMaster = true;
                startActivity(new Intent(SettingsActivity.this, AuthorizeActivity.class));
            }
        }));


        addItem(new HeaderItem(this).setTitle(getString(R.string.puff_secure_keyboard)));
        addItem(new TextItem(this, "ime").setTitle(getString(R.string.enable_puff_secure_keyboard)). setOnclick(new TextItem.OnClickListener() {
            @Override
            public void onClick(TextItem textItem) {
                startActivity(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS));
                Toast.makeText(SettingsActivity.this, getString(R.string.please_enable_puf_ime), Toast.LENGTH_LONG).show();
            }
        }));


        addItem(new HeaderItem(this).setTitle(getString(R.string.database)));
        addItem(new TextItem(this, "database").setTitle(getString(R.string.export_database))
                .setSubtitle(getString(com.infonium.password.R.string.database_file_can_be_used))
                .setOnclick(new TextItem.OnClickListener() {
            @Override
            public void onClick(TextItem textItem) {

                new AlertDialog.Builder(SettingsActivity.this).setTitle(getString(R.string.export_database))
                        .setMessage(com.infonium.password.R.string.confrim_export_database)
                        .setCancelable(false)
                        .setPositiveButton(com.infonium.password.R.string.yes, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface d, int which) {
                                d.dismiss();
                                dialog = ResUtil.getInstance(null).showProgressbar(SettingsActivity.this);
                                DBExportRunnable runnable = new DBExportRunnable(SettingsActivity.this);
                                new Thread(runnable).run();
                            }
                        })
                        .setNegativeButton(com.infonium.password.R.string.cancel, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).show();

            }
        }));


        addItem(new HeaderItem(this).setTitle(getString(R.string.about)));
        addItem(new TextItem(this, "about").setTitle(getResources().getString(R.string.about_puff_title)).setOnclick(new TextItem.OnClickListener() {
            @Override
            public void onClick(TextItem textItem) {
                startActivity(new Intent(SettingsActivity.this, AboutActivity.class));
            }
        }));

    }

    @Override
    public StorageInterface initStorageInterface() {
        return UserDefault.getInstance(this);
    }


    @Override
    public void onResume() {
        super.onResume();
        quickSwitcher.updateTitle(UserDefault.getInstance(null).hasQuickPassword()
                ? getString(R.string.disable_gesture_lock)
                : getString(R.string.enable_gesture_lock));
    }

    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }


    public void onEventMainThread(Object event) {
//        if (!(event instanceof DBExportEvent)) {
//            return;
//        }
        if (event instanceof CryptoEvent && didClickedChangeMaster) {
            didClickedChangeMaster = false;
            if (((CryptoEvent) event).getType() == AppConstants.TYPE_MASTERPWD) {
                Intent intent = new Intent(SettingsActivity.this, SetMasterPasswordActivity.class);
                intent.putExtra("showMode", SetMasterPasswordActivity.ShowMode.ShowModeChange);
                intent.putExtra("oldPassword", ((CryptoEvent) event).getResult());
                UserDefault.getInstance(null).clearQuickPassword();
                AccountHelper.getInstance(null).clearQuickAccount();
                startActivity(intent);
            }
            return;
        }
        if (dialog != null) {
            dialog.dismiss();
        }
        if (!(event instanceof DBExportEvent)) {
            return;
        }
        DBExportEvent dbExportEvent = (DBExportEvent) event;
        if (dbExportEvent.success) {
            new AlertDialog.Builder(this)
                    .setTitle(R.string.success_em)
                    .setMessage(getString(R.string.database_exported_to)
                                    + dbExportEvent.filePath)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    })
                    .show();
        } else {
            new AlertDialog.Builder(this).setTitle(R.string.failed_em)
                    .setMessage(R.string.please_try_again)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    })
                    .show();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode != RequestCodeSetMainPassword ) {
            return;
        }
        if (resultCode != RESULT_OK) {
            UserDefault.getInstance(null).clearQuickPassword();
        } else {
            UserDefault.getInstance(null).setHasQuickPassword();
        }
    }

}

当我将AppcompatActivity扩展为超级类时,除MaterialSettings的addItem这是抽象类之外的错误被消除。

当我将MaterialSettings扩展为超级类时,会产生上述错误。

我正在设计Android中的“设置页面”。还在外部工具中尝试了javah,并且将appcompact的最新版本更改为28. +和27.1.1,但仍未解决错误。

请指导我在何处以及需要更新或更改什么。

继承AppCompatActivity-错误看起来像这样
Inheriting AppCompatActivity - Error Looks Like This

继承MaterialSettings-错误看起来像这样 Inheriting MaterialSettings - Error Looks Like This

1 个答案:

答案 0 :(得分:1)

“材料设置”是从ActionBarActivity扩展过来的第三方库。但是,ActionBarActivity已过时,不应再使用。为了支持活动中的操作栏,您应该从AppCompatActivity开始。

我建议您不要将第三方,未维护的库用于此目的。而是实施您自己的设置屏幕。如果您不知道该怎么做,可以在网上找到很多教程。供您参考:https://medium.com/@JakobUlbrich/building-a-settings-screen-for-android-part-1-5959aa49337c