Example usage for android.widget ArrayAdapter setDropDownViewResource

List of usage examples for android.widget ArrayAdapter setDropDownViewResource

Introduction

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

Prototype

public void setDropDownViewResource(@LayoutRes int resource) 

Source Link

Document

Sets the layout resource to create the drop down views.

Usage

From source file:net.reichholf.dreamdroid.activities.TimerEditActivity.java

/**
 * Set the GUI-Content from <code>mTimer</code>
 *///  www .  j  av a2s.  c o  m
private void reload() {
    // Name
    mName.setText(mTimer.getString(Timer.NAME));
    mName.setHint(R.string.title);

    // Description
    mDescription.setText(mTimer.getString(Timer.DESCRIPTION));
    mDescription.setHint(R.string.description);

    // Enabled
    int disabled = new Integer(mTimer.getString(Timer.DISABLED));
    if (disabled == 0) {
        mEnabled.setChecked(true);
    } else {
        mEnabled.setChecked(false);
    }

    mService.setText(mTimer.getString(Timer.SERVICE_NAME));

    // Afterevents
    ArrayAdapter<CharSequence> aaAfterevent = ArrayAdapter.createFromResource(this, R.array.afterevents,
            android.R.layout.simple_spinner_item);
    aaAfterevent.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mAfterevent.setAdapter(aaAfterevent);

    int aeValue = new Integer(mTimer.getString(Timer.AFTER_EVENT)).intValue();
    mAfterevent.setSelection(aeValue);

    // Locations
    ArrayAdapter<String> aaLocations = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            DreamDroid.LOCATIONS);
    aaLocations.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLocation.setAdapter(aaLocations);

    String timerLoc = mTimer.getString(Timer.LOCATION);
    for (int i = 0; i < DreamDroid.LOCATIONS.size(); i++) {
        String loc = DreamDroid.LOCATIONS.get(i);

        if (timerLoc != null) {
            if (timerLoc.equals(loc)) {
                mLocation.setSelection(i);
            }
        }
    }

    // Start and Endtime
    int begin = new Integer(mTimer.getString(Timer.BEGIN));
    int end = new Integer(mTimer.getString(Timer.END));
    long b = ((long) begin) * 1000;
    long e = ((long) end) * 1000;
    Date dateBegin = new Date(b);
    Date dateEnd = new Date(e);

    mStart.setText(dateBegin.toLocaleString());
    mEnd.setText(dateEnd.toLocaleString());

    // Repeatings
    int repeatedValue = new Integer(mTimer.getString(Timer.REPEATED));
    String repeatedText = getRepeated(repeatedValue);
    mRepeatings.setText(repeatedText);

    String text = mTimer.getString(Timer.TAGS);
    if (text == null) {
        text = "";
    }
    mTags.setText(text);
    String[] tags = text.split(" ");
    for (String tag : tags) {
        mSelectedTags.add(tag);
    }
}

From source file:edu.cmu.hcii.hangg.beeksbeacon.Fragments.ManageBeaconFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i(TAG, "bi.id: " + beaconInstance.id + ", bi.googleType: " + beaconInstance.googleType);
    View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false);

    advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type);
    advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id);
    status = (TextView) rootView.findViewById(R.id.status);
    placeId = (TextView) rootView.findViewById(R.id.placeId);
    placeId.setOnClickListener(new View.OnClickListener() {
        @Override/*  w  w w . j  av  a 2  s  .com*/
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    latLng = (TextView) rootView.findViewById(R.id.latLng);
    latLng.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    mapView = (ImageView) rootView.findViewById(R.id.mapView);
    mapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });

    expectedStability = (TextView) rootView.findViewById(R.id.expectedStability);
    expectedStability.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability");
            final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
                    R.array.stability_enums, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            final Spinner spinner = new Spinner(getActivity());
            spinner.setAdapter(adapter);
            // Set the position of the spinner to the current value.
            if (beaconInstance.expectedStability != null
                    && !beaconInstance.expectedStability.equals(BeaconInstance.STABILITY_UNSPECIFIED)) {
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (beaconInstance.expectedStability.equals(spinner.getItemAtPosition(i))) {
                        spinner.setSelection(i);
                    }
                }
            }
            builder.setView(spinner);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beaconInstance.expectedStability = (String) spinner.getSelectedItem();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    description = (TextView) rootView.findViewById(R.id.description);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description");
            final EditText editText = new EditText(getActivity());
            editText.setText(description.getText());
            builder.setView(editText);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beaconInstance.description = editText.getText().toString();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    actionButton = (Button) rootView.findViewById(R.id.actionButton);

    decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton);
    decommissionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon")
                    .setMessage("Are you sure you want to decommission this beacon? This operation is "
                            + "irreversible and the beacon cannot be registered again")
                    .setPositiveButton("Decommission", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            Callback decommissionCallback = new Callback() {
                                @Override
                                public void onFailure(Request request, IOException e) {
                                    logErrorAndToast("Failed request: " + request, e);
                                }

                                @Override
                                public void onResponse(Response response) throws IOException {
                                    if (response.isSuccessful()) {
                                        beaconInstance.status = BeaconInstance.STATUS_DECOMMISSIONED;
                                        updateBeacon();
                                    } else {
                                        String body = response.body().string();
                                        logErrorAndToast("Unsuccessful decommissionBeacon request: " + body);
                                    }
                                }
                            };
                            client.decommissionBeacon(decommissionCallback, beaconInstance.getBeaconName());
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).show();
        }
    });

    attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider);
    attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel);
    attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout);

    // Fetch the namespace for the developer console project ID. We redraw the UI once that
    // request completes.
    // TODO: cache this.
    Callback listNamespacesCallback = new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            logErrorAndToast("Failed request: " + request, e);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            String body = response.body().string();
            if (response.isSuccessful()) {
                try {
                    JSONObject json = new JSONObject(body);
                    JSONArray namespaces = json.getJSONArray("namespaces");
                    // At present there can be only one namespace.
                    String tmp = namespaces.getJSONObject(0).getString("namespaceName");
                    if (tmp.startsWith("namespaces/")) {
                        namespace = tmp.substring("namespaces/".length());
                    } else {
                        namespace = tmp;
                    }
                    redraw();
                } catch (JSONException e) {
                    Log.e(TAG, "JSONException", e);
                }
            } else {
                logErrorAndToast("Unsuccessful listNamespaces request: " + body);
            }
        }
    };
    client.listNamespaces(listNamespacesCallback);
    return rootView;
}

From source file:com.joefernandez.irrduino.android.remote.IrrduinoRemoteActivity.java

public ArrayAdapter<SpinnerItemData> getSpinnerAdapter() {
    ArrayAdapter<SpinnerItemData> adapter = new ArrayAdapter<SpinnerItemData>(this,
            android.R.layout.simple_spinner_item);

    adapter.add(new SpinnerItemData("1 Minute", 1));
    adapter.add(new SpinnerItemData("2 Minutes", 2));
    adapter.add(new SpinnerItemData("3 Minutes", 3));
    adapter.add(new SpinnerItemData("4 Minutes", 4));
    adapter.add(new SpinnerItemData("5 Minutes", 5));
    adapter.add(new SpinnerItemData("6 Minutes", 6));
    adapter.add(new SpinnerItemData("7 Minutes", 7));
    adapter.add(new SpinnerItemData("8 Minutes", 8));
    adapter.add(new SpinnerItemData("9 Minutes", 9));
    adapter.add(new SpinnerItemData("10 Minutes", 10));

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return adapter;
}

From source file:com.example.android.contactslist.ui.chartActivity.ContactDetailChartFragment.java

private void addItemsToChartSpinner() {

    //set the adapter to the string-array in the strings resource
    ArrayAdapter<String> chartFeedSelectionAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.array_of_event_classes));

    //choose the style of the list.
    chartFeedSelectionAdapter.setDropDownViewResource(android.R.layout.simple_list_item_activated_1);

    mClassSelectionSpinner.setAdapter(chartFeedSelectionAdapter);
}

From source file:com.androidquery.simplefeed.activity.PostActivity.java

public void albumCb(String url, JSONObject jo, AjaxStatus status) {

    AQUtility.debug(jo);//from  w w  w .  j a va  2  s. c  o m

    List<Entry> albums = new ArrayList<Entry>();

    albums.add(new Entry(getString(R.string.app_name), "me"));

    int position = 0;

    if (jo != null) {

        JSONArray ja = jo.optJSONArray("data");
        for (int i = 0; i < ja.length(); i++) {
            JSONObject album = ja.optJSONObject(i);
            String name = album.optString("name");
            String id = album.optString("id");
            if ("mobile".equals(album.optString("type", "me"))) {
                position = i + 1;
            }
            albums.add(new Entry(name, id));
        }

        if (status.expired(HALF_DAY)) {
            albumCheck(-1);
        }

    }

    ArrayAdapter<Entry> adapter = new ArrayAdapter<Entry>(this, android.R.layout.simple_spinner_item, albums);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    aq.id(R.id.spinner_album).adapter(adapter).setSelection(position).visible();

}

From source file:dev.drsoran.moloko.fragments.AbstractTaskEditFragment.java

protected void createLocationSpinnerAdapterForValues(List<String> locationIds, List<String> locationNames) {
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getSherlockActivity(),
            android.R.layout.simple_spinner_item, android.R.id.text1, new ArrayList<String>(locationNames));
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    locationSpinner.setAdapter(adapter);
    locationSpinner.setValues(new ArrayList<String>(locationIds));
    locationSpinner.setSelectionByValue(getCurrentValue(Tasks.LOCATION_ID, String.class), 0);
}

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   ww  w .ja  v a2  s . c  o  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.pdftron.pdf.controls.AddPageDialogFragment.java

private ArrayAdapter<CharSequence> getOrientationSpinnerAdapter() {
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item);
    for (PageOrientation size : PageOrientation.values()) {
        switch (size) {
        case Portrait:
            adapter.add(getString(R.string.dialog_add_page_orientation_portrait));
            break;
        case Landscape:
            adapter.add(getString(R.string.dialog_add_page_orientation_landscape));
            break;
        }//ww  w  . j  a  v a2 s.c  om
    }
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return adapter;
}

From source file:com.towson.wavyleaf.Sighting.java

