Search in sources :

Example 16 with UP

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();
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification) IntList(de.danoeh.antennapod.core.util.IntList) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v7.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 17 with UP

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);
}
Also used : NavigationView(android.support.design.widget.NavigationView) TabLayout(android.support.design.widget.TabLayout) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 18 with UP

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);
        }
    });
}
Also used : Window(android.view.Window) Palette(android.support.v7.graphics.Palette) Transformation(android.view.animation.Transformation) ColorDrawable(android.graphics.drawable.ColorDrawable) Animation(android.view.animation.Animation)

Example 19 with UP

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);
}
Also used : SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ActionBar(android.support.v7.app.ActionBar)

Example 20 with UP

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);
}
Also used : ScrollView(android.widget.ScrollView) Drawable(android.graphics.drawable.Drawable) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) View(android.view.View)

Aggregations

View (android.view.View)135 RecyclerView (android.support.v7.widget.RecyclerView)97 TextView (android.widget.TextView)69 Toolbar (android.support.v7.widget.Toolbar)50 ActionBar (android.support.v7.app.ActionBar)49 Intent (android.content.Intent)44 ImageView (android.widget.ImageView)41 AdapterView (android.widget.AdapterView)33 ArrayList (java.util.ArrayList)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)29 DialogInterface (android.content.DialogInterface)25 AlertDialog (android.support.v7.app.AlertDialog)25 ListView (android.widget.ListView)25 Bundle (android.os.Bundle)22 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 SharedPreferences (android.content.SharedPreferences)21 Preference (android.support.v7.preference.Preference)20 GridLayoutManager (android.support.v7.widget.GridLayoutManager)19 SuppressLint (android.annotation.SuppressLint)16 Point (android.graphics.Point)16