Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Tuesday, October 22, 2019

android animation-

shaking / wobble view animation in android

/**
 *
 * @param view      view that will be animated
 * @param duration  for how long in ms will it shake
 * @param offset    start offset of the animation
 * @return          returns the same view with animation properties
 */
public static View makeMeShake(View view, int duration, int offset) {
    Animation anim = new TranslateAnimation(-offset,offset,0,0);
    anim.setDuration(duration);
    anim.setRepeatMode(Animation.REVERSE);
    anim.setRepeatCount(5);
    view.startAnimation(anim);
    return view;
}
use:
TextView tv;
makeMeShake(tv,20,5);    // it will shake quite fast

Wednesday, October 16, 2019

PIN code android

public class OTPEditText extends AppCompatEditText {
    private float mSpace = 24; //24 dp by default, space between the lines    private float mNumChars = 4;
    private float mLineSpacing = 8; //8dp by default, height of the text from our lines    private int mMaxLength = 4;
    private float mLineStroke = 2;
    private Paint mLinesPaint;
    private OnClickListener mClickListener;

    public OTPEditText(Context context) {
        super(context);
    }

    public OTPEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public OTPEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        float multi = context.getResources().getDisplayMetrics().density;
        mLineStroke = multi * mLineStroke;
        mLinesPaint = new Paint(getPaint());
        mLinesPaint.setStrokeWidth(mLineStroke);
        mLinesPaint.setColor(getResources().getColor(R.color.brand_color));
        setBackgroundResource(0);
        mSpace = multi * mSpace; //convert to pixels for our density        mLineSpacing = multi * mLineSpacing; //convert to pixels for our density        mNumChars = mMaxLength;

        super.setOnClickListener(new OnClickListener() {
            @Override            public void onClick(View v) {
                // When tapped, move cursor to end of text.                setSelection(getText().length());
                if (mClickListener != null) {
                    mClickListener.onClick(v);
                }
            }
        });
    }

    @Override    public void setOnClickListener(OnClickListener l) {
        mClickListener = l;
    }

    @Override    protected void onDraw(Canvas canvas) {
        int availableWidth = getWidth() - getPaddingRight() - getPaddingLeft();
        float mCharSize;
        if (mSpace < 0) {
            mCharSize = (availableWidth / (mNumChars * 2 - 1));
        } else {
            mCharSize = (availableWidth - (mSpace * (mNumChars - 1))) / mNumChars;
        }

        int startX = getPaddingLeft();
        int bottom = getHeight() - getPaddingBottom();

        //Text Width        Editable text = getText();
        int textLength = text.length();
        float[] textWidths = new float[textLength];
        getPaint().getTextWidths(getText(), 0, textLength, textWidths);

        for (int i = 0; i < mNumChars; i++) {
            canvas.drawLine(startX, bottom, startX + mCharSize, bottom, mLinesPaint);
            if (getText().length() > i) {
                float middle = startX + mCharSize / 2;
                canvas.drawText(text, i, i + 1, middle - textWidths[0] / 2, bottom - mLineSpacing, getPaint());
            }
            if (mSpace < 0) {
                startX += mCharSize * 2;
            } else {
                startX += mCharSize + mSpace;
            }
        }
    }
    }

Monday, October 14, 2019

Image Resize / roated in android

