Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

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

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:mn.today.TheHubActivity.java

/**
 * Generates a Popup Menu with Two Actions Edit and Delete.
 *
 * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to
 * delete from file//from   w w w  . j  av a  2  s  . co m
 *
 * Editing launches a renaming process
 *
 * @param longClickedFlow Flow represented by cardview longclicked
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @return
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private boolean showLongClickPopUpMenu(final ToDay longClickedFlow, final int cardPosition,
        final View cardViewClicked) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border

    popup.setBackgroundDrawable(new ColorDrawable());
    popup.setFocusable(true);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item);

    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Deletes current Flow from file and UI */
            rvContent.remove(cardPosition);
            manager.delete(longClickedFlow.getUuid());
            adapter.notifyItemRemoved(cardPosition);
            adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount());

            popup.dismiss();

            Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG)
                    .setAction("!!!", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            rvContent.add(cardPosition, longClickedFlow);
                            manager.save(longClickedFlow.getUuid(), longClickedFlow);
                            adapter.notifyItemInserted(cardPosition);
                        }
                    });

            bar.show();
        }
    });

    ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item);

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popup.dismiss();
            renameFlow(cardPosition, cardViewClicked);

        }
    });

    // Displaying the popup at the specified location, + offsets.
    popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP);
    longClickPopup = popup;
    return true;
}

From source file:com.brandao.tictactoe.board.BoardFragment.java

@Override
public void onViewCreated(View v, @Nullable Bundle savedInstanceState) {
    for (ImageView screen : mScreens) {
        screen.setOnClickListener(this);
    }/*from w w  w .  ja va2 s  .  co  m*/

    setTheme(v);

    restoreGameState(v);
}

From source file:mn.today.TheHubActivity.java

/**
 * Displays a popup window prompting the user to
 *
 * Confirm the changes to the name, saving the new name to file and updating the UI.
 *
 * Cancel the changes, returning the user back to the original state before editing
 *
 * @param newName new name to be used/* w w  w.j  a  v a  2  s .  c  om*/
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @param switcher the viewSwitcher object used to rename
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void showEditPopupWindow(final EditText newName, View cardViewClicked, final ViewSwitcher switcher,
        final int cardPosition) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_editing, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_editing);

    // Creating the PopupWindow
    final PopupWindow popupEditing = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border from appearing outside popupwindow
    popupEditing.setBackgroundDrawable(new ColorDrawable());
    popupEditing.setFocusable(false);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView confirmEdit = (ImageView) layout.findViewById(R.id.popup_confirm_item_changes);

    confirmEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ToDay toChange = rvContent.get(cardPosition);
            if (newName.getText().toString().equals("")) {
                // Need to optimize this so that the dialog does NOT disappear and just display toast
                Toast.makeText(TheHubActivity.this, "??  !", Toast.LENGTH_LONG).show();
            } else {
                toChange.setName(newName.getText().toString());
                manager.overwrite(toChange.getUuid(), toChange);
                adapter.notifyDataSetChanged();
                switcher.showNext();
                menuState = AppConstants.MENU_ITEMS_NATIVE;
                invalidateOptionsMenu();
                popupEditing.dismiss();
                newName.clearFocus();
            }

        }
    });

    ImageView cancelEdit = (ImageView) layout.findViewById(R.id.popup_cancel_item_changes);

    cancelEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switcher.showNext();
            menuState = AppConstants.MENU_ITEMS_NATIVE;
            invalidateOptionsMenu();
            popupEditing.dismiss();
        }
    });

    // Displaying the popup at the specified location, + offsets.
    popupEditing.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight,
            Gravity.TOP);
    editingPopup = popupEditing;
}

