use of android.support.v7.app.AppCompatActivity in project Shuttle by timusus.
the class SuggestedFragment method onOverflowClick.
@Override
public void onOverflowClick(View v, int position, Object item) {
if (item instanceof AlbumArtist) {
PopupMenu menu = new PopupMenu(SuggestedFragment.this.getActivity(), v);
MenuUtils.addAlbumArtistMenuOptions(getActivity(), menu);
MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, (AlbumArtist) item);
menu.show();
} else if (item instanceof Album) {
PopupMenu menu = new PopupMenu(SuggestedFragment.this.getActivity(), v);
MenuUtils.addAlbumMenuOptions(getActivity(), menu);
MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, (Album) item);
menu.show();
} else if (item instanceof Song) {
PopupMenu menu = new PopupMenu(SuggestedFragment.this.getActivity(), v);
MenuUtils.addSongMenuOptions(getActivity(), menu);
MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, (Song) item, menuItem -> {
switch(menuItem.getItemId()) {
case BLACKLIST:
{
BlacklistHelper.addToBlacklist(((Song) item));
suggestedAdapter.removeItem(position);
return true;
}
}
return false;
});
menu.show();
}
}
use of android.support.v7.app.AppCompatActivity in project Shuttle by timusus.
the class AlbumFragment method onOverflowClick.
@Override
public void onOverflowClick(View v, int position, Album album) {
PopupMenu menu = new PopupMenu(AlbumFragment.this.getActivity(), v);
MenuUtils.addAlbumMenuOptions(getActivity(), menu);
MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, album);
menu.show();
}
use of android.support.v7.app.AppCompatActivity in project Shuttle by timusus.
the class QueueFragment method onOverflowClick.
@Override
public void onOverflowClick(View v, int position, Song song) {
PopupMenu menu = new PopupMenu(QueueFragment.this.getActivity(), v);
MenuUtils.addQueueMenuOptions(getActivity(), menu);
MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, song, item -> {
switch(item.getItemId()) {
case REMOVE:
{
MusicUtils.removeFromQueue(song, true);
songAdapter.removeItem(position);
return true;
}
case BLACKLIST:
{
BlacklistHelper.addToBlacklist(song);
MusicUtils.removeFromQueue(song, true);
songAdapter.removeItem(position);
return true;
}
}
return false;
});
menu.show();
}
use of android.support.v7.app.AppCompatActivity in project BlurDialogFragment by tvbarthel.
the class BlurDialogEngine method blur.
/**
* Blur the given bitmap and add it to the activity.
*
* @param bkg should be a bitmap of the background.
* @param view background view.
*/
private void blur(Bitmap bkg, View view) {
long startMs = System.currentTimeMillis();
//define layout params to the previous imageView in order to match its parent
mBlurredBackgroundLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
//overlay used to build scaled preview and blur background
Bitmap overlay = null;
//evaluate top offset due to action bar, 0 if the actionBar should be blurred.
int actionBarHeight;
if (mBlurredActionBar) {
actionBarHeight = 0;
} else {
actionBarHeight = getActionBarHeight();
}
//evaluate top offset due to status bar
int statusBarHeight = 0;
if ((mHoldingActivity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0) {
//not in fullscreen mode
statusBarHeight = getStatusBarHeight();
}
// on content bellow the status.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && isStatusBarTranslucent()) {
statusBarHeight = 0;
}
final int topOffset = actionBarHeight + statusBarHeight;
// evaluate bottom or right offset due to navigation bar.
int bottomOffset = 0;
int rightOffset = 0;
final int navBarSize = getNavigationBarOffset();
if (mHoldingActivity.getResources().getBoolean(R.bool.blur_dialog_has_bottom_navigation_bar)) {
bottomOffset = navBarSize;
} else {
rightOffset = navBarSize;
}
//add offset to the source boundaries since we don't want to blur actionBar pixels
Rect srcRect = new Rect(0, topOffset, bkg.getWidth() - rightOffset, bkg.getHeight() - bottomOffset);
//in order to keep the same ratio as the one which will be used for rendering, also
//add the offset to the overlay.
double height = Math.ceil((view.getHeight() - topOffset - bottomOffset) / mDownScaleFactor);
double width = Math.ceil(((view.getWidth() - rightOffset) * height / (view.getHeight() - topOffset - bottomOffset)));
// Render script doesn't work with RGB_565
if (mUseRenderScript) {
overlay = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
} else {
overlay = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.RGB_565);
}
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || mHoldingActivity instanceof ActionBarActivity || mHoldingActivity instanceof AppCompatActivity) {
//add offset as top margin since actionBar height must also considered when we display
// the blurred background. Don't want to draw on the actionBar.
mBlurredBackgroundLayoutParams.setMargins(0, actionBarHeight, 0, 0);
mBlurredBackgroundLayoutParams.gravity = Gravity.TOP;
}
} catch (NoClassDefFoundError e) {
// no dependency to appcompat, that means no additional top offset due to actionBar.
mBlurredBackgroundLayoutParams.setMargins(0, 0, 0, 0);
}
//scale and draw background view on the canvas overlay
Canvas canvas = new Canvas(overlay);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
//build drawing destination boundaries
final RectF destRect = new RectF(0, 0, overlay.getWidth(), overlay.getHeight());
//draw background from source area in source background to the destination area on the overlay
canvas.drawBitmap(bkg, srcRect, destRect, paint);
//apply fast blur on overlay
if (mUseRenderScript) {
overlay = RenderScriptBlurHelper.doBlur(overlay, mBlurRadius, true, mHoldingActivity);
} else {
overlay = FastBlurHelper.doBlur(overlay, mBlurRadius, true);
}
if (mDebugEnable) {
String blurTime = (System.currentTimeMillis() - startMs) + " ms";
Log.d(TAG, "Blur method : " + (mUseRenderScript ? "RenderScript" : "FastBlur"));
Log.d(TAG, "Radius : " + mBlurRadius);
Log.d(TAG, "Down Scale Factor : " + mDownScaleFactor);
Log.d(TAG, "Blurred achieved in : " + blurTime);
Log.d(TAG, "Allocation : " + bkg.getRowBytes() + "ko (screen capture) + " + overlay.getRowBytes() + "ko (blurred bitmap)" + (!mUseRenderScript ? " + temp buff " + overlay.getRowBytes() + "ko." : "."));
Rect bounds = new Rect();
Canvas canvas1 = new Canvas(overlay);
paint.setColor(Color.BLACK);
paint.setAntiAlias(true);
paint.setTextSize(20.0f);
paint.getTextBounds(blurTime, 0, blurTime.length(), bounds);
canvas1.drawText(blurTime, 2, bounds.height(), paint);
}
//set bitmap in an image view for final rendering
mBlurredBackgroundView = new ImageView(mHoldingActivity);
mBlurredBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP);
mBlurredBackgroundView.setImageDrawable(new BitmapDrawable(mHoldingActivity.getResources(), overlay));
}
use of android.support.v7.app.AppCompatActivity in project WordPress-Android by wordpress-mobile.
the class CommentsListFragment method getAdapter.
private CommentAdapter getAdapter() {
if (mAdapter == null) {
// called after comments have been loaded
CommentAdapter.OnDataLoadedListener dataLoadedListener = new CommentAdapter.OnDataLoadedListener() {
@Override
public void onDataLoaded(boolean isEmpty) {
if (!isAdded())
return;
if (!isEmpty) {
// Hide the empty view if there are already some displayed comments
mFilteredCommentsView.hideEmptyView();
} else if (!mIsUpdatingComments) {
// Change LOADING to NO_CONTENT message
mFilteredCommentsView.updateEmptyView(EmptyViewMessageType.NO_CONTENT);
}
}
};
// adapter calls this to request more comments from server when it reaches the end
CommentAdapter.OnLoadMoreListener loadMoreListener = new CommentAdapter.OnLoadMoreListener() {
@Override
public void onLoadMore() {
if (mCanLoadMoreComments && !mIsUpdatingComments) {
updateComments(true);
}
}
};
// adapter calls this when selected comments have changed (CAB)
CommentAdapter.OnSelectedItemsChangeListener changeListener = new CommentAdapter.OnSelectedItemsChangeListener() {
@Override
public void onSelectedItemsChanged() {
if (mActionMode != null) {
if (getSelectedCommentCount() == 0) {
mActionMode.finish();
} else {
updateActionModeTitle();
// must invalidate to ensure onPrepareActionMode is called
mActionMode.invalidate();
}
}
}
};
CommentAdapter.OnCommentPressedListener pressedListener = new CommentAdapter.OnCommentPressedListener() {
@Override
public void onCommentPressed(int position, View view) {
CommentModel comment = getAdapter().getItem(position);
if (comment == null) {
return;
}
if (mActionMode == null) {
mFilteredCommentsView.invalidate();
if (getActivity() instanceof OnCommentSelectedListener) {
((OnCommentSelectedListener) getActivity()).onCommentSelected(comment.getRemoteCommentId());
}
} else {
getAdapter().toggleItemSelected(position, view);
}
}
@Override
public void onCommentLongPressed(int position, View view) {
// enable CAB if it's not already enabled
if (mActionMode == null) {
if (getActivity() instanceof AppCompatActivity) {
((AppCompatActivity) getActivity()).startSupportActionMode(new ActionModeCallback());
getAdapter().setEnableSelection(true);
getAdapter().setItemSelected(position, true, view);
}
} else {
getAdapter().toggleItemSelected(position, view);
}
}
};
mAdapter = new CommentAdapter(getActivity(), mSite);
mAdapter.setOnCommentPressedListener(pressedListener);
mAdapter.setOnDataLoadedListener(dataLoadedListener);
mAdapter.setOnLoadMoreListener(loadMoreListener);
mAdapter.setOnSelectedItemsChangeListener(changeListener);
}
return mAdapter;
}
Aggregations