Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

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

Prototype

public ArrayAdapter(@NonNull Context context, @LayoutRes int resource) 

Source Link

Document

Constructor

Usage

From source file:com.pgmacdesign.lacunacompanion.fragments.MailFragment.java

public void refreshMail() {

    JSONObject hashOptions = new JSONObject();
    if (pageNum != 1)
        JsonParser.put(hashOptions, "page_number", pageNum);
    if (filterTag != "")
        JsonParser.put(hashOptions, "tags", filterTag);

    ClientSide.setContext(getActivity());
    JSONObject result = ClientSide.send(new Object[] { hashOptions }, "/inbox", "view_inbox");

    if (result != null) {
        JSONArray messages = JsonParser.getJA(result, "messages");
        List<Map<String, String>> mailList = new ArrayList<Map<String, String>>();
        ArrayList<String> mailIds = new ArrayList<String>(24); // Max numbers on each page is 25.

        boolean hasMail = false; // By default, so that there's no way to screw up.
        if (messages.length() > 0) {
            for (int i = 0; i < messages.length(); i++) {
                JSONObject message = JsonParser.getJO(messages, i);

                Map<String, String> datum = new HashMap<String, String>(2);
                datum.put("from", JsonParser.getS(message, "from"));
                datum.put("subject", JsonParser.getS(message, "subject"));
                mailList.add(datum);//from  ww w.  j  ava  2 s. c  o  m

                mailIds.add(JsonParser.getS(message, "id"));

                hasMail = true;
            }
        } else {
            Map<String, String> datum = new HashMap<String, String>(2);
            datum.put("from", "No new Mail available.");
            datum.put("subject", "Sorry. :(");
            mailList.add(datum);

            hasMail = false;
        }

        // Let the UI refresh when there's no mails.
        ListView mails = (ListView) getActivity().findViewById(R.id.mails);
        SimpleAdapter adapter = new SimpleAdapter(getActivity(), mailList, android.R.layout.simple_list_item_2,
                new String[] { "from", "subject" }, new int[] { android.R.id.text1, android.R.id.text2 });
        mails.setAdapter(adapter);

        if (hasMail == true) {
            final Object[] MAIL_IDS = mailIds.toArray();

            //spinnerReset = System.currentTimeMillis();
            mails.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> a, View v, int pos, long id) {
                    //if (System.currentTimeMillis() - spinnerReset < 1000) {
                    //Nothing!
                    //}
                    //else if (System.currentTimeMillis() - spinnerReset > 1000) {
                    String mailId = MAIL_IDS[pos].toString();

                    Intent intent = new Intent(getActivity(),
                            com.pgmacdesign.lacunacompanion.module.inbox.ViewMail.class);
                    intent.putExtra("mailId", mailId);

                    getActivity().startActivity(intent);
                    //}
                }
            });

            // Populate the pages Spinner.
            ArrayAdapter<String> pagesSpinnerAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            Spinner mailPages = (Spinner) getActivity().findViewById(R.id.mailPage);
            double pages = (double) Math.ceil(JsonParser.getL(result, "message_count") / 25);

            for (int i = 1; i < pages; i++) {
                pagesSpinnerAdapter.add("" + i);
            }

            mailPages.setAdapter(pagesSpinnerAdapter);
            mailPages.recomputeViewAttributes(mailPages);
            mailPages.setSelection(pageNum - 1);
        }
    }
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

private ActionBarDrawerToggle initializeDrawerToggle() {
    final int drawerImageRes;

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    //actionBar.setCustomView(mTextView);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setIcon(R.drawable.icon);/*from ww w  .  ja  v a2s. c  om*/
    actionBar.setTitle("");//ZV

    //actionBar.setBackgroundDrawable(new ColorDrawable(Color.rgb(197, 197, 197))); //ZV

    final ArrayAdapter<CharSequence> actionBarAdapter = new ArrayAdapter<>(actionBar.getThemedContext(),
            android.R.layout.simple_spinner_item);
    for (final String tab : TAB_LIST) {
        actionBarAdapter.add(getText(LibraryTabsUtil.getTabTitleResId(tab)));
    }

    actionBarAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    actionBar.setListNavigationCallbacks(actionBarAdapter, this);

    /**
     * @param Activity activity
     * @param DrawerLayout
     * @param drawerImageRes nav drawer icon to replace 'Up' caret
     * @param openDrawerContentDescRes "open drawer" description
     * @param closeDrawerContentDescRes "close drawer" description
     */
    return new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {

        /**
         * Called when a drawer has settled in a completely closed
         * state.
         */
        @Override
        public void onDrawerClosed(final View drawerView) {
            refreshActionBarTitle();
        }

        /**
         * Called when a drawer has settled in a completely open
         * state.
         */
        @Override
        public void onDrawerOpened(final View drawerView) {
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setTitle(R.string.app_name);//ZV
            //mTextView.setText(R.string.app_name); ZV
        }
    };
}

