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:com.fullmeadalchemist.mustwatch.ui.batch.form.AddIngredientDialog.java

@NonNull
@Override/*from   ww  w  . java  2  s  . c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.ingredient_dialog, null);
    viewModel = ViewModelProviders.of(this, viewModelFactory).get(BatchFormViewModel.class);

    String typeString = getArguments().getString(INGREDIENT_TYPE);
    Ingredient.IngredientType type;
    type = Ingredient.IngredientType.fromString(typeString);
    if (type == null) {
        type = Ingredient.IngredientType.SUGAR;
    }
    Timber.d("Got INGREDIENT_TYPE=%s", type);
    spinnerItems = new ArrayList<>();
    LiveData<List<Ingredient>> ingredientsSpinnerObjects;
    int unitsSpinnerResource = 0;
    switch (type) {
    case YEAST:
        unitsSpinnerResource = R.array.mass_units_list;
        ingredientsSpinnerObjects = viewModel.getYeasts();
        break;
    case NUTRIENT:
        unitsSpinnerResource = R.array.mass_units_list;
        ingredientsSpinnerObjects = viewModel.getNutrients();
        break;
    case STABILIZER:
        unitsSpinnerResource = R.array.mass_units_list;
        ingredientsSpinnerObjects = viewModel.getStabilizers();
        break;
    case SUGAR:
    default:
        unitsSpinnerResource = R.array.sugar_units_list;
        ingredientsSpinnerObjects = viewModel.getSugars();
        break;
    }

    ingredientsSpinnerObjects.observe(this, ingredients -> {
        if (ingredients != null) {
            Timber.d("updating ingredients spinner with %d objects", ingredients.size());
            spinnerItems = ingredients;
            List<String> stringifiedIngredients = new ArrayList<>(ingredients.size());
            for (Ingredient ingredient : ingredients) {
                if (ingredient != null) {
                    int resID = getResources().getIdentifier(ingredient.id, "string",
                            this.getActivity().getPackageName());
                    stringifiedIngredients.add(getString(resID));
                } else {
                    Timber.e("Got a null ingredient from the database!?");
                }
            }
            Spinner ingredientsSpinner = view.findViewById(R.id.ingredients_spinner);
            ArrayAdapter<String> ingredientsAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item, stringifiedIngredients);
            ingredientsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            ingredientsSpinner.setAdapter(ingredientsAdapter);
        }
    });

    Spinner unitsSpinner = view.findViewById(R.id.quantity_unit_spinner);
    ArrayAdapter<CharSequence> unitsAdapter = ArrayAdapter.createFromResource(getActivity(),
            unitsSpinnerResource, android.R.layout.simple_spinner_item);
    unitsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    unitsSpinner.setAdapter(unitsAdapter);

    return new AlertDialog.Builder(getActivity()).setView(view)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                Spinner spinner = view.findViewById(R.id.ingredients_spinner);
                int selectedItemId = safeLongToInt(spinner.getSelectedItemId());
                Ingredient selectedIngredient = spinnerItems.get(selectedItemId);
                Timber.d("Registered spinner number %d selected, corresponding to ingredient %s",
                        selectedItemId, selectedIngredient.id);

                TextView qtyAmount = view.findViewById(R.id.quantity_amount);
                String qtyAmountValueText = qtyAmount.getText().toString();

                float qtyValue = toFloat(qtyAmountValueText, 0.0f);

                //Spinner unitsSpinner = view.findViewById(R.id.quantity_unit_spinner);
                String selectedUnit = unitsSpinner.getSelectedItem().toString();

                Timber.d("Ingredient selected: %s, %s %s", selectedIngredient.id, qtyValue, selectedUnit);

                Intent intent = new Intent(INGREDIENT_SET_EVENT);
                intent.putExtra(INGREDIENT, selectedIngredient.id);
                intent.putExtra(AMOUNT, qtyValue);
                intent.putExtra(UNIT, selectedUnit);
                LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
            }).setNegativeButton(android.R.string.cancel, null).create();
}

From source file:eu.power_switch.gui.fragment.configure_gateway.ConfigureGatewayDialogPage1Fragment.java

@Nullable
@Override//from w  w w . ja  va2s.  co m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_fragment_configure_gateway_page_1, container, false);

    TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            checkSetupValidity();
            sendAddressChangedBroadcast(getActivity());
        }
    };
    floatingName = (TextInputLayout) rootView.findViewById(R.id.gateway_name_text_input_layout);
    name = (EditText) rootView.findViewById(R.id.txt_edit_gateway_name);
    name.addTextChangedListener(textWatcher);

    model = (Spinner) rootView.findViewById(R.id.spinner_gateway_type);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.gateway_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    model.setAdapter(adapter);
    SpinnerInteractionListener spinnerInteractionListener = new SpinnerInteractionListener() {
        @Override
        public void onItemSelectedByUser(AdapterView<?> parent, View view, int pos, long id) {
            sendAddressChangedBroadcast(getActivity());
        }
    };
    model.setOnTouchListener(spinnerInteractionListener);
    model.setOnItemSelectedListener(spinnerInteractionListener);

    floatingLocalAddress = (TextInputLayout) rootView
            .findViewById(R.id.gateway_local_address_text_input_layout);
    localAddress = (EditText) rootView.findViewById(R.id.txt_edit_gateway_local_address);
    localAddress.addTextChangedListener(textWatcher);

    floatingLocalPort = (TextInputLayout) rootView.findViewById(R.id.gateway_local_port_text_input_layout);
    localPort = (EditText) rootView.findViewById(R.id.txt_edit_gateway_local_port);
    localPort.addTextChangedListener(textWatcher);

    floatingWanAddress = (TextInputLayout) rootView.findViewById(R.id.gateway_wan_address_text_input_layout);
    wanAddress = (EditText) rootView.findViewById(R.id.txt_edit_gateway_wan_address);
    wanAddress.addTextChangedListener(textWatcher);

    floatingWanPort = (TextInputLayout) rootView.findViewById(R.id.gateway_wan_port_text_input_layout);
    wanPort = (EditText) rootView.findViewById(R.id.txt_edit_gateway_wan_port);
    wanPort.addTextChangedListener(textWatcher);

    Bundle args = getArguments();
    if (args != null && args.containsKey(ConfigureGatewayDialog.GATEWAY_ID_KEY)) {
        gatewayId = args.getLong(ConfigureGatewayDialog.GATEWAY_ID_KEY);
        initializeGatewayData(gatewayId);
    }
    checkSetupValidity();

    return rootView;
}

From source file:ws.logv.trainmonitor.ui.MainActivity.java

@SuppressWarnings("UnusedDeclaration")
public void onEventMainThread(AccountChoosnEvent event) {
    Context context = getSupportActionBar().getThemedContext();
    ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.navigation,
            R.layout.sherlock_spinner_item);
    list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

    getSupportActionBar().setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_LIST);
    getSupportActionBar().setListNavigationCallbacks(list, this);
}

From source file:com.example.vedantn.algaeestimator.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Set values for the main spinner
    calcMethodSpinner = (Spinner) findViewById(R.id.calcMethodSpinner);
    ArrayAdapter adapterCalcMethod = ArrayAdapter.createFromResource(this, R.array.calcMethod,
            android.R.layout.simple_spinner_dropdown_item);
    calcMethodSpinner.setAdapter(adapterCalcMethod);
    calcMethodSpinner.setOnItemSelectedListener(this);

    spinnerDepth = (Spinner) findViewById(R.id.spinnerDepth);
    spinnerDepth.setOnItemSelectedListener(this);

    spinnerStemp = (Spinner) findViewById(R.id.spinnerStemp);
    spinnerStemp.setOnItemSelectedListener(this);

    spinnerBotTemp = (Spinner) findViewById(R.id.spinnerBotTemp);
    spinnerBotTemp.setOnItemSelectedListener(this);

    spinnerSD = (Spinner) findViewById(R.id.spinnerSD);
    spinnerSD.setOnItemSelectedListener(this);

    //Get all user inputs
    tbValueOfAlgal = (EditText) findViewById(R.id.tbValueOfAlgal);
    tbPbott = (EditText) findViewById(R.id.tbPbott);
    tbDepth = (EditText) findViewById(R.id.tbDepth);
    tbStemp = (EditText) findViewById(R.id.tbStemp);
    tbBotTemp = (EditText) findViewById(R.id.tbBotTemp);
    tbSD = (EditText) findViewById(R.id.tbSD);
    tbDO = (EditText) findViewById(R.id.tbDO);
    tbLakeDescription = (EditText) findViewById(R.id.tbLakeDescription);
    lblLocation = (TextView) findViewById(R.id.lblLocation);
    //Get GPS coordinates
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationListener = new LocationListener() {
        @Override/*from   ww  w . j a v  a  2s .  c  om*/
        //This methods is called every time the GPS location changes
        public void onLocationChanged(Location location) {

            if (location != null) {
                userLat = location.getLatitude();
                userLon = location.getLongitude();
                //Toast.makeText(MainActivity.this,"Location Changed",Toast.LENGTH_LONG).show();
                lblLocation.setText("Current Location\n" + userLat + "\n" + userLon);

            }

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {

        }

        @Override
        public void onProviderEnabled(String provider) {

        }

        @Override
        public void onProviderDisabled(String provider) {

        }
    };

    //Get location updated after 60000 milliseconds or 5 meters.
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 5, locationListener);

}

