Skip to content

Commit 6263e11

Browse files
committed
custom section added
1 parent 6969ae2 commit 6263e11

File tree

14 files changed

+12934
-23444
lines changed

14 files changed

+12934
-23444
lines changed
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
package com.reactnativecustomtimernotification
2+
3+
import android.app.*
4+
import android.content.Intent
5+
import android.graphics.Bitmap
6+
import android.graphics.BitmapFactory
7+
import android.graphics.Color
8+
import android.os.Build
9+
import android.util.Log
10+
import android.util.TypedValue
11+
import android.view.View
12+
import android.widget.FrameLayout
13+
import android.widget.RemoteViews
14+
import androidx.core.app.NotificationCompat
15+
import com.facebook.react.bridge.Callback
16+
import com.facebook.react.bridge.ReactApplicationContext
17+
import com.facebook.react.bridge.ReactContextBaseJavaModule
18+
import com.facebook.react.bridge.ReactMethod
19+
import com.facebook.react.bridge.ReadableMap
20+
import android.util.Base64;
21+
22+
23+
class CustomNotificationModule: ReactContextBaseJavaModule {
24+
var loading : Boolean = false;
25+
lateinit var notificationManager: NotificationManager
26+
lateinit var builder: Notification.Builder
27+
val channelId:String = "255"
28+
var packageName: String = ""
29+
lateinit var myContext: ReactApplicationContext;
30+
31+
constructor (context:ReactApplicationContext):super(context){
32+
this.loading= true;
33+
this.myContext= context
34+
this.packageName=this.myContext.getPackageName()
35+
}
36+
37+
override fun getName(): String {
38+
return "CustomNotificationModule"
39+
}
40+
private fun adjustViewHeight(resID: Int, pixels: Int, activity: Activity) {
41+
(activity.findViewById<View>(resID).layoutParams as FrameLayout.LayoutParams).bottomMargin =
42+
pixels
43+
activity.findViewById<View>(resID).invalidate()
44+
activity.findViewById<View>(resID).requestLayout()
45+
}
46+
47+
@ReactMethod
48+
fun multiply(objectData:ReadableMap,callback: Callback) {
49+
println("multiply")
50+
51+
try{
52+
val teamImg1 = objectData.getString("teamImg1");
53+
val teamImg2 = objectData.getString("teamImg2");
54+
val payload = objectData.getString("payload");
55+
val title = objectData.getString("title");
56+
val body = objectData.getString("body");
57+
val id =objectData.getInt("id");
58+
val text = objectData.getArray("TextView");
59+
val imageView = objectData.getArray("ImageView");
60+
var image: Bitmap? = null
61+
var image1: Bitmap? = null
62+
63+
image = BitmapFactory.decodeStream(java.net.URL(teamImg1).openStream());
64+
image1 = BitmapFactory.decodeStream(java.net.URL(teamImg2).openStream());
65+
val intent = Intent(myContext, CustomTimerNotificationPackage::class.java);
66+
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
67+
intent.putExtra("evenData",payload);
68+
val pendingIntent = PendingIntent.getActivity(myContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
69+
val notificationLayout = RemoteViews(packageName, R.layout.notification_collapsed);
70+
71+
for (i in 0..(text?.size()?.minus(1) ?: 0)) {
72+
val item = text?.getMap(i);
73+
val textView = RemoteViews(myContext.getPackageName(), R.layout.text_view_layout)
74+
textView.setTextViewText(R.id.textView1, item?.getString("name"))
75+
76+
val float:Float=item?.getDouble("size")?.toFloat()!!
77+
textView.setTextViewTextSize(R.id.textView1, TypedValue.COMPLEX_UNIT_SP, float);
78+
textView.setTextColor(R.id.textView1,Color.parseColor("#0099cc"));
79+
if(item?.getBoolean("setViewVisibility"))
80+
textView.setViewVisibility (R.id.textView1,
81+
View.INVISIBLE)
82+
83+
84+
85+
try {
86+
// textView.setString(R.id.textView1, "layout_marginLeft", "34dp");
87+
val PaddingLeft: Int? = item?.getInt("PaddingLeft");
88+
val PaddingTop: Int? = item.getInt("PaddingTop");
89+
val PaddingRight: Int? = item.getInt("PaddingRight");
90+
val PaddingBottom: Int? = item.getInt("PaddingBottom");
91+
92+
textView.setViewPadding(
93+
R.id.textView1,
94+
PaddingLeft ?: 0,
95+
PaddingTop ?: 0,
96+
PaddingRight ?: 0,
97+
PaddingBottom ?: 0
98+
);
99+
} catch (e:Exception){
100+
println(e)
101+
}
102+
notificationLayout.addView(R.id.main, textView)
103+
// notificationLayout.setImageViewBitmap(R.id.imageView1,image1)
104+
105+
}
106+
val arrayname = arrayOf(R.layout.image_view_layout1, R.layout.image_view_layout);
107+
val arrayname1 = arrayOf(R.id.imageView2, R.id.imageView1);
108+
109+
if (true) {
110+
val item = imageView?.getMap(0);
111+
val textView = RemoteViews(myContext.getPackageName(),R.layout.image_view_layout);
112+
val url:String?=item?.getString("url");
113+
val imageBitMap = BitmapFactory.decodeStream(java.net.URL(url).openStream());
114+
val float:Float=item?.getDouble("size")?.toFloat()!!
115+
notificationLayout.setImageViewBitmap(R.id.imageView1,imageBitMap);
116+
117+
try {
118+
// textView.setString(R.id.imageView1, "layout_width", "34dp");
119+
val PaddingLeft: Int? = item?.getInt("PaddingLeft");
120+
val PaddingTop: Int? = item?.getInt("PaddingTop");
121+
val PaddingRight: Int? = item?.getInt("PaddingRight");
122+
val PaddingBottom: Int? = item?.getInt("PaddingBottom");
123+
124+
textView.setViewPadding(
125+
R.id.imageView1,
126+
PaddingLeft ?: 0,
127+
PaddingTop ?: 0,
128+
PaddingRight ?: 0,
129+
PaddingBottom ?: 0
130+
);
131+
} catch (e:Exception){
132+
println(e)
133+
}
134+
//textView.setViewPadding (Align.CENTER)
135+
notificationLayout.addView(R.id.main, textView)
136+
// notificationLayout.setImageViewBitmap(R.id.imageView1,image1)
137+
138+
}
139+
if (true) {
140+
val item = imageView?.getMap(1);
141+
val textView = RemoteViews(myContext.getPackageName(),R.layout.image_view_layout1);
142+
val url:String?=item?.getString("url");
143+
val decodedString: ByteArray = Base64.decode(url, Base64.DEFAULT)
144+
val decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
145+
146+
// val imageBitMap = BitmapFactory.decodeStream(java.net.URL(url).openStream());
147+
val float:Float=item?.getDouble("size")?.toFloat()!!
148+
notificationLayout.setImageViewBitmap(R.id.imageView2,decodedByte);
149+
150+
try {
151+
152+
// textView.setString(R.id.imageView1, "layout_width", "34dp");
153+
val PaddingLeft: Int? = item?.getInt("PaddingLeft");
154+
val PaddingTop: Int? = item?.getInt("PaddingTop");
155+
val PaddingRight: Int? = item?.getInt("PaddingRight");
156+
val PaddingBottom: Int? = item?.getInt("PaddingBottom");
157+
158+
textView.setViewPadding(
159+
R.id.imageView1,
160+
10,
161+
0,
162+
0,
163+
0
164+
);
165+
} catch (e:Exception){
166+
println(e)
167+
}
168+
//textView.setViewPadding (Align.CENTER)
169+
notificationLayout.addView(R.id.main, textView)
170+
// notificationLayout.setImageViewBitmap(R.id.imageView1,image1)
171+
172+
}
173+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
174+
val notificationChannel = NotificationChannel(channelId,"Lineup",NotificationManager.IMPORTANCE_HIGH)
175+
notificationChannel.setDescription("Lineup out")
176+
notificationChannel.enableLights(true)
177+
notificationChannel.setLightColor(Color.RED)
178+
notificationManager = myContext.getSystemService(NotificationManager::class.java)
179+
notificationManager.createNotificationChannel(notificationChannel)
180+
val notificationBuilder:NotificationCompat.Builder =
181+
NotificationCompat.Builder(myContext,channelId)
182+
notificationBuilder.setAutoCancel(true)
183+
.setWhen(System.currentTimeMillis())
184+
.setSmallIcon(myContext.getResources().getIdentifier("ic_launcher", "mipmap", myContext.getPackageName()))
185+
.setContentTitle(title)
186+
.setContentText(body)
187+
.setTicker("hearty")
188+
.setCustomContentView(notificationLayout)
189+
.setContentIntent(pendingIntent)
190+
.setPriority(NotificationCompat.PRIORITY_HIGH);
191+
notificationManager.notify(id,notificationBuilder.build())
192+
193+
} else {
194+
195+
notificationManager = myContext.getSystemService(NotificationManager::class.java)
196+
197+
val notificationBuilder:NotificationCompat.Builder =
198+
NotificationCompat.Builder(myContext,channelId)
199+
notificationBuilder.setAutoCancel(true)
200+
.setWhen(System.currentTimeMillis())
201+
.setSmallIcon(myContext.getResources().getIdentifier("ic_launcher", "mipmap", myContext.getPackageName()))
202+
.setContentTitle(title)
203+
.setContentText(body)
204+
.setTicker("hearty")
205+
.setCustomContentView(notificationLayout)
206+
.setContentIntent(pendingIntent)
207+
.setPriority(NotificationCompat.PRIORITY_HIGH);
208+
notificationManager.notify(id,notificationBuilder.build())
209+
210+
}
211+
} catch (e:Exception) {
212+
Log.i("Notification crash",e.toString())
213+
callback.invoke(e.toString());
214+
}
215+
216+
//promise.resolve(a * b)
217+
218+
}
219+
220+
221+
}
222+
223+

