Example usage for android.widget ArrayAdapter createFromResource

List of usage examples for android.widget ArrayAdapter createFromResource

Introduction

In this page you can find the example usage for android.widget ArrayAdapter createFromResource.

Prototype

public static @NonNull ArrayAdapter<CharSequence> createFromResource(@NonNull Context context,
        @ArrayRes int textArrayResId, @LayoutRes int textViewResId) 

Source Link

Document

Creates a new ArrayAdapter from external resources.

Usage

From source file:org.gnucash.android.ui.transaction.TransactionFormFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);/*from  w  ww  . j a va  2 s.com*/
    ActionBar actionBar = getSherlockActivity().getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mUseDoubleEntry = sharedPrefs.getBoolean(getString(R.string.key_use_double_entry), true);
    if (!mUseDoubleEntry) {
        getView().findViewById(R.id.layout_double_entry).setVisibility(View.GONE);
    }

    //updateTransferAccountsList must only be called after creating mAccountsDbAdapter
    mAccountsDbAdapter = new AccountsDbAdapter(getActivity());
    updateTransferAccountsList();

    ArrayAdapter<CharSequence> recurrenceAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.recurrence_period_strings, android.R.layout.simple_spinner_item);
    recurrenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mRecurringTransactionSpinner.setAdapter(recurrenceAdapter);

    long transactionId = getArguments().getLong(UxArgument.SELECTED_TRANSACTION_ID);
    mTransactionsDbAdapter = new TransactionsDbAdapter(getActivity());
    mTransaction = mTransactionsDbAdapter.getTransaction(transactionId);

    final long accountId = getArguments().getLong(UxArgument.SELECTED_ACCOUNT_ID);
    mAccountType = mAccountsDbAdapter.getAccountType(accountId);
    toggleTransactionTypeState();

    setListeners();
    if (mTransaction == null)
        initalizeViews();
    else {
        if (mUseDoubleEntry && isInDoubleAccount()) {
            mTransaction.setAmount(mTransaction.getAmount().negate());
        }
        initializeViewsWithTransaction();
    }

    initTransactionNameAutocomplete();
}

From source file:com.bydavy.card.receipts.activities.ReceiptListActivity.java

private void setupActionBar() {
    final Context context = getSupportActionBar().getThemedContext();
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    final ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context,
            R.array.activity_receipt_list__navigation_list, R.layout.sherlock_spinner_item);
    list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
    getSupportActionBar().setListNavigationCallbacks(list, this);
}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private void populateSecondForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title)));
    EditText passwordEditText = createEditText(mContext.getString(R.string.account_create_password_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, PASSWORD_KEY);
    passwordEditText.setTransformationMethod(new PasswordTransformationMethod());

    formLayout.addView(passwordEditText);
    formLayout.addView(createErrorView(PASSWORD_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title)));
    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);//from   w  ww . j  a  v  a2s  .  co  m
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.sexes_array,
            android.R.layout.simple_spinner_item);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt));
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(GENDER_KEY, adapter.getItem(pos).toString());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    if (mFormData.get(GENDER_KEY) != null) {
        spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY)));
    }

    formLayout.addView(spinner);

}

