Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

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

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:com.cmput301w17t07.moody.CreateMoodActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_mood);
    UserController userController = new UserController();
    userName = userController.readUsername(CreateMoodActivity.this).toString();
    setUpMenuBar(this);
    location = null;/* ww  w .java  2  s .  c  om*/
    date = new Date();
    Intent intent = getIntent();
    locationText = (TextView) findViewById(R.id.locationText);
    Description = (EditText) findViewById(R.id.Description);
    mImageView = (ImageView) findViewById(R.id.editImageView);

    //try to get picklocation, if it is equal to 1 that means, user just back from map not
    //other activities
    try {
        pickLocation = (int) intent.getExtras().getInt("pickLocation");
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (pickLocation == 1) {
        tempMood = (Mood) intent.getSerializableExtra("editMood");
        bitmap = (Bitmap) intent.getParcelableExtra("bitmapback");
        latitude = tempMood.getLatitude();
        longitude = tempMood.getLongitude();
        address = tempMood.getDisplayLocation();
        locationText.setText(address);
        Description.setText(tempMood.getMoodMessage());
        mImageView.setImageBitmap(bitmap);
        date = tempMood.getDate();
        displayAttributes();
    }

    /**
     * Spinner dropdown logic taken from http://stackoverflow.com/questions/13377361/how-to-create-a-drop-down-list <br>
     * Author: Nicolas Tyler, 2013/07/15 8:47 <br>
     * taken by Xin Huang 2017/03/10 <br>
     */
    //Spinner for emotion and socialsituatuion
    if (pickLocation == 0) {
        Spinner dropdown = (Spinner) findViewById(R.id.Emotion);

        String[] items = new String[] { "anger", "confusion", "disgust", "fear", "happiness", "sadness",
                "shame", "surprise" };
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item, items);
        dropdown.setAdapter(adapter);
        dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                EmotionText = parent.getItemAtPosition(position).toString();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                Toast.makeText(CreateMoodActivity.this, "Please pick a feeling!", Toast.LENGTH_SHORT).show();
            }
        });

        Spinner dropdown_SocialSituation = (Spinner) findViewById(R.id.SocialSituation);
        String[] item_SocialSituation = new String[] { "", "alone", "with one other person", "with two people",
                "with several people", "with a crowd" };
        ArrayAdapter<String> adapter_SocialSituation = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item, item_SocialSituation);
        dropdown_SocialSituation.setAdapter(adapter_SocialSituation);

        dropdown_SocialSituation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                SocialSituation = parent.getItemAtPosition(position).toString();
                TextView sizeView = (TextView) findViewById(R.id.SocialText);
                sizeView.setText("  " + SocialSituation);
            }

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

    ImageButton chooseButton = (ImageButton) findViewById(R.id.Camera);

    ImageButton locationButton = (ImageButton) findViewById(R.id.location);

    ImageButton PickerButton = (ImageButton) findViewById(R.id.Picker);

    //click on PickerButton, call the datetimePicker
    PickerButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            innit();
            TimeDialog.show();
        }
    });

    chooseButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            try {
                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                startActivityForResult(intent, 1);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), CreateMoodActivity.class);
                startActivity(intent);
            }
        }
    });

    chooseButton.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            try {
                Intent intent = new Intent("android.intent.action.PICK");
                intent.setType("image/*");
                startActivityForResult(intent, 0);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), CreateMoodActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    locationButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            //check available tools
            List<String> locationList = locationManager.getProviders(true);
            if (locationList.contains(LocationManager.GPS_PROVIDER)) {
                provider = LocationManager.GPS_PROVIDER;
            } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) {
                provider = LocationManager.NETWORK_PROVIDER;
            } else {
                Toast.makeText(getApplicationContext(), "Please check application permissions",
                        Toast.LENGTH_LONG).show();
            }

            //check the permission
            if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getApplicationContext(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                Toast.makeText(getApplicationContext(), "Get location failed, Please check the Permission",
                        Toast.LENGTH_SHORT).show();
                return;
            }

            location = locationManager.getLastKnownLocation(provider);
            if (location == null) {
                latitude = 0;
                longitude = 0;
            } else {
                latitude = location.getLatitude();
                longitude = location.getLongitude();
            }

            Geocoder gcd = new Geocoder(CreateMoodActivity.this, Locale.getDefault());
            try {
                List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1);
                if (addresses.size() > 0)
                    address = "  " + addresses.get(0).getFeatureName() + " "
                            + addresses.get(0).getThoroughfare() + ", " + addresses.get(0).getLocality() + ", "
                            + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode();
                locationText.setText(address);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    //pass users' changes to map, will be passed back
    locationButton.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            int fromCreate = 123;
            moodMessage_text = Description.getText().toString();
            tempMood = new Mood(EmotionText, userName, moodMessage_text, latitude, longitude, null,
                    SocialSituation, date, address);
            Intent editLocation = new Intent(CreateMoodActivity.this, EditLocation.class);
            editLocation.putExtra("EditMood", tempMood);
            editLocation.putExtra("fromCreate", fromCreate);
            editLocation.putExtra("bitmap", compress(bitmap));
            startActivity(editLocation);
            return true;
        }
    });

    Button submitButton = (Button) findViewById(R.id.button5);
    submitButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            moodMessage_text = Description.getText().toString();
            MoodController moodController = new MoodController();

            // --------------------------- achievements -------------------------------------
            AchievementManager.initManager(CreateMoodActivity.this);
            AchievementController achievementController = new AchievementController();
            achievements = achievementController.getAchievements();
            achievements.moodCount += 1;
            achievementController.incrementMoodCounter(EmotionText);
            achievementController.saveAchievements();
            // ------------------------------------------------------------------------------
            if (location != null || pickLocation == 1) {
                //todo can remove these if/else statements that toast message too long. They could
                // be handled in the controller
                if (!MoodController.createMood(EmotionText, userName, moodMessage_text, latitude, longitude,
                        bitmap, SocialSituation, date, address, CreateMoodActivity.this)) {
                    Toast.makeText(CreateMoodActivity.this,
                            "Mood message length is too long. Please try again.", Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent(CreateMoodActivity.this, TimelineActivity.class);
                    startActivity(intent);
                    finish();
                }
            } else {
                if (!MoodController.createMood(EmotionText, userName, moodMessage_text, 0, 0, bitmap,
                        SocialSituation, date, address, CreateMoodActivity.this)) {
                    Toast.makeText(CreateMoodActivity.this,
                            "Mood message length is too long. Please try again.", Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent(CreateMoodActivity.this, TimelineActivity.class);
                    startActivity(intent);
                    finish();
                }
            }
        }
    });
}

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

