Search in sources :

Example 26 with Builder

use of android.support.v7.app.AlertDialog.Builder in project WordPress-Android by wordpress-mobile.

the class EditorFragment method checkForFailedUploadAndSwitchToHtmlMode.

public void checkForFailedUploadAndSwitchToHtmlMode(final ToggleButton toggleButton) {
    if (!isAdded()) {
        return;
    }
    // Show an Alert Dialog asking the user if he wants to remove all failed media before upload
    if (hasFailedMediaUploads()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.editor_failed_uploads_switch_html).setPositiveButton(R.string.editor_remove_failed_uploads, new OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                // Clear failed uploads and switch to HTML mode
                removeAllFailedMediaUploads();
                toggleHtmlMode(toggleButton);
            }
        }).setNegativeButton(android.R.string.cancel, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                toggleButton.setChecked(false);
            }
        });
        builder.create().show();
    } else {
        toggleHtmlMode(toggleButton);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) SuppressLint(android.annotation.SuppressLint)

Example 27 with Builder

use of android.support.v7.app.AlertDialog.Builder in project CloudReader by youlookwhat.

the class EverydayAdapter method setOnClick.

private void setOnClick(final LinearLayout linearLayout, final AndroidBean bean) {
    linearLayout.setOnClickListener(new PerfectClickListener() {

        @Override
        protected void onNoDoubleClick(View v) {
            WebViewActivity.loadUrl(v.getContext(), bean.getUrl(), "加载中...");
        }
    });
    linearLayout.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
            View view = View.inflate(v.getContext(), R.layout.title_douban_top, null);
            TextView titleTop = (TextView) view.findViewById(R.id.title_top);
            titleTop.setTextSize(14);
            String title = TextUtils.isEmpty(bean.getType()) ? bean.getDesc() : bean.getType() + ":  " + bean.getDesc();
            titleTop.setText(title);
            builder.setCustomTitle(view);
            builder.setPositiveButton("查看详情", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    WebViewActivity.loadUrl(linearLayout.getContext(), bean.getUrl(), "加载中...");
                }
            });
            builder.show();
            return false;
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) PerfectClickListener(com.example.jingbin.cloudreader.utils.PerfectClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 28 with Builder

use of android.support.v7.app.AlertDialog.Builder in project SR-Tracker-for-Overwatch by Rexios80.

the class StatsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.stats_fragment, container, false);
    if (dpWidth() > 750) {
        LinearLayout llStats = (LinearLayout) v.findViewById(R.id.ll_stats);
        int cardBackground = ContextCompat.getColor(getActivity(), R.color.cardBackground);
        llStats.setBackgroundColor(cardBackground);
    }
    lvStats = (ListView) v.findViewById(R.id.lv_stats);
    adapter = new StatsListViewAdapter(getActivity(), new DatabaseParser(getContext()).getStatsList(), getContext());
    lvStats.setAdapter(adapter);
    lvStats.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long arg3) {
            String timeString = ((HashMap<String, String>) adapter.getItem(position)).get("time");
            String snackbarText;
            if (timeString == null || timeString.equals("0")) {
                snackbarText = "No time recorded";
            } else {
                long time = Long.parseLong(timeString);
                SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/yy  -  h:mm a");
                Date date = new Date(time);
                snackbarText = dateFormat.format(date);
            }
            Snackbar.make(getActivity().findViewById(android.R.id.content), snackbarText, Snackbar.LENGTH_LONG).show();
        }
    });
    lvStats.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> a, View v, int position, long arg3) {
            String noteString = ((HashMap<String, String>) adapter.getItem(position)).get("note");
            if (noteString == null || noteString.equals("")) {
                Snackbar.make(getActivity().findViewById(android.R.id.content), "No note recorded", Snackbar.LENGTH_LONG).show();
                return true;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustom);
            builder.setMessage(noteString).show();
            return true;
        }
    });
    return v;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Date(java.util.Date) AdapterView(android.widget.AdapterView) SimpleDateFormat(java.text.SimpleDateFormat) LinearLayout(android.widget.LinearLayout)

Example 29 with Builder

use of android.support.v7.app.AlertDialog.Builder in project Tusky by Vavassor.

