Search in sources :

Example 51 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project AnimeTaste by daimajia.

the class ShareHelper method showUp.

public static void showUp(final Context context, final Animation animation) {
    View v = LayoutInflater.from(context).inflate(R.layout.layout_share, null, false);
    final MaterialDialog dialog = new MaterialDialog.Builder(context).customView(v, false).build();
    dialog.show();
    ShareSDK.initSDK(context);
    ShareButton weibo = (ShareButton) v.findViewById(R.id.action_share_weibo);
    ShareButton wechat = (ShareButton) v.findViewById(R.id.action_share_wechat);
    ShareButton wechatTimeline = (ShareButton) v.findViewById(R.id.action_share_wechat_timeline);
    ShareButton qq = (ShareButton) v.findViewById(R.id.action_share_qq);
    ShareButton link = (ShareButton) v.findViewById(R.id.action_share_link);
    ShareButton qzone = (ShareButton) v.findViewById(R.id.action_share_qzone);
    TextView cancel = (TextView) v.findViewById(R.id.cancel);
    final Handler showMsg = new Handler(new Handler.Callback() {

        @Override
        public boolean handleMessage(Message msg) {
            Toast.makeText(context, msg.obj.toString(), Toast.LENGTH_SHORT).show();
            return true;
        }
    });
    final PlatformActionListener platformActionListener = new PlatformActionListener() {

        @Override
        public void onComplete(Platform platform, int i, HashMap<String, Object> stringObjectHashMap) {
            Message msg = Message.obtain(showMsg);
            msg.obj = "(๑•̀ㅂ•́)و分享成功!Ye";
            msg.sendToTarget();
        }

        @Override
        public void onError(Platform platform, int i, Throwable throwable) {
            Log.e("Error", throwable.getMessage());
            Message msg = Message.obtain(showMsg);
            msg.obj = "(⊙﹏⊙) 好像出了错误";
            msg.sendToTarget();
        }

        @Override
        public void onCancel(Platform platform, int i) {
            Message msg = Message.obtain(showMsg);
            msg.obj = "o(TヘTo) 取消了耶...";
            msg.sendToTarget();
        }
    };
    weibo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SinaWeibo.ShareParams sp = new SinaWeibo.ShareParams();
            Platform pf = ShareSDK.getPlatform(context, SinaWeibo.NAME);
            String toSend = "「" + animation.Name + "」 " + animation.OriginVideoUrl + " " + animation.Brief;
            toSend = toSend.substring(0, 140);
            sp.setText(toSend);
            sp.setUrl(animation.OriginVideoUrl);
            sp.setImageUrl(animation.DetailPic);
            pf.setPlatformActionListener(platformActionListener);
            pf.share(sp);
            shareAction(context, dialog);
        }
    });
    wechat.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Platform plat = ShareSDK.getPlatform(context, Wechat.NAME);
            Wechat.ShareParams sp = new Wechat.ShareParams();
            sp.setTitle(animation.Name);
            sp.setText(animation.Brief);
            sp.setImageUrl(animation.HomePic);
            sp.setUrl(animation.getShareUrl());
            sp.setShareType(Platform.SHARE_WEBPAGE);
            plat.setPlatformActionListener(platformActionListener);
            plat.share(sp);
            shareAction(context, dialog);
        }
    });
    wechatTimeline.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Platform plat = ShareSDK.getPlatform(context, WechatMoments.NAME);
            WechatMoments.ShareParams sp = new WechatMoments.ShareParams();
            sp.title = animation.Name;
            sp.text = animation.Brief;
            sp.imageUrl = animation.HomePic;
            sp.url = animation.getShareUrl();
            sp.shareType = Platform.SHARE_WEBPAGE;
            plat.setPlatformActionListener(platformActionListener);
            plat.share(sp);
            shareAction(context, dialog);
        }
    });
    qq.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Platform plat = ShareSDK.getPlatform(context, QQ.NAME);
            QQ.ShareParams sp = new QQ.ShareParams();
            sp.setTitle(animation.Name);
            sp.setText(animation.Brief);
            sp.setImageUrl(animation.HomePic);
            sp.setTitleUrl(animation.getShareUrl());
            sp.setShareType(QQ.SHARE_WEBPAGE);
            plat.setPlatformActionListener(platformActionListener);
            plat.share(sp);
            shareAction(context, dialog);
        }
    });
    qzone.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Platform plat = ShareSDK.getPlatform(context, QZone.NAME);
            QZone.ShareParams sp = new QZone.ShareParams();
            sp.setTitle(animation.Name);
            sp.setText(animation.Brief);
            sp.setImageUrl(animation.HomePic);
            sp.setTitleUrl(animation.getShareUrl());
            sp.setShareType(QZone.SHARE_WEBPAGE);
            plat.setPlatformActionListener(platformActionListener);
            plat.share(sp);
            shareAction(context, dialog);
        }
    });
    link.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int sdk = android.os.Build.VERSION.SDK_INT;
            if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setText(animation.getShareUrl());
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText("data", animation.getShareUrl());
                clipboard.setPrimaryClip(clip);
            }
            dialog.dismiss();
            Toast.makeText(context, "复制完成,快快分享给你的好朋友们!", Toast.LENGTH_LONG).show();
        }
    });
    cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}