From source file:com.example.bluetooth_faster_connection.MainActivity.java

private void setupMessage() {
    Log.d(TAG, "setupMessage()");

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
    mConversationView = (ListView) findViewById(R.id.in);
    mConversationView.setAdapter(mConversationArrayAdapter);

    /*//  ww w  .jav  a2  s  .c  o m
     * // Initialize the compose field with a listener for the return key
     * mOutEditText = (EditText) findViewById(R.id.edit_text_out);
     * mOutEditText.setOnEditorActionListener(mWriteListener);
     * 
     * // Initialize the send button with a listener that for click events
     * mSendButton = (Button) findViewById(R.id.button_send);
     * mSendButton.setOnClickListener(new OnClickListener() { public void
     * onClick(View v) { // Send a message using content of the edit text
     * widget TextView view = (TextView) findViewById(R.id.edit_text_out);
     * String message = view.getText().toString(); sendMessage(message); }
     * });
     */

    // Initialize the BluetoothMessageService to perform bluetooth
    // connections
    mMessageService = new BluetoothMessageService(this, mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java

/**
 * UI??./*from   w ww.ja v a  2 s  . c  om*/
 */
private void initUI() {
    // ?
    mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);

    // 
    ListView listView = (ListView) findViewById(R.id.reqResList);
    listView.setAdapter(mListAdapter);
    initSpinner();

    // ?
    mTextPath = (EditText) findViewById(R.id.reqPath);

    // URL?
    mSelectUrl = (CheckBox) findViewById(R.id.isUrl);
    mSelectUrl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            enableSetting(buttonView.isChecked());
        }
    });

    mWebsocketBtn = (ToggleButton) findViewById(R.id.reqWesocket);
    mWebsocketBtn.setOnClickListener(this);
}

From source file:com.cyanogenmod.effem.FmRadio.java

/**
 * Sets up the buttons and their listeners
 *///from   w w w .j  a va 2  s  . c  o m
private void setupButtons() {
    // populate favorites menu
    mMenuAdapter = new ArrayAdapter<MenuTuple>(this, android.R.layout.simple_spinner_item);

    try {
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        JSONObject conf = new JSONObject(settings.getString("stations", ""));
        JSONArray stations = conf.getJSONArray("stations");
        for (int i = 0; i < stations.length(); i++) {
            MenuTuple mt = MenuTuple.fromJSON(stations.getJSONObject(i));
            mMenuAdapter.add(mt);
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, "Failed to load station list");
    }

    // get references to buttons
    mFrequencyTextView = (TextView) findViewById(R.id.FrequencyTextView);
    mStationNameTextView = (TextView) findViewById(R.id.PSNTextView);
    mStationInfoTextView = (TextView) findViewById(R.id.RTTextView);
    mProgramTypeTextView = (TextView) findViewById(R.id.PTYTextView);
    final ImageButton scanUp = (ImageButton) findViewById(R.id.ScanUp);
    final ImageButton scanDown = (ImageButton) findViewById(R.id.ScanDown);
    final ImageButton pause = (ImageButton) findViewById(R.id.Pause);
    final ImageButton favorite = (ImageButton) findViewById(R.id.Favorite);
    mStationInfoTextView.setSelected(true);

    // set typeface for station frequency widget
    // this is done here instead of layout xml to keep ICS compatibility
    mFrequencyTextView.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));

    scanUp.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            scanUp.setEnabled(false);
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.changeFrequency(FmRadioService.SEEK_STEPUP, 0);
                }
            });
            return true;
        }
    });

    scanDown.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            scanDown.setEnabled(false);
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.changeFrequency(FmRadioService.SEEK_STEPDOWN, 0);
                }
            });
            return true;
        }
    });

    scanUp.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.startRadio(mSelectedBand, mCurrentFrequency, mSelectedOutput);
                    if (mService.isStarted())
                        mService.changeFrequency(FmRadioService.SEEK_SCANUP, 0);
                }
            });
            scanUp.setEnabled(false);
        }
    });

    scanDown.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.startRadio(mSelectedBand, mCurrentFrequency, mSelectedOutput);
                    if (mService.isStarted())
                        mService.changeFrequency(FmRadioService.SEEK_SCANDOWN, 0);
                }
            });
            scanDown.setEnabled(false);
        }
    });

    pause.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mService.isStarted())
                mService.stopRadio();
            else {
                mWorkerHandler.post(new Runnable() {
                    public void run() {
                        mService.startRadio(mSelectedBand, mCurrentFrequency, mSelectedOutput);
                    }
                });
            }
        }
    });

    favorite.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            toggleFavorite(v, mCurrentFrequency);
        }
    });
}