From source file:felixwiemuth.lincal.ui.CalendarViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.calendar_view, container, false);
    TextView titleView = (TextView) rootView.findViewById(R.id.cal_title);
    TextView authorView = (TextView) rootView.findViewById(R.id.cal_author);

    notificationsEnabled = (CheckBox) rootView.findViewById(R.id.notifications_enabled);
    textViewEarliestNotificationTime = (TextView) rootView
            .findViewById(R.id.setting_earliest_notification_time);
    earliestNotificationTimeEnabled = (CheckBox) rootView
            .findViewById(R.id.setting_earliest_notification_time_enabled);
    entryDisplayModeDate = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_date);
    entryDisplayModeDescription = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_description);
    buttonRemoveCalendar = (Button) rootView.findViewById(R.id.button_remove_cal);

    if (calendar == null) {
        titleView.setText(R.string.cal_title_error_loading);
        notificationsEnabled.setEnabled(false);
        earliestNotificationTimeEnabled.setEnabled(false);
        entryDisplayModeDate.setEnabled(false);
        entryDisplayModeDescription.setEnabled(false);
    } else {/*from   ww  w .  j  a v a2  s  . com*/
        titleView.setText(calendar.getTitle());
        authorView.setText(calendar.getAuthor());
        entryList = (RecyclerView) rootView.findViewById(R.id.entry_list_recycler_view);
        SimpleItemRecyclerViewAdapter adapter = new SimpleItemRecyclerViewAdapter();
        entryList.setAdapter(adapter);
        ((TextView) rootView.findViewById(R.id.cal_descr)).setText(calendar.getDescription());
        ((TextView) rootView.findViewById(R.id.cal_version)).setText(calendar.getVersion());
        ((TextView) rootView.findViewById(R.id.cal_date)).setText(calendar.getDateStr());
        if (calendar.hasForceEntryDisplayModeDate()) {
            entryDisplayModeDate.setEnabled(false);
        }
        if (calendar.hasForceEntryDisplayModeDescription()) {
            entryDisplayModeDescription.setEnabled(false);
        }
    }

    ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.setting_entry_display_mode_options, android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    entryDisplayModeDate.setAdapter(spinnerAdapter);
    entryDisplayModeDescription.setAdapter(spinnerAdapter);

    loadSettings(); // loading settings before adding listeners prevents them from firing due to initialization (e.g. Spinner)

    if (calendar != null) {
        // Set listeners
        final View.OnClickListener saveSettingsListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveSettings();
                NotificationService.runWithCalendar(getContext(),
                        Calendars.getInstance(getContext()).getConfigByPos(calendarPos).getId()); //TODO reconsider when to call
            }
        };

        notificationsEnabled.setOnClickListener(saveSettingsListener);
        textViewEarliestNotificationTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadSettings(); // update earliestNotificationTime
                DialogFragment dialogFragment = new TimePickerFragment();
                Bundle arguments = new Bundle();
                arguments.putInt("hour", earliestNotificationTime.getHour());
                arguments.putInt("minute", earliestNotificationTime.getMinute());
                arguments.putInt("calendarPos", calendarPos);
                dialogFragment.setArguments(arguments);
                dialogFragment.show(getFragmentManager(), "timePicker");
            }
        });
        earliestNotificationTimeEnabled.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveSettingsListener.onClick(v);
                // have to update the displayed notification times (only show when enabled)
                entryList.getAdapter().notifyDataSetChanged();
            }
        });
        //TODO implement
        //        onScreenOnEnabled = (CheckBox) rootView.findViewById(R.id.setting_show_notification_on_screen_on);
        //        onScreenOnEnabled.setOnClickListener(saveSettingsListener);
        entryDisplayModeDate.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener(
                entryDisplayModeDate.getSelectedItemPosition(), saveSettingsListener));
        entryDisplayModeDescription.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener(
                entryDisplayModeDescription.getSelectedItemPosition(), saveSettingsListener));
    }

    buttonRemoveCalendar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle(R.string.dialog_remove_cal_title).setMessage(R.string.dialog_remove_cal_msg)
                    .setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // First remove this fragment, so that it cannot be used anymore
                            getActivity().getSupportFragmentManager().beginTransaction()
                                    .remove(CalendarViewFragment.this).commit();
                            Calendars calendars = Calendars.getInstance(getContext());
                            calendars.removeCalendarByPos(getContext(), calendarPos);
                            // Notify calendar list that the calendar with the given position was removed and return to calendar list in case of CalendarViewActivity
                            Activity hostActivity = getActivity();
                            if (hostActivity instanceof CalendarListActivity) {
                                ((CalendarListActivity) hostActivity).notifyCalendarRemoved(calendarPos);
                            } else if (hostActivity instanceof CalendarViewActivity) {
                                Intent resultData = new Intent();
                                resultData.putExtra(CalendarListActivity.EXTRA_RESULT_CAL_REMOVED, calendarPos);
                                hostActivity.setResult(Activity.RESULT_OK, resultData);
                                hostActivity.finish();
                            } else {
                                throw new RuntimeException(
                                        "CalendarViewFragment may only be contained in either CalendarListActivity or CalendarViewActivity.");
                            }
                        }
                    });
            builder.show();
        }
    });

    return rootView;
}

