Open top menu


Example-Custom Multiple Selection Spinner with Searching in android?


activity_maim.xml

xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.project.mespl.multipleseleectspinner.MainActivity">


    <com.project.mespl.multipleseleectspinner.MultiSpinnerSearch
       
android:id="@+id/searchMultiSpinner"
        android:layout_margin="20dp"
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>


 


MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArrayList list = new ArrayList<>();

        for (int i = 0; i < 30; i++) {
            list.add(String.valueOf(i));
        }

        List listArray0 = new ArrayList<>();

        for (int i = 0; i < list.size(); i++) {
            KeyPairBoolData h = new KeyPairBoolData();
            h.setId(i + 1);
            h.setName(list.get(i));
            h.setSelected(false);
            listArray0.add(h);
        }

        MultiSpinnerSearch searchMultiSpinnerUnlimited = (MultiSpinnerSearch) findViewById(R.id.searchMultiSpinner);
        searchMultiSpinnerUnlimited.setItems(listArray0, -1, new SpinnerListener() {

            @Override            public void onItemsSelected(List items) {

                for (int i = 0; i < items.size(); i++) {
                    if (items.get(i).isSelected()) {
                        Log.i(TAG, i + " : " + items.get(i).getName() + " : " + items.get(i).isSelected());
                    }
                }
            }
        });

    }

}





Item List




 Search View





More




























































Read more



Why we Used Manifest file in android App ?

Explain:-the manifest file in its root Directory.  Must every application Manifest File.The manifest file provide all essential information about your app to the android system.
1.       Its name the java package for the application .package name serves as a unique identifier for the application.
2.       Described the components of the application, which include the activites,services,broadcast receivers, and content providers .
3.       The classes that implement each of the components and publishes the capabilities.
4.       It determines the processes that host the application component.
5.       Declares the permissions that the application must have in order to access protected parts of the API and interact with other application.
6.       It declares the minimum level of the Android API that the application requires.



Here is an example of the Manifest file.

xml version=”1.” Encoding=”utf-8”?>

<manifest>

<uses-permission />

<permission />

<permission- group />

<instrumentation />

<uses-sdk />

<uses-configuraton />

<uses-feature />

<support-screen />

<support-gl-texture />



<application >

    <activity>

        <intent-filter>

            <action />

            <category />



            <data />

        </intent-filter>

    </activity>



    <activity–alias>

    <intent-filter />

    < Meta-data />

</activity–alias>





<service>

    <intent-filter />

    <mete-data />

</service>


<
receiver>
    <
intent-filter />
    <
meta-data />
</
receiver>

<
provider >
    <
grant-uri-permission/>
    <
path-permission />
    <
meta-data />
</
provider>

<
uses-library />

</
application>

    </
manifest>


Action

Add action to an intent filter .for eg

<intent-filter>
<
action android:name="android.intent.action.EDIT" />
<
action android:name="android.intent.action.INSERT" />
<
action android:name="android.intent.action.DELETE" />
</
intent-filter>

An element must contain multiple  element.
But to assigine  one of these action to the attribute

<action android:name="com.example.project.TRANSMOGRIFY" />


Activity-alias

 The target must be in the same Application as the alias and it must be declared before the alias in the manifest.


    android:exported=["true" | "false"]
    android:icon="drawable resource"
    android:label="string resource"
    android:name="string"
    android:permission="string"
    android:targetActivity="string" >
    . . .
   
 
 

Category

Adds a category name to an intent filter. See Intents and Intent Filters for details on intent filters and the role of category specifications within a filter.

Syntax-
<category android:name="string" />
 


Data

The specification can be just a data type (the mimeType attribute), just a URI, or both a data type and a URI.

Syntax-

<data android:scheme="string"
   
android:host="string"
   
android:port="string"
   
android:path="string"
   
android:pathPattern="string"
   
android:pathPrefix="string"
   
android:mimeType="string" />

 
 
Grant-URI-Permission

Data subsets are indicated by the path part of a content: URI. (The authority part of the URI identifies the content provider.) Granting permission is a way of enabling clients of the provider that don't normally have permission to access its data to overcome that restriction on a one-time basis.

Syntax-
<grant-uri-permission android:path="string"
   
android:pathPattern="string"
   
android:pathPrefix="string"
/>

Instrumentation

Base class for implementing application instrumentation code . class that enables you to monitor an application's interaction with the system.

Syntax –

<instrumentation android:functionalTest=["true" | "false"]
android:handleProfiling=["true" | "false"]
android:icon="drawable resource"
android:label="string resource"
android:name="string"
android:targetPackage="string" />

 
Meta –Data

A name-value pair for an item of additional, arbitrary data that can be supplied to the parent component. A component element can contain any number of <meta-data> subelements.

Syntax-
<meta-data android:name="string"
   
android:resource="resource specification"
   
android:value="string" />


Receiver

Declares a broadcast receiver (a BroadcastReceiver subclass) as one of the application's components. Broadcast receivers enable applications to receive intents that are broadcast by the system or by other applications, even when other components of the application are not running.

