Postingan
Menampilkan postingan dengan label Tools Code
Tools - AddView Widget
- Dapatkan link
- X
- Aplikasi Lainnya
/* * * if you use in mainactivity use: * return this.getWindow().getDecorView().findViewById(android.R.id.content); * */ final Button mybtn = new Button(this); mybtn.setText("Your Button"); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT); #Add ((ViewGroup) getActivityContentView()).addView(mybtn, layoutParams); #Remove ((ViewGroup) getActivityContentView()).removeView(mybtn); } public View getActivityContentView() { try { return ((Activity) getContext()).getWindow().getDecorView().findViewById(android.R.id.content); } catch(ClassCastException e) { throw new ClassCastException("Please provide an Activity context for this FloatingActionButton."); } }{
Tools - AsynTask Source URL
- Dapatkan link
- X
- Aplikasi Lainnya
new BackTask().execute("URL"); } private class BackTask extends AsyncTask<String, Integer, String> { @Override protected void onPreExecute() { } protected String doInBackground(String... address) { String output = ""; try { java.net.URL url = new java.net.URL(address[0]); java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(url.openStream())); String line; while ((line = in.readLine()) != null) { output += line; } in.close(); } catch (java.net.MalformedURLException e) { output = e.getMessage(); } catch (java.io.IOException e) { output = e.getMessage(); } catch (Exception e) { output = e.toString(); } return output; } protected void onProgressUpdate(Integer... values) { } protected void onPostExecute(String s){ textview1.setText(s); } } {
Tools - Auto Generated ID
- Dapatkan link
- X
- Aplikasi Lainnya
//Generate ID private static final java.util.concurrent.atomic.AtomicInteger sNextGeneratedId = new java.util.concurrent.atomic.AtomicInteger(1); public static int generateViewId() { for (;;) { final int result = sNextGeneratedId.get(); // aapt-generated IDs have the high byte nonzero; clamp to the range under that. int newValue = result + 1; if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. if (sNextGeneratedId.compareAndSet(result, newValue)) { return result; } } } //use if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { myView.setId(Utils.generateViewId()); } else { myView.setId(View.generateViewId()); }
Tools - Clear Cache
- Dapatkan link
- X
- Aplikasi Lainnya
} public static void deleteCache(Context context) { try { java.io.File dir = context.getCacheDir(); deleteDir(dir); } catch (Exception e) { e.printStackTrace(); showMessage(e.toString()); } } public static boolean deleteDir(java.io.File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new java.io.File(dir, children[i])); if (!success) { return false; } } return dir.delete(); } else if(dir!= null && dir....
Tools - Get Package
- Dapatkan link
- X
- Aplikasi Lainnya
public class _getPackageName { private String _package = ""; public String _get() { _getPackageName _o = new _getPackageName(); Package _pack = _o.getClass().getPackage(); String _packageName = _pack.getName(); return _package = _packageName; } public String _getPackage() { if (_package.equals("")) { _get(); return _package; } else { return _package; } } }
Tools - Get Version Code/Name
- Dapatkan link
- X
- Aplikasi Lainnya
//Create variable versionName and versionCode String versionName = "null"; int versionCode = -1; try { android.content.pm.PackageInfo packageInfo = MainActivity.this.getPackageManager().getPackageInfo(getPackageName(), 0); versionName = packageInfo.versionName; versionCode = packageInfo.versionCode; } catch (android.content.pm.PackageManager.NameNotFoundException e) { e.printStackTrace(); } //textview set text TextView textViewVersionInfo = (TextView) findViewById(R.id.textview1); textViewVersionInfo.setText(String.format("Version Name: %s Version Code:%d", versionName, versionCode));
Tools - Notification
- Dapatkan link
- X
- Aplikasi Lainnya
//Generate Alert Feature Notification.Builder mBuilder = new Notification.Builder(MainActivity.this); mBuilder.setSmallIcon(R.drawable.appicon); mBuilder.setContentTitle("You're Title"); mBuilder.setContentText("You're Text"); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int onx = 1; notificationManager.notify(onx, mBuilder.build()); //Run activity and create alert notification Notification.Builder mBuilder = new Notification.Builder(MainActivity.this); mBuilder.setSmallIcon(R.drawable.appicon); mBuilder.setContentTitle("You're Title"); mBuilder.setContentText("You're Text"); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent( getApplicationContext(), SwwActivity.class); PendingIntent p...
Tools - Print
- Dapatkan link
- X
- Aplikasi Lainnya
java.lang.System.setOut(new java.io.PrintStream(new java.io.OutputStream() { java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream(); @Override public void write(int oneByte) throws java.io.IOException { outputStream.write(oneByte); textview1.setText(new String(outputStream.toByteArray())); } })); //Testing the System.out stream java.lang.System.out.println("Test"); java.lang.System.out.println("Test 2");
Tools - Print Method
- Dapatkan link
- X
- Aplikasi Lainnya
public void Function(String _str) { try { Class<?> c = Class.forName(_str); System.out.println("name = " + c.getName()); System.out.println("package = " + c.getPackage()); java.lang.reflect.Method[] methods = c.getDeclaredMethods(); System.out.println("----- Class methods ---------------"); for (java.lang.reflect.Method method : methods) { System.out.println(method.getName()); } } catch (ClassNotFoundException e) { e.printStackTrace(); } }
Tools - Read Resources
- Dapatkan link
- X
- Aplikasi Lainnya
java.io.InputStream ins = getResources().openRawResource(R.drawable.file); StringBuilder text = new StringBuilder(); try { java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(ins)); String line; while ((line = br.readLine()) != null) { text.append(line); text.append('n'); } br.close(); } catch (java.io.IOException e) { } EditText tv = (EditText)findViewById(R.id.edittext1); tv.setText(text.toString());
Tools - Share Apk File
- Dapatkan link
- X
- Aplikasi Lainnya
String apk = ""; String uri = ("com.my.project"); try { android.content.pm.PackageInfo pi = getPackageManager().getPackageInfo(uri, android.content.pm.PackageManager.GET_ACTIVITIES); apk = pi.applicationInfo.publicSourceDir; } catch (Exception e) { showMessage(e.toString()); } Intent iten = new Intent(Intent.ACTION_SEND); iten.setType("*/*"); iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(apk))); startActivity(Intent.createChooser(iten, "Send APK"));
Tools - Speech to Text
- Dapatkan link
- X
- Aplikasi Lainnya
//Set onCreate } private final int REQ_CODE_SPEECH_INPUT=100; private void sowhat() { //Set on moreblock "speech" Intent intent = new Intent(android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL, android.speech.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); intent.putExtra(android.speech.RecognizerIntent.EXTRA_PROMPT, "Say something"); try { startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); } catch (ActivityNotFoundException a) { Toast.makeText(getApplicationContext(), "Your device doesn't support speech input", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQ_CODE_SPEECH_INPUT: { if (resultCode == RESULT_OK && null != data) { Ar...
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 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...
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 ,...
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...
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...
Codes for modifying Action Bar in Sketchware
We can modify the Action Bar or Title bar in our Sketchware project, by using simple codes in onCreate method. Below I provide a few of those codes. Change title of Action Bar ActionBar ab = getActionBar(); ab.setTitle(" Title "); Replace the underlined text with the title you want to set. Change subtitle of Action Bar ActionBar ab = getActionBar(); ab.setSubtitle(" subtitle "); Replace the underlined text with the subtitle you want to set. Show App icon in Action Bar ActionBar ab = getActionBar(); ab.setDisplayShowHomeEnabled(true); Set an image as icon in Action Bar Add the image to be displayed in Action Bar using Image Manager in your sketchware android project. Then add the following code in onCreate event. ActionBar ab = getActionBar(); ab.setIcon(getDrawable(R.drawable. imagename )); ab.setDisplayShowHomeEnabled(true); Replace the underlined text with name of the image added using Image Manager. Use Custom view in Action Bar ActionBar ab = getActionBar(); ab...
How to integrate Admob Ads in Sketchware project using AIDE?
AIDE can be used to integrate Admob Ads to a Sketchware project. First export the source code of your sketchware android project and then follow the steps below to learn how to integrate Admob banner ads in AIDE. Prerequisites A Sketchware project AIDE with pro account key purchased Account in Google developer console Account in Admob Before placing admob ads in an app, the app needs to be uploaded to google play store, however test ads can be tried in any app. Always place the test ad ID before placing your ad unit ID. App ID and ad unit ID can be obtained by registering the app on Admob. But for using test ads no registration is required. Do not click on your own Ads. This code works in apps which do not use AppCompat and Design. Export the Sketchware project In Sketchware, under MY PROJECTS, go to project settings of the app to be exported, and click on Export to PC (Android Studio) . The exported file is a zip file. Create a new folder...
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...
Firebase Login/Register with email verification
To verify the email address of a user registered in your firebase app in Sketchware, follow the steps given below. 1. In main.xml , add three EditText fields, edit_email , edit_username , and edit_password , and add two Buttons register and login . 2. Add a FirebaseAuth component fauth , a FirebaseDb component user:users , and an Intent component i . 3. Add a Map Variable map , a String variable username , and a Boolean variable emailVerified . 4. Create a new page verify_email.xml . 5. In MainActivity.java , in onCreate event, if user is logged in and email is verified move to ChatActivity or the home page of your app and Finish Activity. And if user is logged in and email in not verified move to VerifyEmailActivity . See image below. The code use in add source directly block: emailVerified = fauth.getCurrentUser().isEmailVerified(); 6. In the event register button onClick ...