From source file:com.markupartist.sthlmtraveling.ChangeRouteTimeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.change_route_time);

    registerScreen("Change route time");

    restoreState(savedInstanceState);//ww w  .java 2s . co  m

    Bundle extras = getIntent().getExtras();
    mJourneyQuery = extras.getParcelable(RoutesActivity.EXTRA_JOURNEY_QUERY);

    mTime = mJourneyQuery.time;

    mDateButton = (Button) findViewById(R.id.change_route_date);
    mDateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_DATE);
        }
    });

    mTimeButton = (Button) findViewById(R.id.change_route_time);
    mTimeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_TIME);
        }
    });

    ImageButton refreshTimeButton = (ImageButton) findViewById(R.id.btn_set_to_now);
    ViewHelper.tintIcon(refreshTimeButton.getDrawable(), Color.GRAY);
    refreshTimeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mJourneyQuery.time != null) {
                mJourneyQuery.time.setTime(System.currentTimeMillis());
                updateTimeViews();
            }
        }
    });

    // Don't fill via if it has been restored.
    if (!mViaPoint.looksValid() && mJourneyQuery.hasVia()) {
        mViaPoint = mJourneyQuery.via;
        //            new Site();
        //            mViaPoint.setId(mJourneyQuery.via.id);
        //            mViaPoint.setName(mJourneyQuery.via.name);
        //            mViaPoint.setLocation(mJourneyQuery.via.latitude, mJourneyQuery.via.longitude);
    }

    mViaPointAutoComplete = createAutoCompleteTextView(R.id.via, mViaPoint, true);
    mViaPointAutoComplete.setText(mViaPoint.getName());

    int selectedPosition = mJourneyQuery.isTimeDeparture ? 0 : 1;
    mWhenSpinner = (Spinner) findViewById(R.id.departure_arrival_choice);
    ArrayAdapter<CharSequence> whenChoiceAdapter = ArrayAdapter.createFromResource(this, R.array.when_choice,
            android.R.layout.simple_spinner_item);
    whenChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mWhenSpinner.setAdapter(whenChoiceAdapter);
    mWhenSpinner.setSelection(selectedPosition);

    // Inflate a "Done/Discard" custom action bar view.
    LayoutInflater inflater = (LayoutInflater) getSupportActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done_discard, null);
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(this);
    customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(this);

    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    updateViews();
}