/** Called when the activity is first created. */
@Override/*from w  w  w. ja  v  a 2  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:org.mklab.mikity.android.SceneGraphTreeFragment.java

/**
 * ????//  w  w w  . ja v  a 2  s. c om
 */
void createTree() {
    this.tree = new GraphTree(getActivity());
    this.treeView.setAdapter(this.tree);

    bindModelToTree();

    setSelectedItem(this.rootItem, 0);

    this.tree.notifyDataSetChanged();

    this.treeView.setOnItemClickListener(new OnItemClickListener() {

        /**
         * {@inheritDoc}
         */
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SceneGraphTreeFragment.this.selectedTreeItem = (TreeItem) parent.getItemAtPosition(position);

            if (SceneGraphTreeFragment.this.selectedTreeItem.isExpanded()) {
                SceneGraphTreeFragment.this.selectedTreeItem.collapse();
            } else {
                if (SceneGraphTreeFragment.this.selectedTreeItem.hasItems()) {
                    SceneGraphTreeFragment.this.selectedTreeItem.expand();
                }
            }

            SceneGraphTreeFragment.this.tree.notifyDataSetChanged();

            updatetSelectedObject();
        }
    });
}

From source file:jp.co.conit.sss.sp.ex1.fragment.AbstStoreListFragment.java