From source file:com.androguide.honamicontrol.kernel.KernelFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.profiles, menu);
    MenuItem item = menu.findItem(R.id.profile_spinner);
    View spinner = item != null ? item.getActionView() : null;
    if (spinner instanceof android.widget.Spinner) {
        final SharedPreferences profilePrefs = super.getActivity().getSharedPreferences("PROFILES", 0);
        Spinner profiles = (Spinner) spinner;
        profiles.setAdapter(ArrayAdapter.createFromResource(super.getActivity(), R.array.profiles_array,
                R.layout.spinner_action_row));
        profiles.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override//w ww. j  ava 2 s.  co m
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                final int currProfile = profilePrefs.getInt("CURR_PROFILE", 5);
                ActionBarActivity context = (ActionBarActivity) getActivity();
                switch (i) {
                case 0:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryMaxProfile(), context);
                    profileCounter++;
                    break;
                case 1:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryProfile(), context);
                    profileCounter++;
                    break;
                case 2:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BalancedProfile(), context);
                    profileCounter++;
                    break;
                case 3:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new PerformanceProfile(), context);
                    profileCounter++;
                    break;
                case 4:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BenchmarkProfile(), context);
                    profileCounter++;
                    break;
                }
                profilePrefs.edit().putInt("CURR_PROFILE", i).commit();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

        profiles.setSelection(profilePrefs.getInt("CURR_PROFILE", 5));
    }
}

From source file:com.busticket.amedora.busticketsrl.TicketingHomeActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_ticket_home);
    myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);//from   w  w w .  j a  v  a2 s  . c om
    //synchTrips();
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    spBoard = (Spinner) findViewById(R.id.spBoard);
    spBuses = (Spinner) findViewById(R.id.spBusNo);
    spTrips = (Spinner) findViewById(R.id.spTripType);
    spHighlight = (Spinner) findViewById(R.id.spHighlight);
    mAccount = CreateSyncAccount(this);
    mQueue = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicket = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketSynch = Volley.newRequestQueue(getApplicationContext());
    rQSyncBalance = Volley.newRequestQueue(getApplicationContext());
    rqTrip = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketing = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketingSynch = Volley.newRequestQueue(getApplicationContext());
    //Key methods needed to be sent to server on activity created
    syncTicketing();
    syncTickets();

    apps = db.getApp(Installation.appId(getApplicationContext()));
    EMAIL = apps.getRoute_name();
    NAME = "CODE: " + apps.getAgent_code().toUpperCase() + " Trip: " + apps.getTripCount();
    // Get the content resolver for your app
    mResolver = getContentResolver();
    /*
     * Turn on periodic syncing
     */

    mTitle = mDrawerTitle = getTitle();
    ContentResolver.addPeriodicSync(CreateSyncAccount(this), AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL);

    String[] tdata = populateTerminals();
    String[] bdata = populateBuses();
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBoard.setAdapter(adapter);/**/

    ArrayAdapter Hadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata);
    Hadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spHighlight.setAdapter(Hadapter);

    ArrayAdapter gadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bdata);
    gadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBuses.setAdapter(gadapter);

    ArrayAdapter<CharSequence> tadapter = ArrayAdapter.createFromResource(this, R.array.tripTypes,
            android.R.layout.simple_spinner_item);
    tadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    /*ArrayAdapter badapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,bdata);
    badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/
    spTrips.setAdapter(tadapter);

    spBuses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            bus = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spBoard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            board = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spHighlight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            highlight = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spTrips.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            trip = parent.getItemAtPosition(position).toString();

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    btnGenerate = (Button) findViewById(R.id.btnGenerate);

    btnGenerate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // get a new activity to show invoice preview
            sendData();
        }
    });
    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size

    mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    // And passing the titles,icons,header view name, header view email,
    // and header view profile picture

    // Setting the adapter to RecyclerView
    //mRecyclerView.setLayoutManager(mLayoutManager);                 // Setting the layout Manager
    LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(mAdapter);
    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
    // Drawer object Assigned to the view

    mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer,
            R.string.closeDrawer) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
            // open I am not going to put anything here)
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Code here will execute once drawer is closed
            invalidateOptionsMenu();
        }
    }; // Drawer Toggle Object Made
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
    mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State

    final GestureDetector mGestureDetector = new GestureDetector(TicketingHomeActivity.this,
            new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return true;
                }

            });

    mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
            if (child != null && mGestureDetector.onTouchEvent(motionEvent)) {
                Drawer.closeDrawers();
                if (recyclerView.getChildPosition(child) == 1) {

                } else if (recyclerView.getChildPosition(child) == 2) {
                    Intent intent = new Intent(TicketingHomeActivity.this, AccountActivity.class);
                    startActivity(intent);
                } else if (recyclerView.getChildPosition(child) == 3) {
                    Intent intent = new Intent(TicketingHomeActivity.this, TicketListActivity.class);
                    startActivity(intent);
                } else if (recyclerView.getChildPosition(child) == 4) {

                    syncTicketingSynchronize();
                    syncTicketsSynchronize();
                    synchAccount();
                    insertBuses();
                    //insertTerminals();

                    //syncTickets();

                    //dialog = ProgressDialog.show(TicketingHomeActivity.this, "", "Synchronizing App Data. Please wait...", true);
                    /*new Thread(new Runnable() {
                    @Override
                    public void run() {
                            
                        Looper.prepare();
                            
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {*/

                    // insertTerminals();

                    // insertBuses();
                    //getTickets();

                    //Toast.makeText(TicketingHomeActivity.this, "Looper startes ", Toast.LENGTH_SHORT).show();
                    /*handler.removeCallbacks(this);
                            
                    Looper.myLooper().quit();
                    }
                    }, 30000);
                            
                    Looper.loop();
                    }
                    }).start();*/

                } else if (recyclerView.getChildPosition(child) == 5) {
                    if (apps.getLicenceNo() != null) {
                        Intent intent = new Intent(TicketingHomeActivity.this, TripHomeActivity.class);
                        startActivity(intent);

                    } else {
                        //Intent intent = new Intent(TicketingHomeActivity.this,TestPrintActivity.class);
                        //startActivity(intent);
                        Toast.makeText(TicketingHomeActivity.this,
                                "Application is in default mode you cannot use this menu", Toast.LENGTH_SHORT)
                                .show();
                    }

                } else if (recyclerView.getChildPosition(child) == 6) {
                    Intent intent = new Intent(TicketingHomeActivity.this, LogoutActivity.class);
                    startActivity(intent);
                    // Toast.makeText(TicketingHomeActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show();
                }
                return true;
            }
            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

        }
    });
    List<Ticket> issuedTickets = db.getIssuedTickets();
    Log.e("SYNC LOG", issuedTickets.toString());
}