From source file:com.example.nativeaudio.NativeAudio.java

/** Called when the activity is first created. */
@Override//ww w  .  j a va2  s.co m
@TargetApi(17)
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    Log.d(TAG, "onCreate ----------- ");

    assetManager = getAssets();

    /*
    Ctrl+O ?
    Ctrl+I ?
            
    Ctrl+N /?
    Ctrl+Shift+N 
    Ctrl+Shift+ALt+N ?
            
            
    Ctrl+Space ???
    Ctrl+Shift+Space ?
    Ctrl+Shift+Enter (? ?; )
    Ctrl+P ??
            
    Alt+Enter ?/?/
            
    Ctrl+J ?? ( for foreach Toast system.out.println) logm logr loge
      */

    // initialize native audio system
    createEngine();

    int sampleRate = 0;
    int bufSize = 0;
    /*
     * retrieve fast audio path sample rate and buf size; if we have it, we pass to native
     * side to create a player with fast audio enabled [ fast audio == low latency audio ];
     * IF we do not have a fast audio path, we pass 0 for sampleRate, which will force native
     * side to pick up the 8Khz sample rate.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        String nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
        sampleRate = Integer.parseInt(nativeParam);
        nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
        bufSize = Integer.parseInt(nativeParam); // buffer?

        PackageManager pm = getPackageManager();
        boolean claimsFeature = pm.hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY);

        // ?5 OUTPUT_SAMPLE_RATE = 48000 OUTPUT_FRAMES_PER_BUFFER = 192 FEATURE_AUDIO_LOW_LATENCY = false
        // MTK MT6735  OUTPUT_SAMPLE_RATE = 44100 OUTPUT_FRAMES_PER_BUFFER = 1024 FEATURE_AUDIO_LOW_LATENCY = false
        Log.d(TAG, "OUTPUT_SAMPLE_RATE = " + sampleRate + " OUTPUT_FRAMES_PER_BUFFER = " + bufSize
                + " FEATURE_AUDIO_LOW_LATENCY = " + claimsFeature);
    }

    //  buffer queue AudioPlayer Demo
    createBufferQueueAudioPlayer(sampleRate, bufSize);

    // initialize URI spinner
    Spinner uriSpinner = (Spinner) findViewById(R.id.uri_spinner);
    ArrayAdapter<CharSequence> uriAdapter = ArrayAdapter.createFromResource(this,
            R.array.local_uri_spinner_array,
            /* R.array.uri_spinner_array, */
            android.R.layout.simple_spinner_item);
    uriAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    uriSpinner.setAdapter(uriAdapter);
    uriSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            URI = parent.getItemAtPosition(pos).toString();
            /* ? ?
              <string-array name="uri_spinner_array">
                <item>http://upload.wikimedia.org/wikipedia/commons/6/6d/Banana.ogg</item>
                <item>http://www.freesound.org/data/previews/18/18765_18799-lq.mp3</item>
              </string-array>
             */
        }

        public void onNothingSelected(AdapterView parent) {
            URI = null;
        }

    });

    // initialize button click handlers

    ((Button) findViewById(R.id.hello)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_HELLO, 2);
        }
    });

    ((Button) findViewById(R.id.android)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_ANDROID, 7);
        }
    });

    ((Button) findViewById(R.id.sawtooth)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_SAWTOOTH, 1);
        }
    });

    ((Button) findViewById(R.id.reverb)).setOnClickListener(new OnClickListener() {
        boolean enabled = false;

        public void onClick(View view) {
            enabled = !enabled;
            if (!enableReverb(enabled)) {
                enabled = !enabled;
            }
        }
    });

    //  AssertManager APK?mp3
    //
    ((Button) findViewById(R.id.embedded_soundtrack)).setOnClickListener(new OnClickListener() {
        boolean created = false;

        public void onClick(View view) {
            if (!created) {
                created = createAssetAudioPlayer(assetManager, "withus.mp3");
            }
            if (created) {
                // URI AudioPlayer Demo ?
                // URI AudioPlayer Demo ? ?play pause
                // Assert/fd AudioPlayer  Demo ?
                isPlayingAsset = !isPlayingAsset;
                setPlayingAssetAudioPlayer(isPlayingAsset);
            }
        }
    });

    ((Button) findViewById(R.id.uri_soundtrack)).setOnClickListener(new OnClickListener() {
        boolean created = false;

        public void onClick(View view) {
            if (!created && URI != null) {
                Log.d(TAG, " uri_soundtrack create URI Audio Player URI " + URI);
                //URI = "file:///mnt/sdcard/xxx.3gp" ;
                //URI = "file:///mnt/sdcard/Banana.ogg" ;
                created = createUriAudioPlayer(URI);
            }
        }
    });

    ((Button) findViewById(R.id.pause_uri)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            Log.d(TAG, " setPlayingUriAudioPlayer  pause URI ");
            setPlayingUriAudioPlayer(false);
        }
    });

    ((Button) findViewById(R.id.play_uri)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            Log.d(TAG, " setPlayingUriAudioPlayer  play URI ");
            setPlayingUriAudioPlayer(true);
        }
    });

    ((Button) findViewById(R.id.loop_uri)).setOnClickListener(new OnClickListener() {
        boolean isLooping = false;

        public void onClick(View view) {
            isLooping = !isLooping;
            setLoopingUriAudioPlayer(isLooping);

        }
    });

    ((Button) findViewById(R.id.mute_left_uri)).setOnClickListener(new OnClickListener() {
        boolean muted = false;

        public void onClick(View view) {
            muted = !muted;
            setChannelMuteUriAudioPlayer(0, muted);
        }
    });

    ((Button) findViewById(R.id.mute_right_uri)).setOnClickListener(new OnClickListener() {
        boolean muted = false;

        public void onClick(View view) {
            muted = !muted;
            setChannelMuteUriAudioPlayer(1, muted);
        }
    });

    ((Button) findViewById(R.id.solo_left_uri)).setOnClickListener(new OnClickListener() {
        boolean soloed = false;

        public void onClick(View view) {
            soloed = !soloed;
            setChannelSoloUriAudioPlayer(0, soloed);
        }
    });

    ((Button) findViewById(R.id.solo_right_uri)).setOnClickListener(new OnClickListener() {
        boolean soloed = false;

        public void onClick(View view) {
            soloed = !soloed;
            setChannelSoloUriAudioPlayer(1, soloed);
        }
    });

    ((Button) findViewById(R.id.mute_uri)).setOnClickListener(new OnClickListener() {
        boolean muted = false;

        public void onClick(View view) {
            muted = !muted;
            setMuteUriAudioPlayer(muted);
        }
    });

    /*
    *  ???? ?  Stereo Panning
    *  https://developer.android.com/ndk/guides/audio/opensl-prog-notes.html#panning
    *
    * */
    ((Button) findViewById(R.id.enable_stereo_position_uri)).setOnClickListener(new OnClickListener() {
        boolean enabled = false;

        public void onClick(View view) {
            enabled = !enabled;
            enableStereoPositionUriAudioPlayer(enabled);
        }
    });

    // ??  ?AudioPlayer ??? ?SetPlayState???
    ((Button) findViewById(R.id.channels_uri)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (numChannelsUri == 0) {
                numChannelsUri = getNumChannelsUriAudioPlayer();
            }
            Toast.makeText(NativeAudio.this, "Channels: " + numChannelsUri, Toast.LENGTH_SHORT).show();
        }
    });

    // ??
    ((SeekBar) findViewById(R.id.volume_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        int lastProgress = 100;

        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) {
                throw new AssertionError();
            }
            lastProgress = progress;
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
            int attenuation = 100 - lastProgress;
            int millibel = attenuation * -50; // 100 * -50  ~  0
            setVolumeUriAudioPlayer(millibel);
        }
    });

    ((SeekBar) findViewById(R.id.pan_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        int lastProgress = 100;

        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) {
                throw new AssertionError();
            }
            lastProgress = progress;
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
            // ?? ?
            // ? ?  ?<50  >50 ?
            int permille = (lastProgress - 50) * 20;
            setStereoPositionUriAudioPlayer(permille);
        }
    });

    ((SeekBar) findViewById(R.id.playback_rate_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        int lastProgress = 100;

        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) {
                throw new AssertionError();
            }
            lastProgress = progress;
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        public void onStopTrackingTouch(SeekBar seekBar) {

            /*
                    0 ----- 50 ---- 100
                  -1000 --- 0 ---- 1000
             */
            int permille = lastProgress * (1000 - -1000) / 100 + (-1000);
            setPlaybackRateUriAudioPlayer(permille);
        }
    });

    ((Button) findViewById(R.id.record)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            //                int status = ActivityCompat.checkSelfPermission(NativeAudio.this,
            //                        Manifest.permission.RECORD_AUDIO);
            //                if (status != PackageManager.PERMISSION_GRANTED) {
            //                    ActivityCompat.requestPermissions(
            //                            NativeAudio.this,
            //                            new String[]{Manifest.permission.RECORD_AUDIO},
            //                            AUDIO_ECHO_REQUEST);
            //                    return;
            //                }
            recordAudio();
        }
    });

    ((Button) findViewById(R.id.playback)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_PLAYBACK, 3);
        }
    });

}

