Search in sources :

Example 16 with AppCompatButton

use of android.support.v7.widget.AppCompatButton in project ChatExchange by HueToYou.

the class AccountsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_accounts, container, false);
    getActivity().setTitle(getResources().getText(R.string.app_name));
    mAccountManager = AccountManager.get(getActivity());
    Account[] accounts = mAccountManager.getAccounts();
    LinearLayout accountLayout = (LinearLayout) view.findViewById(R.id.select_account_lin);
    List<String> spinnerArray = new ArrayList<String>();
    for (final Account account : accounts) {
        spinnerArray.add(account.name);
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, spinnerArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner sItems = (Spinner) accountLayout.findViewById(R.id.accountsSpinner);
    sItems.setAdapter(adapter);
    Button newAccount = new AppCompatButton(getActivity());
    newAccount.setText(getResources().getText(R.string.activity_main_add_account));
    newAccount.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().startActivity(new Intent(getActivity(), AuthenticatorActivity.class));
        }
    });
    ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    params.setMargins(0, 20, 0, 0);
    newAccount.setLayoutParams(params);
    accountLayout.addView(newAccount);
    View v = new View(getActivity());
    v.setMinimumHeight(2);
    v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
    ViewGroup.MarginLayoutParams vparams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    vparams.setMargins(40, 40, 40, 40);
    v.setLayoutParams(vparams);
    accountLayout.addView(v);
    Button newChat = new AppCompatButton(getActivity());
    newChat.setText(getResources().getText(R.string.activity_main_add_chat));
    newChat.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getActivity() instanceof MainActivity) {
                ((MainActivity) getActivity()).showAddTabDialog();
            }
        }
    });
    accountLayout.addView(newChat);
    return view;
}
Also used : Account(android.accounts.Account) Spinner(android.widget.Spinner) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) Intent(android.content.Intent) MainActivity(com.huetoyou.chatexchange.ui.activity.MainActivity) View(android.view.View) AppCompatButton(android.support.v7.widget.AppCompatButton) AppCompatButton(android.support.v7.widget.AppCompatButton) Button(android.widget.Button) LinearLayout(android.widget.LinearLayout) ArrayAdapter(android.widget.ArrayAdapter)

Example 17 with AppCompatButton

use of android.support.v7.widget.AppCompatButton in project Rashr by DsLNeXuS.

the class BackupActivity method showPopup.

public void showPopup(final View v, final File file) {
    PopupMenu popup = new PopupMenu(mActivity, v);
    popup.getMenuInflater().inflate(R.menu.bakmgr_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem menuItem) {
            final AppCompatDialog dialog = new AppCompatDialog(mActivity);
            dialog.setTitle(R.string.setname);
            dialog.setContentView(R.layout.dialog_input);
            final AppCompatButton bGo = dialog.findViewById(R.id.bGoBackup);
            final AppCompatEditText etFileName = dialog.findViewById(R.id.etFileName);
            if (bGo == null || etFileName == null)
                return false;
            // If current item is 0 (first item) a recovery backup will be edited or created
            final File path = mPager.getCurrentItem() == 0 ? App.PathToRecoveryBackups : App.PathToKernelBackups;
            try {
                switch(menuItem.getItemId()) {
                    case R.id.iRestore:
                        FlashUtil RestoreUtil = new FlashUtil(mActivity, file, mPager.getCurrentItem() == 0 ? FlashUtil.JOB_RESTORE_RECOVERY : FlashUtil.JOB_RESTORE_KERNEL);
                        RestoreUtil.execute();
                        return true;
                    case R.id.iRename:
                        etFileName.setHint(file.getName());
                        bGo.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                String Name;
                                if (etFileName.getText() != null && etFileName.isEnabled() && !etFileName.getText().toString().equals("")) {
                                    // User has defined a name for the backup. Use it.
                                    Name = etFileName.getText().toString();
                                } else {
                                    // Use hint as backup name. Normally the correct version
                                    // and Recovery System (if Rashr could read it out of
                                    // "/cache/recovery/last_log"
                                    Name = String.valueOf(etFileName.getHint());
                                }
                                if (!Name.endsWith(App.Device.getRecoveryExt())) {
                                    // Append extension
                                    Name += App.Device.getRecoveryExt();
                                }
                                File renamedBackup = new File(path, Name);
                                if (renamedBackup.exists()) {
                                    Toast.makeText(mActivity, R.string.backupalready, Toast.LENGTH_SHORT).show();
                                    // if backup already exists, let the user chose a new name
                                    onMenuItemClick(menuItem);
                                } else {
                                    if (file.renameTo(renamedBackup)) {
                                        mAdapter.loadBackups();
                                    } else {
                                        Toast.makeText(mActivity, R.string.rename_failed, Toast.LENGTH_SHORT).show();
                                    }
                                }
                                dialog.dismiss();
                            }
                        });
                        dialog.show();
                        return true;
                    case R.id.iDeleteBackup:
                        if (file.delete()) {
                            Toast.makeText(mActivity, mContext.getString(R.string.bak_deleted), Toast.LENGTH_SHORT).show();
                        }
                        mAdapter.loadBackups();
                        return true;
                    default:
                        return false;
                }
            } catch (Exception e) {
                if (e.getMessage().contains("EINVAL") && file.getName().contains(":")) {
                    AlertDialog.Builder adialog = new AlertDialog.Builder(mContext);
                    adialog.setMessage(R.string.check_name);
                    adialog.setMessage(R.string.ok);
                    adialog.show();
                }
                App.ERRORS.add(App.TAG + " " + e);
                return false;
            }
        }
    });
    popup.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) MenuItem(android.view.MenuItem) BindView(butterknife.BindView) View(android.view.View) AppCompatTextView(android.support.v7.widget.AppCompatTextView) RecyclerView(android.support.v7.widget.RecyclerView) AppCompatButton(android.support.v7.widget.AppCompatButton) AppCompatEditText(android.support.v7.widget.AppCompatEditText) AppCompatDialog(android.support.v7.app.AppCompatDialog) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