From source file:fm.krui.kruifm.StreamFragment.java

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

    // Instantiate class members
    prefManager = new PreferenceManager(getActivity());
    favTrackManager = new FavoriteTrackManager(getActivity());

    // FIXME: Move these to PreferenceManager after expanding its scope for cleaner code
    trackPrefs = getActivity().getSharedPreferences(StreamService.PREFS_NAME, 0);

    // Instantiate broadcast receiver
    broadcastReceiver = new BroadcastReceiver() {
        @Override//w  w  w  .j  a va 2s .  c o m
        public void onReceive(Context context, Intent intent) {
            processBroadcastCommand(intent);
        }
    };

    // Determine the URL we need to use to stream based on the station tag and quality preferences
    streamUrl = getStreamUrl(stationTag);
    Log.v(TAG, "streamUrl is now set to: " + streamUrl);

    // Perform initial configuration of audio server
    changeUrl(stationTag);

    // Begin buffering the audio
    startAudio((ImageView) getActivity().findViewById(R.id.play_audio_imageview));

    // Build play button listener
    final ImageView playButton = (ImageView) getActivity().findViewById(R.id.play_audio_imageview);
    playButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleAudio(playButton);
        }
    });

    // Build volume seek bar listener
    // ** DISABLED FOR NOW -- This might be completely thrown out. **
    /*final SeekBar volumeSeekBar = (SeekBar)getActivity().findViewById(R.id.volume_seekbar);
    volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            
    // When seek bar progress is changed, change the audio of the media player appropriately.
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        // Send new volume via intent? Will this be slow?
    }
            
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }
            
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    }
    }); */

    // Build settings button listener and apply it to settings icon and submit button
    View.OnClickListener flipListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Card flip animation which toggles between stream controls and settings views
            flipCard();
        }
    };

    final ImageView settingsButton = (ImageView) getActivity().findViewById(R.id.stream_settings_imageview);
    final Button saveSettingsButton = (Button) getActivity().findViewById(R.id.set_stream_settings_button);
    settingsButton.setOnClickListener(flipListener);
    saveSettingsButton.setOnClickListener(flipListener);

    // Build favorite button listener
    final ImageView favoriteButton = (ImageView) getActivity().findViewById(R.id.stream_favorite_imageview);
    favoriteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (trackIsFavorite) {
                favoriteButton.setImageResource(R.drawable.star_unfilled_white);
                trackIsFavorite = false;
                removeTrackFromFavorites();
            } else {
                favoriteButton.setImageResource(R.drawable.star_filled_white);
                trackIsFavorite = true;
                addTrackToFavorites();
            }
        }
    });

    // Build settings switches
    final Switch streamQualitySwitch = (Switch) getActivity().findViewById(R.id.stream_quality_switch);
    final Switch albumArtSwitch = (Switch) getActivity().findViewById(R.id.stream_album_art_switch);

    // Set initial state of switches
    albumArtSwitch.setChecked(prefManager.getAlbumArtDownloadPreference());
    if (prefManager.getStreamQuality() == prefManager.HIGH_QUALITY) {
        streamQualitySwitch.setChecked(true);
    } else {
        streamQualitySwitch.setChecked(false);
    }

    // Assign listeners to switches
    streamQualitySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                prefManager.setStreamQuality(prefManager.HIGH_QUALITY);
                Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality());
            } else {
                prefManager.setStreamQuality(prefManager.LOW_QUALITY);
                Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality());
            }
            changeUrl(stationSpinnerPosition);
        }
    });

    albumArtSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                prefManager.setAlbumArtDownloadPreference(true);
                Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference());
            } else {
                prefManager.setAlbumArtDownloadPreference(false);
                Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference());
            }
        }
    });

}

