Example usage for android.widget Spinner setSelection

List of usage examples for android.widget Spinner setSelection

Introduction

In this page you can find the example usage for android.widget Spinner setSelection.

Prototype

@Override
    public void setSelection(int position) 

Source Link

Usage

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void submitChat() {

    ChatConfig config = new ChatConfig();
    config.instance = this.instance.id;
    config.conversation = MainActivity.conversation;
    config.speak = !MainActivity.deviceVoice;
    config.avatar = this.avatarId;
    if (MainActivity.translate && MainActivity.voice != null) {
        config.language = MainActivity.voice.language;
    }//from   w w w.  ja va 2  s. co  m
    if (MainActivity.disableVideo) {
        config.avatarFormat = "image";
    } else {
        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
    }
    config.avatarHD = MainActivity.hd;

    EditText v = (EditText) findViewById(R.id.messageText);
    config.message = v.getText().toString().trim();
    if (config.message.equals("")) {
        return;
    }
    this.messages.add(config);
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ListView list = (ListView) findViewById(R.id.chatList);
            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
            list.invalidateViews();
        }

    });

    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
    config.emote = emoteSpin.getSelectedItem().toString();

    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
    action.execute();

    v.setText("");
    emoteSpin.setSelection(0);
    resetToolbar();

    WebView responseView = (WebView) findViewById(R.id.responseText);
    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);

    //Check the volume
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (volume <= 3 && volumeChecked) {
        Toast.makeText(this, "Please check 'Media' volume", Toast.LENGTH_LONG).show();
        volumeChecked = false;
    }

    //stop letting the mic on.
    stopListening();
    //its Important for "sleep" "scream" ...etc commands.
    //this will turn off the mic
    MainActivity.listenInBackground = false;
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

private void updateShootModeSpinner() {

    Spinner shootModeSpinner = (Spinner) findViewById(R.id.shoot_mode_spinner);
    if (mIsSeriesMode)
        shootModeSpinner.setSelection(SERIES_POS);
    else/*  ww  w. jav a 2  s. c  o  m*/
        shootModeSpinner.setSelection(SINGLE_POS);

}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

