Autoformat

This commit is contained in:
Xorok 2017-03-09 23:24:46 +01:00 committed by Karim Abou Zeid
commit 35aaca78ea
5 changed files with 33 additions and 39 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.kabouzeid.gramophone"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kabouzeid.gramophone">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@ -175,8 +175,7 @@
android:label="@string/report_an_issue" />
<activity
android:name=".appshortcuts.AppShortcutLauncherActivity"
android:exported="true"
/>
android:exported="true" />
</application>
</manifest>

View file

@ -20,6 +20,8 @@ import java.util.ArrayList;
public class AppShortcutLauncherActivity extends Activity {
public static final String KEY_SHORTCUT_TYPE = "com.kabouzeid.gramophone.appshortcuts.ShortcutType";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -28,10 +30,10 @@ public class AppShortcutLauncherActivity extends Activity {
//Set shortcutType from the intent extras
Bundle extras = getIntent().getExtras();
if (extras!=null){
if (extras != null) {
try {
shortcutType = ShortcutType.valueOf(extras.getString(KEY_SHORTCUT_TYPE));
} catch (IllegalArgumentException e){ //In the event we're somehow passed an invalid enum string, don't crash.
} catch (IllegalArgumentException e) { //In the event we're somehow passed an invalid enum string, don't crash.
e.printStackTrace();
shortcutType = ShortcutType.NONE;
}
@ -60,15 +62,12 @@ public class AppShortcutLauncherActivity extends Activity {
}
finish();
}
private enum PlayMode {NORMAL, SHUFFLE}
private void launchMainActivityWithSongs(PlayMode playMode, ArrayList<Song> songs){
private void launchMainActivityWithSongs(PlayMode playMode, ArrayList<Song> songs) {
//Create a new intent to launch MainActivity
Intent intent = new Intent(this, MainActivity.class);
switch (playMode){
switch (playMode) {
case NORMAL:
intent.setAction(MainActivity.INTENT_ACTION_MEDIA_PLAY);
break;
@ -89,11 +88,12 @@ public class AppShortcutLauncherActivity extends Activity {
startActivity(intent);
}
private void shortcutError(){
private void shortcutError() {
Toast.makeText(getApplicationContext(), R.string.error_launching_shortcut, Toast.LENGTH_LONG).show();
}
public static final String KEY_SHORTCUT_TYPE = "com.kabouzeid.gramophone.appshortcuts.ShortcutType";
private enum PlayMode {NORMAL, SHUFFLE}
public enum ShortcutType {
SHUFFLE_ALL, TOP_TRACKS, LAST_ADDED, NONE
}

View file

@ -8,7 +8,9 @@ import android.content.pm.ShortcutManager;
import android.graphics.Color;
import android.graphics.drawable.Icon;
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.*;
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.LastAddedShortcutType;
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.ShuffleAllShortcutType;
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.TopTracksShortcutType;
import java.util.ArrayList;
import java.util.Arrays;
@ -23,29 +25,13 @@ public class DynamicShortcutManager {
Context mContext;
ShortcutManager shortcutManager;
public DynamicShortcutManager(Context context){
public DynamicShortcutManager(Context context) {
mContext = context;
shortcutManager = mContext.getSystemService(ShortcutManager.class);
}
public void initDynamicShortcuts(){
if (shortcutManager.getDynamicShortcuts().size() == 0){
shortcutManager.setDynamicShortcuts(getDefaultShortcuts());
}
}
public List<ShortcutInfo> getDefaultShortcuts(){
return (Arrays.asList(
new ShuffleAllShortcutType(mContext).getShortcutInfo(),
new TopTracksShortcutType(mContext).getShortcutInfo(),
new LastAddedShortcutType(mContext).getShortcutInfo()
));
}
public static ShortcutInfo createShortcut(Context context, String id, String shortLabel, String longLabel, Icon icon, Intent intent){
public static ShortcutInfo createShortcut(Context context, String id, String shortLabel, String longLabel, Icon icon, Intent intent) {
return new ShortcutInfo.Builder(context, id)
.setShortLabel(shortLabel)
.setLongLabel(longLabel)
@ -54,12 +40,27 @@ public class DynamicShortcutManager {
.build();
}
public void tintShortcutIcons(ArrayList<ShortcutInfo> shortcutInfos, Color color){
public void initDynamicShortcuts() {
if (shortcutManager.getDynamicShortcuts().size() == 0) {
shortcutManager.setDynamicShortcuts(getDefaultShortcuts());
}
}
public List<ShortcutInfo> getDefaultShortcuts() {
return (Arrays.asList(
new ShuffleAllShortcutType(mContext).getShortcutInfo(),
new TopTracksShortcutType(mContext).getShortcutInfo(),
new LastAddedShortcutType(mContext).getShortcutInfo()
));
}
public void tintShortcutIcons(ArrayList<ShortcutInfo> shortcutInfos, Color color) {
for (ShortcutInfo shortcutInfo : shortcutInfos) {
tintShortcutIcon(shortcutInfo, color);
}
}
public void tintShortcutIcon(ShortcutInfo shortcutInfo, Color color){
public void tintShortcutIcon(ShortcutInfo shortcutInfo, Color color) {
//TODO Tint icons here
}

View file

@ -7,10 +7,6 @@ import android.content.pm.ShortcutInfo;
import android.os.Bundle;
import com.kabouzeid.gramophone.appshortcuts.AppShortcutLauncherActivity;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.ui.activities.MainActivity;
import java.util.ArrayList;
/**
* @author Adrian Campos
@ -31,7 +27,6 @@ public abstract class BaseShortcutType {
abstract ShortcutInfo getShortcutInfo();
/**
* Creates an Intent that will launch MainActivtiy and immediately play {@param songs} in either shuffle or normal mode
*

View file

@ -7,7 +7,6 @@ import android.graphics.drawable.Icon;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.appshortcuts.AppShortcutLauncherActivity;
import com.kabouzeid.gramophone.loader.TopAndRecentlyPlayedTracksLoader;
/**
* @author Adrian Campos
@ -18,7 +17,7 @@ public final class TopTracksShortcutType extends BaseShortcutType {
public TopTracksShortcutType(Context context) {
super(context);
}
public ShortcutInfo getShortcutInfo() {
return new ShortcutInfo.Builder(mContext, ID_PREFIX + "top_tracks")
.setShortLabel(mContext.getString(R.string.appshortcut_toptracks_short))