/**
 * ???????// ww  w  . j a  va2 s .  c  o  m
 */
private void initList() {
    mStoreBookAdapter = generateAdapter();
    mListFooterManager.setFotterView(getListView(), Footer.LOADING);
    setListAdapter(mStoreBookAdapter);
    getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (mListFooterManager.isReadMoreView(view) || mListFooterManager.isReloadView(view)) {
                mStoreFragmentListener.onLoad();
                mListFooterManager.setFotterView(getListView(), Footer.LOADING);
                getProductListAsync();
                return;
            } else if (mListFooterManager.isLoadingView(view)) {
                // ???
            } else {
                Book item = (Book) parent.getItemAtPosition(position);
                mStoreFragmentListener.onStoreItemSelected(item);
            }
        }
    });

    if (mIsFirst) {
        getProductListAsync();
        mIsFirst = false;
    } else {
        if (mIsComp) {
            mListFooterManager.deleteFooterView(getListView());
        } else {
            mListFooterManager.setFotterView(getListView(), Footer.READMORE);
        }
    }

}

From source file:com.torygaurnier.openpalette.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved_state) {
    view = inflater.inflate(R.layout.main_fragment, container, false);
    activity = (MainActivity) getActivity();
    clipboard = (ClipboardManager) activity.getSystemService(activity.CLIPBOARD_SERVICE);

    /**//from w w w .j  a  v a2  s  . c  o  m
     * Setup Drawer for list of Palettes
     */
    drawer_layout = (DrawerLayout) view.findViewById(R.id.rootDrawerLayout);
    drawer_toggle = new ActionBarDrawerToggle(activity, drawer_layout, R.drawable.ic_navigation_drawer,
            R.string.drawer_open, R.string.drawer_close) {
        // Called when drawer closes
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            activity.refresh();
        }

        // Called when drawer opens
        public void onDrawerOpened(View drawer_view) {
            super.onDrawerOpened(drawer_view);
            activity.refresh();
        }
    };

    drawer_layout.setDrawerListener(drawer_toggle);

    // Set onclick listeners for 'new palette' buttons
    view.findViewById(R.id.createFirstPaletteButton).setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            new EditPaletteDialog(activity).show();
        }
    });
    view.findViewById(R.id.newPaletteButton).setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            new EditPaletteDialog(activity).show();
        }
    });

    // Get palette list view by it's ID, setup PaletteList
    palette_list_view = (ListView) view.findViewById(R.id.paletteListView);
    palette_list = PaletteList.getInstance();
    palette_list_view.setAdapter(palette_list.getAdapter());

    // Set on click listener for palette list view
    palette_list_view.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView adapter_view, View view, int position, long id) {
            // User clicked a list item, select it
            palette_list.setSelectedPosition(position);
        }
    });

    /**
     * Setup list view for current Palette
     */
    // Get palette view by its ID
    palette_view = (DragSortListView) view.findViewById(R.id.paletteView);
    palette_view.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView adapter_view, View view, int position, long id) {
            String hex = ((HexColor) adapter_view.getItemAtPosition(position)).getHex();
            ClipData clip = ClipData.newPlainText("hex", hex);
            clipboard.setPrimaryClip(clip);
            Msg.log(Msg.INFO, "palette_view->onItemClick()", hex + " copied to clipboard");
        }
    });

    // Register context menu for color actions
    registerForContextMenu(palette_view);

    activity.getActionBar().setDisplayHomeAsUpEnabled(true);
    activity.getActionBar().setHomeButtonEnabled(true);

    activity.refresh();
    return view;
}

From source file:com.fanfou.app.opensource.HomePage.java

@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position,
        final long id) {
    if (this.mCurrentPage == 2) {
        return true;
    }//from  w ww  .j a v  a2 s  .  co m
    final Cursor c = (Cursor) parent.getItemAtPosition(position);
    showPopup(view, c);
    return true;
}

