Categories
discuss

Is there a way to filter network requests using Google Chrome developer tools?

Is it possible to filter out some requests using Chrome developer tools, say, filter out all image requests?

Answer

There isn’t a very flexible filtering feature, but the bar at the bottom does allow you to only show requests of a certain document or connection type:

You can’t just exclude images, but it should help.

You can also press Control/Command+F to search for a particular string in the request list, and check the “filter” box to hide requests that don’t match:

enter image description here

Categories
discuss

How to create a titled border in Android?

has someone an idea how to create a titled border layout like in swing?

On this site i found a trick to generate a rectangle between a object. Maybe this can help me to create such a titled border?

greetings

Answer

Quick and dirty:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:color="#000000">
<View
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/rectangle"
    android:layout_margin="20dp"
    />
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="#000000"
        android:layout_marginTop="10dp"
        android:text="TITLE!"
        android:textColor="#ffffff"/>
</RelativeLayout>

</FrameLayout>

And @drawable/rectangle is in a drawable rectangle.xml file like this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<stroke  android:width="2dip" android:color="#ffffff"/>  
</shape>
Categories
discuss

IntelliJ IDEA “Make project automatically” woes

Back in December I switched from Eclipse to IntelliJ IDEA but within a couple of days I switched back. Today I tried IntelliJ again and basically I have only one issue left.

The issue is I want to compile Java classes on saving. The reason is I’m using JRebel which will pick up the new class. I don’t want to hit +F9 every time to compile the changed class.

I read about the EclipseModel plugin but this does not seem to work (anymore) as can be read in the comments on the plugin’s page: http://plugins.jetbrains.com/plugin/?id=3822

I also tried the “Make project automatically” but this compiles ALL classes and not only the changed class. This is only not more time consuming it will also cause JRebel to reload all classes.

Any suggestions?

Answer

I ended up creating a Macro which does the Save and the Make Build.
I then assigned the Ctrl+S shortcut to this Macro and then it works fine.

Categories
discuss

Broadcast a message to all available machines on WiFi

my apologies if this is a trivial question.

I’ve recently begun doing some android programming and I’m writing a simple app that allows you to use your android device as a controller for your windows PC. Specifically it allows the user to do things like turn off the machine, make it sleep, reboot it etc etc. I’m currently using a python library called CherryPy as a server on the windows machine to execute the actual win32api calls to perform the desired function. What i’m not sure about is how to discover (dynamically) which machine on the network is actually hosting the server. Everything is working fine if I hardcode my machines public IP into the android app, but obviously that is far less than ideal. I’ve considered having the user manually enter their machines public IP in the app, but if there’s a way to, say, broadcast a quick message to all machines on the WiFi and check for a pre-canned response that my Python server would send out, that’d be wonderful. Is that possible?

Thanks in advance guys.

Answer

Write your app using the framework. AllJoyn will handle these details for you.

Categories
discuss

Android how to use/show MediaController with SurfaceView and MediaPlayer for video?

I have to use MediaPlayer to play a video, NOT a VideoView. I have a SurfaceView in Xml Layout and on the Activity side a MediaPlayer and a MediaController.

I coudldn’t find a way to use MediaController with SurfaceView and MediaPlayer. It is so easy with VideoView but cant figure out how to use with MediaPlayer.

I have found examples online but they are all about playing audio, not video.

This is surfaceCreated method where i create the MediaPlayer

@Override
    public void surfaceCreated(SurfaceHolder holder) {
        try {
            mMediaPlayer = new MediaPlayer();
            mMediaPlayer.setDisplay(mSurfaceHolder);
            mMediaPlayer.setDataSource(this, Uri.parse(mUrl));
            mMediaPlayer.setOnPreparedListener(this);
            mMediaPlayer.prepare();
            mMediaController = new MediaController(this);

        } catch (Exception e) {
            Log.e(TAG, "MediaPlayer Prepare: " + e.getMessage());
        }
    }

and this MediaPlayer onPrepared method

@Override
    public void onPrepared(MediaPlayer mp) {

        mVideoWidth = mp.getVideoWidth();
        mVideoHeight = mp.getVideoHeight();
        mSurfaceHolder.setFixedSize(mVideoWidth, mVideoHeight);
        startVideoPlayback();

        mMediaController.setMediaPlayer(this);              

        handler.post(new Runnable() {

            public void run() {
                mMediaController.setEnabled(true);
                mMediaController.show();
            }
        });    
    }

The code above doesn’t show the MediaController on SurfaceView.
How can i achieve this?

Thanks in advance.

Answer

for that you have to implement to activity

OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener,
OnVideoSizeChangedListener, SurfaceHolder.Callback, MediaPlayerControl

check below working code

package com.example.demo;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.MediaController;
import android.widget.MediaController.MediaPlayerControl;
import android.widget.ProgressBar;

public class MainActivity extends Activity implements  OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener,
OnVideoSizeChangedListener, SurfaceHolder.Callback, MediaPlayerControl{
    String url = "your video url";
    MediaPlayer mMediaPlayer ;
    SurfaceView mSurfaceView ;
    SurfaceHolder holder ;
    private ConstantAnchorMediaController controller = null;
    ProgressBar progressBar1 ;
    MediaController mcontroller ;
    Handler handler ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBar1 = (ProgressBar)findViewById(R.id.progressBar1);
        SurfaceView v = (SurfaceView) findViewById(R.id.surface); 
        handler = new Handler();
        holder = v.getHolder(); 
        holder.addCallback(this);
        playVideo();

    }
    private void playVideo() {
        try {
            mcontroller = new MediaController(this);
            mMediaPlayer = MediaPlayer.create(this, Uri.parse(url));
            mMediaPlayer.setOnBufferingUpdateListener(this);
            mMediaPlayer.setOnCompletionListener(this);
            mMediaPlayer.setOnPreparedListener(this);
            mMediaPlayer.setScreenOnWhilePlaying(true);
            mMediaPlayer.setOnVideoSizeChangedListener(this);
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
         mcontroller.show();
         return false;
    }
    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub
    }
    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
        mMediaPlayer.setDisplay(holder); 
        try {
            mMediaPlayer.start();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        // TODO Auto-generated method stub
        progressBar1.setVisibility(View.GONE);
        mcontroller.setMediaPlayer(this);
        mcontroller.setAnchorView(findViewById(R.id.surface));
        mcontroller.setEnabled(true);

        handler.post(new Runnable() {
            public void run() {
                mcontroller.show();
            }
        });
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onBufferingUpdate(MediaPlayer mp, int percent) {
        // TODO Auto-generated method stub
    }
    public void start() {
        mMediaPlayer.start();
    }

    public void pause() {
        mMediaPlayer.pause();
    }

    public int getDuration() {
        return mMediaPlayer.getDuration();
    }

    public int getCurrentPosition() {
        return mMediaPlayer.getCurrentPosition();
    }

    public void seekTo(int i) {
        mMediaPlayer.seekTo(i);
    }

    public boolean isPlaying() {
        return mMediaPlayer.isPlaying(); 
    }

    public int getBufferPercentage() {
        return 0;
    }

    public boolean canPause() {
        return true;
    }

    public boolean canSeekBackward() {
        return true;
    }

    public boolean canSeekForward() {
        return true;
    }
}
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..