From source file:br.com.frs.foodrestrictions.FoodIconConfig.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_restriction_settings, container, false);

    foodSettings = MainActivity.getFoodSettings();
    if (foodSettings != null) {

        cbDontEatCow = (CheckBox) v.findViewById(R.id.cbDontEatCow);
        cbDontEatCow.setOnClickListener(this);
        cbAllergicCow = (CheckBox) v.findViewById(R.id.cbAllergicCow);
        cbAllergicCow.setOnClickListener(this);

        cbDontEatChicken = (CheckBox) v.findViewById(R.id.cbDontEatChicken);
        cbDontEatChicken.setOnClickListener(this);
        cbAllergicChicken = (CheckBox) v.findViewById(R.id.cbAllergicChicken);
        cbAllergicChicken.setOnClickListener(this);

        cbDontEatPork = (CheckBox) v.findViewById(R.id.cbDontEatPork);
        cbDontEatPork.setOnClickListener(this);
        cbAllergicPork = (CheckBox) v.findViewById(R.id.cbAllergicPork);
        cbAllergicPork.setOnClickListener(this);

        cbDontEatFish = (CheckBox) v.findViewById(R.id.cbDontEatFish);
        cbDontEatFish.setOnClickListener(this);
        cbAllergicFish = (CheckBox) v.findViewById(R.id.cbAllergicFish);
        cbAllergicFish.setOnClickListener(this);

        cbDontEatCheese = (CheckBox) v.findViewById(R.id.cbDontEatCheese);
        cbDontEatCheese.setOnClickListener(this);
        cbAllergicCheese = (CheckBox) v.findViewById(R.id.cbAllergicCheese);
        cbAllergicCheese.setOnClickListener(this);

        cbDontEatMilk = (CheckBox) v.findViewById(R.id.cbDontEatMilk);
        cbDontEatMilk.setOnClickListener(this);
        cbAllergicMilk = (CheckBox) v.findViewById(R.id.cbAllergicMilk);
        cbAllergicMilk.setOnClickListener(this);

        cbDontEatPepper = (CheckBox) v.findViewById(R.id.cbDontEatPepper);
        cbDontEatPepper.setOnClickListener(this);
        cbAllergicPepper = (CheckBox) v.findViewById(R.id.cbAllergicPepper);
        cbAllergicPepper.setOnClickListener(this);

        cbDontEatCow.setChecked(foodSettings.isDontEatCow());
        cbDontEatCow.setOnClickListener(this);
        cbAllergicCow.setChecked(foodSettings.isAllergicCow());
        cbAllergicCow.setOnClickListener(this);

        cbDontEatChicken.setChecked(foodSettings.isDontEatChicken());
        cbDontEatChicken.setOnClickListener(this);
        cbAllergicChicken.setChecked(foodSettings.isAllergicChicken());
        cbAllergicChicken.setOnClickListener(this);

        cbDontEatPork.setChecked(foodSettings.isDontEatPork());
        cbDontEatPork.setOnClickListener(this);
        cbAllergicPork.setChecked(foodSettings.isAllergicPork());
        cbAllergicPork.setOnClickListener(this);

        cbDontEatFish.setChecked(foodSettings.isDontEatFish());
        cbDontEatFish.setOnClickListener(this);
        cbAllergicFish.setChecked(foodSettings.isAllergicFish());
        cbAllergicFish.setOnClickListener(this);

        cbDontEatCheese.setChecked(foodSettings.isDontEatCheese());
        cbDontEatCheese.setOnClickListener(this);
        cbAllergicCheese.setChecked(foodSettings.isAllergicCheese());
        cbAllergicCheese.setOnClickListener(this);

        cbDontEatMilk.setChecked(foodSettings.isDontEatMilk());
        cbDontEatMilk.setOnClickListener(this);
        cbAllergicMilk.setChecked(foodSettings.isAllergicMilk());
        cbAllergicMilk.setOnClickListener(this);

        cbDontEatPepper.setChecked(foodSettings.isDontEatPepper());
        cbDontEatPepper.setOnClickListener(this);
        cbAllergicPepper.setChecked(foodSettings.isAllergicPepper());
        cbAllergicPepper.setOnClickListener(this);

        View.OnClickListener imageOnClickListener = new View.OnClickListener() {
            @Override//from  w  w  w  .  jav a2  s  .  c  om
            public void onClick(View v) {
                String name = "";
                switch (v.getId()) {
                case R.id.ivCow:
                    name = getResources().getString(R.string.cow);
                    break;
                case R.id.ivChicken:
                    name = getResources().getString(R.string.chicken);
                    break;
                case R.id.ivPork:
                    name = getResources().getString(R.string.pork);
                    break;
                case R.id.ivFish:
                    name = getResources().getString(R.string.fish);
                    break;
                case R.id.ivCheese:
                    name = getResources().getString(R.string.cheese);
                    break;
                case R.id.ivMilk:
                    name = getResources().getString(R.string.milk);
                    break;
                case R.id.ivPepper:
                    name = getResources().getString(R.string.pepper);
                    break;
                }

                Snackbar.make(v, name, Snackbar.LENGTH_LONG).setAction("Action", null).show();

            }
        };

        ImageView ivCow = (ImageView) v.findViewById(R.id.ivCow);
        ImageView ivChicken = (ImageView) v.findViewById(R.id.ivChicken);
        ImageView ivPork = (ImageView) v.findViewById(R.id.ivPork);
        ImageView ivFish = (ImageView) v.findViewById(R.id.ivFish);
        ImageView ivCheese = (ImageView) v.findViewById(R.id.ivCheese);
        ImageView ivMilk = (ImageView) v.findViewById(R.id.ivMilk);
        ImageView ivPepper = (ImageView) v.findViewById(R.id.ivPepper);

        ivCow.setOnClickListener(imageOnClickListener);
        ivChicken.setOnClickListener(imageOnClickListener);
        ivPork.setOnClickListener(imageOnClickListener);
        ivFish.setOnClickListener(imageOnClickListener);
        ivCheese.setOnClickListener(imageOnClickListener);
        ivMilk.setOnClickListener(imageOnClickListener);
        ivPepper.setOnClickListener(imageOnClickListener);

    }
    return v;
}