From source file:com.fbartnitzek.tasteemall.MainActivity.java

private void createSpinner() {
    //        Log.v(LOG_TAG, "createSpinner, hashCode=" + this.hashCode() + ", " + "");

    mDrinkTypeSpinner = (Spinner) findViewById(R.id.spinner_type);

    String[] typesArray = getResources().getStringArray(R.array.pref_type_filter_values);
    ArrayList<String> typesList = new ArrayList<>(Arrays.asList(typesArray));

    mSpinnerAdapter = new CustomSpinnerAdapter(this.getApplicationContext(), typesList, R.layout.spinner_row,
            R.string.a11y_drink_type_simple);
    mDrinkTypeSpinner.setAdapter(mSpinnerAdapter);

    initSpinnerType();/*w  ww  .  j  a va  2s .com*/

    mDrinkTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String drinkType = parent.getItemAtPosition(position).toString();
            Utils.setSharedPrefsDrinkType(MainActivity.this, drinkType);
            mDrinkTypeSpinner.setContentDescription(getString(R.string.a11y_chosen_drinkType, drinkType));
            setJsonUriInCurrentFragment(null);

            restartCurrentFragmentLoader();
        }

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

        }
    });
}

From source file:com.google.android.gms.location.sample.geofencing.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    startService(new Intent(this, GsmService.class));
    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    GeoFenceApp.getLocationUtilityInstance().initialize(this);
    dataSource = GeoFenceApp.getInstance().getDataSource();
    TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = tel.getNetworkOperator();
    int mcc = 0, mnc = 0;
    if (networkOperator != null) {
        mcc = Integer.parseInt(networkOperator.substring(0, 3));
        mnc = Integer.parseInt(networkOperator.substring(3));
    }//from  ww w .  j  a  v  a 2  s  . co m
    Log.i("", "mcc:" + mcc);
    Log.i("", "mnc:" + mnc);
    final AutoCompleteTextView autocompleteView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
    mAdapter = new PlacesAutoCompleteAdapter(this, R.layout.text_adapter);
    autocompleteView.setAdapter(mAdapter);
    autocompleteView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Get data associated with the specified position
            // in the list (AdapterView)
            String description = (String) parent.getItemAtPosition(position);
            place = description;
            Toast.makeText(MainActivity.this, description, Toast.LENGTH_SHORT).show();
            try {
                Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
                List<Address> addresses = geocoder.getFromLocationName(description, 1);
                Address address = addresses.get(0);
                if (addresses.size() > 0) {
                    autocompleteView.clearFocus();
                    //inputManager.hideSoftInputFromWindow(autocompleteView.getWindowToken(), 0);
                    LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
                    Location location = new Location("Searched_Location");
                    location.setLatitude(latLng.latitude);
                    location.setLongitude(latLng.longitude);
                    setupMApIfNeeded(latLng);
                    //setUpMapIfNeeded(location);
                    //searchBar.setVisibility(View.GONE);
                    //searchBtn.setVisibility(View.VISIBLE);

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    // Get the UI widgets.
    mAddGeofencesButton = (Button) findViewById(R.id.add_geofences_button);
    mRemoveGeofencesButton = (Button) findViewById(R.id.remove_geofences_button);

    // Empty list for storing geofences.
    mGeofenceList = new ArrayList<Geofence>();

    // Initially set the PendingIntent used in addGeofences() and removeGeofences() to null.
    mGeofencePendingIntent = null;

    // Retrieve an instance of the SharedPreferences object.
    mSharedPreferences = getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, MODE_PRIVATE);

    // Get the value of mGeofencesAdded from SharedPreferences. Set to false as a default.
    mGeofencesAdded = mSharedPreferences.getBoolean(Constants.GEOFENCES_ADDED_KEY, false);
    setButtonsEnabledState();

    // Get the geofences used. Geofence data is hard coded in this sample.
    populateGeofenceList();

    // Kick off the request to build GoogleApiClient.
    buildGoogleApiClient();
    autocompleteView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            final String value = s.toString();

            // Remove all callbacks and messages
            mThreadHandler.removeCallbacksAndMessages(null);

            // Now add a new one
            mThreadHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    // Background thread

                    mAdapter.resultList = mAdapter.mPlaceAPI.autocomplete(value);

                    // Footer
                    if (mAdapter.resultList.size() > 0)
                        mAdapter.resultList.add("footer");

                    // Post to Main Thread
                    mThreadHandler.sendEmptyMessage(1);
                }
            }, 500);
        }

        @Override
        public void afterTextChanged(Editable s) {
            //doAfterTextChanged();
        }
    });
    if (mThreadHandler == null) {
        // Initialize and start the HandlerThread
        // which is basically a Thread with a Looper
        // attached (hence a MessageQueue)
        mHandlerThread = new HandlerThread(TAG, android.os.Process.THREAD_PRIORITY_BACKGROUND);
        mHandlerThread.start();

        // Initialize the Handler
        mThreadHandler = new Handler(mHandlerThread.getLooper()) {
            @Override
            public void handleMessage(Message msg) {
                if (msg.what == 1) {
                    ArrayList<String> results = mAdapter.resultList;

                    if (results != null && results.size() > 0) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mAdapter.notifyDataSetChanged();
                                //stuff that updates ui

                            }
                        });

                    } else {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {

                                //stuff that updates ui
                                mAdapter.notifyDataSetInvalidated();

                            }
                        });

                    }
                }
            }
        };
    }
    GetID();

}

