Postingan
Menampilkan postingan dengan label Graphics Code
Graphics Image From Layout
- Dapatkan link
- X
- Aplikasi Lainnya
//onCreate } private void storeImage(Bitmap image) { java.io.File pictureFile = new java.io.File(getExternalCacheDir() + "/image.jpg"); if (pictureFile == null) { Log.d("MainActivity", "Error creating media file, check storage permissions: "); return; } try { java.io.FileOutputStream fos = new java.io.FileOutputStream(pictureFile); image.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.close(); } catch (java.io.FileNotFoundException e) { Log.d("MainActivity", "File not found: " + e.getMessage()); } catch (java.io.IOException e) { Log.d("MainActivity", "Error accessing file: " + e.getMessage()); } Intent iten = new Intent(android.content.Intent.ACTION_SEND); iten.setType("*/*"); iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg"))); startActivity(Intent.createChooser(iten, "Поделиться/сохранить")); } private Bitmap getBitmapFromView(View...
Graphics Bitmap To String
- Dapatkan link
- X
- Aplikasi Lainnya
//Bitmap to String: public String BitMapToString(Bitmap bitmap){ java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG,100, baos); byte [] arr=baos.toByteArray(); String result=Base64.encodeToString(arr, Base64.DEFAULT); return result; } //String to Bitmap: public Bitmap StringToBitMap(String image){ try{ byte [] encodeByte=Base64.decode(image,Base64.DEFAULT); Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); return bitmap; }catch(Exception e){ e.getMessage(); return null; } }
Graphics Bitmap Compression
- Dapatkan link
- X
- Aplikasi Lainnya
android.graphics.drawable.Drawable drawable = getDrawable(R.drawable.image); Bitmap bitmap = ((android.graphics.drawable.BitmapDrawable)drawable).getBitmap(); //Source imageview1.setImageBitmap(bitmap); java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG,50,stream); byte[] byteArray = stream.toByteArray(); Bitmap compressedBitmap = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length); //Result 50% Quality imageview2.setImageBitmap(compressedBitmap);
Graphics DP to Pixel
- Dapatkan link
- X
- Aplikasi Lainnya
//OnButton int dp_first = 25; int dp_second = 15; int dp_third = 29; int dp_fourth = 41; Activity activity = MainActivity.this; textview1.setText("DIP/DP to Pixels conversion... "); textview1.setText(textview1.getText()+ ""+dp_first+ "dp = "+ getPixelsFromDPs(activity,dp_first) + "pixels "+dp_second+ "dp = "+ getPixelsFromDPs(activity,dp_second) + "pixels "+dp_third+ "dp = "+ getPixelsFromDPs(activity,dp_third) + "pixels "+dp_fourth+ "dp = "+ getPixelsFromDPs(activity,dp_fourth) + "pixels "); //onCreate public static int getPixelsFromDPs(Activity activity, int dps){ android.content.res.Resources r = activity.getResources(); int px = (int) (android.util.TypedValue.applyDimension(android.util.TypedValue.COMPLEX_UNIT_DIP, dps, r.getDisplayMetrics())); return px; } #Pixel to DP //OnButton int pixels_first = 37; int pixels_second = 22; int pixels_third = 43; int pixels_fourth = 61; Context c...
Graphics Debos Effect
- Dapatkan link
- X
- Aplikasi Lainnya
EmbossMaskFilter filter = new EmbossMaskFilter( new float[]{ 0f, -1f, 0.5f }, // direction of the light source 0.8f, // ambient light between 0 to 1 13, // specular highlights 7.0f // blur before applying lighting ); textview1.setLayerType(View.LAYER_TYPE_SOFTWARE,null); textview1.getPaint().setMaskFilter(filter);
Graphics Draw Bitmap On Canvas
- Dapatkan link
- X
- Aplikasi Lainnya
//Add Private private Context mContext; private android.content.res.Resources mResources; //onCreate mContext = getApplicationContext(); mResources = getResources(); //onButton // Bitmap to draw on the canvas Bitmap bitmap = BitmapFactory.decodeResource( mResources, R.drawable.icon ); // Define an offset value between canvas and bitmap int offset = 50; // Initialize a new Bitmap to hold the source bitmap Bitmap dstBitmap = Bitmap.createBitmap( bitmap.getWidth() + offset * 2, // Width bitmap.getHeight() + offset * 2, // Height Bitmap.Config.ARGB_8888 // Config ); // Initialize a new Canvas instance Canvas canvas = new Canvas(dstBitmap); // Draw a solid color on the canvas as background canvas.drawColor(Color.LTGRAY); canvas.drawBitmap( bitmap, // Bitmap offset, // Left ...
Graphics Draw Finger
- Dapatkan link
- X
- Aplikasi Lainnya
dv = new DrawingView(this); linear1.addView(dv); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.GREEN); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); } DrawingView dv; private Paint mPaint; private Canvas mCanvas; public class DrawingView extends View { public int width; public int height; private Bitmap mBitmap; private Path mPath; private Paint mBitmapPaint; Context context; private Paint circlePaint; private Path circlePath; public DrawingView(Context c) { super(c); context=c; mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); circlePaint = new Paint(); circlePath = new Path(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); } @Override protected void onSizeChanged(int w, int h, int oldw, int ...
Graphics Drawable
- Dapatkan link
- X
- Aplikasi Lainnya
imageview1.setBackground(Drawables.getSelectableDrawableFor(Color.parseColor("#404040"))); imageview1.setClickable(true); } public static class Drawables { public static android.graphics.drawable.Drawable getSelectableDrawableFor(int color) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { android.graphics.drawable.StateListDrawable stateListDrawable = new android.graphics.drawable.StateListDrawable(); stateListDrawable.addState( new int[]{android.R.attr.state_pressed}, new android.graphics.drawable.ColorDrawable(Color.parseColor("#ffffff")) ); stateListDrawable.addState( new int[]{android.R.attr.stat...
Graphics Fit Device
- Dapatkan link
- X
- Aplikasi Lainnya
Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); try { display.getRealSize(size); } catch (NoSuchMethodError err) { display.getSize(size); } int width = size.x; int height = size.y; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((int)(width), LinearLayout.LayoutParams.MATCH_PARENT); layout1.setLayoutParams(lp);
Graphics Font External
- Dapatkan link
- X
- Aplikasi Lainnya
String path = getExternalCacheDir() + "/myfont.ttf"; //let us copy the font on private storage. copyFiletoExternalStorage(R.raw.myfont2, "myfont.ttf"); //let us load the font Typeface myTypeface = Typeface.createFromFile(path); //let us set the font to text view txt2.setTypeface(myTypeface); } private void copyFiletoExternalStorage(int resourceId, String resourceName){ String pathSDCard = getExternalCacheDir() + "/myfont.ttf";//Environment.getExternalStorageDirectory() + "/Android/data/" + resourceName; try{ java.io.InputStream in = getResources().openRawResource(resourceId); java.io.FileOutputStream out = null; out = new java.io.FileOutputStream(pathSDCard); byte[] buff = new byte[1024]; int read = 0; ...
Graphics Gradient Color
- Dapatkan link
- X
- Aplikasi Lainnya
//Gradient Code Starts Here int[] colors = {Color.rgb(138,41,81),Color.rgb(41,53,158)}; android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable(android.graphics.drawable.GradientDrawable.Orientation.BR_TL, colors); gd.setCornerRadius(0f); gd.setStroke(0,Color.WHITE); if(android.os.Build.VERSION.SDK_INT >= 16) {linear1.setBackground(gd); } else {linear1.setBackgroundDrawable(gd);} //End of Gradient Generator
Graphics Image Base64
- Dapatkan link
- X
- Aplikasi Lainnya
//on onCreate } private static final String STATE_IMAGE_URI = "STATE_IMAGE_URI"; private Uri imageUri; public void onSaveInstanceState(Bundle state) { super.onSaveInstanceState(state); if (imageUri != null ) { state.putParcelable(STATE_IMAGE_URI, imageUri); } } public void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); if(state == null || !state.containsKey(STATE_IMAGE_URI)) return; setImage((Uri)state.getParcelable(STATE_IMAGE_URI)); } private static final int IMAGE_REQUEST_CODE = 9; private void chooseImage() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select picture"), IMAGE_REQUEST_CODE); } public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode != IMAGE_REQUEST_CODE) { return; } if (resultCode != Activity.RESULT_OK) { ret...
Graphics Image Croper
- Dapatkan link
- X
- Aplikasi Lainnya
private void performCrop(Uri picUri) { try { Intent cropIntent = new Intent("com.android.camera.action.CROP"); // indicate image type and Uri cropIntent.setDataAndType(picUri, "image/*"); // set crop properties here cropIntent.putExtra("crop", true); // indicate aspect of desired crop cropIntent.putExtra("aspectX", 1); cropIntent.putExtra("aspectY", 1); // indicate output X and Y cropIntent.putExtra("outputX", 128); cropIntent.putExtra("outputY", 128); // retrieve data on return cropIntent.putExtra("return-data", true); // start the activity - we handle returning in onActivityResult ...
Cara pembuatan Apps paling Populer
Create Stopwatch App in Android using Sketchware
Timer component and number variables can be used to add a Stopwatch to your Android App created in Sketchware. To create a Stopwatch App in Sketchware follow the steps below. 1. Start a new project in Sketchware . Fill app name, package name and app icon. 2. In VIEW area, insert a Textview and a Button widget. In Textview properties set layout_gravity as center_horizontal, text as 00:00:00.00, and text_size as 40sp. In Button properties set layout_gravity as center_horizontal, text as Start/Stop/Reset and text_size as 20sp. 3. In LOGIC area add a new timer component t . 4. In onCreate event, add five number variables , one each for hour, minutes, seconds, and milliseconds, and an extra variable for managing Button Click. Set all these number variables to 0. 5. Suppose the five number variables are named as h , m ,...
TextInputLayout in Sketchware
To create an EditText with animation features, we can use the EditText in a TextInputLayout which is a Layout interface in android.support.design.widget library. In Sketchware we cannot add it in xml file but we can create it programmatically. Follow the instructions given below for a simple example. 1. In VIEW area of your project add two Linear horizontal linear2 and linear3 , and a Button button1 . 2. Switch On AppCompat and design. 3. Create a more block extra and define the block using an add source directly block. Put following code in it. } EditText edittext1, edittext2; { Here we declare two EditText fields, edittext1 and edittext2 . 4. In onCreate event, i. Use add source directly block and use codes to define edittext1, set it's LayoutParams, set it's hint, and set it's text color. edittext1 = new EditText(this); edittext1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayou...
How to find and highlight a word in a text field in Sketchware?
We can highlight a particular searched character sequence in a TextView or EditText field or any other text field by using Spannable. To use Spannable class to highlight a searched text in Sketchware Android Project, follow the steps given below. 1. In VIEW area of your project, add an EditText field ( edittext1 ) which will act as input field for search term. Add a TextView ( textview1 ) which will display the number of results found. And add another TextView ( textview2 ) or EditText (edittext2) field which will contain the text in which the word is to be searched. 2. In LOGIC area, in onCreate event set the text to be searched in TextView field. 3. If you want the app to search from any text added by user, use EditText instead textview2 in step no.1 and do not set the text in onCreate. 4. Add a new String variable text . Add three number variables total, len and y . 4. Add a new event edittext1 onTextChanged . 5. In the event edittext1 onTextChange...
A Flash Light App in Sketchware
To create a Torch Flashlight application for Android with Sketchware follow the steps given below. 1. Create a new project in Sketchware. In VIEW area add an ImageView imageview1 . Set it's width and height to 100, and scale type to FIT_XY. 2. Using Image Manager add two images ic_flash_on_black and ic_flash_off_black . 3. Set ic_flash_off_black as the image of imageview1. 4. In Library manager switch on AppCompat and Design . 5. Add a Camera component . 6. Add two Boolean variables: flashLightStatus and hasCameraFlash . 7. Add two More Blocks: flashLightOn and flashLightOff . 8. In onCreate event, use add source directly block and put following code: hasCameraFlash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); 9. In More Block flashLightOn , use add source directly block and put following code: android.hardware.camera2.CameraManager cameraManager = (andr...
How to enable download in webview in Sketchware apps?
How to enable download in an app created with Sketchware? Suppose you have created an app in Sketchware which uses webview to open a site. You can seamlessly explore the site in your app. But the download links in the webview field do not work. But it is possible to make it work by exporting the source code. You can edit the code in either Android studio or Eclipse to add your desired features and then recompile it. I tried to do that but soon realized that setting up environment for development of Android app is not easy for a naive like me. But it can be done by code injection or by using another mobile app called Anacode. Enabling download from webview in Sketchware using add source directly block. 1. In VIEW area of your app insert a WebView (webview1). 2. In LOGIC area, in onCreate event, a. Add write String... to file path ... Block. This will add WRITE_EXTERNAL_STORAGE permission. b. Then add an add source directly block. In this block pu...
Intent - Open File By Type
java.io.File _PathOpenFile = Environment.getExternalStorageDirectory(); java.io.File myFile = new java.io.File(_PathOpenFile + "/aan.zip"); java.io.File url = myFile; Uri uri = Uri.fromFile(url); Intent intent = new Intent(Intent.ACTION_VIEW); if (url.toString().contains(".doc") || url.toString().contains(".docx")) { intent.setDataAndType(uri, "application/msword"); } else if(url.toString().contains(".pdf")) { intent.setDataAndType(uri, "application/pdf"); } else if(url.toString().contains(".ppt") || url.toString().contains(".pptx")) { intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if(url.toString().contains(".xls") || url.toString().contains(".xlsx")) { intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if(url.toString().contains(".zip") || url.toString().contains(".rar")) { intent.setDataAndType(uri, "applica...
Code for implementing Notifications in Sketchware
This tutorial shows a Sketchware android project example in which a Notification is displayed when a Button is clicked and when the Notification is clicked, it opens a new Activity. 1. Create a new project in Sketchware. In VIEW area add an EditText edittext1 , and a Button button1 . 2. Using Image Manager add an images mail_white . This will be used as the Notification icon. 3. In Library manager switch on AppCompat and Design . 4. Create a new VIEW two.xml / TwoActivity.java . 5. Add a More Block: createChannel . 6. In More Block createChannel , use add source directly block and put following code: 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 not...
How to share an image from Drawable folder?
To share an image in drawable folder of your sketchware android project, first save the image in app cache and then share the saved image using it's Uri. The code to be used is provided below. 1. First add the image (my_image.jpg) to be shared in your Sketchware android project using image manager. 2. Add a Button button1 which will act as share button. 3. In event button1 onClick, use add source directly block and add following code: Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.my_image); String path = getExternalCacheDir()+"/shareimage.jpg"; java.io.OutputStream out = null; java.io.File file=new java.io.File(path); try { out = new java.io.FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } path=file.getPath(); Uri bmpUri = Uri.parse("file://"+path); Intent shareIntent = new Intent(); shareIntent = new Intent(android.content.Intent.ACTION...
ActionBar back button
Animation Transtition Animation
/*this will go in button click, activity start, or whatever*/ android.transition.TransitionManager.beginDelayedTransition(linear1,makeFadeTransition()); toggleVisibility(imageview1,imageview2,imageview3,imageview4); android.transition.TransitionManager.beginDelayedTransition(linear1,makeSlideTransition()); toggleVisibility(imageview1,imageview2,imageview3,imageview4); android.transition.TransitionManager.beginDelayedTransition(linear1,makeExplodeTransition()); toggleVisibility(imageview1,imageview2,imageview3,imageview4); /*This stays at the bottom of all code in onCreate*/ } private android.transition.Fade makeFadeTransition(){ android.transition.Fade fade = new android.transition.Fade(); fade.setDuration(2000); fade.setInterpolator(new AnticipateInterpolator()); return fade; } private android.transition.Slide makeSlideTransition(){ android.transition.Slide slide = new android.transition.Slide(); slide.setSlideEdge(Gravity.TOP); slide.setInterpolator(new BounceInterpolator()); slide.s...