Search in sources :

Example 56 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project JamsMusicPlayer by psaravan.

the class PlaylistEditorArtistsMultiselectAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Cursor c = (Cursor) getItem(position);
    SongsListViewHolder holder = null;
    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_artists_layout, parent, false);
        holder = new SongsListViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.artistThumbnailMusicLibraryEditor);
        holder.title = (TextView) convertView.findViewById(R.id.artistNameMusicLibraryEditor);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.artistCheckboxMusicLibraryEditor);
        convertView.setTag(holder);
    } else {
        holder = (SongsListViewHolder) convertView.getTag();
    }
    final View finalConvertView = convertView;
    final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID));
    final String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));
    String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));
    holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    //Set the song title.
    holder.title.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image, PlaylistEditorActivity.displayImageOptions);
    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (PlaylistEditorActivity.songDBIdsList.contains(songId)) {
        holder.checkBox.setChecked(true);
        convertView.setBackgroundColor(0xCC0099CC);
    } else {
        holder.checkBox.setChecked(false);
        convertView.setBackgroundColor(0x00000000);
    }
    //Set a tag to the row that will attach the artist's name to it.
    convertView.setTag(R.string.artist, songArtist);
    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {
            if (isChecked == true) {
                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCC0099CC);
                    AsyncGetArtistSongIds task = new AsyncGetArtistSongIds(mContext, songArtist);
                    task.execute(new String[] { "ADD" });
                }
            } else if (isChecked == false) {
                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0x00000000);
                    AsyncGetArtistSongIds task = new AsyncGetArtistSongIds(mContext, songArtist);
                    task.execute(new String[] { "REMOVE" });
                }
            }
        }
    });
    return convertView;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Cursor(android.database.Cursor) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Example 57 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project JamsMusicPlayer by psaravan.

the class CautionEditAlbumsDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    parentActivity = getActivity();
    dialogFragment = this;
    album = this.getArguments().getString("ALBUM");
    artist = this.getArguments().getString("ARTIST");
    callingActivity = this.getArguments().getString("CALLING_FRAGMENT");
    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.fragment_caution_edit_albums, null);
    cautionText = (TextView) rootView.findViewById(R.id.caution_text);
    cautionText.setText(R.string.caution_albums_text);
    cautionText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    cautionText.setPaintFlags(cautionText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    sharedPreferences = getActivity().getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);
    dontShowAgainText = (TextView) rootView.findViewById(R.id.dont_show_again_text);
    dontShowAgainText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    dontShowAgainText.setPaintFlags(dontShowAgainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    dontShowAgainCheckbox = (CheckBox) rootView.findViewById(R.id.dont_show_again_checkbox);
    dontShowAgainCheckbox.setChecked(true);
    sharedPreferences.edit().putBoolean("SHOW_ALBUM_EDIT_CAUTION", false).commit();
    dontShowAgainCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
            if (isChecked == true) {
                sharedPreferences.edit().putBoolean("SHOW_ALBUM_EDIT_CAUTION", false).commit();
            } else {
                sharedPreferences.edit().putBoolean("SHOW_ALBUM_EDIT_CAUTION", true).commit();
            }
        }
    });
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    //Set the dialog title.
    builder.setTitle(R.string.caution);
    builder.setView(rootView);
    builder.setNegativeButton(R.string.no, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();
        }
    });
    builder.setPositiveButton(R.string.yes, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            Bundle bundle = new Bundle();
            bundle.putString("EDIT_TYPE", "ALBUM");
            bundle.putString("ALBUM", album);
            bundle.putString("ARTIST", artist);
            bundle.putString("CALLING_FRAGMENT", callingActivity);
            ID3sAlbumEditorDialog dialog = new ID3sAlbumEditorDialog();
            dialog.setArguments(bundle);
            dialog.show(ft, "id3EditorDialog");
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) Paint(android.graphics.Paint) FragmentTransaction(android.support.v4.app.FragmentTransaction) OnClickListener(android.content.DialogInterface.OnClickListener) CompoundButton(android.widget.CompoundButton)

Example 58 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project JamsMusicPlayer by psaravan.