Also used : Message(android.os.Message) Platform(cn.sharesdk.framework.Platform) HashMap(java.util.HashMap) SinaWeibo(cn.sharesdk.sina.weibo.SinaWeibo) TextView(android.widget.TextView) Context(android.content.Context) ShareButton(com.zhan_dui.utils.ShareButton) QQ(cn.sharesdk.tencent.qq.QQ) PlatformActionListener(cn.sharesdk.framework.PlatformActionListener) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Handler(android.os.Handler) TextView(android.widget.TextView) View(android.view.View) Wechat(cn.sharesdk.wechat.friends.Wechat) WechatMoments(cn.sharesdk.wechat.moments.WechatMoments) QZone(cn.sharesdk.tencent.qzone.QZone)

Example 52 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project XposedInstaller by rovo89.

the class DownloadsUtil method showDownloadDialog.

private static void showDownloadDialog(final Builder b, final long id) {
    final Context context = b.mContext;
    final DownloadDialog dialog = new DownloadDialog(new MaterialDialog.Builder(context).title(b.mTitle).content(R.string.download_view_waiting).progress(false, 0, true).progressNumberFormat(context.getString(R.string.download_progress)).canceledOnTouchOutside(false).negativeText(R.string.download_view_cancel).onNegative(new SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.cancel();
        }
    }).cancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            removeById(context, id);
        }
    }));
    dialog.setShowProcess(false);
    dialog.show();
    new Thread("DownloadDialog") {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    return;
                }
                final DownloadInfo info = getById(context, id);
                if (info == null) {
                    dialog.cancel();
                    return;
                } else if (info.status == DownloadManager.STATUS_FAILED) {
                    dialog.cancel();
                    XposedApp.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(context, context.getString(R.string.download_view_failed, info.reason), Toast.LENGTH_LONG).show();
                        }
                    });
                    return;
                } else if (info.status == DownloadManager.STATUS_SUCCESSFUL) {
                    dialog.dismiss();
                    // Hack to reset stat information.
                    new File(info.localFilename).setExecutable(false);
                    if (b.mCallback != null) {
                        b.mCallback.onDownloadFinished(context, info);
                    }
                    return;
                }
                XposedApp.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (info.totalSize <= 0 || info.status != DownloadManager.STATUS_RUNNING) {
                            dialog.setContent(R.string.download_view_waiting);
                            dialog.setShowProcess(false);
                        } else {
                            dialog.setContent(R.string.download_running);
                            dialog.setProgress(info.bytesDownloaded / 1024);
                            dialog.setMaxProgress(info.totalSize / 1024);
                            dialog.setShowProcess(true);
                        }
                    }
                });
            }
        }
    }.start();
}
Also used : Context(android.content.Context) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogInterface(android.content.DialogInterface) UiThread(android.support.annotation.UiThread) DialogAction(com.afollestad.materialdialogs.DialogAction) SingleButtonCallback(com.afollestad.materialdialogs.MaterialDialog.SingleButtonCallback) File(java.io.File)

Example 53 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project XposedInstaller by rovo89.