private void setupScheduleEntrySpinners(final View entryView, ScheduleItem scheduleItem,
        String[] routineNames) {//from   w w w  . j  a va  2  s. co  m

    final Spinner routineSpinner = (Spinner) entryView.findViewById(R.id.entry_routine_spinner);
    final TextView doseTv = (TextView) entryView.findViewById(R.id.entry_dose_textview);
    //        final Spinner doseSpinner = (Spinner) entryView.findViewById(R.id.entry_dose_spinner);

    doseTv.setTag(scheduleItem);
    routineSpinner.setTag(scheduleItem);

    // set up the routine selection adapter
    updateRoutineSelectionAdapter(entryView, routineSpinner, routineNames);

    if (scheduleItem != null && scheduleItem.routine() != null) {
        String routineName = scheduleItem.routine().name();
        int index = Arrays.asList(routineNames).indexOf(routineName);
        routineSpinner.setSelection(index);
    } else {
        routineSpinner.setSelection(routineNames.length - 1);
    }

    doseTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDosePickerDialog((ScheduleItem) v.getTag(), (TextView) v);
        }
    });

    doseTv.setText(scheduleItem.displayDose());

    // setup listeners
    routineSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selected = (String) adapterView.getItemAtPosition(i);
            Routine r = Routine.findByName(selected);
            ScheduleItem item = ((ScheduleItem) routineSpinner.getTag());

            if (r != null) {
                updateEntryTime(r, entryView);
            } else {
                updateEntryTime(null, entryView);
                showAddNewRoutineDialog(entryView);
            }
            Log.d(TAG, "Updated routine to " + (r != null ? r.name() : "NULL") + " on item " + item.getId());
            item.setRoutine(r);

            logScheduleItems();
        }

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

    routineSpinner.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                if (((String) routineSpinner.getSelectedItem())
                        .equalsIgnoreCase(getString(R.string.create_new_routine))) {
                    showAddNewRoutineDialog(entryView);
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:universe.constellation.orion.viewer.OrionViewerActivity.java

public void initZoomScreen() {
    //zoom screen

    final Spinner sp = (Spinner) findMyViewById(R.id.zoom_spinner);

    final EditText zoomText = (EditText) findMyViewById(R.id.zoom_picker_message);

    final SeekBar zoomSeek = (SeekBar) findMyViewById(R.id.zoom_picker_seeker);

    if (zoomSeek != null) {
        zoomSeek.setMax(300);/*from  ww  w .  j a  v  a 2 s.  c  o  m*/
        zoomSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (zoomInternal != 1) {
                    zoomText.setText("" + progress);
                    if (sp.getSelectedItemPosition() != 0) {
                        int oldInternal = zoomInternal;
                        zoomInternal = 2;
                        sp.setSelection(0);
                        zoomInternal = oldInternal;
                    }
                }
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
    }

    getSubscriptionManager().addDocListeners(new DocumentViewAdapter() {
        @Override
        public void documentOpened(Controller controller) {
            updateZoom();
        }
    });

    final ImageButton zplus = (ImageButton) findMyViewById(R.id.zoom_picker_plus);
    zplus.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            zoomSeek.incrementProgressBy(1);
        }
    });

    final ImageButton zminus = (ImageButton) findMyViewById(R.id.zoom_picker_minus);
    zminus.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (zoomSeek.getProgress() != 0) {
                zoomSeek.incrementProgressBy(-1);
            }
        }
    });

    ImageButton closeZoomPeeker = (ImageButton) findMyViewById(R.id.zoom_picker_close);
    closeZoomPeeker.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //main menu
            onAnimatorCancel();
            //updateZoom();
        }
    });

    ImageButton zoom_preview = (ImageButton) findMyViewById(R.id.zoom_preview);
    zoom_preview.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            onApplyAction();
            int index = sp.getSelectedItemPosition();
            controller.changeZoom(index == 0 ? (int) (Float.parseFloat(zoomText.getText().toString()) * 100)
                    : -1 * (index - 1));
            updateZoom();
        }
    });

    sp.setAdapter(new MyArrayAdapter());
    sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            boolean disable = position != 0;
            int oldZoomInternal = zoomInternal;
            if (zoomInternal != 2) {
                zoomInternal = 1;
                if (disable) {
                    zoomText.setText((String) parent.getAdapter().getItem(position));
                } else {
                    zoomText.setText("" + ((int) (controller.getCurrentPageZoom() * 10000)) / 100f);
                    zoomSeek.setProgress((int) (controller.getCurrentPageZoom() * 100));
                }
                zoomInternal = oldZoomInternal;
            }

            zminus.setVisibility(disable ? View.GONE : View.VISIBLE);
            zplus.setVisibility(disable ? View.GONE : View.VISIBLE);

            zoomText.setFocusable(!disable);
            zoomText.setFocusableInTouchMode(!disable);

            final LinearLayout parent1 = (LinearLayout) zoomText.getParent();

            parent1.post(new Runnable() {
                @Override
                public void run() {
                    parent1.requestLayout();
                }
            });
        }

        public void onNothingSelected(AdapterView<?> parent) {
            //To change body of implemented methods use File | Settings | File Templates.
        }
    });

    //by width
    sp.setSelection(1);

}

From source file:org.irmacard.cardemu.selfenrol.EnrollSelectActivity.java

/**
 * Called when the user presses the continue button
 *///w w  w.  j a  v a2s .com