Syntax-
  <receiver android:directBootAware=["true" | "false"]
    android:enabled=["true" | "false"]
    android:exported=["true" | "false"]
    android:icon="drawable resource"
    android:label="string resource"
    android:name="string"
    android:permission="string"
    android:process="string" >
    
</
receiver>
Read more






Example- How to Implement Material Spinner in android?


Step 1 - For normal look use

compile 'com.weiwangcn.betterspinner:library:1.1.0'
 
If you have appcompat-v7 in your dependencies make sure to exclude it :

compile ('com.weiwangcn.betterspinner:library:1.1.0') {
    exclude
group: 'com.android.support', module: 'appcompat-v7'
}



Step 2- Add View main_activity.xml.



<com.weiwangcn.betterspinner.library.BetterSpinner
    android:id="@+id/spinner_sp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/edittext_view"
    android:hint="@string/select"
    android:padding="8dp"

     />
 
 
Step 3- Find View id in MainActivity.Java.

public class MainActivity extends AppCompatActivity {
 String[] age = {"12", "13","14","15","16","17","18","19","20",};

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BetterSpinner Age_Sppiner = (BetterSpinner)
                                    findViewById(R.id.Age_Sppiner);

        ArrayAdapter arrayAdapterage = 
        new ArrayAdapter(listener, android.R.layout.
                                  simple_spinner_dropdown_item, age); 
                                
        Age_Sppiner.setAdapter(arrayAdapterage);
 

    }

}



Read more



Example- How to used HTML tag in TextView Programmatically.

  I this tutorial explain how to design String Programmatically
















Read more

Security Tips for Android Applications.

Android has built-in security feature that significantly reduce the frequency and impact of application security issue.

1.       An application framework with robust implementation of common security functionality such as cryptography ,permission.
2.       Technologies like ASLR. NX, ProPolice , safe_iop ,OpenBSd DlMalloc, OpenBSD Calloc,risk associated with common memory Management errors.
3.       An Encrypted file system that can be enabled to protect data on lost or stolen Devices.
4.       Application-defined permission to control application data on n application.
5.       User granted permission to restrict access to system feature and user data.


Storing Data

The most common security concern for an application on android.
1.       Internal Storage:-Avoid the MODE_WORLD_WRITEABLE or MODE_WORLD_READABLE for IPC files because they do not provide the ability to limit data access to particular application, nor do they provide any control of data format. You can encrypt local files using a key that is not directly accessible to the application.

2.  External Storage:-File created on external storage, such as SD cards, are globally readable and Writable. Because external storage can be removed by the user and also modified by any application .you should not store executables or class files on external storage prior or dynamic loading.

3.  Content Providers:-creating a content Provider that is exported for use by other application, you can specify a single permission for reading and writing, or you can specify distinct permission for reading and writing. You should limit your permission to those required to accomplish the task at hand.


Permission

You should minimize the number of permission that your app request. Restricting access to sensitive permission reduces the risk .your application in a way that does not require any permission that is preferable.
Generally, you can create permission strive to define as few permission as possible while satisfying your security requirement.





















































Read more





Introduced Latest Android Version(8.0 Oreo).


The Android Oreo Luanch latest Android(8.0) version.Oreo smarter ,faster,and more powerful.Android 8.0 (API level 26) introduces a variety of new feature and capabilities for users and developers.


1.       Picture-in-Picture mode:-PIP is a special type of multi-window mode mostly used foe video playback.

2.       Notifications:-
(a)    Notification channels:- that’s allow you to create a user-cutomizable channel foe each type.of notification you want to display.
(b)   Notification dots:-Displaying dots,or badges ,on  app launcher icon.
(c)    Snoozing:-Which causes them to disapper for a priod of time before reappering.
(d)   Notification timeout:-you can set a time when creating a notification using SetTimeoutAfter().
(e)   Notification settings:-you can call setSettingTExt() set to the text.that appers when you create alink to your apps notification settings .
(f)     Notification:-User can dismiss notification themselves,and apps can remove them programmatically.
(g)    Background Colors:- you can set and enabled a background color for a notification.
(h)   Messaging style:- Use the MessagingStyle class diplay more content in teir collapsed form.
3.       Autofill Framwork:- User can save time filling out forms by using autofill in their devices.filling forms , such as account and credit card forms, easier with the introduction of the autofill framework.

4.       Downloadable fonts:-Android support Library 26 introduce support for api to request fonts from a provide application instead of bundling files into tha apk or letting athe apkdownload font.

5.        Shortcuts Pinning:-you can create Pinned shortcuts. Unlike static and dynamic shortcuts, pinned shortcuts appears in supported launchers as seprate icon.

6.       Webview feature:-Android provides several Apis to help you manage the Webview Objects that display web content in your app.

7.       Fontin XML:- introduced a new feature, fonts in XML.you can add the Font File in the res/font/   folder to bundle fonts as resoures. Thes fonts are compiled in your R file and are Automatically Available in Android Studio.

8.       Adaptive icon:-Introduces adaptive launcher icons, which can display a varity of sahpes across different device models. For Example an adaptive launcher icon can display a circular shape on one OEM device and display a squirecle o another device. Each device OEM provide a mask. Which the system then used to render all adaptive icons with same shape.

