Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
first implementation of built-in Camera for proofmode
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironrabbit committed May 31, 2018
1 parent 9f2f328 commit 9041d66
Show file tree
Hide file tree
Showing 48 changed files with 150 additions and 75 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ dependencies {
implementation 'com.google.android.gms:play-services-nearby:15.0.1'

//built in camera now!
//https://github.com/siralam/CameraViewPlus?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=6575
//https://github.com/siralam/CameraViewPlus
implementation 'com.asksira.android:cameraviewplus:0.9.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public class XmppConnection extends ImConnection {
private LastActivityManager mLastActivityManager;
private BookmarkManager mBookmarkManager;
private PrivateDataManager mPrivateManager;
private ReconnectionManager mReconnectionManager;

private Contact mUser;
private BareJid mUserJid;
Expand Down Expand Up @@ -1741,23 +1742,6 @@ private void initConnectionAndLogin (Imps.ProviderSettings.QueryMap providerSett
mRoster.setSubscriptionMode(subMode);
getContactListManager().listenToRoster(mRoster);

/**
manager.enableAutomaticReconnection();
manager.addReconnectionListener(new ReconnectionListener() {
@Override
public void reconnectingIn(int seconds) {
debug (TAG,"reconnecting in: " + seconds + " seconds");
}
@Override
public void reconnectionFailed(Exception e) {
debug (TAG,"reconnection failed",e);
}
});**/

mChatManager = ChatManager.getInstanceFor(conn);

// mPingManager = PingManager.getInstanceFor(mConnection) ;
Expand Down Expand Up @@ -2245,50 +2229,6 @@ public void processStanza(Stanza packet) {
ConnectionListener connectionListener = new ConnectionListener() {


/**
* Called from smack when connect() is fully successful
*
* This is called on the executor thread while we are in reconnect()
*/
/**
@Override
public void reconnectionSuccessful() {
if (mStreamHandler == null || !mStreamHandler.isResumePending()) {
debug(TAG, "Reconnection success");
onReconnectionSuccessful();
mRoster = Roster.getInstanceFor(mConnection);
sendPresencePacket();
mChatGroupManager.reconnectAll();
} else {
debug(TAG, "Ignoring reconnection callback due to pending resume");
}
}**/


/**
@Override
public void reconnectionFailed(Exception e) {
debug(TAG, "reconnection failed",e);
// We are not using the reconnection manager
// throw new UnsupportedOperationException();
execute(new Runnable() {
public void run() {
mNeedReconnect = true;
setState(LOGGING_IN,
new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, "network error"));
reconnect();
}
});
}**/

@Override
public void connectionClosedOnError(final Exception e) {
/*
Expand Down Expand Up @@ -2370,9 +2310,6 @@ public void authenticated(XMPPConnection connection, boolean resumed) {
sendPresencePacket();
mChatGroupManager.reconnectAll();

ReconnectionManager manager = ReconnectionManager.getInstanceFor(mConnection);
manager.disableAutomaticReconnection();

initServiceDiscovery();

}
Expand Down Expand Up @@ -2426,9 +2363,6 @@ public void run() {

conn.setReplyTimeout(SOTIMEOUT);

ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor(conn);
reconnectionManager.enableAutomaticReconnection();

return conn;
}

Expand Down Expand Up @@ -4126,6 +4060,30 @@ private void initServiceDiscovery() {
mBookmarkManager = BookmarkManager.getBookmarkManager(mConnection);
mPrivateManager = PrivateDataManager.getInstanceFor(mConnection);


if (mReconnectionManager != null) {
mReconnectionManager.abortPossiblyRunningReconnection();
mReconnectionManager.disableAutomaticReconnection();
}


mReconnectionManager = ReconnectionManager.getInstanceFor(mConnection);
mReconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAY);
mReconnectionManager.addReconnectionListener(new ReconnectionListener() {
@Override
public void reconnectingIn(int i) {
debug(TAG,"Reconnecting in..." + i);

}

@Override
public void reconnectionFailed(Exception e) {
debug(TAG,"Reconnection failed",e);
}
});
mReconnectionManager.enableAutomaticReconnection();


try {
debug(TAG,"is Private Data supported?" + mPrivateManager.isSupported());
} catch (SmackException.NoResponseException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,60 @@
package org.awesomeapp.messenger.ui.camera;

import android.graphics.Bitmap;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.OrientationEventListener;
import android.view.View;
import android.widget.Toast;

import com.google.android.cameraview.CameraView;
import com.google.android.cameraview.CameraViewImpl;

import org.awesomeapp.messenger.ImApp;
import org.awesomeapp.messenger.provider.Imps;
import org.awesomeapp.messenger.util.SecureMediaStore;
import org.awesomeapp.messenger.util.SystemServices;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;

import im.zom.messenger.R;



public class CameraActivity extends AppCompatActivity {

CameraView mCameraView;
OrientationEventListener mOrientationEventListener;
int mLastOrientation = -1;

public static final int ORIENTATION_PORTRAIT = 0;
public static final int ORIENTATION_LANDSCAPE = 1;
public static final int ORIENTATION_PORTRAIT_REVERSE = 2;
public static final int ORIENTATION_LANDSCAPE_REVERSE = 3;

private Handler mHandler = new Handler ()
{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);

if (msg.what == 1)
{
Toast.makeText(CameraActivity.this,"\uD83D\uDCF7",Toast.LENGTH_SHORT).show();
}
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -30,9 +68,18 @@ protected void onCreate(Bundle savedInstanceState) {

mCameraView.setOnPictureTakenListener(new CameraViewImpl.OnPictureTakenListener() {
@Override
public void onPictureTaken(Bitmap bitmap, int rotationDegrees) {
public void onPictureTaken(final Bitmap bitmap, final int rotationDegrees) {

new Thread ()
{
public void run ()
{
storeBitmap(rotate(bitmap,rotationDegrees));

//startSavingPhoto(bitmap, int rotationDegrees);
}
}.start();

mHandler.sendEmptyMessage(1);
}
});

Expand All @@ -56,6 +103,48 @@ public void onClick(View view) {
mCameraView.setFlash(CameraView.FLASH_AUTO);
}
});

mOrientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int orientation) {

if (orientation < 0) {
return; // Flip screen, Not take account
}

int curOrientation;

if (orientation <= 45) {
curOrientation = ORIENTATION_PORTRAIT;
} else if (orientation <= 135) {
curOrientation = ORIENTATION_LANDSCAPE_REVERSE;
} else if (orientation <= 225) {
curOrientation = ORIENTATION_PORTRAIT_REVERSE;
} else if (orientation <= 315) {
curOrientation = ORIENTATION_LANDSCAPE;
} else {
curOrientation = ORIENTATION_PORTRAIT;
}
if (curOrientation != mLastOrientation) {

mLastOrientation = curOrientation;

}
}
};

if (mOrientationEventListener.canDetectOrientation()) {
mOrientationEventListener.enable();
} else {
mOrientationEventListener.disable();
}

}

@Override
protected void onDestroy() {
super.onDestroy();
mOrientationEventListener.disable();
}

@Override
Expand All @@ -67,12 +156,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

private void rotate (Bitmap bitmap, int rotationDegrees)
private Bitmap rotate (Bitmap bitmap, int rotationDegrees)
{

Matrix matrix = new Matrix();
matrix.postRotate(-rotationDegrees);
Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

}

Expand Down Expand Up @@ -133,4 +222,32 @@ protected void onPause() {
super.onPause();
}

private void storeBitmap (Bitmap bitmap)
{
// import
String sessionId = "self";
String offerId = UUID.randomUUID().toString();

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100 /*ignored for JPG*/, bos);
ByteArrayInputStream bs = new ByteArrayInputStream(bos.toByteArray());

Uri vfsUri = SecureMediaStore.importContent(sessionId,"cam" + new Date().getTime() + ".jpg",bs);

String mimeType = "image/jpeg";

//adds in an empty message, so it can exist in the gallery and be forwarded
Imps.insertMessageInDb(
getContentResolver(), false, new Date().getTime(), true, null, vfsUri.toString(),
System.currentTimeMillis(), Imps.MessageType.OUTGOING_ENCRYPTED_VERIFIED,
0, offerId, mimeType);

}
catch (IOException ioe)
{
Log.e(ImApp.LOG_TAG,"error importing photo",ioe);
}
}

}
Binary file added app/src/main/res/drawable-hdpi/ic_camera_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_camera_rear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_flash_auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_flash_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_flash_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_resolution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_settings_cog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_shutter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_video_rec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_video_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_camera_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_camera_rear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_flash_auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_flash_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_flash_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_resolution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_settings_cog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_shutter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_video_rec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_video_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_camera_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_camera_rear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_flash_auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_flash_off.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_flash_on.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_resolution.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_settings_cog.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_shutter.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_video.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_video_rec.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_camera_rear.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_flash_auto.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_flash_off.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_flash_on.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_resolution.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_shutter.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_video.png
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dp"
android:src="@drawable/ic_refresh_white_24dp"/>
android:src="@drawable/ic_camera_front"/>

<ImageView
android:id="@+id/btnCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dp"
android:src="@drawable/ic_photo_camera_white_36dp"/>
android:src="@drawable/ic_shutter"/>

<ImageView
android:id="@+id/toggle_flash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dp"
android:src="@drawable/ic_audiotrack_white_24dp"/>
android:src="@drawable/ic_flash_auto"/>

</LinearLayout>
</FrameLayout>
Expand Down

0 comments on commit 9041d66

Please sign in to comment.