private String getRightAngleImage(String photoPath) {

    try {
        ExifInterface ei = new ExifInterface(photoPath);
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int degree = 0;

        switch (orientation) {
            case ExifInterface.ORIENTATION_NORMAL:
                degree = 0;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
            case ExifInterface.ORIENTATION_UNDEFINED:
                degree = 0;
                break;
            default:
                degree = 90;
        }

        return rotateImage(degree,photoPath);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return photoPath;
}

private String rotateImage(int degree, String imagePath) {

    if (degree <= 0) {
        return imagePath;
    }
    try {
        Bitmap b = BitmapFactory.decodeFile(imagePath);

        Matrix matrix = new Matrix();
        if (b.getWidth() > b.getHeight()) {
            matrix.setRotate(degree);
            b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(),
                    matrix, true);
        }

        FileOutputStream fOut = new FileOutputStream(imagePath);
        String imageName = imagePath.substring(imagePath.lastIndexOf("/") + 1);
        String imageType = imageName.substring(imageName.lastIndexOf(".") + 1);

        FileOutputStream out = new FileOutputStream(imagePath);
        if (imageType.equalsIgnoreCase("png")) {
            b.compress(Bitmap.CompressFormat.PNG, 100, out);
        } else if (imageType.equalsIgnoreCase("jpeg") || imageType.equalsIgnoreCase("jpg")) {
            b.compress(Bitmap.CompressFormat.JPEG, 100, out);
        }
        fOut.flush();
        fOut.close();

        b.recycle();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return imagePath;
}

Thursday, October 10, 2019

My Note private policy


Privacy Policy

Md. Amirul islam built the My Note app as
a Free app. This SERVICE is provided by
Md. Amirul islam at no cost and is intended for
use as is.

This page is used to inform visitors regarding
my policies with the collection, use, and
disclosure of Personal Information if anyone decided to use
my Service.

If you choose to use my Service, then you agree
to the collection and use of information in relation to this
policy. The Personal Information that I collect is
used for providing and improving the Service.
I will not use or share your
information with anyone except as described in this Privacy
Policy.

The terms used in this Privacy Policy have the same meanings
as in our Terms and Conditions, which is accessible at
My Note unless otherwise defined in this Privacy
Policy.

Information Collection and Use

For a better experience, while using our Service,
I may require you to provide us with certain
personally identifiable information, including but not limited to myNote, task. The
information that I request will be
retained on your device and is not collected by me in any way.

The app does use third party services that may collect
information used to identify you.

Link to privacy policy of third party service providers
used by the app

Log Data

I want to inform you that whenever
you use my Service, in a case of an error in the
app I collect data and information (through third
party products) on your phone called Log Data. This Log Data
may include information such as your device Internet
Protocol (“IP”) address, device name, operating system
version, the configuration of the app when utilizing
my Service, the time and date of your use of the
Service, and other statistics.

Cookies

Cookies are files with a small amount of data that are
commonly used as anonymous unique identifiers. These are
sent to your browser from the websites that you visit and
are stored on your device's internal memory.

This Service does not use these “cookies” explicitly.
However, the app may use third party code and libraries that
use “cookies” to collect information and improve their
services. You have the option to either accept or refuse
these cookies and know when a cookie is being sent to your
device. If you choose to refuse our cookies, you may not be
able to use some portions of this Service.

Service Providers

I may employ third-party companies
and individuals due to the following reasons:

  • To facilitate our Service;
  • To provide the Service on our behalf;
  • To perform Service-related services; or
  • To assist us in analyzing how our Service is used.

I want to inform users of this
Service that these third parties have access to your
Personal Information. The reason is to perform the tasks
assigned to them on our behalf. However, they are obligated
not to disclose or use the information for any other
purpose.

Security

I value your trust in providing us
your Personal Information, thus we are striving to use
commercially acceptable means of protecting it. But remember
that no method of transmission over the internet, or method
of electronic storage is 100% secure and reliable, and
I cannot guarantee its absolute security.

Links to Other Sites

This Service may contain links to other sites. If you click
on a third-party link, you will be directed to that site.
Note that these external sites are not operated by
me. Therefore, I strongly advise you to
review the Privacy Policy of these websites.
I have no control over and assume no
responsibility for the content, privacy policies, or
practices of any third-party sites or services.

Children’s Privacy

These Services do not address anyone under the age of 13.
I do not knowingly collect personally
identifiable information from children under 13. In the case
I discover that a child under 13 has provided
me with personal information,
I immediately delete this from our servers. If you
are a parent or guardian and you are aware that your child
has provided us with personal information, please contact
me so that I will be able to do
necessary actions.

Changes to This Privacy Policy

I may update our Privacy Policy from
time to time. Thus, you are advised to review this page
periodically for any changes. I will
notify you of any changes by posting the new Privacy Policy
on this page. These changes are effective immediately after
they are posted on this page.

Contact Us

If you have any questions or suggestions about
my Privacy Policy, do not hesitate to contact
me at amirul.csejust@gmail.com.

This privacy policy page was created at
privacypolicytemplate.net
and modified/generated by
App Privacy Policy Generator

Saturday, October 5, 2019

How to Handle Fragment from Main Activity backpress


MainActivity.java

public interface OnBackPressedListner{
    boolean onBackPressed();
}



@Overridepublic void onBackPressed() {


Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.mainContent);
if(!(fragment instanceof  OnBackPressedListner)|| !((OnBackPressedListner)fragment).onBackPressed()){

    Toast.makeText(this, "back", Toast.LENGTH_SHORT).show();
    setTitle("HSC ICT");
   super.onBackPressed();
}else {

    if (doubleBackToExitPressedOnce) {
        finish();
    }

    this.doubleBackToExitPressedOnce = true;
    Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();

    new Handler().postDelayed(new Runnable() {

        @Override        public void run() {
            doubleBackToExitPressedOnce=false;
        }
    }, 2000);



   // Toast.makeText(this, "new ", Toast.LENGTH_SHORT).show();}

}




In Fragment :-

public class FirstChapter extends Fragment implements MainActivity.OnBackPressedListner 
{


@Overridepublic boolean onBackPressed() {
    Toast.makeText(getContext(), "Back Click", Toast.LENGTH_SHORT).show();
    return false;
}


}




Easily handle Fragment from Activity.

Thursday, September 19, 2019

Recycler view different view type- android studio

public class LiteratureAdapter extends RecyclerView.Adapter {

    private List<Literature> mLiteratureList;

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView;
        switch (viewType) {
            case Literature.TYPE_BOOK:
                itemView = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.your_layout, parent, false);
                return new BookViewHolder(itemView);
            case Literature.TYPE_MAGAZINE:
                itemView = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.your_layout, parent, false);
                return new MagazineViewHolder(itemView);
            default: // TYPE_NEWSPAPER
                itemView = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.your_layout, parent, false);
                return new NewspaperViewHolder(itemView);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        switch (getItemViewType(position)) {
            case Literature.TYPE_BOOK:
                ((BookViewHolder) holder).bindView(position);
                break;
            case Literature.TYPE_MAGAZINE:
                ((MagazineViewHolder) holder).bindView(position);
                break;
            case Literature.TYPE_NEWSPAPER:
                ((NewspaperViewHolder) holder).bindView(position);
                break;
        }
    }

    @Override
    public int getItemCount() {
        if (mLiteratureList == null) {
            return 0;
        } else {
            return mLiteratureList.size();
        }
    }

    @Override
    public int getItemViewType(int position) {
        return mLiteratureList.get(position).getType();
    }

    public void setLiteratureList(List<? extends Literature> literatureList) {
        if (mLiteratureList == null){
            mLiteratureList = new ArrayList<>();
        }
        mLiteratureList.clear();
        mLiteratureList.addAll(literatureList);
        notifyDataSetChanged();
    }

    class BookViewHolder extends RecyclerView.ViewHolder {

        public BookViewHolder(View itemView) {
            super(itemView);
            // get reference to views
            // itemView.findViewById...
        }

        void bindView(int position) {
            Book book = (Book) mLiteratureList.get(position);
            // bind data to the views
            // textView.setText()...
        }
    }

    class MagazineViewHolder extends RecyclerView.ViewHolder {

        public MagazineViewHolder(View itemView) {
            super(itemView);
            // get reference to views
        }

        void bindView(int position) {
            Magazine magazine = (Magazine) mLiteratureList.get(position);
            // bind data to the views
        }
    }

    class NewspaperViewHolder extends RecyclerView.ViewHolder {

        public NewspaperViewHolder(View itemView) {
            super(itemView);
            // get reference to views
        }

        void bindView(int position) {
            Newspaper newspaper = (Newspaper) mLiteratureList.get(position);
            // bind data to the views
        }
    }
}

