Saturday 27 July 2019

How to make window full screen in android

To make window full screen we have to define one line code in onCreate method,


@Overrideprotected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.activity_main);

Done , above one line code in bold font we have to declare for window full screen.

Wednesday 10 July 2019

Android VideoView with Multimedia controls

Here is the code for play any video using VideoView and with Media Controller

Add below code in your main_activity.xml

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"    
android:layout_alignParentBottom="true"    
android:layout_centerHorizontal="true"    
android:layout_gravity="center"    
android:layout_marginTop="@dimen/d_10dp"    
android:layout_marginBottom="@dimen/d_10dp">

<VideoView    
android:id="@+id/videoview"    
android:layout_width="match_parent"    
android:layout_height="200dp"   />

</RelativeLayout>




Now add below code in MainActivity.java

define your variable first


VideoView videoView;
MediaController mediaControls;

in onCreateView method add below code
videoView = (VideoView)view.findViewById(R.id.videoview);

add below code where you want to play video

String FullVideopath = "Here is your video path";

videoView.setVideoPath(FullVideopath);
mediaControls = new MediaController(mcontext);
mediaControls.setAnchorView(videoView);
videoView.setMediaController(mediaControls);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override    public void onPrepared(MediaPlayer mp) {
        mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
            @Override  public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

                videoView.setMediaController(mediaControls);
                mediaControls.setAnchorView(videoView);
            }
        });
    }
});

viewvideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    @Override    public void onCompletion(MediaPlayer mp) {
        Toast.makeText(mcontext, "Video over...!!!", Toast.LENGTH_LONG).show();
    }
});
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
    @Override    public boolean onError(MediaPlayer mp, int what, int extra) {
        Toast.makeText(mcontext, "Oops An Error Occur While Playing Video...!!!", 
Toast.LENGTH_LONG).show(); 
return false;
    }
});}

Wednesday 3 July 2019

Android Json response parsing method with Gson

Hello guy's here i  m sharing Json response parsing method to do parse in particular pojo class.
here you need to get your Json response in your String variable before start parsing it.


do this process in Your Class

String result = "Your Json Resonse" ;

List<MUsers> mUsers = null;
                try {
    Gson gson = new Gson();
    Type type = new TypeToken<List<MUsers>>(){}.getType();
    mUsers = gson.fromJson(result, type);
} catch (JsonSyntaxException e) {
    e.printStackTrace();
}

Here  in Your MUsers Class need to contain all require keys to parse it based on your Json response contains no of keys . here explaining with single key value parsing class as below it would be like.

public class MUsers{

    @SerializedName("USR")
    @Expose
    private String usr;

    public void setUSR(String usern) {
        this.usr = usern;
    }

    public String getUSR() {
        return usr;
    }
}



Here  in your build.gradle file need to add supportive library to parse this data

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...