Search in sources :

Example 1 with Settings

use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.

the class PanicResponderActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    if (intent != null && PANIC_TRIGGER_ACTION.equals(intent.getAction())) {
        Settings settings = new Settings(this);
        Set<String> response = settings.getPanicResponse();
        if (response.contains("accounts")) {
            DatabaseHelper.wipeDatabase(this);
            KeyStoreHelper.wipeKeys(this);
        }
        if (response.contains("settings"))
            settings.clear(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        finishAndRemoveTask();
    } else {
        finish();
    }
}
Also used : Intent(android.content.Intent) Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Example 2 with Settings

use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.

the class AboutFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_about, container, false);
    settings = new Settings(getActivity());
    ColorFilter filter = Tools.getThemeColorFilter(getActivity(), android.R.attr.textColorSecondary);
    for (int i : imageResources) {
        ImageView imgView = v.findViewById(i);
        imgView.getDrawable().setColorFilter(filter);
    }
    String versionName = "";
    try {
        PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        versionName = packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    LinearLayout versionLayout = v.findViewById(R.id.about_layout_version);
    versionLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            long thisTap = System.currentTimeMillis();
            if (thisTap - lastTap < 500) {
                taps = taps + 1;
                if (currentToast != null && taps <= 7)
                    currentToast.cancel();
                if (taps >= 3 && taps <= 7)
                    currentToast = Toast.makeText(getActivity(), String.valueOf(taps), Toast.LENGTH_SHORT);
                if (taps == 7) {
                    if (settings.getSpecialFeatures())
                        currentToast = Toast.makeText(getActivity(), R.string.about_toast_special_features_enabled, Toast.LENGTH_LONG);
                    else
                        enableSpecialFeatures();
                }
                if (currentToast != null)
                    currentToast.show();
            } else {
                taps = 0;
            }
            lastTap = thisTap;
        }
    });
    TextView version = v.findViewById(R.id.about_text_version);
    version.setText(versionName);
    LinearLayout license = v.findViewById(R.id.about_layout_license);
    LinearLayout changelog = v.findViewById(R.id.about_layout_changelog);
    LinearLayout source = v.findViewById(R.id.about_layout_source);
    license.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(MIT_URI);
        }
    });
    changelog.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(CHANGELOG_URI);
        }
    });
    source.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(GITHUB_URI);
        }
    });
    LinearLayout author1Layout = v.findViewById(R.id.aboutLayoutAuthor1);
    TextView author1Donate = v.findViewById(R.id.about_author1_extra);
    author1Layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(AUTHOR1_GITHUB);
        }
    });
    author1Donate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            try {
                openURI(AUTHOR1_EXTRA);
            } catch (Exception ignored) {
                copyToClipboard(AUTHOR1_EXTRA);
            }
        }
    });
    LinearLayout author2Layout = v.findViewById(R.id.aboutLayoutAuthor2);
    TextView author2Donate = v.findViewById(R.id.about_author2_extra);
    author2Layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(AUTHOR2_GITHUB);
        }
    });
    author2Donate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            try {
                openURI(AUTHOR2_EXTRA);
            } catch (Exception ignored) {
                copyToClipboard(AUTHOR2_EXTRA);
            }
        }
    });
    LinearLayout authorOrigialLayout = v.findViewById(R.id.aboutLayoutOriginalAuthor);
    TextView authorOriginalApp = v.findViewById(R.id.about_author_original_extra);
    authorOrigialLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(AUTHOR_ORIGINAL_GITHUB);
        }
    });
    authorOriginalApp.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            try {
                openURI(AUTHOR_ORIGINAL_EXTRA);
            } catch (Exception ignored) {
                copyToClipboard(AUTHOR_ORIGINAL_EXTRA);
            }
        }
    });
    LinearLayout contributors = v.findViewById(R.id.about_layout_contributors);
    LinearLayout translators = v.findViewById(R.id.about_layout_translators);
    contributors.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(CONTRIBUTORS_URI);
        }
    });
    translators.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(TRANSLATORS_URI);
        }
    });
    LinearLayout bugReport = v.findViewById(R.id.about_layout_bugs);
    LinearLayout translate = v.findViewById(R.id.about_layout_translate);
    bugReport.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(BUGREPORT_URI);
        }
    });
    translate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openURI(TRANSLATE_URI);
        }
    });
    return v;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ColorFilter(android.graphics.ColorFilter) PackageManager(android.content.pm.PackageManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Settings(org.shadowice.flocke.andotp.Utilities.Settings) LinearLayout(android.widget.LinearLayout)

Example 3 with Settings

use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.

the class EntryViewHolder method updateValues.

public void updateValues(Entry entry) {
    Settings settings = new Settings(context);
    if (entry.getType() == Entry.OTPType.HOTP) {
        counterLayout.setVisibility(View.VISIBLE);
        counter.setText(String.format(Locale.ENGLISH, "%d", entry.getCounter()));
    } else {
        counterLayout.setVisibility(View.GONE);
    }
    final String tokenFormatted = Tools.formatToken(entry.getCurrentOTP(), settings.getTokenSplitGroupSize());
    this.label.setText(entry.getLabel());
    value.setText(tokenFormatted);
    // save the unformatted token to the tag of this TextView for copy/paste
    value.setTag(entry.getCurrentOTP());
    List<String> tags = entry.getTags();
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < tags.size(); i++) {
        stringBuilder.append(tags.get(i));
        if (i < tags.size() - 1) {
            stringBuilder.append(", ");
        }
    }
    this.tags.setText(stringBuilder.toString());
    if (!tags.isEmpty()) {
        this.tags.setVisibility(View.VISIBLE);
    } else {
        this.tags.setVisibility(View.GONE);
    }
    thumbnailFrame.setVisibility(settings.getThumbnailVisible() ? View.VISIBLE : View.GONE);
    int thumbnailSize = settings.getThumbnailSize();
    if (settings.getThumbnailVisible()) {
        thumbnailImg.setImageBitmap(EntryThumbnail.getThumbnailGraphic(context, entry.getLabel(), thumbnailSize, entry.getThumbnail()));
    }
    if (this.tapToReveal) {
        if (entry.isVisible()) {
            valueLayout.setVisibility(View.VISIBLE);
            coverLayout.setVisibility(View.GONE);
            visibleImg.setVisibility(View.GONE);
        } else {
            valueLayout.setVisibility(View.GONE);
            coverLayout.setVisibility(View.VISIBLE);
            visibleImg.setVisibility(View.VISIBLE);
        }
    }
}
Also used : Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Example 4 with Settings