Example 18 with AppCompatButton

use of android.support.v7.widget.AppCompatButton in project twicalico by moko256.

the class ShowTweetActivity method updateView.

private void updateView(Status item) {
    TextView tweetIsReply = findViewById(R.id.tweet_show_is_reply_text);
    long replyTweetId = item.getInReplyToStatusId();
    if (replyTweetId != -1) {
        tweetIsReply.setVisibility(VISIBLE);
        tweetIsReply.setOnClickListener(v -> startActivity(getIntent(this, replyTweetId)));
    } else {
        tweetIsReply.setVisibility(GONE);
    }
    StatusView statusView = new StatusView(this);
    statusView.setStatus(item);
    ViewGroup cview = (ViewGroup) statusView.getChildAt(0);
    ViewGroup sview = (ViewGroup) cview.getChildAt(0);
    cview.removeView(sview);
    FrameLayout statusViewFrame = findViewById(R.id.tweet_show_tweet);
    statusViewFrame.removeAllViews();
    statusViewFrame.addView(sview);
    ((TextView) findViewById(R.id.tweet_show_timestamp)).setText(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(item.getCreatedAt()));
    TextView viaText = findViewById(R.id.tweet_show_via);
    viaText.setText(TwitterStringUtils.convertUrlSpanToCustomTabs(Html.fromHtml("via:" + item.getSource()), this));
    viaText.setMovementMethod(new LinkMovementMethod());
    AppCompatEditText replyText = findViewById(R.id.tweet_show_tweet_reply_text);
    AppCompatButton replyButton = findViewById(R.id.tweet_show_tweet_reply_button);
    UserMentionEntity[] users = item.getUserMentionEntities();
    replyText.setText(TwitterStringUtils.convertToReplyTopString(GlobalApplication.userCache.get(GlobalApplication.userId).getScreenName(), item.getUser().getScreenName(), users));
    replyButton.setOnClickListener(v -> {
        replyButton.setEnabled(false);
        PostTweetModel model = PostTweetModelCreator.getInstance(GlobalApplication.twitter, getContentResolver());
        model.setTweetText(replyText.getText().toString());
        model.setInReplyToStatusId(item.getId());
        subscriptions.add(model.postTweet().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(it -> {
            replyText.setText(TwitterStringUtils.convertToReplyTopString(GlobalApplication.userCache.get(GlobalApplication.userId).getScreenName(), item.getUser().getScreenName(), users));
            replyButton.setEnabled(true);
            Toast.makeText(ShowTweetActivity.this, R.string.succeeded, Toast.LENGTH_SHORT).show();
        }, e -> {
            e.printStackTrace();
            Toast.makeText(ShowTweetActivity.this, R.string.error_occurred, Toast.LENGTH_SHORT).show();
            replyButton.setEnabled(true);
        }));
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) PostTweetModel(com.github.moko256.twicalico.model.base.PostTweetModel) FrameLayout(android.widget.FrameLayout) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) LinkMovementMethod(android.text.method.LinkMovementMethod) TwitterStringUtils(com.github.moko256.twicalico.text.TwitterStringUtils) UserMentionEntity(twitter4j.UserMentionEntity) MenuItem(android.view.MenuItem) AppCompatButton(android.support.v7.widget.AppCompatButton) Single(rx.Single) AppCustomTabsKt(com.github.moko256.twicalico.intent.AppCustomTabsKt) Toast(android.widget.Toast) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) TwitterException(twitter4j.TwitterException) VISIBLE(android.view.View.VISIBLE) ActionBar(android.support.v7.app.ActionBar) DateFormat(java.text.DateFormat) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) StatusCacheMap(com.github.moko256.twicalico.cacheMap.StatusCacheMap) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) CompositeSubscription(rx.subscriptions.CompositeSubscription) TextView(android.widget.TextView) GONE(android.view.View.GONE) Html(android.text.Html) Status(twitter4j.Status) PostTweetModelCreator(com.github.moko256.twicalico.model.impl.PostTweetModelCreator) AppCompatEditText(android.support.v7.widget.AppCompatEditText) AppCompatEditText(android.support.v7.widget.AppCompatEditText) UserMentionEntity(twitter4j.UserMentionEntity) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) PostTweetModel(com.github.moko256.twicalico.model.base.PostTweetModel) AppCompatButton(android.support.v7.widget.AppCompatButton)

Aggregations

AppCompatButton (android.support.v7.widget.AppCompatButton)18 View (android.view.View)16 DialogInterface (android.content.DialogInterface)7 AppCompatEditText (android.support.v7.widget.AppCompatEditText)7 AppCompatTextView (android.support.v7.widget.AppCompatTextView)7 AdapterView (android.widget.AdapterView)7 ListView (android.widget.ListView)7 File (java.io.File)7 AlertDialog (android.support.v7.app.AlertDialog)6 AppCompatDialog (android.support.v7.app.AppCompatDialog)6 ViewGroup (android.view.ViewGroup)5 BindView (butterknife.BindView)5 ArrayList (java.util.ArrayList)5 AppCompatCheckBox (android.support.v7.widget.AppCompatCheckBox)4 ArrayAdapter (android.widget.ArrayAdapter)4 TextView (android.widget.TextView)4 MenuItem (android.view.MenuItem)3 ProgressDialog (android.app.ProgressDialog)2 Intent (android.content.Intent)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2