use of android.support.v7.widget.helper.ItemTouchHelper.UP in project AntennaPod by AntennaPod.
the class PlaybackService method setupNotification.
/**
* Prepares notification and starts the service in the foreground.
*/
private void setupNotification(final PlaybackServiceMediaPlayer.PSMPInfo info) {
final PendingIntent pIntent = PendingIntent.getActivity(this, 0, PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT);
if (notificationSetupThread != null) {
notificationSetupThread.interrupt();
}
Runnable notificationSetupTask = new Runnable() {
Bitmap icon = null;
@Override
public void run() {
Log.d(TAG, "Starting background work");
if (android.os.Build.VERSION.SDK_INT >= 11) {
if (info.playable != null) {
int iconSize = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
try {
icon = Glide.with(PlaybackService.this).load(info.playable.getImageLocation()).asBitmap().diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).centerCrop().into(iconSize, iconSize).get();
} catch (Throwable tr) {
Log.e(TAG, "Error loading the media icon for the notification", tr);
}
}
}
if (icon == null) {
icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext()));
}
if (mediaPlayer == null) {
return;
}
PlayerStatus playerStatus = mediaPlayer.getPlayerStatus();
final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
if (!Thread.currentThread().isInterrupted() && started && info.playable != null) {
String contentText = info.playable.getEpisodeTitle();
String contentTitle = info.playable.getFeedTitle();
Notification notification;
// Builder is v7, even if some not overwritten methods return its parent's v4 interface
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(PlaybackService.this).setContentTitle(contentTitle).setContentText(contentText).setOngoing(false).setContentIntent(pIntent).setLargeIcon(icon).setSmallIcon(smallIcon).setWhen(// we don't need the time
0).setPriority(// set notification priority
UserPreferences.getNotifyPriority());
IntList compactActionList = new IntList();
// we start and 0 and then increment by 1 for each call to addAction
int numActions = 0;
if (isCasting) {
Intent stopCastingIntent = new Intent(PlaybackService.this, PlaybackService.class);
stopCastingIntent.putExtra(EXTRA_CAST_DISCONNECT, true);
PendingIntent stopCastingPendingIntent = PendingIntent.getService(PlaybackService.this, numActions, stopCastingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_media_cast_disconnect, getString(R.string.cast_disconnect_label), stopCastingPendingIntent);
numActions++;
}
// always let them rewind
PendingIntent rewindButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_REWIND, numActions);
notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent);
if (UserPreferences.showRewindOnCompactNotification()) {
compactActionList.add(numActions);
}
numActions++;
if (playerStatus == PlayerStatus.PLAYING) {
PendingIntent pauseButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_PAUSE, numActions);
//pause action
notificationBuilder.addAction(//pause action
android.R.drawable.ic_media_pause, getString(R.string.pause_label), pauseButtonPendingIntent);
compactActionList.add(numActions++);
} else {
PendingIntent playButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_PLAY, numActions);
//play action
notificationBuilder.addAction(//play action
android.R.drawable.ic_media_play, getString(R.string.play_label), playButtonPendingIntent);
compactActionList.add(numActions++);
}
// ff follows play, then we have skip (if it's present)
PendingIntent ffButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, numActions);
notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent);
if (UserPreferences.showFastForwardOnCompactNotification()) {
compactActionList.add(numActions);
}
numActions++;
if (UserPreferences.isFollowQueue()) {
PendingIntent skipButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_NEXT, numActions);
notificationBuilder.addAction(android.R.drawable.ic_media_next, getString(R.string.skip_episode_label), skipButtonPendingIntent);
if (UserPreferences.showSkipOnCompactNotification()) {
compactActionList.add(numActions);
}
numActions++;
}
PendingIntent stopButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_STOP, numActions);
notificationBuilder.setStyle(new android.support.v7.app.NotificationCompat.MediaStyle().setMediaSession(mediaSession.getSessionToken()).setShowActionsInCompactView(compactActionList.toArray()).setShowCancelButton(true).setCancelButtonIntent(stopButtonPendingIntent)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setColor(NotificationCompat.COLOR_DEFAULT);
notification = notificationBuilder.build();
if (playerStatus == PlayerStatus.PLAYING || playerStatus == PlayerStatus.PREPARING || playerStatus == PlayerStatus.SEEKING || isCasting) {
startForeground(NOTIFICATION_ID, notification);
} else {
stopForeground(false);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
Log.d(TAG, "Notification set up");
}
}
};
notificationSetupThread = new Thread(notificationSetupTask);
notificationSetupThread.start();
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project AdMoney by ErnestoGonAr.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bd = new BDHandlerAM(this);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Lightning-Browser by anthonycr.
the class BrowserActivity method changeToolbarBackground.
/**
* Animates the color of the toolbar from one color to another. Optionally animates
* the color of the tab background, for use when the tabs are displayed on the top
* of the screen.
*
* @param favicon the Bitmap to extract the color from
* @param tabBackground the optional LinearLayout to color
*/
@Override
public void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable final Drawable tabBackground) {
final int defaultColor = ContextCompat.getColor(this, R.color.primary_color);
if (mCurrentUiColor == Color.BLACK) {
mCurrentUiColor = defaultColor;
}
Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// OR with opaque black to remove transparency glitches
int color = 0xff000000 | palette.getVibrantColor(defaultColor);
// Lighten up the dark color if it is
final int finalColor;
// too dark
if (!mShowTabsInDrawer || Utils.isColorTooDark(color)) {
finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f);
} else {
finalColor = color;
}
final Window window = getWindow();
if (!mShowTabsInDrawer) {
window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
}
final int startSearchColor = getSearchBarColor(mCurrentUiColor, defaultColor);
final int finalSearchColor = getSearchBarColor(finalColor, defaultColor);
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final int color = DrawableUtils.mixColor(interpolatedTime, mCurrentUiColor, finalColor);
if (mShowTabsInDrawer) {
mBackground.setColor(color);
Handlers.MAIN.post(new Runnable() {
@Override
public void run() {
window.setBackgroundDrawable(mBackground);
}
});
} else if (tabBackground != null) {
tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
mCurrentUiColor = color;
mToolbarLayout.setBackgroundColor(color);
mSearchBackground.getBackground().setColorFilter(DrawableUtils.mixColor(interpolatedTime, startSearchColor, finalSearchColor), PorterDuff.Mode.SRC_IN);
}
};
animation.setDuration(300);
mToolbarLayout.startAnimation(animation);
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project android by JetBrains.
the class NavigationDrawerFragment method setUp.
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* @param fragmentId The android:id of this fragment in its activity's layout.
* @param drawerLayout The DrawerLayout containing this fragment's UI.
*/
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close) {
/* "close drawer" description for accessibility */
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit();
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
};
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project HumaneApp by Ganesh1010.
the class UserProfileActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_profile);
toolbar = (Toolbar) findViewById(R.id.toolbar_user_profile);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("");
// Back Arrow
final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material);
upArrow.setColorFilter(ContextCompat.getColor(this, R.color.colorTextIcons), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
// Focusing up the page
scrollView = ((ScrollView) findViewById(R.id.scrollview_user_profile));
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_UP);
}
});
// Edit button functionality
editImageButton = (CircleImageView) findViewById(R.id.edit_imagebutton_user_profile);
editImageButton.setOnClickListener(UserProfileActivity.this);
// My Organisation Button
myOrgButton = (Button) findViewById(R.id.my_org_button_edit_profile);
myOrgButton.setOnClickListener(UserProfileActivity.this);
}
Aggregations