Friday, 10 May 2019

Fix MTP driver Installation on Windows 10

Fix MTP driver Installation on Windows 10

C:\Windows\INF\wpmdmtp.inf

wpmdmtp.inf is a file related to MTP and installing it manually can possibly 
resolve your issues is a file related to MTP and installing it manually can 
possibly resolve your issues

Right-click on the wpmdmtp.inf file and select Install
now the problem solved.

Thursday, 9 May 2019

How to get string if length is more than 50 after 50 it split into another string ?

String st = "A string is a data type used in programming,
 such as an integer and floating point unit,
but is used to represent text rather than numbers";
if (st.length() > 50) {
    int comma = st.indexOf(',', 50);
    if (comma >= 0) {

        //Bit before comma        String partOne = st.substring(0, comma);

        //Bit after comma        String partTwo = st.substring(comma);
        Log.e("string partOne", partOne);
        Log.e("string partTwo", partTwo);
    }
}

Parses a specific value from string against a specific key for xml format data l̥

 Parses a specific value from string against a specific key for xml format data l̥

private String getValueFromString(String key, String input) {
    if (!AppUtility.isNullOrEmpty(input)) {
        try {
            String match = key.toLowerCase() + "=\"";
            String[] dataArray1 = input.split(match);
            String[] dataArray2;
            if (dataArray1 != null && (dataArray1.length > 0)) {
                int size = dataArray1.length;
                if (size > 1) {
                    dataArray2 = dataArray1[1].split("\"");
                    return dataArray2[0].trim();
                } else {
                    match = key.toUpperCase() + "=\"";
                    dataArray1 = input.split(match);
                    if (dataArray1 != null && (dataArray1.length > 0)) {
                        size = dataArray1.length;
                        if (size > 1) {
                            dataArray2 = dataArray1[1].split("\"");
                            return dataArray2[0].trim();
                        }
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return " ";/*empty string*/
}

Tuesday, 9 April 2019

Add quotation at the start and end of each line of string word in Notepad++ and make array in java

1.Find (in regular expression mode):
        (.+)

        Replace with:
        "\1"
        This adds the quotes:
        "amit"        "programming "        "code "        "tech"        
 2.Find (in extended mode):
        \r\n

   Replace with (with a space after the comma, not shown):
        ,

  This converts the lines into a comma-separated list:
        "amit", "programming", "code", "tech"

Number format in indian style RS in java android

import java.text.Format;
import java.text.NumberFormat;
import java.util.Locale;

Code:-

Format format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
     
Log.e("valueindianstyle",format.format("10000000"));

OUTPUT: Rs 1,00,00,000

Monday, 1 April 2019

move a file into another directory location in android with java programmatically


/*move a file into another directory location in android with programmatically*/
   private void moveFile(File file, File dir, File deteleold) throws IOException {
    File newFile = new File(dir, file.getName());
    FileChannel outputChannel = null;
    FileChannel inputChannel = null;
    try {
        outputChannel = new FileOutputStream(newFile).getChannel();
        inputChannel = new FileInputStream(file).getChannel();
        inputChannel.transferTo(0, inputChannel.size(), outputChannel);
        inputChannel.close();
        file.delete();/*remove the file */
    } finally {
        if (inputChannel != null) inputChannel.close();
        if (outputChannel != null) outputChannel.close();
    }

}

Thursday, 10 January 2019

Get RecyclerViewAdapter onclick position in main activity

You can achieve this by creating an interface inside 
your adapter for an itemclicklistener and then you can
 set onItemClickListener from your MainActivity.

Somewhere inside your RecyclerViewAdapter you would
 need the following:



private onRecyclerViewItemClickListener mItemClickListener;


public void setOnItemClickListener(onRecyclerViewItemClickListener mItemClickListener) {

    this.mItemClickListener = mItemClickListener;
}


public interface onRecyclerViewItemClickListener {

    void onItemClickListener(View view, int position);
}


Then inside your ViewHolder (which I've added as an inner class inside my adapter),
 you would apply the listener to the components you'd like the user to click, like so:

 class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public ImageView imageview;

    RecyclerViewHolder(View view) {

        super(view);

        this.imageview = (ImageView) view

                .findViewById(R.id.image);

        imageview.setOnClickListener(this);
    }


    @Override

    public void onClick(View v) {

        if (mItemClickListener != null) {

            mItemClickListener.onItemClickListener(v, getAdapterPosition());
        }
    }
}

This example shows an onClickListener being applied to the image inside a ViewHolder.
To implement this code, you would setOnItemClickListener to your adapter 
inside MainActivity as shown above.


 recyclerView.setAdapter(adapter);// set adapter on recyclerview

            adapter.notifyDataSetChanged();// Notify the adapter

            adapter.setOnItemClickListener(new RecyclerViewAdapter.onRecyclerViewItemClickListener() {

    @Override

    public void onItemClickListener(View view, int position) {

        Switch (view.getId()) {

            case R.id.letter:
                //logic here
                break;

            case R.id.firstname:
                //logic here
                break;
        ....            

        }
    }
});

Wednesday, 9 January 2019

How to use fragment method in Main Activity class


Create interface
public interface ListenFromActivity {    void doSomethingInFragment();}
In Activity class keep refrence of ListenFromActivity interface
public ListenFromActivity activityListener;   
Make public method to set listener
public void setActivityListener(ListenFromActivity activityListener) {        this.activityListener = activityListener;    }
Add some trigger point in activity class, here I have used user interaction
   @Override    public void onUserInteraction() {        super.onUserInteraction();
        if (null != activityListener) {            activityListener.doSomethingInFragment();        }    }

Now in Fragment class
make your fragment implement interface class
public class SomeFragment extends Fragment implements ListenFromActivity
Android studio will prompt you to implement method of interface in fragment
void doSomethingInFragment(){//Add your code here }
Final part part listener instance to activity like this in fragment onCreate method
((ListnerActivity) getActivity()).setActivityListener(SomeFragment.this);
DONE!!. now you can call fragment method from activity.

Saturday, 29 September 2018

Forget password and key of .jsk file : How to retrieve Key Alias and Key Password for signed APK in android studio

On Windows 
 1. C:\Users\amit rawat\.AndroidStudio3.1\system\log\idea.log.1.
 2. Then search for “Pandroid.injected.signing.store” in the idea.log 
3. look like this
 Pandroid.injected.invoked.from.ide=true,
 -Pandroid.injected.signing.store.file=C:\Users\amit rawat\keystore\mykey.keystore.jks, 
- Pandroid.injected.signing.store.password=password, 
-Pandroid.injected.signing.key.alias=mykey,
 -Pandroid.injected.signing.key.password=password

Sunday, 23 September 2018

Cursor values print into Logcat code

Print the cursor to the logcat row by row you can use code as below:
Cursor cursor = mContext.getContentResolver().query(mUri, mProjections, null, null, null);
if (cursor.moveToFirst()) {

    do {

        StringBuilder sb = new StringBuilder();

        int columnsQty = cursor.getColumnCount();

        for (int idx = 0; idx < columnsQty; ++idx) {

            sb.append(cursor.getString(idx));

            if (idx < columnsQty - 1)

                sb.append("; ");

        }

        Log.v(TAG, String.format("Row: %d, Values: %s", cursor.getPosition(),

                sb.toString()));

    } while (cursor.moveToNext());

}

Saturday, 11 August 2018

Check multiple duplicate record in SQLite

 Check multiple duplicate record in SQLite, you can define the column as UNIQUE ON CONFLICT REPLACE like
private static final String TABLE_CREATE_DIAGONESE =
        "CREATE TABLE " + TABLE_DIAGONESE + " (" +
                DIAGNONES_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                DIAGONESE_TEXT + " TEXT UNIQUE ON CONFLICT REPLACE, " +
                DIAGONESE_CREATED + " TEXT default CURRENT_TIMESTAMP," +
                DIAGONESE_ERROR + " INTEGER , "  +
                DIAGONESE_STAR + " INTEGER  "+
                ")";

You can perform insert as usual, the db would ensure no duplicates exist.

Saturday, 19 May 2018

Android shared element Animation or transitions between two activities in android studio

                         Shared Animation Between Two Activity 
Transitions between different activities or fragments involved enter and exit transitions that animated entire view hierarchies independent to each other. Example of such transitions are a fade transition, slide transition.
Note :-the shared element transitions require Android 5.0 (API level 21) and above and will be ignored for any lower API versions. Be sure to check the version at runtime before 
using API 21 specific features.

   
STEP 1. Create a new Project  ActivityAnimation  in Android Studio.
STEP 2. Add dependency under the build.gradle(Module:app).
                            build.gradle(Module:app)
dependencies {

    implementation 'de.hdodenhof:circleimageview:2.1.0'
    implementation 'com.android.support:cardview-v7:27.1.1'

}
STEP 3. Add item in res/values/style.xml that Enable Window Content Transitions
style.xml
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
       <!-- enable window content transition-->
        <item name="android:windowActivityTransitions">true</item>
    </style>

</resources>

STEP 4. 1Paste this .png images in res/drawable folder or you can download your 
            image from internet. And add text into res/values/string.xml
  Click here for --->>  image1, image2

    string.xml
<resources>
    <string name="app_name">ActivityAnimation</string>
    <string name="name">Phil Read – 52 wins</string>
    <string name="dec">Britain rider of all time championships,
 with GP titles in the 125cc, 250cc (x4) and 500cc (x2) classes.</string>

</resources>


Assign a common transition name to the shared elements in both layout   activity_main.xml and activity_second.xml
android:transitionName=" "
2. Write xml code and Create layout in res/layout/activity_main.xml
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"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_gravity="center"
        android:layout_marginTop="40dp"
        android:src="@mipmap/ic_launcher" />

    <android.support.v7.widget.CardView
        android:id="@+id/profile_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="40dp"
        app:cardCornerRadius="5dp"
        app:cardPreventCornerOverlap="true"
        app:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp">
            <!--profile pic-->
            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_img"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:src="@drawable/programmingcodetechprofile"
                android:transitionName="profileimg_transiton"<!--transitionName same as in activity_second.xml pic -->
                app:civ_border_color="@color/black"
                app:civ_border_width="1dp" />

            <!--tile and description -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginStart="10dp"
                android:layout_toEndOf="@id/profile_img"
                android:layout_toRightOf="@+id/profile_img"
                android:orientation="vertical">

                <!--title-->
                <TextView
                    android:id="@+id/profile_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/name"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/black"
                    android:textStyle="bold"
                    android:transitionName="profilename_transiton" />
<!--transitionName same as in activity_second.xml title -->

<!--description-->
                <TextView
                    android:id="@+id/profile_dec"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/dec"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:transitionName="profiledes_transiton" />
<!--transitionName same as in activity_second.xml description -->


            </LinearLayout>

        </RelativeLayout>

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

</LinearLayout>

3.  Write xml code and Create layout file res/layout/activity_second.xml
activity_second.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_margin="5dp"
    android:orientation="vertical"
    android:paddingTop="30dp">
    <!--profile pic-->
    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/shared_img"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:src="@drawable/programmingcodetechprofile"
        android:transitionName="profileimg_transiton"<!--transitionName same as in activity_main.xml profiel pic -->
        app:civ_border_color="@color/black"
        app:civ_border_width="1dp" />
    <!--tile and description -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:layout_toEndOf="@id/profile_img"
        android:layout_toRightOf="@+id/profile_img"
        android:orientation="vertical">

        <!--title-->
        <TextView
            android:id="@+id/shared_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:text="@string/name"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/black"
            android:textStyle="bold"
            android:transitionName="profilename_transiton" />
<!--transitionName same as in activity_main.xml title -->
        
<!--description-->
        <TextView
            android:id="@+id/shared_dec"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="5dp"
            android:text="@string/dec"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:transitionName="profiledes_transiton" />
<!--transitionName same as in activity_main.xml description -->


    </LinearLayout>

</LinearLayout>

STEP 5. Create and Codin java/MainActivity.java
MainActivity.java 
package com.example.amitrawat.activityanimation;

import android.app.ActivityOptions;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.util.Pair;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    CardView profile_card;
    de.hdodenhof.circleimageview.CircleImageView profile_img;
    TextView profile_nameprofile_decmsg;

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

        profile_card = findViewById(R.id.profile_card);
        profile_img = findViewById(R.id.profile_img);
        profile_name = findViewById(R.id.profile_name);
        profile_dec = findViewById(R.id.profile_dec);

        profile_card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent sharedintent = new Intent(MainActivity.this, SecondActivity.class);
                Pair[] pairs = new Pair[3];
                pairs[0] = new Pair<View, String>(profile_img"profileimg_transiton");
                pairs[1] = new Pair<View, String>(profile_name"profilename_transiton");
                pairs[2] = new Pair<View, String>(profile_dec"profiledes_transiton");

                ActivityOptions option = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, pairs);
                startActivity(sharedintent, option.toBundle());

            }
        });
    }
}

STEP 6. Create and Code in java/SecondActivity.java 
SecondActivity.java 
package com.example.amitrawat.activityanimation;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

public class SecondActivity extends AppCompatActivity {
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
    }
}

STEP 7. Entry MainActivity.java and SecondActivity.java in mainfest/Android.xml
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.amitrawat.activityanimation">

    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".SecondActivity" />
    </application>

</manifest>