Wednesday, March 6, 2019

Progress bar in android studio


Drawable - custom_progressbar.xml


<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"    android:fromDegrees="0"    android:pivotX="50%"    android:pivotY="50%"    android:toDegrees="1440">
    <shape        android:innerRadiusRatio="3"        android:shape="ring"        android:thicknessRatio="8"        android:thickness="4dp"        android:useLevel="false">

        <gradient            android:angle="0"            android:endColor="@color/brand_color"            android:startColor="@android:color/transparent"            android:type="sweep"            android:useLevel="false" />

    </shape>
</rotate>


<LinearLayout    android:id="@+id/llProfile"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:clickable="true"    android:gravity="center_horizontal"    android:orientation="horizontal"    android:padding="@dimen/base_padding">

    <RelativeLayout        android:layout_width="180dp"        android:layout_height="180dp">

        <de.hdodenhof.circleimageview.CircleImageView            android:id="@+id/ivProfile"            android:layout_width="120dp"            android:layout_height="120dp"            android:layout_centerInParent="true"            android:src="@mipmap/motherboard"            app:civ_border_color="@color/grey_300"            app:civ_border_width="1dp" />

        <ImageView            android:layout_width="32dp"            android:layout_height="32dp"            android:layout_below="@+id/ivProfile"            android:layout_gravity="bottom"            android:layout_marginLeft="-20dp"            android:layout_marginTop="-15dp"            android:layout_toRightOf="@+id/ivProfile"            android:tint="@color/black"            app:srcCompat="@drawable/ic_edit_profile" />


        <ProgressBar            android:id="@+id/progress_bar"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_centerInParent="true"            android:indeterminateDrawable="@drawable/custom_progress_dialog"            android:visibility="gone" />


    </RelativeLayout>