From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java

/**
 * Initializes the UI and creates the detector pipeline.
 *//*from  ww  w . j  a  v a 2s .c  om*/
//    @Override
//    public void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//
//        if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
//            Toast.makeText(getContext(), "pic saved", Toast.LENGTH_LONG).show();
//            Log.d("CameraDemo", "Pic saved");
//        }
//    }

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View view = inflater.inflate(R.layout.view_ocr_capture, container, false);
    final Activity activity = getActivity();
    final Context context = getContext();

    ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger))
            .setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent));
    final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
            + "/picFolder/";
    File newdir = new File(dir);
    newdir.mkdirs();

    mPreview = (CameraSourcePreview) view.findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) view.findViewById(R.id.graphicOverlay);

    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());

    // Set good defaults for capturing text.
    boolean autoFocus = true;
    boolean useFlash = false;

    //        createNewThread();
    //        t.start();

    final ImageView upArrow = (ImageView) view.findViewById(R.id.arrow_up);
    upArrow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (rotationAngle == 0) { // arrow up
                //mCameraSource.takePicture(null, mPicture);
                //mGraphicOverlay.clear();
                //                    mGraphicOverlay.clear();
                //                    mGraphicOverlay.amountItem = null;
                onPause();
                //shouldContinue = false;
                //mCamera.takePicture(null, null, mPicture);

                File pictureFile = getOutputMediaFile();
                if (pictureFile == null) {
                    return;
                }
                try {
                    FileOutputStream fos = new FileOutputStream(pictureFile);
                    Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap);
                    receiptBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
                    picPath = pictureFile.getAbsolutePath();
                    //fos.write(mCameraSource.mostRecentBitmap);
                    fos.close();
                } catch (FileNotFoundException e) {

                } catch (IOException e) {
                }

                upArrow.animate().rotation(180).setDuration(500).start();

                TextView amount = (TextView) view.findViewById(R.id.text_amount_value);
                if (mGraphicOverlay.amountItem == null) {
                    amount.setText("0.00");
                } else {
                    amount.setText(String.format("%.2f", mGraphicOverlay.amountItemAfterFormat));
                }
                TextView desc = (TextView) view.findViewById(R.id.text_name_value);
                desc.setText(mGraphicOverlay.description);

                RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box);
                box.setVisibility(View.VISIBLE);
                Animation slide_up = AnimationUtils.loadAnimation(activity.getApplicationContext(),
                        R.anim.slide_up);

                box.startAnimation(slide_up);
                rotationAngle = 180;

            } else {
                //                    t.interrupt();
                //                    t = null;
                RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box);
                Animation slide_down = AnimationUtils.loadAnimation(activity.getApplicationContext(),
                        R.anim.slide_down);

                upArrow.animate().rotation(0).setDuration(500).start();

                box.startAnimation(slide_down);
                box.setVisibility(View.INVISIBLE);
                //shouldContinue = true;
                mGraphicOverlay.amountItem = null;
                mGraphicOverlay.amountItemAfterFormat = 0f;
                mGraphicOverlay.description = "";
                onResume();
                //                    createNewThread();
                //                    t.start();
                rotationAngle = 0;
            }
        }
    });

    ImageView addButton = (ImageView) view.findViewById(R.id.add_icon);
    addButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // takePicture();
            EditText description = (EditText) view.findViewById(R.id.text_name_value);
            EditText amount = (EditText) view.findViewById(R.id.text_amount_value);
            float floatAmount = Float.parseFloat(amount.getText().toString());
            Summary t = new Summary(description.getText().toString(), floatAmount);

            Bundle bundle = new Bundle();
            bundle.putSerializable("splitTransaction", t);

            //                 ByteArrayOutputStream stream = new ByteArrayOutputStream();
            //                 mCameraSource.mostRecentBitmap.compress(Bitmap.CompressFormat.PNG, 80, stream);
            //                 byte[] byteArray = stream.toByteArray();
            //Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap);
            //bundle.putParcelable("receiptPicture",receiptBitmap);
            bundle.putString("receiptPicture", picPath);

            FriendsSelectionFragment fragment = new FriendsSelectionFragment();
            fragment.setArguments(bundle);

            ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)).setVisibility(View.INVISIBLE);
            getActivity().getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragment_holder, fragment, "FriendsSelectionFragment").addToBackStack(null)
                    .commit();
        }
    });

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(context, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener());

    //        Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom",
    //                Snackbar.LENGTH_LONG)
    //                .show();

    // Set up the Text To Speech engine.
    TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(final int status) {
            if (status == TextToSpeech.SUCCESS) {
                Log.d("OnInitListener", "Text to speech engine started successfully.");
                tts.setLanguage(Locale.US);
            } else {
                Log.d("OnInitListener", "Error starting the text to speech engine.");
            }
        }
    };
    tts = new TextToSpeech(activity.getApplicationContext(), listener);

    return view;
}