the class StatusInstallerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.status_installer, container, false);
    // Available ZIPs
    final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefreshlayout);
    refreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
    ONLINE_ZIP_LOADER.setSwipeRefreshLayout(refreshLayout);
    ONLINE_ZIP_LOADER.addListener(mOnlineZipListener);
    ONLINE_ZIP_LOADER.triggerFirstLoadIfNecessary();
    LOCAL_ZIP_LOADER.addListener(mLocalZipListener);
    LOCAL_ZIP_LOADER.triggerFirstLoadIfNecessary();
    refreshZipViews(v);
    // Disable switch
    final SwitchCompat disableSwitch = (SwitchCompat) v.findViewById(R.id.disableSwitch);
    disableSwitch.setChecked(!DISABLE_FILE.exists());
    disableSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (DISABLE_FILE.exists()) {
                DISABLE_FILE.delete();
                Snackbar.make(disableSwitch, R.string.xposed_on_next_reboot, Snackbar.LENGTH_LONG).show();
            } else {
                try {
                    DISABLE_FILE.createNewFile();
                    Snackbar.make(disableSwitch, R.string.xposed_off_next_reboot, Snackbar.LENGTH_LONG).show();
                } catch (IOException e) {
                    Log.e(XposedApp.TAG, "Could not create " + DISABLE_FILE, e);
                }
            }
        }
    });
    // Device info
    TextView androidSdk = (TextView) v.findViewById(R.id.android_version);
    TextView manufacturer = (TextView) v.findViewById(R.id.ic_manufacturer);
    TextView cpu = (TextView) v.findViewById(R.id.cpu);
    androidSdk.setText(getString(R.string.android_sdk, Build.VERSION.RELEASE, getAndroidVersion(), Build.VERSION.SDK_INT));
    manufacturer.setText(getUIFramework());
    cpu.setText(FrameworkZips.ARCH);
    // Known issues
    refreshKnownIssue(v);
    // Display warning dialog to new users
    if (!XposedApp.getPreferences().getBoolean("hide_install_warning", false)) {
        new MaterialDialog.Builder(getActivity()).title(R.string.install_warning_title).content(R.string.install_warning).positiveText(android.R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                if (dialog.isPromptCheckBoxChecked()) {
                    XposedApp.getPreferences().edit().putBoolean("hide_install_warning", true).apply();
                }
            }
        }).checkBoxPromptRes(R.string.dont_show_again, false, null).cancelable(false).show();
    }
    return v;
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 54 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project material-dialogs by afollestad.

the class ChangelogDialog method onCreateDialog.

@SuppressLint("InflateParams")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final View customView;
    try {
        customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_webview, null);
    } catch (InflateException e) {
        throw new IllegalStateException("This device does not support Web Views.");
    }
    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).theme(getArguments().getBoolean("dark_theme") ? Theme.DARK : Theme.LIGHT).title(R.string.changelog).customView(customView, false).positiveText(android.R.string.ok).build();
    final WebView webView = (WebView) customView.findViewById(R.id.webview);
    try {
        // Load from changelog.html in the assets folder
        StringBuilder buf = new StringBuilder();
        InputStream json = getActivity().getAssets().open("changelog.html");
        BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
        String str;
        while ((str = in.readLine()) != null) {
            buf.append(str);
        }
        in.close();
        // Inject color values for WebView body background and links
        final int accentColor = getArguments().getInt("accent_color");
        webView.loadData(buf.toString().replace("{style-placeholder}", getArguments().getBoolean("dark_theme") ? "body { background-color: #444444; color: #fff; }" : "body { background-color: #fff; color: #000; }").replace("{link-color}", colorToHex(shiftColor(accentColor, true))).replace("{link-color-active}", colorToHex(accentColor)), "text/html", "UTF-8");
    } catch (Throwable e) {
        webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
    }
    return dialog;
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint) BufferedReader(java.io.BufferedReader) InflateException(android.view.InflateException) WebView(android.webkit.WebView) NonNull(android.support.annotation.NonNull) SuppressLint(android.annotation.SuppressLint)

Example 55 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project material-dialogs by afollestad.

the class MainActivity method showCustomView.