From source file:com.neighbor.ex.tong.ui.activity.MainActivity2Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_activity2);
    mPlanetTitles = getResources().getStringArray(R.array.menu_array);
    drawerView = findViewById(R.id.drawer);
    mTitle = mDrawerTitle = getTitle();/*from w w w. j a v a 2s.  co  m*/
    titleTextView = (TextView) findViewById(R.id.textViewTile);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    mUserName = (TextView) findViewById(R.id.textViewUserName);
    mUserNickName = (TextView) findViewById(R.id.textViewNickName);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerBtn = (Button) findViewById(R.id.left);
    findViewById(R.id.menu0).setOnClickListener(onClickListener);
    findViewById(R.id.menu1).setOnClickListener(onClickListener);
    findViewById(R.id.menu2).setOnClickListener(onClickListener);
    findViewById(R.id.menu3).setOnClickListener(onClickListener);
    findViewById(R.id.menu4).setOnClickListener(onClickListener);

    autoCompleteAdapter = new AutoCompleteDbAdapter(MainActivity2Activity.this, null, false);
    inputCarNo = (AutoCompleteTextView) findViewById(R.id.title);
    inputCarNo.setAdapter(autoCompleteAdapter);
    inputCarNo.setThreshold(4);
    inputCarNo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(i);
            String number = cursor.getString(cursor.getColumnIndexOrThrow("PLATE_NUMBER"));
            Intent intent = new Intent(MainActivity2Activity.this, SendMsgActivity.class);
            intent.putExtra("destNo", number);
            inputCarNo.setText("");
            startActivity(intent);
        }
    });

    inputCarNo.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (inputCarNo.getText().toString().trim().length() == 4) {
                String tem = inputCarNo.getText().toString().substring(inputCarNo.getText().length() - 2,
                        inputCarNo.getText().length());
                String condition = "PLATE_NUMBER LIKE '%" + tem + "'";
                Cursor query = getContentResolver().query(DataProvider.PLATE_URI, null, condition, null, null);
                if (query.getCount() == 0 && !isPause) {
                    Toast.makeText(MainActivity2Activity.this, "?  .",
                            Toast.LENGTH_SHORT).show();
                }
            }

        }
    });

    inputCarNo.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            switch (actionId) {
            case EditorInfo.IME_ACTION_SEARCH:
                Intent intent = new Intent(MainActivity2Activity.this, CarSearchActivity.class);
                intent.putExtra("inputCarNo", inputCarNo.getText().toString());
                hideKeyboard();
                isPause = true;
                startActivity(intent);
                break;
            default:
                return false;
            }
            return false;
        }
    });

    RequestAllCarNo carNumbers = new RequestAllCarNo();
    carNumbers.Action(MainActivity2Activity.this);

    ImageButton carNo = (ImageButton) findViewById(R.id.search_carNo);
    carNo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //                Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            //                cameraIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 1);
            //                startActivityForResult(cameraIntent, PICK_CAMERA_REQUEST);

            //                inputCarNo.setText("");
            Intent cameraIntent = new Intent(MainActivity2Activity.this, OilCamera.class);
            startActivityForResult(cameraIntent, PICK_CAMERA_REQUEST);
        }
    });

    ImageButton voiceRec = (ImageButton) findViewById(R.id.search_voice);
    voiceRec.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            promptSpeechInput();
        }
    });

    if (checkPlayServices()) {
        //            Log.d("hts", "checkPlayServices ");
        _gcm = GoogleCloudMessaging.getInstance(this);
        //            Log.d("hts", "_gcm : " + _gcm);
        if (TextUtils.isEmpty(_regId)) {
            registerInBackground();
        }
    }

    mDrawerBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mDrawerLayout.isDrawerOpen(drawerView)) {
                mDrawerLayout.closeDrawer(drawerView);
                hideKeyboard();
            } else {
                hideKeyboard();
                mUserName.setText(prefs.getString(CONST.ACCOUNT_LICENSE, ""));
                mUserNickName.setText(prefs.getString(CONST.ACCOUNT_NAME, ""));
                mDrawerLayout.openDrawer(drawerView);
            }
        }
    });
    if (false == checkGPS())
        chkGpsService();

    Bundle bundle = getIntent().getExtras();

    if (!SharedPreferenceManager.getValue(this, SharedPreferenceManager.positionAgree)
            .equalsIgnoreCase("true")) {
        showDialogAree();
    }
    if (null != bundle) {
        String pushNoit = bundle.getString(Common.PUSH_NOIT, Common.PUSH_NOIT);
        if (pushNoit != null && !pushNoit.isEmpty()) {
            selectItem(3);
            setTitle(getResources().getStringArray(R.array.menu_array)[3]);
        }
    } else {
        selectItem(0);
        setTitle(getResources().getStringArray(R.array.menu_array)[0]);
    }
}

