Skip to content

Commit

Permalink
Updated sample requirements
Browse files Browse the repository at this point in the history
- Sample readme
- metadata file
- Screenshots folder(with at least one screenshot)
- Code formatted
  • Loading branch information
gonzalonm committed Sep 21, 2016
1 parent 328a90f commit bca8d21
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 74 deletions.
144 changes: 72 additions & 72 deletions DirectReply/DirectReply/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,80 +27,80 @@ protected override void OnCreate(Bundle savedInstanceState)
// and attach an event to it
var button = FindViewById<Button>(Resource.Id.myButton);

// Set button listener
button.Click += (sender, args) =>
{
OnButtonClick();
};
// Set button listener
button.Click += (sender, args) =>
{
OnButtonClick();
};
}

private void OnButtonClick()
{
requestCode++;

// Build PendingIntent
var pendingIntent = MakePendingIntent();

var replyText = GetString(Resource.String.reply_text);

// Create remote input that will read text
var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(KEY_TEXT_REPLY)
.SetLabel(replyText)
.Build();

// Build action for noticiation
var action = new NotificationCompat.Action.Builder(Resource.Drawable.action_reply, replyText, pendingIntent)
.AddRemoteInput(remoteInput)
.Build();

// Build notification
var notification = new NotificationCompat.Builder(this)
.SetSmallIcon(Resource.Drawable.reply)
.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.avatar))
.SetContentText("Hey, it is James! What's up?")
.SetContentTitle(GetString(Resource.String.message))
.SetAutoCancel(true)
.AddAction(action)
.Build();

// Notify
using (var notificationManager = NotificationManagerCompat.From(this))
{
notificationManager.Notify(requestCode, notification);
}
}

private PendingIntent MakePendingIntent()
{
PendingIntent pendingIntent = null;

if ((int)Build.VERSION.SdkInt >= (int)BuildVersionCodes.N)
{
// >= Android N
var intent = new Intent(REPLY_ACTION)
.AddFlags(ActivityFlags.IncludeStoppedPackages)
.SetAction(REPLY_ACTION)
.PutExtra(REQUEST_CODE_KEY, requestCode);

pendingIntent = PendingIntent.GetBroadcast(this,
requestCode,
intent,
PendingIntentFlags.UpdateCurrent);
}
else
{
// < Android N
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);

pendingIntent = PendingIntent.GetActivity(this,
requestCode,
intent,
PendingIntentFlags.UpdateCurrent);
}

return pendingIntent;
}
private void OnButtonClick()
{
requestCode++;

// Build PendingIntent
var pendingIntent = MakePendingIntent();

var replyText = GetString(Resource.String.reply_text);

// Create remote input that will read text
var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(KEY_TEXT_REPLY)
.SetLabel(replyText)
.Build();

// Build action for noticiation
var action = new NotificationCompat.Action.Builder(Resource.Drawable.action_reply, replyText, pendingIntent)
.AddRemoteInput(remoteInput)
.Build();

// Build notification
var notification = new NotificationCompat.Builder(this)
.SetSmallIcon(Resource.Drawable.reply)
.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.avatar))
.SetContentText("Hey, it is James! What's up?")
.SetContentTitle(GetString(Resource.String.message))
.SetAutoCancel(true)
.AddAction(action)
.Build();

// Notify
using (var notificationManager = NotificationManagerCompat.From(this))
{
notificationManager.Notify(requestCode, notification);
}
}

private PendingIntent MakePendingIntent()
{
PendingIntent pendingIntent = null;

if ((int)Build.VERSION.SdkInt >= (int)BuildVersionCodes.N)
{
// >= Android N
var intent = new Intent(REPLY_ACTION)
.AddFlags(ActivityFlags.IncludeStoppedPackages)
.SetAction(REPLY_ACTION)
.PutExtra(REQUEST_CODE_KEY, requestCode);

pendingIntent = PendingIntent.GetBroadcast(this,
requestCode,
intent,
PendingIntentFlags.UpdateCurrent);
}
else
{
// < Android N
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);

pendingIntent = PendingIntent.GetActivity(this,
requestCode,
intent,
PendingIntentFlags.UpdateCurrent);
}

return pendingIntent;
}
}
}

2 changes: 1 addition & 1 deletion DirectReply/DirectReply/MessageReplyReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void OnReceive(Context context, Intent intent)
{
if (!MainActivity.REPLY_ACTION.Equals(intent.Action))
return;


var requestId = intent.GetIntExtra(MainActivity.REQUEST_CODE_KEY, -1);
if (requestId == -1)
Expand Down
2 changes: 1 addition & 1 deletion DirectReply/DirectReply/Resources/layout/Main.axml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
Expand Down
12 changes: 12 additions & 0 deletions DirectReply/Metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<SampleMetadata>
<ID>C6BE12C4-B54A-43E8-9EB5-54DAE2675A12</ID>
<IsFullApplication>false</IsFullApplication>
<Level>Beginner</Level>
<Tags>User Interface, Notifications</Tags>
<SupportedPlatforms>Android</SupportedPlatforms>
<LicenseRequirement>Starter</LicenseRequirement>
<Brief>Demonstrates DirectReply feature for Android 7.0</Brief>
<Gallery>true</Gallery>
<HideZip>false</HideZip><!--IF references code outside folder root, do not ZIP-->
</SampleMetadata>
Empty file added DirectReply/README.md
Empty file.
Binary file added DirectReply/Screenshots/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DirectReply/Screenshots/replied_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DirectReply/Screenshots/reply_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DirectReply/Screenshots/replying_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bca8d21

Please sign in to comment.