From source file:com.app.khclub.base.easeim.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/* w w w.  ja v  a 2 s .  c  o m*/
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);

    // ???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();

    // ?
    query = (EditText) getView().findViewById(R.id.query);
    query.setHint(R.string.search);
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);

            }
        }

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

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();
            hideSoftKeyboard();
        }
    });

    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = ((KHHXSDKHelper) HXSDKHelper.getInstance()).getContactList()
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else if (Constant.CHAT_ROOM.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class));
            } else if (Constant.CHAT_ROBOT.equals(username)) {
                // // Robot?
                // startActivity(new Intent(getActivity(),
                // RobotsActivity.class));
                // ???
                Intent intentToCardList = new Intent(getActivity(), CollectCardActivity.class);
                startActivity(intentToCardList);
                // ?
                getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
            } else {
                // demo??
                // startActivity(new Intent(getActivity(),
                // ChatActivity.class)
                // .putExtra("userId", adapter.getItem(position)
                // .getUsername()));
                // ?
                Intent intent = new Intent(getActivity(), OtherPersonalActivity.class);
                intent.putExtra(OtherPersonalActivity.INTENT_KEY,
                        KHUtils.stringToInt(adapter.getItem(position).getUsername().replace(KHConst.KH, "")));
                startActivity(intent);
                getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    // ?
    qrImageView = new QRCodePopupMenu(getActivity());
    final ImageView operateMenuView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ???
    operateMenuView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (null == mainMenu) {
                mainMenu = new MainPopupMenu(getActivity());
                mainMenu.setListener(new ClickListener() {

                    @Override
                    public void scanQRcodeClick() {
                        // ???
                        Intent intent = new Intent();
                        intent.setClass(getActivity(), MipcaCaptureActivity.class);
                        startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
                    }

                    @Override
                    public void searchClick() {
                        // ??
                        Intent intentToSearch = new Intent(getActivity(), SearchActivity.class);
                        startActivity(intentToSearch);
                        // ?
                        getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
                    }

                    @Override
                    public void createGroupClick() {
                        // ?
                        startActivity(new Intent(getActivity(), NewGroupActivity.class));
                        getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
                    }

                    @Override
                    public void userQRShowClick() {
                        // TODO ?
                        qrImageView.setQRcode(false);
                        qrImageView.showPopupWindow((RelativeLayout) getView().findViewById(R.id.title_bar));
                    }
                });
            }
            mainMenu.showPopupWindow(operateMenuView);
            // startActivity(new Intent(getActivity(),
            // AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

    progressBar = (View) getView().findViewById(R.id.progress_bar);

    contactSyncListener = new HXContactSyncListener();
    HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener);

    blackListSyncListener = new HXBlackListSyncListener();
    HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener);

    contactInfoSyncListener = new HXContactInfoSyncListener();
    ((KHHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager()
            .addSyncContactInfoListener(contactInfoSyncListener);

    if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}

From source file:br.org.funcate.dynamicforms.views.GPictureView.java

private ImageView getImageView(final Context context, Bitmap photo, String uuid) {
    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(thumbnailWidth, thumbnailHeight));
    imageView.setPadding(5, 5, 5, 5);/*from w w w  .j ava 2 s  .  c om*/
    imageView.setImageBitmap(photo);
    imageView.setBackgroundDrawable(getResources().getDrawable(R.drawable.border_black_1px));
    imageView.setTag(uuid);
    imageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String photoId = (String) v.getTag();

            FragmentActivity activity = mFragmentDetail.getActivity();
            Intent intent = new Intent(activity, PictureActivity.class);

            if (addedIdsToImageViews.containsKey(photoId)) {// pictures on session
                intent.putExtra(FormUtilities.PICTURE_PATH_VIEW, addedIdsToImageViews.get(photoId));
            } else if (_pictures.containsKey(photoId)) {// pictures from database

                Map<String, String> imagePaths = _pictures.get(photoId);
                String imagePath = imagePaths.get("display");

                intent.putExtra(FormUtilities.PICTURE_DB_VIEW, imagePath);// Image temporary path
            }
            if (intent.hasExtra(FormUtilities.PICTURE_PATH_VIEW)
                    || intent.hasExtra(FormUtilities.PICTURE_DB_VIEW)) {
                intent.putExtra(FormUtilities.PICTURE_BITMAP_ID, photoId);
                activity.startActivityForResult(intent, PICTURE_VIEW_RESULT);
            } else
                Toast.makeText(getContext(), "Fail, the picture not found.", Toast.LENGTH_LONG).show();

            /*
            JSONArray form = null;
            try {
            form = mFragmentDetail.getSelectedForm();
            } catch (JSONException jse) {
            jse.printStackTrace();
            Toast.makeText(getContext(), jse.getMessage(), Toast.LENGTH_LONG).show();
            }
                    
            if (form != null) {
            try {
                String json = encodeToJson();
                FormUtilities.updatePicture(form, json);
            } catch (JSONException e) {
                e.printStackTrace();
            }catch (Exception e) {
                e.printStackTrace();
            }
            }
            try {
            refresh(getContext());
            } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }*/
            /**
             * open in markers to edit it
             */
            // MarkersUtilities.launchOnImage(context, image);
            /* try {
                 Intent intent = new Intent();
                 intent.setAction(Intent.ACTION_VIEW);
                 Image image = imagesDbHelper.getImage(imageIdLong);
                 File tempDir = ResourcesManager.getInstance(context).getTempDir();
                 String ext = ".jpg";
                 if (image.getName().endsWith(".png"))
                     ext = ".png";
                 File imageFile = new File(tempDir, ImageUtilities.getTempImageName(ext));
                 byte[] imageData = imagesDbHelper.getImageData(image.getId());
                 ImageUtilities.writeImageDataToFile(imageData, imageFile.getAbsolutePath());
                    
                 intent.setDataAndType(Uri.fromFile(imageFile), "image*//**//*"); //$NON-NLS-1$
                                                                             context.startActivity(intent);
                                                                             } catch (Exception e) {
                                                                             //GPLog.error(this, null, e);
                                                                             Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                                                                             }*/
            //Toast.makeText(getContext(), "Implement this action", Toast.LENGTH_LONG).show();

        }
    });
    return imageView;
}