the class ComposeActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose);
    ButterKnife.bind(this);
    // Setup the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
        ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
        actionBar.setHomeAsUpIndicator(closeIcon);
    }
    // Setup the interface buttons.
    floatingBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onSendClicked();
        }
    });
    pickBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onMediaPick();
        }
    });
    takeBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            initiateCameraApp();
        }
    });
    nsfwBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleNsfw();
        }
    });
    visibilityBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showComposeOptions();
        }
    });
    /* Initialise all the state, or restore it from a previous run, to determine a "starting"
         * state. */
    SharedPreferences preferences = getPrivatePreferences();
    String startingVisibility;
    boolean startingHideText;
    String startingContentWarning = null;
    ArrayList<SavedQueuedMedia> savedMediaQueued = null;
    if (savedInstanceState != null) {
        showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive");
        startingVisibility = savedInstanceState.getString("statusVisibility");
        statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
        startingHideText = savedInstanceState.getBoolean("statusHideText");
        // Keep these until everything needed to put them in the queue is finished initializing.
        savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
        // These are for restoring an in-progress commit content operation.
        InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat.wrap(savedInstanceState.getParcelable("commitContentInputContentInfo"));
        int previousFlags = savedInstanceState.getInt("commitContentFlags");
        if (previousInputContentInfo != null) {
            onCommitContentInternal(previousInputContentInfo, previousFlags);
        }
    } else {
        showMarkSensitive = false;
        startingVisibility = preferences.getString("rememberedVisibility", "public");
        statusMarkSensitive = false;
        startingHideText = false;
    }
    /* If the composer is started up as a reply to another post, override the "starting" state
         * based on what the intent from the reply request passes. */
    Intent intent = getIntent();
    String[] mentionedUsernames = null;
    inReplyToId = null;
    if (intent != null) {
        inReplyToId = intent.getStringExtra("in_reply_to_id");
        String replyVisibility = intent.getStringExtra("reply_visibility");
        if (replyVisibility != null && startingVisibility != null) {
            // Lowest possible visibility setting in response
            if (startingVisibility.equals("direct") || replyVisibility.equals("direct")) {
                startingVisibility = "direct";
            } else if (startingVisibility.equals("private") || replyVisibility.equals("private")) {
                startingVisibility = "private";
            } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) {
                startingVisibility = "unlisted";
            } else {
                startingVisibility = replyVisibility;
            }
        }
        mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames");
        if (inReplyToId != null) {
            startingHideText = !intent.getStringExtra("content_warning").equals("");
            if (startingHideText) {
                startingContentWarning = intent.getStringExtra("content_warning");
            }
        }
    }
    /* If the currently logged in account is locked, its posts should default to private. This
         * should override even the reply settings, so this must be done after those are set up. */
    if (preferences.getBoolean("loggedInAccountLocked", false)) {
        startingVisibility = "private";
    }
    // After the starting state is finalised, the interface can be set to reflect this state.
    setStatusVisibility(startingVisibility);
    postProgress.setVisibility(View.INVISIBLE);
    updateNsfwButtonColor();
    final ParserUtils parser = new ParserUtils(this);
    // Setup the main text field.
    // new String[] { "image/gif", "image/webp" }
    setEditTextMimeTypes(null);
    final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
    SpanUtils.highlightSpans(textEditor.getText(), mentionColour);
    textEditor.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

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

        @Override
        public void afterTextChanged(Editable editable) {
            SpanUtils.highlightSpans(editable, mentionColour);
        }
    });
    textEditor.addOnPasteListener(new EditTextTyped.OnPasteListener() {

        @Override
        public void onPaste() {
            parser.getPastedURLText(ComposeActivity.this);
        }
    });
    // Add any mentions to the text field when a reply is first composed.
    if (mentionedUsernames != null) {
        StringBuilder builder = new StringBuilder();
        for (String name : mentionedUsernames) {
            builder.append('@');
            builder.append(name);
            builder.append(' ');
        }
        textEditor.setText(builder);
        textEditor.setSelection(textEditor.length());
    }
    // Initialise the content warning editor.
    contentWarningEditor.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) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    showContentWarning(startingHideText);
    if (startingContentWarning != null) {
        contentWarningEditor.setText(startingContentWarning);
    }
    // Initialise the empty media queue state.
    mediaQueued = new ArrayList<>();
    waitForMediaLatch = new CountUpDownLatch();
    statusAlreadyInFlight = false;
    // These can only be added after everything affected by the media queue is initialized.
    if (savedMediaQueued != null) {
        for (SavedQueuedMedia item : savedMediaQueued) {
            addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
        }
    } else if (intent != null && savedInstanceState == null) {
        /* Get incoming images being sent through a share action from another app. Only do this
             * when savedInstanceState is null, otherwise both the images from the intent and the
             * instance state will be re-queued. */
        String type = intent.getType();
        if (type != null) {
            if (type.startsWith("image/")) {
                List<Uri> uriList = new ArrayList<>();
                switch(intent.getAction()) {
                    case Intent.ACTION_SEND:
                        {
                            Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                            if (uri != null) {
                                uriList.add(uri);
                            }
                            break;
                        }
                    case Intent.ACTION_SEND_MULTIPLE:
                        {
                            ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                            if (list != null) {
                                for (Uri uri : list) {
                                    if (uri != null) {
                                        uriList.add(uri);
                                    }
                                }
                            }
                            break;
                        }
                }
                for (Uri uri : uriList) {
                    long mediaSize = getMediaSize(getContentResolver(), uri);
                    pickMedia(uri, mediaSize);
                }
            } else if (type.equals("text/plain")) {
                String action = intent.getAction();
                if (action != null && action.equals(Intent.ACTION_SEND)) {
                    String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                    if (text != null) {
                        int start = Math.max(textEditor.getSelectionStart(), 0);
                        int end = Math.max(textEditor.getSelectionEnd(), 0);
                        int left = Math.min(start, end);
                        int right = Math.max(start, end);
                        textEditor.getText().replace(left, right, text, 0, text.length());
                        parser.putInClipboardManager(this, text);
                        textEditor.onPaste();
                    }
                }
            }
        }
    }
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) CountUpDownLatch(com.keylesspalace.tusky.util.CountUpDownLatch) StringUtils.randomAlphanumericString(com.keylesspalace.tusky.util.StringUtils.randomAlphanumericString) Uri(android.net.Uri) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) List(java.util.List) ArrayList(java.util.ArrayList) ParserUtils(com.keylesspalace.tusky.util.ParserUtils) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) SharedPreferences(android.content.SharedPreferences) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) EditTextTyped(com.keylesspalace.tusky.view.EditTextTyped)

