Add button in preferences to rescan library

This commit is contained in:
Christopher Eby 2012-01-29 20:30:58 -06:00
parent b2bb5b7c91
commit 95b5965a12
4 changed files with 79 additions and 1 deletions

View File

@ -10,5 +10,5 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-14
target=android-15
proguard.config=proguard.config

View File

@ -174,6 +174,11 @@ THE SOFTWARE.
<string name="stock_broadcast_title">Emulate Stock Broadcasts</string>
<string name="stock_broadcast_summary">Send broadcasts emulating those sent by the stock music player to work with 3rd party lockscreen controls, widgets, etc.</string>
<string name="media_scan">Refresh Library</string>
<string name="click_to_scan">Click to scan external storage for music</string>
<string name="scan_in_progress">Scan in progress…</string>
<string name="finished_scanning">Finished scanning. Click to scan again.</string>
<!-- The following are for the list preferences -->
<string name="last_used_action">Last used action</string>

View File

@ -158,5 +158,6 @@ THE SOFTWARE.
android:title="@string/stock_broadcast_title"
android:summary="@string/stock_broadcast_summary"
android:defaultValue="false" />
<org.kreed.vanilla.ScanPreference />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -0,0 +1,72 @@
/*
* Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
*
* 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 org.kreed.vanilla;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Environment;
import android.preference.Preference;
import android.util.AttributeSet;
/**
* A preference that allows the MediaScanner to be triggered.
*/
public class ScanPreference extends Preference {
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
android.util.Log.i("VanillaMusic", "receive: " + intent);
String action = intent.getAction();
if (action.equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) {
setSummary(R.string.scan_in_progress);
setEnabled(false);
} else if (intent.getAction().equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
setSummary(R.string.finished_scanning);
setEnabled(true);
}
}
};
public ScanPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
setTitle(R.string.media_scan);
setSummary(R.string.click_to_scan);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
intentFilter.addDataScheme("file");
context.registerReceiver(mReceiver, intentFilter);
}
@Override
public void onClick()
{
Uri storage = Uri.parse("file://" + Environment.getExternalStorageDirectory());
getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, storage));
}
}