From source file:com.tomeokin.lspush.biz.home.CollectionListAdapter.java

private void setExplorers(ViewGroup container, @Nullable List<User> explorers) {
    final Context context = container.getContext();
    // // TODO: 2016/10/8 performance improve
    //container.removeAllViews();
    //for (User explorer : explorers) {
    //    final ImageView avatar =
    //        (ImageView) LayoutInflater.from(context).inflate(R.layout.layout_item_explorer, container, false);
    //    ImageLoader.loadAvatar(context, avatar, explorer.getImage());
    //    container.addView(avatar);
    //}//from  w w  w  . ja  v  a 2s.c o m

    final int count = container.getChildCount();
    int targetCount = explorers == null ? 0 : explorers.size();
    targetCount = targetCount >= 5 ? 5 : targetCount;
    final LayoutInflater inflater = LayoutInflater.from(context);
    if (count > targetCount) {
        container.removeViews(targetCount, count - targetCount);
    }
    ImageView avatar;
    for (int i = 0; i < targetCount; i++) {
        if (i > count - 1) { // no cache
            avatar = (ImageView) inflater.inflate(R.layout.layout_item_explorer, container, false);
        } else {
            avatar = (ImageView) container.getChildAt(i);
        }
        ImageLoader.loadAvatar(context, avatar, explorers.get(i).getImage());
        if (avatar.getParent() == null) {
            container.addView(avatar);
        }
        avatar.setTag(R.id.avatar_tag_uid, explorers.get(i).getUid());
        avatar.setOnClickListener(mExplorerListener);
    }
}