the class ID3sArtistEditorDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mContext = getActivity();
    parentActivity = getActivity();
    dialogFragment = this;
    //Get the artist name.
    ARTIST = getArguments().getString("ARTIST");
    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.fragment_edit_id3_artist_album_dialog, null);
    titleText = (TextView) rootView.findViewById(R.id.edit_title_text);
    artistText = (TextView) rootView.findViewById(R.id.edit_artist_text);
    albumText = (TextView) rootView.findViewById(R.id.edit_album_text);
    albumArtistText = (TextView) rootView.findViewById(R.id.edit_album_artist_text);
    genreText = (TextView) rootView.findViewById(R.id.edit_genre_text);
    producerText = (TextView) rootView.findViewById(R.id.edit_producer_text);
    yearText = (TextView) rootView.findViewById(R.id.edit_year_text);
    trackText = (TextView) rootView.findViewById(R.id.edit_track_text);
    ofText = (TextView) rootView.findViewById(R.id.text_of);
    commentsText = (TextView) rootView.findViewById(R.id.edit_comment_text);
    titleEditText = (EditText) rootView.findViewById(R.id.edit_title_field);
    artistEditText = (EditText) rootView.findViewById(R.id.edit_artist_field);
    albumEditText = (EditText) rootView.findViewById(R.id.edit_album_field);
    albumArtistEditText = (EditText) rootView.findViewById(R.id.edit_album_artist_field);
    genreEditText = (EditText) rootView.findViewById(R.id.edit_genre_field);
    producerEditText = (EditText) rootView.findViewById(R.id.edit_producer_field);
    yearEditText = (EditText) rootView.findViewById(R.id.edit_year_field);
    trackEditText = (EditText) rootView.findViewById(R.id.edit_track_field);
    trackTotalEditText = (EditText) rootView.findViewById(R.id.edit_track_total_field);
    commentsEditText = (EditText) rootView.findViewById(R.id.edit_comment_field);
    titleCheckbox = (CheckBox) rootView.findViewById(R.id.title_checkbox);
    artistCheckbox = (CheckBox) rootView.findViewById(R.id.artist_checkbox);
    albumCheckbox = (CheckBox) rootView.findViewById(R.id.album_checkbox);
    albumArtistCheckbox = (CheckBox) rootView.findViewById(R.id.album_artist_checkbox);
    genreCheckbox = (CheckBox) rootView.findViewById(R.id.genre_checkbox);
    producerCheckbox = (CheckBox) rootView.findViewById(R.id.producer_checkbox);
    yearCheckbox = (CheckBox) rootView.findViewById(R.id.year_checkbox);
    trackCheckbox = (CheckBox) rootView.findViewById(R.id.track_checkbox);
    commentCheckbox = (CheckBox) rootView.findViewById(R.id.comment_checkbox);
    titleText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    artistText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    albumText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    albumArtistText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    genreText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    producerText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    yearText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    trackText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    ofText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    commentsText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    titleText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    artistText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    albumText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    albumArtistText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    genreText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    producerText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    yearText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    trackText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    ofText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    commentsText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    titleEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    artistEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    albumEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    albumArtistEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    genreEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    producerEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    yearEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    trackEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    trackTotalEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    commentsEditText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    titleEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    artistEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    albumEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    albumArtistEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    genreEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    producerEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    yearEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    trackEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    trackTotalEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    commentsEditText.setPaintFlags(titleText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    //Keep all the fields locked by default.
    titleCheckbox.setChecked(false);
    artistCheckbox.setChecked(false);
    albumCheckbox.setChecked(false);
    albumArtistCheckbox.setChecked(false);
    genreCheckbox.setChecked(false);
    producerCheckbox.setChecked(false);
    yearCheckbox.setChecked(false);
    trackCheckbox.setChecked(false);
    commentCheckbox.setChecked(false);
    //Disable all EditTexts by default.
    titleEditText.setEnabled(false);
    artistEditText.setEnabled(false);
    albumEditText.setEnabled(false);
    albumArtistEditText.setEnabled(false);
    genreEditText.setEnabled(false);
    producerEditText.setEnabled(false);
    yearEditText.setEnabled(false);
    trackEditText.setEnabled(false);
    commentsEditText.setEnabled(false);
    //Register click registers on each checkbox.
    titleCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                titleEdited = true;
                titleEditText.setEnabled(true);
            } else {
                titleEdited = false;
                titleEditText.setEnabled(false);
            }
        }
    });
    artistCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                artistEdited = true;
                artistEditText.setEnabled(true);
                ;
            } else {
                artistEdited = false;
                artistEditText.setEnabled(false);
            }
        }
    });
    albumArtistCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                albumEdited = true;
                albumEditText.setEnabled(true);
                ;
            } else {
                albumEdited = false;
                albumEditText.setEnabled(false);
            }
        }
    });
    albumCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                albumArtistEdited = true;
                albumArtistEditText.setEnabled(true);
                ;
            } else {
                albumArtistEdited = false;
                albumArtistEditText.setEnabled(false);
            }
        }
    });
    genreCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                genreEdited = true;
                genreEditText.setEnabled(true);
                ;
            } else {
                genreEdited = false;
                genreEditText.setEnabled(false);
            }
        }
    });
    producerCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                producerEdited = true;
                producerEditText.setEnabled(true);
                ;
            } else {
                producerEdited = false;
                producerEditText.setEnabled(false);
            }
        }
    });
    yearCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                yearEdited = true;
                yearEditText.setEnabled(true);
                ;
            } else {
                yearEdited = false;
                yearEditText.setEnabled(false);
            }
        }
    });
    trackCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                trackEdited = true;
                trackEditText.setEnabled(true);
                ;
            } else {
                trackEdited = false;
                trackEditText.setEnabled(false);
            }
        }
    });
    commentCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            if (checked == true) {
                commentEdited = true;
                commentsEditText.setEnabled(true);
                ;
            } else {
                commentEdited = false;
                commentsEditText.setEnabled(false);
            }
        }
    });
    if (ARTIST != null) {
        songURIsList = getAllSongsByArtist(ARTIST);
        //Populate the ArrayLists with the song tags.
        try {
            getSongTags(songURIsList);
        } catch (CannotReadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TagException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ReadOnlyFileException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvalidAudioFrameException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //Now check if any of the ArrayLists contain the same exact elements.
        boolean titlesSame = checkIfAllElementsEqual(titlesList);
        boolean artistsSame = checkIfAllElementsEqual(artistsList);
        boolean albumsSame = checkIfAllElementsEqual(albumsList);
        boolean albumArtistsSame = checkIfAllElementsEqual(albumArtistsList);
        boolean genresSame = checkIfAllElementsEqual(genresList);
        boolean producersSame = checkIfAllElementsEqual(producersList);
        boolean yearsSame = checkIfAllElementsEqual(yearsList);
        boolean tracksSame = checkIfAllElementsEqual(trackNumbersList);
        boolean totalTracksSame = checkIfAllElementsEqual(totalTracksList);
        boolean commentsSame = checkIfAllElementsEqual(commentsList);
        //Populate the EditTexts.
        setEditorFields(titlesSame, titlesList, titleEditText);
        setEditorFields(artistsSame, artistsList, artistEditText);
        setEditorFields(albumsSame, albumsList, albumEditText);
        setEditorFields(albumArtistsSame, albumArtistsList, albumArtistEditText);
        setEditorFields(genresSame, genresList, genreEditText);
        setEditorFields(producersSame, producersList, producerEditText);
        setEditorFields(yearsSame, yearsList, yearEditText);
        setEditorFields(tracksSame, trackNumbersList, trackEditText);
        setEditorFields(totalTracksSame, totalTracksList, trackTotalEditText);
        setEditorFields(commentsSame, commentsList, commentsEditText);
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    //Set the dialog title.
    builder.setTitle(R.string.edit_tags);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.save, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();
            AsyncSaveArtistTagsTask asyncSaveArtistTagsTask = new AsyncSaveArtistTagsTask(getActivity(), getActivity());
            asyncSaveArtistTagsTask.execute();
        }
    });
    builder.setNegativeButton(R.string.cancel, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) DialogInterface(android.content.DialogInterface) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) IOException(java.io.IOException) Paint(android.graphics.Paint) TagException(org.jaudiotagger.tag.TagException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) OnClickListener(android.content.DialogInterface.OnClickListener) CompoundButton(android.widget.CompoundButton)