From source file:com.example.lilach.alsweekathon_new.MainActivity.java

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

    ///////////////////////////////////////////
    try {/*from  www.jav a  2s  . com*/
        String yourFilePath = Environment.getExternalStorageDirectory() + "/"
                + "spiralStairs_CalInertialAndMag.csv";
        CSVReader reader = new CSVReader(new FileReader(yourFilePath));

        String[] nextLine;
        //skip the first line - headers
        reader.readNext();
        LinkedList<Signal> signals = new LinkedList<Signal>();

        for (int i = 0; i < 3; i++) {
            nextLine = reader.readNext();
            // while ((nextLine = reader.readNext()) != null) {
            // nextLine[] is an array of values from the line
            System.out.println(nextLine[0] + nextLine[1] + "etc...");
            Signal signal = new Signal();
            signal.setTimestamp(new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date()));
            signal.setPacketId(Integer.parseInt(nextLine[PACKET_NUMBER_INDEX]));
            signal.setAccelerometer(new XYZValues(Float.parseFloat(nextLine[ACCELEROMETER_X_INDEX]),
                    Float.parseFloat(nextLine[ACCELEROMETER_Y_INDEX]),
                    Float.parseFloat(nextLine[ACCELEROMETER_Z_INDEX])));
            signal.setGyro(new XYZValues(Float.parseFloat(nextLine[GYROSCOPE_X_INDEX]),
                    Float.parseFloat(nextLine[GYROSCOPE_Y_INDEX]),
                    Float.parseFloat(nextLine[GYROSCOPE_Z_INDEX])));

            signals.add(signal);

        }

        serverRequest sr = new serverRequest();
        sr.setSignals(signals);
        sr.setUserid("user");
        sr.setTimestamp("111111");

        //send the data to the server: Json, Post
        Gson gson = new Gson();
        String json = gson.toJson(sr);
        Log.d("aa", json);
        makeRequest("http://alsvm.cloudapp.net:8080/signals/user", json);
        // HttpResponse a = makeRequest("http://alsvm.cloudapp.net:8080/signals/user", json);
        // Log.d("httpResponse", a.toString());

        //            List myEntries = reader.readAll();
        //            System.out.println("size: " +myEntries.size());
        //            System.out.println("first item: "+myEntries.get(0));

    } catch (IOException e) {
        Log.d("exception: ", e.getMessage());
    }

    //////////////////////////////////////////////

    setContentView(R.layout.main);
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    /// service_init();

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mBtAdapter.isEnabled()) {
                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                if (btnConnectDisconnect.getText().equals("Connect")) {

                    //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices

                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {
                    //Disconnect button pressed
                    //                    if (mDevice!=null)
                    //                    {
                    //                       //mService.disconnect();
                    //
                    //                    }
                }
            }
        }
    });
    // Handler Send button
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                //mService.writeRXCharacteristic(value);
                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Set initial UI state

}

From source file:com.nonstop.android.SoC.BluetoothChat.BluetoothChat.java