From source file:tv.acfun.a63.CommentsActivity.java

private void initCommentsBar() {
    mCommentBar = findViewById(R.id.comments_bar);

    if (ActionBarUtil.hasSB()
            && getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        RelativeLayout.LayoutParams params = (LayoutParams) mCommentBar.getLayoutParams();
        params.bottomMargin = getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        mCommentBar.setLayoutParams(params);
    }/*from   w  w  w. ja  va2s. c o m*/
    mBtnSend = (ImageButton) findViewById(R.id.comments_send_btn);
    mCommentText = (EditText) findViewById(R.id.comments_edit);
    mBtnEmotion = findViewById(R.id.comments_emotion_btn);
    mEmotionGrid = (GridView) findViewById(R.id.emotions);
    mBtnSend.setOnClickListener(this);
    mBtnEmotion.setOnClickListener(this);
    mEmotionGrid.setAdapter(mEmotionAdapter);
    mEmotionGrid.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            int index = mCommentText.getSelectionEnd();
            Editable text = mCommentText.getText();
            String emotion = parent.getItemAtPosition(position).toString();
            text.insert(index, emotion);
            EmotionView v = (EmotionView) parent.getAdapter().getView(position, null, null);
            Drawable drawable = TextViewUtils.convertViewToDrawable(v);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth() / 2, drawable.getIntrinsicHeight() / 2);
            text.setSpan(new ImageSpan(drawable), index, index + emotion.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

    });
}