Example 59 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project fitscales by paulburton.

the class SettingsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.settings_fragment, container, false);
    editHeightMain = (EditText) v.findViewById(R.id.editHeightMain);
    editHeightSub = (EditText) v.findViewById(R.id.editHeightSub);
    rowHeightSub = (TableRow) v.findViewById(R.id.rowHeightSub);
    spinHeightUnit = (Spinner) v.findViewById(R.id.spinHeightUnit);
    spinWeightUnit = (Spinner) v.findViewById(R.id.spinWeightUnit);
    seekStabilityPrecision = (SeekBar) v.findViewById(R.id.seekStabilityPrecision);
    textHeightSubUnit = (TextView) v.findViewById(R.id.textHeightSubUnit);
    listSyncServices = (ListView) v.findViewById(R.id.listSyncServices);
    swSyncAuto = (Switch) v.findViewById(R.id.swSyncAuto);
    btnDonate = (Button) v.findViewById(R.id.btnDonate);
    TabHost tabHost = (TabHost) v.findViewById(android.R.id.tabhost);
    tabHost.setup();
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (DEBUG)
            Log.d(TAG, "Using horizontal layout");
        LinearLayout llMain = (LinearLayout) v.findViewById(R.id.llMain);
        llMain.setOrientation(LinearLayout.HORIZONTAL);
        TabWidget tw = tabHost.getTabWidget();
        tw.setOrientation(LinearLayout.VERTICAL);
        tw.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
        FrameLayout tc = tabHost.getTabContentView();
        tc.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f));
    }
    tabHost.addTab(tabHost.newTabSpec("tab_body").setIndicator(createIndicatorView(tabHost, "Body", null, inflater)).setContent(R.id.tabViewBody));
    tabHost.addTab(tabHost.newTabSpec("tab_sync").setIndicator(createIndicatorView(tabHost, "Sync", null, inflater)).setContent(R.id.tabViewSync));
    tabHost.addTab(tabHost.newTabSpec("tab_about").setIndicator(createIndicatorView(tabHost, "About", null, inflater)).setContent(R.id.tabViewAbout));
    tabHost.setCurrentTab(0);
    ArrayAdapter<CharSequence> heightUnitAdapter = ArrayAdapter.createFromResource(inflater.getContext(), R.array.height_units_main_array, android.R.layout.simple_spinner_item);
    heightUnitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinHeightUnit.setAdapter(heightUnitAdapter);
    spinHeightUnit.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putInt(Prefs.KEY_HEIGHTUNIT, spinHeightUnit.getSelectedItemPosition());
            Prefs.save(edit);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    editHeightMain.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            saveHeight();
        }
    });
    editHeightSub.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            saveHeight();
        }
    });
    ArrayAdapter<CharSequence> weightUnitAdapter = ArrayAdapter.createFromResource(inflater.getContext(), R.array.weight_units_main_array, android.R.layout.simple_spinner_item);
    weightUnitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinWeightUnit.setAdapter(weightUnitAdapter);
    spinWeightUnit.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putInt(Prefs.KEY_WEIGHTUNIT, spinWeightUnit.getSelectedItemPosition());
            Prefs.save(edit);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    final float stabilityPrecisionStep = 0.1f;
    seekStabilityPrecision.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (!fromUser)
                return;
            float precision = Prefs.STABILITY_PRECISION_MIN + (progress * stabilityPrecisionStep);
            if (precision == Prefs.getStabilityPrecision())
                return;
            if (DEBUG)
                Log.d(TAG, "Stability precision change to " + precision);
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putFloat(Prefs.KEY_STABILITY_PRECISION, precision);
            Prefs.save(edit);
        }
    });
    seekStabilityPrecision.setMax((int) ((Prefs.STABILITY_PRECISION_MAX - Prefs.STABILITY_PRECISION_MIN) / stabilityPrecisionStep) + 1);
    seekStabilityPrecision.setProgress((int) ((Prefs.getStabilityPrecision() - Prefs.STABILITY_PRECISION_MIN) / stabilityPrecisionStep));
    swSyncAuto.setChecked(Prefs.getSyncAuto());
    swSyncAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked == Prefs.getSyncAuto())
                return;
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putBoolean(Prefs.KEY_SYNCAUTO, isChecked);
            Prefs.save(edit);
        }
    });
    btnDonate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=396BVJNLQFD62&lc=GB&item_name=FitScales%20Android%20App&currency_code=GBP&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"));
            startActivity(intent);
        }
    });
    /* Prevent onClick being passed up to the settingsView */
    v.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    listSyncServices.setAdapter(new SyncServiceAdapter(this, inflater.getContext(), R.layout.settings_sync_item, FitscalesApplication.inst.syncServices));
    loadSettings();
    return v;
}
Also used : TabWidget(android.widget.TabWidget) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) TabHost(android.widget.TabHost) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) FrameLayout(android.widget.FrameLayout) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) OnClickListener(android.view.View.OnClickListener) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Example 60 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project SeriesGuide by UweTrottmann.