From source file:com.facebook.samples.booleanog.LogicActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    setContentView(R.layout.main);/*from www . jav a 2s .co  m*/

    // Views
    logicButton = (Button) findViewById(R.id.logic_button);
    friendsButton = (Button) findViewById(R.id.friends_button);
    settingsButton = (Button) findViewById(R.id.settings_button);
    contentButton = (Button) findViewById(R.id.content_button);

    logicGroup = (ViewGroup) findViewById(R.id.logic_group);
    leftSpinner = (Spinner) findViewById(R.id.left_spinner);
    rightSpinner = (Spinner) findViewById(R.id.right_spinner);
    andButton = (Button) findViewById(R.id.and_button);
    orButton = (Button) findViewById(R.id.or_button);
    resultText = (TextView) findViewById(R.id.result_text);
    postResultText = (TextView) findViewById(R.id.post_result_text);

    friendsGroup = (ViewGroup) findViewById(R.id.friends_group);
    ListView friendActivityList = (ListView) findViewById(R.id.friend_activity_list);
    String[] mapColumnNames = { "date", "action" };
    int[] mapViewIds = { R.id.friend_action_date, R.id.friend_action_data };
    friendActivityAdapter = new SimpleCursorAdapter(this, R.layout.friend_activity_row, createEmptyCursor(),
            mapColumnNames, mapViewIds);
    friendActivityList.setAdapter(friendActivityAdapter);
    friendActivityProgressBar = (ProgressBar) findViewById(R.id.friend_activity_progress_bar);

    settingsGroup = (ViewGroup) findViewById(R.id.settings_group);

    contentGroup = (ViewGroup) findViewById(R.id.content_group);
    contentImage = (ImageView) findViewById(R.id.content_image);
    contentSpinner = (Spinner) findViewById(R.id.content_spinner);

    // Fragments
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
    if (friendPickerFragment == null) {
        Bundle args = new Bundle();
        args.putBoolean(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, false);
        friendPickerFragment = new FriendPickerFragment(args);
        transaction.add(R.id.friend_picker_fragment, friendPickerFragment);
    }

    userSettingsFragment = (UserSettingsFragment) fragmentManager.findFragmentById(R.id.login_fragment);
    if (userSettingsFragment == null) {
        userSettingsFragment = new UserSettingsFragment();
        transaction.add(R.id.login_fragment, userSettingsFragment);
    }

    transaction.commit();

    // Spinners
    ArrayAdapter<CharSequence> truthAdapter = ArrayAdapter.createFromResource(this, R.array.truth_values,
            android.R.layout.simple_spinner_item);
    truthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    leftSpinner.setAdapter(truthAdapter);
    rightSpinner.setAdapter(truthAdapter);
    contentSpinner.setAdapter(truthAdapter);
    leftSpinner.setSelection(0);
    rightSpinner.setSelection(0);

    // Navigation
    for (Button button : Arrays.asList(logicButton, friendsButton, settingsButton, contentButton)) {
        initializeNavigationButton(button);
    }

    // Logic
    initializeCalculationButton(andButton);
    initializeCalculationButton(orButton);

    // Friends
    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            LogicActivity.this.onError(error);
        }
    });
    friendPickerFragment.setUserId("me");
    friendPickerFragment.setMultiSelect(false);
    friendPickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
        @Override
        public void onSelectionChanged(PickerFragment<?> fragment) {
            LogicActivity.this.onFriendSelectionChanged();
        }
    });
    friendPickerFragment.setExtraFields(Arrays.asList(INSTALLED));
    friendPickerFragment.setFilter(new PickerFragment.GraphObjectFilter<GraphUser>() {
        @Override
        public boolean includeItem(GraphUser graphObject) {
            Boolean installed = graphObject.cast(GraphUserWithInstalled.class).getInstalled();
            return (installed != null) && installed.booleanValue();
        }
    });

    // Content
    contentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            LogicActivity.this.onContentSelectionChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            LogicActivity.this.onContentSelectionChanged();
        }
    });

    // Restore saved state
    Button startButton = logicButton;

    if (savedInstanceState != null) {
        leftSpinner.setSelection(savedInstanceState.getInt(SAVE_LEFT_OPERAND_SELECTION));
        rightSpinner.setSelection(savedInstanceState.getInt(SAVE_RIGHT_OPERAND_SELECTION));
        contentSpinner.setSelection(savedInstanceState.getInt(SAVE_CONTENT_SELECTION));
        resultText.setText(savedInstanceState.getString(SAVE_RESULT_TEXT));
        postResultText.setText(savedInstanceState.getString(SAVE_POST_RESULT_TEXT));
        activeTab = savedInstanceState.getString(SAVE_ACTIVE_TAB);
        pendingPost = savedInstanceState.getBundle(SAVE_PENDING);

        friendActionList = savedInstanceState.getParcelableArrayList(SAVE_FRIEND_ACTIONS);
        if ((friendActionList != null) && (friendActionList.size() > 0)) {
            updateCursor(friendActionList);
        }

        if (getString(R.string.navigate_friends).equals(activeTab)) {
            startButton = friendsButton;
        } else if (getString(R.string.navigate_content).equals(activeTab)) {
            startButton = contentButton;
        } else if (getString(R.string.navigate_settings).equals(activeTab)) {
            startButton = settingsButton;
        }
    }

    if (!handleNativeLink()) {
        onNavigateButtonClick(startButton);
    }
}