From source file:freed.viewer.dngconvert.DngConvertingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    appSettingsManager = new AppSettingsManager(
            PreferenceManager.getDefaultSharedPreferences(getActivity().getBaseContext()), getResources());
    if (appSettingsManager.getDevice() == null)
        appSettingsManager.SetDevice(new DeviceUtils().getDevice(getResources()));
    handler = new Handler();
    view = inflater.inflate(R.layout.dngconvertingfragment, container, false);
    editTextwidth = (EditText) view.findViewById(id.editText_width);
    editTextheight = (EditText) view.findViewById(id.editText_height);
    editTextblacklvl = (EditText) view.findViewById(id.editText_blacklevel);
    spinnerMatrixProfile = (Spinner) view.findViewById(id.spinner_MatrixProfile);
    matrixChooserParameter = new MatrixChooserParameter(appSettingsManager.getMatrixesMap());
    String[] items = matrixChooserParameter.GetValues();
    ArrayAdapter<String> matrixadapter = new ArrayAdapter<>(getContext(), layout.simple_spinner_item, items);
    //ArrayAdapter<CharSequence> matrixadapter = ArrayAdapter.createFromResource(getContext(),R.array.matrixes, android.R.layout.simple_spinner_item);
    matrixadapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
    spinnerMatrixProfile.setAdapter(matrixadapter);

    buttonconvertToDng = (Button) view.findViewById(id.button_convertDng);
    buttonconvertToDng.setOnClickListener(convertToDngClick);

    spinnerColorPattern = (Spinner) view.findViewById(id.spinner_ColorPattern);
    ArrayAdapter<CharSequence> coloradapter = ArrayAdapter.createFromResource(getContext(), array.color_pattern,
            layout.simple_spinner_item);
    coloradapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
    spinnerColorPattern.setAdapter(coloradapter);

    spinnerrawFormat = (Spinner) view.findViewById(id.spinner_rawFormat);
    ArrayAdapter<CharSequence> rawadapter = ArrayAdapter.createFromResource(getContext(), array.raw_format,
            layout.simple_spinner_item);
    rawadapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
    spinnerrawFormat.setAdapter(rawadapter);
    closeButton = (Button) view.findViewById(id.button_goback_from_conv);
    closeButton.setOnClickListener(new OnClickListener() {
        @Override//w  w  w . j  av a2s  .  c  om
        public void onClick(View v) {
            Intent returnIntent = new Intent();
            getActivity().setResult(Activity.RESULT_CANCELED, returnIntent);
            getActivity().finish();
        }
    });
    imageView = (TouchImageView) view.findViewById(id.dngconvert_imageview);
    fakeGPS = (CheckBox) view.findViewById(id.checkBox_fakeGPS);
    return view;
}

