Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import barcodescanner #504

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ buildscript {
}

repositories {
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url "http://jcenter.bintray.com" }
maven { url "https://jitpack.io" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "http://dl.bintray.com/drummer-aidan/maven" }
maven { url "https://repository.apache.org/content/repositories/snapshots/" }
maven { url 'https://maven.google.com' }

}

apply plugin: "com.android.application"
Expand Down Expand Up @@ -210,6 +211,11 @@ dependencies {

compile 'pub.devrel:easypermissions:0.3.0'
compile 'com.github.angads25:filepicker:1.0.6'
compile ('cn.yipianfengye.android:zxing-library:2.2'){
exclude group: 'com.android.support'
}
compile 'android.arch.lifecycle:common-java8:1.1.1'
compile 'android.arch.lifecycle:extensions:1.1.1'

// androidTestCompile 'org.scala-lang:scala-library:2.11.8'
// androidTestCompile 'com.android.support.test:runner:0.4'
Expand Down
Binary file removed app/libs/com.google.zxing-core.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@
android:smallScreens="true" />

<application
android:name="chat.tox.antox.tox.ToxApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:logo="@drawable/ic_actionbar"
android:theme="@style/AntoxTheme"
tools:replace="android:allowBackup">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<service
android:name="chat.tox.antox.tox.ToxService"
android:exported="false"
Expand Down
18 changes: 6 additions & 12 deletions app/src/main/java/chat/tox/QR/IntentIntegrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import android.os.Bundle;
import android.util.Log;

import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -240,10 +242,8 @@ public final AlertDialog initiateScan() {
* if a prompt was needed, or null otherwise
*/
public final AlertDialog initiateScan(Collection<String> desiredBarcodeFormats) {
Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
intentScan.addCategory(Intent.CATEGORY_DEFAULT);

// check which types of codes to scan for
ZXingLibrary.initDisplayOpinion(activity);
Intent intentScan = new Intent(activity,CaptureActivity.class);
if (desiredBarcodeFormats != null) {
// set the desired barcode types
StringBuilder joinedByComma = new StringBuilder();
Expand All @@ -255,12 +255,6 @@ public final AlertDialog initiateScan(Collection<String> desiredBarcodeFormats)
}
intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
}

String targetAppPackage = findTargetAppPackage(intentScan);
if (targetAppPackage == null) {
return showDownloadDialog();
}
intentScan.setPackage(targetAppPackage);
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
attachMoreExtras(intentScan);
Expand Down Expand Up @@ -346,8 +340,8 @@ public void onClick(DialogInterface dialogInterface, int i) {
public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
String contents = intent.getStringExtra("result_string");
String formatName = intent.getStringExtra("RESULT_FORMAT");
byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files"
path="." />
</paths>
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import java.util.Date

import android.app.Activity
import android.content.{Context, Intent}
import android.net.Uri
import android.os.{Build, Bundle, Environment, SystemClock}
import android.provider.MediaStore
import android.support.v4.content.CursorLoader
import android.support.v4.content.{CursorLoader, FileProvider}
import android.view.View
import android.view.View.OnClickListener
import android.widget._
Expand Down Expand Up @@ -117,7 +116,7 @@ class ChatActivity extends GenericChatActivity[FriendKey] {
val storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
try {
val file = File.createTempFile(image_name, ".jpg", storageDir)
val imageUri = Uri.fromFile(file)
val imageUri = FileProvider.getUriForFile(getApplicationContext, getPackageName + ".provider", file)
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
photoPath = Some(file.getAbsolutePath)
startActivityForResult(cameraIntent, Constants.PHOTO_RESULT)
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/scala/chat/tox/antox/activities/MainActivity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content._
import android.net.ConnectivityManager
import android.os.{Build, Bundle}
import android.preference.PreferenceManager
import android.provider.Settings
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.{MenuItem, View, WindowManager}
Expand Down Expand Up @@ -75,8 +76,43 @@ class MainActivity extends AppCompatActivity {
Options.videoCallStartWithNoVideo = preferences.getBoolean("videocallstartwithnovideo", false)

State.setBatterySavingMode(preferences.getBoolean("batterysavingmode", false))

batteryOptimization()
}

def batteryOptimization(): Unit = {
try // ask user to whitelist app from DozeMode/BatteryOptimizations
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val settings = PreferenceManager.getDefaultSharedPreferences(this)
val asked_for_whitelist_doze_already = settings.getBoolean("asked_whitelist_doze", false)
if (!asked_for_whitelist_doze_already) {
settings.edit.putBoolean("asked_whitelist_doze", true).commit
val intent = new Intent
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
val resolve_activity = getPackageManager.resolveActivity(intent, 0)
if (resolve_activity != null) {

var ad = new AlertDialog.Builder(this).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
override def onClick(dialog: DialogInterface, id: Int): Unit = {
startActivity(intent)
}
}).setNegativeButton("no", new DialogInterface.OnClickListener() {
override def onClick(dialog: DialogInterface, id: Int): Unit = {
}
}).create
ad.setTitle("INFO")
ad.setMessage("Add Antox to the exception list for Batteryoptimization?")
ad.setCancelable(false)
ad.setCanceledOnTouchOutside(false)
ad.show()
}
}
}
catch {
case e: Exception =>
e.printStackTrace()
}
}

def onClickAdd(v: View) {
val intent = new Intent(this, classOf[AddActivity])
Expand Down
1 change: 1 addition & 0 deletions app/src/main/scala/chat/tox/antox/av/CallService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CallService(toxService: ToxService) {
case None =>
// if there is no active call stop foreground and remove the notification
toxService.stopForeground(true)
toxService.stickForground()
}
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AntoxOnConnectionStatusCallback(private var ctx: Context) extends FriendCo
def setAllStatusNone(): Unit = {
if (!ToxSingleton.isToxConnected(preferences, ctx)) {
for (friendInfo <- State.db.friendInfoList.toBlocking.first) {
friendConnectionStatus(friendInfo, ToxConnection.NONE)(Unit)
friendConnectionStatus(friendInfo, ToxConnection.NONE)(Unit) //fixme: ToxConnection.NONE means nothing to do
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/scala/chat/tox/antox/data/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ object State {
var lastFileTransferAction: Long = -1
var lastIncomingMessageAction: Long = -1
val noBatterySavingWithActionWithinLastXSeconds = 5 * 60

var internetConnectivity = true
var isAppVisible = false
// 5min
var MainToxService: ToxService = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ class MainDrawerFragment extends Fragment {
private var preferences: SharedPreferences = _

private var userDetailsSubscription: Subscription = _

private var rootView: View = _
override def onCreate(savedInstanceState: Bundle): Unit = {
super.onCreate(savedInstanceState)
preferences = PreferenceManager.getDefaultSharedPreferences(getActivity)
}

override def getView: View = super.getView

override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View = {

super.onCreateView(inflater, container, savedInstanceState)
val rootView = inflater.inflate(R.layout.fragment_main_drawer, container, false)
rootView = inflater.inflate(R.layout.fragment_main_drawer, container, false)

// Set up the navigation drawer
mDrawerLayout = rootView.findViewById(R.id.drawer_layout).asInstanceOf[DrawerLayout]
Expand Down Expand Up @@ -88,7 +90,7 @@ class MainDrawerFragment extends Fragment {
}

def refreshDrawerHeader(userInfo: UserInfo, connectionStatus: ToxConnection): Unit = {
val avatarView = getView.findViewById(R.id.drawer_avatar).asInstanceOf[CircleImageView]
val avatarView = rootView.findViewById(R.id.drawer_avatar).asInstanceOf[CircleImageView]

val mAvatar = AVATAR.getAvatarFile(userInfo.avatarName, getActivity)

Expand All @@ -102,13 +104,13 @@ class MainDrawerFragment extends Fragment {
}
}

val nameView = getView.findViewById(R.id.name).asInstanceOf[TextView]
val nameView = rootView.findViewById(R.id.name).asInstanceOf[TextView]

// zoff //
if (nameView != null) {
nameView.setText(new String(userInfo.nickname.value))
}
val statusMessageView = getView.findViewById(R.id.status_message).asInstanceOf[TextView]
val statusMessageView = rootView.findViewById(R.id.status_message).asInstanceOf[TextView]
// zoff //
if (statusMessageView != null) {
statusMessageView.setText(new String(userInfo.statusMessage.value))
Expand All @@ -118,11 +120,11 @@ class MainDrawerFragment extends Fragment {
}

def updateNavigationHeaderStatus(toxConnection: ToxConnection): Unit = {
val statusView = getView.findViewById(R.id.status)
val statusView = rootView.findViewById(R.id.status)

val status = UserStatus.getToxUserStatusFromString(State.userDb(getActivity).getActiveUserDetails.status)
val online = toxConnection != ToxConnection.NONE
val drawable = getResources.getDrawable(IconColor.iconDrawable(online, status))
val drawable = rootView.getResources.getDrawable(IconColor.iconDrawable(online, status))

// zoff //
if (statusView != null) {
Expand All @@ -138,6 +140,14 @@ class MainDrawerFragment extends Fragment {

def openDrawer(): Unit = {
mDrawerLayout.openDrawer(GravityCompat.START)
// bugfix--the maindrawer does not refresh the username and status when the drawer open
userDetailsSubscription = State.userDb(getActivity)
.activeUserDetailsObservable()
.combineLatestWith(AntoxOnSelfConnectionStatusCallback.connectionStatusSubject)((user, status) => (user, status))
.observeOn(AndroidMainThreadScheduler())
.subscribe((tuple) => {
refreshDrawerHeader(tuple._1, tuple._2)
})
}

def closeDrawer(): Unit = {
Expand Down
44 changes: 44 additions & 0 deletions app/src/main/scala/chat/tox/antox/tox/ToxApplication.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package chat.tox.antox.tox

import android.arch.lifecycle.{DefaultLifecycleObserver, LifecycleOwner, ProcessLifecycleOwner}
import android.content.{Context, IntentFilter}
import android.net.ConnectivityManager
import android.os.Build
import android.support.annotation.NonNull
import android.support.multidex.MultiDexApplication
import chat.tox.antox.data.State
import chat.tox.antox.utils.ConnectionManager

object ToxApplication {
def getInstance(context: Context): ToxApplication = context.getApplicationContext.asInstanceOf[ToxApplication]
}

class ToxApplication extends MultiDexApplication with DefaultLifecycleObserver {


def onStart(@NonNull owner: LifecycleOwner): Unit = {
State.isAppVisible = true
}

def onStop(@NonNull owner: LifecycleOwner): Unit = {
State.isAppVisible = false
}

def getAppVisible: Boolean = State.isAppVisible

override def onCreate(): Unit = {
super.onCreate()
ProcessLifecycleOwner.get.getLifecycle.addObserver(this)
try
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val intentFilter = new IntentFilter
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(new ConnectionManager, intentFilter)
}
catch {
case e: Exception =>
e.printStackTrace()
}
}

}
25 changes: 24 additions & 1 deletion app/src/main/scala/chat/tox/antox/tox/ToxService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.preference.PreferenceManager
import android.support.v4.app.NotificationCompat
import chat.tox.antox.R
import chat.tox.antox.av.CallService
import chat.tox.antox.callbacks.{AntoxOnSelfConnectionStatusCallback, ToxCallbackListener, ToxavCallbackListener}
import chat.tox.antox.data.State
import chat.tox.antox.utils.AntoxLog
import im.tox.tox4j.core.enums.ToxConnection
import im.tox.tox4j.impl.jni.ToxJniLog
import rx.lang.scala.schedulers.AndroidMainThreadScheduler
import rx.lang.scala.{Observable, Subscription}

import scala.concurrent.duration._

class ToxService extends Service {
Expand All @@ -26,6 +30,10 @@ class ToxService extends Service {

private var callService: CallService = _

private val FOREGROUND_ID = 1030

private val bgIterateInterval = 3 * 1000 //in ms

override def onCreate() {
if (!ToxSingleton.isInited) {
ToxSingleton.initTox(getApplicationContext)
Expand Down Expand Up @@ -85,7 +93,11 @@ class ToxService extends Service {
println(ToxJniLog().entries.filter(_.name == "tox4j_video_receive_frame_cb").map(_.elapsedNanos).toList.map(nanos => s" elapsed nanos video cb: $nanos").mkString("\n"))
}

Thread.sleep(Math.min(ToxSingleton.interval, ToxSingleton.toxAv.interval))
if (State.isAppVisible)
Thread.sleep(Math.min(ToxSingleton.interval, ToxSingleton.toxAv.interval))
else {
Thread.sleep(bgIterateInterval)
}
ticks += 1
} catch {
case e: Exception =>
Expand All @@ -100,6 +112,17 @@ class ToxService extends Service {

serviceThread = new Thread(start)
serviceThread.start()

stickForground()
}

def stickForground(): Unit = {
val builder = new NotificationCompat.Builder(this)
builder.setContentTitle("Antox")
builder.setPriority(NotificationCompat.PRIORITY_MIN)
builder.setWhen(0)
builder.setSmallIcon(R.drawable.ic_action_add)
startForeground(FOREGROUND_ID, builder.build)
}

override def onBind(intent: Intent): IBinder = null
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/scala/chat/tox/antox/tox/ToxSingleton.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ object ToxSingleton {
val wifiOnly = preferences.getBoolean("wifi_only", true)
val wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)

!(wifiOnly && !wifiInfo.isConnected)
(!(wifiOnly && !wifiInfo.isConnected)) && State.internetConnectivity
}


Expand Down
Loading