Android Open Source - FxExplorer Hash Info Dialog






From Project

Back to project page FxExplorer.

License

The source code is released under:

Apache License

If you think the Android project FxExplorer 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 info.breezes.fxmanager.dialog;
//from  w  w w. j a  va  2 s  . co  m
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import info.breezes.DigestUtils;
import info.breezes.fxmanager.R;
import info.breezes.fxmanager.countly.CountlyEvent;
import info.breezes.fxmanager.countly.CountlyUtils;
import info.breezes.fxmanager.model.MediaItem;
import info.breezes.toolkit.ui.Toast;

/**
 * single file hash code dialog
 * Created by Qiao on 2015/1/1.
 */
public class HashInfoDialog {
    private final Context context;

    public HashInfoDialog(Context context) {
        this.context = context;
    }

    private View.OnClickListener copyToClipboardListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TextView tv = (TextView) v;
            ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            clipboardManager.setPrimaryClip(ClipData.newPlainText(String.valueOf(tv.getTag()), tv.getText()));
            CountlyUtils.addEvent(CountlyEvent.COPY_HASH, String.valueOf(tv.getTag()));
            Toast.showText(context, String.format(context.getString(R.string.tip_hash_copied), tv.getTag()));
        }
    };

    public void showHashDialog(MediaItem mediaItem) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(mediaItem.title);
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        @SuppressLint("InflateParams")
        View view = layoutInflater.inflate(R.layout.dialog_hash_info, null);
        TextView md5TextView = (TextView) view.findViewById(R.id.hash_md5);
        TextView sha1TextView = (TextView) view.findViewById(R.id.hash_sha1);
        md5TextView.setTag("MD5");
        sha1TextView.setTag("SHA1");
        md5TextView.setOnClickListener(copyToClipboardListener);
        sha1TextView.setOnClickListener(copyToClipboardListener);
        asyncComputeHash("MD5", mediaItem, md5TextView, (ProgressBar) view.findViewById(R.id.progressBar));
        asyncComputeHash("SHA1", mediaItem, sha1TextView, (ProgressBar) view.findViewById(R.id.progressBar2));
        builder.setView(view);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.show();
    }

    private void asyncComputeHash(final String type, final MediaItem mediaItem, final TextView textView, final ProgressBar progressBar) {
        new AsyncTask<Void, Void, Void>() {
            private String msg;
            private String hash;

            @Override
            protected void onPreExecute() {
                if (progressBar != null) {
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar.setIndeterminate(true);
                }
            }

            @Override
            protected Void doInBackground(Void... params) {
                try {
                    switch (type) {
                        case "MD5":
                            hash = DigestUtils.md5File(mediaItem.path);
                            break;
                        case "SHA1":
                            hash = DigestUtils.sha1File(mediaItem.path);
                            break;
                        default:
                            msg = String.format(context.getString(R.string.tip_unknown_hash_method), type);
                    }
                } catch (Exception exp) {
                    msg = exp.getMessage();
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                if (progressBar != null) {
                    progressBar.setVisibility(View.GONE);
                    progressBar.setIndeterminate(false);
                }
                if (!TextUtils.isEmpty(msg)) {
                    Toast.showText(context, msg);
                }
                if (hash != null) {
                    textView.setText(hash);
                }
            }
        }.execute();
    }
}




Java Source Code List

info.breezes.fx.downloader.ApplicationTest.java
info.breezes.fx.downloader.DlMainActivity.java
info.breezes.fx.editor.ApplicationTest.java
info.breezes.fx.editor.EditorMainActivity.java
info.breezes.fx.player.ApplicationTest.java
info.breezes.fx.player.MainActivity.java
info.breezes.fx.viewer.ApplicationTest.java
info.breezes.fx.viewer.BigImageView.java
info.breezes.fx.viewer.ImageUtility.java
info.breezes.fx.viewer.MainActivity.java
info.breezes.fxmanager.ApplicationTest.java
info.breezes.fxmanager.FxApplication.java
info.breezes.fxmanager.LocalFileSystemProvider.java
info.breezes.fxmanager.MainActivity.java
info.breezes.fxmanager.MediaFragment.java
info.breezes.fxmanager.MediaItemUtil.java
info.breezes.fxmanager.MediaProvider.java
info.breezes.fxmanager.MenuAdapter.java
info.breezes.fxmanager.MimeTypeMap.java
info.breezes.fxmanager.NetUtils.java
info.breezes.fxmanager.PackagesProvider.java
info.breezes.fxmanager.ScanResultActivity.java
info.breezes.fxmanager.ScannerActivity.java
info.breezes.fxmanager.SettingsActivity.java
info.breezes.fxmanager.ShellUtil.java
info.breezes.fxmanager.StorageTool.java
info.breezes.fxmanager.ThemeChooserActivity.java
info.breezes.fxmanager.android.app.QAlertDialog.java
info.breezes.fxmanager.countly.CountlyActivity.java
info.breezes.fxmanager.countly.CountlyEvent.java
info.breezes.fxmanager.countly.CountlyFragment.java
info.breezes.fxmanager.countly.CountlyUtils.java
info.breezes.fxmanager.dialog.ApkInfoDialog.java
info.breezes.fxmanager.dialog.FileInfoDialog.java
info.breezes.fxmanager.dialog.HashInfoDialog.java
info.breezes.fxmanager.model.DrawerMenu.java
info.breezes.fxmanager.model.MediaItem.java
info.breezes.fxmanager.qrcode.QrBitmapDecoder.java
info.breezes.fxmanager.service.FileService.java
net.gescobar.httpserver.Handler.java
net.gescobar.httpserver.HttpConnection.java
net.gescobar.httpserver.HttpServer.java
net.gescobar.httpserver.Request.java
net.gescobar.httpserver.Response.java