use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.

the class PlainTextBackupBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Settings settings = new Settings(context);
    if (settings.isPlainTextBackupBroadcastEnabled()) {
        if (!canSaveBackup(context))
            return;
        Uri savePath = Tools.buildUri(settings.getBackupDir(), FileHelper.backupFilename(context, Constants.BackupType.PLAIN_TEXT));
        SecretKey encryptionKey = null;
        if (settings.getEncryption() == Constants.EncryptionType.KEYSTORE) {
            encryptionKey = KeyStoreHelper.loadEncryptionKeyFromKeyStore(context, false);
        } else {
            NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_custom_encryption_failed);
            return;
        }
        if (Tools.isExternalStorageWritable()) {
            ArrayList<Entry> entries = DatabaseHelper.loadDatabase(context, encryptionKey);
            if (FileHelper.writeStringToFile(context, savePath, DatabaseHelper.entriesToString(entries))) {
                NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_SUCCESS, R.string.backup_receiver_title_backup_success, savePath.getPath());
            } else {
                NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_export_failed);
            }
        } else {
            NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_storage_not_accessible);
        }
    } else {
        NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_plain_disabled);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) Entry(org.shadowice.flocke.andotp.Database.Entry) Uri(android.net.Uri) Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Example 5 with Settings

use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.

the class IntroScreenActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = new Settings(this);
    encryptionFragment = new EncryptionFragment();
    authenticationFragment = new AuthenticationFragment();
    encryptionFragment.setEncryptionChangedCallback(new EncryptionFragment.EncryptionChangedCallback() {

        @Override
        public void onEncryptionChanged(Constants.EncryptionType newEncryptionType) {
            authenticationFragment.updateEncryptionType(newEncryptionType);
        }
    });
    setButtonBackFunction(BUTTON_BACK_FUNCTION_BACK);
    addSlide(new SimpleSlide.Builder().title(R.string.intro_slide1_title).description(R.string.intro_slide1_desc).background(R.color.colorPrimary).backgroundDark(R.color.colorPrimaryDark).canGoBackward(false).scrollable(false).build());
    addSlide(new FragmentSlide.Builder().background(R.color.colorPrimary).backgroundDark(R.color.colorPrimaryDark).fragment(encryptionFragment).build());
    // Tell the fragment where it is located
    authenticationFragment.setSlidePos(getSlides().size());
    addSlide(new FragmentSlide.Builder().background(R.color.colorPrimary).backgroundDark(R.color.colorPrimaryDark).fragment(authenticationFragment).build());
    addSlide(new SimpleSlide.Builder().title(R.string.intro_slide4_title).description(R.string.intro_slide4_desc).background(R.color.colorPrimary).backgroundDark(R.color.colorPrimaryDark).scrollable(false).build());
    addOnNavigationBlockedListener(new OnNavigationBlockedListener() {

        @Override
        public void onNavigationBlocked(int position, int direction) {
            if (position == 2)
                authenticationFragment.flashWarning();
        }
    });
    addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            if (position == 3)
                saveSettings();
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
Also used : FragmentSlide(com.heinrichreimersoftware.materialintro.slide.FragmentSlide) OnNavigationBlockedListener(com.heinrichreimersoftware.materialintro.app.OnNavigationBlockedListener) Constants(org.shadowice.flocke.andotp.Utilities.Constants) ViewPager(android.support.v4.view.ViewPager) SimpleSlide(com.heinrichreimersoftware.materialintro.slide.SimpleSlide) Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Aggregations

Settings (org.shadowice.flocke.andotp.Utilities.Settings)8 Uri (android.net.Uri)2 SecretKey (javax.crypto.SecretKey)2 Entry (org.shadowice.flocke.andotp.Database.Entry)2 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ColorFilter (android.graphics.ColorFilter)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 OnNavigationBlockedListener (com.heinrichreimersoftware.materialintro.app.OnNavigationBlockedListener)1 FragmentSlide (com.heinrichreimersoftware.materialintro.slide.FragmentSlide)1 SimpleSlide (com.heinrichreimersoftware.materialintro.slide.SimpleSlide)1 File (java.io.File)1 Constants (org.shadowice.flocke.andotp.Utilities.Constants)1