Thursday, 27 April 2017

Interview Questions

1.Activity to thread communicaton
2.static and dynamic broad cast receivers
3.collection and collections diff
4.Arraylist and /array internally working memory...etc
5.java how to create synchronised object
6.Asynctask internal communication
7.Asyntask simultaneously run how?
8.Sharing file b/w application developed by same developer
9.Broadcast receivers and intent filters
10.Custombroad cast
If we do not know intent filters then how can we listen for broad cast?
11.Content Provider Athorisation Token
12.Custom HashMap
13.Activit ifeCucle
14.Data Abstraction
15.Service start two times
16.ArrayList Creation ways
17.Collision
18.Producer Consumer Problem
19.Thread LifeCycle
20.Thread Architecture Java
21.DVM
22.Application Architecture
23.Intent Service
24.Intent Filter


1: Explain Android Architecture?
2: Activity life cycle?
3. Fragment life cycle?
4. Difference between Service,Asynctask,Thread?
5. Difference between Hashmap and Hashtable?
6. What is task affinity?
7. Permission required to access user Location in android?
8. Have you worked in Map integration?Explain in brief.
9.Have you worked in Camera integration?Explain in brief.
10. What are Crash and user analytics tools?
11. How to do good memory management in Android?
12. What is Broadcast receiver?
13.What is Notification?
14 Twitter,Facebook integration.
15. Intent and intent filter.
16. How to create custom permission in Android?
17. Difference between <permission> and <uses permission> tag in Manifest file?
18. What is the use of minSdkVersion,maxSdkVersion,targetSdkVersion in <uses-sdk> in Manifest file?
19 What are Android application components?
20. Why fragment is required?
21 Example of Inheritance in Android application?
22 What is content provider?How to create your own content provider?
23. Difference between content provider and Sqlite database?
24 Have you worked in OpenGL,3d animation in Android?
25. Version control systems.
26.Multiple screen support in Android?
27.Multiple language support in Android?
28. About latest Android OS and what are the new features added on it?
29 Have you developed in any open source library?

Thursday, 20 April 2017

Onclick listener on the view items in RecyclerViewAdapter

int pos = getAdapterPosition();

Call this inside viewholder defined in adapter

One of example
http://wiki.workassis.com/android-recyclerview-example/

Wednesday, 12 April 2017

Resize Bitmap Size Android



Uri selectedImageUri = data.getData();

String[] fileProperties = {MediaStore.Images.Media.DATA};

Cursor cursor = getContentResolver().query(selectedImageUri, fileProperties, null, null, null);
cursor.moveToFirst();

int filePathIndex = cursor.getColumnIndex(fileProperties[0]);
String selectedImagePath = cursor.getString(filePathIndex);
String imageDec = decodeFile(selectedImagePath , 200 , 200);

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedImagePath, options);
options.inSampleSize = CommonUtils.calculateInSampleSize(options, 200,
        200);
options.inJustDecodeBounds = false;
Bitmap profileImageBitmap = BitmapFactory.decodeFile(selectedImagePath, options);


//Resize method



public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
    int width = image.getWidth();
    int height = image.getHeight();

    float bitmapRatio = (float)width / (float) height;
    if (bitmapRatio > 1) {
        width = maxSize;
        height = (int) (width / bitmapRatio);
    } else {
        height = maxSize;
        width = (int) (height * bitmapRatio);
    }
    return Bitmap.createScaledBitmap(image, width, height, true);
}


Tuesday, 11 April 2017

Android Softkeyboard Listener

public class KeyboardWatcher {
    private final WeakReference<Activity> activityRef;
    private WeakReference<View> rootViewRef;
    private WeakReference<OnKeyboardToggleListener> onKeyboardToggleListenerRef;
    private ViewTreeObserver.OnGlobalLayoutListener viewTreeObserverListener;

    /**     * Instantiates a new Keyboard watcher.     *     * @param activity the activity     */    public KeyboardWatcher(Activity activity) {
        activityRef = new WeakReference<>(activity);
        initialize();
    }

    /**     * Sets listener.     *     * @param onKeyboardToggleListener the on keyboard toggle listener     */    public void setListener(OnKeyboardToggleListener onKeyboardToggleListener) {
        onKeyboardToggleListenerRef = new WeakReference<>(onKeyboardToggleListener);
    }

    /**     * Destroy.     */    public void destroy() {
        if (rootViewRef.get() != null)
            if (Build.VERSION.SDK_INT >= 16) {
                rootViewRef.get().getViewTreeObserver().removeOnGlobalLayoutListener(viewTreeObserverListener);
            } else {
                rootViewRef.get().getViewTreeObserver().removeGlobalOnLayoutListener(viewTreeObserverListener);
            }
    }

    private void initialize() {
        if (hasAdjustResizeInputMode()) {
            viewTreeObserverListener = new GlobalLayoutListener();
            rootViewRef = new WeakReference<>(activityRef.get().findViewById(Window.ID_ANDROID_CONTENT));
            rootViewRef.get().getViewTreeObserver().addOnGlobalLayoutListener(viewTreeObserverListener);
        } else {
            throw new IllegalArgumentException(String.format("Activity %s should have windowSoftInputMode=\"adjustResize\"" +
                    "to make KeyboardWatcher working. You can set it in AndroidManifest.xml", activityRef.get().getClass().getSimpleName()));
        }
    }

    private boolean hasAdjustResizeInputMode() {
        return (activityRef.get().getWindow().getAttributes().softInputMode & WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) != 0;
    }

    /**     * The interface On keyboard toggle listener.     */    public interface OnKeyboardToggleListener {
        /**         * On keyboard shown.         */        void onKeyboardShown();

        /**         * On keyboard closed.         */        void onKeyboardClosed();
    }