</LinearLayout>




private void initProgressBar() {
    progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
    progressBar.setIndeterminate(true);

    RelativeLayout relativeLayout = new RelativeLayout(this);
    relativeLayout.setGravity(Gravity.CENTER);
   relativeLayout.setBackgroundColor(Color.TRANSPARENT);
    relativeLayout.addView(progressBar);

    RelativeLayout.LayoutParams params = new            
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
   // progressBar.setVisibility(View.INVISIBLE);

    this.addContentView(relativeLayout, params);
    progressBar.setVisibility(View.VISIBLE);
}

Tuesday, February 19, 2019

Edit text field check.. email cannot be empty.

public static boolean emptyChecker(EditText[] editTexts, Activity activity) {
    /**     * checking input field for empty or not     */    int totalLength = 0;
    for (int i = 0; i < editTexts.length; i++) {
        EditText editText = editTexts[i];
        if (editText.getText().toString().trim().equals("")) {
            Toast.makeText(activity, editTexts[i].getTag().toString() + " " + activity.getString(R.string.is_empty), Toast.LENGTH_SHORT).show();
            break;
        } else {
            if (editText.getTag().toString().toLowerCase().equals(activity.getString(R.string.email).toLowerCase())) {
                String email = editText.getText().toString().trim();
                String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
                if (!email.matches(emailPattern)) {
                    Toast.makeText(activity, activity.getString(R.string.invalid), Toast.LENGTH_SHORT).show();
                    break;
                } else {
                    totalLength++;
                }
            } else {
                totalLength++;
            }

        }
    }
    //true means all okay    //false means at least one is empty    return totalLength == editTexts.length;
}




Tuesday, November 13, 2018

use back4app.com for parsing data from server very easy







Step 1 - Set up

At the beginning of each Parse activity, import the following:
1
2
3
4
5
6
7
8
9
10
11
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseUser;  


Step 2 - Sign Up

Signing up basically involves saving a new object of class ParseUser, shown as “User” in your app Dashboard, and setting at least two of its pre-defined attributes: username and password. In order to set these attributes, two specific methods of this class are used: ParseUser.setUsername() and ParseUser.setPassword().
The method used for saving the new user on the Dashboard is ParseUser.signUpInBackground(), which may come together with a callback function.
Note: Objects of this special class are not saved on the Dashboard with ParseObject.save() method.
To make SignUpActivity work, follow these steps:
  1. Import into your SignUpActivity, in addition to the dependencies imported in Step 1:
    1
    import com.parse.SignUpCallback;
    
  2. To implement user registration, simply use the following code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ParseUser user = new ParseUser();
    // Set the user's username and password, which can be obtained by a forms
    user.setUsername(<Insert Username Here>);
    user.setPassword(<Insert User Password Here>);
    user.signUpInBackground(new SignUpCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {
                alertDisplayer("Sucessful Sign Up!","Welcome" + <Insert Username Here> + "!");
            } else {
                ParseUser.logOut();
                Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
           }
        }
    });
    
    In the example project, this code is placed inside a SIGN UP button callback.
    Also, username and password are caught using Edit Texts.
  3. It’s interesting to add an additional method to display Alert Dialogs and make the process look more professional. The method below do this:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    private void alertDisplayer(String title,String message){
           AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this)
                   .setTitle(title)
                   .setMessage(message)
                   .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                       @Override
                       public void onClick(DialogInterface dialog, int which) {
                           dialog.cancel();
                           // don't forget to change the line below with the names of your Activities
                           Intent intent = new Intent(SignUpActivity.this, LogoutActivity.class);
                           intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                           startActivity(intent);
                       }
                   });
           AlertDialog ok = builder.create();
           ok.show();
       }
    

