Android Open Source - sony-camera-remote-java Main Activity






From Project

Back to project page sony-camera-remote-java.

License

The source code is released under:

Apache License

If you think the Android project sony-camera-remote-java listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.praetoriandroid.cameraremote.app;
/*  w ww .j  ava  2 s.c  o  m*/
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.praetoriandroid.cameraremote.LiveViewFetcher;
import com.praetoriandroid.cameraremote.rpc.ActTakePictureRequest;
import com.praetoriandroid.cameraremote.rpc.ActTakePictureResponse;
import com.praetoriandroid.cameraremote.rpc.SetSelfTimerRequest;
import com.praetoriandroid.cameraremote.rpc.SimpleResponse;
import com.praetoriandroid.widget.RadialSelector;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_main)
public class MainActivity extends Activity implements Rpc.ConnectionListener {
    @Bean Rpc rpc;

    @ViewById LiveView liveView;
    @ViewById Button shot;
    @ViewById View progress;
    @ViewById View connectionErrorDialog;
    @ViewById TextView progressLabel;
    @ViewById SelfTimerSelector selfTimer;

    @AfterViews
    void init() {
        progressLabel.setText(R.string.connection_label);
        selfTimer.setOnValueSelectedListener(new RadialSelector.OnValueSelectedListener<Integer>() {
            @Override
            public void onValueSelected(final Integer timer) {
                onSelfTimerSelected(timer);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        rpc.registerInitCallback(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        rpc.unregisterInitCallback(this);
        rpc.stopLiveView();
    }

    @Click
    void shotClicked() {
        shot.setEnabled(false);
        rpc.sendRequest(new ActTakePictureRequest(), shot, new Rpc.ResponseHandler<ActTakePictureResponse>() {
            @Override
            public void onSuccess(ActTakePictureResponse response) {
                shot.setEnabled(true);
            }

            @Override
            public void onFail(Throwable e) {
                Log.e("@@@@@", "Shot failed", e);
                shot.setEnabled(true);
            }
        });
    }

    @Override
    @UiThread (propagation = UiThread.Propagation.REUSE)
    public void onConnected() {
        dismissProgress();

        if (isFinishing()) {
            return;
        }

        shot.setEnabled(true);
        rpc.startLiveView(new Rpc.LiveViewCallback() {
            @Override
            public void onNextFrame(LiveViewFetcher.Frame frame) {
                Bitmap bitmap = BitmapFactory.decodeByteArray(frame.getBuffer(), 0, frame.getSize());
                liveView.putFrame(bitmap);
            }

            @Override
            public void onError(Throwable e) {
                Log.e("@@@@@", "Live view error: " + e);
                rpc.stopLiveView();
                showConnectionErrorDialog();
            }
        });
    }

    @Override
    @UiThread (propagation = UiThread.Propagation.REUSE)
    public void onConnectionFailed(Throwable e) {
        dismissProgress();
        showConnectionErrorDialog();
    }

    @Click
    void wiFiSettingsClicked() {
        dismissConnectionErrorDialog();
        try {
            Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            showConnectionErrorDialog();
            Toast.makeText(this, R.string.error_no_wi_fi_settings_activity, Toast.LENGTH_SHORT)
                    .show();
        }
    }

    @Click
    void reconnectClicked() {
        dismissConnectionErrorDialog();
        showProgress();
        rpc.connect();
    }

    @UiThread (propagation = UiThread.Propagation.REUSE)
    void showProgress() {
        progress.setVisibility(View.VISIBLE);
    }

    @UiThread (propagation = UiThread.Propagation.REUSE)
    void dismissProgress() {
        progress.setVisibility(View.INVISIBLE);
    }

    @UiThread (propagation = UiThread.Propagation.REUSE)
    void showConnectionErrorDialog() {
        connectionErrorDialog.setVisibility(View.VISIBLE);
    }

    @UiThread (propagation = UiThread.Propagation.REUSE)
    void dismissConnectionErrorDialog() {
        connectionErrorDialog.setVisibility(View.INVISIBLE);
    }

    @Click
    void zoomClicked() {
        Toast.makeText(this, "zoom", Toast.LENGTH_SHORT).show();
    }

    private void onSelfTimerSelected(final int timerValue) {
        rpc.sendRequest(new SetSelfTimerRequest(timerValue), selfTimer, new Rpc.ResponseHandler<SimpleResponse>() {
            @Override
            public void onSuccess(SimpleResponse response) {
                Toast.makeText(MainActivity.this, "Self timer was set to " + timerValue,
                        Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFail(Throwable e) {
                Toast.makeText(MainActivity.this, "Failed to set self timer", Toast.LENGTH_SHORT)
                        .show();
            }
        });
    }

}




Java Source Code List

com.praetoriandroid.cameraremote.BadHttpStatusException.java
com.praetoriandroid.cameraremote.DeviceDescription.java
com.praetoriandroid.cameraremote.HttpClient.java
com.praetoriandroid.cameraremote.InvalidDataFormatException.java
com.praetoriandroid.cameraremote.LiveViewDisconnectedException.java
com.praetoriandroid.cameraremote.LiveViewFetcher.java
com.praetoriandroid.cameraremote.Logger.java
com.praetoriandroid.cameraremote.ParseException.java
com.praetoriandroid.cameraremote.RpcClient.java
com.praetoriandroid.cameraremote.RpcException.java
com.praetoriandroid.cameraremote.ServiceNotSupportedException.java
com.praetoriandroid.cameraremote.SsdpClient.java
com.praetoriandroid.cameraremote.SsdpException.java
com.praetoriandroid.cameraremote.app.LiveView.java
com.praetoriandroid.cameraremote.app.MainActivity.java
com.praetoriandroid.cameraremote.app.Rpc.java
com.praetoriandroid.cameraremote.app.SelfTimerSelector.java
com.praetoriandroid.cameraremote.app.ThisApp.java
com.praetoriandroid.cameraremote.rpc.ActTakePictureRequest.java
com.praetoriandroid.cameraremote.rpc.ActTakePictureResponse.java
com.praetoriandroid.cameraremote.rpc.AwaitTakePictureRequest.java
com.praetoriandroid.cameraremote.rpc.BaseRequest.java
com.praetoriandroid.cameraremote.rpc.BaseResponse.java
com.praetoriandroid.cameraremote.rpc.CustomizableEntity.java
com.praetoriandroid.cameraremote.rpc.EventEntity.java
com.praetoriandroid.cameraremote.rpc.GetApplicationInfoRequest.java
com.praetoriandroid.cameraremote.rpc.GetApplicationInfoResponse.java
com.praetoriandroid.cameraremote.rpc.GetAvailableApiListRequest.java
com.praetoriandroid.cameraremote.rpc.GetAvailableApiListResponse.java
com.praetoriandroid.cameraremote.rpc.GetAvailableSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetAvailableSelfTimerResponse.java
com.praetoriandroid.cameraremote.rpc.GetEventRequest.java
com.praetoriandroid.cameraremote.rpc.GetEventResponse.java
com.praetoriandroid.cameraremote.rpc.GetExposureModeRequest.java
com.praetoriandroid.cameraremote.rpc.GetMethodTypesRequest.java
com.praetoriandroid.cameraremote.rpc.GetMethodTypesResponse.java
com.praetoriandroid.cameraremote.rpc.GetSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetSupportedSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetSupportedSelfTimerResponse.java
com.praetoriandroid.cameraremote.rpc.GetVersionsRequest.java
com.praetoriandroid.cameraremote.rpc.GetVersionsResponse.java
com.praetoriandroid.cameraremote.rpc.IllegalResultSizeException.java
com.praetoriandroid.cameraremote.rpc.MethodTypesEntity.java
com.praetoriandroid.cameraremote.rpc.RpcMethod.java
com.praetoriandroid.cameraremote.rpc.SetSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.SimpleResponse.java
com.praetoriandroid.cameraremote.rpc.StartLiveViewRequest.java
com.praetoriandroid.cameraremote.rpc.StartLiveViewResponse.java
com.praetoriandroid.cameraremote.rpc.StartMovieRecRequest.java
com.praetoriandroid.cameraremote.rpc.StartRecModeRequest.java
com.praetoriandroid.cameraremote.rpc.StopLiveviewRequest.java
com.praetoriandroid.cameraremote.rpc.StopMovieRecRequest.java
com.praetoriandroid.cameraremote.rpc.StopMovieRecResponse.java
com.praetoriandroid.cameraremote.rpc.StopRecModeRequest.java
com.praetoriandroid.cameraremote.rpc.ValidationException.java
com.praetoriandroid.cameraremote.rpc._DummyResponse.java
com.praetoriandroid.cameraremote.tool.Cache.java
com.praetoriandroid.cameraremote.tool.RemoteControl.java
com.praetoriandroid.widget.ItemViewCreator.java
com.praetoriandroid.widget.RadialFreeSpace.java
com.praetoriandroid.widget.RadialSelector.java