protected void advanceScreen() {
    switch (screen) {
    case SCREEN_START:
        setContentView(R.layout.enroll_activity_bac);
        screen = SCREEN_BAC;
        updateProgressCounter(screen - 1);
        Spinner spinner = (Spinner) findViewById(R.id.bac_selector);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.document_list,
                android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Log.v(TAG, (String) parent.getItemAtPosition(position));
                RelativeLayout drivers_license = (RelativeLayout) findViewById(R.id.drivers_license_data);
                RelativeLayout passport = (RelativeLayout) findViewById(R.id.passport_data);
                if (position == 0) {
                    drivers_license.setVisibility(View.GONE);
                    passport.setVisibility(View.VISIBLE);
                    next_activity = PASSPORT_ACTIVITY;
                } else if (position == 1) {
                    drivers_license.setVisibility(View.VISIBLE);
                    passport.setVisibility(View.GONE);
                    next_activity = DL_ACTIVITY;
                } else {
                    throw new IllegalArgumentException("Pulldown list provided unspecified argument");
                }
                if (bacFieldWatcher != null)
                    bacFieldWatcher.onTextChanged("", 0, 0, 0);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO Auto-generated method stub
            }
        });
        spinner.setSelection(settings.getInt("enroll_document", PASSPORT_ACTIVITY));
        populateBacAndBapFields();
        EditText docnrEditText;
        EditText dobEditText;
        EditText doeEditText;
        long bacDob;
        long bacDoe;

        enableContinueButton();
        setBacFieldWatcher();

        break;
    case SCREEN_BAC:
        if (next_activity == PASSPORT_ACTIVITY) {
            // Store the entered document number and dates in the settings.
            docnrEditText = (EditText) findViewById(R.id.doc_nr_edittext);
            dobEditText = (EditText) findViewById(R.id.dob_edittext);
            doeEditText = (EditText) findViewById(R.id.doe_edittext);

            if (docnrEditText != null && dobEditText != null && doeEditText != null) {
                bacDob = 0;
                bacDoe = 0;
                try {
                    String dobString = dobEditText.getText().toString();
                    String doeString = doeEditText.getText().toString();
                    if (dobString.length() != 0)
                        bacDob = hrDateFormat.parse(dobString).getTime();
                    if (doeString.length() != 0)
                        bacDoe = hrDateFormat.parse(doeString).getTime();
                } catch (ParseException e) {
                    // Should not happen: the DOB and DOE EditTexts are set only by the DatePicker's,
                    // OnDateSetListener, which should always set a properly formatted string.
                    e.printStackTrace();
                }

                if (bacDoe < System.currentTimeMillis()) {
                    showErrorScreen(getString(R.string.error_enroll_passport_expired),
                            getString(R.string.abort), 0, getString(R.string.retry), SCREEN_BAC);
                    return;
                }

                settings.edit().putInt("enroll_document", next_activity).putLong("enroll_bac_dob", bacDob)
                        .putLong("enroll_bac_doe", bacDoe)
                        .putString("enroll_bac_docnr", docnrEditText.getText().toString()).apply();
            }

            Intent i = new Intent(this, PassportEnrollActivity.class);
            startActivityForResult(i, PassportEnrollActivity.PassportEnrollActivityCode);
        } else if (next_activity == DL_ACTIVITY) {
            //safe the mrz text field for later.
            EditText mrzText = (EditText) findViewById(R.id.mrz);
            if (mrzText != null) {
                settings.edit().putInt("enroll_document", next_activity)
                        .putString("mrz", mrzText.getText().toString()).apply();
            }
            //TODO handle DL GUI

            Intent i = new Intent(this, DriversLicenseEnrollActivity.class);
            startActivityForResult(i, DriversLicenseEnrollActivity.DriversLicenseEnrollActivityCode);
        } else {
            throw new IllegalStateException("Enroll Activity advancing an unknown screen: " + screen);
        }
        break;
    case SCREEN_ISSUE:
    case SCREEN_ERROR:
        screen = SCREEN_START;
        finish();
        break;

    default:
        Log.e(TAG, "Error, screen switch fall through: " + screen);
        break;
    }
}