Step 3 - Log in

Logging in creates a Session object, which points to the User logged in. If login is successful, ParseUser.getCurrentUser() returns a User object, and a Session object is created in the Dashboard. Otherwise, if the target username does not exist, or the password is wrong, it returns null.
The method used to perform the login action is ParseUser.logInInBackground(), which requires as many arguments as the strings of username and password, and may call a callback function.
Note: After signing up, login is performed automatically.
To make LoginActivity work, follow these steps:
  1. Import into your LoginActivity, in addition to the dependencies imported in the Step 1:
    1
    import com.parse.LogInCallback;
    
  2. To implement user login function, simply use the code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ParseUser.logInInBackground(<Insert Username Here>, <Insert User Password Here>, new LogInCallback() {
        @Override
        public void done(ParseUser parseUser, ParseException e) {
            if (parseUser != null) {
                alertDisplayer("Sucessful Login","Welcome back" + <Insert Username Here> + "!");
            } else {
                ParseUser.logOut();
                Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });
    
    In the example project, this code is placed inside a LOG IN button callback.
    Also, username and password are caught using Edit Texts.
    The method alertDisplayer is the same that you added in the SignUpActivity, don’t forget to change its Intent arguments though.

Step 4 - Log Out

Logging out deletes the active Session object for the logged User. The method used to perform log out is ParseUser.logOut().
To implement user log out, simply use the code below, in the LogoutActivity:
1
2
3
// logging out of Parse
ParseUser.logOut();
alertDisplayer("So, you're going...", "Ok...Bye-bye then");
In the example project, this code is placed inside a LOG OUT button callback.
The method alertDisplayer is the same that you added in the LoginActivity and SignUpActivity, don’t forget to change its Intent arguments though.

Step 5 - Test your app

  1. Run your app and create a couple of users, also try logging in again after registering them.
  2. Login at Back4App Website.
  3. Find your app and click on Dashboard > Core > Browser > User.
At this point, you should see your users as displayed below:
Note: Using the codes displayed above, every time you log in with a user, a Session is opened in your Dashboard, but when the user logs out that particular Session ends. Also, whenever an unsuccessful login or sign up attempt occurs, the Session opened in Parse Server Dashboard is deleted.

It’s done!

At this stage, you can log in, register or log out of your app using Parse Server core features through Back4App!


Login RegistrationSource

back4app CRUD operation

Adminca

Sunday, November 11, 2018

selectable button in android studio | click a button show hovor in android studio

Today I will discuss about android studio button selection. How we can use a hover effect in this button. .

here the code , you use this code snap to your drawer folder and give a name as you want.
then you use this as a background in your button which is stayed in layout section.



thanks , I will talk to you another topics later.

Thursday, December 21, 2017

how to selected color in drawer item - কিভাবে DrawerItem সিলেক্টেড item কে color করা যায়

drawer_item_color.xml


<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#101010"        android:state_checked="true" />
    <item android:color="#4D5D6C" />
</selector>


<android.support.design.widget.NavigationView    android:id="@+id/nav_view"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:layout_gravity="start"    android:fitsSystemWindows="true"    android:background="#EFEFEF"    app:itemIconTint="@color/bgcolor"    app:itemTextColor="@color/drawer_item_color" // এখানে ব্যবহার করা হয়েছে।
    app:headerLayout="@layout/nav_header_main"    app:menu="@menu/activity_main_drawer" />




কোন item ইউজার click করলে সেই item টি বিশেষ color করে দিয়া যাবে।

Navigation DrawerLayout নিয়ে কাজ করতে এটি জানা লাগবে। 
ভাল থাকুন