From source file:ca.ualberta.cs.unter.view.DriverSearchRequestActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_driver_search_request);

    // merline stuff
    merlin = new Merlin.Builder().withConnectableCallbacks().withDisconnectableCallbacks()
            .withBindableCallbacks().build(this);
    merlin.registerConnectable(this);
    merlin.registerDisconnectable(this);
    merlin.registerBindable(this);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    searchContextEditText = (EditText) findViewById(R.id.editText_searchRequest_DriverSearchRequestActivity);

    // https://developer.android.com/guide/topics/ui/controls/spinner.html#Populate
    searchOptionSpinner = (Spinner) findViewById(R.id.spinner_searchOption_DriverSearchRequestActivity);
    searchOptionAdapter = ArrayAdapter.createFromResource(this, R.array.search_option,
            android.R.layout.simple_spinner_item);

    searchOptionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    searchOptionSpinner.setAdapter(searchOptionAdapter);

    searchOptionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//w  w  w . j  a va  2s.c o m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            searchOption = position;
        }

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

        }
    });

    searchButton = (Button) findViewById(R.id.button_search_DriverSearchRequestActivity);
    assert searchButton != null;
    searchButton.setOnClickListener(this);

    filterButton = (Button) findViewById(R.id.button_filter_driversearchrequestactivity);
    assert filterButton != null;
    filterButton.setOnClickListener(this);

    searchRequestListView = (ListView) findViewById(R.id.listView_searchList_DriverSearchRequestActivity);
    searchRequestListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Open dialog
            openRequestInfoDialog(searchRequestList.get(position));
        }
    });
}

