Android Open Source - simpleplayer Preferences Activity






From Project

Back to project page simpleplayer.

License

The source code is released under:

GNU General Public License

If you think the Android project simpleplayer 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

package org.sergez.splayer.activity;
/*from   ww w  .j  av  a2s  .  c om*/
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.util.Log;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
import org.sergez.splayer.R;

public class PreferencesActivity extends SherlockPreferenceActivity {
  private final static String TAG = PreferencesActivity.class.getSimpleName();
  private ProgressDialog pDialog;
  private MediaIntentReceiver mediaIntentReceiver;

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

    addPreferencesFromResource(R.xml.preferences);

    Preference rowAbout = findPreference("showAbout");   // TODO move to constants
    rowAbout.setOnPreferenceClickListener(new OnPreferenceClickListener() {
      public boolean onPreferenceClick(Preference preference) {
        PackageInfo pInfo = null;
        String version = null;
        try {
          pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
          version = pInfo.versionName;
        } catch (NameNotFoundException e) {
          Log.e(TAG, e.getMessage(), e);
          version = "?";
        }

        String title = getResources().getString(R.string.about_title) + " " + getResources().getString(R.string.app_name);
        new AlertDialog.Builder(PreferencesActivity.this)
            .setIcon(R.drawable.ic_launcher)
            .setTitle(title)
            .setMessage(
                getString(R.string.version) + " " + version + "\n" + "\n"
                    + getString(R.string.author)
            )
            .setPositiveButton(R.string.ok, null).show();
        return true;
      }

    });
    Preference rowRefreshMedia = (Preference) findPreference("refreshMedia");
    if (android.os.Build.VERSION.SDK_INT > 18) {  // in Kitkat and newer intent.action.MEDIA_MOUNTED os blocked
      PreferenceScreen preferenceScreen = getPreferenceScreen();
      preferenceScreen.removePreference(rowRefreshMedia);
    } else {
      rowRefreshMedia.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
          if (android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment.getExternalStorageState())) {
            IntentFilter mountedMediaFilter;
            mountedMediaFilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_FINISHED);
            mountedMediaFilter.addDataScheme("file");
            mediaIntentReceiver = new MediaIntentReceiver();
            registerReceiver(mediaIntentReceiver, mountedMediaFilter);
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + Environment.getExternalStorageDirectory())));
            pDialog = ProgressDialog.show(PreferencesActivity.this, getString(R.string.refreshing_media), getString(R.string.please_wait), true, false);
          } else {
            new AlertDialog.Builder(PreferencesActivity.this)
                .setTitle(R.string.app_name)
                .setMessage(R.string.media_cant_be_refreshed)
                .setPositiveButton(R.string.ok, null).show();
          }
          return true;
        }
      });
    }

  }

  @Override
  public void onStart() {
    super.onStart();
  }

  public class MediaIntentReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
      if (Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(intent.getAction())) {
        //refreshCountdown.cancel();
        unregisterReceiver(mediaIntentReceiver);
        if (pDialog != null) {
          pDialog.dismiss();
          pDialog = null;
        }
      }

    }
  }
}




Java Source Code List

org.sergez.splayer.activity.AnimationMakeGoneListener.java
org.sergez.splayer.activity.AudioFxDemo.java
org.sergez.splayer.activity.DonationActivity.java
org.sergez.splayer.activity.ListData.java
org.sergez.splayer.activity.PlayFileAdapter.java
org.sergez.splayer.activity.PreferencesActivity.java
org.sergez.splayer.activity.SimplePlayerActivity.java
org.sergez.splayer.enums.RepeatState.java
org.sergez.splayer.enums.ShuffleState.java
org.sergez.splayer.inappbilling.Base64DecoderException.java
org.sergez.splayer.inappbilling.Base64.java
org.sergez.splayer.inappbilling.IabException.java
org.sergez.splayer.inappbilling.IabHelper.java
org.sergez.splayer.inappbilling.IabResult.java
org.sergez.splayer.inappbilling.Inventory.java
org.sergez.splayer.inappbilling.Purchase.java
org.sergez.splayer.inappbilling.Security.java
org.sergez.splayer.inappbilling.SkuDetails.java
org.sergez.splayer.service.SimplePlayerService.java
org.sergez.splayer.util.Constants.java
org.sergez.splayer.util.DialogUtils.java
org.sergez.splayer.util.DurationAlbumID.java
org.sergez.splayer.util.FileFormat.java
org.sergez.splayer.util.MediaFileData.java
org.sergez.splayer.util.MediaFileUtil.java
org.sergez.splayer.util.PlayerState.java
org.sergez.splayer.util.PrefsConstants.java
org.sergez.splayer.util.PrefsController.java
org.sergez.splayer.util.SortIgnoreCase.java
org.sergez.splayer.util.UIStateController.java
org.sergez.splayer.util.Utils.java
org.sergez.splayer.view.ScrollingTextView.java