Search in sources :

Example 1 with MainActivity

use of com.huetoyou.chatexchange.ui.activity.MainActivity 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)

Aggregations

Account (android.accounts.Account)1 Intent (android.content.Intent)1 AppCompatButton (android.support.v7.widget.AppCompatButton)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 LinearLayout (android.widget.LinearLayout)1 Spinner (android.widget.Spinner)1 MainActivity (com.huetoyou.chatexchange.ui.activity.MainActivity)1 ArrayList (java.util.ArrayList)1