• Lesson 190. Notifications. channels
    Android Lessons

    Lesson 190. Notifications. channels

    Android Oreo (API 26) has the ability to create message channels. In this lesson we will understand how to do it and why it is necessary. For each application, the user can customize the message. To do this, go to the system settings, select Apps there, find in the list and open the desired program and select the Notifications section. By default they look like this: The settings are a little bit, and they will touch all the messages from this app. Channels allow you to expand these settings and apply them selectively. The application developer creates a channel and specifies its channel ID when creating messages. The user in…

  • Lesson 189. Notifications. message grouping
    Android Lessons

    Lesson 189. Notifications. message grouping

    Android 7 (API 24) has the ability to group messages. Even if you don’t explicitly implement it, the system will create the group itself if you have 4 or more messages. It looks like this: You can expand / collapse / delete a group. You can also tap or delete a separate message. If the number of messages in a group is less than 4, then the messages become separate from the group. All your messages will fall into one unnamed group. By default, clicking on this group will open the application. Let’s look at what group management options we have been given. We can: 1) create multiple groups and…

  • Lesson 188. Notifications. custom messages
    Android Lessons

    Lesson 188. Notifications. custom messages

    Android enables us to create a layout for messages ourselves. Consider a simple example: layout / notification.xml Height 64dp – standard message height. We will only show TextView. It is recommended to use @ style / TextAppearance.Compat.Notification. * Styles for your text to be displayed correctly on any version of Android. The message binder code looks like this: RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification); remoteViews.setTextViewText(R.id.textView, "Custom notification text"); remoteViews.setOnClickPendingIntent(R.id.root, rootPendingIntent); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContent(remoteViews); We create RemoteViews from the layout file. With the setTextViewText method, we place the text in View c id = R.id.textView. And with the setOnClickPendingIntent method, we specify PendingIntent, which will be called…

  • Lesson 187. Notifications. Action buttons. Reply.
    Android Lessons

    Lesson 187. Notifications. Action buttons. Reply.

    Android 4.1 has the ability to add buttons to messages. This is done using the addAction method. Intent deleteIntent = new Intent(this, MyService.class); deleteIntent.setAction("ru.startandroid.notifications.action_delete"); PendingIntent deletePendingIntent = PendingIntent.getService(this, 0, deleteIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Title") .setContentText("Notification text") .addAction(android.R.drawable.ic_delete, "Delete", deletePendingIntent); We first create a PendingIntent, which will be called after a button is clicked. Then we pass it to the addAction method, and with it the icon and text for the button. A button will be displayed when the message is opened. Pressing the button will not close the message itself. If you need to close it, use cancel in the click handler. You can add up…

  • Lesson 186. Notifications. advanced messages
    Android Lessons

    Lesson 186. Notifications. advanced messages

    Android 4.1 (API 16) has advanced messages. Pulling down the message will display additional information. To create an advanced message, you must add a style to the builder. There are several styles. They are all heirs to the abstract class NotificationCompat.Style. It is usually clear from the style name what it can be used for. Consider, for example, the BigTextStyle style to reflect long text. Next I will give only the code of the builder. And how to get and display messages from the builder, you can see in the previous lessons. code: String longText = "To have a notification appear in an expanded view, " + "first create a…

  • Lesson 185. Notifications. Activity Opening Modes
    Android Lessons

    Lesson 185. Notifications. Activity Opening Modes

    In the last lesson, we already looked at how to display Activity after clicking on a message. But there was a simple case. In this lesson, let’s look at more interesting cases. To understand everything that goes on, you will need knowledge of Activity Tasks Stack. You can read about this in the documentation or in Lesson 116. For example, let’s take a mail application consisting of three screens: a list of letters (MainActivity), the contents of a letter (DetailsActivity) and information about the new version (WhatsNewActivity). When you start MainActivity, it displays the letters, and when you click on the letter, DetailsActivity opens with the contents of the letter.…

  • Lesson 184. Android Notifications. Message. foundations
    Android Lessons

    Lesson 184. Android Notifications. Message. foundations

    Notifications are messages that the user sees at the top of the screen when he or she receives a new email, message, update, etc. In the next few lessons, we will take a closer look at what opportunities developers have for displaying messages. In this tutorial, we will cover the basics of displaying / updating / deleting a message and handling it. display The simple message creation code looks like this: NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Title") .setContentText("Notification text"); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(1, notification); We use a builder that specifies an icon, title and text for the message. With the build method, we…

  • Lesson 183. ConstraintSet. ConstraintLayout software setup
    Android Lessons

    Lesson 183. ConstraintSet. ConstraintLayout software setup

    With ConstraintSet you can programmatically create bindings, chains, barriers and customize them. For a complete list of operations, see the official documentation. I’ll look at some of them. For examples I will use the following code: import android.os.Bundle; import android.support.constraint.ConstraintLayout; import android.support.constraint.ConstraintSet; import android.support.transition.TransitionManager; import android.support.v7.app.AppCompatActivity; import butterknife.BindDimen; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class MainActivity extends AppCompatActivity { @BindView(R.id.container) ConstraintLayout constraintLayout; @BindDimen(R.dimen.some_margin) int someMargin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); } @OnClick(R.id.button) void onButtonClick() { ConstraintSet set = new ConstraintSet(); // copy constraints settings from current ConstraintLayout to set set.clone(constraintLayout); // change constraints settings changeConstraints(set); // enable animation TransitionManager.beginDelayedTransition(constraintLayout); // apply constraints settings from set…

  • Lesson 182. ConstraintLayout: chain, weight, barrier, group, circular
    Android Lessons

    Lesson 182. ConstraintLayout: chain, weight, barrier, group, circular

    We continue to consider ConstraintLayout. Chain Chain can be translated as a chain. A chain will allow you to distribute multiple View evenly in the available free space. To create a chain, you must select View and center them horizontally or vertically. The chain can be in one of three modes. spread Free space is evenly distributed between the View and the boundaries of the parent. spread_inside Free space is evenly distributed between View only. Extreme View pressed against the boundaries of the father. packed Free space is evenly distributed between the Extreme View and the borders of the parent. You can use margin to indent between View. Chain modes…

  • Lesson 181. ConstraintLayout: match_constraints, toolbar tools, guidelines, aspect ratio
    Android Lessons

    Lesson 181. ConstraintLayout: match_constraints, toolbar tools, guidelines, aspect ratio

    We continue to consider ConstraintLayout. match_constraints At ConstraintLayout, we can still use wrap_content as a width / height View or specify a fixed size in dp. But match_parent is not recommended here. The help is written as follows:You should not use match_parent for any view in a ConstraintLayout. Instead of using “match constraints” (0dp) Instead of match_parent, we are offered to use match_constraints, aka 0dp. If match_parent extends View to its parent size, match_constraints View will take up space available between the objects to which it is attached. Let’s look at all three modes in the TextView example, which is tied to the left border on the left and the…