Android Open Source - MaterialManager Remote Connection Dialog






From Project

Back to project page MaterialManager.

License

The source code is released under:

There is no license, someone decided to pretty much republish Cabinet with no credit so I?m taking away the license altogether.

If you think the Android project MaterialManager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.afollestad.cabinet.fragments;
//from  ww w .j  av a  2 s.  c  o m
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.afollestad.cabinet.R;
import com.afollestad.cabinet.sftp.SftpClient;
import com.afollestad.cabinet.ui.DrawerActivity;
import com.afollestad.cabinet.utils.Pins;
import com.afollestad.cabinet.utils.ThemeUtils;
import com.afollestad.cabinet.utils.Utils;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;

public class RemoteConnectionDialog implements SftpClient.CompletionCallback {

    public RemoteConnectionDialog(Activity context) {
        mContext = context;
    }

    private Activity mContext;
    private SftpClient client;
    private MaterialDialog dialog;
    private Button testConnection;
    private TextView host;
    private TextView port;
    private TextView user;
    private TextView pass;

    public void show() {
        Utils.lockOrientation(mContext);
        View view = mContext.getLayoutInflater().inflate(R.layout.dialog_add_remote, null);
        testConnection = (Button) view.findViewById(R.id.testConnection);
        host = (TextView) view.findViewById(R.id.host);
        port = (TextView) view.findViewById(R.id.port);
        user = (TextView) view.findViewById(R.id.user);
        pass = (TextView) view.findViewById(R.id.pass);

        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                if (host.getText().toString().trim().length() > 0 &&
                        port.getText().toString().trim().length() > 0 &&
                        user.getText().toString().trim().length() > 0 &&
                        pass.getText().toString().trim().length() > 0) {
                    dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                    testConnection.setEnabled(true);
                } else {
                    dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
                    testConnection.setEnabled(false);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        };
        host.addTextChangedListener(watcher);
        port.addTextChangedListener(watcher);
        user.addTextChangedListener(watcher);
        pass.addTextChangedListener(watcher);
        testConnection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                view.setEnabled(false);
                host.setEnabled(false);
                port.setEnabled(false);
                user.setEnabled(false);
                pass.setEnabled(false);
                client = new SftpClient()
                        .setHost(host.getText().toString().trim(), Integer.parseInt(port.getText().toString().trim()))
                        .setUser(user.getText().toString())
                        .setPass(pass.getText().toString())
                        .connect(RemoteConnectionDialog.this);
            }
        });

        dialog = new MaterialDialog.Builder(mContext)
                .positiveColorRes(R.color.cabinet_accent_color)
                .theme(ThemeUtils.getDialogTheme(mContext))
                .title(R.string.new_remote_connection)
                .customView(view)
                .cancelable(false)
                .positiveText(android.R.string.ok)
                .negativeText(android.R.string.cancel)
                .callback(new MaterialDialog.Callback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        Utils.unlockOrientation(mContext);
                        onSubmit();
                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        Utils.unlockOrientation(mContext);
                        if (client != null && client.isConnected()) client.disconnect();
                        client = null;
                    }
                }).build();
        dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
        dialog.show();
    }

    @Override
    public void onComplete() {
        if (client == null) return;
        client.disconnect();
        client = null;
        mContext.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                testConnection.setEnabled(true);
                host.setEnabled(true);
                port.setEnabled(true);
                user.setEnabled(true);
                pass.setEnabled(true);
                testConnection.setText(R.string.connection_successful);
            }
        });
    }

    @Override
    public void onError(final Exception e) {
        if (client == null) return;
        client = null;
        mContext.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                testConnection.setEnabled(true);
                host.setEnabled(true);
                port.setEnabled(true);
                user.setEnabled(true);
                pass.setEnabled(true);
                testConnection.setText(e.getMessage());
            }
        });
    }

    protected void onSubmit() {
        if (client != null) {
            client.disconnect();
            client = null;
        }
        Pins.add(mContext, new Pins.Item(
                host.getText().toString().trim(),
                Integer.parseInt(port.getText().toString().trim()),
                user.getText().toString().trim(),
                pass.getText().toString().trim(),
                "/"
        ));
        ((DrawerActivity) mContext).reloadNavDrawer(true);
    }
}