From source file:com.slim.ota.SlimOTA.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mDeviceOut = (TextView) getView().findViewById(ID_DEVICE_NAME);
    mCodenameOut = (TextView) getView().findViewById(ID_DEVICE_CODE_NAME);
    mCurVerOut = (TextView) getView().findViewById(ID_CURRENT_VERSION);
    mCurFileOut = (TextView) getView().findViewById(ID_CURRENT_FILE);
    mUpdateFile = (TextView) getView().findViewById(ID_UPDATE_FILE);
    mStatusIcon = (ImageView) getView().findViewById(ID_STATUS_IMAGE);
    final ImageView setButton = (ImageView) getView().findViewById(R.id.btn_setting);
    final ImageView updateButton = (ImageView) getView().findViewById(R.id.btn_update);

    prefs = this.getActivity().getSharedPreferences("UpdateChecker", 0);
    prefs.registerOnSharedPreferenceChangeListener(this);

    if (UpdateChecker.connectivityAvailable(getActivity())) {
        if (Settings.isUpdateEnabled(getView().getContext()))
            doTheUpdateCheck();/* www . j  a  v  a2 s.  c  o  m*/
    } else {
        Toast.makeText(getView().getContext(), R.string.toast_no_data_text, Toast.LENGTH_LONG).show();
    }

    setDeviceInfoContainer();
    addShortCutFragment();

    setInitialUpdateInterval();

    setButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), Settings.class);
            startActivity(intent);
        }
    });

    updateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (UpdateChecker.connectivityAvailable(getActivity())) {
                doTheUpdateCheck();
            }
            setDeviceInfoContainer();
            addShortCutFragment();
        }
    });
}