From source file:org.thezero.qrfi.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView;
    if (position == 0) {
        rootView = inflater.inflate(R.layout.fragment_generate, container, false);
        final CardView cardQr = (CardView) rootView.findViewById(R.id.card_qr);
        cardQr.setVisibility(View.GONE);

        String[] items = new String[] { "Open", "WEP", "WPA/WPA2" };
        final EditText ssid = (EditText) rootView.findViewById(R.id.edit_ssid);
        final EditText pass = (EditText) rootView.findViewById(R.id.edit_pass);
        final Spinner spinner = (Spinner) rootView.findViewById(R.id.wifi_type);

        ArrayAdapter<String> adapter = new ArrayAdapter<>(c, android.R.layout.simple_spinner_item, items);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);/*from  w  w w  .  j  av  a2s.com*/
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (parent.getSelectedItem().toString().equals("Open")) {
                    rootView.findViewById(R.id.second).setVisibility(View.GONE);
                } else {
                    rootView.findViewById(R.id.second).setVisibility(View.VISIBLE);
                }
            }

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

        final boolean[] cardHide = { true };
        Button delete = (Button) rootView.findViewById(R.id.delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cardHide[0] = true;
                cardQr.animate().translationY(0).alpha(0.0f).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        if (cardHide[0])
                            cardQr.setVisibility(View.GONE);
                    }
                });
                ssid.setText("");
                pass.setText("");
                spinner.setSelection(0);
            }
        });

        Button gen = (Button) rootView.findViewById(R.id.generate);
        gen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // WIFI:S:Pistol;T:WEP;P:pistolawifi2;;
                if (pass.getText().length() < 8 && !spinner.getSelectedItem().toString().equals("Open")) {
                    Toast.makeText(c, c.getString(R.string.error_pass), Toast.LENGTH_LONG).show();
                    return;
                }
                String ap = "WIFI:S:" + ssid.getText() + ";T:" + spinner.getSelectedItem().toString() + ";P:"
                        + pass.getText() + ";;";
                Log.d(TAG, ap);
                QRCodeWriter writer = new QRCodeWriter();
                try {
                    BitMatrix matrix = writer.encode(ap, BarcodeFormat.QR_CODE, 700, 700, null);
                    int height = matrix.getHeight();
                    int width = matrix.getWidth();
                    final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
                    for (int x = 0; x < width; x++) {
                        for (int y = 0; y < height; y++) {
                            bmp.setPixel(x, y, matrix.get(x, y) ? Color.BLACK : Color.WHITE);
                        }
                    }
                    ImageView qr_image = (ImageView) rootView.findViewById(R.id.qrimage);
                    qr_image.setImageBitmap(bmp);
                    cardHide[0] = false;
                    cardQr.setVisibility(View.VISIBLE);
                    cardQr.setAlpha(1.0f);
                    cardQr.animate().translationY(10).alpha(1.0f);

                    Button dialogButton = (Button) rootView.findViewById(R.id.ok);
                    dialogButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            File sdcard = Environment.getExternalStorageDirectory();
                            FileOutputStream out = null;
                            File check = new File(sdcard, "/wifipv/");
                            if (!(check.exists())) {
                                boolean resu = check.mkdir();
                                if (!resu) {
                                    return;
                                }
                            }

                            try {
                                File myFile = new File(sdcard, "/wifipv/" + ssid.getText() + ".png");
                                out = new FileOutputStream(myFile);
                                boolean success = bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
                                if (success) {
                                    MediaScannerConnection.scanFile(c,
                                            new String[] { myFile.getAbsolutePath() }, null,
                                            new MediaScannerConnection.OnScanCompletedListener() {
                                                @Override
                                                public void onScanCompleted(String path, Uri uri) {
                                                    Log.d(TAG, "file " + path + " was scanned seccessfully: "
                                                            + uri);
                                                    Intent shareIntent = new Intent();
                                                    shareIntent.setAction(Intent.ACTION_SEND);
                                                    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                                                    shareIntent.setType("image/png");
                                                    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                                    Intent new_intent = Intent.createChooser(shareIntent,
                                                            c.getText(R.string.send_to));
                                                    new_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                                    c.startActivity(new_intent);

                                                }
                                            });
                                } else {
                                    Toast.makeText(c, c.getString(R.string.error_share), Toast.LENGTH_LONG)
                                            .show();
                                }
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            } finally {
                                if (out != null)
                                    try {
                                        out.close();
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                            }
                        }
                    });
                } catch (WriterException e) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        rootView = inflater.inflate(R.layout.fragment_scan, container, false);
        Button scan = (Button) rootView.findViewById(R.id.scan);
        scan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent(c, ScanActivity.class);
                myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                c.startActivity(myIntent);
            }
        });
        Button gallery = (Button) rootView.findViewById(R.id.gallery);
        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectFromGallery();
            }
        });
        /*final boolean[] tutorialHide = {false};
        final CardView tutorial = (CardView)rootView.findViewById(R.id.card_tutorial);
        tutorial.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                
            if(tutorialHide[0]){
                tutorialHide[0]=false;
                Animation anidelta = new ResizeAnimation(tutorial, tutorial.getHeight());
                anidelta.setDuration(500);
                anidelta.setFillAfter(true);
                tutorial.startAnimation(anidelta);
            }else{
                tutorialHide[0]=true;
                Animation anidelta = new ResizeAnimation(tutorial, 120);
                anidelta.setDuration(500);
                anidelta.setFillAfter(true);
                tutorial.startAnimation(anidelta);
            }
        }
        });*/
    }
    ViewCompat.setElevation(rootView, 50);
    return rootView;
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java

