Android how to remove new line and spaces and all html tags from String

Step 1: 

compile 'org.jsoup:jsoup:1.11.3'

add jsonup gradle and sync. 

Step 2 : 
create a method
public static String html2text(String html) {
    return Jsoup.parse(html).text();
}

Step 3 : 
implement this
String descriptionRawText = "raw text";
String descriptionFinalText = descriptionRawText.replace("\n", "").replaceAll("\\<[^>]*>","").replace("\r", "");
String htmlConvertedText = html2text(descriptionFinalText);
productDesc.setText(Html.fromHtml(String.valueOf(Html.fromHtml(htmlConvertedText))));



Done :) 







Android Google map clustering – how to show actual marker in cluster

1 . Create Custom Cluster renderer

[java]
package com.findbitcoinatm.android.utils;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.util.SparseArray;
import android.view.ViewGroup;

import com.findbitcoinatm.android.models.cluster.ATMClusterItems;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.clustering.view.DefaultClusterRenderer;
import com.google.maps.android.ui.IconGenerator;
import com.google.maps.android.ui.SquareTextView;

public class MyClusterItemRenderer extends DefaultClusterRenderer&lt;ATMClusterItems&gt; {

private final IconGenerator mIconGenerator;
private final ShapeDrawable mColoredCircleBackground;
private final float mDensity;

private SparseArray&lt;BitmapDescriptor&gt; mIcons = new SparseArray();

public MyClusterItemRenderer(Context context, GoogleMap map, ClusterManager&lt;ATMClusterItems&gt; clusterManager) {
super(context, map, clusterManager);
mIconGenerator = new IconGenerator(context);
mColoredCircleBackground = new ShapeDrawable(new OvalShape());
mDensity = context.getResources().getDisplayMetrics().density;

SquareTextView squareTextView = new SquareTextView(context);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-2, -2);
squareTextView.setLayoutParams(layoutParams);
squareTextView.setId(com.google.maps.android.R.id.amu_text);
int twelveDpi = (int)(12.0F * this.mDensity);
squareTextView.setPadding(twelveDpi, twelveDpi, twelveDpi, twelveDpi);
this.mIconGenerator.setContentView(squareTextView);

mIconGenerator.setTextAppearance(com.google.maps.android.R.style.amu_Bubble_TextAppearance_Light);

ShapeDrawable outline = new ShapeDrawable(new OvalShape());
outline.getPaint().setColor(Color.parseColor("#FFFFFF"));
LayerDrawable background = new LayerDrawable(new Drawable[]{outline, this.mColoredCircleBackground});
int strokeWidth = (int) (this.mDensity * 3.0F);
background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
mIconGenerator.setBackground(background);

}

public int getBucket(Cluster&lt;ATMClusterItems&gt; cluster) {
int size = cluster.getSize();
return size;
}

@Override
protected void onBeforeClusterRendered(Cluster&lt;ATMClusterItems&gt; cluster, MarkerOptions markerOptions) {
int bucket = this.getBucket(cluster);
BitmapDescriptor descriptor = (BitmapDescriptor)this.mIcons.get(bucket);
if(descriptor == null) {
this.mColoredCircleBackground.getPaint().setColor(this.getColor(bucket));
descriptor = BitmapDescriptorFactory.fromBitmap(this.mIconGenerator.makeIcon(String.valueOf(cluster.getSize())));
this.mIcons.put(bucket, descriptor);
}

markerOptions.icon(descriptor);
}
}
[/java]

2 . And google map class – just call the custom renderer class

[java]
mClusterManager.setRenderer(new MyClusterItemRenderer(getActivity(), mMap, mClusterManager));
[/java]

Like this

[java]
mClusterManager = new ClusterManager&lt;ATMClusterItems&gt;(getActivity(), mMap);
mClusterManager.setRenderer(new MyClusterItemRenderer(getActivity(), mMap, mClusterManager));
[/java]

And done . 🙂

Error:Execution failed for task ‘:app:preDebugAndroidTestBuild’. > Conflict with dependency ‘com.android.support:support-annotations’ in project ‘:app’. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

