Skip to content

Instantly share code, notes, and snippets.

@chanakaDe
Last active July 22, 2019 04:36
Show Gist options
  • Save chanakaDe/765748b8b465138efbe951a049fc0f9b to your computer and use it in GitHub Desktop.
Save chanakaDe/765748b8b465138efbe951a049fc0f9b to your computer and use it in GitHub Desktop.
// **************** page 12 ****************
var remoteTimeOb = {
mode: "MODE_BLOCK_TIME",
status: "add",
day: day,
start: start_time,
end: end_time,
device: $scope.selectedChild.one_signal_id
};
remoteService.saveTimeScheduleData(schedule_data).then(function (data) {
console.log("POST OUTPUT : ", data);
remoteService.getTimeScheduleData($scope.selectedChild.child_id, day).then(function (data) {
console.log(data);
$scope.savedTimes = data.data;
});
});
// **************** page 14 ****************
<receiver android:name=".AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
AlarmManager am =( AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, Alarm.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
// **************** page 21 ****************
public void bright(View view){
operation = Bitmap.createBitmap(bmp.getWidth() , bmp.getHeight() , bmp.getConfig();
for(int i=0; i<bmp.getWidth(); i++){
for(int j=0; j<bmp.getHeight(); j++){
int p = bmp.getPixel(i , j);
int r = Color.red(p);
int g = Color.green(p);
int b = Color.blue(p);
int alpha = Color.alpha(p);
r = 100 + r;
g = 100 + g;
b = 100 + b;
alpha = 100 + alpha;
operation.setPixel(i , j , Color.argb(alpha , r , g , b));
}
}
im.setImageBitmap(operation);
}
// **************** page 22 ****************
for(int j=0; j<bmp.getHeight(); j++){
int p = bmp.getPixel(i , j);
int r = Color.red(p);
int g = Color.green(p);
int b = Color.blue(p);
int alpha = Color.alpha(p);
r = 0;
g = g + 150;
b = 0;
alpha = 0;
operation.setPixel(i , j , Color.argb(alpha , r , g , b));
}
// **************** page 25 ****************
if (mDisplay.getRotation() == Surface.ROTATION_0 || mDisplay.getRotation() == Surface.ROTATION_180) {
double abs = Math.abs(this.pitch);
abs = (abs - 0.4) / 0.01;
setScreenBrightness((int) Math.round(abs), this);
if ((int) Math.round(abs) >= 40) {
dismissAlertWindow();
} else {
if (!isWindowShow)
isWindowShow = showAlertWindow(3);
}
} else if (mDisplay.getRotation() == Surface.ROTATION_90 || mDisplay.getRotation() == Surface.ROTATION_270) {
double abs = Math.abs(this.roll);
Log.d("ABS ", abs + "");
if (abs >= 1.5) {
abs = (2.7 - abs) / 0.01;
} else {
abs = (abs - 0.4) / 0.01;
}
setScreenBrightness((int) Math.round(abs), this);
if ((int) Math.round(abs) >= 40) {
dismissAlertWindow();
} else {
if (!isWindowShow)
isWindowShow = showAlertWindow(3);
}
}
// **************** page 25 **************** ( part 2 )
FaceDetector detector = new FaceDetector.Builder(context)
.setTrackingEnabled(false)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.build();
// **************** page 26 ****************
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<Face> faces = detector.detect(frame);
for (int i = 0; i < faces.size(); ++i) {
Face face = faces.valueAt(i);
for (Landmark landmark : face.getLandmarks()) {
int cx = (int) (landmark.getPosition().x * scale);
int cy = (int) (landmark.getPosition().y * scale);
canvas.drawCircle(cx, cy, 10, paint);
}
}
// **************** page 27 ****************
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
ORIENTATIONS.append(Surface.ROTATION_0, 90);
ORIENTATIONS.append(Surface.ROTATION_90, 0);
ORIENTATIONS.append(Surface.ROTATION_180, 270);
ORIENTATIONS.append(Surface.ROTATION_270, 180);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private int getRotationCompensation(String cameraId, Activity activity, Context context)
throws CameraAccessException {
int deviceRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
int rotationCompensation = ORIENTATIONS.get(deviceRotation);
CameraManager cameraManager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
int sensorOrientation = cameraManager
.getCameraCharacteristics(cameraId)
.get(CameraCharacteristics.SENSOR_ORIENTATION);
rotationCompensation = (rotationCompensation + sensorOrientation + 270) % 360;
int result;
switch (rotationCompensation) {
case 0:
result = FirebaseVisionImageMetadata.ROTATION_0;
break;
case 90:
result = FirebaseVisionImageMetadata.ROTATION_90;
break;
case 180:
result = FirebaseVisionImageMetadata.ROTATION_180;
break;
case 270:
result = FirebaseVisionImageMetadata.ROTATION_270;
break;
default:
result = FirebaseVisionImageMetadata.ROTATION_0;
Log.e(TAG, "Bad rotation value: " + rotationCompensation);
}
return result;
}
// **************** page 28 ****************
for (FirebaseVisionFace face : faces) {
Rect bounds = face.getBoundingBox();
float rotY = face.getHeadEulerAngleY(); // Head is rotated to the right rotY degrees
float rotZ = face.getHeadEulerAngleZ(); // Head is tilted sideways rotZ degrees
FirebaseVisionFaceLandmark leftEar = face.getLandmark(FirebaseVisionFaceLandmark.LEFT_EAR);
if (leftEar != null) {
FirebaseVisionPoint leftEarPos = leftEar.getPosition();
}
List<FirebaseVisionPoint> leftEyeContour =
face.getContour(FirebaseVisionFaceContour.LEFT_EYE).getPoints();
List<FirebaseVisionPoint> upperLipBottomContour =
face.getContour(FirebaseVisionFaceContour.UPPER_LIP_BOTTOM).getPoints();
if (face.getSmilingProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
float smileProb = face.getSmilingProbability();
}
if (face.getRightEyeOpenProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
float rightEyeOpenProb = face.getRightEyeOpenProbability();
}
if (face.getTrackingId() != FirebaseVisionFace.INVALID_ID) {
int id = face.getTrackingId();
}
}
// **************** page 29 ****************
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<Face> faces = detector.detect(frame);
for (int i = 0; i < faces.size(); ++i) {
Face face = faces.valueAt(i);
for (Landmark landmark : face.getLandmarks()) {
int cx = (int) (landmark.getPosition().x * scale);
int cy = (int) (landmark.getPosition().y * scale);
canvas.drawCircle(cx, cy, 10, paint);
}
}
// **************** page 33 ****************
Location pointA = new Location("");
pointA.setLatitude(26.2145);
pointA.setLogitude(-80.1245);
Location pointB = new Location("");
pointB.setLatitude(36.2145);
pointB.setLogitude(-90.1245);
float distanceInMeters = pointA.distanceTo(pointB);
// **************** page 35 ****************
if (status) {
if (PermissionUtil.isRequiredPermissionGranted(context, MODE_APP_BLOCK)) {
if (!Utility.isServiceRunning(context, LocationService4.class)) {
SharedPrefsUtil.setBooleanPreference(context, MODE_APP_BLOCK, true);
Intent intent1 = new Intent(context, LocationService4.class);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
context.startForegroundService(intent1);
} else {
context.startService(intent1);
}
}
}
} else {
SharedPrefsUtil.setBooleanPreference(context, MODE_APP_BLOCK, false);
Intent intent = new Intent(context, LocationService4.class);
context.stopService(intent);
}
// **************** page 36 ****************
if (isSpeedOverLimit) {
if (appBlockView == null || !appBlockView.isShown()) {
if (isConcernedAppIsInForeground()) {
new Handler(Looper.getMainLooper()).post(() -> {
if (!currentApp.equals(previousApp)) {
showAppBlockWindow();
previousApp = currentApp;
}
});
} else {
new Handler(Looper.getMainLooper()).post(() -> dismissAppBlockWindow());
}
}
} else {
new Handler(Looper.getMainLooper()).post(() -> dismissAppBlockWindow());
}
// **************** page 38 ****************
RequestParams rp = new RequestParams();
rp.add("username", "xxxx"); rp.add("password", "xxxx");
HttpUtils.post(AppConstant.URL_FEED, rp, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
// If the response is JSONObject instead of expected JSONArray
Log.d("asd", "---------------- this is response : " + response);
try {
JSONObject serverResp = new JSONObject(response.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray timeline) {
}
});
// **************** page 41 ****************
PackageManager p = context.getPackageManager();
ComponentName componentName = new ComponentName(context, SplashActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
// **************** page 42 ****************
<div class="row">
<div class="col-lg-8">
<h5 style="color:white">TekNekk App Hide</h5>
</div>
<div class="col-lg-2">
<toggle-switch style="border: 4px solid #FFFF00" ng-change="getAppHideAction()" ng-model="remote.appHide">
</toggle-switch>
</div>
</div>
// **************** page 43 ****************
$scope.getAppHideAction = function () {
$scope.playAudio();
console.log("App Hide : ", $scope.remote.appHide);
var notifyMsg = "";
if ($scope.remote.appHide == true) {
notifyMsg = "ON";
} else {
notifyMsg = "OFF";
}
var appHideOb = {
mode: 'MODE_HIDE_UNHIDE_APP',
status: $scope.remote.appHide,
device: $scope.selectedChild.one_signal_id
};
console.log("Ob : ", appHideOb);
remoteService.manageRemoteConnection(appHideOb).then(function (data) {
console.log(data);
if (data.code == 200) {
var appHideHistory = {
mode: 'MODE_HIDE_UNHIDE_APP',
status: $scope.remote.appHide,
child_id: $scope.selectedChild.child_id
};
remoteService.manageConnectionHistory(appHideHistory).then(function (data) {
console.log("HISTORY : ", data);
});
toastr.success('TekNekk App Hide Turned ' + notifyMsg, 'SUCCESS', {
"positionClass": "toast-top-right",
"timeOut": "5000",
"newestOnTop": true,
"maxOpened": 0
});
} else {
toastr.error('Device Not Found. Connection Failed ', 'Error', {
"positionClass": "toast-top-right",
"timeOut": "5000",
"newestOnTop": true,
"maxOpened": 0
});
}
});
}
// **************** page 44 ****************
manageRemoteConnection: function (data) {
return $http({
method: "POST",
data: data,
url: host.admin_control_manage + '/admin_control/remote'
}).then(function (response) {
return response.data;
});
}
var mode = req.body.mode;
var status = req.body.status;
var device = req.body.device;
firstNotification.setTargetDevices([device]);
firstNotification.setParameter('data', {"mode": mode, "status": status});
console.log(firstNotification);
myClient.sendNotification(firstNotification, function (err, httpResponse, data) {
if (err) {
console.log('Something went wrong....');
} else {
console.log(data, httpResponse.statusCode);
res.json({type: "success", code: httpResponse.statusCode, data: data});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment