List of usage examples for android.widget ArrayAdapter createFromResource
public static @NonNull ArrayAdapter<CharSequence> createFromResource(@NonNull Context context, @ArrayRes int textArrayResId, @LayoutRes int textViewResId)
From source file:no.barentswatch.fiskinfo.MapActivity.java
/** * /* w w w. j av a2 s. c o m*/ * @param activityContext * The context of the current activity */ @SuppressLint("InflateParams") public void setProximityAlertDialog(Context activityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_scheduled_task_executor, null); final AlertDialog builder = new AlertDialog.Builder(activityContext).create(); builder.setTitle(R.string.map_set_proximity_alert_title); builder.setView(view); final EditText distanceEditText = (EditText) view.findViewById(R.id.scheduledProximityRangeEditText); final SeekBar seekbar = (SeekBar) view.findViewById(R.id.scheduledSetProximityRangeSeekBar); distanceEditText.setText(String.valueOf(minLenghtMeters)); final Spinner measuringUnitSpinner = (Spinner) view.findViewById(R.id.scheduledMeasuringUnitsSpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.measurement_units, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); measuringUnitSpinner.setAdapter(adapter); seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser == true) { if (currentlySelected == meterIndex) { distanceEditText .setText(String.valueOf((int) (minLenghtMeters + (stepSizeMeters * progress)))); } else if (currentlySelected == nauticalMileIndex) { distanceEditText.setText( String.valueOf(minLenghtNauticalMiles + (stepSizeNauticalMiles * progress))); } } } }); measuringUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { double distance = (distanceEditText.length() != 0 ? Double.parseDouble(distanceEditText.getText().toString()) : 0); System.out.println("posistion: " + position); System.out.println("currentlySelected: " + position); if (position == meterIndex) { if (position != currentlySelected) { distance = convertDistance(distance, position); distanceEditText.setText(String.valueOf(distance)); currentlySelected = position; } } else if (position == nauticalMileIndex) { if (position != currentlySelected) { distance = convertDistance(distance, position); distanceEditText.setText(String.valueOf(distance)); currentlySelected = position; } } else { return; } System.out.println("distance: " + distance); int newProgress = findProgress(distance, position); seekbar.setProgress(newProgress); System.out.println("progress: " + newProgress); distanceEditText.setText(String.valueOf(distance)); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); Button setProximityAlertButton = (Button) view.findViewById(R.id.scheduledSetProximityCheckerDialogButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); builder.setView(view); builder.setCanceledOnTouchOutside(false); setProximityAlertButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (!alarmSet) { mGpsLocationTracker = new GpsLocationTracker(getContext()); double latitude, longitude = 0; if (mGpsLocationTracker.canGetLocation()) { latitude = mGpsLocationTracker.getLatitude(); cachedLat = latitude; longitude = mGpsLocationTracker.getLongitude(); cachedLon = longitude; } else { mGpsLocationTracker.showSettingsAlert(); return; } String distance = distanceEditText.getText().toString(); cachedDistance = distance; cacheWriter = new DownloadMapLayerFromBarentswatchApiInBackground().execute("fishingfacility", "OLEX", "cachedResults", String.valueOf(longitude), String.valueOf(latitude), distance, "true"); alarmSet = true; runScheduledAlarm(); } builder.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { builder.cancel(); } }); builder.show(); }
From source file:com.z299studio.pb.EditFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mApp == null || mApp.getAccountManager() == null) { return null; }/*from ww w. j a v a 2 s . co m*/ View rootView = inflater.inflate(R.layout.fragment_edit, container, false); mContainer = (LinearLayout) rootView.findViewById(android.R.id.list); View footer = inflater.inflate(R.layout.add_field, container, false); footer.setOnClickListener(this); mNameEditText = (EditText) rootView.findViewById(android.R.id.title); mScroll = (PbScrollView) rootView.findViewById(R.id.scroll); mNameEditText.addTextChangedListener(this); mToolbarContainer = rootView.findViewById(R.id.toolbar_container); if (mToolbarContainer != null) { mHeader = rootView.findViewById(R.id.header); mScroll.setPbScrollListener(this); } setupToolbar(rootView); mCategorySpinner = (Spinner) rootView.findViewById(R.id.category); if (mAccountId >= 0) { mDummyAccount = mApp.getAccountManager().getAccountById(mAccountId).clone(); mName = mDummyAccount.getAccountName(); } else { mDummyAccount = getEntryList(); mName = ""; } int spinnerLayout = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN ? android.R.layout.simple_spinner_dropdown_item : R.layout.spinner_dropdown; mTypeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.field_types, android.R.layout.simple_spinner_dropdown_item); mTypeAdapter.setDropDownViewResource(spinnerLayout); mEntries = new ArrayList<>(); mDeleteView = (ImageView) inflater.inflate(R.layout.delete_field, container, false); int pos = 0; for (Entry e : mDummyAccount.getEntryList()) { onAddField(e, pos++); } mContainer.addView(footer); mContainer.addView(mDeleteView); mDeleteView.setOnDragListener(mDragListener); ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, mApp.getSortedCategoryNames()); spinnerAdapter.setDropDownViewResource(spinnerLayout); mCategorySpinner.setAdapter(spinnerAdapter); mCategorySpinner.setOnItemSelectedListener(this); View top = rootView.findViewById(R.id.top_frame); if (top != null) { top.setOnClickListener(this); } return rootView; }
From source file:com.teitsmch.hearthmaker.MainActivity.java
private void setSpinnerAdapter(Spinner currentSpinner, int arrayId) { ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arrayId, R.layout.spinner_item); adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); currentSpinner.setAdapter(adapter);// w w w.j ava 2 s. c o m }
From source file:us.theparamountgroup.android.inventory.EditorActivity.java
/** * Setup the dropdown spinner that allows the user to select the type of shell. *//*from w w w. ja va2 s. c o m*/ private void setupTypeSpinner() { // Create adapter for spinner. The list options are from the String array it will use // the spinner will use the default layout ArrayAdapter typeSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_type_options, android.R.layout.simple_spinner_item); // Specify dropdown layout style - simple list view with 1 item per line typeSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); // Apply the adapter to the spinner mTypeSpinner.setAdapter(typeSpinnerAdapter); // Set the integer mSelected to the constant values mTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String selection = (String) parent.getItemAtPosition(position); if (!TextUtils.isEmpty(selection)) { if (selection.equals(getString(R.string.type_scallop))) { mType = ShellContract.ShellEntry.TYPE_SCALLOP; } else if (selection.equals(getString(R.string.type_jingle))) { mType = ShellContract.ShellEntry.TYPE_JINGLE; } else if (selection.equals(getString(R.string.type_slipper))) { mType = ShellContract.ShellEntry.TYPE_SLIPPER; } else { mType = ShellContract.ShellEntry.TYPE_SHARD; } } } // Because AdapterView is an abstract class, onNothingSelected must be defined @Override public void onNothingSelected(AdapterView<?> parent) { mType = ShellContract.ShellEntry.TYPE_SCALLOP; } }); }
From source file:com.cypress.cysmart.BLEServiceFragments.FindMeService.java
/** * Method to get required characteristics from service */// w w w. j ava2s . c o m private void getGattData() { LinearLayout ll_layout = (LinearLayout) rootView.findViewById(R.id.linkloss_layout); LinearLayout im_layout = (LinearLayout) rootView.findViewById(R.id.immalert_layout); LinearLayout tp_layout = (LinearLayout) rootView.findViewById(R.id.transmission_layout); RelativeLayout tpr_layout = (RelativeLayout) rootView.findViewById(R.id.transmission_rel_layout); for (int position = 0; position < mExtraservice.size(); position++) { HashMap<String, BluetoothGattService> item = mExtraservice.get(position); BluetoothGattService bgs = item.get("UUID"); List<BluetoothGattCharacteristic> gattCharacteristicsCurrent = bgs.getCharacteristics(); for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristicsCurrent) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.ALERT_LEVEL)) { if (bgs.getUuid().toString().equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE)) { ll_layout.setVisibility(View.VISIBLE); mSpinnerLinkLoss = (CustomSpinner) rootView.findViewById(R.id.linkloss_spinner); // Create an ArrayAdapter using the string array and a // default // spinner layout ArrayAdapter<CharSequence> adapter_linkloss = ArrayAdapter.createFromResource(getActivity(), R.array.findme_immediate_alert_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices // appears adapter_linkloss.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mSpinnerLinkLoss.setAdapter(adapter_linkloss); mSpinnerLinkLoss.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("No Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_NO_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("Mid Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_MID_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_MID_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("High Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_HIGH_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); } if (bgs.getUuid().toString().equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE)) { im_layout.setVisibility(View.VISIBLE); mSpinnerImmediateAlert = (CustomSpinner) rootView.findViewById(R.id.immediate_spinner); // Create an ArrayAdapter using the string array and a // default // spinner layout ArrayAdapter<CharSequence> adapter_immediate_alert = ArrayAdapter.createFromResource( getActivity(), R.array.findme_immediate_alert_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices // appears adapter_immediate_alert .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mSpinnerImmediateAlert.setAdapter(adapter_immediate_alert); mSpinnerImmediateAlert.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("No Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_NO_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("Mid Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_MID_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_MID_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("High Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_HIGH_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); } } if (uuidchara.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_LEVEL)) { tp_layout.setVisibility(View.VISIBLE); tpr_layout.setVisibility(View.VISIBLE); mReadCharacteristic_tp = gattCharacteristic; mTransmissionPower = (ImageView) rootView.findViewById(R.id.findme_tx_power_img); mTransmissionPowerValue = (TextView) rootView.findViewById(R.id.findme_tx_power_txt); if (mReadCharacteristic_tp != null) { prepareBroadcastDataReadtp(mReadCharacteristic_tp); } } } } }
From source file:com.farbod.labelledspinner.LabelledSpinner.java
/** * Sets the array of items to be used in the Spinner. * * @param arrayResId The identifier of the array to use as the data * source (e.g. {@code R.array.myArray}) * @param spinnerItemRes The identifier of the layout used to create * views (e.g. {@code R.layout.my_item}) * @param dropdownViewRes The layout resource to create the drop down * views (e.g. {@code R.layout.my_dropdown}) * * @see #setItemsArray(int)//ww w .ja v a2 s . co m * @see #setItemsArray(CharSequence[]) * @see #setItemsArray(CharSequence[], int, int) * @see #setItemsArray(List) * @see #setItemsArray(List, int, int) * * @attr ref R.styleable#LabelledSpinner_entries */ public void setItemsArray(@ArrayRes int arrayResId, @LayoutRes int spinnerItemRes, @LayoutRes int dropdownViewRes) { ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), arrayResId, spinnerItemRes); adapter.setDropDownViewResource(dropdownViewRes); mSpinner.setAdapter(adapter); }
From source file:org.gnucash.android.ui.export.ExportFormFragment.java
/** * Bind views to actions when initializing the export form *///from w w w.jav a 2s .c om private void bindViewListeners() { // export destination bindings ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.export_destinations, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDestinationSpinner.setAdapter(adapter); mDestinationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { View recurrenceOptionsView = getView().findViewById(R.id.recurrence_options); switch (position) { case 0: mExportTarget = ExportParams.ExportTarget.SD_CARD; recurrenceOptionsView.setVisibility(View.VISIBLE); break; case 1: recurrenceOptionsView.setVisibility(View.VISIBLE); mExportTarget = ExportParams.ExportTarget.DROPBOX; String dropboxAppKey = getString(R.string.dropbox_app_key, BackupPreferenceFragment.DROPBOX_APP_KEY); String dropboxAppSecret = getString(R.string.dropbox_app_secret, BackupPreferenceFragment.DROPBOX_APP_SECRET); if (!DropboxHelper.hasToken()) { Auth.startOAuth2Authentication(getActivity(), dropboxAppKey); } break; case 2: recurrenceOptionsView.setVisibility(View.VISIBLE); mExportTarget = ExportParams.ExportTarget.GOOGLE_DRIVE; BackupPreferenceFragment.mGoogleApiClient = BackupPreferenceFragment .getGoogleApiClient(getActivity()); BackupPreferenceFragment.mGoogleApiClient.connect(); break; case 3: recurrenceOptionsView.setVisibility(View.VISIBLE); mExportTarget = ExportParams.ExportTarget.OWNCLOUD; if (!(PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean(getString(R.string.key_owncloud_sync), false))) { OwnCloudDialogFragment ocDialog = OwnCloudDialogFragment.newInstance(null); ocDialog.show(getActivity().getSupportFragmentManager(), "ownCloud dialog"); } break; case 4: mExportTarget = ExportParams.ExportTarget.SHARING; recurrenceOptionsView.setVisibility(View.GONE); break; default: mExportTarget = ExportParams.ExportTarget.SD_CARD; break; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); int position = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getInt(getString(R.string.key_last_export_destination), 0); mDestinationSpinner.setSelection(position); //**************** export start time bindings ****************** Timestamp timestamp = PreferencesHelper.getLastExportTime(); mExportStartCalendar.setTimeInMillis(timestamp.getTime()); final Date date = new Date(timestamp.getTime()); mExportStartDate.setText(TransactionFormFragment.DATE_FORMATTER.format(date)); mExportStartTime.setText(TransactionFormFragment.TIME_FORMATTER.format(date)); mExportStartDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { long dateMillis = 0; try { Date date = TransactionFormFragment.DATE_FORMATTER.parse(mExportStartDate.getText().toString()); dateMillis = date.getTime(); } catch (ParseException e) { Log.e(getTag(), "Error converting input time to Date object"); } Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(dateMillis); int year = calendar.get(Calendar.YEAR); int monthOfYear = calendar.get(Calendar.MONTH); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); CalendarDatePickerDialogFragment datePickerDialog = new CalendarDatePickerDialogFragment(); datePickerDialog.setOnDateSetListener(ExportFormFragment.this); datePickerDialog.setPreselectedDate(year, monthOfYear, dayOfMonth); datePickerDialog.show(getFragmentManager(), "date_picker_fragment"); } }); mExportStartTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { long timeMillis = 0; try { Date date = TransactionFormFragment.TIME_FORMATTER.parse(mExportStartTime.getText().toString()); timeMillis = date.getTime(); } catch (ParseException e) { Log.e(getTag(), "Error converting input time to Date object"); } Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeMillis); RadialTimePickerDialogFragment timePickerDialog = new RadialTimePickerDialogFragment(); timePickerDialog.setOnTimeSetListener(ExportFormFragment.this); timePickerDialog.setStartTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE)); timePickerDialog.show(getFragmentManager(), "time_picker_dialog_fragment"); } }); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mExportAllSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mExportStartDate.setEnabled(!isChecked); mExportStartTime.setEnabled(!isChecked); int color = isChecked ? android.R.color.darker_gray : android.R.color.black; mExportStartDate.setTextColor(getResources().getColor(color)); mExportStartTime.setTextColor(getResources().getColor(color)); } }); mExportAllSwitch.setChecked(sharedPrefs.getBoolean(getString(R.string.key_export_all_transactions), false)); mDeleteAllCheckBox.setChecked( sharedPrefs.getBoolean(getString(R.string.key_delete_transactions_after_export), false)); mRecurrenceTextView.setOnClickListener( new RecurrenceViewClickListener((AppCompatActivity) getActivity(), mRecurrenceRule, this)); //this part (setting the export format) must come after the recurrence view bindings above String defaultExportFormat = sharedPrefs.getString(getString(R.string.key_default_export_format), ExportFormat.QIF.name()); mExportFormat = ExportFormat.valueOf(defaultExportFormat); View.OnClickListener radioClickListener = new View.OnClickListener() { @Override public void onClick(View view) { onRadioButtonClicked(view); } }; View v = getView(); assert v != null; mOfxRadioButton.setOnClickListener(radioClickListener); mQifRadioButton.setOnClickListener(radioClickListener); mXmlRadioButton.setOnClickListener(radioClickListener); ExportFormat defaultFormat = ExportFormat.valueOf(defaultExportFormat.toUpperCase()); switch (defaultFormat) { case QIF: mQifRadioButton.performClick(); break; case OFX: mOfxRadioButton.performClick(); break; case XML: mXmlRadioButton.performClick(); break; } if (GnuCashApplication.isDoubleEntryEnabled()) { mOfxRadioButton.setVisibility(View.GONE); } else { mXmlRadioButton.setVisibility(View.GONE); } }
From source file:com.crearo.gpslogger.GpsMainActivity.java
public void setUpToolbar() { try {/* w w w .j a va 2 s.c o m*/ Toolbar toolbar = getToolbar(); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayShowTitleEnabled(false); } //Deprecated in Lollipop but required if targeting 4.x SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.gps_main_views, R.layout.spinner_dropdown_item); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, this); getSupportActionBar().setSelectedNavigationItem(getUserSelectedNavigationItem()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } } catch (Exception ex) { //http://stackoverflow.com/questions/26657348/appcompat-v7-v21-0-0-causing-crash-on-samsung-devices-with-android-v4-2-2 LOG.error("Thanks for this, Samsung", ex); } }
From source file:info.tellmetime.TellmetimeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tellmetime); mDensity = getResources().getDisplayMetrics().density; mScreenWidth = getResources().getDisplayMetrics().widthPixels; mScreenHeight = getResources().getDisplayMetrics().heightPixels; mShorterEdge = Math.min(mScreenWidth, mScreenHeight); mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop(); mBacklightLight = getResources().getColor(R.color.backlight_light); mBacklightDark = getResources().getColor(R.color.backlight_dark); // Restore background and highlight colors from saved values or set defaults. mSettings = getSharedPreferences("PREFS", Context.MODE_PRIVATE); mHighlightColor = mSettings.getInt(HIGHLIGHT, Color.WHITE); mBacklightColor = mSettings.getInt(BACKLIGHT, mBacklightLight); mBackgroundColor = mSettings.getInt(BACKGROUND, getResources().getColor(R.color.background)); mBackgroundMode = mSettings.getInt(BACKGROUND_MODE, MODE_BACKGROUND_SOLID); mHighlightPosition = mSettings.getFloat(POSITION, 0.0f); mMinutesSize = mSettings.getInt(MINUTES_SIZE, 36); isNightMode = mSettings.getBoolean(NIGHTMODE, false); // Dim the navigation bar. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) getWindow().getDecorView().setSystemUiVisibility(isNightMode ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0); mSurface = (RelativeLayout) findViewById(R.id.surface); mSurface.setBackgroundColor(mBackgroundColor); resizeClock();/*from w ww . java 2s . c om*/ Typeface mTypefaceBold = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf"); // Set typeface of all items in the clock to Roboto and dim each one and drop shadow on them. final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock); for (int i = 0; i < mClock.getChildCount(); i++) { LinearLayout row = (LinearLayout) mClock.getChildAt(i); for (int j = 0; j < row.getChildCount(); j++) { TextView tv = (TextView) row.getChildAt(j); tv.setTypeface(mTypefaceBold); tv.setTextColor(mBacklightColor); tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor); } } ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots); for (int i = 0; i < minutesDots.getChildCount(); i++) { TextView m = (TextView) minutesDots.getChildAt(i); m.setTypeface(mTypefaceBold); m.setTextColor(mBacklightColor); m.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor); } // Set Roboto font on TextView where it isn't default. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { Typeface mTypefaceItalic = Typeface.createFromAsset(getAssets(), "Roboto-CondensedItalic.ttf"); ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.info_background)).setTypeface(mTypefaceItalic); ((TextView) findViewById(R.id.info_image)).setTypeface(mTypefaceItalic); ((TextView) findViewById(R.id.labelHighlight)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.radio_backlight_light)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.radio_backlight_dark)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.radio_backlight_highlight)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.labelMinutes)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m1)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m2)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m3)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m4)).setTypeface(mTypefaceBold); } FrameLayout mTouchZone = (FrameLayout) findViewById(R.id.touchZone); mTouchZone.setOnTouchListener(this); mTouchZone.setBackgroundColor( getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent)); mBackgroundImage = (ImageView) findViewById(R.id.background_image); switchBackgroundMode(mBackgroundMode); RelativeLayout mPanel = (RelativeLayout) findViewById(R.id.panel); mPanel.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { mHider.delayedHide(4000); return true; } }); mHider = new PanelHider(mPanel, this); Spinner spinnerBackgroundMode = (Spinner) findViewById(R.id.spinnerBackgroundMode); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.backgrounds_modes, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerBackgroundMode.setAdapter(adapter); spinnerBackgroundMode.setOnItemSelectedListener(this); spinnerBackgroundMode.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { mHider.showNoAutoHide(); return false; } }); spinnerBackgroundMode.setSelection(mBackgroundMode); mSeekBarHighlight = (SeekBar) findViewById(R.id.highlightValue); mSeekBarHighlight.setOnSeekBarChangeListener(this); // Draw rainbow gradient on #mSeekBarHighlight and set position. drawRainbow(); if (mBacklightColor == mBacklightLight) ((RadioButton) findViewById(R.id.radio_backlight_light)).setChecked(true); else if (mBacklightColor == mBacklightDark) ((RadioButton) findViewById(R.id.radio_backlight_dark)).setChecked(true); else ((RadioButton) findViewById(R.id.radio_backlight_highlight)).setChecked(true); SeekBar mSeekBarMinutes = (SeekBar) findViewById(R.id.minutesSize); mSeekBarMinutes.setOnSeekBarChangeListener(this); mSeekBarMinutes.setProgress(mMinutesSize); mHider.hideNow(); Color.colorToHSV(mBackgroundColor, mHSV); mHSV[1] = 1.0f; //Trigger initial tick. mClockAlgorithm.tickTock(); // Schedule the clock algorithm to tick every round minute. Calendar time = Calendar.getInstance(); time.set(Calendar.MILLISECOND, 0); time.set(Calendar.SECOND, 0); time.add(Calendar.MINUTE, 1); Timer timer = new Timer(); timer.schedule(mClockTask, time.getTime(), 60 * 1000); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mSurface.setAlpha(0.0f); mSurface.animate().alpha(1.0f).setDuration(1500); } // If it is first run, hint to user that panel is available. if (!mSettings.contains(HIGHLIGHT)) showToast(R.string.info_first_run); }
From source file:com.terraremote.terrafieldreport.OpenGroundReport.java
@OnItemSelected(R.id.checkInContactRoleSpinner) void ohsAdministratorSpinnerSelected(int position) { position = mCheckInContactRoleSpinner.getSelectedItemPosition(); if (position == 1) { // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(OpenGroundReport.this, R.array.check_in_contact_ohs_administrator_names, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mCheckInContactNameSpinner.setVisibility(View.VISIBLE); mOtherContactName.setVisibility(View.GONE); mOtherContactName.setText(""); // Apply the adapter to the spinner mCheckInContactNameSpinner.setAdapter(adapter); }//from w w w .ja v a2 s. co m }