final static private void setSpinnerExtraDataBoolean(final GlobalParameters mGlblParms, Dialog dialog,
        Spinner spinner, CustomSpinnerAdapter adapter, String selected) {
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setPrompt(/*from   w w  w  .  ja  va2s  .  com*/
            mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_activity_data_type));
    spinner.setAdapter(adapter);
    adapter.clear();
    adapter.add("false");
    adapter.add("true");
    int sel_no = 0;
    if (selected.equals("true"))
        sel_no = 1;
    spinner.setSelection(sel_no);
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void submitCorrection() {
    final EditText text = new EditText(this);
    MainActivity.prompt("Enter correction to the bot's response (what it should have said)", this, text,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    if (instance == null) {
                        return;
                    }//from   ww w.ja v  a 2 s.  com

                    ChatConfig config = new ChatConfig();
                    config.instance = instance.id;
                    config.conversation = MainActivity.conversation;
                    config.speak = !MainActivity.deviceVoice;
                    config.avatar = avatarId;
                    if (MainActivity.disableVideo) {
                        config.avatarFormat = "image";
                    } else {
                        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
                    }
                    config.avatarHD = MainActivity.hd;

                    config.message = text.getText().toString().trim();
                    if (config.message.equals("")) {
                        return;
                    }
                    messages.add(config);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ListView list = (ListView) findViewById(R.id.chatList);
                            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
                            list.invalidateViews();
                        }

                    });

                    config.correction = true;

                    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
                    config.emote = emoteSpin.getSelectedItem().toString();

                    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
                    action.execute();

                    EditText v = (EditText) findViewById(R.id.messageText);
                    v.setText("");
                    emoteSpin.setSelection(0);
                    resetToolbar();

                    WebView responseView = (WebView) findViewById(R.id.responseText);
                    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);

                }
            });
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void flagResponse() {
    if (MainActivity.user == null) {
        MainActivity.showMessage("You must sign in to flag a response", this);
        return;/* ww w . j ava 2 s .  c o  m*/
    }
    final EditText text = new EditText(this);
    MainActivity.prompt("Enter reason for flagging response as offensive", this, text,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    if (instance == null) {
                        return;
                    }
                    ChatConfig config = new ChatConfig();
                    config.instance = instance.id;
                    config.conversation = MainActivity.conversation;
                    config.speak = !MainActivity.deviceVoice;
                    config.avatar = avatarId;
                    if (MainActivity.translate && MainActivity.voice != null) {
                        config.language = MainActivity.voice.language;
                    }
                    if (MainActivity.disableVideo) {
                        config.avatarFormat = "image";
                    } else {
                        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
                    }
                    config.avatarHD = MainActivity.hd;

                    config.message = text.getText().toString().trim();
                    if (config.message.equals("")) {
                        return;
                    }
                    messages.add(config);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ListView list = (ListView) findViewById(R.id.chatList);
                            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
                            list.invalidateViews();
                        }

                    });

                    config.offensive = true;

                    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
                    config.emote = emoteSpin.getSelectedItem().toString();

                    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
                    action.execute();

                    EditText v = (EditText) findViewById(R.id.messageText);
                    v.setText("");
                    emoteSpin.setSelection(0);
                    resetToolbar();

                    WebView responseView = (WebView) findViewById(R.id.responseText);
                    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);
                }
            });
}