android/src/main/java/com/reactnativecustomtimernotification/CustomTimerNotificationPackage.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import com.facebook.react.uimanager.ViewManager
77

88

99
class CustomTimerNotificationPackage : ReactPackage {
10-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11-
return listOf(CustomTimerNotificationModule(reactContext))
12-
}
10+
override fun createNativeModules(
11+
reactContext: ReactApplicationContext): List<NativeModule> {
12+
val modules = ArrayList<NativeModule>()
13+
14+
modules.add(CustomNotificationModule(reactContext))
15+
modules.add(CustomTimerNotificationModule(reactContext))
16+
return modules
17+
}
1318

1419
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
1520
return emptyList()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:id="@+id/ImageView"
7+
>
8+
9+
<ImageView
10+
xmlns:android="http://schemas.android.com/apk/res/android"
11+
android:id="@+id/imageView1"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
15+
/>
16+
17+
</LinearLayout>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:id="@+id/ImageView1"
7+
>
8+
9+
<ImageView
10+
xmlns:android="http://schemas.android.com/apk/res/android"
11+
android:id="@+id/imageView2"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
15+
/>
16+
17+
</LinearLayout>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="64dp"
5+
android:orientation="vertical"
6+
android:id="@+id/main"
7+
android:layout_marginLeft="45dp"
8+
9+
>
10+
11+
12+
13+
14+
15+
<!-- DYNAMIC TEXT-->
16+
<LinearLayout
17+
android:layout_width="match_parent"
18+
android:layout_height="match_parent"
19+
android:layout_marginLeft="42dp"
20+
>
21+
<ImageView
22+
android:id="@+id/image"
23+
android:layout_width="25dp"
24+
android:layout_height="20dp"
25+
android:layout_marginTop="35dp"/>
26+
27+
<TextView
28+
android:id="@+id/tv_title"
29+
style="@style/TextAppearance.Compat.Notification.Title"
30+
android:layout_width="wrap_content"
31+
android:layout_height="20dp"
32+
android:layout_marginTop="35dp"
33+
android:background="@null"
34+
android:ellipsize="end"
35+
android:maxLines="1"
36+
android:textColor="#ffff" />
37+
38+
39+
40+
<TextView
41+
android:id="@+id/tv_content"
42+
style="@style/TextAppearance.Compat.Notification.Title"
43+
android:layout_width="wrap_content"
44+
android:layout_height="20dp"
45+
android:layout_marginTop="35dp"
46+
android:background="@null"
47+
android:ellipsize="end"
48+
android:maxLines="1"
49+
android:textColor="#ffff" />
50+
51+
<ImageView
52+
android:id="@+id/image1"
53+
android:layout_width="30dp"
54+
android:layout_height="20dp"
55+
android:layout_marginTop="35dp"/>
56+
57+
</LinearLayout>
58+
<!--PICK NOW-->
59+
<RelativeLayout
60+
android:layout_width="fill_parent"
61+
android:layout_height="fill_parent">
62+
63+
64+
</RelativeLayout>
65+
</RelativeLayout>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:id="@+id/LinearLayout"
7+
>
8+
<TextView
9+
android:id="@+id/textView1"
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:text="TextView"
13+
android:layout_marginLeft="45dp"
14+
android:textAppearance="?android:attr/textAppearanceLarge" />
15+
</LinearLayout>
16+

example/android/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ buildscript {
55
minSdkVersion = 16
66
compileSdkVersion = 29
77
targetSdkVersion = 29
8+
9+
ndkVersion = "21.4.7075529"
810
}
911
repositories {
1012
google()
1113
mavenCentral()
1214
jcenter()
1315
}
1416
dependencies {
15-
classpath("com.android.tools.build:gradle:3.5.3")
17+
classpath 'com.android.tools.build:gradle:4.0.0'
1618

1719
// NOTE: Do not place your application dependencies here; they belong
1820
// in the individual module build.gradle files

0 commit comments

Comments
 (0)