From source file:com.armtimes.dialogs.DialogSettings.java

private void initImageQualityControllers(final View view) {
    Spinner spinner = (Spinner) view.findViewById(R.id.spinnerImageQuality);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.image_quality_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);//from   www.j ava2 s  .c om
    spinner.setSelection(getImageQuality(getActivity()));

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setImageQuality(getActivity(), position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}

From source file:org.tvheadend.tvhclient.fragments.TimerRecordingAddFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (channelName != null) {
        TVHClientApplication app = (TVHClientApplication) activity.getApplication();
        List<String> channels = new ArrayList<String>();
        for (Channel c : app.getChannels()) {
            channels.add(c.name);/* w w w.  j av  a  2  s  .  c  o  m*/
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item,
                channels);
        channelName.setAdapter(adapter);
        channelName.setSelection(channelSelectionValue);
    }

    if (priority != null) {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(activity, R.array.dvr_priorities,
                android.R.layout.simple_spinner_item);
        priority.setAdapter(adapter);
        priority.setSelection((int) priorityValue);
    }

    if (daysOfWeek != null) {
        MultiSpinnerListener msl = new MultiSpinnerListener() {
            @Override
            public void onItemsSelected(boolean[] checked) {
                daysOfWeekValue = daysOfWeek.getSpinnerValue();
            }
        };
        List<String> items = new ArrayList<String>(
                Arrays.asList(getResources().getStringArray(R.array.day_long_names)));
        List<String> textItems = new ArrayList<String>(
                Arrays.asList(getResources().getStringArray(R.array.day_short_names)));
        daysOfWeek.setItems(items, textItems, daysOfWeekValue, msl);
    }

    if (startTime != null && stopTime != null) {
        // Converts the value in minutes into a time format
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm", Locale.US);

        // Fill the list with the time values from 0:00 to 23:50
        List<String> timeList = new ArrayList<String>();
        for (int i = 0; i <= 1430; i += 10) {
            String time = formatter.format(new Date(i * 60L * 1000L));
            timeList.add(time);
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item,
                timeList);
        startTime.setAdapter(adapter);
        stopTime.setAdapter(adapter);

        String start = formatter.format(new Date(startTimeValue * 60L * 1000L));
        String stop = formatter.format(new Date(stopTimeValue * 60L * 1000L));
        startTime.setSelection(adapter.getPosition(start));
        stopTime.setSelection(adapter.getPosition(stop));
    }

    if (title != null) {
        title.setText(titleValue);
    }
    if (name != null) {
        name.setText(nameValue);
    }
    if (directory != null) {
        directory.setText(directoryValue);
    }
    if (retention != null) {
        retention.setText(String.valueOf(retentionValue));
    }
    if (isEnabled != null) {
        isEnabled.setChecked(enabledValue);
    }

    if (toolbar != null) {
        if (rec != null) {
            toolbar.setTitle((rec.name.length() > 0) ? rec.name : rec.title);
        }
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                return onToolbarItemSelected(item);
            }
        });
        // Inflate a menu to be displayed in the toolbar
        toolbar.inflateMenu(R.menu.save_cancel_menu);
        toolbar.setTitle(R.string.add_recording);
    }
}

