Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Enable clang-format on AOSP Music Player"
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Jan 27, 2017
2 parents ef3044c + b0fba8b commit 879edc6
Show file tree
Hide file tree
Showing 28 changed files with 1,609 additions and 1,838 deletions.
32 changes: 32 additions & 0 deletions .clang-format
@@ -0,0 +1,32 @@
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Below are some minor deviations from the default Google style to
# accommodate for handling of the large legacy code base.
#

BasedOnStyle: Google
CommentPragmas: NOLINT:.*
DerivePointerAlignment: false

---
Language: Java
BasedOnStyle: Google
IndentWidth: 4
ContinuationIndentWidth: 8
ColumnLimit: 100
AllowShortIfStatementsOnASingleLine: true
6 changes: 6 additions & 0 deletions PREUPLOAD.cfg
@@ -0,0 +1,6 @@
[Options]
ignore_merged_commits = true

[Builtin Hooks]
clang_format = true

169 changes: 76 additions & 93 deletions src/com/android/music/AlbumBrowserActivity.java

Large diffs are not rendered by default.

259 changes: 124 additions & 135 deletions src/com/android/music/ArtistAlbumBrowserActivity.java

Large diffs are not rendered by default.

44 changes: 21 additions & 23 deletions src/com/android/music/AudioPreview.java
100755 → 100644
Expand Up @@ -53,8 +53,8 @@
/**
* Dialog that comes up in response to various music-related VIEW intents.
*/
public class AudioPreview extends Activity implements OnPreparedListener, OnErrorListener, OnCompletionListener
{
public class AudioPreview
extends Activity implements OnPreparedListener, OnErrorListener, OnCompletionListener {
private final static String TAG = "AudioPreview";
private PreviewPlayer mPlayer;
private TextView mTextLine1;
Expand All @@ -74,7 +74,7 @@ public class AudioPreview extends Activity implements OnPreparedListener, OnErro
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

Intent intent = getIntent();
if (intent == null) {
finish();
Expand All @@ -86,7 +86,7 @@ public void onCreate(Bundle icicle) {
return;
}
String scheme = mUri.getScheme();

setVolumeControlStream(AudioManager.STREAM_MUSIC);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.audiopreview);
Expand Down Expand Up @@ -130,16 +130,15 @@ public void onCreate(Bundle icicle) {
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
if (cursor != null && cursor.moveToFirst()) {

int titleIdx = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int artistIdx = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int idIdx = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
int displaynameIdx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);

if (idIdx >=0) {
if (idIdx >= 0) {
mMediaId = cursor.getLong(idIdx);
}

if (titleIdx >= 0) {
String title = cursor.getString(titleIdx);
mTextLine1.setText(title);
Expand Down Expand Up @@ -168,8 +167,8 @@ protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
if (mUri.getAuthority() == MediaStore.AUTHORITY) {
// try to get title and artist from the media content provider
mAsyncQueryHandler.startQuery(0, null, mUri, new String [] {
MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST},
mAsyncQueryHandler.startQuery(0, null, mUri,
new String[] {MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST},
null, null, null);
} else {
// Try to get the display name from another content provider.
Expand All @@ -181,10 +180,10 @@ protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
// check if this file is in the media database (clicking on a download
// in the download manager might follow this path
String path = mUri.getPath();
mAsyncQueryHandler.startQuery(0, null, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String [] {MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST},
MediaStore.Audio.Media.DATA + "=?", new String [] {path}, null);
mAsyncQueryHandler.startQuery(0, null, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST},
MediaStore.Audio.Media.DATA + "=?", new String[] {path}, null);
} else {
// We can't get metadata from the file/stream itself yet, because
// that API is hidden, so instead we display the URI being played
Expand Down Expand Up @@ -274,7 +273,7 @@ private void showPostPrepareUI() {
}
updatePlayPause();
}

private OnAudioFocusChangeListener mAudioFocusListener = new OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
if (mPlayer == null) {
Expand Down Expand Up @@ -305,14 +304,14 @@ public void onAudioFocusChange(int focusChange) {
updatePlayPause();
}
};

private void start() {
mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
mPlayer.start();
mProgressRefresher.postDelayed(new ProgressRefresher(), 200);
}

public void setNames() {
if (TextUtils.isEmpty(mTextLine1.getText())) {
mTextLine1.setText(mUri.getLastPathSegment());
Expand All @@ -325,7 +324,6 @@ public void setNames() {
}

class ProgressRefresher implements Runnable {

@Override
public void run() {
if (mPlayer != null && !mSeeking && mDuration != 0) {
Expand All @@ -337,7 +335,7 @@ public void run() {
}
}
}

private void updatePlayPause() {
ImageButton b = (ImageButton) findViewById(R.id.playpause);
if (b != null && mPlayer != null) {
Expand Down Expand Up @@ -392,7 +390,7 @@ public void playPauseClicked(View v) {
}
updatePlayPause();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
Expand All @@ -414,7 +412,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
item.setVisible(false);
return false;
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
Expand Down Expand Up @@ -467,8 +465,9 @@ public void setActivity(AudioPreview activity) {
}

public void setDataSourceAndPrepare(Uri uri) throws IllegalArgumentException,
SecurityException, IllegalStateException, IOException {
setDataSource(mActivity,uri);
SecurityException,
IllegalStateException, IOException {
setDataSource(mActivity, uri);
prepareAsync();
}

Expand All @@ -485,5 +484,4 @@ boolean isPrepared() {
return mIsPrepared;
}
}

}
6 changes: 2 additions & 4 deletions src/com/android/music/CheckableRelativeLayout.java
Expand Up @@ -29,9 +29,7 @@
public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
private boolean mChecked;

private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_checked
};
private static final int[] CHECKED_STATE_SET = {android.R.attr.state_checked};

public CheckableRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
Expand All @@ -49,7 +47,7 @@ protected int[] onCreateDrawableState(int extraSpace) {
public void toggle() {
setChecked(!mChecked);
}

public boolean isChecked() {
return mChecked;
}
Expand Down
49 changes: 22 additions & 27 deletions src/com/android/music/CreatePlaylist.java
Expand Up @@ -35,8 +35,7 @@
import android.widget.EditText;
import android.widget.TextView;

public class CreatePlaylist extends Activity
{
public class CreatePlaylist extends Activity {
private EditText mPlaylist;
private TextView mPrompt;
private Button mSaveButton;
Expand All @@ -48,20 +47,20 @@ public void onCreate(Bundle icicle) {

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.create_playlist);
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT);
getWindow().setLayout(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);

mPrompt = (TextView)findViewById(R.id.prompt);
mPlaylist = (EditText)findViewById(R.id.playlist);
mPrompt = (TextView) findViewById(R.id.prompt);
mPlaylist = (EditText) findViewById(R.id.playlist);
mSaveButton = (Button) findViewById(R.id.create);
mSaveButton.setOnClickListener(mOpenClicked);

((Button)findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});

String defaultname = icicle != null ? icicle.getString("defaultname") : makePlaylistName();
if (defaultname == null) {
finish();
Expand All @@ -74,7 +73,7 @@ public void onClick(View v) {
mPlaylist.setSelection(defaultname.length());
mPlaylist.addTextChangedListener(mTextWatcher);
}

TextWatcher mTextWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// don't care about this one
Expand All @@ -97,12 +96,11 @@ public void afterTextChanged(Editable s) {
// don't care about this one
}
};

private int idForplaylist(String name) {
Cursor c = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Playlists._ID },
MediaStore.Audio.Playlists.NAME + "=?",
new String[] { name },
new String[] {MediaStore.Audio.Playlists._ID},
MediaStore.Audio.Playlists.NAME + "=?", new String[] {name},
MediaStore.Audio.Playlists.NAME);
int id = -1;
if (c != null) {
Expand All @@ -114,38 +112,34 @@ private int idForplaylist(String name) {
}
return id;
}

@Override
public void onSaveInstanceState(Bundle outcicle) {
outcicle.putString("defaultname", mPlaylist.getText().toString());
}

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

private String makePlaylistName() {

String template = getString(R.string.new_playlist_name_template);
int num = 1;

String[] cols = new String[] {
MediaStore.Audio.Playlists.NAME
};
String[] cols = new String[] {MediaStore.Audio.Playlists.NAME};
ContentResolver resolver = getContentResolver();
String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
Cursor c = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
cols, whereclause, null,
MediaStore.Audio.Playlists.NAME);
Cursor c = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols,
whereclause, null, MediaStore.Audio.Playlists.NAME);

if (c == null) {
return null;
}

String suggestedname;
suggestedname = String.format(template, num++);

// Need to loop until we've made 1 full pass through without finding a match.
// Looping more than once shouldn't happen very often, but will happen if
// you have playlists named "New Playlist 1"/10/2/3/4/5/6/7/8/9, where
Expand All @@ -155,7 +149,7 @@ private String makePlaylistName() {
while (!done) {
done = true;
c.moveToFirst();
while (! c.isAfterLast()) {
while (!c.isAfterLast()) {
String playlistname = c.getString(0);
if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
suggestedname = String.format(template, num++);
Expand All @@ -167,7 +161,7 @@ private String makePlaylistName() {
c.close();
return suggestedname;
}

private View.OnClickListener mOpenClicked = new View.OnClickListener() {
public void onClick(View v) {
String name = mPlaylist.getText().toString();
Expand All @@ -176,7 +170,8 @@ public void onClick(View v) {
int id = idForplaylist(name);
Uri uri;
if (id >= 0) {
uri = ContentUris.withAppendedId(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, id);
uri = ContentUris.withAppendedId(
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, id);
MusicUtils.clearPlaylist(CreatePlaylist.this, id);
} else {
ContentValues values = new ContentValues(1);
Expand Down
17 changes: 8 additions & 9 deletions src/com/android/music/DeleteItems.java
Expand Up @@ -25,11 +25,10 @@
import android.widget.Button;
import android.widget.TextView;

public class DeleteItems extends Activity
{
public class DeleteItems extends Activity {
private TextView mPrompt;
private Button mButton;
private long [] mItemList;
private long[] mItemList;

@Override
public void onCreate(Bundle icicle) {
Expand All @@ -38,14 +37,14 @@ public void onCreate(Bundle icicle) {

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.confirm_delete);
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT);
getWindow().setLayout(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);

mPrompt = (TextView)findViewById(R.id.prompt);
mPrompt = (TextView) findViewById(R.id.prompt);
mButton = (Button) findViewById(R.id.delete);
mButton.setOnClickListener(mButtonClicked);

((Button)findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
Expand All @@ -54,10 +53,10 @@ public void onClick(View v) {
Bundle b = getIntent().getExtras();
String desc = b.getString("description");
mItemList = b.getLongArray("items");

mPrompt.setText(desc);
}

private View.OnClickListener mButtonClicked = new View.OnClickListener() {
public void onClick(View v) {
// delete the selected item(s)
Expand Down

0 comments on commit 879edc6

Please sign in to comment.