Android Open Source - vanilindy New Playlist Dialog






From Project

Back to project page vanilindy.

License

The source code is released under:

Apache License

If you think the Android project vanilindy listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
 *//  w  w  w. j a v  a 2s.co  m
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package ch.blinkenlights.android.vanilla;

import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

/**
 * Simple dialog to prompt to user to enter a playlist name. Has an EditText to
 * enter the name and two buttons, create and cancel. Create changes to
 * overwrite if a name that already exists is selected.
 */
public class NewPlaylistDialog extends Dialog implements TextWatcher, View.OnClickListener {
  /**
   * The create/overwrite button.
   */
  private Button mPositiveButton;
  /**
   * The text entry view.
   */
  private EditText mText;
  /**
   * Whether the dialog has been accepted. The dialog is accepted if create
   * was clicked.
   */
  private boolean mAccepted;
  /**
   * The text to display initially. When the EditText contains this text, the
   * positive button will be disabled.
   */
  private final String mInitialText;
  /**
   * The resource containing the string describing the default positive
   * action (e.g. "Create" or "Rename").
   */
  private final int mActionRes;
  /**
   * An intent that is simply stored in the dialog.
   */
  private final Intent mIntent;

  /**
   * Create a NewPlaylistDialog.
   *
   * @param context A Context to use.
   * @param initialText The text to show initially. The positive button is
   * disabled when the EditText contains this text.
   * @param actionText A string resource describing the default positive
   * action (e.g. "Create").
   * @param intent An optional intent to store with the dialog.
   */
  public NewPlaylistDialog(Context context, String initialText, int actionText, Intent intent)
  {
    super(context);
    mInitialText = initialText;
    mActionRes = actionText;
    mIntent = intent;
  }

  @Override
  protected void onCreate(Bundle state)
  {
    super.onCreate(state);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    setContentView(R.layout.new_playlist_dialog);

    setTitle(R.string.choose_playlist_name);

    mPositiveButton = (Button)findViewById(R.id.create);
    mPositiveButton.setOnClickListener(this);
    mPositiveButton.setText(mActionRes);
    View negativeButton = findViewById(R.id.cancel);
    negativeButton.setOnClickListener(this);

    mText = (EditText)findViewById(R.id.playlist_name);
    mText.addTextChangedListener(this);
    mText.setText(mInitialText);
    mText.requestFocus();
  }

  /**
   * Returns the playlist name currently entered in the dialog.
   */
  public String getText()
  {
    return mText.getText().toString();
  }

  /**
   * Returns the stored intent.
   */
  public Intent getIntent()
  {
    return mIntent;
  }

  public void afterTextChanged(Editable s)
  {
    // do nothing
  }

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

  public void onTextChanged(CharSequence text, int start, int before, int count)
  {
    String string = text.toString();
    if (string.equals(mInitialText)) {
      mPositiveButton.setEnabled(false);
    } else {
      mPositiveButton.setEnabled(true);
      // Update the action button based on whether there is an
      // existing playlist with the given name.
      ContentResolver resolver = getContext().getContentResolver();
      int res = Playlist.getPlaylist(resolver, string) == -1 ? mActionRes : R.string.overwrite;
      mPositiveButton.setText(res);
    }
  }

  /**
   * Returns whether the dialog has been accepted. The dialog is accepted
   * when the create/overwrite button is clicked.
   */
  public boolean isAccepted()
  {
    return mAccepted;
  }

  public void onClick(View view)
  {
    switch (view.getId()) {
    case R.id.create:
      mAccepted = true;
      // fall through
    case R.id.cancel:
      dismiss();
      break;
    }
  }
}




Java Source Code List

android.support.v4.view.PagerAdapter.java
android.support.v4.view.ViewPager.java
ch.blinkenlights.android.vanilla.ActionBarControls.java
ch.blinkenlights.android.vanilla.Action.java
ch.blinkenlights.android.vanilla.BastpUtil.java
ch.blinkenlights.android.vanilla.BuildConfig.java
ch.blinkenlights.android.vanilla.CompatHoneycomb.java
ch.blinkenlights.android.vanilla.CompatIcs.java
ch.blinkenlights.android.vanilla.CoverBitmap.java
ch.blinkenlights.android.vanilla.CoverView.java
ch.blinkenlights.android.vanilla.DragListView.java
ch.blinkenlights.android.vanilla.DragTextView.java
ch.blinkenlights.android.vanilla.FileSystemAdapter.java
ch.blinkenlights.android.vanilla.FilebrowserStartActivity.java
ch.blinkenlights.android.vanilla.FilebrowserStartAdapter.java
ch.blinkenlights.android.vanilla.FourLongWidget.java
ch.blinkenlights.android.vanilla.FourSquareWidget.java
ch.blinkenlights.android.vanilla.FourWhiteWidget.java
ch.blinkenlights.android.vanilla.FullPlaybackActivity.java
ch.blinkenlights.android.vanilla.IdlePreference.java
ch.blinkenlights.android.vanilla.LibraryActivity.java
ch.blinkenlights.android.vanilla.LibraryAdapter.java
ch.blinkenlights.android.vanilla.LibraryPagerAdapter.java
ch.blinkenlights.android.vanilla.Limiter.java
ch.blinkenlights.android.vanilla.ListPreferenceSummary.java
ch.blinkenlights.android.vanilla.MediaAdapter.java
ch.blinkenlights.android.vanilla.MediaButtonReceiver.java
ch.blinkenlights.android.vanilla.MediaUtils.java
ch.blinkenlights.android.vanilla.MiniPlaybackActivity.java
ch.blinkenlights.android.vanilla.MusicAlphabetIndexer.java
ch.blinkenlights.android.vanilla.NewPlaylistDialog.java
ch.blinkenlights.android.vanilla.OneCellWidget.java
ch.blinkenlights.android.vanilla.PlayCountsHelper.java
ch.blinkenlights.android.vanilla.PlaybackActivity.java
ch.blinkenlights.android.vanilla.PlaybackService.java
ch.blinkenlights.android.vanilla.PlaylistActivity.java
ch.blinkenlights.android.vanilla.PlaylistAdapter.java
ch.blinkenlights.android.vanilla.Playlist.java
ch.blinkenlights.android.vanilla.PrefKeys.java
ch.blinkenlights.android.vanilla.PreferencesActivity.java
ch.blinkenlights.android.vanilla.PreferencesBackupAgent.java
ch.blinkenlights.android.vanilla.QueryTask.java
ch.blinkenlights.android.vanilla.ReadaheadThread.java
ch.blinkenlights.android.vanilla.SeekBarPreference.java
ch.blinkenlights.android.vanilla.ShowQueueActivity.java
ch.blinkenlights.android.vanilla.ShowQueueAdapter.java
ch.blinkenlights.android.vanilla.SongTimeline.java
ch.blinkenlights.android.vanilla.Song.java
ch.blinkenlights.android.vanilla.TabOrderActivity.java
ch.blinkenlights.android.vanilla.TabOrderAdapter.java
ch.blinkenlights.android.vanilla.WidgetD.java
ch.blinkenlights.android.vanilla.WidgetE.java
ch.blinkenlights.bastp.Bastp.java
ch.blinkenlights.bastp.Common.java
ch.blinkenlights.bastp.FlacFile.java
ch.blinkenlights.bastp.ID3v2File.java
ch.blinkenlights.bastp.LameHeader.java
ch.blinkenlights.bastp.OggFile.java
com.viewpagerindicator.TabPageIndicator.java