From source file:com.dryver.Activities.ActivityDryverMain.java

/**
 * Assigns all UI elements to the actual views and instantiates adapters
 *
 * @see DryverMainAdapter//from  w w  w.j  a v a 2s . c o m
 * @see ArrayAdapter
 */
private void assignElements() {
    sortSpinner = (Spinner) findViewById(R.id.requestSortSpinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.activity_driver_spinner,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sortSpinner.setAdapter(adapter);
    sortSpinner.setOnItemSelectedListener(this);
    searchByEditText = (EditText) findViewById(R.id.searchWith);
    searchButton = (Button) findViewById(R.id.searchButton);

    //TODO: Change this in future
    //sets the request singleton's requests lists to getAllRequests in ES Controller
    driverListView = (ListView) findViewById(R.id.dryverMainListView);
    //requestSingleton.setRequestsAll();
    dryverMainAdapter = new DryverMainAdapter(this, requestSingleton.getRequests());
    driverListView.setAdapter(dryverMainAdapter);
}

From source file:com.z299studio.pb.ActionDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (Application.getInstance() == null || Application.getInstance().getAccountManager() == null) {
        return null;
    }//w w w .  jav  a  2  s .co m
    View rootView;
    int[] layouts = { R.layout.dialog_authenticate, R.layout.dialog_export, R.layout.dialog_import,
            R.layout.dialog_reset_pwd, R.layout.dialog_credits, R.layout.dialog_license,
            R.layout.dialog_authenticate };
    rootView = inflater.inflate(layouts[mDlgType], container, false);
    mOkButton = (Button) rootView.findViewById(R.id.ok);
    if (mOkButton != null) {
        mOkButton.setOnClickListener(this);
    }
    View cancel = rootView.findViewById(R.id.cancel);
    if (cancel != null) {
        cancel.setOnClickListener(this);
    }
    if (mDlgType != ACTION_EXPORT && mOkButton != null) {
        mOkButton.setEnabled(false);
        mOkButton.setAlpha(0.4f);
    }
    switch (mDlgType) {
    case ACTION_EXPORT:
    case ACTION_IMPORT:
        Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getActivity(),
                mDlgType == ACTION_EXPORT ? R.array.file_types : R.array.file_types_import,
                android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinnerAdapter);
        spinner.setSelection(mFileType);
        spinner.setOnItemSelectedListener(this);
        if (mDlgType == ACTION_IMPORT) {
            int ids[] = { R.id.ignore, R.id.keepall, R.id.overwrite };
            for (int i = 0; i < ids.length; ++i) {
                RadioButton rb = (RadioButton) rootView.findViewById(ids[i]);
                rb.setOnClickListener(this);
                if (i == mOption) {
                    rb.setChecked(true);
                }
            }
            mSelectButton = (Button) rootView.findViewById(R.id.select);
            mSelectButton.setOnClickListener(this);
        }
        break;
    case ACTION_AUTHENTICATE2:
        ((TextView) rootView.findViewById(R.id.auth_desc)).setText(R.string.diff_pwd);
        ((Button) rootView.findViewById(R.id.cancel)).setText(R.string.discard);
        // no break to use the logic of authenticate
    case ACTION_AUTHENTICATE:
        mPasswordEdits[1] = (EditText) rootView.findViewById(R.id.et_password);
        mPasswordEdits[1].addTextChangedListener(this);
        break;

    case ACTION_RESET_PWD:
        int ids[] = { R.id.et_cur_pwd, R.id.et_password, R.id.et_confirm };
        for (int i = 0; i < ids.length; ++i) {
            mPasswordEdits[i] = (EditText) rootView.findViewById(ids[i]);
            mPasswordEdits[i].addTextChangedListener(this);
        }
        break;

    case ACTION_CREDITS:
        rootView.findViewById(R.id.cancel).setOnClickListener(this);
        TextView tv = (TextView) rootView.findViewById(R.id.testers);
        tv.setText(R.string.cc_yhc);
        tv = (TextView) rootView.findViewById(R.id.translators);
        String translators = String.format(Locale.getDefault(), "%s: %s\n%s: %s\n%s: %s",
                getString(R.string.lang_fr), getString(R.string.cc_xcx), getString(R.string.lang_es),
                getString(R.string.cc_jh), getString(R.string.lang_zhtw), getString(R.string.cc_qqz));
        tv.setText(translators);
        break;

    case ACTION_LICENSE:
        WebView wv = (WebView) rootView.findViewById(R.id.licence_page);
        wv.loadUrl("file:///android_asset/licence.html");
        break;
    }
    return rootView;
}