protected void init() {
    getWindow().setBackgroundDrawable(null);
    Typeface tf_light = Typeface.createFromAsset(getAssets(), "fonts/roboto_light.ttf");
    Typeface tf_bold = Typeface.createFromAsset(getAssets(), "fonts/roboto_bold.ttf");

    tvlat = (TextView) findViewById(R.id.tv_latitude);
    tvlong = (TextView) findViewById(R.id.tv_longitude);
    tvpicnotes = (TextView) findViewById(R.id.tv_picturenotes);
    tvper = (TextView) findViewById(R.id.tv_percentageseen);
    tvper_summary = (TextView) findViewById(R.id.tv_percentageseen_summary);
    tvcoor = (TextView) findViewById(R.id.tv_coordinates);
    tvarea = (TextView) findViewById(R.id.tv_areainfested);
    tvarea_summary = (TextView) findViewById(R.id.tv_areainfested_summary);
    tv_treatment = (TextView) findViewById(R.id.tv_treatment);
    notes = (EditText) findViewById(R.id.notes);
    etarea = (EditText) findViewById(R.id.et_areainfested);
    b1 = (ToggleButton) findViewById(R.id.bu_1);
    b2 = (ToggleButton) findViewById(R.id.bu_2);
    b3 = (ToggleButton) findViewById(R.id.bu_3);
    b4 = (ToggleButton) findViewById(R.id.bu_4);
    b5 = (ToggleButton) findViewById(R.id.bu_5);
    b6 = (ToggleButton) findViewById(R.id.bu_6);
    cb = (CheckBox) findViewById(R.id.cb_confirm);
    rg = (RadioGroup) findViewById(R.id.toggleGroup);
    sp = (Spinner) findViewById(R.id.sp_areainfested);
    sp_treatment = (Spinner) findViewById(R.id.sp_treatment);
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationData = (LocationApplication) getApplication();
    currentEditableLocation = locationData.getLocation();

    updateLocationTimer = new Timer();
    TimerTask updateLocationTask = new TimerTask() {
        @Override/*from  ww  w .  ja v  a2s .  com*/
        public void run() {
            checkLocation();
        }
    };
    updateLocationTimer.scheduleAtFixedRate(updateLocationTask, 0, FIVE_SECONDS);

    // Listener for EditText in Area Infested
    etarea.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (etarea.getText().length() == 0) {
                tvarea_summary.setText("");
            } else if (etarea.getText().toString().contains("-")) { // Negative number
                etarea.getEditableText().clear();
                Toast.makeText(getApplicationContext(), "Negative values not allowed", Toast.LENGTH_SHORT)
                        .show();
            } else {
                tvarea_summary.setText(etarea.getText() + " " + sp.getSelectedItem().toString());
            }
        }

        public void afterTextChanged(Editable s) {
        }

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

    // Listener for spinner in Area Infested
    sp.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (etarea.getText().length() != 0)
                tvarea_summary.setText(etarea.getText() + " " + sp.getSelectedItem());
        }
    });

    // Adapter for area infested spinner
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.areainfested_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp.setAdapter(adapter);

    // Adapter for Treatment spinner
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.treatment_array,
            android.R.layout.simple_spinner_item);
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp_treatment.setAdapter(adapter2);

    // Just to be safe
    cb.setChecked(false);

    // Set all the beautiful typefaces
    tvlat.setTypeface(tf_light);
    tvlong.setTypeface(tf_light);
    tvcoor.setTypeface(tf_bold);
    tvarea.setTypeface(tf_bold);
    tvarea_summary.setTypeface(tf_bold);
    tvper.setTypeface(tf_bold);
    tvper_summary.setTypeface(tf_bold);
    tvpicnotes.setTypeface(tf_bold);
    tv_treatment.setTypeface(tf_bold);
    cb.setTypeface(tf_light);
    b1.setTypeface(tf_light);
    b2.setTypeface(tf_light);
    b3.setTypeface(tf_light);
    b4.setTypeface(tf_light);
    b5.setTypeface(tf_light);
    b6.setTypeface(tf_light);

    if (!locationData.isSearching())
        findUsersLocation();

    ib = (ImageButton) findViewById(R.id.imagebutton_sighting);
    // Listener for camera button
    ib.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            takePicture();
        }
    });

    ib_percent = (ImageButton) findViewById(R.id.ib_percent);
    // Listener for help button in Percentage Infested category
    ib_percent.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            showDialog(HELP_PERCENT);
        }
    });

    ib_treatment = (ImageButton) findViewById(R.id.ib_treatment);
    // Listener for help button in Treatment catgeory
    ib_treatment.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            showDialog(HELP_TREATMENT);
            //            Toast.makeText(getApplicationContext(), "Specify the type of treatment that was done to this area", Toast.LENGTH_LONG).show();
        }
    });
}

From source file:com.pluscubed.velociraptor.settings.SettingsActivity.java