From source file:com.RSMSA.policeApp.OffenceReportForm.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_report_offence);
    sharedpreferences = getSharedPreferences(MyPREF, Context.MODE_PRIVATE);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from ww w .  j a va2 s.  c  om

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setTranslucentStatus(true);
    }
    SystemBarTintManager tintManager = new SystemBarTintManager(this);
    tintManager.setStatusBarTintEnabled(true);
    ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(R.color.blue_900));
    tintManager.setTintDrawable(colorDrawable);

    RelativeLayout inputs = (RelativeLayout) findViewById(R.id.inputs);
    plateNumberEdit = (EditText) findViewById(R.id.plate_number_edit_text);
    licenceNumberEdit = (EditText) findViewById(R.id.licence_number_edit_text);

    final Bundle bundle = getIntent().getExtras();
    namePassed = bundle.getString("name");
    dLicense = bundle.getString("licence_number");
    plateNumberObtained = bundle.getString("plate_number");
    driverUid = bundle.getString("driverUid");
    vehicleUid = bundle.getString("vehicleUid");

    try {
        invalidLicence = bundle.getString("invalidLicence");
        expiredInsuarance = bundle.getString("expiredInsuarance");
    } catch (NullPointerException e) {
    }

    if (dLicense.equals("") || dLicense == null) {
        licenceNumberEdit.setVisibility(View.VISIBLE);
    } else if (plateNumberObtained.equals("") || plateNumberObtained == null) {
        plateNumberEdit.setVisibility(View.VISIBLE);
    }

    submit = (TextView) findViewById(R.id.submit_text);

    plateNo = (TextView) findViewById(R.id.plate_no_);
    chargesAcceptance = (TextView) findViewById(R.id.charges_acceptance);
    chargesAcceptance.setTypeface(MainOffence.Roboto_Regular);

    offensesCommittedTextview = (TextView) findViewById(R.id.offences_committed_title);
    offensesCommittedTextview.setTypeface(MainOffence.Roboto_BoldCondensed);

    ChargesAcceptanceTitle = (TextView) findViewById(R.id.charges_acceptance_title);
    paymentMethodTitle = (TextView) findViewById(R.id.payment_method_title);
    PaymentTitle = (TextView) findViewById(R.id.payment_title);

    ChargesAcceptanceTitle.setTypeface(MainOffence.Roboto_BoldCondensed);
    paymentMethodTitle.setTypeface(MainOffence.Roboto_BoldCondensed);
    PaymentTitle.setTypeface(MainOffence.Roboto_BoldCondensed);

    offencesCostTitle = (TextView) findViewById(R.id.offences_cost_title);
    offencesCostTitle.setTypeface(MainOffence.Roboto_BoldCondensed);

    submitText = (TextView) findViewById(R.id.submit_text);

    license = (TextView) findViewById(R.id.license);
    license.setText(dLicense);

    report = (RelativeLayout) findViewById(R.id.report);
    summary = (RelativeLayout) findViewById(R.id.summary);
    submit_layout = (RelativeLayout) findViewById(R.id.submit_layout);

    submit_layout1 = (RelativeLayout) findViewById(R.id.submit_layout1);
    submit_layout1.setVisibility(View.GONE);

    progressBar = (ProgressBar) findViewById(R.id.pbar_report);

    TextView driverName = (TextView) findViewById(R.id.driver_name);
    driverName.setTypeface(MainOffence.Roboto_BoldCondensed);

    TextView plateNumberTitle = (TextView) findViewById(R.id.plate_no_title_);
    plateNumberTitle.setTypeface(MainOffence.Roboto_BoldCondensed);

    TextView driverLicense = (TextView) findViewById(R.id.driver_license);
    driverLicense.setTypeface(MainOffence.Roboto_BoldCondensed);

    RelativeLayout OffenseType = (RelativeLayout) findViewById(R.id.offense_type);
    OffenseType.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(OffenceReportForm.this, OffenseListActivity.class);
            OffenceReportForm.this.startActivityForResult(intent, REPORT_RESULT);
        }
    });

    offense_type_text = (TextView) findViewById(R.id.offense_type_text);

    offencesSelectedTextView = (TextView) findViewById(R.id.offence_list);
    offensesCommittedTextview = (TextView) findViewById(R.id.offences_committed);

    TextView name = (TextView) findViewById(R.id.name);
    name.setText(namePassed);

    final RadioButton court = (RadioButton) findViewById(R.id.court);
    court.setTypeface(MainOffence.Roboto_BoldCondensed);
    final RadioButton guilty = (RadioButton) findViewById(R.id.guilty);
    guilty.setTypeface(MainOffence.Roboto_BoldCondensed);

    guilty.setChecked(true);

    court.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b == true) {
                guilty.setChecked(false);
                commit = false;
            }
        }
    });

    guilty.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b == true) {
                court.setChecked(false);
                commit = true;
            }
        }
    });

    final String[] paymentMethodsArray = this.getResources().getStringArray(R.array.payment_methods);
    final Spinner paymentMethodSpinner = (Spinner) findViewById(R.id.payment_method_spinner);
    final RadioButton paid = (RadioButton) findViewById(R.id.paid);
    paid.setTypeface(MainOffence.Roboto_Regular);
    final RadioButton not_paid = (RadioButton) findViewById(R.id.not_paid);
    final TextView receipt_title = (TextView) findViewById(R.id.receipt_title);
    receiptEditText = (EditText) findViewById(R.id.receipt);

    receipt_title.setTypeface(MainOffence.Roboto_BoldCondensed);

    not_paid.setTypeface(MainOffence.Roboto_Regular);

    not_paid.setChecked(true);

    paymentMethodSpinner.setBackground(null);

    paid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b == true) {
                paymentStatus = true;
                paymentMethodTitle.setVisibility(View.VISIBLE);
                paymentMethodSpinner.setVisibility(View.VISIBLE);
                paymentMethod = paymentMethodsArray[0];
                paymentMethodSpinner.setSelection(0);
                receipt_title.setVisibility(View.VISIBLE);
                receiptEditText.setVisibility(View.VISIBLE);
            }
        }
    });

    not_paid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b == true) {
                paymentStatus = false;
                paymentMethodTitle.setVisibility(View.GONE);
                paymentMethodSpinner.setVisibility(View.GONE);
                receipt_title.setVisibility(View.GONE);
                receiptEditText.setVisibility(View.GONE);
                paymentMethod = "";
                receiptEditText.setText("");

            }
        }
    });

    PaymentMethodSpinnerAdapter adapter = new PaymentMethodSpinnerAdapter(
            getSupportActionBar().getThemedContext(), R.layout.row_menu, paymentMethodsArray);
    paymentMethodSpinner.setAdapter(adapter);
    paymentMethodSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            paymentMethod = paymentMethodsArray[position];
            if (position == 0) {
                receiptEditText.setVisibility(View.VISIBLE);
                receipt_title.setVisibility(View.VISIBLE);
            } else {
                receiptEditText.setVisibility(View.GONE);
                receipt_title.setVisibility(View.GONE);
            }
        }

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

        }
    });

}