Android Open Source - AndroidCloud Mkdir Task






From Project

Back to project page AndroidCloud.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidCloud 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

/*
 * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *// w ww.j a  v a 2 s.c o  m
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file 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.twlkyao.kuaipan;

import com.twlkyao.androidcloud.R;

import cn.kuaipan.android.openapi.KuaipanAPI;
import cn.kuaipan.android.sdk.exception.KscException;
import cn.kuaipan.android.sdk.exception.KscRuntimeException;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

public class MkdirTask {

    private static final String TAG = "MkdirTask";

    private ProgressDialog dialog;
    private Activity activity;

    public MkdirTask(Activity activity) {
        this.activity = activity;
    }

    public void showProgressDialog(String msg) {
        dialog = new ProgressDialog(activity);
        dialog.setMessage(msg);
        dialog.setCancelable(false);
        dialog.show();
    }

    public void hideProgressDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    protected void displayAlert(String title, String message) {

        AlertDialog.Builder confirm = new AlertDialog.Builder(activity);
        confirm.setTitle(title);
        confirm.setMessage(message);

        confirm.setNegativeButton(activity.getString(R.string.ok),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {

                        dialog.dismiss();
                    }
                });

        confirm.show().show();
    }

    protected void displayErrorAlert(String title, String message) {

        AlertDialog.Builder confirm = new AlertDialog.Builder(activity);
        confirm.setTitle(title);
        confirm.setMessage(message);

        confirm.setNegativeButton(activity.getString(R.string.ok),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {

                        activity.finish();
                    }
                });

        confirm.show().show();
    }

    public void start(RequestBase req) {
        new Mkdir().execute(req);
    }

    private class Mkdir extends AsyncTask<RequestBase, Void, ResultBase> {

        protected void onPreExecute() {
            showProgressDialog("create directory");
        }

        protected ResultBase doInBackground(RequestBase... params) {
            Log.v(TAG, "====mkdir task doInBackground====");
            if (params == null || params.length != 1) {
                return null;
            }

            final RequestBase req = (RequestBase) params[0];
            final String remotepath = req.getRemotePath();
            final KuaipanAPI api = req.getApi();

            ResultBase result = new ResultBase();

            result.setRemotePath(remotepath);
            Log.v(TAG, "remotepath:["+remotepath+"], you want to create");
            try {
                api.mkdirs(remotepath);
            } catch (KscRuntimeException e) {
                e.printStackTrace();
                result.setErrorMsg(e.toString());
                Log.v(TAG, "KscRuntimeException:"+e.toString());
            } catch (KscException e) {
                e.printStackTrace();
                result.setErrorMsg(e.toString());
                Log.v(TAG, "KscException:"+e.toString());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            Log.v(TAG, "====mkdir task doInBackground end====");
            return result;

        }

        protected void onPostExecute(ResultBase result) {

            hideProgressDialog();
            if (result == null) {
                Toast.makeText(activity,
                        "mkdir failed",
                        Toast.LENGTH_LONG).show();
                return;
            }

            if (result.getErrorMsg() != null) {
                displayErrorAlert("Mkdir",
                        result.getErrorMsg());
            } else {
                displayAlert("Mkdir Task Finish",
                        "Mkdir file [" + result.getRemotePath() + "] Successed!");
            }
        }
    }
}




Java Source Code List

com.twlkyao.androidcloud.ApkValidate.java
com.twlkyao.androidcloud.ContactsActivity.java
com.twlkyao.androidcloud.FileListAdapter.java
com.twlkyao.androidcloud.KuaipanDiskActivity.java
com.twlkyao.androidcloud.LoginActivity.java
com.twlkyao.androidcloud.MainActivity.java
com.twlkyao.androidcloud.MessageActivity.java
com.twlkyao.androidcloud.ObserverService.java
com.twlkyao.androidcloud.RegisterActivity.java
com.twlkyao.androidcloud.SetEncryptLevelActivity.java
com.twlkyao.androidcloud.StartUpReceiver.java
com.twlkyao.dao.DaoMaster.java
com.twlkyao.dao.DaoSession.java
com.twlkyao.dao.FileInfoDao.java
com.twlkyao.dao.FileInfo.java
com.twlkyao.kuaipan.DownloadTask.java
com.twlkyao.kuaipan.MkdirTask.java
com.twlkyao.kuaipan.RequestBase.java
com.twlkyao.kuaipan.ResultBase.java
com.twlkyao.kuaipan.TransportListener.java
com.twlkyao.kuaipan.UploadTask.java
com.twlkyao.utils.ApkOperation.java
com.twlkyao.utils.ConstantVariables.java
com.twlkyao.utils.ExportSms.java
com.twlkyao.utils.FileDEncryption.java
com.twlkyao.utils.FileOperation.java
com.twlkyao.utils.ImportSms.java
com.twlkyao.utils.LogUtils.java
com.twlkyao.utils.SmsField.java
com.twlkyao.utils.SmsItem.java
com.twlkyao.utils.StringSplice.java