private void setupChat() {
    Log.d(TAG, "setupChat()");

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
    mConversationView = (ListView) findViewById(R.id.in);
    mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    mOutEditText = (EditText) findViewById(R.id.edit_text_out);
    mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events
    mSendButton = (Button) findViewById(R.id.button_send);
    mSendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            TextView view = (TextView) findViewById(R.id.edit_text_out);
            String message = view.getText().toString();
            sendMessage(message);/*from  w ww . j  a va 2  s. c om*/
        }
    });
    mTurnLeftButton = (Button) findViewById(R.id.button_turnleft);
    mTurnLeftButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            mChatService.mGlasOData.setDirection(Direction.LEFT);
            sendMessage(mChatService.mGlasOData.makePacket());
        }
    });
    mTurnRightButton = (Button) findViewById(R.id.button_turnright);
    mTurnRightButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mChatService.mGlasOData.setDirection(Direction.RIGHT);
            sendMessage(mChatService.mGlasOData.makePacket());
        }
    });
    mNormalButton = (Button) findViewById(R.id.button_normal);
    mNormalButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mChatService.mGlasOData.setDirection(Direction.NORMAL);
            sendMessage(mChatService.mGlasOData.makePacket());
        }
    });

    mNoAlarmButton = (Button) findViewById(R.id.button_no_alarm);
    mNoAlarmButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mChatService.mGlasOData.setAlarm_(Alarm.NOUSE);
            sendMessage(mChatService.mGlasOData.makePacket());
        }
    });
    mAroundAlarmButton = (Button) findViewById(R.id.button_around_alarm);
    mAroundAlarmButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mChatService.mGlasOData.setAlarm_(Alarm.AROUND);
            sendMessage(mChatService.mGlasOData.makePacket());
        }
    });
    mOnAlarmButton = (Button) findViewById(R.id.button_on_alarm);
    mOnAlarmButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mChatService.mGlasOData.setAlarm_(Alarm.ONTIME);
            sendMessage(mChatService.mGlasOData.makePacket());
        }
    });
    mOnTimeButton = (Button) findViewById(R.id.button_ontime);
    mOnTimeButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mChatService.mGlasOData.setOnTime(OnTime.ON);
            sendMessage(mChatService.mGlasOData.makePacket());
            mChatService.mGlasOData.setOnTime(OnTime.OFF);
        }
    });
    mPhotoButton = (Button) findViewById(R.id.button_photo);
    mPhotoButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            if (!Utility.mFacebook.isSessionValid()) {
                // Util.showAlert(this, "Warning",
                // "You must first log in.");
            } else {
                /*
                 * Source tag: upload_photo_tag
                 */
                dialog = ProgressDialog.show(BluetoothChat.this, "", getString(R.string.please_wait), true,
                        true);
                Bundle params = new Bundle();
                params.putString("url", "http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
                params.putString("caption", "FbAPIs Sample App photo upload");
                Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
            }
        }
    });

    mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
    mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup arg0, int arg1) {
            if (arg1 == R.id.radio_exceed) {

                mChatService.mGlasOData.setExceed(Exceed.EXCEED);
            } else if (arg1 == R.id.radio_exceedhigh) {

                mChatService.mGlasOData.setExceed(Exceed.EXCEEDHIGH);
            } else if (arg1 == R.id.radio_normalspeed) {
                mChatService.mGlasOData.setExceed(Exceed.NORMALSPEED);
            }
            sendMessage(mChatService.mGlasOData.makePacket());
        }
    });

    mStatusCheckBox = (CheckBox) findViewById(R.id.checkBox_status);
    mStatusCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mChatService.mGlasOData.setStatus(Status.WRONG);
            } else {
                mChatService.mGlasOData.setStatus(Status.NORMAL);
            }
        }
    });

    mNaviToggle = (ToggleButton) findViewById(R.id.toggle_navi);
    mNaviToggle.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (D)
                    Log.e(TAG, "++ NAVI ON ++");
                mChatService.navi_stat_ = 1;

            } else {
                if (D)
                    Log.e(TAG, "++ NAVI OFF ++");
                mChatService.navi_stat_ = 0;

            }
        }
    });
    mHeartbeatToggle = (ToggleButton) findViewById(R.id.toggle_Heartbeat);
    mHeartbeatToggle.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (D)
                    Log.e(TAG, "++ HEARTBEAT ON ++");
                mChatService.heartbeat_stat_ = 1;
            } else {
                if (D)
                    Log.e(TAG, "++ HEARTBEAT OFF ++");
                mChatService.heartbeat_stat_ = 0;
            }
            if (mChatService.heartbeat_stat_ == 0 && mChatService.distance_stat_ == 0
                    && mChatService.speed_stat_ == 0) {
                mChatService.sens_stat_ = 0;
            } else {
                mChatService.sens_stat_ = 1;
            }
        }
    });

    mHeartbeat = (SeekBar) findViewById(R.id.seekBar_Heartbeat);
    mHeartbeat.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mChatService.mGlasOData.setHeartbeat_(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    mSpeedToggle = (ToggleButton) findViewById(R.id.toggle_Velocity);
    mSpeedToggle.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (D)
                    Log.e(TAG, "++ SpeedSens ON ++");
                mChatService.speed_stat_ = 1;
            } else {
                if (D)
                    Log.e(TAG, "++ SpeedSens OFF ++");
                mChatService.speed_stat_ = 0;
            }
            if (mChatService.heartbeat_stat_ == 0 && mChatService.distance_stat_ == 0
                    && mChatService.speed_stat_ == 0) {
                mChatService.sens_stat_ = 0;
            } else {
                mChatService.sens_stat_ = 1;
            }
        }
    });

    mSpeed = (SeekBar) findViewById(R.id.seekBar_Velocity);
    mSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mChatService.mGlasOData.setVelocity_(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    mDistanceToggle = (ToggleButton) findViewById(R.id.toggle_Distance);
    mDistanceToggle.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (D)
                    Log.e(TAG, "++ Distance ON ++");
                mChatService.distance_stat_ = 1;
            } else {
                if (D)
                    Log.e(TAG, "++ Distance OFF ++");
                mChatService.distance_stat_ = 0;
            }
            if (mChatService.heartbeat_stat_ == 0 && mChatService.distance_stat_ == 0
                    && mChatService.speed_stat_ == 0) {
                mChatService.sens_stat_ = 0;
            } else {
                mChatService.sens_stat_ = 1;
            }
        }
    });

    mDiatance = (SeekBar) findViewById(R.id.seekBar_Distance);
    mDiatance.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mChatService.mGlasOData.setDistance_(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(this, mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

From source file:it.chefacile.app.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = this;
    chefacileDb = new DatabaseHelper(this);
    // FilterButton = (ImageButton) findViewById(R.id.buttonfilter);
    TutorialButton = (ImageButton) findViewById(R.id.button);
    //  AddButton = (ImageButton) findViewById(R.id.button2);
    responseView = (TextView) findViewById(R.id.responseView);
    editText = (EditText) findViewById(R.id.ingredientText);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    //Show = (ImageButton) findViewById(R.id.buttonShow);
    //Show2 = (ImageButton) findViewById(R.id.buttonShow2);
    materialAnimatedSwitch = (MaterialAnimatedSwitch) findViewById(R.id.pin);
    //buttoncuisine = (ImageButton) findViewById(R.id.btn_cuisine);
    //buttondiet = (ImageButton) findViewById(R.id.btn_diet);
    //buttonintol = (ImageButton) findViewById(R.id.btn_intoll);
    //Mostra = (Button) findViewById(R.id.btn_mostra);

    final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    animation.setDuration(1000); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(5); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE);

    ImageView icon = new ImageView(this); // Create an icon
    icon.setImageDrawable(getResources().getDrawable(R.drawable.logo));

    final com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton actionButton = new com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton.Builder(
            this).setPosition(
                    com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton.POSITION_RIGHT_CENTER)
                    .setContentView(icon).build();

    SubActionButton.Builder itemBuilder = new SubActionButton.Builder(this);
    // repeat many times:
    ImageView dietIcon = new ImageView(this);
    dietIcon.setImageDrawable(getResources().getDrawable(R.drawable.diet));
    SubActionButton button1 = itemBuilder.setContentView(dietIcon).build();
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showSingleChoiceDialogDiet(v);
        }//from w  ww . j a va2s  .c o m
    });

    ImageView intolIcon = new ImageView(this);
    intolIcon.setImageDrawable(getResources().getDrawable(R.drawable.intoll));
    SubActionButton button2 = itemBuilder.setContentView(intolIcon).build();
    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showMultiChoiceDialogIntol(v);
        }
    });

    ImageView cuisineIcon = new ImageView(this);
    cuisineIcon.setImageDrawable(getResources().getDrawable(R.drawable.cook12));
    SubActionButton button3 = itemBuilder.setContentView(cuisineIcon).build();
    button3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showMultiChoiceDialogCuisine(v);
        }
    });

    ImageView favouriteIcon = new ImageView(this);
    favouriteIcon.setImageDrawable(getResources().getDrawable(R.drawable.favorite));
    SubActionButton button4 = itemBuilder.setContentView(favouriteIcon).build();
    button4.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showSimpleListDialogFav(v);
        }
    });

    ImageView wandIcon = new ImageView(this);
    wandIcon.setImageDrawable(getResources().getDrawable(R.drawable.wand));
    SubActionButton button5 = itemBuilder.setContentView(wandIcon).build();
    button5.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            sugg = getSuggestion();
            suggOccurrences = getCount();
            showSimpleListDialogSuggestions(v);
        }
    });

    final FloatingActionButton actionABC = (FloatingActionButton) findViewById(R.id.action_abc);

    actionABC.bringToFront();
    actionABC.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ingredients.length() < 2) {
                Snackbar.make(responseView, "Insert at least one ingredient", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            } else {
                new RetrieveFeedTask().execute();
            }
        }

        // Snackbar.make(view, "Non disponibile, mangia l'aria", Snackbar.LENGTH_LONG)
        //         .setAction("Action", null).show();

    });

    FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(this).setStartAngle(90).setEndAngle(270)
            .addSubActionView(button1).addSubActionView(button2).addSubActionView(button3)
            .addSubActionView(button4).addSubActionView(button5).attachTo(actionButton).build();

    startDatabase(chefacileDb);

    for (int j = 0; j < cuisineItems.length; j++) {
        cuisineItems[j] = cuisineItems[j].substring(0, 1).toUpperCase() + cuisineItems[j].substring(1);
    }
    Arrays.sort(cuisineItems);

    for (int i = 0; i < 24; i++) {
        cuisineBool[i] = false;
    }

    Arrays.sort(intolItems);

    for (int i = 0; i < 11; i++) {
        intolBool[i] = false;
    }

    mListView = (MaterialListView) findViewById(R.id.material_listview);

    adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);

    TutorialButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, IntroScreenActivity.class));
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

        }
    });

    iv = (ImageView) findViewById(R.id.imageView);
    iv.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            clicks++;
            Log.d("CLICKS", String.valueOf(clicks));
            if (clicks == 15) {
                Log.d("IMAGE SHOWN", "mai vero");
                setBackground(iv);
            }
        }
    });

    materialAnimatedSwitch.setOnCheckedChangeListener(new MaterialAnimatedSwitch.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(boolean isChecked) {
            if (isChecked == true) {
                ranking = 2;
                Toast.makeText(getApplicationContext(), "Minimize missing ingredients", Toast.LENGTH_SHORT)
                        .show();
            } else {
                ranking = 1;
                Toast.makeText(getApplicationContext(), "Maximize used ingredients", Toast.LENGTH_SHORT).show();
            }
            Log.d("Ranking", String.valueOf(ranking));
        }
    });

    final CharSequence[] items = { "Maximize used ingredients", "Minimize missing ingredients" };

    editText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    if (!(editText.getText().toString().trim().equals(""))) {

                        String input;
                        String s1 = editText.getText().toString().substring(0, 1).toUpperCase();
                        String s2 = editText.getText().toString().substring(1);
                        input = s1 + s2;

                        Log.d("INPUT: ", input);
                        searchedIngredients.add(input);
                        Log.d("SEARCHED INGR LIST", searchedIngredients.toString());

                        if (!chefacileDb.findIngredientPREF(input)) {
                            if (chefacileDb.findIngredient(input)) {
                                chefacileDb.updateCount(input);
                                mapIngredients = chefacileDb.getDataInMapIngredient();
                                Map<String, Integer> map2;
                                map2 = sortByValue(mapIngredients);
                                Log.d("MAPPACOUNT: ", map2.toString());

                            } else {
                                if (chefacileDb.occursExceeded()) {
                                    //chefacileDb.deleteMinimum(input);
                                    // chefacileDb.insertDataIngredient(input);
                                    mapIngredients = chefacileDb.getDataInMapIngredient();
                                    Map<String, Integer> map3;
                                    map3 = sortByValue(mapIngredients);
                                    Log.d("MAPPAINGREDIENTE: ", map3.toString());

                                } else {
                                    chefacileDb.insertDataIngredient(input);
                                    mapIngredients = chefacileDb.getDataInMapIngredient();
                                    Map<String, Integer> map3;
                                    map3 = sortByValue(mapIngredients);
                                    Log.d("MAPPAINGREDIENTE: ", map3.toString());
                                }
                            }
                        }
                    }

                    if (editText.getText().toString().trim().equals("")) {
                        ingredients += editText.getText().toString().trim() + "";
                        editText.getText().clear();

                    } else {
                        ingredients += editText.getText().toString().replaceAll(" ", "+").trim().toLowerCase()
                                + ",";
                        singleIngredient = editText.getText().toString().trim().toLowerCase();
                        currentIngredient = singleIngredient;
                        new RetrieveIngredientTask().execute();

                        //adapter.add(singleIngredient.substring(0,1).toUpperCase() + singleIngredient.substring(1));
                    }

                    InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

                    in.hideSoftInputFromWindow(editText.getApplicationWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);

                    actionABC.startAnimation(animation);

                    return true;
                default:
                    break;
                }
            }
            return false;
        }
    });

    responseView = (TextView) findViewById(R.id.responseView);
    editText = (EditText) findViewById(R.id.ingredientText);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);

}

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