@SuppressWarnings("ConstantConditions")
@Override//from  w w w  .  j  a  v a2s .  co m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    ButterKnife.bind(this);

    setSupportActionBar(toolbar);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        View marshmallowPermissionsCard = findViewById(R.id.card_m_permissions);
        marshmallowPermissionsCard.setVisibility(View.GONE);
    }

    openStreetMapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ShareCompat.IntentBuilder.from(SettingsActivity.this).setText("https://www.openstreetmap.org")
                    .setType("text/plain").startChooser();
        }
    });

    checkCoverageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            googleApiClient = new GoogleApiClient.Builder(SettingsActivity.this)
                    .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                        @Override
                        @SuppressWarnings("MissingPermission")
                        public void onConnected(@Nullable Bundle bundle) {
                            String uriString = "http://product.itoworld.com/map/124";
                            if (Utils.isLocationPermissionGranted(SettingsActivity.this)) {
                                Location lastLocation = LocationServices.FusedLocationApi
                                        .getLastLocation(googleApiClient);
                                if (lastLocation != null) {
                                    uriString += "?lon=" + lastLocation.getLongitude() + "&lat="
                                            + lastLocation.getLatitude() + "&zoom=12";
                                }
                            }
                            Intent intent = new Intent();
                            intent.setData(Uri.parse(uriString));
                            intent.setAction(Intent.ACTION_VIEW);
                            try {
                                startActivity(intent);
                            } catch (ActivityNotFoundException e) {
                                Snackbar.make(enableFloatingButton, R.string.open_coverage_map_failed,
                                        Snackbar.LENGTH_LONG).show();
                            }

                            googleApiClient.disconnect();
                        }

                        @Override
                        public void onConnectionSuspended(int i) {
                        }
                    }).addApi(LocationServices.API).build();

            googleApiClient.connect();
        }
    });

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notifControlsContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(SettingsActivity.this, SpeedLimitService.class);
            intent.putExtra(SpeedLimitService.EXTRA_NOTIF_START, true);
            PendingIntent pending = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent intentClose = new Intent(SettingsActivity.this, SpeedLimitService.class);
            intentClose.putExtra(SpeedLimitService.EXTRA_NOTIF_CLOSE, true);
            PendingIntent pendingClose = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE_CLOSE,
                    intentClose, PendingIntent.FLAG_CANCEL_CURRENT);

            Intent settings = new Intent(SettingsActivity.this, SettingsActivity.class);
            PendingIntent settingsIntent = PendingIntent.getActivity(SettingsActivity.this, PENDING_SETTINGS,
                    settings, PendingIntent.FLAG_CANCEL_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(SettingsActivity.this)
                    .setSmallIcon(R.drawable.ic_speedometer)
                    .setContentTitle(getString(R.string.controls_notif_title))
                    .setContentText(getString(R.string.controls_notif_desc))
                    .addAction(0, getString(R.string.show), pending)
                    .addAction(0, getString(R.string.hide), pendingClose).setDeleteIntent(pendingClose)
                    .setContentIntent(settingsIntent);
            Notification notification = builder.build();
            notificationManager.notify(NOTIFICATION_CONTROLS, notification);
        }
    });

    appSelectionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(SettingsActivity.this, AppSelectionActivity.class));
        }
    });

    appDetectionSwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this));
    appDetectionContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            appDetectionSwitch.toggle();
            boolean autoDisplayEnabled = appDetectionSwitch.isChecked();
            PrefUtils.setAutoDisplay(SettingsActivity.this, autoDisplayEnabled);
            updateAppDetectionOptionStates();
        }
    });

    enableServiceButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
            } catch (ActivityNotFoundException e) {
                Snackbar.make(enableServiceButton, R.string.open_settings_failed_accessibility,
                        Snackbar.LENGTH_LONG).show();
            }
        }
    });

    enableFloatingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                //Open the current default browswer App Info page
                openSettings(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, BuildConfig.APPLICATION_ID);
            } catch (ActivityNotFoundException ignored) {
                Snackbar.make(enableFloatingButton, R.string.open_settings_failed_overlay, Snackbar.LENGTH_LONG)
                        .show();
            }
        }
    });

    enableLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityCompat.requestPermissions(SettingsActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION);
        }
    });

    ArrayAdapter<String> unitAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text,
            new String[] { "mph", "km/h" });
    unitAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    unitSpinner.setAdapter(unitAdapter);
    unitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (PrefUtils.getUseMetric(SettingsActivity.this) != (position == 1)) {
                PrefUtils.setUseMetric(SettingsActivity.this, position == 1);
                unitSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this,
                        unitSpinner.getSelectedItemPosition() * -48));

                Utils.updateFloatingServicePrefs(SettingsActivity.this);
            }
        }

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

        }
    });
    unitSpinner.setSelection(PrefUtils.getUseMetric(this) ? 1 : 0);
    unitSpinner
            .setDropDownVerticalOffset(Utils.convertDpToPx(this, unitSpinner.getSelectedItemPosition() * -48));

    ArrayAdapter<String> styleAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text,
            new String[] { getString(R.string.united_states), getString(R.string.international) });
    styleAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    styleSpinner.setAdapter(styleAdapter);
    styleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position != PrefUtils.getSignStyle(SettingsActivity.this)) {
                PrefUtils.setSignStyle(SettingsActivity.this, position);
                styleSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this,
                        styleSpinner.getSelectedItemPosition() * -48));

                Utils.updateFloatingServicePrefs(SettingsActivity.this);
            }
        }

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

        }
    });
    styleSpinner.setSelection(PrefUtils.getSignStyle(this));
    styleSpinner
            .setDropDownVerticalOffset(Utils.convertDpToPx(this, styleSpinner.getSelectedItemPosition() * -48));

    toleranceView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new ToleranceDialogFragment().show(getFragmentManager(), "dialog_tolerance");
        }
    });

    sizeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new SizeDialogFragment().show(getFragmentManager(), "dialog_size");
        }
    });

    opacityView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new OpacityDialogFragment().show(getFragmentManager(), "dialog_opacity");
        }
    });

    showSpeedometerSwitch.setChecked(PrefUtils.getShowSpeedometer(this));
    ((View) showSpeedometerSwitch.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSpeedometerSwitch.setChecked(!showSpeedometerSwitch.isChecked());

            PrefUtils.setShowSpeedometer(SettingsActivity.this, showSpeedometerSwitch.isChecked());

            Utils.updateFloatingServicePrefs(SettingsActivity.this);
        }
    });

    debuggingSwitch.setChecked(PrefUtils.isDebuggingEnabled(this));
    ((View) debuggingSwitch.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            debuggingSwitch.setChecked(!debuggingSwitch.isChecked());

            PrefUtils.setDebugging(SettingsActivity.this, debuggingSwitch.isChecked());

            Utils.updateFloatingServicePrefs(SettingsActivity.this);
        }
    });

    beepSwitch.setChecked(PrefUtils.isBeepAlertEnabled(this));
    beepSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PrefUtils.setBeepAlertEnabled(SettingsActivity.this, beepSwitch.isChecked());
        }
    });
    testBeepButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.playBeep();
        }
    });

    androidAutoSwitch.setChecked(PrefUtils.isAutoIntegrationEnabled(this));
    androidAutoContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BuildConfig.FLAVOR.equals("play")) {
                Snackbar.make(findViewById(android.R.id.content), R.string.auto_not_available,
                        Snackbar.LENGTH_LONG).show();
                return;
            }
            if (!androidAutoSwitch.isEnabled()) {
                return;
            }
            androidAutoSwitch.toggle();
            boolean checked = androidAutoSwitch.isChecked();
            if (checked) {
                new MaterialDialog.Builder(SettingsActivity.this)
                        .content(R.string.android_auto_instruction_dialog).positiveText(android.R.string.ok)
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, true);
                            }
                        }).show();
            } else {
                PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, checked);
            }
        }
    });

    invalidateStates();

    if (BuildConfig.VERSION_CODE > PrefUtils.getVersionCode(this) && !PrefUtils.isFirstRun(this)) {
        showChangelog();
    }

    billingProcessor = new BillingProcessor(this, getString(R.string.play_license_key),
            new BillingProcessor.IBillingHandler() {
                @Override
                public void onProductPurchased(String productId, TransactionDetails details) {
                    PrefUtils.setSupported(SettingsActivity.this, true);
                    if (Arrays.asList(PURCHASES).contains(productId))
                        billingProcessor.consumePurchase(productId);
                }

                @Override
                public void onPurchaseHistoryRestored() {

                }

                @Override
                public void onBillingError(int errorCode, Throwable error) {
                    if (errorCode != 110) {
                        Snackbar.make(findViewById(android.R.id.content),
                                "Billing error: code = " + errorCode + ", error: "
                                        + (error != null ? error.getMessage() : "?"),
                                Snackbar.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onBillingInitialized() {
                    billingProcessor.loadOwnedPurchasesFromGoogle();
                }
            });

    PrefUtils.setFirstRun(this, false);
    PrefUtils.setVersionCode(this, BuildConfig.VERSION_CODE);
}