Solution :

compile 'com.android.support:support-annotations:27.1.1' to gradle(app) and sync . Solved :)


Example : 
apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.arifhasnat.islamicbooks"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.android.support:support-annotations:27.1.1'
    compile 'com.github.barteksc:android-pdf-viewer:2.8.2'
}

Android how to add collapsing toolbar with layout body touch collapse and expand

1 .

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
 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.adn.activities.root.HomeActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
       >



        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true"

            >


            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/AppTheme.PopupOverlay" >



                    <!--<ImageView-->
                    <!--android:src="@drawable/logo"-->
                    <!--android:layout_width="@dimen/count_60dp"-->
                    <!--android:layout_height="wrap_content" />-->

                </android.support.v7.widget.Toolbar>





            </LinearLayout>




</android.support.design.widget.CollapsingToolbarLayout>


        <EditText
            android:id="@+id/search_bar"
            android:background="@drawable/corner_radious"
            android:layout_width="match_parent"
            android:editable="false"
            android:layout_height="@dimen/count_40dp"
            android:paddingLeft="@dimen/count_10dp"
            android:drawableLeft="@drawable/search_gray_24"
            android:hint="Search for Products, Brands and More "
            android:textSize="@dimen/count_12dp"
            android:drawablePadding="@dimen/count_10dp"
            android:textColorHint="@color/dark_gray"
            android:textColor="@color/dark_gray"
            android:layout_marginLeft="@dimen/count_10dp"
            android:layout_marginRight="@dimen/count_10dp"
            android:layout_marginBottom="@dimen/count_5dp"

            />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_home2" />



</android.support.design.widget.CoordinatorLayout>



2. In content layout add inner scroll view 


<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 
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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.adn.activities.root.HomeActivity"
    tools:showIn="@layout/app_bar_home">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>



3 . Call this method in onCreate 

private void setAppBarDragging(final boolean newValue) {
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout);
    CoordinatorLayout.LayoutParams params =
            (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
    AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
    behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
        @Override
        public boolean canDrag(AppBarLayout appBarLayout) {
            return newValue;
        }
    });
    params.setBehavior(behavior);
}


and done :)

Android show collapsing toolbar layout title only when collapsed

final CollapsingToolbarLayout collapsingToolbarLayout = 
(CollapsingToolbarLayout) findViewById(R.id.collapsingToolbarLayout);
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    boolean isShow = true;
    int scrollRange = -1;

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (scrollRange == -1) {
            scrollRange = appBarLayout.getTotalScrollRange();
        }
        if (scrollRange + verticalOffset == 0) {
            collapsingToolbarLayout.setTitle("Title");
            isShow = true;
        } else if(isShow) {
            collapsingToolbarLayout.setTitle(" ");
          //carefull there should a space between double quote otherwise it wont work 
            isShow = false;
        }
    }
}); 

Source : stackoverflow

itunesconnect supported screenshoot sizes

The following resolutions are acceptable to iTunes connect:

  • iPhone 3+4 (3.5 Inch)
    • 640 x 960
  • iPhone 5 (4 Inch)
    • 640 x 1136
  • iPhone 6 (4.7 Inch)
    • 750 x 1334
  • iPhone 6 Plus (5.5 Inch)
    • 1242 x 2208
    • You need the screenshot in this resolution, the phone scales them down to 1080 x 1920
  • iPhone X
    • 1125 x 2436
  • iPad (Air and Mini Retina)
    • 1536 x 2048
  • iPad Pro (12.9 Inch)
    • 2048 x 2732
  • Apple Watch
    • 312 x 390 pixels
    • (only one orientation)

Android navigation/ toolbar back

Step one :

put these in oncreate method

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

 

 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

   
}

Step two :

Give action to go specific page or actions

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent(fromActivity.this, toActivity.class);
    startActivity(intent);
    return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    Intent intent = new Intent(fromActivity.this, toActivity.class);
    startActivity(intent);
}