public void initViews() {
    mSearchView = getActivity().getLayoutInflater().inflate(R.layout.search, null);
    getListView().addHeaderView(mSearchView, null, false);

    final TextView historyView = (TextView) getActivity().getLayoutInflater().inflate(R.layout.header, null);
    historyView.setText(R.string.history_label);
    historyView.setOnClickListener(null); // Makes the header un-clickable, hack!
    getListView().addHeaderView(historyView);

    // Hide dividers on the header view.
    getListView().setHeaderDividersEnabled(false);

    if (!mStartPoint.hasName()) {
        mStartPoint.setName(Site.TYPE_MY_LOCATION);
    }/*w  ww.  j  av  a 2 s.c om*/
    mStartPointAutoComplete = createAutoCompleteTextView(R.id.from, /*R.id.from_progress*/ -1, mStartPoint);
    mEndPointAutoComplete = createAutoCompleteTextView(R.id.to, /*R.id.to_progress*/ -1, mEndPoint);
    mViaPointAutoComplete = createAutoCompleteTextView(R.id.via, /*R.id.via_progress*/ -1, mViaPoint, true);

    try {
        mHistoryDbAdapter = new HistoryDbAdapter(getActivity()).open();
    } catch (final Exception e) {
        showDialog(createDialogReinstallApp());
        return;
    }

    // Setup view for choosing other data for start and end point.
    final ImageButton fromDialog = (ImageButton) mSearchView.findViewById(R.id.from_menu);
    fromDialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            mStartPointAutoComplete.setError(null);
            showDialog(createDialogStartPoint());
        }
    });
    final ImageButton toDialog = (ImageButton) mSearchView.findViewById(R.id.to_menu);
    toDialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            mEndPointAutoComplete.setError(null);
            showDialog(createDialogEndPoint());
        }
    });
    final ImageButton viaDialog = (ImageButton) mSearchView.findViewById(R.id.via_menu);
    viaDialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            mViaPointAutoComplete.setError(null);
            showDialog(createDialogViaPoint());
        }
    });
    // Views for date and time
    mChangeTimeLayout = (LinearLayout) mSearchView.findViewById(R.id.planner_change_time_layout);

    mDateButton = (Button) mSearchView.findViewById(R.id.planner_route_date);
    mDateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            showDialog(createDialogDate());
        }
    });

    mTimeButton = (Button) mSearchView.findViewById(R.id.planner_route_time);
    mTimeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            showDialog(createDialogTime());
        }
    });

    // Views for radio buttons
    final RadioButton nowRadioButton = (RadioButton) mSearchView.findViewById(R.id.planner_check_now);
    nowRadioButton.setOnCheckedChangeListener(this);
    final RadioButton laterRadioButton = (RadioButton) mSearchView
            .findViewById(R.id.planner_check_more_choices);
    laterRadioButton.setOnCheckedChangeListener(this);

    mWhenSpinner = (Spinner) mSearchView.findViewById(R.id.departure_arrival_choice);
    final ArrayAdapter<CharSequence> whenChoiceAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.when_choice, android.R.layout.simple_spinner_item);
    whenChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mWhenSpinner.setAdapter(whenChoiceAdapter);

    // Handle create shortcut.
    if (mCreateShortcut) {
        registerScreen("Planner create shortcut");
        getActivity().setTitle(R.string.create_shortcut_label);

        // Add search label to button

        RadioGroup chooseTimeGroup = (RadioGroup) mSearchView.findViewById(R.id.planner_choose_time_group);
        chooseTimeGroup.setVisibility(View.GONE);
        historyView.setVisibility(View.GONE);
        // Fake an adapter. This needs to be fixed later on so we can use the history.
        setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.journey_history_row));
    } else {
        setListAdapter(mAdapter);
    }
}

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

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

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

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