@SuppressWarnings("ResourceAsColor")
@OnClick(R.id.customView)
public void showCustomView() {
    MaterialDialog dialog = new MaterialDialog.Builder(this).title(R.string.googleWifi).customView(R.layout.dialog_customview, true).positiveText(R.string.connect).negativeText(android.R.string.cancel).onPositive((dialog1, which) -> showToast("Password: " + passwordInput.getText().toString())).build();
    positiveAction = dialog.getActionButton(DialogAction.POSITIVE);
    //noinspection ConstantConditions
    passwordInput = (EditText) dialog.getCustomView().findViewById(R.id.password);
    passwordInput.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            positiveAction.setEnabled(s.toString().trim().length() > 0);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    // Toggling the show password CheckBox will mask or unmask the password input EditText
    CheckBox checkbox = (CheckBox) dialog.getCustomView().findViewById(R.id.showPassword);
    checkbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
        passwordInput.setInputType(!isChecked ? InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT);
        passwordInput.setTransformationMethod(!isChecked ? PasswordTransformationMethod.getInstance() : null);
    });
    int widgetColor = ThemeSingleton.get().widgetColor;
    MDTintHelper.setTint(checkbox, widgetColor == 0 ? ContextCompat.getColor(this, R.color.accent) : widgetColor);
    MDTintHelper.setTint(passwordInput, widgetColor == 0 ? ContextCompat.getColor(this, R.color.accent) : widgetColor);
    dialog.show();
    // disabled by default
    positiveAction.setEnabled(false);
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) ButterKnife(butterknife.ButterKnife) GravityEnum(com.afollestad.materialdialogs.GravityEnum) CircleView(com.afollestad.materialdialogs.color.CircleView) Intent(android.content.Intent) ColorDrawable(android.graphics.drawable.ColorDrawable) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) FolderChooserDialog(com.afollestad.materialdialogs.folderselector.FolderChooserDialog) Editable(android.text.Editable) OnClick(butterknife.OnClick) MenuItem(android.view.MenuItem) ThemeSingleton(com.afollestad.materialdialogs.internal.ThemeSingleton) Manifest(android.Manifest) CheckBox(android.widget.CheckBox) Handler(android.os.Handler) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) StackingBehavior(com.afollestad.materialdialogs.StackingBehavior) MDTintHelper(com.afollestad.materialdialogs.internal.MDTintHelper) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) MaterialSimpleListItem(com.afollestad.materialdialogs.simplelist.MaterialSimpleListItem) Build(android.os.Build) TargetApi(android.annotation.TargetApi) ContextCompat(android.support.v4.content.ContextCompat) InputType(android.text.InputType) DialogAction(com.afollestad.materialdialogs.DialogAction) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) FileChooserDialog(com.afollestad.materialdialogs.folderselector.FileChooserDialog) File(java.io.File) Theme(com.afollestad.materialdialogs.Theme) Color(android.graphics.Color) ColorInt(android.support.annotation.ColorInt) MaterialSimpleListAdapter(com.afollestad.materialdialogs.simplelist.MaterialSimpleListAdapter) Html(android.text.Html) DialogUtils(com.afollestad.materialdialogs.util.DialogUtils) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorChooserDialog(com.afollestad.materialdialogs.color.ColorChooserDialog) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CheckBox(android.widget.CheckBox) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnClick(butterknife.OnClick)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)90 View (android.view.View)57 DialogAction (com.afollestad.materialdialogs.DialogAction)45 TextView (android.widget.TextView)36 NonNull (android.support.annotation.NonNull)33 Intent (android.content.Intent)21 File (java.io.File)21 RecyclerView (android.support.v7.widget.RecyclerView)20 ImageView (android.widget.ImageView)19 SuppressLint (android.annotation.SuppressLint)18 List (java.util.List)16 LayoutInflater (android.view.LayoutInflater)14 MenuItem (android.view.MenuItem)14 Context (android.content.Context)13 PopupMenu (android.widget.PopupMenu)12 Activity (android.app.Activity)11 ListView (android.widget.ListView)11 Toast (android.widget.Toast)11 ArrayList (java.util.ArrayList)11 Bundle (android.os.Bundle)8