    private class GlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {
        /**         * The Initial value.         */        int initialValue;
        /**         * The Has sent initial action.         */        boolean hasSentInitialAction;
        /**         * The Is keyboard shown.         */        boolean isKeyboardShown;

        @Override        public void onGlobalLayout() {
            if (initialValue == 0) {
                initialValue = rootViewRef.get().getHeight();
            } else {
                if (initialValue > rootViewRef.get().getHeight()) {
                    if (onKeyboardToggleListenerRef.get() != null) {
                        if (!hasSentInitialAction || !isKeyboardShown) {
                            isKeyboardShown = true;
                            onKeyboardToggleListenerRef.get().onKeyboardShown();
                        }
                    }
                } else {
                    if (!hasSentInitialAction || isKeyboardShown) {
                        isKeyboardShown = false;
                        rootViewRef.get().post(new Runnable() {
                            @Override                            public void run() {
                                if (onKeyboardToggleListenerRef.get() != null) {
                                    onKeyboardToggleListenerRef.get().onKeyboardClosed();
                                }
                            }
                        });
                    }
                }
                hasSentInitialAction = true;
            }
        }
    }

}


Implement it and register for it in oncreate

keyboardWatcher = new KeyboardWatcher(this);
keyboardWatcher.setListener(this);

and then override following mehods

@Overridepublic void onKeyboardShown() {
 
}

@Overridepublic void onKeyboardClosed() {

 

}

Push Layout above android keyboard

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_888
android:orientation="vertical">
<include layout="@layout/toolbar" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="40dp"
android:background="@color/color_separator" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.sample.customwidget.CustomTextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_weight="1"
android:padding="20dp"
android:text="@string/signature"
android:textColor="@color/colorBlack"
android:textSize="@dimen/text_size_18sp"
android:textStyle="bold"
/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:theme="@style/SwitchTheme" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/color_separator" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="40dp"
android:background="@color/color_separator" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.sample.customwidget.RichEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:gravity="left"
android:imeOptions="actionDone"
android:inputType="text|textNoSuggestions|textMultiLine"
android:minHeight="200dp"
android:padding="20dp"
android:textColor="@color/colorBlack"
android:textSize="@dimen/text_size_18sp"
android:textStyle="normal" />
<com.sample.customwidget.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_weight="1"
android:lineSpacingExtra="4dp"
android:padding="15dp"
android:text="@string/signature_enabled_str"
android:textColor="@color/color_141_166_177"
android:textSize="@dimen/text_size_14sp"
oracle:customFont="@string/font_roboto_regular" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</LinearLayout>
//Tool Bar Here
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorWhite"
android:orientation="vertical"
android:visibility="gone">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="@color/colorGrayDark" />
<LinearLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="5">
<ToggleButton
android:id="@+id/Settings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/xxx"
android:contentDescription="@string/desc_fonts"
android:textOff=""
android:textOn="" />
<com.sample.richtexteditor.richtext.RichTextToolbarImageButton
android:id="@+id/toolbar_bold"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/font_style_bold_toggle_selector" />
<com.sample.richtexteditor.richtext.RichTextToolbarImageButton
android:id="@+id/toolbar_italic"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/font_style_italic_toggle_selector" />
<com.sample.richtexteditor.richtext.RichTextToolbarImageButton
android:id="@+id/toolbar_bullet"
style="?attr/rte_ToolbarButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/font_style_bullet_toggle_selector" />
<com.sample.richtexteditor.richtext.RichTextToolbarImageButton
android:id="@+id/toolbar_bullet_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/font_style_bullet_toggle_number_selector" />
</LinearLayout>
<LinearLayout
android:id="@+id/font_settings_"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/my_toolbar"
android:orientation="vertical"
android:visibility="gone">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="@color/colorGrayDark" />
<LinearLayout
android:id="@+id/font_size_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="4">
<com.sample.customwidget.CustomTextView
android:id="@+id/fontSizeTiny"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/desc_small_text_size"
android:gravity="center"
android:text="T"
android:textColor="@color/colorBlack"
android:textSize="12sp"
oracle:customFont="@string/font_roboto_medium" />
<com.sample.customwidget.CustomTextView
android:id="@+id/fontSizeSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/desc_medium_text_size"
android:gravity="center"
android:text="T"
android:textColor="@color/colorBlack"
android:textSize="16sp"
oracle:customFont="@string/font_roboto_medium" />
<com.sample.customwidget.CustomTextView
android:id="@+id/fontSizeMedium"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/desc_large_text_size"
android:gravity="center"
android:text="T"
android:textColor="@color/colorBlack"
android:textSize="24sp"
oracle:customFont="@string/font_roboto_medium" />
<com.sample.customwidget.CustomTextView
android:id="@+id/fontSizeLarge"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/desc_extra_large_text_size"
android:gravity="center"
android:src="@drawable/add"
android:text="T"
android:textColor="@color/colorBlack"
android:textSize="32sp"
oracle:customFont="@string/font_roboto_medium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="@color/colorGrayDark" />
<LinearLayout
android:id="@+id/font_family_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="2">
<com.sample.customwidget.CustomTextView
android:id="@+id/fonts_header_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="@string/fonts_settings_header_text"
android:textColor="@color/colorBlack"
android:textSize="@dimen/text_size_16sp"
oracle:customFont="@string/font_roboto_medium" />
<com.sample.customwidget.CustomTextView
android:id="@+id/fonts_family_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="DEFAULT"
android:textColor="@color/fontValueColor"
android:textSize="@dimen/text_size_16sp"
oracle:customFont="@string/font_roboto_medium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="@color/colorGrayDark" />
<include layout="@layout/color_picker" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
</LinearLayout>

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...