add a Dark theme
This commit is contained in:
parent
4f6b825ede
commit
61796c1557
17 changed files with 145 additions and 34 deletions
|
@ -34,15 +34,18 @@
|
|||
|
||||
<activity
|
||||
android:name=".activities.AboutActivity"
|
||||
android:label="@string/about"/>
|
||||
android:label="@string/about"
|
||||
android:parentActivityName=".activities.MainActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.LicenseActivity"
|
||||
android:label="@string/third_party_licences"/>
|
||||
android:label="@string/third_party_licences"
|
||||
android:parentActivityName=".activities.AboutActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/settings"/>
|
||||
android:label="@string/settings"
|
||||
android:parentActivityName=".activities.MainActivity"/>
|
||||
|
||||
<service
|
||||
android:name=".MusicService"
|
||||
|
|
|
@ -23,6 +23,14 @@ public class Config {
|
|||
mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply();
|
||||
}
|
||||
|
||||
public boolean getIsDarkTheme() {
|
||||
return mPrefs.getBoolean(Constants.IS_DARK_THEME, false);
|
||||
}
|
||||
|
||||
public void setIsDarkTheme(boolean isDarkTheme) {
|
||||
mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply();
|
||||
}
|
||||
|
||||
public boolean getIsShuffleEnabled() {
|
||||
return mPrefs.getBoolean(Constants.SHUFFLE, true);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public class Constants {
|
|||
// shared preferences
|
||||
public static final String PREFS_KEY = "Music Player";
|
||||
public static final String IS_FIRST_RUN = "is_first_run";
|
||||
public static final String IS_DARK_THEME = "is_dark_theme";
|
||||
public static final String SHUFFLE = "shuffle";
|
||||
public static final String NUMERIC_PROGRESS = "numeric_progress";
|
||||
public static final String SORTING = "sorting";
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
|||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.View;
|
||||
|
@ -21,7 +20,7 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
public class AboutActivity extends SimpleActivity {
|
||||
@BindView(R.id.about_copyright) TextView mCopyright;
|
||||
@BindView(R.id.about_email) TextView mEmailTV;
|
||||
@BindView(R.id.about_rate_us) View mRateUs;
|
||||
|
|
|
@ -3,14 +3,13 @@ package com.simplemobiletools.musicplayer.activities;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.simplemobiletools.musicplayer.R;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class LicenseActivity extends AppCompatActivity {
|
||||
public class LicenseActivity extends SimpleActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.ContentValues;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaScannerConnection;
|
||||
|
@ -16,7 +17,6 @@ import android.support.design.widget.Snackbar;
|
|||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
|
@ -51,7 +51,7 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
public class MainActivity extends SimpleActivity
|
||||
implements ListView.MultiChoiceModeListener, AdapterView.OnItemClickListener, ListView.OnTouchListener,
|
||||
MediaScannerConnection.OnScanCompletedListener, SeekBar.OnSeekBarChangeListener {
|
||||
private static final int STORAGE_PERMISSION = 1;
|
||||
|
@ -62,16 +62,20 @@ public class MainActivity extends AppCompatActivity
|
|||
@BindView(R.id.songArtist) TextView mArtistTV;
|
||||
@BindView(R.id.progressbar) SeekBar mProgressBar;
|
||||
@BindView(R.id.song_progress) TextView mProgress;
|
||||
@BindView(R.id.previousBtn) ImageView mPreviousBtn;
|
||||
@BindView(R.id.nextBtn) ImageView mNextBtn;
|
||||
|
||||
private static Bus mBus;
|
||||
private static Song mCurrentSong;
|
||||
private static List<Song> mSongs;
|
||||
private static Snackbar mSnackbar;
|
||||
private static List<String> mToBeDeleted;
|
||||
private static Bitmap mPlayBitmap;
|
||||
private static Bitmap mPauseBitmap;
|
||||
|
||||
private static boolean mIsSnackbarShown;
|
||||
private static int mSelectedItemsCnt;
|
||||
private static boolean mIsNumericProgressShown;
|
||||
private static int mSelectedItemsCnt;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -81,6 +85,7 @@ public class MainActivity extends AppCompatActivity
|
|||
mBus = BusProvider.getInstance();
|
||||
mBus.register(this);
|
||||
mProgressBar.setOnSeekBarChangeListener(this);
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
initializePlayer();
|
||||
|
@ -93,10 +98,12 @@ public class MainActivity extends AppCompatActivity
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
mIsNumericProgressShown = Config.newInstance(getApplicationContext()).getIsNumericProgressEnabled();
|
||||
if (mIsNumericProgressShown)
|
||||
setupIconColors();
|
||||
if (mIsNumericProgressShown) {
|
||||
mProgress.setVisibility(View.VISIBLE);
|
||||
else
|
||||
} else {
|
||||
mProgress.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,6 +148,15 @@ public class MainActivity extends AppCompatActivity
|
|||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
|
||||
private void setupIconColors() {
|
||||
final Resources res = getResources();
|
||||
final int color = mTitleTV.getCurrentTextColor();
|
||||
mPreviousBtn.setImageBitmap(Utils.getColoredIcon(res, color, R.mipmap.previous));
|
||||
mNextBtn.setImageBitmap(Utils.getColoredIcon(res, color, R.mipmap.next));
|
||||
mPlayBitmap = Utils.getColoredIcon(res, color, R.mipmap.play);
|
||||
mPauseBitmap = Utils.getColoredIcon(res, color, R.mipmap.pause);
|
||||
}
|
||||
|
||||
private void songPicked(int pos) {
|
||||
final Intent intent = new Intent(this, MusicService.class);
|
||||
intent.putExtra(Constants.SONG_POS, pos);
|
||||
|
@ -202,11 +218,11 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
@Subscribe
|
||||
public void songStateChanged(Events.SongStateChanged event) {
|
||||
int id = R.mipmap.play;
|
||||
if (event.getIsPlaying())
|
||||
id = R.mipmap.pause;
|
||||
|
||||
mPlayPauseBtn.setImageDrawable(getResources().getDrawable(id));
|
||||
if (event.getIsPlaying()) {
|
||||
mPlayPauseBtn.setImageBitmap(mPauseBitmap);
|
||||
} else {
|
||||
mPlayPauseBtn.setImageBitmap(mPlayBitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.simplemobiletools.musicplayer.activities;
|
|||
import android.content.Intent;
|
||||
import android.media.audiofx.Equalizer;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.support.v7.widget.AppCompatSpinner;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
@ -18,7 +18,8 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
import butterknife.OnItemSelected;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
public class SettingsActivity extends SimpleActivity {
|
||||
@BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch;
|
||||
@BindView(R.id.settings_shuffle) SwitchCompat mShuffleSwitch;
|
||||
@BindView(R.id.settings_numeric_progress) SwitchCompat mNumericProgressSwitch;
|
||||
@BindView(R.id.settings_sorting) AppCompatSpinner mSortingSpinner;
|
||||
|
@ -39,6 +40,11 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
setupNumericProgress();
|
||||
setupSorting();
|
||||
setupEqualizer();
|
||||
setupDarkTheme();
|
||||
}
|
||||
|
||||
private void setupDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
|
||||
}
|
||||
|
||||
private void setupShuffle() {
|
||||
|
@ -53,16 +59,11 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
mSortingSpinner.setSelection(mConfig.getSorting());
|
||||
}
|
||||
|
||||
private void setupEqualizer() {
|
||||
final int cnt = mEqualizer.getNumberOfPresets();
|
||||
final String[] presets = new String[cnt];
|
||||
for (short i = 0; i < cnt; i++) {
|
||||
presets[i] = mEqualizer.getPresetName(i);
|
||||
}
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, presets);
|
||||
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mEqualizerSpinner.setAdapter(arrayAdapter);
|
||||
mEqualizerSpinner.setSelection(mConfig.getEqualizer());
|
||||
@OnClick(R.id.settings_dark_theme_holder)
|
||||
public void handleDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked());
|
||||
mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked());
|
||||
restartActivity();
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_shuffle_holder)
|
||||
|
@ -94,6 +95,22 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
startService(intent);
|
||||
}
|
||||
|
||||
private void restartActivity() {
|
||||
TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities();
|
||||
}
|
||||
|
||||
private void setupEqualizer() {
|
||||
final int cnt = mEqualizer.getNumberOfPresets();
|
||||
final String[] presets = new String[cnt];
|
||||
for (short i = 0; i < cnt; i++) {
|
||||
presets[i] = mEqualizer.getPresetName(i);
|
||||
}
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, presets);
|
||||
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mEqualizerSpinner.setAdapter(arrayAdapter);
|
||||
mEqualizerSpinner.setSelection(mConfig.getEqualizer());
|
||||
}
|
||||
|
||||
private void updatePlaylist() {
|
||||
final Intent intent = new Intent(this, MusicService.class);
|
||||
intent.putExtra(Constants.UPDATE_ACTIVITY, true);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.simplemobiletools.musicplayer.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.simplemobiletools.musicplayer.Config;
|
||||
import com.simplemobiletools.musicplayer.R;
|
||||
|
||||
public class SimpleActivity extends AppCompatActivity {
|
||||
protected Config mConfig;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
setTheme(mConfig.getIsDarkTheme() ? R.style.AppTheme_Dark : R.style.AppTheme);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,7 +57,6 @@
|
|||
android:fontFamily="sans-serif-light"
|
||||
android:gravity="center_horizontal"
|
||||
android:maxLines="1"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<TextView
|
||||
|
@ -71,7 +70,6 @@
|
|||
android:fontFamily="sans-serif-light"
|
||||
android:gravity="center_horizontal"
|
||||
android:maxLines="1"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<SeekBar
|
||||
|
|
|
@ -11,6 +11,32 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_dark_theme_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_padding"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_dark_theme_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="@dimen/settings_padding"
|
||||
android:text="@string/dark_theme"/>
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/settings_dark_theme"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@null"
|
||||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_shuffle_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:text="Song Title"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<TextView
|
||||
|
@ -27,7 +26,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:text="Song Artist"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Impostazioni</string>
|
||||
<string name="dark_theme">Tema scuro</string>
|
||||
<string name="shuffle">Mischia</string>
|
||||
<string name="numeric_progress">Mostra anche l\'avanzamento in numeri</string>
|
||||
<string name="sort_by">Ordina tracce per</string>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
<!-- Settings -->
|
||||
<string name="settings">設定</string>
|
||||
<string name="dark_theme">ダークテーマ</string>
|
||||
<string name="shuffle">シャッフル</string>
|
||||
<string name="numeric_progress">再生状況を数値でも表示する</string>
|
||||
<string name="sort_by">トラックの並び替え</string>
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Inställningar</string>
|
||||
<string name="dark_theme">Mörkt tema</string>
|
||||
<string name="shuffle">Blanda</string>
|
||||
<string name="numeric_progress">Visa även förloppet i siffror</string>
|
||||
<string name="sort_by">Sortera låtar efter</string>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="sorting">
|
||||
<string-array name="sorting" translatable="false">
|
||||
<item>@string/title</item>
|
||||
<item>@string/artist</item>
|
||||
</string-array>
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
<string name="dark_theme">Dark theme</string>
|
||||
<string name="shuffle">Shuffle</string>
|
||||
<string name="numeric_progress">Display progress in numbers too</string>
|
||||
<string name="sort_by">Sort tracks by</string>
|
||||
|
|
|
@ -11,6 +11,17 @@
|
|||
<item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.Dark" parent="Theme.AppCompat">
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
|
||||
<item name="android:textSize">@dimen/normal_text_size</item>
|
||||
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
|
||||
<item name="spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
|
||||
<item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
|
||||
</style>
|
||||
|
||||
<style name="MyWidgetConfigTheme" parent="@style/AppTheme">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowShowWallpaper">true</item>
|
||||
|
|
Loading…
Reference in a new issue