Java Source Code List

com.afollestad.cabinet.App.java
com.afollestad.cabinet.ApplicationTest.java
com.afollestad.cabinet.adapters.FileAdapter.java
com.afollestad.cabinet.adapters.NavigationDrawerAdapter.java
com.afollestad.cabinet.cab.CopyCab.java
com.afollestad.cabinet.cab.CutCab.java
com.afollestad.cabinet.cab.MainCab.java
com.afollestad.cabinet.cab.PickerCab.java
com.afollestad.cabinet.cab.base.BaseCab.java
com.afollestad.cabinet.cab.base.BaseFileCab.java
com.afollestad.cabinet.comparators.AlphabeticalComparator.java
com.afollestad.cabinet.comparators.ExtensionComparator.java
com.afollestad.cabinet.comparators.FoldersFirstComparator.java
com.afollestad.cabinet.comparators.HighLowSizeComparator.java
com.afollestad.cabinet.comparators.LastModifiedComparator.java
com.afollestad.cabinet.comparators.LowHighSizeComparator.java
com.afollestad.cabinet.file.CloudFile.java
com.afollestad.cabinet.file.LocalFile.java
com.afollestad.cabinet.file.Remote.java
com.afollestad.cabinet.file.base.FileFilter.java
com.afollestad.cabinet.file.base.File.java
com.afollestad.cabinet.file.root.LsParser.java
com.afollestad.cabinet.file.root.LsTokenizer.java
com.afollestad.cabinet.file.root.RootFile.java
com.afollestad.cabinet.fragments.AboutDialog.java
com.afollestad.cabinet.fragments.DetailsDialog.java
com.afollestad.cabinet.fragments.DirectoryFragment.java
com.afollestad.cabinet.fragments.NavigationDrawerFragment.java
com.afollestad.cabinet.fragments.RemoteConnectionDialog.java
com.afollestad.cabinet.fragments.WelcomeFragment.java
com.afollestad.cabinet.services.NetworkService.java
com.afollestad.cabinet.sftp.FileNotExistsException.java
com.afollestad.cabinet.sftp.SftpClient.java
com.afollestad.cabinet.ui.DrawerActivity.java
com.afollestad.cabinet.ui.SettingsActivity.java
com.afollestad.cabinet.ui.TextEditor.java
com.afollestad.cabinet.ui.base.NetworkedActivity.java
com.afollestad.cabinet.ui.base.ThemableActivity.java
com.afollestad.cabinet.utils.APKIconDownloader.java
com.afollestad.cabinet.utils.PauseOnScrollListener.java
com.afollestad.cabinet.utils.Perm.java
com.afollestad.cabinet.utils.Pins.java
com.afollestad.cabinet.utils.StorageHelper.java
com.afollestad.cabinet.utils.ThemeUtils.java
com.afollestad.cabinet.utils.TimeUtils.java
com.afollestad.cabinet.utils.Utils.java
com.afollestad.cabinet.zip.Unzipper.java
com.afollestad.cabinet.zip.Zipper.java
eu.chainfire.libsuperuser.ApplicationTest.java
eu.chainfire.libsuperuser.Application.java
eu.chainfire.libsuperuser.Debug.java
eu.chainfire.libsuperuser.HideOverlaysReceiver.java
eu.chainfire.libsuperuser.ShellNotClosedException.java
eu.chainfire.libsuperuser.ShellOnMainThreadException.java
eu.chainfire.libsuperuser.Shell.java
eu.chainfire.libsuperuser.StreamGobbler.java