Posts

Showing posts from December, 2019
Image
Horizontal slide in Sketchware Code 1(declaration): final android.support.v4.view.ViewPager viewPager = new android.support.v4.view.ViewPager(this); viewPager.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); viewPager.setBackgroundColor(Color.parseColor("#FFFFFF")); MyPagerAdapter adapter = new MyPagerAdapter(); viewPager.setAdapter(adapter); viewPager.setCurrentItem(0); linear1.addView(viewPager); viewPager.addOnPageChangeListener(new android.support.v4.view.ViewPager.OnPageChangeListener() { public void onPageSelected(int position) { View noview = (View) viewPager.findViewWithTag("myview" + viewPager.getCurrentItem()); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { } }); } private class MyPagerAdapter extends android.support.v4.view.PagerAdapter { public ...
Image
Bottom Sheet dialog in Sketchware android.support.design.widget.BottomSheetDialog bottomSheetDialog = new android.support.design.widget.BottomSheetDialog(MainActivity.this); View bottomSheetView; bottomSheetView = getLayoutInflater().inflate(R.layout.bottom_dialog, null ); bottomSheetDialog.setContentView(bottomSheetView); bottomSheetDialog.show();
Image
Custom notification in Sketchware In extra block: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = "Channel name 1"; String description = "Notification channel"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel("id 1", name, importance); channel.setDescription(description); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); } In button: RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.cview); Intent intent = new Intent(MainActivity.this, TwoActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4....
Image
Notifications in Sketchware In extra block: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = "Channel name 1"; String description = "Notification channel"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel("id 1", name, importance); channel.setDescription(description); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); } In button: Intent intent = new Intent(MainActivity.this, TwoActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(MainActivity.this, "id 1") .setSmallIcon(R.drawable.m...
Image
Dynamically changing background color in Sketchware Code: color1 = 0xffffffff; anim = ObjectAnimator.ofInt(linear1, "backgroundColor", color1); anim.setEvaluator(new ArgbEvaluator()); anim.setDuration(1000); new Thread() { public void run() { while(true) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } runOnUiThread(new Runnable() { public void run() { red2 = (int)(java.lang.Math.random() * 128 + 127); green2 = (int)(java.lang.Math.random() * 128 + 127); blue2 = (int)(java.lang.Math.random() * 128 + 127); color2 = 0xff << 24 | (red2 << 16) | (green2 << 8) | blue2; anim.setIntValues(color1, color2); anim.start(); color1 = color2; } }); } } }.start(); } public int color1, color2, red1, red2, blue1, blue2, green1, green2; ObjectAnimator anim; {