From source file:com.creationgroundmedia.popularmovies.MovieListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    inflater.inflate(R.menu.menu_fragment, menu);
    /**//w  w w  . ja v  a2 s .c o m
     * use a spinner to select sort order, that way the user can always see what the order is
     */
    MenuItem item = menu.findItem(R.id.action_sorting_spinner);
    Spinner sortingSpinner = (Spinner) MenuItemCompat.getActionView(item);
    ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.sorting_modes,
            R.layout.spinner_item);
    spinnerAdapter.setDropDownViewResource(R.layout.spinner_item);
    sortingSpinner.setAdapter(spinnerAdapter);
    sortingSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            sortOrder = sortOrders[position];
            movieCursorLoader = getSupportLoaderManager().restartLoader(URL_LOADER, null,
                    MovieListActivity.this);
            recyclerView.getAdapter().notifyDataSetChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    item = menu.findItem(R.id.action_faves_only);
    Button faveButton = (Button) MenuItemCompat.getActionView(item);
    faveButton.setSelected(mFavoritesOnly);
    faveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFavoritesOnly = !v.isSelected();
            v.setSelected(mFavoritesOnly);
            mSelectFavorites = mFavoritesOnly ? MoviesContract.MovieEntry.COLUMN_FAVORITE + " = 1" : null;
            movieCursorLoader = getSupportLoaderManager().restartLoader(URL_LOADER, null,
                    MovieListActivity.this);
        }
    });

    return super.onCreateOptionsMenu(menu);
}