9.       Wide-gamut color:- To allow conversion between color spaces, this implementation uses the CIE XYZ profile connection space(PCS).

10.    Multidisplay Support:-the platform offers enhance support for multiple daiplays.if an activity support  multi-window mode and is running on a dvice with multiple display,users can move the activity from one display to another.

11.   Autosizing TextView:- you can set the size ofyour text expand or contract automatically based on the size of the textView. This means, it is much easier o potimize the text size on different screens or with dynamic content.
















Read more


Read PDF file via assets folder in Android Studio


In this tutorial explain how to read pdf file assets folder.
I have used PDF Read Library .

Step 1. Create Android Project.

Step 2. Add Permission in Manifest file.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Step 3.Add dependencies .
compile 'com.github.barteksc:android-pdf-viewer:2.7.0-beta.1'
Step 4. Create activity_main.xml.
 
xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">     <Button         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="Android Begginer Point"         android:textAllCaps="true"         android:textStyle="bold"         android:textColor="#FF439934"         />     <com.github.barteksc.pdfviewer.PDFView         android:id="@+id/pdfView"         android:layout_width="match_parent"         android:layout_height="match_parent" /> </LinearLayout>
Step 5. Create MainActivity.java.
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.pdf.PdfRenderer;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.github.barteksc.pdfviewer.PDFView;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class MainActivity extends AppCompatActivity {

    private static final String FILENAME = "sit.pdf";
    PDFView ReadTxt;
   
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ReadTxt=(PDFView)findViewById(R.id.pdfView);
        File file = new File(this.getCacheDir(), FILENAME);
        if (!file.exists()) {
            try {
                InputStream asset = this.getAssets().open(FILENAME);
                ReadTxt.fromStream(asset)
                        .pages(0, 2, 1, 3, 3, 3)
                        .enableSwipe(true)
                        .swipeHorizontal(false)
                        .enableDoubletap(true)
                        .defaultPage(0)
                        .enableAnnotationRendering(false)
                        .password(null)
                        .scrollHandle(null)
                        .enableAntialiasing(true)
                        .spacing(0)
                        .load();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else {
           Toast.makeText(getApplicationContext(),
"File not found",Toast.LENGTH_LONG).show();
        }
    }

    @Override    protected void onStart() {
        super.onStart();
    }

}



try this.........




Read more






In this tutorial explain how to Create / Delete Multiple text file Inside Root Folder  and every text file Size is 5Mb .

private File createEVENTFileWriter() {

    File filelog = null;

    try {

        String root = Environment.getExternalStorageDirectory().toString();
        File myDir = new File(root + "/" + log_foldereventname);
        myDir.mkdirs();
        String h = DateFormat.format("MM-dd-yyyyy ss",System.currentTimeMillis()).toString();
        filelog = new File(myDir, log_filenameevent);
        filelog.createNewFile();
        long fileSizeInBytes = filelog.length();
        long fileSizeInKB = fileSizeInBytes / 1024;

        if (fileSizeInKB > 5000) {

            File from = new File(myDir, log_filenameevent);
            File to = new File(myDir, h + log_filenameevent);
            if (from.exists()) {
                from.renameTo(to);

            }
        }

    } catch (Exception err) {
        fileWriteCreationFailed = true;
        err.printStackTrace();
    }
    return filelog;

}
 

public void DeletOlderFolder() {
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir =
new File(root + "/" + log_foldereventname);
    myDir.mkdirs();
    File list[] = myDir.listFiles();
   
for (int i = 0; i < list.length; i++) {
       
long diff = new Date().getTime() - list[i].getAbsoluteFile().lastModified();
       
if (diff >  3 * 24 * 60 * 60 * 1000) {//3 * 24 * 60 * 60 * 1000(3days)
           
list[i].getAbsoluteFile().delete();
        }
    }
Read more




Explain- The Log file delete alternate in  3 days.


import android.content.Context;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;


public class LogFile {

    Context context;

     public LogFile ( ) {

        DeletOlderFolder();
    }

    public void DeletOlderFolder(){

        File file=new File("sdcard/LoungeLogFile.txt");

        if(file != null) {

            long diff = new Date().getTime() - file.lastModified();

            if (diff > 3 * 24 * 60 * 60 * 1000) {

                file.delete();

            }

        }

    }

}
 
 

public class MainActivity extends Activity  {
 
@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
 
 
new LogFile (); // Delete Log file in 3 days
 
 
}
}


Read more


Explain-  write Log file programmatically in android.


 
import android.content.Context;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;


public class LogClass {
    Context context;

    public LogClass(Context context, String text) {
       this.context=context;
        LogFile(text);
        DeletOlderFolder();
    }

    public  void LogFile( String text){

            File logFile = new File("sdcard/LoungeLogFile.txt");
            if (!logFile.exists()) {
                try {
                    logFile.createNewFile();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
            try {
                BufferedWriter buf = new BufferedWriter(

                                    new FileWriter(logFile, true));
                buf.append(text);
                buf.newLine();
                buf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

    }
 }
Read more