the class AutoBackupFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_auto_backup, container, false);
    unbinder = ButterKnife.bind(this, v);
    progressBar.setVisibility(View.GONE);
    // display last auto-backup date
    long lastAutoBackupTime = AdvancedSettings.getLastAutoBackupTime(getActivity());
    boolean showLastBackupTime = BackupSettings.isUseAutoBackupDefaultFiles(getContext()) ? DataLiberationTools.isAutoBackupDefaultFilesAvailable() : !BackupSettings.isMissingAutoBackupFile(getContext());
    textViewLastAutoBackup.setText(getString(R.string.last_auto_backup, showLastBackupTime ? DateUtils.getRelativeDateTimeString(getActivity(), lastAutoBackupTime, DateUtils.SECOND_IN_MILLIS, DateUtils.DAY_IN_MILLIS, 0) : "n/a"));
    // setup listeners
    boolean autoBackupEnabled = AdvancedSettings.isAutoBackupEnabled(getContext());
    containerSettings.setVisibility(autoBackupEnabled ? View.VISIBLE : View.GONE);
    switchAutoBackup.setChecked(autoBackupEnabled);
    switchAutoBackup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                tryEnableAutoBackup();
            } else {
                setAutoBackupEnabled(false);
            }
        }
    });
    checkBoxImportWarning.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            buttonImportAutoBackup.setEnabled(isChecked);
        }
    });
    buttonImportAutoBackup.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tryDataLiberationAction();
        }
    });
    // as we use Storage Access Framework in this case
    if (AndroidUtils.isKitKatOrHigher()) {
        checkBoxDefaultFiles.setChecked(BackupSettings.isUseAutoBackupDefaultFiles(getContext()));
        checkBoxDefaultFiles.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceManager.getDefaultSharedPreferences(buttonView.getContext()).edit().putBoolean(BackupSettings.KEY_AUTO_BACKUP_USE_DEFAULT_FILES, isChecked).commit();
                updateFileViews();
            }
        });
        buttonShowsExportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectExportFile(AutoBackupFragment.this, JsonExportTask.EXPORT_JSON_FILE_SHOWS, REQUEST_CODE_SHOWS_EXPORT_URI);
            }
        });
        buttonListsExportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectExportFile(AutoBackupFragment.this, JsonExportTask.EXPORT_JSON_FILE_LISTS, REQUEST_CODE_LISTS_EXPORT_URI);
            }
        });
        buttonMoviesExportFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                DataLiberationTools.selectExportFile(AutoBackupFragment.this, JsonExportTask.EXPORT_JSON_FILE_MOVIES, REQUEST_CODE_MOVIES_EXPORT_URI);
            }
        });
    } else {
        checkBoxDefaultFiles.setVisibility(View.GONE);
    }
    updateFileViews();
    return v;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) OnClickListener(android.view.View.OnClickListener) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Aggregations

OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)101 CompoundButton (android.widget.CompoundButton)98 View (android.view.View)78 TextView (android.widget.TextView)66 ImageView (android.widget.ImageView)40 OnClickListener (android.view.View.OnClickListener)31 CheckBox (android.widget.CheckBox)30 DialogInterface (android.content.DialogInterface)27 AdapterView (android.widget.AdapterView)24 AlertDialog (android.app.AlertDialog)23 ListView (android.widget.ListView)20 Button (android.widget.Button)19 LayoutInflater (android.view.LayoutInflater)17 ArrayList (java.util.ArrayList)17 List (java.util.List)15 OnClickListener (android.content.DialogInterface.OnClickListener)12 SuppressLint (android.annotation.SuppressLint)11 Intent (android.content.Intent)11 ViewGroup (android.view.ViewGroup)10 Cursor (android.database.Cursor)9