Example 30 with Builder

use of android.support.v7.app.AlertDialog.Builder in project Synthese_2BIN by TheYoungSensei.

the class ItemListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(getTitle());
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
    View recyclerView = findViewById(R.id.item_list);
    assert recyclerView != null;
    setupRecyclerView((RecyclerView) recyclerView);
    if (findViewById(R.id.item_detail_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-w900dp).
        // If this view is present, then the
        // activity should be in two-pane mode.
        mTwoPane = true;
    }
    model = ((Builder) getApplication()).getModel();
    model.registerObserver(this);
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    task = new MyTask();
    if (networkInfo != null && networkInfo.isConnected()) {
        //fetch data
        task.execute("http://ws.audioscrobbler.com/2.0/?method=geo.gettopartists&country=belgium&api_key=32ef5df0e36797b605e205529058f3b8&format=json&limit=" + INT);
    } else {
    //ERROR
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) FloatingActionButton(android.support.design.widget.FloatingActionButton) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)114 DialogInterface (android.content.DialogInterface)76 View (android.view.View)67 TextView (android.widget.TextView)48 Intent (android.content.Intent)36 RecyclerView (android.support.v7.widget.RecyclerView)27 ListView (android.widget.ListView)23 Dialog (android.app.Dialog)22 LayoutInflater (android.view.LayoutInflater)20 ImageView (android.widget.ImageView)20 EditText (android.widget.EditText)18 SuppressLint (android.annotation.SuppressLint)17 Context (android.content.Context)17 Bundle (android.os.Bundle)15 NonNull (android.support.annotation.NonNull)14 Button (android.widget.Button)13 ArrayList (java.util.ArrayList)12 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)10 OnClickListener (android.content.DialogInterface.OnClickListener)10 ScrollView (android.widget.ScrollView)10